Skip to content

Commit 3e2ad68

Browse files
danjefferybrianmay
authored andcommitted
Fix tests for existing PR-312 (sshuttle#337)
* use addrtype match to return the LOCAL trafik * Add assertion for the new LOCAL firewall rule added in PR 312. * Fix linter complaints
1 parent 635cf86 commit 3e2ad68

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

sshuttle/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,13 @@ def main(listenip_v6, listenip_v4,
602602
except KeyError:
603603
raise Fatal("User %s does not exist." % user)
604604

605-
required.ipv6 = len(subnets_v6) > 0 or listenip_v6 is not None
606-
required.ipv4 = len(subnets_v4) > 0 or listenip_v4 is not None
605+
if fw.method.name != 'nat':
606+
required.ipv6 = len(subnets_v6) > 0 or listenip_v6 is not None
607+
required.ipv4 = len(subnets_v4) > 0 or listenip_v4 is not None
608+
else:
609+
required.ipv6 = None
610+
required.ipv4 = None
611+
607612
required.udp = avail.udp
608613
required.dns = len(nslist) > 0
609614
required.user = False if user is None else True

sshuttle/methods/nat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def _ipm(*args):
5050
_ipt('-I', 'OUTPUT', '1', *args)
5151
_ipt('-I', 'PREROUTING', '1', *args)
5252

53+
# Firstly we always skip all LOCAL addtrype address, i.e. avoid
54+
# tunnelling the traffic designated to all local TCP/IP addresses.
55+
_ipt('-A', chain, '-j', 'RETURN',
56+
'-m', 'addrtype',
57+
'--dst-type', 'LOCAL')
58+
5359
# create new subnet entries.
5460
for _, swidth, sexclude, snet, fport, lport \
5561
in sorted(subnets, key=subnet_weight, reverse=True):

tests/client/test_methods_nat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def test_setup_firewall(mock_ipt_chain_exists, mock_ipt_ttl, mock_ipt):
139139
call(AF_INET, 'nat', '-F', 'sshuttle-1025'),
140140
call(AF_INET, 'nat', '-I', 'OUTPUT', '1', '-j', 'sshuttle-1025'),
141141
call(AF_INET, 'nat', '-I', 'PREROUTING', '1', '-j', 'sshuttle-1025'),
142+
call(AF_INET, 'nat', '-A', 'sshuttle-1025', '-j', 'RETURN',
143+
'-m', 'addrtype', '--dst-type', 'LOCAL'),
142144
call(AF_INET, 'nat', '-A', 'sshuttle-1025', '-j', 'RETURN',
143145
'--dest', u'1.2.3.66/32', '-p', 'tcp', '--dport', '8080:8080')
144146
]

0 commit comments

Comments
 (0)