--- embedaddon/dnsmasq/src/bpf.c 2014/06/15 16:31:38 1.1.1.2 +++ embedaddon/dnsmasq/src/bpf.c 2021/03/17 00:56:46 1.1.1.4 @@ -1,4 +1,4 @@ -/* dnsmasq is Copyright (c) 2000-2014 Simon Kelley +/* dnsmasq is Copyright (c) 2000-2021 Simon Kelley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,7 +20,9 @@ #include #include +#if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__) #include +#endif #include #include #include @@ -29,9 +31,7 @@ # include #endif #include -#ifdef HAVE_IPV6 -# include -#endif +#include #ifndef SA_SIZE #define SA_SIZE(sa) \ @@ -42,7 +42,7 @@ #ifdef HAVE_BSD_NETWORK static int del_family = 0; -static struct all_addr del_addr; +static union all_addr del_addr; #endif #if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__) @@ -103,7 +103,7 @@ int arp_enumerate(void *parm, int (*callback)()) int iface_enumerate(int family, void *parm, int (*callback)()) { struct ifaddrs *head, *addrs; - int errsav, fd = -1, ret = 0; + int errsave, fd = -1, ret = 0; if (family == AF_UNSPEC) #if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__) @@ -119,7 +119,7 @@ int iface_enumerate(int family, void *parm, int (*call if (getifaddrs(&head) == -1) return 0; -#if defined(HAVE_BSD_NETWORK) && defined(HAVE_IPV6) +#if defined(HAVE_BSD_NETWORK) if (family == AF_INET6) fd = socket(PF_INET6, SOCK_DGRAM, 0); #endif @@ -139,7 +139,7 @@ int iface_enumerate(int family, void *parm, int (*call struct in_addr addr, netmask, broadcast; addr = ((struct sockaddr_in *) addrs->ifa_addr)->sin_addr; #ifdef HAVE_BSD_NETWORK - if (del_family == AF_INET && del_addr.addr.addr4.s_addr == addr.s_addr) + if (del_family == AF_INET && del_addr.addr4.s_addr == addr.s_addr) continue; #endif netmask = ((struct sockaddr_in *) addrs->ifa_netmask)->sin_addr; @@ -150,7 +150,6 @@ int iface_enumerate(int family, void *parm, int (*call if (!((*callback)(addr, iface_index, NULL, netmask, broadcast, parm))) goto err; } -#ifdef HAVE_IPV6 else if (family == AF_INET6) { struct in6_addr *addr = &((struct sockaddr_in6 *) addrs->ifa_addr)->sin6_addr; @@ -160,14 +159,14 @@ int iface_enumerate(int family, void *parm, int (*call u32 valid = 0xffffffff, preferred = 0xffffffff; int flags = 0; #ifdef HAVE_BSD_NETWORK - if (del_family == AF_INET6 && IN6_ARE_ADDR_EQUAL(&del_addr.addr.addr6, addr)) + if (del_family == AF_INET6 && IN6_ARE_ADDR_EQUAL(&del_addr.addr6, addr)) continue; #endif #if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__) struct in6_ifreq ifr6; memset(&ifr6, 0, sizeof(ifr6)); - strncpy(ifr6.ifr_name, addrs->ifa_name, sizeof(ifr6.ifr_name)); + safe_strncpy(ifr6.ifr_name, addrs->ifa_name, sizeof(ifr6.ifr_name)); ifr6.ifr_addr = *((struct sockaddr_in6 *) addrs->ifa_addr); if (fd != -1 && ioctl(fd, SIOCGIFAFLAG_IN6, &ifr6) != -1) @@ -217,7 +216,6 @@ int iface_enumerate(int family, void *parm, int (*call (int) preferred, (int)valid, parm))) goto err; } -#endif /* HAVE_IPV6 */ #ifdef HAVE_DHCP6 else if (family == AF_LINK) @@ -235,11 +233,11 @@ int iface_enumerate(int family, void *parm, int (*call ret = 1; err: - errsav = errno; + errsave = errno; freeifaddrs(head); if (fd != -1) close(fd); - errno = errsav; + errno = errsave; return ret; } @@ -359,7 +357,7 @@ void send_via_bpf(struct dhcp_packet *mess, size_t len iov[3].iov_base = mess; iov[3].iov_len = len; - while (writev(daemon->dhcp_raw_fd, iov, 4) == -1 && retry_send()); + while (retry_send(writev(daemon->dhcp_raw_fd, iov, 4))); } #endif /* defined(HAVE_BSD_NETWORK) && defined(HAVE_DHCP) */ @@ -376,7 +374,7 @@ void route_init(void) die(_("cannot create PF_ROUTE socket: %s"), NULL, EC_BADNET); } -void route_sock(time_t now) +void route_sock(void) { struct if_msghdr *msg; int rc = recv(daemon->routefd, daemon->packet, daemon->packet_buff_sz, 0); @@ -401,7 +399,7 @@ void route_sock(time_t now) else if (msg->ifm_type == RTM_NEWADDR) { del_family = 0; - newaddress(now); + queue_event(EVENT_NEWADDR); } else if (msg->ifm_type == RTM_DELADDR) { @@ -424,11 +422,9 @@ void route_sock(time_t now) { del_family = sa->sa_family; if (del_family == AF_INET) - del_addr.addr.addr4 = ((struct sockaddr_in *)sa)->sin_addr; -#ifdef HAVE_IPV6 + del_addr.addr4 = ((struct sockaddr_in *)sa)->sin_addr; else if (del_family == AF_INET6) - del_addr.addr.addr6 = ((struct sockaddr_in6 *)sa)->sin6_addr; -#endif + del_addr.addr6 = ((struct sockaddr_in6 *)sa)->sin6_addr; else del_family = 0; } @@ -439,7 +435,7 @@ void route_sock(time_t now) of += sizeof(long) - (diff & (sizeof(long) - 1)); } - newaddress(now); + queue_event(EVENT_NEWADDR); } }