Moved segment configuration parsing to ha_sync_plugin
This commit is contained in:
committed by
Martin Willi
parent
37459ea928
commit
6921e8d5a9
@@ -90,6 +90,29 @@ static void destroy(private_ha_sync_plugin_t *this)
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert segment string to mask
|
||||||
|
*/
|
||||||
|
static segment_mask_t parse_active(char *active)
|
||||||
|
{
|
||||||
|
enumerator_t *enumerator;
|
||||||
|
u_int segment;
|
||||||
|
segment_mask_t mask = 0;
|
||||||
|
|
||||||
|
enumerator = enumerator_create_token(active, ",", " ");
|
||||||
|
while (enumerator->enumerate(enumerator, &active))
|
||||||
|
{
|
||||||
|
segment = atoi(active);
|
||||||
|
if (segment > 0 && segment < SEGMENTS_MAX)
|
||||||
|
{
|
||||||
|
mask |= SEGMENTS_BIT(segment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* see header file
|
* see header file
|
||||||
*/
|
*/
|
||||||
@@ -97,6 +120,8 @@ plugin_t *plugin_create()
|
|||||||
{
|
{
|
||||||
private_ha_sync_plugin_t *this;
|
private_ha_sync_plugin_t *this;
|
||||||
char *local, *remote, *secret;
|
char *local, *remote, *secret;
|
||||||
|
segment_mask_t active;
|
||||||
|
u_int count;
|
||||||
bool fifo;
|
bool fifo;
|
||||||
|
|
||||||
local = lib->settings->get_str(lib->settings,
|
local = lib->settings->get_str(lib->settings,
|
||||||
@@ -107,6 +132,10 @@ plugin_t *plugin_create()
|
|||||||
"charon.plugins.ha_sync.secret", NULL);
|
"charon.plugins.ha_sync.secret", NULL);
|
||||||
fifo = lib->settings->get_bool(lib->settings,
|
fifo = lib->settings->get_bool(lib->settings,
|
||||||
"charon.plugins.ha_sync.fifo_interface", FALSE);
|
"charon.plugins.ha_sync.fifo_interface", FALSE);
|
||||||
|
count = min(SEGMENTS_MAX, lib->settings->get_int(lib->settings,
|
||||||
|
"charon.plugins.ha_sync.segment_count", 1));
|
||||||
|
active = parse_active(lib->settings->get_str(lib->settings,
|
||||||
|
"charon.plugins.ha_sync.active_segments", "1"));
|
||||||
if (!local || !remote)
|
if (!local || !remote)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "HA sync config misses local/remote address");
|
DBG1(DBG_CFG, "HA sync config misses local/remote address");
|
||||||
@@ -125,7 +154,7 @@ plugin_t *plugin_create()
|
|||||||
free(this);
|
free(this);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
this->segments = ha_sync_segments_create(this->socket);
|
this->segments = ha_sync_segments_create(this->socket, count, active);
|
||||||
if (secret)
|
if (secret)
|
||||||
{
|
{
|
||||||
this->tunnel = ha_sync_tunnel_create(secret, local, remote);
|
this->tunnel = ha_sync_tunnel_create(secret, local, remote);
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ typedef u_int8_t u8;
|
|||||||
|
|
||||||
#include <linux/jhash.h>
|
#include <linux/jhash.h>
|
||||||
|
|
||||||
#define MAX_SEGMENTS 16
|
|
||||||
|
|
||||||
typedef struct private_ha_sync_segments_t private_ha_sync_segments_t;
|
typedef struct private_ha_sync_segments_t private_ha_sync_segments_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +58,7 @@ struct private_ha_sync_segments_t {
|
|||||||
/**
|
/**
|
||||||
* mask of active segments
|
* mask of active segments
|
||||||
*/
|
*/
|
||||||
u_int16_t active;
|
segment_mask_t active;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,14 +112,6 @@ static void log_segments(private_ha_sync_segments_t *this, bool activated,
|
|||||||
segment, activated ? "" : "de", buf);
|
segment, activated ? "" : "de", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the bit of the segment in the bitmask
|
|
||||||
*/
|
|
||||||
static inline u_int16_t bit_of(u_int segment)
|
|
||||||
{
|
|
||||||
return 0x01 << (segment - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable/Disable an an IKE_SA.
|
* Enable/Disable an an IKE_SA.
|
||||||
*/
|
*/
|
||||||
@@ -148,11 +138,11 @@ static void enable_disable(private_ha_sync_segments_t *this, u_int segment,
|
|||||||
{
|
{
|
||||||
if (enable)
|
if (enable)
|
||||||
{
|
{
|
||||||
this->active |= bit_of(i);
|
this->active |= SEGMENTS_BIT(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->active &= ~bit_of(i);
|
this->active &= ~SEGMENTS_BIT(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enumerator = charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
|
enumerator = charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
|
||||||
@@ -246,7 +236,7 @@ static void resync(private_ha_sync_segments_t *this, u_int segment)
|
|||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
linked_list_t *list;
|
linked_list_t *list;
|
||||||
ike_sa_id_t *id;
|
ike_sa_id_t *id;
|
||||||
u_int16_t mask = bit_of(segment);
|
u_int16_t mask = SEGMENTS_BIT(segment);
|
||||||
|
|
||||||
list = linked_list_create();
|
list = linked_list_create();
|
||||||
this->lock->read_lock(this->lock);
|
this->lock->read_lock(this->lock);
|
||||||
@@ -309,12 +299,10 @@ static void destroy(private_ha_sync_segments_t *this)
|
|||||||
/**
|
/**
|
||||||
* See header
|
* See header
|
||||||
*/
|
*/
|
||||||
ha_sync_segments_t *ha_sync_segments_create(ha_sync_socket_t *socket)
|
ha_sync_segments_t *ha_sync_segments_create(ha_sync_socket_t *socket,
|
||||||
|
u_int count, segment_mask_t active)
|
||||||
{
|
{
|
||||||
private_ha_sync_segments_t *this = malloc_thing(private_ha_sync_segments_t);
|
private_ha_sync_segments_t *this = malloc_thing(private_ha_sync_segments_t);
|
||||||
enumerator_t *enumerator;
|
|
||||||
u_int segment;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
this->public.activate = (void(*)(ha_sync_segments_t*, u_int segment,bool))activate;
|
this->public.activate = (void(*)(ha_sync_segments_t*, u_int segment,bool))activate;
|
||||||
this->public.deactivate = (void(*)(ha_sync_segments_t*, u_int segment,bool))deactivate;
|
this->public.deactivate = (void(*)(ha_sync_segments_t*, u_int segment,bool))deactivate;
|
||||||
@@ -324,22 +312,8 @@ ha_sync_segments_t *ha_sync_segments_create(ha_sync_socket_t *socket)
|
|||||||
this->socket = socket;
|
this->socket = socket;
|
||||||
this->lock = rwlock_create(RWLOCK_TYPE_DEFAULT);
|
this->lock = rwlock_create(RWLOCK_TYPE_DEFAULT);
|
||||||
this->initval = 0;
|
this->initval = 0;
|
||||||
this->active = 0;
|
this->active = active;
|
||||||
this->segment_count = lib->settings->get_int(lib->settings,
|
this->segment_count = count;
|
||||||
"charon.plugins.ha_sync.segment_count", 1);
|
|
||||||
this->segment_count = min(this->segment_count, MAX_SEGMENTS);
|
|
||||||
str = lib->settings->get_str(lib->settings,
|
|
||||||
"charon.plugins.ha_sync.active_segments", "1");
|
|
||||||
enumerator = enumerator_create_token(str, ",", " ");
|
|
||||||
while (enumerator->enumerate(enumerator, &str))
|
|
||||||
{
|
|
||||||
segment = atoi(str);
|
|
||||||
if (segment > 0 && segment < MAX_SEGMENTS)
|
|
||||||
{
|
|
||||||
this->active |= bit_of(segment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
enumerator->destroy(enumerator);
|
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,18 @@
|
|||||||
|
|
||||||
typedef struct ha_sync_segments_t ha_sync_segments_t;
|
typedef struct ha_sync_segments_t ha_sync_segments_t;
|
||||||
|
|
||||||
|
typedef u_int16_t segment_mask_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* maximum number of segments
|
||||||
|
*/
|
||||||
|
#define SEGMENTS_MAX (sizeof(segment_mask_t)*8)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the bit in the mask of a segment
|
||||||
|
*/
|
||||||
|
#define SEGMENTS_BIT(segment) (0x01 << (segment - 1))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Segmentation of peers into active and passive.
|
* Segmentation of peers into active and passive.
|
||||||
*/
|
*/
|
||||||
@@ -70,8 +82,11 @@ struct ha_sync_segments_t {
|
|||||||
* Create a ha_sync_segments instance.
|
* Create a ha_sync_segments instance.
|
||||||
*
|
*
|
||||||
* @param socket socket to communicate segment (de-)activation
|
* @param socket socket to communicate segment (de-)activation
|
||||||
|
* @param count number of segments the cluster uses
|
||||||
|
* @param active bit mask of initially active segments
|
||||||
* @return segment object
|
* @return segment object
|
||||||
*/
|
*/
|
||||||
ha_sync_segments_t *ha_sync_segments_create(ha_sync_socket_t *socket);
|
ha_sync_segments_t *ha_sync_segments_create(ha_sync_socket_t *socket,
|
||||||
|
u_int count, segment_mask_t active);
|
||||||
|
|
||||||
#endif /* HA_SYNC_SEGMENTS_ @}*/
|
#endif /* HA_SYNC_SEGMENTS_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user