: FreeBSD DCO support
PATCH 1/1 : FreeBSD DCO support
Hi,
Here's the most recent version of the FreeBSD DCO patch. This is based on top of the dco branch, at 480fa1c983aba9b0790ea94df209e1686f08336b.
Relatedly, the kernel side of that support has just landed in FreeBSD's
repo: https://cgit.freebsd.org/src/commit/?id=ab91feabcc6f9da21d5c75028153af16d06e679a
Best regards,
Kristof
PATCH 1/1 ovpn-dco: introduce FreeBSD data-channel offload support
From: Kristof Provost <[email protected]...>
Implement data-channel offload for FreeBSD. The implementation and flow is very similar to that of the Linux DCO support.
--- configure.ac | 5 + src/openvpn/Makefile.am | 1 + src/openvpn/dco_freebsd.c | 636 +++++++++++++++++++++++++++++++++ src/openvpn/dco_freebsd.h | 59 +++ src/openvpn/dco_internal.h | 1 + src/openvpn/forward.c | 6 +- src/openvpn/mtcp.c | 4 +- src/openvpn/mudp.c | 2 +- src/openvpn/multi.c | 2 +- src/openvpn/options.c | 8 +- src/openvpn/ovpn_dco_freebsd.h | 64 ++++ src/openvpn/tun.c | 8 +- src/openvpn/tun.h | 6 + 13 files changed, 787 insertions(+), 15 deletions(-) create mode 100644 src/openvpn/dco_freebsd.c create mode 100644 src/openvpn/dco_freebsd.h create mode 100644 src/openvpn/ovpn_dco_freebsd.h
configure.ac +5 -0
@@ -787,6 +787,11 @@ dnl AC_DEFINE(ENABLE_DCO, 1, [Enable shared data channel offload]) AC_MSG_NOTICE([Enabled ovpn-dco support for Linux]) ;; + *-*-freebsd*) + LIBS="${LIBS} -lnv" + AC_DEFINE(ENABLE_DCO, 1, [Enable data channel offload for FreeBSD]) + AC_MSG_NOTICE([Enabled ovpn-dco support for FreeBSD]) + ;; *-mingw*) AC_MSG_NOTICE([NOTE: --enable-dco ignored on Windows because it's always enabled]) ;;
src/openvpn/Makefile.am +1 -0
@@ -54,6 +54,7 @@ openvpn_SOURCES = \ crypto_openssl.c crypto_openssl.h \ crypto_mbedtls.c crypto_mbedtls.h \ dco.c dco.h dco_internal.h \ + dco_freebsd.c dco_freebsd.h \ dco_linux.c dco_linux.h \ dco_win.c dco_win.h \ dhcp.c dhcp.h \
src/openvpn/dco_freebsd.c new file +636 -0
636 lines not on this page · raw message
src/openvpn/dco_freebsd.h new file +59 -0
59 lines not on this page · raw message
src/openvpn/dco_internal.h +1 -0
@@ -27,6 +27,7 @@#if defined(ENABLE_DCO ) +#include "dco_freebsd.h" #include "dco_linux.h" #include "dco_win.h"
src/openvpn/forward.c +3 -3
@@ -1113,7 +1113,7 @@ process_incoming_link(struct context *c)static void process_incoming_dco (struct context *c) { -#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) +#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ))struct link_socket_info *lsi =get_link_socket_info (c);dco_context_t *dco = &c->c1.tuntap->dco;
@@ -1967,7 +1967,7 @@ io_wait_dowork(struct context *c, const unsigned int flags)#ifdef ENABLE_ASYNC_PUSH static int file_shift =FILE_SHIFT ;#endif -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )static int dco_shift =DCO_SHIFT ;/* Event from DCO linux kernel module */ #endif
@@ -2077,7 +2077,7 @@ io_wait_dowork(struct context *c, const unsigned int flags)*/ socket_set (c->c2.link_socket, c->c2.event_set, socket, (void *)&socket_shift,NULL );tun_set (c->c1.tuntap, c->c2.event_set, tuntap, (void *)&tun_shift,NULL ); -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (socket &EVENT_READ && c->c2.did_open_tun) {dco_event_set (&c->c1.tuntap->dco, c->c2.event_set, (void *)&dco_shift);
src/openvpn/mtcp.c +2 -2
@@ -283,7 +283,7 @@ multi_tcp_wait(const struct context *c, }#endif tun_set (c->c1.tuntap, mtcp->es,EVENT_READ ,MTCP_TUN , persistent); -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )dco_event_set (&c->c1.tuntap->dco, mtcp->es,MTCP_DCO );#endif
@@ -763,7 +763,7 @@ multi_tcp_process_io(struct multi_context *m)multi_tcp_action (m, mi,TA_INITIAL , false); } } -#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) +#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ))/* incoming data on DCO? */ else if (e->arg == MTCP_DCO) {
src/openvpn/mudp.c +1 -1
@@ -380,7 +380,7 @@ multi_process_io_udp(struct multi_context *m)multi_process_file_closed (m, mpp_flags); }#endif -#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) +#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) else if (status & DCO_READ) {if (!IS_SIG (&m->top))
src/openvpn/multi.c +1 -1
@@ -3150,7 +3150,7 @@ multi_signal_instance(struct multi_context *m, struct multi_instance *mi, const }#endif -#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) +#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ))static void process_incoming_dco_packet (struct multi_context *m,struct multi_instance *mi,dco_context_t *dco) {
src/openvpn/options.c +4 -4
@@ -181,7 +181,7 @@ static const char usage_message[] =" does not begin with \"tun\" or \"tap\".\n" "--dev-node node : Explicitly set the device node rather than using\n" " /dev/net/tun, /dev/tun, /dev/tap, etc.\n" -#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) +#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )) "--disable-dco : Do not attempt using Data Channel Offload.\n"#endif "--lladdr hw : Set the link layer address of the tap device.\n"
@@ -1718,7 +1718,7 @@ show_settings(const struct options *o)SHOW_STR (dev);SHOW_STR (dev_type);SHOW_STR (dev_node); -#if defined(ENABLE_DCO ) && defined(TARGET_LINUX ) +#if defined(ENABLE_DCO ) && (defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ))SHOW_BOOL (tuntap_options.disable_dco);#endif SHOW_STR (lladdr);
@@ -3480,7 +3480,7 @@ options_postprocess_mutate(struct options *o) }/* check if any option should force disabling DCO */ -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) o->tuntap_options.disable_dco = !dco_check_option_conflict (D_DCO , o);#endif
@@ -5798,7 +5798,7 @@ add_option(struct options *options,#endif else if (streq(p[0], "disable-dco") || streq(p[0], "dco-disable")) { -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) options->tuntap_options.disable_dco = true;#endif }
src/openvpn/ovpn_dco_freebsd.h new file +64 -0
64 lines not on this page · raw message
src/openvpn/tun.c +4 -4
@@ -1797,7 +1797,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node, "/dev/%s%d", dev, i);openvpn_snprintf (dynamic_name,sizeof (dynamic_name),"%s%d" , dev, i); -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (!tt->options.disable_dco) {if (open_tun_dco (tt, ctx, dynamic_name) ==0 )
@@ -1832,7 +1832,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node, } } -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (!tt->options.disable_dco) {if (!dynamic_opened)
@@ -2006,7 +2006,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun {open_null (tt); } -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) else if (!tt->options.disable_dco) {open_tun_generic (dev, dev_type, dev_node, true, tt, ctx);
@@ -2262,7 +2262,7 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)net_ctx_reset (ctx); } -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (!tt->options.disable_dco) {close_tun_dco (tt, ctx);
src/openvpn/tun.h +6 -0
@@ -145,6 +145,12 @@ struct tuntap_options {bool disable_dco; }; +#elif defined(TARGET_FREEBSD ) + +struct tuntap_options { +bool disable_dco; +}; +#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ struct tuntap_options {
Signature · 1 line
2.36.1
Hi,
Quoted 6 lines · Kristof Provost via Openvpn-devel
Hi,
Here's the most recent version of the FreeBSD DCO patch. This is based on top of the dco branch, at
480fa1c983aba9b0790ea94df209e1686f08336b.
Thanks! DCO patches may still change a bit due to review, but their converging :-) Thanks a lot for bearing with us.
Quoted 3 lines
Relatedly, the kernel side of that support has just landed in FreeBSD's
repo: https://cgit.freebsd.org/src/commit/?id=ab91feabcc6f9da21d5c75028153af16d06e679a
Wonderful news! Congratulations!!
Cheers,
Signature · 1 line
Antonio Quartulli
Quoted 11 lines · Antonio Quartulli
Quoted 6 lines · Kristof Provost via Openvpn-devel
Hi,
Here's the most recent version of the FreeBSD DCO patch. This is based on top of the dco branch, at
480fa1c983aba9b0790ea94df209e1686f08336b.Thanks! DCO patches may still change a bit due to review, but their converging :-) Thanks a lot for bearing with us.
I figured, but I mostly wanted to remind you all that there are FreeBSD patches and that I haven’t forgotten about you yet.
I’ve been happy working with you (and the other openvpn devs). I’m not worried about a little churn and patch rebase work.
Quoted 6 lines
Quoted 3 lines
Relatedly, the kernel side of that support has just landed in FreeBSD's
repo: https://cgit.freebsd.org/src/commit/?id=ab91feabcc6f9da21d5c75028153af16d06e679aWonderful news! Congratulations!!
Also, the recent pfSense plus 22.05 release includes DCO support. So far there don’t seem to be major issues. It’s only been out for about a day, so maybe I should stop taunting Murphy.
Best regards,
Kristof
Am 28.06.22 um 18:28 schrieb Kristof Provost via Openvpn-devel:
Quoted 8 lines
Hi,
Here's the most recent version of the FreeBSD DCO patch. This is based on top of the dco branch, at
480fa1c983aba9b0790ea94df209e1686f08336b.Relatedly, the kernel side of that support has just landed in FreeBSD's
repo: https://cgit.freebsd.org/src/commit/?id=ab91feabcc6f9da21d5c75028153af16d06e679a
I tested this on top of Antonios branch but got an error when connecting from a test client:
2022-06-29 17:10:57 us=506086 lethe/192.168.188.134:61923 dco_new_peer: peer-id 0, fd 7 2022-06-29 17:10:57 us=506125 lethe/192.168.188.134:61923 Failed to create new peer 51 2022-06-29 17:10:57 us=506137 lethe/192.168.188.134:61923 Cannot add peer to DCO: Operation not permitted
Any idea why I might get a permission denied from the kernel there?
command line was (config fp only has fingerprint commands in it):
sudo ./src/openvpn/openvpn --server 10.0.0.0 255.255.255.0 --dev tun --dh none --config ~/ovpn/confs/fp --cert ~/ovpn/confs/cert128serial.pem --key ~/ovpn/confs/cert128serial.pem --verb 3 --max-clients 25000 --push "explicit-exit-notify 1" --keepalive 10 60 --explicit-exit-notify 1 --push "blaba bla" --tun-mtu 65000 --topology subnet --verb 6
2022-06-29 17:12:04 us=36114 192.168.188.134:54932 VERIFY OK: depth=0, CN=lethe 2022-06-29 17:12:04 us=36235 192.168.188.134:54932 VERIFY OK: depth=0, CN=lethe 2022-06-29 17:12:04 us=39002 192.168.188.134:54932 peer info: IV_VER=2.6_git 2022-06-29 17:12:04 us=39034 192.168.188.134:54932 peer info: IV_PLAT=win 2022-06-29 17:12:04 us=39041 192.168.188.134:54932 peer info: IV_TCPNL=1 2022-06-29 17:12:04 us=39046 192.168.188.134:54932 peer info: IV_NCP=2 2022-06-29 17:12:04 us=39052 192.168.188.134:54932 peer info: IV_CIPHERS=AES-256-GCM:AES-128-GCM 2022-06-29 17:12:04 us=39058 192.168.188.134:54932 peer info: IV_PROTO=30 2022-06-29 17:12:04 us=39063 192.168.188.134:54932 peer info: IV_LZO_STUB=1 2022-06-29 17:12:04 us=39068 192.168.188.134:54932 peer info: IV_COMP_STUB=1 2022-06-29 17:12:04 us=39073 192.168.188.134:54932 peer info: IV_COMP_STUBv2=1 2022-06-29 17:12:04 us=39113 192.168.188.134:54932 WARNING: 'link-mtu' is used inconsistently, local='link-mtu 65041', remote='link-mtu 1441' 2022-06-29 17:12:04 us=39123 192.168.188.134:54932 WARNING: 'tun-mtu' is used inconsistently, local='tun-mtu 65000', remote='tun-mtu 1400' 2022-06-29 17:12:04 us=39182 192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:04 us=39210 192.168.188.134:54932 UDPv6 WRITE [184] to [AF_INET6]::ffff:192.168.188.134:54932: P_CONTROL_V1 kid=0 [ 2 ] pid=3 DATA len=158 2022-06-29 17:12:04 us=39254 192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:04 us=39268 192.168.188.134:54932 UDPv6 WRITE [216] to [AF_INET6]::ffff:192.168.188.134:54932: P_CONTROL_V1 kid=0 [ ] pid=4 DATA len=202 2022-06-29 17:12:04 us=39282 192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:04 us=40390 192.168.188.134:54932 UDPv6 READ [22] from [AF_INET6]::ffff:192.168.188.134:54932: P_ACK_V1 kid=0 [ 3 ] DATA len=0 2022-06-29 17:12:04 us=40440 192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:04 us=44123 192.168.188.134:54932 UDPv6 READ [22] from [AF_INET6]::ffff:192.168.188.134:54932: P_ACK_V1 kid=0 [ 4 ] DATA len=0 2022-06-29 17:12:04 us=44198 192.168.188.134:54932 Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 384 bit EC, curve secp384r1, signature: ecdsa-with-SHA256 2022-06-29 17:12:04 us=44219 192.168.188.134:54932 [lethe] Peer Connection Initiated with [AF_INET6]::ffff:192.168.188.134:54932 2022-06-29 17:12:04 us=44236 192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:04 us=44252 lethe/192.168.188.134:54932 MULTI_sva: pool returned IPv4=10.0.0.2, IPv6=(Not enabled) 2022-06-29 17:12:04 us=44364 lethe/192.168.188.134:54932 MULTI: Learn: 10.0.0.2 -> lethe/192.168.188.134:54932 2022-06-29 17:12:04 us=44373 lethe/192.168.188.134:54932 MULTI: primary virtual IP for lethe/192.168.188.134:54932: 10.0.0.2 2022-06-29 17:12:04 us=44393 lethe/192.168.188.134:54932 dco_new_peer: peer-id 0, fd 7 2022-06-29 17:12:04 us=44492 lethe/192.168.188.134:54932 Failed to create new peer 51 2022-06-29 17:12:04 us=44530 lethe/192.168.188.134:54932 Cannot add peer to DCO: Operation not permitted 2022-06-29 17:12:04 us=44538 lethe/192.168.188.134:54932 Delayed exit in 5 seconds 2022-06-29 17:12:04 us=44559 lethe/192.168.188.134:54932 SENT CONTROL [lethe]: 'AUTH_FAILED' (status=1) 2022-06-29 17:12:04 us=44589 lethe/192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:04 us=44606 lethe/192.168.188.134:54932 UDPv6 WRITE [48] to [AF_INET6]::ffff:192.168.188.134:54932: P_CONTROL_V1 kid=0 [ ] pid=5 DATA len=34 2022-06-29 17:12:04 us=44633 lethe/192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:05 us=242725 lethe/192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:06 us=508405 lethe/192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:06 us=508569 lethe/192.168.188.134:54932 UDPv6 WRITE [48] to [AF_INET6]::ffff:192.168.188.134:54932: P_CONTROL_V1 kid=0 [ ] pid=5 DATA len=34 2022-06-29 17:12:06 us=508616 lethe/192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:07 us=729578 lethe/192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:08 us=929417 lethe/192.168.188.134:54932 dco_update_keys: peer_id=0 2022-06-29 17:12:10 us=142712 lethe/192.168.188.134:54932 SIGTERM[soft,delayed-exit] received, client-instance exiting
Quoted 10 lines · Arne Schwabe
Am 28.06.22 um 18:28 schrieb Kristof Provost via Openvpn-devel:
Quoted 8 lines
Hi,
Here's the most recent version of the FreeBSD DCO patch. This is based on top of the dco branch, at
480fa1c983aba9b0790ea94df209e1686f08336b.Relatedly, the kernel side of that support has just landed in FreeBSD's
repo: https://cgit.freebsd.org/src/commit/?id=ab91feabcc6f9da21d5c75028153af16d06e679a
Quoted 9 lines
I tested this on top of Antonios branch but got an error when connecting from a test client:
2022-06-29 17:10:57 us=506086 lethe/192.168.188.134:61923 dco_new_peer: peer-id 0, fd 7 2022-06-29 17:10:57 us=506125 lethe/192.168.188.134:61923 Failed to create new peer 51 2022-06-29 17:10:57 us=506137 lethe/192.168.188.134:61923 Cannot add peer to DCO: Operation not permittedAny idea why I might get a permission denied from the kernel there?
The first thing to note here is that the ‘Operation not permitted’ error is misleading. That’s produced based on the return value of dco_new_peer(), which is going to be -1. The line above it has the errno, which is 51 or ENETUNREACH.
I suspect this is happening because you’re using ipv6_ipv4mapping (or sysctl net.inet6.ip6.v6only=0). Presumably that indicates a bug on my side, but can you see if disabling that helps?
Br,
Kristof
Am 29.06.2022 um 19:40 schrieb Kristof Provost:
Quoted 17 lines · Arne Schwabe
Quoted 16 lines
Am 28.06.22 um 18:28 schrieb Kristof Provost via Openvpn-devel:
Quoted 8 lines
Hi,
Here's the most recent version of the FreeBSD DCO patch. This is based on top of the dco branch, at
480fa1c983aba9b0790ea94df209e1686f08336b.Relatedly, the kernel side of that support has just landed in FreeBSD's
repo: https://cgit.freebsd.org/src/commit/?id=ab91feabcc6f9da21d5c75028153af16d06e679aI tested this on top of Antonios branch but got an error when connecting from a test client:
2022-06-29 17:10:57 us=506086 lethe/192.168.188.134:61923 dco_new_peer: peer-id 0, fd 7 2022-06-29 17:10:57 us=506125 lethe/192.168.188.134:61923 Failed to create new peer 51 2022-06-29 17:10:57 us=506137 lethe/192.168.188.134:61923 Cannot add peer to DCO: Operation not permitted
Quoted 5 lines
Quoted 2 lines
Any idea why I might get a permission denied from the kernel there?
The first thing to note here is that the ‘Operation not permitted’ error is misleading. That’s produced based on the return value of
dco_new_peer(), which is going to be -1. The line above it has the errno, which is 51 or ENETUNREACH.I suspect this is happening because you’re using
ipv6_ipv4mapping(or sysctl net.inet6.ip6.v6only=0). Presumably that indicates a bug on my side, but can you see if disabling that helps?
Yes. That is the default that OpenVPN uses. It will ignore the sysctl since we use the socket option per default on v6 sockets. (search the man page for ipv6only). Adding --proto udp4 fixes the problem but that is something at least needs a better error mesage.
Arne
Quoted 18 lines · Arne Schwabe
Am 29.06.2022 um 19:40 schrieb Kristof Provost:
Quoted 17 lines · Arne Schwabe
Quoted 16 lines
Am 28.06.22 um 18:28 schrieb Kristof Provost via Openvpn-devel:
Quoted 8 lines
Hi,
Here's the most recent version of the FreeBSD DCO patch. This is based on top of the dco branch, at
480fa1c983aba9b0790ea94df209e1686f08336b.Relatedly, the kernel side of that support has just landed in FreeBSD's
repo: https://cgit.freebsd.org/src/commit/?id=ab91feabcc6f9da21d5c75028153af16d06e679aI tested this on top of Antonios branch but got an error when connecting from a test client:
2022-06-29 17:10:57 us=506086 lethe/192.168.188.134:61923 dco_new_peer: peer-id 0, fd 7 2022-06-29 17:10:57 us=506125 lethe/192.168.188.134:61923 Failed to create new peer 51 2022-06-29 17:10:57 us=506137 lethe/192.168.188.134:61923 Cannot add peer to DCO: Operation not permitted
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Any idea why I might get a permission denied from the kernel there?
The first thing to note here is that the ‘Operation not permitted’ error is misleading. That’s produced based on the return value of
dco_new_peer(), which is going to be -1. The line above it has the errno, which is 51 or ENETUNREACH.I suspect this is happening because you’re using
ipv6_ipv4mapping(or sysctl net.inet6.ip6.v6only=0). Presumably that indicates a bug on my side, but can you see if disabling that helps?Yes. That is the default that OpenVPN uses. It will ignore the sysctl since we use the socket option per default on v6 sockets. (search the man page for ipv6only). Adding --proto udp4 fixes the problem but that is something at least needs a better error mesage.
I’ll do some digging in the next couple of days. I’m hopeful it can just be made to work.
Kristof