summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-23 15:57:57 +0100
committerChristian Poessinger <christian@poessinger.com>2020-03-23 15:57:57 +0100
commit02d12b89d48416971941a063e620f9055ac0b07c (patch)
tree4699568a639ac53129a92c1e684c0e1e7d668755 /python/vyos
parenta32d4d0bb0c2d324d4c6a20df263348171ec5254 (diff)
downloadvyos-1x-02d12b89d48416971941a063e620f9055ac0b07c.tar.gz
vyos-1x-02d12b89d48416971941a063e620f9055ac0b07c.zip
ifconfig: T2151: ensure interface is admin down when changing MAC address
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/ifconfig/interface.py10
1 files changed, 10 insertions, 0 deletions
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=''):