Re: udhcpc: udhcpc skips RENEWING state when lease time is short

Tomas Tonhauser t.tonhauser at pobox.sk
Fri Nov 2 20:08:12 UTC 2018


Thanks!
Works fine, just "lease time 122" (instead of 120) appears in log but this is just cosmetic.
Tomas
 
______________________________________________________________
> Od: "Denys Vlasenko" <vda.linux at googlemail.com>
> Komu: t.tonhauser at pobox.sk
> Dátum: 30.10.2018 11:57
> Predmet: Re: udhcpc: udhcpc skips RENEWING state when lease time is short
>
> CC: <busybox at busybox.net>
Should be fixed by:
 
 commit c05aa6a776ab2420a42c041a3b5d45db587fd9ef
 Date:   Tue Oct 30 11:56:18 2018 +0100
 
    udhcpc: ensure at least one unicast renew attempt
 
    Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
 
 diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
 index 66e4b6c6a..e2f8a6a9c 100644
 --- a/networking/udhcp/d6_dhcpc.c
 +++ b/networking/udhcp/d6_dhcpc.c
 @@ -1738,8 +1738,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
                                /* note: "int timeout" will not
 overflow even with 0xffffffff inputs here: */
                                timeout = (prefix_timeout <
 address_timeout ? prefix_timeout : address_timeout) / 2;
                                /* paranoia: must not be too small */
 -                               if (timeout < 0x10)
 -                                       timeout = 0x10;
 +                               /* timeout > 60 - ensures at least one
 unicast renew attempt */
 +                               if (timeout < 61)
 +                                       timeout = 61;
                                /* enter bound state */
                                d6_run_script(packet.d6_options, packet_end,
                                        (state == REQUESTING ? "bound"
 : "renew"));
 diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
 index ab3e5a463..d2f165904 100644
 --- a/networking/udhcp/dhcpc.c
 +++ b/networking/udhcp/dhcpc.c
 @@ -1725,8 +1725,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
 
 move_from_unaligned32(lease_seconds, temp);
                                        lease_seconds = ntohl(lease_seconds);
                                        /* paranoia: must not be too
 small and not prone to overflows */
 -                                       if (lease_seconds < 0x10)
 -                                               lease_seconds = 0x10;
 +                                       /* timeout > 60 - ensures at
 least one unicast renew attempt */
 +                                       if (lease_seconds < 2 * 61)
 +                                               lease_seconds = 2 * 61;
                                        //if (lease_seconds > 0x7fffffff)
                                        //      lease_seconds = 0x7fffffff;
                                        //^^^not necessary since
 "timeout = lease_seconds / 2"
 On Wed, Oct 3, 2018 at 10:06 PM Tomas Tonhauser <t.tonhauser at pobox.sk> wrote:
 >
 > 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
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 > _______________________________________________
 > busybox mailing list
 > busybox at busybox.net
 > http://lists.busybox.net/mailman/listinfo/busybox <http://lists.busybox.net/mailman/listinfo/busybox>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20181102/61c34c94/attachment-0001.html>


More information about the busybox mailing list