[S] Change in openvpn[master]: options_util: move subnet_pool_by_tag out of multi.c

"ordex \(Code Review\) via Openvpn-devel" <[email protected]>
Newsgroups gmane.network.openvpn.devel
Message-ID <[email protected]>
Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1784?usp=email

to review the following change.


Change subject: options_util: move subnet_pool_by_tag out of multi.c
......................................................................

options_util: move subnet_pool_by_tag out of multi.c

It is a pure lookup over the --subnet-pool list; relocating it to
options_util.c (and taking the list head directly) lets it be unit
tested without multi.c's dependencies. No functional change.

Change-Id: I087cbccc9b4a994376aa2d2409509a2307068899
GitHub: closes openvpn/OpenVPN#987
Signed-off-by: Antonio Quartulli <[email protected]>
---
M src/openvpn/multi.c
M src/openvpn/options_util.c
M src/openvpn/options_util.h
3 files changed, 27 insertions(+), 16 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/84/1784/1

diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 84f25b3..da46cf4 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -42,6 +42,7 @@
 #include "vlan.h"
 #include "auth_token.h"
 #include "route.h"
+#include "options_util.h"
 #include <inttypes.h>
 #include <string.h>
 
@@ -1419,19 +1420,6 @@
     }
 }
 
-static const struct subnet_pool_def *
-subnet_pool_by_tag(const struct options *o, const char *tag)
-{
-    for (const struct subnet_pool_def *d = o->subnet_pools; d; d = d->next)
-    {
-        if (!strcmp(d->tag, tag))
-        {
-            return d;
-        }
-    }
-    return NULL;
-}
-
 /*
  * Return the dynamic pool serving the clients tagged with <tag>, creating it
  * on first use from the matching --subnet-pool definition.
@@ -1449,7 +1437,7 @@
         }
     }
 
-    const struct subnet_pool_def *d4 = subnet_pool_by_tag(&m->top.options, tag);
+    const struct subnet_pool_def *d4 = subnet_pool_by_tag(m->top.options.subnet_pools, tag);
     ALLOC_OBJ_CLEAR(sp, struct subnet_pool);
     sp->tag = d4->tag;
     sp->pool = ifconfig_pool_init(true, IFCONFIG_POOL_INDIV, d4->network + 2,
@@ -1475,7 +1463,7 @@
     if (mi->context.options.subnet_pool_tag && !mi->context.options.subnet_pool_defined)
     {
         const struct subnet_pool_def *d =
-            subnet_pool_by_tag(&m->top.options, mi->context.options.subnet_pool_tag);
+            subnet_pool_by_tag(m->top.options.subnet_pools, mi->context.options.subnet_pool_tag);
         if (d)
         {
             mi->context.options.subnet_pool_defined = true;
@@ -2864,7 +2852,7 @@
     }
 
     if (mi->context.options.subnet_pool_tag
-        && !subnet_pool_by_tag(&m->top.options, mi->context.options.subnet_pool_tag))
+        && !subnet_pool_by_tag(m->top.options.subnet_pools, mi->context.options.subnet_pool_tag))
     {
         msg(D_MULTI_ERRORS, "MULTI: client has been rejected due to unknown --subnet-pool-tag '%s'",
             mi->context.options.subnet_pool_tag);
diff --git a/src/openvpn/options_util.c b/src/openvpn/options_util.c
index 47fe0bc..ba04917 100644
--- a/src/openvpn/options_util.c
+++ b/src/openvpn/options_util.c
@@ -31,6 +31,19 @@
 
 #include "push.h"
 
+const struct subnet_pool_def *
+subnet_pool_by_tag(const struct subnet_pool_def *pools, const char *tag)
+{
+    for (const struct subnet_pool_def *d = pools; d; d = d->next)
+    {
+        if (!strcmp(d->tag, tag))
+        {
+            return d;
+        }
+    }
+    return NULL;
+}
+
 const char *
 parse_auth_failed_temp(struct options *o, const char *reason)
 {
diff --git a/src/openvpn/options_util.h b/src/openvpn/options_util.h
index 1d4ea9b..c54357c 100644
--- a/src/openvpn/options_util.h
+++ b/src/openvpn/options_util.h
@@ -28,6 +28,16 @@
 
 const char *parse_auth_failed_temp(struct options *o, const char *reason);
 
+/**
+ * Look up a named --subnet-pool in a list of pool definitions.
+ *
+ * @param pools  head of the --subnet-pool list (may be NULL)
+ * @param tag    the --subnet-pool-tag to match
+ * @return       the matching pool definition, or NULL if none matches
+ */
+const struct subnet_pool_def *subnet_pool_by_tag(const struct subnet_pool_def *pools,
+                                                 const char *tag);
+
 
 /** Checks if the string is a valid integer by checking if it can be
  *  converted to an integer */

-- 
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1784?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I087cbccc9b4a994376aa2d2409509a2307068899
Gerrit-Change-Number: 1784
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.