From 594c58e1118e496eadd284647755b16b74665337 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 11 Sep 2012 10:41:11 +0200 Subject: Pass the full list of pools to acquire_address, enumerate in providers If the provider has access to the full pool list, it can enumerate them twice, for example to search for existing leases first, and only search for new leases in a second step. Fixes lease enumeration in attr-sql using multiple pools. --- src/libhydra/plugins/attr_sql/sql_attribute.c | 41 +++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'src/libhydra/plugins/attr_sql/sql_attribute.c') diff --git a/src/libhydra/plugins/attr_sql/sql_attribute.c b/src/libhydra/plugins/attr_sql/sql_attribute.c index 8055be71c..28e59850e 100644 --- a/src/libhydra/plugins/attr_sql/sql_attribute.c +++ b/src/libhydra/plugins/attr_sql/sql_attribute.c @@ -233,25 +233,50 @@ static host_t* get_lease(private_sql_attribute_t *this, char *name, } METHOD(attribute_provider_t, acquire_address, host_t*, - private_sql_attribute_t *this, char *name, identification_t *id, + private_sql_attribute_t *this, linked_list_t *pools, identification_t *id, host_t *requested) { + enumerator_t *enumerator; host_t *address = NULL; u_int identity, pool, timeout; + char *name; identity = get_identity(this, id); if (identity) { - pool = get_pool(this, name, &timeout); - if (pool) + /* check for an existing lease in all pools */ + enumerator = pools->create_enumerator(pools); + while (enumerator->enumerate(enumerator, &name)) { - /* check for an existing lease */ - address = check_lease(this, name, pool, identity); - if (address == NULL) + pool = get_pool(this, name, &timeout); + if (pool) { - /* get an unallocated address or expired lease */ - address = get_lease(this, name, pool, timeout, identity); + address = check_lease(this, name, pool, identity); + if (address) + { + break; + } + } + } + enumerator->destroy(enumerator); + + if (!address) + { + /* get an unallocated address or expired lease */ + enumerator = pools->create_enumerator(pools); + while (enumerator->enumerate(enumerator, &name)) + { + pool = get_pool(this, name, &timeout); + if (pool) + { + address = get_lease(this, name, pool, timeout, identity); + if (address) + { + break; + } + } } + enumerator->destroy(enumerator); } } return address; -- cgit v1.2.3