Commit Graph

66 Commits

Author SHA1 Message Date
Denys Vlasenko
4bbc391c7f udhcpc: improve logs - show offer as it is received
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-02 19:51:52 +02:00
Michal Kazior
b817699e6c udhcp: bind to device even for ucast packets
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-12-15 21:44:21 +01:00
Denys Vlasenko
4a0eb0370c gcc-9.x warning fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 03:07:22 +02:00
James Byrne
6937487be7 libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d437 ("'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-07-02 11:35:03 +02:00
James Byrne
253c4e787a Optionally re-introduce bb_info_msg()
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-04-30 10:51:27 +02:00
Denys Vlasenko
148788eb0e udhcpc: remove code which requires server ID to be on local network
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-06-21 17:38:14 +02:00
Denys Vlasenko
f625836e60 udhcpc[6]: make log2 messages for chaddr field indented like the rest
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-29 18:02:01 +02:00
Denys Vlasenko
a6a3ad3273 udhcpc: paranoia when using kernel UDP mode for sending renew: server ID may be bogus
With new code, we request that target IP (server ID) must be directly reachable.
If it's not, this happens:

udhcpc: waiting 2000 seconds
udhcpc: entering listen mode: kernel
udhcpc: opening listen socket on *:68 wlan0
udhcpc: entering renew state
udhcpc: sending renew to 1.1.1.1
udhcpc: send: Network is unreachable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1.1.1.1 needs routing, this is fishy!
udhcpc: entering rebinding state
udhcpc: entering listen mode: raw
udhcpc: created raw socket
udhcpc: sending renew to 0.0.0.0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ going to use broadcast

which is the desired behavior. Before the patch, packet to 1.1.1.1 was routed
over eth0 (!) and maybe even into Internet (!!!).

function                                             old     new   delta
udhcpc_main                                         2752    2763     +11
udhcp_send_kernel_packet                             295     301      +6
send_renew                                            82      84      +2
send_packet                                          166     168      +2
bcast_or_ucast                                        23      25      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 23/0)               Total: 23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-29 16:02:11 +02:00
Denys Vlasenko
2b9acc60c0 udhcpc[6]: initialize entire sockaddr_ll
I see random field values like sll_hatype=0x267 when I strace.
They seem to not matter, but just in case they sometimes do,
let's at least have deterministic values (via memset(0)).

function                                             old     new   delta
change_listen_mode                                   308     322     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-29 14:22:43 +02:00
Denys Vlasenko
4ee824f6ba randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 01:22:13 +02:00
Denys Vlasenko
8f2e99c813 udhcp: get rid of bb_info_msg()
function                                             old     new   delta
udhcpd_main                                         1501    1531     +30
d6_recv_raw_packet                                   251     264     +13
perform_d6_release                                   188     198     +10
udhcpc6_main                                        2443    2449      +6
udhcp_recv_raw_packet                                582     588      +6
udhcp_recv_kernel_packet                             132     138      +6
send_d6_renew                                        140     146      +6
d6_recv_kernel_packet                                118     124      +6
send_renew                                            77      82      +5
send_discover                                         85      90      +5
send_decline                                          84      89      +5
send_d6_select                                        97     102      +5
send_d6_discover                                     174     179      +5
perform_release                                      167     172      +5
count_lines                                           72      74      +2
udhcpc_main                                         2836    2837      +1
bb_info_msg                                          125       -    -125
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 17/4 up/down: 117/-180)         Total: -63 bytes
   text	   data	    bss	    dec	    hex	filename
 924935	    906	  17160	 943001	  e6399	busybox_old
 924736	    906	  17160	 942802	  e62d2	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:41:23 +02:00
Johannes Stezenbach
2d576e2a22 udhcpc: make DHCP packets to have at least 300 DHCP bytes
Commit b8b72f02 removed all padding from DHCP packets
to fix operation with buggy servers which can't handle
maximum sized packets.  But it introduced a regression
with buggy routers which drop DHCP packets smaller
than 300 bytes (i.e. 342 byte ethernet packets).
Add back some padding to work around.

