From 64483324c5422ad8e3cf413929b1360ce6245e7e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 20 Feb 2021 18:09:54 +0100 Subject: udhcpc: clarify bcast/unicast sends in logs, include server ID Before: sending discover sending select for 192.168.1.173 lease of 192.168.1.173 obtained, lease time 43200 sending renew to 192.168.1.1 lease of 192.168.1.173 obtained, lease time 43200 After: broadcasting discover broadcasting select for 192.168.1.173, server 192.168.1.1 lease of 192.168.1.173 obtained from 192.168.1.1, lease time 43200 sending renew to server 192.168.1.1 lease of 192.168.1.173 obtained from 192.168.1.1, lease time 43200 function old new delta udhcpc_main 2580 2610 +30 send_select 104 130 +26 send_renew 82 99 +17 send_discover 94 89 -5 send_decline 93 88 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/2 up/down: 73/-10) Total: 63 bytes text data bss dec hex filename 1019732 559 5020 1025311 fa51f busybox_old 1019898 559 5020 1025477 fa5c5 busybox_unstripped Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'networking/udhcp/dhcpc.c') diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 922c71ebd..f1f6720f3 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -729,7 +729,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) */ add_client_options(&packet); - bb_info_msg("sending %s", "discover"); + bb_simple_info_msg("broadcasting discover"); return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); } @@ -742,6 +742,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste { struct dhcp_packet packet; struct in_addr temp_addr; + char server_str[sizeof("255.255.255.255")]; /* * RFC 2131 4.3.2 DHCPREQUEST message @@ -772,8 +773,13 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste */ add_client_options(&packet); + temp_addr.s_addr = server; + strcpy(server_str, inet_ntoa(temp_addr)); temp_addr.s_addr = requested; - bb_info_msg("sending select for %s", inet_ntoa(temp_addr)); + bb_info_msg("broadcasting select for %s, server %s", + inet_ntoa(temp_addr), + server_str + ); return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); } @@ -782,7 +788,6 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) { struct dhcp_packet packet; - struct in_addr temp_addr; /* * RFC 2131 4.3.2 DHCPREQUEST message @@ -813,8 +818,14 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) */ add_client_options(&packet); - temp_addr.s_addr = server; - bb_info_msg("sending renew to %s", inet_ntoa(temp_addr)); + if (server) { + struct in_addr temp_addr; + temp_addr.s_addr = server; + bb_info_msg("sending renew to server %s", inet_ntoa(temp_addr)); + } else { + bb_simple_info_msg("broadcasting renew"); + } + return bcast_or_ucast(&packet, ciaddr, server); } @@ -843,7 +854,7 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); - bb_info_msg("sending %s", "decline"); + bb_simple_info_msg("broadcasting decline"); return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); } #endif @@ -1720,6 +1731,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) unsigned start; uint32_t lease_seconds; struct in_addr temp_addr; + char server_str[sizeof("255.255.255.255")]; uint8_t *temp; temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); @@ -1775,9 +1787,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) } #endif /* enter bound state */ + temp_addr.s_addr = server_addr; + strcpy(server_str, inet_ntoa(temp_addr)); temp_addr.s_addr = packet.yiaddr; - bb_info_msg("lease of %s obtained, lease time %u", - inet_ntoa(temp_addr), (unsigned)lease_seconds); + bb_info_msg("lease of %s obtained from %s, lease time %u", + inet_ntoa(temp_addr), server_str, (unsigned)lease_seconds); requested_ip = packet.yiaddr; start = monotonic_sec(); -- cgit v1.2.3 From a4959eef71067dd6763bf60113bdeafdcb5f2d91 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 21 Feb 2021 16:32:07 +0100 Subject: udhcp: reuse strings text data bss dec hex filename 1019916 559 5020 1025495 fa5d7 busybox_old 1019906 559 5020 1025485 fa5cd busybox_unstripped Signed-off-by: Denys Vlasenko --- networking/udhcp/d6_dhcpc.c | 14 ++++++++------ networking/udhcp/dhcpc.c | 6 ++++-- networking/udhcp/dhcpd.c | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'networking/udhcp/dhcpc.c') diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index fbdaa99bd..76b087b92 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -1589,8 +1589,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) } if ((packet.d6_xid32 & htonl(0x00ffffff)) != xid) { - log1("xid %x (our is %x), ignoring packet", - (unsigned)(packet.d6_xid32 & htonl(0x00ffffff)), (unsigned)xid); + log1("xid %x (our is %x)%s", + (unsigned)(packet.d6_xid32 & htonl(0x00ffffff)), (unsigned)xid, + ", ignoring packet" + ); continue; } @@ -1743,7 +1745,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) free(client6_data.ia_na); client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA); if (!client6_data.ia_na) { - bb_info_msg("no %s option, ignoring packet", "IA_NA"); + bb_info_msg("no %s option%s", "IA_NA", ", ignoring packet"); continue; } if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) { @@ -1756,7 +1758,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) D6_OPT_IAADDR ); if (!iaaddr) { - bb_info_msg("no %s option, ignoring packet", "IAADDR"); + bb_info_msg("no %s option%s", "IAADDR", ", ignoring packet"); continue; } if (iaaddr->len < (16 + 4 + 4)) { @@ -1781,7 +1783,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) free(client6_data.ia_pd); client6_data.ia_pd = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_PD); if (!client6_data.ia_pd) { - bb_info_msg("no %s option, ignoring packet", "IA_PD"); + bb_info_msg("no %s option%s", "IA_PD", ", ignoring packet"); continue; } if (client6_data.ia_pd->len < (4 + 4 + 4) + (2 + 2 + 4 + 4 + 1 + 16)) { @@ -1794,7 +1796,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) D6_OPT_IAPREFIX ); if (!iaprefix) { - bb_info_msg("no %s option, ignoring packet", "IAPREFIX"); + bb_info_msg("no %s option%s", "IAPREFIX", ", ignoring packet"); continue; } if (iaprefix->len < (4 + 4 + 1 + 16)) { diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index f1f6720f3..bbcbd1fca 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1655,8 +1655,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) } if (packet.xid != xid) { - log1("xid %x (our is %x), ignoring packet", - (unsigned)packet.xid, (unsigned)xid); + log1("xid %x (our is %x)%s", + (unsigned)packet.xid, (unsigned)xid, + ", ignoring packet" + ); continue; } diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index cd32cb437..260130507 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -1048,7 +1048,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) move_from_unaligned32(server_id_network_order, server_id_opt); if (server_id_network_order != server_data.server_nip) { /* client talks to somebody else */ - log1("server ID doesn't match%s", ", ignoring"); + log1("server ID doesn't match%s", ", ignoring packet"); continue; } } @@ -1171,7 +1171,7 @@ o DHCPREQUEST generated during REBINDING state: if (!requested_ip_opt) { requested_nip = packet.ciaddr; if (requested_nip == 0) { - log1("no requested IP and no ciaddr%s", ", ignoring"); + log1("no requested IP and no ciaddr%s", ", ignoring packet"); break; } } -- cgit v1.2.3