[MERGED] openggsn[master]: lib/ippool: Move ippool_aton() out of ippool_new()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Sep 5 21:06:02 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: lib/ippool: Move ippool_aton() out of ippool_new()
......................................................................


lib/ippool: Move ippool_aton() out of ippool_new()

we rather pass the in46_prefix directly into ippool_new()

Change-Id: Iadf6274e881a9bfc75eb41f9380f5ae2d8c92a0f
---
M ggsn/ggsn.c
M lib/ippool.c
M lib/ippool.h
3 files changed, 24 insertions(+), 29 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index c82f630..7614b92 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -565,23 +565,24 @@
 	}
 
 	/* dynip                                                        */
+	struct in46_prefix i46p;
+	size_t prefixlen;
 	if (!args_info.dynip_arg) {
-		if (ippool_new(&ippool, args_info.net_arg, NULL, 1, 0,
-			       IPPOOL_NONETWORK | IPPOOL_NOGATEWAY |
-			       IPPOOL_NOBROADCAST)) {
-			SYS_ERR(DGGSN, LOGL_ERROR, 0,
-				"Failed to allocate IP pool!");
+		if (ippool_aton(&i46p.addr, &prefixlen, args_info.net_arg, 0)) {
+			SYS_ERR(DIP, LOGL_ERROR, 0, "Failed to parse dynamic pool");
 			exit(1);
 		}
 	} else {
-		if (ippool_new(&ippool, args_info.dynip_arg, NULL, 1, 0,
-			       IPPOOL_NONETWORK | IPPOOL_NOGATEWAY |
-			       IPPOOL_NOBROADCAST)) {
-			SYS_ERR(DGGSN, LOGL_ERROR, 0,
-				"Failed to allocate IP pool!");
+		if (ippool_aton(&i46p.addr, &prefixlen, args_info.dynip_arg, 0)) {
+			SYS_ERR(DIP, LOGL_ERROR, 0, "Failed to parse dynamic pool");
 			exit(1);
 		}
 	}
+	i46p.prefixlen = prefixlen;
+	if (ippool_new(&ippool, &i46p, NULL, IPPOOL_NONETWORK | IPPOOL_NOGATEWAY | IPPOOL_NOBROADCAST)) {
+		SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to allocate IP pool!");
+		exit(1);
+	}
 
 	/* DNS1 and DNS2 */
 	memset(&dns1, 0, sizeof(dns1));
diff --git a/lib/ippool.c b/lib/ippool.c
index b1b242d..a236fe7 100644
--- a/lib/ippool.c
+++ b/lib/ippool.c
@@ -185,8 +185,8 @@
 }
 
 /* Create new address pool */
-int ippool_new(struct ippool_t **this, const char *dyn, const char *stat,
-	       int allowdyn, int allowstat, int flags)
+int ippool_new(struct ippool_t **this, const struct in46_prefix *dyn, const struct in46_prefix *stat,
+	       int flags)
 {
 
 	/* Parse only first instance of pool for now */
@@ -200,14 +200,11 @@
 	int dynsize;
 	unsigned int statsize;
 
-	if (!allowdyn) {
+	if (!dyn || dyn->addr.len == 0) {
 		dynsize = 0;
 	} else {
-		if (ippool_aton(&addr, &addrprefixlen, dyn, 0)) {
-			SYS_ERR(DIP, LOGL_ERROR, 0,
-				"Failed to parse dynamic pool");
-			return -1;
-		}
+		addr = dyn->addr;
+		addrprefixlen = dyn->prefixlen;
 		/* we want to work with /64 prefixes, i.e. allocate /64 prefixes rather
 		 * than /128 (single IPv6 addresses) */
 		if (addr.len == sizeof(struct in6_addr))
@@ -227,18 +224,15 @@
 			dynsize--;
 	}
 
-	if (!allowstat) {
+	if (!stat || stat->addr.len == 0) {
 		statsize = 0;
 		stataddr.len = 0;
 		stataddrprefixlen = 0;
 	} else {
-		if (ippool_aton(&stataddr, &stataddrprefixlen, stat, 0)) {
-			SYS_ERR(DIP, LOGL_ERROR, 0,
-				"Failed to parse static range");
-			return -1;
-		}
+		stataddr = stat->addr;
+		stataddrprefixlen = stat->prefixlen;
 
-		statsize = (1 << (addr.len - addrprefixlen + 1)) -1;
+		statsize = (1 << (addr.len - stataddrprefixlen + 1)) -1;
 		if (statsize > IPPOOL_STATSIZE)
 			statsize = IPPOOL_STATSIZE;
 	}
@@ -251,8 +245,8 @@
 		return -1;
 	}
 
-	(*this)->allowdyn = allowdyn;
-	(*this)->allowstat = allowstat;
+	(*this)->allowdyn = dyn ? 1 : 0;
+	(*this)->allowstat = stat ? 1 : 0;
 	if (stataddr.len > 0)
 		(*this)->stataddr = stataddr;
 	(*this)->stataddrprefixlen = stataddrprefixlen;
diff --git a/lib/ippool.h b/lib/ippool.h
index 8249b7f..fbac66d 100644
--- a/lib/ippool.h
+++ b/lib/ippool.h
@@ -71,8 +71,8 @@
 extern unsigned long int ippool_hash(struct in46_addr *addr);
 
 /* Create new address pool */
-extern int ippool_new(struct ippool_t **this, const char *dyn, const char *stat,
-		      int allowdyn, int allowstat, int flags);
+extern int ippool_new(struct ippool_t **this, const struct in46_prefix *dyn,
+		      const struct in46_prefix *stat, int flags);
 
 /* Delete existing address pool */
 extern int ippool_free(struct ippool_t *this);

-- 
To view, visit https://gerrit.osmocom.org/3842
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iadf6274e881a9bfc75eb41f9380f5ae2d8c92a0f
Gerrit-PatchSet: 3
Gerrit-Project: openggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list