Skip to contentSkip to conversation

Visual Studio: upgrade project files to VS2019

PATCH Superseded Lev Stipakov 3 participants 17 messages Sep 17, 2019 – Sep 29, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 Visual Studio: upgrade project files to VS2019

From: Lev Stipakov <[email protected]...>

This set of patches adds support of wintun kernel driver (https://www.wintun.net) to OpenVPN.

While wintun is in beta, it performs significantly faster comparison to tap-windows6.

Here are some performance numbers (download bandwidth):

Server - community openvpn2

mingw, tap-windows6   - 340Mbit/s
mingw, wintun         - 675Mbit/s
VS2019, tap-windows6  - 425Mbit/s
VS2019, wintun        - 750Mbit/s

Server - propietary openvpn3 with kernel acceleration (in development)

mingw, tap-windows6   - 360Mbit/s
mingw, wintun         - 840Mbit/s
VS2019, tap-windows6  - 430Mbit/s
VS2019, wintun        - 1,14Gbit/s

And for the reference
openvpn3 test client, VS2019, wintun - 1,71Gbit/s

Some observations from those numbers:

* wintun performs more than twice faster comparison to tap-windows6 agains community server (750Mbit/s vs 340Mbit/s)
* Visual Studio provides noticeable performance boost (up to 25%)
* we should build Windows clients with VS, not with mingw
* There's room for improvement in openvpn2, since under best conditions openvpn3 performs 50% faster

Steps to try out new client:

* Install Wintun driver
* since driver is not signed, you need to enable test mode to install unsigned driver
* run in administrative command prompt:
bcdedit /set testsigning on
* restart
* download and unpack https://staging.openvpn.net/openvpn2/wintun-0.6-unsigned.zip to C:\Temp\wintun (for example)
* if you have OpenVPN GUI client installed, run under administrative command prompt:
c:\Program Files\TAP-Windows\bin>tapinstall.exe install c:\Temp\wintun\wintun.inf wintun
* alternatively you can install driver via windows device manager -> action ->add legacy hardware -> install manually -> point to wintun.inf in C:\Temp\wintun

* Install openvpn client with wintun support
* download and unpack https://staging.openvpn.net/openvpn2/openvpn2-wintun-support.zip to C:\Temp\openvpn (for example)
* if you use OpenVPN GUI, copy all files from C:\Temp\openvpn to C:\Program Files\OpenVPN\bin. Don't forget to
stop OpenVPN Interactive Service before copying and start it back afterwards (net stop/start OpenVPNServiceInteractive in admin command prompt)

* Connect to VPN from command line
* run from administrative command prompt
c:\Temp\openvpn>openvpn.exe --config client.ovpn --windows-driver wintun
* you should see something around these lines in log
Tue Sep 17 15:09:58 2019 us=296000 interactive service msg_channel=0
Tue Sep 17 15:09:58 2019 us=312000 open_tun
Tue Sep 17 15:09:58 2019 us=312000 Wintun device [Lähiverkkoyhteys] opened: \\?\ROOT#NET#0004#{cac88484-7515-4c03-82e6-71a87abac361} Tue Sep 17 15:09:58 2019 us=312000 do_ifconfig, ipv4=1, ipv6=0
Tue Sep 17 15:09:59 2019 us=312000 NETSH: C:\Windows\system32\netsh.exe interface ip set address Lähiverkkoyhteys static 10.8.0.2 255.255.255.0 Tue Sep 17 15:10:00 2019 us=406000 NETSH: C:\Windows\system32\netsh.exe interface ip delete dns Lähiverkkoyhteys all Tue Sep 17 15:10:01 2019 us=484000 NETSH: C:\Windows\system32\netsh.exe interface ip set dns Lähiverkkoyhteys static 10.8.0.1 Tue Sep 17 15:10:14 2019 us=578000 NETSH: C:\Windows\system32\netsh.exe interface ip delete wins Lähiverkkoyhteys all Tue Sep 17 15:10:19 2019 us=296000 TEST ROUTES: 0/0 succeeded len=0 ret=1 a=0 u/d=up
Tue Sep 17 15:10:19 2019 us=296000 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this Tue Sep 17 15:10:19 2019 us=296000 Initialization Sequence Completed
* congratulations!

* Connect to VPN from OpenVPN GUI
* right click on tray icon -> profile name -> Edit Config
* add "windows-driver wintun" to profile, save and close
* right click on tray icon -> profile name -> Connect
* you should see something around these lines in log
Tue Sep 17 15:15:46 2019 interactive service msg_channel=676
Tue Sep 17 15:15:46 2019 open_tun
Tue Sep 17 15:15:46 2019 Wintun device [Lähiverkkoyhteys] opened: \\?\ROOT#NET#0004#{cac88484-7515-4c03-82e6-71a87abac361} Tue Sep 17 15:15:46 2019 Ring buffers registered via service
Tue Sep 17 15:15:46 2019 do_ifconfig, ipv4=1, ipv6=0
Tue Sep 17 15:15:46 2019 MANAGEMENT: >STATE:1568722546,ASSIGN_IP,,10.8.0.2,,,,
Tue Sep 17 15:15:46 2019 Setting IPv4 dns servers on 'Lähiverkkoyhteys' (if_index = 3) using service
Tue Sep 17 15:15:46 2019 IPv4 dns servers set using service
Tue Sep 17 15:15:51 2019 TEST ROUTES: 0/0 succeeded len=0 ret=1 a=0 u/d=up
Tue Sep 17 15:15:51 2019 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this Tue Sep 17 15:15:51 2019 Initialization Sequence Completed
* congratulations!

---
 src/compat/compat.vcxproj             | 12 ++++++------
 src/openvpn/openvpn.vcxproj           | 12 ++++++------
 src/openvpnmsica/openvpnmsica.vcxproj | 14 +++++++-------
 src/openvpnserv/openvpnserv.vcxproj   | 12 ++++++------
 src/tapctl/tapctl.vcxproj             | 14 +++++++-------
 5 files changed, 32 insertions(+), 32 deletions(-)
src/compat/compat.vcxproj +6 -6
index 111dacd..e388008 100644
@@ -22,30 +22,30 @@
     <ProjectGuid>{4B2E2719-E661-45D7-9203-F6F456B22F19}</ProjectGuid>
     <RootNamespace>compat</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <CharacterSet>MultiByte</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -115,4 +115,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
src/openvpn/openvpn.vcxproj +6 -6
index 92d7e32..3422b64 100644
@@ -22,30 +22,30 @@
     <ProjectGuid>{29DF226E-4D4E-440F-ADAF-5829CFD4CA94}</ProjectGuid>
     <RootNamespace>openvpn</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -299,4 +299,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
src/openvpnmsica/openvpnmsica.vcxproj +7 -7
index 5f1d699..afa4fae 100644
@@ -31,32 +31,32 @@
     <ProjectGuid>{D41AA9D6-B818-476E-992E-0E16EB86BEE2}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
     <RootNamespace>openvpnmsica</RootNamespace>
-    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
@@ -64,14 +64,14 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
src/openvpnserv/openvpnserv.vcxproj +6 -6
index 7407757..7061b7b 100644
@@ -22,30 +22,30 @@
     <ProjectGuid>{9C91EE0B-817D-420A-A1E6-15A5A9D98BAD}</ProjectGuid>
     <RootNamespace>openvpnserv</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -139,4 +139,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
src/tapctl/tapctl.vcxproj +7 -7
index 5c1983b..1d593fc 100644
@@ -31,32 +31,32 @@
     <ProjectGuid>{A06436E7-D576-490D-8BA0-0751D920334A}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
     <RootNamespace>tapctl</RootNamespace>
-    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
@@ -64,14 +64,14 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/7 wintun: add --windows-driver config option

From: Lev Stipakov <[email protected]...>

This allows to specify which tun driver openvpn should use, tap-windows6 (default) or wintun.

Note than wintun support will be added in follow-up patches.

---
 src/openvpn/init.c    |  7 +++++++
 src/openvpn/options.c | 37 +++++++++++++++++++++++++++++++++++++
 src/openvpn/options.h |  1 +
 src/openvpn/tun.h     |  1 +
 4 files changed, 46 insertions(+)
src/openvpn/init.c +7 -0
index b5a034d..edd11c2 100644
@@ -1727,6 +1727,10 @@ do_init_tun(struct context *c)
                             c->c2.es,
                             &c->net_ctx);
 
