bsbf-openwrt-resources: improve iface type detection and DNS
authorChester A. Unal <redacted>
Sat, 16 May 2026 19:33:33 +0000 (20:33 +0100)
committerChester A. Unal <redacted>
Sun, 17 May 2026 09:13:54 +0000 (10:13 +0100)
To find the correct network interface to create a network entry for, check
which driver is driving the network interface.

Restrict creating a network entry with DHCP client to network interfaces
driven by the cdc_ether, r8152, rndis_host, or ipheth driver.

Ensure UCI section name derived from interface name is proper.

Do not disable using DNS servers advertised by the ISP. This was a
requirement of bsbf-bonding. We can now do this as we transparently proxy
all DNS traffic to Xray which resolves queries.

Do not exit non-zero as it's useless.

Signed-off-by: Chester A. Unal <redacted>
net/bsbf-openwrt-resources/Makefile
net/bsbf-openwrt-resources/files/etc/hotplug.d/net/99-bsbf-autoconf-cellular
net/bsbf-openwrt-resources/files/etc/hotplug.d/net/99-bsbf-autoconf-dhcp

index 7588b7f1f57d229db0c085444310b440021fbf6a..96793ca22dd180e36df4f3d0104964965d0f6171 100644 (file)
@@ -4,7 +4,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=bsbf-openwrt-resources
-PKG_VERSION:=4
+PKG_VERSION:=5
 
 PKG_LICENSE:=AGPL-3.0-or-later
 PKG_MAINTAINER:=Chester A. Unal <chester.a.unal@arinc9.com>
index f4149b88d3446564b6b876217fabeadcd0fec062..462196b7de3c24aaa5e365fd2a7f456d38e415a0 100644 (file)
@@ -3,7 +3,7 @@
 # Copyright (C) 2026 Chester A. Unal <chester.a.unal@arinc9.com>
 
 # Only run if an MBIM or QMI network interface is being added.
-[ "$ACTION" = "add" ] && cur_proto=$(grep -oE "(mbim|qmi)" /sys"${DEVPATH%/*/*}/uevent") || exit
+[ "$ACTION" = "add" ] && cur_proto=$(grep "^DRIVER=" /sys${DEVPATH%/*/*}/uevent | grep -oE "mbim|qmi") || exit
 
 # Find the device path.
 if echo "$DEVPATH" | grep -q usb; then
@@ -45,8 +45,8 @@ while [ $metric -le 8 ]; do
        # Add 1 to metric if another network uses this metric.
        metric=$((metric + 1))
 done
-# If there are no available metrics, exit with code 1.
-[ "$metric" -gt 8 ] && exit 1
+# Exit if there are no available metrics.
+[ "$metric" -gt 8 ] && exit
 
 # Decide on the network name. Start from wwan1.
 index=1
@@ -59,7 +59,6 @@ uci set network.wwan$index.device="$DEVICENAME"
 uci set network.wwan$index.devpath="$devpath"
 uci set network.wwan$index.proto="$cur_proto"
 uci set network.wwan$index.apn='internet'
-uci set network.wwan$index.peerdns='0'
 uci set network.wwan$index.metric="$metric"
 
 # Add wwan network entry to firewall wan zone.
index 36ceee07428500e4f740a78db5f8e64132551f6e..fffeb4021cf0dbafdbeac4076a9c952078c2c754 100644 (file)
@@ -2,14 +2,16 @@
 # SPDX-License-Identifier: AGPL-3.0-or-later
 # Copyright (C) 2025-2026 Chester A. Unal <chester.a.unal@arinc9.com>
 
-# Only run if a non-virtual network interface is being added.
-[ "$ACTION" = "add" ] && echo "$DEVPATH" | grep -qv virtual || exit
+# Only run if a cdc_ether, r8152, rndis_host, or ipheth network interface is
+# being added.
+[ "$ACTION" = "add" ] && grep -E '^DRIVER=(cdc_ether|r8152|rndis_host|ipheth)$' /sys${DEVPATH%/*/*}/uevent || exit
 
-# Exclude MBIM and QMI network interfaces which a DHCP client wouldn't work on.
-grep -E "(mbim|qmi)" /sys"${DEVPATH%/*/*}/uevent" && exit
+# UCI section names must only contain [a-zA-Z0-9_]. Replace any other character
+# with an underscore.
+sec_name=$(echo "$DEVICENAME" | sed 's/[^a-zA-Z0-9_]/_/g')
 
-# If a network with the same name already exists, exit.
-uci get network.wan_"$DEVICENAME" && exit
+# Exit if a network with the same name already exists.
+uci get network.wan_"$sec_name" && exit
 
 # Decide on the metric value. Start from 1 and work up to 8.
 uci_network=$(uci show network)
@@ -21,19 +23,18 @@ while [ $metric -le 8 ]; do
        # Add 1 to metric if another network uses this metric.
        metric=$((metric + 1))
 done
-# If there are no available metrics, exit with code 1.
-[ "$metric" -gt 8 ] && exit 1
+# Exit if there are no available metrics.
+[ "$metric" -gt 8 ] && exit
 
-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 set network.wan_"$sec_name"=interface
+uci set network.wan_"$sec_name".device="$DEVICENAME"
+uci set network.wan_"$sec_name".proto='dhcp'
+uci set network.wan_"$sec_name".metric="$metric"
 
 # Add wan network entry to firewall wan zone.
 fw_section=$(uci show firewall | grep "name='wan'" | cut -d. -f2)
-[ -n "$fw_section" ] && uci add_list firewall.$fw_section.network="wan_$DEVICENAME"
+[ -n "$fw_section" ] && uci add_list firewall.$fw_section.network="wan_$sec_name"
 
 uci commit
 service firewall reload
-ifup wan_"$DEVICENAME"
+ifup wan_"$sec_name"
git clone https://git.99rst.org/PROJECT