function                                             old     new   delta
udhcp_send_kernel_packet                             268     292     +24
udhcp_send_raw_packet                                462     473     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 35/0)               Total: 35 bytes

Signed-off-by: Johannes Stezenbach <js@sig21.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-10-28 23:27:37 +01:00
Denys Vlasenko
50089fc61c udhcpc: trim help text, rename badly-named variable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-11-07 15:44:46 +01:00
Denys Vlasenko
3b46fcb95d udhcpc: remove workaround for bugs in Win98 dhcp server ("MSFT 98" vendor string)
Stats for last three commits:

function                                             old     new   delta
udhcpc_main                                         2635    2646     +11
udhcp_recv_raw_packet                                425     414     -11
udhcp_recv_kernel_packet                             210     134     -76
packed_usage                                       28940   28857     -83
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 11/-170)          Total: -159 bytes
   text    data     bss     dec     hex filename
 879524     493    7584  887601   d8b31 busybox_old
 879340     493    7584  887417   d8a79 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-11-05 01:26:18 +01:00
Baruch Siach
e8f36330d9 networking: consolidate the IP checksum code. -129 bytes.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-07 17:55:40 +02:00
Dan Fandrich
f533ec8767 *: simplify Ethernet header includes
Signed-off-by: Dan Fandrich <dan@coneharvesters.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-06-10 05:17:59 +02:00
Denys Vlasenko
2c3b71a0d2 dhcp: typo fix: UPD_DHCP_SIZE -> UDP_DHCP_SIZE
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-10-20 18:04:36 +02:00
Denys Vlasenko
0ef64bdb40 *: make GNU licensing statement forms more regular
This change retains "or later" state! No licensing _changes_ here,
only form is adjusted (article, space between "GPL" and "v2" and so on).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-08-16 20:14:46 +02:00
Denys Vlasenko
b8b72f02f0 dhcp: truncate packets instead of padding them to 574 bytes. closes bug 1849
function                                             old     new   delta
udhcp_send_raw_packet                                411     456     +45
udhcp_send_kernel_packet                             259     271     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-31 00:45:09 +02:00
Denys Vlasenko
b7d19cc400 dhcp: readability cleanups and small code shrink
function                                             old     new   delta
udhcp_run_script                                     654     617     -37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-30 23:41:23 +02:00
Denys Vlasenko
385b4562e3 udhcp: cosmetic cleanups; one case of s/full_read/xread/
function                                             old     new   delta
dumpleases_main                                      632     623      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-26 10:09:34 +01:00
Denys Vlasenko
7724c766bd udhcp: pass pointer to whole packet to "add option" functions
This is needed for "overflow option" support

function                                             old     new   delta
udhcp_find_option                                      -      34     +34
udhcp_add_binary_option                               94     106     +12
write_leases                                         227     223      -4
udhcp_init_header                                     86      82      -4
send_release                                         104      99      -5
init_packet                                           87      81      -6
add_client_options                                   160     154      -6
add_server_options                                   100      92      -8
udhcpd_main                                         1964    1954     -10
udhcpc_main                                         2859    2837     -22
find_option                                           34       -     -34
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/8 up/down: 46/-99)            Total: -53 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-26 09:32:09 +01:00
Denys Vlasenko
37a658c4c8 udhcp: handle errors in read_staticlease
also gets rid of ether-aton's static buffer in ether-wake:
   text   data    bss    dec    hexfilename
 838664    441   7572 846677  ceb55busybox_old
 838650    441   7564 846655  ceb3fbusybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-23 15:43:08 +01:00
Denys Vlasenko
dde8bdcc5b udhcp: merge options.h into common.h, script.c into dhcpc.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-22 14:29:13 +01:00
Denys Vlasenko
c7dc79e71d udhcpd: untangle incredibly messy handling of DHCPREQUEST
Also fixes attacks possible via DHCPDECLINE / DHCPRELEASE

