mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-04-22 18:28:24 +02:00
Add new option for overriding destination DNS server.
This commit is contained in:
parent
cdbb379910
commit
d2e97a60f7
@ -34,4 +34,4 @@ sshuttle.helpers.verbose = verbosity
|
|||||||
|
|
||||||
import sshuttle.cmdline_options as options
|
import sshuttle.cmdline_options as options
|
||||||
from sshuttle.server import main
|
from sshuttle.server import main
|
||||||
main(options.latency_control, options.auto_hosts)
|
main(options.latency_control, options.auto_hosts, options.to_nameserver)
|
||||||
|
@ -415,7 +415,8 @@ def ondns(listener, method, mux, handlers):
|
|||||||
|
|
||||||
def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
||||||
python, latency_control,
|
python, latency_control,
|
||||||
dns_listener, seed_hosts, auto_hosts, auto_nets, daemon):
|
dns_listener, seed_hosts, auto_hosts, auto_nets, daemon,
|
||||||
|
to_nameserver):
|
||||||
|
|
||||||
debug1('Starting client with Python version %s\n'
|
debug1('Starting client with Python version %s\n'
|
||||||
% platform.python_version())
|
% platform.python_version())
|
||||||
@ -434,7 +435,8 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
|||||||
ssh_cmd, remotename, python,
|
ssh_cmd, remotename, python,
|
||||||
stderr=ssyslog._p and ssyslog._p.stdin,
|
stderr=ssyslog._p and ssyslog._p.stdin,
|
||||||
options=dict(latency_control=latency_control,
|
options=dict(latency_control=latency_control,
|
||||||
auto_hosts=auto_hosts))
|
auto_hosts=auto_hosts,
|
||||||
|
to_nameserver=to_nameserver))
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e.args[0] == errno.EPIPE:
|
if e.args[0] == errno.EPIPE:
|
||||||
raise Fatal("failed to establish ssh session (1)")
|
raise Fatal("failed to establish ssh session (1)")
|
||||||
@ -534,7 +536,7 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
|||||||
def main(listenip_v6, listenip_v4,
|
def main(listenip_v6, listenip_v4,
|
||||||
ssh_cmd, remotename, python, latency_control, dns, nslist,
|
ssh_cmd, remotename, python, latency_control, dns, nslist,
|
||||||
method_name, seed_hosts, auto_hosts, auto_nets,
|
method_name, seed_hosts, auto_hosts, auto_nets,
|
||||||
subnets_include, subnets_exclude, daemon, pidfile):
|
subnets_include, subnets_exclude, daemon, to_nameserver, pidfile):
|
||||||
|
|
||||||
if daemon:
|
if daemon:
|
||||||
try:
|
try:
|
||||||
@ -549,6 +551,8 @@ def main(listenip_v6, listenip_v4,
|
|||||||
# Get family specific subnet lists
|
# Get family specific subnet lists
|
||||||
if dns:
|
if dns:
|
||||||
nslist += resolvconf_nameservers()
|
nslist += resolvconf_nameservers()
|
||||||
|
if to_nameserver is not None:
|
||||||
|
to_nameserver = "%s@%s" % tuple(to_nameserver[1:])
|
||||||
|
|
||||||
subnets = subnets_include + subnets_exclude # we don't care here
|
subnets = subnets_include + subnets_exclude # we don't care here
|
||||||
subnets_v6 = [i for i in subnets if i[0] == socket.AF_INET6]
|
subnets_v6 = [i for i in subnets if i[0] == socket.AF_INET6]
|
||||||
@ -741,7 +745,7 @@ def main(listenip_v6, listenip_v4,
|
|||||||
try:
|
try:
|
||||||
return _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
return _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
||||||
python, latency_control, dns_listener,
|
python, latency_control, dns_listener,
|
||||||
seed_hosts, auto_hosts, auto_nets, daemon)
|
seed_hosts, auto_hosts, auto_nets, daemon, to_nameserver)
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
if daemon:
|
if daemon:
|
||||||
|
@ -73,7 +73,9 @@ def main():
|
|||||||
opt.auto_nets,
|
opt.auto_nets,
|
||||||
includes,
|
includes,
|
||||||
excludes,
|
excludes,
|
||||||
opt.daemon, opt.pidfile)
|
opt.daemon,
|
||||||
|
opt.to_ns,
|
||||||
|
opt.pidfile)
|
||||||
|
|
||||||
if return_code == 0:
|
if return_code == 0:
|
||||||
log('Normal exit code, exiting...')
|
log('Normal exit code, exiting...')
|
||||||
|
@ -146,6 +146,15 @@ parser.add_argument(
|
|||||||
capture and forward DNS requests made to the following servers
|
capture and forward DNS requests made to the following servers
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--to-ns",
|
||||||
|
metavar="IP[:PORT]",
|
||||||
|
type=parse_ipport,
|
||||||
|
help="""
|
||||||
|
the DNS server to forward requests to; defaults to servers in /etc/resolv.conf on remote side if not given.
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--method",
|
"--method",
|
||||||
choices=["auto", "nat", "tproxy", "pf", "ipfw"],
|
choices=["auto", "nat", "tproxy", "pf", "ipfw"],
|
||||||
|
@ -160,7 +160,7 @@ class Hostwatch:
|
|||||||
|
|
||||||
class DnsProxy(Handler):
|
class DnsProxy(Handler):
|
||||||
|
|
||||||
def __init__(self, mux, chan, request):
|
def __init__(self, mux, chan, request, to_nameserver):
|
||||||
Handler.__init__(self, [])
|
Handler.__init__(self, [])
|
||||||
self.timeout = time.time() + 30
|
self.timeout = time.time() + 30
|
||||||
self.mux = mux
|
self.mux = mux
|
||||||
@ -168,6 +168,15 @@ class DnsProxy(Handler):
|
|||||||
self.tries = 0
|
self.tries = 0
|
||||||
self.request = request
|
self.request = request
|
||||||
self.peers = {}
|
self.peers = {}
|
||||||
|
if to_nameserver is None:
|
||||||
|
self.to_nameserver = None
|
||||||
|
else:
|
||||||
|
peer, port = to_nameserver.split("@")
|
||||||
|
port = int(port)
|
||||||
|
if port == 0:
|
||||||
|
port = 53
|
||||||
|
family = socket.AF_INET6 if ":" in peer else socket.AF_INET
|
||||||
|
self.to_nameserver = family, peer, port
|
||||||
self.try_send()
|
self.try_send()
|
||||||
|
|
||||||
def try_send(self):
|
def try_send(self):
|
||||||
@ -175,18 +184,19 @@ class DnsProxy(Handler):
|
|||||||
return
|
return
|
||||||
self.tries += 1
|
self.tries += 1
|
||||||
|
|
||||||
family, peer = resolvconf_random_nameserver()
|
if self.to_nameserver is None:
|
||||||
|
family, peer = resolvconf_random_nameserver()
|
||||||
|
port = 53
|
||||||
|
else:
|
||||||
|
family, peer, port = self.to_nameserver
|
||||||
|
|
||||||
sock = socket.socket(family, socket.SOCK_DGRAM)
|
sock = socket.socket(family, socket.SOCK_DGRAM)
|
||||||
sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
|
sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
|
||||||
# Connect to custom DNS server running in the Telepresence pod:
|
sock.connect((peer, port))
|
||||||
# XXX eventually this should be configured via command-line
|
|
||||||
# option and submitted to upstream as improvement.
|
|
||||||
sock.connect(('127.0.0.1', 9053))
|
|
||||||
|
|
||||||
self.peers[sock] = peer
|
self.peers[sock] = peer
|
||||||
|
|
||||||
debug2('DNS: sending to %r (try %d)\n' % (peer, self.tries))
|
debug2('DNS: sending to %r:%d (try %d)\n' % (peer, port, self.tries))
|
||||||
try:
|
try:
|
||||||
sock.send(self.request)
|
sock.send(self.request)
|
||||||
self.socks.append(sock)
|
self.socks.append(sock)
|
||||||
@ -261,7 +271,7 @@ class UdpProxy(Handler):
|
|||||||
self.mux.send(self.chan, ssnet.CMD_UDP_DATA, hdr + data)
|
self.mux.send(self.chan, ssnet.CMD_UDP_DATA, hdr + data)
|
||||||
|
|
||||||
|
|
||||||
def main(latency_control, auto_hosts):
|
def main(latency_control, auto_hosts, to_nameserver):
|
||||||
debug1('Starting server with Python version %s\n'
|
debug1('Starting server with Python version %s\n'
|
||||||
% platform.python_version())
|
% platform.python_version())
|
||||||
|
|
||||||
@ -335,7 +345,7 @@ def main(latency_control, auto_hosts):
|
|||||||
|
|
||||||
def dns_req(channel, data):
|
def dns_req(channel, data):
|
||||||
debug2('Incoming DNS request channel=%d.\n' % channel)
|
debug2('Incoming DNS request channel=%d.\n' % channel)
|
||||||
h = DnsProxy(mux, channel, data)
|
h = DnsProxy(mux, channel, data, to_nameserver)
|
||||||
handlers.append(h)
|
handlers.append(h)
|
||||||
dnshandlers[channel] = h
|
dnshandlers[channel] = h
|
||||||
mux.got_dns_req = dns_req
|
mux.got_dns_req = dns_req
|
||||||
|
Loading…
Reference in New Issue
Block a user