1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-23 06:00:40 +08:00

roa.py: needs py37

This commit is contained in:
JerryXiao 2020-05-13 21:09:30 +08:00
parent 09d9edcbb2
commit b820deb165
Signed by: Jerry
GPG key ID: 9D9CE43650FF2BAA

View file

@ -9,9 +9,7 @@ import re
NEONET_ADDR_POOL = ('10.127.0.0/16', 'fd10:127::/32') NEONET_ADDR_POOL = ('10.127.0.0/16', 'fd10:127::/32')
NEONET_ADDR_POOL = [ip_network(neo) for neo in NEONET_ADDR_POOL] NEONET_ADDR_POOL = [ip_network(neo) for neo in NEONET_ADDR_POOL]
IS_NEONET = lambda net: bool([True for neo in NEONET_ADDR_POOL if net.version == neo.version and net.subnet_of(neo)]) IS_NEONET = lambda net: bool([True for neo in NEONET_ADDR_POOL if net.version == neo.version and net.subnet_of(neo)])
if not hasattr(IPv4Network, 'subnet_of'): assert hasattr(IPv4Network, 'subnet_of') # needs at least python 3.7
IS_NEONET = lambda x: True
print('# [!] IPv4Network has no attr subnet_of, please consider upgrading your python installation')
class BashParser: class BashParser:
def __init__(self): def __init__(self):
@ -171,16 +169,22 @@ def neonet_route2roa(dirname, is_ipv6=False):
print("[!] Error while processing file", f) print("[!] Error while processing file", f)
raise raise
roa_entries.sort(key=lambda l: l['asn']) roa_entries.sort(key=lambda l: l['asn'])
l_prefix = [_roa['prefix'] for _roa in roa_entries]
for _net1, _net2 in combinations(roa_entries, 2): for _net1, _net2 in combinations(roa_entries, 2):
net1, net2 = sorted([_net1, _net2], key=lambda net: net['prefix'].prefixlen) net1, net2 = sorted([_net1, _net2], key=lambda net: net['prefix'].prefixlen)
if net1['prefix'].overlaps(net2['prefix']): if net1['prefix'].overlaps(net2['prefix']):
if net1['prefix'] != net2['prefix'] and net1['prefix'].supernet_of(net2['prefix']) \ try:
and net2['supernet'] == net1['prefix']: assert net1['prefix'] != net2['prefix']
# This is allowed assert net1['prefix'].supernet_of(net2['prefix'])
pass s1net, s2net= (net1['supernet'], net2['supernet'])
else: assert s2net # please include SUPERNET=<cidr> in your route
print("[!] Error: found", net2, "overlaps", net1) # if net1(the bigger net) has a supernet s1net, then s1net and net1
raise AssertionError # if this is intended, please include SUPERNET=<cidr> in your route # will be checked or must have been checked, same for net2
assert not s1net or s1net in l_prefix # net1.supernet is garbage
assert s2net == net1['prefix'] or s2net in l_prefix # net2.supernet is garbage
except AssertionError:
print("[!] Error: found", net1, "overlaps", net2)
raise
return roa_entries return roa_entries
if __name__ == "__main__": if __name__ == "__main__":