]> granicus.if.org Git - pdns/commitdiff
auth: lua records - mirror backupSelector behaviour to ifportup
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 29 Nov 2018 16:25:17 +0000 (17:25 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 29 Nov 2018 16:25:17 +0000 (17:25 +0100)
docs/lua-records/functions.rst
pdns/lua-record.cc

index ae4afc47c6048d9e66c739ce3299123e86b22a30..ab125acd67a78d7c2174ac9cd600ed4df0b9bfca 100644 (file)
@@ -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
 
index cc1dc0538a61172a445a6d1b27ad89039f23305b..6357a372be1dfc833c3a00f1df6e18d123c08280 100644 (file)
@@ -677,6 +677,7 @@ std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, cons
       vector<ComboAddress> candidates, unavailables;
       opts_t opts;
       vector<ComboAddress > conv;
+      std::string selector;
 
       if(options)
         opts = *options;
@@ -689,12 +690,16 @@ std::vector<shared_ptr<DNSRecordContent>> 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<ComboAddress> res = useSelector(getOptionValue(options, "selector", "random"), bestwho, candidates);
+      vector<ComboAddress> res = useSelector(selector, bestwho, candidates);
       return convIpListToString(res);
     });
 
@@ -730,13 +735,13 @@ std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, cons
         }
       }
 
-      // All units down, apply defaultSelector on all candidates
+      // All units down, apply backupSelector on all candidates
       vector<ComboAddress> ret{};
       for(const auto& unit : candidates) {
         ret.insert(ret.end(), unit.begin(), unit.end());
       }
 
-      vector<ComboAddress> res = useSelector(getOptionValue(options, "defaultSelector", "random"), bestwho, ret);
+      vector<ComboAddress> res = useSelector(getOptionValue(options, "backupSelector", "random"), bestwho, ret);
       return convIpListToString(res);
     });