aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2009-07-16 21:53:46 +0200
committerAndreas Steffen <andreas.steffen@strongswan.org>2009-07-16 21:53:46 +0200
commit07be083b7fdb54144c718f81931e6981ad2c7550 (patch)
treeb0f30502240b28890c61a5c9e58ec73ec5a9192d
parent375a91bb9b173ad8758e868b00b2d74877320496 (diff)
downloadstrongswan-07be083b7fdb54144c718f81931e6981ad2c7550.tar.bz2
strongswan-07be083b7fdb54144c718f81931e6981ad2c7550.tar.xz
fixed problem with static leases over multiple pools
-rw-r--r--src/charon/plugins/sql/sql_attribute.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/charon/plugins/sql/sql_attribute.c b/src/charon/plugins/sql/sql_attribute.c
index 95d0d30d4..fa728eab6 100644
--- a/src/charon/plugins/sql/sql_attribute.c
+++ b/src/charon/plugins/sql/sql_attribute.c
@@ -137,13 +137,29 @@ static host_t *get_address(private_sql_attribute_t *this, char *name,
}
}
- /* check for an expired lease */
+ /* check for an available address */
while (TRUE)
{
- e = this->db->query(this->db,
+ int hits;
+
+ if (timeout)
+ {
+ /* check for an expired lease */
+ e = this->db->query(this->db,
"SELECT id, address FROM addresses "
"WHERE pool = ? AND released != 0 AND released < ? LIMIT 1",
DB_UINT, pool, DB_UINT, now - timeout, DB_UINT, DB_BLOB);
+ }
+ else
+ {
+ /* with static leases, check for an unallocated address */
+ e = this->db->query(this->db,
+ "SELECT id, address FROM addresses "
+ "WHERE pool = ? AND identity = 0 LIMIT 1",
+ DB_UINT, pool, DB_UINT, DB_BLOB);
+
+ }
+
if (!e || !e->enumerate(e, &id, &address))
{
DESTROY_IF(e);
@@ -152,12 +168,24 @@ static host_t *get_address(private_sql_attribute_t *this, char *name,
address = chunk_clonea(address);
e->destroy(e);
- if (this->db->execute(this->db, NULL,
- "UPDATE addresses SET "
- "acquired = ?, released = 0, identity = ? "
- "WHERE id = ? AND released != 0 AND released < ?",
- DB_UINT, now, DB_UINT, identity,
- DB_UINT, id, DB_UINT, now - timeout) > 0)
+ if (timeout)
+ {
+ hits = this->db->execute(this->db, NULL,
+ "UPDATE addresses SET "
+ "acquired = ?, released = 0, identity = ? "
+ "WHERE id = ? AND released != 0 AND released < ?",
+ DB_UINT, now, DB_UINT, identity,
+ DB_UINT, id, DB_UINT, now - timeout);
+ }
+ else
+ {
+ hits = this->db->execute(this->db, NULL,
+ "UPDATE addresses SET "
+ "acquired = ?, released = 0, identity = ? "
+ "WHERE id = ? AND identity = 0",
+ DB_UINT, now, DB_UINT, identity, DB_UINT, id);
+ }
+ if (hits > 0)
{
host = host_create_from_chunk(AF_UNSPEC, address, 0);
if (host)