[Openvpn-devel,v2] Extract read_incoming_tls_plaintext into its own function

Message ID 20220503112900.933975-1-arne@rfc2549.org
State Accepted
Headers show
Series
  • [Openvpn-devel,v2] Extract read_incoming_tls_plaintext into its own function
Related show

Commit Message

Arne Schwabe May 3, 2022, 11:29 a.m.
This makes the tls_process_state function a bit easier to read allows
extending the read_incoming_tls_plaintext function later without
making tls_process_state even longer.

Patch v2: fix compile error.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/ssl.c | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

Comments

Frank Lichtenheld May 3, 2022, 1:13 p.m. | #1
Acked-By: Frank Lichtenheld <frank@lichtenheld.com>

Trivial code move. Compiles now.

> Arne Schwabe <arne@rfc2549.org> hat am 03.05.2022 13:29 geschrieben:
> 
>  
> This makes the tls_process_state function a bit easier to read allows

I still think there is an "and" missing after "read"

> extending the read_incoming_tls_plaintext function later without
> making tls_process_state even longer.
> 
> Patch v2: fix compile error.

Regards,
--
Frank Lichtenheld
Gert Doering May 6, 2022, 1:03 p.m. | #2
Stared at code for a bit (looks trivial enough), added "and" to the
commit message, ran client test.

Your patch has been applied to the master branch.

commit 413877f522e89ccc6dd2543bc585ac553df3bd42
Author: Arne Schwabe
Date:   Tue May 3 13:29:00 2022 +0200

     Extract read_incoming_tls_plaintext into its own function

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
     Message-Id: <20220503112900.933975-1-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24268.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index e3101c7fa..bd28260aa 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -2613,6 +2613,32 @@  control_packet_needs_wkc(const struct key_state *ks)
 }
 
 
+static bool
+read_incoming_tls_plaintext(struct key_state *ks, struct buffer *buf,
+                            interval_t *wakeup, bool *state_change)
+{
+    ASSERT(buf_init(buf, 0));
+
+    int status = key_state_read_plaintext(&ks->ks_ssl, buf, TLS_CHANNEL_BUF_SIZE);
+
+    update_time();
+    if (status == -1)
+    {
+        msg(D_TLS_ERRORS, "TLS Error: TLS object -> incoming plaintext read error");
+        return false;
+    }
+    if (status == 1)
+    {
+        *state_change = true;
+        dmsg(D_TLS_DEBUG, "TLS -> Incoming Plaintext");
+
+        /* More data may be available, wake up again asap to check. */
+        *wakeup = 0;
+    }
+    return true;
+}
+
+
 static bool
 tls_process_state(struct tls_multi *multi,
                   struct tls_session *session,
@@ -2705,24 +2731,10 @@  tls_process_state(struct tls_multi *multi,
     struct buffer *buf = &ks->plaintext_read_buf;
     if (!buf->len)
     {
-        int status;
-
-        ASSERT(buf_init(buf, 0));
-        status = key_state_read_plaintext(&ks->ks_ssl, buf, TLS_CHANNEL_BUF_SIZE);
-        update_time();
-        if (status == -1)
+        if (!read_incoming_tls_plaintext(ks, buf, wakeup, &state_change))
         {
-            msg(D_TLS_ERRORS, "TLS Error: TLS object -> incoming plaintext read error");
             goto error;
         }
-        if (status == 1)
-        {
-            state_change = true;
-            dmsg(D_TLS_DEBUG, "TLS -> Incoming Plaintext");
-
-            /* More data may be available, wake up again asap to check. */
-            *wakeup = 0;
-        }
     }
 
     /* Send Key */