Browse code

Multi-socket: local_list clean-up

Optimize the current local_list implementation
by replacing the static array with a resizable
one, as the static allocation serves no real
purpose, particularly on the client side.

Github: OpenVPN/openvpn#682

Change-Id: I32effed9e273fbe8986d1f4e8da4a4d0ac216463
Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250618140016.2766-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31927.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Gianmarco De Gregori authored on 2025/06/18 23:00:09
Showing 2 changed files
... ...
@@ -2067,12 +2067,20 @@ alloc_local_entry(struct connection_entry *ce, const int msglevel,
2067 2067
     struct local_list *l = alloc_local_list_if_undef(ce, gc);
2068 2068
     struct local_entry *e;
2069 2069
 
2070
-    if (l->len >= CONNECTION_LIST_SIZE)
2070
+    if (l->len >= l->capacity)
2071 2071
     {
2072
-        msg(msglevel, "Maximum number of 'local' options (%d) exceeded",
2073
-            CONNECTION_LIST_SIZE);
2072
+        const int new_cap = l->capacity + 1;
2073
+        const size_t elem_size = sizeof(*l->array);
2074 2074
 
2075
-        return NULL;
2075
+        struct local_entry **new_array = gc_realloc(l->array, new_cap * elem_size, gc);
2076
+        if (!new_array)
2077
+        {
2078
+            msg(msglevel, "Unable to process more local options: out of memory. Number of entries = %d", l->len);
2079
+            return NULL;
2080
+        }
2081
+
2082
+        l->array = new_array;
2083
+        l->capacity = new_cap;
2076 2084
     }
2077 2085
 
2078 2086
     ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc);
... ...
@@ -188,8 +188,9 @@ struct remote_entry
188 188
 
189 189
 struct local_list
190 190
 {
191
+    int capacity;
191 192
     int len;
192
-    struct local_entry *array[CONNECTION_LIST_SIZE];
193
+    struct local_entry **array;
193 194
 };
194 195
 
195 196
 struct connection_list