Move restoring pre pull options to initialising of c2 context
PATCH v2 1/3 Move restoring pre pull options to initialising of c2 context
We currently delay restoring these options until we actually must restore them. Since there is no reason to do so apart from the very minor saving to not have to execute that code when a connection fails, move them it into the general context_2 initialisation.
Patch V2: rebase on master.
--- src/openvpn/init.c | 5 +++++ src/openvpn/openvpn.h | 1 - src/openvpn/push.c | 5 ----- 3 files changed, 5 insertions(+), 6 deletions(-)
src/openvpn/init.c +5 -0
@@ -4165,6 +4165,11 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f } } +if (c->options.pull) + { +pre_pull_restore (&c->options, &c->c2.gc); + } +/* map in current connection entry */ next_connection_entry (c);
src/openvpn/openvpn.h +0 -1
@@ -463,7 +463,6 @@ struct context_2struct event_timeout push_request_interval;time_t push_request_timeout; -bool did_pre_pull_restore;/* hash of pulled options, so we can compare when options change */ bool pulled_options_digest_init_done;
src/openvpn/push.c +0 -5
@@ -929,11 +929,6 @@ process_incoming_push_reply(struct context *c,md_ctx_init (c->c2.pulled_options_state,md_kt_get ("SHA256" )); c->c2.pulled_options_digest_init_done = true; } -if (!c->c2.did_pre_pull_restore) - { -pre_pull_restore (&c->options, &c->c2.gc); - c->c2.did_pre_pull_restore = true; - } if (apply_push_options(&c->options, buf, permission_mask,
Signature · 1 line
2.30.1
PATCH v2 2/3 Move NCP saving and restore to the prepush restore code
This unifies save/restoring options that might be changed by a push from the server. It also removes using the context_1 to store something that is not related to a SIGHUP lifetime.
Patch v2: rebase on master.
--- src/openvpn/init.c | 36 +++++------------------------------- src/openvpn/openvpn.h | 4 ---- src/openvpn/options.c | 11 +++++++++++ src/openvpn/options.h | 4 ++++ 4 files changed, 20 insertions(+), 35 deletions(-)
src/openvpn/init.c +5 -31
@@ -668,28 +668,6 @@ uninit_proxy(struct context *c)uninit_proxy_dowork (c); } -/* -* Saves the initial state of NCP-regotiable -* options into a storage which persists over SIGUSR1. -*/ -static void -save_ncp_options (struct context *c) -{ - c->c1.ciphername = c->options.ciphername; - c->c1.authname = c->options.authname; - c->c1.keysize = c->options.keysize; -} - -/* Restores NCP-negotiable options to original values */ -static void -restore_ncp_options (struct context *c) -{ - c->options.ciphername = c->c1.ciphername; - c->options.authname = c->c1.authname; - c->options.keysize = c->c1.keysize; - c->options.data_channel_use_ekm = false; -} -void context_init_1 (struct context *c) {
@@ -699,8 +677,6 @@ context_init_1(struct context *c)init_connection_list (c); -save_ncp_options (c); -#if defined(ENABLE_PKCS11 )if (c->first_time) {
@@ -2868,8 +2844,8 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.replay_window = options->replay_window; to.replay_time = options->replay_time; to.tcp_mode =link_socket_proto_connection_oriented (options->ce.proto); - to.config_ciphername = c->c1.ciphername; - to.config_ncp_ciphers = options->ncp_ciphers; + to.config_ciphername = c->options.ciphername; + to.config_ncp_ciphers = c->options.ncp_ciphers; to.ncp_enabled = options->ncp_enabled; to.transition_window = options->transition_window; to.handshake_window = options->handshake_window;
@@ -4465,8 +4441,6 @@ close_instance(struct context *c)/* free key schedules */ do_close_free_key_schedule (c, (c->mode ==CM_P2P || c->mode ==CM_TOP )); -restore_ncp_options (c); -/* close TCP/UDP connection */ do_close_link_socket (c);
@@ -4537,9 +4511,9 @@ inherit_context_child(struct context *dest, dest->c1.ks.tls_auth_key_type = src->c1.ks.tls_auth_key_type; dest->c1.ks.tls_crypt_v2_server_key = src->c1.ks.tls_crypt_v2_server_key;/* inherit pre-NCP ciphers */ - dest->c1.ciphername = src->c1.ciphername; - dest->c1.authname = src->c1.authname; - dest->c1.keysize = src->c1.keysize; + dest->options.ciphername = src->options.ciphername; + dest->options.authname = src->options.authname; + dest->options.keysize = src->options.keysize;/* inherit auth-token */ dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
src/openvpn/openvpn.h +0 -4
@@ -203,10 +203,6 @@ struct context_1struct user_pass *auth_user_pass;/**< Username and password for * authentication. */ - -const char *ciphername;/**< Data channel cipher from config file */ -const char *authname;/**< Data channel auth from config file */ -int keysize;/**< Data channel keysize from config file */ #endif };
src/openvpn/options.c +11 -0
@@ -3535,7 +3535,13 @@ pre_pull_save(struct options *o) o->pre_pull->client_nat =clone_client_nat_option_list (o->client_nat, &o->gc); o->pre_pull->client_nat_defined = true; } + +/* NCP related options that can be overwritten by a push */ + o->pre_pull->ciphername = o->ciphername; + o->pre_pull->authname = o->authname; + o->pre_pull->keysize = o->keysize; } + }void
@@ -3581,10 +3587,15 @@ pre_pull_restore(struct options *o, struct gc_arena *gc) } o->foreign_option_index = pp->foreign_option_index; + + o->ciphername = pp->ciphername; + o->authname = pp->authname; + o->keysize = pp->keysize; } o->push_continuation =0 ; o->push_option_types_found =0 ; + o->data_channel_use_ekm = false; }#endif /* if P2MP */
src/openvpn/options.h +4 -0
@@ -75,6 +75,10 @@ struct options_pre_pullbool client_nat_defined;struct client_nat_option_list *client_nat; +const char * ciphername; +const char * authname; +int keysize; +int foreign_option_index; };
Signature · 1 line
2.30.1
PATCH v2 3/3 Restore also ping related options on a reconnect
In reply to Arne SchwabeThis fixes the issue that if a client reconnects the next connection entries inherits the keepalive settings that were pushed or set by the previous entry. Since UDP+PULL entries have an implicit 120s timeout, this timeout also got applied to a TCP session after an UDP entry.
Patch v2: rebase on master
--- src/openvpn/options.c | 9 +++++++++ src/openvpn/options.h | 4 ++++ 2 files changed, 13 insertions(+)
src/openvpn/options.c +9 -0
@@ -3540,6 +3540,11 @@ pre_pull_save(struct options *o) o->pre_pull->ciphername = o->ciphername; o->pre_pull->authname = o->authname; o->pre_pull->keysize = o->keysize; + +/* Ping related options should be reset to the config values on reconnect */ + o->pre_pull->ping_rec_timeout = o->ping_rec_timeout; + o->pre_pull->ping_rec_timeout_action = o->ping_rec_timeout_action; + o->pre_pull->ping_send_timeout = o->ping_send_timeout; } }
@@ -3591,6 +3596,10 @@ pre_pull_restore(struct options *o, struct gc_arena *gc) o->ciphername = pp->ciphername; o->authname = pp->authname; o->keysize = pp->keysize; + + o->ping_rec_timeout = pp->ping_rec_timeout; + o->ping_rec_timeout_action = pp->ping_rec_timeout_action; + o->ping_send_timeout = pp->ping_send_timeout; } o->push_continuation =0 ;
src/openvpn/options.h +4 -0
@@ -79,6 +79,10 @@ struct options_pre_pullconst char * authname;int keysize; +int ping_send_timeout; +int ping_rec_timeout; +int ping_rec_timeout_action; +int foreign_option_index; };
Signature · 1 line
2.30.1
Hi all,
Quoted 8 lines · Arne Schwabe
We currently delay restoring these options until we actually must restore them. Since there is no reason to do so apart from the very minor saving to not have to execute that code when a connection fails, move them it into the general
context_2initialisation.Patch V2: rebase on master.
Signed-off-by Arne Schwabe <[email protected]...>
This patch is simply about moving when the pre-pull settings have to be restored. Aims at simplifying the code and make it easier to follow (thanks to the patches that will come later).
This patch was reviewed with the Arne's guidance.
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v2 2/3] Move NCP saving and restore to the prepush restore code
In reply to Arne SchwabeHi all,
Quoted 7 lines · Arne Schwabe
This unifies save/restoring options that might be changed by a push from the server. It also removes using the
context_1to store something that is not related to a SIGHUP lifetime.Patch v2: rebase on master.
Signed-off-by Arne Schwabe <[email protected]...>
As a follow pu of patch 1/3, this patch moves the init and reset of ncp settings to a common function for easier reading.
Moving the attributes out of c1 as it does not make much sense.
This patch was reviewed with the Arne's guidance.
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v2 3/3] Restore also ping related options on a reconnect
In reply to Arne SchwabeHi all,
Quoted 10 lines · Arne Schwabe
This fixes the issue that if a client reconnects the next connection entries inherits the keepalive settings that were pushed or set by the previous entry. Since UDP+PULL entries have an implicit 120s timeout, this timeout also got applied to a TCP session after an UDP entry.
Patch v2: rebase on master
Reported-By Jan Just Keijser <[email protected]...>Signed-off-by Arne Schwabe <[email protected]...>
This patch is actually fixing a bug, as reported by JJK, however it is such a coerner case that we may not want to backport this to 2.4 (backporting requires rewriting the patch).
This patch was reviewed with the Arne's guidance.
Signature · 1 line
Antonio Quartulli
Your patch has been applied to the master branch.
I do not really have a test rig to test this, currently. I think it would need a long-running client instance that connects to a server, receives a set of options, disconnects (server kicking it out?), reconnects, and receives *different* options. Or possibly "not receives options that were set before", so verify "fall back to default/config file settings".
OTOH staring at the code looks reasonable - we only restore if something was saved before (o->pre_pull initialized) and if we succeed connecting, it's the same amount of energy spent.
I have run this through the enhanced client side tests (including the "must fail!") tests, but since these all only do single-shot connections, this is not really excercising the code change.
I do wonder if connection *failures* would cause an increased memory consumption now... is "&c->c2.gc" cleared eventually? (Because we allocate new copies of route-lists in that GC)... *looking*... ah, yes, c2.gc lives only for "one instance" (init_instance() to close_instance()), and since that one talks about "advance connection entry", it looks like "this dance is done per connection attempt"...
commit 528a78fb144ff6a3d5865c871a402ba98fdfe21e
Author: Arne Schwabe Date: Wed Mar 17 17:00:36 2021 +0100
Move restoring pre pull options to initialising of c2 context
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21676.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Move NCP saving and restore to the prepush restore code
In reply to Arne SchwabeYour patch has been applied to the master branch.
As discussed with Antonion on IRC, we have no real testbed to test this code change ("connect to server A that pushes options, disconnect, then connect to server B that *does not* push anything"). I did some manual tests with
- a client config that has multiple <connection> entries, to servers that push different cipher settings or have OCC or nothing.
- using the client management interface and SIGHUP/SIGUSR1, remote SKIP, remote ACCEPT to "walk to the next server"
- talk to a NCP enabled server, which pushes "cipher AES-256-GCM"
- then talk to a 2.3 server with --enable-small, which does not understand NCP or OCC -> client falls back to o->ciphername (by means of data-cipher-fallback), using "cipher BF-CBC", *if properly restored*
- using SIGUSR1, things actually break (server A pushes "compress lz4", server B does not do that, but the client still is in "LZ4 mode", logs "Bad LZ4 decompression header byte: 250"). But this is an older issue (my test candidate is f6dca235ae560597, which is before this patch set) - and Arne already found that this is is because we neglect to *save* compression settings in options_pre_pull...
- using SIGHUP, things work
In addition to this, the patch survived a very close stare-at-code and extensive t_client runs :-)
commit 7064ccb9fd3578c0b25713b1c8e620ad9449f7f4
Author: Arne Schwabe Date: Wed Mar 17 17:00:37 2021 +0100
Move NCP saving and restore to the prepush restore code
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21674.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Restore also ping related options on a reconnect
In reply to Arne SchwabeThe patch is visually fine, and I was actually successfull in testing pre/post behaviour. As in: client with multiple <connection> blocks, and using the management interface to make it connect to server A ("push ping, ping-restart") first, then server B ("do not push anything ping-related"). Without the patch, the client would die with --ping-restart timeout, with the patch it happily does "no ping restart".
It needs SIGUSR1 restarts to trigger the issue. SIGHUP restarts do a "full config reload" and never display "lingering pushed config" problems.
Testing has uncovered more save & restore bugs, related to compression and "--route-gateway". At least...
Your patch has been applied to the master and release/2.5 branch (bugfix), but I'm not sure I want to really backport it to 2.4 - it's not a crucial crashbug, not easy to trigger, and if you're annoyed by it, just upgrade.
I have not tested the 2.5 backport in full depth, just a basic t_client run (but the change is straightforward enough, and it applied without much friction).
commit 5a2ed714d14acb2312d27fe40e300be96d970c27 (master) commit a0e844c892d6f67977bf8e9162cbc43a3f64ba46 (release/2.5)
Author: Arne Schwabe Date: Wed Mar 17 17:00:38 2021 +0100
Restore also ping related options on a reconnect
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21675.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Restore also ping related options on a reconnect
In reply to Arne SchwabeThe patch is visually fine, and I was actually successfull in testing pre/post behaviour. As in: client with multiple <connection> blocks, and using the management interface to make it connect to server A ("push ping, ping-restart") first, then server B ("do not push anything ping-related"). Without the patch, the client would die with --ping-restart timeout, with the patch it happily does "no ping restart".
It needs SIGUSR1 restarts to trigger the issue. SIGHUP restarts do a "full config reload" and never display "lingering pushed config" problems.
Testing has uncovered more save & restore bugs, related to compression and "--route-gateway". At least...
Your patch has been applied to the master and release/2.5 branch (bugfix), but I'm not sure I want to really backport it to 2.4 - it's not a crucial crashbug, not easy to trigger, and if you're annoyed by it, just upgrade.
I have not tested the 2.5 backport in full depth, just a basic t_client run (but the change is straightforward enough, and it applied without much friction).
commit 5a2ed714d14acb2312d27fe40e300be96d970c27 (master) commit a0e844c892d6f67977bf8e9162cbc43a3f64ba46 (release/2.5)
Author: Arne Schwabe Date: Wed Mar 17 17:00:38 2021 +0100
Restore also ping related options on a reconnect
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21675.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering