Commit 5072cbd341 for strongswan.org
commit 5072cbd341b29758e5bf9531d1ac287ab287f3eb
Author: Tobias Brunner <tobias@strongswan.org>
Date: Thu Nov 12 18:32:53 2026 +0100
ha: Properly handle VIPs with make-before-break reauthentication
This tracks virtual IPs across SAs and assigns the previous address
during a make-before-break reauthentication.
Compared to the tracking in `mem_pool_t`, we keep track of the SAs that
own a lease, so we can properly reserve VIPs on the passive node and
migrate them during a rekeying or update the address hash (on the active
node only right now).
For IKEv1, there are some extra measures to handle the weird adoption
mechanisms. But we can soon remove that stuff anyway.
Closes strongswan/strongswan#3203
diff --git a/src/libcharon/plugins/ha/ha_attribute.c b/src/libcharon/plugins/ha/ha_attribute.c
index ebe5ad4a36..2d9d779a76 100644
--- a/src/libcharon/plugins/ha/ha_attribute.c
+++ b/src/libcharon/plugins/ha/ha_attribute.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2018-2026 Tobias Brunner
* Copyright (C) 2010 Martin Willi
*
* Copyright (C) secunet Security Networks AG
@@ -16,6 +17,8 @@
#include "ha_attribute.h"
+#include <collections/array.h>
+#include <collections/hashtable.h>
#include <collections/linked_list.h>
#include <threading/mutex.h>
@@ -64,13 +67,119 @@ typedef struct {
int size;
/** bitmask for address usage */
u_char *mask;
+ /** identity/lease table (identification_t -> entry_t) */
+ hashtable_t *leases;
} pool_t;
+/**
+ * Leases for a specific identity
+ */
+typedef struct {
+ /** peer identity (key) */
+ identification_t *id;
+ /** individual leases (lease_t) */
+ array_t *leases;
+} entry_t;
+
+/**
+ * Hashtable hash function
+ */
+static u_int entry_hash(const void *key)
+{
+ identification_t *id = (identification_t*)key;
+ return id->hash(id, 0);
+}
+
+/**
+ * Hashtable equals function
+ */
+static bool entry_equals(const void *a, const void *b)
+{
+ identification_t *id = (identification_t*)a;
+ return id->equals(id, (identification_t*)b);
+}
+
+/**
+ * Lease entry for an offset
+ */
+typedef struct {
+ /** offset of the address in the pool */
+ int offset;
+ /** IKE_SA ID that currently owns this lease */
+ ike_sa_id_t *id;
+ /** hash of the peer's address/port for make-before-break reauth */
+ uint32_t hash;
+} lease_t;
+
+/**
+ * Create a unique hash for a remote address
+ */
+static uint32_t hash_addr(host_t *addr)
+{
+ return chunk_hash_inc(addr->get_address(addr), addr->get_port(addr));
+}
+
+/**
+ * Get or create the entry for an identity
+ */
+static entry_t *entry_get(pool_t *pool, identification_t *id)
+{
+ entry_t *entry;
+
+ entry = pool->leases->get(pool->leases, id);
+ if (!entry)
+ {
+ INIT(entry,
+ .id = id->clone(id),
+ );
+ pool->leases->put(pool->leases, entry->id, entry);
+ }
+ return entry;
+}
+
+/**
+ * Create a lease entry for an IKE_SA
+ */
+static lease_t *create_lease(int offset, ike_sa_t *ike_sa)
+{
+ lease_t *this;
+ ike_sa_id_t *id;
+
+ id = ike_sa->get_id(ike_sa);
+
+ INIT(this,
+ .offset = offset,
+ .id = id->clone(id),
+ .hash = hash_addr(ike_sa->get_other_host(ike_sa)),
+ );
+ return this;
+}
+
+/**
+ * Destroy a lease
+ */
+static void lease_destroy(lease_t *this)
+{
+ this->id->destroy(this->id);
+ free(this);
+}
+
+/**
+ * Destroy an identity entry and all leases
+ */
+static void entry_destroy(entry_t *this)
+{
+ array_destroy_function(this->leases, (void*)lease_destroy, NULL);
+ this->id->destroy(this->id);
+ free(this);
+}
+
/**
* Clean up a pool entry
*/
static void pool_destroy(pool_t *pool)
{
+ pool->leases->destroy_function(pool->leases, (void*)entry_destroy);
pool->base->destroy(pool->base);
free(pool->name);
free(pool->mask);
@@ -167,6 +276,35 @@ static pool_t* get_pool(private_ha_attribute_t *this, char *name)
return found;
}
+/**
+ * Find the responsible pool (if any) and determine the offset for the given
+ * virtual IP
+ */
+static pool_t *get_pool_by_vip(private_ha_attribute_t *this, host_t *vip,
+ int *offset)
+{
+ enumerator_t *enumerator;
+ pool_t *pool;
+
+ enumerator = this->pools->create_enumerator(this->pools);
+ while (enumerator->enumerate(enumerator, &pool))
+ {
+ if (pool->base->get_family(pool->base) != vip->get_family(vip))
+ {
+ continue;
+ }
+ *offset = host2offset(pool, vip);
+ if (!valid_offset(pool, *offset))
+ {
+ continue;
+ }
+ enumerator->destroy(enumerator);
+ return pool;
+ }
+ enumerator->destroy(enumerator);
+ return NULL;
+}
+
/**
* Check if we are responsible for an offset
*/
@@ -178,18 +316,192 @@ static bool responsible_for(private_ha_attribute_t *this, int offset)
return this->segments->is_active(this->segments, segment);
}
+/**
+ * Find a lease by offset and the IKE_SA ID, if omitted, finds the first
+ * lease of that offset
+ */
+static lease_t *find_lease(entry_t *entry, int offset, ike_sa_id_t *id,
+ int *index)
+{
+ lease_t *lease;
+ int i;
+
+ for (i = 0; i < array_count(entry->leases); i++)
+ {
+ array_get(entry->leases, i, &lease);
+
+ if (lease->offset == offset &&
+ (!id || lease->id->equals(lease->id, id)))
+ {
+ if (index)
+ {
+ *index = i;
+ }
+ return lease;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Find a lease by offset that is not owned by the given IKE_SA
+ */
+static lease_t *find_lease_other(entry_t *entry, int offset, ike_sa_id_t *id,
+ int *index)
+{
+ lease_t *lease;
+ int i;
+
+ for (i = 0; i < array_count(entry->leases); i++)
+ {
+ array_get(entry->leases, i, &lease);
+
+ if (lease->offset == offset && !lease->id->equals(lease->id, id))
+ {
+ if (index)
+ {
+ *index = i;
+ }
+ return lease;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Release the lease at the given index, clears the offset if no further
+ * references are found (returns TRUE in that case)
+ */
+static bool release_lease(pool_t *pool, entry_t *entry, int index)
+{
+ lease_t *lease;
+ bool cleared = FALSE;
+
+ array_remove(entry->leases, index, &lease);
+ if (!find_lease(entry, lease->offset, NULL, NULL))
+ {
+ pool->mask[lease->offset / 8] &= ~(1 << (lease->offset % 8));
+ cleared = TRUE;
+ }
+ lease_destroy(lease);
+ return cleared;
+}
+
+/**
+ * Remove and destroy an identity entry if there are no leases
+ */
+static void remove_entry_if_empty(pool_t *pool, entry_t *entry)
+{
+ if (!array_count(entry->leases))
+ {
+ pool->leases->remove(pool->leases, entry->id);
+ entry_destroy(entry);
+ }
+}
+
+/**
+ * Reassign an online lease for the current peer during a make-before-break
+ * reauthentication
+ */
+static host_t *acquire_online(private_ha_attribute_t *this,
+ linked_list_t *pools, ike_sa_t *ike_sa,
+ host_t *requested)
+{
+ enumerator_t *enumerator;
+ pool_t *pool = NULL;
+ entry_t *entry;
+ lease_t *lease, *found = NULL;
+ identification_t *id;
+ ike_sa_id_t *sa;
+ int offset = -1, i;
+ u_int hash;
+ char *name;
+ bool is_any;
+ host_t *address = NULL;
+
+ id = ike_sa->get_other_eap_id(ike_sa);
+ sa = ike_sa->get_id(ike_sa);
+ hash = hash_addr(ike_sa->get_other_host(ike_sa));
+ is_any = requested->is_anyaddr(requested);
+
+ enumerator = pools->create_enumerator(pools);
+ while (enumerator->enumerate(enumerator, &name))
+ {
+ pool = get_pool(this, name);
+ if (!pool ||
+ pool->base->get_family(pool->base) !=
+ requested->get_family(requested))
+ {
+ continue;
+ }
+ if (!is_any)
+ {
+ offset = host2offset(pool, requested);
+ if (!valid_offset(pool, offset) ||
+ !responsible_for(this, offset))
+ {
+ continue;
+ }
+ }
+ entry = pool->leases->get(pool->leases, id);
+ if (!entry)
+ {
+ continue;
+ }
+ for (i = 0; i < array_count(entry->leases); i++)
+ {
+ array_get(entry->leases, i, &lease);
+
+ if ((offset == -1 || offset == lease->offset) &&
+ valid_offset(pool, lease->offset) &&
+ responsible_for(this, lease->offset) &&
+ lease->hash == hash &&
+ !find_lease(entry, lease->offset, sa, NULL) &&
+ (pool->mask[lease->offset / 8] & (1 << (lease->offset % 8))))
+ {
+ found = lease;
+ break;
+ }
+ }
+ if (found)
+ {
+ lease = create_lease(found->offset, ike_sa);
+ array_insert_create(&entry->leases, ARRAY_TAIL, lease);
+ address = offset2host(pool, found->offset);
+ DBG1(DBG_CFG, "reassigned address %H to '%Y' from HA pool '%s'",
+ address, id, name);
+ break;
+ }
+ }
+ enumerator->destroy(enumerator);
+ return address;
+}
+
METHOD(attribute_provider_t, acquire_address, host_t*,
private_ha_attribute_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
host_t *requested)
{
enumerator_t *enumerator;
+ identification_t *id;
pool_t *pool = NULL;
+ entry_t *entry;
+ lease_t *lease;
int offset = -1, tmp_offset, byte, bit;
- host_t *address;
+ host_t *address = NULL;
char *name;
- enumerator = pools->create_enumerator(pools);
this->mutex->lock(this->mutex);
+
+ /* reacquire a lease already owned by the same peer */
+ address = acquire_online(this, pools, ike_sa, requested);
+ if (address)
+ {
+ this->mutex->unlock(this->mutex);
+ return address;
+ }
+
+ id = ike_sa->get_other_eap_id(ike_sa);
+ enumerator = pools->create_enumerator(pools);
while (enumerator->enumerate(enumerator, &name))
{
pool = get_pool(this, name);
@@ -215,6 +527,9 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
{
offset = tmp_offset;
pool->mask[byte] |= 1 << bit;
+ entry = entry_get(pool, id);
+ lease = create_lease(offset, ike_sa);
+ array_insert_create(&entry->leases, ARRAY_TAIL, lease);
break;
}
}
@@ -234,16 +549,16 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
break;
}
}
- this->mutex->unlock(this->mutex);
enumerator->destroy(enumerator);
if (offset != -1)
{
address = offset2host(pool, offset);
- DBG1(DBG_CFG, "acquired address %H from HA pool '%s'", address, name);
- return address;
+ DBG1(DBG_CFG, "acquired address %H for '%Y' from HA pool '%s'",
+ address, id, name);
}
- return NULL;
+ this->mutex->unlock(this->mutex);
+ return address;
}
METHOD(attribute_provider_t, release_address, bool,
@@ -251,32 +566,54 @@ METHOD(attribute_provider_t, release_address, bool,
ike_sa_t *ike_sa)
{
enumerator_t *enumerator;
+ identification_t *id;
pool_t *pool;
- int offset;
+ entry_t *entry;
+ lease_t *lease;
+ int offset, index;
char *name;
bool found = FALSE;
+ id = ike_sa->get_other_eap_id(ike_sa);
+
enumerator = pools->create_enumerator(pools);
this->mutex->lock(this->mutex);
while (enumerator->enumerate(enumerator, &name))
{
pool = get_pool(this, name);
- if (!pool)
+ if (!pool ||
+ pool->base->get_family(pool->base) != address->get_family(address))
{
continue;
}
- if (pool->base->get_family(pool->base) != address->get_family(address))
+ offset = host2offset(pool, address);
+ if (!valid_offset(pool, offset))
{
continue;
}
- offset = host2offset(pool, address);
- if (valid_offset(pool, offset))
+ entry = pool->leases->get(pool->leases, id);
+ if (!entry)
{
- pool->mask[offset / 8] &= ~(1 << (offset % 8));
- DBG1(DBG_CFG, "released address %H to HA pool '%s'", address, name);
- found = TRUE;
- break;
+ continue;
}
+ lease = find_lease(entry, offset, ike_sa->get_id(ike_sa), &index);
+ if (!lease)
+ {
+ continue;
+ }
+ if (release_lease(pool, entry, index))
+ {
+ DBG1(DBG_CFG, "released address %H for '%Y' to HA pool '%s'",
+ address, id, name);
+ }
+ else
+ {
+ DBG2(DBG_CFG, "address %H released by '%Y' still in use in HA "
+ "pool '%s'", address, id, name);
+ }
+ remove_entry_if_empty(pool, entry);
+ found = TRUE;
+ break;
}
this->mutex->unlock(this->mutex);
enumerator->destroy(enumerator);
@@ -285,11 +622,16 @@ METHOD(attribute_provider_t, release_address, bool,
}
METHOD(ha_attribute_t, reserve, void,
- private_ha_attribute_t *this, char *name, host_t *address)
+ private_ha_attribute_t *this, ike_sa_t *ike_sa, char *name, host_t *address)
{
+ identification_t *id;
pool_t *pool;
+ entry_t *entry;
+ lease_t *lease;
int offset;
+ id = ike_sa->get_other_eap_id(ike_sa);
+
this->mutex->lock(this->mutex);
pool = get_pool(this, name);
if (pool)
@@ -298,9 +640,209 @@ METHOD(ha_attribute_t, reserve, void,
if (valid_offset(pool, offset))
{
pool->mask[offset / 8] |= 1 << (offset % 8);
- DBG1(DBG_CFG, "reserved address %H in HA pool '%s'", address, name);
+ entry = entry_get(pool, id);
+ if (!find_lease(entry, offset, ike_sa->get_id(ike_sa), NULL))
+ {
+ lease = create_lease(offset, ike_sa);
+ array_insert_create(&entry->leases, ARRAY_TAIL, lease);
+ }
+ DBG1(DBG_CFG, "reserved address %H for '%Y' in HA pool '%s'",
+ address, id, name);
+ }
+ }
+ this->mutex->unlock(this->mutex);
+}
+
+METHOD(ha_attribute_t, migrate, void,
+ private_ha_attribute_t *this, ike_sa_t *old, ike_sa_t *new)
+{
+ enumerator_t *vips;
+ ike_sa_id_t *old_id, *new_id;
+ identification_t *id;
+ host_t *vip;
+ pool_t *pool;
+ entry_t *entry;
+ lease_t *lease;
+ int offset;
+
+ old_id = old->get_id(old);
+ new_id = new->get_id(new);
+ if (old_id->equals(old_id, new_id))
+ {
+ return;
+ }
+ id = old->get_other_eap_id(old);
+
+ this->mutex->lock(this->mutex);
+ vips = new->create_virtual_ip_enumerator(new, FALSE);
+ while (vips->enumerate(vips, &vip))
+ {
+ pool = get_pool_by_vip(this, vip, &offset);
+ if (!pool)
+ {
+ continue;
+ }
+ entry = pool->leases->get(pool->leases, id);
+ if (!entry)
+ {
+ continue;
+ }
+ lease = find_lease(entry, offset, old_id, NULL);
+ if (lease)
+ {
+ lease->id->destroy(lease->id);
+ lease->id = new_id->clone(new_id);
+ }
+ }
+ vips->destroy(vips);
+ this->mutex->unlock(this->mutex);
+}
+
+METHOD(ha_attribute_t, update, void,
+ private_ha_attribute_t *this, ike_sa_t *ike_sa, host_t *remote)
+{
+ enumerator_t *pools;
+ ike_sa_id_t *sa;
+ identification_t *id;
+ pool_t *pool;
+ entry_t *entry;
+ lease_t *lease;
+ u_int hash;
+ int i;
+
+ id = ike_sa->get_other_eap_id(ike_sa);
+ sa = ike_sa->get_id(ike_sa);
+ hash = hash_addr(remote);
+
+ this->mutex->lock(this->mutex);
+ pools = this->pools->create_enumerator(this->pools);
+ while (pools->enumerate(pools, &pool))
+ {
+ entry = pool->leases->get(pool->leases, id);
+ if (!entry)
+ {
+ continue;
+ }
+ for (i = 0; i < array_count(entry->leases); i++)
+ {
+ array_get(entry->leases, i, &lease);
+ if (lease->id->equals(lease->id, sa))
+ {
+ lease->hash = hash;
+ }
+ }
+ }
+ pools->destroy(pools);
+ this->mutex->unlock(this->mutex);
+}
+
+METHOD(ha_attribute_t, adopt, void,
+ private_ha_attribute_t *this, ike_sa_t *ike_sa)
+{
+ enumerator_t *vips;
+ ike_sa_id_t *sa;
+ identification_t *id;
+ host_t *vip;
+ pool_t *pool;
+ entry_t *entry;
+ lease_t *lease;
+ int offset;
+
+ id = ike_sa->get_other_eap_id(ike_sa);
+ sa = ike_sa->get_id(ike_sa);
+
+ this->mutex->lock(this->mutex);
+ vips = ike_sa->create_virtual_ip_enumerator(ike_sa, FALSE);
+ while (vips->enumerate(vips, &vip))
+ {
+ pool = get_pool_by_vip(this, vip, &offset);
+ if (!pool)
+ {
+ continue;
+ }
+ entry = pool->leases->get(pool->leases, id);
+ if (!entry)
+ {
+ continue;
+ }
+ if (!find_lease(entry, offset, sa, NULL))
+ {
+ /* add a lease for the new SA, the old SA's lease is removed
+ * when that SA is destroyed */
+ lease = create_lease(offset, ike_sa);
+ array_insert_create(&entry->leases, ARRAY_TAIL, lease);
+ }
+ }
+ vips->destroy(vips);
+ this->mutex->unlock(this->mutex);
+}
+
+/**
+ * Check if the given IKE_SA still owns the virtual IP that corresponds to the
+ * offset
+ */
+static bool owns_offset(pool_t *pool, ike_sa_t *ike_sa, int offset)
+{
+ enumerator_t *vips;
+ host_t *vip;
+ bool found = FALSE;
+
+ vips = ike_sa->create_virtual_ip_enumerator(ike_sa, FALSE);
+ while (vips->enumerate(vips, &vip))
+ {
+ if (offset == host2offset(pool, vip))
+ {
+ found = TRUE;
+ break;
+ }
+ }
+ vips->destroy(vips);
+ return found;
+}
+
+METHOD(ha_attribute_t, cleanup, void,
+ private_ha_attribute_t *this, ike_sa_t *ike_sa)
+{
+ enumerator_t *pools;
+ ike_sa_id_t *sa;
+ identification_t *id;
+ pool_t *pool;
+ entry_t *entry;
+ lease_t *lease;
+ int i;
+
+ id = ike_sa->get_other_eap_id(ike_sa);
+ sa = ike_sa->get_id(ike_sa);
+
+ this->mutex->lock(this->mutex);
+ pools = this->pools->create_enumerator(this->pools);
+ while (pools->enumerate(pools, &pool))
+ {
+ entry = pool->leases->get(pool->leases, id);
+ if (!entry)
+ {
+ continue;
+ }
+ for (i = array_count(entry->leases) - 1; i >= 0; i--)
+ {
+ array_get(entry->leases, i, &lease);
+
+ if (!lease->id->equals(lease->id, sa))
+ {
+ continue;
+ }
+ /* release the lease if another SA still owns the address or if the
+ * VIP got cleared from the SA (IKEv1 adoption), so it won't get
+ * released regularly */
+ if (find_lease_other(entry, lease->offset, sa, NULL) ||
+ !owns_offset(pool, ike_sa, lease->offset))
+ {
+ release_lease(pool, entry, i);
+ }
}
+ remove_entry_if_empty(pool, entry);
}
+ pools->destroy(pools);
this->mutex->unlock(this->mutex);
}
@@ -365,6 +907,7 @@ static void load_pools(private_ha_attribute_t *this)
.name = strdup(name),
.base = base,
.size = (1 << mask),
+ .leases = hashtable_create(entry_hash, entry_equals, 8),
);
pool->mask = calloc(pool->size / 8, 1);
/* do not use first/last address of pool */
@@ -393,6 +936,10 @@ ha_attribute_t *ha_attribute_create(ha_kernel_t *kernel, ha_segments_t *segments
.create_attribute_enumerator = (void*)enumerator_create_empty,
},
.reserve = _reserve,
+ .migrate = _migrate,
+ .update = _update,
+ .adopt = _adopt,
+ .cleanup = _cleanup,
.destroy = _destroy,
},
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
diff --git a/src/libcharon/plugins/ha/ha_attribute.h b/src/libcharon/plugins/ha/ha_attribute.h
index 382312bd56..700c53ae04 100644
--- a/src/libcharon/plugins/ha/ha_attribute.h
+++ b/src/libcharon/plugins/ha/ha_attribute.h
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2026 Tobias Brunner
* Copyright (C) 2010 Martin Willi
*
* Copyright (C) secunet Security Networks AG
@@ -42,10 +43,53 @@ struct ha_attribute_t {
/**
* Reserve an address for a passive IKE_SA.
*
+ * @param ike_sa passive IKE_SA the address is reserved for
* @param name pool name to reserve address in
* @param address address to reserve
*/
- void (*reserve)(ha_attribute_t *this, char *name, host_t *address);
+ void (*reserve)(ha_attribute_t *this, ike_sa_t *ike_sa, char *name,
+ host_t *address);
+
+ /**
+ * Migrate address ownership from one IKE_SA to another.
+ *
+ * Used when IKE rekeying moves remote virtual IPs from an old SA to the
+ * new one without releasing them to the pool.
+ *
+ * @param old old IKE_SA
+ * @param new new IKE_SA that inherits the virtual IPs
+ */
+ void (*migrate)(ha_attribute_t *this, ike_sa_t *old, ike_sa_t *new);
+
+ /**
+ * Update the remote endpoint hash associated with leases of an SA so
+ * make-before-break reauth can reassign the same virtual IP later.
+ *
+ * @param ike_sa IKE_SA that changed
+ * @param remote new remote endpoint
+ */
+ void (*update)(ha_attribute_t *this, ike_sa_t *ike_sa, host_t *remote);
+
+ /**
+ * Let leases get adopted by the given IKE_SA.
+ *
+ * This is only used for IKEv1 to cover the multiple adopt/migrate VIPs
+ * paths.
+ *
+ * @param ike_sa new IKE_SA that adopted the virtual IPs
+ */
+ void (*adopt)(ha_attribute_t *this, ike_sa_t *ike_sa);
+
+ /**
+ * Cleanup leases owned by the given IKE_SA if another still owns the same
+ * address or if it can't release them itself later.
+ *
+ * This is only used by IKEv1 to handle VIPs that were adopted without being
+ * released.
+ *
+ * @param ike_sa IKE_SA for which to release virtual IPs
+ */
+ void (*cleanup)(ha_attribute_t *this, ike_sa_t *ike_sa);
/**
* Destroy a ha_attribute_t.
diff --git a/src/libcharon/plugins/ha/ha_dispatcher.c b/src/libcharon/plugins/ha/ha_dispatcher.c
index dfe84ad85b..db72ac739d 100644
--- a/src/libcharon/plugins/ha/ha_dispatcher.c
+++ b/src/libcharon/plugins/ha/ha_dispatcher.c
@@ -321,6 +321,7 @@ static void process_ike_add(private_ha_dispatcher_t *this, ha_message_t *message
ike_sa);
ike_sa->inherit_pre(ike_sa, old_sa);
ike_sa->inherit_post(ike_sa, old_sa);
+ this->attr->migrate(this->attr, old_sa, ike_sa);
charon->ike_sa_manager->checkin_and_destroy(
charon->ike_sa_manager, old_sa);
old_sa = NULL;
@@ -522,7 +523,7 @@ static void process_ike_update(private_ha_dispatcher_t *this,
vips = ike_sa->create_virtual_ip_enumerator(ike_sa, FALSE);
while (vips->enumerate(vips, &vip))
{
- this->attr->reserve(this->attr, pool, vip);
+ this->attr->reserve(this->attr, ike_sa, pool, vip);
}
vips->destroy(vips);
}
diff --git a/src/libcharon/plugins/ha/ha_ike.c b/src/libcharon/plugins/ha/ha_ike.c
index df0ad25d9a..a2ddb3f9db 100644
--- a/src/libcharon/plugins/ha/ha_ike.c
+++ b/src/libcharon/plugins/ha/ha_ike.c
@@ -46,6 +46,11 @@ struct private_ha_ike_t {
* message cache
*/
ha_cache_t *cache;
+
+ /**
+ * HA enabled pool
+ */
+ ha_attribute_t *attr;
};
/**
@@ -243,11 +248,38 @@ METHOD(listener_t, ike_updown, bool,
METHOD(listener_t, ike_rekey, bool,
private_ha_ike_t *this, ike_sa_t *old, ike_sa_t *new)
{
+ if (this->tunnel && this->tunnel->is_sa(this->tunnel, old))
+ { /* do not sync SA between nodes */
+ return TRUE;
+ }
+ this->attr->migrate(this->attr, old, new);
ike_updown(this, old, FALSE);
ike_updown(this, new, TRUE);
return TRUE;
}
+METHOD(listener_t, ike_update, bool,
+ private_ha_ike_t *this, ike_sa_t *ike_sa, host_t *local, host_t *remote)
+{
+ if (this->tunnel && this->tunnel->is_sa(this->tunnel, ike_sa))
+ { /* do not sync SA between nodes */
+ return TRUE;
+ }
+ /* address updates are currently only effective on the active node */
+ this->attr->update(this->attr, ike_sa, remote);
+ return TRUE;
+}
+
+METHOD(listener_t, assign_vips, bool,
+ private_ha_ike_t *this, ike_sa_t *ike_sa, bool assign)
+{
+ if (assign && ike_sa->get_version(ike_sa) == IKEV1)
+ {
+ this->attr->adopt(this->attr, ike_sa);
+ }
+ return TRUE;
+}
+
METHOD(listener_t, alert, bool,
private_ha_ike_t *this, ike_sa_t *ike_sa, alert_t alert, va_list args)
{
@@ -265,10 +297,16 @@ METHOD(listener_t, alert, bool,
METHOD(listener_t, ike_state_change, bool,
private_ha_ike_t *this, ike_sa_t *ike_sa, ike_sa_state_t new)
{
- /* delete any remaining cache entry if IKE_SA gets destroyed */
if (new == IKE_DESTROYING)
{
+ /* delete any remaining cache entry if IKE_SA gets destroyed */
this->cache->delete(this->cache, ike_sa);
+
+ /* remove leases of adopted VIPs for IKEv1 only */
+ if (ike_sa->get_version(ike_sa) == IKEV1)
+ {
+ this->attr->cleanup(this->attr, ike_sa);
+ }
}
return TRUE;
}
@@ -403,7 +441,7 @@ METHOD(ha_ike_t, destroy, void,
* See header
*/
ha_ike_t *ha_ike_create(ha_socket_t *socket, ha_tunnel_t *tunnel,
- ha_cache_t *cache)
+ ha_cache_t *cache, ha_attribute_t *attr)
{
private_ha_ike_t *this;
@@ -414,6 +452,8 @@ ha_ike_t *ha_ike_create(ha_socket_t *socket, ha_tunnel_t *tunnel,
.ike_keys = _ike_keys,
.ike_updown = _ike_updown,
.ike_rekey = _ike_rekey,
+ .ike_update = _ike_update,
+ .assign_vips = _assign_vips,
.ike_state_change = _ike_state_change,
.message = _message_hook,
},
@@ -422,6 +462,7 @@ ha_ike_t *ha_ike_create(ha_socket_t *socket, ha_tunnel_t *tunnel,
.socket = socket,
.tunnel = tunnel,
.cache = cache,
+ .attr = attr,
);
return &this->public;
diff --git a/src/libcharon/plugins/ha/ha_ike.h b/src/libcharon/plugins/ha/ha_ike.h
index 7d51d21885..cf063cca17 100644
--- a/src/libcharon/plugins/ha/ha_ike.h
+++ b/src/libcharon/plugins/ha/ha_ike.h
@@ -28,6 +28,7 @@ typedef struct ha_ike_t ha_ike_t;
#include "ha_tunnel.h"
#include "ha_segments.h"
#include "ha_cache.h"
+#include "ha_attribute.h"
#include <daemon.h>
@@ -53,9 +54,10 @@ struct ha_ike_t {
* @param socket socket to use for sending synchronization messages
* @param tunnel tunnel securing sync messages, if any
* @param cache message cache
+ * @param attr HA enabled pool
* @return IKE listener
*/
ha_ike_t *ha_ike_create(ha_socket_t *socket, ha_tunnel_t *tunnel,
- ha_cache_t *cache);
+ ha_cache_t *cache, ha_attribute_t *attr);
#endif /** HA_IKE_ @}*/
diff --git a/src/libcharon/plugins/ha/ha_plugin.c b/src/libcharon/plugins/ha/ha_plugin.c
index fc2814036c..643c1cbb67 100644
--- a/src/libcharon/plugins/ha/ha_plugin.c
+++ b/src/libcharon/plugins/ha/ha_plugin.c
@@ -147,7 +147,8 @@ static bool initialize_plugin(private_ha_plugin_t *this)
this->attr = ha_attribute_create(this->kernel, this->segments);
this->dispatcher = ha_dispatcher_create(this->socket, this->segments,
this->cache, this->kernel, this->attr);
- this->ike = ha_ike_create(this->socket, this->tunnel, this->cache);
+ this->ike = ha_ike_create(this->socket, this->tunnel, this->cache,
+ this->attr);
this->child = ha_child_create(this->socket, this->tunnel, this->segments,
this->kernel);
return TRUE;