summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-10-07 19:56:41 +0200
committerChristian Breunig <christian@breunig.cc>2026-10-31 09:58:29 +0000
commit9d24bffcc47b48396c580a48ec9405411e955342 (patch)
tree13311bdbd4b305c15001c683e64355d010873022 /python
parente12776075f2dde8026f523e0d86f327bac7d398c (diff)
downloadvyos-1x-9d24bffcc47b48396c580a48ec9405411e955342.tar.gz
vyos-1x-9d24bffcc47b48396c580a48ec9405411e955342.zip
ethernet: T3871: an ethernet interface belongs to the Kernel and can not be deleted
Every NIC used to carry a hw-id, which was enough to make its node exist. Without it a bare node is empty and never reaches the running configuration, so releasing a bond member looked exactly like a deletion: the port was torn down and left admin-down, with nothing left to bring it back. An ethernet interface is owned by the Kernel and - like 'lo' - outlives its configuration. Removing it now resets the port to the Kernel defaults and leaves the link up.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig/ethernet.py43
1 files changed, 36 insertions, 7 deletions
diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py
index 41fd6a0b9..8360c4654 100644
--- a/python/vyos/ifconfig/ethernet.py
+++ b/python/vyos/ifconfig/ethernet.py
@@ -19,9 +19,11 @@ from glob import glob
from vyos.base import Warning
from vyos.ethtool import Ethtool
+from vyos.ifconfig.ifname_store import permanent_mac
from vyos.ifconfig.interface import Interface
from vyos.utils.dict import dict_search
from vyos.utils.file import read_file
+from vyos.utils.network import get_interface_config
from vyos.utils.process import run
from vyos.utils.assertion import assert_list
@@ -83,6 +85,9 @@ class EthernetIf(Interface):
},
}
+ # T5862: clamped against the adapter maximum wherever it is used
+ DEFAULT_MTU = '1500'
+
@staticmethod
def get_bond_member_allowed_options() -> list:
"""
@@ -122,14 +127,22 @@ class EthernetIf(Interface):
self.ethtool = Ethtool(ifname)
def _create(self):
+ # we cannot create this interface as it is managed by the Kernel
pass
def remove(self):
"""
- Remove interface from config. Removing the interface deconfigures all
- assigned IP addresses.
+ Return the interface to the state the Kernel gave it.
+
+ An ethernet interface is owned by the Kernel and - like 'lo' - can not
+ be removed, so deleting its configuration means resetting the port
+ rather than tearing it down: addresses flushed, MTU and hardware
+ address back to the Kernel default and the link left up. Leaving it
+ admin-down stranded a port with nothing left to bring it back, a
+ released bond member included.
+
Example:
- >>> from vyos.ifconfig import WWANIf
+ >>> from vyos.ifconfig import EthernetIf
>>> i = EthernetIf('eth0')
>>> i.remove()
"""
@@ -140,10 +153,26 @@ class EthernetIf(Interface):
# and thus survives this call.
super().remove()
- if self.exists(self.ifname):
- # interface is placed in A/D state when removed from config! It
- # will remain visible for the operating system.
- self.set_admin_state('down')
+ if not self.exists(self.ifname):
+ return
+
+ # undo what the configuration changed about the hardware itself.
+ #
+ # While the port is still enslaved its address belongs to the bond -
+ # most modes need every member to carry the bond's one, and set_mac()
+ # would bounce the link underneath it. BondIf.update() releases the
+ # member and then runs this cleanup again, which is where the address
+ # is put back.
+ tmp = get_interface_config(self.ifname)
+ if dict_search('linkinfo.info_slave_kind', tmp) != 'bond':
+ mac = permanent_mac(self.ifname)
+ if mac:
+ self.set_mac(mac)
+
+ mtu = min(int(EthernetIf.DEFAULT_MTU), int(self.get_max_mtu()))
+ self.set_mtu(str(mtu))
+
+ self.set_admin_state('up')
def set_flow_control(self, enable, warn=True):
"""