Implemented table of init hashes without linked_list_t.
This commit is contained in:
@@ -366,7 +366,7 @@ struct private_ike_sa_manager_t {
|
|||||||
/**
|
/**
|
||||||
* Hash table with chunk_t objects.
|
* Hash table with chunk_t objects.
|
||||||
*/
|
*/
|
||||||
linked_list_t **init_hashes_table;
|
table_item_t **init_hashes_table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Segments of the "hashes" hash table.
|
* Segments of the "hashes" hash table.
|
||||||
@@ -939,8 +939,7 @@ static void remove_connected_peers(private_ike_sa_manager_t *this, entry_t *entr
|
|||||||
static bool check_and_put_init_hash(private_ike_sa_manager_t *this,
|
static bool check_and_put_init_hash(private_ike_sa_manager_t *this,
|
||||||
chunk_t init_hash)
|
chunk_t init_hash)
|
||||||
{
|
{
|
||||||
chunk_t *clone;
|
table_item_t *item;
|
||||||
linked_list_t *list;
|
|
||||||
u_int row, segment;
|
u_int row, segment;
|
||||||
mutex_t *mutex;
|
mutex_t *mutex;
|
||||||
chunk_t *chunk;
|
chunk_t *chunk;
|
||||||
@@ -949,28 +948,28 @@ static bool check_and_put_init_hash(private_ike_sa_manager_t *this,
|
|||||||
segment = row & this->segment_mask;
|
segment = row & this->segment_mask;
|
||||||
mutex = this->init_hashes_segments[segment].mutex;
|
mutex = this->init_hashes_segments[segment].mutex;
|
||||||
mutex->lock(mutex);
|
mutex->lock(mutex);
|
||||||
list = this->init_hashes_table[row];
|
item = this->init_hashes_table[row];
|
||||||
if (list)
|
while (item)
|
||||||
{
|
{
|
||||||
chunk_t *current;
|
chunk_t *current = item->value;
|
||||||
|
|
||||||
if (list->find_first(list, (linked_list_match_t)chunk_equals_ptr,
|
if (chunk_equals(init_hash, *current))
|
||||||
(void**)¤t, &init_hash) == SUCCESS)
|
|
||||||
{
|
{
|
||||||
mutex->unlock(mutex);
|
mutex->unlock(mutex);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
item = item->next;
|
||||||
else
|
|
||||||
{
|
|
||||||
list = this->init_hashes_table[row] = linked_list_create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT(chunk,
|
INIT(chunk,
|
||||||
.len = init_hash.len,
|
.len = init_hash.len,
|
||||||
.ptr = init_hash.ptr,
|
.ptr = init_hash.ptr,
|
||||||
);
|
);
|
||||||
list->insert_last(list, chunk);
|
INIT(item,
|
||||||
|
.value = chunk,
|
||||||
|
.next = this->init_hashes_table[row],
|
||||||
|
);
|
||||||
|
this->init_hashes_table[row] = item;
|
||||||
mutex->unlock(mutex);
|
mutex->unlock(mutex);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -980,7 +979,7 @@ static bool check_and_put_init_hash(private_ike_sa_manager_t *this,
|
|||||||
*/
|
*/
|
||||||
static void remove_init_hash(private_ike_sa_manager_t *this, chunk_t init_hash)
|
static void remove_init_hash(private_ike_sa_manager_t *this, chunk_t init_hash)
|
||||||
{
|
{
|
||||||
linked_list_t *list;
|
table_item_t *item, *prev = NULL;
|
||||||
u_int row, segment;
|
u_int row, segment;
|
||||||
mutex_t *mutex;
|
mutex_t *mutex;
|
||||||
|
|
||||||
@@ -988,23 +987,27 @@ static void remove_init_hash(private_ike_sa_manager_t *this, chunk_t init_hash)
|
|||||||
segment = row & this->segment_mask;
|
segment = row & this->segment_mask;
|
||||||
mutex = this->init_hashes_segments[segment].mutex;
|
mutex = this->init_hashes_segments[segment].mutex;
|
||||||
mutex->lock(mutex);
|
mutex->lock(mutex);
|
||||||
list = this->init_hashes_table[row];
|
item = this->init_hashes_table[row];
|
||||||
if (list)
|
while (item)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
chunk_t *current = item->value;
|
||||||
chunk_t *current;
|
|
||||||
|
|
||||||
enumerator = list->create_enumerator(list);
|
if (chunk_equals(init_hash, *current))
|
||||||
while (enumerator->enumerate(enumerator, ¤t))
|
|
||||||
{
|
{
|
||||||
if (chunk_equals_ptr(current, &init_hash))
|
if (prev)
|
||||||
{
|
{
|
||||||
list->remove_at(list, enumerator);
|
prev->next = item->next;
|
||||||
free(current);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->init_hashes_table[row] = item->next;
|
||||||
|
}
|
||||||
|
free(current);
|
||||||
|
free(item);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
prev = item;
|
||||||
|
item = item->next;
|
||||||
}
|
}
|
||||||
mutex->unlock(mutex);
|
mutex->unlock(mutex);
|
||||||
}
|
}
|
||||||
@@ -1879,10 +1882,7 @@ METHOD(ike_sa_manager_t, destroy, void,
|
|||||||
{
|
{
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
for (i = 0; i < this->table_size; i++)
|
/* these are already cleared in flush() above */
|
||||||
{
|
|
||||||
DESTROY_IF(this->init_hashes_table[i]);
|
|
||||||
}
|
|
||||||
free(this->ike_sa_table);
|
free(this->ike_sa_table);
|
||||||
free(this->half_open_table);
|
free(this->half_open_table);
|
||||||
free(this->connected_peers_table);
|
free(this->connected_peers_table);
|
||||||
@@ -2002,7 +2002,7 @@ ike_sa_manager_t *ike_sa_manager_create()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* and again for the table of hashes of seen initial IKE messages */
|
/* and again for the table of hashes of seen initial IKE messages */
|
||||||
this->init_hashes_table = calloc(this->table_size, sizeof(linked_list_t*));
|
this->init_hashes_table = calloc(this->table_size, sizeof(table_item_t*));
|
||||||
this->init_hashes_segments = calloc(this->segment_count, sizeof(segment_t));
|
this->init_hashes_segments = calloc(this->segment_count, sizeof(segment_t));
|
||||||
for (i = 0; i < this->segment_count; i++)
|
for (i = 0; i < this->segment_count; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user