Skip to content

Commit 85b7607

Browse files
committed
T8329: Fix interface naming for Azure VF interfaces with Accelerated Networking enabled
ROOT-CAUSE: Some Azure VF interfaces miss to get renamed leading to errors in the downstream rules and mess up with the interface names. Two main problematic scenarios were found which prohibited the renaming of a VF interface to vf_ethN: 1. Missing udev add event, when change event is received directly 2. A VF interface registering during rootfs stage FIX: Rule 63: -Azure VF naming is now handled by a dedicated helper - vyos_vf_name to provide collision-free names for VF interfaces. The helper vyos_vf_name would be packaged into initramfs so the same behavior works in early boot and normal boot (a separate PR). -Rule 63 is now guarded to prevent recursive renaming of VF interfaces. Rule 65: -A fallback VF rename path has been added for any leftover VF interfaces that were missed to be renamed due to some unexpected situation. Those VF interfaces are renamed prior to running persistent renaming of synthetic interfaces. This prevents VF interfaces from being considered as synthetic interfaces which may lead to errors in the flow of execution. -Rule 65 is now guarded so generic persistent naming does not override VF names.
1 parent 69039b4 commit 85b7607

3 files changed

Lines changed: 108 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
ACTION!="add", GOTO="vyos_net_end"
55
SUBSYSTEM!="net", GOTO="vyos_net_end"
66

7+
# Fallback path for Azure VFs: if any Azure Mellanox VF still appears as plain
8+
# ethN, rename it to vf_ethX before persistent synthetic interface naming runs
9+
# to 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+
12+
# VF interfaces are not handled by vyos_net_name, so skip them.
13+
# KERNEL=="vf_*" catches already-renamed VFs.
14+
# DRIVERS=="mlx*_core" on Azure catches VFs that reached here in an unexpected
15+
# intermediate state, are still named ethN/eN and must not be remapped
16+
# by vyos_net_name. This guard is intentionally scoped to Microsoft Azure
17+
# to avoid excluding bare-metal Mellanox NICs on physical hardware, which do
18+
# need persistent naming via vyos_net_name.
19+
KERNEL=="vf_*", GOTO="vyos_net_end"
20+
ATTR{[dmi/id]sys_vendor}=="Microsoft Corporation", DRIVERS=="mlx*_core", GOTO="vyos_net_end"
21+
722
# Do name change for ethernet and wireless devices only
823
KERNEL!="eth*|wlan*|e*", GOTO="vyos_net_end"
924

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)