: FreeBSD DCO support
PATCH 1/1 : FreeBSD DCO support
Hi,
Here's an updated version for the FreeBSD DCO support, as well as a few generic bugfixes.
Best regards,
Kristof
PATCH 1/4 mtcp: Handle multi_create_instance() returning NULL
From: Kristof Provost <[email protected]...>
multi_create_instance() can fail (i.e. return NULL). multi_create_instance_tcp() is ready for this, but called multi_assign_peer_id() without first checking if mi was non-NULL. multi_assign_peer_id() assumed that mi is non-NULL, dereferencing it and causing a crash.
Move the call to multi_assign_peer_id() after the mi NULL check.
--- src/openvpn/mtcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpn/mtcp.c +2 -1
@@ -124,7 +124,6 @@ multi_create_instance_tcp(struct multi_context *m)struct hash *hash = m->hash; mi =multi_create_instance (m,NULL ); -multi_assign_peer_id (m, mi);if (mi) {
@@ -132,6 +131,8 @@ multi_create_instance_tcp(struct multi_context *m)const uint32_t hv =hash_value (hash, &mi->real);struct hash_bucket *bucket =hash_bucket (hash, hv); +multi_assign_peer_id (m, mi); + he =hash_lookup_fast (hash, bucket, &mi->real, hv);if (he)
Signature · 1 line
2.36.1
PATCH 2/4 rework do_up() for correct order of DCO operations
In reply to Kristof ProvostFrom: Kristof Provost <[email protected]...>
We must create the peer before we can dco_set_peer or dco_new_key. On the other hand, we must first process options, because those may change our peer id and we should create the peer with the correct id.
Split up do_deferred_options() in do_deferred_options() and finish_options(). Call any DCO configuration operations (i.e. dco_set_peer()/dco_new_key()) after we've created the peer (i.e. dco_new_peer()).
--- src/openvpn/init.c | 112 +++++++++++++++++++++++++------------------- src/openvpn/init.h | 2 + src/openvpn/multi.c | 2 + 3 files changed, 68 insertions(+), 48 deletions(-)
src/openvpn/init.c +64 -48
@@ -2093,26 +2093,26 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) } } -if ((c->mode ==MODE_POINT_TO_POINT ) && c->c2.did_open_tun) +if (pulled_options) { -/* ovpn-dco requires adding the peer now, before any option can be set */ -int ret =dco_p2p_add_new_peer (c); -if (ret <0 ) +if (!do_deferred_options (c, option_types_found)) { -msg (D_DCO ,"Cannot add peer to DCO: %s" ,strerror (-ret)); +msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" );return false; } } - -if (pulled_options) +if (c->mode ==MODE_POINT_TO_POINT ) { -if (!do_deferred_options (c, option_types_found)) +/* ovpn-dco requires adding the peer now, before any option can be set */ +int ret =dco_p2p_add_new_peer (c); +if (ret <0 ) { -msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" ); +msg (D_DCO ,"Cannot add peer to DCO: %s" ,strerror (-ret));return false; } } -else if (c->mode ==MODE_POINT_TO_POINT ) + +if (!pulled_options && c->mode ==MODE_POINT_TO_POINT ) {if (!do_deferred_p2p_ncp (c)) {
@@ -2121,6 +2121,13 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) } } + +if (!finish_options (c)) + { +msg (D_TLS_ERRORS ,"ERROR: Failed to finish option processing" ); +return false; + } +if (c->c2.did_open_tun) { c->c1.pulled_options_digest_save = c->c2.pulled_options_digest;
@@ -2337,49 +2344,58 @@ do_deferred_options(struct context *c, const unsigned int found) {return false; } -struct frame *frame_fragment =NULL ; + } + +return true; +} + +bool +finish_options (struct context *c) +{ +if (!c->options.pull || !dco_enabled (&c->options)) + { +return true; + } + +struct frame *frame_fragment =NULL ;#ifdef ENABLE_FRAGMENT -if (c->options.ce.fragment) - { - frame_fragment = &c->c2.frame_fragment; - } +if (c->options.ce.fragment) + { + frame_fragment = &c->c2.frame_fragment; + }#endif -struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ]; -if (!tls_session_update_crypto_params (c->c2.tls_multi, session, - &c->options, &c->c2.frame, - frame_fragment, -get_link_socket_info (c))) - { -msg (D_TLS_ERRORS ,"OPTIONS ERROR: failed to import crypto options" ); -return false; - } +struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ]; +if (!tls_session_update_crypto_params (c->c2.tls_multi, session, + &c->options, &c->c2.frame, + frame_fragment, +get_link_socket_info (c))) + { +msg (D_TLS_ERRORS ,"OPTIONS ERROR: failed to import crypto options" ); +return false; + } -if (dco_enabled (&c->options)) - { -/* Check if the pushed options are compatible with DCO if we have -* DCO enabled */ -if (!check_dco_pull_options (&c->options)) - { -msg (D_TLS_ERRORS ,"OPTIONS ERROR: pushed options are incompatible with " -"data channel offload. Use --disable-dco to connect" -"to this server" ); -return false; - } +/* Check if the pushed options are compatible with DCO if we have +* DCO enabled */ +if (!check_dco_pull_options (&c->options)) + { +msg (D_TLS_ERRORS ,"OPTIONS ERROR: pushed options are incompatible with " +"data channel offload. Use --disable-dco to connect" +"to this server" ); +return false; + } -if (c->options.ping_send_timeout || c->c2.frame.mss_fix) - { -int ret =dco_set_peer (&c->c1.tuntap->dco, - c->c2.tls_multi->peer_id, - c->options.ping_send_timeout, - c->options.ping_rec_timeout, - c->c2.frame.mss_fix); -if (ret <0 ) - { -msg (D_DCO ,"Cannot set DCO peer: %s" ,strerror (-ret)); -return false; - } - } +if (c->options.ping_send_timeout || c->c2.frame.mss_fix) + { +int ret =dco_set_peer (&c->c1.tuntap->dco, + c->c2.tls_multi->peer_id, + c->options.ping_send_timeout, + c->options.ping_rec_timeout, + c->c2.frame.mss_fix); +if (ret <0 ) + { +msg (D_DCO ,"Cannot set DCO peer: %s" ,strerror (-ret)); +return false; } }return true;
src/openvpn/init.h +2 -0
@@ -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/multi.c +2 -0
@@ -2452,6 +2452,8 @@ multi_client_connect_late_setup(struct multi_context *m, mi->context.c2.tls_multi->multi_state =CAS_FAILED ; } +finish_options (&mi->context); +/* send push reply if ready */ if (mi->context.c2.push_request_received) {
Signature · 1 line
2.36.1
PATCH 3/4 ovpn-dco: introduce FreeBSD data-channel offload support
In reply to Kristof ProvostFrom: 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 | 636 +++++++++++++++++++++++++++++++++ src/openvpn/dco_freebsd.h | 59 +++ 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, 789 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 +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 +4 -4
@@ -1112,7 +1112,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;
@@ -1665,7 +1665,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,
@@ -1940,7 +1940,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
@@ -2050,7 +2050,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
@@ -282,7 +282,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
@@ -401,7 +401,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
@@ -764,7 +764,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
@@ -3158,7 +3158,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
@@ -5805,7 +5805,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); -#ifdef 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, } } -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD )if (!tt->options.disable_dco) {if (!dynamic_opened)
@@ -2005,7 +2005,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);
@@ -2261,7 +2261,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
PATCH 4/4 Set (DCO) timeouts as well for p2p mode
In reply to Kristof ProvostFrom: Kristof Provost <[email protected]...>
--- src/openvpn/init.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
src/openvpn/init.c +15 -0
@@ -2232,6 +2232,21 @@ do_deferred_p2p_ncp(struct context *c)msg (D_TLS_ERRORS ,"ERROR: failed to set crypto cipher" );return false; } + +if (dco_enabled (&c->options) && (c->options.ping_send_timeout || c->c2.frame.mss_fix)) + { +int ret =dco_set_peer (&c->c1.tuntap->dco, + c->c2.tls_multi->peer_id, + c->options.ping_send_timeout, + c->options.ping_rec_timeout, + c->c2.frame.mss_fix); +if (ret <0 ) + { +msg (D_DCO ,"Cannot set DCO peer: %s" ,strerror (-ret)); +return false; + } + } +return true; }
Signature · 1 line
2.36.1
Re: [Openvpn-devel] [PATCH 1/4] mtcp: Handle multi_create_instance() returning NULL
In reply to Kristof ProvostAm 16.05.2022 um 20:56 schrieb Kristof Provost via Openvpn-devel:
Quoted 10 lines
From: Kristof Provost <[email protected]...>
multi_create_instance()can fail (i.e. return NULL).multi_create_instance_tcp()is ready for this, but calledmulti_assign_peer_id()without first checking if mi was non-NULL.multi_assign_peer_id()assumed that mi is non-NULL, dereferencing it and causing a crash.Move the call to
multi_assign_peer_id()after the mi NULL check.
I did add multi_assign_peer there iirc but Kristof is right.
Re: [Openvpn-devel] [PATCH 1/4] mtcp: Handle multi_create_instance() returning NULL
Hi all,
Quoted 10 lines · Arne Schwabe
Am 16.05.2022 um 20:56 schrieb Kristof Provost via Openvpn-devel:
Quoted 8 lines
From: Kristof Provost <[email protected]...>
multi_create_instance()can fail (i.e. return NULL).multi_create_instance_tcp()is ready for this, but calledmulti_assign_peer_id()without first checking if mi was non-NULL.multi_assign_peer_id()assumed that mi is non-NULL, dereferencing it and causing a crash.
Quoted 5 lines
Quoted 2 lines
Move the call to
multi_assign_peer_id()after the mi NULL check.I did add
multi_assign_peerthere iirc but Kristof is right.Acked-by Arne Schwabe <[email protected]...
Thank you both.
I am pulling this patch in the dco branch.
Regards,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH 4/4] Set (DCO) timeouts as well for p2p mode
In reply to Kristof ProvostHi,
Quoted 20 lines · Kristof Provost via Openvpn-devel
From: Kristof Provost <[email protected]...>
Signed-off-by Kristof Provost <[email protected]...>--- src/openvpn/init.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)src/openvpn/init.c +5
-0@@ -2232,6 +2232,21 @@ do_deferred_p2p_ncp(struct context *c)msg (D_TLS_ERRORS ,"ERROR: failed to set crypto cipher" );return false; } + +if (dco_enabled (&c->options) && (c->options.ping_send_timeout || c->c2.frame.mss_fix)) + { + int ret = dco_set_peer(&c->c1.tuntap->dco, + c->c2.tls_multi->peer_id,
src/openvpn/init.c do_deferred_p2p_ncp(struct context *c) · line 2249
Quoted 10 lines
src/openvpn/init.c +10
-0+ c->options.ping_send_timeout, + c->options.ping_rec_timeout, + c->c2.frame.mss_fix); +if (ret <0 ) + { +msg (D_DCO ,"Cannot set DCO peer: %s" ,strerror (-ret)); +return false; + } + } +
unless I am missing something, I don't think we need another dco_set_peer call.
It should be enough to move the invocation of dco_set_peer in finish_options at the very top, before any attempt of bailing out.
Regards,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH 2/4] rework do_up() for correct order of DCO operations
In reply to Kristof ProvostHi,
Quoted 6 lines · Kristof Provost via Openvpn-devel
From: Kristof Provost <[email protected]...>
We must create the peer before we can
dco_set_peerordco_new_key. On the other hand, we must first process options, because those may change our peer id and we should create the peer with the correct id.
Quoted 6 lines
Split up
do_deferred_options()indo_deferred_options()andfinish_options(). Call any DCO configuration operations (i.e. dco_set_peer()/dco_new_key()) after we've created the peer (i.e.dco_new_peer()).Signed-off-by Kristof Provost <[email protected]...>
I am including this patch in the dco branch as well.
Please note that this change has been reworked a little bit.
Regards,
Quoted 184 lines
--- src/openvpn/init.c | 112 +++++++++++++++++++++++++------------------- src/openvpn/init.h | 2 + src/openvpn/multi.c | 2 + 3 files changed, 68 insertions(+), 48 deletions(-)src/openvpn/init.c +64
-48@@ -2093,26 +2093,26 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) } } -if ((c->mode ==MODE_POINT_TO_POINT ) && c->c2.did_open_tun) +if (pulled_options) { -/* ovpn-dco requires adding the peer now, before any option can be set */ -int ret =dco_p2p_add_new_peer (c); -if (ret <0 ) +if (!do_deferred_options (c, option_types_found)) { -msg (D_DCO ,"Cannot add peer to DCO: %s" ,strerror (-ret)); +msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" );return false; } } - -if (pulled_options) +if (c->mode ==MODE_POINT_TO_POINT ) { -if (!do_deferred_options (c, option_types_found)) +/* ovpn-dco requires adding the peer now, before any option can be set */ +int ret =dco_p2p_add_new_peer (c); +if (ret <0 ) { -msg (D_PUSH_ERRORS ,"ERROR: Failed to apply push options" ); +msg (D_DCO ,"Cannot add peer to DCO: %s" ,strerror (-ret));return false; } } -else if (c->mode ==MODE_POINT_TO_POINT ) + +if (!pulled_options && c->mode ==MODE_POINT_TO_POINT ) {if (!do_deferred_p2p_ncp (c)) {@@ -2121,6 +2121,13 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found) } } + +if (!finish_options (c)) + { +msg (D_TLS_ERRORS ,"ERROR: Failed to finish option processing" ); +return false; + } +if (c->c2.did_open_tun) { c->c1.pulled_options_digest_save = c->c2.pulled_options_digest;@@ -2337,49 +2344,58 @@ do_deferred_options(struct context *c, const unsigned int found) {return false; } -struct frame *frame_fragment =NULL ; + } + +return true; +} + +bool +finish_options (struct context *c) +{ +if (!c->options.pull || !dco_enabled (&c->options)) + { +return true; + } + +struct frame *frame_fragment =NULL ;#ifdef ENABLE_FRAGMENT -if (c->options.ce.fragment) - { - frame_fragment = &c->c2.frame_fragment; - } +if (c->options.ce.fragment) + { + frame_fragment = &c->c2.frame_fragment; + }#endif -struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ]; -if (!tls_session_update_crypto_params (c->c2.tls_multi, session, - &c->options, &c->c2.frame, - frame_fragment, -get_link_socket_info (c))) - { -msg (D_TLS_ERRORS ,"OPTIONS ERROR: failed to import crypto options" ); -return false; - } +struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ]; +if (!tls_session_update_crypto_params (c->c2.tls_multi, session, + &c->options, &c->c2.frame, + frame_fragment, +get_link_socket_info (c))) + { +msg (D_TLS_ERRORS ,"OPTIONS ERROR: failed to import crypto options" ); +return false; + } -if (dco_enabled (&c->options)) - { -/* Check if the pushed options are compatible with DCO if we have -* DCO enabled */ -if (!check_dco_pull_options (&c->options)) - { -msg (D_TLS_ERRORS ,"OPTIONS ERROR: pushed options are incompatible with " -"data channel offload. Use --disable-dco to connect" -"to this server" ); -return false; - } +/* Check if the pushed options are compatible with DCO if we have +* DCO enabled */ +if (!check_dco_pull_options (&c->options)) + { +msg (D_TLS_ERRORS ,"OPTIONS ERROR: pushed options are incompatible with " +"data channel offload. Use --disable-dco to connect" +"to this server" ); +return false; + } -if (c->options.ping_send_timeout || c->c2.frame.mss_fix) - { -int ret =dco_set_peer (&c->c1.tuntap->dco, - c->c2.tls_multi->peer_id, - c->options.ping_send_timeout, - c->options.ping_rec_timeout, - c->c2.frame.mss_fix); -if (ret <0 ) - { -msg (D_DCO ,"Cannot set DCO peer: %s" ,strerror (-ret)); -return false; - } - } +if (c->options.ping_send_timeout || c->c2.frame.mss_fix) + { +int ret =dco_set_peer (&c->c1.tuntap->dco, + c->c2.tls_multi->peer_id, + c->options.ping_send_timeout, + c->options.ping_rec_timeout, + c->c2.frame.mss_fix); +if (ret <0 ) + { +msg (D_DCO ,"Cannot set DCO peer: %s" ,strerror (-ret)); +return false; } }return true;src/openvpn/init.h +2
-0@@ -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/multi.c +2
-0@@ -2452,6 +2452,8 @@ multi_client_connect_late_setup(struct multi_context *m, mi->context.c2.tls_multi->multi_state =CAS_FAILED ; } +finish_options (&mi->context); +/* send push reply if ready */ if (mi->context.c2.push_request_received) {
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH 2/4] rework do_up() for correct order of DCO operations
Quoted 12 lines · Antonio Quartulli
Quoted 11 lines · Kristof Provost via Openvpn-devel
From: Kristof Provost <[email protected]...>
We must create the peer before we can
dco_set_peerordco_new_key. On the other hand, we must first process options, because those may change our peer id and we should create the peer with the correct id.Split up
do_deferred_options()indo_deferred_options()andfinish_options(). Call any DCO configuration operations (i.e. dco_set_peer()/dco_new_key()) after we've created the peer (i.e.dco_new_peer()).
Quoted 6 lines
Quoted 1 line
Signed-off-by Kristof Provost <[email protected]...>I am including this patch in the dco branch as well.
Please note that this change has been reworked a little bit.
Thanks!
Kristof
Re: [Openvpn-devel] [PATCH 4/4] Set (DCO) timeouts as well for p2p mode
In reply to Antonio QuartulliQuoted 36 lines · Antonio Quartulli
Hi,
Quoted 20 lines · Kristof Provost via Openvpn-devel
From: Kristof Provost <[email protected]...>
Signed-off-by Kristof Provost <[email protected]...>--- src/openvpn/init.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)src/openvpn/init.c +5
-0@@ -2232,6 +2232,21 @@ do_deferred_p2p_ncp(struct context *c)msg (D_TLS_ERRORS ,"ERROR: failed to set crypto cipher" );return false; } + +if (dco_enabled (&c->options) && (c->options.ping_send_timeout || c->c2.frame.mss_fix)) + { + int ret = dco_set_peer(&c->c1.tuntap->dco, + c->c2.tls_multi->peer_id,src/openvpn/init.c do_deferred_p2p_ncp(struct context *c) · line 2249
Quoted 10 lines
src/openvpn/init.c +10
-0+ c->options.ping_send_timeout, + c->options.ping_rec_timeout, + c->c2.frame.mss_fix); +if (ret <0 ) + { +msg (D_DCO ,"Cannot set DCO peer: %s" ,strerror (-ret)); +return false; + } + } +unless I am missing something, I don't think we need another
dco_set_peercall.
Quoted 2 lines
It should be enough to move the invocation of
dco_set_peerinfinish_optionsat the very top, before any attempt of bailing out.
Good point. I’ll update my patchset and include this in the next update.
Br,
Kristof