Introduce ovpn-dco(-win) support
v2 cover Introduce ovpn-dco(-win) support
Hi all,
I am happy to publish the second version of the RFC ovpn-dco support!
This is going to be the *last RFC prototype* before submitting the code for official review and (possible) merge.
For this reason, please have a look, test and speak up any concern you may have!
The code has changed quite a lot compared to the previous RFC:
* DCO key handling has been refactored so that we now have two different functions for:
- installing a new key into DCO
- swapping keys after the new key is promoted to primary These two mechanisms were earlier combined in a key-dance function that now does not exist anymore.
* the DCO API has been cleaned up:
- dco.h contains the DCO API that the rest of the OpenVPN code is supposed to invoke. These functions are some kind of glue code between OpenVPN and the real ovpn-dco(-win).
- dco_internal.h contains the actual driver API. Its implementation is platform dependant and can be found in dco_win.c or dco_linux.c.
* DCO should happily work with both iproute2 and sitnl as it does not directly depend on either one. net_iface_new/del are now implemented in both backends.
* added Linux DCO build in our GitHub Actions script.
NOTE: the 'none' cipher is still supported but we're discussing whether to drop support in ovpn-dco before the release.
NOTE2: this patchset requires the patch "tun: remove tun_finalize()" to be applied on master first.
Linux DCO supports both client and server mode, while Windows DCO works in client mode only.
Please test, break and have fun!!
Happy weekend!
----------------
As mentioned in the previous version:
This implementation supports both dco for Linux and for Windows.
* For Linux, please get the ovpn-dco kernel module source at:
https://gitlab.com/openvpn/ovpn-dco
(alternatively, it is also packaged on various distributions along with OpenVPN3-for-Linux)
* For Windows, a snapshot of the driver can be found on:
https://github.com/OpenVPN/ovpn-dco-win/actions
(note that "test signing" must be enabled on your Windows box, for the driver to be accepted. Instructions to enable this mode are here:
https://github.com/OpenVPN/ovpn-dco-win/blob/master/README.md#installation
DO IT AT YOUR OWN RISK)
-----------------
Antonio Quartulli (4):
networking: silence warnings about unused arguments
networking: implement net_iface_new and net_iface_del APIs
ovpn-dco: introduce linux data-channel offload support GitHub Actions: add Linux DCO build (on Ubuntu 20.04)
Arne Schwabe (3):
networking: remove duplicate methods from networking_sitnl.c
tun: extract close_tun_handle into its own fucntion and print correct
type
ovpn-dco-win: introduce windows data-channel offload support
.github/workflows/build.yaml | 19 +- Changes.rst | 7 + README.dco.md | 131 +++ config-msvc.h | 2 + configure.ac | 34 + contrib/vcpkg-ports/ovpn-dco-win/CONTROL | 3 + .../vcpkg-ports/ovpn-dco-win/portfile.cmake | 14 + doc/man-sections/advanced-options.rst | 13 + src/compat/Makefile.am | 3 +- src/compat/compat-dco_get_overlapped_result.c | 44 + src/compat/compat.h | 6 + src/compat/compat.vcxproj | 1 + src/compat/compat.vcxproj.filters | 3 + src/openvpn/Makefile.am | 3 + src/openvpn/crypto.c | 1 + src/openvpn/dco.c | 631 +++++++++++++ src/openvpn/dco.h | 279 ++++++ src/openvpn/dco_internal.h | 85 ++ src/openvpn/dco_linux.c | 869 ++++++++++++++++++ src/openvpn/dco_linux.h | 60 ++ src/openvpn/dco_win.c | 354 +++++++ src/openvpn/dco_win.h | 59 ++ src/openvpn/errlevel.h | 2 + src/openvpn/event.h | 3 + src/openvpn/forward.c | 59 +- src/openvpn/init.c | 163 +++- src/openvpn/init.h | 2 +- src/openvpn/misc.h | 3 +- src/openvpn/mtcp.c | 61 +- src/openvpn/mudp.c | 13 + src/openvpn/multi.c | 169 +++- src/openvpn/multi.h | 6 +- src/openvpn/networking.h | 36 +- src/openvpn/networking_iproute2.c | 34 + src/openvpn/networking_sitnl.c | 78 +- src/openvpn/openvpn.vcxproj | 8 +- src/openvpn/openvpn.vcxproj.filters | 17 +- src/openvpn/options.c | 37 +- src/openvpn/options.h | 15 + src/openvpn/ovpn-dco-win.h | 107 +++ src/openvpn/ovpn_dco_linux.h | 240 +++++ src/openvpn/socket.c | 105 ++- src/openvpn/socket.h | 21 +- src/openvpn/ssl.c | 81 +- src/openvpn/ssl.h | 7 +- src/openvpn/ssl_common.h | 23 + src/openvpn/ssl_ncp.c | 2 +- src/openvpn/tun.c | 243 +++-- src/openvpn/tun.h | 62 +- tests/unit_tests/openvpn/test_networking.c | 25 +- 50 files changed, 4005 insertions(+), 238 deletions(-) create mode 100644 README.dco.md create mode 100644 contrib/vcpkg-ports/ovpn-dco-win/CONTROL create mode 100644 contrib/vcpkg-ports/ovpn-dco-win/portfile.cmake create mode 100644 src/compat/compat-dco_get_overlapped_result.c create mode 100644 src/openvpn/dco.c create mode 100644 src/openvpn/dco.h create mode 100644 src/openvpn/dco_internal.h create mode 100644 src/openvpn/dco_linux.c create mode 100644 src/openvpn/dco_linux.h 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 create mode 100644 src/openvpn/ovpn_dco_linux.h
Signature · 1 line
2.34.1
RFC v2 1/7 networking: remove duplicate methods from networking_sitnl.c
From: Arne Schwabe <[email protected]...>
The net_ctx_init/reset/free methods of sitnl are the same dummy methods that are already defined for non-Linux platforms in the networking.h header.
--- src/openvpn/networking.h | 7 ++++++- src/openvpn/networking_sitnl.c | 22 ---------------------- 2 files changed, 6 insertions(+), 23 deletions(-)
src/openvpn/networking.h +6 -1
@@ -33,7 +33,12 @@ struct context;/* define mock types to ensure code builds on any platform */ typedef void *openvpn_net_ctx_t ;typedef void *openvpn_net_iface_t ; +#endif /* ifdef ENABLE_SITNL */ +/* Only the iproute2 backend implements these functions, +* the rest can rely on these stubs +*/ +#if !defined(ENABLE_IPROUTE )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -51,7 +56,7 @@ net_ctx_free(openvpn_net_ctx_t *ctx) { (void )ctx; } -#endif /* ifdef ENABLE_SITNL */ +#endif /* !defined(ENABLE_IPROUTE) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +0 -22
@@ -595,28 +595,6 @@ net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, }#ifdef ENABLE_SITNL - -int -net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) -{ - (void )c; - (void )ctx; - -return 0 ; -} - -void -net_ctx_reset (openvpn_net_ctx_t *ctx) -{ - (void )ctx; -} - -void -net_ctx_free (openvpn_net_ctx_t *ctx) -{ - (void )ctx; -} -int net_route_v4_best_gw (openvpn_net_ctx_t *ctx,const in_addr_t *dst,in_addr_t *best_gw,char *best_iface)
Signature · 1 line
2.34.1
RFC v2 2/7 networking: silence warnings about unused arguments
In reply to Antonio QuartulliIn the net_ctx_init() stub definition, arguments are not used and therefore they should be explicitly marked to avoid compiler warnings.
--- src/openvpn/networking.h | 3 +++ 1 file changed, 3 insertions(+)
src/openvpn/networking.h +3 -0
@@ -42,6 +42,9 @@ typedef void *openvpn_net_iface_t;static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) { + (void )c; + (void )ctx; +return 0 ; }
Signature · 1 line
2.34.1
RFC v2 3/7 networking: implement net_iface_new and net_iface_del APIs
In reply to Antonio QuartulliThese two new methods can be used to create and delete a tun or an ovpn-dco interface via networking API.
Implementations for SITNL and iproute2 are provided
--- src/openvpn/networking.h | 26 ++++++++++ src/openvpn/networking_iproute2.c | 34 ++++++++++++ src/openvpn/networking_sitnl.c | 60 ++++++++++++++++++++++ tests/unit_tests/openvpn/test_networking.c | 22 +++++++- 4 files changed, 141 insertions(+), 1 deletion(-)
src/openvpn/networking.h +26 -0
@@ -35,6 +35,12 @@ typedef void *openvpn_net_ctx_t;typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ +enum iface_type { +IFACE_DUMMY , +IFACE_TUN , +IFACE_OVPN_DCO , +}; +/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */
@@ -87,6 +93,26 @@ void net_ctx_reset(openvpn_net_ctx_t *ctx);*/ void net_ctx_free (openvpn_net_ctx_t *ctx); +/** +* Add a new interface +* +* @param ctx the implementation specific context +* @param iface interface to create +* @param type interface type (see enum iface_type declaration) +* @return int 0 on success, negative error code on error +*/ +int net_iface_new (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface, +enum iface_type type); + +/** +* Remove an interface +* +* @param ctx the implementation specific context +* @param iface interface to delete +* @return int 0 on success, negative error code on error +*/ +int net_iface_del (openvpn_net_ctx_t *ctx,const openvpn_net_iface_t *iface); +/** * Bring interface up or down. *
src/openvpn/networking_iproute2.c +34 -0
@@ -38,6 +38,12 @@#include <stdbool.h> #include <netinet/in.h> +static const char *iface_type_str[] = { + [IFACE_DUMMY ] ="dummy" , + [IFACE_TUN ] ="tun" , + [IFACE_OVPN_DCO ] ="ovpn-dco" , +}; +int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,6 +69,34 @@ net_ctx_free(openvpn_net_ctx_t *ctx)gc_free (&ctx->gc); } +int +net_iface_new (openvpn_net_ctx_t *ctx,const char *iface,enum iface_type type) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link add %s type %s" , iproute_path, iface, + iface_type_str[type]); +argv_msg (M_INFO , &argv); +openvpn_execve_check (&argv, ctx->es,S_FATAL ,"Linux ip link add failed" ); + +argv_free (&argv); + +return 0 ; +} + +int +net_iface_del (openvpn_net_ctx_t *ctx,const char *iface) +{ +struct argv argv =argv_new (); + +argv_printf (&argv,"%s link del %s" , iproute_path, iface); +openvpn_execve_check (&argv, ctx->es,S_FATAL ,"Linux ip link del failed" ); + +argv_free (&argv); + +return 0 ; +} +int net_iface_up (openvpn_net_ctx_t *ctx,const char *iface,bool up) {
src/openvpn/networking_sitnl.c +60 -0
72 lines not on this page · raw message
tests/unit_tests/openvpn/test_networking.c +21 -1
@@ -13,6 +13,20 @@ net__iface_up(bool up)return net_iface_up (NULL , iface, up); } +static int +net__iface_new (const char *name,enum iface_type type,char *type_str) +{ +printf ("CMD: ip link add %s type %s\n" , name, type_str); +return net_iface_new (NULL , name, type); +} + +static int +net__iface_del (const char *name) +{ +printf ("CMD: ip link del %s\n" , name); +return net_iface_del (NULL , name); +} +static int net__iface_mtu_set (int mtu) {
@@ -191,7 +205,7 @@ net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_str,static void usage (char *name) { -printf ("Usage: %s <0-7>\n" , name); +printf ("Usage: %s <0-9>\n" , name); }int
@@ -243,6 +257,12 @@ main(int argc, char *argv[])case 7 :return net__route_v6_add_gw ("2001:cafe:babe::" ,48 ,"2001::2" ,600 ); +case 8 : +return net__iface_new ("dummy0815" ,IFACE_DUMMY ,"dummy" ); + +case 9 : +return net__iface_del ("dummy0815" ); +default :printf ("invalid test: %d\n" , test);break ;
Signature · 1 line
2.34.1
RFC v2 4/7 ovpn-dco: introduce linux data-channel offload support
In reply to Antonio QuartulliImplement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.
--- Changes.rst | 7 + README.dco.md | 123 +++ configure.ac | 27 + doc/man-sections/advanced-options.rst | 13 + src/openvpn/Makefile.am | 2 + src/openvpn/crypto.c | 1 + src/openvpn/dco.c | 603 ++++++++++++++ src/openvpn/dco.h | 279 +++++++ src/openvpn/dco_internal.h | 84 ++ src/openvpn/dco_linux.c | 869 +++++++++++++++++++++ src/openvpn/dco_linux.h | 60 ++ src/openvpn/errlevel.h | 2 + src/openvpn/event.h | 3 + src/openvpn/forward.c | 59 +- src/openvpn/init.c | 131 +++- src/openvpn/init.h | 2 +- src/openvpn/misc.h | 3 +- src/openvpn/mtcp.c | 61 +- src/openvpn/mudp.c | 13 + src/openvpn/multi.c | 169 +++- src/openvpn/multi.h | 6 +- src/openvpn/openvpn.vcxproj | 4 +- src/openvpn/openvpn.vcxproj.filters | 6 + src/openvpn/options.c | 15 + src/openvpn/options.h | 20 + src/openvpn/ovpn_dco_linux.h | 240 ++++++ src/openvpn/socket.h | 1 + src/openvpn/ssl.c | 81 +- src/openvpn/ssl.h | 7 +- src/openvpn/ssl_common.h | 23 + src/openvpn/ssl_ncp.c | 2 +- src/openvpn/tun.c | 127 ++- src/openvpn/tun.h | 6 +- tests/unit_tests/openvpn/test_networking.c | 3 + 34 files changed, 2921 insertions(+), 131 deletions(-) create mode 100644 README.dco.md create mode 100644 src/openvpn/dco.c create mode 100644 src/openvpn/dco.h create mode 100644 src/openvpn/dco_internal.h create mode 100644 src/openvpn/dco_linux.c create mode 100644 src/openvpn/dco_linux.h create mode 100644 src/openvpn/ovpn_dco_linux.h
Changes.rst +7 -0
@@ -62,6 +62,13 @@ Optional ciphers in ``--data-ciphers`` Ciphers in ``--data-ciphers`` can now be prefixed with a ``?`` to mark those as optional and only use them if the SSL library supports them. +Data channel offloading with ovpn-dco + 2.6.0+ implements support for data-channel offloading where the data packets + are directly processed and forwarded in kernel space thanks to the ovpn-dco + kernel module. The userspace openvpn program acts purely as a control plane + application. + + Deprecated features ------------------- ``inetd`` has been removed
README.dco.md new file +123 -0
123 lines not on this page · raw message
configure.ac +27 -0
@@ -142,6 +142,13 @@ AC_ARG_ENABLE( [enable_small="no"] ) +AC_ARG_ENABLE( + [dco], + [AS_HELP_STRING([--enable-dco], [enable data channel offload support using ovpn-dco kernel module @<:@default=no@:>@])], + , + [enable_dco="no"] +) + AC_ARG_ENABLE( [iproute2], [AS_HELP_STRING([--enable-iproute2], [enable support for iproute2 @<:@default=no@:>@])],
@@ -766,6 +773,26 @@ PKG_CHECK_MODULES( [] ) + + +if test "$enable_dco" = "yes"; then +dnl +dnl Include generic netlink library used to talk to ovpn-dco +dnl + + PKG_CHECK_MODULES([LIBNL_GENL], + [libnl-genl-3.0 >= 3.2.29], + [have_libnl="yes"], + [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] + ) + + CFLAGS="${CFLAGS} ${LIBNL_GENL_CFLAGS}" + LIBS="${LIBS} ${LIBNL_GENL_LIBS}" + + AC_DEFINE(ENABLE_DCO, 1, [Enable shared data channel offload]) + AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) +fi + if test "${with_crypto_library}" = "openssl"; then AC_ARG_VAR([OPENSSL_CFLAGS], [C compiler flags for OpenSSL]) AC_ARG_VAR([OPENSSL_LIBS], [linker flags for OpenSSL])
doc/man-sections/advanced-options.rst +13 -0
@@ -91,3 +91,16 @@ used when debugging or testing out special usage scenarios. *(Linux only)* Set the TX queue length on the TUN/TAP interface. Currently defaults to operating system default. +--disable-dco + Disables the opportunistic use the data channel offloading if available. + Without this option, OpenVPN will opportunistically use DCO mode if + the config options and the running kernel supports using DCO. + + Data channel offload currently requires data-ciphers to only contain + AEAD ciphers (AES-GCM and Chacha20-Poly1305) and Linux with the + ovpn-dco module. + + Note that some options have no effect or not available when + DCO mode is enabled. + + A platforms that do not support DCO ``disable-dco`` has no effect.
src/openvpn/Makefile.am +2 -0
@@ -53,6 +53,8 @@ openvpn_SOURCES = \ crypto.c crypto.h crypto_backend.h \ crypto_openssl.c crypto_openssl.h \ crypto_mbedtls.c crypto_mbedtls.h \ + dco.c dco.h dco_internal.h \ + dco_linux.c dco_linux.h \ dhcp.c dhcp.h \ env_set.c env_set.h \ errlevel.h \
src/openvpn/crypto.c +1 -0
@@ -888,6 +888,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, cipher_kt_iv_size(kt->cipher));warn_insecure_key_type (ciphername); } +if (md_defined (kt->digest)) { ctx->hmac =hmac_ctx_new ();
src/openvpn/dco.c new file +603 -0
603 lines not on this page · raw message
src/openvpn/dco.h new file +279 -0
279 lines not on this page · raw message
src/openvpn/dco_internal.h new file +84 -0
84 lines not on this page · raw message
src/openvpn/dco_linux.c new file +869 -0
869 lines not on this page · raw message
src/openvpn/dco_linux.h new file +60 -0
60 lines not on this page · raw message
src/openvpn/errlevel.h +2 -0
@@ -91,6 +91,7 @@#define D_OSBUF LOGLEV(3, 43, 0)/* show socket/tun/tap buffer sizes */ #define D_PS_PROXY LOGLEV(3, 44, 0)/* messages related to --port-share option */ #define D_IFCONFIG LOGLEV(3, 0, 0)/* show ifconfig info (don't mute) */ +#define D_DCO LOGLEV(3, 0, 0)/* show DCO related messages */ #define D_SHOW_PARMS LOGLEV(4, 50, 0)/* show all parameters on program initiation */ #define D_SHOW_OCC LOGLEV(4, 51, 0)/* show options compatibility string */
@@ -113,6 +114,7 @@#define D_TUN_RW LOGLEV(6, 69, M_DEBUG)/* show TUN/TAP reads/writes */ #define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG)/* show TAP-Windows driver debug info */ #define D_CLIENT_NAT LOGLEV(6, 69, M_DEBUG)/* show client NAT debug info */ +#define D_DCO_DEBUG LOGLEV(6, 69, M_DEBUG)/* show DCO related lowlevel debug messages */ #define D_SHOW_KEYS LOGLEV(7, 70, M_DEBUG)/* show data channel encryption keys */ #define D_SHOW_KEY_SOURCE LOGLEV(7, 70, M_DEBUG)/* show data channel key source entropy */
src/openvpn/event.h +3 -0
@@ -72,6 +72,9 @@#define MANAGEMENT_WRITE (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT))#define FILE_SHIFT 8#define FILE_CLOSED (1 << (FILE_SHIFT + READ_SHIFT)) +#define DCO_SHIFT 10 +#define DCO_READ (1 << (DCO_SHIFT + READ_SHIFT)) +#define DCO_WRITE (1 << (DCO_SHIFT + WRITE_SHIFT))/* * Initialization flags passed to event_set_init
src/openvpn/forward.c +55 -4
111 lines not on this page · raw message
src/openvpn/init.c +100 -31
233 lines not on this page · raw message
src/openvpn/init.h +1 -1
@@ -30,7 +30,7 @@* Baseline maximum number of events * to wait for. */ -#define BASE_N_EVENTS 4 +#define BASE_N_EVENTS 5void context_clear (struct context *c);
src/openvpn/misc.h +2 -1
@@ -32,10 +32,11 @@#include "buffer.h" #include "platform.h" +#include <stddef.h> +/* forward declarations */ struct plugin_list ; -/* Set standard file descriptors to /dev/null */ void set_std_files_to_null (bool stdin_only);
src/openvpn/mtcp.c +47 -14
120 lines not on this page · raw message
src/openvpn/mudp.c +13 -0
@@ -227,6 +227,19 @@ multi_process_io_udp(struct multi_context *m)multi_process_file_closed (m, mpp_flags); }#endif +#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) + else if (status & DCO_READ) + { +if (!IS_SIG (&m->top)) + { +bool ret = true; +while (ret) + { + ret =multi_process_incoming_dco (m); + } + } + } +#endif }/*
src/openvpn/multi.c +150 -19
242 lines not on this page · raw message
src/openvpn/multi.h +5 -1
@@ -98,7 +98,9 @@ struct client_connect_defer_state* server-mode. */ struct multi_instance { -struct schedule_entry se;/* this must be the first element of the structure */ +struct schedule_entry se;/* this must be the first element of the structure, +* We cast between this and schedule_entry so the +* beginning of the struct must be identical */ struct gc_arena gc;bool halt;int refcount;
@@ -308,6 +310,8 @@ void multi_process_float(struct multi_context *m, struct multi_instance *mi);bool multi_process_post (struct multi_context *m,struct multi_instance *mi,const unsigned int flags); +bool multi_process_incoming_dco (struct multi_context *m); +/**************************************************************************/ /** * Demultiplex and process a packet received over the external network
src/openvpn/openvpn.vcxproj +3 -1
@@ -253,8 +253,9 @@ <ClCompile Include="crypto.c" /> <ClCompile Include="crypto_openssl.c" /> <ClCompile Include="cryptoapi.c" /> - <ClCompile Include="env_set.c" /> + <ClCompile Include="dco.c" /> <ClCompile Include="dhcp.c" /> + <ClCompile Include="env_set.c" /> <ClCompile Include="error.c" /> <ClCompile Include="event.c" /> <ClCompile Include="fdmisc.c" />
@@ -335,6 +336,7 @@ <ClInclude Include="crypto_backend.h" /> <ClInclude Include="crypto_openssl.h" /> <ClInclude Include="cryptoapi.h" /> + <ClInclude Include="dco.h" /> <ClInclude Include="dhcp.h" /> <ClInclude Include="env_set.h" /> <ClInclude Include="errlevel.h" />
src/openvpn/openvpn.vcxproj.filters +6 -0
@@ -39,6 +39,9 @@ <ClCompile Include="dhcp.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="dco.c"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="error.c"> <Filter>Source Files</Filter> </ClCompile>
@@ -287,6 +290,9 @@ <ClInclude Include="cryptoapi.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="dco.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="dhcp.h"> <Filter>Header Files</Filter> </ClInclude>
src/openvpn/options.c +15 -0
@@ -60,6 +60,7 @@#include "forward.h" #include "ssl_verify.h" #include "platform.h" +#include "dco.h" #include <ctype.h> #include "memdbg.h"
@@ -105,6 +106,9 @@ const char title_string[] =#endif #endif " [AEAD]" +#ifdef ENABLE_DCO + " [DCO]" +#endif" built on " __DATE__ ;
@@ -3307,6 +3311,11 @@ options_postprocess_mutate(struct options *o) o->verify_hash_no_ca = true; } +/* check if any option should force disabling DCO */ +#if defined(TARGET_LINUX ) + o->tuntap_options.disable_dco =dco_check_option_conflict (D_DCO , o); +#endif +/* * Save certain parms before modifying options during connect, especially * when using --pull
@@ -5595,6 +5604,12 @@ add_option(struct options *options, options->windows_driver =parse_windows_driver (p[1 ],M_FATAL ); }#endif + else if (streq(p[0], "disable-dco") || streq(p[0], "dco-disable")) + { +#if defined(TARGET_LINUX ) + options->tuntap_options.disable_dco = true; +#endif + } else if (streq(p[0], "dev-node") && p[1] && !p[2]) {VERIFY_PERMISSION (OPT_P_GENERAL );
src/openvpn/options.h +20 -0
@@ -862,4 +862,24 @@ void options_string_import(struct options *options,unsigned int *option_types_found, struct env_set *es); +#if defined(ENABLE_DCO ) + +/** +* Returns whether the current configuration has dco enabled. +*/ +static inline bool +dco_enabled (const struct options *o) +{ +return !o->tuntap_options.disable_dco; +} + +#else + +static inline bool +dco_enabled (const struct options *o) +{ +return false; +} + +#endif #endif /* ifndef OPTIONS_H */
src/openvpn/ovpn_dco_linux.h new file +240 -0
15 lines not on this page · raw message
src/openvpn/ssl.c +59 -22
81 lines not on this page · raw message
src/openvpn/tun.c +94 -33
127 lines not on this page · raw message
tests/unit_tests/openvpn/test_networking.c +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
RFC v2 5/7 tun: extract close_tun_handle into its own fucntion and print correct type
In reply to Antonio QuartulliFrom: Arne Schwabe <[email protected]...>
This moves closing the tun handle into its own function and also prints the adapter type we are operating on, instead hardcoding it to tap-windows.
--- src/openvpn/tun.c | 75 ++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 34 deletions(-)
src/openvpn/tun.c +41 -34
@@ -6770,6 +6770,46 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gcargv_free (&argv); } +static +void close_tun_handle (struct tuntap * tt) +{ +const char * adaptertype =print_windows_driver (tt->windows_driver); +if (tt->hand !=NULL ) + { +dmsg (D_WIN32_IO_LOW ,"Attempting CancelIO on %s adapter" , adaptertype); +if (!CancelIo (tt->hand)) + { +msg (M_WARN |M_ERRNO ,"Warning: CancelIO failed on %s adapter" , adaptertype); + } + } + +dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped read event on %s adapter" , adaptertype); +overlapped_io_close (&tt->reads); + +dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped write event on %s adapter" , adaptertype); +overlapped_io_close (&tt->writes); + +if (tt->hand !=NULL ) + { +dmsg (D_WIN32_IO_LOW ,"Attempting CloseHandle on %s adapter" , adaptertype); +if (!CloseHandle (tt->hand)) + { +msg (M_WARN |M_ERRNO ,"Warning: CloseHandle failed on %s adapter" , adaptertype); + } + tt->hand =NULL ; + } + +if (tt->windows_driver ==WINDOWS_DRIVER_WINTUN ) + { +CloseHandle (tt->rw_handle.read); +CloseHandle (tt->rw_handle.write); +UnmapViewOfFile (tt->wintun_send_ring); +UnmapViewOfFile (tt->wintun_receive_ring); +CloseHandle (tt->wintun_send_ring_handle); +CloseHandle (tt->wintun_receive_ring_handle); + } +} +void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx) {
@@ -6839,43 +6879,10 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)dhcp_release (tt); -if (tt->hand !=NULL ) - { -dmsg (D_WIN32_IO_LOW ,"Attempting CancelIO on TAP-Windows adapter" ); -if (!CancelIo (tt->hand)) - { -msg (M_WARN |M_ERRNO ,"Warning: CancelIO failed on TAP-Windows adapter" ); - } - } - -dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped read event on TAP-Windows adapter" ); -overlapped_io_close (&tt->reads); - -dmsg (D_WIN32_IO_LOW ,"Attempting close of overlapped write event on TAP-Windows adapter" ); -overlapped_io_close (&tt->writes); - -if (tt->hand !=NULL ) - { -dmsg (D_WIN32_IO_LOW ,"Attempting CloseHandle on TAP-Windows adapter" ); -if (!CloseHandle (tt->hand)) - { -msg (M_WARN |M_ERRNO ,"Warning: CloseHandle failed on TAP-Windows adapter" ); - } - } +close_tun_handle (tt);free (tt->actual_name); -if (tt->windows_driver ==WINDOWS_DRIVER_WINTUN ) - { -CloseHandle (tt->rw_handle.read); -CloseHandle (tt->rw_handle.write); -UnmapViewOfFile (tt->wintun_send_ring); -UnmapViewOfFile (tt->wintun_receive_ring); -CloseHandle (tt->wintun_send_ring_handle); -CloseHandle (tt->wintun_receive_ring_handle); - } - -clear_tuntap (tt);free (tt);gc_free (&gc);
Signature · 1 line
2.34.1
RFC v2 6/7 ovpn-dco-win: introduce windows data-channel offload support
In reply to Antonio QuartulliFrom: Arne Schwabe <[email protected]...>
Implement the data-channel offloading using the ovpn-dco-win kernel module. See README.dco.md for more details.
--- .github/workflows/build.yaml | 6 +- README.dco.md | 8 + config-msvc.h | 2 + configure.ac | 29 +- contrib/vcpkg-ports/ovpn-dco-win/CONTROL | 3 + .../vcpkg-ports/ovpn-dco-win/portfile.cmake | 14 + src/compat/Makefile.am | 3 +- src/compat/compat-dco_get_overlapped_result.c | 44 +++ src/compat/compat.h | 6 + src/compat/compat.vcxproj | 1 + src/compat/compat.vcxproj.filters | 3 + src/openvpn/Makefile.am | 1 + src/openvpn/dco.c | 28 ++ src/openvpn/dco_internal.h | 1 + src/openvpn/dco_win.c | 354 ++++++++++++++++++ src/openvpn/dco_win.h | 59 +++ src/openvpn/init.c | 34 +- src/openvpn/openvpn.vcxproj | 4 +- src/openvpn/openvpn.vcxproj.filters | 11 +- src/openvpn/options.c | 22 +- src/openvpn/options.h | 13 +- src/openvpn/ovpn-dco-win.h | 107 ++++++ src/openvpn/socket.c | 105 +++++- src/openvpn/socket.h | 20 +- src/openvpn/tun.c | 43 ++- src/openvpn/tun.h | 56 ++- 26 files changed, 907 insertions(+), 70 deletions(-) create mode 100644 contrib/vcpkg-ports/ovpn-dco-win/CONTROL create mode 100644 contrib/vcpkg-ports/ovpn-dco-win/portfile.cmake create mode 100644 src/compat/compat-dco_get_overlapped_result.c 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
.github/workflows/build.yaml +4 -2
@@ -59,10 +59,12 @@ jobs: wget -c -P download-cache/ "https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz" wget -c -P download-cache/ "https://github.com/OpenSC/pkcs11-helper/archive/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.gz" wget -c -P download-cache/ "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz" + wget -c -O download-cache/ovpn-dco-win.zip "https://github.com/OpenVPN/ovpn-dco-win/archive/refs/heads/master.zip" tar zxf "download-cache/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.gz" tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz" tar zxf "download-cache/lzo-${LZO_VERSION}.tar.gz" unzip download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip + unzip download-cache/ovpn-dco-win.zip - name: Configure OpenSSL if: steps.cache.outputs.cache-hit != 'true'
@@ -119,7 +121,7 @@ jobs: run: cp ./tap-windows-9.23.3/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 DCO_INCLUDEDIR=$(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 working-directory: openvpn - name: build OpenVPN
@@ -269,7 +271,7 @@ jobs: uses: lukka/[email protected]... with: vcpkgGitCommitId: 'a2fcb03749ff5897b5985092934dc6057680c789' - vcpkgArguments: 'openssl lz4 lzo pkcs11-helper tap-windows6' + vcpkgArguments: 'openssl lz4 lzo pkcs11-helper tap-windows6 ovpn-dco-win' vcpkgTriplet: '${{ matrix.triplet }}-windows-ovpn' cleanAfterBuild: false
README.dco.md +8 -0
@@ -58,6 +58,12 @@ see a message like in your log. +Getting started (Windows) +------------------------- +Getting started under windows is currently for brave people having experience +with windows development. You need to compile openvpn yourself and also need +to get the test driver installed on your system. + DCO and P2P mode ---------------- DCO is also available when running OpenVPN in P2P mode without --pull/--client option.
@@ -103,6 +109,8 @@ Limitations by design - topology subnet is the only supported `--topology` for servers - iroute directives install routes on the host operating system, see also routing with ovpn-dco +- (ovpn-dco-win) client and p2p mode only +- (ovpn-dco-win) only AES-GCM-128/192/256 cipher support Current implementation limitations
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 +18 -11
@@ -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"
@@ -779,18 +780,24 @@ 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], + [libnl-genl-3.0 >= 3.2.29], + [have_libnl="yes"], + [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] + ) - PKG_CHECK_MODULES([LIBNL_GENL], - [libnl-genl-3.0 >= 3.2.29], - [have_libnl="yes"], - [AC_MSG_ERROR([libnl-genl-3.0 package not found or too old. Is the development package and pkg-config installed? Must be version 3.4.0 or newer])] - ) - - CFLAGS="${CFLAGS} ${LIBNL_GENL_CFLAGS}" - LIBS="${LIBS} ${LIBNL_GENL_LIBS}" + CFLAGS="${CFLAGS} ${LIBNL_GENL_CFLAGS}" + LIBS="${LIBS} ${LIBNL_GENL_LIBS}" + AC_DEFINE(ENABLE_DCO, 1, [Enable data channel offload for Linux]) + AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) + ;; - AC_DEFINE(ENABLE_DCO, 1, [Enable shared data channel offload]) - AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) + *-mingw*) + AC_MSG_NOTICE([NOTE: --enable-dco ignored on Windows because it's always enabled]) + ;; + esac fi if test "${with_crypto_library}" = "openssl"; then
contrib/vcpkg-ports/ovpn-dco-win/CONTROL new file +3 -0
@@ -0,0 +1,3 @@ +Source: ovpn-dco-win +Version: 0.6 +Description: OpenVPN Data Channel Offload. Note: This package only contains the headers for the driver.
contrib/vcpkg-ports/ovpn-dco-win/portfile.cmake new file +14 -0
@@ -0,0 +1,14 @@ +include(vcpkg_common_functions) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO OpenVPN/ovpn-dco-win + REF 2d0c1e0d12105c8cc28b1f5ef53afe01733310d4 + SHA512 ba794c3025637626200ce3372617f22f0f5188fd380c525848d3fdd0eaada7e59a896281442b88849ec7171052f3ffb454ddd6cb4762255bb5155ebbf76def24 +) + +file(COPY ${SOURCE_PATH}/uapi/ovpn-dco.h DESTINATION ${CURRENT_PACKAGES_DIR}/include/uapi) + +file(INSTALL + ${SOURCE_PATH}/COPYRIGHT.MIT + DESTINATION ${CURRENT_PACKAGES_DIR}/share/ovpn-dco-win RENAME copyright)
src/compat/Makefile.am +2 -1
@@ -28,4 +28,5 @@ libcompat_la_SOURCES = \ compat-gettimeofday.c \ compat-daemon.c \ compat-strsep.c \ - compat-versionhelpers.h + compat-versionhelpers.h \ + compat-dco_get_overlapped_result.c
src/compat/compat-dco_get_overlapped_result.c new file +44 -0
44 lines not on this page · raw message
src/compat/compat.h +6 -0
@@ -62,4 +62,10 @@ char *strsep(char **stringp, const char *delim);#endif +#if defined(__MINGW32__) && !defined(__MINGW64__) +BOOL dco_get_overlapped_result (HANDLE handle,OVERLAPPED * ov,DWORD * transferred,DWORD delay_millisec,BOOL unused); +#else +#define dco_get_overlapped_result GetOverlappedResultEx +#endif +#endif /* COMPAT_H */
src/compat/compat.vcxproj +1 -0
@@ -159,6 +159,7 @@ </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="compat-basename.c" /> + <ClCompile Include="compat-dco_get_overlapped_result.c" /> <ClCompile Include="compat-dirname.c" /> <ClCompile Include="compat-gettimeofday.c" /> <ClCompile Include="compat-daemon.c" />
src/compat/compat.vcxproj.filters +3 -0
@@ -30,6 +30,9 @@ <ClCompile Include="compat-strsep.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="compat-dco_get_overlapped_result.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="compat.h">
src/openvpn/Makefile.am +1 -0
@@ -55,6 +55,7 @@ openvpn_SOURCES = \ crypto_mbedtls.c crypto_mbedtls.h \ dco.c dco.h dco_internal.h \ dco_linux.c dco_linux.h \ + dco_win.c dco_win.h \ dhcp.c dhcp.h \ env_set.c env_set.h \ errlevel.h \
src/openvpn/dco.c +28 -0
@@ -44,6 +44,7 @@ static bool dco_multi_get_localaddr(struct multi_context *m, struct multi_instance *mi, struct sockaddr_storage *local) { +#if ENABLE_IP_PKTINFO struct context *c = &mi->context;if (!(c->options.sockflags &SF_USE_IP_PKTINFO ))
@@ -74,6 +75,9 @@ dco_multi_get_localaddr(struct multi_context *m, struct multi_instance *mi, }return true; +#else +return false; +#endif }int
@@ -424,6 +428,25 @@ dco_check_option_conflict_ce(const struct connection_entry *ce, int msglevel)return false; } +static bool +dco_check_option_conflict_platform (int msglevel,const struct options *o) +{ +#if defined(_WIN32) +if (o->mode ==MODE_SERVER ) + { +msg (msglevel,"Only client and p2p data channel offload is supported " +"with ovpn-dco-win." ); +return true; + } +if (o->persist_tun) + { +msg (msglevel,"--persist-tun is not supported with ovpn-dco-win." ); +return true; + } +#endif +return false; +} +bool dco_check_option_conflict (int msglevel,const struct options *o) {
@@ -438,6 +461,11 @@ dco_check_option_conflict(int msglevel, const struct options *o)return true; } +if (dco_check_option_conflict_platform (msglevel, o)) + { +return true; + } +if (dev_type_enum (o->dev, o->dev_type) !=DEV_TYPE_TUN ) {msg (msglevel,"Note: dev-type not tun, disabling data channel offload." );
src/openvpn/dco_internal.h +1 -0
@@ -28,6 +28,7 @@#if defined(ENABLE_DCO )#include "dco_linux.h" +#include "dco_win.h" /** * This file contains the internal DCO API definition.
src/openvpn/dco_win.c new file +354 -0
354 lines not on this page · raw message
src/openvpn/dco_win.h new file +59 -0
59 lines not on this page · raw message
src/openvpn/init.c +29 -5
@@ -1736,7 +1736,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;
@@ -1760,7 +1761,11 @@ do_open_tun(struct context *c)bool ret = false;#ifndef TARGET_ANDROID -if (!c->c1.tuntap) +if (!c->c1.tuntap +#ifdef _WIN32 + || (c->c1.tuntap && !c->c1.tuntap->dco.real_tun_init) +#endif + ) {#endif
@@ -1839,9 +1844,12 @@ do_open_tun(struct context *c)ovpn_dco_init (&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 opend the device for the socket */ +if (!is_windco (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)
@@ -3570,6 +3578,22 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)static void do_close_link_socket (struct context *c) { +#ifdef _WIN32 +if (c->c2.link_socket && c->c2.link_socket->info.dco_installed &&is_windco (c->c1.tuntap)) + { +ASSERT (c->c2.link_socket_owned); +ASSERT (c->c1.tuntap); + +/* We rely on the tun close to the handle if also setup +* routes etc, since they cannot be delete when the interface +* handle has been closed */ +if (true && !c->c1.tuntap->dco.real_tun_init) + { +do_close_tun_simple (c); + } + c->c2.link_socket->sd =SOCKET_UNDEFINED ; + } +#endif if (c->c2.link_socket && c->c2.link_socket_owned) {link_socket_close (c->c2.link_socket);
src/openvpn/openvpn.vcxproj +3 -1
@@ -254,6 +254,7 @@ <ClCompile Include="crypto_openssl.c" /> <ClCompile Include="cryptoapi.c" /> <ClCompile Include="dco.c" /> + <ClCompile Include="dco_win.c" /> <ClCompile Include="dhcp.c" /> <ClCompile Include="env_set.c" /> <ClCompile Include="error.c" />
@@ -337,6 +338,7 @@ <ClInclude Include="crypto_openssl.h" /> <ClInclude Include="cryptoapi.h" /> <ClInclude Include="dco.h" /> + <ClInclude Include="dco_win.h" /> <ClInclude Include="dhcp.h" /> <ClInclude Include="env_set.h" /> <ClInclude Include="errlevel.h" />
@@ -429,4 +431,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project> +</Project>
src/openvpn/openvpn.vcxproj.filters +10 -1
@@ -249,6 +249,9 @@ <ClCompile Include="ssl_util.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="dco_win.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="base64.h">
@@ -374,6 +377,9 @@ <ClInclude Include="multi.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="networking_windco.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="ntlm.h"> <Filter>Header Files</Filter> </ClInclude>
@@ -521,6 +527,9 @@ <ClInclude Include="win32-util.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="dco_win.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="openvpn_win32_resources.rc">
@@ -532,4 +541,4 @@ <Filter>Resource Files</Filter> </Manifest> </ItemGroup> -</Project> +</Project>
src/openvpn/options.c +18 -4
@@ -2249,6 +2249,11 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--windows-driver wintun requires --dev tun" ); } + +if (options->windows_driver ==WINDOWS_DRIVER_WINDCO ) + { +dco_check_option_conflict (M_USAGE , options); + }#endif /* ifdef _WIN32 */ /*
@@ -3001,8 +3006,8 @@ 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 +/* 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_WINDCO ) && (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 ;
@@ -3088,10 +3093,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" ;
@@ -3873,7 +3880,8 @@ options_string(const struct options *o,NULL , false,NULL , - ctx); + ctx, + NULL);if (tt) { tt_local = true;
@@ -4298,9 +4306,15 @@ parse_windows_driver(const char *str, const int msglevel) {return WINDOWS_DRIVER_WINTUN ; } + + else if (streq(str, "ovpn-dco-win")) + { +return WINDOWS_DRIVER_WINDCO ; + } 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 ; } }
src/openvpn/options.h +4 -9
@@ -862,24 +862,19 @@ void options_string_import(struct options *options,unsigned int *option_types_found, struct env_set *es); -#if defined(ENABLE_DCO ) -/** * 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_WINDCO ; +#elif defined(ENABLE_DCO )return !o->tuntap_options.disable_dco; -} -#else - -static inline bool -dco_enabled (const struct options *o) -{return false; +#endif /* defined(_WIN32) */ } -#endif #endif /* ifndef OPTIONS_H */
src/openvpn/ovpn-dco-win.h new file +107 -0
107 lines not on this page · raw message
src/openvpn/socket.c +99 -6
153 lines not on this page · raw message
src/openvpn/socket.h +15 -5
@@ -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.
@@ -1043,6 +1044,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); }
@@ -1060,7 +1066,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;
@@ -1101,19 +1110,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
@@ -1175,8 +1184,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 +34 -9
100 lines not on this page · raw message
src/openvpn/tun.h +40 -16
109 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC v2 7/7 GitHub Actions: add Linux DCO build (on Ubuntu 20.04)
In reply to Antonio Quartulli--- .github/workflows/build.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
.github/workflows/build.yaml +10 -3
@@ -150,21 +150,28 @@ jobs: sslpkg: "libssl-dev" libname: OpenSSL 1.1.1 ssllib: openssl + - os: ubuntu-20.04 + sslpkg: "libssl-dev" + libname: OpenSSL 1.1.1 + ssllib: openssl + extraconf: "--enable-dco" + nlpkg: "libnl-genl-3-dev" - name: "gcc - ${{matrix.os}} - ${{matrix.libname}}" + name: "gcc - ${{matrix.os}} - ${{matrix.libname}} ${{matrix.extraconf}}" env: SSLPKG: "${{matrix.sslpkg}}" + NLPKG: "${{matrix.nlpkg}}" runs-on: ${{matrix.os}} steps: - name: Install dependencies - run: sudo apt update && sudo apt install -y liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html libcmocka-dev python3-docutils libtool automake autoconf ${SSLPKG} + run: sudo apt update && sudo apt install -y liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html libcmocka-dev python3-docutils libtool automake autoconf ${SSLPKG} ${NLPKG} - name: Checkout OpenVPN uses: actions/[email protected]... - name: autoconf run: autoreconf -fvi - name: configure - run: ./configure --with-crypto-library=${{matrix.ssllib}} + run: ./configure --with-crypto-library=${{matrix.ssllib}} ${{matrix.extraconf}} - name: make all run: make -j3 - name: make check
Signature · 1 line
2.34.1
Hi all,
We would love to get eager early adopters to test OpenVPN2 with ovpn-dco support.
For this reason we are providing testing repositories that contain OpenVPN2 compiled out of the "dco" branch:
* OpenWRT feed
** https://github.com/OpenVPN/openvpn-dev-openwrt
* COPR repo (Fedora, CentOS, RHEL)
** for openvpn2: https://copr.fedorainfracloud.org/coprs/dsommers/openvpn-dco/
** for ovpn-dco: https://copr.fedorainfracloud.org/coprs/dsommers/openvpn3/
A repository for Debian/Ubuntu is in the making and will be available soon!
If you are excited about getting ovpn-dco running on your server, please test and provide feedback.
We already have various instances running this code together with ovpn-dco, but the larger the number of beta-testers the better!
Regards,
Signature · 1 line
Antonio Quartulli
Quoted 4 lines · Antonio Quartulli
* COPR repo (Fedora, CentOS, RHEL)
** for openvpn2: https://copr.fedorainfracloud.org/coprs/dsommers/openvpn-dco/
** for ovpn-dco: https://copr.fedorainfracloud.org/coprs/dsommers/openvpn3/
Just a few quick steps on how to test this on Fedora and RHEL (with clones).
First, ensure you have the a functional 'yum copr' command. This is normally available by default on Fedora and RHEL-8 and up.
Then run these commands:
# yum copr enable dsommers/openvpn-dco # yum copr enable dsommers/openvpn3 # yum install kmod-ovpn-dco openvpn
Then you can put your server configs into /etc/openvpn/server and client configs into /etc/openvpn/client.
To start the OpenVPN server:
# systemctl enable --now [email protected]...
To start the OpenVPN client:
# systemctl enable --now [email protected]...
These steps will also start OpenVPN automatically upon boot. If you don't want that, just replace 'enable --now' with 'start'.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc