Commit Graph

598 Commits

Author SHA1 Message Date
Denys Vlasenko
a840884531 udhcpd: support per-client hostnames in static leases
function                                             old     new   delta
read_staticlease                                     222     299     +77
add_server_options                                    92     154     +62
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 139/0)             Total: 139 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-16 11:18:49 +02:00
Denys Vlasenko
abe248b208 udhcpc6: unbreak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-15 14:20:32 +02:00
Denys Vlasenko
8402969d48 udhcpd: code shrink - do not fetch requested IP twice
function                                             old     new   delta
send_offer                                           444     443      -1
udhcpd_main                                         1454    1442     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-13)             Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-15 13:08:48 +02:00
Denys Vlasenko
8c317f03f6 style fix, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-14 17:26:47 +02:00
Denys Vlasenko
15021f393d udhcpd: code shrink
function                                             old     new   delta
is_nip_reserved_as_static                              -      28     +28
get_static_nip_by_mac                                 43      47      +4
udhcpd_main                                         1459    1454      -5
send_offer                                           449     444      -5
read_leases                                          309     299     -10
is_nip_reserved                                       20       -     -20
packed_usage                                       33283   33243     -40
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/4 up/down: 32/-80)            Total: -48 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-10 15:55:12 +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
60bf77f7e7 udhcpc6: code shrink
function                                             old     new   delta
d6_read_interface                                    593     582     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-14 17:01:10 +02:00
Denys Vlasenko
0d75e8b797 udhcpc6: add a few comments, no code changes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-13 19:43:15 +02:00
Denys Vlasenko
cc45cbcca4 udhcpc6: make it enabled in defconfig
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-13 17:32:40 +02:00
Antoine Girard-Vallée
0e7bd69bb5 udhcp: add 100 and 101 dhcp options for ipv4
Support for the IEEE timezone string and timezone database strings (100
and 101 options respectively) is added for ipv4, conforming to RFC-4833.

The two options are passed to hook scripts in the variables tzstr and
tzdbstr.

function                                             old     new   delta
dhcp_option_strings                                  280     294     +14
dhcp_optflags                                         76      80      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 18/0)               Total: 18 bytes

Signed-off-by: Antoine Girard-Vallée <antoine.girard-vallee@savoirfairelinux.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-13 16:27:26 +02:00
Andrey Mazo
87e216294a udhcpc: don't exit after backgrounding on -n -b
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-27 08:27:47 +01:00
Denys Vlasenko
544143da0c udhcpc: tweak --help
function                                             old     new   delta
packed_usage                                       33324   33315      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-27 08:17:07 +01:00
Denys Vlasenko
edb74f4019 Update examples/udhcp/udhcpd.conf
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-15 13:19:01 +01:00
Denys Vlasenko
74d9f1ba37 udhcpc: when decoding DHCP_SUBNET, ensure it is 4 bytes long
function                                             old     new   delta
udhcp_run_script                                     795     801      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-07 15:33:42 +01:00
Denys Vlasenko
b80bdeba02 udhcp: code shrink
function                                             old     new   delta
attach_option                                        406     349     -57

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-07 15:23:18 +01:00
Denys Vlasenko
df1ff103c9 config: add size information for three more applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28 13:37:44 +01:00
Denys Vlasenko
83e7e13628 config: add size information for udhcpc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28 13:03:48 +01:00
Denys Vlasenko
b097a84d62 config: update size information
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28 03:20:17 +01:00
Denys Vlasenko
3d27d435db randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-27 18:03:20 +01:00
Denys Vlasenko
6d3b4bb24d udhcpc: check that 4-byte options are indeed 4-byte, closes 11506
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-12-17 18:07:18 +01:00
Denys Vlasenko
9d05ad087e udhcpc: code shrink
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-11-03 23:34:35 +01:00
Denys Vlasenko
c05aa6a776 udhcpc: ensure at least one unicast renew attempt
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-10-30 11:56:18 +01:00
Denys Vlasenko
aae428f0bf udhcpc: give SIGUSR1-induced renew one chance of unicast renew
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-09-28 14:44:09 +02:00
Denys Vlasenko
02cf149ed7 udhcpc: add a cooment about sanitizing DHCP_DOMAIN_NAME, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-01 13:36:36 +02:00
Denys Vlasenko
48ec979ed1 udhcpc: do in fact not allow hostname components which start with dash
function                                             old     new   delta
xmalloc_optname_optval                               879     893     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-01 13:16:05 +02:00
Denys Vlasenko
2cd81698ee udhcp: add decimal option values in comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-04 16:05:48 +02:00
Denys Vlasenko
6d26744a2c udhcp: tweak comment indentation, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-04 15:44:22 +02:00
Jeremy Kerr
fc267214f0 udhcp: add option 211, "reboot time"
As defined in RFC 5071.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-04 15:38:19 +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
Kartik Agaram
43b17b1cd0 restore documentation on the build config language
Kconfig-language.txt was deleted in commit 4fa499a17b back in 2006.
Move to docs/ as suggested by Xabier Oneca:
  http://lists.busybox.net/pipermail/busybox/2014-May/080914.html
