Skip to content

Commit

Permalink
Merge pull request #47 from esnet-security/hotfix/asn_community
Browse files Browse the repository at this point in the history
Hotfix/asn community
  • Loading branch information
samoehlert authored Jun 13, 2024
2 parents 3142ed4 + 9bcf273 commit 0450bce
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion translator/gobgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,25 @@ def _build_path(self, ip, event_data={}):
as_path.Pack(as_segments)

# Set our community number
# The ASN gets packed into the community so we need to be careful about size to not overflow the structure
communities = Any()
communities.Pack(attribute_pb2.CommunitiesAttribute(communities=[community]))
# Standard community
# Since we pack both into the community string we need to make sure they will both fit
if asn < 65536 and community < 65536:
comm_id = (asn << 16) + community
communities.Pack(attribute_pb2.CommunitiesAttribute(communities=[comm_id]))
else:
logging.info(f"LargeCommunity Used - ASN:{asn} Community: {community}")
global_admin = asn
local_data1 = community
# set to 0 because there's no use case for it, but we need a local_data2 for gobgp to read any of it
local_data2 = 0
large_community = attribute_pb2.LargeCommunity(
global_admin=global_admin,
local_data1=local_data1,
local_data2=local_data2,
)
communities.Pack(attribute_pb2.LargeCommunitiesAttribute(communities=[large_community]))

attributes = [origin, next_hop, as_path, communities]

Expand Down

0 comments on commit 0450bce

Please sign in to comment.