From: bert hubert Date: Thu, 19 Nov 2015 11:05:00 +0000 (+0100) Subject: amazingly, we could not *set* the local address from Lua, only add to the set of... X-Git-Tag: dnsdist-1.0.0-alpha1~210^2~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5949b95b1c5c930c2f0070d87b52835e04f8a8a2;p=pdns amazingly, we could not *set* the local address from Lua, only add to the set of listen addresses! --- diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 01f118ba6..649885b71 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -543,6 +543,9 @@ Here are all functions: * `addACL(netmask)`: add to the ACL set who can use this server * `setACL({netmask, netmask})`: replace the ACL set with these netmasks. Use `setACL({})` to reset the list, meaning no one can use us * `showACL()`: show our ACL set + * Network related: + * `addLocal(netmask, [false])`: add to addresses we listen on. Second optional parameter sets TCP/IP or not. + * `setLocal(netmask, [false])`: reset list of addresses we listen on to this address. Second optional parameter sets TCP/IP or not. * Blocking related: * `addDomainBlock(domain)`: block queries within this domain * Carbon/Graphite/Metronome statistics related: diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index b24878384..3a3945a68 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -268,6 +268,19 @@ vector> setupLua(bool client, const std::string& confi g_ACL.modify([domain](NetmaskGroup& nmg) { nmg.addMask(domain); }); }); + g_lua.writeFunction("setLocal", [client](const std::string& addr, boost::optional doTCP) { + if(client) + return; + try { + ComboAddress loc(addr, 53); + g_locals.clear(); + g_locals.push_back({loc, doTCP ? *doTCP : true}); /// only works pre-startup, so no sync necessary + } + catch(std::exception& e) { + g_outputBuffer="Error: "+string(e.what())+"\n"; + } + }); + g_lua.writeFunction("addLocal", [client](const std::string& addr, boost::optional doTCP) { if(client) return;