[Openvpn-devel,3/6] Add send_control_channel_string_dowork variant

Message ID 20190114154819.6064-3-arne@rfc2549.org
State Accepted
Headers show
Series
  • [Openvpn-devel,1/6] Fix loading inline tls-crypt-v2 keys with mbed TLS
Related show

Commit Message

Arne Schwabe Jan. 14, 2019, 3:48 p.m.
From: Arne Schwabe <arne@openvpn.net>

The send_control_channel_string_dowork variant does not schedule
the sending of the actual and can be used where struct context is not
available.
---
 src/openvpn/forward.c | 43 +++++++++++++++++++++++--------------------
 src/openvpn/forward.h | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 21 deletions(-)

Comments

Gert Doering Jan. 16, 2019, 7:54 p.m. | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

"Just moving of code" (though the change c2->c2.multi -> multi makes this 
harder for git to show).  Tested with t_client testset plus a profile that
uses user+pass auth so these still go out.

Your patch has been applied to the master branch.

commit 1000d5e1191d0a372e9e82f76dd1d1f101fe308e
Author: Arne Schwabe
Date:   Mon Jan 14 16:48:16 2019 +0100

     Add send_control_channel_string_dowork variant

     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20190114154819.6064-3-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18092.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 0a90fff0..4076f647 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -464,42 +464,45 @@  check_connection_established_dowork(struct context *c)
     }
 }
 
-/*
- * Send a string to remote over the TLS control channel.
- * Used for push/pull messages, passing username/password,
- * etc.
- */
+bool
+send_control_channel_string_dowork(struct tls_multi *multi,
+                                   const char *str, int msglevel)
+{
+    struct gc_arena gc = gc_new();
+    bool stat;
+
+    /* buffered cleartext write onto TLS control channel */
+    stat = tls_send_payload(multi, (uint8_t *) str, strlen(str) + 1);
+
+    msg(msglevel, "SENT CONTROL [%s]: '%s' (status=%d)",
+        tls_common_name(multi, false),
+        sanitize_control_message(str, &gc),
+        (int) stat);
+
+    gc_free(&gc);
+    return stat;
+}
+
 bool
 send_control_channel_string(struct context *c, const char *str, int msglevel)
 {
     if (c->c2.tls_multi)
     {
-        struct gc_arena gc = gc_new();
-        bool stat;
-
-        /* buffered cleartext write onto TLS control channel */
-        stat = tls_send_payload(c->c2.tls_multi, (uint8_t *) str, strlen(str) + 1);
-
+        bool ret = send_control_channel_string_dowork(c->c2.tls_multi,
+                                                      str, msglevel);
         /*
          * Reschedule tls_multi_process.
          * NOTE: in multi-client mode, usually the below two statements are
          * insufficient to reschedule the client instance object unless
          * multi_schedule_context_wakeup(m, mi) is also called.
          */
+
         interval_action(&c->c2.tmp_int);
         context_immediate_reschedule(c); /* ZERO-TIMEOUT */
-
-        msg(msglevel, "SENT CONTROL [%s]: '%s' (status=%d)",
-            tls_common_name(c->c2.tls_multi, false),
-            sanitize_control_message(str, &gc),
-            (int) stat);
-
-        gc_free(&gc);
-        return stat;
+        return ret;
     }
     return true;
 }
-
 /*
  * Add routes.
  */
diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h
index f97b0e2e..48202c07 100644
--- a/src/openvpn/forward.h
+++ b/src/openvpn/forward.h
@@ -286,7 +286,36 @@  void process_outgoing_tun(struct context *c);
 
 /**************************************************************************/
 
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+/*
+ * Send a string to remote over the TLS control channel.
+ * Used for push/pull messages, passing username/password,
+ * etc.
+ * @param c          - The context structure of the VPN tunnel associated with
+ *                     the packet.
+ * @param str        - The message to be sent
+ * @param msglevel   - Message level to use for logging
+ */
+bool
+send_control_channel_string(struct context *c, const char *str, int msglevel);
+
+/*
+ * Send a string to remote over the TLS control channel.
+ * Used for push/pull messages, passing username/password,
+ * etc.
+ *
+ * This variant does not schedule the actual sending of the message
+ * The caller needs to ensure that it is scheduled or call
+ * send_control_channel_string
+ *
+ * @param multi      - The tls_multi structure of the VPN tunnel associated
+ *                     with the packet.
+ * @param str        - The message to be sent
+ * @param msglevel   - Message level to use for logging
+ */
+
+bool
+send_control_channel_string_dowork(struct tls_multi *multi,
+                                   const char *str, int msglevel);
 
 #define PIPV4_PASSTOS                   (1<<0)
 #define PIP_MSSFIX                      (1<<1)         /* v4 and v6 */