bsbf-autoconf-dhcp: switch to wan_$DEVICENAME naming scheme

Use wan_$DEVICENAME naming scheme instead of using consecutive numbering
for the network name.

This makes it easier to match the network interface to the corresponding
network.

Signed-off-by: Chester A. Unal <chester.a.unal@arinc9.com>
This commit is contained in:
Chester A. Unal
2026-03-05 22:17:00 +02:00
parent 6990436459
commit 1cb70a0b3c
2 changed files with 10 additions and 16 deletions

View File

@@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=bsbf-openwrt-resources
PKG_VERSION:=2
PKG_VERSION:=3
PKG_LICENSE:=AGPL-3.0-or-later
PKG_MAINTAINER:=Chester A. Unal <chester.a.unal@arinc9.com>

View File

@@ -8,11 +8,11 @@
# Exclude MBIM and QMI network interfaces which a DHCP client wouldn't work on.
grep -E "(mbim|qmi)" /sys"${DEVPATH%/*/*}/uevent" && exit
# Exit if a network with the network interface already exists.
uci_network=$(uci show network)
echo "$uci_network" | grep -q ".device='$DEVICENAME'" && exit
# If a network with the same name already exists, exit.
uci get network.wan_"$DEVICENAME" && exit
# Decide on the metric value. Start from 1 and work up to 8.
uci_network=$(uci show network)
metric=1
while [ $metric -le 8 ]; do
# Break if this metric isn't in use.
@@ -24,16 +24,10 @@ done
# If there are no available metrics, exit with code 1.
[ "$metric" -gt 8 ] && exit 1
# Decide on the network name. Start from wan1.
index=1
while echo "$uci_network" | grep -q "wan$index"; do
index=$((index + 1))
done
uci set network.wan$index=interface
uci set network.wan$index.device="$DEVICENAME"
uci set network.wan$index.proto='dhcp'
uci set network.wan$index.peerdns='0'
uci set network.wan$index.metric="$metric"
uci set network.wan_"$DEVICENAME"=interface
uci set network.wan_"$DEVICENAME".device="$DEVICENAME"
uci set network.wan_"$DEVICENAME".proto='dhcp'
uci set network.wan_"$DEVICENAME".peerdns='0'
uci set network.wan_"$DEVICENAME".metric="$metric"
uci commit network
ifup wan$index
ifup wan_"$DEVICENAME"