dhcpv6: set a static define for DUID max length
authorPaul Donald <[email protected]>
Wed, 12 Nov 2025 23:59:13 +0000 (00:59 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Thu, 13 Nov 2025 12:37:08 +0000 (13:37 +0100)
so the number 130 isn't so mysterious at first glance.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/118
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv6.c
src/odhcp6c.h

index 21fd16bd941126793348eb2ea13d47a188e4244e..a6fe1768a3e4beddae7952ce7c7486f99274345c 100644 (file)
@@ -1190,7 +1190,7 @@ static int dhcpv6_handle_advert(enum dhcpv6_msg orig, const int rc,
 
                switch (otype) {
                case DHCPV6_OPT_SERVERID:
-                       if (olen <= 130) {
+                       if (olen <= DHCPV6_DUID_MAX_LEN) {
                                memcpy(cand.duid, odata, olen);
                                cand.duid_len = olen;
                        }
index 405a2bf6fde2f4def103cab12251ad69c3e08dd1..6c669c0e5cf9b947313796a475abbf802129d0f9 100644 (file)
@@ -272,6 +272,7 @@ struct dhcpv6_retx {
 
 #define DHCPV6_OPT_HDR_SIZE 4
 #define DHCPV6_OPT_HDR_SIZE_U 4U
+#define DHCPV6_DUID_MAX_LEN 130 // 2-byte type + 128-byte DUID, RFC8415, §11.1
 
 // DHCPv6 Protocol Headers
 struct dhcpv6_header {
@@ -364,7 +365,7 @@ struct dhcpv6_server_cand {
        bool wants_reconfigure;
        int16_t preference;
        uint8_t duid_len;
-       uint8_t duid[130];
+       uint8_t duid[DHCPV6_DUID_MAX_LEN];
        struct in6_addr server_addr;
        uint32_t sol_max_rt;
        uint32_t inf_max_rt;