mirror of
https://github.com/NeoCloud/NeoNetwork
synced 2024-12-26 10:59:24 +08:00
strict asn checking
This commit is contained in:
parent
ddfa48a9d1
commit
3766d1a350
1 changed files with 10 additions and 6 deletions
|
@ -54,13 +54,17 @@ def shell2dict(shellscript):
|
||||||
cwd = Path()
|
cwd = Path()
|
||||||
assert not [d for d in ("asn", "route", "route6", "node", "entity") if not (cwd / d).is_dir()]
|
assert not [d for d in ("asn", "route", "route6", "node", "entity") if not (cwd / d).is_dir()]
|
||||||
|
|
||||||
def str2asn(s_asn):
|
def str2asn(s_asn, strict=None):
|
||||||
|
""" strict: 1 with prefix AS, other bool(x)==True without prefix AS """
|
||||||
s_asn = s_asn.strip().lower()
|
s_asn = s_asn.strip().lower()
|
||||||
|
if strict == 1:
|
||||||
|
assert s_asn.startswith('as')
|
||||||
|
elif strict:
|
||||||
|
assert int(s_asn)
|
||||||
if s_asn.startswith('as'):
|
if s_asn.startswith('as'):
|
||||||
s_asn = s_asn[2:]
|
s_asn = s_asn[2:]
|
||||||
return int(s_asn)
|
return int(s_asn)
|
||||||
|
|
||||||
|
|
||||||
def name2nichdl(name):
|
def name2nichdl(name):
|
||||||
r, num = re.subn(r'[^0-9A-Z]', '-', name.upper())
|
r, num = re.subn(r'[^0-9A-Z]', '-', name.upper())
|
||||||
_r = len(r.replace('-', ''))
|
_r = len(r.replace('-', ''))
|
||||||
|
@ -109,9 +113,9 @@ def neonet_get_asns():
|
||||||
continue
|
continue
|
||||||
fc = shell2dict(f.read_text())
|
fc = shell2dict(f.read_text())
|
||||||
present_keys = ('name', 'owner', 'desc')
|
present_keys = ('name', 'owner', 'desc')
|
||||||
asns[str2asn(f.name)] = {k: fc.get(k) for k in present_keys}
|
asns[str2asn(f.name, 1)] = {k: fc.get(k) for k in present_keys}
|
||||||
assert fc.get('owner') in PEOPLE
|
assert fc.get('owner') in PEOPLE
|
||||||
for v in asns[str2asn(f.name)].values():
|
for v in asns[str2asn(f.name, 1)].values():
|
||||||
assert v is not None
|
assert v is not None
|
||||||
except Exception:
|
except Exception:
|
||||||
print("[!] Error while processing file", f)
|
print("[!] Error while processing file", f)
|
||||||
|
@ -126,7 +130,7 @@ def node2asn():
|
||||||
if not f.is_file():
|
if not f.is_file():
|
||||||
continue
|
continue
|
||||||
fc = shell2dict(f.read_text())
|
fc = shell2dict(f.read_text())
|
||||||
asn = str2asn(fc.get('asn'))
|
asn = str2asn(fc.get('asn'), 2)
|
||||||
assert asn in ASNS
|
assert asn in ASNS
|
||||||
node_table[f.name] = asn
|
node_table[f.name] = asn
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -162,7 +166,7 @@ def neonet_route2roa(dirname, is_ipv6=False):
|
||||||
get_supernet = lambda s_net: None if not s_net else nettype(s_net, strict=True)
|
get_supernet = lambda s_net: None if not s_net else nettype(s_net, strict=True)
|
||||||
roa_entries_key = ("asn", "prefix", "supernet", "netname")
|
roa_entries_key = ("asn", "prefix", "supernet", "netname")
|
||||||
if fc.get('type').lower() in ('lo', 'subnet'):
|
if fc.get('type').lower() in ('lo', 'subnet'):
|
||||||
asn = str2asn(fc.get('asn'))
|
asn = str2asn(fc.get('asn'), 2)
|
||||||
assert asn in ASNS # asn not in as-dir
|
assert asn in ASNS # asn not in as-dir
|
||||||
route = f.name.replace(',', '/')
|
route = f.name.replace(',', '/')
|
||||||
net = nettype(route, strict=True)
|
net = nettype(route, strict=True)
|
||||||
|
|
Loading…
Reference in a new issue