]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Move parsing IV_PROTO to separate function
authorArne Schwabe <arne@rfc2549.org>
Mon, 10 Aug 2020 14:37:06 +0000 (16:37 +0200)
committerGert Doering <gert@greenie.muc.de>
Tue, 11 Aug 2020 08:12:01 +0000 (10:12 +0200)
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20200810143707.5834-17-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20679.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/multi.c

index b7b7e32fbe540ca90208f8287e5cbe4af393826b..137381805f7d8cab2f2e12d53a6a5c120d868b5e 100644 (file)
@@ -1771,6 +1771,28 @@ multi_client_connect_setenv(struct multi_context *m,
     gc_free(&gc);
 }
 
+/**
+ * Extracts the IV_PROTO variable and returns its value or 0
+ * if it cannot be extracted.
+ *
+ */
+static unsigned int
+extract_iv_proto(const char *peer_info)
+{
+
+    const char *optstr = peer_info ? strstr(peer_info, "IV_PROTO=") : NULL;
+    if (optstr)
+    {
+        int proto = 0;
+        int r = sscanf(optstr, "IV_PROTO=%d", &proto);
+        if (r == 1 && proto > 0)
+        {
+            return proto;
+        }
+    }
+    return 0;
+}
+
 /**
  * Calculates the options that depend on the client capabilities
  * based on local options and available peer info
@@ -1780,30 +1802,19 @@ multi_client_connect_setenv(struct multi_context *m,
 static bool
 multi_client_set_protocol_options(struct context *c)
 {
-
-    const char *optstr = NULL;
     struct tls_multi *tls_multi = c->c2.tls_multi;
     const char *const peer_info = tls_multi->peer_info;
     struct options *o = &c->options;
 
-    /* Send peer-id if client supports it */
-    optstr = peer_info ? strstr(peer_info, "IV_PROTO=") : NULL;
-    if (optstr)
-    {
-        int proto = 0;
-        int r = sscanf(optstr, "IV_PROTO=%d", &proto);
-        if (r == 1)
-        {
-            if (proto & IV_PROTO_DATA_V2)
-            {
-                tls_multi->use_peer_id = true;
-            }
-            if (proto & IV_PROTO_REQUEST_PUSH)
-            {
-                c->c2.push_request_received = true;
-            }
-        }
 
+    unsigned int proto = extract_iv_proto(peer_info);
+    if (proto & IV_PROTO_DATA_V2)
+    {
+        tls_multi->use_peer_id = true;
+    }
+    if (proto & IV_PROTO_REQUEST_PUSH)
+    {
+        c->c2.push_request_received = true;
     }
 
     /* Select cipher if client supports Negotiable Crypto Parameters */