Skip to contentSkip to conversation

ovpn-dco: introduce linux data-channel offload support

PATCH In review Antonio Quartulli 1 participant 6 messages May 19, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/5 ovpn-dco: introduce linux data-channel offload support

Implement the data-channel offloading using the ovpn-dco kernel module. See README.dco.md for more details.

Comments and bugfixes provided also by Kristof Provost <[email protected]...>

---

Changes from v2 (highlights):
* added more doc to the netlink code in dco_linux.c
* use IN6_IS_ADDR_V4MAPPED()
* simplify dco_p2p_add_new_peer/dco_installed logic
* invert call to dco_del_peer and setting peer_added to false
* change dco_status assignment to ternary if
* remove some double new lines
* make DCO_DEFAULT_METRIC define unique across platforms
* in ovpn_nl_msg_send just set nl_cb once with no if
* rework do_up based on kp's suggestion
* set timeout for the p2p case
* properly set dynamic_name (from kp)

 Changes.rst                                |   9 +
 README.dco.md                              | 123 +++
 configure.ac                               |  28 +
 dev-tools/special-files.lst                |   1 +
 doc/man-sections/advanced-options.rst      |  13 +
 doc/man-sections/server-options.rst        |   6 +
 src/openvpn/Makefile.am                    |   2 +
 src/openvpn/dco.c                          | 600 +++++++++++++
 src/openvpn/dco.h                          | 301 +++++++
 src/openvpn/dco_internal.h                 |  83 ++
 src/openvpn/dco_linux.c                    | 933 +++++++++++++++++++++
 src/openvpn/dco_linux.h                    |  62 ++
 src/openvpn/errlevel.h                     |   2 +
 src/openvpn/event.h                        |   3 +
 src/openvpn/forward.c                      |  85 +-
 src/openvpn/init.c                         | 191 ++++-
 src/openvpn/init.h                         |   4 +-
 src/openvpn/misc.h                         |   3 +-
 src/openvpn/mtcp.c                         |  62 +-
 src/openvpn/mudp.c                         |  13 +
 src/openvpn/multi.c                        | 217 ++++-
 src/openvpn/multi.h                        |   6 +-
 src/openvpn/networking_sitnl.c             |  11 +
 src/openvpn/openvpn.vcxproj                |   4 +-
 src/openvpn/openvpn.vcxproj.filters        |   6 +
 src/openvpn/options.c                      |  29 +
 src/openvpn/options.h                      |  20 +
 src/openvpn/ovpn_dco_linux.h               | 265 ++++++
 src/openvpn/socket.h                       |   1 +
 src/openvpn/ssl.c                          |  76 +-
 src/openvpn/ssl.h                          |   7 +-
 src/openvpn/ssl_common.h                   |  23 +
 src/openvpn/ssl_ncp.c                      |   2 +-
 src/openvpn/tun.c                          | 130 ++-
 src/openvpn/tun.h                          |   6 +-
 tests/unit_tests/openvpn/test_networking.c |   3 +
 36 files changed, 3170 insertions(+), 160 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 +9 -0
index 67a23c79..275f8d64 100644
@@ -79,6 +79,15 @@ Cookie based handshake for UDP server
     shake. The tls-crypt-v2 option allows controlling if older clients are
     accepted.
 
+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. Note that DCO will use DATA_V2 packets in P2P mode, therefore,
+    this implies that peers must be running 2.6.0+ in order to have P2P-NCP
+    which brings DATA_V2 packet support.
+
+
 Deprecated features
 -------------------
 ``inetd`` has been removed
README.dco.md new file +123 -0

123 lines not on this page · raw message

configure.ac +28 -0
index 9c898718..c5e09fb8 100644
@@ -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@:>@])],
@@ -760,6 +767,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.4.0],
+			  [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])
@@ -1196,6 +1223,7 @@ fi
 AM_CONDITIONAL([HAVE_SITNL], [false])
 
 if test "${enable_iproute2}" = "yes"; then
+	test "${enable_dco}" = "yes" && AC_MSG_ERROR([iproute2 support cannot be enabled when using DCO])
 	test -z "${IPROUTE}" && AC_MSG_ERROR([ip utility is required but missing])
 	AC_DEFINE([ENABLE_IPROUTE], [1], [enable iproute2 support])
 else if test "${have_sitnl}" = "yes"; then
dev-tools/special-files.lst +1 -0
index 64ee9e1a..33e830d7 100644
@@ -1,3 +1,4 @@
 E:doc/doxygen/doc_key_generation.h     # @verbatim section gets mistreated, exclude it
 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
doc/man-sections/advanced-options.rst +13 -0
index 5157c561..d5a6b4f2 100644
@@ -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 of 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 cannot be used when DCO mode
+  is enabled.
+
+  On platforms that do not support DCO ``disable-dco`` has no effect.
doc/man-sections/server-options.rst +6 -0
index 08ee7bd3..31992732 100644
@@ -321,6 +321,12 @@ fast hardware. SSL/TLS authentication must be used in this mode.
   from the kernel to OpenVPN. Once in OpenVPN, the ``--iroute`` directive
   routes to the specific client.
 
