#include "ha_sync_segments.h"
+#include <utils/mutex.h>
#include <utils/linked_list.h>
typedef u_int32_t u32;
*/
ha_sync_segments_t public;
+ /**
+ * read/write lock for segment manipulation
+ */
+ rwlock_t *lock;
+
/**
* Init value for jhash
*/
enumerator_t *enumerator;
u_int i, limit;
+ this->lock->write_lock(this->lock);
+
if (segment == 0 || segment <= this->segment_count)
{
if (segment)
log_segments(this, enable, segment);
}
+
+ this->lock->unlock(this->lock);
}
/**
ike_sa_id_t *id;
u_int16_t mask = bit_of(segment);
+ list = linked_list_create();
+ this->lock->read_lock(this->lock);
+
if (segment > 0 && segment <= this->segment_count && (this->active & mask))
{
this->active &= ~mask;
- list = linked_list_create();
DBG1(DBG_CFG, "resyncing HA sync segment %d", segment);
}
}
enumerator->destroy(enumerator);
+ }
+ this->lock->unlock(this->lock);
- while (list->remove_last(list, (void**)&id) == SUCCESS)
+ while (list->remove_last(list, (void**)&id) == SUCCESS)
+ {
+ ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, id);
+ id->destroy(id);
+ if (ike_sa)
{
- ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, id);
- id->destroy(id);
- if (ike_sa)
+ DBG1(DBG_CFG, "resyncing IKE_SA");
+ if (ike_sa->rekey(ike_sa) != DESTROY_ME)
{
- DBG1(DBG_CFG, "resyncing IKE_SA");
- if (ike_sa->rekey(ike_sa) != DESTROY_ME)
+ if (rekey_children(ike_sa) != DESTROY_ME)
{
- if (rekey_children(ike_sa) != DESTROY_ME)
- {
- charon->ike_sa_manager->checkin(
- charon->ike_sa_manager, ike_sa);
- continue;
- }
+ charon->ike_sa_manager->checkin(
+ charon->ike_sa_manager, ike_sa);
+ continue;
}
- charon->ike_sa_manager->checkin_and_destroy(
- charon->ike_sa_manager, ike_sa);
}
+ charon->ike_sa_manager->checkin_and_destroy(
+ charon->ike_sa_manager, ike_sa);
}
- list->destroy(list);
}
+ list->destroy(list);
}
/**
*/
static void destroy(private_ha_sync_segments_t *this)
{
+ this->lock->destroy(this->lock);
free(this);
}
this->public.resync = (void(*)(ha_sync_segments_t*, u_int segment))resync;
this->public.destroy = (void(*)(ha_sync_segments_t*))destroy;
+ this->lock = rwlock_create(RWLOCK_TYPE_DEFAULT);
this->initval = 0;
this->active = 0;
this->segment_count = lib->settings->get_int(lib->settings,