From be0bdc08e3a65246473f399ff93c1ed06c56dfbe Mon Sep 17 00:00:00 2001 From: wangmenglan Date: Mon, 4 Nov 2024 15:20:24 +0800 Subject: OMPUB-1508 For tunnel traffic, asymmetric traffic, and traffic matching the "no intercept" policy, only a session ID index flow table is created --- common/src/tfe_session_table.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'common/src/tfe_session_table.cpp') diff --git a/common/src/tfe_session_table.cpp b/common/src/tfe_session_table.cpp index d9fac5e..accd9ad 100644 --- a/common/src/tfe_session_table.cpp +++ b/common/src/tfe_session_table.cpp @@ -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) { -- cgit v1.2.3