4 local adns
= require
"net.adns";
6 local map_config
= module
:get_option("srvinjection") or {};
7 local map
= module
:shared
"s2s_map"
9 for host
, mapping
in pairs(map_config
) do
10 if type(mapping
) == "table" and type(mapping
[1]) == "string" and (type(mapping
[2]) == "number") then
11 local connecthost
, connectport
= mapping
[1], mapping
[2] or 5269;
14 target
= connecthost
..".";
21 module
:log("warn", "Ignoring invalid SRV injection for host '%s'", host
);
26 local original_lookup
= adns
.lookup
;
27 function adns
.lookup(handler
, qname
, qtype
, qclass
)
28 if qtype
== "SRV" then
29 local host
= qname
:match("^_xmpp%-server%._tcp%.(.*)%.$");
30 local mapping
= map
[host
] or map
["*"];
35 elseif qtype
== "A" then
36 if (qname
== "localhost." or qname
== "127.0.0.1.") then
37 handler({{ a
= "127.0.0.1" }});
40 local ip
= qname
:match("^(%d+.%d+.%d+.%d+).$");
42 handler({{ a
= ip
}});
46 return original_lookup(handler
, qname
, qtype
, qclass
);
49 function module
.unload()
50 adns
.lookup
= original_lookup
;