]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Also disable PMTU for v6 10264/head
authorOtto <otto.moerbeek@open-xchange.com>
Tue, 6 Apr 2021 08:41:39 +0000 (10:41 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Tue, 6 Apr 2021 12:26:41 +0000 (14:26 +0200)
pdns/dnsdist.cc
pdns/iputils.cc
pdns/iputils.hh
pdns/nameserver.cc
pdns/pdns_recursor.cc

index 5eee451c3784016d016dbd9d42dc5d1cdae3409e..f474c79c91e52ac449b40c4d06c11e47ba59ccc8 100644 (file)
@@ -1903,9 +1903,9 @@ static void setUpLocalBind(std::unique_ptr<ClientState>& cs)
   /* Only set this on IPv4 UDP sockets.
      Don't set it for DNSCrypt binds. DNSCrypt pads queries for privacy
      purposes, so we do receive large, sometimes fragmented datagrams. */
-  if (!cs->tcp && cs->local.isIPv4() && !cs->dnscryptCtx) {
+  if (!cs->tcp && !cs->dnscryptCtx) {
     try {
-      setSocketIgnorePMTU(cs->udpFD);
+      setSocketIgnorePMTU(cs->udpFD, cs->local.sin4.sin_family);
     }
     catch(const std::exception& e) {
       warnlog("Failed to set IP_MTU_DISCOVER on UDP server socket for local address '%s': %s", cs->local.toStringWithPort(), e.what());
index 019eff2dd2d40e33521268f5dcf60a0459527bb1..216945b7cc73f5fba94c2d6d57db5d96c3f24114 100644 (file)
@@ -136,28 +136,51 @@ int SSetsockopt(int sockfd, int level, int opname, int value)
   return ret;
 }
 
-void setSocketIgnorePMTU(int sockfd)
+void setSocketIgnorePMTU(int sockfd, int family)
 {
+  if (family == AF_INET) {
 #if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
 #ifdef IP_PMTUDISC_OMIT
   /* Linux 3.15+ has IP_PMTUDISC_OMIT, which discards PMTU information to prevent
      poisoning, but still allows fragmentation if the packet size exceeds the
      outgoing interface MTU, which is good.
   */
-  try {
-    SSetsockopt(sockfd, IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_OMIT);
-    return;
-  }
-  catch(const std::exception& e) {
-    /* failed, let's try IP_PMTUDISC_DONT instead */
-  }
+    try {
+      SSetsockopt(sockfd, IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_OMIT);
+      return;
+    }
+    catch(const std::exception& e) {
+      /* failed, let's try IP_PMTUDISC_DONT instead */
+    }
 #endif /* IP_PMTUDISC_OMIT */
 
   /* IP_PMTUDISC_DONT disables Path MTU discovery */
-  SSetsockopt(sockfd, IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_DONT);
+    SSetsockopt(sockfd, IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_DONT);
 #endif /* defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT) */
+  }
+  else {
+    #if defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DONT)
+#ifdef IPV6_PMTUDISC_OMIT
+  /* Linux 3.15+ has IPV6_PMTUDISC_OMIT, which discards PMTU information to prevent
+     poisoning, but still allows fragmentation if the packet size exceeds the
+     outgoing interface MTU, which is good.
+  */
+    try {
+      SSetsockopt(sockfd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, IPV6_PMTUDISC_OMIT);
+      return;
+    }
+    catch(const std::exception& e) {
+      /* failed, let's try IP_PMTUDISC_DONT instead */
+    }
+#endif /* IPV6_PMTUDISC_OMIT */
+
+  /* IPV6_PMTUDISC_DONT disables Path MTU discovery */
+    SSetsockopt(sockfd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, IPV6_PMTUDISC_DONT);
+#endif /* defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DONT) */
+  }
 }
 
+
 bool setReusePort(int sockfd)
 {
 #if defined(SO_REUSEPORT_LB)
index b0999f01ff1f51fb5f4dac5996494e09d029010e..92055f8c2cc6b1256b76311fa45912a916da55f3 100644 (file)
@@ -1433,7 +1433,7 @@ int SBind(int sockfd, const ComboAddress& local);
 int SAccept(int sockfd, ComboAddress& remote);
 int SListen(int sockfd, int limit);
 int SSetsockopt(int sockfd, int level, int opname, int value);
-void setSocketIgnorePMTU(int sockfd);
+void setSocketIgnorePMTU(int sockfd, int family);
 bool setReusePort(int sockfd);
 
 #if defined(IP_PKTINFO)
index a09953e635b9f693e6489a132e61a9b27f03444b..3f03eb3ff54e42b89c9048fcd5afb9212f911efa 100644 (file)
@@ -128,13 +128,11 @@ void UDPNameserver::bindAddresses()
     if (!setSocketTimestamps(s))
       g_log<<Logger::Warning<<"Unable to enable timestamp reporting for socket "<<locala.toStringWithPort()<<endl;
 
-    if (locala.isIPv4()) {
-      try {
-        setSocketIgnorePMTU(s);
-      }
-      catch(const std::exception& e) {
-        g_log<<Logger::Warning<<"Failed to set IP_MTU_DISCOVER on UDP server socket: "<<e.what()<<endl;
-      }
+    try {
+      setSocketIgnorePMTU(s, locala.sin4.sin_family);
+    }
+    catch(const std::exception& e) {
+      g_log<<Logger::Warning<<"Failed to set IP_MTU_DISCOVER on UDP server socket: "<<e.what()<<endl;
     }
 
     if (d_can_reuseport) {
index 5d8b3c959f459f6eda703de4fe90620f044c86c8..76330cba71366057757602d13b88e9d93b6277f3 100644 (file)
@@ -3427,13 +3427,11 @@ static void makeUDPServerSockets(deferredAdd_t& deferredAdds)
 #endif
     }
 
-    if (sin.isIPv4()) {
-      try {
-        setSocketIgnorePMTU(fd);
-      }
-      catch(const std::exception& e) {
-        g_log<<Logger::Warning<<"Failed to set IP_MTU_DISCOVER on UDP server socket: "<<e.what()<<endl;
-      }
+    try {
+      setSocketIgnorePMTU(fd, sin.sin4.sin_family);
+    }
+    catch(const std::exception& e) {
+      g_log<<Logger::Warning<<"Failed to set IP_MTU_DISCOVER on UDP server socket: "<<e.what()<<endl;
     }
 
     socklen_t socklen=sin.getSocklen();