+#ifdef _WIN32
+    c->c1.tuntap->wintun = c->options.wintun;
+#endif
+
     init_tun_post(c->c1.tuntap,
                   &c->c2.frame,
                   &c->options.tuntap_options);
@@ -1769,6 +1773,9 @@ do_open_tun(struct context *c)
     /* store (hide) interactive service handle in tuntap_options */
     c->c1.tuntap->options.msg_channel = c->options.msg_channel;
     msg(D_ROUTE, "interactive service msg_channel=%u", (unsigned int) c->options.msg_channel);
+
+    c->c1.tuntap->wintun = c->options.wintun;
+
 #endif
 
     /* allocate route list structure */
src/openvpn/options.c +37 -0
index 2d3865a..9f8e92b 100644
@@ -744,6 +744,9 @@ static const char usage_message[] =
     "                       optional parameter controls the initial state of ex.\n"
     "--show-net-up   : Show " PACKAGE_NAME "'s view of routing table and net adapter list\n"
     "                  after TAP adapter is up and routes have been added.\n"
+    "--windows-driver   : Which tun driver to use?\n"
+    "                     tap-windows6 (default)\n"
+    "                     wintun\n"
 #ifdef _WIN32
     "--block-outside-dns   : Block DNS on other network adapters to prevent DNS leaks\n"
 #endif
@@ -848,6 +851,7 @@ init_options(struct options *o, const bool init_gc)
     o->tuntap_options.dhcp_masq_offset = 0;     /* use network address as internal DHCP server address */
     o->route_method = ROUTE_METHOD_ADAPTIVE;
     o->block_outside_dns = false;
+    o->wintun = false;
 #endif
 #if P2MP_SERVER
     o->real_hash_size = 256;
@@ -2935,6 +2939,12 @@ options_postprocess_mutate_invariant(struct options *options)
         options->ifconfig_noexec = false;
     }
 
+    /* for wintun kernel doesn't send DHCP requests, so use ipapi to set IP address and netmask */
+    if (options->wintun)
+    {
+        options->tuntap_options.ip_win32_type = IPW32_SET_IPAPI;
+    }
+
     remap_redirect_gateway_flags(options);
 #endif
 
@@ -3980,6 +3990,26 @@ foreign_option(struct options *o, char *argv[], int len, struct env_set *es)
     }
 }
 
+#ifdef _WIN32
+bool
+parse_windows_driver(const char *str, const int msglevel)
+{
+    if (streq(str, "tap-windows6"))
+    {
+        return false;
+    }
+    else if (streq(str, "wintun"))
+    {
+        return true;
+    }
+    else
+    {
+        msg(msglevel, "--windows-driver must be tap-windows6 or wintun");
+        return false;
+    }
+}
+#endif
+
 /*
  * parse/print topology coding
  */
@@ -5222,6 +5252,13 @@ add_option(struct options *options,
         VERIFY_PERMISSION(OPT_P_GENERAL);
         options->dev_type = p[1];
     }
+#ifdef _WIN32
+    else if (streq(p[0], "windows-driver") && p[1] && !p[2])
+    {
+        VERIFY_PERMISSION(OPT_P_GENERAL);
+        options->wintun = parse_windows_driver(p[1], M_FATAL);
+    }
+#endif
     else if (streq(p[0], "dev-node") && p[1] && !p[2])
     {
         VERIFY_PERMISSION(OPT_P_GENERAL);
src/openvpn/options.h +1 -0
index 63f0f4c..37dee71 100644
@@ -621,6 +621,7 @@ struct options
     bool show_net_up;
     int route_method;
     bool block_outside_dns;
+    bool wintun;
 #endif
 
     bool use_peer_id;
src/openvpn/tun.h +1 -0
index 69831c4..a61aa22 100644
@@ -175,6 +175,7 @@ struct tuntap
      * ~0 if undefined */
     DWORD adapter_index;
 
+    bool wintun; /* true if wintun is used instead of tap-windows6 */
     int standby_iter;
 #else  /* ifdef _WIN32 */
     int fd; /* file descriptor for TUN/TAP dev */
Signature · 1 line
2.7.4
#2 lore raw

PATCH 3/7 wintun: implement opening wintun device

In reply to Lev Stipakov

From: Lev Stipakov <[email protected]...>

To open wintun device, we cannot use "\\.\Global\Wintun<luid>" path as before. To get device path which we supply to CreateFile, we have to use SetupAPI to:

- enumerate network adapters with "wintun" as component id
- for each adapter save its guid
- open device information set
- for each item in set
- open corresponding registry key to get net_cfg_instance_id
- get symbolic link name of device interface by instance id
- path will be symbolic link name of device instance matched with adapter's guid

See https://github.com/OpenVPN/openvpn3/blob/master/openvpn/tun/win/tunutil.hpp and
https://github.com/WireGuard/wireguard-go/blob/master/tun/wintun/wintun_windows.go for implementation examples.

---
 src/openvpn/Makefile.am     |   2 +-
 src/openvpn/openvpn.vcxproj |   4 +-
 src/openvpn/tun.c           | 244 +++++++++++++++++++++++++++++++++++++-------
 src/openvpn/tun.h           |  14 +++
 4 files changed, 222 insertions(+), 42 deletions(-)
src/openvpn/Makefile.am +1 -1
index 30caa01..7d4b429 100644
@@ -137,5 +137,5 @@ openvpn_LDADD = \
 	$(OPTIONAL_DL_LIBS)
 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc block_dns.c block_dns.h
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi
 endif
src/openvpn/openvpn.vcxproj +2 -2
index 3422b64..88be4c2 100644
@@ -91,7 +91,7 @@
     </ClCompile>
     <ResourceCompile />
     <Link>
-      <AdditionalDependencies>legacy_stdio_definitions.lib;Ncrypt.lib;libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;Fwpuclnt.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>legacy_stdio_definitions.lib;Ncrypt.lib;libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;Fwpuclnt.lib;Rpcrt4.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <SubSystem>Console</SubSystem>
     </Link>
@@ -117,7 +117,7 @@
     </ClCompile>
     <ResourceCompile />
     <Link>
-      <AdditionalDependencies>legacy_stdio_definitions.lib;Ncrypt.lib;libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;Fwpuclnt.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>legacy_stdio_definitions.lib;Ncrypt.lib;libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;Fwpuclnt.lib;Rpcrt4.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <SubSystem>Console</SubSystem>
     </Link>
src/openvpn/tun.c +205 -39

393 lines not on this page · raw message

src/openvpn/tun.h +14 -0
index a61aa22..18eb1b0 100644
@@ -27,6 +27,8 @@
 #ifdef _WIN32
 #include <winioctl.h>
 #include <tap-windows.h>
+#include <setupapi.h>
+#include <cfgmgr32.h>
 #endif
 
 #include "buffer.h"
@@ -38,6 +40,10 @@
 #include "misc.h"
 #include "networking.h"
 
+#ifdef _WIN32
+#define WINTUN_COMPONENT_ID "wintun"
+#endif
+
 #if defined(_WIN32) || defined(TARGET_ANDROID)
 
 #define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
@@ -342,6 +348,7 @@ route_order(void)
 struct tap_reg
 {
     const char *guid;
+    bool wintun;
     struct tap_reg *next;
 };
 
@@ -352,6 +359,13 @@ struct panel_reg
     struct panel_reg *next;
 };
 
