]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
global: Check setsockopt return value
authorAki Tuomi <cmouse@cmouse.fi>
Fri, 5 Mar 2021 09:57:04 +0000 (11:57 +0200)
committerAki Tuomi <cmouse@cmouse.fi>
Fri, 17 Sep 2021 07:22:00 +0000 (10:22 +0300)
pdns/dnsdist.cc
pdns/nameserver.cc
pdns/rec_channel.cc

index f6d4f1d9cb1edd6db2aae4a3717e43afe1a331e0..60de4ecb436b4c93caa9482cc46dc145cbc3d9a9 100644 (file)
@@ -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<ClientState>& cs)
 {
   /* skip some warnings if there is an identical UDP context */
@@ -2039,9 +2041,13 @@ static void setUpLocalBind(std::unique_ptr<ClientState>& 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
   }
 
index 56c1fca68e52dec8f1ecc22061b9f61e7fe960a9..ce07abdc7d8f379c038ad03f7f80f410e4b9045f 100644 (file)
@@ -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
       }
     }
index 17d408398a2087a64adfa530ee4d24f5a98a1640..ff570952763b3de5cdffb8cfa5e1a337b07c62e8 100644 (file)
@@ -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));
 }