From 0cb747dd9e30787a773198b515a340c17b2aebf8 Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Tue, 2 Mar 2021 13:20:06 +0100 Subject: [PATCH] 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 Signed-off-by: Julien Fortin --- ifupdown2/lib/iproute2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ifupdown2/lib/iproute2.py b/ifupdown2/lib/iproute2.py index 203425a..984f604 100644 --- a/ifupdown2/lib/iproute2.py +++ b/ifupdown2/lib/iproute2.py @@ -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)