@@ -70,9 +70,13 @@ def ipt_ttl(*args):
7070# multiple copies shouldn't have overlapping subnets, or only the most-
7171# recently-started one will win (because we use "-I OUTPUT 1" instead of
7272# "-A OUTPUT").
73- def do_iptables (port , dnsport , route_username , subnets ):
73+ def do_iptables (port , dnsport , route_username , excludedports , subnets ):
7474 chain = 'sshuttle-%s' % port
7575
76+ eportsargv = []
77+ if excludedports :
78+ eportsargv += ['--match' , 'multiport' , '!' , '--dport' , excludedports ]
79+
7680 # basic cleanup/setup of chains
7781 if ipt_chain_exists (chain ):
7882 if not route_username :
@@ -107,8 +111,9 @@ def do_iptables(port, dnsport, route_username, subnets):
107111 ipt_ttl ('-A' , chain , '-j' , 'REDIRECT' ,
108112 '--dest' , '%s/%s' % (snet ,swidth ),
109113 '-p' , 'tcp' ,
110- '--to-ports' , str (port ))
111-
114+ '--to-ports' , str (port ),
115+ * eportsargv )
116+
112117 if dnsport :
113118 nslist = resolvconf_nameservers ()
114119 for ip in nslist :
@@ -261,7 +266,7 @@ def ipfw(*args):
261266 _call (argv )
262267
263268
264- def do_ipfw (port , dnsport , route_username , subnets ):
269+ def do_ipfw (port , dnsport , route_username , excludedports , subnets ):
265270 sport = str (port )
266271 xsport = str (port + 1 )
267272
@@ -457,7 +462,7 @@ def ip_in_subnets(ip, subnets):
457462# exit. In case that fails, it's not the end of the world; future runs will
458463# supercede it in the transproxy list, at least, so the leftover rules
459464# are hopefully harmless.
460- def main (port , dnsport , syslog , route_username ):
465+ def main (port , dnsport , syslog , route_username , excludedports ):
461466 assert (port > 0 )
462467 assert (port <= 65535 )
463468 assert (dnsport >= 0 )
@@ -522,7 +527,7 @@ def main(port, dnsport, syslog, route_username):
522527 try :
523528 if line :
524529 debug1 ('firewall manager: starting transproxy.\n ' )
525- do_wait = do_it (port , dnsport , route_username , subnets )
530+ do_wait = do_it (port , dnsport , route_username , excludedports , subnets )
526531 sys .stdout .write ('STARTED\n ' )
527532
528533 try :
@@ -552,5 +557,5 @@ def main(port, dnsport, syslog, route_username):
552557 debug1 ('firewall manager: undoing changes.\n ' )
553558 except :
554559 pass
555- do_it (port , 0 , route_username , [])
560+ do_it (port , 0 , route_username , excludedports , [])
556561 restore_etc_hosts (port )
0 commit comments