]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add and document a `localwho()` function for LUA records, so you can change your...
authorbert hubert <bert@hubertnet.nl>
Fri, 10 Nov 2023 20:00:31 +0000 (21:00 +0100)
committerbert hubert <bert@hubertnet.nl>
Fri, 10 Nov 2023 20:00:31 +0000 (21:00 +0100)
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
pdns/lua-record.cc

index f01466eb0a944803d259f7210768a350364ddba3..6902d761ad2c2e8c2782301f04894f96091228f9 100644 (file)
@@ -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
 -------------------
index e3c7f52c0b2f59c388abc1969ffc19603e8de003..abe4a108f5735af7d091b323dfd7581040dca8ac 100644 (file)
@@ -1146,6 +1146,7 @@ std::vector<shared_ptr<DNSRecordContent>> 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);