]> granicus.if.org Git - pdns/commitdiff
add addDomainBlock, spruce up documentation
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 25 Feb 2015 21:19:35 +0000 (22:19 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Wed, 25 Feb 2015 21:19:35 +0000 (22:19 +0100)
pdns/README-dnsdist.md
pdns/dnsdist.cc
pdns/dnsdistconf.lua

index 2f82b9855465ddf9574abf0047f577fc4dfdd90d..d8729445cfc3e83a86f9229b1d7d7ca8cebeb8da 100644 (file)
@@ -105,9 +105,6 @@ this:
 > addDomainBlock("sh43354.cn.")
 ```
 
-WARNING: This is not actually implemented yet, but `dnsdistconf.lua` shows
-the powerful but more typing way of achieving addDomainBlock!
-
 Or we configure a server dedicated to receiving the nasty stuff:
 
 ```
@@ -134,18 +131,22 @@ More powerful things can be achieved by defining a function called
 `blockFilter()` in the configuration file, which can decide to drop traffic
 on any reason it wants.
 
-The default load balancing policy is called 'first', which means the first
-server that has not exceeded its QPS limit gets the traffic. If you don't
-like this default policy, you can create your own, like this for example:
+The default load balancing policy is called 'firstAvailable', which means
+the first server that has not exceeded its QPS limit gets the traffic.  If
+you don't like this default policy, you can create your own, like this for
+example:
 
 ```
 counter=0
 servers=getServers()
-function roundrobin(remote, qname, qtype) 
+function luaroundrobin(remote, qname, qtype) 
         counter=counter+1
         return servers[1+(counter % #servers)]
 end
 
-setServerPolicy(roundrobin)
+setServerPolicy(luaroundrobin)
 ```
 
+Incidentally, this is similar to setting: `setServerPolicy(roundrobin)`
+which uses the C++ based roundrobin policy.
+
index db30d53ddf4fb225b49c8173d070ec764e0011d0..1f8d51494ebd6ead090e745740d7933cbf07035d 100644 (file)
@@ -311,6 +311,21 @@ shared_ptr<DownstreamState> firstAvailable(const ComboAddress& remote, const DNS
   return g_dstates[counter % g_dstates.size()];
 }
 
+shared_ptr<DownstreamState> roundrobin(const ComboAddress& remote, const DNSName& qname, uint16_t qtype)
+{
+  vector<shared_ptr<DownstreamState>> poss;
+  for(auto& d : g_dstates) {
+    if(d->isUp())
+      poss.push_back(d);
+  }
+  static int counter=0;
+  ++counter;
+  if(poss.empty())
+    return g_dstates[counter % g_dstates.size()];
+  return poss[counter % poss.size()];
+}
+
+
 #if 0
 static void daemonize(void)
 {
@@ -331,6 +346,7 @@ static void daemonize(void)
 }
 #endif
 
+SuffixMatchNode g_suffixMatchNodeFilter;
 SuffixMatchNode g_abuseSMN;
 NetmaskGroup g_abuseNMG;
 shared_ptr<DownstreamState> g_abuseDSS;
@@ -378,6 +394,9 @@ try
        continue;
     }
 
+    if(g_suffixMatchNodeFilter.check(qname))
+      continue;
+
     if(re && re->match(qname.toString())) {
       g_regexBlocks++;
       continue;
@@ -387,8 +406,10 @@ try
     if(g_abuseSMN.check(qname) || g_abuseNMG.match(remote)) {
       ss = &*g_abuseDSS;
     }
-    else
+    else {
+      std::lock_guard<std::mutex> lock(g_luamutex);
       ss = g_policy(remote, qname, qtype).get();
+    }
     ss->queries++;
 
     unsigned int idOffset = (ss->idOffset++) % ss->idStates.size();
@@ -743,10 +764,11 @@ void setupLua()
       g_policy = func;
     });
 
-  g_lua.writeFunction("unsetServerPolicy", []() {
-      g_policy = firstAvailable;
-    });
 
+  g_lua.writeFunction("firstAvailable", firstAvailable);
+  g_lua.writeFunction("roundrobin", roundrobin);
+
+  g_lua.writeFunction("addDomainBlock", [](const std::string& domain) { g_suffixMatchNodeFilter.add(DNSName(domain)); });
   g_lua.writeFunction("listServers", []() {  
       try {
       string ret;
index 421e849753f9cb93b62b591e82db6a8e62818229..ef95a51d05afa109374a497e1fbc8f62a5597d5c 100644 (file)
@@ -36,10 +36,10 @@ counter=0
 servers=getServers()
 
 -- called to pick a downstream server
-function roundrobin(remote, qname, qtype) 
+function luaroundrobin(remote, qname, qtype) 
         counter=counter+1;
         return servers[1+(counter % #servers)]
 end
 
--- setServerPolicy("roundrobin")
+-- setServerPolicy(luaroundrobin)