function                                             old     new   delta
udhcpd_main                                         1846    1949    +103
send_renew                                           105     142     +37
send_NAK                                              61       -     -61
send_ACK                                             180       -    -180
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/0 up/down: 140/-241)         Total: -101 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-21 06:15:28 +01:00
Denys Vlasenko
9038d6f8f5 remove trailing whitespace
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-07-15 20:02:19 +02:00
Denys Vlasenko
7a76eba1f6 udhcp: fix trivial compile error
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-06-19 13:51:29 +02:00
Denys Vlasenko
6947d2c7e1 udhcp: logging improvements, field and variable renames
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-06-17 13:24:03 +02:00
Denys Vlasenko
31af3d5a1d udhcp: shorten mac len from 16 to 6 in lease file
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-06-17 11:57:09 +02:00
Denys Vlasenko
ac906fa85e udhcp: change UDHCP_DEBUG into int, make verbosity selectable with -v
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-06-17 11:54:52 +02:00
Denis Vlasenko
db12d1d733 Fix forgotten license comments 2008-12-07 00:52:58 +00:00
Denis Vlasenko
739e30fbc3 udhcp: add inline docs; small code shrink
function                                             old     new   delta
send_packet                                          103      87     -16
udhcpc_main                                         2359    2323     -36
2008-09-26 23:45:20 +00:00
Denis Vlasenko
c321b51dc6 udhcp: added some FIXMEs; code shrink. -49 bytes 2008-09-26 16:29:12 +00:00
Denis Vlasenko
f1980f67d3 dhcp: add FAST_FUNC as appropriate. -160 bytes. 2008-09-26 09:34:59 +00:00
Denis Vlasenko
6de8994440 udhcpc: regularize the names of receiving functions,
pause on "serious failure to receive".
Some misc fixes are also folded in here.
2008-05-21 07:05:06 +00:00
Denis Vlasenko
a523e2efad udhcp: we were forgetting to set right op byte in tha packet
for DHCPDECLINE. Fixing, and making code smaller.
2008-02-20 22:33:38 +00:00
Denis Vlasenko
8e5b6f58a2 Makefile: change version to 1.10.0.svn
udhcpc: make UDP packet sending the same as raw sending in regards
  to error messages. Minor code size shrink. Total size grows due
  to added messages:

   text    data     bss     dec     hex filename
 770312     683    7244  778239   bdfff busybox_old
 770327     683    7244  778254   be00e busybox_unstripped
2007-12-24 17:32:22 +00:00
Denis Vlasenko
619879246d udhcp: decided to not send "short" dhcp packets,
but lets add comments how to do it if needed.
2007-12-21 16:32:30 +00:00
Denis Vlasenko
fff145dba3 udhcp: fix oversized packet sending (introduced by "slack for bad dhcp servers" options);
slight optimizations and function renaming

udhcp_send_raw_packet                                  -     391    +391
udhcp_send_kernel_packet                               -     197    +197
udhcp_recv_packet                                      -     134    +134
get_raw_packet                                       353     326     -27
udhcp_get_packet                                     134       -    -134
udhcp_kernel_packet                                  197       -    -197
udhcp_raw_packet                                     391       -    -391
------------------------------------------------------------------------------
(add/remove: 3/3 grow/shrink: 0/1 up/down: 722/-749)          Total: -27 bytes
2007-12-20 21:11:38 +00:00
Denis Vlasenko
6884f665bd dhcp: stop using magic constants; use (htonl(CONST) != a) - it's smaller
function                                             old     new   delta
udhcp_get_packet                                     146     134     -12
get_raw_packet                                       368     353     -15
2007-11-23 00:08:54 +00:00
Denis Vlasenko
a27a11bb2c introduce and use xdup2(int, int)
stop checking whether setsockopt_reuseaddr(int fd) was successful (it always is)
remove second parameter (sockllen) from xmalloc_sockaddr2xxxxx functions

