diff options
author | Martin Willi <martin@revosec.ch> | 2012-09-11 11:33:42 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-09-11 16:18:28 +0200 |
commit | 1e04488f3230b42beab1453f12806b574a69ceb0 (patch) | |
tree | 07dc073342df8fcfad460c6bacae5ff710584e72 /src/libcharon/plugins/stroke/stroke_attribute.c | |
parent | 28a3d5bfbde466f71a3f8b692d58b775ff7290ce (diff) | |
download | strongswan-1e04488f3230b42beab1453f12806b574a69ceb0.tar.bz2 strongswan-1e04488f3230b42beab1453f12806b574a69ceb0.tar.xz |
Check for an existing lease in all stroke pools before creating a new one
Diffstat (limited to 'src/libcharon/plugins/stroke/stroke_attribute.c')
-rw-r--r-- | src/libcharon/plugins/stroke/stroke_attribute.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/libcharon/plugins/stroke/stroke_attribute.c b/src/libcharon/plugins/stroke/stroke_attribute.c index e0c8360a1..85fb94e9e 100644 --- a/src/libcharon/plugins/stroke/stroke_attribute.c +++ b/src/libcharon/plugins/stroke/stroke_attribute.c @@ -89,35 +89,59 @@ static mem_pool_t *find_pool(private_stroke_attribute_t *this, char *name) return found; } -METHOD(attribute_provider_t, acquire_address, host_t*, - private_stroke_attribute_t *this, linked_list_t *pools, identification_t *id, - host_t *requested) +/** + * Find an existing or not yet existing lease + */ +static host_t *find_addr(private_stroke_attribute_t *this, linked_list_t *pools, + identification_t *id, host_t *requested, + mem_pool_op_t operation) { + host_t *addr = NULL; enumerator_t *enumerator; mem_pool_t *pool; - host_t *addr = NULL; char *name; enumerator = pools->create_enumerator(pools); - this->lock->read_lock(this->lock); while (enumerator->enumerate(enumerator, &name)) { pool = find_pool(this, name); if (pool) { - addr = pool->acquire_address(pool, id, requested); + addr = pool->acquire_address(pool, id, requested, operation); if (addr) { break; } } } - this->lock->unlock(this->lock); enumerator->destroy(enumerator); return addr; } +METHOD(attribute_provider_t, acquire_address, host_t*, + private_stroke_attribute_t *this, linked_list_t *pools, identification_t *id, + host_t *requested) +{ + host_t *addr; + + this->lock->read_lock(this->lock); + + addr = find_addr(this, pools, id, requested, MEM_POOL_EXISTING); + if (!addr) + { + addr = find_addr(this, pools, id, requested, MEM_POOL_NEW); + if (!addr) + { + addr = find_addr(this, pools, id, requested, MEM_POOL_REASSIGN); + } + } + + this->lock->unlock(this->lock); + + return addr; +} + METHOD(attribute_provider_t, release_address, bool, private_stroke_attribute_t *this, linked_list_t *pools, host_t *address, identification_t *id) |