Seed hosts without auto hosts

A possible implementation for the change requested in #94, so that seed
hosts can be used without auto hosts. In this scenario only the
specified hosts (or ips) will be looked up (or rev looked up).
This commit is contained in:
vieira 2016-05-03 00:18:32 +00:00
parent f3cbc5018a
commit 495b3c39ea
5 changed files with 22 additions and 20 deletions

View File

@ -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) main(options.latency_control, options.auto_hosts)

View File

@ -400,7 +400,7 @@ 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_nets, daemon): dns_listener, seed_hosts, auto_hosts, auto_nets, daemon):
debug1('Starting client with Python version %s\n' debug1('Starting client with Python version %s\n'
% platform.python_version()) % platform.python_version())
@ -418,7 +418,8 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
(serverproc, serversock) = ssh.connect( (serverproc, serversock) = ssh.connect(
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))
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)")
@ -514,7 +515,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_nets, method_name, seed_hosts, auto_hosts, auto_nets,
subnets_include, subnets_exclude, daemon, pidfile): subnets_include, subnets_exclude, daemon, pidfile):
if daemon: if daemon:
@ -713,7 +714,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_nets, daemon) seed_hosts, auto_hosts, auto_nets, daemon)
finally: finally:
try: try:
if daemon: if daemon:

View File

@ -35,8 +35,6 @@ def main():
if remotename == '' or remotename == '-': if remotename == '' or remotename == '-':
remotename = None remotename = None
nslist = [family_ip_tuple(ns) for ns in opt.ns_hosts] nslist = [family_ip_tuple(ns) for ns in opt.ns_hosts]
if opt.seed_hosts and not opt.auto_hosts:
parser.error('--seed-hosts only works if you also use -H')
if opt.seed_hosts: if opt.seed_hosts:
sh = re.split(r'[\s,]+', (opt.seed_hosts or "").strip()) sh = re.split(r'[\s,]+', (opt.seed_hosts or "").strip())
elif opt.auto_hosts: elif opt.auto_hosts:
@ -69,6 +67,7 @@ def main():
nslist, nslist,
opt.method, opt.method,
sh, sh,
opt.auto_hosts,
opt.auto_nets, opt.auto_nets,
includes, includes,
excludes, excludes,

View File

@ -255,7 +255,7 @@ def _stdin_still_ok(timeout):
return True return True
def hw_main(seed_hosts): def hw_main(seed_hosts, auto_hosts):
if helpers.verbose >= 2: if helpers.verbose >= 2:
helpers.logprefix = 'HH: ' helpers.logprefix = 'HH: '
else: else:
@ -264,17 +264,18 @@ def hw_main(seed_hosts):
debug1('Starting hostwatch with Python version %s\n' debug1('Starting hostwatch with Python version %s\n'
% platform.python_version()) % platform.python_version())
read_host_cache()
_enqueue(_check_etc_hosts)
_enqueue(_check_netstat)
check_host('localhost')
check_host(socket.gethostname())
check_workgroup('workgroup')
check_workgroup('-')
for h in seed_hosts: for h in seed_hosts:
check_host(h) check_host(h)
if auto_hosts:
read_host_cache()
_enqueue(_check_etc_hosts)
_enqueue(_check_netstat)
check_host('localhost')
check_host(socket.gethostname())
check_workgroup('workgroup')
check_workgroup('-')
while 1: while 1:
now = time.time() now = time.time()
for t, last_polled in list(queue.items()): for t, last_polled in list(queue.items()):

View File

@ -98,7 +98,7 @@ def _exc_dump():
return ''.join(traceback.format_exception(*exc_info)) return ''.join(traceback.format_exception(*exc_info))
def start_hostwatch(seed_hosts): def start_hostwatch(seed_hosts, auto_hosts):
s1, s2 = socket.socketpair() s1, s2 = socket.socketpair()
pid = os.fork() pid = os.fork()
if not pid: if not pid:
@ -110,7 +110,7 @@ def start_hostwatch(seed_hosts):
os.dup2(s1.fileno(), 1) os.dup2(s1.fileno(), 1)
os.dup2(s1.fileno(), 0) os.dup2(s1.fileno(), 0)
s1.close() s1.close()
rv = hostwatch.hw_main(seed_hosts) or 0 rv = hostwatch.hw_main(seed_hosts, auto_hosts) or 0
except Exception: except Exception:
log('%s\n' % _exc_dump()) log('%s\n' % _exc_dump())
rv = 98 rv = 98
@ -227,7 +227,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): def main(latency_control, auto_hosts):
debug1('Starting server with Python version %s\n' debug1('Starting server with Python version %s\n'
% platform.python_version()) % platform.python_version())
@ -277,7 +277,8 @@ def main(latency_control):
def got_host_req(data): def got_host_req(data):
if not hw.pid: if not hw.pid:
(hw.pid, hw.sock) = start_hostwatch(data.strip().split()) (hw.pid, hw.sock) = start_hostwatch(
data.strip().split(), auto_hosts)
handlers.append(Handler(socks=[hw.sock], handlers.append(Handler(socks=[hw.sock],
callback=hostwatch_ready)) callback=hostwatch_ready))
mux.got_host_req = got_host_req mux.got_host_req = got_host_req