Skip to contentSkip to conversation

Setting adapter mtu on windows systems

PATCH In review Christopher Schenk 6 participants 32 messages Mar 28, 2019 – Jul 6, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Setting adapter mtu on windows systems

From: Christopher Schenk <[email protected]...>

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
src/openvpn/tun.c +38 -1
index 48a8fdf7..93d028c8 100644
@@ -69,6 +69,12 @@ static void netsh_ifconfig(const struct tuntap_options *to,
                            const in_addr_t netmask,
                            const unsigned int flags);
 
+static void netsh_set_mtu_ipv4(const char *flex_name,
+                               const int mtu);
+
+static void netsh_set_mtu_ipv6(const char *flex_name,
+                               const int mtu);
+
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                    const int addr_len,
                                    const char *flex_name);
@@ -1000,6 +1006,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,
         netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */
         netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname);
+        netsh_set_mtu_ipv6(ifname, tun_mtu);
     }
 
     /* explicit route needed */
@@ -1391,9 +1398,9 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
             case IPW32_SET_NETSH:
                 netsh_ifconfig(&tt->options, ifname, tt->local,
                                tt->adapter_netmask, NI_IP_NETMASK|NI_OPTIONS);
-
                 break;
         }
+		netsh_set_mtu_ipv4(ifname, tun_mtu);
     }
 
 #else  /* if defined(TARGET_LINUX) */
@@ -5236,6 +5243,36 @@ out:
     return ret;
 }
 
+static void
+netsh_set_mtu_ipv4(const char *flex_name,
+                   const int mtu)
+{
+	struct argv argv = argv_new();
+	argv_printf(&argv, "%s%sc interface ipv4 set subinterface %s mtu = %d store=active",
+		get_win_sys_path(),
+		NETSH_PATH_SUFFIX,
+		flex_name,
+		mtu);
+
+	netsh_command(&argv, 3, M_WARN);
+	argv_reset(&argv);
+}
+
+static void
+netsh_set_mtu_ipv6(const char *flex_name,
+	const int mtu)
+{
+	struct argv argv = argv_new();
+	argv_printf(&argv, "%s%sc interface ipv6 set subinterface %s mtu = %d store=active",
+		get_win_sys_path(),
+		NETSH_PATH_SUFFIX,
+		flex_name,
+		mtu);
+
+	netsh_command(&argv, 3, M_WARN);
+	argv_reset(&argv);
+}
+
 /*
  * Return a TAP name for netsh commands.
  */
Signature · 1 line
2.21.0.windows.1
#1 lore raw

Am 28.03.19 um 13:27 schrieb Christopher Schenk:

Quoted 43 lines

From: Christopher Schenk <[email protected]...>

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
src/openvpn/tun.c +8 -1
index 48a8fdf7..93d028c8 100644
@@ -69,6 +69,12 @@ static void netsh_ifconfig(const struct tuntap_options *to,
                            const in_addr_t netmask,
                            const unsigned int flags);
 
+static void netsh_set_mtu_ipv4(const char *flex_name,
+                               const int mtu);
+
+static void netsh_set_mtu_ipv6(const char *flex_name,
+                               const int mtu);
+
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                    const int addr_len,
                                    const char *flex_name);
@@ -1000,6 +1006,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,
         netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */
         netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname);
+        netsh_set_mtu_ipv6(ifname, tun_mtu);
     }
 
     /* explicit route needed */
@@ -1391,9 +1398,9 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
             case IPW32_SET_NETSH:
                 netsh_ifconfig(&tt->options, ifname, tt->local,
                                tt->adapter_netmask, NI_IP_NETMASK|NI_OPTIONS);
-
                 break;
         }
+		netsh_set_mtu_ipv4(ifname, tun_mtu);
     }
 
 #else  /* if defined(TARGET_LINUX) */

src/openvpn/tun.c out: · line 5251

Quoted 9 lines
src/openvpn/tun.c +6 -0
@@ -5236,6 +5243,36 @@ out:
     return ret;
 }
 
+static void
+netsh_set_mtu_ipv4(const char *flex_name,
+                   const int mtu)
+{
+	struct argv argv = argv_new();
+	argv_printf(&argv, "%s%sc interface ipv4 set subinterface %s mtu = %d store=active",

The spacing here looks a bit odd. I would have expected mtu=%d instead. Is this necessary or was there a reason for doing this?

Patch looks okay enough to ACK but:

In general, this patch adds a missing feature (setting MTU) with one windows interface only (netsh). And more commonly used interface (interactive service)would be different then leading to harder to debug problems.

Are you planning on adding MTU setting to the interactive service as well? If we have patches for MTU setting for both, I have problem to ACK both.

Arne

#2 lore raw

Hi

Quoted 63 lines · Arne Schwabe

Am 28.03.19 um 13:27 schrieb Christopher Schenk:

src/openvpn/tun.c static void netsh_ifconfig(const struct

Quoted 11 lines

From: Christopher Schenk <[email protected]...>

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
src/openvpn/tun.c +0 -0
index 48a8fdf7..93d028c8 100644
@@ -69,6 +69,12 @@ static void netsh_ifconfig(const struct

tuntap_options *to,

src/openvpn/tun.c do_ifconfig_ipv6(struct tuntap *tt, const char

Quoted 13 lines
src/openvpn/tun.c +6 -0
                            const in_addr_t netmask,
                            const unsigned int flags);
 
+static void netsh_set_mtu_ipv4(const char *flex_name,
+                               const int mtu);
+
+static void netsh_set_mtu_ipv6(const char *flex_name,
+                               const int mtu);
+
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                    const int addr_len,
                                    const char *flex_name);
@@ -1000,6 +1006,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char

*ifname, int tun_mtu,

src/openvpn/tun.c do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,

Quoted 3 lines
src/openvpn/tun.c +0 -0
         netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */
         netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len,

ifname);

src/openvpn/tun.c do_ifconfig_ipv4(struct tuntap *tt, const char

Quoted 5 lines
src/openvpn/tun.c +1 -0
+        netsh_set_mtu_ipv6(ifname, tun_mtu);
     }
 
     /* explicit route needed */
@@ -1391,9 +1398,9 @@ do_ifconfig_ipv4(struct tuntap *tt, const char

*ifname, int tun_mtu,

src/openvpn/tun.c do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,

Quoted 3 lines
src/openvpn/tun.c +0 -0
             case IPW32_SET_NETSH:
                 netsh_ifconfig(&tt->options, ifname, tt->local,
                                tt->adapter_netmask,

NI_IP_NETMASK|NI_OPTIONS);

Quoted 8 lines
src/openvpn/tun.c +1 -1
-
                 break;
         }
+             netsh_set_mtu_ipv4(ifname, tun_mtu);
     }
 
 #else  /* if defined(TARGET_LINUX) */

src/openvpn/tun.c out: · line 5251

Quoted 9 lines
src/openvpn/tun.c +6 -0
@@ -5236,6 +5243,36 @@ out:
     return ret;
 }
 
+static void
+netsh_set_mtu_ipv4(const char *flex_name,
+                   const int mtu)
+{
+     struct argv argv = argv_new();
+     argv_printf(&argv, "%s%sc interface ipv4 set subinterface %s mtu =

%d store=active",

The spacing here looks a bit odd. I would have expected mtu=%d instead. Is this necessary or was there a reason for doing this?

Quoted 7 lines

Patch looks okay enough to ACK but:

In general, this patch adds a missing feature (setting MTU) with one windows interface only (netsh). And more commonly used interface (interactive service)would be different then leading to harder to debug problems.

I would go a step further to say we should not add new features that do not work when started using the interactive service.

Secondly, we should avoid the old style use of netsh and instead use the iphelper API as far as possible. It should be possible to set MTU using the SetIfEntry() or SetIpInterfaceEnrty() function -- I haven't
checked which one is appropriate here.

Selva

#4 lore raw

Hi,

Quoted 1 line · Marvin Adeff

From a user perspective, there should probably be a way to disable any programmatic setting of mtu. In our usage, the same network interface that OpenVPN traffic goes out on often also must carry large traffic to other destinations that not uncommonly go through some low mtu path. In these cases we have to manually set mtu to a setting that most likely is much lower than OpenVPN might sense it as.

OpenVPN will not touch the LAN MTU, just its own tun/tap interface (and it does not look at "outgoing interface MTU" anyway - it will do path MTU sensing if supported, or just statically calculated).

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#5 lore raw
In reply to Selva Nair

Hi,

Quoted 7 lines · Selva Nair

I would go a step further to say we should not add new features that do not work when started using the interactive service.

Secondly, we should avoid the old style use of netsh and instead use the iphelper API as far as possible. It should be possible to
set MTU using the SetIfEntry() or SetIpInterfaceEnrty() function -- I haven't checked which one is appropriate here.

I agree on the point that we should add this functionality to the interactive service as well. So i modified the patch accordingly. I also modified my patch so that it uses the SetIpInterfaceEnrty function instead of netsh.

---

include/openvpn-msg.h +0 -0
index 66177a21..f59c5a21 100644
@@ -39,6 +39,7 @@ typedef enum {

     msg_del_block_dns,
     msg_register_dns,
     msg_enable_dhcp,
+    msg_set_mtu,
 } message_type_t;

 typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
     interface_t iface;
 } enable_dhcp_message_t;

+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
 #endif /* ifndef OPENVPN_MSG_H_ */

src/openvpn/tun.c +0 -0
index 48a8fdf7..9fe8444f 100644
@@ -69,6 +69,10 @@ static void netsh_ifconfig(const struct tuntap_options *to,

                            const in_addr_t netmask, const unsigned int flags);

+static void windows_set_mtu(const int iface_indey,
+                                short family,
+                               const int mtu);
+
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list, const int addr_len, const char *flex_name); @@ -201,6 +205,63 @@ out:
     return ret;
 }

+static bool
+do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
+{
+    DWORD len;
+    bool ret = false;
+    ack_message_t ack;
+    struct gc_arena gc = gc_new();
+    HANDLE pipe = tt->options.msg_channel;
+
+    set_mtu_message_t mtu_msg = {
+        .header = {
+            msg_set_mtu,
+            sizeof(set_mtu_message_t),
+            0
+        },
+        .iface = {.index = tt->adapter_index,.name = tt->actual_name },
+        .mtu = mtu,
+        .family = family
+    };
+
+    if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack, "Set_mtu"))
+    {
+        goto out;
+    }
+
+    if (family == AF_INET)
+    {
+        if (ack.error_number != NO_ERROR)
+        {
+            msg(M_NONFATAL, "TUN: setting IPv4 mtu using service failed: %s [status=%u if_index=%d]", +                strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.iface.index); +        }
+        else
+        {
+            msg(M_INFO, "IPv4 MTU set to %d on interface %d using service", mtu, mtu_msg.iface.index); +            ret = true;
+        }
+    }
+    else if (family == AF_INET6)
+    {
+        if (ack.error_number != NO_ERROR)
+        {
+            msg(M_NONFATAL, "TUN: setting IPv6 mtu using service failed: %s [status=%u if_index=%d]", +                strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.iface.index); +        }
+        else
+        {
+            msg(M_INFO, "IPv6 MTU set to %d on interface %d using service", mtu, mtu_msg.iface.index); +            ret = true;
+        }
+    }
+
+out:
+    gc_free(&gc);
+    return ret;
+}
+
 #endif /* ifdef _WIN32 */

 #ifdef TARGET_SOLARIS
