]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
scripts: dhcpv6: harmonize IAID between IA_NA and IA_PD requests 23758/head
authorShine <4c.fce2@proton.me>
Fri, 12 Jun 2026 14:27:28 +0000 (16:27 +0200)
committerRobert Marko <robimarko@gmail.com>
Wed, 24 Jun 2026 11:34:32 +0000 (13:34 +0200)
For DHCPv6 address requests (IA_NA), odhcp6c currently uses the first eight
digits of the i/f name's MD5 hash as IAID.

In case of DHCPv6-PD, however, odhcp6c expects the IAID to be specified
explicitly for the IA_PD(s) requested, otherwise it will start counting the
IAID from "1" up for each "-P" argument.

As OpenWrt only requests a single IA_PD per interface, make sure to pass
the identical IAID for IA_PD as is used for IA_NA, unless a custom IAID
was explicitly specified in the i/f configuration.

This prevents regressions with ISPs that expect an IA_PD request to come
from the same IAID+DUID combination as the IA_NA request.

In addition, add some validation of the "reqprefix" value, in order to
catch most cases that would otherwise result in netifd or odhcp6c
malfunction.

Signed-off-by: Shine <4c.fce2@proton.me>
Link: https://github.com/openwrt/openwrt/pull/23758
Signed-off-by: Robert Marko <robimarko@gmail.com>
package/network/ipv6/odhcp6c/files/dhcpv6.sh

index 6e257e11cbe76f9f35de365a88202d72c1eaa7e2..71777bc4e175d6a5066de727960201fd6f31c174 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 . /lib/functions.sh
+. /lib/functions/network.sh
 . ../netifd-proto.sh
 . /lib/config/uci.sh
 init_proto "$@"
@@ -9,7 +10,7 @@ proto_dhcpv6_init_config() {
        renew_handler=1
 
        proto_config_add_string 'reqaddress:or("try","force","none")'
-       proto_config_add_string 'reqprefix:or("auto","no",range(0, 64))'
+       proto_config_add_string reqprefix
        proto_config_add_string clientid
        proto_config_add_string 'reqopts:list(uinteger)'
        proto_config_add_string 'defaultreqopts:bool'
@@ -85,7 +86,25 @@ proto_dhcpv6_setup() {
        [ -n "$reqaddress" ] && append opts "-N$reqaddress"
 
        [ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
-       [ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
+       [ "$reqprefix" != "no" ] && {
+               # append interface IAID if none specified
+               local iaid=$(echo -n $reqprefix | sed -nr 's/^.*:([0-9A-Fa-f]{1,8})$/\1/p')
+               [ -z "$iaid" ] && {
+                       network_generate_iface_iaid iaid "$iface"
+                       reqprefix="$reqprefix:$iaid"
+               }
+               # validate prefix/length hint
+               local hint=${reqprefix%:$iaid}
+               [ "${hint#/}" -le "128" ] 2>/dev/null && {
+                       reqprefix=${reqprefix#/}
+               } || {
+                       validate_data cidr6 "$hint" 2>/dev/null || {
+                               reqprefix="0:$iaid"
+                               logger -p warn -t dhcpv6 "$iface: ignoring invalid prefix hint"
+                       }
+               }
+               append opts "-P$reqprefix"
+       }
 
        [ -n "$clientid" ] && {
                clientid="$(hexdump_2hex "$clientid")"