From 5949b95b1c5c930c2f0070d87b52835e04f8a8a2 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 19 Nov 2015 12:05:00 +0100 Subject: [PATCH] amazingly, we could not *set* the local address from Lua, only add to the set of listen addresses! --- pdns/README-dnsdist.md | 3 +++ pdns/dnsdist-lua.cc | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 01f118ba63..649885b718 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 b24878384f..3a3945a681 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; -- 2.47.2