dco-win: introduce low-level code for handling ovpn-dco-win in Windows
PATCH v101 1/7 dco-win: introduce low-level code for handling ovpn-dco-win in Windows
---
Changes from v100:
* rebased (fixed conflict in configure.ac)
* fixed access to disable_dco member in dco.c
* renamed ovpn-dco-win.h to ovpn_dco_win.h
* make tun_open_device and close_tun_handle non static
* add ASSERT(0) to functions that should not be called on Windows
* remove real_tun_init member (unused now)
--- config-msvc.h | 2 + configure.ac | 9 +- dev-tools/special-files.lst | 1 + src/openvpn/Makefile.am | 4 +- src/openvpn/dco.c | 2 +- src/openvpn/dco_internal.h | 1 + src/openvpn/dco_win.c | 400 ++++++++++++++++++++++++++++ src/openvpn/dco_win.h | 57 ++++ src/openvpn/openvpn.vcxproj | 3 + src/openvpn/openvpn.vcxproj.filters | 9 + src/openvpn/ovpn_dco_win.h | 108 ++++++++ src/openvpn/tun.c | 4 +- src/openvpn/tun.h | 10 +- 13 files changed, 602 insertions(+), 8 deletions(-) create mode 100644 src/openvpn/dco_win.c create mode 100644 src/openvpn/dco_win.h create mode 100644 src/openvpn/ovpn_dco_win.h
config-msvc.h +2 -0
@@ -87,3 +87,5 @@ typedef uint16_t in_port_t;#ifdef HAVE_CONFIG_MSVC_LOCAL_H #include <config-msvc-local.h> #endif + +#define ENABLE_DCO 1
configure.ac +6 -3
@@ -144,7 +144,7 @@ AC_ARG_ENABLE( AC_ARG_ENABLE( [dco], - [AS_HELP_STRING([--enable-dco], [enable data channel offload support using ovpn-dco kernel module @<:@default=no@:>@])], + [AS_HELP_STRING([--enable-dco], [enable data channel offload support using the ovpn-dco kernel module (always enabled on Windows) @<:@default=no@:>@])], , [enable_dco="no"] )
@@ -328,6 +328,7 @@ case "$host" in ;; *-mingw*) AC_DEFINE([TARGET_WIN32], [1], [Are we running WIN32?]) + AC_DEFINE([ENABLE_DCO], [1], [DCO is always enabled on Windows]) AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["W"], [Target prefix]) CPPFLAGS="${CPPFLAGS} -DWIN32_LEAN_AND_MEAN" CPPFLAGS="${CPPFLAGS} -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA"
@@ -772,7 +773,6 @@ if test "$enable_dco" = "yes"; then dnl dnl Include generic netlink library used to talk to ovpn-dco dnl - case "$host" in *-*-linux*) PKG_CHECK_MODULES([LIBNL_GENL],
@@ -792,8 +792,11 @@ dnl AC_DEFINE(ENABLE_DCO, 1, [Enable data channel offload for FreeBSD]) AC_MSG_NOTICE([Enabled ovpn-dco support for FreeBSD]) ;; + *-mingw*) + AC_MSG_NOTICE([NOTE: --enable-dco ignored on Windows because it's always enabled]) + ;; *) - AC_MSG_NOTICE([Ignoring --enable-dco on non Linux platform]) + AC_MSG_NOTICE([Ignoring --enable-dco on non supported platform]) ;; esac fi
dev-tools/special-files.lst +1 -0
@@ -2,3 +2,4 @@ E:doc/doxygen/doc_key_generation.h # @verbatim section gets mistreated, excl E:src/compat/compat-lz4.c # Preserve LZ4 upstream formatting E:src/compat/compat-lz4.h # Preserve LZ4 upstream formatting E:src/openvpn/ovpn_dco_linux.h # Preserve ovpn-dco upstream formatting +E:src/openvpn/ovpn_dco_win.h # Preserve ovpn-dco-win upstream formatting
src/openvpn/Makefile.am +3 -1
@@ -56,6 +56,7 @@ openvpn_SOURCES = \ dco.c dco.h dco_internal.h \ dco_freebsd.c dco_freebsd.h \ dco_linux.c dco_linux.h \ + dco_win.c dco_win.h \ dhcp.c dhcp.h \ dns.c dns.h \ env_set.c env_set.h \
@@ -79,6 +80,7 @@ openvpn_SOURCES = \ memdbg.h \ misc.c misc.h \ ovpn_dco_linux.h \ + ovpn_dco_win.h \ platform.c platform.h \ console.c console.h console_builtin.c console_systemd.c \ mroute.c mroute.h \
@@ -152,5 +154,5 @@ openvpn_LDADD = \ $(OPTIONAL_INOTIFY_LIBS) if WIN32 openvpn_SOURCES += openvpn_win32_resources.rc block_dns.c block_dns.h ring_buffer.h -openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi +openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt endif
src/openvpn/dco.c +1 -1
@@ -289,7 +289,7 @@ dco_check_option_conflict(int msglevel, const struct options *o)* specified at all. In the latter case, later logic will most likely stop * OpenVPN, so no need to print any message here. */ -if (o->tuntap_options.disable_dco || !o->dev) +if (!dco_enabled (o) || !o->dev) {return false; }
src/openvpn/dco_internal.h +1 -0
@@ -29,6 +29,7 @@#include "dco_freebsd.h" #include "dco_linux.h" +#include "dco_win.h" /** * This file contains the internal DCO API definition.
src/openvpn/dco_win.c new file +400 -0
400 lines not on this page · raw message
src/openvpn/dco_win.h new file +57 -0
57 lines not on this page · raw message
src/openvpn/openvpn.vcxproj +3 -0
@@ -278,6 +278,7 @@ <ClCompile Include="cryptoapi.c" /> <ClCompile Include="dco.c" /> <ClCompile Include="dco_linux.c" /> + <ClCompile Include="dco_win.c" /> <ClCompile Include="dhcp.c" /> <ClCompile Include="dns.c" /> <ClCompile Include="env_set.c" />
@@ -367,6 +368,7 @@ <ClInclude Include="dco.h" /> <ClInclude Include="dco_internal.h" /> <ClInclude Include="dco_linux.h" /> + <ClInclude Include="dco_win.h" /> <ClInclude Include="dhcp.h" /> <ClInclude Include="dns.h" /> <ClInclude Include="env_set.h" />
@@ -402,6 +404,7 @@ <ClInclude Include="options.h" /> <ClInclude Include="otime.h" /> <ClInclude Include="ovpn_dco_linux.h" /> + <ClInclude Include="ovpn_dco_win.h" /> <ClInclude Include="packet_id.h" /> <ClInclude Include="perf.h" /> <ClInclude Include="ping.h" />
src/openvpn/openvpn.vcxproj.filters +9 -0
@@ -42,6 +42,9 @@ <ClCompile Include="dco_linux.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="dco_win.c"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="dhcp.c"> <Filter>Source Files</Filter> </ClCompile>
@@ -314,6 +317,9 @@ <ClInclude Include="dco_linux.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="dco_win.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="dhcp.h"> <Filter>Header Files</Filter> </ClInclude>
@@ -416,6 +422,9 @@ <ClInclude Include="ovpn_dco_linux.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ovpn_dco_win.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="packet_id.h"> <Filter>Header Files</Filter> </ClInclude>
src/openvpn/ovpn_dco_win.h new file +108 -0
108 lines not on this page · raw message
src/openvpn/tun.c +2 -2
@@ -6532,7 +6532,7 @@ tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct devreturn true; } -static void +void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc) {const struct tap_reg *tap_reg =get_tap_reg (gc);
@@ -6824,7 +6824,7 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gcargv_free (&argv); } -static void +void close_tun_handle (struct tuntap *tt) {const char *adaptertype =print_windows_driver (tt->windows_driver);
src/openvpn/tun.h +9 -1
@@ -48,7 +48,8 @@enum windows_driver_type {WINDOWS_DRIVER_UNSPECIFIED ,WINDOWS_DRIVER_TAP_WINDOWS6 , -WINDOWS_DRIVER_WINTUN +WINDOWS_DRIVER_WINTUN , +WINDOWS_DRIVER_DCO };#endif
@@ -64,6 +65,8 @@ struct tuntap_options {/* --ip-win32 options */ bool ip_win32_defined; +bool disable_dco; +#define IPW32_SET_MANUAL 0/* "--ip-win32 manual" */ #define IPW32_SET_NETSH 1/* "--ip-win32 netsh" */ #define IPW32_SET_IPAPI 2/* "--ip-win32 ipapi" */
@@ -259,6 +262,11 @@ void open_tun(const char *dev, const char *dev_type, const char *dev_node,void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void tun_open_device (struct tuntap *tt,const char *dev_node, +const char **device_guid,struct gc_arena *gc); + +void close_tun_handle (struct tuntap *tt); +int write_tun (struct tuntap *tt,uint8_t *buf,int len);int read_tun (struct tuntap *tt,uint8_t *buf,int len);
Signature · 1 line
2.35.1
PATCH v101 2/7 dco-win: check for incompatible options
At the moment dco-win doesn't support --persist-tun and --server, so check for these options at startup time.
---
Changes from v100:
* improved commit title/message
--- src/openvpn/dco.c | 17 +++++++++++++++-- src/openvpn/options.c | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)
src/openvpn/dco.c +15 -2
@@ -221,7 +221,20 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)static bool dco_check_option_conflict_platform (int msglevel,const struct options *o) { -#if defined(TARGET_LINUX ) +#if defined(_WIN32) +if (o->mode ==MODE_SERVER ) + { +msg (msglevel,"Only client and p2p data channel offload is supported " +"with ovpn-dco-win." ); +return false; + } + +if (o->persist_tun) + { +msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +return false; + } +#elif defined(TARGET_LINUX )/* if the device name is fixed, we need to check if an interface with this * name already exists. IF it does, it must be a DCO interface, otherwise * DCO has to be disabled in order to continue.
@@ -246,7 +259,7 @@ dco_check_option_conflict_platform(int msglevel, const struct options *o) strerror(-ret), ret); } } -#endif /* if defined(TARGET_LINUX) */ +#endif /* if defined(_WIN32) */ return true; }
src/openvpn/options.c +5 -0
@@ -2450,6 +2450,11 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--windows-driver wintun requires --dev tun" ); } + +if (options->windows_driver ==WINDOWS_DRIVER_DCO ) + { +dco_check_option_conflict (M_USAGE , options); + }#endif /* ifdef _WIN32 */ /*
Signature · 1 line
2.35.1
PATCH v101 3/7 dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Antonio QuartulliWith this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
---
Changes from v100:
* rebased (fixed conflicts in options.h and tun.h)
Changes from v3:
* rename WINDOWS_DRIVER_WINDCO to WINDOWS_DRIVER_DCO
* add reference string check
Changes from v2:
* added is_tun_type_set() and removed real_tun_init flag
* moved link-close to do_close_tun()
Changes from v1:
* use suffix _dco_win instead of _windco
* create helper function to retrieve last error from socket object
--- src/openvpn/forward.c | 8 ++++ src/openvpn/init.c | 33 ++++++++++++--- src/openvpn/options.c | 23 ++++++++--- src/openvpn/options.h | 15 +++---- src/openvpn/socket.c | 93 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/socket.h | 25 ++++++++---- src/openvpn/tun.c | 52 +++++++++++++++++++----- src/openvpn/tun.h | 66 +++++++++++++++++++++++------- 8 files changed, 255 insertions(+), 60 deletions(-)
src/openvpn/forward.c +8 -0
@@ -864,9 +864,17 @@ read_incoming_link(struct context *c)return ; } +/* check_status() call below resets last-error code */ +bool dco_win_timeout =tuntap_is_dco_win_timeout (c->c1.tuntap, status); +/* check recvfrom status */ check_status (status,"read" , c->c2.link_socket,NULL ); +if (dco_win_timeout) + { +trigger_ping_timeout_signal (c); + } +/* Remove socks header if applicable */ socks_postprocess_incoming_link (c);
src/openvpn/init.c +28 -5
@@ -1699,7 +1699,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es, - &c->net_ctx); + &c->net_ctx, + c->c1.tuntap);#ifdef _WIN32 c->c1.tuntap->windows_driver = c->options.windows_driver;
@@ -1723,7 +1724,7 @@ can_preserve_tun(struct tuntap *tt)#ifdef TARGET_ANDROID return false;#else -return tt; +return is_tun_type_set (tt);#endif }
@@ -1810,9 +1811,12 @@ do_open_tun(struct context *c)ovpn_dco_init (c->mode, &c->c1.tuntap->dco); } -/* open the tun device */ -open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap, &c->net_ctx); +/* open the tun device (ovpn-dco-win already opened the device for the socket) */ +if (!tuntap_is_dco_win (c->c1.tuntap)) + { +open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, + c->c1.tuntap, &c->net_ctx); + }/* set the hardware address */ if (c->options.lladdr)
@@ -1930,6 +1934,16 @@ do_close_tun_simple(struct context *c)static void do_close_tun (struct context *c,bool force) { +/* With dco-win we open tun handle in the very beginning. +* In case when tun wasn't opened - like we haven't connected, +* we still need to close tun handle +*/ +if (tuntap_is_dco_win (c->c1.tuntap) && !is_tun_type_set (c->c1.tuntap)) + { +do_close_tun_simple (c); +return ; + } +if (!c->c1.tuntap || !c->c1.tuntap_owned) {return ;
@@ -3570,6 +3584,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/options.c +17 -6
@@ -3343,9 +3343,11 @@ options_postprocess_mutate_invariant(struct options *options)#ifdef _WIN32const int dev =dev_type_enum (options->dev, options->dev_type); -/* when using wintun, kernel doesn't send DHCP requests, so don't use it */ -if (options->windows_driver ==WINDOWS_DRIVER_WINTUN - && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) +/* when using wintun/ovpn-dco-win, kernel doesn't send DHCP requests, so don't use it */ +if ((options->windows_driver ==WINDOWS_DRIVER_WINTUN + || options->windows_driver ==WINDOWS_DRIVER_DCO ) + && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ + || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) { options->tuntap_options.ip_win32_type =IPW32_SET_NETSH ; }
@@ -3439,10 +3441,12 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +#if !defined(_WIN32) else if (cipher_valid("CHACHA20-POLY1305")) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ; } +#endif else { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM" ;
@@ -4165,7 +4169,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4552,13 +4557,19 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco-win")) + { +return WINDOWS_DRIVER_DCO ; + } else { -msg (msglevel,"--windows-driver must be tap-windows6 or wintun" ); +msg (msglevel,"--windows-driver must be tap-windows6, wintun " +"or ovpn-dco-win" );return WINDOWS_DRIVER_UNSPECIFIED ; } } -#endif +#endif /* ifdef _WIN32 */ /* * parse/print topology coding
src/openvpn/options.h +5 -10
@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) -/** * Returns whether the current configuration has dco enabled. */ static inline bool dco_enabled (const struct options *o) { +#if defined(_WIN32) +return o->windows_driver ==WINDOWS_DRIVER_DCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} - -#else /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))*/ - -static inline bool -dco_enabled (const struct options *o) -{ +#else return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/socket.c +87 -6
141 lines not on this page · raw message
src/openvpn/socket.h +18 -7
@@ -34,6 +34,7 @@#include "proxy.h" #include "socks.h" #include "misc.h" +#include "tun.h" /* * OpenVPN's default port number as assigned by IANA.
@@ -937,7 +938,8 @@ socket_connection_reset(const struct link_socket *sock, int status) {const int err =openvpn_errno ();#ifdef _WIN32 -return err ==WSAECONNRESET || err ==WSAECONNABORTED ; +return err ==WSAECONNRESET || err ==WSAECONNABORTED + || err ==ERROR_CONNECTION_ABORTED ;#else return err ==ECONNRESET ;#endif
@@ -1048,6 +1050,11 @@ link_socket_read_udp_win32(struct link_socket *sock, struct link_socket_actual *from) {sockethandle_t sh = { .s = sock->sd }; +if (sock->info.dco_installed) + { +addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + sh.is_handle = true; + }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1057,7 +1064,7 @@ int link_socket_read_udp_posix(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from); -#endif +#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int
@@ -1065,7 +1072,10 @@ link_socket_read(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) + || sock->info.dco_installed) + /* unified UDPv4 and UDPv6, for DCO the kernel + * will strip the length header */ { int res;
@@ -1106,19 +1116,19 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );if (status <0 ) { - err =WSAGetLastError (); + err =SocketHandleGetLastError (sh); } }socket_send_queue (sock, buf, to);if (status <0 ) { -WSASetLastError (err); +SocketHandleSetLastError (sh, err);return status; }else
@@ -1180,8 +1190,9 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) { + /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); } else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
src/openvpn/tun.c +41 -11
102 lines not on this page · raw message
src/openvpn/tun.h +51 -15
104 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH v101 4/7 dco-win: add documentation to README.dco.md
In reply to Antonio Quartulli---
Changes from v100:
* add URL to windows installer (openvpn+dco) and modify text
--- README.dco.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
README.dco.md +10 -1
@@ -57,6 +57,13 @@ see a message like in your log. +Getting started (Windows) +------------------------- +The simplest way to test DCO under Windows is to download the latest installer +from https://build.openvpn.net/downloads/snapshots/github-actions/openvpn2/ . +This installer contains the latest OpenVPN code and the ovpn-dco-win driver. + + DCO and P2P mode ---------------- DCO is also available when running OpenVPN in P2P mode without `--pull` /
@@ -111,7 +118,9 @@ Limitations by design - older versions are missing support for the AEAD ciphers; - topology subnet is the only supported `--topology` for servers; - iroute directives install routes on the host operating system, see also - Routing with ovpn-dco. + Routing with ovpn-dco; +- (ovpn-dco-win) client and p2p mode only; +- (ovpn-dco-win) Chacha20-Poly1305 support available starting with Windows 11. Current implementation limitations
Signature · 1 line
2.35.1
PATCH v101 5/7 dco-win: update GH Actions config file
In reply to Antonio Quartulli--- .github/workflows/build.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
.github/workflows/build.yaml +1 -6
@@ -59,11 +59,6 @@ jobs: steps: - name: Install dependencies run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip - - name: Checkout ovpn-dco-win - uses: actions/[email protected]... - with: - repository: OpenVPN/ovpn-dco-win - path: ovpn-dco-win - name: Checkout OpenVPN uses: actions/[email protected]... with:
@@ -151,7 +146,7 @@ jobs: run: cp ./tap-windows-${TAP_WINDOWS_VERSION}/include/tap-windows.h ${HOME}/mingw/opt/include/ - name: configure OpenVPN - run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig DCO_SOURCEDIR=$(realpath ../ovpn-dco-win) LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 --enable-dco + run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 working-directory: openvpn - name: build OpenVPN
Signature · 1 line
2.35.1
PATCH v101 6/7 dco-win: ensure the DCO API is not used when running on Windows
In reply to Antonio QuartulliOn Windows the high level API should still use the link_socket object to read and write packets. For this reason, even if dco_installed is true, we still need to rely on the classic link_socket object.
---
Changes from v100:
* removed ASSERTs (moved to previous patch)
* improve comment text in forward.c
--- src/openvpn/forward.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
src/openvpn/forward.c +21 -1
@@ -1601,6 +1601,26 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) } } +/* Linux-like DCO implementations pass the socket to the kernel and +* disallow usage of it from userland, so (control) packets sent and +* received by OpenVPN need to go through the DCO interface. +* +* Windows DCO needs control packets to be sent via the normal +* Socket API. +* +* Hide that complexity (...especially if more platforms show up +* in future...) in a small inline function. +*/ +static bool +should_use_dco_socket (struct link_socket *sock) +{ +#if defined(TARGET_LINUX ) +return sock->info.dco_installed; +#else +return false; +#endif +} +/* * Input: c->c2.to_link */
@@ -1674,7 +1694,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (c->c2.link_socket->info.dco_installed) +if (should_use_dco_socket (c->c2.link_socket)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,
Signature · 1 line
2.35.1
PATCH v101 7/7 dco: properly name variables
In reply to Antonio Quartullirenamed remote_addrX variables to vpn_addrX to make it clear that they refer to the address over the VPN/tunnel
--- src/openvpn/dco.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
src/openvpn/dco.c +9 -8
@@ -561,19 +561,20 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; } -struct in_addr remote_ip4 = {0 }; -struct in6_addr *remote_addr6 =NULL ; -struct in_addr *remote_addr4 =NULL ; -/* In server mode we need to fetch the remote addresses from the push config */ + +struct in_addr vpn_ip4 = {0 }; +struct in_addr *vpn_addr4 =NULL ;if (c->c2.push_ifconfig_defined) { - remote_ip4.s_addr =htonl (c->c2.push_ifconfig_local); - remote_addr4 = &remote_ip4; + vpn_ip4.s_addr =htonl (c->c2.push_ifconfig_local); + vpn_addr4 = &vpn_ip4; } + +struct in6_addr *vpn_addr6 =NULL ;if (c->c2.push_ifconfig_ipv6_defined) { - remote_addr6 = &c->c2.push_ifconfig_ipv6_local; + vpn_addr6 = &c->c2.push_ifconfig_ipv6_local; }if (dco_multi_get_localaddr (m, mi, &local))
@@ -582,7 +583,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) }int ret =dco_new_peer (&c->c1.tuntap->dco, peer_id, sd, localaddr, - remoteaddr, remote_addr4, remote_addr6); + remoteaddr, vpn_addr4, vpn_addr6);if (ret <0 ) {return ret;
Signature · 1 line
2.35.1
I stared at the code, tested with tap-windows6 with this commit and with dco driver with the latest commit in dco branch, works as expected.
All my concerns are resolved. I am still not sure if it worth to split implementation into two parts - this commit introduces set of functions which are not called yet - I am OK with that if it makes code easier to review.
Disclaimer: I contributed some code to this commit, so I might be slightly biased.
la 13. elok. 2022 klo 23.43 Antonio Quartulli ([email protected]...) kirjoitti:
Quoted 902 lines
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
Changes from v100:
* rebased (fixed conflict in configure.ac)
* fixed access todisable_dcomember indco.c
* renamedovpn-dco-win.htoovpn_dco_win.h
* maketun_open_deviceandclose_tun_handlenon static
* add ASSERT(0) to functions that should not be called on Windows
* removereal_tun_initmember (unused now)--- config-msvc.h | 2 + configure.ac | 9 +- dev-tools/special-files.lst | 1 + src/openvpn/Makefile.am | 4 +- src/openvpn/dco.c | 2 +- src/openvpn/dco_internal.h | 1 + src/openvpn/dco_win.c | 400 ++++++++++++++++++++++++++++ src/openvpn/dco_win.h | 57 ++++ src/openvpn/openvpn.vcxproj | 3 + src/openvpn/openvpn.vcxproj.filters | 9 + src/openvpn/ovpn_dco_win.h | 108 ++++++++ src/openvpn/tun.c | 4 +- src/openvpn/tun.h | 10 +- 13 files changed, 602 insertions(+), 8 deletions(-) create mode 100644 src/openvpn/dco_win.c create mode 100644 src/openvpn/dco_win.h create mode 100644 src/openvpn/ovpn_dco_win.hconfig-msvc.h +2
-0@@ -87,3 +87,5 @@ typedef uint16_t in_port_t;#ifdef HAVE_CONFIG_MSVC_LOCAL_H #include <config-msvc-local.h> #endif + +#define ENABLE_DCO 1configure.ac +1
-1@@ -144,7 +144,7 @@ AC_ARG_ENABLE( AC_ARG_ENABLE( [dco], - [AS_HELP_STRING([--enable-dco], [enable data channel offload support using ovpn-dco kernel module @<:@default=no@:>@])], + [AS_HELP_STRING([--enable-dco], [enable data channel offload support using the ovpn-dco kernel module (always enabled on Windows) @<:@default=no@:>@])],, [enable_dco="no"])
configure.ac +1
-0@@ -328,6 +328,7 @@ case "$host" in ;; *-mingw*) AC_DEFINE([TARGET_WIN32], [1], [Are we running WIN32?]) + AC_DEFINE([ENABLE_DCO], [1], [DCO is always enabled on Windows]) AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["W"], [Target prefix]) CPPFLAGS="${CPPFLAGS} -DWIN32_LEAN_AND_MEAN"CPPFLAGS="${CPPFLAGS} -DNTDDI_VERSION=NTDDI_VISTAconfigure.ac +3
-3-D_WIN32_WINNT=_WIN32_WINNT_VISTA"@@ -772,7 +773,6 @@ if test "$enable_dco" = "yes"; then dnl dnl Include generic netlink library used to talk to ovpn-dco dnl - case "$host" in *-*-linux*) PKG_CHECK_MODULES([LIBNL_GENL],@@ -792,8 +792,11 @@ dnl AC_DEFINE(ENABLE_DCO, 1, [Enable data channel offload for FreeBSD]) AC_MSG_NOTICE([Enabled ovpn-dco support for FreeBSD]) ;; + *-mingw*) + AC_MSG_NOTICE([NOTE: --enable-dco ignored on Windows because it's always enabled]) + ;; *) - AC_MSG_NOTICE([Ignoring --enable-dco on non Linuxplatform])
+ AC_MSG_NOTICE([Ignoring --enable-dco on non
supported platform]);; esacfi
dev-tools/special-files.lst +0
-0@@ -2,3 +2,4 @@ E:doc/doxygen/doc_key_generation.h # @verbatim sectiongets mistreated, excl
E:src/compat/compat-lz4.c # Preserve LZ4 upstream formatting E:src/compat/compat-lz4.h # Preserve LZ4 upstream formatting E:src/openvpn/ovpn_dco_linux.h # Preserve ovpn-dco upstreamformatting
+E:src/openvpn/ovpn_dco_win.h # Preserve ovpn-dco-win upstream
formattingsrc/openvpn/Makefile.am +2
-0@@ -56,6 +56,7 @@ openvpn_SOURCES = \ dco.c dco.h dco_internal.h \ dco_freebsd.c dco_freebsd.h \ dco_linux.c dco_linux.h \ + dco_win.c dco_win.h \ dhcp.c dhcp.h \ dns.c dns.h \ env_set.c env_set.h \@@ -79,6 +80,7 @@ openvpn_SOURCES = \ memdbg.h \ misc.c misc.h \ ovpn_dco_linux.h \ + ovpn_dco_win.h \ platform.c platform.h \ console.c console.h console_builtin.c console_systemd.c \ mroute.c mroute.h \@@ -152,5 +154,5 @@ openvpn_LDADD = \ $(OPTIONAL_INOTIFY_LIBS) if WIN32 openvpn_SOURCES += openvpn_win32_resources.rc block_dns.c block_dns.h
ring_buffer.hsrc/openvpn/Makefile.am +1
-3-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi +openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt endifsrc/openvpn/dco.c +0
-0@@ -289,7 +289,7 @@ dco_check_option_conflict(int msglevel, const struct options *o) * specified at all. In the latter case, later logic will most likelystop
* OpenVPN, so no need to print any message here. */src/openvpn/dco.c +1
-1-if (o->tuntap_options.disable_dco || !o->dev) +if (!dco_enabled (o) || !o->dev) {return false; }src/openvpn/dco_internal.h +1
-0@@ -29,6 +29,7 @@#include "dco_freebsd.h" #include "dco_linux.h" +#include "dco_win.h" /** * This file contains the internal DCO API definition. src/openvpn/dco_win.c new file +74
-0@@ -0,0 +1,400 @@ +/* +* Interface to ovpn-win-dco networking code +* +* Copyright (C) 2020-2022 Arne Schwabe <[email protected]...> +* Copyright (C) 2020-2022 OpenVPN Inc <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see the file COPYING included with this +* distribution); if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#elif defined(_MSC_VER) +#include "config-msvc.h" +#endif + +#if defined(_WIN32) + +#include "syshead.h" + +#include "dco.h" +#include "tun.h" +#include "crypto.h" +#include "ssl_common.h" + +#include <bcrypt.h> +#include <winsock2.h> +#include <ws2tcpip.h> + +#if defined(__MINGW32__) +const IN_ADDR in4addr_any = { 0 }; +#endif + +static struct tuntap +create_dco_handle(const char *devname, struct gc_arena *gc) +{ + struct tuntap tt = { .windows_driver = WINDOWS_DRIVER_DCO }; + const char *device_guid; + + tun_open_device(&tt, devname, &device_guid, gc); + + return tt; +} + +bool +ovpn_dco_init(int mode, dco_context_t *dco) +{ + return true; +} + +int +open_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev) +{ + ASSERT(0); + return 0; +} + +static void +dco_wait_ready(DWORD idx) +{ + for (int i = 0; i < 20; ++i) + { + MIB_IPINTERFACE_ROW row = {.InterfaceIndex = idx, .Family =
AF_INET};src/openvpn/dco_win.c new file +15
-0+if (GetIpInterfaceEntry (&row) !=ERROR_NOT_FOUND ) + { +break ; + } +msg (D_DCO_DEBUG ,"interface %ld not yet ready, retrying" , idx); +Sleep (50 ); + } +} + +void +dco_start_tun (struct tuntap *tt) +{ +msg (D_DCO_DEBUG ,"%s" , __func__); + +/* reference the tt object inside the DCO context, because the latter will
src/openvpn/dco_win.c new file +19
-0+* be passed around +*/ + tt->dco.tt = tt; + +DWORD bytes_returned =0 ; +if (!DeviceIoControl (tt->hand,OVPN_IOCTL_START_VPN ,NULL ,0 ,NULL ,0 , + &bytes_returned,NULL )) + { +msg (M_ERR ,"DeviceIoControl(OVPN_IOCTL_START_VPN) failed" ); + } + +/* Sometimes IP Helper API, which we use for setting IP address etc, +* complains that interface is not found. Give it some time to settle +*/ +dco_wait_ready (tt->adapter_index); +} + +static int +dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, volatile int
*signal_received)src/openvpn/dco_win.c new file +10
-0+{ +DWORD timeout_msec = timeout *1000 ; +const int poll_interval_ms =50 ; + +while (timeout_msec >0 ) + { + timeout_msec -= poll_interval_ms; + +DWORD transferred; + if (GetOverlappedResultEx(handle, ov, &transferred,
poll_interval_ms, FALSE) != 0)src/openvpn/dco_win.c new file +69
-0+ { +/* TCP connection established by dco */ +return 0 ; + } + +DWORD err =GetLastError (); +if ((err !=WAIT_TIMEOUT ) && (err !=ERROR_IO_INCOMPLETE )) + { +/* dco reported connection error */ +msg (M_NONFATAL |M_ERRNO ,"dco connect error" ); + *signal_received =SIGUSR1 ; +return -1 ; + } + +get_signal (signal_received); +if (*signal_received) + { +return -1 ; + } + +management_sleep (0 ); + } + +/* we end up here when timeout occurs in userspace */ +msg (M_NONFATAL ,"dco connect timeout" ); + *signal_received =SIGUSR1 ; + +return -1 ; +} + +struct tuntap +dco_create_socket (struct addrinfo *remoteaddr,bool bind_local, +struct addrinfo *bind,const char *devname, +struct gc_arena *gc,int timeout, +volatile int *signal_received) +{ +msg (D_DCO_DEBUG ,"%s" , __func__); + +OVPN_NEW_PEER peer = {0 }; + +struct sockaddr *local =NULL ; +struct sockaddr *remote = remoteaddr->ai_addr; + +if (remoteaddr->ai_protocol ==IPPROTO_TCP + || remoteaddr->ai_socktype ==SOCK_STREAM ) + { + peer.Proto =OVPN_PROTO_TCP ; + } +else + { + peer.Proto =OVPN_PROTO_UDP ; + } + +if (bind_local) + { +/* Use first local address with correct address family */ +while (bind && !local) + { +if (bind->ai_family == remote->sa_family) + { + local = bind->ai_addr; + } + bind = bind->ai_next; + } + } + +if (bind_local && !local) + { + msg(M_FATAL, "DCO: Socket bind failed: Address to bind lacks %srecord",
src/openvpn/dco_win.c new file +40
-0+ addr_family_name(remote->sa_family)); + } + +if (remote->sa_family ==AF_INET6 ) + { + peer.Remote.Addr6 = *((SOCKADDR_IN6 *)(remoteaddr->ai_addr)); +if (local) + { + peer.Local.Addr6 = *((SOCKADDR_IN6 *)local); + } +else + { + peer.Local.Addr6.sin6_addr = in6addr_any; + peer.Local.Addr6.sin6_port =0 ; + peer.Local.Addr6.sin6_family =AF_INET6 ; + } + } +else if (remote->sa_family ==AF_INET ) + { + peer.Remote.Addr4 = *((SOCKADDR_IN *)(remoteaddr->ai_addr)); +if (local) + { + peer.Local.Addr4 = *((SOCKADDR_IN *)local); + } +else + { + peer.Local.Addr4.sin_addr = in4addr_any; + peer.Local.Addr4.sin_port =0 ; + peer.Local.Addr4.sin_family =AF_INET ; + } + } +else + { +ASSERT (0 ); + } + +struct tuntap tt =create_dco_handle (devname, gc); + +OVERLAPPED ov = {0 }; + if (!DeviceIoControl(tt.hand, OVPN_IOCTL_NEW_PEER, &peer,sizeof(peer), NULL, 0, NULL, &ov))
src/openvpn/dco_win.c new file +9
-0+ { +DWORD err =GetLastError (); +if (err !=ERROR_IO_PENDING ) + { +msg (M_ERR ,"DeviceIoControl(OVPN_IOCTL_NEW_PEER) failed" ); + } +else + { + if (dco_connect_wait(tt.hand, &ov, timeout, signal_received)< 0)
src/openvpn/dco_win.c new file +21
-0+ { +close_tun_handle (&tt); + } + } + } +return tt; +} + +int +dco_new_peer (dco_context_t *dco,unsigned int peerid,int sd, +struct sockaddr *localaddr,struct sockaddr *remoteaddr, +struct in_addr *remote_in4,struct in6_addr *remote_in6) +{ +msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d" , __func__, peerid, sd); +return 0 ; +} + +int +dco_del_peer (dco_context_t *dco,unsigned int peerid) +{ + msg(D_DCO_DEBUG, "%s: peer-id %d - not implemented", __func__,peerid);
src/openvpn/dco_win.c new file +21
-0+return 0 ; +} + +int +dco_set_peer (dco_context_t *dco,unsigned int peerid, +int keepalive_interval,int keepalive_timeout,int mss) +{ +msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, + peerid, keepalive_interval, keepalive_timeout, mss); + +OVPN_SET_PEER peer; + + peer.KeepaliveInterval = keepalive_interval; + peer.KeepaliveTimeout = keepalive_timeout; + peer.MSS = mss; + +DWORD bytes_returned =0 ; +if (!DeviceIoControl (dco->tt->hand,OVPN_IOCTL_SET_PEER , &peer, +sizeof (peer),NULL ,0 , &bytes_returned,NULL )) + { + msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_SET_PEER)failed");
src/openvpn/dco_win.c new file +40
-0+return -1 ; + } +return 0 ; +} + +int +dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, + dco_key_slot_t slot, + const uint8_t *encrypt_key, const uint8_t *encrypt_iv, + const uint8_t *decrypt_key, const uint8_t *decrypt_iv, + const char *ciphername) +{ + msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", + __func__, slot, keyid, peerid, ciphername); + + const int nonce_len = 8; + size_t key_len = cipher_kt_key_size(ciphername); + + OVPN_CRYPTO_DATA crypto_data; + ZeroMemory(&crypto_data, sizeof(crypto_data)); + + crypto_data.CipherAlg = dco_get_cipher(ciphername); + crypto_data.KeyId = keyid; + crypto_data.PeerId = peerid; + crypto_data.KeySlot = slot; + + CopyMemory(crypto_data.Encrypt.Key, encrypt_key, key_len); + crypto_data.Encrypt.KeyLen = (char)key_len; + CopyMemory(crypto_data.Encrypt.NonceTail, encrypt_iv, nonce_len); + + CopyMemory(crypto_data.Decrypt.Key, decrypt_key, key_len); + crypto_data.Decrypt.KeyLen = (char)key_len; + CopyMemory(crypto_data.Decrypt.NonceTail, decrypt_iv, nonce_len); + + ASSERT(crypto_data.CipherAlg > 0); + + DWORD bytes_returned = 0; + + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_NEW_KEY, &crypto_data, + sizeof(crypto_data), NULL, 0, &bytes_returned,NULL))
src/openvpn/dco_win.c new file +10
-0+ { +msg (M_ERR ,"DeviceIoControl(OVPN_IOCTL_NEW_KEY) failed" ); +return -1 ; + } +return 0 ; +} +int +dco_del_key (dco_context_t *dco,unsigned int peerid,dco_key_slot_t slot) +{ + msg(D_DCO, "%s: peer-id %d, slot %d called but ignored", __func__,peerid,
src/openvpn/dco_win.c new file +12
-0+ slot); +/* FIXME: Implement in driver first */ +return 0 ; +} + +int +dco_swap_keys(dco_context_t *dco, unsigned int peer_id) +{ + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peer_id); + + DWORD bytes_returned = 0; + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_SWAP_KEYS, NULL, 0,NULL, 0,
src/openvpn/dco_win.c new file +48
-0+ &bytes_returned, NULL)) + { +msg (M_ERR ,"DeviceIoControl(OVPN_IOCTL_SWAP_KEYS) failed" ); +return -1 ; + } +return 0 ; +} + +bool +dco_available (int msglevel) +{ +return true; +} + +int +dco_do_read (dco_context_t *dco) +{ +/* no-op on windows */ +ASSERT (0 ); +return 0 ; +} + +int +dco_do_write (dco_context_t *dco,int peer_id,struct buffer *buf) +{ +/* no-op on windows */ +ASSERT (0 ); +return 0 ; +} + +void +dco_event_set (dco_context_t *dco,struct event_set *es,void *arg) +{ +/* no-op on windows */ +ASSERT (0 ); +} + +const char * +dco_get_supported_ciphers () +{ +/* +* this API can be called either from user mode or kernel mode, +* which enables us to probe driver's chachapoly support +* (available starting from Windows 11) +*/ + +BCRYPT_ALG_HANDLE h; + NTSTATUS status = BCryptOpenAlgorithmProvider(&h,L"CHACHA20_POLY1305", NULL, 0);
src/openvpn/dco_win.c new file +12
-0+if (BCRYPT_SUCCESS (status)) + { +BCryptCloseAlgorithmProvider (h,0 ); +return "AES-128-GCM:AES-256-GCM:AES-192-GCM:CHACHA20-POLY1305" ; + } +else + { +return "AES-128-GCM:AES-256-GCM:AES-192-GCM" ; + } +} + +#endif /* defined(_WIN32) */ src/openvpn/dco_win.h new file +57
-0@@ -0,0 +1,57 @@ +/* +* Interface to ovpn-win-dco networking code +* +* Copyright (C) 2020-2022 Arne Schwabe <[email protected]...> +* Copyright (C) 2020-2022 OpenVPN Inc <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see the file COPYING included with this +* distribution); if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef DCO_WIN_H +#define DCO_WIN_H + +#if defined(ENABLE_DCO ) && defined(_WIN32) + +#include "buffer.h" +#include "ovpn_dco_win.h" + +typedef OVPN_KEY_SLOT dco_key_slot_t ; +typedef OVPN_CIPHER_ALG dco_cipher_t ; + +struct dco_context { +struct tuntap *tt; +}; + +typedef struct dco_context dco_context_t ; + +struct tuntap +dco_create_socket (struct addrinfo *remoteaddr,bool bind_local, +struct addrinfo *bind,const char *devname, +struct gc_arena *gc,int timeout, +volatile int *signal_received); + +void +dco_start_tun (struct tuntap *tt); + +#else /* if defined(ENABLE_DCO) && defined(_WIN32) */ + +static inline void +dco_start_tun (struct tuntap *tt) +{ +ASSERT (false); +} + +#endif /* defined(_WIN32) */ +#endif /* ifndef DCO_H */ src/openvpn/openvpn.vcxproj +3
-0@@ -278,6 +278,7 @@ <ClCompile Include="cryptoapi.c" /> <ClCompile Include="dco.c" /> <ClCompile Include="dco_linux.c" /> + <ClCompile Include="dco_win.c" /> <ClCompile Include="dhcp.c" /> <ClCompile Include="dns.c" /> <ClCompile Include="env_set.c" />@@ -367,6 +368,7 @@ <ClInclude Include="dco.h" /> <ClInclude Include="dco_internal.h" /> <ClInclude Include="dco_linux.h" /> + <ClInclude Include="dco_win.h" /> <ClInclude Include="dhcp.h" /> <ClInclude Include="dns.h" /> <ClInclude Include="env_set.h" />@@ -402,6 +404,7 @@ <ClInclude Include="options.h" /> <ClInclude Include="otime.h" /> <ClInclude Include="ovpn_dco_linux.h" /> + <ClInclude Include="ovpn_dco_win.h" /> <ClInclude Include="packet_id.h" /> <ClInclude Include="perf.h" /> <ClInclude Include="ping.h" />src/openvpn/openvpn.vcxproj.filters +9
-0@@ -42,6 +42,9 @@ <ClCompile Include="dco_linux.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="dco_win.c"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="dhcp.c"> <Filter>Source Files</Filter> </ClCompile>@@ -314,6 +317,9 @@ <ClInclude Include="dco_linux.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="dco_win.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="dhcp.h"> <Filter>Header Files</Filter> </ClInclude>@@ -416,6 +422,9 @@ <ClInclude Include="ovpn_dco_linux.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ovpn_dco_win.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="packet_id.h"> <Filter>Header Files</Filter> </ClInclude>src/openvpn/ovpn_dco_win.h new file +17
-0@@ -0,0 +1,108 @@ +/* +* ovpn-dco-win OpenVPN protocol accelerator for Windows +* +* Copyright (C) 2020-2021 OpenVPN Inc <[email protected]...> +* +* Author: Lev Stipakov <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * This particular file (uapi.h) is also licensed using the MIT license (see COPYRIGHT.MIT).
+ */src/openvpn/ovpn_dco_win.h new file +62
-0+ +#pragma once +#ifndef _KERNEL_MODE +#include <winsock2.h> +#endif +#include <ws2def.h> +#include <ws2ipdef.h> + +typedef enum { +OVPN_PROTO_UDP , +OVPN_PROTO_TCP +}OVPN_PROTO ; + +typedef struct _OVPN_NEW_PEER { +union { +SOCKADDR_IN Addr4; +SOCKADDR_IN6 Addr6; + } Local; + +union { +SOCKADDR_IN Addr4; +SOCKADDR_IN6 Addr6; + } Remote; + +OVPN_PROTO Proto; +}OVPN_NEW_PEER , *POVPN_NEW_PEER ; + +typedef struct _OVPN_STATS { +LONG LostInControlPackets; +LONG LostOutControlPackets; + +LONG LostInDataPackets; +LONG LostOutDataPackets; + +LONG ReceivedDataPackets; +LONG ReceivedControlPackets; + +LONG SentControlPackets; +LONG SentDataPackets; + +LONG64 TransportBytesSent; +LONG64 TransportBytesReceived; + +LONG64 TunBytesSent; +LONG64 TunBytesReceived; +}OVPN_STATS , *POVPN_STATS ; + +typedef enum _OVPN_KEY_SLOT { +OVPN_KEY_SLOT_PRIMARY , +OVPN_KEY_SLOT_SECONDARY +}OVPN_KEY_SLOT ; + +typedef enum _OVPN_CIPHER_ALG { +OVPN_CIPHER_ALG_NONE , +OVPN_CIPHER_ALG_AES_GCM , +OVPN_CIPHER_ALG_CHACHA20_POLY1305 +}OVPN_CIPHER_ALG ; + +typedef struct _OVPN_KEY_DIRECTION +{ + unsigned char Key[32]; + unsigned char KeyLen; // 16/24/32 ->AES-128-GCM/AES-192-GCM/AES-256-GCM
src/openvpn/ovpn_dco_win.h new file +19
-0+unsigned char NonceTail[8 ]; +}OVPN_KEY_DIRECTION ; + +typedef struct _OVPN_CRYPTO_DATA { +OVPN_KEY_DIRECTION Encrypt; +OVPN_KEY_DIRECTION Decrypt; +OVPN_KEY_SLOT KeySlot; +OVPN_CIPHER_ALG CipherAlg; +unsigned char KeyId; +int PeerId; +}OVPN_CRYPTO_DATA , *POVPN_CRYPTO_DATA ; + +typedef struct _OVPN_SET_PEER { +LONG KeepaliveInterval; +LONG KeepaliveTimeout; +LONG MSS; +}OVPN_SET_PEER , *POVPN_SET_PEER ; + +#define OVPN_IOCTL_NEW_PEER CTL_CODE(FILE_DEVICE_UNKNOWN, 1,
METHOD_BUFFERED,FILE_ANY_ACCESS)
+#defineOVPN_IOCTL_GET_STATSCTL_CODE(FILE_DEVICE_UNKNOWN, 2,METHOD_BUFFERED,FILE_ANY_ACCESS)
+#defineOVPN_IOCTL_NEW_KEYCTL_CODE(FILE_DEVICE_UNKNOWN, 3,METHOD_BUFFERED,FILE_ANY_ACCESS)
+#defineOVPN_IOCTL_SWAP_KEYSCTL_CODE(FILE_DEVICE_UNKNOWN, 4,METHOD_BUFFERED,FILE_ANY_ACCESS)
+#defineOVPN_IOCTL_SET_PEERCTL_CODE(FILE_DEVICE_UNKNOWN, 5,METHOD_BUFFERED,FILE_ANY_ACCESS)
+#defineOVPN_IOCTL_START_VPNCTL_CODE(FILE_DEVICE_UNKNOWN, 6,METHOD_BUFFERED,FILE_ANY_ACCESS)src/openvpn/tun.c +1
-1@@ -6532,7 +6532,7 @@ tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct dev return true; } -static void +void tun_open_device (struct tuntap *tt,const char *dev_node,const char **device_guid,struct gc_arena *gc){ const struct tap_reg *tap_reg = get_tap_reg(gc);src/openvpn/tun.c +0
-0@@ -6824,7 +6824,7 @@ netsh_delete_address_dns(const struct tuntap *tt,bool ipv6, struct
gc_arena*gcargv_free(&argv);}
src/openvpn/tun.c +1
-1-static void +void close_tun_handle (struct tuntap *tt) {const char *adaptertype =print_windows_driver (tt->windows_driver);src/openvpn/tun.h +9
-1@@ -48,7 +48,8 @@enum windows_driver_type {WINDOWS_DRIVER_UNSPECIFIED ,WINDOWS_DRIVER_TAP_WINDOWS6 , -WINDOWS_DRIVER_WINTUN +WINDOWS_DRIVER_WINTUN , +WINDOWS_DRIVER_DCO };#endif @@ -64,6 +65,8 @@ struct tuntap_options {/* --ip-win32 options */ bool ip_win32_defined; +bool disable_dco; +#define IPW32_SET_MANUAL 0/* "--ip-win32 manual" */ #define IPW32_SET_NETSH 1/* "--ip-win32 netsh" */ #define IPW32_SET_IPAPI 2/* "--ip-win32 ipapi" */ @@ -259,6 +262,11 @@ void open_tun(const char *dev, const char *dev_type,const char *dev_node, void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx); +void tun_open_device (struct tuntap *tt,const char *dev_node, +const char **device_guid,struct gc_arena *gc); + +void close_tun_handle (struct tuntap *tt); +int write_tun (struct tuntap *tt,uint8_t *buf,int len);int
read_tun(struct tuntap *tt, uint8_t *buf, int len);
--
2.35.1_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
Re: [Openvpn-devel] [PATCH v101 2/7] dco-win: check for incompatible options
In reply to Antonio QuartulliAgain, this cannot be tested yet.
Stared at the code and tested with follow-up commits, looks good and works as expected.
la 13. elok. 2022 klo 23.43 Antonio Quartulli ([email protected]...) kirjoitti:
Quoted 81 lines
At the moment dco-win doesn't support --persist-tun and --server, so check for these options at startup time.
Signed-off-by Antonio Quartulli <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>---
Changes from v100:
* improved commit title/message--- src/openvpn/dco.c | 17 +++++++++++++++-- src/openvpn/options.c | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)src/openvpn/dco.c +4
-1@@ -221,7 +221,20 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi) static bool dco_check_option_conflict_platform(int msglevel, const struct options *o) { -#if defined(TARGET_LINUX ) +#if defined(_WIN32) + if (o->mode == MODE_SERVER) + { + msg(msglevel, "Only client and p2p data channel offload issupported "
src/openvpn/dco.c +7
-0+ "with ovpn-dco-win."); +return false; + } + +if (o->persist_tun) + { + msg(msglevel, "--persist-tun is not supported withovpn-dco-win.");
src/openvpn/dco.c +3
-0+ return false; + } +#elif defined(TARGET_LINUX)/* if the device name is fixed, we need to check if an interface with this
* name already exists. IF it does, it must be a DCO interface,
otherwise
* DCO has to be disabled in order to continue.src/openvpn/dco.c +1
-1@@ -246,7 +259,7 @@ dco_check_option_conflict_platform(int msglevel, const struct options *o) strerror(-ret), ret); } } -#endif /* if defined(TARGET_LINUX) */ +#endif /* if defined(_WIN32) */ return true; }src/openvpn/options.c +5
-0@@ -2450,6 +2450,11 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--windows-driver wintun requires --dev tun" ); } + +if (options->windows_driver ==WINDOWS_DRIVER_DCO ) + { +dco_check_option_conflict (M_USAGE , options); + }#endif /* ifdef _WIN32 */ /*--
2.35.1_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
PATCH v102 6/7 dco-win: ensure the DCO API is not used when running on Windows
In reply to Antonio QuartulliOn Windows the high level API should still use the link_socket object to read and write packets. For this reason, even if dco_installed is true, we still need to rely on the classic link_socket object.
---
Changes from v101:
* add defined(TARGET_FREEBSD) to the #if guard
Changes from v100:
* removed ASSERTs (moved to previous patch)
* improve comment text in forward.c
--- src/openvpn/forward.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
src/openvpn/forward.c +21 -1
@@ -1601,6 +1601,26 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) } } +/* Linux-like DCO implementations pass the socket to the kernel and +* disallow usage of it from userland, so (control) packets sent and +* received by OpenVPN need to go through the DCO interface. +* +* Windows DCO needs control packets to be sent via the normal +* Socket API. +* +* Hide that complexity (...especially if more platforms show up +* in future...) in a small inline function. +*/ +static bool +should_use_dco_socket (struct link_socket *sock) +{ +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) +return sock->info.dco_installed; +#else +return false; +#endif +} +/* * Input: c->c2.to_link */
@@ -1674,7 +1694,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (c->c2.link_socket->info.dco_installed) +if (should_use_dco_socket (c->c2.link_socket)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH v102 6/7] dco-win: ensure the DCO API is not used when running on Windows
Hi,
Quoted 3 lines
On Windows the high level API should still use the
link_socketobject to read and write packets. For this reason, even ifdco_installedis true, we still need to rely on the classiclink_socketobject.
This is true.
Quoted 4 lines
+ *
+ * Windows DCO needs control packets to be sent via the normal
+ * Socket API.
This is a bit confusing IMHO. What does "Socket API" mean here? To read/write control packets we use what Windows calls "Overlapped I/O", basically asynchronous IO with Write/ReadFile and events. We do not use Winsock API, even though the OpenVPN function we use is called "link_socket_write_win32()".
I would change the above mentioned comment to "normal Overlapped I/O". Maybe this could be done at commit.
Also, as mentioned in chat, this should be merged before 3/7 ("dco-win: implement ovpn-dco support in P2P Windows code path").
-Lev
PATCH v103 6/7 dco-win: ensure the DCO API is not used when running on Windows
In reply to Antonio QuartulliOn Windows the high level API should still use the link_socket object to read and write packets. For this reason, even if dco_installed is true, we still need to rely on the classic link_socket object.
---
Changes from v102:
* mark helper as 'inline'
* improve comment wording (by Lev)
Changes from v101:
* add defined(TARGET_FREEBSD) to the #if guard
Changes from v100:
* removed ASSERTs (moved to previous patch)
* improve comment text in forward.c
--- src/openvpn/forward.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
src/openvpn/forward.c +21 -1
@@ -1601,6 +1601,26 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) } } +/* Linux-like DCO implementations pass the socket to the kernel and +* disallow usage of it from userland, so (control) packets sent and +* received by OpenVPN need to go through the DCO interface. +* +* Windows DCO needs control packets to be sent via the normal +* standard Overlapped I/O. +* +* Hide that complexity (...especially if more platforms show up +* in future...) in a small inline function. +*/ +static inline bool +should_use_dco_socket (struct link_socket *sock) +{ +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) +return sock->info.dco_installed; +#else +return false; +#endif +} +/* * Input: c->c2.to_link */
@@ -1674,7 +1694,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (c->c2.link_socket->info.dco_installed) +if (should_use_dco_socket (c->c2.link_socket)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,
Signature · 1 line
2.35.1
[Openvpn-devel] [PATCH applied] Re: dco: properly name variables
In reply to Antonio QuartulliThanks for that. This really helps understanding which address is which.
Mechanical rename, so "trivial", but still tested on the Linux DCO test rig :-)
Interesting enough, uncrustify did not catch this whitespace error
+ vpn_ip4.s_addr = htonl(c->c2.push_ifconfig_local);
"two blanks before htonl()" -> fixed.
Your patch has been applied to the master branch.
commit cea978bcb60a3b18be6d227466702fb14d6bc490
Author: Antonio Quartulli Date: Sat Aug 13 22:42:24 2022 +0200
dco: properly name variables
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24916.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: dco-win: ensure the DCO API is not used when running on Windows
In reply to Antonio QuartulliTaking the ACK from Lev on 102, applying to 103 - which mostly has "better wording". I have tested this on the DCO test rig, and it's fine with the change.
I wouldn't be surprised to see more work in this area for "we need to be able to send packets to not-yet-authenticated remotes in p2p mode", though... :-)
Your patch has been applied to the master branch.
commit d4f2209cdb4dfda32f36fa750d97b7e1ba751a4d
Author: Antonio Quartulli Date: Sun Aug 14 10:51:17 2022 +0200
dco-win: ensure the DCO API is not used when running on Windows
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24929.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v101 2/7] dco-win: check for incompatible options
In reply to Antonio QuartulliHi,
Quoted 2 lines · Antonio Quartulli
At the moment dco-win doesn't support --persist-tun and --server, so check for these options at startup time.
This needs rebasing anyway (due to the startup change), but while at it...
src/openvpn/options.c options_postprocess_verify_ce(const struct options *options, · line 2457
Quoted 5 lines
src/openvpn/options.c +5
-0+ +if (options->windows_driver ==WINDOWS_DRIVER_DCO ) + { +dco_check_option_conflict (M_USAGE , options); + }
... this should read "if (dco_enabled(options))", no? Patch 3/7 changes dco_enabled() to do exactly this "if (driver == WINDOWS_DRIVER_DCO)" and it would make *this* function more clear.
OTOH, the first thing dco_check_options_conflict() does is "check if DCO is enabled at all", so why check it in the caller again?
Staring at this for a while, I do wonder why we do the "linux DCO" options check in options_postprocess_mutate(), and the "Win32 DCO" options check in options_postprocess_verify_ce() (while it does not look at the actual ->ce entries, and really *really* does not belong).
Can we please clean this up, and have one joint call for all DCO platforms? I see no good reason for having two calls to the same function, doing the same thing, in two different call chains for different OSes.
Now there is a material difference, if the Win32 invocation finds a dco-incompatible option, it will exit M_USAGE, while Linux will just disable DCO - if this is what we want, we should still keep the stuff closer together, like
/* check if any option should force disabling DCO */
#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
o->tuntap_options.disable_dco = !dco_check_option_conflict(D_DCO, o)
|| !dco_check_startup_option_conflict(D_DCO,
o);
#else if _WIN32
/* we can not currently fallback to non-DCO on Windows, so exit M_USAGE
* if an option conflict is discovered */
dco_check_option_conflict(M_USAGE, o);
dco_check_startup_option_conflict(M_USAGE, o);#endif
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]...PATCH 2/7 dco-win: check for incompatible options
In reply to Antonio QuartulliAt the moment dco-win doesn't support --persist-tun and --server, so check for these options at startup time.
---
Changes from v101:
* rebased
* remove call to dco_check_option_ from verify() and reuse invocation that was already implemented for linux/freebsd in mutate_ce()
* hide log level to use in case of option check failure inside dco_win/linux/freebsd.h
Changes from v100:
* improved commit title/message
--- src/openvpn/dco.c | 17 +++++++++++++++-- src/openvpn/dco_freebsd.h | 3 +++ src/openvpn/dco_linux.h | 3 +++ src/openvpn/dco_win.h | 5 +++++ src/openvpn/options.c | 6 ++---- 5 files changed, 28 insertions(+), 6 deletions(-)
src/openvpn/dco.c +15 -2
@@ -225,7 +225,20 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)bool dco_check_startup_option_conflict (int msglevel,const struct options *o) { -#if defined(TARGET_LINUX ) +#if defined(_WIN32) +if (o->mode ==MODE_SERVER ) + { +msg (msglevel,"Only client and p2p data channel offload is supported " +"with ovpn-dco-win." ); +return false; + } + +if (o->persist_tun) + { +msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +return false; + } +#elif defined(TARGET_LINUX )/* if the device name is fixed, we need to check if an interface with this * name already exists. IF it does, it must be a DCO interface, otherwise * DCO has to be disabled in order to continue.
@@ -250,7 +263,7 @@ dco_check_startup_option_conflict(int msglevel, const struct options *o) strerror(-ret), ret); } } -#endif /* if defined(TARGET_LINUX) */ +#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )/* DCO can't operate without CAP_NET_ADMIN. To retain it when switching user
src/openvpn/dco_freebsd.h +3 -0
@@ -27,6 +27,9 @@#include "ovpn_dco_freebsd.h" +/* define to what log level we print when a conflicting option is found */ +#define DCO_CHECK_OPTION_LEVEL D_DCO +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_key_cipher dco_cipher_t ;
src/openvpn/dco_linux.h +3 -0
@@ -31,6 +31,9 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* define to what log level we print when a conflicting option is found */ +#define DCO_CHECK_OPTION_LEVEL D_DCO +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ;
src/openvpn/dco_win.h +5 -0
@@ -27,6 +27,11 @@#include "buffer.h" #include "ovpn_dco_win.h" +/* define to what log level we print when a conflicting option is found. +* On windows we can't fallback to non-DCO so we bail out with M_USAGE +*/ +#define DCO_CHECK_OPTION_LEVEL M_USAGE +typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ;
src/openvpn/options.c +2 -4
@@ -3670,10 +3670,8 @@ options_postprocess_mutate(struct options *o, struct env_set *es) }/* check if any option should force disabling DCO */ -#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) - o->tuntap_options.disable_dco = !dco_check_option_conflict (D_DCO , o) - || !dco_check_startup_option_conflict (D_DCO , o); -#endif + o->tuntap_options.disable_dco = !dco_check_option_conflict (DCO_CHECK_OPTION_LEVEL , o) + || !dco_check_startup_option_conflict (DCO_CHECK_OPTION_LEVEL , o);if (dco_enabled (o) && o->dev_node) {
Signature · 1 line
2.30.2
Re: [Openvpn-devel] [PATCH v102i 2/7] dco-win: check for incompatible options
Hi,
src/openvpn/options.c options_postprocess_mutate(struct options *o, struct env_set *es) · line 3674
Quoted 6 lines · Antonio Quartulli
src/openvpn/options.c +2
-4-#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) - o->tuntap_options.disable_dco = !dco_check_option_conflict (D_DCO , o) - || !dco_check_startup_option_conflict (D_DCO , o); -#endif + o->tuntap_options.disable_dco = !dco_check_option_conflict (DCO_CHECK_OPTION_LEVEL , o) + || !dco_check_startup_option_conflict (DCO_CHECK_OPTION_LEVEL , o);
Nah, this is not good.
This reads as "this is code which will always return, and will log with some arbitrary log level" (how would a reader know that D_DCO and DCO_CHECK_OPTION_LEVEL is not both coming from errror.h?).
Make it explicit, and explain why.
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]...PATCH v103 2/7 dco-win: check for incompatible options
In reply to Antonio QuartulliAt the moment dco-win doesn't support --persist-tun and --server, so check for these options at startup time.
---
Changes from v102:
* remove platform defined log level and make check_options_ calls on Windows explicit and document why.
Changes from v101:
* rebased
* remove call to dco_check_option_ from verify() and reuse invocation that was already implemented for linux/freebsd in mutate_ce()
* hide log level to use in case of option check failure inside dco_win/linux/freebsd.h
Changes from v100:
* improved commit title/message
--- src/openvpn/dco.c | 17 +++++++++++++++-- src/openvpn/options.c | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-)
src/openvpn/dco.c +15 -2
@@ -225,7 +225,20 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)bool dco_check_startup_option_conflict (int msglevel,const struct options *o) { -#if defined(TARGET_LINUX ) +#if defined(_WIN32) +if (o->mode ==MODE_SERVER ) + { +msg (msglevel,"Only client and p2p data channel offload is supported " +"with ovpn-dco-win." ); +return false; + } + +if (o->persist_tun) + { +msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +return false; + } +#elif defined(TARGET_LINUX )/* if the device name is fixed, we need to check if an interface with this * name already exists. IF it does, it must be a DCO interface, otherwise * DCO has to be disabled in order to continue.
@@ -250,7 +263,7 @@ dco_check_startup_option_conflict(int msglevel, const struct options *o) strerror(-ret), ret); } } -#endif /* if defined(TARGET_LINUX) */ +#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )/* DCO can't operate without CAP_NET_ADMIN. To retain it when switching user
src/openvpn/options.c +7 -1
@@ -3669,10 +3669,16 @@ options_postprocess_mutate(struct options *o, struct env_set *es) "incompatible with each other."); } +#if defined(TARGET_LINUX ) && defined(TARGET_FREEBSD )/* check if any option should force disabling DCO */ -#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) o->tuntap_options.disable_dco = !dco_check_option_conflict (D_DCO , o) || !dco_check_startup_option_conflict (D_DCO , o); +#elif defined(_WIN32) +/* in Windows we have no 'fallback to non-DCO' strategy, so if a conflicting +* option is found, we simply bail out by means of M_USAGE +*/ +dco_check_option_conflict (M_USAGE , o); +dco_check_startup_option_conflict (M_USAGE , o);#endif if (dco_enabled (o) && o->dev_node)
Signature · 1 line
2.30.2
I've stared at the code for a while... I'm not really happy with the jumping back and forth between dco.c and tun.c (who is supposed to understand that code flow in 6 weeks from now?). That said, the "non windows" changes in this patch are harmless enough, and the "windows bits" do look safe enough (wrt memory issues etc).
I notice a distinct lack of comments on "what do all these functions do?" - neither dco_win.h nor dco_win.c have function descriptions (what does it do, what goes in, what comes out). Like, dco_connect_wait() or dco_create_socket()... this really should be improved.
Some constructs nest too deeply...
+ DWORD err = GetLastError();
+ if (err != ERROR_IO_PENDING)
+ {
+ msg(M_ERR, "DeviceIoControl(OVPN_IOCTL_NEW_PEER) failed");
+ }
+ else
+ {+ if (dco_connect_wait(tt.hand, &ov, timeout, signal_received) < 0)
+ {
+ close_tun_handle(&tt);
+ }
+ }
.. M_ERR does not return, so why have an else { } level here?
+ OVPN_CRYPTO_DATA crypto_data;
+ ZeroMemory(&crypto_data, sizeof(crypto_data));
.. we do have CLEAR(crypto_data) for this purpose. Do not invent new code for each platform to zeroize memory.
+ ASSERT(crypto_data.CipherAlg > 0);
this looks a bit out of place, 10+ lines after the CipherAlg assignment...
Since I currently can't build MinGW, I've pushed this to Github for building, and the GHA-mingw/mingw64 builds succeed (and so does the rest).
I've also subjected this to the linux DCO test rig "to be sure" - though *these* changes really should not upset other platforms. Seems they do not :-)
My local git hook complains about formatting of ovpn_dco_win.h - we do exclude that now in dev-tools/special-files.lst, but that is not effective on the initial commit. Not sure, though, why we want to maintain something only maintained by us in a different coding style... I can see this for dco-linux (where "the Linux people" want a different style) - but here?
Anyway.
Your patch has been applied to the master branch.
commit 8b80cbc3846a56581e373a664db20d227a90120a
Author: Antonio Quartulli Date: Sat Aug 13 22:42:18 2022 +0200
dco-win: introduce low-level code for handling ovpn-dco-win in Windows
Signed-off-by: Arne Schwabe <[email protected]...>
Signed-off-by: Lev Stipakov <[email protected]...>
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24919.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v103 2/7] dco-win: check for incompatible options
In reply to Antonio QuartulliHi,
Quoted 5 lines · Antonio Quartulli
At the moment dco-win doesn't support --persist-tun and --server, so check for these options at startup time.
Signed-off-by Antonio Quartulli <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>
I was about to merge this (and thank you for bearing with a grumpy old man's preferences ;-) - but I really think that the difference in these platforms need to stand out right there...).
Butbut...
This breaks Linux/Non-DCO builds with --dev tun30, and I can't see an obvious reason *why*
$ src/openvpn/openvpn --version OpenVPN 2.6_git [git:vw/master/f10c870c140bd3c6] x86_64-pc-linux-gnu [SSL (mbed TLS)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] built on Aug 18 2022
(no DCO here, this is "master + 2/7 v103", on Linux)
$ openvpn ... --dev tun30 --proto udp ... ... 2022-08-18 21:43:52 OPTIONS IMPORT: peer-id set 2022-08-18 21:43:52 OPTIONS IMPORT: data channel crypto options modified 2022-08-18 21:43:52 net_route_v4_best_gw query: dst 0.0.0.0 2022-08-18 21:43:52 net_route_v4_best_gw result: via 195.30.8.94 dev ens160 2022-08-18 21:43:52 GDG6: remote_host_ipv6=n/a 2022-08-18 21:43:52 net_route_v6_best_gw query: dst :: 2022-08-18 21:43:52 net_route_v6_best_gw result: via 2001:608:1:995a::ffff dev ens160 2022-08-18 21:43:52 DCO device tun30 opened 2022-08-18 21:43:52 net_iface_mtu_set: rtnl: cannot get ifindex for tun30: No such device (errno=19) 2022-08-18 21:43:52 Linux can't set mtu (1500) on tun30 2022-08-18 21:43:52 Exiting due to fatal error
why is it talking about DCO here? Why would it even *know* about DCO in a non-DCO build?
Not sure why any of the hunks in this patch have an effect, but if I go back to the current master, --dev tun30 works, both with and without --enable-dco.
*scratch head*
Ow.
+#if defined(TARGET_LINUX) && defined(TARGET_FREEBSD)
/* check if any option should force disabling DCO */
-#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
this is not "just moving" these lines, but requiring "LEENUX AND FREEBSD" now...
You owe me a beer :-)
(Changing the && to || makes the --dev tun30 test pass again - I'm still not sure *what* happened here... but maybe we should reconsider the decision to have disable_dco default to "false" even on non-DCO builds...)
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]...PATCH v104 1/1 dco-win: check for incompatible options
In reply to Antonio QuartulliAt the moment dco-win doesn't support --persist-tun and --server, so check for these options at startup time.
---
Changes from v103:
* fix ifdef condition (use || instead of &&) in options.c
Changes from v102:
* remove platform defined log level and make check_options_ calls on Windows explicit and document why.
Changes from v101:
* rebased
* remove call to dco_check_option_ from verify() and reuse invocation that was already implemented for linux/freebsd in mutate_ce()
* hide log level to use in case of option check failure inside dco_win/linux/freebsd.h
Changes from v100:
* improved commit title/message
--- src/openvpn/dco.c | 17 +++++++++++++++-- src/openvpn/options.c | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-)
src/openvpn/dco.c +15 -2
@@ -225,7 +225,20 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)bool dco_check_startup_option_conflict (int msglevel,const struct options *o) { -#if defined(TARGET_LINUX ) +#if defined(_WIN32) +if (o->mode ==MODE_SERVER ) + { +msg (msglevel,"Only client and p2p data channel offload is supported " +"with ovpn-dco-win." ); +return false; + } + +if (o->persist_tun) + { +msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +return false; + } +#elif defined(TARGET_LINUX )/* if the device name is fixed, we need to check if an interface with this * name already exists. IF it does, it must be a DCO interface, otherwise * DCO has to be disabled in order to continue.
@@ -250,7 +263,7 @@ dco_check_startup_option_conflict(int msglevel, const struct options *o) strerror(-ret), ret); } } -#endif /* if defined(TARGET_LINUX) */ +#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )/* DCO can't operate without CAP_NET_ADMIN. To retain it when switching user
src/openvpn/options.c +7 -1
@@ -3669,10 +3669,16 @@ options_postprocess_mutate(struct options *o, struct env_set *es) "incompatible with each other."); } -/* check if any option should force disabling DCO */ #if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) +/* check if any option should force disabling DCO */ o->tuntap_options.disable_dco = !dco_check_option_conflict (D_DCO , o) || !dco_check_startup_option_conflict (D_DCO , o); +#elif defined(_WIN32) +/* in Windows we have no 'fallback to non-DCO' strategy, so if a conflicting +* option is found, we simply bail out by means of M_USAGE +*/ +dco_check_option_conflict (M_USAGE , o); +dco_check_startup_option_conflict (M_USAGE , o);#endif if (dco_enabled (o) && o->dev_node)
Signature · 1 line
2.30.2
[Openvpn-devel] [PATCH applied] Re: dco-win: check for incompatible options
"This one is better" :-)
Test built via GHA for MSVC, tested on Linux non-DCO / DCO client and DCO server. This time, neither "non DCO" nor "DCO build" exhibited any surprises (as expected).
Not tested actual Windows build, but the checks match the commit message (and the discussions on what works and what doesn't).
Your patch has been applied to the master branch.
commit 8c3b7c11d1212a6521e84a1d423abe75b974741e
Author: Antonio Quartulli Date: Fri Aug 19 08:52:50 2022 +0200
dco-win: check for incompatible options
Signed-off-by: Antonio Quartulli <[email protected]...>
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25014.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v101 3/7] dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Antonio QuartulliHi,
Quoted 6 lines · Antonio Quartulli
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>
All the prerequisites for this have now been merged. So if someone could *test* that "master + 3/7" actually works, we could proceed with merging it...
I do have a few code nags that I hope will find agreement.
src/openvpn/init.c do_open_tun(struct context *c) · line 1819
Quoted 13 lines
src/openvpn/init.c +6
-3@@ -1810,9 +1811,12 @@ do_open_tun(struct context *c)ovpn_dco_init (c->mode, &c->c1.tuntap->dco); } -/* open the tun device */ -open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap, &c->net_ctx); +/* open the tun device (ovpn-dco-win already opened the device for the socket) */ +if (!tuntap_is_dco_win (c->c1.tuntap)) + { +open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, + c->c1.tuntap, &c->net_ctx); + }
do_open_tun() is one of the already-confusing functions, and this extra condition isn't helping.
Can we move the extra condition into the *WIN32 specific* open_tun() ("/* nothing to do for DCO, return */") and leave init.c alone?
src/openvpn/init.c do_close_free_key_schedule(struct context *c, bool free_ssl_ctx) · line 3595
Quoted 13 lines
src/openvpn/init.c +9
-0@@ -3570,6 +3584,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +
Overloading the link socket with a tun handle and then having special cases all around is not exactly easy to understand or maintainable code. I have no good suggestion how to make this nicer, but this is going to come back and haunt us.
(We still do not have automated windows testing, with all 3 driver types...)
src/openvpn/options.c options_postprocess_setdefault_ncpciphers(struct options *o) · line 3449
Quoted 10 lines
src/openvpn/options.c +2
-0@@ -3439,10 +3441,12 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +#if !defined(_WIN32) else if (cipher_valid("CHACHA20-POLY1305")) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ; } +#endif
Not sure I understand this exclusion. It's the *default* ciphers, and we know that Windows can do CHACHA20-POLY1305 - *DCO* on Windows might not be able to use this, but this disables using CHACHA-Poly in the default config for all windows builds.
Maybe just query the DCO cipher list here, if DCO is enabled?
So
...
else if (dco_enabled())
{
o->ncp_ciphers = dco_get_supported_ciphers()
}
else if (cipher_valid("CHACHA20-POLY1305"))
{
o->ncp_ciphers = "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
}...
Quoted 12 lines
src/openvpn/socket.c +3
-1@@ -2162,7 +2197,24 @@ link_socket_init_phase2(struct context *c)/* If a valid remote has been found, create the socket with its addrinfo */ if (sock->info.lsa->current_remote) { -create_socket (sock, sock->info.lsa->current_remote); +#if defined(_WIN32) +if (dco_enabled (&c->options)) + {
src/openvpn/socket.c link_socket_init_phase2(struct context *c) · line 2212
Quoted 10 lines
src/openvpn/socket.c +10
-0+create_socket_dco_win (c, sock, &sig_info->signal_received); +if (sig_info->signal_received) + { + goto done; + } + +linksock_print_addr (sock); + goto done; + } +else
I understand that we need to use a different create_socket_dco_win() function here, but all the *other* lines of code are just "huh, wat".
Why not move the linksock_print_addr(sock); *into* create_socket_dco_win(), and then this would collaps to a much more compact
src/openvpn/socket.c link_socket_init_phase2(struct context *c) · line 2213
Quoted 8 lines
src/openvpn/socket.c +8
-0+#if defined(_WIN32) +if (dco_enabled (&c->options)) + { +create_socket_dco_win (c, sock, &sig_info->signal_received); + goto done; + } + else +#endif
(still quite ugly)
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]...Re: [Openvpn-devel] [PATCH v101 5/7] dco-win: update GH Actions config file
In reply to Antonio QuartulliHi,
Quoted 5 lines · Antonio Quartulli
Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>--- .github/workflows/build.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
I do not understand this commit. Not at all.
It seems to take an existing setup that builds an installer *with* DCO, and remove the DCO bits?
.github/workflows/build.yaml jobs: · line 66
Quoted 9 lines
.github/workflows/build.yaml +0
-5@@ -59,11 +59,6 @@ jobs: steps: - name: Install dependencies run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip - - name: Checkout ovpn-dco-win - uses: actions/[email protected]... - with: - repository: OpenVPN/ovpn-dco-win - path: ovpn-dco-win
... so maybe we can have a better commit message that explains this?
.github/workflows/build.yaml jobs: · line 150
Quoted 7 lines
.github/workflows/build.yaml +1
-1@@ -151,7 +146,7 @@ jobs: run: cp ./tap-windows-${TAP_WINDOWS_VERSION}/include/tap-windows.h ${HOME}/mingw/opt/include/ - name: configure OpenVPN - run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig DCO_SOURCEDIR=$(realpath ../ovpn-dco-win) LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 --enable-dco + run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 working-directory: openvpn
This, I think, is clear - "--enable-dco is default for windows builds", and maybe also "no DCO_SOURCEDIR neccesary anymore, since ovpn_dco_win.h is now part of our tree", right?
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]...Re: [Openvpn-devel] [PATCH v101 4/7] dco-win: add documentation to README.dco.md
In reply to Antonio QuartulliHi,
this looks good to me - will apply as soon as 3/7 goes in (to avoid having documentation that says "it's in" while it isn't).
Quoted 48 lines · Antonio Quartulli
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
Changes from v100:
* add URL to windows installer (openvpn+dco) and modify text--- README.dco.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)README.dco.md +10
-1@@ -57,6 +57,13 @@ see a message like in your log. +Getting started (Windows) +------------------------- +The simplest way to test DCO under Windows is to download the latest installer +from https://build.openvpn.net/downloads/snapshots/github-actions/openvpn2/ . +This installer contains the latest OpenVPN code and the ovpn-dco-win driver. + + DCO and P2P mode ---------------- DCO is also available when running OpenVPN in P2P mode without `--pull` /@@ -111,7 +118,9 @@ Limitations by design - older versions are missing support for the AEAD ciphers; - topology subnet is the only supported `--topology` for servers; - iroute directives install routes on the host operating system, see also - Routing with ovpn-dco. + Routing with ovpn-dco; +- (ovpn-dco-win) client and p2p mode only; +- (ovpn-dco-win) Chacha20-Poly1305 support available starting with Windows 11. Current implementation limitationsSignature · 8 lines
2.35.1 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
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]...Re: [Openvpn-devel] [PATCH v101 5/7] dco-win: update GH Actions config file
In reply to Gert DoeringHi,
I remember someone was explaining to me the necessity of verbose commit messages.
Chi può essere?
Quoted 4 lines
It seems to take an existing setup that builds an installer *with* DCO, and remove the DCO bits?
... so maybe we can have a better commit message that explains this?
We decided to move the uapi header to the openvpn repo, so no need anymore to clone driver repo to get that header. Hence this change.
Quoted 8 lines
.github/workflows/build.yaml jobs: · line 150
Quoted 4 lines
- name: configure OpenVPN
.github/workflows/build.yaml +1
-1- run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig DCO_SOURCEDIR=$(realpath ../ovpn-dco-win) LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 --enable-dco + run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 working-directory: openvpnThis, I think, is clear - "--enable-dco is default for windows builds", and maybe also "no
DCO_SOURCEDIRneccesary anymore, sinceovpn_dco_win.his now part of our tree", right?
Yep.
-Lev
Re: [Openvpn-devel] [PATCH v101 3/7] dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Gert DoeringHi,
Regarding testing - if ordex could rebase and push dco branch, I could start a fresh openvpn-build on GHA to build Windows installers with dco. Here are MSI installers build with 6 days old dco branch:
https://github.com/OpenVPN/openvpn-build/actions/runs/2815957952
pe 19. elok. 2022 klo 12.02 Gert Doering ([email protected]...) kirjoitti:
Quoted 142 lines
Hi,
Quoted 6 lines · Antonio Quartulli
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>All the prerequisites for this have now been merged. So if someone could *test* that "master + 3/7" actually works, we could proceed with merging it...
I do have a few code nags that I hope will find agreement.
src/openvpn/init.c do_open_tun(struct context *c) · line 1819
Quoted 13 lines
src/openvpn/init.c +6
-3@@ -1810,9 +1811,12 @@ do_open_tun(struct context *c)ovpn_dco_init (c->mode, &c->c1.tuntap->dco); } -/* open the tun device */ -open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap, &c->net_ctx); +/* open the tun device (ovpn-dco-win already opened the device for the socket) */ +if (!tuntap_is_dco_win (c->c1.tuntap)) + { +open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, + c->c1.tuntap, &c->net_ctx); + }
do_open_tun()is one of the already-confusing functions, and this extra condition isn't helping.Can we move the extra condition into the *WIN32 specific*
open_tun()("/* nothing to do for DCO, return */") and leaveinit.calone?src/openvpn/init.c do_close_free_key_schedule(struct context *c, bool free_ssl_ctx) · line 3595
Quoted 13 lines
src/openvpn/init.c +9
-0@@ -3570,6 +3584,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +Overloading the link socket with a tun handle and then having special cases all around is not exactly easy to understand or maintainable code. I have no good suggestion how to make this nicer, but this is going to come back and haunt us.
(We still do not have automated windows testing, with all 3 driver types...)
src/openvpn/options.c options_postprocess_setdefault_ncpciphers(struct options *o) · line 3449
Quoted 10 lines
src/openvpn/options.c +2
-0@@ -3439,10 +3441,12 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +#if !defined(_WIN32) else if (cipher_valid("CHACHA20-POLY1305")) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ; } +#endif Not sure I understand this exclusion. It's the *default* ciphers, and we know that Windows can do CHACHA20-POLY1305 - *DCO* on Windows might not be able to use this, but this disables using CHACHA-Poly in the default config for all windows builds.
Maybe just query the DCO cipher list here, if DCO is enabled?
So
... else if (dco_enabled()) { o->ncp_ciphers = dco_get_supported_ciphers() } else if (cipher_valid("CHACHA20-POLY1305")) { o->ncp_ciphers = "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305"; }...
Quoted 12 lines
src/openvpn/socket.c +3
-1@@ -2162,7 +2197,24 @@ link_socket_init_phase2(struct context *c)/* If a valid remote has been found, create the socket with its addrinfo */ if (sock->info.lsa->current_remote) { -create_socket (sock, sock->info.lsa->current_remote); +#if defined(_WIN32) +if (dco_enabled (&c->options)) + {src/openvpn/socket.c link_socket_init_phase2(struct context *c) · line 2212
Quoted 10 lines
src/openvpn/socket.c +10
-0+create_socket_dco_win (c, sock, &sig_info->signal_received); +if (sig_info->signal_received) + { + goto done; + } + +linksock_print_addr (sock); + goto done; + } +else I understand that we need to use a different
create_socket_dco_win()function here, but all the *other* lines of code are just "huh, wat".Why not move the
linksock_print_addr(sock); *into*create_socket_dco_win(), and then this would collaps to a much more compactsrc/openvpn/socket.c link_socket_init_phase2(struct context *c) · line 2213
Quoted 8 lines
src/openvpn/socket.c +8
-0+#if defined(_WIN32) +if (dco_enabled (&c->options)) + { +create_socket_dco_win (c, sock, &sig_info->signal_received); + goto done; + } + else +#endif (still quite ugly)
gert
--
"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 MistressGert Doering - Munich, Germany [email protected]...
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
PATCH v102 3/7 dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Gert DoeringFrom: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
---
Changes from v101:
* move tuntap_is_dco_win() check from init.c to open_tun() in tun.c
* move linksock_print_addr() into create_socket_dco_win() to simplify link_socket_init_phase2()
* fix chachapoly support on Windows for non-DCO case
Changes from v100:
* rebased (fixed conflicts in options.h and tun.h)
Changes from v3:
* rename WINDOWS_DRIVER_WINDCO to WINDOWS_DRIVER_DCO
* add reference string check
Changes from v2:
* added is_tun_type_set() and removed real_tun_init flag
* moved link-close to do_close_tun()
Changes from v1:
* use suffix _dco_win instead of _windco
* create helper function to retrieve last error from socket object
src/openvpn/forward.c | 8 ++++ src/openvpn/init.c | 24 +++++++++++- src/openvpn/options.c | 25 +++++++++--- src/openvpn/options.h | 15 +++----- src/openvpn/socket.c | 89 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/socket.h | 25 ++++++++---- src/openvpn/tun.c | 58 ++++++++++++++++++++++------ src/openvpn/tun.h | 66 ++++++++++++++++++++++++-------- 8 files changed, 253 insertions(+), 57 deletions(-)
src/openvpn/forward.c +8 -0
@@ -864,9 +864,17 @@ read_incoming_link(struct context *c)return ; } +/* check_status() call below resets last-error code */ +bool dco_win_timeout =tuntap_is_dco_win_timeout (c->c1.tuntap, status); +/* check recvfrom status */ check_status (status,"read" , c->c2.link_socket,NULL ); +if (dco_win_timeout) + { +trigger_ping_timeout_signal (c); + } +/* Remove socks header if applicable */ socks_postprocess_incoming_link (c);
src/openvpn/init.c +22 -2
@@ -1699,7 +1699,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es, - &c->net_ctx); + &c->net_ctx, + c->c1.tuntap);#ifdef _WIN32 c->c1.tuntap->windows_driver = c->options.windows_driver;
@@ -1723,7 +1724,7 @@ can_preserve_tun(struct tuntap *tt)#ifdef TARGET_ANDROID return false;#else -return tt; +return is_tun_type_set (tt);#endif }
@@ -1934,6 +1935,16 @@ do_close_tun_simple(struct context *c)static void do_close_tun (struct context *c,bool force) { +/* With dco-win we open tun handle in the very beginning. +* In case when tun wasn't opened - like we haven't connected, +* we still need to close tun handle +*/ +if (tuntap_is_dco_win (c->c1.tuntap) && !is_tun_type_set (c->c1.tuntap)) + { +do_close_tun_simple (c); +return ; + } +if (!c->c1.tuntap || !c->c1.tuntap_owned) {return ;
@@ -3574,6 +3585,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/options.c +19 -6
@@ -3338,9 +3338,11 @@ options_postprocess_mutate_invariant(struct options *options)#ifdef _WIN32const int dev =dev_type_enum (options->dev, options->dev_type); -/* when using wintun, kernel doesn't send DHCP requests, so don't use it */ -if (options->windows_driver ==WINDOWS_DRIVER_WINTUN - && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) +/* when using wintun/ovpn-dco-win, kernel doesn't send DHCP requests, so don't use it */ +if ((options->windows_driver ==WINDOWS_DRIVER_WINTUN + || options->windows_driver ==WINDOWS_DRIVER_DCO ) + && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ + || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) { options->tuntap_options.ip_win32_type =IPW32_SET_NETSH ; }
@@ -3434,6 +3436,10 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +else if (dco_enabled (o)) + { + o->ncp_ciphers =dco_get_supported_ciphers (); + }else if (cipher_valid ("CHACHA20-POLY1305" )) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ;
@@ -4167,7 +4173,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4554,13 +4561,19 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco-win")) + { +return WINDOWS_DRIVER_DCO ; + } else { -msg (msglevel,"--windows-driver must be tap-windows6 or wintun" ); +msg (msglevel,"--windows-driver must be tap-windows6, wintun " +"or ovpn-dco-win" );return WINDOWS_DRIVER_UNSPECIFIED ; } } -#endif +#endif /* ifdef _WIN32 */ /* * parse/print topology coding
src/openvpn/options.h +5 -10
@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) -/** * Returns whether the current configuration has dco enabled. */ static inline bool dco_enabled (const struct options *o) { +#if defined(_WIN32) +return o->windows_driver ==WINDOWS_DRIVER_DCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} - -#else /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))*/ - -static inline bool -dco_enabled (const struct options *o) -{ +#else return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/socket.c +83 -6
137 lines not on this page · raw message
src/openvpn/socket.h +18 -7
@@ -34,6 +34,7 @@#include "proxy.h" #include "socks.h" #include "misc.h" +#include "tun.h" /* * OpenVPN's default port number as assigned by IANA.
@@ -937,7 +938,8 @@ socket_connection_reset(const struct link_socket *sock, int status) {const int err =openvpn_errno ();#ifdef _WIN32 -return err ==WSAECONNRESET || err ==WSAECONNABORTED ; +return err ==WSAECONNRESET || err ==WSAECONNABORTED + || err ==ERROR_CONNECTION_ABORTED ;#else return err ==ECONNRESET ;#endif
@@ -1048,6 +1050,11 @@ link_socket_read_udp_win32(struct link_socket *sock, struct link_socket_actual *from) {sockethandle_t sh = { .s = sock->sd }; +if (sock->info.dco_installed) + { +addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + sh.is_handle = true; + }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1057,7 +1064,7 @@ int link_socket_read_udp_posix(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from); -#endif +#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int
@@ -1065,7 +1072,10 @@ link_socket_read(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) + || sock->info.dco_installed) + /* unified UDPv4 and UDPv6, for DCO the kernel + * will strip the length header */ { int res;
@@ -1106,19 +1116,19 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );if (status <0 ) { - err =WSAGetLastError (); + err =SocketHandleGetLastError (sh); } }socket_send_queue (sock, buf, to);if (status <0 ) { -WSASetLastError (err); +SocketHandleSetLastError (sh, err);return status; }else
@@ -1180,8 +1190,9 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) { + /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); } else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
src/openvpn/tun.c +47 -11
114 lines not on this page · raw message
src/openvpn/tun.h +51 -15
104 lines not on this page · raw message
Signature · 1 line
2.23.0.windows.1
Re: [Openvpn-devel] [PATCH v102 3/7] dco-win: implement ovpn-dco support in P2P Windows code path
Hi,
Quoted 8 lines · Lev Stipakov
From: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>
I am fine with the code changes, and I have tested this on FreeBSD and Linux with/without DCO (full set takes like ~2 hours now) - so what worked before still works.
I am *not* going to merge this "just based on this", because I want to be sure it actually works on Win10/Win111 with dco... can I get a tester? Richard refuses to do Win10, so, no DCO for him... :-(
(But I have confirmation that the resulting installers still work fine for tun/tap and wintun on Win7, so that's at least reassuring :-) ).
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]...Re: [Openvpn-devel] [PATCH v102 3/7] dco-win: implement ovpn-dco support in P2P Windows code path
(adding Selva, Simon and Samuli just in case :)
If anyone could / want to test it - MSI installers could be found here:
https://github.com/lstipakov/openvpn-build/actions/runs/2894560760
To enable dco driver, add
--windows-driver ovpn-dco-win
I myself tested it on my Windows 10 laptop (udp / tcp), will check today later on the Windows Server 2022 VM and my son's Windows 11 PC.
But since I contributed to the client code and the driver, it would be great to get confirmation from someone else :)
I'll also try to get some QA resources from the corp side on Monday.
la 20. elok. 2022 klo 19.06 Gert Doering ([email protected]...) kirjoitti:
Quoted 33 lines
Hi,
Quoted 8 lines · Lev Stipakov
From: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>I am fine with the code changes, and I have tested this on FreeBSD and Linux with/without DCO (full set takes like ~2 hours now) - so what worked before still works.
I am *not* going to merge this "just based on this", because I want to be sure it actually works on Win10/Win111 with dco... can I get a tester? Richard refuses to do Win10, so, no DCO for him... :-(
(But I have confirmation that the resulting installers still work fine for tun/tap and wintun on Win7, so that's at least reassuring :-) ).
gert
--
"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 MistressGert Doering - Munich, Germany [email protected]...
Signature · 1 line
-Lev
Re: [Openvpn-devel] [PATCH v102 3/7] dco-win: implement ovpn-dco support in P2P Windows code path
Hi,
Did a quick test on Windows 10 and appears to work as expected. Some minor things:
(i) I had persist-tun which caused a fatal error that required opening the log file to find what's wrong and then fix the config file -- unfortunately the GUI status window cannot display such early errors. Isn't a warning that persist-tun is not supported enough?
(ii) windows-driver ovpn-dco (without the trailing -win) would be better?
"windows" is already there in the option name.
Selva
Re: [Openvpn-devel] [PATCH v102 3/7] dco-win: implement ovpn-dco support in P2P Windows code path
Yes, persist-tun support is in progress and coming soon.
Agreed on ”windows-driver dco-win”. I’ll send a patch.
Lähetetty iPhonesta
Quoted 12 lines
Selva Nair <[email protected]...> kirjoitti 21.8.2022 kello 19.29:
Hi,Did a quick test on Windows 10 and appears to work as expected. Some minor things:
(i) I had persist-tun which caused a fatal error that required opening the log file to find what's wrong and then fix the config file -- unfortunately the GUI status window cannot display such early errors. Isn't a warning that persist-tun is not supported enough?
(ii) windows-driver ovpn-dco (without the trailing -win) would be better? "windows" is already there in the option name.
Selva
PATCH v103 1/1 dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Selva NairFrom: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
---
Changes from v102:
* use "windows-driver ovpn-dco" without trailing "-win", since "windows" is already implied by option name.
Changes from v101:
* move tuntap_is_dco_win() check from init.c to open_tun() in tun.c
* move linksock_print_addr() into create_socket_dco_win() to simplify link_socket_init_phase2()
* fix chachapoly support on Windows for non-DCO case
Changes from v100:
* rebased (fixed conflicts in options.h and tun.h)
Changes from v3:
* rename WINDOWS_DRIVER_WINDCO to WINDOWS_DRIVER_DCO
* add reference string check
Changes from v2:
* added is_tun_type_set() and removed real_tun_init flag
* moved link-close to do_close_tun()
Changes from v1:
* use suffix _dco_win instead of _windco
* create helper function to retrieve last error from socket object
src/openvpn/dco.c | 4 +- src/openvpn/forward.c | 8 ++++ src/openvpn/init.c | 24 +++++++++++- src/openvpn/options.c | 25 +++++++++--- src/openvpn/options.h | 15 +++----- src/openvpn/socket.c | 89 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/socket.h | 25 ++++++++---- src/openvpn/tun.c | 58 ++++++++++++++++++++++------ src/openvpn/tun.h | 66 ++++++++++++++++++++++++-------- 9 files changed, 255 insertions(+), 59 deletions(-)
src/openvpn/dco.c +2 -2
@@ -229,13 +229,13 @@ dco_check_startup_option_conflict(int msglevel, const struct options *o)if (o->mode ==MODE_SERVER ) {msg (msglevel,"Only client and p2p data channel offload is supported " -"with ovpn-dco-win." ); +"with ovpn-dco." );return false; }if (o->persist_tun) { -msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +msg (msglevel,"--persist-tun is not supported with ovpn-dco." );return false; }#elif defined(TARGET_LINUX )
src/openvpn/forward.c +8 -0
@@ -864,9 +864,17 @@ read_incoming_link(struct context *c)return ; } +/* check_status() call below resets last-error code */ +bool dco_win_timeout =tuntap_is_dco_win_timeout (c->c1.tuntap, status); +/* check recvfrom status */ check_status (status,"read" , c->c2.link_socket,NULL ); +if (dco_win_timeout) + { +trigger_ping_timeout_signal (c); + } +/* Remove socks header if applicable */ socks_postprocess_incoming_link (c);
src/openvpn/init.c +22 -2
@@ -1699,7 +1699,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es, - &c->net_ctx); + &c->net_ctx, + c->c1.tuntap);#ifdef _WIN32 c->c1.tuntap->windows_driver = c->options.windows_driver;
@@ -1723,7 +1724,7 @@ can_preserve_tun(struct tuntap *tt)#ifdef TARGET_ANDROID return false;#else -return tt; +return is_tun_type_set (tt);#endif }
@@ -1934,6 +1935,16 @@ do_close_tun_simple(struct context *c)static void do_close_tun (struct context *c,bool force) { +/* With dco-win we open tun handle in the very beginning. +* In case when tun wasn't opened - like we haven't connected, +* we still need to close tun handle +*/ +if (tuntap_is_dco_win (c->c1.tuntap) && !is_tun_type_set (c->c1.tuntap)) + { +do_close_tun_simple (c); +return ; + } +if (!c->c1.tuntap || !c->c1.tuntap_owned) {return ;
@@ -3574,6 +3585,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/options.c +19 -6
@@ -3338,9 +3338,11 @@ options_postprocess_mutate_invariant(struct options *options)#ifdef _WIN32const int dev =dev_type_enum (options->dev, options->dev_type); -/* when using wintun, kernel doesn't send DHCP requests, so don't use it */ -if (options->windows_driver ==WINDOWS_DRIVER_WINTUN - && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) +/* when using wintun/ovpn-dco, kernel doesn't send DHCP requests, so don't use it */ +if ((options->windows_driver ==WINDOWS_DRIVER_WINTUN + || options->windows_driver ==WINDOWS_DRIVER_DCO ) + && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ + || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) { options->tuntap_options.ip_win32_type =IPW32_SET_NETSH ; }
@@ -3434,6 +3436,10 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +else if (dco_enabled (o)) + { + o->ncp_ciphers =dco_get_supported_ciphers (); + }else if (cipher_valid ("CHACHA20-POLY1305" )) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ;
@@ -4167,7 +4173,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4554,13 +4561,19 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco")) + { +return WINDOWS_DRIVER_DCO ; + } else { -msg (msglevel,"--windows-driver must be tap-windows6 or wintun" ); +msg (msglevel,"--windows-driver must be tap-windows6, wintun " +"or ovpn-dco" );return WINDOWS_DRIVER_UNSPECIFIED ; } } -#endif +#endif /* ifdef _WIN32 */ /* * parse/print topology coding
src/openvpn/options.h +5 -10
@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) -/** * Returns whether the current configuration has dco enabled. */ static inline bool dco_enabled (const struct options *o) { +#if defined(_WIN32) +return o->windows_driver ==WINDOWS_DRIVER_DCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} - -#else /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))*/ - -static inline bool -dco_enabled (const struct options *o) -{ +#else return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/socket.c +83 -6
137 lines not on this page · raw message
src/openvpn/socket.h +18 -7
@@ -34,6 +34,7 @@#include "proxy.h" #include "socks.h" #include "misc.h" +#include "tun.h" /* * OpenVPN's default port number as assigned by IANA.
@@ -937,7 +938,8 @@ socket_connection_reset(const struct link_socket *sock, int status) {const int err =openvpn_errno ();#ifdef _WIN32 -return err ==WSAECONNRESET || err ==WSAECONNABORTED ; +return err ==WSAECONNRESET || err ==WSAECONNABORTED + || err ==ERROR_CONNECTION_ABORTED ;#else return err ==ECONNRESET ;#endif
@@ -1048,6 +1050,11 @@ link_socket_read_udp_win32(struct link_socket *sock, struct link_socket_actual *from) {sockethandle_t sh = { .s = sock->sd }; +if (sock->info.dco_installed) + { +addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + sh.is_handle = true; + }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1057,7 +1064,7 @@ int link_socket_read_udp_posix(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from); -#endif +#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int
@@ -1065,7 +1072,10 @@ link_socket_read(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) + || sock->info.dco_installed) + /* unified UDPv4 and UDPv6, for DCO the kernel + * will strip the length header */ { int res;
@@ -1106,19 +1116,19 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );if (status <0 ) { - err =WSAGetLastError (); + err =SocketHandleGetLastError (sh); } }socket_send_queue (sock, buf, to);if (status <0 ) { -WSASetLastError (err); +SocketHandleSetLastError (sh, err);return status; }else
@@ -1180,8 +1190,9 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) { + /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); } else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
src/openvpn/tun.c +47 -11
114 lines not on this page · raw message
src/openvpn/tun.h +51 -15
104 lines not on this page · raw message
Signature · 1 line
2.23.0.windows.1
Re: [Openvpn-devel] [PATCH v103] dco-win: implement ovpn-dco support in P2P Windows code path
Fo the reference - I have tested the installer
https://github.com/lstipakov/openvpn-build/actions/runs/2902240643
(which includes openvpn-build dco changes and openvpn master branch with this patch)
on Windows 11 (VMware ESXi) - dco-win/tap-windows6/wintun drivers work as expected.
I also verified that ChaCha20-Poly1305 (cipher supported starting from Windows 11) works fine with the dco-win driver ,
as well as the good old AES-256-GCM.
More testers are very welcomed.
ma 22. elok. 2022 klo 11.56 Lev Stipakov ([email protected]...) kirjoitti:
Quoted 720 lines
From: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
Changes from v102:
* use "windows-driver ovpn-dco" without trailing "-win", since "windows" is already implied by option name.Changes from v101:
* movetuntap_is_dco_win()check frominit.ctoopen_tun()intun.c
* movelinksock_print_addr()intocreate_socket_dco_win()to simplifylink_socket_init_phase2()
* fix chachapoly support on Windows for non-DCO caseChanges from v100:
* rebased (fixed conflicts inoptions.handtun.h)Changes from v3:
* renameWINDOWS_DRIVER_WINDCOtoWINDOWS_DRIVER_DCO
* add reference string checkChanges from v2:
* addedis_tun_type_set()and removedreal_tun_initflag
* moved link-close todo_close_tun()Changes from v1:
* use suffix_dco_wininstead of_windco
* create helper function to retrieve last error from socket objectsrc/openvpn/dco.c | 4 +- src/openvpn/forward.c | 8 ++++ src/openvpn/init.c | 24 +++++++++++- src/openvpn/options.c | 25 +++++++++--- src/openvpn/options.h | 15 +++----- src/openvpn/socket.c | 89 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/socket.h | 25 ++++++++---- src/openvpn/tun.c | 58 ++++++++++++++++++++++------ src/openvpn/tun.h | 66 ++++++++++++++++++++++++-------- 9 files changed, 255 insertions(+), 59 deletions(-)src/openvpn/dco.c +2
-2@@ -229,13 +229,13 @@ dco_check_startup_option_conflict(int msglevel, const struct options *o)if (o->mode ==MODE_SERVER ) {msg (msglevel,"Only client and p2p data channel offload is supported " -"with ovpn-dco-win." ); +"with ovpn-dco." );return false; }if (o->persist_tun) { -msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +msg (msglevel,"--persist-tun is not supported with ovpn-dco." );return false; }#elif defined(TARGET_LINUX )src/openvpn/forward.c +8
-0@@ -864,9 +864,17 @@ read_incoming_link(struct context *c)return ; } +/* check_status() call below resets last-error code */ +bool dco_win_timeout =tuntap_is_dco_win_timeout (c->c1.tuntap, status); +/* check recvfrom status */ check_status (status,"read" , c->c2.link_socket,NULL ); +if (dco_win_timeout) + { +trigger_ping_timeout_signal (c); + } +/* Remove socks header if applicable */ socks_postprocess_incoming_link (c);src/openvpn/init.c +22
-2@@ -1699,7 +1699,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es, - &c->net_ctx); + &c->net_ctx, + c->c1.tuntap);#ifdef _WIN32 c->c1.tuntap->windows_driver = c->options.windows_driver;@@ -1723,7 +1724,7 @@ can_preserve_tun(struct tuntap *tt)#ifdef TARGET_ANDROID return false;#else -return tt; +return is_tun_type_set (tt);#endif }@@ -1934,6 +1935,16 @@ do_close_tun_simple(struct context *c)static void do_close_tun (struct context *c,bool force) { +/* With dco-win we open tun handle in the very beginning. +* In case when tun wasn't opened - like we haven't connected, +* we still need to close tun handle +*/ +if (tuntap_is_dco_win (c->c1.tuntap) && !is_tun_type_set (c->c1.tuntap)) + { +do_close_tun_simple (c); +return ; + } +if (!c->c1.tuntap || !c->c1.tuntap_owned) {return ;@@ -3574,6 +3585,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);src/openvpn/options.c +19
-6@@ -3338,9 +3338,11 @@ options_postprocess_mutate_invariant(struct options *options)#ifdef _WIN32const int dev =dev_type_enum (options->dev, options->dev_type); -/* when using wintun, kernel doesn't send DHCP requests, so don't use it */ -if (options->windows_driver ==WINDOWS_DRIVER_WINTUN - && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) +/* when using wintun/ovpn-dco, kernel doesn't send DHCP requests, so don't use it */ +if ((options->windows_driver ==WINDOWS_DRIVER_WINTUN + || options->windows_driver ==WINDOWS_DRIVER_DCO ) + && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ + || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) { options->tuntap_options.ip_win32_type =IPW32_SET_NETSH ; }@@ -3434,6 +3436,10 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +else if (dco_enabled (o)) + { + o->ncp_ciphers =dco_get_supported_ciphers (); + }else if (cipher_valid ("CHACHA20-POLY1305" )) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ;@@ -4167,7 +4173,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;@@ -4554,13 +4561,19 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco")) + { +return WINDOWS_DRIVER_DCO ; + } else { -msg (msglevel,"--windows-driver must be tap-windows6 or wintun" ); +msg (msglevel,"--windows-driver must be tap-windows6, wintun " +"or ovpn-dco" );return WINDOWS_DRIVER_UNSPECIFIED ; } } -#endif +#endif /* ifdef _WIN32 */ /* * parse/print topology coding src/openvpn/options.h +5
-10@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) -/** * Returns whether the current configuration has dco enabled. */ static inline bool dco_enabled (const struct options *o) { +#if defined(_WIN32) +return o->windows_driver ==WINDOWS_DRIVER_DCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} - -#else /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))*/ - -static inline bool -dco_enabled (const struct options *o) -{ +#else return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */ src/openvpn/socket.c +83
-6@@ -2123,6 +2123,43 @@ phase2_socks_client(struct link_socket *sock, struct signal_info *sig_info)resolve_remote (sock,1 ,NULL , &sig_info->signal_received); } +#if defined(_WIN32) +static void +create_socket_dco_win (struct context *c,struct link_socket *sock, +volatile int *signal_received) +{ +struct tuntap *tt; +/* In this case persist-tun is enabled, which we don't support yet */ +ASSERT (!c->c1.tuntap); + + ALLOC_OBJ(tt, struct tuntap); + + *tt =dco_create_socket (sock->info.lsa->current_remote, + sock->bind_local, + sock->info.lsa->bind_local, + c->options.dev_node, + &c->gc, +get_server_poll_remaining_time (sock->server_poll_timeout), + signal_received); + +/* This state is used by signal handler which does teardown, +* so it has to be set before return */ + c->c1.tuntap = tt; + sock->info.dco_installed = true; + +if (*signal_received) + { +return ; + } + +/* Ensure we can "safely" cast the handle to a socket */ +static_assert (sizeof (sock->sd) ==sizeof (tt->hand),"HANDLE and SOCKET size differs" ); + sock->sd = (SOCKET )tt->hand; + +linksock_print_addr (sock); +} +#endif /* if defined(_WIN32) */ +/* finalize socket initialization */ void link_socket_init_phase2 (struct context *c)@@ -2162,7 +2199,18 @@ link_socket_init_phase2(struct context *c)/* If a valid remote has been found, create the socket with its addrinfo */ if (sock->info.lsa->current_remote) { -create_socket (sock, sock->info.lsa->current_remote); +#if defined(_WIN32) +if (dco_enabled (&c->options)) + { +create_socket_dco_win (c, sock, &sig_info->signal_received); + goto done; + } + else +#endif + { +create_socket (sock, sock->info.lsa->current_remote); + } + }/* If socket has not already been created create it now */ @@ -3430,6 +3478,17 @@ link_socket_write_udp_posix_sendmsg(struct link_socket *sock,#ifdef _WIN32 +static int +socket_get_last_error (const struct link_socket *sock) +{ +if (sock->info.dco_installed) + { +return GetLastError (); + } + +return WSAGetLastError (); +} +int socket_recv_queue (struct link_socket *sock,int maxsize) {@@ -3463,7 +3522,14 @@ socket_recv_queue(struct link_socket *sock, int maxsize)ASSERT (ResetEvent (sock->reads.overlapped.hEvent)); sock->reads.flags =0 ; -if (proto_is_udp (sock->info.proto)) +if (sock->info.dco_installed) + { + status =ReadFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, + &sock->reads.size, &sock->reads.overlapped); +/* Readfile status is inverted from WSARecv */ + status = !status; + } +else if (proto_is_udp (sock->info.proto)) { sock->reads.addr_defined = true; sock->reads.addrlen =sizeof (sock->reads.addr6);@@ -3516,7 +3582,7 @@ socket_recv_queue(struct link_socket *sock, int maxsize) }else { - status =WSAGetLastError (); + status =socket_get_last_error (sock);if (status ==WSA_IO_PENDING )/* operation queued? */ { sock->reads.iostate =IOSTATE_QUEUED ;@@ -3561,7 +3627,16 @@ socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct linASSERT (ResetEvent (sock->writes.overlapped.hEvent)); sock->writes.flags =0 ; -if (proto_is_udp (sock->info.proto)) +if (sock->info.dco_installed) + { + status =WriteFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, + &sock->writes.size, &sock->writes.overlapped); + +/* WriteFile status is inverted from WSASendTo */ + status = !status; + + } +else if (proto_is_udp (sock->info.proto)) {/* set destination address for UDP writes */ sock->writes.addr_defined = true;@@ -3622,8 +3697,9 @@ socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct lin }else { - status =WSAGetLastError (); -if (status ==WSA_IO_PENDING )/* operation queued? */ + status =socket_get_last_error (sock); +/* both status code have the identical value */ +if (status ==WSA_IO_PENDING || status ==ERROR_IO_PENDING )/* operation queued? */ { sock->writes.iostate =IOSTATE_QUEUED ; sock->writes.status = status;@@ -3648,6 +3724,7 @@ socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct linreturn sock->writes.iostate; } +/* Returns the number of bytes successfully read */ int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io,src/openvpn/socket.h +18
-7@@ -34,6 +34,7 @@#include "proxy.h" #include "socks.h" #include "misc.h" +#include "tun.h" /* * OpenVPN's default port number as assigned by IANA. @@ -937,7 +938,8 @@ socket_connection_reset(const struct link_socket *sock, int status) {const int err =openvpn_errno ();#ifdef _WIN32 -return err ==WSAECONNRESET || err ==WSAECONNABORTED ; +return err ==WSAECONNRESET || err ==WSAECONNABORTED + || err ==ERROR_CONNECTION_ABORTED ;#else return err ==ECONNRESET ;#endif @@ -1048,6 +1050,11 @@ link_socket_read_udp_win32(struct link_socket *sock, struct link_socket_actual *from) {sockethandle_t sh = { .s = sock->sd }; +if (sock->info.dco_installed) + { +addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + sh.is_handle = true; + }return sockethandle_finalize (sh, &sock->reads, buf, from); }@@ -1057,7 +1064,7 @@ int link_socket_read_udp_posix(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from); -#endif +#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int@@ -1065,7 +1072,10 @@ link_socket_read(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) + || sock->info.dco_installed) + /* unified UDPv4 and UDPv6, for DCO the kernel + * will strip the length header */ { int res;@@ -1106,19 +1116,19 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );if (status <0 ) { - err =WSAGetLastError (); + err =SocketHandleGetLastError (sh); } }socket_send_queue (sock, buf, to);if (status <0 ) { -WSASetLastError (err); +SocketHandleSetLastError (sh, err);return status; }else @@ -1180,8 +1190,9 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) { + /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); } else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */src/openvpn/tun.c +47
-11@@ -743,12 +743,14 @@ init_tun(const char *dev, /* --dev option */struct addrinfo *remote_public, const bool strict_warn, struct env_set *es, - openvpn_net_ctx_t *ctx) + openvpn_net_ctx_t *ctx, + struct tuntap *tt) { - struct tuntap *tt; - - ALLOC_OBJ(tt, struct tuntap); -clear_tuntap (tt); + if (!tt) + { +ALLOC_OBJ (tt ,struct tuntap ); +clear_tuntap (tt); + } tt->type =dev_type_enum (dev, dev_type); tt->topology = topology;@@ -890,6 +892,12 @@ init_tun_post(struct tuntap *tt, { tt->options = *options;#ifdef _WIN32 +if (tt->windows_driver ==WINDOWS_DRIVER_DCO ) + { +dco_start_tun (tt); +return ; + } +overlapped_io_init (&tt->reads, frame, FALSE, true);overlapped_io_init (&tt->writes, frame, TRUE, true); tt->adapter_index =TUN_ADAPTER_INDEX_INVALID ;@@ -3542,6 +3550,9 @@ print_windows_driver(enum windows_driver_type windows_driver)case WINDOWS_DRIVER_WINTUN :return "wintun" ; +case WINDOWS_DRIVER_DCO : +return "ovpn-dco" ; +default :return "unspecified" ; }@@ -3930,6 +3941,10 @@ get_tap_reg(struct gc_arena *gc) { windows_driver =WINDOWS_DRIVER_WINTUN ; } + else if (strcasecmp(component_id, "ovpn-dco") == 0) + { + windows_driver = WINDOWS_DRIVER_DCO; + } if (windows_driver != WINDOWS_DRIVER_UNSPECIFIED) {@@ -4284,7 +4299,9 @@ at_least_one_tap_win(const struct tap_reg *tap_reg) {if (!tap_reg) { -msg (M_FATAL ,"There are no TAP-Windows nor Wintun adapters on this system. You should be able to create an adapter by using tapctl.exe utility." ); +msg (M_FATAL ,"There are no TAP-Windows, Wintun or ovpn-dco adapters " +"on this system. You should be able to create an adapter " +"by using tapctl.exe utility." ); } }@@ -6484,17 +6501,30 @@ tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct devconst char *path =NULL ;char tuntap_device_path[256 ]; -if (tt->windows_driver ==WINDOWS_DRIVER_WINTUN ) +if (tt->windows_driver ==WINDOWS_DRIVER_WINTUN + || tt->windows_driver ==WINDOWS_DRIVER_DCO ) {const struct device_instance_id_interface *dev_if;for (dev_if = device_instance_id_interface; dev_if !=NULL ; dev_if = dev_if->next) { -if (strcmp ((const char *)dev_if->net_cfg_instance_id, device_guid) ==0 ) +if (strcmp ((const char *)dev_if->net_cfg_instance_id, device_guid) !=0 ) { - path = dev_if->device_interface; -break ; +continue ; + } + +if (tt->windows_driver ==WINDOWS_DRIVER_DCO ) + { +char *last_sep =strrchr (dev_if->device_interface,'\\' ); +if (!last_sep + ||strcmp (last_sep +1 ,DCO_WIN_REFERENCE_STRING ) !=0 ) + { +continue ; + } } + + path = dev_if->device_interface; +break ; }if (path ==NULL ) {@@ -6503,7 +6533,7 @@ tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct dev }else { -/* Open TAP-Windows adapter */ +/* Open TAP-Windows */ openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s", USERMODEDEVICEDIR, device_guid,@@ -6710,6 +6740,12 @@ void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt, openvpn_net_ctx_t *ctx) { + /* dco-win already opened the device, which handle we treat as socket */ + if (tuntap_is_dco_win(tt)) + { + return; + } +const char *device_guid =NULL ;/*netcmd_semaphore_lock ();*/ src/openvpn/tun.h +51
-16@@ -44,6 +44,7 @@#ifdef _WIN32#define WINTUN_COMPONENT_ID "wintun" +#define DCO_WIN_REFERENCE_STRING "ovpn-dco"enum windows_driver_type { WINDOWS_DRIVER_UNSPECIFIED,@@ -293,7 +294,8 @@ struct tuntap *init_tun(const char *dev, /* --dev option */struct addrinfo *remote_public, const bool strict_warn, struct env_set *es, - openvpn_net_ctx_t *ctx); + openvpn_net_ctx_t *ctx, + struct tuntap *tt); void init_tun_post(struct tuntap *tt, const struct frame *frame,@@ -646,6 +648,18 @@ write_tun_buffered(struct tuntap *tt, struct buffer *buf) } } +static inline bool +tuntap_is_dco_win (struct tuntap *tt) +{ +return tt && tt->windows_driver ==WINDOWS_DRIVER_DCO ; +} + +static inline bool +tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +{ +return tuntap_is_dco_win (tt) && (status <0 ) && (openvpn_errno () ==ERROR_NETNAME_DELETED ); +} +#else /* ifdef _WIN32 */ static inline bool@@ -671,6 +685,19 @@ tun_standby(struct tuntap *tt) return true; } + +static inline bool +tuntap_is_dco_win (struct tuntap *tt) +{ +return false; +} + +static inline bool +tuntap_is_dco_win_timeout (struct tuntap *tt,int status) +{ +return false; +} +#endif /* ifdef _WIN32 */ /* @@ -694,28 +721,37 @@ tun_set(struct tuntap *tt, void *arg, unsigned int *persistent) { - if (tuntap_defined(tt)) +if (!tuntap_defined (tt) ||tuntap_is_dco_win (tt)) { -/* if persistent is defined, call event_ctl only if rwflags has changed since last call */ -if (!persistent || *persistent != rwflags) +return ; + } + +/* if persistent is defined, call event_ctl only if rwflags has changed since last call */ +if (!persistent || *persistent != rwflags) + { +event_ctl (es,tun_event_handle (tt), rwflags, arg); +if (persistent) { -event_ctl (es,tun_event_handle (tt), rwflags, arg); -if (persistent) - { - *persistent = rwflags; - } + *persistent = rwflags; } + }#ifdef _WIN32 -if (tt->windows_driver ==WINDOWS_DRIVER_TAP_WINDOWS6 && (rwflags &EVENT_READ )) - { -tun_read_queue (tt,0 ); - } -#endif - tt->rwflags_debug = rwflags; +if (tt->windows_driver ==WINDOWS_DRIVER_TAP_WINDOWS6 && (rwflags &EVENT_READ )) + { +tun_read_queue (tt,0 ); } +#endif + tt->rwflags_debug = rwflags; + }const char *tun_stat (const struct tuntap *tt,unsigned int rwflags,struct gc_arena *gc);bool tun_name_is_fixed (const char *dev); +static inline bool +is_tun_type_set (const struct tuntap *tt) +{ +return tt && tt->type !=DEV_TYPE_UNDEF ; +} +#endif /* TUN_H */ --2.23.0.windows.1
Signature · 1 line
-Lev
Re: [Openvpn-devel] [PATCH v103] dco-win: implement ovpn-dco support in P2P Windows code path
Another feedback - I asked our corp QA engineer to give this build a try, here are results:
---
Testing OpenVPN GUI on Windows 11:
- install, remove and upgrade from 2.5.7 to
https://github.com/lstipakov/openvpn-build/actions/runs/2902240643
- Connection with DCO via autologin, user-locked, cloud, user-locked with Google and DUO authentication
- Connection with DCO through TCP and UDP protocols
- Basic test for connection with TAP and Wintun drivers
- Reconnecting after network change with DCO
---
-Lev
Re: [Openvpn-devel] [PATCH v103] dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Lev StipakovHi,
Quoted 5 lines · Lev Stipakov
From: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
Quoted 7 lines
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
Changes from v102:
* use "windows-driver ovpn-dco" without trailing "-win", since "windows" is already implied by option name.
I have received sufficient test reports to be happy about it. The change for v102 makes sense.
Alas, there is one change in v101 that I initiated which I'm now no longer happy about:
src/openvpn/options.c options_postprocess_setdefault_ncpciphers(struct options *o) · line 3445
Quoted 11 lines
src/openvpn/options.c +4
-0@@ -3434,6 +3436,10 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +else if (dco_enabled (o)) + { + o->ncp_ciphers =dco_get_supported_ciphers (); + }else if (cipher_valid ("CHACHA20-POLY1305" )) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ;
This change does the right thing for DCO-enabled *Windows* builds, but it does bad things for DCO-enabled FreeBSD, because of
const char *dco_get_supported_ciphers()
{
return "none:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
}in dco_freebsd.c - so with the above change, we'd advertise "NONE!" as cipher we're willing to accept. Which is a hard no for the *default* setting...
I still think using dco_get_supported_ciphers() to set the default on Windows is a good idea (because "no none" there) - so I'd suggest to do this:
Review
Quoted 9 lines
(quoted diff) +9
-0+#ifdef _WIN32 + /* CHACHA-POLY availability on DCO for Windows depends on system wide + * availability -> query DCO layer for default --data-ciphers set + */ + else if (dco_enabled(o)) + { + o->ncp_ciphers = dco_get_supported_ciphers(); + } +#endif
sorry for adding more complications.
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]...PATCH v104 1/1 dco-win: implement ovpn-dco support in P2P Windows code path
From: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
---
Changes from v103:
* Query DCO code for default --data-ciphers only on Windows
Changes from v102:
* use "windows-driver ovpn-dco" without trailing "-win", since "windows" is already implied by option name.
Changes from v101:
* move tuntap_is_dco_win() check from init.c to open_tun() in tun.c
* move linksock_print_addr() into create_socket_dco_win() to simplify link_socket_init_phase2()
* fix chachapoly support on Windows for non-DCO case
Changes from v100:
* rebased (fixed conflicts in options.h and tun.h)
Changes from v3:
* rename WINDOWS_DRIVER_WINDCO to WINDOWS_DRIVER_DCO
* add reference string check
Changes from v2:
* added is_tun_type_set() and removed real_tun_init flag
* moved link-close to do_close_tun()
Changes from v1:
* use suffix _dco_win instead of _windco
* create helper function to retrieve last error from socket object
src/openvpn/dco.c | 4 +- src/openvpn/forward.c | 8 ++++ src/openvpn/init.c | 24 +++++++++++- src/openvpn/options.c | 30 ++++++++++++--- src/openvpn/options.h | 15 +++----- src/openvpn/socket.c | 89 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/socket.h | 25 ++++++++---- src/openvpn/tun.c | 58 ++++++++++++++++++++++------ src/openvpn/tun.h | 66 ++++++++++++++++++++++++-------- 9 files changed, 260 insertions(+), 59 deletions(-)
src/openvpn/dco.c +2 -2
@@ -229,13 +229,13 @@ dco_check_startup_option_conflict(int msglevel, const struct options *o)if (o->mode ==MODE_SERVER ) {msg (msglevel,"Only client and p2p data channel offload is supported " -"with ovpn-dco-win." ); +"with ovpn-dco." );return false; }if (o->persist_tun) { -msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +msg (msglevel,"--persist-tun is not supported with ovpn-dco." );return false; }#elif defined(TARGET_LINUX )
src/openvpn/forward.c +8 -0
@@ -864,9 +864,17 @@ read_incoming_link(struct context *c)return ; } +/* check_status() call below resets last-error code */ +bool dco_win_timeout =tuntap_is_dco_win_timeout (c->c1.tuntap, status); +/* check recvfrom status */ check_status (status,"read" , c->c2.link_socket,NULL ); +if (dco_win_timeout) + { +trigger_ping_timeout_signal (c); + } +/* Remove socks header if applicable */ socks_postprocess_incoming_link (c);
src/openvpn/init.c +22 -2
@@ -1699,7 +1699,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es, - &c->net_ctx); + &c->net_ctx, + c->c1.tuntap);#ifdef _WIN32 c->c1.tuntap->windows_driver = c->options.windows_driver;
@@ -1723,7 +1724,7 @@ can_preserve_tun(struct tuntap *tt)#ifdef TARGET_ANDROID return false;#else -return tt; +return is_tun_type_set (tt);#endif }
@@ -1934,6 +1935,16 @@ do_close_tun_simple(struct context *c)static void do_close_tun (struct context *c,bool force) { +/* With dco-win we open tun handle in the very beginning. +* In case when tun wasn't opened - like we haven't connected, +* we still need to close tun handle +*/ +if (tuntap_is_dco_win (c->c1.tuntap) && !is_tun_type_set (c->c1.tuntap)) + { +do_close_tun_simple (c); +return ; + } +if (!c->c1.tuntap || !c->c1.tuntap_owned) {return ;
@@ -3574,6 +3585,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/options.c +24 -6
@@ -3338,9 +3338,11 @@ options_postprocess_mutate_invariant(struct options *options)#ifdef _WIN32const int dev =dev_type_enum (options->dev, options->dev_type); -/* when using wintun, kernel doesn't send DHCP requests, so don't use it */ -if (options->windows_driver ==WINDOWS_DRIVER_WINTUN - && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) +/* when using wintun/ovpn-dco, kernel doesn't send DHCP requests, so don't use it */ +if ((options->windows_driver ==WINDOWS_DRIVER_WINTUN + || options->windows_driver ==WINDOWS_DRIVER_DCO ) + && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ + || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) { options->tuntap_options.ip_win32_type =IPW32_SET_NETSH ; }
@@ -3434,6 +3436,15 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +#ifdef _WIN32 +/* ChaChaPoly availability on DCO for Windows depends on system wide +* availability -> query DCO layer for default --data-ciphers set +*/ + else if (dco_enabled(o)) + { + o->ncp_ciphers =dco_get_supported_ciphers (); + } +#endif else if (cipher_valid("CHACHA20-POLY1305")) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ;
@@ -4167,7 +4178,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4554,13 +4566,19 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco")) + { +return WINDOWS_DRIVER_DCO ; + } else { -msg (msglevel,"--windows-driver must be tap-windows6 or wintun" ); +msg (msglevel,"--windows-driver must be tap-windows6, wintun " +"or ovpn-dco" );return WINDOWS_DRIVER_UNSPECIFIED ; } } -#endif +#endif /* ifdef _WIN32 */ /* * parse/print topology coding
src/openvpn/options.h +5 -10
@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) -/** * Returns whether the current configuration has dco enabled. */ static inline bool dco_enabled (const struct options *o) { +#if defined(_WIN32) +return o->windows_driver ==WINDOWS_DRIVER_DCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} - -#else /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))*/ - -static inline bool -dco_enabled (const struct options *o) -{ +#else return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/socket.c +83 -6
137 lines not on this page · raw message
src/openvpn/socket.h +18 -7
@@ -34,6 +34,7 @@#include "proxy.h" #include "socks.h" #include "misc.h" +#include "tun.h" /* * OpenVPN's default port number as assigned by IANA.
@@ -937,7 +938,8 @@ socket_connection_reset(const struct link_socket *sock, int status) {const int err =openvpn_errno ();#ifdef _WIN32 -return err ==WSAECONNRESET || err ==WSAECONNABORTED ; +return err ==WSAECONNRESET || err ==WSAECONNABORTED + || err ==ERROR_CONNECTION_ABORTED ;#else return err ==ECONNRESET ;#endif
@@ -1048,6 +1050,11 @@ link_socket_read_udp_win32(struct link_socket *sock, struct link_socket_actual *from) {sockethandle_t sh = { .s = sock->sd }; +if (sock->info.dco_installed) + { +addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + sh.is_handle = true; + }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1057,7 +1064,7 @@ int link_socket_read_udp_posix(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from); -#endif +#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int
@@ -1065,7 +1072,10 @@ link_socket_read(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) + || sock->info.dco_installed) + /* unified UDPv4 and UDPv6, for DCO the kernel + * will strip the length header */ { int res;
@@ -1106,19 +1116,19 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );if (status <0 ) { - err =WSAGetLastError (); + err =SocketHandleGetLastError (sh); } }socket_send_queue (sock, buf, to);if (status <0 ) { -WSASetLastError (err); +SocketHandleSetLastError (sh, err);return status; }else
@@ -1180,8 +1190,9 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) { + /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); } else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
src/openvpn/tun.c +47 -11
114 lines not on this page · raw message
src/openvpn/tun.h +51 -15
104 lines not on this page · raw message
Signature · 1 line
2.23.0.windows.1
Re: [Openvpn-devel] [PATCH v103] dco-win: implement ovpn-dco support in P2P Windows code path
In reply to Gert DoeringAm 25.08.22 um 13:29 schrieb Gert Doering:
Quoted 22 lines
Hi,
Quoted 5 lines · Lev Stipakov
From: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
Quoted 7 lines
Signed-off-by Arne Schwabe <[email protected]...>Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>---
Changes from v102:
* use "windows-driver ovpn-dco" without trailing "-win", since "windows" is already implied by option name.I have received sufficient test reports to be happy about it. The change for v102 makes sense.
Alas, there is one change in v101 that I initiated which I'm now no longer happy about:
Quoted 14 lines
src/openvpn/options.c options_postprocess_setdefault_ncpciphers(struct options *o) · line 3445
Quoted 11 lines
src/openvpn/options.c +4
-0@@ -3434,6 +3436,10 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } +else if (dco_enabled (o)) + { + o->ncp_ciphers =dco_get_supported_ciphers (); + }else if (cipher_valid ("CHACHA20-POLY1305" )) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ;This change does the right thing for DCO-enabled *Windows* builds, but it does bad things for DCO-enabled FreeBSD, because of
I would also NAK the patch based on this. The default is currenlty AES-128-GCM:AES-256-GCM and Chacha20-Poly1305 if supported. We don't want to expose all algorithms that a DCO implementation supports.
The other thing is AES-192-GCM that we never announced before by default and this change would announce that by default. That is also weird behaviour.
Currently that might sound like nit picking but there are already other AEAD ciphers that can be easily added to DCO implementations (ARIA as AES variant is probably trivial in Linux for example).
Arne
PATCH v105 1/1 dco-win: implement ovpn-dco support in P2P Windows code path
From: Antonio Quartulli <[email protected]...>
With this change it is possible to use ovpn-dco-win when running OpenVPN in client or P2P mode.
---
Changes from v104:
* query first crypto library for chacha support and then, if needed, query dco (dco-win supports chacha starting from Win11)
Changes from v103:
* Query DCO code for default --data-ciphers only on Windows
Changes from v102:
* use "windows-driver ovpn-dco" without trailing "-win", since "windows" is already implied by option name.
Changes from v101:
* move tuntap_is_dco_win() check from init.c to open_tun() in tun.c
* move linksock_print_addr() into create_socket_dco_win() to simplify link_socket_init_phase2()
* fix chachapoly support on Windows for non-DCO case
Changes from v100:
* rebased (fixed conflicts in options.h and tun.h)
Changes from v3:
* rename WINDOWS_DRIVER_WINDCO to WINDOWS_DRIVER_DCO
* add reference string check
Changes from v2:
* added is_tun_type_set() and removed real_tun_init flag
* moved link-close to do_close_tun()
Changes from v1:
* use suffix _dco_win instead of _windco
* create helper function to retrieve last error from socket object
src/openvpn/dco.c | 4 +- src/openvpn/forward.c | 8 ++++ src/openvpn/init.c | 24 +++++++++++- src/openvpn/options.c | 33 ++++++++++++---- src/openvpn/options.h | 15 +++----- src/openvpn/socket.c | 89 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/socket.h | 25 ++++++++---- src/openvpn/tun.c | 58 ++++++++++++++++++++++------ src/openvpn/tun.h | 66 ++++++++++++++++++++++++-------- 9 files changed, 262 insertions(+), 60 deletions(-)
src/openvpn/dco.c +2 -2
@@ -229,13 +229,13 @@ dco_check_startup_option_conflict(int msglevel, const struct options *o)if (o->mode ==MODE_SERVER ) {msg (msglevel,"Only client and p2p data channel offload is supported " -"with ovpn-dco-win." ); +"with ovpn-dco." );return false; }if (o->persist_tun) { -msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +msg (msglevel,"--persist-tun is not supported with ovpn-dco." );return false; }#elif defined(TARGET_LINUX )
src/openvpn/forward.c +8 -0
@@ -864,9 +864,17 @@ read_incoming_link(struct context *c)return ; } +/* check_status() call below resets last-error code */ +bool dco_win_timeout =tuntap_is_dco_win_timeout (c->c1.tuntap, status); +/* check recvfrom status */ check_status (status,"read" , c->c2.link_socket,NULL ); +if (dco_win_timeout) + { +trigger_ping_timeout_signal (c); + } +/* Remove socks header if applicable */ socks_postprocess_incoming_link (c);
src/openvpn/init.c +22 -2
@@ -1699,7 +1699,8 @@ do_init_tun(struct context *c) c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es, - &c->net_ctx); + &c->net_ctx, + c->c1.tuntap);#ifdef _WIN32 c->c1.tuntap->windows_driver = c->options.windows_driver;
@@ -1723,7 +1724,7 @@ can_preserve_tun(struct tuntap *tt)#ifdef TARGET_ANDROID return false;#else -return tt; +return is_tun_type_set (tt);#endif }
@@ -1934,6 +1935,16 @@ do_close_tun_simple(struct context *c)static void do_close_tun (struct context *c,bool force) { +/* With dco-win we open tun handle in the very beginning. +* In case when tun wasn't opened - like we haven't connected, +* we still need to close tun handle +*/ +if (tuntap_is_dco_win (c->c1.tuntap) && !is_tun_type_set (c->c1.tuntap)) + { +do_close_tun_simple (c); +return ; + } +if (!c->c1.tuntap || !c->c1.tuntap_owned) {return ;
@@ -3574,6 +3585,15 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +/* in dco-win case, link socket is a tun handle which is +* closed in do_close_tun(). Set it to UNDEFINED so +* we won't use WinSock API to close it. */ +if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket + && c->c2.link_socket->info.dco_installed) + { + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/options.c +26 -7
@@ -3338,9 +3338,11 @@ options_postprocess_mutate_invariant(struct options *options)#ifdef _WIN32const int dev =dev_type_enum (options->dev, options->dev_type); -/* when using wintun, kernel doesn't send DHCP requests, so don't use it */ -if (options->windows_driver ==WINDOWS_DRIVER_WINTUN - && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) +/* when using wintun/ovpn-dco, kernel doesn't send DHCP requests, so don't use it */ +if ((options->windows_driver ==WINDOWS_DRIVER_WINTUN + || options->windows_driver ==WINDOWS_DRIVER_DCO ) + && (options->tuntap_options.ip_win32_type ==IPW32_SET_DHCP_MASQ + || options->tuntap_options.ip_win32_type ==IPW32_SET_ADAPTIVE )) { options->tuntap_options.ip_win32_type =IPW32_SET_NETSH ; }
@@ -3434,7 +3436,17 @@ options_postprocess_setdefault_ncpciphers(struct options *o)/* custom --data-ciphers set, keep list */ return ; } -else if (cipher_valid ("CHACHA20-POLY1305" )) + +/* check if crypto library supports chacha */ +bool can_do_chacha =cipher_valid ("CHACHA20-POLY1305" ); + +if (can_do_chacha &&dco_enabled (o)) + { +/* also make sure that dco supports chacha */ + can_do_chacha =tls_item_in_cipher_list ("CHACHA20-POLY1305" ,dco_get_supported_ciphers ()); + } + +if (can_do_chacha) { o->ncp_ciphers ="AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305" ; }
@@ -4167,7 +4179,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4554,13 +4567,19 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco")) + { +return WINDOWS_DRIVER_DCO ; + } else { -msg (msglevel,"--windows-driver must be tap-windows6 or wintun" ); +msg (msglevel,"--windows-driver must be tap-windows6, wintun " +"or ovpn-dco" );return WINDOWS_DRIVER_UNSPECIFIED ; } } -#endif +#endif /* ifdef _WIN32 */ /* * parse/print topology coding
src/openvpn/options.h +5 -10
@@ -876,24 +876,19 @@ void options_string_import(struct options *options,bool key_is_external (const struct options *options); -#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) -/** * Returns whether the current configuration has dco enabled. */ static inline bool dco_enabled (const struct options *o) { +#if defined(_WIN32) +return o->windows_driver ==WINDOWS_DRIVER_DCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} - -#else /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))*/ - -static inline bool -dco_enabled (const struct options *o) -{ +#else return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/socket.c +83 -6
137 lines not on this page · raw message
src/openvpn/socket.h +18 -7
@@ -34,6 +34,7 @@#include "proxy.h" #include "socks.h" #include "misc.h" +#include "tun.h" /* * OpenVPN's default port number as assigned by IANA.
@@ -937,7 +938,8 @@ socket_connection_reset(const struct link_socket *sock, int status) {const int err =openvpn_errno ();#ifdef _WIN32 -return err ==WSAECONNRESET || err ==WSAECONNABORTED ; +return err ==WSAECONNRESET || err ==WSAECONNABORTED + || err ==ERROR_CONNECTION_ABORTED ;#else return err ==ECONNRESET ;#endif
@@ -1048,6 +1050,11 @@ link_socket_read_udp_win32(struct link_socket *sock, struct link_socket_actual *from) {sockethandle_t sh = { .s = sock->sd }; +if (sock->info.dco_installed) + { +addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + sh.is_handle = true; + }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1057,7 +1064,7 @@ int link_socket_read_udp_posix(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from); -#endif +#endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int
@@ -1065,7 +1072,10 @@ link_socket_read(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *from) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) + || sock->info.dco_installed) + /* unified UDPv4 and UDPv6, for DCO the kernel + * will strip the length header */ { int res;
@@ -1106,19 +1116,19 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );if (status <0 ) { - err =WSAGetLastError (); + err =SocketHandleGetLastError (sh); } }socket_send_queue (sock, buf, to);if (status <0 ) { -WSASetLastError (err); +SocketHandleSetLastError (sh, err);return status; }else
@@ -1180,8 +1190,9 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ + if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) { + /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); } else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
src/openvpn/tun.c +47 -11
114 lines not on this page · raw message
src/openvpn/tun.h +51 -15
104 lines not on this page · raw message
Signature · 1 line
2.23.0.windows.1
[Openvpn-devel] [PATCH applied] Re: dco-win: implement ovpn-dco support in P2P Windows code path
Thanks for the test reports. I had stared-at-code in v102, and the changes 102->105 are still fine with me.
I have subjected this to build tests on github (fine), and had my test machinery chew on the linux and freebsd DCO and non-DCO builds very thoroughly, as this touches "related" code paths. Things definitely look good now .-)
Your patch has been applied to the master branch.
commit 3adbc5c6a221f686764c0ff841daf1c95b90abcc
Author: Antonio Quartulli Date: Thu Aug 25 16:14:49 2022 +0300
dco-win: implement ovpn-dco support in P2P Windows code path
Signed-off-by: Arne Schwabe <[email protected]...>
Signed-off-by: Lev Stipakov <[email protected]...>
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25108.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: dco-win: add documentation to README.dco.md
In reply to Antonio QuartulliNot very much to review here, anyway :-)
Your patch has been applied to the master branch.
commit a8b00c908b4b8567dcfd792b7ab1d9005bcc587b
Author: Antonio Quartulli Date: Sat Aug 13 22:42:21 2022 +0200
dco-win: add documentation to README.dco.md
Signed-off-by: Arne Schwabe <[email protected]...>
Signed-off-by: Lev Stipakov <[email protected]...>
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24921.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v101 5/7] dco-win: update GH Actions config file
In reply to Antonio QuartulliHi,
.github/workflows/build.yaml
Quoted 10 lines · Antonio Quartulli
Signed-off-by Lev Stipakov <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>--- .github/workflows/build.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-).github/workflows/build.yaml +0
-0
This does no longer apply (Arne has sneaked in other updates to build.yaml).
When you send a rebase, please include something resembling a commit message :-) - otherwise the "empty commit message whitespace dragon" will eat the patch.
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]...PATCH v102 5/7 dco-win: update GH Actions config file
In reply to Antonio QuartulliIn order to build OpenVPN with DCO support on Windows there is no need to pull the full ovpn-dco-win source code, because we now ship the UAPI header within OpenVPN directly. This also eliminates the need to specify the DCO_SOURCEDIR var.
At the same time, DCO is always enabled therefore passing --enable-dco at configure time is not needed anymore.
---
Changes from v101:
* rebased
.github/workflows/build.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
.github/workflows/build.yaml +1 -6
@@ -59,11 +59,6 @@ jobs: steps: - name: Install dependencies run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip - - name: Checkout ovpn-dco-win - uses: actions/[email protected]... - with: - repository: OpenVPN/ovpn-dco-win - path: ovpn-dco-win - name: Checkout OpenVPN uses: actions/[email protected]... with:
@@ -151,7 +146,7 @@ jobs: run: cp ./tap-windows-${TAP_WINDOWS_VERSION}/include/tap-windows.h ${HOME}/mingw/opt/include/ - name: configure OpenVPN - run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig DCO_SOURCEDIR=$(realpath ../ovpn-dco-win) LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 --enable-dco + run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${CHOST} --disable-lz4 working-directory: openvpn - name: build OpenVPN
Signature · 1 line
2.30.2
[Openvpn-devel] [PATCH applied] Re: dco-win: update GH Actions config file
Your patch has been applied to the master branch.
commit 26d619277284f346f1d45c15bf0bbbdbda4a99f9
Author: Antonio Quartulli Date: Fri Aug 26 10:41:11 2022 +0200
dco-win: update GH Actions config file
Signed-off-by: Lev Stipakov <[email protected]...>
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25120.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering