Skip to content

Commit

Permalink
fix extended community display
Browse files Browse the repository at this point in the history
  • Loading branch information
Teun Vink committed Jul 17, 2024
1 parent 5feca88 commit b741193
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion nlnog_lg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -908,6 +935,7 @@ def robots():
"""
return send_from_directory(app.static_folder, "robots.txt")


data = Datastore()
data.communitylist = read_communities()

Expand Down

0 comments on commit b741193

Please sign in to comment.