Re: udhcpc: udhcpc skips RENEWING state when lease time is short
Thanks! Works fine, just "lease time 122" (instead of 120) appears in log but this is just cosmetic. Tomas __ Od: "Denys Vlasenko" Komu: t.tonhau...@pobox.sk Dátum: 30.10.2018 11:57 Predmet: Re: udhcpc: udhcpc skips RENEWING state when lease time is short CC: 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 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 0x 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 > 0x7fff) // lease_seconds = 0x7fff; //^^^not necessary since "timeout = lease_seconds / 2" On Wed, Oct 3, 2018 at 10:06 PM Tomas Tonhauser 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 >
Re: [PATCH] libarchive: add a function to unpack embedded data
Sam Liddicott wrote: >Will that support an embedded .profile there as well? It doesn't currently. I looked into it briefly and it should be possible. Ron ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH] libarchive: add a function to unpack embedded data
Will that support an embedded .profile there as well? Sam On Fri, 2 Nov 2018 at 13:19, Denys Vlasenko wrote: > Applied, thanks! > On Fri, Nov 2, 2018 at 9:34 AM Ron Yorston wrote: > > > > Similar code to unpack embedded data is used to decompress usage > > messages, embedded scripts and the config file (in the non-default > > bbconfig applet). > > > > Moving this code to a common function reduces the size of the default > > build and hides more of the internals of libarchive. > > > > function old new delta > > unpack_bz2_data- 135+135 > > bb_show_usage137 157 +20 > > get_script_content32 47 +15 > > unpack_scripts 119 --119 > > unpack_usage_messages124 --124 > > > -- > > (add/remove: 1/2 grow/shrink: 2/0 up/down: 170/-243) Total: -73 > bytes > > > > Signed-off-by: Ron Yorston > > --- > > archival/libarchive/decompress_bunzip2.c | 38 +-- > > include/bb_archive.h | 7 +- > > libbb/appletlib.c| 81 +--- > > miscutils/bbconfig.c | 27 ++-- > > 4 files changed, 54 insertions(+), 99 deletions(-) > > > > diff --git a/archival/libarchive/decompress_bunzip2.c > b/archival/libarchive/decompress_bunzip2.c > > index 7ef4e035f..3deb213a8 100644 > > --- a/archival/libarchive/decompress_bunzip2.c > > +++ b/archival/libarchive/decompress_bunzip2.c > > @@ -107,7 +107,7 @@ struct bunzip_data { > > uint8_t selectors[32768]; /* nSelectors=15 bits */ > > struct group_data groups[MAX_GROUPS]; /* Huffman coding tables > */ > > }; > > -/* typedef struct bunzip_data bunzip_data; -- done in .h file */ > > +typedef struct bunzip_data bunzip_data; > > > > > > /* Return the next nnn bits of input. All reads from the compressed > input > > @@ -575,7 +575,7 @@ static int get_next_block(bunzip_data *bd) > > in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not > 0. > > (Why? This allows to get rid of one local variable) > > */ > > -int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) > > +static int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) > > { > > const uint32_t *dbuf; > > int pos, current, previous; > > @@ -699,7 +699,7 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char > *outbuf, int len) > > /* Because bunzip2 is used for help text unpacking, and because > bb_show_usage() > > should work for NOFORK applets too, we must be extremely careful to > not leak > > any allocations! */ > > -int FAST_FUNC start_bunzip( > > +static int FAST_FUNC start_bunzip( > > void *jmpbuf, > > bunzip_data **bdp, > > int in_fd, > > @@ -759,7 +759,7 @@ int FAST_FUNC start_bunzip( > > return RETVAL_OK; > > } > > > > -void FAST_FUNC dealloc_bunzip(bunzip_data *bd) > > +static void FAST_FUNC dealloc_bunzip(bunzip_data *bd) > > { > > free(bd->dbuf); > > free(bd); > > @@ -847,6 +847,36 @@ unpack_bz2_stream(transformer_state_t *xstate) > > return i ? i : IF_DESKTOP(total_written) + 0; > > } > > > > +const char * FAST_FUNC > > +unpack_bz2_data(const char *packed, int packed_len, int unpacked_len) > > +{ > > + char *outbuf = NULL; > > + bunzip_data *bd; > > + int i; > > + jmp_buf jmpbuf; > > + > > + /* Setup for I/O error handling via longjmp */ > > + i = setjmp(jmpbuf); > > + if (i == 0) { > > + i = start_bunzip(, > > + , > > + /* src_fd: */ -1, > > + /* inbuf: */ packed, > > + /* len:*/ packed_len > > + ); > > + } > > + /* read_bunzip can longjmp and end up here with i != 0 > > +* on read data errors! Not trivial */ > > + if (i == 0) { > > + /* Cannot use xmalloc: will leak bd in NOFORK case! */ > > + outbuf = malloc_or_warn(unpacked_len); > > + if (outbuf) > > + read_bunzip(bd, outbuf, unpacked_len); > > + } > > + dealloc_bunzip(bd); > > + return outbuf; > > +} > > + > > #ifdef TESTING > > > > static char *const bunzip_errors[] = { > > diff --git a/include/bb_archive.h b/include/bb_archive.h > > index d2022336b..0dbe17496 100644 > > --- a/include/bb_archive.h > > +++ b/include/bb_archive.h > > @@ -214,12 +214,7 @@ const llist_t *find_list_entry(const llist_t *list, > const char *filename) FAST_F > > const llist_t *find_list_entry2(const llist_t *list, const char > *filename) FAST_FUNC; > > > > /* A bit of bunzip2 internals are exposed for
Re: [PATCH] libarchive: add a function to unpack embedded data
Applied, thanks! On Fri, Nov 2, 2018 at 9:34 AM Ron Yorston wrote: > > Similar code to unpack embedded data is used to decompress usage > messages, embedded scripts and the config file (in the non-default > bbconfig applet). > > Moving this code to a common function reduces the size of the default > build and hides more of the internals of libarchive. > > function old new delta > unpack_bz2_data- 135+135 > bb_show_usage137 157 +20 > get_script_content32 47 +15 > unpack_scripts 119 --119 > unpack_usage_messages124 --124 > -- > (add/remove: 1/2 grow/shrink: 2/0 up/down: 170/-243) Total: -73 bytes > > Signed-off-by: Ron Yorston > --- > archival/libarchive/decompress_bunzip2.c | 38 +-- > include/bb_archive.h | 7 +- > libbb/appletlib.c| 81 +--- > miscutils/bbconfig.c | 27 ++-- > 4 files changed, 54 insertions(+), 99 deletions(-) > > diff --git a/archival/libarchive/decompress_bunzip2.c > b/archival/libarchive/decompress_bunzip2.c > index 7ef4e035f..3deb213a8 100644 > --- a/archival/libarchive/decompress_bunzip2.c > +++ b/archival/libarchive/decompress_bunzip2.c > @@ -107,7 +107,7 @@ struct bunzip_data { > uint8_t selectors[32768]; /* nSelectors=15 bits */ > struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */ > }; > -/* typedef struct bunzip_data bunzip_data; -- done in .h file */ > +typedef struct bunzip_data bunzip_data; > > > /* Return the next nnn bits of input. All reads from the compressed input > @@ -575,7 +575,7 @@ static int get_next_block(bunzip_data *bd) > in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0. > (Why? This allows to get rid of one local variable) > */ > -int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) > +static int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) > { > const uint32_t *dbuf; > int pos, current, previous; > @@ -699,7 +699,7 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, > int len) > /* Because bunzip2 is used for help text unpacking, and because > bb_show_usage() > should work for NOFORK applets too, we must be extremely careful to not > leak > any allocations! */ > -int FAST_FUNC start_bunzip( > +static int FAST_FUNC start_bunzip( > void *jmpbuf, > bunzip_data **bdp, > int in_fd, > @@ -759,7 +759,7 @@ int FAST_FUNC start_bunzip( > return RETVAL_OK; > } > > -void FAST_FUNC dealloc_bunzip(bunzip_data *bd) > +static void FAST_FUNC dealloc_bunzip(bunzip_data *bd) > { > free(bd->dbuf); > free(bd); > @@ -847,6 +847,36 @@ unpack_bz2_stream(transformer_state_t *xstate) > return i ? i : IF_DESKTOP(total_written) + 0; > } > > +const char * FAST_FUNC > +unpack_bz2_data(const char *packed, int packed_len, int unpacked_len) > +{ > + char *outbuf = NULL; > + bunzip_data *bd; > + int i; > + jmp_buf jmpbuf; > + > + /* Setup for I/O error handling via longjmp */ > + i = setjmp(jmpbuf); > + if (i == 0) { > + i = start_bunzip(, > + , > + /* src_fd: */ -1, > + /* inbuf: */ packed, > + /* len:*/ packed_len > + ); > + } > + /* read_bunzip can longjmp and end up here with i != 0 > +* on read data errors! Not trivial */ > + if (i == 0) { > + /* Cannot use xmalloc: will leak bd in NOFORK case! */ > + outbuf = malloc_or_warn(unpacked_len); > + if (outbuf) > + read_bunzip(bd, outbuf, unpacked_len); > + } > + dealloc_bunzip(bd); > + return outbuf; > +} > + > #ifdef TESTING > > static char *const bunzip_errors[] = { > diff --git a/include/bb_archive.h b/include/bb_archive.h > index d2022336b..0dbe17496 100644 > --- a/include/bb_archive.h > +++ b/include/bb_archive.h > @@ -214,12 +214,7 @@ const llist_t *find_list_entry(const llist_t *list, > const char *filename) FAST_F > const llist_t *find_list_entry2(const llist_t *list, const char *filename) > FAST_FUNC; > > /* A bit of bunzip2 internals are exposed for compressed help support: */ > -typedef struct bunzip_data bunzip_data; > -int start_bunzip(void *, bunzip_data **bdp, int in_fd, const void *inbuf, > int len) FAST_FUNC; > -/* NB: read_bunzip returns < 0 on error, or the number of *unfilled* bytes > - * in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0: */ > -int
[PATCH] libarchive: add a function to unpack embedded data
Similar code to unpack embedded data is used to decompress usage messages, embedded scripts and the config file (in the non-default bbconfig applet). Moving this code to a common function reduces the size of the default build and hides more of the internals of libarchive. function old new delta unpack_bz2_data- 135+135 bb_show_usage137 157 +20 get_script_content32 47 +15 unpack_scripts 119 --119 unpack_usage_messages124 --124 -- (add/remove: 1/2 grow/shrink: 2/0 up/down: 170/-243) Total: -73 bytes Signed-off-by: Ron Yorston --- archival/libarchive/decompress_bunzip2.c | 38 +-- include/bb_archive.h | 7 +- libbb/appletlib.c| 81 +--- miscutils/bbconfig.c | 27 ++-- 4 files changed, 54 insertions(+), 99 deletions(-) diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c index 7ef4e035f..3deb213a8 100644 --- a/archival/libarchive/decompress_bunzip2.c +++ b/archival/libarchive/decompress_bunzip2.c @@ -107,7 +107,7 @@ struct bunzip_data { uint8_t selectors[32768]; /* nSelectors=15 bits */ struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */ }; -/* typedef struct bunzip_data bunzip_data; -- done in .h file */ +typedef struct bunzip_data bunzip_data; /* Return the next nnn bits of input. All reads from the compressed input @@ -575,7 +575,7 @@ static int get_next_block(bunzip_data *bd) in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0. (Why? This allows to get rid of one local variable) */ -int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) +static int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) { const uint32_t *dbuf; int pos, current, previous; @@ -699,7 +699,7 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) /* Because bunzip2 is used for help text unpacking, and because bb_show_usage() should work for NOFORK applets too, we must be extremely careful to not leak any allocations! */ -int FAST_FUNC start_bunzip( +static int FAST_FUNC start_bunzip( void *jmpbuf, bunzip_data **bdp, int in_fd, @@ -759,7 +759,7 @@ int FAST_FUNC start_bunzip( return RETVAL_OK; } -void FAST_FUNC dealloc_bunzip(bunzip_data *bd) +static void FAST_FUNC dealloc_bunzip(bunzip_data *bd) { free(bd->dbuf); free(bd); @@ -847,6 +847,36 @@ unpack_bz2_stream(transformer_state_t *xstate) return i ? i : IF_DESKTOP(total_written) + 0; } +const char * FAST_FUNC +unpack_bz2_data(const char *packed, int packed_len, int unpacked_len) +{ + char *outbuf = NULL; + bunzip_data *bd; + int i; + jmp_buf jmpbuf; + + /* Setup for I/O error handling via longjmp */ + i = setjmp(jmpbuf); + if (i == 0) { + i = start_bunzip(, + , + /* src_fd: */ -1, + /* inbuf: */ packed, + /* len:*/ packed_len + ); + } + /* read_bunzip can longjmp and end up here with i != 0 +* on read data errors! Not trivial */ + if (i == 0) { + /* Cannot use xmalloc: will leak bd in NOFORK case! */ + outbuf = malloc_or_warn(unpacked_len); + if (outbuf) + read_bunzip(bd, outbuf, unpacked_len); + } + dealloc_bunzip(bd); + return outbuf; +} + #ifdef TESTING static char *const bunzip_errors[] = { diff --git a/include/bb_archive.h b/include/bb_archive.h index d2022336b..0dbe17496 100644 --- a/include/bb_archive.h +++ b/include/bb_archive.h @@ -214,12 +214,7 @@ const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_F const llist_t *find_list_entry2(const llist_t *list, const char *filename) FAST_FUNC; /* A bit of bunzip2 internals are exposed for compressed help support: */ -typedef struct bunzip_data bunzip_data; -int start_bunzip(void *, bunzip_data **bdp, int in_fd, const void *inbuf, int len) FAST_FUNC; -/* NB: read_bunzip returns < 0 on error, or the number of *unfilled* bytes - * in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0: */ -int read_bunzip(bunzip_data *bd, char *outbuf, int len) FAST_FUNC; -void dealloc_bunzip(bunzip_data *bd) FAST_FUNC; +const char *unpack_bz2_data(const char *packed, int packed_len, int unpacked_len) FAST_FUNC; /* Meaning and direction (input/output) of the fields are transformer-specific */ typedef struct