Skip to contentSkip to conversation

Simplify calling logic of check_connection_established_dowork

PATCH In review Arne Schwabe 3 participants 5 messages Jul 25, 2020 – Jul 26, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Simplify calling logic of check_connection_established_dowork

The check event_timeout_defined in check_connection_established is completely redundant as event_timeout_trigger will do the very same check as first action. Removing this check makes the function superfluous. To further improve the code move the call check if the time is expired into process_coarse_timers

---
 src/openvpn/forward.c | 77 +++++++++++++++++++------------------------
 src/openvpn/forward.h |  2 +-
 2 files changed, 34 insertions(+), 45 deletions(-)
src/openvpn/forward.c +33 -44
index 3d462d0a..30a3fd46 100644
@@ -138,21 +138,6 @@ check_incoming_control_channel(struct context *c)
 #endif
 }
 
-/*
- * Options like --up-delay need to be triggered by this function which
- * checks for connection establishment.
- */
-static inline void
-check_connection_established(struct context *c)
-{
-    void check_connection_established_dowork(struct context *c);
-
-    if (event_timeout_defined(&c->c2.wait_for_connect))
-    {
-        check_connection_established_dowork(c);
-    }
-}
-
 /*
  * Should we add routes?
  */
@@ -437,43 +422,45 @@ check_push_request_dowork(struct context *c)
 
 /*
  * Things that need to happen immediately after connection initiation should go here.
+ *
+ * Options like --up-delay need to be triggered by this function which
+ * checks for connection establishment.
  */
 void
