From b741193ed4f2ba2a0e7dd9f24f2bb0ee195e43b2 Mon Sep 17 00:00:00 2001 From: Teun Vink Date: Wed, 17 Jul 2024 21:34:04 +0200 Subject: [PATCH] fix extended community display --- nlnog_lg.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/nlnog_lg.py b/nlnog_lg.py index 6fdc3f2..4ef99c4 100755 --- a/nlnog_lg.py +++ b/nlnog_lg.py @@ -116,6 +116,28 @@ def get_community_type(community: str) -> str: return "unknown" +def fix_extended_community(community: str) -> str: + """ rewrite the extended community from the format openbgpd uses to the rfc format + see IANA_EXT_COMMUNITIES in bgpd.h source of openbgpd source code + """ + + replacemap = { + "rt": "0x02:0x02", + "soo": "0x02:0x03", + "odi": "0x02:0x05", + "bdc": "0x02:0x08", + "srcas": "0x02:0x09", + "l2vid": "0x02:0x0a", + } + + if " " not in community: + return community + csplit = community.split(" ") + if csplit[0] in replacemap: + return f"{replacemap[csplit[0]]}:{csplit[1]}" + return community + + def read_communities() -> dict: """ Read the list of community definitions from communities/*.txt and translate them into a dictionary containing community lists for exact matches, ranges and regexps. @@ -206,9 +228,14 @@ def get_community_descr_from_list(community: str) -> str: """ community = community.strip() - asn = f"as{community.split(':')[0]}" ctype = get_community_type(community) + if ctype == "extended": + asn = "as" + community.split(" ")[1].split(":")[0] + community = fix_extended_community(community) + else: + asn = f"as{community.split(':')[0]}" + if ctype == "unknown": print(f"Unknown community requested: {community}") return "" @@ -908,6 +935,7 @@ def robots(): """ return send_from_directory(app.static_folder, "robots.txt") + data = Datastore() data.communitylist = read_communities()