perf: 优化通过Session ID查询流表的逻辑
This commit is contained in:
@@ -367,28 +367,31 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
struct sce_ctx *sce_ctx = thread_ctx->ref_sce_ctx;
|
||||||
|
if (sce_ctx->enable_debug)
|
||||||
{
|
{
|
||||||
char *addr_str = four_tuple_tostring(&inner_addr);
|
struct four_tuple inner_addr;
|
||||||
LOG_ERROR("%s: unexpected raw packet, session %lu expected address tuple4 is %s, but current packet's address tuple4 is %s, bypass !!!", LOG_TAG_PKTIO, session_ctx->session_id, session_ctx->session_addr, addr_str);
|
struct four_tuple reverse_addr;
|
||||||
free(addr_str);
|
struct packet data_pkt;
|
||||||
return NULL;
|
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)
|
||||||
|
{
|
||||||
|
char *addr_str = four_tuple_tostring(&inner_addr);
|
||||||
|
LOG_ERROR("%s: unexpected raw packet, session %lu expected address tuple4 is %s, but current packet's address tuple4 is %s, bypass !!!", LOG_TAG_PKTIO, session_ctx->session_id, session_ctx->session_addr, addr_str);
|
||||||
|
free(addr_str);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return session_ctx;
|
return session_ctx;
|
||||||
@@ -396,7 +399,7 @@ static struct session_ctx *data_packet_search_session(struct session_table *tabl
|
|||||||
|
|
||||||
// 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user