+  However, when using DCO, the ``--iroute`` directive is usually enough
+  for DCO to fully configure the routing table. The extra ``--route``
+  directive is required only if the expected behaviour is to route the
+  traffic for a specific network to the VPN interface also when the
+  responsible client is not connected (traffic will then be dropped).
+
   This option must be specified either in a client instance config file
   using ``--client-config-dir`` or dynamically generated using a
   ``--client-connect`` script.
src/openvpn/Makefile.am +2 -0
index 57729480..2eb627cc 100644
@@ -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 \
 	dns.c dns.h \
 	env_set.c env_set.h \
src/openvpn/dco.c new file +600 -0

600 lines not on this page · raw message

src/openvpn/dco.h new file +301 -0

301 lines not on this page · raw message

src/openvpn/dco_internal.h new file +83 -0

83 lines not on this page · raw message

src/openvpn/dco_linux.c new file +933 -0

933 lines not on this page · raw message

src/openvpn/dco_linux.h new file +62 -0

62 lines not on this page · raw message

src/openvpn/errlevel.h +2 -0
index e616a496..5bb1e65e 100644
@@ -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 */
@@ -114,6 +115,7 @@
 #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_XKEY               LOGLEV(6, 69, M_DEBUG)  /* show xkey-provider 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
index a472afbe..f2438f97 100644
@@ -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 +81 -4

137 lines not on this page · raw message

src/openvpn/init.c +153 -38

296 lines not on this page · raw message

src/openvpn/init.h +3 -1
index 2b8c2dcc..5cc2a990 100644
@@ -30,7 +30,7 @@
  * Baseline maximum number of events
  * to wait for.
  */
-#define BASE_N_EVENTS 4
+#define BASE_N_EVENTS 5
 
 void context_clear(struct context *c);
 
@@ -97,6 +97,8 @@ void reset_coarse_timers(struct context *c);
 
 bool do_deferred_options(struct context *c, const unsigned int found);
 
+bool finish_options(struct context *c);
+
 void inherit_context_child(struct context *dest,
                            const struct context *src);
 
src/openvpn/misc.h +2 -1
index 2a6c0b8b..11ec122a 100644
@@ -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 +48 -14

127 lines not on this page · raw message

src/openvpn/mudp.c +13 -0
index 0810fada..14aa7236 100644
@@ -380,6 +380,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 +174 -43

167 lines not on this page · raw message

src/openvpn/multi.h +5 -1
index f1e9ab91..12d73126 100644

Lines of this file are not shown. View the raw message.

src/openvpn/networking_sitnl.c +11 -0
index e6328090..7ffbeb95 100644

Lines of this file are not shown. View the raw message.

src/openvpn/openvpn.vcxproj +3 -1
index 860ef892..4213a1c7 100644

Lines of this file are not shown. View the raw message.

src/openvpn/openvpn.vcxproj.filters +6 -0
index f76e5923..9121bba4 100644

Lines of this file are not shown. View the raw message.

src/openvpn/options.c +29 -0
index 9ff384d0..d63cd535 100644

Lines of this file are not shown. View the raw message.

src/openvpn/options.h +20 -0
index c2937dc3..4d82538c 100644

Lines of this file are not shown. View the raw message.

src/openvpn/ovpn_dco_linux.h new file +265 -0

265 lines not on this page · raw message

src/openvpn/socket.h +1 -0
index 270a829f..b478f3a8 100644

Lines of this file are not shown. View the raw message.

src/openvpn/ssl.c +56 -20

76 lines not on this page · raw message

src/openvpn/ssl.h +5 -2
index 0ba86d3e..ba271971 100644

Lines of this file are not shown. View the raw message.

src/openvpn/ssl_common.h +23 -0
index cef2611b..9eb81fe9 100644

Lines of this file are not shown. View the raw message.

src/openvpn/ssl_ncp.c +1 -1
index 5d7e6dd3..0ed0fa13 100644

Lines of this file are not shown. View the raw message.

src/openvpn/tun.c +97 -33

130 lines not on this page · raw message

src/openvpn/tun.h +5 -1
index 4bc35916..cf02bf43 100644

Lines of this file are not shown. View the raw message.

tests/unit_tests/openvpn/test_networking.c +3 -0
index 10ed2cb5..befbb546 100644

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.35.1

Part of the diff is not shown here. View the raw message.

#1 lore raw

PATCH v3 2/5 tun: extract close_tun_handle into its own fucntion and print correct type

From: 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.

While at it, set the handle to NULL after closing, to prevent a double close due to multiple invocations of this helper.

---

Changes from v1:
* rebased

 src/openvpn/tun.c | 75 ++++++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 34 deletions(-)
src/openvpn/tun.c +41 -34
index e4b27a13..e8ec0d6b 100644
@@ -6766,6 +6766,46 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gc
     argv_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)
 {
@@ -6835,43 +6875,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.35.1
#2 lore raw

PATCH v3 3/5 ovpn-dco-win: introduce windows data-channel offload support

In reply to Antonio Quartulli

From: Arne Schwabe <[email protected]...>

Implement the data-channel offloading using the ovpn-dco-win kernel module. See README.dco.md for more details.

---

Changes from v1:
* properly handle peer timeout

 .github/workflows/build.yaml                  |   7 +-
 README.dco.md                                 |   9 +
 config-msvc.h                                 |   2 +
 configure.ac                                  |  29 +-
 dev-tools/special-files.lst                   |   1 +
 src/compat/Makefile.am                        |   3 +-
 src/compat/compat-dco_get_overlapped_result.c |  46 ++
 src/compat/compat.h                           |   8 +
 src/compat/compat.vcxproj                     |   1 +
 src/compat/compat.vcxproj.filters             |   3 +
 src/openvpn/Makefile.am                       |   3 +-
 src/openvpn/dco.c                             |  28 +-
 src/openvpn/dco.h                             |   5 +
 src/openvpn/dco_internal.h                    |   1 +
 src/openvpn/dco_linux.c                       |   6 +
 src/openvpn/dco_linux.h                       |   1 -
 src/openvpn/dco_win.c                         | 401 ++++++++++++++++++
 src/openvpn/dco_win.h                         |  58 +++
 src/openvpn/forward.c                         |   7 +
 src/openvpn/init.c                            |  34 +-
 src/openvpn/openvpn.vcxproj                   |   2 +
 src/openvpn/openvpn.vcxproj.filters           |   9 +
 src/openvpn/options.c                         |  24 +-
 src/openvpn/options.h                         |  15 +-
 src/openvpn/ovpn-dco-win.h                    | 108 +++++
 src/openvpn/socket.c                          | 105 ++++-
 src/openvpn/socket.h                          |  22 +-
 src/openvpn/tun.c                             |  44 +-
 src/openvpn/tun.h                             |  58 ++-
 29 files changed, 961 insertions(+), 79 deletions(-)
 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 +1 -6
index d34f4e9a..9301f76e 100644
@@ -56,11 +56,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:
@@ -148,7 +143,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 --enable-dco
         working-directory: openvpn
 
       - name: build OpenVPN
README.dco.md +9 -0
index e73e0fc2..14f97628 100644
@@ -58,6 +58,13 @@ 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.
@@ -109,6 +116,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) Chacha20-Poly1305 support available starting with Windows 11
 
 
 Current implementation limitations
