Skip to content

Commit b30ccbf

Browse files
authored
Merge pull request #5338 from ritika0313/T8329-azure-interface-naming-fix
T8329: Fix interface naming for Azure VF interfaces with Accelerated Networking enabled
2 parents 79e70fb + a1360d6 commit b30ccbf

4 files changed

Lines changed: 124 additions & 1 deletion

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
ATTR{[dmi/id]sys_vendor}!="Microsoft Corporation", GOTO="end_hyperv_nic"
22

3-
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="hv_pci", NAME="vf_%k"
3+
# Primary rename path for Azure VF.
4+
# Use helper-based naming so the VFs that reuse eth0,eth1,.. names do not
5+
# collide with already assigned vf_ethN names. Also, prevent renaming of
6+
# the interfaces already renamed to vf_ethN
7+
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="hv_pci", KERNEL=="eth*", PROGRAM="vyos_vf_name %k", NAME="%c"
48

59
LABEL="end_hyperv_nic"

src/etc/udev/rules.d/65-vyos-net.rules

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
ACTION!="add", GOTO="vyos_net_end"
55
SUBSYSTEM!="net", GOTO="vyos_net_end"
66

7+
# Fallback path for Azure VF interfaces: if a VF still appears as plain ethN,
8+
# rename it to vf_ethX before persistent synthetic interface naming runs to
9+
# prevent it from incorrectly being considered as a synthetic interface.
10+
ATTR{[dmi/id]sys_vendor}=="Microsoft Corporation", DRIVERS=="mlx*_core", KERNEL=="eth*", PROGRAM="vyos_vf_name %k", NAME="%c", GOTO="vyos_net_end"
11+
ATTR{[dmi/id]sys_vendor}=="Microsoft Corporation", DRIVERS=="mana", KERNEL=="eth*", PROGRAM="vyos_vf_name %k", NAME="%c", GOTO="vyos_net_end"
12+
13+
# VF interfaces are not handled by vyos_net_name, so skip them.
14+
# KERNEL=="vf_*" catches already-renamed Mellanox and MANA VFs.
15+
# DRIVERS=="mlx*_core" and DRIVERS=="mana" on Azure catch VF interfaces
16+
# in an unexpected intermediate state (still named ethN/eN) that must not
17+
# be remapped by vyos_net_name.
18+
# This guard is intentionally scoped to Microsoft Azure to
19+
# avoid excluding bare-metal Mellanox NICs on physical hardware, which do
20+
# need persistent naming via vyos_net_name.
21+
KERNEL=="vf_*", GOTO="vyos_net_end"
22+
ATTR{[dmi/id]sys_vendor}=="Microsoft Corporation", DRIVERS=="mlx*_core", GOTO="vyos_net_end"
23+
ATTR{[dmi/id]sys_vendor}=="Microsoft Corporation", DRIVERS=="mana", GOTO="vyos_net_end"
24+
725
# Do name change for ethernet and wireless devices only
826
KERNEL!="eth*|wlan*|e*", GOTO="vyos_net_end"
927

src/system/vyos-net-name-resolve.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ def discover_physical_interfaces(sys_class_net: str = '/sys/class/net') -> dict:
178178
"""Return {kernel_name: mac} for every interface backed by a real bus
179179
device - excludes lo, bridges, bonds, VLANs, veth, tunnels, etc.
180180
181+
Also excludes interfaces enslaved to another netdev (master symlink
182+
present), which covers Azure VF datapath interfaces bound under their
183+
synthetic parent. Those are acceleration children, not independent
184+
primary interfaces, and must not be candidates for hw-id naming.
185+
181186
sys_class_net is overridable for testing against a fake sysfs tree.
182187
"""
183188
interfaces = {}
@@ -187,6 +192,14 @@ def discover_physical_interfaces(sys_class_net: str = '/sys/class/net') -> dict:
187192

188193
for entry in net_dir.iterdir():
189194
if not (entry / 'device').exists():
195+
logger.debug(
196+
f"skipping '{entry.name}': no backing device in sysfs"
197+
)
198+
continue
199+
if (entry / 'master').exists():
200+
logger.debug(
201+
f"skipping '{entry.name}': interface is enslaved via master link"
202+
)
190203
continue
191204
mac = get_permanent_mac(entry.name, sys_class_net)
192205
if mac:

src/udev/vyos_vf_name

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/sh
2+
# vyos_vf_name - pick a non-colliding VF interface name.
3+
# Called by udev rules for VF devices that still have plain ethN names.
4+
#
5+
# Written as a POSIX shell script so it works in both initramfs (no Python3)
6+
# and the normal rootfs udev context.
7+
#
8+
# Usage: vyos_vf_name <current_ifname>
9+
# Prints the target vf_ethN name to stdout.
10+
11+
set -e
12+
13+
if [ -z "$1" ]; then
14+
exit 1
15+
fi
16+
17+
IFNAME="$1"
18+
LOCK_DIR="/run/udev"
19+
LOCK_PATH="${LOCK_DIR}/vyos_vf_name.lock"
20+
21+
# Already normalized - return as-is.
22+
case "$IFNAME" in
23+
vf_*)
24+
echo "$IFNAME"
25+
exit 0
26+
;;
27+
esac
28+
29+
mkdir -p "$LOCK_DIR"
30+
31+
# Acquire a lock to avoid race conditions when multiple VF devices are being
32+
# renamed concurrently.
33+
LOCK_ACQUIRED=0
34+
I=0
35+
while [ "$I" -lt 200 ]; do
36+
if mkdir "$LOCK_PATH" 2>/dev/null; then
37+
LOCK_ACQUIRED=1
38+
break
39+
fi
40+
I=$((I + 1))
41+
sleep 0.01
42+
done
43+
44+
[ "$LOCK_ACQUIRED" -eq 1 ] || exit 1
45+
46+
cleanup() {
47+
rmdir "$LOCK_PATH" 2>/dev/null || true
48+
}
49+
trap cleanup EXIT INT TERM
50+
51+
# Preferred: preserve the original ethN index when vf_ethN is not yet taken.
52+
case "$IFNAME" in
53+
eth*)
54+
PREFERRED="${IFNAME#eth}"
55+
# Validate it is a pure integer.
56+
case "$PREFERRED" in
57+
*[!0-9]*)
58+
;;
59+
*)
60+
if ! [ -d "/sys/class/net/vf_eth${PREFERRED}" ]; then
61+
echo "vf_eth${PREFERRED}"
62+
exit 0
63+
fi
64+
;;
65+
esac
66+
;;
67+
esac
68+
69+
# Fallback: allocate just above the highest ethN synthetic index present to
70+
# avoid collisions.
71+
MAX=-1
72+
for D in /sys/class/net/eth*; do
73+
[ -d "$D" ] || continue
74+
N="${D##*/eth}"
75+
# Skip if not a pure integer (e.g. no match expands to literal path).
76+
case "$N" in *[!0-9]*) continue;; esac
77+
[ "$N" -gt "$MAX" ] && MAX="$N"
78+
done
79+
80+
IDX=$((MAX + 1))
81+
[ "$IDX" -lt 0 ] && IDX=0
82+
83+
# Skip any indices already occupied by existing vf_ethN interfaces.
84+
while [ -d "/sys/class/net/vf_eth${IDX}" ]; do
85+
IDX=$((IDX + 1))
86+
done
87+
88+
echo "vf_eth${IDX}"

0 commit comments

Comments
 (0)