This commit is contained in:
chapeau 2024-07-30 15:20:41 +02:00
parent 06edb7c818
commit 278fac9985

14
dns.py
View file

@ -24,13 +24,16 @@ class ProxyResolver(BaseResolver):
]
qname = DNSLabel(request.q.qname)
current_server = ()
for (net, sub, trans, dns) in subnets:
for serv in dns:
if serv["domain"] == str(qname)[-len(serv["domain"])-1:-1]:
if serv == str(qname)[-len(serv)-1:-1]:
if net == self.config.local_network:
address = dns["ip"]
current_server = {"sub": sub, "trans": trans, "dns": dns[serv]}
else:
address = translate(serc["ip"], sub, trans)
current_server = {"sub": sub, "trans": trans, "dns": translate(dns[serv], sub, trans)}
address = current_server["dns"]
try:
proxy_r = request.send(address, port, timeout=self.timeout)
reply = DNSRecord.parse(proxy_r)
@ -39,9 +42,8 @@ class ProxyResolver(BaseResolver):
reply.header.rcode = getattr(RCODE, 'NXDOMAIN')
if address != self.default_address and address not in self.config.data["network"][self.config.local_network]["dns"].values():
for rr in reply.rr:
for (net, sub, trans, dns) in subnets:
if address in dns.values() and netIPv4Address(rr.rdata) in IPv4Network(sub):
rr.rdata.data = IPv4Address(translate(str(rr.rdata), sub, trans)).packed
if address == current_server["dns"] and IPv4Address(rr.rdata) in IPv4Network(current_server["sub"]):
rr.rdata.data = IPv4Address(translate(str(rr.rdata), current_server["sub"], current_server["trans"])).packed
reply.set_header_qa()
return reply