aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ippool.c
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 /lib/ippool.c
parentb513b951bdd9a7bb2d55a0d77fe7e3403448d2dd (diff)
lib/ippool: Move ippool_aton() out of ippool_new()
we rather pass the in46_prefix directly into ippool_new() Change-Id: Iadf6274e881a9bfc75eb41f9380f5ae2d8c92a0f
Diffstat (limited to 'lib/ippool.c')
-rw-r--r--lib/ippool.c28
1 files changed, 11 insertions, 17 deletions
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;