[git commit] udhcpc6: send proper Rebind messages

Denys Vlasenko vda.linux at googlemail.com
Sun Oct 11 00:41:42 UTC 2026


commit: https://git.busybox.net/busybox/commit/?id=57c5bba044df638abb2460c9c2d5b7680cc354a7
branch: https://git.busybox.net/busybox/log/?h=master

The REBINDING state uses the Renew packet builder, so its multicast
fallback sends another Renew containing the original server ID. It
cannot ask a different server to extend the lease.

Reuse the existing builder for both message types. Send D6_MSG_REBIND
without a server ID in REBINDING, preserving the client options and
IA_NA/IA_PD contents. Start a new transaction and reset elapsed time
when entering that state; retransmissions retain the transaction ID.
This follows RFC 9915 section 18.2.5 and resolves the TODO in the
REBINDING state asking whether send_d6_renew() should use D6_MSG_REBIND
instead of D6_MSG_RENEW.

Keep the renewal schedule, retry limits, and multicast option behavior
unchanged.

Tested on aarch64 with Alpine's configuration: initial acquisition and
Renew, server failover with IA_NA, IA_PD, and both, Rebind retransmissions,
and stateless Information-request. The unpatched tree loses its lease
in the same failover test. Packet captures verify the message type,
options, transaction ID, and elapsed time.

Native aarch64, GCC 15.2.0, Alpine configuration; relative to
the preceding patch in this series. Data and BSS are unchanged.

bloat-o-meter:
function                                             old     new   delta
static.send_d6_renew                                 208     256     +48
udhcpc6_main                                        3000    3024     +24
.rodata                                            69447   69449      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 74/0)               Total: 74 bytes

Signed-off-by: Jake Buchholz Göktürk <tomalok at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/udhcp/d6_dhcpc.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index cda83485a..ebfa5350b 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -841,7 +841,7 @@ static NOINLINE int send_d6_select(void)
 	return d6_mcast_from_client_data_ifindex(&packet, opt_ptr);
 }
 
-/* Unicast or broadcast a DHCP renew message
+/* Send a DHCPv6 Renew or Rebind message
  *
  * RFC 3315 18.1.3. Creation and Transmission of Renew Messages
  *
@@ -888,16 +888,19 @@ static NOINLINE int send_d6_select(void)
  * about parameter values the client would like to have returned.
  */
 /* NOINLINE: limit stack usage in caller */
-static NOINLINE int send_d6_renew(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6)
+static NOINLINE int send_d6_renew(int msg_type,
+		struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6)
 {
 	struct d6_packet packet;
 	uint8_t *opt_ptr;
 
 	/* Fill in: msg type, xid, ELAPSED_TIME */
-	opt_ptr = init_d6_packet(&packet, D6_MSG_RENEW);
+	opt_ptr = init_d6_packet(&packet, msg_type);
 
-	/* server id */
-	opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2);
+	/* Rebind must not contain a server ID */
+	if (msg_type == D6_MSG_RENEW) {
+		opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2);
+	}
 	/* IA NA (contains requested IP) */
 	if (client6_data.ia_na)
 		opt_ptr = mempcpy(opt_ptr, client6_data.ia_na, client6_data.ia_na->len + 2+2);
@@ -910,7 +913,7 @@ static NOINLINE int send_d6_renew(struct in6_addr *server_ipv6, struct in6_addr
 	 */
 	opt_ptr = add_d6_client_options(opt_ptr);
 
-	bb_info_msg("sending %s", "renew");
+	bb_info_msg("sending %s", msg_type == D6_MSG_RENEW ? "renew" : "rebind");
 	if (server_ipv6)
 		return d6_send_kernel_packet_from_client_data_ifindex(
 			&packet, (opt_ptr - (uint8_t*) &packet),
@@ -1514,7 +1517,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
 					if (opt & OPT_l)
 						send_d6_info_request();
 					else
-						send_d6_renew(OPT_m ? NULL : &srv6_buf, requested_ipv6);
+						send_d6_renew(D6_MSG_RENEW,
+								OPT_m ? NULL : &srv6_buf, requested_ipv6);
 					timeout = discover_timeout;
 					packet_num++;
 					continue;
@@ -1531,6 +1535,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
 				/* Switch to bcast receive */
 				change_listen_mode(LISTEN_RAW);
 				packet_num = 0;
+				client_data.xid = random_xid();
+				client_data.first_secs = 0;
 				/* fall right through */
 			case REBINDING:
 				/* Lease is *really* about to run out,
@@ -1538,9 +1544,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
 				if (lease_remaining > 0 && packet_num < 3) {
 					if (opt & OPT_l)
 						send_d6_info_request();
-					else /* send a broadcast renew request */
-//TODO: send_d6_renew uses D6_MSG_RENEW message, should we use D6_MSG_REBIND here instead?
-						send_d6_renew(/*server_ipv6:*/ NULL, requested_ipv6);
+					else /* send a multicast rebind request */
+						send_d6_renew(D6_MSG_REBIND, /*server_ipv6:*/ NULL, requested_ipv6);
 					timeout = discover_timeout;
 					packet_num++;
 					continue;


More information about the busybox-cvs mailing list