vici: Add support for address range definitions of pools

This commit is contained in:
Tobias Brunner
2014-10-30 12:32:45 +01:00
parent c355e2b2c7
commit 5e92534313
2 changed files with 39 additions and 9 deletions
+35 -5
View File
@@ -1,4 +1,7 @@
/*
* Copyright (C) 2014 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* Copyright (C) 2014 Martin Willi
* Copyright (C) 2014 revosec AG
*
@@ -354,6 +357,24 @@ static vici_message_t* create_reply(char *fmt, ...)
return builder->finalize(builder);
}
/**
* Parse a range definition of an address pool
*/
static mem_pool_t *create_pool_range(char *name, char *buf)
{
mem_pool_t *pool;
host_t *from, *to;
if (!host_create_from_range(buf, &from, &to))
{
return NULL;
}
pool = mem_pool_create_range(name, from, to);
from->destroy(from);
to->destroy(to);
return pool;
}
/**
* Parse callback data, passed to each callback
*/
@@ -490,7 +511,8 @@ CALLBACK(pool_kv, bool,
if (streq(name, "addrs"))
{
char buf[128];
host_t *base;
mem_pool_t *pool;
host_t *base = NULL;
int bits;
if (data->pool->vips)
@@ -503,14 +525,22 @@ CALLBACK(pool_kv, bool,
data->request->reply = create_reply("invalid addrs value");
return FALSE;
}
base = host_create_from_subnet(buf, &bits);
if (!base)
pool = create_pool_range(data->name, buf);
if (!pool)
{
base = host_create_from_subnet(buf, &bits);
if (base)
{
pool = mem_pool_create(data->name, base, bits);
base->destroy(base);
}
}
if (!pool)
{
data->request->reply = create_reply("invalid addrs value: %s", buf);
return FALSE;
}
data->pool->vips = mem_pool_create(data->name, base, bits);
base->destroy(base);
data->pool->vips = pool;
return TRUE;
}
data->request->reply = create_reply("invalid attribute: %s", name);
+4 -4
View File
@@ -782,11 +782,11 @@ pools.<name> { # }
Section defining a single pool with a unique name.
pools.<name>.addrs =
Subnet defining addresses allocated in pool.
Addresses allocated in pool.
Subnet defining addresses allocated in pool. Accepts a single CIDR subnet
defining the pool to allocate addresses from. Pools must be unique and
non-overlapping.
Subnet or range defining addresses allocated in pool. Accepts a single CIDR
subnet defining the pool to allocate addresses from, or an address range
(<from>-<to>). Pools must be unique and non-overlapping.
pools.<name>.<attr> =
Comma separated list of additional attributes from type <attr>.