From 02d12b89d48416971941a063e620f9055ac0b07c Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 23 Mar 2020 15:57:57 +0100 Subject: ifconfig: T2151: ensure interface is admin down when changing MAC address --- python/vyos/ifconfig/interface.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'python/vyos') diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 37fa43bde..8fe0de921 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -309,6 +309,16 @@ class Interface(Control): >>> from vyos.ifconfig import Interface >>> Interface('eth0').set_mac('00:50:ab:cd:ef:01') """ + + # If MAC is unchanged, bail out early + if mac == self.get_mac(): + return None + + # MAC address can only be changed if interface is in 'down' state + prev_state = self.get_state() + if prev_state == 'up': + self.set_state('down') + self.set_interface('mac', mac) def set_vrf(self, vrf=''): -- cgit v1.2.3