mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-02-14 17:39:13 +01:00
More changes to simplify the upcomming IPv6 patch.
This commit is contained in:
parent
c6200eecdc
commit
9a7412c08f
@ -125,16 +125,14 @@ class MultiListener:
|
|||||||
|
|
||||||
|
|
||||||
class FirewallClient:
|
class FirewallClient:
|
||||||
def __init__(self, port, subnets_include, subnets_exclude, dnsport, method):
|
def __init__(self, port_v4, subnets_include, subnets_exclude, dnsport_v4, method):
|
||||||
self.port = port
|
|
||||||
self.auto_nets = []
|
self.auto_nets = []
|
||||||
self.subnets_include = subnets_include
|
self.subnets_include = subnets_include
|
||||||
self.subnets_exclude = subnets_exclude
|
self.subnets_exclude = subnets_exclude
|
||||||
self.dnsport = dnsport
|
|
||||||
argvbase = ([sys.argv[1], sys.argv[0], sys.argv[1]] +
|
argvbase = ([sys.argv[1], sys.argv[0], sys.argv[1]] +
|
||||||
['-v'] * (helpers.verbose or 0) +
|
['-v'] * (helpers.verbose or 0) +
|
||||||
['--firewall', str(port),
|
['--firewall', str(port_v4),
|
||||||
str(dnsport),
|
str(dnsport_v4),
|
||||||
method])
|
method])
|
||||||
if ssyslog._p:
|
if ssyslog._p:
|
||||||
argvbase += ['--syslog']
|
argvbase += ['--syslog']
|
||||||
|
38
main.py
38
main.py
@ -4,30 +4,36 @@ import compat.ssubprocess as ssubprocess
|
|||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
|
|
||||||
|
# 1.2.3.4/5 or just 1.2.3.4
|
||||||
|
def parse_subnet4(s):
|
||||||
|
m = re.match(r'(\d+)(?:\.(\d+)\.(\d+)\.(\d+))?(?:/(\d+))?$', s)
|
||||||
|
if not m:
|
||||||
|
raise Fatal('%r is not a valid IP subnet format' % s)
|
||||||
|
(a,b,c,d,width) = m.groups()
|
||||||
|
(a,b,c,d) = (int(a or 0), int(b or 0), int(c or 0), int(d or 0))
|
||||||
|
if width == None:
|
||||||
|
width = 32
|
||||||
|
else:
|
||||||
|
width = int(width)
|
||||||
|
if a > 255 or b > 255 or c > 255 or d > 255:
|
||||||
|
raise Fatal('%d.%d.%d.%d has numbers > 255' % (a,b,c,d))
|
||||||
|
if width > 32:
|
||||||
|
raise Fatal('*/%d is greater than the maximum of 32' % width)
|
||||||
|
return(socket.AF_INET, '%d.%d.%d.%d' % (a,b,c,d), width)
|
||||||
|
|
||||||
|
|
||||||
# list of:
|
# list of:
|
||||||
# 1.2.3.4/5 or just 1.2.3.4
|
# 1.2.3.4/5 or just 1.2.3.4
|
||||||
def parse_subnets(subnets_str):
|
def parse_subnets(subnets_str):
|
||||||
subnets = []
|
subnets = []
|
||||||
for s in subnets_str:
|
for s in subnets_str:
|
||||||
m = re.match(r'(\d+)(?:\.(\d+)\.(\d+)\.(\d+))?(?:/(\d+))?$', s)
|
subnet = parse_subnet4(s)
|
||||||
if not m:
|
subnets.append(subnet)
|
||||||
raise Fatal('%r is not a valid IP subnet format' % s)
|
|
||||||
(a,b,c,d,width) = m.groups()
|
|
||||||
(a,b,c,d) = (int(a or 0), int(b or 0), int(c or 0), int(d or 0))
|
|
||||||
if width == None:
|
|
||||||
width = 32
|
|
||||||
else:
|
|
||||||
width = int(width)
|
|
||||||
if a > 255 or b > 255 or c > 255 or d > 255:
|
|
||||||
raise Fatal('%d.%d.%d.%d has numbers > 255' % (a,b,c,d))
|
|
||||||
if width > 32:
|
|
||||||
raise Fatal('*/%d is greater than the maximum of 32' % width)
|
|
||||||
subnets.append((socket.AF_INET, '%d.%d.%d.%d' % (a,b,c,d), width))
|
|
||||||
return subnets
|
return subnets
|
||||||
|
|
||||||
|
|
||||||
# 1.2.3.4:567 or just 1.2.3.4 or just 567
|
# 1.2.3.4:567 or just 1.2.3.4 or just 567
|
||||||
def parse_ipport(s):
|
def parse_ipport4(s):
|
||||||
s = str(s)
|
s = str(s)
|
||||||
m = re.match(r'(?:(\d+)\.(\d+)\.(\d+)\.(\d+))?(?::)?(?:(\d+))?$', s)
|
m = re.match(r'(?:(\d+)\.(\d+)\.(\d+)\.(\d+))?(?::)?(?:(\d+))?$', s)
|
||||||
if not m:
|
if not m:
|
||||||
@ -118,7 +124,7 @@ try:
|
|||||||
method = opt.method
|
method = opt.method
|
||||||
else:
|
else:
|
||||||
o.fatal("method %s not supported"%opt.method)
|
o.fatal("method %s not supported"%opt.method)
|
||||||
ipport_v4 = parse_ipport(opt.listen or '0.0.0.0:0')
|
ipport_v4 = parse_ipport4(opt.listen or '0.0.0.0:0')
|
||||||
sys.exit(client.main(ipport_v4,
|
sys.exit(client.main(ipport_v4,
|
||||||
opt.ssh_cmd,
|
opt.ssh_cmd,
|
||||||
remotename,
|
remotename,
|
||||||
|
Loading…
Reference in New Issue
Block a user