diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-10-07 19:57:01 +0200 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2026-10-31 09:58:29 +0000 |
| commit | 710d0a19b25262fe77a6ebd4a62a5c427a1efa6f (patch) | |
| tree | 33d8412868406a43e5d4cad82da01d394ff0c1ee /python | |
| parent | 9f75f7bf6c143ee3ba7522d281f3a930634cbd83 (diff) | |
| download | vyos-1x-710d0a19b25262fe77a6ebd4a62a5c427a1efa6f.tar.gz vyos-1x-710d0a19b25262fe77a6ebd4a62a5c427a1efa6f.zip | |
interfaces: T3871: only give a name to a device of its own kind
A recorded slot was enough to claim a name, whatever turned up in it. Pull a
modem and put an ordinary USB NIC in the same port and the NIC was handed
wwan0 - a name 'interfaces wwan' reads, so a modem's configuration would be
applied to a card which can not carry it. The reverse was already handled.
Require the device to belong to the namespace the name is read under. If it
does not, the name stays reserved for the hardware that earned it and the
newcomer is named as what it is.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/ifconfig/ifname_store.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/python/vyos/ifconfig/ifname_store.py b/python/vyos/ifconfig/ifname_store.py index d30d39a7f..5a0a29398 100644 --- a/python/vyos/ifconfig/ifname_store.py +++ b/python/vyos/ifconfig/ifname_store.py @@ -325,6 +325,13 @@ def _prefix_for(device: dict) -> str: return 'wlan' if device.get('wireless') else 'eth' +def _name_fits(name: str, device: dict) -> bool: + """A name belongs to the namespace the CLI reads it under, so a modem + can not take an ethernet name nor an ethernet card a modem's. + """ + return name.startswith(_prefix_for(device)) + + def _next_free(taken: set, prefix: str) -> str: index = 0 while f'{prefix}{index}' in taken: @@ -376,7 +383,8 @@ def resolve(devices: list, store: dict) -> tuple: for name, key in entries.items(): for device in remaining: if (device_matches(device['properties'], key) - and seen.get(name, device['mac']) == device['mac']): + and seen.get(name, device['mac']) == device['mac'] + and _name_fits(name, device)): claim(device, name, 'matched') break @@ -391,7 +399,8 @@ def resolve(devices: list, store: dict) -> tuple: continue for device in remaining: if (device_matches(device['properties'], key) - and device['mac'] in known): + and device['mac'] in known + and _name_fits(name, device)): claim(device, name, 'reassigned') break @@ -402,7 +411,7 @@ def resolve(devices: list, store: dict) -> tuple: if name in assigned or not seen.get(name): continue for device in remaining: - if device['mac'] == seen[name]: + if device['mac'] == seen[name] and _name_fits(name, device): claim(device, name, 'moved') break @@ -414,7 +423,8 @@ def resolve(devices: list, store: dict) -> tuple: if name in assigned: continue for device in remaining: - if device_matches(device['properties'], key): + if (device_matches(device['properties'], key) + and _name_fits(name, device)): claim(device, name, 'replaced') break |
