TSG-13837 支持decrypted traffic steering/mirroring,并重构packet_io

This commit is contained in:
luwenpeng
2023-03-14 16:10:44 +08:00
parent 29755f2162
commit 0e85d3c9c5
26 changed files with 1960 additions and 1941 deletions

View File

@@ -2,7 +2,6 @@
#include "session_table.h"
#include "utils.h"
#include "log.h"
struct session_table
{
@@ -33,9 +32,9 @@ void session_table_destory(struct session_table *table)
HASH_DELETE(hh1, table->root_by_id, node);
HASH_DELETE(hh2, table->root_by_addr, node);
if (node->val_freecb && node->val_data)
if (node->value_free_cb && node->value)
{
node->val_freecb(node->val_data);
node->value_free_cb(node->value);
}
free(node);
@@ -58,9 +57,9 @@ void session_table_reset(struct session_table *table)
HASH_DELETE(hh1, table->root_by_id, node);
HASH_DELETE(hh2, table->root_by_addr, node);
if (node->val_freecb && node->val_data)
if (node->value_free_cb && node->value)
{
node->val_freecb(node->val_data);
node->value_free_cb(node->value);
}
free(node);
@@ -84,14 +83,13 @@ uint64_t session_table_count(struct session_table *table)
}
// session_addr : deep copy
// val_data : shallow copy (malloc by user, free by val_freecb)
int session_table_insert(struct session_table *table, uint64_t session_id, const struct addr_tuple4 *session_addr, void *val_data, const fn_free_cb *val_freecb)
// value : shallow copy (malloc by user, free by value_free_cb)
int session_table_insert(struct session_table *table, uint64_t session_id, const struct addr_tuple4 *session_addr, void *value, const fn_free_cb *value_free_cb)
{
struct session_node *temp = NULL;
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
if (temp)
{
LOG_DEBUG("%s: insert: key %lu exists", LOG_TAG_STABLE, session_id);
return -1;
}
@@ -100,13 +98,12 @@ int session_table_insert(struct session_table *table, uint64_t session_id, const
temp->session_id = session_id;
memcpy(&temp->session_addr, session_addr, sizeof(struct addr_tuple4));
temp->val_data = val_data;
temp->val_freecb = val_freecb;
temp->value = value;
temp->value_free_cb = value_free_cb;
HASH_ADD(hh1, table->root_by_id, session_id, sizeof(temp->session_id), temp);
HASH_ADD(hh2, table->root_by_addr, session_addr, sizeof(temp->session_addr), temp);
LOG_DEBUG("%s: insert: key %lu success", LOG_TAG_STABLE, session_id);
table->session_node_count++;
return 0;
@@ -118,23 +115,21 @@ int session_table_delete_by_id(struct session_table *table, uint64_t session_id)
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
if (!temp)
{
LOG_DEBUG("%s: delete: key %lu not exists", LOG_TAG_STABLE, session_id);
return -1;
}
HASH_DELETE(hh1, table->root_by_id, temp);
HASH_DELETE(hh2, table->root_by_addr, temp);
if (temp->val_freecb && temp->val_data)
if (temp->value_free_cb && temp->value)
{
temp->val_freecb(temp->val_data);
temp->val_data = NULL;
temp->value_free_cb(temp->value);
temp->value = NULL;
}
free(temp);
temp = NULL;
LOG_DEBUG("%s: delete: key %lu success", LOG_TAG_STABLE, session_id);
table->session_node_count--;
return 0;
@@ -143,7 +138,6 @@ 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 addr_tuple4 *session_addr)
{
struct session_node *temp = NULL;
char *addr_str = addr_tuple4_to_str(session_addr);
HASH_FIND(hh2, table->root_by_addr, session_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
@@ -152,8 +146,6 @@ int session_table_delete_by_addr(struct session_table *table, const struct addr_
HASH_FIND(hh2, table->root_by_addr, &reverse_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
LOG_DEBUG("%s: delete: key %s not exists", LOG_TAG_STABLE, addr_str);
free(addr_str);
return -1;
}
}
@@ -161,18 +153,15 @@ int session_table_delete_by_addr(struct session_table *table, const struct addr_
HASH_DELETE(hh1, table->root_by_id, temp);
HASH_DELETE(hh2, table->root_by_addr, temp);
if (temp->val_freecb && temp->val_data)
if (temp->value_free_cb && temp->value)
{
temp->val_freecb(temp->val_data);
temp->val_data = NULL;
temp->value_free_cb(temp->value);
temp->value = NULL;
}
free(temp);
temp = NULL;
LOG_DEBUG("%s: delete: key %s success", LOG_TAG_STABLE, addr_str);
free(addr_str);
addr_str = NULL;
table->session_node_count--;
return 0;
@@ -184,19 +173,15 @@ struct session_node *session_table_search_by_id(struct session_table *table, uin
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
if (!temp)
{
LOG_DEBUG("%s: search: key %lu not exists", LOG_TAG_STABLE, session_id);
return NULL;
}
LOG_DEBUG("%s: search: key %lu success", LOG_TAG_STABLE, session_id);
return temp;
}
struct session_node *session_table_search_by_addr(struct session_table *table, const struct addr_tuple4 *session_addr)
{
struct session_node *temp = NULL;
char *addr_str = addr_tuple4_to_str(session_addr);
HASH_FIND(hh2, table->root_by_addr, session_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
@@ -205,16 +190,9 @@ struct session_node *session_table_search_by_addr(struct session_table *table, c
HASH_FIND(hh2, table->root_by_addr, &reverse_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
LOG_DEBUG("%s: search: key %s not exists", LOG_TAG_STABLE, addr_str);
free(addr_str);
addr_str = NULL;
return NULL;
}
}
LOG_DEBUG("%s: search: key %s success", LOG_TAG_STABLE, addr_str);
free(addr_str);
addr_str = NULL;
return temp;
}