[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: =?utf-8?q?udhcpc=3A_udhcpc_skips_RENEWING_state_when_lease_time_is_short?=
From: Tomas_Tonhauser <t.tonhauser () pobox ! sk>
Date: 2018-10-03 19:56:10
Message-ID: 20181003215610.1BE7FC39 () pobox ! sk
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hello all,
busybox 1.28.3-4 (OpenWrt 18.06.1) running on a WiFi router, requesting IP address \
from 4G router (Huawei B2338-168) running in IPv4 passtrough mode. In this mode, 4G \
router is assigning the the same IP address it got from ISP (mobile network \
operator), lease time is 120 seconds. Because first renew request is sent after 60 \
seconds, it is broadcasted (= REBINDING state); RENEWING state is skipped:
...
case RENEWING:
if (timeout > 60) {
/* send an unicast renew request */
...
4G router drops broadcasted renew request and after lease is expired, WiFi router \
releases the IP address and enters init state:
Wed Oct 3 19:02:39 2018 user.notice firewall: Reloading firewall due to ifup of wan \
(eth1) Wed Oct 3 19:03:37 2018 daemon.notice netifd: wan (1166): udhcpc: sending \
renew to 0.0.0.0 Wed Oct 3 19:04:07 2018 daemon.notice netifd: wan (1166): udhcpc: \
sending renew to 0.0.0.0 Wed Oct 3 19:04:22 2018 daemon.notice netifd: wan (1166): \
udhcpc: sending renew to 0.0.0.0 Wed Oct 3 19:04:29 2018 daemon.notice netifd: wan \
(1166): udhcpc: sending renew to 0.0.0.0 Wed Oct 3 19:04:32 2018 daemon.notice \
netifd: wan (1166): udhcpc: sending renew to 0.0.0.0 Wed Oct 3 19:04:33 2018 \
daemon.notice netifd: wan (1166): udhcpc: sending renew to 0.0.0.0 Wed Oct 3 \
19:04:33 2018 daemon.notice netifd: wan (1166): udhcpc: lease lost, entering init \
state Wed Oct 3 19:04:34 2018 daemon.notice netifd: Interface 'wan' has lost the \
connection Wed Oct 3 19:04:34 2018 daemon.notice netifd: wan (1166): udhcpc: sending \
select for 10.98.21.140 Wed Oct 3 19:04:34 2018 daemon.notice netifd: wan (1166): \
udhcpc: lease of 10.98.21.140 obtained, lease time 120 Wed Oct 3 19:04:34 2018 \
daemon.err openvpn(******)[1539]: write UDP: Network unreachable (code=128) Wed Oct \
3 19:04:34 2018 daemon.warn dnsmasq[1511]: no servers found in /tmp/resolv.conf.auto, \
will retry Wed Oct 3 19:04:35 2018 daemon.notice netifd: Interface 'wan' is now up
Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: reading /tmp/resolv.conf.auto
Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using local addresses only for \
domain test Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using local addresses \
only for domain onion Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using local \
addresses only for domain localhost Wed Oct 3 19:04:35 2018 daemon.info \
dnsmasq[1511]: using local addresses only for domain local Wed Oct 3 19:04:35 2018 \
daemon.info dnsmasq[1511]: using local addresses only for domain invalid Wed Oct 3 \
19:04:35 2018 daemon.info dnsmasq[1511]: using local addresses only for domain bind \
Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using nameserver \
192.168.11.254#53 for domain *** Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: \
using local addresses only for domain ***** Wed Oct 3 19:04:35 2018 daemon.info \
dnsmasq[1511]: using nameserver 160.218.161.60#53 Wed Oct 3 19:04:35 2018 \
daemon.info dnsmasq[1511]: using nameserver 160.218.167.5#53 Wed Oct 3 19:04:36 2018 \
user.notice firewall: Reloading firewall due to ifup of wan (eth1)
So each 2 minutes wan connectivity is lost for a fraction of second.
I'd propose to perform at least one unicast renew reques irrespective of lease time, \
proposed patch:
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index fd18325..01241ca 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1414,6 +1414,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
struct dhcp_packet packet;
/* silence "uninitialized!" warning */
unsigned timestamp_before_wait = timestamp_before_wait;
+ uint32_t unicast_renew_attempt = 0;
//bb_error_msg("sockfd:%d, listen_mode:%d", sockfd, listen_mode);
@@ -1468,6 +1469,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
switch (state) {
case INIT_SELECTING:
+ unicast_renew_attempt = 0;
if (!discover_retries || packet_num < \
discover_retries) { if (packet_num == 0)
xid = random_xid();
@@ -1521,8 +1523,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
case_RENEW_REQUESTED:
case RENEWING:
- if (timeout > 60) {
+ /* we should try to send at least one unicast renew \
request */ + if (timeout > 60 || \
!unicast_renew_attempt) {
/* send an unicast renew request */
+ unicast_renew_attempt = 1;
/* Sometimes observed to fail (EADDRNOTAVAIL) to bind
* a new UDP socket for sending inside send_renew.
* I hazard to guess existing listening socket
After applying patch, unicast renew request towards Huawei 4G router works as \
expected: Wed Oct 3 20:12:58 2018 daemon.notice netifd: wan (3610): udhcpc: sending \
renew to 192.168.22.1 Wed Oct 3 20:12:58 2018 daemon.notice netifd: wan (3610): \
udhcpc: lease of 10.98.21.140 obtained, lease time 120 Wed Oct 3 20:13:58 2018 \
daemon.notice netifd: wan (3610): udhcpc: sending renew to 192.168.22.1 Wed Oct 3 \
20:13:59 2018 daemon.notice netifd: wan (3610): udhcpc: lease of 10.98.21.140 \
obtained, lease time 120 Wed Oct 3 20:14:59 2018 daemon.notice netifd: wan (3610): \
udhcpc: sending renew to 192.168.22.1 Wed Oct 3 20:14:59 2018 daemon.notice netifd: \
wan (3610): udhcpc: lease of 10.98.21.140 obtained, lease time 120 Wed Oct 3 \
20:16:00 2018 daemon.notice netifd: wan (3610): udhcpc: sending renew to 192.168.22.1 \
Wed Oct 3 20:16:00 2018 daemon.notice netifd: wan (3610): udhcpc: lease of \
10.98.21.140 obtained, lease time 120 Wed Oct 3 20:17:00 2018 daemon.notice netifd: \
wan (3610): udhcpc: sending renew to 192.168.22.1 Wed Oct 3 20:17:00 2018 \
daemon.notice netifd: wan (3610): udhcpc: lease of 10.98.21.140 obtained, lease time \
120
Thanks,
Tomas
[Attachment #5 (text/html)]
<p style="padding:0 0 0 0; margin:0 0 0 0;">Hello all,</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">busybox 1.28.3-4 (OpenWrt 18.06.1) \
running on a WiFi router, requesting IP address from 4G router (Huawei B2338-168) \
running in IPv4 passtrough mode. In this mode, 4G router is assigning the the same IP \
address it got from ISP (mobile network operator), lease time is 120 seconds. Because \
first renew request is sent after 60 seconds, it is broadcasted (= REBINDING state); \
RENEWING state is skipped:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: \
x-small;">...</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-family: courier new; \
font-size: x-small;"> case \
RENEWING:</span><br /> <span style="font-family: courier new; font-size: \
x-small;"> \
if (timeout > 60) {</span><br /> <span style="font-size: x-small;"><span \
style="font-family: courier new;"> \
/* send an unicast renew \
request */</span><span style="font-family: courier new;"></span></span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: \
x-small;">...</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">4G router drops broadcasted renew request \
and after lease is expired, WiFi router releases the IP address and enters init \
state:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-family: courier new; \
font-size: x-small;">Wed Oct 3 19:02:39 2018 user.notice firewall: Reloading \
firewall due to ifup of wan (eth1)</span><br /> <span style="font-family: courier \
new; font-size: x-small;">Wed Oct 3 19:03:37 2018 daemon.notice netifd: wan \
(1166): udhcpc: sending renew to 0.0.0.0</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:07 2018 daemon.notice netifd: \
wan (1166): udhcpc: sending renew to 0.0.0.0</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:22 2018 daemon.notice netifd: \
wan (1166): udhcpc: sending renew to 0.0.0.0</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:29 2018 daemon.notice netifd: \
wan (1166): udhcpc: sending renew to 0.0.0.0</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:32 2018 daemon.notice netifd: \
wan (1166): udhcpc: sending renew to 0.0.0.0</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:33 2018 daemon.notice netifd: \
wan (1166): udhcpc: sending renew to 0.0.0.0</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:33 2018 daemon.notice netifd: \
wan (1166): udhcpc: lease lost, entering init state</span><br /> <span \
style="font-family: courier new; font-size: x-small;">Wed Oct 3 19:04:34 2018 \
daemon.notice netifd: Interface 'wan' has lost the connection</span><br /> <span \
style="font-family: courier new; font-size: x-small;">Wed Oct 3 19:04:34 2018 \
daemon.notice netifd: wan (1166): udhcpc: sending select for 10.98.21.140</span><br \
/> <span style="font-family: courier new; font-size: x-small;">Wed Oct 3 \
19:04:34 2018 daemon.notice netifd: wan (1166): udhcpc: lease of 10.98.21.140 \
obtained, lease time 120</span><br /> <span style="font-family: courier new; \
font-size: x-small;">Wed Oct 3 19:04:34 2018 daemon.err openvpn(******)[1539]: \
write UDP: Network unreachable (code=128)</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:34 2018 daemon.warn \
dnsmasq[1511]: no servers found in /tmp/resolv.conf.auto, will retry</span><br /> \
<span style="font-family: courier new; font-size: x-small;">Wed Oct 3 19:04:35 \
2018 daemon.notice netifd: Interface 'wan' is now up</span><br /> <span \
style="font-family: courier new; font-size: x-small;">Wed Oct 3 19:04:35 2018 \
daemon.info dnsmasq[1511]: reading /tmp/resolv.conf.auto</span><br /> <span \
style="font-family: courier new; font-size: x-small;">Wed Oct 3 19:04:35 2018 \
daemon.info dnsmasq[1511]: using local addresses only for domain test</span><br /> \
<span style="font-family: courier new; font-size: x-small;">Wed Oct 3 19:04:35 \
2018 daemon.info dnsmasq[1511]: using local addresses only for domain onion</span><br \
/> <span style="font-family: courier new; font-size: x-small;">Wed Oct 3 \
19:04:35 2018 daemon.info dnsmasq[1511]: using local addresses only for domain \
localhost</span><br /> <span style="font-family: courier new; font-size: \
x-small;">Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using local \
addresses only for domain local</span><br /> <span style="font-family: courier new; \
font-size: x-small;">Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using \
local addresses only for domain invalid</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 19:04:35 2018 daemon.info \
dnsmasq[1511]: using local addresses only for domain bind</span><br /> <span \
style="font-family: courier new; font-size: x-small;">Wed Oct 3 19:04:35 2018 \
daemon.info dnsmasq[1511]: using nameserver 192.168.11.254#53 for domain \
***</span><br /> <span style="font-family: courier new; font-size: x-small;">Wed \
Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using local addresses only for \
domain *****</span><br /> <span style="font-family: courier new; font-size: \
x-small;">Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using nameserver \
160.218.161.60#53</span><br /> <span style="font-family: courier new; font-size: \
x-small;">Wed Oct 3 19:04:35 2018 daemon.info dnsmasq[1511]: using nameserver \
160.218.167.5#53</span><br /> <span style="font-family: courier new; font-size: \
x-small;">Wed Oct 3 19:04:36 2018 user.notice firewall: Reloading firewall due \
to ifup of wan (eth1)</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">So each 2 minutes wan connectivity is \
lost for a fraction of second.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">I'd propose to perform at least one \
unicast renew reques irrespective of lease time, proposed patch:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-family: courier new; \
font-size: x-small;">diff --git a/networking/udhcp/dhcpc.c \
b/networking/udhcp/dhcpc.c</span><br /> <span style="font-family: courier new; \
font-size: x-small;">index fd18325..01241ca 100644</span><br /> <span \
style="font-family: courier new; font-size: x-small;">--- \
a/networking/udhcp/dhcpc.c</span><br /> <span style="font-family: courier new; \
font-size: x-small;">+++ b/networking/udhcp/dhcpc.c</span><br /> <span \
style="font-family: courier new; font-size: x-small;">@@ -1414,6 +1414,7 @@ int \
udhcpc_main(int argc UNUSED_PARAM, char **argv)</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;"> \
struct dhcp_packet packet;</span><br /> <span style="font-family: courier new; \
font-size: x-small;"> \
/* silence "uninitialized!" warning */</span><br /> <span style="font-family: courier \
new; font-size: x-small;"> \
unsigned timestamp_before_wait = timestamp_before_wait;</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;">+ \
uint32_t unicast_renew_attempt = 0;</span><br /> <br />
<span style="font-family: courier new; font-size: \
x-small;"> \
//bb_error_msg("sockfd:%d, listen_mode:%d", sockfd, listen_mode);</span><br /> \
<br /> <span style="font-family: courier new; font-size: x-small;">@@ -1468,6 \
+1469,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)</span><br /> <br \
/> <span style="font-family: courier new; font-size: \
x-small;"> \
switch (state) {</span><br /> <span style="font-family: courier new; font-size: \
x-small;"> \
case INIT_SELECTING:</span><br /> <span style="font-family: courier new; font-size: \
x-small;">+ &nb \
sp; \
unicast_renew_attempt = 0;</span><br /> <span style="font-family: courier new; \
font-size: x-small;">   \
; \
if (!discover_retries || packet_num < discover_retries) {</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;"> &nbs \
p; \
if (packet_num == 0)</span><br /> <span style="font-family: courier new; font-size: \
x-small;"> &nbs \
p; \
\
xid = random_xid();</span><br /> <span style="font-family: courier new; font-size: \
x-small;">@@ -1521,8 +1523,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char \
**argv)</span><br /> <span style="font-family: courier new; font-size: \
x-small;"> \
case RENEW_REQUESTED: /* manual (SIGUSR1) renew */</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;"> \
case_RENEW_REQUESTED:</span><br /> <span style="font-family: courier new; font-size: \
x-small;"> \
case RENEWING:</span><br /> <span style="font-family: courier new; font-size: \
x-small;">- &nb \
sp; \
if (timeout > 60) {</span><br /> <span style="font-family: courier new; font-size: \
x-small;">+ &nb \
sp; \
/* we should try to send at least one unicast renew request */</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;">+ &nb \
sp; \
if (timeout > 60 || !unicast_renew_attempt) {</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;"> &nbs \
p; \
/* send an unicast renew request */</span><br /> <span style="font-family: courier \
new; font-size: x-small;">+   \
; & \
nbsp; \
unicast_renew_attempt = 1;</span><br /> <span style="font-family: courier new; \
font-size: x-small;"> \
/* Sometimes observed to fail (EADDRNOTAVAIL) to bind</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;"> \
* a new UDP socket for sending inside send_renew.</span><br /> <span \
style="font-family: courier new; font-size: \
x-small;"> \
* I hazard to guess existing listening socket</span><br /> <br />
</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">After applying patch, unicast renew \
request towards Huawei 4G router works as expected:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-family: courier new; \
font-size: x-small;">Wed Oct 3 20:12:58 2018 daemon.notice netifd: wan (3610): \
udhcpc: sending renew to 192.168.22.1</span><br /> <span style="font-family: courier \
new; font-size: x-small;">Wed Oct 3 20:12:58 2018 daemon.notice netifd: wan \
(3610): udhcpc: lease of 10.98.21.140 obtained, lease time 120</span><br /> <span \
style="font-family: courier new; font-size: x-small;">Wed Oct 3 20:13:58 2018 \
daemon.notice netifd: wan (3610): udhcpc: sending renew to 192.168.22.1</span><br /> \
<span style="font-family: courier new; font-size: x-small;">Wed Oct 3 20:13:59 \
2018 daemon.notice netifd: wan (3610): udhcpc: lease of 10.98.21.140 obtained, lease \
time 120</span><br /> <span style="font-family: courier new; font-size: x-small;">Wed \
Oct 3 20:14:59 2018 daemon.notice netifd: wan (3610): udhcpc: sending renew to \
192.168.22.1</span><br /> <span style="font-family: courier new; font-size: \
x-small;">Wed Oct 3 20:14:59 2018 daemon.notice netifd: wan (3610): udhcpc: \
lease of 10.98.21.140 obtained, lease time 120</span><br /> <span style="font-family: \
courier new; font-size: x-small;">Wed Oct 3 20:16:00 2018 daemon.notice netifd: \
wan (3610): udhcpc: sending renew to 192.168.22.1</span><br /> <span \
style="font-family: courier new; font-size: x-small;">Wed Oct 3 20:16:00 2018 \
daemon.notice netifd: wan (3610): udhcpc: lease of 10.98.21.140 obtained, lease time \
120</span><br /> <span style="font-family: courier new; font-size: x-small;">Wed \
Oct 3 20:17:00 2018 daemon.notice netifd: wan (3610): udhcpc: sending renew to \
192.168.22.1</span><br /> <span style="font-family: courier new; font-size: \
x-small;">Wed Oct 3 20:17:00 2018 daemon.notice netifd: wan (3610): udhcpc: \
lease of 10.98.21.140 obtained, lease time 120</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">Thanks,</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">Tomas</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic