: FreeBSD DCO support
PATCH 1/1 : FreeBSD DCO support
Hi,
This is my second attempt at sending in the updated FreeBSD DCO support patch. (The previous version had a cleanup patch but nothing else).
The main difference to the previous version is that is passes the peer_id in most calls. There have been some changes on the driver side to improve server mode support, which required this information.
This requires the FreeBSD driver in https://reviews.freebsd.org/D34340
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 | 6 +- src/openvpn/Makefile.am | 1 + src/openvpn/dco_freebsd.c | 621 +++++++++++++++++++++++++++++++++ src/openvpn/dco_freebsd.h | 58 +++ src/openvpn/dco_internal.h | 1 + src/openvpn/forward.c | 8 +- src/openvpn/mtcp.c | 6 +- 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, 773 insertions(+), 18 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 -1
@@ -787,7 +787,11 @@ dnl AC_DEFINE(ENABLE_DCO, 1, [Enable data channel offload for Linux]) 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 +621 -0
621 lines not on this page · raw message
src/openvpn/dco_freebsd.h new file +58 -0
58 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 +4 -4
@@ -1104,7 +1104,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;
@@ -1651,7 +1651,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (c->c2.link_socket->info.dco_installed) { size = dco_do_write(&c->c1.tuntap->dco,
@@ -1926,7 +1926,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
@@ -2036,7 +2036,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 +3 -3
@@ -281,7 +281,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
@@ -400,7 +400,7 @@ multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, const intv_clear (&c->c2.timeval);/* ZERO-TIMEOUT */ -#if defined(TARGET_LINUX ) +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (mi && mi->context.c2.link_socket->info.dco_installed) {/* If we got a socket that has been handed over to the kernel
@@ -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
@@ -227,7 +227,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
@@ -3156,7 +3156,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"
@@ -1680,7 +1680,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);
@@ -3442,7 +3442,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
@@ -5804,7 +5804,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
@@ -1796,7 +1796,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); -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (!tt->options.disable_dco) {if (open_tun_dco (tt, ctx, dynamic_name) ==0 )
@@ -1831,7 +1831,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node, } } -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (!tt->options.disable_dco) {if (!dynamic_opened)
@@ -2011,7 +2011,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,NULL , true, tt, ctx);
@@ -2267,7 +2267,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.35.1