-check_connection_established_dowork(struct context *c)
+check_connection_established(struct context *c)
 {
-    if (event_timeout_trigger(&c->c2.wait_for_connect, &c->c2.timeval, ETT_DEFAULT))
+
+    if (CONNECTION_ESTABLISHED(c))
     {
-        if (CONNECTION_ESTABLISHED(c))
-        {
 #if P2MP
-            /* if --pull was specified, send a push request to server */
-            if (c->c2.tls_multi && c->options.pull)
-            {
+        /* if --pull was specified, send a push request to server */
+        if (c->c2.tls_multi && c->options.pull)
+        {
 #ifdef ENABLE_MANAGEMENT
-                if (management)
-                {
-                    management_set_state(management,
-                                         OPENVPN_STATE_GET_CONFIG,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         NULL);
-                }
-#endif
-                /* fire up push request right away (already 1s delayed) */
-                event_timeout_init(&c->c2.push_request_interval, 0, now);
-                reset_coarse_timers(c);
-            }
-            else
-#endif /* if P2MP */
+            if (management)
             {
-                do_up(c, false, 0);
+                management_set_state(management,
+                                     OPENVPN_STATE_GET_CONFIG,
+                                     NULL,
+                                     NULL,
+                                     NULL,
+                                     NULL,
+                                     NULL);
             }
-
-            event_timeout_clear(&c->c2.wait_for_connect);
+#endif
+            /* fire up push request right away (already 1s delayed) */
+            event_timeout_init(&c->c2.push_request_interval, 0, now);
+            reset_coarse_timers(c);
         }
+        else
+#endif /* if P2MP */
+        {
+            do_up(c, false, 0);
+        }
+
+        event_timeout_clear(&c->c2.wait_for_connect);
     }
+
 }
 
 bool
@@ -777,8 +764,10 @@ process_coarse_timers(struct context *c)
     check_status_file(c);
 
     /* process connection establishment items */
-    check_connection_established(c);
-
+    if (event_timeout_trigger(&c->c2.wait_for_connect, &c->c2.timeval, ETT_DEFAULT))
+    {
+        check_connection_established(c);
+    }
 #if P2MP
     /* see if we should send a push_request in response to --pull */
     check_push_request(c);
src/openvpn/forward.h +1 -1
index ff898133..635e84ae 100644
@@ -88,7 +88,7 @@ void check_fragment_dowork(struct context *c);
 
 #endif /* ENABLE_FRAGMENT */
 
-void check_connection_established_dowork(struct context *c);
+void check_connection_established(struct context *c);
 
 void check_add_routes_dowork(struct context *c);
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/2 Avoid sending push request after receving push reply

The introduction of IV_PROTO_REQUEST_PUSH (c290df55) sometimes causes the server to reply before we setup the push timer. The push reply will then clear a timer that has not been setup yet. We then start sending push request after we have gone through the whole initialisation already.

This patch also clears the connestion_established timer that sets up the push request timer. This lead to the

management_set_state(management, OPENVPN_STATE_GET_CONFIG, ...)

function not being called. But a to display "waiting for configuration..." or sending a "getting config state" after "initialisation" does not make sense anyway.

Also add the IV_PROTO_REQUEST_PUSH feature as new feature in Changes.rst

---
 Changes.rst           | 11 +++++++++++
 src/openvpn/forward.c |  3 +++
 src/openvpn/push.c    |  1 +
 3 files changed, 15 insertions(+)
Changes.rst +11 -0
index 8fbaf419..e377a36c 100644
@@ -37,6 +37,13 @@ Deferred client-connect
     asynchronous/deferred return of the configuration file in the same way
     as the auth-plugin.
 
+Faster connection setup
+    A client will signal in the ``IV_PROTO`` variable that is in pull
+    mode. This allows the server to push the configuration options to
+    the client without waiting for a ``PULL_REQUEST`` message. The feature
+    is automatically enabled if both client and server support it and
+    reduces the of connection setup time by one round-trip time.
+
 Deprecated features
 -------------------
 For an up-to-date list of all deprecated options, see this wiki page:
@@ -72,6 +79,10 @@ User-visible Changes
 - Support for building with OpenSSL 1.0.1 has been removed. The minimum
   supported OpenSSL version is now 1.0.2.
 
+- The GET_CONFIG management state is ommited if the server pushes
+  the client configuration almost immediately as result of the
+  faster connection setup feature.
+
 
 Overview of changes in 2.4
 ==========================
src/openvpn/forward.c +3 -0
index 30a3fd46..759fdbe1 100644
@@ -425,6 +425,9 @@ check_push_request_dowork(struct context *c)
  *
  * Options like --up-delay need to be triggered by this function which
  * checks for connection establishment.
+ *
+ * Note: The process_incoming_push_reply currently assumes that this function
+ * only sets ups the pull request timer when pull is enabled.
  */
 void
 check_connection_established(struct context *c)
src/openvpn/push.c +1 -0
index 84193afe..9c720b42 100644
@@ -358,6 +358,7 @@ incoming_push_message(struct context *c, const struct buffer *buffer)
             }
         }
         event_timeout_clear(&c->c2.push_request_interval);
+        event_timeout_clear(&c->c2.wait_for_connect);
     }
 
     goto cleanup;
Signature · 1 line
2.26.2
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/2] Avoid sending push request after receving push reply

a little help..

Quoted 11 lines · Arne Schwabe

The introduction of IV_PROTO_REQUEST_PUSH (c290df55) sometimes causes the server to reply before we setup the push timer. The push reply will then clear a timer that has not been setup yet. We then start sending push request after we have gone through the whole initialisation already.

This patch also clears the connestion_established timer that sets up the push request timer. This lead to the

management_set_state(management, OPENVPN_STATE_GET_CONFIG, ...)

function not being called. But a to display "waiting for configuration..." or

I think this was meant to read as (moved 'a'):

But to display a "waiting for configuration..."

Quoted 17 lines

sending a "getting config state" after "initialisation" does not make sense anyway.

Also add the IV_PROTO_REQUEST_PUSH feature as new feature in Changes.rst

---
  Changes.rst           | 11 +++++++++++
  src/openvpn/forward.c |  3 +++
  src/openvpn/push.c    |  1 +
  3 files changed, 15 insertions(+)
Changes.rst +0 -0
index 8fbaf419..e377a36c 100644

Changes.rst Deferred client-connect · line 41

Quoted 5 lines
Changes.rst +2 -0
@@ -37,6 +37,13 @@ Deferred client-connect
      asynchronous/deferred return of the configuration file in the same way
      as the auth-plugin.
 
+Faster connection setup
+    A client will signal in the ``IV_PROTO`` variable that is in pull

I think this is meant to read:
variable that is in pull ->
variable that it is in pull

Changes.rst User-visible Changes · line 82

Quoted 13 lines
Changes.rst +6 -0
+    mode. This allows the server to push the configuration options to
+    the client without waiting for a ``PULL_REQUEST`` message. The feature
+    is automatically enabled if both client and server support it and
+    reduces the of connection setup time by one round-trip time.
+
  Deprecated features
  -------------------
  For an up-to-date list of all deprecated options, see this wiki page:
@@ -72,6 +79,10 @@ User-visible Changes
  - Support for building with OpenSSL 1.0.1 has been removed. The minimum
    supported OpenSSL version is now 1.0.2.
 
+- The GET_CONFIG management state is ommited if the server pushes

ommited -> ommitted

Quoted 11 lines
Changes.rst +3 -0
+  the client configuration almost immediately as result of the
+  faster connection setup feature.
+
 
  Overview of changes in 2.4
  ==========================
src/openvpn/forward.c +0 -0
index 30a3fd46..759fdbe1 100644

src/openvpn/forward.c check_push_request_dowork(struct context *c) · line 430

Quoted 6 lines
src/openvpn/forward.c +3 -0
@@ -425,6 +425,9 @@ check_push_request_dowork(struct context *c)
   *
   * Options like --up-delay need to be triggered by this function which
   * checks for connection establishment.
+ *
+ * Note: The process_incoming_push_reply currently assumes that this function
+ * only sets ups the pull request timer when pull is enabled.

ups -> up

Quoted 16 lines
src/openvpn/forward.c +0 -0
   */
  void
  check_connection_established(struct context *c)
src/openvpn/push.c +1 -0
index 84193afe..9c720b42 100644
@@ -358,6 +358,7 @@ incoming_push_message(struct context *c, const struct buffer *buffer)
              }
          }
          event_timeout_clear(&c->c2.push_request_interval);
+        event_timeout_clear(&c->c2.wait_for_connect);
      }
 
      goto cleanup;
Acked-by on v1 1/2
#4 lore raw
In reply to Arne Schwabe

The change to "check_connection_established(c)" is really trivial and straight-forward, and best viewed with "git show -w". Taking away an effective no-op wrapper function and getting rid of one indentation level is always good.

Nevertheless I've forced this through the full client/server tests, and it succeeded nicely :-)

Your patch has been applied to the master branch.

commit 7cadbe24b6e5b583b4e763cd7a3b30d540b1c7a0

Author: Arne Schwabe
Date:   Sun Jul 26 01:48:02 2020 +0200
     Simplify calling logic of check_connection_established_dowork

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg20588.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 2/2
#3 lore raw

[Openvpn-devel] [PATCH applied] Re: Avoid sending push request after receving push reply

In reply to Arne Schwabe

This is magic :-) - it's just a one liner (plus lots of documentation) but the description makes sense, staring at the code for a while also makes sense. Plus, it works :-)

I have not tested the server side, as (to my understanding) this is basically "client side only" code. I *have* tested p2p with --tls-client (now! part of my t_client rig :-) ) and that still works - relevant, as the code flows along the "established? send pull?" path here.

The new code also works correctly with pre-fast-pull servers (the "reference server" is - because I'm lazy - still running an older version).

I have merged the typo fixes from Richard as well (note: ommitted has only one m! I asked google!), and done a bit more bragging in the Changes.rst wording ("significantly! improves connection time!").

Your patch has been applied to the master branch.

commit a3b21a76b87fedf045c409481f55c34486d8cd27

Author: Arne Schwabe
Date:   Sun Jul 26 01:48:03 2020 +0200
     Avoid sending push request after receving push reply

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg20589.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering