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>
This commit is contained in:
Denys Vlasenko 2020-12-15 21:55:15 +01:00
parent b817699e6c
commit f3d6711c97
3 changed files with 19 additions and 25 deletions

View File

@ -159,18 +159,16 @@ int FAST_FUNC d6_recv_kernel_packet(
struct d6_packet *packet, int fd struct d6_packet *packet, int fd
); );
int FAST_FUNC d6_send_raw_packet( int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex(
struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct d6_packet *d6_pkt, unsigned d6_pkt_size,
struct in6_addr *src_ipv6, int source_port, struct in6_addr *src_ipv6, int source_port,
struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp, struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp
int ifindex
); );
int FAST_FUNC d6_send_kernel_packet( int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex(
struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct d6_packet *d6_pkt, unsigned d6_pkt_size,
struct in6_addr *src_ipv6, int source_port, struct in6_addr *src_ipv6, int source_port,
struct in6_addr *dst_ipv6, int dest_port, struct in6_addr *dst_ipv6, int dest_port
int ifindex
); );
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2

View File

@ -558,11 +558,10 @@ static int d6_mcast_from_client_data_ifindex(struct d6_packet *packet, uint8_t *
0x33, 0x33, 0x00, 0x01, 0x00, 0x02, 0x33, 0x33, 0x00, 0x01, 0x00, 0x02,
}; };
return d6_send_raw_packet( return d6_send_raw_packet_from_client_data_ifindex(
packet, (end - (uint8_t*) packet), packet, (end - (uint8_t*) packet),
/*src*/ &client6_data.ll_ip6, CLIENT_PORT6, /*src*/ &client6_data.ll_ip6, CLIENT_PORT6,
/*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_DHCP6MCAST_ADDR, /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_DHCP6MCAST_ADDR
client_data.ifindex
); );
} }
@ -864,11 +863,10 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st
bb_info_msg("sending %s", "renew"); bb_info_msg("sending %s", "renew");
if (server_ipv6) if (server_ipv6)
return d6_send_kernel_packet( return d6_send_kernel_packet_from_client_data_ifindex(
&packet, (opt_ptr - (uint8_t*) &packet), &packet, (opt_ptr - (uint8_t*) &packet),
our_cur_ipv6, CLIENT_PORT6, our_cur_ipv6, CLIENT_PORT6,
server_ipv6, SERVER_PORT6, server_ipv6, SERVER_PORT6
client_data.ifindex
); );
return d6_mcast_from_client_data_ifindex(&packet, opt_ptr); return d6_mcast_from_client_data_ifindex(&packet, opt_ptr);
} }
@ -893,11 +891,10 @@ int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6)
opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, client6_data.ia_pd->len + 2+2); opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, client6_data.ia_pd->len + 2+2);
bb_info_msg("sending %s", "release"); bb_info_msg("sending %s", "release");
return d6_send_kernel_packet( return d6_send_kernel_packet_from_client_data_ifindex(
&packet, (opt_ptr - (uint8_t*) &packet), &packet, (opt_ptr - (uint8_t*) &packet),
our_cur_ipv6, CLIENT_PORT6, our_cur_ipv6, CLIENT_PORT6,
server_ipv6, SERVER_PORT6, server_ipv6, SERVER_PORT6
client_data.ifindex
); );
} }

View File

@ -6,6 +6,7 @@
*/ */
#include "common.h" #include "common.h"
#include "d6_common.h" #include "d6_common.h"
#include "dhcpc.h"
#include "dhcpd.h" #include "dhcpd.h"
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/if_ether.h> #include <netinet/if_ether.h>
@ -50,11 +51,10 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6
} }
/* Construct a ipv6+udp header for a packet, send packet */ /* Construct a ipv6+udp header for a packet, send packet */
int FAST_FUNC d6_send_raw_packet( int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex(
struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct d6_packet *d6_pkt, unsigned d6_pkt_size,
struct in6_addr *src_ipv6, int source_port, struct in6_addr *src_ipv6, int source_port,
struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp, struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp)
int ifindex)
{ {
struct sockaddr_ll dest_sll; struct sockaddr_ll dest_sll;
struct ip6_udp_d6_packet packet; struct ip6_udp_d6_packet packet;
@ -74,7 +74,7 @@ int FAST_FUNC d6_send_raw_packet(
dest_sll.sll_family = AF_PACKET; dest_sll.sll_family = AF_PACKET;
dest_sll.sll_protocol = htons(ETH_P_IPV6); dest_sll.sll_protocol = htons(ETH_P_IPV6);
dest_sll.sll_ifindex = ifindex; dest_sll.sll_ifindex = client_data.ifindex;
/*dest_sll.sll_hatype = ARPHRD_???;*/ /*dest_sll.sll_hatype = ARPHRD_???;*/
/*dest_sll.sll_pkttype = PACKET_???;*/ /*dest_sll.sll_pkttype = PACKET_???;*/
dest_sll.sll_halen = 6; dest_sll.sll_halen = 6;
@ -103,8 +103,8 @@ int FAST_FUNC d6_send_raw_packet(
*/ */
packet.ip6.ip6_hlim = IPPROTO_UDP; packet.ip6.ip6_hlim = IPPROTO_UDP;
packet.udp.check = inet_cksum( packet.udp.check = inet_cksum(
(uint8_t *)&packet + 4, (uint8_t *)&packet + 4,
offsetof(struct ip6_udp_d6_packet, data) - 4 + d6_pkt_size offsetof(struct ip6_udp_d6_packet, data) - 4 + d6_pkt_size
); );
/* fix 'hop limit' and 'next header' after UDP checksumming */ /* fix 'hop limit' and 'next header' after UDP checksumming */
packet.ip6.ip6_hlim = 1; /* observed Windows machines to use hlim=1 */ packet.ip6.ip6_hlim = 1; /* observed Windows machines to use hlim=1 */
@ -126,11 +126,10 @@ int FAST_FUNC d6_send_raw_packet(
} }
/* Let the kernel do all the work for packet generation */ /* Let the kernel do all the work for packet generation */
int FAST_FUNC d6_send_kernel_packet( int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex(
struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct d6_packet *d6_pkt, unsigned d6_pkt_size,
struct in6_addr *src_ipv6, int source_port, struct in6_addr *src_ipv6, int source_port,
struct in6_addr *dst_ipv6, int dest_port, struct in6_addr *dst_ipv6, int dest_port)
int ifindex)
{ {
struct sockaddr_in6 sa; struct sockaddr_in6 sa;
int fd; int fd;
@ -157,7 +156,7 @@ int FAST_FUNC d6_send_kernel_packet(
sa.sin6_family = AF_INET6; sa.sin6_family = AF_INET6;
sa.sin6_port = htons(dest_port); sa.sin6_port = htons(dest_port);
sa.sin6_addr = *dst_ipv6; /* struct copy */ sa.sin6_addr = *dst_ipv6; /* struct copy */
sa.sin6_scope_id = ifindex; sa.sin6_scope_id = client_data.ifindex;
if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
msg = "connect"; msg = "connect";
goto ret_close; goto ret_close;