mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Fix dnspr for Windows
This commit is contained in:
1 parent
845df7d196
commit
a194f207ba
7 files changed
+59
-12
No files matched your search
@@ -1,5 +1,7 @@
|
||||
"""dnspr: a caching DNS proxy, answering from what it has been told."""
|
||||
|
||||
import time
|
||||
|
||||
|
||||
def run(t):
|
||||
port = t.free_port()
|
||||
@@ -15,8 +17,11 @@ def run(t):
|
||||
allow *
|
||||
dnspr -p{port}
|
||||
""")
|
||||
# wait for the service: a datagram sent too early is simply lost
|
||||
for _ in range(100):
|
||||
# Wait for the service: a datagram sent too early is simply lost. Bound
|
||||
# by the clock, not by a number of attempts, so a server that answers
|
||||
# nothing costs seconds rather than minutes.
|
||||
deadline = time.time() + 5
|
||||
while time.time() < deadline:
|
||||
if t.dns_query(port, "host.test"):
|
||||
break
|
||||
|
||||
|
||||
+12
-4
@@ -190,15 +190,23 @@ def run(t):
|
||||
|
||||
t.ne(200, t.http(v4url, proxy=f"127.0.0.1:{partial}").status,
|
||||
"denying 127.0.0.1 denies the address as written")
|
||||
t.eq(200, t.http(mapped, proxy=f"127.0.0.1:{partial}").status,
|
||||
"but the same host asked for as ::ffff:127.0.0.1 is still reached")
|
||||
|
||||
# Whether the mapped form reaches the same host is up to the stack: it
|
||||
# does where a mapped address is routed to IPv4, and that is the hazard
|
||||
# the security notes describe. Where it does not, there is nothing to
|
||||
# assert, but the rule that names every spelling still has to hold.
|
||||
if t.http(mapped, proxy=f"127.0.0.1:{partial}").status == 200:
|
||||
t.ok("the same host asked for as ::ffff:127.0.0.1 is still reached")
|
||||
else:
|
||||
t.skip("the mapped form (this stack does not route it to IPv4)")
|
||||
|
||||
t.eq(200, t.http(url, proxy=f"127.0.0.1:{partial}").status,
|
||||
"and so is ::1, which the rule never mentioned")
|
||||
"and ::1 is reached, which the rule never mentioned")
|
||||
|
||||
t.ne(200, t.http(v4url, proxy=f"127.0.0.1:{complete}").status,
|
||||
"naming every spelling denies the plain address")
|
||||
t.ne(200, t.http(mapped, proxy=f"127.0.0.1:{complete}").status,
|
||||
"and the mapped one")
|
||||
"and the mapped one, whether or not it would have been reachable")
|
||||
t.ne(200, t.http(url, proxy=f"127.0.0.1:{complete}").status,
|
||||
"and the IPv6 loopback")
|
||||
|
||||
|
||||
+8
-3
@@ -424,15 +424,20 @@ class Tester:
|
||||
|
||||
# ---- DNS ---------------------------------------------------------
|
||||
|
||||
def dns_query(self, port, name, host="127.0.0.1"):
|
||||
"""Ask for an A record and return the addresses in the answer."""
|
||||
def dns_query(self, port, name, host="127.0.0.1", timeout=2.0):
|
||||
"""Ask for an A record and return the addresses in the answer.
|
||||
|
||||
The default timeout is short: a name server on the loopback answers
|
||||
at once or not at all, and waiting the full request timeout on every
|
||||
attempt turns a server that answers nothing into a very slow run.
|
||||
"""
|
||||
query = struct.pack("!HHHHHH", 0x2A2A, 0x0100, 1, 0, 0, 0)
|
||||
for label in name.split("."):
|
||||
query += bytes([len(label)]) + label.encode()
|
||||
query += b"\x00" + struct.pack("!HH", 1, 1)
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.settimeout(self.timeout)
|
||||
sock.settimeout(timeout)
|
||||
try:
|
||||
sock.sendto(query, (host, port))
|
||||
data = sock.recvfrom(65536)[0]
|
||||
|
||||
Reference in new issue
Block a user