#include <daemon.h>
#include <collections/hashtable.h>
+#include <collections/array.h>
#include <assert.h>
kernel_ipsec_t public;
/**
+ * Rekey listener
+ */
+ listener_t listener;
+
+ /**
* Allocated SPI
*/
refcount_t spi;
return SUCCESS;
}
+METHOD(listener_t, ike_rekey, bool,
+ listener_t *listener, ike_sa_t *old, ike_sa_t *new)
+{
+ enumerator_t *enumerator;
+ array_t *sas = NULL;
+ entry_t *entry;
+
+ enumerator = instance->sas->create_enumerator(instance->sas);
+ while (enumerator->enumerate(enumerator, &entry, NULL))
+ {
+ if (entry->ike_sa == old)
+ {
+ instance->sas->remove_at(instance->sas, enumerator);
+ array_insert_create(&sas, ARRAY_TAIL, entry);
+ }
+ }
+ enumerator->destroy(enumerator);
+ enumerator = array_create_enumerator(sas);
+ while (enumerator->enumerate(enumerator, &entry))
+ {
+ array_remove_at(sas, enumerator);
+ entry->ike_sa = new;
+ entry = instance->sas->put(instance->sas, entry, entry);
+ assert(!entry);
+ }
+ enumerator->destroy(enumerator);
+ array_destroy(sas);
+ return TRUE;
+}
+
METHOD(kernel_ipsec_t, add_policy, status_t,
private_kernel_ipsec_t *this, kernel_ipsec_policy_id_t *id,
kernel_ipsec_manage_policy_t *data)
METHOD(kernel_ipsec_t, destroy, void,
private_kernel_ipsec_t *this)
{
+ charon->bus->remove_listener(charon->bus, &this->listener);
this->sas->destroy(this->sas);
free(this);
}
.enable_udp_decap = (void*)return_true,
.destroy = _destroy,
},
+ .listener = {
+ .ike_rekey = _ike_rekey,
+ },
.sas = hashtable_create(entry_hash, entry_equals, 8),
);
instance = this;
+ charon->bus->add_listener(charon->bus, &this->listener);
+
return &this->public;
}