summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTil Kaiser2024-09-29 14:55:57 +0000
committerHauke Mehrtens2024-10-19 17:10:56 +0000
commit503596b8cea735b74c90f3420cd246c706f74905 (patch)
tree4cb8a8f804b96fc387afcc9eb31a033175898d04
parent0a47d518df0d758e8d3b31264cb0428d57c362c3 (diff)
base-files: add ucidef_set_network_device_path_port function
The already existing uci function ucidef_set_network_device_path can be used to specify a unique PCI address to name a network interface. However, I noticed that some NIC ports share the same PCI address but are still distinguishable by the dev_port value of the network interface's sysfs entry. This commit adds a new uci function ucidef_set_network_device_path_port, which is similar to ucidef_set_network_device_path but takes an additional argument where the user can specify the dev_port value. The internal function preinit_config_port loops through all network interfaces at the given PCI address and chooses the one where the dev_port value matches. This was tested on an x86_64 device using a Mellanox ConnectX-3 card. Signed-off-by: Til Kaiser <mail@tk154.de> Link: https://github.com/openwrt/openwrt/pull/16560 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--package/base-files/files/lib/functions/uci-defaults.sh5
-rw-r--r--package/base-files/files/lib/preinit/10_indicate_preinit20
2 files changed, 23 insertions, 2 deletions
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index 8355099c35..5293ce12c0 100644
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -122,6 +122,11 @@ ucidef_set_network_device_path() {
_ucidef_set_network_device_common $1 path $2
}
+ucidef_set_network_device_path_port() {
+ _ucidef_set_network_device_common $1 path $2
+ _ucidef_set_network_device_common $1 port $3
+}
+
ucidef_set_network_device_gro() {
_ucidef_set_network_device_common $1 gro $2
}
diff --git a/package/base-files/files/lib/preinit/10_indicate_preinit b/package/base-files/files/lib/preinit/10_indicate_preinit
index a8f7758c84..12f8fc2e21 100644
--- a/package/base-files/files/lib/preinit/10_indicate_preinit
+++ b/package/base-files/files/lib/preinit/10_indicate_preinit
@@ -65,12 +65,27 @@ preinit_config_switch() {
preinit_config_port() {
local original
+ local dev_port
local netdev="$1"
local path="$2"
+ local port="$3"
[ -d "/sys/devices/$path/net" ] || return
- original="$(ls "/sys/devices/$path/net" | head -1)"
+
+ if [ -z "$port" ]; then
+ original="$(ls "/sys/devices/$path/net" | head -1)"
+ else
+ for device in /sys/devices/$path/net/*; do
+ dev_port="$(cat "$device/dev_port")"
+ if [ "$dev_port" = "$port" ]; then
+ original="${device##*/}"
+ break
+ fi
+ done
+
+ [ -z "$original" ] && return
+ fi
[ "$netdev" = "$original" ] && return
@@ -109,7 +124,8 @@ preinit_config_board() {
json_select "network_device"
json_select "$netdev"
json_get_vars path path
- [ -n "$path" ] && preinit_config_port "$netdev" "$path"
+ json_get_vars port port
+ [ -n "$path" ] && preinit_config_port "$netdev" "$path" "$port"
json_select ..
json_select ..
done