From: Chester A. Unal Date: Thu, 26 Feb 2026 08:34:56 +0000 (+0200) Subject: bsbf-usb-netdev-autodhcp: add X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=fea7b41d64f6c4206f1cf5e6e1ef0016c1a70b64;p=openwrt-packages.git bsbf-usb-netdev-autodhcp: add bsbf-usb-netdev-autodhcp creates a network with a DHCP client using a newly created network interface. It uses metric values from 1 to 8. Signed-off-by: Chester A. Unal --- diff --git a/net/bsbf-usb-netdev-autodhcp/Makefile b/net/bsbf-usb-netdev-autodhcp/Makefile new file mode 100644 index 000000000..46c7e8c04 --- /dev/null +++ b/net/bsbf-usb-netdev-autodhcp/Makefile @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# Copyright (C) 2025-2026 Chester A. Unal + +include $(TOPDIR)/rules.mk + +PKG_NAME:=bsbf-usb-netdev-autodhcp +PKG_VERSION:=1 + +PKG_LICENSE:=AGPL-3.0-or-later +PKG_MAINTAINER:=Chester A. Unal + +include $(INCLUDE_DIR)/package.mk + +define Package/bsbf-usb-netdev-autodhcp + SECTION:=net + CATEGORY:=Network + TITLE:=bsbf-usb-netdev-autodhcp +endef + +define Package/bsbf-usb-netdev-autodhcp/description + bsbf-usb-netdev-autodhcp creates a network with a DHCP client using a newly + created network interface. It uses metric values from 1 to 8. +endef + +define Build/Compile +endef + +define Package/bsbf-usb-netdev-autodhcp/install + $(INSTALL_DIR) $(1)/etc/hotplug.d/net + $(INSTALL_BIN) ./files/etc/hotplug.d/net/99-bsbf-usb-netdev-autodhcp $(1)/etc/hotplug.d/net +endef + +$(eval $(call BuildPackage,bsbf-usb-netdev-autodhcp)) diff --git a/net/bsbf-usb-netdev-autodhcp/files/etc/hotplug.d/net/99-bsbf-usb-netdev-autodhcp b/net/bsbf-usb-netdev-autodhcp/files/etc/hotplug.d/net/99-bsbf-usb-netdev-autodhcp new file mode 100644 index 000000000..6cf87e321 --- /dev/null +++ b/net/bsbf-usb-netdev-autodhcp/files/etc/hotplug.d/net/99-bsbf-usb-netdev-autodhcp @@ -0,0 +1,35 @@ +#!/bin/sh +# SPDX-License-Identifier: AGPL-3.0-or-later +# Copyright (C) 2025-2026 Chester A. Unal + +# Only run if a network interface from a USB device is being added. +[ "$ACTION" = "add" ] && echo "$DEVPATH" | grep -q usb || exit + +# Exclude wwan and qmimux network interfaces which a DHCP client wouldn't work +# on. +case "$DEVICENAME" in + wwan*|qmimux*) exit ;; +esac + +# Decide on the metric value. Start from 1 and work up to 8. +metric=1 +while [ $metric -le 8 ]; do + # Break if this metric isn't in use. + uci show network | grep -q ".metric='$metric'" || break + + # Exit if this metric is in use for the same network interface. + [ "$(uci get network.wan_"$DEVICENAME".metric)" = "$metric" ] && exit + + # 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 + +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_"$DEVICENAME"