diff options
author | Martin Willi <martin@revosec.ch> | 2012-09-11 11:19:56 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-09-11 16:18:28 +0200 |
commit | 28a3d5bfbde466f71a3f8b692d58b775ff7290ce (patch) | |
tree | 8dd021fd6e158054914b3378970a8ef6fe1932d2 /src/libhydra | |
parent | 594c58e1118e496eadd284647755b16b74665337 (diff) | |
download | strongswan-28a3d5bfbde466f71a3f8b692d58b775ff7290ce.tar.bz2 strongswan-28a3d5bfbde466f71a3f8b692d58b775ff7290ce.tar.xz |
Pass full pool list to release_address
Diffstat (limited to 'src/libhydra')
-rw-r--r-- | src/libhydra/attributes/attribute_manager.c | 4 | ||||
-rw-r--r-- | src/libhydra/attributes/attribute_manager.h | 5 | ||||
-rw-r--r-- | src/libhydra/attributes/attribute_provider.h | 5 | ||||
-rw-r--r-- | src/libhydra/plugins/attr_sql/sql_attribute.c | 35 |
4 files changed, 31 insertions, 18 deletions
diff --git a/src/libhydra/attributes/attribute_manager.c b/src/libhydra/attributes/attribute_manager.c index e7a687a50..000d2e082 100644 --- a/src/libhydra/attributes/attribute_manager.c +++ b/src/libhydra/attributes/attribute_manager.c @@ -84,7 +84,7 @@ METHOD(attribute_manager_t, acquire_address, host_t*, } METHOD(attribute_manager_t, release_address, bool, - private_attribute_manager_t *this, char *pool, host_t *address, + private_attribute_manager_t *this, linked_list_t *pools, host_t *address, identification_t *id) { enumerator_t *enumerator; @@ -95,7 +95,7 @@ METHOD(attribute_manager_t, release_address, bool, enumerator = this->providers->create_enumerator(this->providers); while (enumerator->enumerate(enumerator, ¤t)) { - if (current->release_address(current, pool, address, id)) + if (current->release_address(current, pools, address, id)) { found = TRUE; break; diff --git a/src/libhydra/attributes/attribute_manager.h b/src/libhydra/attributes/attribute_manager.h index 45e5a40f1..99f41772c 100644 --- a/src/libhydra/attributes/attribute_manager.h +++ b/src/libhydra/attributes/attribute_manager.h @@ -51,13 +51,14 @@ struct attribute_manager_t { /** * Release a previously acquired address. * - * @param pool pool name from which the address was acquired + * @param pools list of pool names (char*) to release to * @param address address to release * @param id peer identity to get address for * @return TRUE if address released to pool */ bool (*release_address)(attribute_manager_t *this, - char *pool, host_t *address, identification_t *id); + linked_list_t *pools, host_t *address, + identification_t *id); /** * Create an enumerator over attributes to hand out to a peer. diff --git a/src/libhydra/attributes/attribute_provider.h b/src/libhydra/attributes/attribute_provider.h index 7d0acdbac..e5e556fc4 100644 --- a/src/libhydra/attributes/attribute_provider.h +++ b/src/libhydra/attributes/attribute_provider.h @@ -46,13 +46,14 @@ struct attribute_provider_t { /** * Release a previously acquired address. * - * @param pool name of the pool this address was acquired from + * @param pools list of pool names (char*) to release to * @param address address to release * @param id peer ID * @return TRUE if the address has been released by the provider */ bool (*release_address)(attribute_provider_t *this, - char *pool, host_t *address, identification_t *id); + linked_list_t *pools, host_t *address, + identification_t *id); /** * Create an enumerator over attributes to hand out to a peer. diff --git a/src/libhydra/plugins/attr_sql/sql_attribute.c b/src/libhydra/plugins/attr_sql/sql_attribute.c index 28e59850e..a7d90e728 100644 --- a/src/libhydra/plugins/attr_sql/sql_attribute.c +++ b/src/libhydra/plugins/attr_sql/sql_attribute.c @@ -283,33 +283,44 @@ METHOD(attribute_provider_t, acquire_address, host_t*, } METHOD(attribute_provider_t, release_address, bool, - private_sql_attribute_t *this, char *name, host_t *address, + private_sql_attribute_t *this, linked_list_t *pools, host_t *address, identification_t *id) { + enumerator_t *enumerator; u_int pool, timeout; time_t now = time(NULL); + bool found = FALSE; + char *name; - pool = get_pool(this, name, &timeout); - if (pool) + enumerator = pools->create_enumerator(pools); + while (enumerator->enumerate(enumerator, &name)) { - if (this->history) + pool = get_pool(this, name, &timeout); + if (!pool) { - this->db->execute(this->db, NULL, - "INSERT INTO leases (address, identity, acquired, released)" - " SELECT id, identity, acquired, ? FROM addresses " - " WHERE pool = ? AND address = ?", - DB_UINT, now, DB_UINT, pool, - DB_BLOB, address->get_address(address)); + continue; } if (this->db->execute(this->db, NULL, "UPDATE addresses SET released = ? WHERE " "pool = ? AND address = ?", DB_UINT, time(NULL), DB_UINT, pool, DB_BLOB, address->get_address(address)) > 0) { - return TRUE; + if (this->history) + { + this->db->execute(this->db, NULL, + "INSERT INTO leases (address, identity, acquired, released)" + " SELECT id, identity, acquired, ? FROM addresses " + " WHERE pool = ? AND address = ?", + DB_UINT, now, DB_UINT, pool, + DB_BLOB, address->get_address(address)); + } + found = TRUE; + break; } } - return FALSE; + enumerator->destroy(enumerator); + + return found; } METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*, |