summaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
AgeCommit message (Collapse)Author
2021-06-16*: more --help tweaksDenys Vlasenko
function old new delta packed_usage 33522 33534 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15udhcpc: do not use inet_addr() to parse -r REQ_IP, it's deprecatedDenys Vlasenko
...and we did not error-check it, and this is the only use of it: function old new delta inet_addr 37 - -37 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15udhcpc: rename server_addr to server_id, fix id comparison if it's not specifiedDenys Vlasenko
Even though it is _meant to be_ an IP address, in the wild servers sometimes give bogus server ids, like 1.1.1.1 function old new delta udhcpc_main 2551 2542 -9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15udhcpc[6]: do not pass xid around, keep it in client_data.xidDenys Vlasenko
function old new delta perform_release 105 169 +64 perform_d6_release 259 262 +3 init_d6_packet 84 85 +1 send_d6_discover 286 285 -1 send_d6_select 128 126 -2 send_d6_renew 176 174 -2 send_d6_info_request 65 63 -2 udhcpc_main 2555 2551 -4 send_select 130 122 -8 send_renew 99 91 -8 send_discover 89 81 -8 udhcpc6_main 2636 2602 -34 send_release 74 - -74 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 3/9 up/down: 68/-143) Total: -75 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15udhcpc: send client-id option in DHCPDECLINEDenys Vlasenko
function old new delta add_serverid_and_clientid_options - 46 +46 send_decline 88 83 -5 perform_release 200 159 -41 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 46/-46) Total: 0 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-05udhcpc: revert deprecation message for -VDenys Vlasenko
"-x vendor:VENDOR" will not be a trivial replacement of it: (1) by default, we do send a vendor string ("udhcp BB_VER"), will need code to preserve the default. (2) -V '' currently disables vendor string. -x vendor:'' would not easily achieve that: it adds no option at all (string options can't be empty), and default (1) would trigger. To avoid that, we will need yet another hack to detect -x vendor:'' and interpret that as "no vendor string at all". IOW: removing -V is likely to increase code size, not decrease. function old new delta udhcpc_main 2563 2555 -8 .rodata 103251 103198 -53 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-61) Total: -61 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-03udhcpc[6]: on SIGUSR1, do not go from rebind to renew stateDenys Vlasenko
function old new delta udhcpc6_main 2628 2636 +8 udhcpc_main 2556 2563 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 15/0) Total: 15 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-03udhcpc: code shrink, rename functions, no logic changesDenys Vlasenko
function old new delta d4_run_script - 739 +739 d4_recv_raw_packet - 484 +484 d4_run_script_deconfig - 12 +12 perform_release 207 200 -7 udhcpc_main 2598 2556 -42 udhcp_recv_raw_packet 484 - -484 udhcp_run_script 739 - -739 ------------------------------------------------------------------------------ (add/remove: 3/2 grow/shrink: 0/2 up/down: 1235/-1272) Total: -37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-03udhcpc[6]: when renewing, send 1 packet (not 3), on failure go back to BOUNDDenys Vlasenko
This restores old behavior where we slept for 1/2 of lease, then tried renewing, thel slept for 1/4 and tried again, etc. But now we will NOT be listening to all packets for 1/2 of lease time, processing (rejecting) everyone else's DHCP traffic. We'll go back to bound state, where we have no listening socket at all. function old new delta udhcpc6_main 2600 2655 +55 udhcpc_main 2608 2625 +17 .rodata 103250 103249 -1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 72/-1) Total: 71 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02udhcpc[6]: remove superfluous "created raw socket" log messageDenys Vlasenko
function old new delta change_listen_mode 299 280 -19 .rodata 103272 103250 -22 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-41) Total: -41 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02udhcpc: improve logs - show offer as it is receivedDenys Vlasenko
function old new delta udhcpc_main 2566 2608 +42 .rodata 103248 103272 +24 udhcp_recv_raw_packet 559 562 +3 d6_recv_raw_packet 254 255 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 70/0) Total: 70 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02udhcpc[6]: close listening socket more eagerly (e.g. across script runs)Denys Vlasenko
function old new delta udhcpc6_main 2571 2600 +29 udhcpc_main 2588 2566 -22 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 29/-22) Total: 7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02udhcpc: get rid of client_data.fqdn fieldDenys Vlasenko
function old new delta attach_option 253 276 +23 udhcpc_main 2582 2588 +6 udhcpc6_main 2579 2571 -8 add_client_options 175 158 -17 udhcp_insert_new_option 169 138 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/3 up/down: 29/-56) Total: -27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02udhcpc: remove deprecated -H/-h HOSTNAME options (9 years), deprecate -V VENDORDenys Vlasenko
function old new delta udhcpc_main 2563 2582 +19 dhcp_option_strings 294 301 +7 dhcp_optflags 80 82 +2 .rodata 103250 103248 -2 udhcpc_longopts 252 241 -11 add_client_options 209 175 -34 alloc_dhcp_option 59 - -59 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 3/3 up/down: 28/-106) Total: -78 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02udhcpc: include client-id option in DECLINEs, even if it's a custom -x ↵Denys Vlasenko
61:HEX option client_data.vendorclass, .hostname and .fqdn probably need the same treatment: just insert them into the list of -x opts, get rid of if (client_data.vendorclass) udhcp_add_binary_option(packet, client_data.vendorclass); if (client_data.hostname) udhcp_add_binary_option(packet, client_data.hostname); if (client_data.fqdn) udhcp_add_binary_option(packet, client_data.fqdn); function old new delta udhcp_insert_new_option - 166 +166 perform_release 171 207 +36 perform_d6_release 227 259 +32 udhcpc6_main 2558 2580 +22 init_d6_packet 103 84 -19 udhcpc_main 2585 2564 -21 attach_option 397 253 -144 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/3 up/down: 256/-184) Total: 72 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-01udhcpc[6]: fix "untangle timeout and remaining lease" falloutDenys Vlasenko
As reported in bug 13776, before this fix the renew never times out. function old new delta udhcpc_main 2541 2585 +44 udhcpc6_main 2567 2558 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 44/-9) Total: 35 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-05-01udhcpc[6]: fold perform_renew() into its only callerDenys Vlasenko
function old new delta udhcpc_main 2550 2541 -9 udhcpc6_main 2576 2567 -9 change_listen_mode 321 299 -22 .rodata 103294 103225 -69 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-109) Total: -109 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-05-01udhcpc[6]: untangle "timeout" and "remaining lease"; reduce min lease to 30 ↵Denys Vlasenko
seconds This allows to fix a problem that we wait for renew replies for up to half the lease (!!!) if they never come. Make it so that lease of 60 seconds is not "rounded up" to 120 seconds - set lower "sanity limit" to 30 seconds. After 3 failed renew attempts, switch to rebind. After this change, we can have more flexible choice of when to do the first renew - does not need to be equal to lease / 2. function old new delta udhcpc6_main 2568 2576 +8 .rodata 103339 103294 -45 udhcpc_main 2609 2550 -59 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 8/-104) Total: -96 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21udhcp: reuse stringsDenys Vlasenko
text data bss dec hex filename 1019916 559 5020 1025495 fa5d7 busybox_old 1019906 559 5020 1025485 fa5cd busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-20udhcpc: clarify bcast/unicast sends in logs, include server IDDenys Vlasenko
Before: sending discover sending select for 192.168.1.173 lease of 192.168.1.173 obtained, lease time 43200 sending renew to 192.168.1.1 lease of 192.168.1.173 obtained, lease time 43200 After: broadcasting discover broadcasting select for 192.168.1.173, server 192.168.1.1 lease of 192.168.1.173 obtained from 192.168.1.1, lease time 43200 sending renew to server 192.168.1.1 lease of 192.168.1.173 obtained from 192.168.1.1, lease time 43200 function old new delta udhcpc_main 2580 2610 +30 send_select 104 130 +26 send_renew 82 99 +17 send_discover 94 89 -5 send_decline 93 88 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/2 up/down: 73/-10) Total: 63 bytes text data bss dec hex filename 1019732 559 5020 1025311 fa51f busybox_old 1019898 559 5020 1025477 fa5c5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01udhcpc: Add support to change default interface nameAndre Kalb
Signed-off-by: Andre Kalb <Andre.Kalb@sma.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15udhcp: bind to device even for ucast packetsMichal Kazior
There are cases where binding to source IP and destination IP is insufficient to guarantee sane xmit netdev. One case where this can fail is when route-matching netdev carrier is down (cable unplugged, wifi disconnected), or the netdev is admin down. Then all the IP based bindings (bind() + connect()) will seemingly succeed but the actual packet can go out through a default gw path. Depending on the network this happens on it can create issues or false alarms. It can also leak some subnet info across networks that shouldn't be routed. As such better be safe than sorry and bind to a netdev to be sure it's used for xmit. function old new delta udhcp_send_kernel_packet 293 336 +43 send_packet 182 188 +6 bcast_or_ucast 37 43 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 55/0) Total: 55 bytes Signed-off-by: Michal Kazior <michal@plume.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01gcc-9.x warning fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-13udhcpc: add support for long optionsMartin Lewis
Duplicate options are currently overridden (only the last option is kept). This leads to unexpected behavior when using long options. The patch adds support for long options in compliance with RFC 3396. Fixes #13136. function old new delta udhcp_run_script 601 725 +124 optitem_unset_env_and_free - 38 +38 putenvp 46 59 +13 static.xmalloc_optname_optval 718 717 -1 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/1 up/down: 175/-1) Total: 174 bytes Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29udhcpc: fix a TODO in fill_envp using option scannerMartin Lewis
fill_envp now iterates over the packet only once instead of a few hundred times using the new option scanner. function old new delta udhcp_scan_options - 189 +189 putenvp - 46 +46 init_scan_state - 22 +22 udhcp_get_option 227 104 -123 udhcp_run_script 835 601 -234 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 0/2 up/down: 257/-357) Total: -100 bytes Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09dhcpc: refactor xmalloc_optname_optval to shrink binary sizeMartin Lewis
function old new delta len_of_option_as_string 14 13 -1 dhcp_option_lengths 14 13 -1 udhcp_str2optset 641 637 -4 static.xmalloc_optname_optval 777 718 -59 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-65) Total: -65 bytes Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09dhcpc: code shrink in good_hostnameMartin Lewis
Incorporated valid_domain_label into good_hostname to simplify the implementation. function old new delta static.xmalloc_optname_optval 973 958 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-15) Total: -15 bytes text data bss dec hex filename 993144 16915 1872 1011931 f70db busybox_old 993129 16915 1872 1011916 f70cc busybox_unstripped Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-24udhcpc6: add ELAPSED_TIME option to outgoing packetsDenys Vlasenko
function old new delta init_d6_packet 53 121 +68 udhcpc_main 2577 2582 +5 udhcpc6_main 2593 2597 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 77/0) Total: 77 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-13udhcpc: fix comment, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-11dhcpc.c: Added support for relay server parameter.Martin Lewis
Resolved a TODO by adding support for gateway_nip parameter. function old new delta udhcp_run_script 792 835 +43 Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-31dhcp: downgrade "got raw socket fd" message to log3, make log2 default maxDenys Vlasenko
log3 messages are very much redundant function old new delta change_listen_mode 322 302 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-31dhcp: get rid of static data signal_pipeDenys Vlasenko
function old new delta udhcp_sp_setup 65 110 +45 udhcp_sp_fd_set 60 59 -1 udhcpd_main 1442 1437 -5 udhcpc_main 2684 2679 -5 signal_pipe 8 - -8 packed_usage 33292 33284 -8 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/4 up/down: 45/-27) Total: 18 bytes text data bss dec hex filename 952746 481 7296 960523 ea80b busybox_old 952768 481 7288 960537 ea819 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-26udhcp: rename client_config to client_data, server_config to server_dataDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-26dhcp: get rid of last global dataDenys Vlasenko
function old new delta udhcpc_main 2680 2684 +4 state 1 - -1 listen_mode 1 - -1 sockfd 4 - -4 ------------------------------------------------------------------------------ (add/remove: 0/3 grow/shrink: 1/0 up/down: 4/-6) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-30Optionally re-introduce bb_info_msg()James Byrne
Between Busybox 1.24.2 and 1.25.0 the bb_info_msg() function was eliminated and calls to it changed to be bb_error_msg(). The downside of this is that daemons now log all messages to syslog at the LOG_ERR level which makes it hard to filter errors from informational messages. This change optionally re-introduces bb_info_msg(), controlled by a new option FEATURE_SYSLOG_INFO, restores all the calls to bb_info_msg() that were removed (only in applets that set logmode to LOGMODE_SYSLOG or LOGMODE_BOTH), and also changes informational messages in ifplugd and ntpd. The code size change of this is as follows (using 'defconfig' on x86_64 with gcc 7.3.0-27ubuntu1~18.04) function old new delta bb_info_msg - 182 +182 bb_vinfo_msg - 27 +27 static.log7 194 198 +4 log8 190 191 +1 log5 190 191 +1 crondlog 45 - -45 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 3/0 up/down: 215/-45) Total: 170 bytes If you don't care about everything being logged at LOG_ERR level then when FEATURE_SYSLOG_INFO is disabled Busybox actually gets smaller: function old new delta static.log7 194 200 +6 log8 190 193 +3 log5 190 193 +3 syslog_level 1 - -1 bb_verror_msg 583 581 -2 crondlog 45 - -45 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 3/1 up/down: 12/-48) Total: -36 bytes Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-27udhcpc: don't exit after backgrounding on -n -bAndrey Mazo
Currently, running "udhcpc -n -b" causes udhcpc to go to background and then exit after some time unless a lease is obtained. It's not very useful to do so as the calling process doesn't know if the lease was obtained or not anyway. The code actually tries to favor "-b" over "-n", but doesn't clear "-n" flag while clearing "-b" after backgrounding. So, clear "-n" flag after going into background. This effectively makes "-b" override "-n" completely and "-n -b" behave the same as "-b". This allows to override default "-n" option, passed to udhcpc by ifupdown, without recompiling busybox. URL: https://bugs.busybox.net/11691 Signed-off-by: Andrey Mazo <ahippo@yandex.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-27udhcpc: tweak --helpDenys Vlasenko
function old new delta packed_usage 33324 33315 -9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-07udhcpc: when decoding DHCP_SUBNET, ensure it is 4 bytes longDenys Vlasenko
function old new delta udhcp_run_script 795 801 +6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-17udhcpc: check that 4-byte options are indeed 4-byte, closes 11506Denys Vlasenko
function old new delta udhcp_get_option32 - 27 +27 udhcp_get_option 231 248 +17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 44/0) Total: 44 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-03udhcpc: code shrinkDenys Vlasenko
function old new delta perform_release 112 172 +60 send_release 81 - -81 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 60/-81) Total: -21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-10-30udhcpc: ensure at least one unicast renew attemptDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-28udhcpc: give SIGUSR1-induced renew one chance of unicast renewDenys Vlasenko
The caps were inconsistent: timeout to renew was capped at 20 seconds, and any renews with timeout <= 60 seconds were forced to broadcast. function old new delta udhcpc_main 2683 2680 -3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-01udhcpc: add a cooment about sanitizing DHCP_DOMAIN_NAME, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-01udhcpc: do in fact not allow hostname components which start with dashDenys Vlasenko
function old new delta xmalloc_optname_optval 879 893 +14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-21udhcpc: remove code which requires server ID to be on local networkDenys Vlasenko
This reverts "udhcpc: paranoia when using kernel UDP mode for sending renew: server ID may be bogus". Users complain that they do have servers behind routers (with DHCP relays). function old new delta send_packet 168 166 -2 bcast_or_ucast 25 23 -2 udhcp_send_kernel_packet 301 295 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14udhcpc6: set -x options in requestDenys Vlasenko
Last foru commits: function old new delta option_to_env 621 791 +170 .rodata 168351 168505 +154 attach_option 431 506 +75 add_d6_client_options 112 167 +55 d6_option_strings 30 84 +54 udhcp_str2optset 644 660 +16 d6_optflags 12 20 +8 udhcpc6_main 2590 2596 +6 udhcpc_main 2648 2651 +3 read_optset 15 18 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 10/0 up/down: 544/0) Total: 544 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-13udhcp: support string user options, closes 10946Denys Vlasenko
function old new delta udhcp_str2optset 536 628 +92 packed_usage 32757 32760 +3 udhcpc_main 2708 2692 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 95/-16) Total: 79 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-10udhcpd: fix "not dying on SIGTERM"Denys Vlasenko
Fixes: commit 52a515d18724bbb34e3ccbbb0218efcc4eccc0a8 "udhcp: use poll() instead of select()" Feb 16 2017 udhcp_sp_read() is meant to check whether signal pipe indeed has some data to read. In the above commit, it was changed as follows: - if (!FD_ISSET(signal_pipe.rd, rfds)) + if (!pfds[0].revents) return 0; The problem is, the check was working for select() purely by accident. Caught signal interrupts select()/poll() syscalls, they return with EINTR (regardless of SA_RESTART flag in sigaction). _Then_ signal handler is invoked. IOW: they can't see any changes to fd state caused by signal haldler (in our case, signal handler makes signal pipe ready to be read). For select(), it means that rfds[] bit array is unmodified, bit of signal pipe's read fd is still set, and the above check "works": it thinks select() says there is data to read. This accident does not work for poll(): .revents stays clear, and we do not try reading signal pipe as we should. In udhcpd, we fall through and block in socket read. Further SIGTERM signals simply cause socket read to be interrupted and then restarted (since SIGTERM handler has SA_RESTART=1). Fixing this as follows: remove the check altogether. Set signal pipe read fd to nonblocking mode. Always read it in udhcp_sp_read(). If read fails, assume it's EAGAIN and return 0 ("no signal seen"). udhcpd avoids reading signal pipe on every recvd packet by looping if EINTR (using safe_poll()) - thus ensuring we have correct .revents for all fds - and calling udhcp_sp_read() only if pfds[0].revents!=0. udhcpc performs much fewer reads (typically it sleeps >99.999% of the time), there is no need to optimize it: can call udhcp_sp_read() after each poll unconditionally. To robustify socket reads, unconditionally set pfds[1].revents=0 in udhcp_sp_fd_set() (which is before poll), and check it before reading network socket in udhcpd. TODO: This might still fail: if pfds[1].revents=POLLIN, socket read may still block. There are rare cases when select/poll indicates that data can be read, but then actual read still blocks (one such case is UDP packets with wrong checksum). General advise is, if you use a poll/select loop, keep all your fds nonblocking. Maybe we should also do that to our network sockets? function old new delta udhcp_sp_setup 55 65 +10 udhcp_sp_fd_set 54 60 +6 udhcp_sp_read 46 36 -10 udhcpd_main 1451 1437 -14 udhcpc_main 2723 2708 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/3 up/down: 16/-39) Total: -23 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-07udhcp: do not setlinebuf(stdout), we don't print to stdout anymoreDenys Vlasenko
Since bb_info_msg() was eliminated type of buffering on stdout is not important function old new delta udhcpd_main 1463 1451 -12 udhcpc_main 2735 2723 -12 setlinebuf 19 - -19 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-43) Total: -43 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>