+struct device_instance_id_interface
+{
+    const char *net_cfg_instance_id;
+    const char *device_interface_list;
+    struct device_instance_id_interface *next;
+};
+
 int ascii2ipset(const char *name);
 
 const char *ipset2ascii(int index);
Signature · 1 line
2.7.4
#3 lore raw

PATCH 4/7 wintun: ring buffers based I/O

In reply to Lev Stipakov

From: Lev Stipakov <[email protected]...>

Implemented according to Wintun documentation and reference client code.

Wintun uses ring buffers to communicate between kernel driver and user process. Client allocates send and receive ring buffers, creates events and passes it to kernel driver under LocalSystem privileges.

When data is available for read, wintun modifies "tail" pointer of send ring and signals via event. User process reads data from "head" to "tail" and updates "head" pointer.

When user process is ready to write, it writes to receive ring, updates "tail" pointer and signals to kernel via event.

In openvpn code we add send ring's event to event loop. Before performing io wait, we compare "head" and "tail" pointers of send ring and if they're different, we skip io wait and perform read.

This also adds ring buffers support to tcp and udp server code.

---
 src/openvpn/forward.c |  44 +++++++++++++++---
 src/openvpn/forward.h |  47 +++++++++++++++++++-
 src/openvpn/mtcp.c    |  28 +++++++++++-
 src/openvpn/mudp.c    |  14 ++++++
 src/openvpn/options.c |   4 +-
 src/openvpn/syshead.h |   1 +
 src/openvpn/tun.c     |  45 +++++++++++++++++++
 src/openvpn/tun.h     | 121 +++++++++++++++++++++++++++++++++++++++++++++++++-
 src/openvpn/win32.c   | 120 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/win32.h   |  47 ++++++++++++++++++++
 10 files changed, 460 insertions(+), 11 deletions(-)
src/openvpn/forward.c +39 -5
index c2dcb53..7e4ccd3 100644
@@ -1256,12 +1256,32 @@ read_incoming_tun(struct context *c)
     perf_push(PERF_READ_IN_TUN);
 
     c->c2.buf = c->c2.buffers->read_tun_buf;
+
+#ifdef _WIN32
+    if (c->c1.tuntap->wintun)
+    {
+        read_wintun(c->c1.tuntap, &c->c2.buf);
+        if (c->c2.buf.len == -1)
+        {
+            register_signal(c, SIGHUP, "tun-abort");
+            c->persist.restart_sleep_seconds = 1;
+            msg(M_INFO, "Wintun read error, restarting");
+            perf_pop();
+            return;
+        }
+    }
+    else
+    {
+#endif
 #ifdef TUN_PASS_BUFFER
-    read_tun_buffered(c->c1.tuntap, &c->c2.buf);
+        read_tun_buffered(c->c1.tuntap, &c->c2.buf);
 #else
-    ASSERT(buf_init(&c->c2.buf, FRAME_HEADROOM(&c->c2.frame)));
-    ASSERT(buf_safe(&c->c2.buf, MAX_RW_SIZE_TUN(&c->c2.frame)));
-    c->c2.buf.len = read_tun(c->c1.tuntap, BPTR(&c->c2.buf), MAX_RW_SIZE_TUN(&c->c2.frame));
+        ASSERT(buf_init(&c->c2.buf, FRAME_HEADROOM(&c->c2.frame)));
+        ASSERT(buf_safe(&c->c2.buf, MAX_RW_SIZE_TUN(&c->c2.frame)));
+        c->c2.buf.len = read_tun(c->c1.tuntap, BPTR(&c->c2.buf), MAX_RW_SIZE_TUN(&c->c2.frame));
+#endif
+#ifdef _WIN32
+    }
 #endif
 
 #ifdef PACKET_TRUNCATION_CHECK
@@ -2103,7 +2123,21 @@ io_wait_dowork(struct context *c, const unsigned int flags)
      * Configure event wait based on socket, tuntap flags.
      */
     socket_set(c->c2.link_socket, c->c2.event_set, socket, (void *)&socket_shift, NULL);
-    tun_set(c->c1.tuntap, c->c2.event_set, tuntap, (void *)&tun_shift, NULL);
+
+#ifdef _WIN32
+    if (c->c1.tuntap && c->c1.tuntap->wintun)
+    {
+        /* add ring buffer event */
+        struct rw_handle rw = {.read = c->c1.tuntap->send_tail_moved };
+        event_ctl(c->c2.event_set, &rw, EVENT_READ, (void *)&tun_shift);
+    }
+    else
+    {
+#endif
+        tun_set(c->c1.tuntap, c->c2.event_set, tuntap, (void *)&tun_shift, NULL);
+#ifdef _WIN32
+    }
+#endif
 
 #ifdef ENABLE_MANAGEMENT
     if (management)
src/openvpn/forward.h +45 -2

59 lines not on this page · raw message

