From: Otto Moerbeek Date: Tue, 5 Mar 2019 15:30:22 +0000 (+0100) Subject: Set IP(V6)_RECVERR socket option to get notified of more than just X-Git-Tag: auth-4.2.0-rc1~15^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7540%2Fhead;p=thirdparty%2Fpdns.git Set IP(V6)_RECVERR socket option to get notified of more than just port unreachable errors on Linux. See https://sourceware.org/bugzilla/show_bug.cgi?id=24047 --- diff --git a/pdns/misc.cc b/pdns/misc.cc index b9863ed966..08c42251cf 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -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 ) { diff --git a/pdns/misc.hh b/pdns/misc.hh index f57a010bc6..9adfe35dc4 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -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); diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 1a278125bf..dcbbf88579 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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; }