From 514df45b8c2500891950e8f3f2e55967db20af3e Mon Sep 17 00:00:00 2001 From: bert hubert Date: Fri, 10 Nov 2023 21:00:31 +0100 Subject: [PATCH] Add and document a `localwho()` function for LUA records, so you can change your answer based on which address or port a query came in from. Can be used like this: ``` berthub.eu 300 IN LUA A ";if(localwho:getPort() == 5300) then return '217.100.190.174'; else return '86.82.68.237'; end" ``` This, combined with some forwarding/iptables, means that queries that came in on 217.100.190.174 also get 217.100.190.174 as an answer. And same for 86.82.68.237. In this way you can do some simple DNS-based dual homing. --- docs/lua-records/functions.rst | 2 ++ pdns/lua-record.cc | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/lua-records/functions.rst b/docs/lua-records/functions.rst index f01466eb0a..6902d761ad 100644 --- a/docs/lua-records/functions.rst +++ b/docs/lua-records/functions.rst @@ -34,6 +34,8 @@ Client variables resolver. This is a :class:`ComboAddress`. ``who`` IP address of requesting resolver as a :class:`ComboAddress`. +``localwho`` + IP address (including port) of socket on which the question arrived. Functions available ------------------- diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index e3c7f52c0b..abe4a108f5 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -1146,6 +1146,7 @@ std::vector> luaSynth(const std::string& code, cons lua.writeVariable("zone", zone); lua.writeVariable("zoneid", zoneid); lua.writeVariable("who", dnsp.getInnerRemote()); + lua.writeVariable("localwho", dnsp.getLocal()); lua.writeVariable("dh", (dnsheader*)&dnsp.d); lua.writeVariable("dnssecOK", dnsp.d_dnssecOk); lua.writeVariable("tcp", dnsp.d_tcp); -- 2.47.2