More changes to simplify the upcomming IPv6 patch.

This commit is contained in:
Brian May 2011-07-11 10:18:01 +10:00
parent c6200eecdc
commit 9a7412c08f
2 changed files with 25 additions and 21 deletions

View File

@ -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']

20
main.py
View File

@ -4,11 +4,8 @@ import compat.ssubprocess as ssubprocess
from helpers import * from helpers import *
# 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_subnet4(s):
subnets = []
for s in subnets_str:
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:
raise Fatal('%r is not a valid IP subnet format' % s) raise Fatal('%r is not a valid IP subnet format' % s)
@ -22,12 +19,21 @@ def parse_subnets(subnets_str):
raise Fatal('%d.%d.%d.%d has numbers > 255' % (a,b,c,d)) raise Fatal('%d.%d.%d.%d has numbers > 255' % (a,b,c,d))
if width > 32: if width > 32:
raise Fatal('*/%d is greater than the maximum of 32' % width) 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(socket.AF_INET, '%d.%d.%d.%d' % (a,b,c,d), width)
# list of:
# 1.2.3.4/5 or just 1.2.3.4
def parse_subnets(subnets_str):
subnets = []
for s in subnets_str:
subnet = parse_subnet4(s)
subnets.append(subnet)
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,