config-msvc.h +2 -0
index b08beb52..b621f3fb 100644
@@ -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
index c5e09fb8..85921ddb 100644
@@ -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"
@@ -773,18 +774,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.4.0],
+					  [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.4.0],
-			  [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
dev-tools/special-files.lst +1 -0
index 33e830d7..6d0bc055 100644
@@ -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/compat/Makefile.am +2 -1
index 6eb991dc..6dba08aa 100644
@@ -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 +46 -0

46 lines not on this page · raw message

src/compat/compat.h +8 -0
index 026974a8..2b1ad6a6 100644
@@ -62,4 +62,12 @@ 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
index fe03a51a..1dacb503 100644
@@ -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
index 96ca026a..73fc9f91 100644
@@ -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 +2 -1
index 2eb627cc..9cadbcb2 100644
@@ -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 \
 	dns.c dns.h \
 	env_set.c env_set.h \
@@ -150,5 +151,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 +26 -2
index 1272f011..acbe5eb5 100644
@@ -415,6 +415,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)
 {
@@ -429,6 +448,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.");
@@ -437,7 +461,7 @@ dco_check_option_conflict(int msglevel, const struct options *o)
 
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
-        && !tls_item_in_cipher_list(o->ciphername, DCO_SUPPORTED_CIPHERS))
+        && !tls_item_in_cipher_list(o->ciphername, dco_get_supported_ciphers()))
     {
         msg(msglevel, "Note: --data-cipher-fallback with cipher '%s' "
             "disables data channel offload.", o->ciphername);
@@ -491,7 +515,7 @@ dco_check_option_conflict(int msglevel, const struct options *o)
     const char *token;
     while ((token = strsep(&tmp_ciphers, ":")))
     {
-        if (!tls_item_in_cipher_list(token, DCO_SUPPORTED_CIPHERS))
+        if (!tls_item_in_cipher_list(token, dco_get_supported_ciphers()))
         {
             msg(msglevel, "Note: cipher '%s' in --data-ciphers is not supported "
                 "by ovpn-dco, disabling data channel offload.", token);
src/openvpn/dco.h +5 -0
index 217b6b10..c28fd8ff 100644
@@ -176,6 +176,11 @@ void dco_update_keys(dco_context_t *dco, struct tls_multi *multi);
  */
 bool dco_available(int msglevel);
 
+/**
+ * Return list of colon-separated ciphers supported by platform
+ */
+const char *dco_get_supported_ciphers();
+
 /**
  * Install a DCO in the main event loop
  */
src/openvpn/dco_internal.h +1 -0
index c40c29ca..11d9a1b6 100644
@@ -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_linux.c +6 -0
index 1795bd39..d407d04a 100644
@@ -930,4 +930,10 @@ dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
     }
 }
 
+const char *
+dco_get_supported_ciphers()
+{
+    return "AES-128-GCM:AES-256-GCM:AES-192-GCM:CHACHA20-POLY1305";
+}
+
 #endif /* defined(ENABLE_DCO) && defined(TARGET_LINUX) */
src/openvpn/dco_linux.h +0 -1
index 039761ae..18e35f04 100644
@@ -36,7 +36,6 @@ typedef enum ovpn_cipher_alg dco_cipher_t;
 
 #define DCO_IROUTE_METRIC   100
 #define DCO_DEFAULT_METRIC  200
-#define DCO_SUPPORTED_CIPHERS "AES-128-GCM:AES-256-GCM:AES-192-GCM:CHACHA20-POLY1305"
 
 typedef struct
 {
src/openvpn/dco_win.c new file +401 -0

401 lines not on this page · raw message

src/openvpn/dco_win.h new file +58 -0

58 lines not on this page · raw message

src/openvpn/forward.c +7 -0
index b345395a..9741b545 100644
@@ -859,6 +859,13 @@ read_incoming_link(struct context *c)
     /* check recvfrom status */
     check_status(status, "read", c->c2.link_socket, NULL);
 
+#ifdef _WIN32
+    if (dco_enabled(&c->options) && (status < 0) && (openvpn_errno() == ERROR_NETNAME_DELETED))
+    {
+        trigger_ping_timeout_signal(c);
+    }
+#endif
+
     /* Remove socks header if applicable */
     socks_postprocess_incoming_link(c);
 
src/openvpn/init.c +29 -5
index 172585d7..660194d4 100644
@@ -1673,7 +1673,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;
@@ -1697,7 +1698,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
 
@@ -1776,9 +1781,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 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)
@@ -3531,6 +3539,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 +2 -0
index 4213a1c7..e8c025ef 100644
@@ -277,6 +277,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="dns.c" />
     <ClCompile Include="env_set.c" />
@@ -364,6 +365,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="dns.h" />
     <ClInclude Include="env_set.h" />
src/openvpn/openvpn.vcxproj.filters +9 -0
index 9121bba4..76402942 100644
@@ -261,6 +261,9 @@
     <ClCompile Include="xkey_provider.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="dco_win.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="base64.h">
@@ -389,6 +392,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>
@@ -539,6 +545,9 @@
     <ClInclude Include="xkey_common.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="dco_win.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="openvpn_win32_resources.rc">
src/openvpn/options.c +19 -5
index d63cd535..156438ef 100644
@@ -2338,6 +2338,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 */
 
     /*
@@ -3108,8 +3113,8 @@ options_postprocess_mutate_invariant(struct options *options)
 #ifdef _WIN32
     const 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;
@@ -3205,10 +3210,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";
@@ -4033,7 +4040,8 @@ options_string(const struct options *o,
                       NULL,
                       false,
                       NULL,
-                      ctx);
+                      ctx,
+                      NULL);
         if (tt)
         {
             tt_local = true;
@@ -4458,13 +4466,19 @@ 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;
     }
 }
-#endif
+#endif /* ifdef _WIN32 */
 
 /*
  * parse/print topology coding
src/openvpn/options.h +5 -10
index 4d82538c..3a5b433e 100644
@@ -879,24 +879,19 @@ void options_string_import(struct options *options,
 
 bool key_is_external(const struct options *options);
 
-#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 /* if defined(ENABLE_DCO) */
-
-static inline bool
-dco_enabled(const struct options *o)
-{
+#else
     return false;
+#endif /* defined(_WIN32) */
 }
 
-#endif
 #endif /* ifndef OPTIONS_H */
src/openvpn/ovpn-dco-win.h new file +108 -0

108 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 +16 -6
index b478f3a8..b08933f0 100644
@@ -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.
@@ -1048,6 +1049,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 +1063,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 +1071,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 +1115,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 +1189,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 +35 -9

101 lines not on this page · raw message

src/openvpn/tun.h +42 -16

111 lines not on this page · raw message

Signature · 1 line
2.35.1
#3 lore raw

PATCH v3 4/5 GitHub Actions: add Linux DCO build (on Ubuntu 20.04)

In reply to Antonio Quartulli

---

Changes from v1:
* rebased

 .github/workflows/build.yaml | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
.github/workflows/build.yaml +8 -1
index 9301f76e..ef428db1 100644
@@ -201,15 +201,22 @@ jobs:
             libname: OpenSSL 1.1.1
             ssllib: openssl
             extraconf: "--disable-lzo --disable-lz4"
+          - 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}} ${{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
Signature · 1 line
2.35.1
#4 lore raw

PATCH v3 5/5 Add support for GitLab CI

In reply to Antonio Quartulli
---
 .gitlab-ci.yml         | 182 +++++++++++++++++++++++++++++++++++++++++
 .gitlab/build-check.sh |  23 ++++++
 .gitlab/build-deps.sh  | 157 +++++++++++++++++++++++++++++++++++
 3 files changed, 362 insertions(+)
 create mode 100644 .gitlab-ci.yml
 create mode 100755 .gitlab/build-check.sh
 create mode 100755 .gitlab/build-deps.sh
.gitlab-ci.yml new file +182 -0
new file mode 100644
index 00000000..fe25eb48
@@ -0,0 +1,182 @@
+stages:
+  - test
+
+variables:
+  JOBS: 3
+  PREFIX: ${CI_PROJECT_DIR}/builds
+  TAP_WINDOWS_VERSION: 9.24.6
+  LZO_VERSION: "2.10"
+  PKCS11_HELPER_VERSION: "1.22"
+  MBEDTLS_VERSION: "2.26.0"
+  MBEDTLS_CFLAGS: -I${CI_PROJECT_DIR}/builds/include
+  MBEDTLS_LIBS: -L${CI_PROJECT_DIR}/builds/lib -lmbedtls -lmbedx509 -lmbedcrypto
+  OPENSSL_VERSION: 1.1.1m
+  OPENSSL_CFLAGS: -I${CI_PROJECT_DIR}/builds/include
+  OPENSSL_LIBS: -L${CI_PROJECT_DIR}/builds/lib -lssl -lcrypto
+  SSLLIB: "openssl"
+
+default:
+  image: gcc:latest
+
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html build-essential python
+    - .gitlab/build-deps.sh
+
+  cache:
+    key: ${CI_JOB_NAME}
+    paths:
+      - download-cache/
+      - ${PREFIX}/
+
+dco:
+  variables:
+    EXTRA_CONFIG: "--enable-dco"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html build-essential python libnl-genl-3-dev
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+mtls-latest:
+  variables:
+    SSLLIB: "mbedtls"
+  script:
+    - .gitlab/build-check.sh
+
+mtls-2_16_11:
+  variables:
+    MBEDTLS_VERSION: "2.16.11"
+    SSLLIB: "mbedtls"
+  script:
+    - .gitlab/build-check.sh
+
+mtls-2_7_19:
+  variables:
+    MBEDTLS_VERSION: "2.7.19"
+    SSLLIB: "mbedtls"
+  script:
+    - .gitlab/build-check.sh
+
+ossl:
+  variables:
+    SSLLIB: "openssl"
+    EXTRA_SCRIPT: "make distcheck"
+  artifacts:
+    paths:
+      - src/openvpn/openvpn
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev build-essential unzip python3-docutils libssl-dev
+  script:
+    - .gitlab/build-check.sh
+
+ossl-gcc9:
+  image: gcc:9
+  script:
+    - .gitlab/build-check.sh
+
+ossl-fedora-latest:
+  image: fedora:latest
+  before_script:
+    - yum -y install libtool openssl-devel lzo-devel pam-devel lz4-devel man2html python gcc make autoconf automake wget
+  script:
+    - .gitlab/build-check.sh
+
+ossl-rockylinux-latest:
+  image: rockylinux:latest
+  before_script:
+    - yum -y install epel-release
+    - yum -y install libtool openssl-devel lzo-devel pam-devel lz4-devel man2html python39 gcc make autoconf automake wget
+  script:
+    - .gitlab/build-check.sh
+
+ossl-1_1_0:
+  variables:
+    OPENSSL_VERSION: "1.1.0l"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-1_0_2:
+  variables:
+    OPENSSL_VERSION: "1.0.2u"
+  script:
+    - .gitlab/build-check.sh
+
+
+#ossl-sanitizeaddr:
+#  variables:
+#    CFLAGS: "-fsanitize=address"
+#  script:
+#    - .gitlab/build-check.sh
+
+ossl-sanitizeleak:
+  variables:
+    CFLAGS: "-fsanitize=leak"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-sanitizeundef:
+  variables:
+    CFLAGS: "-fsanitize=undefined"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-win64:
+  variables:
+    CHOST: "x86_64-w64-mingw32"
+    EXTRA_CONFIG: "--disable-lz4"
+  artifacts:
+    paths:
+      - src/openvpn/openvpn.exe
+    name: "openvpn_win64-${CI_COMMIT_REF_SLUG}"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev build-essential mingw-w64 unzip man2html
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+ossl-win32:
+  variables:
+    CHOST: "i686-w64-mingw32"
+    EXTRA_CONFIG: "--disable-lz4"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev build-essential mingw-w64 unzip man2html
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+mtls-iproute2:
+  variables:
+    SSLLIB: "mbedtls"
+    EXTRA_CONFIG: "--enable-iproute2"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html build-essential iproute2 python
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+ossl-nolzo:
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq libpam0g-dev liblz4-dev build-essential unzip
+    - .gitlab/build-deps.sh
+  variables:
+    EXTRA_CONFIG: "--disable-lzo"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-small:
+  variables:
+    EXTRA_CONFIG: "--enable-small"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-asyncpush:
+  variables:
+    EXTRA_CONFIG: "--enable-async-push"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-no-mgmt:
+  variables:
+    EXTRA_CONFIG: "--disable-management"
+  script:
+    - .gitlab/build-check.sh
.gitlab/build-check.sh new file +23 -0
new file mode 100755
index 00000000..7ecb4255
@@ -0,0 +1,23 @@
+#!/bin/sh
+set -eux
+
+export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH:-}"
+
+autoreconf -vi
+
+if [ -z ${CHOST+x} ]; then
+	./configure --with-crypto-library="${SSLLIB}" ${EXTRA_CONFIG:-} || (cat config.log && exit 1)
+	make -j$JOBS
+	src/openvpn/openvpn --version || true
+	ldd src/openvpn/openvpn
+	make check
+	${EXTRA_SCRIPT:-}
+else
+	export TAP_CFLAGS="-I${PWD}/tap-windows-${TAP_WINDOWS_VERSION}/include"
+	export LZO_CFLAGS="-I${PREFIX}/include"
+	export LZO_LIBS="-L${PREFIX}/lib -llzo2"
+	export PKCS11_HELPER_LIBS="-L${PREFIX}/lib -lpkcs11-helper"
+	export PKCS11_HELPER_CFLAGS="-I${PREFIX}/include"
+	./configure --with-crypto-library="${SSLLIB}" --host=${CHOST} --build=x86_64-pc-linux-gnu --enable-pkcs11 --disable-plugins ${EXTRA_CONFIG:-} || (cat config.log && exit 1)
+	make -j${JOBS}
+fi
.gitlab/build-deps.sh new file +157 -0

157 lines not on this page · raw message

Signature · 1 line
2.35.1
#5 lore raw

Re: [Openvpn-devel] [PATCH v3 5/5] Add support for GitLab CI

Hi,

please ignore this patch - it was sent by accident.

Regards,

Quoted 390 lines · Antonio Quartulli
---
  .gitlab-ci.yml         | 182 +++++++++++++++++++++++++++++++++++++++++
  .gitlab/build-check.sh |  23 ++++++
  .gitlab/build-deps.sh  | 157 +++++++++++++++++++++++++++++++++++
  3 files changed, 362 insertions(+)

create mode 100644 .gitlab-ci.yml
create mode 100755 .gitlab/build-check.sh
create mode 100755 .gitlab/build-deps.sh

.gitlab-ci.yml new file +182 -0
new file mode 100644
index 00000000..fe25eb48
@@ -0,0 +1,182 @@
+stages:
+  - test
+
+variables:
+  JOBS: 3
+  PREFIX: ${CI_PROJECT_DIR}/builds
+  TAP_WINDOWS_VERSION: 9.24.6
+  LZO_VERSION: "2.10"
+  PKCS11_HELPER_VERSION: "1.22"
+  MBEDTLS_VERSION: "2.26.0"
+  MBEDTLS_CFLAGS: -I${CI_PROJECT_DIR}/builds/include
+  MBEDTLS_LIBS: -L${CI_PROJECT_DIR}/builds/lib -lmbedtls -lmbedx509 -lmbedcrypto
+  OPENSSL_VERSION: 1.1.1m
+  OPENSSL_CFLAGS: -I${CI_PROJECT_DIR}/builds/include
+  OPENSSL_LIBS: -L${CI_PROJECT_DIR}/builds/lib -lssl -lcrypto
+  SSLLIB: "openssl"
+
+default:
+  image: gcc:latest
+
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html build-essential python
+    - .gitlab/build-deps.sh
+
+  cache:
+    key: ${CI_JOB_NAME}
+    paths:
+      - download-cache/
+      - ${PREFIX}/
+
+dco:
+  variables:
+    EXTRA_CONFIG: "--enable-dco"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html build-essential python libnl-genl-3-dev
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+mtls-latest:
+  variables:
+    SSLLIB: "mbedtls"
+  script:
+    - .gitlab/build-check.sh
+
+mtls-2_16_11:
+  variables:
+    MBEDTLS_VERSION: "2.16.11"
+    SSLLIB: "mbedtls"
+  script:
+    - .gitlab/build-check.sh
+
+mtls-2_7_19:
+  variables:
+    MBEDTLS_VERSION: "2.7.19"
+    SSLLIB: "mbedtls"
+  script:
+    - .gitlab/build-check.sh
+
+ossl:
+  variables:
+    SSLLIB: "openssl"
+    EXTRA_SCRIPT: "make distcheck"
+  artifacts:
+    paths:
+      - src/openvpn/openvpn
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev build-essential unzip python3-docutils libssl-dev
+  script:
+    - .gitlab/build-check.sh
+
+ossl-gcc9:
+  image: gcc:9
+  script:
+    - .gitlab/build-check.sh
+
+ossl-fedora-latest:
+  image: fedora:latest
+  before_script:
+    - yum -y install libtool openssl-devel lzo-devel pam-devel lz4-devel man2html python gcc make autoconf automake wget
+  script:
+    - .gitlab/build-check.sh
+
+ossl-rockylinux-latest:
+  image: rockylinux:latest
+  before_script:
+    - yum -y install epel-release
+    - yum -y install libtool openssl-devel lzo-devel pam-devel lz4-devel man2html python39 gcc make autoconf automake wget
+  script:
+    - .gitlab/build-check.sh
+
+ossl-1_1_0:
+  variables:
+    OPENSSL_VERSION: "1.1.0l"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-1_0_2:
+  variables:
+    OPENSSL_VERSION: "1.0.2u"
+  script:
+    - .gitlab/build-check.sh
+
+
+#ossl-sanitizeaddr:
+#  variables:
+#    CFLAGS: "-fsanitize=address"
+#  script:
+#    - .gitlab/build-check.sh
+
+ossl-sanitizeleak:
+  variables:
+    CFLAGS: "-fsanitize=leak"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-sanitizeundef:
+  variables:
+    CFLAGS: "-fsanitize=undefined"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-win64:
+  variables:
+    CHOST: "x86_64-w64-mingw32"
+    EXTRA_CONFIG: "--disable-lz4"
+  artifacts:
+    paths:
+      - src/openvpn/openvpn.exe
+    name: "openvpn_win64-${CI_COMMIT_REF_SLUG}"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev build-essential mingw-w64 unzip man2html
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+ossl-win32:
+  variables:
+    CHOST: "i686-w64-mingw32"
+    EXTRA_CONFIG: "--disable-lz4"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev build-essential mingw-w64 unzip man2html
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+mtls-iproute2:
+  variables:
+    SSLLIB: "mbedtls"
+    EXTRA_CONFIG: "--enable-iproute2"
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq liblzo2-dev libpam0g-dev liblz4-dev linux-libc-dev man2html build-essential iproute2 python
+    - .gitlab/build-deps.sh
+  script:
+    - .gitlab/build-check.sh
+
+ossl-nolzo:
+  before_script:
+    - apt-get update -qq && apt-get install -y -qq libpam0g-dev liblz4-dev build-essential unzip
+    - .gitlab/build-deps.sh
+  variables:
+    EXTRA_CONFIG: "--disable-lzo"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-small:
+  variables:
+    EXTRA_CONFIG: "--enable-small"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-asyncpush:
+  variables:
+    EXTRA_CONFIG: "--enable-async-push"
+  script:
+    - .gitlab/build-check.sh
+
+ossl-no-mgmt:
+  variables:
+    EXTRA_CONFIG: "--disable-management"
+  script:
+    - .gitlab/build-check.sh
.gitlab/build-check.sh new file +23 -0
new file mode 100755
index 00000000..7ecb4255
@@ -0,0 +1,23 @@
+#!/bin/sh
+set -eux
+
+export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH:-}"
+
+autoreconf -vi
+
+if [ -z ${CHOST+x} ]; then
+	./configure --with-crypto-library="${SSLLIB}" ${EXTRA_CONFIG:-} || (cat config.log && exit 1)
+	make -j$JOBS
+	src/openvpn/openvpn --version || true
+	ldd src/openvpn/openvpn
+	make check
+	${EXTRA_SCRIPT:-}
+else
+	export TAP_CFLAGS="-I${PWD}/tap-windows-${TAP_WINDOWS_VERSION}/include"
+	export LZO_CFLAGS="-I${PREFIX}/include"
+	export LZO_LIBS="-L${PREFIX}/lib -llzo2"
+	export PKCS11_HELPER_LIBS="-L${PREFIX}/lib -lpkcs11-helper"
+	export PKCS11_HELPER_CFLAGS="-I${PREFIX}/include"
+	./configure --with-crypto-library="${SSLLIB}" --host=${CHOST} --build=x86_64-pc-linux-gnu --enable-pkcs11 --disable-plugins ${EXTRA_CONFIG:-} || (cat config.log && exit 1)
+	make -j${JOBS}
+fi
.gitlab/build-deps.sh new file +157 -0
new file mode 100755
index 00000000..d92158be
@@ -0,0 +1,157 @@
+#!/bin/sh
+set -eux
+
+# Set defaults
+PREFIX="${PREFIX:-${HOME}/opt}"
+
+download_tap_windows () {
+    if [ ! -f "download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip" ]; then
+       wget -P download-cache/ \
+           "http://build.openvpn.net/downloads/releases/tap-windows-${TAP_WINDOWS_VERSION}.zip"
+    fi
+}
+
+download_lzo () {
+    if [ ! -f "download-cache/lzo-${LZO_VERSION}.tar.gz" ]; then
+        wget -P download-cache/ \
+            "http://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz"
+    fi
+}
+
+build_lzo () {
+    if [ "$(cat ${PREFIX}/.lzo-version)" != "${LZO_VERSION}" ]; then
+        tar zxf download-cache/lzo-${LZO_VERSION}.tar.gz
+        (
+            cd "lzo-${LZO_VERSION}"
+
+            ./configure --host=${CHOST} --program-prefix='' \
+                --libdir=${PREFIX}/lib --prefix=${PREFIX} --build=x86_64-pc-linux-gnu
+            make all install
+        )
+        echo "${LZO_VERSION}" > "${PREFIX}/.lzo-version"
+    fi
+}
+
+download_pkcs11_helper () {
+    if [ ! -f "pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2" ]; then
+        wget -P download-cache/ \
+            "https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${PKCS11_HELPER_VERSION}/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
+    fi
+}
+
+build_pkcs11_helper () {
+    if [ "$(cat ${PREFIX}/.pkcs11_helper-version)" != "${PKCS11_HELPER_VERSION}" ]; then
+        tar jxf download-cache/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2
+        (
+            cd "pkcs11-helper-${PKCS11_HELPER_VERSION}"
+
+            ./configure --host=${CHOST} --program-prefix='' --libdir=${PREFIX}/lib \
+                 --prefix=${PREFIX} --build=x86_64-pc-linux-gnu \
+                 --disable-crypto-engine-gnutls \
+                 --disable-crypto-engine-nss \
+                 --disable-crypto-engine-polarssl \
+                 --disable-crypto-engine-mbedtls
+            make all install
+         )
+         echo "${PKCS11_HELPER_VERSION}" > "${PREFIX}/.pkcs11_helper-version"
+    fi
+}
+
+download_mbedtls () {
+    if [ ! -f "download-cache/mbedtls-${MBEDTLS_VERSION}-apache.tgz" ]; then
+	    wget "https://github.com/ARMmbed/mbedtls/archive/refs/tags/v${MBEDTLS_VERSION}.tar.gz" \
+	    -O download-cache/mbedtls-${MBEDTLS_VERSION}-apache.tgz
+    fi
+}
+
+build_mbedtls () {
+    if [ "$(cat ${PREFIX}/.mbedtls-version)" != "${MBEDTLS_VERSION}" ]; then
+        tar zxf download-cache/mbedtls-${MBEDTLS_VERSION}-apache.tgz
+        (
+            cd "mbedtls-${MBEDTLS_VERSION}"
+            make
+            make install DESTDIR="${PREFIX}"
+        )
+	echo "${MBEDTLS_VERSION}" > "${PREFIX}/.mbedtls-version"
+    fi
+}
+
+download_openssl () {
+    if [ ! -f "download-cache/openssl-${OPENSSL_VERSION}.tar.gz" ]; then
+        wget -P download-cache/ \
+            "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz"
+    fi
+}
+
+build_openssl_linux () {
+    (
+        cd "openssl-${OPENSSL_VERSION}/"
+        ./config shared --prefix="${PREFIX}" --openssldir="${PREFIX}" -DPURIFY
+        make all install_sw
+    )
+}
+
+build_openssl_osx () {
+    (
+        cd "openssl-${OPENSSL_VERSION}/"
+        ./Configure darwin64-x86_64-cc shared \
+            --prefix="${PREFIX}" --openssldir="${PREFIX}" -DPURIFY
+        make depend all install_sw
+    )
+}
+
+build_openssl_mingw () {
+    (
+        cd "openssl-${OPENSSL_VERSION}/"
+
+        if [ "${CHOST}" = "i686-w64-mingw32" ]; then
+            export TARGET=mingw
+        elif [ "${CHOST}" = "x86_64-w64-mingw32" ]; then
+            export TARGET=mingw64
+        fi
+
+        ./Configure --cross-compile-prefix=${CHOST}- shared \
+           ${TARGET} no-capieng --prefix="${PREFIX}" --openssldir="${PREFIX}" -static-libgcc
+        make install
+    )
+}
+
+build_openssl () {
+    if [ "$(cat ${PREFIX}/.openssl-version)" != "${OPENSSL_VERSION}" ]; then
+        tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
+        if [ ! -z ${CHOST+x} ]; then
+            build_openssl_mingw
+        else
+            build_openssl_linux
+        fi
+        echo "${OPENSSL_VERSION}" > "${PREFIX}/.openssl-version"
+    fi
+}
+
+mkdir -p ${PREFIX}
+mkdir -p download-cache
+
+# Download and build crypto lib
+if [ "${SSLLIB}" = "openssl" ]; then
+    download_openssl
+    build_openssl
+elif [ "${SSLLIB}" = "mbedtls" ]; then
+    download_mbedtls
+    build_mbedtls
+else
+    echo "Invalid crypto lib: ${SSLLIB}"
+    exit 1
+fi
+
+# Download and build dependencies for mingw cross build
+# dependencies are the same as in regular windows installer build
+if [ ! -z ${CHOST+x} ]; then
+      download_tap_windows
+      unzip download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip
+
+      download_lzo
+      build_lzo
+
+      download_pkcs11_helper
+      build_pkcs11_helper
+fi
Signature · 1 line
Antonio Quartulli