Currently, udhcpc6 does not meet the requirements for Identity Association in 
RFC 3315.
This is a specific explanation of RFC 3315 protocol: 
https://datatracker.ietf.org/doc/html/rfc3315#section-10
"The IAID uniquely identifies the IA and must be chosen to be unique
   among the IAIDs on the client.  The IAID is chosen by the client.
   For any given use of an IA by the client, the IAID for that IA MUST
   be consistent across restarts of the DHCP client."
This patch allows the client to generate a consistent IAID based on the MAC 
address.

Signed-off-by: Zhou Siqi <zhousi...@huawei.com>
---
 networking/udhcp/d6_dhcpc.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index a35488d..99a53c8 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -741,6 +741,32 @@ static NOINLINE int send_d6_info_request(void)
       |     OPTION_RECONF_ACCEPT      |               0               |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
+
+/*obtain a consistent IAID based on the MAC address*/
+static int d6_create_iaid()
+{
+       int data = 0;
+       int start_idx = 0, copy_len = 0;
+       int mac_len = 0;
+
+       mac_len = sizeof(client_data.client_mac);
+
+       /*
+        * A simple IAID is the last 4 bytes
+        * of the hardware address.
+        */
+       if (mac_len > 4) {
+               start_idx = mac_len - 4;
+               copy_len = 4;
+       } else {
+               copy_len = mac_len;
+       }
+
+       memcpy(&data, &client_data.client_mac[start_idx], copy_len);
+
+       return data;
+}
+
 /* NOINLINE: limit stack usage in caller */
 static NOINLINE int send_d6_discover(struct in6_addr *requested_ipv6)
 {
@@ -759,7 +785,7 @@ static NOINLINE int send_d6_discover(struct in6_addr 
*requested_ipv6)
                 client6_data.ia_na = xzalloc(len);
                 client6_data.ia_na->code = D6_OPT_IA_NA;
                 client6_data.ia_na->len = len - 4;
-               *(bb__aliased_uint32_t*)client6_data.ia_na->data = rand(); /* 
IAID */
+               *(bb__aliased_uint32_t*)client6_data.ia_na->data = 
d6_create_iaid(); /* IAID */
                 if (requested_ipv6) {
                         struct d6_option *iaaddr = 
(void*)(client6_data.ia_na->data + 4+4+4);
                         iaaddr->code = D6_OPT_IAADDR;
@@ -777,7 +803,7 @@ static NOINLINE int send_d6_discover(struct in6_addr 
*requested_ipv6)
                 client6_data.ia_pd = xzalloc(len);
                 client6_data.ia_pd->code = D6_OPT_IA_PD;
                 client6_data.ia_pd->len = len - 4;
-               *(bb__aliased_uint32_t*)client6_data.ia_pd->data = rand(); /* 
IAID */
+               *(bb__aliased_uint32_t*)client6_data.ia_pd->data = 
d6_create_iaid(); /* IAID */
                 opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, len);
         }
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to