]> granicus.if.org Git - pdns/commitdiff
Set IP(V6)_RECVERR socket option to get notified of more than just
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 5 Mar 2019 15:30:22 +0000 (16:30 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 5 Mar 2019 16:14:20 +0000 (17:14 +0100)
port unreachable errors on Linux.

See https://sourceware.org/bugzilla/show_bug.cgi?id=24047

pdns/misc.cc
pdns/misc.hh
pdns/pdns_recursor.cc

index b9863ed966e901715d6bed02f61b25befb319fc2..08c42251cf70df8aeb2dd10c4d6cf7ddf96048b4 100644 (file)
@@ -1101,6 +1101,22 @@ bool isNonBlocking(int sock)
   return flags & O_NONBLOCK;
 }
 
+bool setReceiveSocketErrors(int sock, int af)
+{
+#ifdef __linux__
+  int tmp = 1, ret;
+  if (af == AF_INET) {
+    ret = setsockopt(sock, IPPROTO_IP, IP_RECVERR, &tmp, sizeof(tmp));
+  } else {
+    ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVERR, &tmp, sizeof(tmp));
+  }
+  if (ret < 0) {
+    throw PDNSException(string("Setsockopt failed: ") + strerror(errno));
+  }
+#endif
+  return true;
+}
+
 // Closes a socket.
 int closesocket( int socket )
 {
index f57a010bc6041bbed5047595444ba26aef5a59e6..9adfe35dc410e43730910ee72ae64436fac2a830 100644 (file)
@@ -534,6 +534,7 @@ bool setNonBlocking( int sock );
 bool setTCPNoDelay(int sock);
 bool setReuseAddr(int sock);
 bool isNonBlocking(int sock);
+bool setReceiveSocketErrors(int sock, int af);
 int closesocket(int fd);
 bool setCloseOnExec(int sock);
 uint64_t udpErrorStats(const std::string& str);
index 1a278125bf5264eaa221d50d8664c6567c63e17e..dcbbf88579b8b93cda311296be150be2b7e389fe 100644 (file)
@@ -623,6 +623,7 @@ public:
     if(!tries)
       throw PDNSException("Resolver binding to local query client socket on "+sin.toString()+": "+stringerror());
 
+    setReceiveSocketErrors(ret, family);
     setNonBlocking(ret);
     return ret;
   }