Skip to content

Commit

Permalink
addons: bridge: skip bridge mac check and force mac-set on bridge cre…
Browse files Browse the repository at this point in the history
…ation

Signed-off-by: Julien Fortin <[email protected]>
  • Loading branch information
julienfortin committed May 27, 2022
1 parent 6861404 commit 46be384
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions ifupdown2/addons/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2814,11 +2814,11 @@ def up_bridge(self, ifaceobj, ifaceobj_getfunc):
self.logger.debug("%s: %s" % (ifname, str(e)))

try:
self._up_bridge_mac(ifaceobj, ifaceobj_getfunc)
self._up_bridge_mac(ifaceobj, link_just_created, ifaceobj_getfunc)
except Exception as e:
self.logger.warning('%s: setting bridge mac address: %s' % (ifaceobj.name, str(e)))

def _get_bridge_mac(self, ifaceobj, ifname, ifaceobj_getfunc):
def _get_bridge_mac(self, ifaceobj, ifname, link_just_created, ifaceobj_getfunc):
bridge_mac_iface = self.bridge_mac_iface.get(ifname)

if bridge_mac_iface and bridge_mac_iface[0] and bridge_mac_iface[1]:
Expand Down Expand Up @@ -2853,16 +2853,20 @@ def _get_bridge_mac(self, ifaceobj, ifname, ifaceobj_getfunc):

# first we need to make sure that the bridge mac is not already inherited from one of it's port
bridge_ports = self._get_bridge_port_list_user_ordered(ifaceobj)
current_mac = self.cache.get_link_address(ifname)

for port in bridge_ports or []:
if not self.is_vxlan(ifaceobj_getfunc(port)):
port_mac = self.cache.get_link_address(port)
# if the bridge was just created we need to set it's mac address to the first port and not look at the
# current bridge mac (the bridge driver probably chose the lowest mac of it's port)
if not link_just_created:
current_mac = self.cache.get_link_address(ifname)

for port in bridge_ports or []:
if not self.is_vxlan(ifaceobj_getfunc(port)):
port_mac = self.cache.get_link_address(port)

if current_mac == port_mac:
self.logger.info("bridge mac is already inherited from %s" % port)
self.bridge_mac_iface[ifname] = (port, port_mac)
return self.bridge_mac_iface[ifname]
if current_mac == port_mac:
self.logger.info("bridge mac is already inherited from %s" % port)
self.bridge_mac_iface[ifname] = (port, port_mac)
return self.bridge_mac_iface[ifname]

for port in bridge_ports or []:
# iterate through the bridge-port list
Expand Down Expand Up @@ -2898,7 +2902,7 @@ def _add_bridge_mac_to_fdb(self, ifaceobj, bridge_mac):
if not ifaceobj.link_privflags & ifaceLinkPrivFlags.BRIDGE_VLAN_AWARE and bridge_mac and ifaceobj.get_attr_value('address'):
self.iproute2.bridge_fdb_add(ifaceobj.name, bridge_mac, vlan=None, bridge=True, remote=None)

def _up_bridge_mac(self, ifaceobj, ifaceobj_getfunc):
def _up_bridge_mac(self, ifaceobj, link_just_created, ifaceobj_getfunc):
"""
We have a day one bridge mac changing problem with changing ports
(basically bridge mac changes when the port it inherited the mac from
Expand All @@ -2917,7 +2921,7 @@ def _up_bridge_mac(self, ifaceobj, ifaceobj_getfunc):
return

ifname = ifaceobj.name
mac_intf, bridge_mac = self._get_bridge_mac(ifaceobj, ifname, ifaceobj_getfunc)
mac_intf, bridge_mac = self._get_bridge_mac(ifaceobj, ifname, link_just_created, ifaceobj_getfunc)
self.logger.debug("%s: _get_bridge_mac returned (%s, %s)"
%(ifname, mac_intf, bridge_mac))

Expand All @@ -2930,7 +2934,9 @@ def _up_bridge_mac(self, ifaceobj, ifaceobj_getfunc):
cached_value = self.cache.get_link_address(ifname)
self.logger.debug('%s: cached hwaddress value: %s' % (ifname, cached_value))
bridge_mac_int = utils.mac_str_to_int(bridge_mac)
if cached_value and utils.mac_str_to_int(cached_value) == bridge_mac_int:

# if the bridge was just created (link_just_created) we should force-set the mac address
if not link_just_created and cached_value and utils.mac_str_to_int(cached_value) == bridge_mac_int:
# the bridge mac is already set to the bridge_mac_intf's mac
return

Expand Down

0 comments on commit 46be384

Please sign in to comment.