Skip to contentSkip to conversation

dhcp: Use bound_time for retransmission timers

PATCH Applied Denis Kenzior 2 participants 8 messages May 11, 2022 – May 18, 2022

lore
Share & tools
lore

Denis Kenzior

author
#0 lore raw

PATCH 1/1 dhcp: Use bound_time for retransmission timers

start_t is used to try and calculate the retransmission timeout value when the client enters RENEWING or REBINDING state. This works fine on the first renewal since the client start timestamp and the lease bound timestamp are very close. Also, the RENEW request is sent immediately whenever the T1 timer expires and most of the time it succeeds.

However, if this isn't a first renewal attempt and the RENEW request sent when the T1 timer expires is not successful, then the renewal timeout value could become too large. Fix that by using the lease bound_time for the retransmission timer calculation (as intended) intead of the client start time (start_t).

---
 ell/dhcp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
ell/dhcp.c +6 -5
index 2d049005a135..01900f3b1d38 100644
@@ -520,6 +520,7 @@ static void dhcp_client_timeout_resend(struct l_timeout *timeout,
 								void *user_data)
 {
 	struct l_dhcp_client *client = user_data;
+	struct l_dhcp_lease *lease = client->lease;
 	unsigned int next_timeout = 0;
 	int r;
 
@@ -555,12 +556,12 @@ static void dhcp_client_timeout_resend(struct l_timeout *timeout,
 
 	switch (client->state) {
 	case DHCP_STATE_RENEWING:
-		next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
-							client->lease->t2);
+		next_timeout = dhcp_rebind_renew_retry_time(lease->bound_time,
+								lease->t2);
 		break;
 	case DHCP_STATE_REBINDING:
-		next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
-						client->lease->lifetime);
+		next_timeout = dhcp_rebind_renew_retry_time(lease->bound_time,
+							lease->lifetime);
 		break;
 	case DHCP_STATE_REQUESTING:
 	case DHCP_STATE_SELECTING:
@@ -642,7 +643,7 @@ static void dhcp_client_t1_expired(struct l_timeout *timeout, void *user_data)
 	l_timeout_set_callback(client->timeout_lease, dhcp_client_t2_expired,
 				client, NULL);
 
-	next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
+	next_timeout = dhcp_rebind_renew_retry_time(client->lease->bound_time,
 							client->lease->t2);
 	client->timeout_resend =
 		l_timeout_create_ms(dhcp_fuzz_secs(next_timeout),
Signature · 1 line
2.32.0
#1 lore raw

Hi Denis,

I've been running this patch for the day and I don't think it's actually fixed the retry. I have set a low lease time and then block the DHCP server for the ACK and I can see that the retry still doesn't happen.

https://pastebin.com/Gy3Gcs4W

Regards,
Michael

Quoted 57 lines · Denis Kenzior

start_t is used to try and calculate the retransmission timeout value when the client enters RENEWING or REBINDING state. This works fine on the first renewal since the client start timestamp and the lease bound timestamp are very close. Also, the RENEW request is sent immediately whenever the T1 timer expires and most of the time it succeeds.

However, if this isn't a first renewal attempt and the RENEW request sent when the T1 timer expires is not successful, then the renewal timeout value could become too large. Fix that by using the lease bound_time for the retransmission timer calculation (as intended) intead of the client start time (start_t).

---
 ell/dhcp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
ell/dhcp.c +6 -6
index 2d049005a135..01900f3b1d38 100644
@@ -520,6 +520,7 @@ static void dhcp_client_timeout_resend(struct l_timeout *timeout,
                                                                void *user_data)
 {
        struct l_dhcp_client *client = user_data;
+       struct l_dhcp_lease *lease = client->lease;
        unsigned int next_timeout = 0;
        int r;
 
@@ -555,12 +556,12 @@ static void dhcp_client_timeout_resend(struct l_timeout *timeout,
 
        switch (client->state) {
        case DHCP_STATE_RENEWING:
-               next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
-                                                       client->lease->t2);
+               next_timeout = dhcp_rebind_renew_retry_time(lease->bound_time,
+                                                               lease->t2);
                break;
        case DHCP_STATE_REBINDING:
-               next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
-                                               client->lease->lifetime);
+               next_timeout = dhcp_rebind_renew_retry_time(lease->bound_time,
+                                                       lease->lifetime);
                break;
        case DHCP_STATE_REQUESTING:
        case DHCP_STATE_SELECTING:
@@ -642,7 +643,7 @@ static void dhcp_client_t1_expired(struct l_timeout *timeout, void *user_data)
        l_timeout_set_callback(client->timeout_lease, dhcp_client_t2_expired,
                                client, NULL);
 
-       next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
+       next_timeout = dhcp_rebind_renew_retry_time(client->lease->bound_time,
                                                        client->lease->t2);
        client->timeout_resend =
                l_timeout_create_ms(dhcp_fuzz_secs(next_timeout),
--

2.32.0

author
#2 lore raw

Hi Michael,

Quoted 6 lines · Michael Johnson

Hi Denis,

I've been running this patch for the day and I don't think it's actually fixed the retry. I have set a low lease time and then block the DHCP server for the ACK and I can see that the retry still doesn't happen.

I suspect it does fix one bug, but not another... I'm not near my test box right now, so debugging this is a bit painful.

Could you debug-print the 'next_timeout' we calculate in dhcp_client_t1_expired() here:

         next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
                                                         client->lease->t2);

And also put in

         L_WARN_ON(!client->timeout_resend);

after the timeout_resend timer is created?

From your 'other' bug report yesterday, we calculate the t1 timer correctly,
but the timer still doesn't fire.
It almost feels like the timers are just not being created. Is there anything suspicious in the kernel logs?

Regards,
-Denis

#3 lore raw

Hi Denis,

I added those log lines and got this.

```
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_rx_message:949 T1 expiring in 299004 ms
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4] l_acd_start:455 Skipping
probes and sending announcements
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4]
announce_wait_timeout:166 No conflicts found for 10.101.8.24,
announcing address
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4] acd_send_packet:146
sending packet with target IP 10.101.8.24
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_t1_expired:630
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_t1_expired:632 Entering state: DHCP_STATE_RENEWING
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_send_request:397
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_t1_expired:643 next_timeout: 225
May 13 15:28:58 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_t2_expired:609
May 13 15:28:58 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_t2_expired:616 Entering state: DHCP_STATE_REBINDING
May 13 15:30:12 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_lease_expired:598
```

Regards,
Michael

Quoted 32 lines · Denis Kenzior

Hi Michael,

Quoted 6 lines · Michael Johnson

Hi Denis,

I've been running this patch for the day and I don't think it's actually fixed the retry. I have set a low lease time and then block the DHCP server for the ACK and I can see that the retry still doesn't happen.

I suspect it does fix one bug, but not another... I'm not near my test box right now, so debugging this is a bit painful.

Could you debug-print the 'next_timeout' we calculate in dhcp_client_t1_expired() here:

         next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
                                                         client->lease->t2);

And also put in

         L_WARN_ON(!client->timeout_resend);

after the timeout_resend timer is created?

From your 'other' bug report yesterday, we calculate the t1 timer correctly,
but the timer still doesn't fire.
It almost feels like the timers are just not being created. Is there anything suspicious in the kernel logs?

Regards,
-Denis

#4 lore raw

Sorry, I put the log for the t2 retry. Putting it in the right place gives us our problem though

```
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4] dhcp_client_t1_expired:630
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]
dhcp_client_t1_expired:632 Entering state: DHCP_STATE_RENEWING
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4] dhcp_client_send_request:397
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]
dhcp_client_t1_expired:642 next_timeout t2: 225
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]
dhcp_client_t1_expired:651 next_timeout t1 retry: 896458022
```

Regards,
Michael

Quoted 63 lines · Michael Johnson

Hi Denis,

I added those log lines and got this.

```
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_rx_message:949 T1 expiring in 299004 ms
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4] l_acd_start:455 Skipping
probes and sending announcements
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4]
announce_wait_timeout:166 No conflicts found for 10.101.8.24,
announcing address
May 13 15:20:14 r2-19006 iwd[28716]: [DHCPv4] acd_send_packet:146
sending packet with target IP 10.101.8.24
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_t1_expired:630
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_t1_expired:632 Entering state: DHCP_STATE_RENEWING
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_send_request:397
May 13 15:25:13 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_t1_expired:643 next_timeout: 225
May 13 15:28:58 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_t2_expired:609
May 13 15:28:58 r2-19006 iwd[28716]: [DHCPv4]
dhcp_client_t2_expired:616 Entering state: DHCP_STATE_REBINDING
May 13 15:30:12 r2-19006 iwd[28716]: [DHCPv4] dhcp_client_lease_expired:598
```

Regards,
Michael

Quoted 32 lines · Denis Kenzior

Hi Michael,

Quoted 6 lines · Michael Johnson

Hi Denis,

I've been running this patch for the day and I don't think it's actually fixed the retry. I have set a low lease time and then block the DHCP server for the ACK and I can see that the retry still doesn't happen.

I suspect it does fix one bug, but not another... I'm not near my test box right now, so debugging this is a bit painful.

Could you debug-print the 'next_timeout' we calculate in dhcp_client_t1_expired() here:

         next_timeout = dhcp_rebind_renew_retry_time(client->start_t,
                                                         client->lease->t2);

And also put in

         L_WARN_ON(!client->timeout_resend);

after the timeout_resend timer is created?

From your 'other' bug report yesterday, we calculate the t1 timer correctly,
but the timer still doesn't fire.
It almost feels like the timers are just not being created. Is there anything suspicious in the kernel logs?

Regards,
-Denis

author
#5 lore raw

Hi Michael,

Quoted 4 lines · Michael Johnson

Sorry, I put the log for the t2 retry. Putting it in the right place gives us our problem though

```

Quoted 8 lines
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4] dhcp_client_t1_expired:630
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]
dhcp_client_t1_expired:632 Entering state: DHCP_STATE_RENEWING
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4] dhcp_client_send_request:397
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]
dhcp_client_t1_expired:642 next_timeout t2: 225
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]

dhcp_client_t1_expired:651 next_timeout t1 retry: 896458022

Ugh, looks like commit:
c78ad1bb6d7e ("dhcp: Set lease expiry based on frame reception times")

broke this. It is mixing up SO_TIMESTAMP which is from CLOCK_REALTIME and our bound_time which is supposed to be in CLOCK_BOOTTIME.

No wonder the timeout way too long :)

Let me send another fixup patch.

Regards,
-Denis

#6 lore raw

Great, thank you!

I'll run this patch on master over the weekend and see if I can get more data for the other issue.

Regards,
Michael

Quoted 29 lines · Denis Kenzior

Hi Michael,

Quoted 4 lines · Michael Johnson

Sorry, I put the log for the t2 retry. Putting it in the right place gives us our problem though

```

Quoted 8 lines
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4] dhcp_client_t1_expired:630
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]
dhcp_client_t1_expired:632 Entering state: DHCP_STATE_RENEWING
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4] dhcp_client_send_request:397
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]
dhcp_client_t1_expired:642 next_timeout t2: 225
May 13 15:38:34 r2-19006 iwd[39610]: [DHCPv4]

dhcp_client_t1_expired:651 next_timeout t1 retry: 896458022

Ugh, looks like commit:
c78ad1bb6d7e ("dhcp: Set lease expiry based on frame reception times")

broke this. It is mixing up SO_TIMESTAMP which is from CLOCK_REALTIME and our bound_time which is supposed to be in CLOCK_BOOTTIME.

No wonder the timeout way too long :)

Let me send another fixup patch.

Regards,
-Denis

author Applied
#7 lore raw
In reply to Denis Kenzior
Quoted 6 lines · Denis Kenzior

start_t is used to try and calculate the retransmission timeout value when the client enters RENEWING or REBINDING state. This works fine on the first renewal since the client start timestamp and the lease bound timestamp are very close. Also, the RENEW request is sent immediately whenever the T1 timer expires and most of the time it succeeds.

Quoted 9 lines

However, if this isn't a first renewal attempt and the RENEW request sent when the T1 timer expires is not successful, then the renewal timeout value could become too large. Fix that by using the lease bound_time for the retransmission timer calculation (as intended) intead of the client start time (start_t).

---
  ell/dhcp.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)

Applied.