From 1a5b44777daab6a827fc41fdfac514404905dd6f Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Mon, 15 Jan 2024 08:43:08 +0000 Subject: [PATCH] Remove copy&paste code from ensure_arp_ndp_enabled_for_bridge TrivialFix Change-Id: I29d93d2be406867ce5ba394b2dc8e747c05566b2 Signed-off-by: Jakub Libosvar --- ovn_bgp_agent/constants.py | 2 ++ ovn_bgp_agent/utils/linux_net.py | 36 +++++++++++++------------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/ovn_bgp_agent/constants.py b/ovn_bgp_agent/constants.py index 4d6b4c7c..cfb3732f 100644 --- a/ovn_bgp_agent/constants.py +++ b/ovn_bgp_agent/constants.py @@ -52,6 +52,8 @@ IP_VERSION_4 = 4 ARP_IPV4_PREFIX = "169.254." NDP_IPV6_PREFIX = "fd53:d91e:400:7f17::" +IPV4_OCTET_RANGE = 256 + BGP_MODE = 'BGP' EVPN_MODE = 'EVPN' diff --git a/ovn_bgp_agent/utils/linux_net.py b/ovn_bgp_agent/utils/linux_net.py index e4a82b3d..3465491d 100644 --- a/ovn_bgp_agent/utils/linux_net.py +++ b/ovn_bgp_agent/utils/linux_net.py @@ -133,27 +133,21 @@ def delete_device(device): def ensure_arp_ndp_enabled_for_bridge(bridge, offset, vlan_tag=None): - ipv4 = constants.ARP_IPV4_PREFIX + str(int(offset / 256)) + "." + str( - offset % 256) - ipv6 = constants.NDP_IPV6_PREFIX + "%x" % offset - try: - ovn_bgp_agent.privileged.linux_net.add_ip_to_dev(ipv4, bridge) - except agent_exc.IpAddressAlreadyExists: - LOG.debug("IP %s already added on bridge %s", ipv4, bridge) - except KeyError as e: - if "object exists" not in str(e): - LOG.error("Unable to add IP on bridge %s to enable arp/ndp. " - "Exception: %s", bridge, e) - raise - try: - ovn_bgp_agent.privileged.linux_net.add_ip_to_dev(ipv6, bridge) - except agent_exc.IpAddressAlreadyExists: - LOG.debug("IP %s already added on bridge %s", ipv6, bridge) - except KeyError as e: - if "object exists" not in str(e): - LOG.error("Unable to add IP on bridge %s to enable arp/ndp. " - "Exception: %s", bridge, e) - raise + ipv4 = "%s%d.%s" % ( + constants.ARP_IPV4_PREFIX, offset / constants.IPV4_OCTET_RANGE, + offset % constants.IPV4_OCTET_RANGE) + ipv6 = "%s%x" % (constants.NDP_IPV6_PREFIX, offset) + + for ip in (ipv4, ipv6): + try: + ovn_bgp_agent.privileged.linux_net.add_ip_to_dev(ip, bridge) + except agent_exc.IpAddressAlreadyExists: + LOG.debug("IP %s already added on bridge %s", ip, bridge) + except KeyError as e: + if "object exists" not in str(e): + LOG.error("Unable to add IP on bridge %s to enable arp/ndp. " + "Exception: %s", bridge, e) + raise # also enable the arp/ndp on the bridge in case there are flat networks enable_proxy_arp(bridge)