7
7
import ssyslog
8
8
import sys
9
9
import os
10
+ import re
10
11
from helpers import log , debug1 , debug3 , islocal , Fatal , family_to_string , \
11
12
resolvconf_nameservers
12
13
from fcntl import ioctl
@@ -469,7 +470,7 @@ def do_wait():
469
470
470
471
def pfctl (args , stdin = None ):
471
472
argv = ['pfctl' ] + list (args .split (" " ))
472
- debug1 ('>> %s, stdin:%s \n ' % ( ' ' .join (argv ), stdin ) )
473
+ debug1 ('>> %s' % ' ' .join (argv ), stdin )
473
474
474
475
p = ssubprocess .Popen (argv , stdin = ssubprocess .PIPE ,
475
476
stdout = ssubprocess .PIPE ,
@@ -480,7 +481,7 @@ def pfctl(args, stdin = None):
480
481
481
482
return o
482
483
483
- _pf_started_by_sshuttle = False
484
+ _pf_context = { 'started_by_sshuttle' : False , 'Xtoken' : '' }
484
485
485
486
def do_pf (port , dnsport , family , subnets , udp ):
486
487
global _pf_started_by_sshuttle
@@ -513,16 +514,11 @@ def do_pf(port, dnsport, family, subnets, udp):
513
514
pf_add_anchor_rule (PF_RDR , "sshuttle" )
514
515
if not '\n anchor "sshuttle" all\n ' in pf_status :
515
516
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
519
517
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 )
521
520
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' ])
526
522
527
523
528
524
def program_exists (name ):
0 commit comments