OMPUB-1508 For tunnel traffic, asymmetric traffic, and traffic matching the "no intercept" policy, only a session ID index flow table is created

This commit is contained in:
wangmenglan
2024-11-04 15:20:24 +08:00
committed by 王孟岚
parent 13ea52d6d1
commit be0bdc08e3
4 changed files with 172 additions and 27 deletions

View File

@@ -1096,6 +1096,7 @@ static int handle_session_opening(struct metadata *meta, marsio_buff_t *rx_buff,
uint16_t size = 0;
uint8_t is_passthrough = 0;
uint8_t hit_no_intercept = 0;
uint8_t is_session_id_only_key = 0;
uint16_t out_size = 0;
char stream_traceid[24] = {0};
char reason_no_intercept_param[] = "Hit No Intercept Policy";
@@ -1300,6 +1301,10 @@ passthrough:
tuple4_reverse(&inner_tuple4, &s_ctx->c2s_info.tuple4);
}
// is_passthrough为1时只通过session id创建流表避免四元组相同的情况下uthash频繁扩展导致崩溃
if (is_passthrough)
is_session_id_only_key = 1;
// c2s
sids_copy(&s_ctx->c2s_info.sids, &parser->seq_sids);
route_ctx_copy(&s_ctx->c2s_info.route_ctx, &parser->seq_route_ctx);
@@ -1309,7 +1314,7 @@ passthrough:
route_ctx_copy(&s_ctx->s2c_info.route_ctx, &parser->ack_route_ctx);
TFE_LOG_INFO(logger, "%s: session %lu %s active first, hit rule %s", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->session_addr, str_rule_id);
session_table_insert(thread->session_table, s_ctx->session_id, &(s_ctx->c2s_info.tuple4), s_ctx, session_value_free_cb);
session_table_insert(thread->session_table, is_session_id_only_key, s_ctx->session_id, &(s_ctx->c2s_info.tuple4), s_ctx, session_value_free_cb);
ATOMIC_INC(&(packet_io_fs->session_num));
if (parser->seq_header)
FREE(&parser->seq_header);
@@ -1520,9 +1525,11 @@ static int handle_raw_packet_from_nf(struct packet_io *handle, marsio_buff_t *rx
throughput_metrics_inc(&packet_io_fs->raw_bypass, 1, raw_len);
if (memcmp(&inner_addr, &s_ctx->c2s_info.tuple4, sizeof(struct tuple4)) == 0) {
s_ctx->c2s_info.is_e2i_dir = meta.is_e2i_dir;
throughput_metrics_inc(&s_ctx->c2s_info.rx, 1, raw_len);
}
else {
s_ctx->s2c_info.is_e2i_dir = meta.is_e2i_dir;
throughput_metrics_inc(&s_ctx->s2c_info.rx, 1, raw_len);
}

View File

@@ -32,7 +32,10 @@ void session_table_destory(struct session_table *table)
HASH_ITER(hh1, table->root_by_id, node, temp)
{
HASH_DELETE(hh1, table->root_by_id, node);
HASH_DELETE(hh2, table->root_by_addr, node);
if (!node->is_session_id_only_key)
{
HASH_DELETE(hh2, table->root_by_addr, node);
}
if (node->val_freecb && node->val_data)
{
@@ -57,7 +60,10 @@ void session_table_reset(struct session_table *table)
HASH_ITER(hh1, table->root_by_id, node, temp)
{
HASH_DELETE(hh1, table->root_by_id, node);
HASH_DELETE(hh2, table->root_by_addr, node);
if (!node->is_session_id_only_key)
{
HASH_DELETE(hh2, table->root_by_addr, node);
}
if (node->val_freecb && node->val_data)
{
@@ -86,7 +92,7 @@ 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 tuple4 *session_addr, void *val_data, const fn_free_cb *val_freecb)
int session_table_insert(struct session_table *table, uint8_t is_session_id_only_key, uint64_t session_id, const struct tuple4 *session_addr, void *val_data, const fn_free_cb *val_freecb)
{
struct session_node *temp = NULL;
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
@@ -99,13 +105,18 @@ int session_table_insert(struct session_table *table, uint64_t session_id, const
temp = (struct session_node *)calloc(1, sizeof(struct session_node));
assert(temp);
temp->is_session_id_only_key = is_session_id_only_key;
temp->session_id = session_id;
memcpy(&temp->session_addr, session_addr, sizeof(struct tuple4));
temp->val_data = val_data;
temp->val_freecb = val_freecb;
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);
if (!is_session_id_only_key)
{
HASH_ADD(hh2, table->root_by_addr, session_addr, sizeof(temp->session_addr), temp);
}
TFE_LOG_DEBUG(g_packet_io_logger, "%s: insert: key %lu success", LOG_TAG_STABLE, session_id);
table->session_node_count++;
@@ -124,7 +135,10 @@ int session_table_delete_by_id(struct session_table *table, uint64_t session_id)
}
HASH_DELETE(hh1, table->root_by_id, temp);
HASH_DELETE(hh2, table->root_by_addr, temp);
if (!temp->is_session_id_only_key)
{
HASH_DELETE(hh2, table->root_by_addr, temp);
}
if (temp->val_freecb && temp->val_data)
{