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

support max-len, closes #236

This commit is contained in:
JerryXiao 2022-11-10 15:47:25 +08:00
parent 75835a3ae4
commit 77c65245b7
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
2 changed files with 9 additions and 3 deletions

View file

@ -20,6 +20,9 @@ name = ""
# IP network description (optional).
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
# regarded as an error, so if this IP network is a subnet of another one, write
# their IP prefix here.

View file

@ -122,6 +122,8 @@ def route_to_roa(asn_table: dict):
continue
fields["asn"] = asn
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")
fields["supernet"] = (
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"])
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"])
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]
for r in roa4:
r["maxLength"] = args.max
if r["prefix"].prefixlen == max_prefixlen:
r["maxLength"] = max_prefixlen
else:
r["maxLength"] = r["maxLength"] if r["maxLength"] <= args.max else args.max
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):
r["prefix"] = r["prefix"].with_prefixlen
return roa4, roa6