Add tuple2 & tuple4 & tuple5 & tuple6

This commit is contained in:
luwenpeng
2023-12-15 16:34:53 +08:00
parent 90a6936fd6
commit 7653d646d3
13 changed files with 914 additions and 312 deletions

View File

@@ -20,24 +20,24 @@ struct session_table
* Private API
******************************************************************************/
static void HASH_FUNCTION_OVERWRITE(const struct session_key *key, unsigned int keylen, uint32_t *hashv)
static void HASH_FUNCTION_OVERWRITE(const struct tuple6 *tuple, unsigned int keylen, uint32_t *hashv)
{
*hashv = session_key_hash(key);
*hashv = tuple6_hash(tuple);
}
static int HASH_KEYCMP_OVERWRITE(const void *key1, const void *key2, size_t len)
static int HASH_KEYCMP_OVERWRITE(const void *key_a, const void *key_b, size_t len)
{
struct session_key *sess_key1 = (struct session_key *)key1;
struct session_key *sess_key2 = (struct session_key *)key2;
struct tuple6 *tuple_a = (struct tuple6 *)key_a;
struct tuple6 *tuple_b = (struct tuple6 *)key_b;
if (session_key_cmp(sess_key1, sess_key2) == 0)
if (tuple6_cmp(tuple_a, tuple_b) == 0)
{
return 0;
}
struct session_key reverse_key;
session_key_reverse(sess_key2, &reverse_key);
if (session_key_cmp(sess_key1, &reverse_key) == 0)
struct tuple6 reversed;
tuple6_reverse(tuple_b, &reversed);
if (tuple6_cmp(tuple_a, &reversed) == 0)
{
return 0;
}
@@ -153,33 +153,33 @@ void session_table_set_freecb(struct session_table *table, session_free_cb free_
}
}
int session_table_add_session(struct session_table *table, const struct session_key *key, struct session *sess)
int session_table_add_session(struct session_table *table, const struct tuple6 *tuple, struct session *sess)
{
if (table == NULL || sess == NULL)
{
return -1;
}
if (session_table_find_session(table, key))
if (session_table_find_session(table, tuple))
{
return -1;
}
HASH_ADD(hh, table->root, key, sizeof(sess->key), sess);
HASH_ADD(hh, table->root, tuple, sizeof(sess->tuple), sess);
session_table_add_session_to_linklist(table, sess);
table->count++;
return 0;
}
void session_table_delete_session(struct session_table *table, const struct session_key *key)
void session_table_delete_session(struct session_table *table, const struct tuple6 *tuple)
{
if (table == NULL)
{
return;
}
struct session *sess = session_table_find_session(table, key);
struct session *sess = session_table_find_session(table, tuple);
if (sess == NULL)
{
return;
@@ -194,7 +194,7 @@ void session_table_delete_session(struct session_table *table, const struct sess
table->count--;
}
struct session *session_table_find_session(struct session_table *table, const struct session_key *key)
struct session *session_table_find_session(struct session_table *table, const struct tuple6 *tuple)
{
if (table == NULL)
{
@@ -202,7 +202,7 @@ struct session *session_table_find_session(struct session_table *table, const st
}
struct session *sess = NULL;
HASH_FIND(hh, table->root, key, sizeof(struct session_key), sess);
HASH_FIND(hh, table->root, tuple, sizeof(struct tuple6), sess);
return sess;
}