Skip to content

Commit 42f4e32

Browse files
rlubosanangl
authored andcommitted
[nrf fromtree] net: dhcpv4: Reset Renewal/Rebinding times on ACK
In case no Renewal/Rebinding times have been provided the server via DHCP options, we should reset their values on ACK, so that the client can recalculate the defaults. This is important, as the lease time may change, so we should recalculate default T1/T2 timeout based on the new lease time value. Signed-off-by: Robert Lubos <[email protected]> (cherry picked from commit 0d3a021)
1 parent e707cf2 commit 42f4e32

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

subsys/net/lib/dhcpv4/dhcpv4.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
928928
uint8_t length;
929929
uint8_t type;
930930
bool router_present = false;
931+
bool renewal_present = false;
932+
bool rebinding_present = false;
931933
bool unhandled = true;
932934

933935
if (net_pkt_read(pkt, cookie, sizeof(cookie)) ||
@@ -1167,6 +1169,8 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
11671169
NET_DBG("options_renewal: %u",
11681170
iface->config.dhcpv4.renewal_time);
11691171

1172+
renewal_present = true;
1173+
11701174
break;
11711175
case DHCPV4_OPTIONS_REBINDING:
11721176
if (length != 4U) {
@@ -1185,6 +1189,8 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
11851189
NET_DBG("options_rebinding: %u",
11861190
iface->config.dhcpv4.rebinding_time);
11871191

1192+
rebinding_present = true;
1193+
11881194
break;
11891195
case DHCPV4_OPTIONS_SERVER_ID:
11901196
if (length != 4U) {
@@ -1246,6 +1252,23 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
12461252
net_if_ipv4_set_gw(iface, &any);
12471253
}
12481254

1255+
if (*msg_type == NET_DHCPV4_MSG_TYPE_ACK) {
1256+
enum net_dhcpv4_state state = iface->config.dhcpv4.state;
1257+
1258+
/* Clear Renew/Rebind times if not provided. They need to be
1259+
* recalculated accordingly.
1260+
*/
1261+
if (state == NET_DHCPV4_RENEWING || state == NET_DHCPV4_REBINDING) {
1262+
if (!renewal_present) {
1263+
iface->config.dhcpv4.renewal_time = 0U;
1264+
}
1265+
1266+
if (!rebinding_present) {
1267+
iface->config.dhcpv4.rebinding_time = 0U;
1268+
}
1269+
}
1270+
}
1271+
12491272
return true;
12501273
}
12511274

0 commit comments

Comments
 (0)