From ff481bb6c198c52c33a349b88c028c492acf3ce6 Mon Sep 17 00:00:00 2001 From: Kelly Chen Date: Tue, 2 Jul 2024 15:07:09 +0800 Subject: [PATCH] fix non canonical format of IPv6 address string in bgpcfgd 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 --- src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py b/src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py index b15f841f6166..bb2b5be63e76 100644 --- a/src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py +++ b/src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py @@ -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