@@ -984,6 +1045,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu, {
         do_address_service(true, AF_INET6, tt);
         do_dns6_service(true, tt);
+        do_set_mtu_service(tt, AF_INET6, tun_mtu);
     }
     else
     {
@@ -1000,6 +1062,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu, netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */ netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname); +        windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
     }

     /* explicit route needed */
@@ -1391,9 +1454,16 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, case IPW32_SET_NETSH:
                 netsh_ifconfig(&tt->options, ifname, tt->local, tt->adapter_netmask, NI_IP_NETMASK|NI_OPTIONS); -
                 break;
         }
+        if (tt->options.msg_channel)
+        {
+            do_set_mtu_service(tt, AF_INET, tun_mtu);
+        }
+        else
+        {
+            windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu);
+        }
     }

 #else  /* if defined(TARGET_LINUX) */
@@ -5236,6 +5306,46 @@ out:
     return ret;
 }

+static void
+windows_set_mtu(const int iface_index, const short family,
+    const int mtu)
+{
+    DWORD err = 0;
+    struct gc_arena gc = gc_new();
+    MIB_IPINTERFACE_ROW row;
+    InitializeIpInterfaceEntry(&row);
+    row.Family = family;
+    row.InterfaceIndex = iface_index;
+    row.NlMtu = mtu;
+
+    err = SetIpInterfaceEntry(&row);
+    if (family == AF_INET)
+    {
+        if (err != NO_ERROR)
+        {
+            msg(M_WARN, "TUN: Setting IPv4 mtu failed: %s [status=%u if_index=%d]", +                strerror_win32(err, &gc), err, iface_index);
+        }
+        else
+        {
+            msg(M_INFO, "Successfully set IPv4 mtu on interface %d", iface_index); +        }
+    }
+    else if (family == AF_INET6)
+    {
+        if (err != NO_ERROR)
+        {
+            msg(M_WARN, "TUN: Setting IPv6 mtu failed: %s [status=%u if_index=%d]", +                strerror_win32(err, &gc), err, iface_index);
+        }
+        else
+        {
+            msg(M_INFO, "Successfully set IPv6 mtu on interface %d", iface_index); +        }
+    }
+}
+
+
 /*
  * Return a TAP name for netsh commands.
  */

src/openvpnserv/interactive.c +0 -0
index 623c3ff7..6e6a63fe 100644
@@ -33,6 +33,7 @@

 #include <sddl.h>
 #include <shellapi.h>
 #include <mstcpip.h>
+#include <netioapi.h>

 #ifdef HAVE_VERSIONHELPERS_H
 #include <versionhelpers.h>
@@ -1198,6 +1199,20 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t *dhcp) return err;
 }

+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW row;
+    InitializeIpInterfaceEntry(&row);
+    row.Family = mtu->family;
+    row.InterfaceIndex = mtu->iface.index;
+    row.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&row);
+    return err;
+}
+
 static VOID
 HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists_t *lists) {
@@ -1210,6 +1225,7 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists block_dns_message_t block_dns;
         dns_cfg_message_t dns;
         enable_dhcp_message_t dhcp;
+        set_mtu_message_t mtu;
     } msg;
     ack_message_t ack = {
         .header = {
@@ -1276,6 +1292,12 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists ack.error_number = HandleEnableDHCPMessage(&msg.dhcp);
             }
             break;
+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu);
+            }
+            break;

         default:
             ack.error_number = ERROR_MESSAGE_TYPE;

#6 lore raw

Hi,

Quoted 13 lines · Christopher Schenk

Hi,

Quoted 8 lines · Selva Nair

I would go a step further to say we should not add new features that do not work when started using the interactive service.

Secondly, we should avoid the old style use of netsh and instead use the iphelper API as far as possible. It should be possible to set MTU using the SetIfEntry() or SetIpInterfaceEnrty() function -- I haven't
checked which one is appropriate here.

Quoted 4 lines

I agree on the point that we should add this functionality to the interactive service as well. So i modified the patch accordingly. I also modified my patch so that it uses the SetIpInterfaceEnrty function instead of netsh.

Thanks for the update. Looks okay, but would prefer a version sent out by git-send-email so that we can apply and test the patch.

Some minor comments below.

Quoted 31 lines

---

include/openvpn-msg.h +8 -0
index 66177a21..f59c5a21 100644
@@ -39,6 +39,7 @@ typedef enum {
      msg_del_block_dns,
      msg_register_dns,
      msg_enable_dhcp,
+    msg_set_mtu,
  } message_type_t;
 
  typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
      interface_t iface;
  } enable_dhcp_message_t;
 
+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
  #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +0 -0
index 48a8fdf7..9fe8444f 100644

src/openvpn/tun.c static void netsh_ifconfig(const struct · line 73

Quoted 5 lines
src/openvpn/tun.c +1 -0
@@ -69,6 +69,10 @@ static void netsh_ifconfig(const struct
 tuntap_options *to,
                             const in_addr_t netmask,
                             const unsigned int flags);
 
+static void windows_set_mtu(const int iface_indey,

iface_indey -> iface_index ?

Quoted 58 lines
src/openvpn/tun.c +3 -0
+                                short family,
+                               const int mtu);
+
  static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                     const int addr_len,
                                     const char *flex_name);
src/openvpn/tun.c +31 -0
@@ -201,6 +205,63 @@ out:
      return ret;
  }
 
+static bool
+do_set_mtu_service(const struct tuntap *tt, const short family, const
 int mtu)
+{
+    DWORD len;
+    bool ret = false;
+    ack_message_t ack;
+    struct gc_arena gc = gc_new();
+    HANDLE pipe = tt->options.msg_channel;
+
+    set_mtu_message_t mtu_msg = {
+        .header = {
+            msg_set_mtu,
+            sizeof(set_mtu_message_t),
+            0
+        },
+        .iface = {.index = tt->adapter_index,.name = tt->actual_name },
+        .mtu = mtu,
+        .family = family
+    };
+
+    if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack,
 "Set_mtu"))
+    {
+        goto out;
+    }
+
+    if (family == AF_INET)
+    {
+        if (ack.error_number != NO_ERROR)
+        {
+            msg(M_NONFATAL, "TUN: setting IPv4 mtu using service
 failed: %s [status=%u if_index=%d]",
+                strerror_win32(ack.error_number, &gc),

ack.error_number, mtu_msg.iface.index);

src/openvpn/tun.c +4 -0
+        }
+        else
+        {
+            msg(M_INFO, "IPv4 MTU set to %d on interface %d using

service", mtu, mtu_msg.iface.index);

src/openvpn/tun.c +8 -0
+            ret = true;
+        }
+    }
+    else if (family == AF_INET6)
+    {
+        if (ack.error_number != NO_ERROR)
+        {
+            msg(M_NONFATAL, "TUN: setting IPv6 mtu using service
Quoted 4 lines

failed: %s [status=%u if_index=%d]",
+ strerror_win32(ack.error_number, &gc),
ack.error_number, mtu_msg.iface.index);
+ }

Though this repetition is fine with me and may be we do the same in other similar contexts, cant we combine these two cases into one by defining a string "IPv4" or "IPv6" based on the value of family?

The same applies to windows_set_mtu() as well.

Quoted 98 lines
src/openvpn/tun.c +3 -0
+        else
+        {
+            msg(M_INFO, "IPv6 MTU set to %d on interface %d using

service", mtu, mtu_msg.iface.index);

src/openvpn/tun.c +10 -0
+            ret = true;
+        }
+    }
+
+out:
+    gc_free(&gc);
+    return ret;
+}
+
  #endif /* ifdef _WIN32 */
 
  #ifdef TARGET_SOLARIS
@@ -984,6 +1045,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
      {
          do_address_service(true, AF_INET6, tt);
          do_dns6_service(true, tt);
+        do_set_mtu_service(tt, AF_INET6, tun_mtu);
      }
      else
      {
src/openvpn/tun.c +1 -0
@@ -1000,6 +1062,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
          netsh_command(&argv, 4, M_FATAL);
          /* set ipv6 dns servers if any are specified */
          netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len,
 ifname);
+        windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
      }
      /* explicit route needed */
src/openvpn/tun.c +8 -1
@@ -1391,9 +1454,16 @@ do_ifconfig_ipv4(struct tuntap *tt, const char
 *ifname, int tun_mtu,
              case IPW32_SET_NETSH:
                  netsh_ifconfig(&tt->options, ifname, tt->local,
                                 tt->adapter_netmask,
 NI_IP_NETMASK|NI_OPTIONS);
-
                  break;
          }
+        if (tt->options.msg_channel)
+        {
+            do_set_mtu_service(tt, AF_INET, tun_mtu);
+        }
+        else
+        {
+            windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu);
+        }
      }
  #else  /* if defined(TARGET_LINUX) */
src/openvpn/tun.c +35 -0
@@ -5236,6 +5306,46 @@ out:
      return ret;
  }
 
+static void
+windows_set_mtu(const int iface_index, const short family,
+    const int mtu)
+{
+    DWORD err = 0;
+    struct gc_arena gc = gc_new();
+    MIB_IPINTERFACE_ROW row;
+    InitializeIpInterfaceEntry(&row);
+    row.Family = family;
+    row.InterfaceIndex = iface_index;
+    row.NlMtu = mtu;
+
+    err = SetIpInterfaceEntry(&row);
+    if (family == AF_INET)
+    {
+        if (err != NO_ERROR)
+        {
+            msg(M_WARN, "TUN: Setting IPv4 mtu failed: %s [status=%u
 if_index=%d]",
+                strerror_win32(err, &gc), err, iface_index);
+        }
+        else
+        {
+            msg(M_INFO, "Successfully set IPv4 mtu on interface %d",
 iface_index);
+        }
+    }
+    else if (family == AF_INET6)
+    {
+        if (err != NO_ERROR)
+        {
+            msg(M_WARN, "TUN: Setting IPv6 mtu failed: %s [status=%u
 if_index=%d]",
+                strerror_win32(err, &gc), err, iface_index);
+        }
+        else
+        {
+            msg(M_INFO, "Successfully set IPv6 mtu on interface %d",

iface_index);

src/openvpn/tun.c

Quoted 2 lines
src/openvpn/tun.c +2 -0
+        }
+    }

See the comment above..

Quoted 56 lines
src/openvpn/tun.c +3 -0
+}
+
+
  /*
   * Return a TAP name for netsh commands.
   */
src/openvpnserv/interactive.c +15 -0
index 623c3ff7..6e6a63fe 100644
@@ -33,6 +33,7 @@
  #include <sddl.h>
  #include <shellapi.h>
  #include <mstcpip.h>