src/openvpn/mtcp.c +27 -1
index abe2059..9ac51c3 100644
@@ -270,7 +270,33 @@ multi_tcp_wait(const struct context *c,
 {
     int status;
     socket_set_listen_persistent(c->c2.link_socket, mtcp->es, MTCP_SOCKET);
-    tun_set(c->c1.tuntap, mtcp->es, EVENT_READ, MTCP_TUN, &mtcp->tun_rwflags);
+
+#ifdef _WIN32
+    if (c->c1.tuntap && c->c1.tuntap->wintun)
+    {
+        if (c->c1.tuntap->send_ring->head != c->c1.tuntap->send_ring->tail)
+        {
+            /* there is data in wintun ring buffer, read it immediately */
+            mtcp->esr[0].arg = MTCP_TUN;
+            mtcp->esr[0].rwflags = EVENT_READ;
+            mtcp->n_esr = 1;
+            return 1;
+        }
+        else
+        {
+            /* add ring buffer event */
+            struct rw_handle rw = { .read = c->c1.tuntap->send_tail_moved };
+            event_ctl(mtcp->es, &rw, EVENT_READ, MTCP_TUN);
+        }
+    }
+    else
+    {
+#endif
+        tun_set(c->c1.tuntap, mtcp->es, EVENT_READ, MTCP_TUN, &mtcp->tun_rwflags);
+#ifdef _WIN32
+    }
+#endif
+
 #ifdef ENABLE_MANAGEMENT
     if (management)
     {
src/openvpn/mudp.c +14 -0
index b7f061a..7715063 100644
@@ -279,6 +279,20 @@ p2mp_iow_flags(const struct multi_context *m)
         flags |= IOW_READ;
     }
 
+#ifdef _WIN32
+    {
+        struct tuntap* tt = m->top.c1.tuntap;
+        if (tt && tt->wintun)
+        {
+            if (tt->send_ring->head == tt->send_ring->tail)
+            {
+                /* nothing to read from tun -> remove tun read flag set by IOW_READ */
+                flags &= ~IOW_READ_TUN;
+            }
+        }
+    }
+#endif
+
     return flags;
 }
 
src/openvpn/options.c +2 -2
index 9f8e92b..af48e7d 100644
@@ -2939,10 +2939,10 @@ options_postprocess_mutate_invariant(struct options *options)
         options->ifconfig_noexec = false;
     }
 
-    /* for wintun kernel doesn't send DHCP requests, so use ipapi to set IP address and netmask */
+    /* for wintun kernel doesn't send DHCP requests, so use netsh to set IP address and netmask */
     if (options->wintun)
     {
-        options->tuntap_options.ip_win32_type = IPW32_SET_IPAPI;
+        options->tuntap_options.ip_win32_type = IPW32_SET_NETSH;
     }
 
     remap_redirect_gateway_flags(options);
src/openvpn/syshead.h +1 -0
index 899aa59..e9accb5 100644
@@ -39,6 +39,7 @@
 #ifdef _WIN32
 #include <windows.h>
 #include <winsock2.h>
+#include <tlhelp32.h>
 #define sleep(x) Sleep((x)*1000)
 #define random rand
 #define srandom srand
src/openvpn/tun.c +45 -0

63 lines not on this page · raw message

src/openvpn/tun.h +120 -1

136 lines not on this page · raw message

src/openvpn/win32.c +120 -0

124 lines not on this page · raw message

src/openvpn/win32.h +47 -0

58 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH 5/7 wintun: interactive service support

In reply to Lev Stipakov

From: Lev Stipakov <[email protected]...>

Wintun requires ring buffers registration to be
performed by privileged process. In order to use
openvpn with wintun by non-Administrator, we
need to use interactive service and shared memory
to register buffers.

Openvpn process creates memory mapping object and event for send and receive ring and passes handles to interactive service. There handles are duplicated and memory mapped object is mapped into the address space of service process. Then address of mapped view and event handle is passed to wintun kernel driver.

After interactive service preformed registration, openvpn process maps memory mapped object into own address space. Thus mapped views in openvpn and service process represent the same memory region.

---
 include/openvpn-msg.h                       |  10 ++
 src/openvpn/Makefile.am                     |   2 +-
 src/openvpn/openvpn.vcxproj                 |   2 +
 src/openvpn/openvpn.vcxproj.filters         |   6 ++
 src/openvpn/ring_buffer.c                   |  54 +++++++++++
 src/openvpn/ring_buffer.h                   |  79 ++++++++++++++++
 src/openvpn/tun.c                           |  89 +++++++++++++++---
 src/openvpn/tun.h                           |   3 +
 src/openvpn/win32.c                         |  25 -----
 src/openvpn/win32.h                         |  43 ---------
 src/openvpnserv/Makefile.am                 |   3 +-
 src/openvpnserv/interactive.c               | 141 ++++++++++++++++++++++++++--
 src/openvpnserv/openvpnserv.vcxproj         |   2 +
 src/openvpnserv/openvpnserv.vcxproj.filters |   6 ++
 14 files changed, 374 insertions(+), 91 deletions(-)
 create mode 100644 src/openvpn/ring_buffer.c
 create mode 100644 src/openvpn/ring_buffer.h
include/openvpn-msg.h +10 -0
index 66177a2..3ed6206 100644
@@ -39,6 +39,7 @@ typedef enum {
     msg_del_block_dns,
     msg_register_dns,
     msg_enable_dhcp,
+    msg_register_ring_buffers
 } message_type_t;
 
 typedef struct {
@@ -117,4 +118,13 @@ typedef struct {
     interface_t iface;
 } enable_dhcp_message_t;
 
+typedef struct {
+    message_header_t header;
+    HANDLE device;
+    HANDLE send_ring_handle;
+    HANDLE receive_ring_handle;
+    HANDLE send_tail_moved;
+    HANDLE receive_tail_moved;
+} register_ring_buffers_message_t;
+
 #endif /* ifndef OPENVPN_MSG_H_ */
src/openvpn/Makefile.am +1 -1
index 7d4b429..93b73a7 100644
@@ -136,6 +136,6 @@ openvpn_LDADD = \
 	$(OPTIONAL_SYSTEMD_LIBS) \
 	$(OPTIONAL_DL_LIBS)
 if WIN32
-openvpn_SOURCES += openvpn_win32_resources.rc block_dns.c block_dns.h
+openvpn_SOURCES += openvpn_win32_resources.rc block_dns.c block_dns.h ring_buffer.c ring_buffer.h
 openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi
 endif
src/openvpn/openvpn.vcxproj +2 -0
index 88be4c2..907febb 100644
@@ -180,6 +180,7 @@
     <ClCompile Include="ps.c" />
     <ClCompile Include="push.c" />
     <ClCompile Include="reliable.c" />
+    <ClCompile Include="ring_buffer.c" />
     <ClCompile Include="route.c" />
     <ClCompile Include="run_command.c" />
     <ClCompile Include="schedule.c" />
@@ -262,6 +263,7 @@
     <ClInclude Include="push.h" />
     <ClInclude Include="pushlist.h" />
     <ClInclude Include="reliable.h" />
+    <ClInclude Include="ring_buffer.h" />
     <ClInclude Include="route.h" />
     <ClInclude Include="run_command.h" />
     <ClInclude Include="schedule.h" />
src/openvpn/openvpn.vcxproj.filters +6 -0
index 7a9aa63..c1a31c2 100644
@@ -234,6 +234,9 @@
     <ClCompile Include="run_command.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="ring_buffer.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="base64.h">
@@ -488,6 +491,9 @@
     <ClInclude Include="run_command.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="ring_buffer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="openvpn_win32_resources.rc">
src/openvpn/ring_buffer.c new file +54 -0

55 lines not on this page · raw message

src/openvpn/ring_buffer.h new file +79 -0

79 lines not on this page · raw message

src/openvpn/tun.c +74 -15

120 lines not on this page · raw message

src/openvpn/tun.h +3 -0
index 5b15dc9..ca5ca5e 100644
@@ -39,6 +39,7 @@
 #include "proto.h"
 #include "misc.h"
 #include "networking.h"
+#include "ring_buffer.h"
 
 #ifdef _WIN32
 #define WINTUN_COMPONENT_ID "wintun"
@@ -184,6 +185,8 @@ struct tuntap
     bool wintun; /* true if wintun is used instead of tap-windows6 */
     int standby_iter;
 
+    HANDLE send_ring_handle;
+    HANDLE receive_ring_handle;
     struct tun_ring *send_ring;
     struct tun_ring *receive_ring;
     HANDLE send_tail_moved;
src/openvpn/win32.c +0 -25
index e9e0258..b2f2a19 100644
@@ -1588,29 +1588,4 @@ impersonate_as_system()
     return true;
 }
 
