netifd: use the global DHCP DUID for DHCPv4
authorDavid Härdeman <[email protected]>
Fri, 10 Oct 2025 09:38:36 +0000 (11:38 +0200)
committerRobert Marko <[email protected]>
Sun, 19 Oct 2025 17:46:22 +0000 (19:46 +0200)
This makes the DHCPv4 client use the global DHCP DUID to generate a
RFC4361-style client identifier.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/20359
Signed-off-by: Robert Marko <[email protected]>
package/network/config/netifd/files/lib/netifd/proto/dhcp.sh

index 0bef6a1abb7757d6475803811c5ad5094b51fd50..f6e0690884f40d97fa0d97e23713268559965f92 100755 (executable)
@@ -4,6 +4,7 @@
 
 . /lib/functions.sh
 . ../netifd-proto.sh
+. /lib/config/uci.sh
 init_proto "$@"
 
 proto_dhcp_init_config() {
@@ -31,6 +32,18 @@ proto_dhcp_add_sendopts() {
        [ -n "$1" ] && append "$3" "-x $1"
 }
 
+proto_dhcp_get_default_clientid() {
+       [ -z "$1" ] && return
+
+       local iface="$1"
+       local duid
+       local iaid="0"
+
+        [ -e "/sys/class/net/$iface/ifindex" ] && iaid="$(cat "/sys/class/net/$iface/ifindex")"
+        duid="$(uci_get network @globals[0] dhcp_default_duid)"
+        [ -n "$duid" ] && printf "ff%08x%s" "$iaid" "$duid"
+}
+
 proto_dhcp_setup() {
        local config="$1"
        local iface="$2"
@@ -51,6 +64,7 @@ proto_dhcp_setup() {
        [ "$defaultreqopts" = 0 ] && defaultreqopts="-o" || defaultreqopts=
        [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
        [ "$norelease" = 1 ] && norelease="" || norelease="-R"
+       [ -z "$clientid" ] && clientid="$(proto_dhcp_get_default_clientid "$iface")"
        [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}"
        [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
        [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212"