Merge branch 'unique-sas'
Makes IKE_SA unique ID and CHILD_SA reqid counters atomic.
This commit is contained in:
@@ -1083,7 +1083,7 @@ METHOD(child_sa_t, destroy, void,
|
|||||||
child_sa_t * child_sa_create(host_t *me, host_t* other,
|
child_sa_t * child_sa_create(host_t *me, host_t* other,
|
||||||
child_cfg_t *config, u_int32_t rekey, bool encap)
|
child_cfg_t *config, u_int32_t rekey, bool encap)
|
||||||
{
|
{
|
||||||
static u_int32_t reqid = 0;
|
static refcount_t reqid = 0;
|
||||||
private_child_sa_t *this;
|
private_child_sa_t *this;
|
||||||
|
|
||||||
INIT(this,
|
INIT(this,
|
||||||
@@ -1142,7 +1142,14 @@ child_sa_t * child_sa_create(host_t *me, host_t* other,
|
|||||||
if (!this->reqid)
|
if (!this->reqid)
|
||||||
{
|
{
|
||||||
/* reuse old reqid if we are rekeying an existing CHILD_SA */
|
/* reuse old reqid if we are rekeying an existing CHILD_SA */
|
||||||
this->reqid = rekey ? rekey : ++reqid;
|
if (rekey)
|
||||||
|
{
|
||||||
|
this->reqid = rekey;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->reqid = ref_get(&reqid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->mark_in.value == MARK_REQID)
|
if (this->mark_in.value == MARK_REQID)
|
||||||
|
|||||||
@@ -2169,7 +2169,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
|
|||||||
ike_version_t version)
|
ike_version_t version)
|
||||||
{
|
{
|
||||||
private_ike_sa_t *this;
|
private_ike_sa_t *this;
|
||||||
static u_int32_t unique_id = 0;
|
static refcount_t unique_id = 0;
|
||||||
|
|
||||||
if (version == IKE_ANY)
|
if (version == IKE_ANY)
|
||||||
{ /* prefer IKEv2 if protocol not specified */
|
{ /* prefer IKEv2 if protocol not specified */
|
||||||
@@ -2281,7 +2281,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
|
|||||||
.other_auth = auth_cfg_create(),
|
.other_auth = auth_cfg_create(),
|
||||||
.my_auths = linked_list_create(),
|
.my_auths = linked_list_create(),
|
||||||
.other_auths = linked_list_create(),
|
.other_auths = linked_list_create(),
|
||||||
.unique_id = ++unique_id,
|
.unique_id = ref_get(&unique_id),
|
||||||
.peer_addresses = linked_list_create(),
|
.peer_addresses = linked_list_create(),
|
||||||
.my_vips = linked_list_create(),
|
.my_vips = linked_list_create(),
|
||||||
.other_vips = linked_list_create(),
|
.other_vips = linked_list_create(),
|
||||||
|
|||||||
@@ -466,11 +466,15 @@ static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
/**
|
/**
|
||||||
* Increase refcount
|
* Increase refcount
|
||||||
*/
|
*/
|
||||||
void ref_get(refcount_t *ref)
|
refcount_t ref_get(refcount_t *ref)
|
||||||
{
|
{
|
||||||
|
refcount_t current;
|
||||||
|
|
||||||
pthread_mutex_lock(&ref_mutex);
|
pthread_mutex_lock(&ref_mutex);
|
||||||
(*ref)++;
|
current = ++(*ref);
|
||||||
pthread_mutex_unlock(&ref_mutex);
|
pthread_mutex_unlock(&ref_mutex);
|
||||||
|
|
||||||
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -661,7 +661,7 @@ typedef volatile u_int refcount_t;
|
|||||||
|
|
||||||
#ifdef HAVE_GCC_ATOMIC_OPERATIONS
|
#ifdef HAVE_GCC_ATOMIC_OPERATIONS
|
||||||
|
|
||||||
#define ref_get(ref) {__sync_fetch_and_add(ref, 1); }
|
#define ref_get(ref) __sync_add_and_fetch(ref, 1)
|
||||||
#define ref_put(ref) (!__sync_sub_and_fetch(ref, 1))
|
#define ref_put(ref) (!__sync_sub_and_fetch(ref, 1))
|
||||||
|
|
||||||
#define cas_bool(ptr, oldval, newval) \
|
#define cas_bool(ptr, oldval, newval) \
|
||||||
@@ -677,8 +677,9 @@ typedef volatile u_int refcount_t;
|
|||||||
* Increments the reference counter atomic.
|
* Increments the reference counter atomic.
|
||||||
*
|
*
|
||||||
* @param ref pointer to ref counter
|
* @param ref pointer to ref counter
|
||||||
|
* @return new value of ref
|
||||||
*/
|
*/
|
||||||
void ref_get(refcount_t *ref);
|
refcount_t ref_get(refcount_t *ref);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put back a unused reference.
|
* Put back a unused reference.
|
||||||
|
|||||||
Reference in New Issue
Block a user