-bool
-register_ring_buffers(HANDLE device,
-                      struct tun_ring* send_ring,
-                      struct tun_ring* receive_ring,
-                      HANDLE send_tail_moved,
-                      HANDLE receive_tail_moved)
-{
-    struct tun_register_rings rr;
-    BOOL res;
-
-    ZeroMemory(&rr, sizeof(rr));
-
-    rr.send.ring = send_ring;
-    rr.send.ring_size = sizeof(send_ring->data);
-    rr.send.tail_moved = send_tail_moved;
-
-    rr.receive.ring = receive_ring;
-    rr.receive.ring_size = sizeof(receive_ring->data);
-    rr.receive.tail_moved = receive_tail_moved;
-
-    res = DeviceIoControl(device, TUN_IOCTL_REGISTER_RINGS, &rr, sizeof(rr), NULL, 0, NULL, NULL);
-
-    return res == TRUE;
-}
-
 #endif /* ifdef _WIN32 */
src/openvpn/win32.h +0 -43

50 lines not on this page · raw message

src/openvpnserv/Makefile.am +2 -1
index bc65070..f8d3319 100644
@@ -36,4 +36,5 @@ openvpnserv_SOURCES = \
 	service.c service.h \
 	validate.c validate.h \
 	$(top_srcdir)/src/openvpn/block_dns.c $(top_srcdir)/src/openvpn/block_dns.h \
-	openvpnserv_resources.rc
+	openvpnserv_resources.rc \
+	$(top_srcdir)/src/openvpn/ring_buffer.c $(top_srcdir)/src/openvpn/ring_buffer.h
src/openvpnserv/interactive.c +135 -6

211 lines not on this page · raw message

src/openvpnserv/openvpnserv.vcxproj +2 -0
index 7061b7b..c5a34b8 100644
@@ -115,6 +115,7 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\openvpn\ring_buffer.c" />
     <ClCompile Include="automatic.c" />
     <ClCompile Include="common.c" />
     <ClCompile Include="interactive.c" />
@@ -123,6 +124,7 @@
     <ClCompile Include="..\openvpn\block_dns.c" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="..\openvpn\ring_buffer.h" />
     <ClInclude Include="service.h" />
     <ClInclude Include="validate.h" />
     <ClInclude Include="..\openvpn\block_dns.h" />
src/openvpnserv/openvpnserv.vcxproj.filters +6 -0
index 3ce9bb2..3cb14ef 100644
@@ -33,6 +33,9 @@
     <ClCompile Include="..\openvpn\block_dns.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\openvpn\ring_buffer.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="service.h">
@@ -44,6 +47,9 @@
     <ClInclude Include="..\openvpn\block_dns.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\openvpn\ring_buffer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="openvpnserv_resources.rc">
Signature · 1 line
2.7.4
#5 lore raw

PATCH 6/7 wintun: set adapter properties via interactive service

In reply to Lev Stipakov

From: Lev Stipakov <[email protected]...>

Since Wintun doesn't do DHCP, use interactive service calls to set up adapter properties.

This also fixes bug in previously unused IPv4 code of do_address_service():

- ipv4 address must be in network byte order
- prefix length cannot be hardcoded /32 but
must be calculated from netmask

---
 src/openvpn/route.c |  2 +-
 src/openvpn/route.h |  3 ++-
 src/openvpn/tun.c   | 77 +++++++++++++++++++++++++++++++++++++++++------------
 3 files changed, 63 insertions(+), 19 deletions(-)
src/openvpn/route.c +1 -1
index 3183fb4..bd3809d 100644
@@ -3019,7 +3019,7 @@ out:
     return ret;
 }
 
-static bool
+bool
 do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const struct tuntap *tt)
 {
     DWORD if_index = windows_route_find_if_index(r, tt);
src/openvpn/route.h +2 -1
index 2e68091..27b652c 100644
@@ -321,7 +321,8 @@ void setenv_routes(struct env_set *es, const struct route_list *rl);
 
 void setenv_routes_ipv6(struct env_set *es, const struct route_ipv6_list *rl6);
 
-
+bool do_route_ipv4_service(const bool add, const struct route_ipv4 *r,
+                           const struct tuntap *tt);
 
 bool is_special_addr(const char *addr_str);
 
src/openvpn/tun.c +60 -17

171 lines not on this page · raw message

Signature · 1 line
2.7.4
#6 lore raw

PATCH 7/7 wintun: clear adapter settings on tun close

In reply to Lev Stipakov

From: Lev Stipakov <[email protected]...>

With tap-windows6 we clear adapter settings with DHCP, but since wintun doesn't do DHCP we do it with netsh.

---
 src/openvpn/tun.c | 79 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 50 insertions(+), 29 deletions(-)
src/openvpn/tun.c +50 -29
index 9fe8f9c..4008203 100644
@@ -6359,6 +6359,50 @@ tun_show_debug(struct tuntap *tt)
     }
 }
 
