Skip to content

Commit e63e121

Browse files
committed
Print PF rules used.
Also support multiline debug output better.
1 parent 2b23533 commit e63e121

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

sshuttle/helpers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77

88

99
def log(s):
10+
global logprefix
1011
try:
1112
sys.stdout.flush()
12-
sys.stderr.write(logprefix + s)
13+
if s.find("\n") != -1:
14+
prefix = logprefix
15+
s = s.rstrip("\n")
16+
for line in s.split("\n"):
17+
sys.stderr.write(prefix + line + "\n")
18+
prefix = "---> "
19+
else:
20+
sys.stderr.write(logprefix + s)
1321
sys.stderr.flush()
1422
except IOError:
1523
# this could happen if stderr gets forcibly disconnected, eg. because

sshuttle/methods/pf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from fcntl import ioctl
88
from ctypes import c_char, c_uint8, c_uint16, c_uint32, Union, Structure, \
99
sizeof, addressof, memmove
10-
from sshuttle.helpers import debug1, debug2, Fatal, family_to_string
10+
from sshuttle.helpers import debug1, debug2, debug3, Fatal, family_to_string
1111
from sshuttle.methods import BaseMethod
1212

1313

@@ -215,6 +215,7 @@ def setup_firewall(self, port, dnsport, nslist, family, subnets, udp):
215215
rules = b'\n'.join(tables + translating_rules + filtering_rules) \
216216
+ b'\n'
217217
assert isinstance(rules, bytes)
218+
debug3("rules:\n" + rules.decode("ASCII"))
218219

219220
pf_status = pfctl('-s all')[0]
220221
if b'\nrdr-anchor "sshuttle" all\n' not in pf_status:

sshuttle/tests/test_helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,28 @@
1111
@patch('sshuttle.helpers.sys.stderr')
1212
def test_log(mock_stderr, mock_stdout):
1313
sshuttle.helpers.log("message")
14+
sshuttle.helpers.log("message 1\n")
15+
sshuttle.helpers.log("message 2\nline2\nline3\n")
16+
sshuttle.helpers.log("message 3\nline2\nline3")
1417
assert mock_stdout.mock_calls == [
1518
call.flush(),
19+
call.flush(),
20+
call.flush(),
21+
call.flush(),
1622
]
1723
assert mock_stderr.mock_calls == [
1824
call.write('prefix: message'),
1925
call.flush(),
26+
call.write('prefix: message 1\n'),
27+
call.flush(),
28+
call.write('prefix: message 2\n'),
29+
call.write('---> line2\n'),
30+
call.write('---> line3\n'),
31+
call.flush(),
32+
call.write('prefix: message 3\n'),
33+
call.write('---> line2\n'),
34+
call.write('---> line3\n'),
35+
call.flush(),
2036
]
2137

2238

sshuttle/tests/test_methods_pf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def pfctl(args, stdin=None):
104104
return None
105105

106106

107+
@patch('sshuttle.helpers.verbose', new=3)
107108
@patch('sshuttle.methods.pf.sys.platform', 'darwin')
108109
@patch('sshuttle.methods.pf.pfctl')
109110
@patch('sshuttle.methods.pf.ioctl')

0 commit comments

Comments
 (0)