From: Tom Ivar Helbekkmo Date: Fri, 5 Jan 2018 13:24:08 +0000 (+0100) Subject: Changes to compile and run on NetBSD X-Git-Tag: dnsdist-1.3.0~167^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d39d7f34cf2406a9f16e28b2f5d21138aecd422;p=pdns Changes to compile and run on NetBSD --- diff --git a/pdns/dns.hh b/pdns/dns.hh index 88a658c5a..e6d0385cd 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -130,7 +130,7 @@ struct EDNS0Record static_assert(sizeof(EDNS0Record) == 4, "EDNS0Record size must be 4"); -#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) +#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) #include #elif __linux__ || __GNU__ # include diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 40aa405ea..87bcb8a11 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -23,7 +23,7 @@ #include "sodcrypto.hh" #include "pwd.h" -#if defined (__OpenBSD__) +#if defined (__OpenBSD__) || defined(__NetBSD__) #include #include #else diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index c3018e0bd..c5578b6cc 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -27,7 +27,7 @@ #include #include "dolog.hh" -#if defined (__OpenBSD__) +#if defined (__OpenBSD__) || defined(__NetBSD__) #include #else #include diff --git a/pdns/iputils.cc b/pdns/iputils.cc index d6facc029..b2d512182 100644 --- a/pdns/iputils.cc +++ b/pdns/iputils.cc @@ -146,7 +146,11 @@ bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv) bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destination) { memset(destination, 0, sizeof(*destination)); +#ifdef __NetBSD__ + struct cmsghdr* cmsg; +#else const struct cmsghdr* cmsg; +#endif for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(const_cast(msgh), const_cast(cmsg))) { #if defined(IP_PKTINFO) if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_PKTINFO)) { diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 8ab4f13c3..b6cf7b4bd 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -82,6 +82,12 @@ #include #endif +#if defined(__NetBSD__) && defined(IP_PKTINFO) && !defined(IP_SENDSRCADDR) +// The IP_PKTINFO option in NetBSD was incompatible with Linux until a +// change that also introduced IP_SENDSRCADDR for FreeBSD compatibility. +#undef IP_PKTINFO +#endif + union ComboAddress { struct sockaddr_in sin4; struct sockaddr_in6 sin6; @@ -992,6 +998,7 @@ int SSetsockopt(int sockfd, int level, int opname, int value); #elif defined(IP_RECVDSTADDR) #define GEN_IP_PKTINFO IP_RECVDSTADDR #endif + bool IsAnyAddress(const ComboAddress& addr); bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destination); bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv); diff --git a/pdns/kqueuemplexer.cc b/pdns/kqueuemplexer.cc index b3510c501..2fb66c8c7 100644 --- a/pdns/kqueuemplexer.cc +++ b/pdns/kqueuemplexer.cc @@ -28,7 +28,7 @@ #include #include "misc.hh" #include -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) #include #endif #include diff --git a/pdns/misc.cc b/pdns/misc.cc index 88e05802e..8dc5d4b36 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -60,6 +60,10 @@ #ifdef __FreeBSD__ # include #endif +#ifdef __NetBSD__ +# include +# include +#endif bool g_singleThreaded; @@ -866,7 +870,7 @@ void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, const ComboAddress* sour pkt->ipi6_ifindex = itfIndex; } else { -#ifdef IP_PKTINFO +#if defined(IP_PKTINFO) struct in_pktinfo *pkt; msgh->msg_control = cmsgbuf; @@ -881,8 +885,7 @@ void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, const ComboAddress* sour memset(pkt, 0, sizeof(*pkt)); pkt->ipi_spec_dst = source->sin4.sin_addr; pkt->ipi_ifindex = itfIndex; -#endif -#ifdef IP_SENDSRCADDR +#elif defined(IP_SENDSRCADDR) struct in_addr *in; msgh->msg_control = cmsgbuf; @@ -1329,9 +1332,20 @@ bool isSettingThreadCPUAffinitySupported() int mapThreadToCPUList(pthread_t tid, const std::set& cpus) { #ifdef HAVE_PTHREAD_SETAFFINITY_NP -# ifdef __FreeBSD__ -# define cpu_set_t cpuset_t -# endif +# ifdef __NetBSD__ + cpuset_t *cpuset; + cpuset = cpuset_create(); + for (const auto cpuID : cpus) { + cpuset_set(cpuID, cpuset); + } + + return pthread_setaffinity_np(tid, + cpuset_size(cpuset), + cpuset); +# else +# ifdef __FreeBSD__ +# define cpu_set_t cpuset_t +# endif cpu_set_t cpuset; CPU_ZERO(&cpuset); for (const auto cpuID : cpus) { @@ -1341,6 +1355,7 @@ int mapThreadToCPUList(pthread_t tid, const std::set& cpus) return pthread_setaffinity_np(tid, sizeof(cpuset), &cpuset); +# endif #endif /* HAVE_PTHREAD_SETAFFINITY_NP */ return ENOSYS; }