From: Charles-Henri Bruyand Date: Thu, 29 Nov 2018 16:25:17 +0000 (+0100) Subject: auth: lua records - mirror backupSelector behaviour to ifportup X-Git-Tag: auth-4.2.0-alpha1~12^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5daed657a82c82d7dedf2e35abe6e4a1afbcd033;p=thirdparty%2Fpdns.git auth: lua records - mirror backupSelector behaviour to ifportup --- diff --git a/docs/lua-records/functions.rst b/docs/lua-records/functions.rst index ae4afc47c6..ab125acd67 100644 --- a/docs/lua-records/functions.rst +++ b/docs/lua-records/functions.rst @@ -46,7 +46,8 @@ Record creation functions Various options can be set in the ``options`` parameter: - - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none'. + - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random'). + - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random'). - ``source``: Source IP address to check from @@ -54,7 +55,9 @@ Record creation functions More sophisticated test that attempts an actual http(s) connection to ``url``. In addition, multiple groups of IP addresses can be supplied. The - first set with a working (available) IP address is used. + first set with a working (available) IP address is used. URL is considered up if + HTTP response code is 200 and optionally if the content matches ``stringmatch`` + option. :param string url: The url to retrieve. :param addresses: List of lists of IP addresses to check the URL on. @@ -62,8 +65,8 @@ Record creation functions Various options can be set in the ``options`` parameter: - - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none'. - - ``defaultSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none'. + - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random'). + - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random'). - ``source``: Source IP address to check from - ``stringmatch``: check ``url`` for this string, only declare 'up' if found diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index cc1dc0538a..6357a372be 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -677,6 +677,7 @@ std::vector> luaSynth(const std::string& code, cons vector candidates, unavailables; opts_t opts; vector conv; + std::string selector; if(options) opts = *options; @@ -689,12 +690,16 @@ std::vector> luaSynth(const std::string& code, cons unavailables.push_back(rem); } } - if(candidates.empty()) { - // if no IP is available, use selector on the whole set + if(!candidates.empty()) { + // use regular selector + selector = getOptionValue(options, "selector", "random"); + } else { + // All units are down, apply backupSelector on all candidates candidates = std::move(unavailables); + selector = getOptionValue(options, "backupSelector", "random"); } - vector res = useSelector(getOptionValue(options, "selector", "random"), bestwho, candidates); + vector res = useSelector(selector, bestwho, candidates); return convIpListToString(res); }); @@ -730,13 +735,13 @@ std::vector> luaSynth(const std::string& code, cons } } - // All units down, apply defaultSelector on all candidates + // All units down, apply backupSelector on all candidates vector ret{}; for(const auto& unit : candidates) { ret.insert(ret.end(), unit.begin(), unit.end()); } - vector res = useSelector(getOptionValue(options, "defaultSelector", "random"), bestwho, ret); + vector res = useSelector(getOptionValue(options, "backupSelector", "random"), bestwho, ret); return convIpListToString(res); });