perf: 优化通过四元组查询流表的实现(查表前先根据端口预判是否需要翻转四元组)

This commit is contained in:
luwenpeng
2023-11-28 16:36:58 +08:00
parent 699be92862
commit 95abad41b5
4 changed files with 167 additions and 154 deletions

View File

@@ -9,47 +9,32 @@ extern "C"
#include <stdint.h>
#include <sys/types.h>
#include "uthash.h"
#include "tuple.h"
// Note: session_addr must be initialized by memset(0) before use !!!
typedef void fn_free_cb(void *args);
struct session_node
{
uint64_t session_id; /* first key */
struct four_tuple session_addr; /* second key */
void *value;
fn_free_cb *value_free_cb;
UT_hash_handle hh1; /* handle for first hash table */
UT_hash_handle hh2; /* handle for second hash table */
};
struct session_table;
struct session_table *session_table_create();
void session_table_destory(struct session_table *table);
void session_table_reset(struct session_table *table);
uint64_t session_table_count(struct session_table *table);
// session_addr : deep copy
// value : shallow copy (malloc by user, free by value_free_cb)
// addr : deep copy
// value : shallow copy (malloc by user, free by free_cb)
// Note : addr must be initialized by memset(0) before use !!!
// return 0 : suceess
// return -1 : key exists
int session_table_insert(struct session_table *table, uint64_t session_id, const struct four_tuple *session_addr, void *value, const fn_free_cb *value_free_cb);
int session_table_insert(struct session_table *table, uint64_t id, const struct four_tuple *addr, void *value, const fn_free_cb *free_cb);
// return 0 : success
// return -1 : key not exists
int session_table_delete_by_id(struct session_table *table, uint64_t session_id);
int session_table_delete_by_addr(struct session_table *table, const struct four_tuple *session_addr);
int session_table_delete_by_id(struct session_table *table, uint64_t id);
int session_table_delete_by_addr(struct session_table *table, const struct four_tuple *addr);
// return NULL : key not exists
// return UnNULL : success
struct session_node *session_table_search_by_id(struct session_table *table, uint64_t session_id);
struct session_node *session_table_search_by_addr(struct session_table *table, const struct four_tuple *session_addr);
// return NULL : key not exists
// return value : success
void *session_table_search_by_id(struct session_table *table, uint64_t id);
void *session_table_search_by_addr(struct session_table *table, const struct four_tuple *addr);
#ifdef __cpluscplus
}