+#include <netioapi.h>
 
  #ifdef HAVE_VERSIONHELPERS_H
  #include <versionhelpers.h>
@@ -1198,6 +1199,20 @@ HandleEnableDHCPMessage(const
 enable_dhcp_message_t *dhcp)
      return err;
  }
 
+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW row;
+    InitializeIpInterfaceEntry(&row);
+    row.Family = mtu->family;
+    row.InterfaceIndex = mtu->iface.index;
+    row.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&row);
+    return err;
+}
+
  static VOID
  HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events,

undo_lists_t *lists)
{

src/openvpnserv/interactive.c +0 -0
@@ -1210,6 +1225,7 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD

count, LPHANDLE events, undo_lists

          block_dns_message_t block_dns;
          dns_cfg_message_t dns;
          enable_dhcp_message_t dhcp;
src/openvpnserv/interactive.c +1 -0
+        set_mtu_message_t mtu;
      } msg;
      ack_message_t ack = {
          .header = {
@@ -1276,6 +1292,12 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD

count, LPHANDLE events, undo_lists

                  ack.error_number = HandleEnableDHCPMessage(&msg.dhcp);
              }
              break;

src/openvpnserv/interactive.c

Quoted 9 lines
src/openvpnserv/interactive.c +6 -0
+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu);
+            }
+            break;
 
          default:
              ack.error_number = ERROR_MESSAGE_TYPE;

Selva

#7 lore raw

Hi,

Quoted 10 lines · Selva Nair
Quoted 9 lines
(quoted diff) +5 -0
+    else if (family == AF_INET6)
+    {
+        if (ack.error_number != NO_ERROR)
+        {
+            msg(M_NONFATAL, "TUN: setting IPv6 mtu using service

failed: %s [status=%u if_index=%d]",
+ strerror_win32(ack.error_number, &gc),
ack.error_number, mtu_msg.iface.index);
+ }

Quoted 6 lines

Though this repetition is fine with me and may be we do the same in other similar contexts, cant we combine these two cases into one by defining a string "IPv4" or "IPv6" based on the value of family?

The same applies to windows_set_mtu() as well.

Yes please, Newer code already tries to do this (like most of the service-related stuff calling a common function for ipv4-or-ipv6 stuff).

(We don't do this for the existing ifconfig orgy because it would not really help readibility... but hopefully that one will get cleaned up more thoroughly eventually)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#8 lore raw

PATCH 1/4 Setting adapter mtu on windows systems

From: Christopher Schenk <[email protected]...>

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
src/openvpn/tun.c +38 -1
index 48a8fdf7..93d028c8 100644
@@ -69,6 +69,12 @@ static void netsh_ifconfig(const struct tuntap_options *to,
                            const in_addr_t netmask,
                            const unsigned int flags);
 
+static void netsh_set_mtu_ipv4(const char *flex_name,
+                               const int mtu);
+
+static void netsh_set_mtu_ipv6(const char *flex_name,
+                               const int mtu);
+
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                    const int addr_len,
                                    const char *flex_name);
@@ -1000,6 +1006,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,
         netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */
         netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname);
+        netsh_set_mtu_ipv6(ifname, tun_mtu);
     }
 
     /* explicit route needed */
@@ -1391,9 +1398,9 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
             case IPW32_SET_NETSH:
                 netsh_ifconfig(&tt->options, ifname, tt->local,
                                tt->adapter_netmask, NI_IP_NETMASK|NI_OPTIONS);
-
                 break;
         }
+		netsh_set_mtu_ipv4(ifname, tun_mtu);
     }
 
 #else  /* if defined(TARGET_LINUX) */
@@ -5236,6 +5243,36 @@ out:
     return ret;
 }
 
+static void
+netsh_set_mtu_ipv4(const char *flex_name,
+                   const int mtu)
+{
+	struct argv argv = argv_new();
+	argv_printf(&argv, "%s%sc interface ipv4 set subinterface %s mtu = %d store=active",
+		get_win_sys_path(),
+		NETSH_PATH_SUFFIX,
+		flex_name,
+		mtu);
+
+	netsh_command(&argv, 3, M_WARN);
+	argv_reset(&argv);
+}
+
+static void
+netsh_set_mtu_ipv6(const char *flex_name,
+	const int mtu)
+{
+	struct argv argv = argv_new();
+	argv_printf(&argv, "%s%sc interface ipv6 set subinterface %s mtu = %d store=active",
+		get_win_sys_path(),
+		NETSH_PATH_SUFFIX,
+		flex_name,
+		mtu);
+
+	netsh_command(&argv, 3, M_WARN);
+	argv_reset(&argv);
+}
+
 /*
  * Return a TAP name for netsh commands.
  */
Signature · 1 line
2.21.0.windows.1
#9 lore raw

PATCH 2/4 Setting MTU also via interactive service

---
 include/openvpn-msg.h         |  8 +++++
 src/openvpn/tun.c             | 67 ++++++++++++++++++++++++++++++++++-
 src/openvpnserv/interactive.c | 50 ++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 1 deletion(-)
include/openvpn-msg.h +8 -0
index 66177a21..f59c5a21 100644
@@ -39,6 +39,7 @@ typedef enum {
     msg_del_block_dns,
     msg_register_dns,
     msg_enable_dhcp,
+	msg_set_mtu,
 } message_type_t;
 
 typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
     interface_t iface;
 } enable_dhcp_message_t;
 
+typedef struct {
+	message_header_t header;
+	interface_t iface;
+	short family;
+	int mtu;
+} set_mtu_message_t;
+
 #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +66 -1

85 lines not on this page · raw message

src/openvpnserv/interactive.c +50 -0

68 lines not on this page · raw message

Signature · 1 line
2.21.0.windows.1
#10 lore raw

PATCH 3/4 Use netioapi instead of netsh to set mtu

In reply to Christopher Schenk
---
 src/openvpn/tun.c             | 68 +++++++++++++++++++----------------
 src/openvpnserv/interactive.c | 44 +++++------------------
 2 files changed, 46 insertions(+), 66 deletions(-)
src/openvpn/tun.c +38 -30
index b0230a7c..9fe8444f 100644
@@ -69,10 +69,8 @@ static void netsh_ifconfig(const struct tuntap_options *to,
                            const in_addr_t netmask,
                            const unsigned int flags);
 
-static void netsh_set_mtu_ipv4(const char *flex_name,
-                               const int mtu);
-
-static void netsh_set_mtu_ipv6(const char *flex_name,
+static void windows_set_mtu(const int iface_indey,
+								short family,
                                const int mtu);
 
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
@@ -1064,7 +1062,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,
         netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */
         netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname);
-        netsh_set_mtu_ipv6(ifname, tun_mtu);
+		windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
     }
 
     /* explicit route needed */
@@ -1464,7 +1462,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
 		}
 		else
 		{
-			netsh_set_mtu_ipv4(ifname, tun_mtu);
+			windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu);
 		}
     }
 
@@ -5309,35 +5307,45 @@ out:
 }
 
 static void
-netsh_set_mtu_ipv4(const char *flex_name,
-                   const int mtu)
-{
-	struct argv argv = argv_new();
-	argv_printf(&argv, "%s%sc interface ipv4 set subinterface %s mtu = %d store=active",
-		get_win_sys_path(),
-		NETSH_PATH_SUFFIX,
-		flex_name,
-		mtu);
-
-	netsh_command(&argv, 3, M_WARN);
-	argv_reset(&argv);
-}
-
-static void
-netsh_set_mtu_ipv6(const char *flex_name,
+windows_set_mtu(const int iface_index, const short family,
 	const int mtu)
 {
-	struct argv argv = argv_new();
-	argv_printf(&argv, "%s%sc interface ipv6 set subinterface %s mtu = %d store=active",
-		get_win_sys_path(),
-		NETSH_PATH_SUFFIX,
-		flex_name,
-		mtu);
+	DWORD err = 0;
+	struct gc_arena gc = gc_new();
+	MIB_IPINTERFACE_ROW row;
+	InitializeIpInterfaceEntry(&row);
+	row.Family = family;
+	row.InterfaceIndex = iface_index;
+	row.NlMtu = mtu;
 
-	netsh_command(&argv, 3, M_WARN);
-	argv_reset(&argv);
+	err = SetIpInterfaceEntry(&row);
+	if (family == AF_INET)
+	{
+		if (err != NO_ERROR)
+		{
+			msg(M_WARN, "TUN: Setting IPv4 mtu failed: %s [status=%u if_index=%d]",
+				strerror_win32(err, &gc), err, iface_index);
+		}
+		else
+		{
+			msg(M_INFO, "Successfully set IPv4 mtu on interface %d", iface_index);
+		}
+	}
+	else if (family == AF_INET6)
+	{
+		if (err != NO_ERROR)
+		{
+			msg(M_WARN, "TUN: Setting IPv6 mtu failed: %s [status=%u if_index=%d]",
+				strerror_win32(err, &gc), err, iface_index);
+		}
+		else
+		{
+			msg(M_INFO, "Successfully set IPv6 mtu on interface %d", iface_index);
+		}
+	}
 }
 
+
 /*
  * Return a TAP name for netsh commands.
  */
src/openvpnserv/interactive.c +8 -36

56 lines not on this page · raw message

Signature · 1 line
2.21.0.windows.1
#11 lore raw

Re: [Openvpn-devel] [PATCH 3/4] Use netioapi instead of netsh to set mtu

Hi,

Quoted 13 lines · Christopher Schenk
---
 src/openvpn/tun.c             | 68 +++++++++++++++++++----------------
 src/openvpnserv/interactive.c | 44 +++++------------------
 2 files changed, 46 insertions(+), 66 deletions(-)
src/openvpn/tun.c +0 -0
index b0230a7c..9fe8444f 100644
@@ -69,10 +69,8 @@ static void netsh_ifconfig(const struct tuntap_options
 *to,
                            const in_addr_t netmask,

src/openvpn/tun.c static void netsh_ifconfig(const struct tuntap_options · line 76

Quoted 10 lines
src/openvpn/tun.c +2 -4
                            const unsigned int flags);
 
-static void netsh_set_mtu_ipv4(const char *flex_name,
-                               const int mtu);
-
-static void netsh_set_mtu_ipv6(const char *flex_name,
+static void windows_set_mtu(const int iface_indey,
+                                                               short
 family,
                                const int mtu);

Do not use tabs, use 4 whitespace characters for indent as in the rest of the code.

src/openvpn/tun.c do_ifconfig_ipv6(struct tuntap *tt, const char · line 1068

Quoted 11 lines

static void netsh_set_dns6_servers(const struct in6_addr *addr_list,

src/openvpn/tun.c +1 -1
@@ -1064,7 +1062,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
         netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */
         netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len,
 ifname);
-        netsh_set_mtu_ipv6(ifname, tun_mtu);
+               windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
 

Code indentation is not "correct" in many places like this -- see remarks in my response to commit 4.

Quoted 28 lines
     }

     /* explicit route needed */
src/openvpn/tun.c +1 -1
@@ -1464,7 +1462,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char
 *ifname, int tun_mtu,
                }
                else
                {
-                       netsh_set_mtu_ipv4(ifname, tun_mtu);
+                       windows_set_mtu(tt->adapter_index, AF_INET,
 tun_mtu);
                }
     }
src/openvpn/tun.c +0 -9
@@ -5309,35 +5307,45 @@ out:
 }
 
 static void