+static void
+netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gc)
+{
+    const char* ifconfig_ip_local;
+    struct argv argv = argv_new();
+
+    /* "store=active" is needed in Windows 8(.1) to delete the
+     * address we added (pointed out by Cedric Tabary).
+     */
+
+     /* netsh interface ipvX delete address \"%s\" %s */
+    if (ipv6)
+    {
+        ifconfig_ip_local = print_in6_addr(tt->local_ipv6, 0, gc);
+    }
+    else
+    {
+        ifconfig_ip_local = print_in_addr_t(tt->local, 0, gc);
+    }
+    argv_printf(&argv,
+                "%s%sc interface %s delete address %s %s store=active",
+                get_win_sys_path(),
+                NETSH_PATH_SUFFIX,
+                ipv6 ? "ipv6" : "ipv4",
+                tt->actual_name,
+                ifconfig_ip_local);
+
+    netsh_command(&argv, 1, M_WARN);
+
+    /* delete ipvX dns servers if any were set */
+    int len = ipv6 ? tt->options.dns6_len : tt->options.dns_len;
+    if (len > 0)
+    {
+        argv_printf(&argv,
+                    "%s%sc interface %s delete dns %s all",
+                    get_win_sys_path(),
+                    NETSH_PATH_SUFFIX,
+                    ipv6 ? "ipv6" : "ipv4",
+                    tt->actual_name);
+        netsh_command(&argv, 1, M_WARN);
+    }
+    argv_reset(&argv);
+}
+
 void
 close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
 {
@@ -6381,35 +6425,7 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
         }
         else
         {
-            const char *ifconfig_ipv6_local;
-            struct argv argv = argv_new();
-
-            /* "store=active" is needed in Windows 8(.1) to delete the
-             * address we added (pointed out by Cedric Tabary).
-             */
-
-            /* netsh interface ipv6 delete address \"%s\" %s */
-            ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0,  &gc);
-            argv_printf(&argv,
-                        "%s%sc interface ipv6 delete address %s %s store=active",
-                        get_win_sys_path(),
-                        NETSH_PATH_SUFFIX,
-                        tt->actual_name,
-                        ifconfig_ipv6_local);
-
-            netsh_command(&argv, 1, M_WARN);
-
-            /* delete ipv6 dns servers if any were set */
-            if (tt->options.dns6_len > 0)
-            {
-                argv_printf(&argv,
-                            "%s%sc interface ipv6 delete dns %s all",
-                            get_win_sys_path(),
-                            NETSH_PATH_SUFFIX,
-                            tt->actual_name);
-                netsh_command(&argv, 1, M_WARN);
-            }
-            argv_reset(&argv);
+            netsh_delete_address_dns(tt, true, &gc);
         }
     }
 #if 1
@@ -6431,6 +6447,11 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
                 strerror_win32(status, &gc));
         }
     }
+    else
+    if (tt->wintun)
+    {
+        netsh_delete_address_dns(tt, false, &gc);
+    }
 #endif
 
     dhcp_release(tt);
Signature · 1 line
2.7.4
#7 lore raw
In reply to Lev Stipakov

Hi,

Quoted 18 lines · Lev Stipakov

From: Lev Stipakov <[email protected]...>

