aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/d6_dhcpc.c
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/d6_dhcpc.c
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/d6_dhcpc.c')
-rw-r--r--networking/udhcp/d6_dhcpc.c34
1 files changed, 17 insertions, 17 deletions
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 }