From a01b1ff1e50f3970ae1af6198022a94cc8fa702a Mon Sep 17 00:00:00 2001 From: Nicolas BESNARD Date: Thu, 20 Feb 2025 13:07:05 +0000 Subject: [PATCH] odhcp6c: fix client exiting if Renew and Rebind fails MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Problem: odhcp6c exits when no reply is received from the server after retransmission of Renew/Rebind messages. Solution: restart the state machine instead of exiting on retransmission failure. Signed-off-by: Nicolas BESNARD Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcp6c/pull/106 Signed-off-by: Álvaro Fernández Rojas --- src/odhcp6c.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 3391aea..ac54ec7 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -634,19 +634,19 @@ int main(_unused int argc, char* const argv[]) odhcp6c_get_state(STATE_IA_PD, &ia_pd_len_r); odhcp6c_get_state(STATE_IA_NA, &ia_na_len_r); + // If we have IAs, try rebind otherwise restart if (ia_pd_len_r == 0 && ia_na_len_r == 0) { - dhcpv6_set_state(DHCPV6_EXIT); + dhcpv6_set_state(DHCPV6_RESET); break; } - // If we have IAs, try rebind otherwise restart msg_type = DHCPV6_MSG_REBIND; dhcpv6_send_request(msg_type); break; case DHCPV6_REBIND_REPLY: if (res < 0) { - dhcpv6_set_state(DHCPV6_EXIT); + dhcpv6_set_state(DHCPV6_RESET); } else { notify_state_change("rebound", 0, true); dhcpv6_set_state(DHCPV6_BOUND); @@ -659,7 +659,7 @@ int main(_unused int argc, char* const argv[]) break; case DHCPV6_INFO_REPLY: - dhcpv6_set_state(res < 0 ? DHCPV6_EXIT : DHCPV6_BOUND); + dhcpv6_set_state(res < 0 ? DHCPV6_RESET : DHCPV6_BOUND); break; case DHCPV6_SOLICIT_PROCESSING: @@ -693,8 +693,10 @@ int main(_unused int argc, char* const argv[]) odhcp6c_get_state(STATE_SERVER_ID, &server_id_len); // Add all prefixes to lost prefixes - bound = false; - notify_state_change("unbound", 0, true); + if (bound) { + bound = false; + notify_state_change("unbound", 0, true); + } if (server_id_len > 0 && (ia_pd_len > 0 || ia_na_len > 0) && config_dhcp->release) dhcpv6_send_request(DHCPV6_MSG_RELEASE); @@ -713,6 +715,11 @@ int main(_unused int argc, char* const argv[]) case DHCPV6_RESET: odhcp6c_clear_state(STATE_CLIENT_ID); + if (bound) { + bound = false; + notify_state_change("unbound", 0, true); + } + size_t oro_user_len, oro_total_len; odhcp6c_get_state(STATE_ORO, &oro_total_len); oro_user_len = config_dhcp->oro_user_cnt * sizeof(uint16_t); -- 2.30.2