]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Disable the PMTUD also for the IPv6 UDP sockets
authorOndřej Surý <ondrej@sury.org>
Wed, 23 Sep 2020 12:47:26 +0000 (14:47 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 24 Jun 2021 15:26:47 +0000 (17:26 +0200)
Disable the PMTUD also on the IPv6 UDP sockets in addition to IPv4 UDP
sockets.

lib/isc/unix/socket.c

index 07d17d95b372ccee9ec5f9404bf5ee137ba804a8..2293baa1ded0dbed57a2823401d9a6ec21c75d8e 100644 (file)
@@ -2585,6 +2585,46 @@ set_tcp_maxseg(isc__socket_t *sock, int size) {
 #endif
 }
 
+static void
+set_ip_nopmtud(isc__socket_t *sock) {
+       /*
+        * Disable the Path MTU Discovery on the socket
+        */
+       if (sock->pf == AF_INET6) {
+#if defined(IPV6_DONTFRAG)
+               int off = 0;
+               (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_DONTFRAG,
+                                &off, sizeof(off));
+#endif /* defined(IPV6_DONTFRAG) */
+#if defined(IPV6_MTU_DISCOVER)
+               int action;
+#if defined(IP_PMTUDISC_OMIT)
+               action = IP_PMTUDISC_OMIT;
+#else /* defined(IP_PMTUDISC_OMIT) */
+               action = IP_PMTUDISC_DONT;
+#endif /* defined(IP_PMTUDISC_OMIT) */
+               (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
+                                &action, sizeof(action));
+#endif /* defined(IPV6_MTU_DISCOVER) */
+       } else if (sock->pf == AF_INET) {
+#if defined(IP_DONTFRAG)
+               int off = 0;
+               (void)setsockopt(sock->fd, IPPROTO_IP, IP_DONTFRAG, &off,
+                                sizeof(off));
+#endif /* defined(IP_DONTFRAG) */
+#if defined(IP_MTU_DISCOVER)
+               int action;
+#if defined(IP_PMTUDISC_OMIT)
+               action = IP_PMTUDISC_OMIT;
+#else /* defined(IP_PMTUDISC_OMIT) */
+               action = IP_PMTUDISC_DONT;
+#endif /* defined(IP_PMTUDISC_OMIT) */
+               (void)setsockopt(sock->fd, IPPROTO_IP, IP_MTU_DISCOVER,
+                                &action, sizeof(action));
+#endif /* defined(IP_MTU_DISCOVER) */
+       }
+}
+
 static isc_result_t
 opensocket(isc__socketmgr_t *manager, isc__socket_t *sock,
           isc__socket_t *dup_socket)
@@ -2864,40 +2904,6 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock,
 #endif /* ISC_PLATFORM_HAVEIPV6 */
 #endif /* defined(USE_CMSG) */
 
-#if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
-               /*
-                * Turn off Path MTU discovery on IPv4/UDP sockets.
-                * Prefer IP_PMTUDISC_OMIT over IP_PMTUDISC_DONT
-                * if it available.
-                */
-               if (sock->pf == AF_INET) {
-                       int action;
-#if defined(IP_PMTUDISC_OMIT)
-                       action = IP_PMTUDISC_OMIT;
-                       if (setsockopt(sock->fd, IPPROTO_IP,
-                                      IP_MTU_DISCOVER, &action,
-                                      sizeof(action)) < 0) {
-#endif
-                               action = IP_PMTUDISC_DONT;
-                               (void)setsockopt(sock->fd, IPPROTO_IP,
-                                                IP_MTU_DISCOVER,
-                                                &action, sizeof(action));
-#if defined(IP_PMTUDISC_OMIT)
-                       }
-#endif
-               }
-#endif
-#if defined(IP_DONTFRAG)
-               /*
-                * Turn off Path MTU discovery on IPv4/UDP sockets.
-                */
-               if (sock->pf == AF_INET) {
-                       int off = 0;
-                       (void)setsockopt(sock->fd, IPPROTO_IP, IP_DONTFRAG,
-                                        &off, sizeof(off));
-               }
-#endif
-
 #if defined(SO_RCVBUF)
                optlen = sizeof(size);
                if (getsockopt(sock->fd, SOL_SOCKET, SO_RCVBUF,
@@ -2947,6 +2953,8 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock,
 #endif
 #endif /* defined(USE_CMSG) || defined(SO_RCVBUF) */
 
+       set_ip_nopmtud(sock);
+
 setup_done:
        inc_stats(manager->stats, sock->statsindex[STATID_OPEN]);
        if (sock->active == 0) {