udhcpc6: code shrink

function                                             old     new   delta
d6_read_interface                                    593     582     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2019-04-14 17:01:10 +02:00
parent 0d75e8b797
commit 60bf77f7e7
3 changed files with 18 additions and 10 deletions

View File

@ -145,7 +145,12 @@ struct client6_data_t {
#define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)])) #define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_addr *nip6, uint8_t *mac); int FAST_FUNC d6_read_interface(
const char *interface,
int *ifindex,
struct in6_addr *nip6,
uint8_t *mac
);
int FAST_FUNC d6_listen_socket(int port, const char *inf); int FAST_FUNC d6_listen_socket(int port, const char *inf);

View File

@ -204,7 +204,6 @@ static void *d6_copy_option(uint8_t *option, uint8_t *option_end, unsigned code)
return xmemdup(opt, opt[3] + 4); return xmemdup(opt, opt[3] + 4);
} }
/*** Script execution code ***/ /*** Script execution code ***/
static char** new_env(void) static char** new_env(void)
@ -902,7 +901,6 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac
return bytes; return bytes;
} }
/*** Main ***/ /*** Main ***/
static int sockfd = -1; static int sockfd = -1;
@ -1146,7 +1144,6 @@ static void client_background(void)
//usage: "\n USR1 Renew lease" //usage: "\n USR1 Renew lease"
//usage: "\n USR2 Release lease" //usage: "\n USR2 Release lease"
int udhcpc6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int udhcpc6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int udhcpc6_main(int argc UNUSED_PARAM, char **argv) int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
{ {

View File

@ -10,7 +10,11 @@
#include <ifaddrs.h> #include <ifaddrs.h>
#include <netpacket/packet.h> #include <netpacket/packet.h>
int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_addr *nip6, uint8_t *mac) int FAST_FUNC d6_read_interface(
const char *interface,
int *ifindex,
struct in6_addr *nip6,
uint8_t *mac)
{ {
int retval = 3; int retval = 3;
struct ifaddrs *ifap, *ifa; struct ifaddrs *ifap, *ifa;
@ -22,12 +26,12 @@ int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_
if (!ifa->ifa_addr || (strcmp(ifa->ifa_name, interface) != 0)) if (!ifa->ifa_addr || (strcmp(ifa->ifa_name, interface) != 0))
continue; continue;
sip6 = (struct sockaddr_in6*)(ifa->ifa_addr);
if (ifa->ifa_addr->sa_family == AF_PACKET) { if (ifa->ifa_addr->sa_family == AF_PACKET) {
struct sockaddr_ll *sll = (struct sockaddr_ll*)(ifa->ifa_addr); struct sockaddr_ll *sll = (void*)(ifa->ifa_addr);
memcpy(mac, sll->sll_addr, 6); memcpy(mac, sll->sll_addr, 6);
log2("MAC %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); log2("MAC %02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
);
*ifindex = sll->sll_ifindex; *ifindex = sll->sll_ifindex;
log2("ifindex %d", *ifindex); log2("ifindex %d", *ifindex);
retval &= (3 - (1<<0)); retval &= (3 - (1<<0));
@ -47,6 +51,8 @@ int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_
* is requesting configuration information as the source address in the * is requesting configuration information as the source address in the
* header of the IP datagram." * header of the IP datagram."
*/ */
sip6 = (void*)(ifa->ifa_addr);
if (ifa->ifa_addr->sa_family == AF_INET6 if (ifa->ifa_addr->sa_family == AF_INET6
&& IN6_IS_ADDR_LINKLOCAL(&sip6->sin6_addr) && IN6_IS_ADDR_LINKLOCAL(&sip6->sin6_addr)
) { ) {
@ -96,7 +102,7 @@ int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_
bb_error_msg("can't get %s", "MAC"); bb_error_msg("can't get %s", "MAC");
if (retval & (1<<1)) if (retval & (1<<1))
bb_error_msg("can't get %s", "link-local IPv6 address"); bb_error_msg("can't get %s", "link-local IPv6 address");
return -1; return retval;
} }
int FAST_FUNC d6_listen_socket(int port, const char *inf) int FAST_FUNC d6_listen_socket(int port, const char *inf)