-netsh_set_mtu_ipv4(const char *flex_name,
-                   const int mtu)
-{
-       struct argv argv = argv_new();
-       argv_printf(&argv, "%s%sc interface ipv4 set subinterface %s mtu =
 %d store=active",
-               get_win_sys_path(),
-               NETSH_PATH_SUFFIX,
-               flex_name,
-               mtu);

src/openvpn/tun.c out: · line 5313

Quoted 10 lines
src/openvpn/tun.c +1 -7
-
-       netsh_command(&argv, 3, M_WARN);
-       argv_reset(&argv);
-}
-
-static void
-netsh_set_mtu_ipv6(const char *flex_name,
+windows_set_mtu(const int iface_index, const short family,
        const int mtu)
 

{

Quoted 9 lines
src/openvpn/tun.c +2 -6
-       struct argv argv = argv_new();
-       argv_printf(&argv, "%s%sc interface ipv6 set subinterface %s mtu =
 %d store=active",
-               get_win_sys_path(),
-               NETSH_PATH_SUFFIX,
-               flex_name,
-               mtu);
+       DWORD err = 0;
+       struct gc_arena gc = gc_new();

src/openvpn/tun.c out: · line 5347

Quoted 10 lines
src/openvpn/tun.c +6 -2
+       MIB_IPINTERFACE_ROW row;
+       InitializeIpInterfaceEntry(&row);
+       row.Family = family;
+       row.InterfaceIndex = iface_index;
+       row.NlMtu = mtu;
 
-       netsh_command(&argv, 3, M_WARN);
-       argv_reset(&argv);
+       err = SetIpInterfaceEntry(&row);
 

I think this has the potential to reset other interface parameters edited elsewhere (or set by the user) to the default values. The right approach would be to get the current state using GetIpInterfaceEntry(&row) and then modify only the mtu before calling SetIpInterfaceEntry().

See how its done in block_dns.c or consult the IP Helper docs.

Same in interactive.c

+ if (family == AF_INET)

Quoted 40 lines
src/openvpn/tun.c +9 -0
+       {
+               if (err != NO_ERROR)
+               {
+                       msg(M_WARN, "TUN: Setting IPv4 mtu failed: %s
 [status=%u if_index=%d]",
+                               strerror_win32(err, &gc), err,
 iface_index);
+               }
+               else
+               {
+                       msg(M_INFO, "Successfully set IPv4 mtu on

interface %d", iface_index);

src/openvpn/tun.c +7 -0
+               }
+       }
+       else if (family == AF_INET6)
+       {
+               if (err != NO_ERROR)
+               {
+                       msg(M_WARN, "TUN: Setting IPv6 mtu failed: %s

[status=%u if_index=%d]",
+ strerror_win32(err, &gc), err,
iface_index);

src/openvpn/tun.c +4 -0
+               }
+               else
+               {
+                       msg(M_INFO, "Successfully set IPv6 mtu on

interface %d", iface_index);

src/openvpn/tun.c +3 -0
+               }
+       }
 }
 
+
 /*
  * Return a TAP name for netsh commands.
  */
src/openvpnserv/interactive.c +0 -0
index 31e4afa0..6e6a63fe 100644

src/openvpnserv/interactive.c line 38

Quoted 6 lines
src/openvpnserv/interactive.c +1 -0
@@ -33,6 +33,7 @@
 #include <sddl.h>
 #include <shellapi.h>
 #include <mstcpip.h>
+#include <netioapi.h>
 
 

There should be no need to include this header directly. Instead let the main IP Helper API header (iphlpapi.h) include it correctly. The latter is already included both in tun.c and interactive.c

Quoted 44 lines
src/openvpnserv/interactive.c +0 -0
 #ifdef HAVE_VERSIONHELPERS_H

#include <versionhelpers.h>

src/openvpnserv/interactive.c +0 -33
@@ -1202,42 +1203,13 @@ static DWORD
 HandleMTUMessage(const set_mtu_message_t *mtu)
 {
        DWORD err = 0;
-       DWORD timeout = 5000; /* in milli seconds */
-       wchar_t argv0[MAX_PATH];
-
-       /* Path of netsh */
-       swprintf(argv0, _countof(argv0), L"%s\\%s", get_win_sys_path(),
 L"netsh.exe");
-       argv0[_countof(argv0) - 1] = L'\0';
-
-       /* cmd template:
-        * netsh interface $family set subinterface "$if_name" mtu=$mtu
-        */
-       const wchar_t *fmt;
-       if (mtu->family == AF_INET)
-       {
-               fmt = L"netsh interface ipv4 set subinterface \"%d\" mtu=
 %d";
-       }
-       else if (mtu->family == AF_INET6)
-       {
-               fmt = L"netsh interface ipv6 set subinterface \"%d\" mtu=
 %d";
-       }
-
-       /* max cmdline length in wchars -- include room for if index:
-        * 20 chars for two 32 bit int in decimal and +1 for NUL
-        */
-       size_t ncmdline = wcslen(fmt) + 20 + 1;
-       wchar_t *cmdline = malloc(ncmdline * sizeof(wchar_t));
-       if (!cmdline)
-       {
-               err = ERROR_OUTOFMEMORY;
-               return err;
-       }
-
-       openvpn_sntprintf(cmdline, ncmdline, fmt, mtu->iface.index,
 mtu->mtu);
-

src/openvpnserv/interactive.c static DWORD · line 1212

Quoted 10 lines
src/openvpnserv/interactive.c +7 -3
-       err = ExecCommand(argv0, cmdline, timeout);
-
-       free(cmdline);
+       MIB_IPINTERFACE_ROW row;
+       InitializeIpInterfaceEntry(&row);
+       row.Family = mtu->family;
+       row.InterfaceIndex = mtu->iface.index;
+       row.NlMtu = mtu->mtu;
+
+       err = SetIpInterfaceEntry(&row);

See the remark above.

Quoted 4 lines
        return err;

}

Selva

#12 lore raw

PATCH 4/4 Simplified if statements for better readability

In reply to Christopher Schenk
---
 src/openvpn/tun.c | 58 ++++++++++++-----------------------------------
 1 file changed, 14 insertions(+), 44 deletions(-)
src/openvpn/tun.c +14 -44
index 9fe8444f..20e661a7 100644
@@ -69,7 +69,7 @@ static void netsh_ifconfig(const struct tuntap_options *to,
                            const in_addr_t netmask,
                            const unsigned int flags);
 
-static void windows_set_mtu(const int iface_indey,
+static void windows_set_mtu(const int iface_index,
 								short family,
                                const int mtu);
 
@@ -213,7 +213,7 @@ do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
 	ack_message_t ack;
 	struct gc_arena gc = gc_new();
 	HANDLE pipe = tt->options.msg_channel;
-
+	char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
 	set_mtu_message_t mtu_msg = {
 		.header = {
 			msg_set_mtu,
@@ -230,31 +230,15 @@ do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
 		goto out;
 	}
 
-	if (family == AF_INET)
+	if (ack.error_number != NO_ERROR)
 	{
-		if (ack.error_number != NO_ERROR)
-		{
-			msg(M_NONFATAL, "TUN: setting IPv4 mtu using service failed: %s [status=%u if_index=%d]",
-				strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.iface.index);
-		}
-		else
-		{
-			msg(M_INFO, "IPv4 MTU set to %d on interface %d using service", mtu, mtu_msg.iface.index);
-			ret = true;
-		}
+		msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%d]",
+			family_name, strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.iface.index);
 	}
-	else if (family == AF_INET6)
+	else
 	{
-		if (ack.error_number != NO_ERROR)
-		{
-			msg(M_NONFATAL, "TUN: setting IPv6 mtu using service failed: %s [status=%u if_index=%d]",
-				strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.iface.index);
-		}
-		else
-		{
-			msg(M_INFO, "IPv6 MTU set to %d on interface %d using service", mtu, mtu_msg.iface.index);
-			ret = true;
-		}
+		msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu, mtu_msg.iface.index);
+		ret = true;
 	}
 
 out:
@@ -5313,35 +5297,21 @@ windows_set_mtu(const int iface_index, const short family,
 	DWORD err = 0;
 	struct gc_arena gc = gc_new();
 	MIB_IPINTERFACE_ROW row;
+	char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
 	InitializeIpInterfaceEntry(&row);
 	row.Family = family;
 	row.InterfaceIndex = iface_index;
 	row.NlMtu = mtu;
 
 	err = SetIpInterfaceEntry(&row);
-	if (family == AF_INET)
+	if (err != NO_ERROR)
 	{
-		if (err != NO_ERROR)
-		{
-			msg(M_WARN, "TUN: Setting IPv4 mtu failed: %s [status=%u if_index=%d]",
-				strerror_win32(err, &gc), err, iface_index);
-		}
-		else
-		{
-			msg(M_INFO, "Successfully set IPv4 mtu on interface %d", iface_index);
-		}
+		msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=%u if_index=%d]",
+			family_name, strerror_win32(err, &gc), err, iface_index);
 	}
-	else if (family == AF_INET6)
+	else
 	{
-		if (err != NO_ERROR)
-		{
-			msg(M_WARN, "TUN: Setting IPv6 mtu failed: %s [status=%u if_index=%d]",
-				strerror_win32(err, &gc), err, iface_index);
-		}
-		else
-		{
-			msg(M_INFO, "Successfully set IPv6 mtu on interface %d", iface_index);
-		}
+		msg(M_INFO, "Successfully set %s mtu on interface %d", family_name, iface_index);
 	}
 }
 
Signature · 1 line
2.21.0.windows.1
#13 lore raw

Re: [Openvpn-devel] [PATCH 4/4] Simplified if statements for better readability

Hi,

Quoted 4 lines · Christopher Schenk
---
 src/openvpn/tun.c | 58 ++++++++++++-----------------------------------
 1 file changed, 14 insertions(+), 44 deletions(-)

@@ -213,7 +213,7 @@ do_set_mtu_service(const struct tuntap *tt, const short

src/openvpn/tun.c do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu) · line 216

Quoted 6 lines

family, const int mtu)

        ack_message_t ack;
        struct gc_arena gc = gc_new();
        HANDLE pipe = tt->options.msg_channel;
src/openvpn/tun.c +1 -1
-
+       char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";

This should be preferably declared as const char *family_name. Also see my response to commit 2

Some general remarks follow:

Now we have 4 commits, two for the initial netsh implementation, one replacing that by SetIpInterfaceEntry() and a fixup. We don't want to keep all that irrelevant history, so these have to be squashed into one commit
(or two if you wish to separate the interactive service part). And edit the final commit message header and description to reflect the final
version. Squashing all into one commit may be easier and that's fine in this case.

