aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-05-16 11:27:28 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-05-16 11:27:28 +0200
commit25393fb55e515cab25bb932420813f2c5bbd18f9 (patch)
tree3e021a9afac176b3a7331c2121b8b12a9a1ec933 /networking/udhcp/dhcpd.c
parenta840884531df649aabc72debb2d6025dabe2abb3 (diff)
downloadbusybox-w32-25393fb55e515cab25bb932420813f2c5bbd18f9.tar.gz
busybox-w32-25393fb55e515cab25bb932420813f2c5bbd18f9.tar.bz2
busybox-w32-25393fb55e515cab25bb932420813f2c5bbd18f9.zip
udhcpd: code shrink
function old new delta send_packet_verbose - 35 +35 send_offer 443 423 -20 send_ACK 152 131 -21 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 35/-41) Total: -6 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--networking/udhcp/dhcpd.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index f231e4001..3d60abf8f 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -627,6 +627,15 @@ static void send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast)
627 send_packet_to_client(dhcp_pkt, force_broadcast); 627 send_packet_to_client(dhcp_pkt, force_broadcast);
628} 628}
629 629
630static void send_packet_verbose(struct dhcp_packet *dhcp_pkt, const char *fmt)
631{
632 struct in_addr addr;
633 addr.s_addr = dhcp_pkt->yiaddr;
634 bb_info_msg(fmt, inet_ntoa(addr));
635 /* send_packet emits error message itself if it detects failure */
636 send_packet(dhcp_pkt, /*force_bcast:*/ 0);
637}
638
630static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacket, char type) 639static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacket, char type)
631{ 640{
632 /* Sets op, htype, hlen, cookie fields 641 /* Sets op, htype, hlen, cookie fields
@@ -722,7 +731,6 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
722{ 731{
723 struct dhcp_packet packet; 732 struct dhcp_packet packet;
724 uint32_t lease_time_sec; 733 uint32_t lease_time_sec;
725 struct in_addr addr;
726 734
727 init_packet(&packet, oldpacket, DHCPOFFER); 735 init_packet(&packet, oldpacket, DHCPOFFER);
728 736
@@ -778,10 +786,8 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
778 udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec)); 786 udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec));
779 add_server_options(&packet); 787 add_server_options(&packet);
780 788
781 addr.s_addr = packet.yiaddr;
782 bb_info_msg("sending OFFER of %s", inet_ntoa(addr));
783 /* send_packet emits error message itself if it detects failure */ 789 /* send_packet emits error message itself if it detects failure */
784 send_packet(&packet, /*force_bcast:*/ 0); 790 send_packet_verbose(&packet, "sending OFFER to %s");
785} 791}
786 792
787/* NOINLINE: limit stack usage in caller */ 793/* NOINLINE: limit stack usage in caller */
@@ -800,7 +806,6 @@ static NOINLINE void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
800{ 806{
801 struct dhcp_packet packet; 807 struct dhcp_packet packet;
802 uint32_t lease_time_sec; 808 uint32_t lease_time_sec;
803 struct in_addr addr;
804 const char *p_host_name; 809 const char *p_host_name;
805 810
806 init_packet(&packet, oldpacket, DHCPACK); 811 init_packet(&packet, oldpacket, DHCPACK);
@@ -810,9 +815,7 @@ static NOINLINE void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
810 udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec)); 815 udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec));
811 add_server_options(&packet); 816 add_server_options(&packet);
812 817
813 addr.s_addr = yiaddr; 818 send_packet_verbose(&packet, "sending ACK to %s");
814 bb_info_msg("sending ACK to %s", inet_ntoa(addr));
815 send_packet(&packet, /*force_bcast:*/ 0);
816 819
817 p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME); 820 p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
818 add_lease(packet.chaddr, packet.yiaddr, 821 add_lease(packet.chaddr, packet.yiaddr,
@@ -852,6 +855,7 @@ static NOINLINE void send_inform(struct dhcp_packet *oldpacket)
852 add_server_options(&packet); 855 add_server_options(&packet);
853 856
854 send_packet(&packet, /*force_bcast:*/ 0); 857 send_packet(&packet, /*force_bcast:*/ 0);
858 // or maybe? send_packet_verbose(&packet, "sending ACK to %s");
855} 859}
856 860
857int udhcpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 861int udhcpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;