aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorJames Byrne <james.byrne@origamienergy.com>2019-07-02 11:35:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /networking/udhcp
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.bz2
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.zip
libbb: reduce the overhead of single parameter bb_error_msg() calls
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>
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/arpping.c4
-rw-r--r--networking/udhcp/common.c2
-rw-r--r--networking/udhcp/common.h19
-rw-r--r--networking/udhcp/d6_dhcpc.c34
-rw-r--r--networking/udhcp/d6_packet.c4
-rw-r--r--networking/udhcp/d6_socket.c2
-rw-r--r--networking/udhcp/dhcpc.c50
-rw-r--r--networking/udhcp/dhcpd.c24
-rw-r--r--networking/udhcp/dhcprelay.c4
-rw-r--r--networking/udhcp/packet.c4
-rw-r--r--networking/udhcp/signalpipe.c2
-rw-r--r--networking/udhcp/socket.c2
12 files changed, 85 insertions, 66 deletions
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index 215d023ce..a395e838d 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -53,12 +53,12 @@ int FAST_FUNC arpping(uint32_t test_nip,
53 53
54 s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); 54 s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP));
55 if (s == -1) { 55 if (s == -1) {
56 bb_perror_msg(bb_msg_can_not_create_raw_socket); 56 bb_simple_perror_msg(bb_msg_can_not_create_raw_socket);
57 return -1; 57 return -1;
58 } 58 }
59 59
60 if (setsockopt_broadcast(s) == -1) { 60 if (setsockopt_broadcast(s) == -1) {
61 bb_perror_msg("can't enable bcast on raw socket"); 61 bb_simple_perror_msg("can't enable bcast on raw socket");
62 goto ret; 62 goto ret;
63 } 63 }
64 64
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index 62ad248ce..4a452cdb9 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -240,7 +240,7 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
240 while (1) { 240 while (1) {
241 if (rem <= 0) { 241 if (rem <= 0) {
242 complain: 242 complain:
243 bb_error_msg("bad packet, malformed option field"); 243 bb_simple_error_msg("bad packet, malformed option field");
244 return NULL; 244 return NULL;
245 } 245 }
246 246
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index bba3d6037..60255eefa 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -267,26 +267,45 @@ struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code)
267# define IF_UDHCP_VERBOSE(...) __VA_ARGS__ 267# define IF_UDHCP_VERBOSE(...) __VA_ARGS__
268extern unsigned dhcp_verbose; 268extern unsigned dhcp_verbose;
269# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0) 269# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0)
270# define log1s(msg) do { if (dhcp_verbose >= 1) bb_simple_info_msg(msg); } while (0)
270# if CONFIG_UDHCP_DEBUG >= 2 271# if CONFIG_UDHCP_DEBUG >= 2
271void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; 272void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
272# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0) 273# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0)
274# define log2s(msg) do { if (dhcp_verbose >= 2) bb_simple_info_msg(msg); } while (0)
273# else 275# else
274# define udhcp_dump_packet(...) ((void)0) 276# define udhcp_dump_packet(...) ((void)0)
275# define log2(...) ((void)0) 277# define log2(...) ((void)0)
278# define log2s(msg) ((void)0)
276# endif 279# endif
277# if CONFIG_UDHCP_DEBUG >= 3 280# if CONFIG_UDHCP_DEBUG >= 3
278# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0) 281# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0)
282# define log3s(msg) do { if (dhcp_verbose >= 3) bb_simple_info_msg(msg); } while (0)
279# else 283# else
280# define log3(...) ((void)0) 284# define log3(...) ((void)0)
285# define log3s(msg) ((void)0)
281# endif 286# endif
282#else 287#else
283# define IF_UDHCP_VERBOSE(...) 288# define IF_UDHCP_VERBOSE(...)
284# define udhcp_dump_packet(...) ((void)0) 289# define udhcp_dump_packet(...) ((void)0)
285# define log1(...) ((void)0) 290# define log1(...) ((void)0)
291# define log1s(msg) ((void)0)
286# define log2(...) ((void)0) 292# define log2(...) ((void)0)
293# define log2s(msg) ((void)0)
287# define log3(...) ((void)0) 294# define log3(...) ((void)0)
295# define log3s(msg) ((void)0)
288#endif 296#endif
289 297
298#if defined(__mips__)
299/*
300 * The 'simple' message functions have a negative impact on the size of the
301 * DHCP code when compiled for MIPS, so don't use them in this case.
302 */
303#define bb_simple_info_msg bb_info_msg
304#define bb_simple_error_msg bb_error_msg
305#define bb_simple_perror_msg_and_die bb_perror_msg_and_die
306#undef log1s
307#define log1s log1
308#endif
290 309
291/*** Other shared functions ***/ 310/*** Other shared functions ***/
292 311
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 4eb7ae1c1..9d8e17c51 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -235,7 +235,7 @@ static char *string_option_to_env(const uint8_t *option,
235 found: 235 found:
236 val_len = (option[2] << 8) | option[3]; 236 val_len = (option[2] << 8) | option[3];
237 if (val_len + &option[D6_OPT_DATA] > option_end) { 237 if (val_len + &option[D6_OPT_DATA] > option_end) {
238 bb_error_msg("option data exceeds option length"); 238 bb_simple_error_msg("option data exceeds option length");
239 return NULL; 239 return NULL;
240 } 240 }
241 return xasprintf("%s=%.*s", name, val_len, (char*)option + 4); 241 return xasprintf("%s=%.*s", name, val_len, (char*)option + 4);
@@ -848,19 +848,19 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac
848 848
849 bytes = safe_read(fd, &packet, sizeof(packet)); 849 bytes = safe_read(fd, &packet, sizeof(packet));
850 if (bytes < 0) { 850 if (bytes < 0) {
851 log1("packet read error, ignoring"); 851 log1s("packet read error, ignoring");
852 /* NB: possible down interface, etc. Caller should pause. */ 852 /* NB: possible down interface, etc. Caller should pause. */
853 return bytes; /* returns -1 */ 853 return bytes; /* returns -1 */
854 } 854 }
855 855
856 if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) { 856 if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) {
857 log1("packet is too short, ignoring"); 857 log1s("packet is too short, ignoring");
858 return -2; 858 return -2;
859 } 859 }
860 860
861 if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) { 861 if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) {
862 /* packet is bigger than sizeof(packet), we did partial read */ 862 /* packet is bigger than sizeof(packet), we did partial read */
863 log1("oversized packet, ignoring"); 863 log1s("oversized packet, ignoring");
864 return -2; 864 return -2;
865 } 865 }
866 866
@@ -874,7 +874,7 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac
874 /* || bytes > (int) sizeof(packet) - can't happen */ 874 /* || bytes > (int) sizeof(packet) - can't happen */
875 || packet.udp.len != packet.ip6.ip6_plen 875 || packet.udp.len != packet.ip6.ip6_plen
876 ) { 876 ) {
877 log1("unrelated/bogus packet, ignoring"); 877 log1s("unrelated/bogus packet, ignoring");
878 return -2; 878 return -2;
879 } 879 }
880 880
@@ -1003,7 +1003,7 @@ static int d6_raw_socket(int ifindex)
1003 } 1003 }
1004#endif 1004#endif
1005 1005
1006 log1("created raw socket"); 1006 log1s("created raw socket");
1007 1007
1008 return fd; 1008 return fd;
1009} 1009}
@@ -1031,7 +1031,7 @@ static void change_listen_mode(int new_mode)
1031/* Called only on SIGUSR1 */ 1031/* Called only on SIGUSR1 */
1032static void perform_renew(void) 1032static void perform_renew(void)
1033{ 1033{
1034 bb_info_msg("performing DHCP renew"); 1034 bb_simple_info_msg("performing DHCP renew");
1035 switch (client_data.state) { 1035 switch (client_data.state) {
1036 case BOUND: 1036 case BOUND:
1037 change_listen_mode(LISTEN_KERNEL); 1037 change_listen_mode(LISTEN_KERNEL);
@@ -1059,10 +1059,10 @@ static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *ou
1059 || client_data.state == REBINDING 1059 || client_data.state == REBINDING
1060 || client_data.state == RENEW_REQUESTED 1060 || client_data.state == RENEW_REQUESTED
1061 ) { 1061 ) {
1062 bb_info_msg("unicasting a release"); 1062 bb_simple_info_msg("unicasting a release");
1063 send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ 1063 send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */
1064 } 1064 }
1065 bb_info_msg("entering released state"); 1065 bb_simple_info_msg("entering released state");
1066/* 1066/*
1067 * We can be here on: SIGUSR2, 1067 * We can be here on: SIGUSR2,
1068 * or on exit (SIGTERM) and -R "release on quit" is specified. 1068 * or on exit (SIGTERM) and -R "release on quit" is specified.
@@ -1275,7 +1275,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1275 /* Create pidfile */ 1275 /* Create pidfile */
1276 write_pidfile(client_data.pidfile); 1276 write_pidfile(client_data.pidfile);
1277 /* Goes to stdout (unless NOMMU) and possibly syslog */ 1277 /* Goes to stdout (unless NOMMU) and possibly syslog */
1278 bb_info_msg("started, v"BB_VER); 1278 bb_simple_info_msg("started, v"BB_VER);
1279 1279
1280 client_data.state = INIT_SELECTING; 1280 client_data.state = INIT_SELECTING;
1281 d6_run_script_no_option("deconfig"); 1281 d6_run_script_no_option("deconfig");
@@ -1321,7 +1321,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1321 continue; 1321 continue;
1322 } 1322 }
1323 /* Else: an error occured, panic! */ 1323 /* Else: an error occured, panic! */
1324 bb_perror_msg_and_die("poll"); 1324 bb_simple_perror_msg_and_die("poll");
1325 } 1325 }
1326 } 1326 }
1327 1327
@@ -1362,7 +1362,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1362 d6_run_script_no_option("leasefail"); 1362 d6_run_script_no_option("leasefail");
1363#if BB_MMU /* -b is not supported on NOMMU */ 1363#if BB_MMU /* -b is not supported on NOMMU */
1364 if (opt & OPT_b) { /* background if no lease */ 1364 if (opt & OPT_b) { /* background if no lease */
1365 bb_info_msg("no lease, forking to background"); 1365 bb_simple_info_msg("no lease, forking to background");
1366 client_background(); 1366 client_background();
1367 /* do not background again! */ 1367 /* do not background again! */
1368 opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); 1368 opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f);
@@ -1375,7 +1375,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1375 } else 1375 } else
1376#endif 1376#endif
1377 if (opt & OPT_n) { /* abort if no lease */ 1377 if (opt & OPT_n) { /* abort if no lease */
1378 bb_info_msg("no lease, failing"); 1378 bb_simple_info_msg("no lease, failing");
1379 retval = 1; 1379 retval = 1;
1380 goto ret; 1380 goto ret;
1381 } 1381 }
@@ -1403,7 +1403,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1403 client_data.state = RENEWING; 1403 client_data.state = RENEWING;
1404 client_data.first_secs = 0; /* make secs field count from 0 */ 1404 client_data.first_secs = 0; /* make secs field count from 0 */
1405 change_listen_mode(LISTEN_KERNEL); 1405 change_listen_mode(LISTEN_KERNEL);
1406 log1("entering renew state"); 1406 log1s("entering renew state");
1407 /* fall right through */ 1407 /* fall right through */
1408 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ 1408 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
1409 case_RENEW_REQUESTED: 1409 case_RENEW_REQUESTED:
@@ -1423,7 +1423,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1423 continue; 1423 continue;
1424 } 1424 }
1425 /* Timed out, enter rebinding state */ 1425 /* Timed out, enter rebinding state */
1426 log1("entering rebinding state"); 1426 log1s("entering rebinding state");
1427 client_data.state = REBINDING; 1427 client_data.state = REBINDING;
1428 /* fall right through */ 1428 /* fall right through */
1429 case REBINDING: 1429 case REBINDING:
@@ -1438,7 +1438,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1438 continue; 1438 continue;
1439 } 1439 }
1440 /* Timed out, enter init state */ 1440 /* Timed out, enter init state */
1441 bb_info_msg("lease lost, entering init state"); 1441 bb_simple_info_msg("lease lost, entering init state");
1442 d6_run_script_no_option("deconfig"); 1442 d6_run_script_no_option("deconfig");
1443 client_data.state = INIT_SELECTING; 1443 client_data.state = INIT_SELECTING;
1444 client_data.first_secs = 0; /* make secs field count from 0 */ 1444 client_data.first_secs = 0; /* make secs field count from 0 */
@@ -1560,7 +1560,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1560 } 1560 }
1561 option = d6_copy_option(packet.d6_options, packet_end, D6_OPT_SERVERID); 1561 option = d6_copy_option(packet.d6_options, packet_end, D6_OPT_SERVERID);
1562 if (!option) { 1562 if (!option) {
1563 bb_info_msg("no server ID, ignoring packet"); 1563 bb_simple_info_msg("no server ID, ignoring packet");
1564 continue; 1564 continue;
1565 /* still selecting - this server looks bad */ 1565 /* still selecting - this server looks bad */
1566 } 1566 }
diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c
index 01d1c930b..446497e15 100644
--- a/networking/udhcp/d6_packet.c
+++ b/networking/udhcp/d6_packet.c
@@ -35,12 +35,12 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6
35 memset(packet, 0, sizeof(*packet)); 35 memset(packet, 0, sizeof(*packet));
36 bytes = safe_read(fd, packet, sizeof(*packet)); 36 bytes = safe_read(fd, packet, sizeof(*packet));
37 if (bytes < 0) { 37 if (bytes < 0) {
38 log1("packet read error, ignoring"); 38 log1s("packet read error, ignoring");
39 return bytes; /* returns -1 */ 39 return bytes; /* returns -1 */
40 } 40 }
41 41
42 if (bytes < offsetof(struct d6_packet, d6_options)) { 42 if (bytes < offsetof(struct d6_packet, d6_options)) {
43 bb_info_msg("packet with bad magic, ignoring"); 43 bb_simple_info_msg("packet with bad magic, ignoring");
44 return -2; 44 return -2;
45 } 45 }
46 log1("received %s", "a packet"); 46 log1("received %s", "a packet");
diff --git a/networking/udhcp/d6_socket.c b/networking/udhcp/d6_socket.c
index 25e622d6f..8ddee5a8e 100644
--- a/networking/udhcp/d6_socket.c
+++ b/networking/udhcp/d6_socket.c
@@ -115,7 +115,7 @@ int FAST_FUNC d6_listen_socket(int port, const char *inf)
115 115
116 setsockopt_reuseaddr(fd); 116 setsockopt_reuseaddr(fd);
117 if (setsockopt_broadcast(fd) == -1) 117 if (setsockopt_broadcast(fd) == -1)
118 bb_perror_msg_and_die("SO_BROADCAST"); 118 bb_simple_perror_msg_and_die("SO_BROADCAST");
119 119
120 /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ 120 /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */
121 if (setsockopt_bindtodevice(fd, inf)) 121 if (setsockopt_bindtodevice(fd, inf))
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index d1a0eaf02..656295ff7 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -906,7 +906,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
906 if (bytes < 0) { 906 if (bytes < 0) {
907 if (errno == EINTR) 907 if (errno == EINTR)
908 continue; 908 continue;
909 log1("packet read error, ignoring"); 909 log1s("packet read error, ignoring");
910 /* NB: possible down interface, etc. Caller should pause. */ 910 /* NB: possible down interface, etc. Caller should pause. */
911 return bytes; /* returns -1 */ 911 return bytes; /* returns -1 */
912 } 912 }
@@ -914,13 +914,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
914 } 914 }
915 915
916 if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { 916 if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
917 log1("packet is too short, ignoring"); 917 log1s("packet is too short, ignoring");
918 return -2; 918 return -2;
919 } 919 }
920 920
921 if (bytes < ntohs(packet.ip.tot_len)) { 921 if (bytes < ntohs(packet.ip.tot_len)) {
922 /* packet is bigger than sizeof(packet), we did partial read */ 922 /* packet is bigger than sizeof(packet), we did partial read */
923 log1("oversized packet, ignoring"); 923 log1s("oversized packet, ignoring");
924 return -2; 924 return -2;
925 } 925 }
926 926
@@ -935,7 +935,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
935 /* || bytes > (int) sizeof(packet) - can't happen */ 935 /* || bytes > (int) sizeof(packet) - can't happen */
936 || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) 936 || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
937 ) { 937 ) {
938 log1("unrelated/bogus packet, ignoring"); 938 log1s("unrelated/bogus packet, ignoring");
939 return -2; 939 return -2;
940 } 940 }
941 941
@@ -943,7 +943,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
943 check = packet.ip.check; 943 check = packet.ip.check;
944 packet.ip.check = 0; 944 packet.ip.check = 0;
945 if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) { 945 if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) {
946 log1("bad IP header checksum, ignoring"); 946 log1s("bad IP header checksum, ignoring");
947 return -2; 947 return -2;
948 } 948 }
949 949
@@ -968,13 +968,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
968 check = packet.udp.check; 968 check = packet.udp.check;
969 packet.udp.check = 0; 969 packet.udp.check = 0;
970 if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { 970 if (check && check != inet_cksum((uint16_t *)&packet, bytes)) {
971 log1("packet with bad UDP checksum received, ignoring"); 971 log1s("packet with bad UDP checksum received, ignoring");
972 return -2; 972 return -2;
973 } 973 }
974 skip_udp_sum_check: 974 skip_udp_sum_check:
975 975
976 if (packet.data.cookie != htonl(DHCP_MAGIC)) { 976 if (packet.data.cookie != htonl(DHCP_MAGIC)) {
977 bb_info_msg("packet with bad magic, ignoring"); 977 bb_simple_info_msg("packet with bad magic, ignoring");
978 return -2; 978 return -2;
979 } 979 }
980 980
@@ -1089,10 +1089,10 @@ static int udhcp_raw_socket(int ifindex)
1089 1089
1090 if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) { 1090 if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) {
1091 if (errno != ENOPROTOOPT) 1091 if (errno != ENOPROTOOPT)
1092 log1("can't set PACKET_AUXDATA on raw socket"); 1092 log1s("can't set PACKET_AUXDATA on raw socket");
1093 } 1093 }
1094 1094
1095 log1("created raw socket"); 1095 log1s("created raw socket");
1096 1096
1097 return fd; 1097 return fd;
1098} 1098}
@@ -1120,7 +1120,7 @@ static void change_listen_mode(int new_mode)
1120/* Called only on SIGUSR1 */ 1120/* Called only on SIGUSR1 */
1121static void perform_renew(void) 1121static void perform_renew(void)
1122{ 1122{
1123 bb_info_msg("performing DHCP renew"); 1123 bb_simple_info_msg("performing DHCP renew");
1124 switch (client_data.state) { 1124 switch (client_data.state) {
1125 case BOUND: 1125 case BOUND:
1126 change_listen_mode(LISTEN_KERNEL); 1126 change_listen_mode(LISTEN_KERNEL);
@@ -1158,7 +1158,7 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip)
1158 inet_ntoa(temp_addr), buffer); 1158 inet_ntoa(temp_addr), buffer);
1159 send_release(server_addr, requested_ip); /* unicast */ 1159 send_release(server_addr, requested_ip); /* unicast */
1160 } 1160 }
1161 bb_info_msg("entering released state"); 1161 bb_simple_info_msg("entering released state");
1162/* 1162/*
1163 * We can be here on: SIGUSR2, 1163 * We can be here on: SIGUSR2,
1164 * or on exit (SIGTERM) and -R "release on quit" is specified. 1164 * or on exit (SIGTERM) and -R "release on quit" is specified.
@@ -1303,7 +1303,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1303 ); 1303 );
1304 if (opt & (OPT_h|OPT_H)) { 1304 if (opt & (OPT_h|OPT_H)) {
1305 //msg added 2011-11 1305 //msg added 2011-11
1306 bb_error_msg("option -h NAME is deprecated, use -x hostname:NAME"); 1306 bb_simple_error_msg("option -h NAME is deprecated, use -x hostname:NAME");
1307 client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0); 1307 client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
1308 } 1308 }
1309 if (opt & OPT_F) { 1309 if (opt & OPT_F) {
@@ -1397,7 +1397,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1397 /* Create pidfile */ 1397 /* Create pidfile */
1398 write_pidfile(client_data.pidfile); 1398 write_pidfile(client_data.pidfile);
1399 /* Goes to stdout (unless NOMMU) and possibly syslog */ 1399 /* Goes to stdout (unless NOMMU) and possibly syslog */
1400 bb_info_msg("started, v"BB_VER); 1400 bb_simple_info_msg("started, v"BB_VER);
1401 /* We want random_xid to be random... */ 1401 /* We want random_xid to be random... */
1402 srand(monotonic_us()); 1402 srand(monotonic_us());
1403 1403
@@ -1444,7 +1444,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1444 continue; 1444 continue;
1445 } 1445 }
1446 /* Else: an error occurred, panic! */ 1446 /* Else: an error occurred, panic! */
1447 bb_perror_msg_and_die("poll"); 1447 bb_simple_perror_msg_and_die("poll");
1448 } 1448 }
1449 } 1449 }
1450 1450
@@ -1485,7 +1485,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1485 udhcp_run_script(NULL, "leasefail"); 1485 udhcp_run_script(NULL, "leasefail");
1486#if BB_MMU /* -b is not supported on NOMMU */ 1486#if BB_MMU /* -b is not supported on NOMMU */
1487 if (opt & OPT_b) { /* background if no lease */ 1487 if (opt & OPT_b) { /* background if no lease */
1488 bb_info_msg("no lease, forking to background"); 1488 bb_simple_info_msg("no lease, forking to background");
1489 client_background(); 1489 client_background();
1490 /* do not background again! */ 1490 /* do not background again! */
1491 opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); 1491 opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f);
@@ -1498,7 +1498,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1498 } else 1498 } else
1499#endif 1499#endif
1500 if (opt & OPT_n) { /* abort if no lease */ 1500 if (opt & OPT_n) { /* abort if no lease */
1501 bb_info_msg("no lease, failing"); 1501 bb_simple_info_msg("no lease, failing");
1502 retval = 1; 1502 retval = 1;
1503 goto ret; 1503 goto ret;
1504 } 1504 }
@@ -1526,7 +1526,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1526 client_data.state = RENEWING; 1526 client_data.state = RENEWING;
1527 client_data.first_secs = 0; /* make secs field count from 0 */ 1527 client_data.first_secs = 0; /* make secs field count from 0 */
1528 change_listen_mode(LISTEN_KERNEL); 1528 change_listen_mode(LISTEN_KERNEL);
1529 log1("entering renew state"); 1529 log1s("entering renew state");
1530 /* fall right through */ 1530 /* fall right through */
1531 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ 1531 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
1532 case_RENEW_REQUESTED: 1532 case_RENEW_REQUESTED:
@@ -1559,7 +1559,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1559 */ 1559 */
1560 } 1560 }
1561 /* Timed out or error, enter rebinding state */ 1561 /* Timed out or error, enter rebinding state */
1562 log1("entering rebinding state"); 1562 log1s("entering rebinding state");
1563 client_data.state = REBINDING; 1563 client_data.state = REBINDING;
1564 /* fall right through */ 1564 /* fall right through */
1565 case REBINDING: 1565 case REBINDING:
@@ -1574,7 +1574,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1574 continue; 1574 continue;
1575 } 1575 }
1576 /* Timed out, enter init state */ 1576 /* Timed out, enter init state */
1577 bb_info_msg("lease lost, entering init state"); 1577 bb_simple_info_msg("lease lost, entering init state");
1578 udhcp_run_script(NULL, "deconfig"); 1578 udhcp_run_script(NULL, "deconfig");
1579 client_data.state = INIT_SELECTING; 1579 client_data.state = INIT_SELECTING;
1580 client_data.first_secs = 0; /* make secs field count from 0 */ 1580 client_data.first_secs = 0; /* make secs field count from 0 */
@@ -1660,13 +1660,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1660 || memcmp(packet.chaddr, client_data.client_mac, 6) != 0 1660 || memcmp(packet.chaddr, client_data.client_mac, 6) != 0
1661 ) { 1661 ) {
1662//FIXME: need to also check that last 10 bytes are zero 1662//FIXME: need to also check that last 10 bytes are zero
1663 log1("chaddr does not match, ignoring packet"); // log2? 1663 log1("chaddr does not match%s", ", ignoring packet"); // log2?
1664 continue; 1664 continue;
1665 } 1665 }
1666 1666
1667 message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); 1667 message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE);
1668 if (message == NULL) { 1668 if (message == NULL) {
1669 bb_info_msg("no message type option, ignoring packet"); 1669 bb_info_msg("no message type option%s", ", ignoring packet");
1670 continue; 1670 continue;
1671 } 1671 }
1672 1672
@@ -1703,7 +1703,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1703 server_addr = 0; 1703 server_addr = 0;
1704 temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); 1704 temp = udhcp_get_option32(&packet, DHCP_SERVER_ID);
1705 if (!temp) { 1705 if (!temp) {
1706 bb_info_msg("no server ID, using 0.0.0.0"); 1706 bb_simple_info_msg("no server ID, using 0.0.0.0");
1707 } else { 1707 } else {
1708 /* it IS unaligned sometimes, don't "optimize" */ 1708 /* it IS unaligned sometimes, don't "optimize" */
1709 move_from_unaligned32(server_addr, temp); 1709 move_from_unaligned32(server_addr, temp);
@@ -1730,7 +1730,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1730 1730
1731 temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); 1731 temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME);
1732 if (!temp) { 1732 if (!temp) {
1733 bb_info_msg("no lease time with ACK, using 1 hour lease"); 1733 bb_simple_info_msg("no lease time with ACK, using 1 hour lease");
1734 lease_seconds = 60 * 60; 1734 lease_seconds = 60 * 60;
1735 } else { 1735 } else {
1736 /* it IS unaligned sometimes, don't "optimize" */ 1736 /* it IS unaligned sometimes, don't "optimize" */
@@ -1763,7 +1763,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1763 client_data.interface, 1763 client_data.interface,
1764 arpping_ms) 1764 arpping_ms)
1765 ) { 1765 ) {
1766 bb_info_msg("offered address is in use " 1766 bb_simple_info_msg("offered address is in use "
1767 "(got ARP reply), declining"); 1767 "(got ARP reply), declining");
1768 send_decline(/*xid,*/ server_addr, packet.yiaddr); 1768 send_decline(/*xid,*/ server_addr, packet.yiaddr);
1769 1769
@@ -1827,7 +1827,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1827 if (!temp) { 1827 if (!temp) {
1828 non_matching_svid: 1828 non_matching_svid:
1829 log1("received DHCP NAK with wrong" 1829 log1("received DHCP NAK with wrong"
1830 " server ID, ignoring packet"); 1830 " server ID%s", ", ignoring packet");
1831 continue; 1831 continue;
1832 } 1832 }
1833 move_from_unaligned32(svid, temp); 1833 move_from_unaligned32(svid, temp);
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 022b8721b..3e08ec011 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -582,11 +582,11 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc
582 || (dhcp_pkt->flags & htons(BROADCAST_FLAG)) 582 || (dhcp_pkt->flags & htons(BROADCAST_FLAG))
583 || dhcp_pkt->ciaddr == 0 583 || dhcp_pkt->ciaddr == 0
584 ) { 584 ) {
585 log1("broadcasting packet to client"); 585 log1s("broadcasting packet to client");
586 ciaddr = INADDR_BROADCAST; 586 ciaddr = INADDR_BROADCAST;
587 chaddr = MAC_BCAST_ADDR; 587 chaddr = MAC_BCAST_ADDR;
588 } else { 588 } else {
589 log1("unicasting packet to client ciaddr"); 589 log1s("unicasting packet to client ciaddr");
590 ciaddr = dhcp_pkt->ciaddr; 590 ciaddr = dhcp_pkt->ciaddr;
591 chaddr = dhcp_pkt->chaddr; 591 chaddr = dhcp_pkt->chaddr;
592 } 592 }
@@ -600,7 +600,7 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc
600/* Send a packet to gateway_nip using the kernel ip stack */ 600/* Send a packet to gateway_nip using the kernel ip stack */
601static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt) 601static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
602{ 602{
603 log1("forwarding packet to relay"); 603 log1s("forwarding packet to relay");
604 604
605 udhcp_send_kernel_packet(dhcp_pkt, 605 udhcp_send_kernel_packet(dhcp_pkt,
606 server_data.server_nip, SERVER_PORT, 606 server_data.server_nip, SERVER_PORT,
@@ -754,7 +754,7 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
754 } 754 }
755 755
756 if (!packet.yiaddr) { 756 if (!packet.yiaddr) {
757 bb_error_msg("no free IP addresses. OFFER abandoned"); 757 bb_simple_error_msg("no free IP addresses. OFFER abandoned");
758 return; 758 return;
759 } 759 }
760 /* Reserve the IP for a short time hoping to get DHCPREQUEST soon */ 760 /* Reserve the IP for a short time hoping to get DHCPREQUEST soon */
@@ -765,7 +765,7 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
765 p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0 765 p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0
766 ); 766 );
767 if (!lease) { 767 if (!lease) {
768 bb_error_msg("no free IP addresses. OFFER abandoned"); 768 bb_simple_error_msg("no free IP addresses. OFFER abandoned");
769 return; 769 return;
770 } 770 }
771 } 771 }
@@ -914,7 +914,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
914 write_pidfile(server_data.pidfile); 914 write_pidfile(server_data.pidfile);
915 /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ 915 /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */
916 916
917 bb_info_msg("started, v"BB_VER); 917 bb_simple_info_msg("started, v"BB_VER);
918 918
919 option = udhcp_find_option(server_data.options, DHCP_LEASE_TIME); 919 option = udhcp_find_option(server_data.options, DHCP_LEASE_TIME);
920 server_data.max_lease_sec = DEFAULT_LEASE_TIME; 920 server_data.max_lease_sec = DEFAULT_LEASE_TIME;
@@ -985,7 +985,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
985 if (errno == EINTR) 985 if (errno == EINTR)
986 goto new_tv; 986 goto new_tv;
987 /* < 0 and not EINTR: should not happen */ 987 /* < 0 and not EINTR: should not happen */
988 bb_perror_msg_and_die("poll"); 988 bb_simple_perror_msg_and_die("poll");
989 } 989 }
990 990
991 if (pfds[0].revents) switch (udhcp_sp_read()) { 991 if (pfds[0].revents) switch (udhcp_sp_read()) {
@@ -1019,16 +1019,16 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
1019 continue; 1019 continue;
1020 } 1020 }
1021 if (packet.hlen != 6) { 1021 if (packet.hlen != 6) {
1022 bb_info_msg("MAC length != 6, ignoring packet"); 1022 bb_info_msg("MAC length != 6%s", ", ignoring packet");
1023 continue; 1023 continue;
1024 } 1024 }
1025 if (packet.op != BOOTREQUEST) { 1025 if (packet.op != BOOTREQUEST) {
1026 bb_info_msg("not a REQUEST, ignoring packet"); 1026 bb_info_msg("not a REQUEST%s", ", ignoring packet");
1027 continue; 1027 continue;
1028 } 1028 }
1029 state = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); 1029 state = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE);
1030 if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) { 1030 if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) {
1031 bb_info_msg("no or bad message type option, ignoring packet"); 1031 bb_info_msg("no or bad message type option%s", ", ignoring packet");
1032 continue; 1032 continue;
1033 } 1033 }
1034 1034
@@ -1039,7 +1039,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
1039 move_from_unaligned32(server_id_network_order, server_id_opt); 1039 move_from_unaligned32(server_id_network_order, server_id_opt);
1040 if (server_id_network_order != server_data.server_nip) { 1040 if (server_id_network_order != server_data.server_nip) {
1041 /* client talks to somebody else */ 1041 /* client talks to somebody else */
1042 log1("server ID doesn't match, ignoring"); 1042 log1("server ID doesn't match%s", ", ignoring");
1043 continue; 1043 continue;
1044 } 1044 }
1045 } 1045 }
@@ -1162,7 +1162,7 @@ o DHCPREQUEST generated during REBINDING state:
1162 if (!requested_ip_opt) { 1162 if (!requested_ip_opt) {
1163 requested_nip = packet.ciaddr; 1163 requested_nip = packet.ciaddr;
1164 if (requested_nip == 0) { 1164 if (requested_nip == 0) {
1165 log1("no requested IP and no ciaddr, ignoring"); 1165 log1("no requested IP and no ciaddr%s", ", ignoring");
1166 break; 1166 break;
1167 } 1167 }
1168 } 1168 }
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c
index 86dcb1af0..ef9447b4b 100644
--- a/networking/udhcp/dhcprelay.c
+++ b/networking/udhcp/dhcprelay.c
@@ -186,7 +186,7 @@ static int sendto_ip4(int sock, const void *msg, int msg_len, struct sockaddr_in
186 err = sendto(sock, msg, msg_len, 0, (struct sockaddr*) to, sizeof(*to)); 186 err = sendto(sock, msg, msg_len, 0, (struct sockaddr*) to, sizeof(*to));
187 err -= msg_len; 187 err -= msg_len;
188 if (err) 188 if (err)
189 bb_perror_msg("sendto"); 189 bb_simple_perror_msg("sendto");
190 return err; 190 return err;
191} 191}
192 192
@@ -273,7 +273,7 @@ int dhcprelay_main(int argc UNUSED_PARAM, char **argv)
273 bb_show_usage(); 273 bb_show_usage();
274 if (argv[3]) { 274 if (argv[3]) {
275 if (!inet_aton(argv[3], &server_addr.sin_addr)) 275 if (!inet_aton(argv[3], &server_addr.sin_addr))
276 bb_perror_msg_and_die("bad server IP"); 276 bb_simple_perror_msg_and_die("bad server IP");
277 } 277 }
278 278
279 iface_list = make_iface_list(argv + 1, &num_sockets); 279 iface_list = make_iface_list(argv + 1, &num_sockets);
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 64af802a3..6d4375237 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -85,14 +85,14 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
85 memset(packet, 0, sizeof(*packet)); 85 memset(packet, 0, sizeof(*packet));
86 bytes = safe_read(fd, packet, sizeof(*packet)); 86 bytes = safe_read(fd, packet, sizeof(*packet));
87 if (bytes < 0) { 87 if (bytes < 0) {
88 log1("packet read error, ignoring"); 88 log1s("packet read error, ignoring");
89 return bytes; /* returns -1 */ 89 return bytes; /* returns -1 */
90 } 90 }
91 91
92 if (bytes < offsetof(struct dhcp_packet, options) 92 if (bytes < offsetof(struct dhcp_packet, options)
93 || packet->cookie != htonl(DHCP_MAGIC) 93 || packet->cookie != htonl(DHCP_MAGIC)
94 ) { 94 ) {
95 bb_info_msg("packet with bad magic, ignoring"); 95 bb_simple_info_msg("packet with bad magic, ignoring");
96 return -2; 96 return -2;
97 } 97 }
98 log1("received %s", "a packet"); 98 log1("received %s", "a packet");
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c
index 81d1fc01a..7df671245 100644
--- a/networking/udhcp/signalpipe.c
+++ b/networking/udhcp/signalpipe.c
@@ -28,7 +28,7 @@ static void signal_handler(int sig)
28 int sv = errno; 28 int sv = errno;
29 unsigned char ch = sig; /* use char, avoid dealing with partial writes */ 29 unsigned char ch = sig; /* use char, avoid dealing with partial writes */
30 if (write(WRITE_FD, &ch, 1) != 1) 30 if (write(WRITE_FD, &ch, 1) != 1)
31 bb_perror_msg("can't send signal"); 31 bb_simple_perror_msg("can't send signal");
32 errno = sv; 32 errno = sv;
33} 33}
34 34
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 34049c3ee..65a1a8ead 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -87,7 +87,7 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf)
87 87
88 setsockopt_reuseaddr(fd); 88 setsockopt_reuseaddr(fd);
89 if (setsockopt_broadcast(fd) == -1) 89 if (setsockopt_broadcast(fd) == -1)
90 bb_perror_msg_and_die("SO_BROADCAST"); 90 bb_simple_perror_msg_and_die("SO_BROADCAST");
91 91
92 /* SO_BINDTODEVICE doesn't work on ethernet aliases (ethN:M) */ 92 /* SO_BINDTODEVICE doesn't work on ethernet aliases (ethN:M) */
93 colon = strrchr(inf, ':'); 93 colon = strrchr(inf, ':');