summaryrefslogtreecommitdiffstats
path: root/Sshuttle VPN.app/Contents/Resources/sshuttle/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'Sshuttle VPN.app/Contents/Resources/sshuttle/server.py')
-rw-r--r--Sshuttle VPN.app/Contents/Resources/sshuttle/server.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/Sshuttle VPN.app/Contents/Resources/sshuttle/server.py b/Sshuttle VPN.app/Contents/Resources/sshuttle/server.py
index 24dd462..45bc2fc 100644
--- a/Sshuttle VPN.app/Contents/Resources/sshuttle/server.py
+++ b/Sshuttle VPN.app/Contents/Resources/sshuttle/server.py
@@ -1,4 +1,4 @@
-import re, struct, socket, select, traceback
+import re, struct, socket, select, traceback, time
if not globals().get('skip_imports'):
import ssnet, helpers, hostwatch
import compat.ssubprocess as ssubprocess
@@ -106,11 +106,31 @@ class Hostwatch:
self.sock = None
+class DnsProxy(Handler):
+ def __init__(self, mux, chan, request):
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ Handler.__init__(self, [sock])
+ self.sock = sock
+ self.timeout = time.time()+30
+ self.mux = mux
+ self.chan = chan
+ self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
+ self.sock.connect((resolvconf_random_nameserver(), 53))
+ self.sock.send(request)
+
+ def callback(self):
+ data = self.sock.recv(4096)
+ debug2('DNS response: %d bytes\n' % len(data))
+ self.mux.send(self.chan, ssnet.CMD_DNS_RESPONSE, data)
+ self.ok = False
+
+
def main():
if helpers.verbose >= 1:
helpers.logprefix = ' s: '
else:
helpers.logprefix = 'server: '
+ debug1('latency control setting = %r\n' % latency_control)
routes = list(list_routes())
debug1('available routes:\n')
@@ -164,6 +184,14 @@ def main():
handlers.append(Proxy(MuxWrapper(mux, channel), outwrap))
mux.new_channel = new_channel
+ dnshandlers = {}
+ def dns_req(channel, data):
+ debug2('Incoming DNS request.\n')
+ h = DnsProxy(mux, channel, data)
+ handlers.append(h)
+ dnshandlers[channel] = h
+ mux.got_dns_req = dns_req
+
while mux.ok:
if hw.pid:
assert(hw.pid > 0)
@@ -172,5 +200,13 @@ def main():
raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv)
ssnet.runonce(handlers, mux)
- mux.check_fullness()
+ if latency_control:
+ mux.check_fullness()
mux.callback()
+
+ if dnshandlers:
+ now = time.time()
+ for channel,h in dnshandlers.items():
+ if h.timeout < now or not h.ok:
+ del dnshandlers[channel]
+ h.ok = False