We also prefer to have patches signed off. Adding -s to "git commit" or doing "git commit -s --amend" will take care of that.

Finally, I'm not sure whether we still require patch authors to follow the code formatting style or we automatically run uncrustify during merge. Even if its not mandatory, its a good practice to follow the style in the rest of
the code to the extent possible: for example, we use 4 spaces for indent (not 8), no tabs anywhere etc. You can run
"uncrustify -c dev-tools/uncrustify.conf" on tun.c, interactive.c and openvpn_msg.h to get most of that rectified. Note that uncrustify may edit unrelated parts of the code -- if it does, do not include such changes in the patch.

Thanks

Selva

#14 lore raw

Re: [Openvpn-devel] [PATCH 4/4] Simplified if statements for better readability

Hi,

Quoted 2 lines · Selva Nair

Finally, I'm not sure whether we still require patch authors to follow the code formatting style or we automatically run uncrustify during merge.

We have decided that all *core* authors are required to either run uncrustify or "get it right on their own" - but Christopher is not "core", so I could do that for him.

OTOH, I prefer to commit patches "as they come in on the list", so, no code changes by me, not even formatting...

@Christopher: the source tree has "openvpn/dev-tools/uncrustify.conf".

If you copy that (on a unixish system) to $HOME/.uncrustify.cfg, you can just call "uncrustify --replace $sourcefile" to have it change the file to our accepted coding standard. Much easier than hanggling on the list later on.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#15 lore raw

PATCH 1/1 Set the correct mtu on windows based systems

---
 include/openvpn-msg.h         |  8 ++++
 src/openvpn/tun.c             | 89 +++++++++++++++++++++++++++++++++++
 src/openvpnserv/interactive.c | 31 ++++++++++++
 3 files changed, 128 insertions(+)
include/openvpn-msg.h +8 -0
index 66177a21..10cd68ac 100644
@@ -39,6 +39,7 @@ typedef enum {
     msg_del_block_dns,
     msg_register_dns,
     msg_enable_dhcp,
+    msg_set_mtu,
 } message_type_t;
 
 typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
     interface_t iface;
 } enable_dhcp_message_t;
 
+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
 #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +89 -0

125 lines not on this page · raw message

src/openvpnserv/interactive.c +31 -0
index 623c3ff7..c24cb22b 100644
@@ -1198,6 +1198,29 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t *dhcp)
     return err;
 }
 
+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    ipiface.Family = mtu->family;
+    ipiface.InterfaceIndex = mtu->iface.index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err != NO_ERROR)
+    {
+        return err;
+    }
+    if (mtu->family == AF_INET)
+    {
+        ipiface.SitePrefixLength = 0;
+    }
+    ipiface.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&ipiface);
+    return err;
+}
+
 static VOID
 HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists_t *lists)
 {
@@ -1210,6 +1233,7 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists
         block_dns_message_t block_dns;
         dns_cfg_message_t dns;
         enable_dhcp_message_t dhcp;
+        set_mtu_message_t mtu;
     } msg;
     ack_message_t ack = {
         .header = {
@@ -1277,6 +1301,13 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists
             }
             break;
 
+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu);
+            }
+            break;
+
         default:
             ack.error_number = ERROR_MESSAGE_TYPE;
             MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Unknown message type %d"), msg.header.type);
Signature · 1 line
2.21.0.windows.1
#16 lore raw

Re: [Openvpn-devel] [PATCH] Set the correct mtu on windows based systems

Hi,

what do you think about this patch? Is anything missing?

Best regards

Christopher

Quoted 222 lines · Christopher Schenk
---
  include/openvpn-msg.h         |  8 ++++
  src/openvpn/tun.c             | 89 +++++++++++++++++++++++++++++++++++
  src/openvpnserv/interactive.c | 31 ++++++++++++
  3 files changed, 128 insertions(+)
include/openvpn-msg.h +8 -0
index 66177a21..10cd68ac 100644
@@ -39,6 +39,7 @@ typedef enum {
      msg_del_block_dns,
      msg_register_dns,
      msg_enable_dhcp,
+    msg_set_mtu,
  } message_type_t;
 
  typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
      interface_t iface;
  } enable_dhcp_message_t;
 
+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
  #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +89 -0
index 48a8fdf7..3895e421 100644
@@ -69,6 +69,10 @@ static void netsh_ifconfig(const struct tuntap_options *to,
                             const in_addr_t netmask,
                             const unsigned int flags);
 
+static void windows_set_mtu(const int iface_index,
+                            const short family,
+                            const int mtu);
+
  static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                     const int addr_len,
                                     const char *flex_name);
@@ -201,6 +205,47 @@ out:
      return ret;
  }
 
+static bool
+do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
+{
+    DWORD len;
+    bool ret = false;
+    ack_message_t ack;
+    struct gc_arena gc = gc_new();
+    HANDLE pipe = tt->options.msg_channel;
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    set_mtu_message_t mtu_msg = {
+        .header = {
+            msg_set_mtu,
+            sizeof(set_mtu_message_t),
+            0
+        },
+        .iface = {.index = tt->adapter_index,.name = tt->actual_name },
+        .mtu = mtu,
+        .family = family
+    };
+
+    if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack, "Set_mtu"))
+    {
+        goto out;
+    }
+
+    if (ack.error_number != NO_ERROR)
+    {
+        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%d]",
+            family_name, strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.iface.index);
+    }
+    else
+    {
+        msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu, mtu_msg.iface.index);
+        ret = true;
+    }
+
+out:
+    gc_free(&gc);
+    return ret;
+}
+
  #endif /* ifdef _WIN32 */
 
  #ifdef TARGET_SOLARIS
@@ -984,6 +1029,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,
      {
          do_address_service(true, AF_INET6, tt);
          do_dns6_service(true, tt);
+        do_set_mtu_service(tt, AF_INET6, tun_mtu);
      }
      else
      {
@@ -1000,6 +1046,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,
          netsh_command(&argv, 4, M_FATAL);
          /* set ipv6 dns servers if any are specified */
          netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname);
+        windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
      }
 
      /* explicit route needed */
@@ -1394,6 +1441,14 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
 
                  break;
          }
+        if (tt->options.msg_channel)
+        {
+            do_set_mtu_service(tt, AF_INET, tun_mtu);
+        }
+        else
+        {
+            windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu);
+        }
      }
 
  #else  /* if defined(TARGET_LINUX) */
@@ -5236,6 +5291,40 @@ out:
      return ret;
  }
 
+static void
+windows_set_mtu(const int iface_index, const short family,
+                const int mtu)
+{
+    DWORD err = 0;
+    struct gc_arena gc = gc_new();
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    ipiface.Family = family;
+    ipiface.InterfaceIndex = iface_index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err == NO_ERROR)
+    {
+        if (family == AF_INET)
+        {
+            ipiface.SitePrefixLength = 0;
+        }
+        ipiface.NlMtu = mtu;
+        err = SetIpInterfaceEntry(&ipiface);
+    }
+
+    if (err != NO_ERROR)
+    {
+        msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=%u if_index=%d]",
+            family_name, strerror_win32(err, &gc), err, iface_index);
+    }
+    else
+    {
+        msg(M_INFO, "Successfully set %s mtu on interface %d", family_name, iface_index);
+    }
+}
+
+
  /*
   * Return a TAP name for netsh commands.
   */
src/openvpnserv/interactive.c +31 -0
index 623c3ff7..c24cb22b 100644
@@ -1198,6 +1198,29 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t *dhcp)
      return err;
  }
 
+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    ipiface.Family = mtu->family;
+    ipiface.InterfaceIndex = mtu->iface.index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err != NO_ERROR)
+    {
+        return err;
+    }
+    if (mtu->family == AF_INET)
+    {
+        ipiface.SitePrefixLength = 0;
+    }
+    ipiface.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&ipiface);
+    return err;
+}
+
  static VOID
  HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists_t *lists)
  {
@@ -1210,6 +1233,7 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists
          block_dns_message_t block_dns;
          dns_cfg_message_t dns;
          enable_dhcp_message_t dhcp;
+        set_mtu_message_t mtu;
      } msg;
      ack_message_t ack = {
          .header = {
@@ -1277,6 +1301,13 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists
              }
              break;
 
+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu);
+            }
+            break;
+
          default:
              ack.error_number = ERROR_MESSAGE_TYPE;
              MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Unknown message type %d"), msg.header.type);
Acked-by on v1 1/1
#17 lore raw

Re: [Openvpn-devel] [PATCH] Set the correct mtu on windows based systems

In reply to Christopher Schenk

Hi,

Thanks for the new version. I somehow missed it as it went into a new thread.

For the record, this is an updated version of the series
https://patchwork.openvpn.net/project/openvpn2/list/?series=471
with requested changes:

(i) tabs removed + some good white-space changes (ii) GetIpInterfaceEntry() called first to read-in the current parameters before calling SetIpInterfaceEntry()

Summary:
The patch sets the tun_mtu value (either the default of 1500 or user-specified --tun-mtu xxx) on the tun/tap interface on Windows using the IP helper API, preferably via the interactive service.

Looks good now and a quick test on WIndows 7 behaves as expected.

I'm ACKing this, but one remark: the patch does not revert the mtu back to the previous value on disconnect. This is an issue only (?) if we want to support clean downgrades to an earlier version without recreating the tun/tap interfaces.

Quoted 83 lines · Christopher Schenk
---
 include/openvpn-msg.h         |  8 ++++
 src/openvpn/tun.c             | 89 +++++++++++++++++++++++++++++++++++
 src/openvpnserv/interactive.c | 31 ++++++++++++
 3 files changed, 128 insertions(+)
include/openvpn-msg.h +8 -0
index 66177a21..10cd68ac 100644
@@ -39,6 +39,7 @@ typedef enum {
     msg_del_block_dns,
     msg_register_dns,
     msg_enable_dhcp,
+    msg_set_mtu,
 } message_type_t;
 
 typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
     interface_t iface;
 } enable_dhcp_message_t;
 
+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
 #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +4 -0
index 48a8fdf7..3895e421 100644
@@ -69,6 +69,10 @@ static void netsh_ifconfig(const struct tuntap_options
 *to,
                            const in_addr_t netmask,
                            const unsigned int flags);
 
+static void windows_set_mtu(const int iface_index,
+                            const short family,
+                            const int mtu);
+
 static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                    const int addr_len,
                                    const char *flex_name);
src/openvpn/tun.c +29 -0
@@ -201,6 +205,47 @@ out:
     return ret;
 }
 
+static bool
+do_set_mtu_service(const struct tuntap *tt, const short family, const int
 mtu)
+{
+    DWORD len;
+    bool ret = false;
+    ack_message_t ack;
+    struct gc_arena gc = gc_new();
+    HANDLE pipe = tt->options.msg_channel;
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    set_mtu_message_t mtu_msg = {
+        .header = {
+            msg_set_mtu,
+            sizeof(set_mtu_message_t),
+            0
+        },
+        .iface = {.index = tt->adapter_index,.name = tt->actual_name },
+        .mtu = mtu,
+        .family = family
+    };
+
+    if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack,
 "Set_mtu"))
