Skip to contentSkip to conversation

Implement --mtu-disc for IPv6 UDP sockets.

PATCH In review Gert Doering 2 participants 3 messages Feb 22, 2022 – May 12, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Implement --mtu-disc for IPv6 UDP sockets.

Commit 4225114b96 repaired "--mtu-disc yes" brokenness for IPv4 UDP sockets (caused by autoconf/ifdef issues). This patch adds new functionality to do --mtu-disc for IPv6 sockets as well.

Half of it (setsockopt(IPV6_MTU_DISCOVER)) was already there, but receiving of detailed socket errors was missing the enablement of setsockopt(IPV6_RECVERR) and parsing of IPPROTO_IPV6/IPV6_RECVERR messages received.

With that, we now get (sending over a route with "mtu 1300"):

2022-02-22 15:28:07 write UDPv6 [EMSGSIZE Path-MTU=1300]: Message too long (fd=3,code=90)
2022-02-22 15:28:07 Note adjusting 'mssfix 1400 mtu' to 'mssfix 1300 mtu' according to path MTU discovery
2022-02-22 15:28:07 Note adjusting 'fragment 1400 mtu' to 'fragment 1300 mtu' according to path MTU discovery
---
 src/openvpn/mtu.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
src/openvpn/mtu.c +19 -1
index aa810f1c..51eeaa64 100644
@@ -352,6 +352,17 @@ format_extended_socket_error(int fd, int *mtu, struct gc_arena *gc)
                     buf_printf(&out,"CMSG=%d|", cmsg->cmsg_type);
                 }
             }
+            else if (cmsg->cmsg_level == IPPROTO_IPV6)
+            {
+                if (cmsg->cmsg_type == IPV6_RECVERR)
+                {
+                    e = (struct sock_extended_err *) CMSG_DATA(cmsg);
+                }
+                else
+                {
+                    buf_printf(&out,"CMSG=%d|", cmsg->cmsg_type);
+                }
+            }
         }
         if (e == NULL)
         {
@@ -405,11 +416,18 @@ void
 set_sock_extended_error_passing(int sd)
 {
     int on = 1;
-    if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)))
+    /* see "man 7 ip" (on Linux) */
+    if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)) != 0)
     {
         msg(M_WARN | M_ERRNO,
             "Note: enable extended error passing on TCP/UDP socket failed (IP_RECVERR)");
     }
+    /* see "man 7 ipv6" (on Linux) */
+    if (setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (void *) &on, sizeof(on)) != 0)
+    {
+        msg(M_WARN | M_ERRNO,
+            "Note: enable extended error passing on TCP/UDP socket failed (IPV6_RECVERR)");
+    }
 }
 
 #endif /* if EXTENDED_SOCKET_ERROR_CAPABILITY */
Signature · 1 line
2.26.3
Acked-by on v1 1/1
#1 lore raw

Am 22.02.22 um 15:35 schrieb Gert Doering:

Quoted 9 lines

Commit 4225114b96 repaired "--mtu-disc yes" brokenness for IPv4 UDP sockets (caused by autoconf/ifdef issues). This patch adds new functionality to do --mtu-disc for IPv6 sockets as well.

Half of it (setsockopt(IPV6_MTU_DISCOVER)) was already there, but receiving of detailed socket errors was missing the enablement of setsockopt(IPV6_RECVERR) and parsing of IPPROTO_IPV6/IPV6_RECVERR messages received.

Quoted 5 lines

With that, we now get (sending over a route with "mtu 1300"):

2022-02-22 15:28:07 write UDPv6 [EMSGSIZE Path-MTU=1300]: Message too long (fd=3,code=90)
2022-02-22 15:28:07 Note adjusting 'mssfix 1400 mtu' to 'mssfix 1300 mtu' according to path MTU discovery
2022-02-22 15:28:07 Note adjusting 'fragment 1400 mtu' to 'fragment 1300 mtu' according to path MTU discovery

Looks simple enough.

Arne

#2 lore raw
In reply to Gert Doering

Patch has been applied to the master branch.

commit 043c67f36342969cd171d24c70ee6b62ebc95fee

Author: Gert Doering
Date:   Tue Feb 22 15:35:14 2022 +0100
     Implement --mtu-disc for IPv6 UDP sockets.

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg23879.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering