77import ssyslog
88import sys
99import os
10+ import re
1011from helpers import log , debug1 , debug3 , islocal , Fatal , family_to_string , \
1112 resolvconf_nameservers
1213from fcntl import ioctl
@@ -469,7 +470,7 @@ def do_wait():
469470
470471def 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
485486def 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 '\n anchor "sshuttle" all\n ' in pf_status :
515516 pf_add_anchor_rule (PF_PASS , "sshuttle" )
516- if not 'INFO:\n Status: 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
528524def program_exists (name ):
0 commit comments