Skip to content

Commit

Permalink
fix non canonical format of IPv6 address string in bgpcfgd
Browse files Browse the repository at this point in the history
IPv6 addresses text used in cfgdb may not follow the canonical IPv6 text format.
When performing IPv6 addresses equivalent check with string, need to make sure
that both of them are in the shortest form defined in rfc 5952
  • Loading branch information
chenkelly authored Jul 2, 2024
1 parent efda929 commit ff481bb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ def get_local_interface(self, local_addr):
If the interface has not been set, return None
"""
local_addresses = self.directory.get_slot("LOCAL", "local_addresses")

# Handle local_addr string that is not represented in canonical text format, especially for IPv6 addresses
try:
ip = netaddr.IPAddress(str(local_addr))
except (netaddr.NotRegisteredError, netaddr.AddrFormatError, netaddr.AddrConversionError):
log_warn("IP Address '%s' format is wrong" % (local_addr))
return None
local_addr = str(ip)

# Check if the local address of this bgp session has been set
if local_addr not in local_addresses:
return None
Expand Down

0 comments on commit ff481bb

Please sign in to comment.