diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-15 21:55:15 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-15 21:55:15 +0100 |
commit | f3d6711c971cde8ed3890a47020c5083a383e606 (patch) | |
tree | 6faa66f95c505bd3411825a0e623ae7162c7ceda | |
parent | b817699e6c5c8efe4fce45e910d66133c9d8c482 (diff) | |
download | busybox-w32-f3d6711c971cde8ed3890a47020c5083a383e606.tar.gz busybox-w32-f3d6711c971cde8ed3890a47020c5083a383e606.tar.bz2 busybox-w32-f3d6711c971cde8ed3890a47020c5083a383e606.zip |
udhcpc6: code shrink - sending functions do not need ifindex parameter
function old new delta
d6_send_raw_packet_from_client_data_ifindex - 427 +427
d6_send_kernel_packet_from_client_data_ifindex - 275 +275
send_d6_renew 182 176 -6
perform_d6_release 246 240 -6
d6_mcast_from_client_data_ifindex 45 39 -6
d6_send_kernel_packet 274 - -274
d6_send_raw_packet 429 - -429
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/3 up/down: 702/-721) Total: -19 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/udhcp/d6_common.h | 10 | ||||
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 15 | ||||
-rw-r--r-- | networking/udhcp/d6_packet.c | 19 |
3 files changed, 19 insertions, 25 deletions
diff --git a/networking/udhcp/d6_common.h b/networking/udhcp/d6_common.h index 688f5d6c7..9dfde7709 100644 --- a/networking/udhcp/d6_common.h +++ b/networking/udhcp/d6_common.h | |||
@@ -159,18 +159,16 @@ int FAST_FUNC d6_recv_kernel_packet( | |||
159 | struct d6_packet *packet, int fd | 159 | struct d6_packet *packet, int fd |
160 | ); | 160 | ); |
161 | 161 | ||
162 | int FAST_FUNC d6_send_raw_packet( | 162 | int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex( |
163 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, | 163 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, |
164 | struct in6_addr *src_ipv6, int source_port, | 164 | struct in6_addr *src_ipv6, int source_port, |
165 | struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp, | 165 | struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp |
166 | int ifindex | ||
167 | ); | 166 | ); |
168 | 167 | ||
169 | int FAST_FUNC d6_send_kernel_packet( | 168 | int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex( |
170 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, | 169 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, |
171 | struct in6_addr *src_ipv6, int source_port, | 170 | struct in6_addr *src_ipv6, int source_port, |
172 | struct in6_addr *dst_ipv6, int dest_port, | 171 | struct in6_addr *dst_ipv6, int dest_port |
173 | int ifindex | ||
174 | ); | 172 | ); |
175 | 173 | ||
176 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 | 174 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 |
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index ac8af91d3..744448cee 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -558,11 +558,10 @@ static int d6_mcast_from_client_data_ifindex(struct d6_packet *packet, uint8_t * | |||
558 | 0x33, 0x33, 0x00, 0x01, 0x00, 0x02, | 558 | 0x33, 0x33, 0x00, 0x01, 0x00, 0x02, |
559 | }; | 559 | }; |
560 | 560 | ||
561 | return d6_send_raw_packet( | 561 | return d6_send_raw_packet_from_client_data_ifindex( |
562 | packet, (end - (uint8_t*) packet), | 562 | packet, (end - (uint8_t*) packet), |
563 | /*src*/ &client6_data.ll_ip6, CLIENT_PORT6, | 563 | /*src*/ &client6_data.ll_ip6, CLIENT_PORT6, |
564 | /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_DHCP6MCAST_ADDR, | 564 | /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_DHCP6MCAST_ADDR |
565 | client_data.ifindex | ||
566 | ); | 565 | ); |
567 | } | 566 | } |
568 | 567 | ||
@@ -864,11 +863,10 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st | |||
864 | 863 | ||
865 | bb_info_msg("sending %s", "renew"); | 864 | bb_info_msg("sending %s", "renew"); |
866 | if (server_ipv6) | 865 | if (server_ipv6) |
867 | return d6_send_kernel_packet( | 866 | return d6_send_kernel_packet_from_client_data_ifindex( |
868 | &packet, (opt_ptr - (uint8_t*) &packet), | 867 | &packet, (opt_ptr - (uint8_t*) &packet), |
869 | our_cur_ipv6, CLIENT_PORT6, | 868 | our_cur_ipv6, CLIENT_PORT6, |
870 | server_ipv6, SERVER_PORT6, | 869 | server_ipv6, SERVER_PORT6 |
871 | client_data.ifindex | ||
872 | ); | 870 | ); |
873 | return d6_mcast_from_client_data_ifindex(&packet, opt_ptr); | 871 | return d6_mcast_from_client_data_ifindex(&packet, opt_ptr); |
874 | } | 872 | } |
@@ -893,11 +891,10 @@ int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) | |||
893 | opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, client6_data.ia_pd->len + 2+2); | 891 | opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, client6_data.ia_pd->len + 2+2); |
894 | 892 | ||
895 | bb_info_msg("sending %s", "release"); | 893 | bb_info_msg("sending %s", "release"); |
896 | return d6_send_kernel_packet( | 894 | return d6_send_kernel_packet_from_client_data_ifindex( |
897 | &packet, (opt_ptr - (uint8_t*) &packet), | 895 | &packet, (opt_ptr - (uint8_t*) &packet), |
898 | our_cur_ipv6, CLIENT_PORT6, | 896 | our_cur_ipv6, CLIENT_PORT6, |
899 | server_ipv6, SERVER_PORT6, | 897 | server_ipv6, SERVER_PORT6 |
900 | client_data.ifindex | ||
901 | ); | 898 | ); |
902 | } | 899 | } |
903 | 900 | ||
diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index 167a813e3..172f8e1ab 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c | |||
@@ -6,6 +6,7 @@ | |||
6 | */ | 6 | */ |
7 | #include "common.h" | 7 | #include "common.h" |
8 | #include "d6_common.h" | 8 | #include "d6_common.h" |
9 | #include "dhcpc.h" | ||
9 | #include "dhcpd.h" | 10 | #include "dhcpd.h" |
10 | #include <netinet/in.h> | 11 | #include <netinet/in.h> |
11 | #include <netinet/if_ether.h> | 12 | #include <netinet/if_ether.h> |
@@ -50,11 +51,10 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6 | |||
50 | } | 51 | } |
51 | 52 | ||
52 | /* Construct a ipv6+udp header for a packet, send packet */ | 53 | /* Construct a ipv6+udp header for a packet, send packet */ |
53 | int FAST_FUNC d6_send_raw_packet( | 54 | int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex( |
54 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, | 55 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, |
55 | struct in6_addr *src_ipv6, int source_port, | 56 | struct in6_addr *src_ipv6, int source_port, |
56 | struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp, | 57 | struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp) |
57 | int ifindex) | ||
58 | { | 58 | { |
59 | struct sockaddr_ll dest_sll; | 59 | struct sockaddr_ll dest_sll; |
60 | struct ip6_udp_d6_packet packet; | 60 | struct ip6_udp_d6_packet packet; |
@@ -74,7 +74,7 @@ int FAST_FUNC d6_send_raw_packet( | |||
74 | 74 | ||
75 | dest_sll.sll_family = AF_PACKET; | 75 | dest_sll.sll_family = AF_PACKET; |
76 | dest_sll.sll_protocol = htons(ETH_P_IPV6); | 76 | dest_sll.sll_protocol = htons(ETH_P_IPV6); |
77 | dest_sll.sll_ifindex = ifindex; | 77 | dest_sll.sll_ifindex = client_data.ifindex; |
78 | /*dest_sll.sll_hatype = ARPHRD_???;*/ | 78 | /*dest_sll.sll_hatype = ARPHRD_???;*/ |
79 | /*dest_sll.sll_pkttype = PACKET_???;*/ | 79 | /*dest_sll.sll_pkttype = PACKET_???;*/ |
80 | dest_sll.sll_halen = 6; | 80 | dest_sll.sll_halen = 6; |
@@ -103,8 +103,8 @@ int FAST_FUNC d6_send_raw_packet( | |||
103 | */ | 103 | */ |
104 | packet.ip6.ip6_hlim = IPPROTO_UDP; | 104 | packet.ip6.ip6_hlim = IPPROTO_UDP; |
105 | packet.udp.check = inet_cksum( | 105 | packet.udp.check = inet_cksum( |
106 | (uint8_t *)&packet + 4, | 106 | (uint8_t *)&packet + 4, |
107 | offsetof(struct ip6_udp_d6_packet, data) - 4 + d6_pkt_size | 107 | offsetof(struct ip6_udp_d6_packet, data) - 4 + d6_pkt_size |
108 | ); | 108 | ); |
109 | /* fix 'hop limit' and 'next header' after UDP checksumming */ | 109 | /* fix 'hop limit' and 'next header' after UDP checksumming */ |
110 | packet.ip6.ip6_hlim = 1; /* observed Windows machines to use hlim=1 */ | 110 | packet.ip6.ip6_hlim = 1; /* observed Windows machines to use hlim=1 */ |
@@ -126,11 +126,10 @@ int FAST_FUNC d6_send_raw_packet( | |||
126 | } | 126 | } |
127 | 127 | ||
128 | /* Let the kernel do all the work for packet generation */ | 128 | /* Let the kernel do all the work for packet generation */ |
129 | int FAST_FUNC d6_send_kernel_packet( | 129 | int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex( |
130 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, | 130 | struct d6_packet *d6_pkt, unsigned d6_pkt_size, |
131 | struct in6_addr *src_ipv6, int source_port, | 131 | struct in6_addr *src_ipv6, int source_port, |
132 | struct in6_addr *dst_ipv6, int dest_port, | 132 | struct in6_addr *dst_ipv6, int dest_port) |
133 | int ifindex) | ||
134 | { | 133 | { |
135 | struct sockaddr_in6 sa; | 134 | struct sockaddr_in6 sa; |
136 | int fd; | 135 | int fd; |
@@ -157,7 +156,7 @@ int FAST_FUNC d6_send_kernel_packet( | |||
157 | sa.sin6_family = AF_INET6; | 156 | sa.sin6_family = AF_INET6; |
158 | sa.sin6_port = htons(dest_port); | 157 | sa.sin6_port = htons(dest_port); |
159 | sa.sin6_addr = *dst_ipv6; /* struct copy */ | 158 | sa.sin6_addr = *dst_ipv6; /* struct copy */ |
160 | sa.sin6_scope_id = ifindex; | 159 | sa.sin6_scope_id = client_data.ifindex; |
161 | if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { | 160 | if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { |
162 | msg = "connect"; | 161 | msg = "connect"; |
163 | goto ret_close; | 162 | goto ret_close; |