+    {
+        goto out;
+    }
+
+    if (ack.error_number != NO_ERROR)
+    {
+        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s
 [status=%u if_index=%d]",
+            family_name, strerror_win32(ack.error_number, &gc),
Quoted 2 lines

ack.error_number, mtu_msg.iface.index);

+ }

Quoted 153 lines
src/openvpn/tun.c +3 -0
+    else
+    {
+        msg(M_INFO, "%s MTU set to %d on interface %d using service",

family_name, mtu, mtu_msg.iface.index);

src/openvpn/tun.c +9 -0
+        ret = true;
+    }
+
+out:
+    gc_free(&gc);
+    return ret;
+}
+
 #endif /* ifdef _WIN32 */
 
 #ifdef TARGET_SOLARIS
@@ -984,6 +1029,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
     {
         do_address_service(true, AF_INET6, tt);
         do_dns6_service(true, tt);
+        do_set_mtu_service(tt, AF_INET6, tun_mtu);
     }
     else
     {
src/openvpn/tun.c +1 -0
@@ -1000,6 +1046,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
         netsh_command(&argv, 4, M_FATAL);
         /* set ipv6 dns servers if any are specified */
         netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len,
 ifname);
+        windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
     }
     /* explicit route needed */
src/openvpn/tun.c +8 -0
@@ -1394,6 +1441,14 @@ do_ifconfig_ipv4(struct tuntap *tt, const char
 *ifname, int tun_mtu,
 
                 break;
         }
+        if (tt->options.msg_channel)
+        {
+            do_set_mtu_service(tt, AF_INET, tun_mtu);
+        }
+        else
+        {
+            windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu);
+        }
     }
 

#else /* if defined(TARGET_LINUX) */

src/openvpn/tun.c +34 -0
@@ -5236,6 +5291,40 @@ out:
     return ret;
 }
 
+static void
+windows_set_mtu(const int iface_index, const short family,
+                const int mtu)
+{
+    DWORD err = 0;
+    struct gc_arena gc = gc_new();
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    ipiface.Family = family;
+    ipiface.InterfaceIndex = iface_index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err == NO_ERROR)
+    {
+        if (family == AF_INET)
+        {
+            ipiface.SitePrefixLength = 0;
+        }
+        ipiface.NlMtu = mtu;
+        err = SetIpInterfaceEntry(&ipiface);
+    }
+
+    if (err != NO_ERROR)
+    {
+        msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=%u
 if_index=%d]",
+            family_name, strerror_win32(err, &gc), err, iface_index);
+    }
+    else
+    {
+        msg(M_INFO, "Successfully set %s mtu on interface %d",
 family_name, iface_index);
+    }
+}
+
+
 /*

* Return a TAP name for netsh commands.
*/

src/openvpnserv/interactive.c +23 -0
index 623c3ff7..c24cb22b 100644
@@ -1198,6 +1198,29 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t
 *dhcp)
     return err;
 }
 
+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    ipiface.Family = mtu->family;
+    ipiface.InterfaceIndex = mtu->iface.index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err != NO_ERROR)
+    {
+        return err;
+    }
+    if (mtu->family == AF_INET)
+    {
+        ipiface.SitePrefixLength = 0;
+    }
+    ipiface.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&ipiface);
+    return err;
+}
+
 static VOID
 HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events,

undo_lists_t *lists)
{

src/openvpnserv/interactive.c +0 -0
@@ -1210,6 +1233,7 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count,

LPHANDLE events, undo_lists

         block_dns_message_t block_dns;
         dns_cfg_message_t dns;
         enable_dhcp_message_t dhcp;
src/openvpnserv/interactive.c +1 -0
+        set_mtu_message_t mtu;
     } msg;
     ack_message_t ack = {
         .header = {
@@ -1277,6 +1301,13 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD

count, LPHANDLE events, undo_lists

             }
             break;
src/openvpnserv/interactive.c +7 -0
+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu);
+            }
+            break;
+
         default:
             ack.error_number = ERROR_MESSAGE_TYPE;
             MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Unknown message type
Quoted 3 lines

%d"), msg.header.type);

Selva

#18 lore raw

Re: [Openvpn-devel] [PATCH] Set the correct mtu on windows based systems

Hi,

i think this is not a big issue since the mtu is only set until the system gets rebooted. So it behaves exactly like my netsh version where i specified a "store=active" in the set command.

Christopher

Quoted 275 lines · Selva Nair

Hi,

Thanks for the new version. I somehow missed it as it went into a new thread.

For the record, this is an updated version of the series
https://patchwork.openvpn.net/project/openvpn2/list/?series=471
with requested changes:

(i) tabs removed + some good white-space changes (ii) GetIpInterfaceEntry() called first to read-in the current parameters before calling SetIpInterfaceEntry()

Summary:
The patch sets the tun_mtu value (either the default of 1500 or user-specified --tun-mtu xxx) on the tun/tap interface on Windows using the IP helper API, preferably via the interactive service.

Looks good now and a quick test on WIndows 7 behaves as expected.

I'm ACKing this, but one remark: the patch does not revert the mtu back to the previous value on disconnect. This is an issue only (?) if we want to support clean downgrades to an earlier version without recreating the tun/tap interfaces.

Quoted 83 lines · Christopher Schenk
---
  include/openvpn-msg.h         |  8 ++++
  src/openvpn/tun.c             | 89 +++++++++++++++++++++++++++++++++++
  src/openvpnserv/interactive.c | 31 ++++++++++++
  3 files changed, 128 insertions(+)
include/openvpn-msg.h +8 -0
index 66177a21..10cd68ac 100644
@@ -39,6 +39,7 @@ typedef enum {
      msg_del_block_dns,
      msg_register_dns,
      msg_enable_dhcp,
+    msg_set_mtu,
  } message_type_t;
 
  typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
      interface_t iface;
  } enable_dhcp_message_t;
 
+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
  #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +4 -0
index 48a8fdf7..3895e421 100644
@@ -69,6 +69,10 @@ static void netsh_ifconfig(const struct tuntap_options
 *to,
                             const in_addr_t netmask,
                             const unsigned int flags);
 
+static void windows_set_mtu(const int iface_index,
+                            const short family,
+                            const int mtu);
+
  static void netsh_set_dns6_servers(const struct in6_addr *addr_list,
                                     const int addr_len,
                                     const char *flex_name);
src/openvpn/tun.c +29 -0
@@ -201,6 +205,47 @@ out:
      return ret;
  }
 
+static bool
+do_set_mtu_service(const struct tuntap *tt, const short family, const int
 mtu)
+{
+    DWORD len;
+    bool ret = false;
+    ack_message_t ack;
+    struct gc_arena gc = gc_new();
+    HANDLE pipe = tt->options.msg_channel;
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    set_mtu_message_t mtu_msg = {
+        .header = {
+            msg_set_mtu,
+            sizeof(set_mtu_message_t),
+            0
+        },
+        .iface = {.index = tt->adapter_index,.name = tt->actual_name },
+        .mtu = mtu,
+        .family = family
+    };
+
+    if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack,
 "Set_mtu"))
+    {
+        goto out;
+    }
+
+    if (ack.error_number != NO_ERROR)
+    {
+        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s
 [status=%u if_index=%d]",
+            family_name, strerror_win32(ack.error_number, &gc),
Quoted 2 lines

ack.error_number, mtu_msg.iface.index);

+ }

Quoted 153 lines
src/openvpn/tun.c +3 -0
+    else
+    {
+        msg(M_INFO, "%s MTU set to %d on interface %d using service",

family_name, mtu, mtu_msg.iface.index);

src/openvpn/tun.c +9 -0
+        ret = true;
+    }
+
+out:
+    gc_free(&gc);
+    return ret;
+}
+
  #endif /* ifdef _WIN32 */
 
  #ifdef TARGET_SOLARIS
@@ -984,6 +1029,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
      {
          do_address_service(true, AF_INET6, tt);
          do_dns6_service(true, tt);
+        do_set_mtu_service(tt, AF_INET6, tun_mtu);
      }
      else
      {
src/openvpn/tun.c +1 -0
@@ -1000,6 +1046,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
          netsh_command(&argv, 4, M_FATAL);
          /* set ipv6 dns servers if any are specified */
          netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len,
 ifname);
+        windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
      }
      /* explicit route needed */
src/openvpn/tun.c +8 -0
@@ -1394,6 +1441,14 @@ do_ifconfig_ipv4(struct tuntap *tt, const char
 *ifname, int tun_mtu,
 
                  break;
          }
+        if (tt->options.msg_channel)
+        {
+            do_set_mtu_service(tt, AF_INET, tun_mtu);
+        }
+        else
+        {
+            windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu);
+        }
      }
 
  #else  /* if defined(TARGET_LINUX) */
src/openvpn/tun.c +34 -0
@@ -5236,6 +5291,40 @@ out:
      return ret;
  }
 
+static void
+windows_set_mtu(const int iface_index, const short family,
+                const int mtu)
+{
+    DWORD err = 0;
+    struct gc_arena gc = gc_new();
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    ipiface.Family = family;
+    ipiface.InterfaceIndex = iface_index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err == NO_ERROR)
+    {
+        if (family == AF_INET)
+        {
+            ipiface.SitePrefixLength = 0;
+        }
+        ipiface.NlMtu = mtu;
+        err = SetIpInterfaceEntry(&ipiface);
+    }
+
+    if (err != NO_ERROR)
+    {
+        msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=%u
 if_index=%d]",
+            family_name, strerror_win32(err, &gc), err, iface_index);
+    }
+    else
+    {
+        msg(M_INFO, "Successfully set %s mtu on interface %d",
 family_name, iface_index);
+    }
+}
+
+
  /*

* Return a TAP name for netsh commands.
*/

src/openvpnserv/interactive.c +23 -0
index 623c3ff7..c24cb22b 100644
@@ -1198,6 +1198,29 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t
 *dhcp)
      return err;
  }
 
+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    ipiface.Family = mtu->family;
+    ipiface.InterfaceIndex = mtu->iface.index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err != NO_ERROR)
+    {
+        return err;
+    }
+    if (mtu->family == AF_INET)
+    {
+        ipiface.SitePrefixLength = 0;
+    }
+    ipiface.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&ipiface);
+    return err;
+}
+
  static VOID
  HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events,

undo_lists_t *lists)
{

src/openvpnserv/interactive.c +0 -0
@@ -1210,6 +1233,7 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD count,

LPHANDLE events, undo_lists

          block_dns_message_t block_dns;
          dns_cfg_message_t dns;
          enable_dhcp_message_t dhcp;
src/openvpnserv/interactive.c +1 -0
+        set_mtu_message_t mtu;
      } msg;
      ack_message_t ack = {
          .header = {
@@ -1277,6 +1301,13 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD

count, LPHANDLE events, undo_lists

              }
              break;
src/openvpnserv/interactive.c +7 -0
+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu);
+            }
+            break;
+
          default:
              ack.error_number = ERROR_MESSAGE_TYPE;
              MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Unknown message type
