mirror of
https://github.com/NeoCloud/NeoNetwork
synced 2024-11-22 10:00:42 +08:00
support max-len, closes #236
This commit is contained in:
parent
75835a3ae4
commit
77c65245b7
2 changed files with 9 additions and 3 deletions
|
@ -20,6 +20,9 @@ name = ""
|
||||||
# IP network description (optional).
|
# IP network description (optional).
|
||||||
description = ""
|
description = ""
|
||||||
|
|
||||||
|
# Max length (optional). Default values: 29 for ipv4, 64 for ipv6
|
||||||
|
max-len = 29
|
||||||
|
|
||||||
# The supernet of this IP network (optional). Overlapping IP prefixes are
|
# The supernet of this IP network (optional). Overlapping IP prefixes are
|
||||||
# regarded as an error, so if this IP network is a subnet of another one, write
|
# regarded as an error, so if this IP network is a subnet of another one, write
|
||||||
# their IP prefix here.
|
# their IP prefix here.
|
||||||
|
|
|
@ -122,6 +122,8 @@ def route_to_roa(asn_table: dict):
|
||||||
continue
|
continue
|
||||||
fields["asn"] = asn
|
fields["asn"] = asn
|
||||||
fields["prefix"] = ip_network(prefix, strict=True)
|
fields["prefix"] = ip_network(prefix, strict=True)
|
||||||
|
fields["maxLength"] = fields.get("max-len", fields["prefix"].max_prefixlen)
|
||||||
|
assert fields["prefix"].prefixlen <= fields["maxLength"] <= fields["prefix"].max_prefixlen
|
||||||
supernet = fields.get("supernet")
|
supernet = fields.get("supernet")
|
||||||
fields["supernet"] = (
|
fields["supernet"] = (
|
||||||
ip_network(supernet, strict=True) if supernet else None
|
ip_network(supernet, strict=True) if supernet else None
|
||||||
|
@ -132,7 +134,7 @@ def route_to_roa(asn_table: dict):
|
||||||
is_neo_network(fields["supernet"])
|
is_neo_network(fields["supernet"])
|
||||||
and fields["supernet"].supernet_of(fields["prefix"])
|
and fields["supernet"].supernet_of(fields["prefix"])
|
||||||
)
|
)
|
||||||
yield pick(fields, ["asn", "name", "type", "prefix", "supernet"])
|
yield pick(fields, ["asn", "name", "type", "prefix", "supernet", "maxLength"])
|
||||||
|
|
||||||
entities = sorted(make_route(), key=lambda item: item["asn"])
|
entities = sorted(make_route(), key=lambda item: item["asn"])
|
||||||
prefixes = [item["prefix"] for item in entities]
|
prefixes = [item["prefix"] for item in entities]
|
||||||
|
@ -177,11 +179,12 @@ def prehandle_roa(asn_table: dict, args):
|
||||||
]
|
]
|
||||||
roa6 = [r for r in roa6 if r["prefix"].prefixlen <= args.max6]
|
roa6 = [r for r in roa6 if r["prefix"].prefixlen <= args.max6]
|
||||||
for r in roa4:
|
for r in roa4:
|
||||||
r["maxLength"] = args.max
|
|
||||||
if r["prefix"].prefixlen == max_prefixlen:
|
if r["prefix"].prefixlen == max_prefixlen:
|
||||||
r["maxLength"] = max_prefixlen
|
r["maxLength"] = max_prefixlen
|
||||||
|
else:
|
||||||
|
r["maxLength"] = r["maxLength"] if r["maxLength"] <= args.max else args.max
|
||||||
for r in roa6:
|
for r in roa6:
|
||||||
r["maxLength"] = args.max6
|
r["maxLength"] = r["maxLength"] if r["maxLength"] <= args.max6 else args.max6
|
||||||
for r in (*roa4, *roa6):
|
for r in (*roa4, *roa6):
|
||||||
r["prefix"] = r["prefix"].with_prefixlen
|
r["prefix"] = r["prefix"].with_prefixlen
|
||||||
return roa4, roa6
|
return roa4, roa6
|
||||||
|
|
Loading…
Reference in a new issue