Commit 50275cc2 authored by Jondy Zhao's avatar Jondy Zhao

move _iterRoutes to utils.py

enable default route check
parent ab7049d3
......@@ -311,34 +311,6 @@ class TunnelManager(object):
if self._makeTunnel(*peer):
break
if sys.platform == 'cygwin':
def _iterRoutes(self):
# Before Vista
if platform.system()[10:11] == '5':
args = ('netsh', 'interface', 'ipv6', 'show', 'route', 'verbose')
else:
args = ('ipwin', 'ipv6', 'show', 'route', 'verbose')
routing_table = subprocess.check_output(args, stderr=subprocess.STDOUT)
for line in routing_table.splitlines():
fs = line.split(':', 1)
test = fs[0].startswith
if test('Prefix'):
prefix, prefix_len = fs[1].split('/', 1)
elif test('Interface'):
yield (fs[1].strip(),
utils.binFromIp(prefix.strip()),
int(prefix_len))
else:
def _iterRoutes(self):
with open('/proc/net/ipv6_route') as f:
routing_table = f.read()
for line in routing_table.splitlines():
line = line.split()
iface = line[-1]
if iface != 'lo' and not (int(line[-2], 16) & RTF_CACHE):
yield (iface, bin(int(line[0], 16))[2:].rjust(128, '0'),
int(line[1], 16))
def _countRoutes(self):
logging.debug('Starting to count the routes on each interface...')
del self._distant_peers[:]
......
......@@ -155,6 +155,50 @@ def binFromSubnet(subnet):
p, l = subnet.split('/')
return bin(int(p))[2:].rjust(int(l), '0')
if sys.platform == 'cygwin':
def _iterRoutes(self):
# Before Vista
if platform.system()[10:11] == '5':
args = ('netsh', 'interface', 'ipv6', 'show', 'route', 'verbose')
else:
args = ('ipwin', 'ipv6', 'show', 'route', 'verbose')
routing_table = subprocess.check_output(args, stderr=subprocess.STDOUT)
for line in routing_table.splitlines():
fs = line.split(':', 1)
test = fs[0].startswith
if test('Prefix'):
prefix, prefix_len = fs[1].split('/', 1)
elif test('Interface'):
yield (fs[1].strip(),
utils.binFromIp(prefix.strip()),
int(prefix_len))
else:
def _iterRoutes():
with open('/proc/net/ipv6_route') as f:
routing_table = f.read()
for line in routing_table.splitlines():
line = line.split()
iface = line[-1]
if 0 < int(line[5], 16) < 1 << 31: # positive metric
yield (iface, bin(int(line[0], 16))[2:].rjust(128, '0'),
int(line[1], 16))
_iterRoutes.__doc__ = """Iterates over all routes
Amongst all returned routes starting with re6st prefix:
- one is the local one with our prefix
- any route with null prefix will be ignored
- other are reachable routes installed by babeld
"""
def iterRoutes(network, exclude_prefix=None):
a = len(network)
for iface, ip, prefix_len in _iterRoutes():
if ip[:a] == network:
prefix = ip[a:prefix_len]
if prefix and prefix != exclude_prefix:
yield iface, prefix
def decrypt(key_path, data):
p = subprocess.Popen(
('openssl', 'rsautl', '-decrypt', '-inkey', key_path),
......
......@@ -361,7 +361,7 @@ def main():
exit(1)
t = threading.Thread(target=check_no_default_route)
t.daemon = True
# t.start()
t.start()
if not sys.platform == 'cygwin':
ip('route', 'unreachable', *x)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment