vici: Add support for address range definitions of pools
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2014 Tobias Brunner
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
* Copyright (C) 2014 Martin Willi
|
* Copyright (C) 2014 Martin Willi
|
||||||
* Copyright (C) 2014 revosec AG
|
* Copyright (C) 2014 revosec AG
|
||||||
*
|
*
|
||||||
@@ -354,6 +357,24 @@ static vici_message_t* create_reply(char *fmt, ...)
|
|||||||
return builder->finalize(builder);
|
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
|
* Parse callback data, passed to each callback
|
||||||
*/
|
*/
|
||||||
@@ -490,7 +511,8 @@ CALLBACK(pool_kv, bool,
|
|||||||
if (streq(name, "addrs"))
|
if (streq(name, "addrs"))
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
host_t *base;
|
mem_pool_t *pool;
|
||||||
|
host_t *base = NULL;
|
||||||
int bits;
|
int bits;
|
||||||
|
|
||||||
if (data->pool->vips)
|
if (data->pool->vips)
|
||||||
@@ -503,14 +525,22 @@ CALLBACK(pool_kv, bool,
|
|||||||
data->request->reply = create_reply("invalid addrs value");
|
data->request->reply = create_reply("invalid addrs value");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
base = host_create_from_subnet(buf, &bits);
|
pool = create_pool_range(data->name, buf);
|
||||||
if (!base)
|
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);
|
data->request->reply = create_reply("invalid addrs value: %s", buf);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
data->pool->vips = mem_pool_create(data->name, base, bits);
|
data->pool->vips = pool;
|
||||||
base->destroy(base);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
data->request->reply = create_reply("invalid attribute: %s", name);
|
data->request->reply = create_reply("invalid attribute: %s", name);
|
||||||
|
|||||||
@@ -782,11 +782,11 @@ pools.<name> { # }
|
|||||||
Section defining a single pool with a unique name.
|
Section defining a single pool with a unique name.
|
||||||
|
|
||||||
pools.<name>.addrs =
|
pools.<name>.addrs =
|
||||||
Subnet defining addresses allocated in pool.
|
Addresses allocated in pool.
|
||||||
|
|
||||||
Subnet defining addresses allocated in pool. Accepts a single CIDR subnet
|
Subnet or range defining addresses allocated in pool. Accepts a single CIDR
|
||||||
defining the pool to allocate addresses from. Pools must be unique and
|
subnet defining the pool to allocate addresses from, or an address range
|
||||||
non-overlapping.
|
(<from>-<to>). Pools must be unique and non-overlapping.
|
||||||
|
|
||||||
pools.<name>.<attr> =
|
pools.<name>.<attr> =
|
||||||
Comma separated list of additional attributes from type <attr>.
|
Comma separated list of additional attributes from type <attr>.
|
||||||
|
|||||||
Reference in New Issue
Block a user