summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-11-12 08:51:35 -0600
committerJohn Estabrook <jestabro@vyos.io>2021-11-12 08:52:38 -0600
commit86e498517b89a37dba8845c89978753bb045a763 (patch)
tree0c6953b9258c2a2d47feb12e2dee7741ce598aae /src/helpers
parentedfab6fd9b5b1ca906b46b548bff7167cb98c935 (diff)
downloadvyos-1x-86e498517b89a37dba8845c89978753bb045a763.tar.gz
vyos-1x-86e498517b89a37dba8845c89978753bb045a763.zip
interface-names: T3871: shift index to accommodate KVM behaviour
(on behalf of Dmitriy Eshenko)
Diffstat (limited to 'src/helpers')
-rwxr-xr-xsrc/helpers/vyos_net_name15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/helpers/vyos_net_name b/src/helpers/vyos_net_name
index 5d9535cf0..13fb9e31f 100755
--- a/src/helpers/vyos_net_name
+++ b/src/helpers/vyos_net_name
@@ -69,6 +69,19 @@ def find_available(intfs: dict, prefix: str) -> str:
return f'{prefix}{len(index_list)}'
+def mod_ifname(ifname: str) -> str:
+ """ Check interface with names eX and return ifname on the next format eth{ifindex} - 2
+ """
+ if re.match("^e[0-9]+$", ifname):
+ intf = ifname.split("e")
+ if intf[1]:
+ if int(intf[1]) >= 2:
+ return "eth" + str(int(intf[1]) - 2)
+ else:
+ return "eth" + str(intf[1])
+
+ return ifname
+
def get_biosdevname(ifname: str) -> str:
""" Use legacy vyatta-biosdevname to query for name
@@ -77,7 +90,7 @@ def get_biosdevname(ifname: str) -> str:
XXX: This throws an error, and likely has for a long time, unnoticed
since vyatta_net_name redirected stderr to /dev/null.
"""
- intf = f"eth{re.sub(r'[^0-9]', '', ifname)}" if 'e' == ifname[0] else ifname
+ intf = mod_ifname(ifname)
if 'eth' not in intf:
return intf