Move dco_installed from sock->info to sock->info.lsa.actual
PATCH 1/3 Move dco_installed from sock->info to sock->info.lsa.actual
For tcp this makes no difference as the remote address of the socket never changes. For udp this allows OpenVPN to differentiate if a reconnecting client is using the same address as before or from a different one. This allow sending via the normal userspace socket in that case.
--- src/openvpn/dco.c | 7 ++++--- src/openvpn/dco_linux.c | 2 +- src/openvpn/forward.c | 8 ++++---- src/openvpn/init.c | 2 +- src/openvpn/mtcp.c | 6 +++--- src/openvpn/socket.h | 6 +++--- 6 files changed, 16 insertions(+), 15 deletions(-)
src/openvpn/dco.c +4 -3
@@ -448,7 +448,7 @@ dco_p2p_add_new_peer(struct context *c) } c->c2.tls_multi->dco_peer_added = true; - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ; }
@@ -522,7 +522,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {struct context *c = &mi->context; -int peer_id = mi->context.c2.tls_multi->peer_id; +int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 };int sd = c->c2.link_socket->sd;
@@ -531,6 +531,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {/* the remote address will be inferred from the TCP socket endpoint */ remoteaddr =NULL ; + c->c2.link_socket->info.lsa->actual.dco_installed = true; } else {
@@ -575,7 +576,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {msg (D_DCO |M_ERRNO ,"error closing TCP socket after DCO handover" ); } - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true; c->c2.link_socket->sd =SOCKET_UNDEFINED ; }
src/openvpn/dco_linux.c +1 -1
@@ -285,7 +285,7 @@ ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg)* * We pass the error code to the user by means of a variable pointed by *arg * (supplied by the user when setting this callback) and we parse the kernel -* reply to see if it contains a human readable error. If found, it is printed. +* reply to see if it contains a human-readable error. If found, it is printed. */ static int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),
src/openvpn/forward.c +4 -4
@@ -1636,13 +1636,13 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf)* standard Overlapped I/O. * * Hide that complexity (...especially if more platforms show up -* in future...) in a small inline function. +* in the future...) in a small inline function. */ static inline bool -should_use_dco_socket (struct link_socket *sock) +should_use_dco_socket (struct link_socket_actual *actual) {#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) -return sock->info.dco_installed; +return actual->dco_installed;#else return false;#endif
@@ -1721,7 +1721,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (should_use_dco_socket (c->c2.link_socket)) +if (should_use_dco_socket (c->c2.to_link_addr)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,
src/openvpn/init.c +1 -1
@@ -3625,7 +3625,7 @@ do_close_link_socket(struct context *c)* closed in do_close_tun(). Set it to UNDEFINED so * we won't use WinSock API to close it. */ if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket - && c->c2.link_socket->info.dco_installed) + && c->c2.link_socket->info.lsa->actual.dco_installed) { c->c2.link_socket->sd =SOCKET_UNDEFINED ; }
src/openvpn/mtcp.c +3 -3
@@ -402,7 +402,7 @@ multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, const intv_clear (&c->c2.timeval);/* ZERO-TIMEOUT */ -if (mi && mi->context.c2.link_socket->info.dco_installed) +if (mi && mi->context.c2.link_socket->info.lsa->actual.dco_installed) {/* If we got a socket that has been handed over to the kernel * we must not call the normal socket function to figure out
@@ -537,7 +537,7 @@ multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const intcase TA_INITIAL :ASSERT (mi); -if (!mi->context.c2.link_socket->info.dco_installed) +if (!mi->context.c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }
@@ -590,7 +590,7 @@ multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int act }else { -if (!c->c2.link_socket->info.dco_installed) +if (!c->c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }
src/openvpn/socket.h +3 -3
@@ -88,6 +88,7 @@ struct link_socket_actual/*int dummy;*/ /* add offset to force a bug if dest not explicitly dereferenced */ struct openvpn_sockaddr dest; +bool dco_installed; #if ENABLE_IP_PKTINFO union { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
@@ -121,7 +122,6 @@ struct link_socket_infosa_family_t af;/* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/ bool bind_ipv6_only;int mtu_changed;/* Set to true when mtu value is changed */ -bool dco_installed; };/*
@@ -1073,7 +1073,7 @@ link_socket_read(struct link_socket *sock, struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) - || sock->info.dco_installed) + || sock->info.lsa->actual.dco_installed)/* unified UDPv4 and UDPv6, for DCO the kernel * will strip the length header */ {
@@ -1190,7 +1190,7 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) + if (proto_is_udp(sock->info.proto) || to->dco_installed) { /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to);
Signature · 1 line
2.37.0 (Apple Git-136)
PATCH 2/3 Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
The lifetime and state machine of multi->peer_id does not exactly the lifetime/state of DCO. This is especially for p2p NCP where a reconnection can change the peer id. Also use this new field with value -1 to mean not installed, replacing the dco_peer_added field.
--- src/openvpn/dco.c | 24 ++++++++++++------------ src/openvpn/forward.c | 2 +- src/openvpn/init.c | 4 ++-- src/openvpn/multi.c | 8 ++++---- src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 9 ++++++++- 6 files changed, 28 insertions(+), 20 deletions(-)
src/openvpn/dco.c +12 -12
@@ -55,7 +55,7 @@ dco_install_key(struct tls_multi *multi, struct key_state *ks, const char *ciphername) { -msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->peer_id, +msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->dco_peer_id, ks->key_id);/* Install a key in the PRIMARY slot only when no other key exist.
@@ -69,7 +69,7 @@ dco_install_key(struct tls_multi *multi, struct key_state *ks, slot =OVPN_KEY_SLOT_SECONDARY ; } -int ret =dco_new_key (multi->dco, multi->peer_id, ks->key_id, slot, +int ret =dco_new_key (multi->dco, multi->dco_peer_id, ks->key_id, slot, encrypt_key, encrypt_iv, decrypt_key, decrypt_iv, ciphername);
@@ -133,7 +133,7 @@ dco_get_secondary_key(struct tls_multi *multi, const struct key_state *primary)void dco_update_keys (dco_context_t *dco,struct tls_multi *multi) { -msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->peer_id); +msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->dco_peer_id);/* this function checks if keys have to be swapped or erased, therefore it * can't do much if we don't have any key installed
@@ -151,14 +151,14 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi) {msg (D_DCO ,"No encryption key found. Purging data channel keys" ); -int ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_PRIMARY ); +int ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_PRIMARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete primary key during wipe: %s (%d)" ,strerror (-ret), ret);return ; } - ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); + ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_SECONDARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete secondary key during wipe: %s (%d)" ,strerror (-ret), ret);
@@ -184,7 +184,7 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)msg (D_DCO_DEBUG ,"Swapping primary and secondary keys, now: id1=%d id2=%d" , primary->key_id, secondary ? secondary->key_id :-1 ); -int ret =dco_swap_keys (dco, multi->peer_id); +int ret =dco_swap_keys (dco, multi->dco_peer_id);if (ret <0 ) {msg (D_DCO ,"Cannot swap keys: %s (%d)" ,strerror (-ret), ret);
@@ -202,7 +202,7 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)/* if we have no secondary key anymore, inform DCO about it */ if (!secondary && multi->dco_keys_installed ==2 ) { -int ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); +int ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_SECONDARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete secondary key: %s (%d)" ,strerror (-ret), ret);
@@ -447,7 +447,7 @@ dco_p2p_add_new_peer(struct context *c)return ret; } - c->c2.tls_multi->dco_peer_added = true; + c->c2.tls_multi->dco_peer_id = multi->peer_id; c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ;
@@ -461,10 +461,10 @@ dco_remove_peer(struct context *c)return ; } -if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) +if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_id) { -dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); - c->c2.tls_multi->dco_peer_added = false; +dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->dco_peer_id); + c->c2.tls_multi->dco_peer_id =-1 ; } }
@@ -567,7 +567,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi)return ret; } - c->c2.tls_multi->dco_peer_added = true; + c->c2.tls_multi->dco_peer_id = peer_id;if (c->mode ==CM_CHILD_TCP ) {
src/openvpn/forward.c +1 -1
@@ -1724,7 +1724,7 @@ process_outgoing_link(struct context *c)if (should_use_dco_socket (c->c2.to_link_addr)) { size =dco_do_write (&c->c1.tuntap->dco, - c->c2.tls_multi->peer_id, + c->c2.tls_multi->dco_peer_id, &c->c2.to_link); }else
src/openvpn/init.c +2 -2
@@ -2150,14 +2150,14 @@ do_deferred_options_part2(struct context *c) && (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->c2.tls_multi->dco_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 parameters for DCO peer (id=%u): %s" , - c->c2.tls_multi->peer_id,strerror (-ret)); + c->c2.tls_multi->dco_peer_id,strerror (-ret));return false; } }
src/openvpn/multi.c +4 -4
@@ -2448,14 +2448,14 @@ multi_client_connect_late_setup(struct multi_context *m,if (mi->context.options.ping_send_timeout || mi->context.c2.frame.mss_fix) {int ret =dco_set_peer (&mi->context.c1.tuntap->dco, - mi->context.c2.tls_multi->peer_id, + mi->context.c2.tls_multi->dco_peer_id, mi->context.options.ping_send_timeout, mi->context.options.ping_rec_timeout, mi->context.c2.frame.mss_fix);if (ret <0 ) {msg (D_DCO ,"Cannot set parameters for DCO peer (id=%u): %s" , - mi->context.c2.tls_multi->peer_id,strerror (-ret)); + mi->context.c2.tls_multi->dco_peer_id,strerror (-ret)); mi->context.c2.tls_multi->multi_state =CAS_FAILED ; } }
@@ -3226,8 +3226,8 @@ process_incoming_del_peer(struct multi_context *m, struct multi_instance *mi, }/* When kernel already deleted the peer, the socket is no longer -* installed and we don't need to cleanup the state in the kernel */ - mi->context.c2.tls_multi->dco_peer_added = false; +* installed, and we do not need to clean up the state in the kernel */ + mi->context.c2.tls_multi->dco_peer_id =-1 ; mi->context.sig->signal_text = reason;multi_signal_instance (m, mi,SIGTERM ); }
src/openvpn/ssl.c +1 -0
@@ -1266,6 +1266,7 @@ tls_multi_init(struct tls_options *tls_options)/* get command line derived options */ ret->opt = *tls_options; + ret->dco_peer_id =-1 ;return ret; }
src/openvpn/ssl_common.h +8 -1
@@ -659,7 +659,14 @@ struct tls_multi/* Only used when DCO is used to remember how many keys we installed * for this session */ int dco_keys_installed; -bool dco_peer_added; +/** +* This is the handle that DCO uses to identify this session with the +* kernel. +* +* We keep this separate as the normal peer_id can change during +* p2p NCP and we need to track the id that is really used. +*/ +int dco_peer_id;dco_context_t *dco; };
Signature · 1 line
2.37.0 (Apple Git-136)
PATCH 3/3 Call dco_p2p_add_new_peer again if the peer id changes
In reply to Arne SchwabeThis allows a reconnect in p2p mode and has the side effect of updating the peer address with the peerid
--- src/openvpn/forward.c | 7 +++++++ 1 file changed, 7 insertions(+)
src/openvpn/forward.c +7 -0
@@ -150,6 +150,13 @@ check_dco_key_status(struct context *c)return ; } +/* If the DCO peer id changed, we need to readd the peer */ +if (c->c2.tls_multi->dco_peer_id !=-1 + && c->c2.tls_multi->peer_id != c->c2.tls_multi->dco_peer_id) + { +dco_p2p_add_new_peer (c); + } +dco_update_keys (&c->c1.tuntap->dco, c->c2.tls_multi); }
Signature · 1 line
2.37.0 (Apple Git-136)
Re: [Openvpn-devel] [PATCH 2/3] Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
In reply to Arne SchwabeHi,
Quoted 4 lines · Arne Schwabe
The lifetime and state machine of
multi->peer_iddoes not exactly the lifetime/state of DCO. This is especially for p2p NCP where a reconnection can change the peer id. Also use this new field with value -1 to mean not installed, replacing thedco_peer_addedfield.
The code seems to disagree with itself whether it's -1 or 0, if I read this correctly...
src/openvpn/dco.c dco_remove_peer(struct context *c) · line 465
Quoted 7 lines
src/openvpn/dco.c +1
-1@@ -461,10 +461,10 @@ dco_remove_peer(struct context *c)return ; } -if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) +if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_id) {
This checks for "not 0"...
src/openvpn/dco.c dco_remove_peer(struct context *c) · line 467
Quoted 4 lines
src/openvpn/dco.c +2
-2-dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); - c->c2.tls_multi->dco_peer_added = false; +dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->dco_peer_id); + c->c2.tls_multi->dco_peer_id =-1 ;
... but sets -1 here, which would evaluate to "true"...?
(All the rest sets "-1", AFAICS, just the if() here is weird)
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH 2/3] Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
Hi,
Quoted 21 lines · Gert Doering
Hi,
Quoted 4 lines · Arne Schwabe
The lifetime and state machine of
multi->peer_iddoes not exactly the lifetime/state of DCO. This is especially for p2p NCP where a reconnection can change the peer id. Also use this new field with value -1 to mean not installed, replacing thedco_peer_addedfield.The code seems to disagree with itself whether it's -1 or 0, if I read this correctly...
src/openvpn/dco.c dco_remove_peer(struct context *c) · line 465
Quoted 7 lines
src/openvpn/dco.c +1
-1@@ -461,10 +461,10 @@ dco_remove_peer(struct context *c)return ; } -if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) +if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_id) {This checks for "not 0"...
Quoted 8 lines
src/openvpn/dco.c dco_remove_peer(struct context *c) · line 467
Quoted 4 lines
src/openvpn/dco.c +2
-2-dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); - c->c2.tls_multi->dco_peer_added = false; +dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->dco_peer_id); + c->c2.tls_multi->dco_peer_id =-1 ;... but sets -1 here, which would evaluate to "true"...?
(All the rest sets "-1", AFAICS, just the
if()here is weird)
Using -1 makes sense, because 0 is a valid peer ID. I presume just that if () is wrong.
Cheers,
Quoted 9 lines
gert
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH 2/3] Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
Am 12.10.22 um 22:54 schrieb Antonio Quartulli:
Quoted 30 lines
Hi,
Quoted 27 lines · Gert Doering
Hi,
Quoted 4 lines · Arne Schwabe
The lifetime and state machine of
multi->peer_iddoes not exactly the lifetime/state of DCO. This is especially for p2p NCP where a reconnection can change the peer id. Also use this new field with value -1 to mean not installed, replacing thedco_peer_addedfield.The code seems to disagree with itself whether it's -1 or 0, if I read this correctly...
Review dco_remove_peer(struct context *c) · line 466
Quoted 8 lines
(quoted diff) +1
-1@@ -461,10 +461,10 @@ dco_remove_peer(struct context *c) return; } - if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) + if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_id) {This checks for "not 0"...
Quoted 4 lines
src/openvpn/dco.c +2
-2- dco_del_peer(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); - c->c2.tls_multi->dco_peer_added = false; + dco_del_peer(&c->c1.tuntap->dco, c->c2.tls_multi->dco_peer_id); + c->c2.tls_multi->dco_peer_id = -1;
Quoted 5 lines
Quoted 3 lines
... but sets -1 here, which would evaluate to "true"...?
(All the rest sets "-1", AFAICS, just the
if()here is weird)Using -1 makes sense, because 0 is a valid peer ID. I presume just that if () is wrong.
Yes. Will update the patch with a correct if.
Arne
Lev Stipakov
NAKNAK.
static inline int link_socket_read_udp_win32(struct link_socket *sock,
struct buffer *buf, struct link_socket_actual *from)
{
sockethandle_t sh = { .s = sock->sd };
if (sock->info.dco_installed)2>C:\Users\lev\Projects\openvpn\src\openvpn\socket.h(1053,20): error
C2039: 'dco_installed': is not a member of 'link_socket_info' 2>C:\Users\lev\Projects\openvpn\src\openvpn\socket.h(114): message :
see declaration of 'link_socket_info'
ke 12. lokak. 2022 klo 16.35 Arne Schwabe ([email protected]...) kirjoitti:
Quoted 190 lines
For tcp this makes no difference as the remote address of the socket never changes. For udp this allows OpenVPN to differentiate if a reconnecting client is using the same address as before or from a different one. This allow sending via the normal userspace socket in that case.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/dco.c | 7 ++++--- src/openvpn/dco_linux.c | 2 +- src/openvpn/forward.c | 8 ++++---- src/openvpn/init.c | 2 +- src/openvpn/mtcp.c | 6 +++--- src/openvpn/socket.h | 6 +++--- 6 files changed, 16 insertions(+), 15 deletions(-)src/openvpn/dco.c +4
-3@@ -448,7 +448,7 @@ dco_p2p_add_new_peer(struct context *c) } c->c2.tls_multi->dco_peer_added = true; - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ; }@@ -522,7 +522,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {struct context *c = &mi->context; -int peer_id = mi->context.c2.tls_multi->peer_id; +int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 };int sd = c->c2.link_socket->sd;@@ -531,6 +531,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {/* the remote address will be inferred from the TCP socket endpoint */ remoteaddr =NULL ; + c->c2.link_socket->info.lsa->actual.dco_installed = true; } else {@@ -575,7 +576,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {msg (D_DCO |M_ERRNO ,"error closing TCP socket after DCO handover" ); } - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true; c->c2.link_socket->sd =SOCKET_UNDEFINED ; }src/openvpn/dco_linux.c +1
-1@@ -285,7 +285,7 @@ ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg)* * We pass the error code to the user by means of a variable pointed by *arg * (supplied by the user when setting this callback) and we parse the kernel -* reply to see if it contains a human readable error. If found, it is printed. +* reply to see if it contains a human-readable error. If found, it is printed. */ static int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),src/openvpn/forward.c +4
-4@@ -1636,13 +1636,13 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf)* standard Overlapped I/O. * * Hide that complexity (...especially if more platforms show up -* in future...) in a small inline function. +* in the future...) in a small inline function. */ static inline bool -should_use_dco_socket (struct link_socket *sock) +should_use_dco_socket (struct link_socket_actual *actual) {#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) -return sock->info.dco_installed; +return actual->dco_installed;#else return false;#endif @@ -1721,7 +1721,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (should_use_dco_socket (c->c2.link_socket)) +if (should_use_dco_socket (c->c2.to_link_addr)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,src/openvpn/init.c +1
-1@@ -3625,7 +3625,7 @@ do_close_link_socket(struct context *c)* closed in do_close_tun(). Set it to UNDEFINED so * we won't use WinSock API to close it. */ if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket - && c->c2.link_socket->info.dco_installed) + && c->c2.link_socket->info.lsa->actual.dco_installed) { c->c2.link_socket->sd =SOCKET_UNDEFINED ; }src/openvpn/mtcp.c +3
-3@@ -402,7 +402,7 @@ multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, const intv_clear (&c->c2.timeval);/* ZERO-TIMEOUT */ -if (mi && mi->context.c2.link_socket->info.dco_installed) +if (mi && mi->context.c2.link_socket->info.lsa->actual.dco_installed) {/* If we got a socket that has been handed over to the kernel * we must not call the normal socket function to figure out @@ -537,7 +537,7 @@ multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const intcase TA_INITIAL :ASSERT (mi); -if (!mi->context.c2.link_socket->info.dco_installed) +if (!mi->context.c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }@@ -590,7 +590,7 @@ multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int act }else { -if (!c->c2.link_socket->info.dco_installed) +if (!c->c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }src/openvpn/socket.h +3
-4@@ -88,6 +88,7 @@ struct link_socket_actual/*int dummy;*/ /* add offset to force a bug if dest not explicitly dereferenced */ struct openvpn_sockaddr dest; +bool dco_installed; #if ENABLE_IP_PKTINFO union { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)@@ -121,7 +122,6 @@ struct link_socket_infosa_family_t af;/* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/ bool bind_ipv6_only;int mtu_changed;/* Set to true when mtu value is changed */ -bool dco_installed; };/* @@ -1073,7 +1073,7 @@ link_socket_read(struct link_socket *sock, struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) - || sock->info.dco_installed) + || sock->info.lsa->actual.dco_installed)/* unified UDPv4 and UDPv6, for DCO the kernel * will strip the length header */ {@@ -1190,7 +1190,7 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) + if (proto_is_udp(sock->info.proto) || to->dco_installed) { /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to); --2.37.0 (Apple Git-136)
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
PATCH v2 1/3 Move dco_installed from sock->info to sock->info.lsa.actual
In reply to Arne SchwabeFor tcp this makes no difference as the remote address of the socket never changes. For udp this allows OpenVPN to differentiate if a reconnecting client is using the same address as before or from a different one. This allow sending via the normal userspace socket in that case.
Patch v2: fix windows code path
--- src/openvpn/dco.c | 7 ++++--- src/openvpn/dco_linux.c | 2 +- src/openvpn/forward.c | 8 ++++---- src/openvpn/init.c | 2 +- src/openvpn/mtcp.c | 6 +++--- src/openvpn/socket.c | 8 ++++---- src/openvpn/socket.h | 12 ++++++------ 7 files changed, 23 insertions(+), 22 deletions(-)
src/openvpn/dco.c +4 -3
@@ -448,7 +448,7 @@ dco_p2p_add_new_peer(struct context *c) } c->c2.tls_multi->dco_peer_added = true; - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ; }
@@ -522,7 +522,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {struct context *c = &mi->context; -int peer_id = mi->context.c2.tls_multi->peer_id; +int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 };int sd = c->c2.link_socket->sd;
@@ -531,6 +531,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {/* the remote address will be inferred from the TCP socket endpoint */ remoteaddr =NULL ; + c->c2.link_socket->info.lsa->actual.dco_installed = true; } else {
@@ -575,7 +576,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {msg (D_DCO |M_ERRNO ,"error closing TCP socket after DCO handover" ); } - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true; c->c2.link_socket->sd =SOCKET_UNDEFINED ; }
src/openvpn/dco_linux.c +1 -1
@@ -285,7 +285,7 @@ ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg)* * We pass the error code to the user by means of a variable pointed by *arg * (supplied by the user when setting this callback) and we parse the kernel -* reply to see if it contains a human readable error. If found, it is printed. +* reply to see if it contains a human-readable error. If found, it is printed. */ static int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),
src/openvpn/forward.c +4 -4
@@ -1643,13 +1643,13 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf)* standard Overlapped I/O. * * Hide that complexity (...especially if more platforms show up -* in future...) in a small inline function. +* in the future...) in a small inline function. */ static inline bool -should_use_dco_socket (struct link_socket *sock) +should_use_dco_socket (struct link_socket_actual *actual) {#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) -return sock->info.dco_installed; +return actual->dco_installed;#else return false;#endif
@@ -1728,7 +1728,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (should_use_dco_socket (c->c2.link_socket)) +if (should_use_dco_socket (c->c2.to_link_addr)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,
src/openvpn/init.c +1 -1
@@ -3644,7 +3644,7 @@ do_close_link_socket(struct context *c)* closed in do_close_tun(). Set it to UNDEFINED so * we won't use WinSock API to close it. */ if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket - && c->c2.link_socket->info.dco_installed) + && c->c2.link_socket->info.lsa->actual.dco_installed) { c->c2.link_socket->sd =SOCKET_UNDEFINED ; }
src/openvpn/mtcp.c +3 -3
@@ -402,7 +402,7 @@ multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, const intv_clear (&c->c2.timeval);/* ZERO-TIMEOUT */ -if (mi && mi->context.c2.link_socket->info.dco_installed) +if (mi && mi->context.c2.link_socket->info.lsa->actual.dco_installed) {/* If we got a socket that has been handed over to the kernel * we must not call the normal socket function to figure out
@@ -537,7 +537,7 @@ multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const intcase TA_INITIAL :ASSERT (mi); -if (!mi->context.c2.link_socket->info.dco_installed) +if (!mi->context.c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }
@@ -590,7 +590,7 @@ multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int act }else { -if (!c->c2.link_socket->info.dco_installed) +if (!c->c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }
src/openvpn/socket.c +4 -4
@@ -2147,7 +2147,7 @@ create_socket_dco_win(struct context *c, struct link_socket *sock,get_server_poll_remaining_time (sock->server_poll_timeout), signal_received); - sock->info.dco_installed = true; + sock->info.lsa->actual.dco_installed = true;if (*signal_received) {
@@ -3480,7 +3480,7 @@ link_socket_write_udp_posix_sendmsg(struct link_socket *sock,static int socket_get_last_error (const struct link_socket *sock) { -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) {return GetLastError (); }
@@ -3521,7 +3521,7 @@ socket_recv_queue(struct link_socket *sock, int maxsize)ASSERT (ResetEvent (sock->reads.overlapped.hEvent)); sock->reads.flags =0 ; -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) { status =ReadFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, &sock->reads.size, &sock->reads.overlapped);
@@ -3626,7 +3626,7 @@ socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct linASSERT (ResetEvent (sock->writes.overlapped.hEvent)); sock->writes.flags =0 ; -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) { status =WriteFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, &sock->writes.size, &sock->writes.overlapped);
src/openvpn/socket.h +6 -6
@@ -88,6 +88,7 @@ struct link_socket_actual/*int dummy;*/ /* add offset to force a bug if dest not explicitly dereferenced */ struct openvpn_sockaddr dest; +bool dco_installed; #if ENABLE_IP_PKTINFO union { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
@@ -121,7 +122,6 @@ struct link_socket_infosa_family_t af;/* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/ bool bind_ipv6_only;int mtu_changed;/* Set to true when mtu value is changed */ -bool dco_installed; };/*
@@ -1050,9 +1050,9 @@ 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) +if (sock->info.lsa->actual.dco_installed) { -addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + *from = sock->info.lsa->actual; sh.is_handle = true; }return sockethandle_finalize (sh, &sock->reads, buf, from);
@@ -1073,7 +1073,7 @@ link_socket_read(struct link_socket *sock, struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) - || sock->info.dco_installed) + || sock->info.lsa->actual.dco_installed)/* unified UDPv4 and UDPv6, for DCO the kernel * will strip the length header */ {
@@ -1116,7 +1116,7 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.lsa->actual.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );
@@ -1190,7 +1190,7 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) + if (proto_is_udp(sock->info.proto) || to->dco_installed) { /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to);
Signature · 1 line
2.37.0 (Apple Git-136)
Hi,
src/openvpn/socket.h link_socket_write(struct link_socket *sock, · line 1194
Quoted 7 lines
src/openvpn/socket.h +1
-1@@ -1190,7 +1190,7 @@ link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) + if (proto_is_udp(sock->info.proto) || to->dco_installed) {
Previously we used to check the dco flag from sock->info and now it is changed to "to", which is a separate member in c->c2 (c->c2.to_link_addr vs c->c2.link_socket).
Why not use "sock->info.lsa->actual.dco_installed" ? My understanding is that this patch
only moves the flag to a different place and is not supposed to change the behavior.
Besides, below we call link_socket_write_win32(), which down the stack checks dco flag from "sock",
not from "to":
static inline int link_socket_write_win32(struct link_socket *sock,
struct buffer *buf, struct link_socket_actual *to)
{
int err = 0;
int status = 0;
sockethandle_t sh = { .s = sock->sd, .is_handle =sock->info.lsa->actual.dco_installed };
This doesn't look consistent.
-Lev
Hi,
Quoted 9 lines · Arne Schwabe
For tcp this makes no difference as the remote address of the socket never changes. For udp this allows OpenVPN to differentiate if a reconnecting client is using the same address as before or from a different one. This allow sending via the normal userspace socket in that case.
Patch v2: fix windows code path
Signed-off-by Arne Schwabe <[email protected]...>
I couldn't test this patch extensively, but it looks good to me. This basically completes what I discussed with Arne some weeks ago.
However, please ensure to get this patch through the test rig before merging.
Regards,
Quoted 235 lines
--- src/openvpn/dco.c | 7 ++++--- src/openvpn/dco_linux.c | 2 +- src/openvpn/forward.c | 8 ++++---- src/openvpn/init.c | 2 +- src/openvpn/mtcp.c | 6 +++--- src/openvpn/socket.c | 8 ++++---- src/openvpn/socket.h | 12 ++++++------ 7 files changed, 23 insertions(+), 22 deletions(-)src/openvpn/dco.c +4
-3@@ -448,7 +448,7 @@ dco_p2p_add_new_peer(struct context *c) } c->c2.tls_multi->dco_peer_added = true; - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ; }@@ -522,7 +522,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {struct context *c = &mi->context; -int peer_id = mi->context.c2.tls_multi->peer_id; +int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 };int sd = c->c2.link_socket->sd;@@ -531,6 +531,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {/* the remote address will be inferred from the TCP socket endpoint */ remoteaddr =NULL ; + c->c2.link_socket->info.lsa->actual.dco_installed = true; } else {@@ -575,7 +576,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {msg (D_DCO |M_ERRNO ,"error closing TCP socket after DCO handover" ); } - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true; c->c2.link_socket->sd =SOCKET_UNDEFINED ; }src/openvpn/dco_linux.c +1
-1@@ -285,7 +285,7 @@ ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg)* * We pass the error code to the user by means of a variable pointed by *arg * (supplied by the user when setting this callback) and we parse the kernel -* reply to see if it contains a human readable error. If found, it is printed. +* reply to see if it contains a human-readable error. If found, it is printed. */ static int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),src/openvpn/forward.c +4
-4@@ -1643,13 +1643,13 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf)* standard Overlapped I/O. * * Hide that complexity (...especially if more platforms show up -* in future...) in a small inline function. +* in the future...) in a small inline function. */ static inline bool -should_use_dco_socket (struct link_socket *sock) +should_use_dco_socket (struct link_socket_actual *actual) {#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) -return sock->info.dco_installed; +return actual->dco_installed;#else return false;#endif @@ -1728,7 +1728,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (should_use_dco_socket (c->c2.link_socket)) +if (should_use_dco_socket (c->c2.to_link_addr)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,src/openvpn/init.c +1
-1@@ -3644,7 +3644,7 @@ do_close_link_socket(struct context *c)* closed in do_close_tun(). Set it to UNDEFINED so * we won't use WinSock API to close it. */ if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket - && c->c2.link_socket->info.dco_installed) + && c->c2.link_socket->info.lsa->actual.dco_installed) { c->c2.link_socket->sd =SOCKET_UNDEFINED ; }src/openvpn/mtcp.c +3
-3@@ -402,7 +402,7 @@ multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, const intv_clear (&c->c2.timeval);/* ZERO-TIMEOUT */ -if (mi && mi->context.c2.link_socket->info.dco_installed) +if (mi && mi->context.c2.link_socket->info.lsa->actual.dco_installed) {/* If we got a socket that has been handed over to the kernel * we must not call the normal socket function to figure out @@ -537,7 +537,7 @@ multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const intcase TA_INITIAL :ASSERT (mi); -if (!mi->context.c2.link_socket->info.dco_installed) +if (!mi->context.c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }@@ -590,7 +590,7 @@ multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int act }else { -if (!c->c2.link_socket->info.dco_installed) +if (!c->c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }src/openvpn/socket.c +4
-4@@ -2147,7 +2147,7 @@ create_socket_dco_win(struct context *c, struct link_socket *sock,get_server_poll_remaining_time (sock->server_poll_timeout), signal_received); - sock->info.dco_installed = true; + sock->info.lsa->actual.dco_installed = true;if (*signal_received) {@@ -3480,7 +3480,7 @@ link_socket_write_udp_posix_sendmsg(struct link_socket *sock,static int socket_get_last_error (const struct link_socket *sock) { -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) {return GetLastError (); }@@ -3521,7 +3521,7 @@ socket_recv_queue(struct link_socket *sock, int maxsize)ASSERT (ResetEvent (sock->reads.overlapped.hEvent)); sock->reads.flags =0 ; -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) { status =ReadFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, &sock->reads.size, &sock->reads.overlapped);@@ -3626,7 +3626,7 @@ socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct linASSERT (ResetEvent (sock->writes.overlapped.hEvent)); sock->writes.flags =0 ; -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) { status =WriteFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, &sock->writes.size, &sock->writes.overlapped);src/openvpn/socket.h +6
-6@@ -88,6 +88,7 @@ struct link_socket_actual/*int dummy;*/ /* add offset to force a bug if dest not explicitly dereferenced */ struct openvpn_sockaddr dest; +bool dco_installed; #if ENABLE_IP_PKTINFO union { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)@@ -121,7 +122,6 @@ struct link_socket_infosa_family_t af;/* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/ bool bind_ipv6_only;int mtu_changed;/* Set to true when mtu value is changed */ -bool dco_installed; };/* @@ -1050,9 +1050,9 @@ 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) +if (sock->info.lsa->actual.dco_installed) { -addr_copy_sa (&from->dest, &sock->info.lsa->actual.dest); + *from = sock->info.lsa->actual; sh.is_handle = true; }return sockethandle_finalize (sh, &sock->reads, buf, from);@@ -1073,7 +1073,7 @@ link_socket_read(struct link_socket *sock, struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) - || sock->info.dco_installed) + || sock->info.lsa->actual.dco_installed)/* unified UDPv4 and UDPv6, for DCO the kernel * will strip the length header */ {@@ -1116,7 +1116,7 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.lsa->actual.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );@@ -1190,7 +1190,7 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) + if (proto_is_udp(sock->info.proto) || to->dco_installed) { /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to);
Signature · 1 line
Antonio Quartulli
Hi,
Quoted 7 lines · Arne Schwabe
For tcp this makes no difference as the remote address of the socket never changes. For udp this allows OpenVPN to differentiate if a reconnecting client is using the same address as before or from a different one. This allow sending via the normal userspace socket in that case.
Patch v2: fix windows code path
Subjected this to the usual torturing, and while everything *looks* good, it breaks
FreeBSD tcp client (old code) --> Linux DCO server (master + patch)
freshly started regular TCP/TLS server instance, handshakes just fine, until the PUSH_REPLY wants to be sent (peer-id allocation?), then
2022-11-23 14:22:50 us=358335 freebsd-14-amd64/194.97.140.5:54725 Data Channel MTU parms [ mss_fix:1366 max_frag:0 tun_mtu:1500 tun_max_mtu:1600 headroom:136 payload:1768 tailroom:562 ET:0 ] 2022-11-23 14:22:50 us=358871 freebsd-14-amd64/194.97.140.5:54725 SENT CONTROL [freebsd-14-amd64]: 'PUSH_REPLY,route 10.220.0.0 255.255.0.0,route-ipv6 fd00:abcd:220::/48,tun-ipv6,route-gateway 10.220.1.1,topology subnet,ping 10,ping-restart 30,compress stub-v2,ifconfig-ipv6 fd00:abcd:220:1::1002/64 fd00:abcd:220:1::1,ifconfig 10.220.1.4 255.255.255.0,peer-id 0,cipher AES-256-GCM' (status=1) 2022-11-23 14:22:50 us=359153 freebsd-14-amd64/194.97.140.5:54725 write TCPv6_SERVER []: Bad file descriptor (fd=-1,code=9) 2022-11-23 14:22:52 us=525667 freebsd-14-amd64/194.97.140.5:54725 PUSH: Received control message: 'PUSH_REQUEST' 2022-11-23 14:22:52 us=526099 freebsd-14-amd64/194.97.140.5:54725 write TCPv6_SERVER []: Bad file descriptor (fd=-1,code=9) 2022-11-23 14:22:56 us=611511 freebsd-14-amd64/194.97.140.5:54725 write TCPv6_SERVER []: Bad file descriptor (fd=-1,code=9) 2022-11-23 14:23:04 us=694791 freebsd-14-amd64/194.97.140.5:54725 PUSH: Received control message: 'PUSH_REQUEST' 2022-11-23 14:23:04 us=694916 freebsd-14-amd64/194.97.140.5:54725 write TCPv6_SERVER []: Bad file descriptor (fd=-1,code=9) 2022-11-23 14:23:04 us=694966 freebsd-14-amd64/194.97.140.5:54725 PUSH: Received control message: 'PUSH_REQUEST' 2022-11-23 14:23:05 us=853345 freebsd-14-amd64/194.97.140.5:54725 write TCPv6_SERVER []: Bad file descriptor (fd=-1,code=9)
on the client I have
2022-11-23 14:22:50 Control Channel: TLSv1.2, cipher TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305, peer certificate: 2048 bit RSA, signature: RSA-SHA1 2022-11-23 14:22:50 [server] Peer Connection Initiated with [AF_INET]195.30.8.84:51194 2022-11-23 14:22:51 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1) 2022-11-23 14:22:56 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1) 2022-11-23 14:23:00 TLS Error: local/remote TLS keys are out of sync: [AF_INET]195.30.8.84:51194 (received key id: 0, known key ids: [key#0 state=S_ACTIVE auth=KS_AUTH_TRUE id=0 sid=934b2d6e 14c3286f] [key#1 state=S_UNDEF auth=KS_AUTH_FALSE id=0 sid=00000000 00000000] [key#2 state=S_UNDEF auth=KS_AUTH_FALSE id=0 sid=00000000 00000000]) 2022-11-23 14:23:01 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1) 2022-11-23 14:23:06 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1) 2022-11-23 14:23:10 TLS Error: local/remote TLS keys are out of sync: [AF_INET]195.30.8.84:51194 (received key id: 0, known key ids: [key#0 state=S_ACTIVE auth=KS_AUTH_TRUE id=0 sid=934b2d6e 14c3286f] [key#1 state=S_UNDEF auth=KS_AUTH_FALSE id=0 sid=00000000 00000000] [key#2 state=S_UNDEF auth=KS_AUTH_FALSE id=0 sid=00000000 00000000])
Not exactly sure why it hickups. This is fully reproduceable, so if you want me to increas debug, just let me know.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v3 1/3 Move dco_installed from sock->info to sock->info.lsa.actual
In reply to Arne SchwabeFor tcp this makes no difference as the remote address of the socket never changes. For udp this allows OpenVPN to differentiate if a reconnecting client is using the same address as before or from a different one. This allow sending via the normal userspace socket in that case.
Patch v2: fix windows code path
Patch v3: fix mtcp server code path
--- src/openvpn/dco.c | 27 +++++++++++++++++++++++---- src/openvpn/dco_linux.c | 2 +- src/openvpn/forward.c | 8 ++++---- src/openvpn/init.c | 2 +- src/openvpn/mtcp.c | 6 +++--- src/openvpn/socket.c | 8 ++++---- src/openvpn/socket.h | 12 ++++++------ 7 files changed, 42 insertions(+), 23 deletions(-)
src/openvpn/dco.c +23 -4
@@ -426,6 +426,22 @@ dco_check_pull_options(int msglevel, const struct options *o)return true; } +static void +addr_set_dco_installed (struct context *c) +{ +/* We ensure that all addresses we currently hold have the dco_installed +* bit set */ +for (int i =0 ; i <KEY_SCAN_SIZE ; ++i) + { +struct key_state *ks =get_key_scan (c->c2.tls_multi, i); +if (ks) + { + ks->remote_addr.dco_installed = true; + } + } +get_link_socket_info (c)->lsa->actual.dco_installed = true; +} +int dco_p2p_add_new_peer (struct context *c) {
@@ -438,6 +454,8 @@ dco_p2p_add_new_peer(struct context *c)ASSERT (ls->info.connection_established); +addr_set_dco_installed (c); +struct sockaddr *remoteaddr = &ls->info.lsa->actual.dest.addr.sa;struct tls_multi *multi = c->c2.tls_multi; int ret = dco_new_peer(&c->c1.tuntap->dco, multi->peer_id,
@@ -448,7 +466,7 @@ dco_p2p_add_new_peer(struct context *c) } c->c2.tls_multi->dco_peer_added = true; - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ; }
@@ -522,11 +540,12 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {struct context *c = &mi->context; -int peer_id = mi->context.c2.tls_multi->peer_id; +int peer_id = c->c2.tls_multi->peer_id;struct sockaddr *remoteaddr, *localaddr =NULL ;struct sockaddr_storage local = {0 };int sd = c->c2.link_socket->sd; +if (c->mode ==CM_CHILD_TCP ) {/* the remote address will be inferred from the TCP socket endpoint */
@@ -537,9 +556,9 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi)ASSERT (c->c2.link_socket_info->connection_established); remoteaddr = &c->c2.link_socket_info->lsa->actual.dest.addr.sa; } +addr_set_dco_installed (c);/* In server mode we need to fetch the remote addresses from the push config */ -struct in_addr vpn_ip4 = {0 };struct in_addr *vpn_addr4 =NULL ;if (c->c2.push_ifconfig_defined)
@@ -575,7 +594,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi) {msg (D_DCO |M_ERRNO ,"error closing TCP socket after DCO handover" ); } - c->c2.link_socket->info.dco_installed = true; + c->c2.link_socket->info.lsa->actual.dco_installed = true; c->c2.link_socket->sd =SOCKET_UNDEFINED ; }
src/openvpn/dco_linux.c +1 -1
@@ -285,7 +285,7 @@ ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg)* * We pass the error code to the user by means of a variable pointed by *arg * (supplied by the user when setting this callback) and we parse the kernel -* reply to see if it contains a human readable error. If found, it is printed. +* reply to see if it contains a human-readable error. If found, it is printed. */ static int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),
src/openvpn/forward.c +4 -4
@@ -1643,13 +1643,13 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf)* standard Overlapped I/O. * * Hide that complexity (...especially if more platforms show up -* in future...) in a small inline function. +* in the future...) in a small inline function. */ static inline bool -should_use_dco_socket (struct link_socket *sock) +should_use_dco_socket (struct link_socket_actual *actual) {#if defined(TARGET_LINUX ) || defined(TARGET_FREEBSD ) -return sock->info.dco_installed; +return actual->dco_installed;#else return false;#endif
@@ -1728,7 +1728,7 @@ process_outgoing_link(struct context *c)socks_preprocess_outgoing_link (c, &to_addr, &size_delta);/* Send packet */ -if (should_use_dco_socket (c->c2.link_socket)) +if (should_use_dco_socket (c->c2.to_link_addr)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,
src/openvpn/init.c +1 -1
@@ -3678,7 +3678,7 @@ do_close_link_socket(struct context *c)* closed in do_close_tun(). Set it to UNDEFINED so * we won't use WinSock API to close it. */ if (tuntap_is_dco_win (c->c1.tuntap) && c->c2.link_socket - && c->c2.link_socket->info.dco_installed) + && c->c2.link_socket->info.lsa->actual.dco_installed) { c->c2.link_socket->sd =SOCKET_UNDEFINED ; }
src/openvpn/mtcp.c +3 -3
@@ -402,7 +402,7 @@ multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, const intv_clear (&c->c2.timeval);/* ZERO-TIMEOUT */ -if (mi && mi->context.c2.link_socket->info.dco_installed) +if (mi && mi->context.c2.link_socket->info.lsa->actual.dco_installed) {/* If we got a socket that has been handed over to the kernel * we must not call the normal socket function to figure out
@@ -537,7 +537,7 @@ multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const intcase TA_INITIAL :ASSERT (mi); -if (!mi->context.c2.link_socket->info.dco_installed) +if (!mi->context.c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }
@@ -590,7 +590,7 @@ multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int act }else { -if (!c->c2.link_socket->info.dco_installed) +if (!c->c2.link_socket->info.lsa->actual.dco_installed) {multi_tcp_set_global_rw_flags (m, mi); }
src/openvpn/socket.c +4 -4
@@ -2147,7 +2147,7 @@ create_socket_dco_win(struct context *c, struct link_socket *sock,get_server_poll_remaining_time (sock->server_poll_timeout), signal_received); - sock->info.dco_installed = true; + sock->info.lsa->actual.dco_installed = true;if (*signal_received) {
@@ -3480,7 +3480,7 @@ link_socket_write_udp_posix_sendmsg(struct link_socket *sock,static int socket_get_last_error (const struct link_socket *sock) { -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) {return GetLastError (); }
@@ -3521,7 +3521,7 @@ socket_recv_queue(struct link_socket *sock, int maxsize)ASSERT (ResetEvent (sock->reads.overlapped.hEvent)); sock->reads.flags =0 ; -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) { status =ReadFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, &sock->reads.size, &sock->reads.overlapped);
@@ -3626,7 +3626,7 @@ socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct linASSERT (ResetEvent (sock->writes.overlapped.hEvent)); sock->writes.flags =0 ; -if (sock->info.dco_installed) +if (sock->info.lsa->actual.dco_installed) { status =WriteFile ((HANDLE )sock->sd, wsabuf[0 ].buf, wsabuf[0 ].len, &sock->writes.size, &sock->writes.overlapped);
src/openvpn/socket.h +6 -6
@@ -88,6 +88,7 @@ struct link_socket_actual/*int dummy;*/ /* add offset to force a bug if dest not explicitly dereferenced */ struct openvpn_sockaddr dest; +bool dco_installed; #if ENABLE_IP_PKTINFO union { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
@@ -121,7 +122,6 @@ struct link_socket_infosa_family_t af;/* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/ bool bind_ipv6_only;int mtu_changed;/* Set to true when mtu value is changed */ -bool dco_installed; };/*
@@ -1036,9 +1036,9 @@ 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) +if (sock->info.lsa->actual.dco_installed) { - from->dest = sock->info.lsa->actual.dest; + *from = sock->info.lsa->actual; sh.is_handle = true; }return sockethandle_finalize (sh, &sock->reads, buf, from);
@@ -1059,7 +1059,7 @@ link_socket_read(struct link_socket *sock, struct link_socket_actual *from) {if (proto_is_udp (sock->info.proto) - || sock->info.dco_installed) + || sock->info.lsa->actual.dco_installed)/* unified UDPv4 and UDPv6, for DCO the kernel * will strip the length header */ {
@@ -1102,7 +1102,7 @@ link_socket_write_win32(struct link_socket *sock, {int err =0 ;int status =0 ; -sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.dco_installed }; +sockethandle_t sh = { .s = sock->sd, .is_handle = sock->info.lsa->actual.dco_installed };if (overlapped_io_active (&sock->writes)) { status =sockethandle_finalize (sh, &sock->writes,NULL ,NULL );
@@ -1176,7 +1176,7 @@ link_socket_write(struct link_socket *sock,struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) + if (proto_is_udp(sock->info.proto) || to->dco_installed) { /* unified UDPv4 and UDPv6 and DCO (kernel adds size header) */ return link_socket_write_udp(sock, buf, to);
Signature · 1 line
2.37.1 (Apple Git-137.1)
Taking the ACK from Antonio on v2, adding my stare-at-code for v2->v3 (introduction of addr_set_dco_installed(), callout to it from dco_p2p_add_new_peer() and dco_multi_add_new_peer()).
Tieing "key state" to "remote addr" is not all wrong, as we do not currently properly differentiate "renegotiate" (= same remote IP/Port) and "reconnect" (might be same, most likely different). So this is certainly something that wants to be cleaned up more thoroughly...
Note: there might be a bit of code duplication here (which should not harm, and might go away in one of the next patches anyway) - addr_set...() has:
+ get_link_socket_info(c)->lsa->actual.dco_installed = true;
and both callers do
+ c->c2.link_socket->info.lsa->actual.dco_installed = true;
.. which seems to be the same thing, in different wrapping, no? Or maybe not, as get_link_socket_info() *could* return a pointer to c->c2.link_socket_info instead. WTF?
Test results are much better now, though :-)
- Ubuntu 20.04 + DCO, client (with+without DCO), server with DCO --> all tests pass (* - those that passed before) (this is the one that uncovered the "TCP p2mp breaks" in v2)
- Gentoo, no DCO in kernel, client + server, many client instances --> all tests pass (*)
- FreeBSD 14, DCO in kernel, client + server, server talks to Ubuntu 20.04 client instances with/without DCO --> all tests pass (*)
- tried ("just to be sure") --reneg-sec to a p2mp tcp DCO server as well. Renegotiates perfectly.
Your patch has been applied to the master branch.
commit f7ea7c2b4c0badfb99f75c94171400888715e8ce
Author: Arne Schwabe Date: Thu Nov 24 17:26:42 2022 +0100
Move dco_installed from sock->info to sock->info.lsa.actual
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/search?l=mid&[email protected]...
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v2 2/3 Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
In reply to Arne SchwabeThe lifetime and state machine of multi->peer_id does not exactly the lifetime/state of DCO. This is especially for p2p NCP where a reconnection can change the peer id. Also use this new field with value -1 to mean not installed, replacing the dco_peer_added field.
Patch v2: fix one comparison checking for 0 instead of -1
--- src/openvpn/dco.c | 24 ++++++++++++------------ src/openvpn/forward.c | 2 +- src/openvpn/init.c | 4 ++-- src/openvpn/multi.c | 8 ++++---- src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 9 ++++++++- 6 files changed, 28 insertions(+), 20 deletions(-)
src/openvpn/dco.c +12 -12
@@ -55,7 +55,7 @@ dco_install_key(struct tls_multi *multi, struct key_state *ks, const char *ciphername) { -msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->peer_id, +msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->dco_peer_id, ks->key_id);/* Install a key in the PRIMARY slot only when no other key exist.
@@ -69,7 +69,7 @@ dco_install_key(struct tls_multi *multi, struct key_state *ks, slot =OVPN_KEY_SLOT_SECONDARY ; } -int ret =dco_new_key (multi->dco, multi->peer_id, ks->key_id, slot, +int ret =dco_new_key (multi->dco, multi->dco_peer_id, ks->key_id, slot, encrypt_key, encrypt_iv, decrypt_key, decrypt_iv, ciphername);
@@ -133,7 +133,7 @@ dco_get_secondary_key(struct tls_multi *multi, const struct key_state *primary)void dco_update_keys (dco_context_t *dco,struct tls_multi *multi) { -msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->peer_id); +msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->dco_peer_id);/* this function checks if keys have to be swapped or erased, therefore it * can't do much if we don't have any key installed
@@ -151,14 +151,14 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi) {msg (D_DCO ,"No encryption key found. Purging data channel keys" ); -int ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_PRIMARY ); +int ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_PRIMARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete primary key during wipe: %s (%d)" ,strerror (-ret), ret);return ; } - ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); + ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_SECONDARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete secondary key during wipe: %s (%d)" ,strerror (-ret), ret);
@@ -184,7 +184,7 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)msg (D_DCO_DEBUG ,"Swapping primary and secondary keys, now: id1=%d id2=%d" , primary->key_id, secondary ? secondary->key_id :-1 ); -int ret =dco_swap_keys (dco, multi->peer_id); +int ret =dco_swap_keys (dco, multi->dco_peer_id);if (ret <0 ) {msg (D_DCO ,"Cannot swap keys: %s (%d)" ,strerror (-ret), ret);
@@ -202,7 +202,7 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)/* if we have no secondary key anymore, inform DCO about it */ if (!secondary && multi->dco_keys_installed ==2 ) { -int ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); +int ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_SECONDARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete secondary key: %s (%d)" ,strerror (-ret), ret);
@@ -465,7 +465,7 @@ dco_p2p_add_new_peer(struct context *c)return ret; } - c->c2.tls_multi->dco_peer_added = true; + c->c2.tls_multi->dco_peer_id = multi->peer_id; c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ;
@@ -479,10 +479,10 @@ dco_remove_peer(struct context *c)return ; } -if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) +if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_id ==-1 ) { -dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); - c->c2.tls_multi->dco_peer_added = false; +dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->dco_peer_id); + c->c2.tls_multi->dco_peer_id =-1 ; } }
@@ -585,7 +585,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi)return ret; } - c->c2.tls_multi->dco_peer_added = true; + c->c2.tls_multi->dco_peer_id = peer_id;if (c->mode ==CM_CHILD_TCP ) {
src/openvpn/forward.c +1 -1
@@ -1731,7 +1731,7 @@ process_outgoing_link(struct context *c)if (should_use_dco_socket (c->c2.to_link_addr)) { size =dco_do_write (&c->c1.tuntap->dco, - c->c2.tls_multi->peer_id, + c->c2.tls_multi->dco_peer_id, &c->c2.to_link); }else
src/openvpn/init.c +2 -2
@@ -2151,14 +2151,14 @@ do_deferred_options_part2(struct context *c) && (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->c2.tls_multi->dco_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 parameters for DCO peer (id=%u): %s" , - c->c2.tls_multi->peer_id,strerror (-ret)); + c->c2.tls_multi->dco_peer_id,strerror (-ret));return false; } }
src/openvpn/multi.c +4 -4
@@ -2448,14 +2448,14 @@ multi_client_connect_late_setup(struct multi_context *m,if (mi->context.options.ping_send_timeout || mi->context.c2.frame.mss_fix) {int ret =dco_set_peer (&mi->context.c1.tuntap->dco, - mi->context.c2.tls_multi->peer_id, + mi->context.c2.tls_multi->dco_peer_id, mi->context.options.ping_send_timeout, mi->context.options.ping_rec_timeout, mi->context.c2.frame.mss_fix);if (ret <0 ) {msg (D_DCO ,"Cannot set parameters for DCO peer (id=%u): %s" , - mi->context.c2.tls_multi->peer_id,strerror (-ret)); + mi->context.c2.tls_multi->dco_peer_id,strerror (-ret)); mi->context.c2.tls_multi->multi_state =CAS_FAILED ; } }
@@ -3226,8 +3226,8 @@ process_incoming_del_peer(struct multi_context *m, struct multi_instance *mi, }/* When kernel already deleted the peer, the socket is no longer -* installed and we don't need to cleanup the state in the kernel */ - mi->context.c2.tls_multi->dco_peer_added = false; +* installed, and we do not need to clean up the state in the kernel */ + mi->context.c2.tls_multi->dco_peer_id =-1 ; mi->context.sig->signal_text = reason;multi_signal_instance (m, mi,SIGTERM ); }
src/openvpn/ssl.c +1 -0
@@ -1315,6 +1315,7 @@ tls_multi_init(struct tls_options *tls_options)/* get command line derived options */ ret->opt = *tls_options; + ret->dco_peer_id =-1 ;return ret; }
src/openvpn/ssl_common.h +8 -1
@@ -661,7 +661,14 @@ struct tls_multi/* Only used when DCO is used to remember how many keys we installed * for this session */ int dco_keys_installed; -bool dco_peer_added; +/** +* This is the handle that DCO uses to identify this session with the +* kernel. +* +* We keep this separate as the normal peer_id can change during +* p2p NCP and we need to track the id that is really used. +*/ +int dco_peer_id;dco_context_t *dco; };
Signature · 1 line
2.37.1 (Apple Git-137.1)
Re: [Openvpn-devel] [PATCH v2 2/3] Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
Hi,
Quoted 6 lines · Arne Schwabe
The lifetime and state machine of
multi->peer_iddoes not exactly the lifetime/state of DCO. This is especially for p2p NCP where a reconnection can change the peer id. Also use this new field with value -1 to mean not installed, replacing thedco_peer_addedfield.Patch v2: fix one comparison checking for 0 instead of -1
This looks good, but fails the server test - after the first few client connects it seems to get confused on peer installation, and dies miserably
Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: MULTI: primary virtual IPv6 for freebsd-14-amd64/194.97.140.5:13776: fd00:abcd:220:2::1002 Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: dco_new_peer: netlink reports error (-6): Object exists: No such file or directory (errno=2) Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: dco_new_peer: failed to send netlink message: File exists (-17) Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: Cannot add peer to DCO: File exists (-17) Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: dco_set_peer: netlink reports object not found, ovpn-dco unloaded? Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: dco_set_peer: failed to send netlink message: No such file or directory (-2) Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: Cannot set parameters for DCO peer (id=4294967295): No such file or directory
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
now that id= hints at "something has not been initialized properly" as that is "(unsiged int) -1"
Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: Data Channel: using negotiated cipher 'AES-256-GCM' Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: Data Channel MTU parms [ mss_fix:1380 max_frag:0 tun_mtu:1500 tun_max_mtu:1600 headroom:136 payload:1768 tailroom:562 ET:0 ] Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: dco_new_key: netlink reports object not found, ovpn-dco unloaded? Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: dco_new_key: failed to send netlink message: No such file or directory (-2) Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: Impossible to install key material in DCO: No such file or directory Nov 25 09:51:53 ubuntu2004 tun-udp-p2mp[641000]: Exiting due to fatal error
(This is plain p2mp udp TLS server, with t_client client connecting to it - same client cert, but new connection, new source ip/port - there is a second client connected for client-to-client testing)
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v3 1/3 Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
In reply to Arne SchwabeThe lifetime and state machine of multi->peer_id does not exactly the lifetime/state of DCO. This is especially for p2p NCP where a reconnection can change the peer id. Also use this new field with value -1 to mean not installed, replacing the dco_peer_added field.
Also ensure that we have a failure adding a new peer, we don't try to set options for that peer or generating keys for it.
Patch v2: fix one comparison checking for 0 instead of -1 Patch v3: make recovery after failing dco_add_peer more robust
and the comparison that lead to not deleting a peer.
--- src/openvpn/dco.c | 24 ++++++------ src/openvpn/forward.c | 2 +- src/openvpn/init.c | 4 +- src/openvpn/multi.c | 80 +++++++++++++++++++++++----------------- src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 9 ++++- 6 files changed, 70 insertions(+), 50 deletions(-)
src/openvpn/dco.c +12 -12
@@ -55,7 +55,7 @@ dco_install_key(struct tls_multi *multi, struct key_state *ks, const char *ciphername) { -msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->peer_id, +msg (D_DCO_DEBUG ,"%s: peer_id=%d keyid=%d" , __func__, multi->dco_peer_id, ks->key_id);/* Install a key in the PRIMARY slot only when no other key exist.
@@ -69,7 +69,7 @@ dco_install_key(struct tls_multi *multi, struct key_state *ks, slot =OVPN_KEY_SLOT_SECONDARY ; } -int ret =dco_new_key (multi->dco, multi->peer_id, ks->key_id, slot, +int ret =dco_new_key (multi->dco, multi->dco_peer_id, ks->key_id, slot, encrypt_key, encrypt_iv, decrypt_key, decrypt_iv, ciphername);
@@ -133,7 +133,7 @@ dco_get_secondary_key(struct tls_multi *multi, const struct key_state *primary)void dco_update_keys (dco_context_t *dco,struct tls_multi *multi) { -msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->peer_id); +msg (D_DCO_DEBUG ,"%s: peer_id=%d" , __func__, multi->dco_peer_id);/* this function checks if keys have to be swapped or erased, therefore it * can't do much if we don't have any key installed
@@ -151,14 +151,14 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi) {msg (D_DCO ,"No encryption key found. Purging data channel keys" ); -int ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_PRIMARY ); +int ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_PRIMARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete primary key during wipe: %s (%d)" ,strerror (-ret), ret);return ; } - ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); + ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_SECONDARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete secondary key during wipe: %s (%d)" ,strerror (-ret), ret);
@@ -184,7 +184,7 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)msg (D_DCO_DEBUG ,"Swapping primary and secondary keys, now: id1=%d id2=%d" , primary->key_id, secondary ? secondary->key_id :-1 ); -int ret =dco_swap_keys (dco, multi->peer_id); +int ret =dco_swap_keys (dco, multi->dco_peer_id);if (ret <0 ) {msg (D_DCO ,"Cannot swap keys: %s (%d)" ,strerror (-ret), ret);
@@ -202,7 +202,7 @@ dco_update_keys(dco_context_t *dco, struct tls_multi *multi)/* if we have no secondary key anymore, inform DCO about it */ if (!secondary && multi->dco_keys_installed ==2 ) { -int ret =dco_del_key (dco, multi->peer_id,OVPN_KEY_SLOT_SECONDARY ); +int ret =dco_del_key (dco, multi->dco_peer_id,OVPN_KEY_SLOT_SECONDARY );if (ret <0 ) {msg (D_DCO ,"Cannot delete secondary key: %s (%d)" ,strerror (-ret), ret);
@@ -465,7 +465,7 @@ dco_p2p_add_new_peer(struct context *c)return ret; } - c->c2.tls_multi->dco_peer_added = true; + c->c2.tls_multi->dco_peer_id = multi->peer_id; c->c2.link_socket->info.lsa->actual.dco_installed = true;return 0 ;
@@ -479,10 +479,10 @@ dco_remove_peer(struct context *c)return ; } -if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_added) +if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_id !=-1 ) { -dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->peer_id); - c->c2.tls_multi->dco_peer_added = false; +dco_del_peer (&c->c1.tuntap->dco, c->c2.tls_multi->dco_peer_id); + c->c2.tls_multi->dco_peer_id =-1 ; } }
@@ -585,7 +585,7 @@ dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi)return ret; } - c->c2.tls_multi->dco_peer_added = true; + c->c2.tls_multi->dco_peer_id = peer_id;if (c->mode ==CM_CHILD_TCP ) {
src/openvpn/forward.c +1 -1
@@ -1734,7 +1734,7 @@ process_outgoing_link(struct context *c)if (should_use_dco_socket (c->c2.to_link_addr)) { size =dco_do_write (&c->c1.tuntap->dco, - c->c2.tls_multi->peer_id, + c->c2.tls_multi->dco_peer_id, &c->c2.to_link); }else
src/openvpn/init.c +2 -2
@@ -2151,14 +2151,14 @@ do_deferred_options_part2(struct context *c) && (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->c2.tls_multi->dco_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 parameters for DCO peer (id=%u): %s" , - c->c2.tls_multi->peer_id,strerror (-ret)); + c->c2.tls_multi->dco_peer_id,strerror (-ret));return false; } }
src/openvpn/multi.c +46 -34
106 lines not on this page · raw message
src/openvpn/ssl.c +1 -0
@@ -1315,6 +1315,7 @@ tls_multi_init(struct tls_options *tls_options)/* get command line derived options */ ret->opt = *tls_options; + ret->dco_peer_id =-1 ;return ret; }
src/openvpn/ssl_common.h +8 -1
@@ -661,7 +661,14 @@ struct tls_multi/* Only used when DCO is used to remember how many keys we installed * for this session */ int dco_keys_installed; -bool dco_peer_added; +/** +* This is the handle that DCO uses to identify this session with the +* kernel. +* +* We keep this separate as the normal peer_id can change during +* p2p NCP and we need to track the id that is really used. +*/ +int dco_peer_id;dco_context_t *dco; };
Signature · 1 line
2.37.1 (Apple Git-137.1)
[Openvpn-devel] [PATCH applied] Re: Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
This patch survived all tests I threw at it (Linux and FreeBSD client and server, with and without DCO, including multiple p2mp clients on the server under test).
The "main" code change (dco_peer_id) is fairly straightforward, if one checks for the right values of "-1".
The completely new bit in v3 is "multi_client_setup_dco_initial()", which packs all the "init a new p2mp DCO peer" into a single function, so early-return is possible, and the path "anything DCO fails -> CAS_FAILED -> AUTH_FAILED" is easier to see.
We discussed - at breakfast - changes necessary to make the server not abort "if anything DCO fails" (v2 tried to setup a peer with "-1", which failed, and that did not lead to "CAS_FAILED" but to "server aborts"). The code in question is in ssl.c, init_key_contexts(), and it has two M_FATAL conditions - we should see that we can turn this into "kill the client instance, not the server". As discussed, "not being able to set up keys in DCO" is a race with "the kernel might have killed that instance just now, due to TCP RST etc".
This is not part of *this* patch yet, but it's not caused by this patch either - so no reason to not progress.
Your patch has been applied to the master branch.
commit 8d4dbb56e7dda87ef031fdf52c6d87e533250ff3
Author: Arne Schwabe Date: Sun Nov 27 10:07:42 2022 +0100
Use dedicated multi->dco_peer_id for DCO instead of multi->peer_id
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/search?l=mid&[email protected]...
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH 3/3] Call dco_p2p_add_new_peer again if the peer id changes
In reply to Arne SchwabeHi,
Quoted 2 lines · Arne Schwabe
This allows a reconnect in p2p mode and has the side effect of updating the peer address with the peerid
Maybe I am just holding it wrong, but the patch does not change the situation for my p2p reconnection problem.
First connect works fine (tls p2p, UDP, one side --tls-client, one side --tls-server).
Second connect, server says
Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: TLS: new session incoming connection from [AF_INET6]::ffff:194.97.140.5:13846 Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: VERIFY OK: depth=1, C=US, ST=California, L=Pleasanton, O=OpenVPN community project, CN=OpenVPN community project CA, [email protected]... Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: VERIFY OK: depth=0, C=DE, ST=Bavaria, L=Munich, O=OpenVPN community project, OU=DCO F14 client, CN=freebsd-14-amd64, [email protected]... Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: peer info: IV_CIPHERS=AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305 Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: peer info: IV_PROTO=42 Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: WARNING: 'link-mtu' is used inconsistently, local='link-mtu 1553', remote='link-mtu 1541' Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: WARNING: 'auth' is used inconsistently, local='auth SHA256', remote='auth SHA1' Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: P2P mode NCP negotiation result: TLS_export=1, DATA_v2=1, peer-id 4549764, cipher=AES-256-GCM Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: TLS: move_session: dest=TM_ACTIVE src=TM_UNTRUSTED reinit_src=1 Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: TLS: tls_multi_process: untrusted session promoted to trusted Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: No encryption key found. Purging data channel keys Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 2048 bit RSA, signature: RSA-SHA256 Nov 28 14:23:10 ubuntu2004 tun-udp-p2p-tls-sha256[770748]: [freebsd-14-amd64] Peer Connection Initiated with [AF_INET6]::ffff:194.97.140.5:13846
... and then, nothing more from openvpn, and the kernel starts logging...
Nov 28 14:23:11 ubuntu2004 kernel: [22040621.308786] ovpn_udp_encap_recv: received data from unknown peer (id: 4549764) Nov 28 14:23:12 ubuntu2004 kernel: [22040622.140640] ovpn_udp_encap_recv: received data from unknown peer (id: 4549764) Nov 28 14:23:12 ubuntu2004 kernel: [22040622.212277] ovpn_udp_encap_recv: received data from unknown peer (id: 4549764)
The recent patches *have* improved the situation noticeably, because without them, the client would end up in a timeout (because UDP reply packets would go to "the old address+port of the client") - so now changing IPv4 <-> IPv6 between connection attempts works fine. Just "installation in kernel" doesn't.
I am slightly confused about the concept of peer-id here, though - so we do P2P NCP, and the peer-id is EKM'ed. Will that result in the *same* peer-id on both sides? Or in a pseudorandom number that differs per side (in which case "tell the kernel" might end up with a different number)?
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH 3/3] Call dco_p2p_add_new_peer again if the peer id changes
Hi,
Quoted 6 lines · Gert Doering
Quoted 2 lines · Arne Schwabe
This allows a reconnect in p2p mode and has the side effect of updating the peer address with the peerid
Maybe I am just holding it wrong, but the patch does not change the situation for my p2p reconnection problem.
I was holding this wrong... applied to my tree, ran server tests, but forgot to "push to the repo that the server tests use".
So, without the patch, the problem is easily reproduceable as written below :-)
Now testing the actual patch.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH 3/3] Call dco_p2p_add_new_peer again if the peer id changes
Hi,
Quoted 1 line · Gert Doering
Now testing the actual patch.
Doesn't work...
without 3/3, I have the
ubuntu2004 kernel: [22034799.495703] ovpn_udp_encap_recv: received data from unknown peer (id: 1114473)
on reconnect, but at least TLS handshake succeeds.
*With* 3/3, I am back to "after half the handshake, UDP packets are sent to the *old* peer IP+port"
2022-11-28 16:51:27 us=427942 Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 2048 bit RSA, signature: RSA-SHA256 2022-11-28 16:54:06 us=24986 TLS: new session incoming connection from [AF_INET6]::ffff:194.97.140.5:43940 2022-11-28 16:54:06 us=26336 read UDPv6 [ECONNREFUSED]: Connection refused (fd=4,code=111) 2022-11-28 16:54:08 us=115117 read UDPv6 [ECONNREFUSED]: Connection refused (fd=4,code=111) 2022-11-28 16:54:08 us=379075 read UDPv6 [ECONNREFUSED]: Connection refused (fd=4,code=111)
and in tcpdump...
client -> server
16:54:37.726666 IP 194.97.140.5.43940 > 195.30.8.84.51201: UDP, length 14
server -> client
16:54:37.728030 IP6 2001:608:1:995a:250:56ff:febb:2084.51201 > 2001:608:0:814::fb00:14.14151: UDP, length 22
16:54:37.728081 IP6 2001:608:0:814::fb00:14 > 2001:608:1:995a:250:56ff:febb:2084: ICMP6, destination unreachable, unreachable port, 2001:608:0:814::fb00:14 udp port 14151, length 78
meh.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Hi,
Quoted 12 lines · Lev Stipakov
src/openvpn/socket.h link_socket_write(struct link_socket *sock, · line 1194
Quoted 7 lines
src/openvpn/socket.h +1
-1@@ -1190,7 +1190,7 @@ link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to) { - if (proto_is_udp(sock->info.proto) || sock->info.dco_installed) + if (proto_is_udp(sock->info.proto) || to->dco_installed) {Previously we used to check the dco flag from
sock->infoand now it is changed to "to", which is a separate member inc->c2(c->c2.to_link_addrvsc->c2.link_socket).
Quoted 4 lines
Why not use "
sock->info.lsa->actual.dco_installed" ? My understanding is that this patch
only moves the flag to a different place and is not supposed to change the behavior.
For the sake of the archives: I asked Arne today, and the reply was "this is not pretty, but with Antonio's upcoming changes to DCO, it's likely that the dco_installed field goes away, or is reworked significantly".
So for now, we leave it as it is, knowing it's working but not perfect.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...