Skip to content

Commit 49c55f6

Browse files
committed
use -E/-X to enable/disable pf on yosemite
1 parent 1874aac commit 49c55f6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/firewall.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import ssyslog
88
import sys
99
import os
10+
import re
1011
from helpers import log, debug1, debug3, islocal, Fatal, family_to_string, \
1112
resolvconf_nameservers
1213
from fcntl import ioctl
@@ -469,7 +470,7 @@ def do_wait():
469470

470471
def pfctl(args, stdin = None):
471472
argv = ['pfctl'] + list(args.split(" "))
472-
debug1('>> %s, stdin:%s\n' % (' '.join(argv), stdin))
473+
debug1('>> %s' % ' '.join(argv), stdin)
473474

474475
p = ssubprocess.Popen(argv, stdin = ssubprocess.PIPE,
475476
stdout = ssubprocess.PIPE,
@@ -480,7 +481,7 @@ def pfctl(args, stdin = None):
480481

481482
return o
482483

483-
_pf_started_by_sshuttle = False
484+
_pf_context = {'started_by_sshuttle': False, 'Xtoken':''}
484485

485486
def do_pf(port, dnsport, family, subnets, udp):
486487
global _pf_started_by_sshuttle
@@ -513,16 +514,11 @@ def do_pf(port, dnsport, family, subnets, udp):
513514
pf_add_anchor_rule(PF_RDR, "sshuttle")
514515
if not '\nanchor "sshuttle" all\n' in pf_status:
515516
pf_add_anchor_rule(PF_PASS, "sshuttle")
516-
if not 'INFO:\nStatus: Enabled' in pf_status:
517-
pfctl('-e')
518-
_pf_started_by_sshuttle = True
519517

520-
pfctl('-a sshuttle -f /dev/stdin', rules)
518+
o = pfctl('-a sshuttle -f /dev/stdin -E', rules)
519+
_pf_context['Xtoken'] = re.search(r'Token : (.+)', o[1]).group(1)
521520
else:
522-
pfctl('-a sshuttle -F all')
523-
524-
if _pf_started_by_sshuttle:
525-
pfctl('-d')
521+
pfctl('-a sshuttle -F all -X %s' % _pf_context['Xtoken'])
526522

527523

528524
def program_exists(name):

0 commit comments

Comments
 (0)