Also update references to it everywhere.

Signed-off-by: Kartik Agaram <akkartik@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-06 15:16:48 +02:00
David Decotigny
8f48fc01e9 udhcpc6: carry along length of packet when parsing it.
This is to avoid parsing garbage past packet's actual end.

Also const-ize params to a few functions.

function                                             old     new   delta
d6_run_script_no_option                                -      12     +12
option_to_env                                        791     798      +7
d6_run_script                                        253     255      +2
perform_d6_release                                    95      93      -2
udhcpc6_main                                        2596    2592      -4
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 21/-6)              Total: 15 bytes

Signed-off-by: David Decotigny <ddecotig@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 18:34:56 +02:00
David Decotigny
a174c791ec udhcpc6: ignore invalid OPTION_IAADDR
Signed-off-by: David Decotigny <ddecotig@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 18:26:01 +02:00
Denys Vlasenko
6027597fd1 udhcpc6: set -x options in request
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-05-14 11:11:08 +02:00
Samuel Mendoza-Jonas
30f4d52ed1 udhcpc6: add PXELINUX options
Add support for the PXELINUX options 209 ("ConfigFile") and 210
("PathPrefix") in the DHCPv6 client.

See also: RFC5071, "Dynamic Host Configuration Protocol Options Used by
PXELINUX".

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Samuel Mendoza-Jonas
23cbd7d5bb udhcpc6: add DHCPv6 boot options
Add support for 'bootfile-url' and 'bootfile-params' as defined by
RFC5970 "DHCPv6 Options for Network Boot".

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Samuel Mendoza-Jonas
bcdec1a8b8 udhcpc6: add DHCPv6 env helper
Add string_option_to_env() to easily generate environment variables for
known simple options.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Samuel Mendoza-Jonas
43b9235f66 udhcp: fix use of trim() in udhcp_str2optset()
trim() modifies the string in place if needed and returns a pointer to
the end of the resulting string. Update udhcp_str2optset() so it no
longer sets the value of 'val' to the return value of trim().

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Denys Vlasenko
266f6f1973 udhcp: support string user options, closes 10946
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-04-13 13:27:52 +02:00
Denys Vlasenko
46ba2468a3 ioctl(SIOCGIFINDEX) does not require clearing of entire ifr
function                                             old     new   delta
INET6_setroute                                       492     472     -20
do_iplink                                           1357    1330     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-47)             Total: -47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-27 23:55:43 +02:00
Denys Vlasenko
3d306bffc5 udhcpd: clamp down huge auto_times to ~2M seconds, better EINTR poll handling
EINTR _should_ only happen on two signals we trap, and safe_poll
_should_ work here just fine, but there were kernel bugs where spurious EINTRs
happen (e.g. on ptrace attach). Be safe.

function                                             old     new   delta
udhcpd_main                                         1437    1468     +31

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-11 11:39:05 +01:00
Denys Vlasenko
3293bc1469 udhcpd: fix "not dying on SIGTERM"
Fixes:
	commit 52a515d187
	"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-03-10 19:34:39 +01:00
Denys Vlasenko
2bd5b4e9a0 udhcp: do not setlinebuf(stdout), we don't print to stdout anymore
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>
2018-02-07 16:32:30 +01:00
Denys Vlasenko
06076494da udhcpd: use ptr_to_globals for its lone global data (g_leases)
function                                             old     new   delta
udhcpd_main                                         1461    1463      +2
add_lease                                            320     318      -2
g_leases                                               4       -      -4
write_leases                                         223     214      -9
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 2/-15)             Total: -13 bytes
   text	   data	    bss	    dec	    hex	filename
 933232	    481	   6856	 940569	  e5a19	busybox_old
 933223	    481	   6852	 940556	  e5a0c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 10:41:14 +01:00
Denys Vlasenko
30b290f996 udhcpc6: additional fix for ppp interface type
Invent a fictitious MAC only once

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-23 16:46:31 +01:00
Denys Vlasenko
f6dd9e0215 udhcpc6: fix for ppp interface type
function                                             old     new   delta
d6_read_interface                                    454     600    +146

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 18:44:19 +01:00
Denys Vlasenko
7c44b600f9 udhcpc[6]: remove overzealous timeout clamping code
function                                             old     new   delta
udhcpc_main                                         2840    2826     -14
udhcpc6_main                                        2699    2670     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-17 13:55:51 +01:00
Denys Vlasenko
64211ce6fa udhcpc6: --help fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 22:23:38 +01:00
Denys Vlasenko
438c72ece4 udhcpc6: show only short opts in --help text
function                                             old     new   delta
packed_usage                                       26028   25966     -62

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 22:10:12 +01:00
Denys Vlasenko
6e9e6d8fbe udhcpc6: fix lease time staying very small because -d was not specified
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 21:52:23 +01:00
Denys Vlasenko
14f13205ef udhcpc6: code shrink
function                                             old     new   delta
udhcpc6_main                                        2723    2727      +4
.rodata                                           128695  128561    -134

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 21:47:10 +01:00