sockaddr2str                                         142     156     +14
collect_blk                                          467     474      +7
xdup2                                                 28      33      +5
singlemount                                         4456    4454      -2
print_host                                           214     212      -2
nslookup_main                                        139     137      -2
ftpgetput_main                                       414     412      -2
udhcpd_main                                         1258    1255      -3
udhcpc_main                                         2405    2402      -3
traceroute_main                                     4125    4122      -3
nc_main                                             1072    1069      -3
buffer_fill_and_print                                 76      73      -3
xmalloc_sockaddr2hostonly_noport                      18      14      -4
xmalloc_sockaddr2host_noport                          18      14      -4
xmalloc_sockaddr2host                                 15      11      -4
xmalloc_sockaddr2dotted_noport                        18      14      -4
xmalloc_sockaddr2dotted                               18      14      -4
wget_main                                           2618    2614      -4
ping_main                                            393     389      -4
ip_port_str                                          120     115      -5
dhcprelay_main                                      1146    1141      -5
dnsd_main                                           1531    1525      -6
passwd_main                                         1110    1102      -8
udhcp_kernel_packet                                  206     197      -9
udhcp_listen_socket                                  154     144     -10
getty_main                                          2576    2566     -10
setup                                                655     640     -15
xmove_fd                                              51      34     -17
dolisten                                             759     742     -17
tcpudpsvd_main                                      1866    1836     -30
startservice                                         339     299     -40
2007-08-18 14:16:39 +00:00
Denis Vlasenko
42b3dea9bf udhcp: many small fixes:
* arpping(): smaller and even probably fixed
* lots of variables/params converted: ulong -> uint32_t
* uptime() nuked in favor of monotonic_sec()
* udhcp_get_packet(): only one "bad vendor", simplify

function                                             old     new   delta
reservedIp                                            36      35      -1
udhcpc_main                                         2462    2460      -2
addStaticLease                                        64      62      -2
static.broken_vendors                                 16       -     -16
uptime                                                19       -     -19
udhcpd_main                                         1273    1238     -35
udhcp_get_packet                                     223     184     -39
.rodata                                           144162  144106     -56
arpping                                              690     609     -81
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-251)           Total: -251 bytes
   text    data     bss     dec     hex filename
 734241    3028   14400  751669   b7835 busybox_old
 734005    3028   14400  751433   b7749 busybox_unstripped
2007-07-03 15:47:50 +00:00
Denis Vlasenko
fbd2918f5c udhcp: MAC_BCAST_ADDR and blank_chaddr are in fact constant, move to rodata.
a few global variables reduced to smallints
function                                             old     new   delta
add_lease                                             75     227    +152
static.blank_chaddr                                    -      16     +16
MAC_BCAST_ADDR                                         -       6      +6
sockfd                                                 4       8      +4
udhcp_run_script                                    1153    1155      +2
state                                                  8       5      -3
listen_mode                                            4       1      -3
perform_release                                      152     148      -4
fd                                                     8       4      -4
blank_chaddr                                          16       -     -16
udhcpc_main                                         2518    2497     -21
.rodata                                           131864  131832     -32
oldest_expired_lease                                  61       -     -61
clear_lease                                          127       -    -127
------------------------------------------------------------------------------
(add/remove: 2/3 grow/shrink: 3/6 up/down: 180/-271)          Total: -91 bytes
2007-04-07 01:05:47 +00:00
Denis Vlasenko
83e5d6f772 A bunch of defined(__GLIBC__) added. static-linking warning expanded 2006-12-18 21:49:06 +00:00
Denis Vlasenko
48237b0c88 introduce setsockopt_reuseaddr(int fd), setsockopt_broadcast(int fd),
use them where appropriate. 200 bytes saved
2006-11-22 23:22:06 +00:00
Denis Vlasenko
c9cdeaa3fe add compile-time check for correct DHCP packet size 2006-11-20 01:13:09 +00:00
Denis Vlasenko
5a3395bc01 udhcp: fix indentation and style.
Eliminate (group) a lot of smallish *.h files
Remove lots of unneeded #includes
2006-11-18 19:51:32 +00:00
Denis Vlasenko
a7189f01a4 add -Wundef, fix uncovered bugs 2006-11-17 20:29:00 +00:00
Denis Vlasenko
e1a0d486e4 message string changes, mostly for consistency, also -32 bytes in .rodata 2006-10-20 13:28:22 +00:00
Denis Vlasenko
3538b9a882 Implement optional syslog logging using ordinary
bb_xx_msg calls, and convert networking/* to it.
The rest of bbox will be converted gradually.
2006-09-06 18:36:50 +00:00