diff --git a/ifupdown2/addons/address.py b/ifupdown2/addons/address.py index 756b1ec..54704bd 100644 --- a/ifupdown2/addons/address.py +++ b/ifupdown2/addons/address.py @@ -835,19 +835,25 @@ class address(AddonWithIpBlackList, moduleBase): self.sysfs.link_set_mtu(ifaceobj.name, mtu_str=self.default_mtu, mtu_int=self.default_mtu_int) return - if (ifupdownconfig.config.get('adjust_logical_dev_mtu', '1') != '0' - and ifaceobj.lowerifaces): - # set vlan interface mtu to lower device mtu - if (ifaceobj.link_kind & ifaceLinkKind.VLAN): - lower_iface = ifaceobj.lowerifaces[0] - lower_iface_mtu_int = self.cache.get_link_mtu(lower_iface) + # set vlan interface mtu to lower device mtu + if ( + ifupdownconfig.config.get('adjust_logical_dev_mtu', '1') != '0' + and ifaceobj.lowerifaces + and ifaceobj.link_kind & ifaceLinkKind.VLAN + ): + lower_iface = ifaceobj.lowerifaces[0] + lower_iface_mtu_int = self.cache.get_link_mtu(lower_iface) - if lower_iface_mtu_int != cached_link_mtu: - self.sysfs.link_set_mtu(ifaceobj.name, mtu_str=str(lower_iface_mtu_int), mtu_int=lower_iface_mtu_int) + if lower_iface_mtu_int != cached_link_mtu: + self.sysfs.link_set_mtu(ifaceobj.name, mtu_str=str(lower_iface_mtu_int), mtu_int=lower_iface_mtu_int) - elif (not (ifaceobj.name == 'lo') and not ifaceobj.link_kind and - not (ifaceobj.link_privflags & ifaceLinkPrivFlags.BOND_SLAVE) and - self.default_mtu): + elif ( + not (ifaceobj.name == 'lo') + and not ifaceobj.link_kind + and not (ifaceobj.link_privflags & ifaceLinkPrivFlags.BOND_SLAVE) + and self.default_mtu + and cached_link_mtu != self.default_mtu_int + ): # logical devices like bridges and vlan devices rely on mtu # from their lower devices. ie mtu travels from # lower devices to upper devices. For bonds mtu travels from @@ -856,8 +862,7 @@ class address(AddonWithIpBlackList, moduleBase): # config by the kernel in play, we try to be cautious here # on which devices we want to reset mtu to default. # essentially only physical interfaces which are not bond slaves - if cached_link_mtu != self.default_mtu_int: - self.sysfs.link_set_mtu(ifaceobj.name, mtu_str=self.default_mtu, mtu_int=self.default_mtu_int) + self.sysfs.link_set_mtu(ifaceobj.name, mtu_str=self.default_mtu, mtu_int=self.default_mtu_int) def _set_bridge_forwarding(self, ifaceobj): """ set ip forwarding to 0 if bridge interface does not have a @@ -1183,12 +1188,11 @@ class address(AddonWithIpBlackList, moduleBase): if hwaddress_int != utils.mac_str_to_int(running_hwaddress): slave_down = False - if ifaceobj.link_kind & ifaceLinkKind.BOND: + if ifaceobj.link_kind & ifaceLinkKind.BOND and ifaceobj.lowerifaces: # if bond, down all the slaves - if ifaceobj.lowerifaces: - for l in ifaceobj.lowerifaces: - self.netlink.link_down(l) - slave_down = True + for l in ifaceobj.lowerifaces: + self.netlink.link_down(l) + slave_down = True try: self.netlink.link_set_address(ifaceobj.name, hwaddress, hwaddress_int) old_mac_addr = running_hwaddress @@ -1411,8 +1415,7 @@ class address(AddonWithIpBlackList, moduleBase): # removed from the configuration file but the IP is still configured on # the device, so we need to mark them as FAIL (we will only mark them # as failure on the first sibling). - if ifaceobj.flags & iface.HAS_SIBLINGS: - if not ifaceobj.flags & iface.YOUNGEST_SIBLING: + if ifaceobj.flags & iface.HAS_SIBLINGS and not ifaceobj.flags & iface.YOUNGEST_SIBLING: return all_stanza_user_config_ip = self.cache.get_user_configured_addresses(ifaceobj_list)