Skip to content

Commit ac72369

Browse files
committed
Restructure code
Pull out firewall methods code into seperate files. Fix problems starting with method=='auto'; we were making decisions based on the method, before the method had been finalized by the firewall. Only very basic testing so far. What could go wrong?
1 parent bcd3205 commit ac72369

File tree

9 files changed

+1138
-972
lines changed

9 files changed

+1138
-972
lines changed

sshuttle/__main__.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,10 @@ def parse_list(list):
149149

150150
try:
151151
if opt.firewall:
152-
if len(extra) != 6:
153-
o.fatal('exactly six arguments expected')
154-
port, dnsport = int(extra[0]), int(extra[1])
155-
nslist = [family_ip_tuple(ns) for ns in parse_list(opt.ns_hosts)]
156-
sys.exit(firewall.main(int(extra[0]), int(extra[1]),
157-
int(extra[2]), int(extra[3]), nslist,
158-
extra[4], int(extra[5]), opt.syslog))
152+
if len(extra) != 0:
153+
o.fatal('exactly zero arguments expected')
154+
result = firewall.main(opt.method, opt.syslog)
155+
sys.exit(result)
159156
elif opt.hostwatch:
160157
sys.exit(hostwatch.hw_main(extra))
161158
else:
@@ -183,23 +180,20 @@ def parse_list(list):
183180
if opt.subnets:
184181
includes = parse_subnet_file(opt.subnets)
185182
if not opt.method:
186-
method = "auto"
183+
method_name = "auto"
187184
elif opt.method in ["auto", "nat", "tproxy", "ipfw", "pf"]:
188-
method = opt.method
185+
method_name = opt.method
189186
else:
190-
o.fatal("method %s not supported" % opt.method)
187+
o.fatal("method_name %s not supported" % opt.method)
191188
if not opt.listen:
192-
if opt.method == "tproxy":
193-
ipport_v6 = parse_ipport6('[::1]:0')
194-
else:
195-
ipport_v6 = None
196-
ipport_v4 = parse_ipport4('127.0.0.1:0')
189+
ipport_v6 = "auto" # parse_ipport6('[::1]:0')
190+
ipport_v4 = "auto" # parse_ipport4('127.0.0.1:0')
197191
else:
198192
ipport_v6 = None
199193
ipport_v4 = None
200194
list = opt.listen.split(",")
201195
for ip in list:
202-
if '[' in ip and ']' in ip and opt.method == "tproxy":
196+
if '[' in ip and ']' in ip:
203197
ipport_v6 = parse_ipport6(ip)
204198
else:
205199
ipport_v4 = parse_ipport4(ip)
@@ -210,7 +204,7 @@ def parse_list(list):
210204
opt.latency_control,
211205
opt.dns,
212206
nslist,
213-
method,
207+
method_name,
214208
sh,
215209
opt.auto_nets,
216210
parse_subnets(includes),

0 commit comments

Comments
 (0)