> 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:
```
`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.
+
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)
{
}
#endif
+SuffixMatchNode g_suffixMatchNodeFilter;
SuffixMatchNode g_abuseSMN;
NetmaskGroup g_abuseNMG;
shared_ptr<DownstreamState> g_abuseDSS;
continue;
}
+ if(g_suffixMatchNodeFilter.check(qname))
+ continue;
+
if(re && re->match(qname.toString())) {
g_regexBlocks++;
continue;
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();
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;
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)