aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-08-12 12:55:04 +0200
committerHarald Welte <laforge@gnumonks.org>2017-09-05 22:42:18 +0200
commit4857f3c2f39a12da1fc984dd65cbda9a3028ac03 (patch)
tree44253788559bc2f779d6d3f06127a1779a081091
parentb513b951bdd9a7bb2d55a0d77fe7e3403448d2dd (diff)
lib/ippool: Move ippool_aton() out of ippool_new()
we rather pass the in46_prefix directly into ippool_new() Change-Id: Iadf6274e881a9bfc75eb41f9380f5ae2d8c92a0f
-rw-r--r--ggsn/ggsn.c21
-rw-r--r--lib/ippool.c28
-rw-r--r--lib/ippool.h4
3 files changed, 24 insertions, 29 deletions
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 @@ int main(int argc, char **argv)
}
/* 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 @@ void in46a_inc(struct in46_addr *addr)
}
/* 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 ippool_new(struct ippool_t **this, const char *dyn, const char *stat,
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 @@ int ippool_new(struct ippool_t **this, const char *dyn, const char *stat,
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 @@ int ippool_new(struct ippool_t **this, const char *dyn, const char *stat,
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 @@ struct ippoolm_t {
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);