mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
netlink: keeping link down after mac change if 'link-down yes' is specified
Signed-off-by: Julien Fortin <jfortin@nvidia.com>
This commit is contained in:
1
debian/changelog
vendored
1
debian/changelog
vendored
@ -2,6 +2,7 @@ ifupdown2 (3.2.1) unstable; urgency=medium
|
||||
|
||||
* New: Attribute: "disable-ipv6" to control ipv6 on an interface
|
||||
* New: Policy: "default_loopback_scope" control loopback ip scope
|
||||
* Fix: keep link down after mac change if 'link-down yes' is specified
|
||||
|
||||
-- Julien Fortin <jfortin@nvidia.com> Thu, 04 May 2023 23:42:00 -0700
|
||||
|
||||
|
@ -1249,7 +1249,12 @@ class address(AddonWithIpBlackList, moduleBase):
|
||||
self.netlink.link_down(l)
|
||||
slave_down = True
|
||||
try:
|
||||
self.netlink.link_set_address(ifaceobj.name, hwaddress, hwaddress_int)
|
||||
self.netlink.link_set_address(
|
||||
ifaceobj.name,
|
||||
hwaddress,
|
||||
hwaddress_int,
|
||||
keep_link_down=ifaceobj.link_privflags & ifaceLinkPrivFlags.KEEP_LINK_DOWN
|
||||
)
|
||||
old_mac_addr = running_hwaddress
|
||||
finally:
|
||||
if slave_down:
|
||||
|
@ -217,14 +217,15 @@ class IPRoute2(Cache, Requirements):
|
||||
|
||||
###
|
||||
|
||||
def link_set_address(self, ifname, address):
|
||||
def link_set_address(self, ifname, address, keep_link_down=False):
|
||||
if utils.mac_str_to_int(address) != self.cache.get_link_address_raw(ifname):
|
||||
self.link_down(ifname)
|
||||
self.__execute_or_batch(
|
||||
utils.ip_cmd,
|
||||
"link set dev %s address %s" % (ifname, address)
|
||||
)
|
||||
self.link_up(ifname)
|
||||
if not keep_link_down:
|
||||
self.link_up(ifname)
|
||||
|
||||
def link_set_address_dry_run(self, ifname, address):
|
||||
self.link_down(ifname)
|
||||
|
@ -2706,7 +2706,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject
|
||||
def link_set_address_dry_run(self, ifname, hw_address, hw_address_int):
|
||||
self.log_info_ifname_dry_run(ifname, "netlink: ip link set dev %s address %s" % (ifname, hw_address))
|
||||
|
||||
def link_set_address(self, ifname, hw_address, hw_address_int):
|
||||
def link_set_address(self, ifname, hw_address, hw_address_int, keep_link_down=False):
|
||||
is_link_up = self.cache.link_is_up(ifname)
|
||||
# check if the link is already up or not if the link is
|
||||
# up we need to down it then make sure we up it again
|
||||
@ -2734,8 +2734,10 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject
|
||||
except Exception as e:
|
||||
raise NetlinkError(e, "cannot set dev %s address %s" % (ifname, hw_address), ifname=ifname)
|
||||
finally:
|
||||
if is_link_up:
|
||||
if is_link_up and not keep_link_down:
|
||||
self.link_up_force(ifname)
|
||||
else:
|
||||
self.logger.info(f"{ifname}: keeping link down")
|
||||
|
||||
###
|
||||
|
||||
|
Reference in New Issue
Block a user