1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

iproute2: link_set_address: dont check the cache on link up

To change the mac address of the device we need to set it down,
then make the change, then bring it back up. Thus we don't need
to check the cache before bringing the device back up.

Also adding a TODO: link_up/down should check if we are running
in a batch context, if so the cache shouldn't be checked to avoid
situation like this.

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
Signed-off-by: Julien Fortin <jfortin@nvidia.com>
This commit is contained in:
Julien Fortin
2021-03-02 13:20:06 +01:00
committed by Julien Fortin
parent 66eb9ce3c5
commit 0cb747dd9e

View File

@ -180,6 +180,7 @@ class IPRoute2(Cache, Requirements):
############################################################################
def link_up(self, ifname):
# TODO: if we already in a batch we shouldn't check the cache as the link might be DOWN during the batch
if not self.cache.link_is_up(ifname):
self.link_up_force(ifname)
@ -235,13 +236,14 @@ class IPRoute2(Cache, Requirements):
def link_set_address_and_keep_down(self, ifname, address, keep_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)
)
if not keep_down:
self.link_up(ifname)
self.link_up_force(ifname)
def link_set_address_and_keep_down_dry_run(self, ifname, address, keep_down=False):
self.link_down(ifname)