From: Aki Tuomi Date: Fri, 5 Mar 2021 09:57:04 +0000 (+0200) Subject: global: Check setsockopt return value X-Git-Tag: dnsdist-1.7.0-alpha1~10^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8816bd4ebfe1db418743e4301510960b7332f839;p=thirdparty%2Fpdns.git global: Check setsockopt return value --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index f6d4f1d9cb..60de4ecb43 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -2006,6 +2006,8 @@ static void checkFileDescriptorsLimits(size_t udpBindsCount, size_t tcpBindsCoun } } +static bool g_warned_ipv6_recvpktinfo = false; + static void setUpLocalBind(std::unique_ptr& cs) { /* skip some warnings if there is an identical UDP context */ @@ -2039,9 +2041,13 @@ static void setUpLocalBind(std::unique_ptr& cs) if(!cs->tcp && IsAnyAddress(cs->local)) { int one=1; - setsockopt(fd, IPPROTO_IP, GEN_IP_PKTINFO, &one, sizeof(one)); // linux supports this, so why not - might fail on other systems + (void)setsockopt(fd, IPPROTO_IP, GEN_IP_PKTINFO, &one, sizeof(one)); // linux supports this, so why not - might fail on other systems #ifdef IPV6_RECVPKTINFO - setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &one, sizeof(one)); + if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &one, sizeof(one)) < 0 && + !g_warned_ipv6_recvpktinfo) { + warnlog("Warning: IPV6_RECVPKTINFO setsockopt failed: %s", stringerror()); + g_warned_ipv6_recvpktinfo = true; + } #endif } diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 56c1fca68e..ce07abdc7d 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -118,11 +118,11 @@ void UDPNameserver::bindAddresses() throw PDNSException("Unable to set UDP socket " + locala.toStringWithPort() + " to non-blocking: "+stringerror()); if(IsAnyAddress(locala)) { - setsockopt(s, IPPROTO_IP, GEN_IP_PKTINFO, &one, sizeof(one)); + (void)setsockopt(s, IPPROTO_IP, GEN_IP_PKTINFO, &one, sizeof(one)); if (locala.isIPv6()) { - setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one)); // if this fails, we report an error in tcpreceiver too + (void)setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one)); // if this fails, we report an error in tcpreceiver too #ifdef IPV6_RECVPKTINFO - setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &one, sizeof(one)); + (void)setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &one, sizeof(one)); #endif } } diff --git a/pdns/rec_channel.cc b/pdns/rec_channel.cc index 17d408398a..ff57095276 100644 --- a/pdns/rec_channel.cc +++ b/pdns/rec_channel.cc @@ -46,7 +46,7 @@ static void setSocketBuffer(int fd, int optname, uint32_t size) return; // failure to raise is not fatal - setsockopt(fd, SOL_SOCKET, optname, (const void*)&size, sizeof(size)); + (void)setsockopt(fd, SOL_SOCKET, optname, (const void*)&size, sizeof(size)); }