]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
scripts: dhcp: option to override preferred Client ID per interface 24107/head
authorShine <4c.fce2@proton.me>
Sun, 31 May 2026 18:33:57 +0000 (20:33 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 11 Jul 2026 15:30:55 +0000 (17:30 +0200)
Using UUID-based client IDs for DHCPv4/DHCPv6 with no option of falling
back to hardware IDs (ie. MAC-address or DUID-LL) resp. none at all (IPv4),
is causing regressions in some setups.

Introduce a new setting to override the preferred client ID to be used for
DHCPv4/DHCPv6 on a per-interface basis:

network.<ifname>.sendclientid='auto|global|hardware|none'

- "auto" (default if empty or not present) uses any explicitly defined
  client ID, or falls back to the global DUID and finally to the DUID-LL
  resp. MAC address (ie. identical to before this commit).
- "global" uses the global default DUID, if configured, for DHCPv4 and
  DHCPv6 requests, even if a client ID is explicitly specified for the i/f
- "hardware" will not pass a client ID to udhcpc/odhcp6c, even if a global
  default DUID is configured or an explicit client ID specified, resulting
  in the i/f MAC address resp. type 3 DUID(-LL) to be used
- "none" (IPv4 only) will not add an option tag 61 to DHCPv4 requests at
  all.

Signed-off-by: Shine <4c.fce2@proton.me>
Link: https://github.com/openwrt/openwrt/pull/24107
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
package/network/config/netifd/Makefile
package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
package/network/ipv6/odhcp6c/Makefile
package/network/ipv6/odhcp6c/files/dhcpv6.sh

index 85f0847eb50936045b3ce43ca134bb4b7c48119d..97b3d721457824d3b1974a68ab3ec4fc81ea3e76 100644 (file)
@@ -1,7 +1,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=netifd
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git
index 5765efffaa042c2cb1d56bc1093cc06c6fa18484..3fbe1aff9736b50499fb7f893c4c55b15099daca 100755 (executable)
@@ -15,6 +15,7 @@ proto_dhcp_init_config() {
        proto_config_add_string 'ipaddr:ipaddr'
        proto_config_add_string 'hostname:hostname'
        proto_config_add_string clientid
+       proto_config_add_string sendclientid
        proto_config_add_string vendorid
        proto_config_add_boolean 'broadcast:bool'
        proto_config_add_boolean 'norelease:bool'
@@ -58,8 +59,8 @@ proto_dhcp_setup() {
        local config="$1"
        local iface="$2"
 
-       local ipaddr hostname clientid vendorid broadcast norelease reqopts defaultreqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes classlessroute timeout retry tryagain
-       json_get_vars ipaddr hostname clientid vendorid broadcast norelease reqopts defaultreqopts iface6rd delegate zone6rd zone mtu6rd customroutes classlessroute timeout retry tryagain
+       local ipaddr hostname clientid sendclientid vendorid broadcast norelease reqopts defaultreqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes classlessroute timeout retry tryagain
+       json_get_vars ipaddr hostname clientid sendclientid vendorid broadcast norelease reqopts defaultreqopts iface6rd delegate zone6rd zone mtu6rd customroutes classlessroute timeout retry tryagain
 
        local opt dhcpopts
        for opt in $reqopts; do
@@ -74,12 +75,28 @@ proto_dhcp_setup() {
        [ "$defaultreqopts" = 0 ] && defaultreqopts="-o" || defaultreqopts=
        [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
        [ "$norelease" = 1 ] && norelease="" || norelease="-R"
-       [ -n "$clientid" ] && {
-               clientid="$(hexdump_2hex "$clientid")"
-               [ -z "$clientid" ] && logger -p warn -t dhcp "$iface: ignoring invalid clientid value"
-       }
-       [ -z "$clientid" ] && clientid="$(proto_dhcp_get_default_clientid "$iface")"
-       [ -n "$clientid" ] && clientid="-x 0x3d:$clientid"
+       case "$sendclientid" in
+               global)
+                       clientid="$(proto_dhcp_get_default_clientid "$iface")"
+                       ;;
+               hardware)
+                       clientid=''
+                       ;;
+               none)
+                       clientid='-C'
+                       ;;
+               auto|\
+               *)
+                       [ -n "$clientid" ] && {
+                               clientid="$(hexdump_2hex "$clientid")"
+                               [ -z "$clientid" ] && {
+                                       logger -p warn -t dhcp "$iface: ignoring invalid clientid value"
+                               }
+                       }
+                       [ -z "$clientid" ] && clientid="$(proto_dhcp_get_default_clientid "$iface")"
+                       ;;
+       esac
+       [ -n "${clientid##-C}" ] && clientid="-x 0x3d:$clientid"
        [ -n "$vendorid" ] && append dhcpopts "-x 0x3c:$(echo -n "$vendorid" | hexdump -ve '1/1 "%02x"')"
        [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
        [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212"
index 480c3e44d7d1b6d4a88e0bf21014a752c1955aaf..98ed16b2d2dc95c41975b37af6271cf2bd788cdb 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=odhcp6c
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/odhcp6c.git
index 71777bc4e175d6a5066de727960201fd6f31c174..033c43e16f55d971a07ddeb7320cad5a26cca423 100755 (executable)
@@ -12,6 +12,7 @@ proto_dhcpv6_init_config() {
        proto_config_add_string 'reqaddress:or("try","force","none")'
        proto_config_add_string reqprefix
        proto_config_add_string clientid
+       proto_config_add_string 'sendclientid:or("auto","global","hardware")'
        proto_config_add_string 'reqopts:list(uinteger)'
        proto_config_add_string 'defaultreqopts:bool'
        proto_config_add_string 'noslaaconly:bool'
@@ -48,6 +49,18 @@ proto_dhcpv6_init_config() {
        proto_config_add_boolean dynamic
 }
 
+proto_dhcpv6_get_default_duid() {
+       local duid="$(uci_get network @globals[0] dhcp_default_duid)"
+       [ -n "$duid" ] && {
+               duid="$(hexdump_2hex "$duid")"
+               [ -z "$duid" ] && {
+                       logger -p warn -t dhcpv6 "$iface: ignoring invalid dhcp_default_duid value"
+               }
+       }
+       [ -z "$duid" ] && return
+       echo -n $duid
+}
+
 proto_dhcpv6_add_prefix() {
        append "$3" "$1"
 }
@@ -60,7 +73,7 @@ proto_dhcpv6_setup() {
        local config="$1"
        local iface="$2"
 
-       local reqaddress reqprefix clientid reqopts defaultreqopts
+       local reqaddress reqprefix clientid sendclientid reqopts defaultreqopts
        local noslaaconly forceprefix extendprefix norelease strict_rfc7550
        local noserverunicast noclientfqdn noacceptreconfig iface_dslite
        local iface_map iface_464xlat ip6ifaceid userclass vendorclass
@@ -70,7 +83,7 @@ proto_dhcpv6_setup() {
 
        local ip6prefix ip6prefixes
 
-       json_get_vars reqaddress reqprefix clientid reqopts defaultreqopts
+       json_get_vars reqaddress reqprefix clientid sendclientid reqopts defaultreqopts
        json_get_vars noslaaconly forceprefix extendprefix norelease strict_rfc7550
        json_get_vars noserverunicast noclientfqdn noacceptreconfig iface_dslite
        json_get_vars iface_map iface_464xlat ip6ifaceid userclass vendorclass
@@ -106,15 +119,24 @@ proto_dhcpv6_setup() {
                append opts "-P$reqprefix"
        }
 
-       [ -n "$clientid" ] && {
-               clientid="$(hexdump_2hex "$clientid")"
-               [ -z "$clientid" ] && logger -p warn -t dhcpv6 "$iface: ignoring invalid clientid value"
-       }
-       [ -z "$clientid" ] && clientid="$(uci_get network @globals[0] dhcp_default_duid)"
-       [ -n "$clientid" ] && {
-               clientid="$(hexdump_2hex "$clientid")"
-               [ -z "$clientid" ] && logger -p warn -t dhcpv6 "$iface: ignoring invalid dhcp_default_duid value"
-       }
+       case "$sendclientid" in
+               global)
+                       clientid="$(proto_dhcpv6_get_default_duid)"
+                       ;;
+               hardware)
+                       clientid=''
+                       ;;
+               auto|\
+               *)
+                       [ -n "$clientid" ] && {
+                               clientid="$(hexdump_2hex "$clientid")"
+                               [ -z "$clientid" ] && {
+                                       logger -p warn -t dhcpv6 "$iface: ignoring invalid clientid value"
+                               }
+                       }
+                       [ -z "$clientid" ] && clientid="$(proto_dhcpv6_get_default_duid)"
+                       ;;
+       esac
        [ -n "$clientid" ] && append opts "-c$clientid"
 
        [ "$defaultreqopts" = "0" ] && append opts "-R"