Quoted 3 lines

%d"), msg.header.type);

Selva

#19 lore raw

Re: [Openvpn-devel] [PATCH] Set the correct mtu on windows based systems

Hi,

any other thoughts on this patch? Any chance to getting it applied?

Christopher

Quoted 292 lines · Christopher Schenk

Hi,

i think this is not a big issue since the mtu is only set until the system gets rebooted. So it behaves exactly like my netsh version where i specified a "store=active" in the set command.

Christopher

Quoted 277 lines · Selva Nair

Hi,

Thanks for the new version. I somehow missed it as it went into a new thread.

For the record, this is an updated version of the series
https://patchwork.openvpn.net/project/openvpn2/list/?series=471
with requested changes:

(i) tabs removed + some good white-space changes (ii) GetIpInterfaceEntry() called first to read-in the current parameters before calling SetIpInterfaceEntry()

Summary:
The  patch sets the tun_mtu value (either the default of 1500 or user-specified --tun-mtu xxx) on the tun/tap  interface on Windows using the IP helper API, preferably via the interactive service.

Looks good now and a quick test on WIndows 7 behaves as expected.

I'm ACKing this, but one remark: the patch does not revert the mtu back to the previous value on disconnect. This is an issue only (?) if we want to support clean downgrades to an earlier version without recreating the tun/tap interfaces.

Quoted 78 lines · Christopher Schenk

---
  include/openvpn-msg.h         |  8 ++++
  src/openvpn/tun.c             | 89 +++++++++++++++++++++++++++++++++++ src/openvpnserv/interactive.c | 31 ++++++++++++

  3 files changed, 128 insertions(+)
include/openvpn-msg.h +8 -0
index 66177a21..10cd68ac 100644
@@ -39,6 +39,7 @@ typedef enum {
       msg_del_block_dns,
       msg_register_dns,
       msg_enable_dhcp,
+    msg_set_mtu,
   } message_type_t;
 
   typedef struct {
@@ -117,4 +118,11 @@ typedef struct {
       interface_t iface;
   } enable_dhcp_message_t;
 
+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
   #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +0 -0
index 48a8fdf7..3895e421 100644
@@ -69,6 +69,10 @@ static void netsh_ifconfig(const struct 

tuntap_options
*to,
                             const in_addr_t netmask, const unsigned int flags);

src/openvpn/tun.c +4 -0
+static void windows_set_mtu(const int iface_index,
+                            const short family,
+                            const int mtu);
+

  static void netsh_set_dns6_servers(const struct in6_addr *addr_list, const int addr_len, const char *flex_name);

src/openvpn/tun.c +2 -0
@@ -201,6 +205,47 @@ out:
       return ret;
   }
 
+static bool
+do_set_mtu_service(const struct tuntap *tt, const short family, 

const int
mtu)

src/openvpn/tun.c +19 -0
+{
+    DWORD len;
+    bool ret = false;
+    ack_message_t ack;
+    struct gc_arena gc = gc_new();
+    HANDLE pipe = tt->options.msg_channel;
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    set_mtu_message_t mtu_msg = {
+        .header = {
+            msg_set_mtu,
+            sizeof(set_mtu_message_t),
+            0
+        },
+        .iface = {.index = tt->adapter_index,.name = tt->actual_name },
+        .mtu = mtu,
+        .family = family
+    };
+
+    if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack,

"Set_mtu"))
+    {
+        goto out;

Quoted 9 lines

+    }
+
+    if (ack.error_number != NO_ERROR)
+    {
+        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%d]",
+            family_name, strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.iface.index);

+    }

Quoted 145 lines

+    else
+    {
+        msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu, mtu_msg.iface.index);
+        ret = true;
+    }

src/openvpn/tun.c +6 -0
+
+out:
+    gc_free(&gc);
+    return ret;
+}
+

  #endif /* ifdef _WIN32 */

  #ifdef TARGET_SOLARIS

src/openvpn/tun.c +1 -0
@@ -984,6 +1029,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
       {
           do_address_service(true, AF_INET6, tt);
           do_dns6_service(true, tt);
+        do_set_mtu_service(tt, AF_INET6, tun_mtu);
       }

      else
      {

src/openvpn/tun.c +1 -0
@@ -1000,6 +1046,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char
 *ifname, int tun_mtu,
           netsh_command(&argv, 4, M_FATAL);
           /* set ipv6 dns servers if any are specified */
           netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len,
 ifname);
+        windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu);
       }

      /* explicit route needed */

src/openvpn/tun.c +8 -0
@@ -1394,6 +1441,14 @@ do_ifconfig_ipv4(struct tuntap *tt, const char
 *ifname, int tun_mtu,
 
                   break;
           }
+        if (tt->options.msg_channel)
+        {
+            do_set_mtu_service(tt, AF_INET, tun_mtu);
+        }
+        else
+        {
+            windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu);
+        }
       }
 

  #else  /* if defined(TARGET_LINUX) */

src/openvpn/tun.c +34 -0
@@ -5236,6 +5291,40 @@ out:
       return ret;
   }
 
+static void
+windows_set_mtu(const int iface_index, const short family,
+                const int mtu)
+{
+    DWORD err = 0;
+    struct gc_arena gc = gc_new();
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
+    ipiface.Family = family;
+    ipiface.InterfaceIndex = iface_index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err == NO_ERROR)
+    {
+        if (family == AF_INET)
+        {
+            ipiface.SitePrefixLength = 0;
+        }
+        ipiface.NlMtu = mtu;
+        err = SetIpInterfaceEntry(&ipiface);
+    }
+
+    if (err != NO_ERROR)
+    {
+        msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=%u
 if_index=%d]",
+            family_name, strerror_win32(err, &gc), err, iface_index);
+    }
+    else
+    {
+        msg(M_INFO, "Successfully set %s mtu on interface %d",
 family_name, iface_index);
+    }
+}
+
+
   /*

   * Return a TAP name for netsh commands.
   */

src/openvpnserv/interactive.c +0 -0
index 623c3ff7..c24cb22b 100644
@@ -1198,6 +1198,29 @@ HandleEnableDHCPMessage(const 

enable_dhcp_message_t
*dhcp)
      return err;
  }

src/openvpnserv/interactive.c +23 -0
+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    ipiface.Family = mtu->family;
+    ipiface.InterfaceIndex = mtu->iface.index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err != NO_ERROR)
+    {
+        return err;
+    }
+    if (mtu->family == AF_INET)
+    {
+        ipiface.SitePrefixLength = 0;
+    }
+    ipiface.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&ipiface);
+    return err;
+}
+

  static VOID
  HandleMessage(HANDLE pipe, DWORD bytes, DWORD count, LPHANDLE events, undo_lists_t *lists)
  {

src/openvpnserv/interactive.c +0 -0
@@ -1210,6 +1233,7 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD 
 count,

LPHANDLE events, undo_lists
          block_dns_message_t block_dns;
          dns_cfg_message_t dns;
          enable_dhcp_message_t dhcp;
+        set_mtu_message_t mtu;
      } msg;
      ack_message_t ack = {
          .header = {

src/openvpnserv/interactive.c +0 -0
@@ -1277,6 +1301,13 @@ HandleMessage(HANDLE pipe, DWORD bytes, DWORD

count, LPHANDLE events, undo_lists
              }
              break;

Quoted 13 lines

+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu); +            }
+            break;
+
          default:
              ack.error_number = ERROR_MESSAGE_TYPE; MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Unknown message type %d"), msg.header.type);

Quoted 2 lines

Selva

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#20 lore raw

Re: [Openvpn-devel] [PATCH] Set the correct mtu on windows based systems

Hi,

Quoted 1 line · Christopher Schenk

any other thoughts on this patch? Any chance to getting it applied?

It got an ACK, so it's in my work queue :-) - there is a given chance that I might find something on my "double check before merging", but usually when Selva says something is good it is so.

Lack of time, mostly... sorry for that.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#21 lore raw

Re: [Openvpn-devel] [PATCH] Set the correct mtu on windows based systems

Hi,

any updates on this? I would really love to see this upstream.

Regards,
Christopher

Quoted 13 lines · Gert Doering

Hi,

Quoted 1 line · Christopher Schenk

any other thoughts on this patch? Any chance to getting it applied?

It got an ACK, so it's in my work queue :-) - there is a given chance that I might find something on my "double check before merging", but usually when Selva says something is good it is so.

Lack of time, mostly... sorry for that.

gert

#22 lore raw

Re: [Openvpn-devel] [PATCH] Set the correct mtu on windows based systems

In reply to Christopher Schenk

Hi,

Quoted 6 lines · Christopher Schenk
---
 include/openvpn-msg.h         |  8 ++++
 src/openvpn/tun.c             | 89 +++++++++++++++++++++++++++++++++++
 src/openvpnserv/interactive.c | 31 ++++++++++++
 3 files changed, 128 insertions(+)

So, we have this nice patch, and I got a very pointed reminder today that I messed merging it up.

The patch has an ACK, so everything is good, but Lev and Simon whacked tun.c a lot in between, and someone else added message types, so it does not apply anymore.

Applying: Set the correct mtu on windows based systems
error: patch failed: include/openvpn-msg.h:39
error: include/openvpn-msg.h: patch does not apply
error: patch failed: src/openvpn/tun.c:984
error: src/openvpn/tun.c: patch does not apply
error: patch failed: src/openvpnserv/interactive.c:1198
error: src/openvpnserv/interactive.c: patch does not apply Patch failed at 0001 Set the correct mtu on windows based systems

Would you accept an apology for me dragging my feet on this for so long, and send a rebased v3 to current master?

(And if that does not get traction, feel free to send Max my way on a weekly basis)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#23 lore raw

PATCH 1/1 Set the correct mtu on windows based systems

---
 include/openvpn-msg.h         | 10 +++-
 src/openvpn/tun.c             | 89 +++++++++++++++++++++++++++++++++++
 src/openvpnserv/interactive.c | 31 ++++++++++++
 3 files changed, 129 insertions(+), 1 deletion(-)
