perf: 优化通过Session ID查询流表的逻辑

This commit is contained in:
luwenpeng
2023-11-29 13:59:06 +08:00
parent 75237e905a
commit 5a569f0781

View File

@@ -367,22 +367,24 @@ static inline int is_uplink_keepalive_packet(marsio_buff_t *rx_buff, int raw_len
// return !NULL // return !NULL
// return NULL // return NULL
static struct session_ctx *data_packet_search_session(struct session_table *table, const char *raw_data, int raw_len, uint64_t session_id) static struct session_ctx *data_packet_search_session(struct session_table *table, const char *raw_data, int raw_len, uint64_t session_id, struct thread_ctx *thread_ctx)
{ {
struct four_tuple inner_addr;
struct four_tuple reverse_addr;
struct packet data_pkt;
packet_parse(&data_pkt, raw_data, raw_len);
sce_packet_get_innermost_tuple(&data_pkt, &inner_addr);
four_tuple_reverse(&inner_addr, &reverse_addr);
struct session_ctx *session_ctx = (struct session_ctx *)session_table_search_by_id(table, session_id); struct session_ctx *session_ctx = (struct session_ctx *)session_table_search_by_id(table, session_id);
if (session_ctx == NULL) if (session_ctx == NULL)
{ {
return NULL; return NULL;
} }
struct sce_ctx *sce_ctx = thread_ctx->ref_sce_ctx;
if (sce_ctx->enable_debug)
{
struct four_tuple inner_addr;
struct four_tuple reverse_addr;
struct packet data_pkt;
packet_parse(&data_pkt, raw_data, raw_len);
sce_packet_get_innermost_tuple(&data_pkt, &inner_addr);
four_tuple_reverse(&inner_addr, &reverse_addr);
if (memcmp(&session_ctx->inner_tuple4, &inner_addr, sizeof(struct four_tuple)) != 0 && memcmp(&session_ctx->inner_tuple4, &reverse_addr, sizeof(struct four_tuple)) != 0) if (memcmp(&session_ctx->inner_tuple4, &inner_addr, sizeof(struct four_tuple)) != 0 && memcmp(&session_ctx->inner_tuple4, &reverse_addr, sizeof(struct four_tuple)) != 0)
{ {
char *addr_str = four_tuple_tostring(&inner_addr); char *addr_str = four_tuple_tostring(&inner_addr);
@@ -390,13 +392,14 @@ static struct session_ctx *data_packet_search_session(struct session_table *tabl
free(addr_str); free(addr_str);
return NULL; return NULL;
} }
}
return session_ctx; return session_ctx;
} }
// return !NULL // return !NULL
// return NULL // return NULL
static struct session_ctx *inject_packet_search_session(struct session_table *table, const char *raw_data, int raw_len) static struct session_ctx *inject_packet_search_session(struct session_table *table, const char *raw_data, int raw_len, struct thread_ctx *thread_ctx)
{ {
struct four_tuple inner_addr; struct four_tuple inner_addr;
struct packet data_pkt; struct packet data_pkt;
@@ -1134,7 +1137,7 @@ static void handle_data_packet(marsio_buff_t *rx_buff, struct thread_ctx *thread
goto error_bypass; goto error_bypass;
} }
session_ctx = data_packet_search_session(session_table, meta.raw_data, meta.raw_len, meta.session_id); session_ctx = data_packet_search_session(session_table, meta.raw_data, meta.raw_len, meta.session_id, thread_ctx);
if (session_ctx == NULL) if (session_ctx == NULL)
{ {
THROUGHPUT_METRICS_INC(&(thread_metrics->miss_sess), 1, meta.raw_len); THROUGHPUT_METRICS_INC(&(thread_metrics->miss_sess), 1, meta.raw_len);
@@ -1193,7 +1196,7 @@ static void handle_inject_vxlan_packet(marsio_buff_t *rx_buff, struct thread_ctx
meta.direction = vxlan_get_opt(vxlan_hdr, VNI_OPT_DIR); meta.direction = vxlan_get_opt(vxlan_hdr, VNI_OPT_DIR);
meta.is_decrypted = vxlan_get_opt(vxlan_hdr, VNI_OPT_TRAFFIC); meta.is_decrypted = vxlan_get_opt(vxlan_hdr, VNI_OPT_TRAFFIC);
session_ctx = inject_packet_search_session(session_table, meta.raw_data, meta.raw_len); session_ctx = inject_packet_search_session(session_table, meta.raw_data, meta.raw_len, thread_ctx);
if (session_ctx == NULL) if (session_ctx == NULL)
{ {
goto error_block; goto error_block;