This set of patches adds support of wintun kernel driver (https://www.wintun.net) to OpenVPN.

While wintun is in beta, it performs significantly faster comparison to tap-windows6.

Here are some performance numbers (download bandwidth):

Server - community openvpn2

mingw, tap-windows6   - 340Mbit/s
mingw, wintun         - 675Mbit/s
VS2019, tap-windows6  - 425Mbit/s
VS2019, wintun        - 750Mbit/s

Server - propietary openvpn3 with kernel acceleration (in development)

Quoted 7 lines
mingw, tap-windows6   - 360Mbit/s
mingw, wintun         - 840Mbit/s
VS2019, tap-windows6  - 430Mbit/s
VS2019, wintun        - 1,14Gbit/s

And for the reference
openvpn3 test client, VS2019, wintun - 1,71Gbit/s

No doubt this is interesting and surprising given mingw (unlike cygwin) uses stock Windows runtime. Does the VS build target a more recent Windows runtime than the legacy one (msvcrt.dll) that mingw would link against?

With some effort it may be possible to make mingw use a newer CRT (say mscrt110.dll) and test whether that helps. Also, do we have to distribute a recent CRT with this executable?

Even if we manage to change the release process to support building on Windows, it will have to remain a hybrid process for a while at least. OpenVPN-GUI doesn't build with visual studio and making it do so will need some work -- especially with the resource file formats. Nothing complicated but cumbersome. Unless someone volunteers.

Selva

#8 lore raw

Hi,

Turns out that our build script for windows-nsis/generic doesn't specify any optimization flags.

I added -O2 and got 400Mbit/s with mingw, which is better than 340 but worse than VS's 425.

Haven't yet checked which flags are used for openssl build.

Also adding "-O2" to CFLAGS breaks rc build:

libtool: compile: i686-w64-mingw32-windres -DHAVE_CONFIG_H -I. -I../.. -I../../include -I../../include -I../../src/compat -DWIN32_LEAN_AND_MEAN -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA -O2 -i openvpnmsica_resources.rc -o .libs/openvpnmsica_resources.o
i686-w64-mingw32-windres: unknown format type `2'
i686-w64-mingw32-windres: supported formats: rc res coff Makefile:827: recipe for target 'openvpnmsica_resources.lo' failed

This happens because windres treats "-O" as own option, so I removed .rc files from Makefile(s).am for testing.

I'll play with optimizations flags and find a proper solution for rc build. I think this has to be fixed also in the next 2.4 release.

Signature · 1 line
-Lev
#9 lore raw

Hello,

Quoted 3 lines

Does the VS build target a more
recent Windows runtime than the legacy one (msvcrt.dll) that mingw would link against?

Yes, VS build targets Universal CRT, while mingw targets "classis", pre-Visual Studio 2015 CRT.

Answering to Gert's question in IRC - CPU load was 25% on 4-core machine, so I assume that
client is CPU-bound.

I enabled optimization (-O2 -flto) for mingw builds

https://github.com/OpenVPN/openvpn-build/pull/153/commits/570bbbb27ec33f06995400b19da5db2af8b0d58a

and problem seems to be fixed, I see no big difference with Visual Studio anymore.

I performed series of tests - for each configuration I ran

Quoted 1 line

iperf3.exe -c 10.8.0.1 -t 60 -V

five times and used average download bandwidth value.

Results below (don't know why they're bit lower comparison to previous runs, probably AWS datacenter has a bad day today):

Server - openvpn 2.4.4, client tun driver - tap-windows6
mingw, no optimization - 334Mbit/s (that's what we have in windows
release now)
mingw, optimized - 390Mbit/s
VS2019 release - 394Mbit/s

Server - openvpn 2.4.4, client tun driver - wintun
mingw, no optimization - 650Mbit/s
mingw, optimized - 731Mbit/s
VS2019 release - 721Mbit/s

Server - openvpn3 with kernel module, client tun driver - wintun
mingw, no optimization - 772Mbit/s
mingw, optimized - 924Mbit/s
VS2019 release - 901Mbit/s

As you can see, using wintun and mingw optimization increases download bandwidth more than twice (334Mbit/s -> 731Mbit)

So for the next release we need to build client with optimization enabled and
it would be nice to have wintun support in 2.5 (see
https://patchwork.openvpn.net/project/openvpn2/list/?series=545)

Signature · 1 line
-Lev
#10 lore raw
In reply to Lev Stipakov

Hello,

Wintun driver is now signed for Windows 10,

https://staging.openvpn.net/openvpn2/wintun-0.6-signed.zip

So if you want to try out super fast openvpn2, no need to meddle anymore with test mode / disabling signature checks.

ti 17. syysk. 2019 klo 15.45 Lev Stipakov ([email protected]...) kirjoitti:

Quoted 440 lines

From: Lev Stipakov <[email protected]...>

This set of patches adds support of wintun kernel driver (
https://www.wintun.net) to OpenVPN.

While wintun is in beta, it performs significantly faster comparison to tap-windows6.

Here are some performance numbers (download bandwidth):

Server - community openvpn2

mingw, tap-windows6   - 340Mbit/s
mingw, wintun         - 675Mbit/s
VS2019, tap-windows6  - 425Mbit/s
VS2019, wintun        - 750Mbit/s

Server - propietary openvpn3 with kernel acceleration (in development)

mingw, tap-windows6   - 360Mbit/s
mingw, wintun         - 840Mbit/s
VS2019, tap-windows6  - 430Mbit/s
VS2019, wintun        - 1,14Gbit/s

And for the reference
openvpn3 test client, VS2019, wintun - 1,71Gbit/s

Some observations from those numbers:

* wintun performs more than twice faster comparison to tap-windows6
agains community server (750Mbit/s vs 340Mbit/s)
* Visual Studio provides noticeable performance boost (up to 25%)
* we should build Windows clients with VS, not with mingw
* There's room for improvement in openvpn2, since under best
conditions openvpn3 performs 50% faster

Steps to try out new client:

* Install Wintun driver
* since driver is not signed, you need to enable test mode to
install unsigned driver
* run in administrative command prompt:
bcdedit /set testsigning on
* restart
* download and unpack
https://staging.openvpn.net/openvpn2/wintun-0.6-unsigned.zip to C:\Temp\wintun (for example)
* if you have OpenVPN GUI client installed, run under
administrative command prompt:
c:\Program Files\TAP-Windows\bin>tapinstall.exe install
c:\Temp\wintun\wintun.inf wintun
* alternatively you can install driver via windows device manager
-> action ->add legacy hardware -> install manually ->
point to wintun.inf in C:\Temp\wintun

* Install openvpn client with wintun support
* download and unpack
https://staging.openvpn.net/openvpn2/openvpn2-wintun-support.zip to C:\Temp\openvpn (for example)
* if you use OpenVPN GUI, copy all files from C:\Temp\openvpn to
C:\Program Files\OpenVPN\bin. Don't forget to
stop OpenVPN Interactive Service before copying and start it
back afterwards (net stop/start OpenVPNServiceInteractive in admin command prompt)

* Connect to VPN from command line
* run from administrative command prompt c:\Temp\openvpn>openvpn.exe --config client.ovpn
--windows-driver wintun
* you should see something around these lines in log Tue Sep 17 15:09:58 2019 us=296000 interactive service
msg_channel=0

          Tue Sep 17 15:09:58 2019 us=312000 open_tun
          Tue Sep 17 15:09:58 2019 us=312000 Wintun device
[Lähiverkkoyhteys] opened:
\\?\ROOT#NET#0004#{cac88484-7515-4c03-82e6-71a87abac361}
          Tue Sep 17 15:09:58 2019 us=312000 do_ifconfig, ipv4=1, ipv6=0
          Tue Sep 17 15:09:59 2019 us=312000 NETSH:
C:\Windows\system32\netsh.exe interface ip set address Lähiverkkoyhteys
static 10.8.0.2 255.255.255.0
          Tue Sep 17 15:10:00 2019 us=406000 NETSH:
C:\Windows\system32\netsh.exe interface ip delete dns Lähiverkkoyhteys all
          Tue Sep 17 15:10:01 2019 us=484000 NETSH:
C:\Windows\system32\netsh.exe interface ip set dns Lähiverkkoyhteys static
10.8.0.1
          Tue Sep 17 15:10:14 2019 us=578000 NETSH:
C:\Windows\system32\netsh.exe interface ip delete wins Lähiverkkoyhteys all
          Tue Sep 17 15:10:19 2019 us=296000 TEST ROUTES: 0/0 succeeded
len=0 ret=1 a=0 u/d=up
          Tue Sep 17 15:10:19 2019 us=296000 WARNING: this configuration
may cache passwords in memory -- use the auth-nocache option to prevent this
          Tue Sep 17 15:10:19 2019 us=296000 Initialization Sequence

Completed
* congratulations!

* Connect to VPN from OpenVPN GUI
* right click on tray icon -> profile name -> Edit Config
* add "windows-driver wintun" to profile, save and close
* right click on tray icon -> profile name -> Connect
* you should see something around these lines in log Tue Sep 17 15:15:46 2019 interactive service msg_channel=676 Tue Sep 17 15:15:46 2019 open_tun
Tue Sep 17 15:15:46 2019 Wintun device [Lähiverkkoyhteys]
opened: \\?\ROOT#NET#0004#{cac88484-7515-4c03-82e6-71a87abac361}

          Tue Sep 17 15:15:46 2019 Ring buffers registered via service
          Tue Sep 17 15:15:46 2019 do_ifconfig, ipv4=1, ipv6=0
          Tue Sep 17 15:15:46 2019 MANAGEMENT:
Quoted 1 line

STATE:1568722546,ASSIGN_IP,,10.8.0.2,,,,

          Tue Sep 17 15:15:46 2019 Setting IPv4 dns servers on
'Lähiverkkoyhteys' (if_index = 3) using service
          Tue Sep 17 15:15:46 2019 IPv4 dns servers set using service
          Tue Sep 17 15:15:51 2019 TEST ROUTES: 0/0 succeeded len=0 ret=1

a=0 u/d=up
Tue Sep 17 15:15:51 2019 WARNING: this configuration may cache
passwords in memory -- use the auth-nocache option to prevent this
Tue Sep 17 15:15:51 2019 Initialization Sequence Completed
* congratulations!

---
 src/compat/compat.vcxproj             | 12 ++++++------
 src/openvpn/openvpn.vcxproj           | 12 ++++++------
 src/openvpnmsica/openvpnmsica.vcxproj | 14 +++++++-------
 src/openvpnserv/openvpnserv.vcxproj   | 12 ++++++------
 src/tapctl/tapctl.vcxproj             | 14 +++++++-------
 5 files changed, 32 insertions(+), 32 deletions(-)
src/compat/compat.vcxproj +0 -1
index 111dacd..e388008 100644
@@ -22,30 +22,30 @@
     <ProjectGuid>{4B2E2719-E661-45D7-9203-F6F456B22F19}</ProjectGuid>
     <RootNamespace>compat</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-

<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup
Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>MultiByte</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization>

src/compat/compat.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>MultiByte</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization>

src/compat/compat.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>MultiByte</CharacterSet>

src/compat/compat.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"

Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>MultiByte</CharacterSet>

src/compat/compat.vcxproj +2 -2
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -115,4 +115,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
src/openvpn/openvpn.vcxproj +0 -1
index 92d7e32..3422b64 100644
@@ -22,30 +22,30 @@
     <ProjectGuid>{29DF226E-4D4E-440F-ADAF-5829CFD4CA94}</ProjectGuid>
     <RootNamespace>openvpn</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-

<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup
Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>Unicode</CharacterSet>

src/openvpn/openvpn.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>Unicode</CharacterSet>

src/openvpn/openvpn.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <CharacterSet>Unicode</CharacterSet>

src/openvpn/openvpn.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"

Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <CharacterSet>Unicode</CharacterSet>

src/openvpn/openvpn.vcxproj +2 -2
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -299,4 +299,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
src/openvpnmsica/openvpnmsica.vcxproj +0 -1
index 5f1d699..afa4fae 100644
@@ -31,32 +31,32 @@
     <ProjectGuid>{D41AA9D6-B818-476E-992E-0E16EB86BEE2}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
     <RootNamespace>openvpnmsica</RootNamespace>
-

<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup
Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries>

src/openvpnmsica/openvpnmsica.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries>

src/openvpnmsica/openvpnmsica.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"

Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries>

src/openvpnmsica/openvpnmsica.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries>

src/openvpnmsica/openvpnmsica.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
@@ -64,14 +64,14 @@
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries>

src/openvpnmsica/openvpnmsica.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries>

src/openvpnmsica/openvpnmsica.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
src/openvpnserv/openvpnserv.vcxproj +0 -1
index 7407757..7061b7b 100644
@@ -22,30 +22,30 @@
     <ProjectGuid>{9C91EE0B-817D-420A-A1E6-15A5A9D98BAD}</ProjectGuid>
     <RootNamespace>openvpnserv</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-

<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup
Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <CharacterSet>Unicode</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization>

src/openvpnserv/openvpnserv.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <CharacterSet>Unicode</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization>

src/openvpnserv/openvpnserv.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <CharacterSet>Unicode</CharacterSet>

src/openvpnserv/openvpnserv.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"

Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <CharacterSet>Unicode</CharacterSet>

src/openvpnserv/openvpnserv.vcxproj +2 -2
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -139,4 +139,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
src/tapctl/tapctl.vcxproj +0 -1
index 5c1983b..1d593fc 100644
@@ -31,32 +31,32 @@
     <ProjectGuid>{A06436E7-D576-490D-8BA0-0751D920334A}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
     <RootNamespace>tapctl</RootNamespace>
-

<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup
Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries>

src/tapctl/tapctl.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries>

src/tapctl/tapctl.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"

Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries>

src/tapctl/tapctl.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries>

src/tapctl/tapctl.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
     <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
@@ -64,14 +64,14 @@
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries>

src/tapctl/tapctl.vcxproj +1 -1
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup

Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries>

src/tapctl/tapctl.vcxproj +1 -2
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
--

2.7.4

Signature · 1 line
-Lev
#12 lore raw

Hi Steffan,

Out of curiosity: does the (signed) driver from wintun.net not work? Of so,

Quoted 2 lines

why?

It does. It is just not usable for openvpn yet because:

1) Wintun is distributed as msm module, which is supposed to be integrated into MSI installer.
Our MSI installer doesn't support wintun yet.

2) One can install wireguard client, which installs wintun, however it still won't work
for openvpn out of the box. Wireguard creates tun adapter on demand, and openvpn
expects it to already exist. So if you try to use openvpn with wintun after installing wireguard
you'll get error "no tun adapters found" (or something). This is not a problem, since
we have "tapctl" tool which can create/list/delete tun/tap adapters. It does not work with
wintun, though, since it has hardcoded "tap0901" hardware id. I plan to make it customizable
so one could create wintun adapter by running something like "tapctl.exe create --name openvpn-wintun --hwid wintun".
We could consider creating tun adapter on demand, but this increases connection time by a few seconds.

Signature · 1 line
-Lev
#13 lore raw

Hi,

Quoted 11 lines · Lev Stipakov

Hi Steffan,

Quoted 1 line

Out of curiosity: does the (signed) driver from wintun.net not work? Of so, why?

It does. It is just not usable for openvpn yet because:

1) Wintun is distributed as msm module, which is supposed to be integrated into MSI installer. Our MSI installer doesn't support wintun yet.

Quoted 9 lines

2) One can install wireguard client, which installs wintun, however it still won't work
for openvpn out of the box. Wireguard creates tun adapter on demand, and openvpn
expects it to already exist. So if you try to use openvpn with wintun after installing wireguard you'll get error "no tun adapters found" (or something). This is not a problem, since
we have "tapctl" tool which can create/list/delete tun/tap adapters. It does not work with
wintun, though, since it has hardcoded "tap0901" hardware id. I plan to make it customizable
so one could create wintun adapter by running something like "tapctl.exe create --name openvpn-wintun --hwid wintun". We could consider creating tun adapter on demand, but this increases connection time by a few seconds.

The last time I tried, I could use the driver that comes with wireguard by "activatin" an adapter from its GUI but not add a tunnel so that the device remains free. Then the pacthed openvpn could open it.

How does one install the driver in the zip file you posted -- using devcon with the hardware id of wintun?

Selva

#14 lore raw

Double checked that it was in my original email :)

Quoted 1 line

* if you have OpenVPN GUI client installed, run under administrative

command prompt:

Quoted 1 line

c:\Program Files\TAP-Windows\bin>tapinstall.exe install

c:\Temp\wintun\wintun.inf wintun

Quoted 1 line

* alternatively you can install driver via windows device manager ->

action ->add legacy hardware -> install manually ->

Quoted 1 line

point to wintun.inf in C:\Temp\wintun

If I am not mistaken, tapinstall is a renamed devcon, so same arguments might work.

You could also patch our own tapctl tool:

src/tapctl/tap.c +0 -0
index e75db354..905fef66 100644
@@ -41,7 +41,7 @@
 
 const static GUID GUID_DEVCLASS_NET = { 0x4d36e972L, 0xe325, 0x11ce, {

0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };

-const static TCHAR szzHardwareIDs[] = TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0");
+const static TCHAR szzHardwareIDs[] = TEXT("wintun") TEXT("\0");

const static TCHAR szInterfaceRegKeyPathTemplate[] =
TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\%") TEXT(PRIsLPOLESTR) TEXT("\\%") TEXT(PRIsLPOLESTR) TEXT("\\Connection");
#define INTERFACE_REGKEY_PATH_MAX
(_countof(TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")) - 1 + 38 + _countof(TEXT("\\")) - 1 + 38 + _countof(TEXT("\\Connection")))

and then run:

Quoted 1 line

tapctl.exe create --name openvpn-wintun

Signature · 1 line
-Lev
#15 lore raw

Since distributing own wintun binaries goes against recommended way (which is MSM modules), here are steps to try out openvpn with wintun (which is even simpler than previous way):

- Install wireguard windows client from https://www.wireguard.com/install/
- Download patched openvpn binaries from
https://staging.openvpn.net/openvpn2/openvpn2-wintun-support.zip
- Unpack downloaded archive and run in administrative command prompt:

    c:\Temp\openvpn>tapctl.exe create --hwid wintun

- That's it! You have created wintun network adapter and ready to use
openvpn with wintun.

This uses tapctl, which is openvpn 2.5+ tool to manipulate tun/tap adapters, which I have patched to work with wintun (
https://patchwork.openvpn.net/patch/833/).

See more detailed instruction here: http://staging.openvpn.net/openvpn2/

Signature · 1 line
-Lev
#16 lore raw

I have added wintun's MSM (official distribution way) to windows client installer:

https://staging.openvpn.net/openvpn2/openvpn-install-2.5_git-I607-Win10.exe

To use wintun driver instead of tap-window6, add "windows-driver wintun" to your VPN profile.

Fresh performance numbers (with recent -O2 fix to windows build system):

Server - openvpn 2.4.4

    tap-windows6: 390Mbit/s
    wintun: 730Mbit/s

Server - openvpn3 with kernel acceleration

    tap-windows6: 405Mbit/s
    wintun: 1.05Gbit/s
Signature · 1 line
-Lev