include/openvpn-msg.h +9 -1
index 3ed62069..a4789e34 100644
@@ -39,7 +39,8 @@ typedef enum {
     msg_del_block_dns,
     msg_register_dns,
     msg_enable_dhcp,
-    msg_register_ring_buffers
+    msg_register_ring_buffers,
+    msg_set_mtu
 } message_type_t;
 
 typedef struct {
@@ -127,4 +128,11 @@ typedef struct {
     HANDLE receive_tail_moved;
 } register_ring_buffers_message_t;
 
+typedef struct {
+    message_header_t header;
+    interface_t iface;
+    short family;
+    int mtu;
+} set_mtu_message_t;
+
 #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/tun.c +89 -0

125 lines not on this page · raw message

src/openvpnserv/interactive.c +31 -0
index 04d64b97..207cc4ae 100644
@@ -1286,6 +1286,29 @@ HandleRegisterRingBuffers(const register_ring_buffers_message_t *rrb, HANDLE ovp
     return err;
 }
 
+static DWORD
+HandleMTUMessage(const set_mtu_message_t *mtu)
+{
+    DWORD err = 0;
+    MIB_IPINTERFACE_ROW ipiface;
+    InitializeIpInterfaceEntry(&ipiface);
+    ipiface.Family = mtu->family;
+    ipiface.InterfaceIndex = mtu->iface.index;
+    err = GetIpInterfaceEntry(&ipiface);
+    if (err != NO_ERROR)
+    {
+        return err;
+    }
+    if (mtu->family == AF_INET)
+    {
+        ipiface.SitePrefixLength = 0;
+    }
+    ipiface.NlMtu = mtu->mtu;
+
+    err = SetIpInterfaceEntry(&ipiface);
+    return err;
+}
+
 static VOID
 HandleMessage(HANDLE pipe, HANDLE ovpn_proc, ring_buffer_handles_t *ring_buffer_handles,
               DWORD bytes, DWORD count, LPHANDLE events, undo_lists_t *lists)
@@ -1300,6 +1323,7 @@ HandleMessage(HANDLE pipe, HANDLE ovpn_proc, ring_buffer_handles_t *ring_buffer_
         dns_cfg_message_t dns;
         enable_dhcp_message_t dhcp;
         register_ring_buffers_message_t rrb;
+        set_mtu_message_t mtu;
     } msg;
     ack_message_t ack = {
         .header = {
@@ -1374,6 +1398,13 @@ HandleMessage(HANDLE pipe, HANDLE ovpn_proc, ring_buffer_handles_t *ring_buffer_
             }
             break;
 
+        case msg_set_mtu:
+            if (msg.header.size == sizeof(msg.mtu))
+            {
+                ack.error_number = HandleMTUMessage(&msg.mtu);
+            }
+            break;
+
         default:
             ack.error_number = ERROR_MESSAGE_TYPE;
             MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Unknown message type %d"), msg.header.type);
Signature · 1 line
2.21.0.windows.1
Acked-by on v1 1/1
#24 lore raw

[Openvpn-devel] [PATCH applied] Re: Set the correct mtu on windows based systems

Selva has ACKed the version sent in April 2019, and it should have been merged then and there - we (I) let it rot, tun.c got changed quite a bit for wintun support, now we have a new patch. Thanks! (And thanks for the repeated reminders, this is necessary at times)

I have compared both patches. They differ in context, of course (*), but the actual changes introduced by this patch are the same - so, I think I can take the ACK from Selva for the new patch as well.

(*) one of the context differences is the iservice message types - we have grown "msg_register_ring_buffers" in the meantime. So to get this patch into 2.4 would be somewhat complicated, to ensure no iservice breakage. But since 2.5 is really close now, I find that acceptable.

I have also reviewed this patch (so, two ACKs, one from Selva and one from me) - code looks good.

The "SitePrefixLength = 0" call confused me a bit, but this is correct according to (long URL):
https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-setipinterfaceentry

I have tested this on Win10:

- config with no "tun-mtu" and iservice -> interface MTU = 1500, good
- config with "tun-mtu 1330" and iservice -> interface MTU = 1330, good
- config with no "tun-mtu" and priv. gui -> interface MTU = 1500, good
- config with "tun-mtu 1330" and priv. gui -> interface MTU = 1330, good

because I sometimes test things before I question myself whether this is a useful thing to test:
- config with "tun-mtu 1200" and priv. gui ->
*succeeds* for IPv4
*fails* for IPv6
"TUN: setting IPv6 mtu using service failed: Falscher Parameter.
[status=87 if_index=8]

(which is Windows telling me that "the IETF says that the mininum MTU
for IPv6 is 1280, so go away and complain to them!" - technically correct, though slightly confusing)

Just for reference: "ipconfig /all" does not show the MTU, you need to call "netsh interface ipv4/ipv6 show subinterfaces".

Remarks:

- if using the iservice, openvpn will log "IPv<x> MTU set to 1330 on interface 8 using service" if using the gui in privileged mode, it will log "Successfully set IPv<x> mtu on interface 8"

--> I think it would be good to use the same message here, and include the numeric value in both cases, like

"IPv<x> MTU set to 1330 on interface 8 using SetIpInterfaceEntry()"

or so. Can you send a followup patch? It will be expedited!

- shall we do "if MTU < 1280, log a notice and do not attempt to set

    IPv6 MTU"?  Or "just log the notice, in case windows will accept
    it nonetheless"?

    if (mtu<1280)
    {
      msg(M_INFO, "NOTE: IPv6 interface MTU < 1280 conflicts with IETF standards and might not work");
    }

Your patch has been applied to the master branch.

Thanks for your patience.

commit 0213f80ed72ad8b6bb43db3bbd72a66ec2e12fcd

Author: Christopher Schenk
Date:   Tue Apr 21 17:46:12 2020 +0200
     Set the correct mtu on windows based systems

     Signed-off-by: Christopher Schenk <[email protected]...>
     Acked-by: Selva Nair <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19803.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#25 lore raw

PATCH 1/2 Unified success messages for setting mtu

---
 src/openvpn/tun.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/tun.c +2 -2
index 18cdf38d..3ef79b2f 100644
@@ -251,7 +251,7 @@ do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
     }
     else
     {
-        msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu, mtu_msg.iface.index);
+        msg(M_INFO, "%s MTU set to %d on interface %d using SetIpInterfaceEntry()", family_name, mtu, mtu_msg.iface.index);
         ret = true;
     }
 
@@ -5516,7 +5516,7 @@ windows_set_mtu(const int iface_index, const short family,
     }
     else
     {
-        msg(M_INFO, "Successfully set %s mtu on interface %d", family_name, iface_index);
+        msg(M_INFO, "%s MTU set to %d on interface %d using SetIpInterfaceEntry()", family_name, mtu, iface_index);
     }
 }
 
Signature · 1 line
2.21.0.windows.1
#26 lore raw

PATCH 2/2 Log a note if someone wants to set a MTU below 1280 on IPv6

---
 src/openvpn/tun.c | 9 +++++++++
 1 file changed, 9 insertions(+)
src/openvpn/tun.c +9 -0
index 3ef79b2f..67d7664e 100644
@@ -238,6 +238,10 @@ do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
         .family = family
     };
     strncpynt(mtu_msg.iface.name, tt->actual_name, sizeof(mtu_msg.iface.name));
+    if (family == AF_INET6 && mtu < 1280)
+    {
+        msg(M_INFO, "NOTE: IPv6 interface MTU < 1280 conflicts with IETF standards and might not work");
+    }
 
     if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack, "Set_mtu"))
     {
@@ -5498,6 +5502,11 @@ windows_set_mtu(const int iface_index, const short family,
     const char *family_name = (family == AF_INET6) ? "IPv6" : "IPv4";
     ipiface.Family = family;
     ipiface.InterfaceIndex = iface_index;
+    if (family == AF_INET6 && mtu < 1280)
+    {
+        msg(M_INFO, "NOTE: IPv6 interface MTU < 1280 conflicts with IETF standards and might not work");
+    }
+
     err = GetIpInterfaceEntry(&ipiface);
     if (err == NO_ERROR)
     {
Signature · 1 line
2.21.0.windows.1
Acked-by on v1 2/2
#27 lore raw

[Openvpn-devel] [PATCH applied] Re: Log a note if someone wants to set a MTU below 1280 on IPv6

Stared-at-code, looks good. Test build on ubuntu/mingw, passes.

I have not actually tested that it prints the warnings when expected, but the code looks good and the change is simple enough :-)

Your patch has been applied to the master branch.

commit 93439307e597007e0d60b904c0f3d9d85de26b49

Author: Christopher Schenk
Date:   Mon Jun 29 21:09:30 2020 +0200
     Log a note if someone wants to set a MTU below 1280 on IPv6

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

--
kind regards,

Gert Doering

#28 lore raw

Re: [Openvpn-devel] [PATCH 1/2] Unified success messages for setting mtu

In reply to Christopher Schenk

Hi,

src/openvpn/tun.c do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu) · line 256

Quoted 12 lines · Christopher Schenk
src/openvpn/tun.c +1 -1
index 18cdf38d..3ef79b2f 100644
@@ -251,7 +251,7 @@ do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
     }
     else
     {
-        msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu, mtu_msg.iface.index);
+        msg(M_INFO, "%s MTU set to %d on interface %d using SetIpInterfaceEntry()", family_name, mtu, mtu_msg.iface.index);
         ret = true;
     }

While I do like unified messages, this is not exactly what I had in mind
- the "using service" bit should stay, if using the service :-) - too much unification.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#29 lore raw

PATCH 1/1 Unified success messages for setting mtu

that makes sense. I updated the patch.

Christopher

---
 src/openvpn/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/tun.c +1 -1
index 5567c445..2a2df27f 100644
@@ -5525,7 +5525,7 @@ windows_set_mtu(const int iface_index, const short family,
     }
     else
     {
-        msg(M_INFO, "Successfully set %s mtu on interface %d", family_name, iface_index);
+        msg(M_INFO, "%s MTU set to %d on interface %d using SetIpInterfaceEntry()", family_name, mtu, iface_index);
     }
 }
 
Signature · 1 line
2.21.0.windows.1
Acked-by on v1 1/1
#30 lore raw

[Openvpn-devel] [PATCH applied] Re: Unified success messages for setting mtu

Thanks :-) - given that this is somewhat trivial, I have not actually run a binary to look at the messages. I have counted arguments and done a test build to see if new warnings show up (no).

I *do* see an old warning...

tun.c: In function 'windows_set_mtu':
tun.c:5523:21: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'DWORD {aka long unsigned int}' [-Wformat=]
msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=%u if_index=%d]",

mmmh...

Your patch has been applied to the master branch.

commit efe01d52e36c597484b6fa24c4820b6345d08ae6

Author: Christopher Schenk
Date:   Tue Jun 30 11:54:44 2020 +0200
     Unified success messages for setting mtu

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

--
kind regards,

Gert Doering

#31 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Unified success messages for setting mtu

Hi,

Quoted 7 lines · Gert Doering

Thanks :-) - given that this is somewhat trivial, I have not actually run a binary to look at the messages. I have counted arguments and done a test build to see if new warnings show up (no).

Quoted 5 lines

I *do* see an old warning...

tun.c: In function 'windows_set_mtu':
tun.c:5523:21: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'DWORD {aka long unsigned int}' [-Wformat=]
msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=%u if_index=%d]",

It's ok if this is only for Windows code (I assume it is because of the name of the function) because x86 and ARM have the same endian-ness and are the only Windows platforms (that I know of). However, it would still be better to use "%lu" to avoid the warning and to future-proof it for any _new_ Windows platform that's different. (Although I admit Microsoft is unlikely to do that.)

Best regards,

Jon