packet io增加fieldstat状态统计
This commit is contained in:
@@ -4,8 +4,7 @@
|
|||||||
src/tfe_pkt_util.cpp src/tfe_tcp_restore.cpp src/raw_socket.cpp src/packet_construct.cpp
|
src/tfe_pkt_util.cpp src/tfe_tcp_restore.cpp src/raw_socket.cpp src/packet_construct.cpp
|
||||||
src/tap.cpp src/io_uring.cpp src/intercept_policy.cpp src/tfe_fieldstat.cpp
|
src/tap.cpp src/io_uring.cpp src/intercept_policy.cpp src/tfe_fieldstat.cpp
|
||||||
src/tfe_addr_tuple4.cpp src/tfe_packet_io.cpp src/tfe_session_table.cpp
|
src/tfe_addr_tuple4.cpp src/tfe_packet_io.cpp src/tfe_session_table.cpp
|
||||||
src/tfe_ctrl_packet.cpp src/tfe_raw_packet.cpp
|
src/tfe_ctrl_packet.cpp src/tfe_raw_packet.cpp src/tfe_packet_io_fs.cpp src/mpack.cpp )
|
||||||
src/tfe_mpack.cpp src/tfe_packet_io_fs.cpp src/mpack.cpp )
|
|
||||||
target_include_directories(common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
|
target_include_directories(common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||||
target_include_directories(common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../bpf/)
|
target_include_directories(common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../bpf/)
|
||||||
target_include_directories(common PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../platform/include/internal)
|
target_include_directories(common PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../platform/include/internal)
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ void ctrl_packet_parser_init(struct ctrl_pkt_parser *handler);
|
|||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int ctrl_packet_parser_parse(struct ctrl_pkt_parser *handler, const char *data, size_t length);
|
int ctrl_packet_parser_parse(void *ctx, const char* data, size_t length, void *logger);
|
||||||
void ctrl_packet_parser_dump(struct ctrl_pkt_parser *handler);
|
void ctrl_packet_parser_dump(struct ctrl_pkt_parser *handler, void *logger);
|
||||||
|
|
||||||
#ifdef __cpluscplus
|
#ifdef __cpluscplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
#ifndef _TFE_MPACK_H
|
|
||||||
#define _TFE_MPACK_H
|
|
||||||
|
|
||||||
#ifdef __cpluscplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "tfe_cmsg.h"
|
|
||||||
|
|
||||||
int parse_messagepack(const char* data, size_t length, void *ctx);
|
|
||||||
|
|
||||||
#ifdef __cpluscplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -33,14 +33,13 @@ struct packet_io_thread_ctx
|
|||||||
|
|
||||||
struct tap_ctx *tap_ctx;
|
struct tap_ctx *tap_ctx;
|
||||||
struct session_table *session_table;
|
struct session_table *session_table;
|
||||||
struct sf_metrics *sf_metrics;
|
|
||||||
|
|
||||||
struct packet_io *ref_io;
|
struct packet_io *ref_io;
|
||||||
struct packet_io_fs *ret_fs_state;
|
|
||||||
struct policy_enforcer *ref_enforcer;
|
|
||||||
struct tfe_proxy *ref_proxy;
|
struct tfe_proxy *ref_proxy;
|
||||||
|
struct packet_io_fs *ret_fs_state;
|
||||||
struct acceptor_kni_v4 *ref_acceptor_ctx;
|
struct acceptor_kni_v4 *ref_acceptor_ctx;
|
||||||
|
|
||||||
|
void *logger;
|
||||||
int session_table_need_reset;
|
int session_table_need_reset;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,10 +79,9 @@ struct acceptor_kni_v4
|
|||||||
int proxy_sids;
|
int proxy_sids;
|
||||||
int sce_sids;
|
int sce_sids;
|
||||||
int nr_worker_threads;
|
int nr_worker_threads;
|
||||||
|
|
||||||
int cpu_affinity_mask[TFE_THREAD_MAX];
|
int cpu_affinity_mask[TFE_THREAD_MAX];
|
||||||
|
|
||||||
cpu_set_t coremask;
|
cpu_set_t coremask;
|
||||||
|
|
||||||
struct packet_io *io;
|
struct packet_io *io;
|
||||||
struct packet_io_fs *packet_io_fs;
|
struct packet_io_fs *packet_io_fs;
|
||||||
struct packet_io_thread_ctx work_threads[TFE_THREAD_MAX];
|
struct packet_io_thread_ctx work_threads[TFE_THREAD_MAX];
|
||||||
@@ -96,10 +94,10 @@ int is_enable_iouring(struct packet_io *handle);
|
|||||||
void tfe_tap_ctx_destory(struct tap_ctx *handler);
|
void tfe_tap_ctx_destory(struct tap_ctx *handler);
|
||||||
struct tap_ctx *tfe_tap_ctx_create(void *ctx);
|
struct tap_ctx *tfe_tap_ctx_create(void *ctx);
|
||||||
|
|
||||||
int packet_io_thread_init(struct packet_io *handle, struct packet_io_thread_ctx *thread_ctx);
|
int packet_io_thread_init(struct packet_io *handle, struct packet_io_thread_ctx *thread_ctx, void *logger);
|
||||||
void packet_io_thread_wait(struct packet_io *handle, struct packet_io_thread_ctx *thread_ctx, int timeout_ms);
|
void packet_io_thread_wait(struct packet_io *handle, struct packet_io_thread_ctx *thread_ctx, int timeout_ms);
|
||||||
void packet_io_destory(struct packet_io *handle);
|
void packet_io_destory(struct packet_io *handle);
|
||||||
struct packet_io *packet_io_create(const char *profile, int thread_num, cpu_set_t *coremask);
|
struct packet_io *packet_io_create(const char *profile, int thread_num, cpu_set_t *coremask, void *logger);
|
||||||
|
|
||||||
int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, void *ctx);
|
int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, void *ctx);
|
||||||
void handle_decryption_packet_from_tap(const char *data, int len, void *args);
|
void handle_decryption_packet_from_tap(const char *data, int len, void *args);
|
||||||
|
|||||||
@@ -21,16 +21,21 @@ struct packet_io_fs
|
|||||||
struct throughput_metrics raw_pkt_rx; // 累计值
|
struct throughput_metrics raw_pkt_rx; // 累计值
|
||||||
struct throughput_metrics raw_pkt_tx; // 累计值
|
struct throughput_metrics raw_pkt_tx; // 累计值
|
||||||
|
|
||||||
struct throughput_metrics hit_policy; // 累计值
|
|
||||||
|
|
||||||
struct throughput_metrics decrypt_tx; // 累计值
|
struct throughput_metrics decrypt_tx; // 累计值
|
||||||
struct throughput_metrics decrypt_rx; // 累计值
|
struct throughput_metrics decrypt_rx; // 累计值
|
||||||
|
|
||||||
|
struct throughput_metrics raw_bypass; // 累计值
|
||||||
|
struct throughput_metrics decrypt_rxdrop; // 累计值
|
||||||
|
|
||||||
struct throughput_metrics ctrl_pkt_rx; // 累计值
|
struct throughput_metrics ctrl_pkt_rx; // 累计值
|
||||||
struct throughput_metrics ctrl_pkt_tx; // 累计值
|
struct throughput_metrics ctrl_pkt_tx; // 累计值
|
||||||
|
|
||||||
|
struct throughput_metrics keepalived_pkt_rx; // 累计值
|
||||||
|
struct throughput_metrics keepalived_pkt_tx; // 累计值
|
||||||
|
|
||||||
struct throughput_metrics tap_pkt_rx; // 累计值
|
struct throughput_metrics tap_pkt_rx; // 累计值
|
||||||
struct throughput_metrics tap_pkt_tx; // 累计值
|
struct throughput_metrics tap_pkt_tx; // 累计值
|
||||||
|
struct throughput_metrics tap_pkt_rxdrop; // 累计值
|
||||||
struct throughput_metrics tap_c_pkt_rx; // 累计值
|
struct throughput_metrics tap_c_pkt_rx; // 累计值
|
||||||
struct throughput_metrics tap_c_pkt_tx; // 累计值
|
struct throughput_metrics tap_c_pkt_tx; // 累计值
|
||||||
struct throughput_metrics tap_s_pkt_rx; // 累计值
|
struct throughput_metrics tap_s_pkt_rx; // 累计值
|
||||||
@@ -42,14 +47,14 @@ struct packet_io_fs
|
|||||||
uint64_t ctrl_pkt_resetall_num; // 累计值
|
uint64_t ctrl_pkt_resetall_num; // 累计值
|
||||||
uint64_t ctrl_pkt_error_num; // 累计值
|
uint64_t ctrl_pkt_error_num; // 累计值
|
||||||
|
|
||||||
uint64_t session_nums; // 瞬时值
|
uint64_t session_num; // 瞬时值
|
||||||
uint64_t send_log; // 瞬时值
|
uint64_t session_log; // 瞬时值
|
||||||
|
|
||||||
screen_stat_handle_t fs_handle;
|
screen_stat_handle_t fs_handle;
|
||||||
int fs_id[128];
|
int fs_id[128];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct packet_io_fs *packet_io_fs_create();
|
struct packet_io_fs *packet_io_fs_create(const char *profile);
|
||||||
void packet_io_fs_destory(struct packet_io_fs *handle);
|
void packet_io_fs_destory(struct packet_io_fs *handle);
|
||||||
void packet_io_fs_dump(struct packet_io_fs *handle);
|
void packet_io_fs_dump(struct packet_io_fs *handle);
|
||||||
|
|
||||||
|
|||||||
@@ -78,19 +78,19 @@ struct raw_pkt_parser
|
|||||||
|
|
||||||
void raw_packet_parser_init(struct raw_pkt_parser *handler, uint64_t pkt_trace_id, enum layer_type expect_type, uint16_t expect_results_num);
|
void raw_packet_parser_init(struct raw_pkt_parser *handler, uint64_t pkt_trace_id, enum layer_type expect_type, uint16_t expect_results_num);
|
||||||
// return most inner payload
|
// return most inner payload
|
||||||
const void *raw_packet_parser_parse(struct raw_pkt_parser *handler, const void *data, size_t length);
|
const void *raw_packet_parser_parse(struct raw_pkt_parser *handler, const void *data, size_t length, void *logger);
|
||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int raw_packet_parser_get_most_inner_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr);
|
int raw_packet_parser_get_most_inner_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger);
|
||||||
int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr);
|
int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger);
|
||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int raw_packet_parser_get_most_inner_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr);
|
int raw_packet_parser_get_most_inner_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger);
|
||||||
int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr);
|
int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger);
|
||||||
|
|
||||||
uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal);
|
uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal, void *logger);
|
||||||
|
|
||||||
#ifdef __cpluscplus
|
#ifdef __cpluscplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,314 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <cjson/cJSON.h>
|
#include <cjson/cJSON.h>
|
||||||
|
|
||||||
#include "tfe_mpack.h"
|
#include "mpack.h"
|
||||||
#include "tfe_cmsg.h"
|
#include "tfe_cmsg.h"
|
||||||
#include "tfe_utils.h"
|
#include "tfe_utils.h"
|
||||||
#include "tfe_ctrl_packet.h"
|
#include "tfe_ctrl_packet.h"
|
||||||
|
|
||||||
|
enum ctr_pkt_index
|
||||||
|
{
|
||||||
|
INDEX_TSYNC = 0,
|
||||||
|
INDEX_SESSION_ID,
|
||||||
|
INDEX_STATE,
|
||||||
|
INDEX_METHOD,
|
||||||
|
INDEX_KEY_SCE,
|
||||||
|
INDEX_VALUE_SCE,
|
||||||
|
INDEX_KEY_SHAPER,
|
||||||
|
INDEX_VALUE_SHAPER,
|
||||||
|
INDEX_KEY_PROXY,
|
||||||
|
INDEX_VALUE_PROXY,
|
||||||
|
INDEX_MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MPACK_ARRAY_INIT,
|
||||||
|
MPACK_ARRAY_FQDN_IDS,
|
||||||
|
MPACK_ARRAY_SEQ_SIDS,
|
||||||
|
MPACK_ARRAY_ACK_SIDS,
|
||||||
|
MPACK_ARRAY_SEQ_ROUTE_CTX,
|
||||||
|
MPACK_ARRAY_ACK_ROUTE_CTX,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mpack_mmap_id2type
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
enum tfe_cmsg_tlv_type type;
|
||||||
|
const char *str_name;
|
||||||
|
int size;
|
||||||
|
int array_index;
|
||||||
|
}mpack_table[] = {
|
||||||
|
{.id = 0, .type = TFE_CMSG_TCP_RESTORE_SEQ, .str_name = "TFE_CMSG_TCP_RESTORE_SEQ", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 1, .type = TFE_CMSG_TCP_RESTORE_ACK, .str_name = "TFE_CMSG_TCP_RESTORE_ACK", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 2, .type = TFE_CMSG_TCP_RESTORE_MSS_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_MSS_CLIENT", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 3, .type = TFE_CMSG_TCP_RESTORE_MSS_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_MSS_SERVER", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 4, .type = TFE_CMSG_TCP_RESTORE_WSACLE_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_WSACLE_CLIENT", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 5, .type = TFE_CMSG_TCP_RESTORE_WSACLE_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_WSACLE_SERVER", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 6, .type = TFE_CMSG_TCP_RESTORE_SACK_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_SACK_CLIENT", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 7, .type = TFE_CMSG_TCP_RESTORE_SACK_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_SACK_SERVER", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 8, .type = TFE_CMSG_TCP_RESTORE_TS_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_TS_CLIENT", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 9, .type = TFE_CMSG_TCP_RESTORE_TS_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_TS_SERVER", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 10, .type = TFE_CMSG_TCP_RESTORE_PROTOCOL, .str_name = "TFE_CMSG_TCP_RESTORE_PROTOCOL", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 11, .type = TFE_CMSG_TCP_RESTORE_WINDOW_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_WINDOW_CLIENT", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 12, .type = TFE_CMSG_TCP_RESTORE_WINDOW_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_WINDOW_SERVER", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 13, .type = TFE_CMSG_TCP_RESTORE_TS_CLIENT_VAL, .str_name = "TFE_CMSG_TCP_RESTORE_TS_CLIENT_VAL", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 14, .type = TFE_CMSG_TCP_RESTORE_TS_SERVER_VAL, .str_name = "TFE_CMSG_TCP_RESTORE_TS_SERVER_VAL", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 15, .type = TFE_CMSG_TCP_RESTORE_INFO_PACKET_CUR_DIR, .str_name = "TFE_CMSG_TCP_RESTORE_INFO_PACKET_CUR_DIR", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 16, .type = TFE_CMSG_SRC_SUB_ID, .str_name = "TFE_CMSG_SRC_SUB_ID", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 17, .type = TFE_CMSG_DST_SUB_ID, .str_name = "TFE_CMSG_DST_SUB_ID", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 18, .type = TFE_CMSG_SRC_ASN, .str_name = "TFE_CMSG_SRC_ASN", .size = 64, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 19, .type = TFE_CMSG_DST_ASN, .str_name = "TFE_CMSG_DST_ASN", .size = 64, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 20, .type = TFE_CMSG_SRC_ORGANIZATION, .str_name = "TFE_CMSG_SRC_ORGANIZATION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 21, .type = TFE_CMSG_DST_ORGANIZATION, .str_name = "TFE_CMSG_DST_ORGANIZATION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 22, .type = TFE_CMSG_SRC_IP_LOCATION_COUNTRY, .str_name = "TFE_CMSG_SRC_IP_LOCATION_COUNTRY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 23, .type = TFE_CMSG_DST_IP_LOCATION_COUNTRY, .str_name = "TFE_CMSG_DST_IP_LOCATION_COUNTRY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 24, .type = TFE_CMSG_SRC_IP_LOCATION_PROVINE, .str_name = "TFE_CMSG_SRC_IP_LOCATION_PROVINE", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 25, .type = TFE_CMSG_DST_IP_LOCATION_PROVINE, .str_name = "TFE_CMSG_DST_IP_LOCATION_PROVINE", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 26, .type = TFE_CMSG_SRC_IP_LOCATION_CITY, .str_name = "TFE_CMSG_SRC_IP_LOCATION_CITY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 27, .type = TFE_CMSG_DST_IP_LOCATION_CITY, .str_name = "TFE_CMSG_DST_IP_LOCATION_CITY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 28, .type = TFE_CMSG_SRC_IP_LOCATION_SUBDIVISION, .str_name = "TFE_CMSG_SRC_IP_LOCATION_SUBDIVISION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 29, .type = TFE_CMSG_DST_IP_LOCATION_SUBDIVISION, .str_name = "TFE_CMSG_DST_IP_LOCATION_SUBDIVISION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 30, .type = TFE_CMSG_SSL_CLIENT_JA3_FINGERPRINT, .str_name = "TFE_CMSG_SSL_CLIENT_JA3_FINGERPRINT", .size = 32, .array_index = MPACK_ARRAY_INIT},
|
||||||
|
{.id = 31, .type = TFE_CMSG_FQDN_CAT_ID_VAL, .str_name = "TFE_CMSG_FQDN_CAT_ID_VAL", .size = 4, .array_index = MPACK_ARRAY_FQDN_IDS},
|
||||||
|
{.id = 32, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_SEQ_SIDS", .size = 2, .array_index = MPACK_ARRAY_SEQ_SIDS},
|
||||||
|
{.id = 33, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_ACK_SIDS", .size = 2, .array_index = MPACK_ARRAY_ACK_SIDS},
|
||||||
|
{.id = 34, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_SEQ_ROUTE_CTX", .size = 1, .array_index = MPACK_ARRAY_SEQ_ROUTE_CTX},
|
||||||
|
{.id = 35, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_ACK_ROUTE_CTX", .size = 1, .array_index = MPACK_ARRAY_ACK_ROUTE_CTX}
|
||||||
|
};
|
||||||
|
|
||||||
|
static int fqdn_id_set_cmsg(struct ctrl_pkt_parser *handler, mpack_node_t node, int table_index)
|
||||||
|
{
|
||||||
|
uint32_t fqdn_val[8] = {0};
|
||||||
|
|
||||||
|
uint32_t array_cnt = mpack_node_array_length(node);
|
||||||
|
tfe_cmsg_set(handler->cmsg, TFE_CMSG_FQDN_CAT_ID_NUM, (const unsigned char *)&array_cnt, sizeof(uint32_t));
|
||||||
|
for (uint32_t i = 0; i < array_cnt; i++) {
|
||||||
|
fqdn_val[i] = mpack_node_u32(mpack_node_array_at(node, i));
|
||||||
|
}
|
||||||
|
tfe_cmsg_set(handler->cmsg, TFE_CMSG_FQDN_CAT_ID_VAL, (const unsigned char*)fqdn_val, array_cnt * sizeof(uint32_t));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sids_array_parse_mpack(struct ctrl_pkt_parser *handler, mpack_node_t node, int table_index, int is_seq)
|
||||||
|
{
|
||||||
|
struct sids *sid = is_seq ? &handler->seq_sids : &handler->ack_sids;
|
||||||
|
if (mpack_node_array_length(node) > MR_SID_LIST_MAXLEN) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sid->num = mpack_node_array_length(node);
|
||||||
|
for (int i = 0; i < sid->num; i++)
|
||||||
|
{
|
||||||
|
sid->elems[i] = mpack_node_u16(mpack_node_array_at(node, i));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int route_ctx_parse_mpack(struct ctrl_pkt_parser *handler, mpack_node_t node, int table_index, int is_seq)
|
||||||
|
{
|
||||||
|
struct route_ctx *ctx = is_seq ? &handler->seq_route_ctx : &handler->ack_route_ctx;
|
||||||
|
if (mpack_node_array_length(node) > 64) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->len = mpack_node_array_length(node);
|
||||||
|
for (int i = 0; i < ctx->len; i++)
|
||||||
|
{
|
||||||
|
ctx->data[i] = mpack_node_u8(mpack_node_array_at(node, i));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int proxy_parse_messagepack(mpack_node_t node, void *ctx, void *logger)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
uint64_t value = 0;
|
||||||
|
char cmsg_str[256] = {0};
|
||||||
|
struct ctrl_pkt_parser *handler = (struct ctrl_pkt_parser *)ctx;
|
||||||
|
|
||||||
|
if (mpack_node_is_nil(mpack_node_map_cstr(node, "rule_ids")))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: session %lu unexpected control packet: (rule_ids no found)", LOG_TAG_CTRLPKT, handler->session_id);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
handler->tfe_policy_id_num = mpack_node_array_length(mpack_node_map_cstr(node, "rule_ids"));
|
||||||
|
for (int i = 0; i < handler->tfe_policy_id_num; i++) {
|
||||||
|
handler->tfe_policy_ids[i] = mpack_node_u64(mpack_node_array_at(mpack_node_map_cstr(node, "rule_ids"), i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handler->tfe_policy_id_num) {
|
||||||
|
tfe_cmsg_set(handler->cmsg, TFE_CMSG_POLICY_ID, (const unsigned char *)&handler->tfe_policy_ids[0], sizeof(uint64_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
mpack_node_t tcp_handshake = mpack_node_map_cstr(node, "tcp_handshake");
|
||||||
|
int cmsg_array_cnt = mpack_node_array_length(tcp_handshake);
|
||||||
|
for (int i = 0; i < cmsg_array_cnt; i++) {
|
||||||
|
mpack_node_t ptr = mpack_node_array_at(tcp_handshake, i);
|
||||||
|
|
||||||
|
switch (mpack_node_type(ptr)) {
|
||||||
|
case mpack_type_uint:
|
||||||
|
value = mpack_node_u64(ptr);
|
||||||
|
tfe_cmsg_set(handler->cmsg, mpack_table[i].type, (const unsigned char *)&value, mpack_table[i].size);
|
||||||
|
break;
|
||||||
|
case mpack_type_str:
|
||||||
|
snprintf(cmsg_str, sizeof(cmsg_str), mpack_node_str(ptr), mpack_node_strlen(ptr));
|
||||||
|
tfe_cmsg_set(handler->cmsg, mpack_table[i].type, (const unsigned char *)cmsg_str, mpack_node_strlen(ptr));
|
||||||
|
break;
|
||||||
|
case mpack_type_nil:
|
||||||
|
break;
|
||||||
|
case mpack_type_array:
|
||||||
|
switch(mpack_table[i].array_index)
|
||||||
|
{
|
||||||
|
case MPACK_ARRAY_FQDN_IDS:
|
||||||
|
fqdn_id_set_cmsg(handler, ptr, i);
|
||||||
|
break;
|
||||||
|
case MPACK_ARRAY_SEQ_SIDS:
|
||||||
|
ret = sids_array_parse_mpack(handler, ptr, i, 1);
|
||||||
|
if (ret != 0)
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case MPACK_ARRAY_ACK_SIDS:
|
||||||
|
ret = sids_array_parse_mpack(handler, ptr, i, 0);
|
||||||
|
if (ret != 0)
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case MPACK_ARRAY_SEQ_ROUTE_CTX:
|
||||||
|
ret = route_ctx_parse_mpack(handler, ptr, i, 1);
|
||||||
|
if (ret != 0)
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case MPACK_ARRAY_ACK_ROUTE_CTX:
|
||||||
|
ret = route_ctx_parse_mpack(handler, ptr, i, 0);
|
||||||
|
if (ret != 0)
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return 0 : success
|
||||||
|
// return -1 : error
|
||||||
|
int ctrl_packet_parser_parse(void *ctx, const char* data, size_t length, void *logger)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct ctrl_pkt_parser *handler = (struct ctrl_pkt_parser *)ctx;
|
||||||
|
char buff[16] = {0};
|
||||||
|
mpack_node_t params;
|
||||||
|
mpack_node_t sce_map;
|
||||||
|
mpack_node_t proxy_map;
|
||||||
|
mpack_tree_t tree;
|
||||||
|
mpack_tree_init_data(&tree, data, length);
|
||||||
|
mpack_tree_parse(&tree);
|
||||||
|
mpack_node_t root = mpack_tree_root(&tree);
|
||||||
|
if (mpack_node_is_nil(root))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet: (invalid mpack format)", LOG_TAG_CTRLPKT);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mpack_node_is_nil(mpack_node_map_cstr(root, "tsync")))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet: (tsync no found)", LOG_TAG_CTRLPKT);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
mpack_node_copy_cstr(mpack_node_map_cstr(root, "tsync"), handler->tsync, sizeof(handler->tsync));
|
||||||
|
if (strcmp(handler->tsync, "2.0") != 0)
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet: (invalid tsync version) %s", LOG_TAG_CTRLPKT, handler->tsync);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mpack_node_is_nil(mpack_node_map_cstr(root, "session_id")))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet: (session_id no found)", LOG_TAG_CTRLPKT);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
handler->session_id = mpack_node_u64(mpack_node_map_cstr(root, "session_id"));
|
||||||
|
|
||||||
|
if (mpack_node_is_nil(mpack_node_map_cstr(root, "state")))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: session %lu unexpected control packet: (state no found)", LOG_TAG_CTRLPKT, handler->session_id);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
mpack_node_copy_cstr(mpack_node_map_cstr(root, "state"), buff, sizeof(buff));
|
||||||
|
if (strncasecmp(buff, "opening", sizeof(buff)) == 0)
|
||||||
|
{
|
||||||
|
handler->state = SESSION_STATE_OPENING;
|
||||||
|
goto succ;
|
||||||
|
}
|
||||||
|
else if (strncasecmp(buff, "active", sizeof(buff)) == 0)
|
||||||
|
{
|
||||||
|
handler->state = SESSION_STATE_ACTIVE;
|
||||||
|
}
|
||||||
|
else if (strncasecmp(buff, "closing", sizeof(buff)) == 0)
|
||||||
|
{
|
||||||
|
handler->state = SESSION_STATE_CLOSING;
|
||||||
|
goto succ;
|
||||||
|
}
|
||||||
|
else if (strncasecmp(buff, "resetall", sizeof(buff)) == 0)
|
||||||
|
{
|
||||||
|
handler->state = SESSION_STATE_RESETALL;
|
||||||
|
goto succ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TFE_LOG_DEBUG(logger, "%s: session %lu unexpected control packet: (invalid state value) %s", LOG_TAG_CTRLPKT, handler->session_id, buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mpack_node_is_nil(mpack_node_map_cstr(root, "method")))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: session %lu unexpected control packet: (method no found)", LOG_TAG_CTRLPKT, handler->session_id);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
mpack_node_copy_cstr(mpack_node_map_cstr(root, "method"), handler->method, sizeof(handler->method));
|
||||||
|
|
||||||
|
if (mpack_node_is_nil(mpack_node_map_cstr(root, "params")))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: session %lu unexpected control packet: (params no found)", LOG_TAG_CTRLPKT, handler->session_id);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
params = mpack_node_map_cstr(root, "params");
|
||||||
|
|
||||||
|
if (!mpack_node_is_missing(mpack_node_map_str_optional(params, "sce", strlen("sce"))))
|
||||||
|
{
|
||||||
|
sce_map = mpack_node_map_cstr(params, "sce");
|
||||||
|
if (mpack_node_is_nil(mpack_node_map_cstr(sce_map, "rule_ids")))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: session %lu unexpected control packet: (sce rule_ids no found)", LOG_TAG_CTRLPKT, handler->session_id);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
handler->sce_policy_id_num = mpack_node_array_length(mpack_node_map_cstr(sce_map, "rule_ids"));
|
||||||
|
for (int i = 0; i < handler->sce_policy_id_num; i++) {
|
||||||
|
handler->sce_policy_ids[i] = mpack_node_u64(mpack_node_array_at(mpack_node_map_cstr(sce_map, "rule_ids"), i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mpack_node_is_missing(mpack_node_map_str_optional(params, "proxy", strlen("proxy"))))
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "%s: session %lu unexpected control packet: (proxy no found)", LOG_TAG_CTRLPKT, handler->session_id);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy_map = mpack_node_map_cstr(params, "proxy");
|
||||||
|
ret = proxy_parse_messagepack(proxy_map, handler, logger);
|
||||||
|
if (ret != 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
succ:
|
||||||
|
mpack_tree_destroy(&tree);
|
||||||
|
return 0;
|
||||||
|
error:
|
||||||
|
mpack_tree_destroy(&tree);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
const char *session_state_to_string(enum session_state state)
|
const char *session_state_to_string(enum session_state state)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
@@ -31,32 +334,25 @@ void ctrl_packet_parser_init(struct ctrl_pkt_parser *handler)
|
|||||||
tfe_cmsg_dup(handler->cmsg);
|
tfe_cmsg_dup(handler->cmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 0 : success
|
void ctrl_packet_parser_dump(struct ctrl_pkt_parser *handler, void *logger)
|
||||||
// return -1 : error
|
|
||||||
int ctrl_packet_parser_parse(struct ctrl_pkt_parser *handler, const char *data, size_t length)
|
|
||||||
{
|
|
||||||
return parse_messagepack(data, length, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ctrl_packet_parser_dump(struct ctrl_pkt_parser *handler)
|
|
||||||
{
|
{
|
||||||
if (handler)
|
if (handler)
|
||||||
{
|
{
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: tsync : %s", LOG_TAG_POLICY, handler->tsync);
|
TFE_LOG_INFO(logger, "%s: tsync : %s", LOG_TAG_POLICY, handler->tsync);
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: session_id : %lu", LOG_TAG_POLICY, handler->session_id);
|
TFE_LOG_INFO(logger, "%s: session_id : %lu", LOG_TAG_POLICY, handler->session_id);
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: state : %s", LOG_TAG_POLICY, session_state_to_string(handler->state));
|
TFE_LOG_INFO(logger, "%s: state : %s", LOG_TAG_POLICY, session_state_to_string(handler->state));
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: method : %s", LOG_TAG_POLICY, handler->method);
|
TFE_LOG_INFO(logger, "%s: method : %s", LOG_TAG_POLICY, handler->method);
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: tfe policy_id_num : %d", LOG_TAG_POLICY, handler->tfe_policy_id_num);
|
TFE_LOG_INFO(logger, "%s: tfe policy_id_num : %d", LOG_TAG_POLICY, handler->tfe_policy_id_num);
|
||||||
|
|
||||||
for (int i = 0; i < handler->tfe_policy_id_num; i++)
|
for (int i = 0; i < handler->tfe_policy_id_num; i++)
|
||||||
{
|
{
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: %d tfe policy_ids[%03lu]", LOG_TAG_POLICY, i, handler->tfe_policy_ids[i]);
|
TFE_LOG_INFO(logger, "%s: %d tfe policy_ids[%03lu]", LOG_TAG_POLICY, i, handler->tfe_policy_ids[i]);
|
||||||
}
|
}
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: sce policy_id_num : %d", LOG_TAG_POLICY, handler->sce_policy_id_num);
|
TFE_LOG_INFO(logger, "%s: sce policy_id_num : %d", LOG_TAG_POLICY, handler->sce_policy_id_num);
|
||||||
|
|
||||||
for (int i = 0; i < handler->tfe_policy_id_num; i++)
|
for (int i = 0; i < handler->sce_policy_id_num; i++)
|
||||||
{
|
{
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: %d sce policy_ids[%03lu]", LOG_TAG_POLICY, i, handler->sce_policy_ids[i]);
|
TFE_LOG_INFO(logger, "%s: %d sce policy_ids[%03lu]", LOG_TAG_POLICY, i, handler->sce_policy_ids[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,319 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
|
|
||||||
#include "mpack.h"
|
|
||||||
#include "tfe_cmsg.h"
|
|
||||||
#include "tfe_utils.h"
|
|
||||||
#include "tfe_ctrl_packet.h"
|
|
||||||
|
|
||||||
enum ctr_pkt_index
|
|
||||||
{
|
|
||||||
INDEX_TSYNC = 0,
|
|
||||||
INDEX_SESSION_ID,
|
|
||||||
INDEX_STATE,
|
|
||||||
INDEX_METHOD,
|
|
||||||
INDEX_KEY_SCE,
|
|
||||||
INDEX_VALUE_SCE,
|
|
||||||
INDEX_KEY_SHAPER,
|
|
||||||
INDEX_VALUE_SHAPER,
|
|
||||||
INDEX_KEY_PROXY,
|
|
||||||
INDEX_VALUE_PROXY,
|
|
||||||
INDEX_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
MPACK_ARRAY_INIT,
|
|
||||||
MPACK_ARRAY_FQDN_IDS,
|
|
||||||
MPACK_ARRAY_SEQ_SIDS,
|
|
||||||
MPACK_ARRAY_ACK_SIDS,
|
|
||||||
MPACK_ARRAY_SEQ_ROUTE_CTX,
|
|
||||||
MPACK_ARRAY_ACK_ROUTE_CTX,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct mpack_mmap_id2type
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
enum tfe_cmsg_tlv_type type;
|
|
||||||
const char *str_name;
|
|
||||||
int size;
|
|
||||||
int array_index;
|
|
||||||
}mpack_table[] = {
|
|
||||||
{.id = 0, .type = TFE_CMSG_TCP_RESTORE_SEQ, .str_name = "TFE_CMSG_TCP_RESTORE_SEQ", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 1, .type = TFE_CMSG_TCP_RESTORE_ACK, .str_name = "TFE_CMSG_TCP_RESTORE_ACK", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 2, .type = TFE_CMSG_TCP_RESTORE_MSS_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_MSS_CLIENT", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 3, .type = TFE_CMSG_TCP_RESTORE_MSS_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_MSS_SERVER", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 4, .type = TFE_CMSG_TCP_RESTORE_WSACLE_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_WSACLE_CLIENT", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 5, .type = TFE_CMSG_TCP_RESTORE_WSACLE_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_WSACLE_SERVER", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 6, .type = TFE_CMSG_TCP_RESTORE_SACK_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_SACK_CLIENT", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 7, .type = TFE_CMSG_TCP_RESTORE_SACK_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_SACK_SERVER", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 8, .type = TFE_CMSG_TCP_RESTORE_TS_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_TS_CLIENT", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 9, .type = TFE_CMSG_TCP_RESTORE_TS_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_TS_SERVER", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 10, .type = TFE_CMSG_TCP_RESTORE_PROTOCOL, .str_name = "TFE_CMSG_TCP_RESTORE_PROTOCOL", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 11, .type = TFE_CMSG_TCP_RESTORE_WINDOW_CLIENT, .str_name = "TFE_CMSG_TCP_RESTORE_WINDOW_CLIENT", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 12, .type = TFE_CMSG_TCP_RESTORE_WINDOW_SERVER, .str_name = "TFE_CMSG_TCP_RESTORE_WINDOW_SERVER", .size = 2, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 13, .type = TFE_CMSG_TCP_RESTORE_TS_CLIENT_VAL, .str_name = "TFE_CMSG_TCP_RESTORE_TS_CLIENT_VAL", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 14, .type = TFE_CMSG_TCP_RESTORE_TS_SERVER_VAL, .str_name = "TFE_CMSG_TCP_RESTORE_TS_SERVER_VAL", .size = 4, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 15, .type = TFE_CMSG_TCP_RESTORE_INFO_PACKET_CUR_DIR, .str_name = "TFE_CMSG_TCP_RESTORE_INFO_PACKET_CUR_DIR", .size = 1, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 16, .type = TFE_CMSG_SRC_SUB_ID, .str_name = "TFE_CMSG_SRC_SUB_ID", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 17, .type = TFE_CMSG_DST_SUB_ID, .str_name = "TFE_CMSG_DST_SUB_ID", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 18, .type = TFE_CMSG_SRC_ASN, .str_name = "TFE_CMSG_SRC_ASN", .size = 64, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 19, .type = TFE_CMSG_DST_ASN, .str_name = "TFE_CMSG_DST_ASN", .size = 64, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 20, .type = TFE_CMSG_SRC_ORGANIZATION, .str_name = "TFE_CMSG_SRC_ORGANIZATION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 21, .type = TFE_CMSG_DST_ORGANIZATION, .str_name = "TFE_CMSG_DST_ORGANIZATION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 22, .type = TFE_CMSG_SRC_IP_LOCATION_COUNTRY, .str_name = "TFE_CMSG_SRC_IP_LOCATION_COUNTRY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 23, .type = TFE_CMSG_DST_IP_LOCATION_COUNTRY, .str_name = "TFE_CMSG_DST_IP_LOCATION_COUNTRY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 24, .type = TFE_CMSG_SRC_IP_LOCATION_PROVINE, .str_name = "TFE_CMSG_SRC_IP_LOCATION_PROVINE", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 25, .type = TFE_CMSG_DST_IP_LOCATION_PROVINE, .str_name = "TFE_CMSG_DST_IP_LOCATION_PROVINE", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 26, .type = TFE_CMSG_SRC_IP_LOCATION_CITY, .str_name = "TFE_CMSG_SRC_IP_LOCATION_CITY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 27, .type = TFE_CMSG_DST_IP_LOCATION_CITY, .str_name = "TFE_CMSG_DST_IP_LOCATION_CITY", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 28, .type = TFE_CMSG_SRC_IP_LOCATION_SUBDIVISION, .str_name = "TFE_CMSG_SRC_IP_LOCATION_SUBDIVISION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 29, .type = TFE_CMSG_DST_IP_LOCATION_SUBDIVISION, .str_name = "TFE_CMSG_DST_IP_LOCATION_SUBDIVISION", .size = 256, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 30, .type = TFE_CMSG_SSL_CLIENT_JA3_FINGERPRINT, .str_name = "TFE_CMSG_SSL_CLIENT_JA3_FINGERPRINT", .size = 32, .array_index = MPACK_ARRAY_INIT},
|
|
||||||
{.id = 31, .type = TFE_CMSG_FQDN_CAT_ID_VAL, .str_name = "TFE_CMSG_FQDN_CAT_ID_VAL", .size = 4, .array_index = MPACK_ARRAY_FQDN_IDS},
|
|
||||||
{.id = 32, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_SEQ_SIDS", .size = 2, .array_index = MPACK_ARRAY_SEQ_SIDS},
|
|
||||||
{.id = 33, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_ACK_SIDS", .size = 2, .array_index = MPACK_ARRAY_ACK_SIDS},
|
|
||||||
{.id = 34, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_SEQ_ROUTE_CTX", .size = 1, .array_index = MPACK_ARRAY_SEQ_ROUTE_CTX},
|
|
||||||
{.id = 35, .type = TFE_CMSG_TLV_NR_MAX, .str_name = "TFE_ACK_ROUTE_CTX", .size = 1, .array_index = MPACK_ARRAY_ACK_ROUTE_CTX}
|
|
||||||
};
|
|
||||||
|
|
||||||
static int fqdn_id_set_cmsg(struct ctrl_pkt_parser *handler, mpack_node_t node, int table_index)
|
|
||||||
{
|
|
||||||
uint32_t fqdn_val[8] = {0};
|
|
||||||
|
|
||||||
uint32_t array_cnt = mpack_node_array_length(node);
|
|
||||||
tfe_cmsg_set(handler->cmsg, TFE_CMSG_FQDN_CAT_ID_NUM, (const unsigned char *)&array_cnt, sizeof(uint32_t));
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu array fqdn_id num: [%u]", LOG_TAG_CTRLPKT, handler->session_id, array_cnt);
|
|
||||||
for (uint32_t i = 0; i < array_cnt; i++) {
|
|
||||||
fqdn_val[i] = mpack_node_u32(mpack_node_array_at(node, i));
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu array fqdn_id msgpack cmsg: [%s] -> [%lu]", LOG_TAG_CTRLPKT, handler->session_id, mpack_table[table_index].str_name, fqdn_val[i]);
|
|
||||||
}
|
|
||||||
tfe_cmsg_set(handler->cmsg, TFE_CMSG_FQDN_CAT_ID_VAL, (const unsigned char*)fqdn_val, array_cnt * sizeof(uint32_t));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sids_array_parse_mpack(struct ctrl_pkt_parser *handler, mpack_node_t node, int table_index, int is_seq)
|
|
||||||
{
|
|
||||||
struct sids *sid = is_seq ? &handler->seq_sids : &handler->ack_sids;
|
|
||||||
if (mpack_node_array_length(node) > MR_SID_LIST_MAXLEN) {
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: session: %lu sid[%ld] more than maxlen %d", LOG_TAG_CTRLPKT, handler->session_id, mpack_node_array_length(node), MR_SID_LIST_MAXLEN);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sid->num = mpack_node_array_length(node);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu array sids num: [%d]", LOG_TAG_CTRLPKT, handler->session_id, sid->num);
|
|
||||||
for (int i = 0; i < sid->num; i++)
|
|
||||||
{
|
|
||||||
sid->elems[i] = mpack_node_u16(mpack_node_array_at(node, i));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int route_ctx_parse_mpack(struct ctrl_pkt_parser *handler, mpack_node_t node, int table_index, int is_seq)
|
|
||||||
{
|
|
||||||
struct route_ctx *ctx = is_seq ? &handler->seq_route_ctx : &handler->ack_route_ctx;
|
|
||||||
if (mpack_node_array_length(node) > 64) {
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: session: %lu route ctx[%ld] more than maxlen 64", LOG_TAG_CTRLPKT, handler->session_id, mpack_node_array_length(node));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->len = mpack_node_array_length(node);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu array route ctx num: [%u]", LOG_TAG_CTRLPKT, handler->session_id, ctx->len);
|
|
||||||
for (int i = 0; i < ctx->len; i++)
|
|
||||||
{
|
|
||||||
ctx->data[i] = mpack_node_u8(mpack_node_array_at(node, i));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int proxy_parse_messagepack(mpack_node_t node, void *ctx)
|
|
||||||
{
|
|
||||||
uint64_t value = 0;
|
|
||||||
struct ctrl_pkt_parser *handler = (struct ctrl_pkt_parser *)ctx;
|
|
||||||
|
|
||||||
if (mpack_node_is_nil(mpack_node_map_cstr(node, "rule_ids")))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (rule_ids no found)", LOG_TAG_CTRLPKT);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
handler->tfe_policy_id_num = mpack_node_array_length(mpack_node_map_cstr(node, "rule_ids"));
|
|
||||||
for (int i = 0; i < handler->tfe_policy_id_num; i++) {
|
|
||||||
handler->tfe_policy_ids[i] = mpack_node_u64(mpack_node_array_at(mpack_node_map_cstr(node, "rule_ids"), i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handler->tfe_policy_id_num) {
|
|
||||||
tfe_cmsg_set(handler->cmsg, TFE_CMSG_POLICY_ID, (const unsigned char *)&handler->tfe_policy_ids[0], sizeof(uint64_t));
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu tfe policy id num: [%d]", LOG_TAG_CTRLPKT, handler->session_id, handler->tfe_policy_id_num);
|
|
||||||
for (int i = 0; i < handler->tfe_policy_id_num; i++) {
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu policy id:%lu ", LOG_TAG_CTRLPKT, handler->session_id, handler->tfe_policy_ids[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mpack_node_t tcp_handshake = mpack_node_map_cstr(node, "tcp_handshake");
|
|
||||||
int cmsg_array_cnt = mpack_node_array_length(tcp_handshake);
|
|
||||||
for (int i = 0; i < cmsg_array_cnt; i++) {
|
|
||||||
mpack_node_t ptr = mpack_node_array_at(tcp_handshake, i);
|
|
||||||
|
|
||||||
switch (mpack_node_type(ptr)) {
|
|
||||||
case mpack_type_uint:
|
|
||||||
value = mpack_node_u64(ptr);
|
|
||||||
tfe_cmsg_set(handler->cmsg, mpack_table[i].type, (const unsigned char *)&value, mpack_table[i].size);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu interger msgpack cmsg: [%s] -> [%lu]", LOG_TAG_CTRLPKT, handler->session_id, mpack_table[i].str_name, value);
|
|
||||||
break;
|
|
||||||
case mpack_type_str:
|
|
||||||
tfe_cmsg_set(handler->cmsg, mpack_table[i].type, (const unsigned char *)mpack_node_str(ptr), mpack_node_strlen(ptr));
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu string msgpack cmsg: [%s] -> [%s]", LOG_TAG_CTRLPKT, handler->session_id, mpack_table[i].str_name, mpack_node_str(ptr));
|
|
||||||
break;
|
|
||||||
case mpack_type_nil:
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu msgpack cmsg: [%s] -> [nil]", LOG_TAG_CTRLPKT, handler->session_id, mpack_table[i].str_name);
|
|
||||||
break;
|
|
||||||
case mpack_type_array:
|
|
||||||
switch(mpack_table[i].array_index)
|
|
||||||
{
|
|
||||||
case MPACK_ARRAY_FQDN_IDS:
|
|
||||||
fqdn_id_set_cmsg(handler, ptr, i);
|
|
||||||
break;
|
|
||||||
case MPACK_ARRAY_SEQ_SIDS:
|
|
||||||
sids_array_parse_mpack(handler, ptr, i, 1);
|
|
||||||
break;
|
|
||||||
case MPACK_ARRAY_ACK_SIDS:
|
|
||||||
sids_array_parse_mpack(handler, ptr, i, 0);
|
|
||||||
break;
|
|
||||||
case MPACK_ARRAY_SEQ_ROUTE_CTX:
|
|
||||||
route_ctx_parse_mpack(handler, ptr, i, 1);
|
|
||||||
break;
|
|
||||||
case MPACK_ARRAY_ACK_ROUTE_CTX:
|
|
||||||
route_ctx_parse_mpack(handler, ptr, i, 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int parse_messagepack(const char* data, size_t length, void *ctx)
|
|
||||||
{
|
|
||||||
struct ctrl_pkt_parser *handler = (struct ctrl_pkt_parser *)ctx;
|
|
||||||
char buff[16] = {0};
|
|
||||||
mpack_node_t params;
|
|
||||||
mpack_node_t sce_map;
|
|
||||||
mpack_node_t proxy_map;
|
|
||||||
mpack_tree_t tree;
|
|
||||||
mpack_tree_init_data(&tree, data, length);
|
|
||||||
mpack_tree_parse(&tree);
|
|
||||||
mpack_node_t root = mpack_tree_root(&tree);
|
|
||||||
if (mpack_node_is_nil(root))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (invalid mpack format)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mpack_node_is_nil(mpack_node_map_cstr(root, "tsync")))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (tsync no found)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
mpack_node_copy_cstr(mpack_node_map_cstr(root, "tsync"), handler->tsync, sizeof(handler->tsync));
|
|
||||||
if (strcmp(handler->tsync, "2.0") != 0)
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (invalid tsync version) %s", LOG_TAG_CTRLPKT, handler->tsync);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mpack_node_is_nil(mpack_node_map_cstr(root, "session_id")))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (session_id no found)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
handler->session_id = mpack_node_u64(mpack_node_map_cstr(root, "session_id"));
|
|
||||||
|
|
||||||
|
|
||||||
if (mpack_node_is_nil(mpack_node_map_cstr(root, "state")))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (state no found)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
mpack_node_copy_cstr(mpack_node_map_cstr(root, "state"), buff, sizeof(buff));
|
|
||||||
if (strncasecmp(buff, "opening", sizeof(buff)) == 0)
|
|
||||||
{
|
|
||||||
handler->state = SESSION_STATE_OPENING;
|
|
||||||
goto succ;
|
|
||||||
}
|
|
||||||
else if (strncasecmp(buff, "active", sizeof(buff)) == 0)
|
|
||||||
{
|
|
||||||
handler->state = SESSION_STATE_ACTIVE;
|
|
||||||
}
|
|
||||||
else if (strncasecmp(buff, "closing", sizeof(buff)) == 0)
|
|
||||||
{
|
|
||||||
handler->state = SESSION_STATE_CLOSING;
|
|
||||||
goto succ;
|
|
||||||
}
|
|
||||||
else if (strncasecmp(buff, "resetall", sizeof(buff)) == 0)
|
|
||||||
{
|
|
||||||
handler->state = SESSION_STATE_RESETALL;
|
|
||||||
goto succ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: unexpected control packet: (invalid state value) %s", LOG_TAG_CTRLPKT, buff);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mpack_node_is_nil(mpack_node_map_cstr(root, "method")))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (method no found)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
mpack_node_copy_cstr(mpack_node_map_cstr(root, "method"), handler->method, sizeof(handler->method));
|
|
||||||
|
|
||||||
if (mpack_node_is_nil(mpack_node_map_cstr(root, "params")))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (params no found)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
params = mpack_node_map_cstr(root, "params");
|
|
||||||
|
|
||||||
if (!mpack_node_is_missing(mpack_node_map_str_optional(params, "sce", strlen("sce"))))
|
|
||||||
{
|
|
||||||
sce_map = mpack_node_map_cstr(params, "sce");
|
|
||||||
if (mpack_node_is_nil(mpack_node_map_cstr(sce_map, "rule_ids")))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (sce rule_ids no found)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
handler->sce_policy_id_num = mpack_node_array_length(mpack_node_map_cstr(sce_map, "rule_ids"));
|
|
||||||
for (int i = 0; i < handler->sce_policy_id_num; i++) {
|
|
||||||
handler->sce_policy_ids[i] = mpack_node_u64(mpack_node_array_at(mpack_node_map_cstr(sce_map, "rule_ids"), i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handler->sce_policy_id_num) {
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu sce policy id num: [%d]", LOG_TAG_CTRLPKT, handler->session_id, handler->sce_policy_id_num);
|
|
||||||
for (int i = 0; i < handler->sce_policy_id_num; i++) {
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: session: %lu policy id:%lu ", LOG_TAG_CTRLPKT, handler->session_id, handler->sce_policy_ids[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mpack_node_is_missing(mpack_node_map_str_optional(params, "proxy", strlen("proxy"))))
|
|
||||||
{
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet: (proxy no found)", LOG_TAG_CTRLPKT);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy_map = mpack_node_map_cstr(params, "proxy");
|
|
||||||
proxy_parse_messagepack(proxy_map, handler);
|
|
||||||
|
|
||||||
succ:
|
|
||||||
mpack_tree_destroy(&tree);
|
|
||||||
return 0;
|
|
||||||
error:
|
|
||||||
mpack_tree_destroy(&tree);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -184,12 +184,12 @@ static int is_downstream_keepalive_packet(marsio_buff_t *rx_buff)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tfe_tap_write_per_thread(int tap_fd, const char *data, int data_len, void *logger)
|
static int tap_write(int tap_fd, const char *data, int data_len, void *logger)
|
||||||
{
|
{
|
||||||
int ret = write(tap_fd, data, data_len);
|
int ret = write(tap_fd, data, data_len);
|
||||||
if (ret != data_len)
|
if (ret != data_len)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: need send %dB, only send %dB, aborting: %s", LOG_TAG_PKTIO, data_len, ret, strerror(errno));
|
TFE_LOG_ERROR(logger, "%s: need send %dB, only send %dB, aborting: %s", LOG_TAG_PKTIO, data_len, ret, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -456,7 +456,7 @@ static int fake_tcp_handshake(struct tfe_proxy *proxy, struct tcp_restore_info *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int overwrite_tcp_mss(struct tfe_cmsg *cmsg, struct tcp_restore_info *restore)
|
static int overwrite_tcp_mss(struct tfe_cmsg *cmsg, struct tcp_restore_info *restore, uint64_t session_id, void *logger)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint16_t size = 0;
|
uint16_t size = 0;
|
||||||
@@ -468,25 +468,25 @@ static int overwrite_tcp_mss(struct tfe_cmsg *cmsg, struct tcp_restore_info *res
|
|||||||
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_DOWNSTREAM_TCP_MSS_ENABLE, (unsigned char *)&client_side_mss_enable, sizeof(client_side_mss_enable), &size);
|
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_DOWNSTREAM_TCP_MSS_ENABLE, (unsigned char *)&client_side_mss_enable, sizeof(client_side_mss_enable), &size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "failed at fetch client side tcp mss from cmsg: %s", strerror(-ret));
|
TFE_LOG_ERROR(logger, "%s: session %lu failed at fetch client side tcp mss from cmsg: %s", LOG_TAG_PKTIO, session_id, strerror(-ret));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_DOWNSTREAM_TCP_MSS_VALUE, (unsigned char *)&client_side_mss_value, sizeof(client_side_mss_value), &size);
|
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_DOWNSTREAM_TCP_MSS_VALUE, (unsigned char *)&client_side_mss_value, sizeof(client_side_mss_value), &size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "failed at fetch client side tcp mss value from cmsg: %s", strerror(-ret));
|
TFE_LOG_ERROR(logger, "%s: session %lu failed at fetch client side tcp mss value from cmsg: %s", LOG_TAG_PKTIO, session_id, strerror(-ret));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_UPSTREAM_TCP_MSS_ENABLE, (unsigned char *)&server_side_mss_enable, sizeof(server_side_mss_enable), &size);
|
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_UPSTREAM_TCP_MSS_ENABLE, (unsigned char *)&server_side_mss_enable, sizeof(server_side_mss_enable), &size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "failed at fetch server side tcp mss from cmsg: %s", strerror(-ret));
|
TFE_LOG_ERROR(logger, "%s: session %lu failed at fetch server side tcp mss from cmsg: %s", LOG_TAG_PKTIO, session_id, strerror(-ret));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_UPSTREAM_TCP_MSS_VALUE, (unsigned char *)&server_side_mss_value, sizeof(server_side_mss_value), &size);
|
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_UPSTREAM_TCP_MSS_VALUE, (unsigned char *)&server_side_mss_value, sizeof(server_side_mss_value), &size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "failed at fetch server side tcp mss value from cmsg: %s", strerror(-ret));
|
TFE_LOG_ERROR(logger, "%s: session %lu failed at fetch server side tcp mss value from cmsg: %s", LOG_TAG_PKTIO, session_id, strerror(-ret));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (client_side_mss_enable)
|
if (client_side_mss_enable)
|
||||||
@@ -700,7 +700,7 @@ static int tcp_restore_set_from_pkg(struct addr_tuple4 *tuple4, struct tcp_resto
|
|||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
static int packet_io_config(const char *profile, struct config *config)
|
static int packet_io_config(const char *profile, struct config *config, void *logger)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
@@ -730,77 +730,77 @@ static int packet_io_config(const char *profile, struct config *config)
|
|||||||
char src_mac_addr[18] = {0};
|
char src_mac_addr[18] = {0};
|
||||||
ret = MESA_load_profile_string_nodef(profile, "PACKET_IO", "src_mac_addr", src_mac_addr, sizeof(src_mac_addr));
|
ret = MESA_load_profile_string_nodef(profile, "PACKET_IO", "src_mac_addr", src_mac_addr, sizeof(src_mac_addr));
|
||||||
if(ret < 0){
|
if(ret < 0){
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: invalid src_mac_addr: src_mac_addr not set, profile = %s, section = PACKET_IO", LOG_TAG_PKTIO, profile);
|
TFE_LOG_ERROR(logger, "%s: invalid src_mac_addr: src_mac_addr not set, profile = %s, section = PACKET_IO", LOG_TAG_PKTIO, profile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
str_to_mac(src_mac_addr, config->src_mac);
|
str_to_mac(src_mac_addr, config->src_mac);
|
||||||
ret = get_mac_by_device_name(config->dev_tap, config->tap_mac);
|
ret = get_mac_by_device_name(config->dev_tap, config->tap_mac);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: invalid tap_name: unable get %s mac", LOG_TAG_PKTIO, config->dev_tap);
|
TFE_LOG_ERROR(logger, "%s: invalid tap_name: unable get %s mac", LOG_TAG_PKTIO, config->dev_tap);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = get_mac_by_device_name(config->dev_tap_c, config->tap_c_mac);
|
ret = get_mac_by_device_name(config->dev_tap_c, config->tap_c_mac);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: invalid device_client: unable get %s mac", LOG_TAG_PKTIO, config->dev_tap_c);
|
TFE_LOG_ERROR(logger, "%s: invalid device_client: unable get %s mac", LOG_TAG_PKTIO, config->dev_tap_c);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = get_mac_by_device_name(config->dev_tap_s, config->tap_s_mac);
|
ret = get_mac_by_device_name(config->dev_tap_s, config->tap_s_mac);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: invalid device_server: unable get %s mac", LOG_TAG_PKTIO, config->dev_tap_s);
|
TFE_LOG_ERROR(logger, "%s: invalid device_server: unable get %s mac", LOG_TAG_PKTIO, config->dev_tap_s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->rx_burst_max > RX_BURST_MAX)
|
if (config->rx_burst_max > RX_BURST_MAX)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: invalid rx_burst_max, exceeds limit %d", LOG_TAG_PKTIO, RX_BURST_MAX);
|
TFE_LOG_ERROR(logger, "%s: invalid rx_burst_max, exceeds limit %d", LOG_TAG_PKTIO, RX_BURST_MAX);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(config->app_symbol) == 0)
|
if (strlen(config->app_symbol) == 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: invalid app_symbol in %s", LOG_TAG_PKTIO, profile);
|
TFE_LOG_ERROR(logger, "%s: invalid app_symbol in %s", LOG_TAG_PKTIO, profile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(config->dev_nf_interface) == 0)
|
if (strlen(config->dev_nf_interface) == 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: invalid dev_nf_interface in %s", LOG_TAG_PKTIO, profile);
|
TFE_LOG_ERROR(logger, "%s: invalid dev_nf_interface in %s", LOG_TAG_PKTIO, profile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->bypass_all_traffic : %d", LOG_TAG_PKTIO, config->bypass_all_traffic);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->bypass_all_traffic : %d", LOG_TAG_PKTIO, config->bypass_all_traffic);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->rx_burst_max : %d", LOG_TAG_PKTIO, config->rx_burst_max);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->rx_burst_max : %d", LOG_TAG_PKTIO, config->rx_burst_max);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->app_symbol : %s", LOG_TAG_PKTIO, config->app_symbol);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->app_symbol : %s", LOG_TAG_PKTIO, config->app_symbol);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->dev_nf_interface : %s", LOG_TAG_PKTIO, config->dev_nf_interface);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->dev_nf_interface : %s", LOG_TAG_PKTIO, config->dev_nf_interface);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->tap_name : %s", LOG_TAG_PKTIO, config->tap_rps_mask);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->tap_name : %s", LOG_TAG_PKTIO, config->tap_rps_mask);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->tap_allow_mutilthread : %d", LOG_TAG_PKTIO, config->tap_allow_mutilthread);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->tap_allow_mutilthread : %d", LOG_TAG_PKTIO, config->tap_allow_mutilthread);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->bpf_obj : %s", LOG_TAG_PKTIO, config->bpf_obj);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->bpf_obj : %s", LOG_TAG_PKTIO, config->bpf_obj);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->bpf_debug_log : %d", LOG_TAG_PKTIO, config->bpf_debug_log);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->bpf_debug_log : %d", LOG_TAG_PKTIO, config->bpf_debug_log);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->bpf_hash_mode : %d", LOG_TAG_PKTIO, config->bpf_hash_mode);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->bpf_hash_mode : %d", LOG_TAG_PKTIO, config->bpf_hash_mode);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->tap_rps_enable : %d", LOG_TAG_PKTIO, config->tap_rps_enable);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->tap_rps_enable : %d", LOG_TAG_PKTIO, config->tap_rps_enable);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->tap_rps_mask : %s", LOG_TAG_PKTIO, config->tap_rps_mask);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->tap_rps_mask : %s", LOG_TAG_PKTIO, config->tap_rps_mask);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->enable_iouring : %d", LOG_TAG_PKTIO, config->enable_iouring);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->enable_iouring : %d", LOG_TAG_PKTIO, config->enable_iouring);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->enable_debuglog : %d", LOG_TAG_PKTIO, config->enable_debuglog);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->enable_debuglog : %d", LOG_TAG_PKTIO, config->enable_debuglog);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->ring_size : %d", LOG_TAG_PKTIO, config->ring_size);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->ring_size : %d", LOG_TAG_PKTIO, config->ring_size);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->buff_size : %d", LOG_TAG_PKTIO, config->buff_size);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->buff_size : %d", LOG_TAG_PKTIO, config->buff_size);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->flags : %d", LOG_TAG_PKTIO, config->flags);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->flags : %d", LOG_TAG_PKTIO, config->flags);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->sq_thread_idle : %d", LOG_TAG_PKTIO, config->sq_thread_idle);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->sq_thread_idle : %d", LOG_TAG_PKTIO, config->sq_thread_idle);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->device_client : %s", LOG_TAG_PKTIO, config->dev_tap_c);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->device_client : %s", LOG_TAG_PKTIO, config->dev_tap_c);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->device_server : %s", LOG_TAG_PKTIO, config->dev_tap_s);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->device_server : %s", LOG_TAG_PKTIO, config->dev_tap_s);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: PACKET_IO->src_mac_addr : %s", LOG_TAG_PKTIO, src_mac_addr);
|
TFE_LOG_DEBUG(logger, "%s: PACKET_IO->src_mac_addr : %s", LOG_TAG_PKTIO, src_mac_addr);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta, void *logger)
|
||||||
{
|
{
|
||||||
memset(meta, 0, sizeof(struct metadata));
|
memset(meta, 0, sizeof(struct metadata));
|
||||||
|
|
||||||
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_SESSION_ID, &(meta->session_id), sizeof(meta->session_id)) <= 0)
|
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_SESSION_ID, &(meta->session_id), sizeof(meta->session_id)) <= 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to get session_id from metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to get session_id from metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,7 +808,7 @@ static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
|||||||
meta->raw_data = marsio_buff_mtod(rx_buff);
|
meta->raw_data = marsio_buff_mtod(rx_buff);
|
||||||
if (meta->raw_data == NULL || meta->raw_len == 0)
|
if (meta->raw_data == NULL || meta->raw_len == 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to get raw_data from metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to get raw_data from metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -816,7 +816,7 @@ static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
|||||||
// 0: I2E
|
// 0: I2E
|
||||||
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_DIR, &(meta->is_e2i_dir), sizeof(meta->is_e2i_dir)) <= 0)
|
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_DIR, &(meta->is_e2i_dir), sizeof(meta->is_e2i_dir)) <= 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to get buff_dir from metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to get buff_dir from metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,7 +826,7 @@ static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
|||||||
// only control packet set MR_BUFF_PAYLOAD_OFFSET
|
// only control packet set MR_BUFF_PAYLOAD_OFFSET
|
||||||
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_PAYLOAD_OFFSET, &(meta->l7offset), sizeof(meta->l7offset)) <= 0)
|
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_PAYLOAD_OFFSET, &(meta->l7offset), sizeof(meta->l7offset)) <= 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to get l7offset from metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to get l7offset from metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -836,7 +836,7 @@ static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
|||||||
uint16_t user_data = 0;
|
uint16_t user_data = 0;
|
||||||
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_USER_0, &(user_data), sizeof(user_data)) <= 0)
|
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_USER_0, &(user_data), sizeof(user_data)) <= 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to get is_decrypted from metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to get is_decrypted from metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (user_data & TRAFFIC_IS_DECRYPTED)
|
if (user_data & TRAFFIC_IS_DECRYPTED)
|
||||||
@@ -852,14 +852,14 @@ static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
|||||||
meta->route_ctx.len = marsio_buff_get_metadata(rx_buff, MR_BUFF_ROUTE_CTX, meta->route_ctx.data, sizeof(meta->route_ctx.data));
|
meta->route_ctx.len = marsio_buff_get_metadata(rx_buff, MR_BUFF_ROUTE_CTX, meta->route_ctx.data, sizeof(meta->route_ctx.data));
|
||||||
if (meta->route_ctx.len <= 0)
|
if (meta->route_ctx.len <= 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to get route_ctx from metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to get route_ctx from metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
meta->sids.num = marsio_buff_get_sid_list(rx_buff, meta->sids.elems, sizeof(meta->sids.elems) / sizeof(meta->sids.elems[0]));
|
meta->sids.num = marsio_buff_get_sid_list(rx_buff, meta->sids.elems, sizeof(meta->sids.elems) / sizeof(meta->sids.elems[0]));
|
||||||
if (meta->sids.num < 0)
|
if (meta->sids.num < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to get sid_list from metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to get sid_list from metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,13 +868,13 @@ static int packet_io_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
|
|||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
static int packet_io_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
|
static int packet_io_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta, void *logger)
|
||||||
{
|
{
|
||||||
if (meta->session_id)
|
if (meta->session_id)
|
||||||
{
|
{
|
||||||
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_SESSION_ID, &(meta->session_id), sizeof(meta->session_id)) != 0)
|
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_SESSION_ID, &(meta->session_id), sizeof(meta->session_id)) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to set session_id for metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to set session_id for metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -884,7 +884,7 @@ static int packet_io_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
|
|||||||
marsio_buff_set_ctrlbuf(tx_buff);
|
marsio_buff_set_ctrlbuf(tx_buff);
|
||||||
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_PAYLOAD_OFFSET, &(meta->l7offset), sizeof(meta->l7offset)) != 0)
|
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_PAYLOAD_OFFSET, &(meta->l7offset), sizeof(meta->l7offset)) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to set l7offset for metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to set l7offset for metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -897,7 +897,7 @@ static int packet_io_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
|
|||||||
}
|
}
|
||||||
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_USER_0, &(user_data), sizeof(user_data)) != 0)
|
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_USER_0, &(user_data), sizeof(user_data)) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to set is_decrypted for metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to set is_decrypted for metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -906,7 +906,7 @@ static int packet_io_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
|
|||||||
{
|
{
|
||||||
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_ROUTE_CTX, meta->route_ctx.data, meta->route_ctx.len) != 0)
|
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_ROUTE_CTX, meta->route_ctx.data, meta->route_ctx.len) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to set route_ctx for metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to set route_ctx for metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -915,7 +915,7 @@ static int packet_io_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
|
|||||||
{
|
{
|
||||||
if (marsio_buff_set_sid_list(tx_buff, meta->sids.elems, meta->sids.num) != 0)
|
if (marsio_buff_set_sid_list(tx_buff, meta->sids.elems, meta->sids.num) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to set sid_list for metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to set sid_list for metadata", LOG_TAG_PKTIO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -923,9 +923,9 @@ static int packet_io_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void packet_io_dump_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
|
static void packet_io_dump_metadata(marsio_buff_t *tx_buff, struct metadata *meta, void *logger)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: META={session_id: %lu, raw_len: %d, is_e2i_dir: %d, is_ctrl_pkt: %d, l7offset: %d, is_decrypted: %u, sids_num: %d}", LOG_TAG_PKTIO, meta->session_id, meta->raw_len, meta->is_e2i_dir, meta->is_ctrl_pkt, meta->l7offset, meta->is_decrypted, meta->sids.num);
|
TFE_LOG_DEBUG(logger, "%s: META={session_id: %lu, raw_len: %d, is_e2i_dir: %d, is_ctrl_pkt: %d, l7offset: %d, is_decrypted: %u, sids_num: %d}", LOG_TAG_PKTIO, meta->session_id, meta->raw_len, meta->is_e2i_dir, meta->is_ctrl_pkt, meta->l7offset, meta->is_decrypted, meta->sids.num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -948,9 +948,10 @@ static void send_event_log(struct session_ctx *s_ctx, int thread_seq, void *ctx)
|
|||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
||||||
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
||||||
struct packet_io *packet_io = thread->ref_io;
|
struct packet_io *packet_io = thread->ref_io;
|
||||||
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
marsio_buff_t *tx_buffs[1];
|
marsio_buff_t *tx_buffs[1];
|
||||||
struct metadata meta = {0};
|
struct metadata meta = {0};
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
uint16_t length = 0;
|
uint16_t length = 0;
|
||||||
uint8_t ssl_intercept_status = 0;
|
uint8_t ssl_intercept_status = 0;
|
||||||
@@ -1059,8 +1060,8 @@ static void send_event_log(struct session_ctx *s_ctx, int thread_seq, void *ctx)
|
|||||||
meta.sids.num = 1;
|
meta.sids.num = 1;
|
||||||
meta.sids.elems[0] = acceptor_ctx->firewall_sids;
|
meta.sids.elems[0] = acceptor_ctx->firewall_sids;
|
||||||
route_ctx_copy(&meta.route_ctx, &s_ctx->ctrl_meta->route_ctx);
|
route_ctx_copy(&meta.route_ctx, &s_ctx->ctrl_meta->route_ctx);
|
||||||
packet_io_set_metadata(tx_buffs[0], &meta);
|
packet_io_set_metadata(tx_buffs[0], &meta, logger);
|
||||||
int nsend = marsio_buff_datalen(tx_buffs[0]);
|
ATOMIC_INC(&(packet_io_fs->session_log));
|
||||||
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread_seq, tx_buffs, 1);
|
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread_seq, tx_buffs, 1);
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
@@ -1068,21 +1069,65 @@ static void send_event_log(struct session_ctx *s_ctx, int thread_seq, void *ctx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tcp_restore_info_dump(struct tcp_restore_info *info, uint64_t session_id, void *logger)
|
||||||
|
{
|
||||||
|
char str_client_addr[64] = { 0 };
|
||||||
|
char str_server_addr[64] = { 0 };
|
||||||
|
|
||||||
|
const struct tcp_restore_endpoint *client = &info->client;
|
||||||
|
const struct tcp_restore_endpoint *server = &info->server;
|
||||||
|
|
||||||
|
assert(client->addr.ss_family == server->addr.ss_family);
|
||||||
|
|
||||||
|
if (client->addr.ss_family == AF_INET)
|
||||||
|
{
|
||||||
|
struct sockaddr_in *sk_client = (struct sockaddr_in *)&client->addr;
|
||||||
|
struct sockaddr_in *sk_server = (struct sockaddr_in *)&server->addr;
|
||||||
|
uint16_t port_client = ntohs(sk_client->sin_port);
|
||||||
|
uint16_t port_server = ntohs(sk_server->sin_port);
|
||||||
|
|
||||||
|
inet_ntop(AF_INET, &sk_client->sin_addr, str_client_addr, sizeof(str_client_addr));
|
||||||
|
inet_ntop(AF_INET, &sk_server->sin_addr, str_server_addr, sizeof(str_client_addr));
|
||||||
|
|
||||||
|
TFE_LOG_DEBUG(logger, "restore_info session %lu %s:%hu %s:%hu: cur_dir=%u\n"
|
||||||
|
"\tclient={ addr=%s, port=%hu, seq:%u, ack:%u, ts_val:%u, mss=%u, window:%hu, wscale_perm=%u, wscale=%u, timestamp_perm=%u, sack_perm=%u }\n"
|
||||||
|
"\tserver={ addr=%s, port=%hu, seq:%u, ack:%u, ts_val:%u, mss=%u, window:%hu, wscale_perm=%u, wscale=%u, timestamp_perm=%u, sack_perm=%u }",
|
||||||
|
session_id, str_client_addr, port_client, str_server_addr, port_server, info->cur_dir,
|
||||||
|
str_client_addr, port_client, client->seq, client->ack, client->ts_val, client->mss, client->window, (client->wscale_perm ? 1 : 0), client->wscale, (client->timestamp_perm ? 1 : 0), (client->sack_perm ? 1 : 0),
|
||||||
|
str_server_addr, port_server, server->seq, server->ack, server->ts_val, server->mss, server->window, (server->wscale_perm ? 1 : 0), server->wscale, (server->timestamp_perm ? 1 : 0), (server->sack_perm ? 1 : 0));
|
||||||
|
}
|
||||||
|
else if (client->addr.ss_family == AF_INET6)
|
||||||
|
{
|
||||||
|
struct sockaddr_in6 *sk_client = (struct sockaddr_in6 *)&client->addr;
|
||||||
|
struct sockaddr_in6 *sk_server = (struct sockaddr_in6 *)&server->addr;
|
||||||
|
uint16_t port_client = ntohs(sk_client->sin6_port);
|
||||||
|
uint16_t port_server = ntohs(sk_server->sin6_port);
|
||||||
|
|
||||||
|
inet_ntop(AF_INET6, &sk_client->sin6_addr, str_client_addr, sizeof(str_client_addr));
|
||||||
|
inet_ntop(AF_INET6, &sk_server->sin6_addr, str_server_addr, sizeof(str_client_addr));
|
||||||
|
|
||||||
|
TFE_LOG_DEBUG(logger, "restore_info session %lu %s:%hu %s:%hu: tcp_restore_info %p cur_dir=%u\n"
|
||||||
|
"\tclient={ addr=%s, port=%hu, seq:%u, ack:%u, ts_val:%u, mss=%u, window:%hu, wscale_perm=%u, wscale=%u, timestamp_perm=%u, sack_perm=%u }\n"
|
||||||
|
"\tserver={ addr=%s, port=%hu, seq:%u, ack:%u, ts_val:%u, mss=%u, window:%hu, wscale_perm=%u, wscale=%u, timestamp_perm=%u, sack_perm=%u }",
|
||||||
|
session_id, str_client_addr, port_client, str_server_addr, port_server, info, info->cur_dir,
|
||||||
|
str_client_addr, port_client, client->seq, client->ack, client->ts_val, client->mss, client->window, (client->wscale_perm ? 1 : 0), client->wscale, (client->timestamp_perm ? 1 : 0), (client->sack_perm ? 1 : 0),
|
||||||
|
str_server_addr, port_server, server->seq, server->ack, server->ts_val, server->mss, server->window, (server->wscale_perm ? 1 : 0), server->wscale, (server->timestamp_perm ? 1 : 0), (server->sack_perm ? 1 : 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser *parser, int thread_seq, void *ctx)
|
static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser *parser, int thread_seq, void *ctx)
|
||||||
{
|
{
|
||||||
uint8_t *iptmp = NULL;
|
|
||||||
int fd_downstream = 0;
|
int fd_downstream = 0;
|
||||||
int fd_upstream = 0;
|
int fd_upstream = 0;
|
||||||
int fd_fake_c = 0;
|
int fd_fake_c = 0;
|
||||||
int fd_fake_s = 0;
|
int fd_fake_s = 0;
|
||||||
uint16_t size = 0;
|
uint16_t size = 0;
|
||||||
char *addr_str = NULL;
|
|
||||||
|
|
||||||
unsigned int stream_common_direction;
|
unsigned int stream_common_direction;
|
||||||
uint8_t stream_protocol_in_char = 0;
|
uint8_t stream_protocol_in_char = 0;
|
||||||
uint8_t enalbe_decrypted_traffic_steering = 0;
|
uint8_t enable_decrypted_traffic_steering = 0;
|
||||||
struct ethhdr *ether_hdr = NULL;
|
struct ethhdr *ether_hdr = NULL;
|
||||||
struct session_ctx *s_ctx = NULL;
|
struct session_ctx *s_ctx = NULL;
|
||||||
struct addr_tuple4 inner_tuple4;
|
struct addr_tuple4 inner_tuple4;
|
||||||
@@ -1090,22 +1135,21 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
|||||||
memset(&inner_tuple4, 0, sizeof(inner_tuple4));
|
memset(&inner_tuple4, 0, sizeof(inner_tuple4));
|
||||||
memset(&restore_info, 0, sizeof(restore_info));
|
memset(&restore_info, 0, sizeof(restore_info));
|
||||||
|
|
||||||
struct sockaddr_in *in_addr_client = (struct sockaddr_in *)&restore_info.client.addr;
|
|
||||||
struct sockaddr_in *in_addr_server = (struct sockaddr_in *)&restore_info.server.addr;
|
|
||||||
|
|
||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
||||||
struct packet_io *packet_io = thread->ref_io;
|
struct packet_io *packet_io = thread->ref_io;
|
||||||
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
struct raw_pkt_parser raw_parser;
|
struct raw_pkt_parser raw_parser;
|
||||||
raw_packet_parser_init(&raw_parser, meta->session_id, LAYER_TYPE_ALL, 8);
|
raw_packet_parser_init(&raw_parser, meta->session_id, LAYER_TYPE_ALL, 8);
|
||||||
const void *payload = raw_packet_parser_parse(&raw_parser, (const void *)meta->raw_data, meta->raw_len);
|
const void *payload = raw_packet_parser_parse(&raw_parser, (const void *)meta->raw_data, meta->raw_len, logger);
|
||||||
if ((char *)payload - meta->raw_data != meta->l7offset)
|
if ((char *)payload - meta->raw_data != meta->l7offset)
|
||||||
{
|
{
|
||||||
uint16_t offset = (char *)payload - meta->raw_data;
|
uint16_t offset = (char *)payload - meta->raw_data;
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: incorrect dataoffset in the control zone of session %lu, offset:%u, l7offset:%u, payload:%p, raw_data:%p", LOG_TAG_PKTIO, meta->session_id, offset, meta->l7offset, payload, meta->raw_data);
|
TFE_LOG_ERROR(logger, "%s: incorrect dataoffset in the control zone of session %lu, offset:%u, l7offset:%u, payload:%p, raw_data:%p", LOG_TAG_PKTIO, meta->session_id, offset, meta->l7offset, payload, meta->raw_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_tuple4);
|
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_tuple4, logger);
|
||||||
|
|
||||||
intercept_policy_enforce(thread->ref_proxy->int_ply_enforcer, parser->cmsg);
|
intercept_policy_enforce(thread->ref_proxy->int_ply_enforcer, parser->cmsg);
|
||||||
tcp_policy_enforce(thread->ref_proxy->tcp_ply_enforcer, parser->cmsg);
|
tcp_policy_enforce(thread->ref_proxy->tcp_ply_enforcer, parser->cmsg);
|
||||||
@@ -1116,51 +1160,17 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
|||||||
tcp_restore_set_from_cmsg(parser->cmsg, &restore_info);
|
tcp_restore_set_from_cmsg(parser->cmsg, &restore_info);
|
||||||
tcp_restore_set_from_pkg(&inner_tuple4, &restore_info);
|
tcp_restore_set_from_pkg(&inner_tuple4, &restore_info);
|
||||||
|
|
||||||
if (overwrite_tcp_mss(parser->cmsg, &restore_info))
|
if (overwrite_tcp_mss(parser->cmsg, &restore_info, meta->session_id, logger))
|
||||||
{
|
{
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
tcp_restore_info_dump(&restore_info, meta->session_id, logger);
|
||||||
|
|
||||||
iptmp = (uint8_t *)&in_addr_client->sin_addr.s_addr;
|
|
||||||
// tcp repair C2S
|
// tcp repair C2S
|
||||||
addr_str = addr_tuple4_to_str(&inner_tuple4);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "restore_info session %lu %s : client", meta->session_id, addr_str);
|
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t addr:%d.%d.%d.%d", iptmp[0], iptmp[1], iptmp[2], iptmp[3]);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t port:%u", in_addr_client->sin_port);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t seq:%u", restore_info.client.seq);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t ack:%u", restore_info.client.ack);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t ts_val:%u", restore_info.client.ts_val);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t mss:%u", restore_info.client.mss);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t window:%u", restore_info.client.window);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t wscale:%u", restore_info.client.wscale);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t wscale_perm:%s", restore_info.client.wscale_perm > 0?"true":"false");
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t timestamp_perm:%s", restore_info.client.timestamp_perm > 0?"true":"false");
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t sack_perm:%s", restore_info.client.sack_perm > 0?"true":"false");
|
|
||||||
|
|
||||||
|
|
||||||
iptmp = (uint8_t *)&in_addr_server->sin_addr.s_addr;
|
|
||||||
// tcp repair C2S
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "restore_info session %lu %s : server", meta->session_id, addr_str);
|
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t addr:%d.%d.%d.%d", iptmp[0], iptmp[1], iptmp[2], iptmp[3]);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t port:%u", in_addr_server->sin_port);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t seq:%u", restore_info.server.seq);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t ack:%u", restore_info.server.ack);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t ts_val:%u", restore_info.server.ts_val);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t mss:%u", restore_info.server.mss);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t window:%u", restore_info.server.window);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t wscale:%u", restore_info.server.wscale);
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t wscale_perm:%s", restore_info.server.wscale_perm > 0?"true":"false");
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t timestamp_perm:%s", restore_info.server.timestamp_perm > 0?"true":"false");
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "\t sack_perm:%s", restore_info.server.sack_perm > 0?"true":"false");
|
|
||||||
|
|
||||||
free(addr_str);
|
|
||||||
|
|
||||||
fd_upstream = tfe_tcp_restore_fd_create(&(restore_info.client), &(restore_info.server), packet_io->config.dev_tap, 0x65);
|
fd_upstream = tfe_tcp_restore_fd_create(&(restore_info.client), &(restore_info.server), packet_io->config.dev_tap, 0x65);
|
||||||
if (fd_upstream < 0)
|
if (fd_upstream < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "Failed at tcp_restore_fd_create(UPSTREAM)");
|
TFE_LOG_ERROR(logger, "%s: session %lu Failed at tcp_restore_fd_create(UPSTREAM)", LOG_TAG_PKTIO, meta->session_id);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1168,40 +1178,40 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
|||||||
fd_downstream = tfe_tcp_restore_fd_create(&(restore_info.server), &(restore_info.client), packet_io->config.dev_tap, 0x65);
|
fd_downstream = tfe_tcp_restore_fd_create(&(restore_info.server), &(restore_info.client), packet_io->config.dev_tap, 0x65);
|
||||||
if (fd_downstream < 0)
|
if (fd_downstream < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "Failed at tcp_restore_fd_create(DOWNSTREAM)");
|
TFE_LOG_ERROR(logger, "%s: session %lu Failed at tcp_restore_fd_create(DOWNSTREAM)", LOG_TAG_PKTIO, meta->session_id);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
tfe_cmsg_get_value(parser->cmsg, TFE_CMSG_TCP_RESTORE_PROTOCOL, (unsigned char *)&stream_protocol_in_char, sizeof(stream_protocol_in_char), &size);
|
tfe_cmsg_get_value(parser->cmsg, TFE_CMSG_TCP_RESTORE_PROTOCOL, (unsigned char *)&stream_protocol_in_char, sizeof(stream_protocol_in_char), &size);
|
||||||
tfe_cmsg_get_value(parser->cmsg, TFE_CMSG_TCP_DECRYPTED_TRAFFIC_STEERING, (unsigned char *)&enalbe_decrypted_traffic_steering, sizeof(enalbe_decrypted_traffic_steering), &size);
|
tfe_cmsg_get_value(parser->cmsg, TFE_CMSG_TCP_DECRYPTED_TRAFFIC_STEERING, (unsigned char *)&enable_decrypted_traffic_steering, sizeof(enable_decrypted_traffic_steering), &size);
|
||||||
if ((STREAM_PROTO_PLAIN == (enum tfe_stream_proto)stream_protocol_in_char && thread->ref_proxy->traffic_steering_options.enable_steering_http) ||
|
if ((STREAM_PROTO_PLAIN == (enum tfe_stream_proto)stream_protocol_in_char && thread->ref_proxy->traffic_steering_options.enable_steering_http) ||
|
||||||
(STREAM_PROTO_SSL == (enum tfe_stream_proto)stream_protocol_in_char && thread->ref_proxy->traffic_steering_options.enable_steering_ssl) ||
|
(STREAM_PROTO_SSL == (enum tfe_stream_proto)stream_protocol_in_char && thread->ref_proxy->traffic_steering_options.enable_steering_ssl) ||
|
||||||
enalbe_decrypted_traffic_steering == 1)
|
enable_decrypted_traffic_steering == 1)
|
||||||
{
|
{
|
||||||
if (fake_tcp_handshake(thread->ref_proxy, &restore_info) == -1)
|
if (fake_tcp_handshake(thread->ref_proxy, &restore_info) == -1)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "session %lu Failed at fake_tcp_handshake()", meta->session_id);
|
TFE_LOG_ERROR(logger, "%s: session %lu Failed at fake_tcp_handshake()", LOG_TAG_PKTIO, meta->session_id);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_fake_c = tfe_tcp_restore_fd_create(&(restore_info.client), &(restore_info.server), thread->ref_proxy->traffic_steering_options.device_client, thread->ref_proxy->traffic_steering_options.so_mask_client);
|
fd_fake_c = tfe_tcp_restore_fd_create(&(restore_info.client), &(restore_info.server), thread->ref_proxy->traffic_steering_options.device_client, thread->ref_proxy->traffic_steering_options.so_mask_client);
|
||||||
if (fd_fake_c < 0)
|
if (fd_fake_c < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "session %lu Failed at tcp_restore_fd_create(fd_fake_c)", meta->session_id);
|
TFE_LOG_ERROR(logger, "%s: session %lu Failed at tcp_restore_fd_create(fd_fake_c)", LOG_TAG_PKTIO, meta->session_id);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_fake_s = tfe_tcp_restore_fd_create(&(restore_info.server), &(restore_info.client), thread->ref_proxy->traffic_steering_options.device_server, thread->ref_proxy->traffic_steering_options.so_mask_server);
|
fd_fake_s = tfe_tcp_restore_fd_create(&(restore_info.server), &(restore_info.client), thread->ref_proxy->traffic_steering_options.device_server, thread->ref_proxy->traffic_steering_options.so_mask_server);
|
||||||
if (fd_fake_s < 0)
|
if (fd_fake_s < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "session %lu Failed at tcp_restore_fd_create(fd_fake_s)", meta->session_id);
|
TFE_LOG_ERROR(logger, "%s: session %lu Failed at tcp_restore_fd_create(fd_fake_s)", LOG_TAG_PKTIO, meta->session_id);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tfe_proxy_fds_accept(thread->ref_proxy, fd_downstream, fd_upstream, fd_fake_c, fd_fake_s, parser->cmsg) < 0)
|
if (tfe_proxy_fds_accept(thread->ref_proxy, fd_downstream, fd_upstream, fd_fake_c, fd_fake_s, parser->cmsg) < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "session %lu Failed at tfe_proxy_fds_accept()", meta->session_id);
|
TFE_LOG_ERROR(logger, "%s: session %lu Failed at tfe_proxy_fds_accept()", LOG_TAG_PKTIO, meta->session_id);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1254,10 +1264,10 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
|||||||
route_ctx_copy(&s_ctx->raw_meta_e2i->route_ctx, &parser->ack_route_ctx);
|
route_ctx_copy(&s_ctx->raw_meta_e2i->route_ctx, &parser->ack_route_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: session %lu %s active first", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->session_addr);
|
TFE_LOG_INFO(logger, "%s: session %lu %s active first", LOG_TAG_PKTIO, s_ctx->session_id, s_ctx->session_addr);
|
||||||
|
|
||||||
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, s_ctx->session_id, &(s_ctx->c2s_info.tuple4), s_ctx, session_value_free_cb);
|
||||||
|
ATOMIC_INC(&(packet_io_fs->session_num));
|
||||||
return 0;
|
return 0;
|
||||||
end:
|
end:
|
||||||
if (parser->cmsg)
|
if (parser->cmsg)
|
||||||
@@ -1285,13 +1295,16 @@ static int handle_session_active(struct metadata *meta, struct ctrl_pkt_parser *
|
|||||||
static int handle_session_closing(struct metadata *meta, struct ctrl_pkt_parser *parser, int thread_seq, void *ctx)
|
static int handle_session_closing(struct metadata *meta, struct ctrl_pkt_parser *parser, int thread_seq, void *ctx)
|
||||||
{
|
{
|
||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
||||||
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
struct session_node *node = session_table_search_by_id(thread->session_table, meta->session_id);
|
struct session_node *node = session_table_search_by_id(thread->session_table, meta->session_id);
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
struct session_ctx *s_ctx = (struct session_ctx *)node->val_data;
|
struct session_ctx *s_ctx = (struct session_ctx *)node->val_data;
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: session %lu closing", LOG_TAG_PKTIO, s_ctx->session_id);
|
TFE_LOG_INFO(logger, "%s: session %lu closing", LOG_TAG_PKTIO, s_ctx->session_id);
|
||||||
session_table_delete_by_id(thread->session_table, meta->session_id);
|
session_table_delete_by_id(thread->session_table, meta->session_id);
|
||||||
|
ATOMIC_DEC(&(packet_io_fs->session_num));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1304,9 +1317,11 @@ static int handle_session_resetall(struct metadata *meta, struct ctrl_pkt_parser
|
|||||||
{
|
{
|
||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
||||||
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
||||||
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: session %lu resetall: notification clears all session tables !!!", LOG_TAG_PKTIO, meta->session_id);
|
TFE_LOG_ERROR(logger, "%s: session %lu resetall: notification clears all session tables !!!", LOG_TAG_PKTIO, meta->session_id);
|
||||||
|
ATOMIC_ZERO(&(packet_io_fs->session_num));
|
||||||
for (int i = 0; i < acceptor_ctx->nr_worker_threads; i++)
|
for (int i = 0; i < acceptor_ctx->nr_worker_threads; i++)
|
||||||
{
|
{
|
||||||
struct packet_io_thread_ctx *thread_ctx = &acceptor_ctx->work_threads[i];
|
struct packet_io_thread_ctx *thread_ctx = &acceptor_ctx->work_threads[i];
|
||||||
@@ -1321,29 +1336,28 @@ static int handle_session_resetall(struct metadata *meta, struct ctrl_pkt_parser
|
|||||||
static int handle_control_packet(struct packet_io *handle, marsio_buff_t *rx_buff, int thread_seq, void *ctx)
|
static int handle_control_packet(struct packet_io *handle, marsio_buff_t *rx_buff, int thread_seq, void *ctx)
|
||||||
{
|
{
|
||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
||||||
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
|
||||||
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
struct metadata meta;
|
struct metadata meta;
|
||||||
if (packet_io_get_metadata(rx_buff, &meta) == -1)
|
if (packet_io_get_metadata(rx_buff, &meta, logger) == -1)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet, unable to get metadata", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet, unable to get metadata\n\tMETA={session_id: %lu, raw_len: %d, is_e2i_dir: %d, is_ctrl_pkt: %d, l7offset: %d, is_decrypted: %u, sids_num: %d}",
|
||||||
packet_io_dump_metadata(rx_buff, &meta);
|
LOG_TAG_PKTIO, meta.session_id, meta.raw_len, meta.is_e2i_dir, meta.is_ctrl_pkt, meta.l7offset, meta.is_decrypted, meta.sids.num);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctrl_pkt_parser ctrl_parser;
|
struct ctrl_pkt_parser ctrl_parser;
|
||||||
ctrl_packet_parser_init(&ctrl_parser);
|
ctrl_packet_parser_init(&ctrl_parser);
|
||||||
if (ctrl_packet_parser_parse(&ctrl_parser, meta.raw_data + meta.l7offset, meta.raw_len - meta.l7offset) == -1)
|
if (ctrl_packet_parser_parse(&ctrl_parser, meta.raw_data + meta.l7offset, meta.raw_len - meta.l7offset, logger) == -1)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet, unable to parse data", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet, metadata's session %lu unable to parse data", LOG_TAG_PKTIO, meta.session_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ctrl_packet_parser_dump(&ctrl_parser);
|
|
||||||
|
|
||||||
if (ctrl_parser.session_id != meta.session_id)
|
if (ctrl_parser.session_id != meta.session_id)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected control packet, metadata's session %lu != control packet's session %lu", LOG_TAG_PKTIO, meta.session_id, ctrl_parser.session_id);
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet, metadata's session %lu != control packet's session %lu", LOG_TAG_PKTIO, meta.session_id, ctrl_parser.session_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1376,17 +1390,18 @@ static int handle_raw_packet_from_nf(struct packet_io *handle, marsio_buff_t *rx
|
|||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)ctx;
|
||||||
struct packet_io *packet_io = thread->ref_io;
|
struct packet_io *packet_io = thread->ref_io;
|
||||||
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
int raw_len = marsio_buff_datalen(rx_buff);
|
int raw_len = marsio_buff_datalen(rx_buff);
|
||||||
char *raw_data = marsio_buff_mtod(rx_buff);
|
char *raw_data = marsio_buff_mtod(rx_buff);
|
||||||
char *buff = NULL;
|
|
||||||
int buff_size = 0;
|
|
||||||
|
|
||||||
struct metadata meta;
|
struct metadata meta;
|
||||||
if (packet_io_get_metadata(rx_buff, &meta) == -1)
|
if (packet_io_get_metadata(rx_buff, &meta, logger) == -1)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected raw packet, unable to get metadata, bypass !!!", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unexpected control packet, unable to get metadata\n\tMETA={session_id: %lu, raw_len: %d, is_e2i_dir: %d, is_ctrl_pkt: %d, l7offset: %d, is_decrypted: %u, sids_num: %d}",
|
||||||
packet_io_dump_metadata(rx_buff, &meta);
|
LOG_TAG_PKTIO, meta.session_id, meta.raw_len, meta.is_e2i_dir, meta.is_ctrl_pkt, meta.l7offset, meta.is_decrypted, meta.sids.num);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_bypass, 1, raw_len);
|
||||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1394,7 +1409,8 @@ static int handle_raw_packet_from_nf(struct packet_io *handle, marsio_buff_t *rx
|
|||||||
struct session_node *node = session_table_search_by_id(thread->session_table, meta.session_id);
|
struct session_node *node = session_table_search_by_id(thread->session_table, meta.session_id);
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected raw packet, unable to find session %lu from session table, bypass !!!", LOG_TAG_PKTIO, meta.session_id);
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_bypass, 1, raw_len);
|
||||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1403,31 +1419,33 @@ static int handle_raw_packet_from_nf(struct packet_io *handle, marsio_buff_t *rx
|
|||||||
|
|
||||||
if (meta.is_decrypted)
|
if (meta.is_decrypted)
|
||||||
{
|
{
|
||||||
|
throughput_metrics_inc(&packet_io_fs->decrypt_rx, 1, raw_len);
|
||||||
// c2s
|
// c2s
|
||||||
if (meta.is_e2i_dir == s_ctx->c2s_info.is_e2i_dir) {
|
if (meta.is_e2i_dir == s_ctx->c2s_info.is_e2i_dir) {
|
||||||
add_ether_header(raw_data, packet_io->config.tap_c_mac, packet_io->config.tap_s_mac);
|
add_ether_header(raw_data, packet_io->config.tap_c_mac, packet_io->config.tap_s_mac);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->tap_s_pkt_tx, 1, raw_len);
|
||||||
if (packet_io->config.enable_iouring) {
|
if (packet_io->config.enable_iouring) {
|
||||||
io_uring_submit_write_entry(thread->tap_ctx->io_uring_s, raw_data, raw_len);
|
io_uring_submit_write_entry(thread->tap_ctx->io_uring_s, raw_data, raw_len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tfe_tap_write_per_thread(thread->tap_ctx->tap_s, raw_data, raw_len, g_default_logger);
|
tap_write(thread->tap_ctx->tap_s, raw_data, raw_len, logger);
|
||||||
}
|
}
|
||||||
throughput_metrics_inc(&packet_io_fs->tap_s_pkt_tx, 1, raw_len);
|
|
||||||
}
|
}
|
||||||
// s2c
|
// s2c
|
||||||
else {
|
else {
|
||||||
add_ether_header(raw_data, packet_io->config.tap_s_mac, packet_io->config.tap_c_mac);
|
add_ether_header(raw_data, packet_io->config.tap_s_mac, packet_io->config.tap_c_mac);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->tap_c_pkt_tx, 1, raw_len);
|
||||||
if (packet_io->config.enable_iouring) {
|
if (packet_io->config.enable_iouring) {
|
||||||
io_uring_submit_write_entry(thread->tap_ctx->io_uring_c, raw_data, raw_len);
|
io_uring_submit_write_entry(thread->tap_ctx->io_uring_c, raw_data, raw_len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tfe_tap_write_per_thread(thread->tap_ctx->tap_c, raw_data, raw_len, g_default_logger);
|
tap_write(thread->tap_ctx->tap_c, raw_data, raw_len, logger);
|
||||||
}
|
}
|
||||||
throughput_metrics_inc(&packet_io_fs->tap_c_pkt_tx, 1, raw_len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len);
|
||||||
if (meta.is_e2i_dir)
|
if (meta.is_e2i_dir)
|
||||||
{
|
{
|
||||||
if (metadata_is_empty(s_ctx->raw_meta_e2i))
|
if (metadata_is_empty(s_ctx->raw_meta_e2i))
|
||||||
@@ -1444,20 +1462,13 @@ static int handle_raw_packet_from_nf(struct packet_io *handle, marsio_buff_t *rx
|
|||||||
}
|
}
|
||||||
s_ctx->raw_meta_i2e->sids = meta.sids;
|
s_ctx->raw_meta_i2e->sids = meta.sids;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
struct raw_pkt_parser raw_parser;
|
|
||||||
raw_packet_parser_init(&raw_parser, meta->session_id, LAYER_TYPE_ALL, 8);
|
|
||||||
const void *payload = raw_packet_parser_parse(&raw_parser, (const void *)meta->raw_data, meta->raw_len);
|
|
||||||
buff_size = raw_len - ((char *)payload - meta->raw_data) + sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct tcphdr);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
// send to tap0
|
// send to tap0
|
||||||
add_ether_header(raw_data, packet_io->config.src_mac, packet_io->config.tap_mac);
|
add_ether_header(raw_data, packet_io->config.src_mac, packet_io->config.tap_mac);
|
||||||
if (packet_io->config.enable_iouring) {
|
if (packet_io->config.enable_iouring) {
|
||||||
io_uring_submit_write_entry(thread->tap_ctx->io_uring_fd, raw_data, raw_len);
|
io_uring_submit_write_entry(thread->tap_ctx->io_uring_fd, raw_data, raw_len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tfe_tap_write_per_thread(thread->tap_ctx->tap_fd, raw_data, raw_len, g_default_logger);
|
tap_write(thread->tap_ctx->tap_fd, raw_data, raw_len, logger);
|
||||||
}
|
}
|
||||||
throughput_metrics_inc(&packet_io_fs->tap_pkt_tx, 1, raw_len);
|
throughput_metrics_inc(&packet_io_fs->tap_pkt_tx, 1, raw_len);
|
||||||
|
|
||||||
@@ -1503,8 +1514,7 @@ struct tap_ctx *tfe_tap_ctx_create(void *ctx)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct packet_io_thread_ctx *thread_ctx = (struct packet_io_thread_ctx *)ctx;
|
struct packet_io_thread_ctx *thread_ctx = (struct packet_io_thread_ctx *)ctx;
|
||||||
struct acceptor_kni_v4 *acceptor_ctx = thread_ctx->ref_acceptor_ctx;
|
struct packet_io *packet_io = thread_ctx->ref_io;
|
||||||
struct packet_io *packet_io = acceptor_ctx->io;
|
|
||||||
struct tap_ctx *tap_ctx = (struct tap_ctx *)calloc(1, sizeof(struct tap_ctx));
|
struct tap_ctx *tap_ctx = (struct tap_ctx *)calloc(1, sizeof(struct tap_ctx));
|
||||||
assert(tap_ctx != NULL);
|
assert(tap_ctx != NULL);
|
||||||
|
|
||||||
@@ -1560,11 +1570,11 @@ error_out:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int packet_io_thread_init(struct packet_io *handle, struct packet_io_thread_ctx *thread_ctx)
|
int packet_io_thread_init(struct packet_io *handle, struct packet_io_thread_ctx *thread_ctx, void *logger)
|
||||||
{
|
{
|
||||||
if (marsio_thread_init(handle->instance) != 0)
|
if (marsio_thread_init(handle->instance) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to init marsio thread %d", LOG_TAG_PKTIO, thread_ctx->thread_index);
|
TFE_LOG_ERROR(logger, "%s: unable to init marsio thread %d", LOG_TAG_PKTIO, thread_ctx->thread_index);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1611,14 +1621,14 @@ void packet_io_destory(struct packet_io *handle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct packet_io *packet_io_create(const char *profile, int thread_num, cpu_set_t *coremask)
|
struct packet_io *packet_io_create(const char *profile, int thread_num, cpu_set_t *coremask, void *logger)
|
||||||
{
|
{
|
||||||
int opt = 1;
|
int opt = 1;
|
||||||
struct packet_io *handle = (struct packet_io *)calloc(1, sizeof(struct packet_io));
|
struct packet_io *handle = (struct packet_io *)calloc(1, sizeof(struct packet_io));
|
||||||
assert(handle != NULL);
|
assert(handle != NULL);
|
||||||
handle->thread_num = thread_num;
|
handle->thread_num = thread_num;
|
||||||
|
|
||||||
if (packet_io_config(profile, &(handle->config)) != 0)
|
if (packet_io_config(profile, &(handle->config), logger) != 0)
|
||||||
{
|
{
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
@@ -1632,32 +1642,32 @@ struct packet_io *packet_io_create(const char *profile, int thread_num, cpu_set_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (thread_num > 1){
|
else if (thread_num > 1){
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: under tap mode, when disable tap_allow_mutilthread, only support one work thread.", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: under tap mode, when disable tap_allow_mutilthread, only support one work thread.", LOG_TAG_PKTIO);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->instance = marsio_create();
|
handle->instance = marsio_create();
|
||||||
if (handle->instance == NULL)
|
if (handle->instance == NULL)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to create marsio instance", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to create marsio instance", LOG_TAG_PKTIO);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (marsio_option_set(handle->instance, MARSIO_OPT_THREAD_MASK_IN_CPUSET, coremask, sizeof(cpu_set_t)) != 0)
|
if (marsio_option_set(handle->instance, MARSIO_OPT_THREAD_MASK_IN_CPUSET, coremask, sizeof(cpu_set_t)) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to set MARSIO_OPT_EXIT_WHEN_ERR option for marsio instance", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to set MARSIO_OPT_EXIT_WHEN_ERR option for marsio instance", LOG_TAG_PKTIO);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (marsio_option_set(handle->instance, MARSIO_OPT_EXIT_WHEN_ERR, &opt, sizeof(opt)) != 0)
|
if (marsio_option_set(handle->instance, MARSIO_OPT_EXIT_WHEN_ERR, &opt, sizeof(opt)) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to set MARSIO_OPT_EXIT_WHEN_ERR option for marsio instance", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to set MARSIO_OPT_EXIT_WHEN_ERR option for marsio instance", LOG_TAG_PKTIO);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (marsio_init(handle->instance, handle->config.app_symbol) != 0)
|
if (marsio_init(handle->instance, handle->config.app_symbol) != 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to initialize marsio instance", LOG_TAG_PKTIO);
|
TFE_LOG_ERROR(logger, "%s: unable to initialize marsio instance", LOG_TAG_PKTIO);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1665,14 +1675,14 @@ struct packet_io *packet_io_create(const char *profile, int thread_num, cpu_set_
|
|||||||
handle->dev_nf_interface.mr_dev = marsio_open_device(handle->instance, handle->config.dev_nf_interface, handle->thread_num, handle->thread_num);
|
handle->dev_nf_interface.mr_dev = marsio_open_device(handle->instance, handle->config.dev_nf_interface, handle->thread_num, handle->thread_num);
|
||||||
if (handle->dev_nf_interface.mr_dev == NULL)
|
if (handle->dev_nf_interface.mr_dev == NULL)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to open device %s", LOG_TAG_PKTIO, handle->config.dev_nf_interface);
|
TFE_LOG_ERROR(logger, "%s: unable to open device %s", LOG_TAG_PKTIO, handle->config.dev_nf_interface);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->dev_nf_interface.mr_path = marsio_sendpath_create_by_vdev(handle->dev_nf_interface.mr_dev);
|
handle->dev_nf_interface.mr_path = marsio_sendpath_create_by_vdev(handle->dev_nf_interface.mr_dev);
|
||||||
if (handle->dev_nf_interface.mr_path == NULL)
|
if (handle->dev_nf_interface.mr_path == NULL)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to create sendpath for device %s", LOG_TAG_PKTIO, handle->config.dev_nf_interface);
|
TFE_LOG_ERROR(logger, "%s: unable to create sendpath for device %s", LOG_TAG_PKTIO, handle->config.dev_nf_interface);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1703,6 +1713,9 @@ int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, voi
|
|||||||
for (int i = 0; i < nr_recv; i++)
|
for (int i = 0; i < nr_recv; i++)
|
||||||
{
|
{
|
||||||
int raw_len = marsio_buff_datalen(rx_buffs[i]);
|
int raw_len = marsio_buff_datalen(rx_buffs[i]);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_tx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_bypass, 1, raw_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, rx_buffs, nr_recv);
|
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, rx_buffs, nr_recv);
|
||||||
@@ -1716,20 +1729,29 @@ int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, voi
|
|||||||
|
|
||||||
if (is_downstream_keepalive_packet(rx_buff))
|
if (is_downstream_keepalive_packet(rx_buff))
|
||||||
{
|
{
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_tx, 1, raw_len);
|
||||||
|
|
||||||
|
throughput_metrics_inc(&packet_io_fs->keepalived_pkt_rx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->keepalived_pkt_tx, 1, raw_len);
|
||||||
|
|
||||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (marsio_buff_is_ctrlbuf(rx_buff))
|
if (marsio_buff_is_ctrlbuf(rx_buff))
|
||||||
{
|
{
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_tx, 1, raw_len);
|
||||||
|
|
||||||
throughput_metrics_inc(&packet_io_fs->ctrl_pkt_rx, 1, raw_len);
|
throughput_metrics_inc(&packet_io_fs->ctrl_pkt_rx, 1, raw_len);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->ctrl_pkt_tx, 1, raw_len);
|
||||||
// all control packet need bypass
|
// all control packet need bypass
|
||||||
handle_control_packet(handle, rx_buff, thread_seq, ctx);
|
handle_control_packet(handle, rx_buff, thread_seq, ctx);
|
||||||
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len);
|
|
||||||
handle_raw_packet_from_nf(handle, rx_buff, thread_seq, ctx);
|
handle_raw_packet_from_nf(handle, rx_buff, thread_seq, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1742,28 +1764,31 @@ void handle_decryption_packet_from_tap(const char *data, int len, void *args)
|
|||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)args;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)args;
|
||||||
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
||||||
struct packet_io *packet_io = thread->ref_io;
|
struct packet_io *packet_io = thread->ref_io;
|
||||||
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
struct addr_tuple4 inner_addr;
|
struct addr_tuple4 inner_addr;
|
||||||
struct raw_pkt_parser raw_parser;
|
struct raw_pkt_parser raw_parser;
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
memset(&inner_addr, 0, sizeof(struct addr_tuple4));
|
memset(&inner_addr, 0, sizeof(struct addr_tuple4));
|
||||||
raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8);
|
raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8);
|
||||||
raw_packet_parser_parse(&raw_parser, (const void *)data, len);
|
raw_packet_parser_parse(&raw_parser, (const void *)data, len, logger);
|
||||||
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr);
|
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr, logger);
|
||||||
|
|
||||||
|
throughput_metrics_inc(&packet_io_fs->decrypt_rx, 1, len);
|
||||||
|
|
||||||
struct session_node *node = session_table_search_by_addr(thread->session_table, &inner_addr);
|
struct session_node *node = session_table_search_by_addr(thread->session_table, &inner_addr);
|
||||||
if (node == NULL)
|
if (node == NULL) {
|
||||||
{
|
throughput_metrics_inc(&packet_io_fs->decrypt_rxdrop, 1, len);
|
||||||
char *addr_string = addr_tuple4_to_str(&inner_addr);
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected inject packet, unable to find session %s from session table, drop !!!", LOG_TAG_PKTIO, addr_string);
|
|
||||||
free(addr_string);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct session_ctx *s_ctx = (struct session_ctx *)node->val_data;
|
struct session_ctx *s_ctx = (struct session_ctx *)node->val_data;
|
||||||
marsio_buff_t *tx_buffs[1];
|
marsio_buff_t *tx_buffs[1];
|
||||||
int alloc_ret = marsio_buff_malloc_device(packet_io->dev_nf_interface.mr_dev, tx_buffs, 1, 0, thread->thread_index);
|
int alloc_ret = marsio_buff_malloc_device(packet_io->dev_nf_interface.mr_dev, tx_buffs, 1, 0, thread->thread_index);
|
||||||
if (alloc_ret < 0){
|
if (alloc_ret < 0){
|
||||||
TFE_LOG_ERROR(g_default_logger, "Failed at alloc marsio buffer, ret = %d, thread_seq = %d",
|
TFE_LOG_ERROR(logger, "Failed at alloc marsio buffer, ret = %d, thread_seq = %d",
|
||||||
alloc_ret, thread->thread_index);
|
alloc_ret, thread->thread_index);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->decrypt_rxdrop, 1, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1781,10 +1806,14 @@ void handle_decryption_packet_from_tap(const char *data, int len, void *args)
|
|||||||
meta.sids.elems[0] = acceptor_ctx->sce_sids;
|
meta.sids.elems[0] = acceptor_ctx->sce_sids;
|
||||||
meta.sids.elems[1] = acceptor_ctx->proxy_sids;
|
meta.sids.elems[1] = acceptor_ctx->proxy_sids;
|
||||||
|
|
||||||
if (memcmp(&inner_addr, &s_ctx->c2s_info.tuple4, sizeof(struct addr_tuple4)) == 0)
|
if (memcmp(&inner_addr, &s_ctx->c2s_info.tuple4, sizeof(struct addr_tuple4)) == 0) {
|
||||||
meta.is_e2i_dir = s_ctx->c2s_info.is_e2i_dir;
|
meta.is_e2i_dir = s_ctx->c2s_info.is_e2i_dir;
|
||||||
else
|
throughput_metrics_inc(&packet_io_fs->tap_c_pkt_rx, 1, len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
meta.is_e2i_dir = s_ctx->s2c_info.is_e2i_dir;
|
meta.is_e2i_dir = s_ctx->s2c_info.is_e2i_dir;
|
||||||
|
throughput_metrics_inc(&packet_io_fs->tap_s_pkt_rx, 1, len);
|
||||||
|
}
|
||||||
|
|
||||||
if (meta.is_e2i_dir)
|
if (meta.is_e2i_dir)
|
||||||
{
|
{
|
||||||
@@ -1794,7 +1823,8 @@ void handle_decryption_packet_from_tap(const char *data, int len, void *args)
|
|||||||
{
|
{
|
||||||
route_ctx_copy(&meta.route_ctx, &s_ctx->raw_meta_i2e->route_ctx);
|
route_ctx_copy(&meta.route_ctx, &s_ctx->raw_meta_i2e->route_ctx);
|
||||||
}
|
}
|
||||||
packet_io_set_metadata(tx_buffs[0], &meta);
|
packet_io_set_metadata(tx_buffs[0], &meta, logger);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->decrypt_tx, 1, len);
|
||||||
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread->thread_index, tx_buffs, 1);
|
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread->thread_index, tx_buffs, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1803,30 +1833,32 @@ void handle_raw_packet_from_tap(const char *data, int len, void *args)
|
|||||||
char *src_mac = NULL;
|
char *src_mac = NULL;
|
||||||
char *dst_mac = NULL;
|
char *dst_mac = NULL;
|
||||||
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)args;
|
struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)args;
|
||||||
struct acceptor_kni_v4 *acceptor_ctx = thread->ref_acceptor_ctx;
|
|
||||||
struct packet_io *packet_io = thread->ref_io;
|
struct packet_io *packet_io = thread->ref_io;
|
||||||
|
struct packet_io_fs *packet_io_fs = thread->ret_fs_state;
|
||||||
struct addr_tuple4 inner_addr;
|
struct addr_tuple4 inner_addr;
|
||||||
struct raw_pkt_parser raw_parser;
|
struct raw_pkt_parser raw_parser;
|
||||||
|
void * logger = thread->logger;
|
||||||
|
|
||||||
memset(&inner_addr, 0, sizeof(struct addr_tuple4));
|
memset(&inner_addr, 0, sizeof(struct addr_tuple4));
|
||||||
raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8);
|
raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8);
|
||||||
raw_packet_parser_parse(&raw_parser, (const void *)data, len);
|
raw_packet_parser_parse(&raw_parser, (const void *)data, len, logger);
|
||||||
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr);
|
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr, logger);
|
||||||
|
|
||||||
|
throughput_metrics_inc(&packet_io_fs->tap_pkt_rx, 1, len);
|
||||||
|
|
||||||
struct session_node *node = session_table_search_by_addr(thread->session_table, &inner_addr);
|
struct session_node *node = session_table_search_by_addr(thread->session_table, &inner_addr);
|
||||||
if (node == NULL)
|
if (node == NULL) {
|
||||||
{
|
throughput_metrics_inc(&packet_io_fs->tap_pkt_rxdrop, 1, len);
|
||||||
char *addr_string = addr_tuple4_to_str(&inner_addr);
|
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unexpected inject packet, unable to find session %s from session table, drop !!!", LOG_TAG_PKTIO, addr_string);
|
|
||||||
free(addr_string);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct session_ctx *s_ctx = (struct session_ctx *)node->val_data;
|
struct session_ctx *s_ctx = (struct session_ctx *)node->val_data;
|
||||||
marsio_buff_t *tx_buffs[1];
|
marsio_buff_t *tx_buffs[1];
|
||||||
int alloc_ret = marsio_buff_malloc_device(packet_io->dev_nf_interface.mr_dev, tx_buffs, 1, 0, thread->thread_index);
|
int alloc_ret = marsio_buff_malloc_device(packet_io->dev_nf_interface.mr_dev, tx_buffs, 1, 0, thread->thread_index);
|
||||||
if (alloc_ret < 0){
|
if (alloc_ret < 0){
|
||||||
TFE_LOG_ERROR(g_default_logger, "Failed at alloc marsio buffer, ret = %d, thread_seq = %d",
|
TFE_LOG_ERROR(logger, "Failed at alloc marsio buffer, ret = %d, thread_seq = %d",
|
||||||
alloc_ret, thread->thread_index);
|
alloc_ret, thread->thread_index);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->tap_pkt_rxdrop, 1, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1865,8 +1897,8 @@ void handle_raw_packet_from_tap(const char *data, int len, void *args)
|
|||||||
route_ctx_copy(&meta.route_ctx, &s_ctx->raw_meta_i2e->route_ctx);
|
route_ctx_copy(&meta.route_ctx, &s_ctx->raw_meta_i2e->route_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packet_io_set_metadata(tx_buffs[0], &meta, logger);
|
||||||
packet_io_set_metadata(tx_buffs[0], &meta);
|
|
||||||
add_ether_header(dst, src_mac, dst_mac);
|
add_ether_header(dst, src_mac, dst_mac);
|
||||||
|
throughput_metrics_inc(&packet_io_fs->raw_pkt_tx, 1, len);
|
||||||
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread->thread_index, tx_buffs, 1);
|
marsio_send_burst(packet_io->dev_nf_interface.mr_path, thread->thread_index, tx_buffs, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,9 @@
|
|||||||
|
|
||||||
enum PACKET_IO_STAT_FIELD
|
enum PACKET_IO_STAT_FIELD
|
||||||
{
|
{
|
||||||
// hit block policy
|
|
||||||
STAT_HIT_POLICY_PKT,
|
|
||||||
STAT_HIT_POLICY_B,
|
|
||||||
|
|
||||||
// dev nf interface
|
// dev nf interface
|
||||||
STAT_RAW_PKT_RX_PKT,
|
STAT_RAW_PKT_RX_PKT,
|
||||||
STAT_RAW_PKT_RX_B,
|
STAT_RAW_PKT_RX_B,
|
||||||
|
|
||||||
STAT_RAW_PKT_TX_PKT,
|
STAT_RAW_PKT_TX_PKT,
|
||||||
STAT_RAW_PKT_TX_B,
|
STAT_RAW_PKT_TX_B,
|
||||||
|
|
||||||
@@ -24,16 +19,18 @@ enum PACKET_IO_STAT_FIELD
|
|||||||
STAT_DECRYPTED_RX_PKT,
|
STAT_DECRYPTED_RX_PKT,
|
||||||
STAT_DECRYPTED_RX_B,
|
STAT_DECRYPTED_RX_B,
|
||||||
|
|
||||||
// control packet
|
STAT_RAW_PKT_BYPASS_PKT,
|
||||||
STAT_CONTROL_RX_PKT,
|
STAT_RAW_PKT_BYPASS_B,
|
||||||
STAT_CONTROL_RX_B,
|
|
||||||
STAT_CONTROL_TX_PKT,
|
STAT_DECRYPT_RXDROP_PKT,
|
||||||
STAT_CONTROL_TX_B,
|
STAT_DECRYPT_RXDROP_B,
|
||||||
|
|
||||||
STAT_TAP_RX_PKT,
|
STAT_TAP_RX_PKT,
|
||||||
STAT_TAP_RX_B,
|
STAT_TAP_RX_B,
|
||||||
STAT_TAP_TX_PKT,
|
STAT_TAP_TX_PKT,
|
||||||
STAT_TAP_TX_B,
|
STAT_TAP_TX_B,
|
||||||
|
STAT_TAP_RXDROP_PKT,
|
||||||
|
STAT_TAP_RXDROP_B,
|
||||||
|
|
||||||
STAT_TAP_C_RX_PKT,
|
STAT_TAP_C_RX_PKT,
|
||||||
STAT_TAP_C_RX_B,
|
STAT_TAP_C_RX_B,
|
||||||
@@ -45,14 +42,26 @@ enum PACKET_IO_STAT_FIELD
|
|||||||
STAT_TAP_S_TX_PKT,
|
STAT_TAP_S_TX_PKT,
|
||||||
STAT_TAP_S_TX_B,
|
STAT_TAP_S_TX_B,
|
||||||
|
|
||||||
|
// keepalived packet
|
||||||
|
STAT_KEEPALIVED_RX_PKT,
|
||||||
|
STAT_KEEPALIVED_RX_B,
|
||||||
|
STAT_KEEPALIVED_TX_PKT,
|
||||||
|
STAT_KEEPALIVED_TX_B,
|
||||||
|
|
||||||
|
// control packet
|
||||||
|
STAT_CONTROL_RX_PKT,
|
||||||
|
STAT_CONTROL_RX_B,
|
||||||
|
STAT_CONTROL_TX_PKT,
|
||||||
|
STAT_CONTROL_TX_B,
|
||||||
|
|
||||||
STAT_CTRL_PKT_OPENING,
|
STAT_CTRL_PKT_OPENING,
|
||||||
STAT_CTRL_PKT_ACTIVE,
|
STAT_CTRL_PKT_ACTIVE,
|
||||||
STAT_CTRL_PKT_CLOSING,
|
STAT_CTRL_PKT_CLOSING,
|
||||||
STAT_CTRL_PKT_RESETALL,
|
STAT_CTRL_PKT_RESETALL,
|
||||||
STAT_CTRL_PKT_ERROR,
|
STAT_CTRL_PKT_ERROR,
|
||||||
|
|
||||||
// send log
|
STAT_SESSION_NUM,
|
||||||
STAT_SEND_LOG,
|
STAT_SESSION_LOG,
|
||||||
|
|
||||||
// max
|
// max
|
||||||
STAT_MAX,
|
STAT_MAX,
|
||||||
@@ -60,14 +69,9 @@ enum PACKET_IO_STAT_FIELD
|
|||||||
|
|
||||||
static const char *stat_map[] =
|
static const char *stat_map[] =
|
||||||
{
|
{
|
||||||
// hit policy
|
|
||||||
[STAT_HIT_POLICY_PKT] = "hit_policy_pkt",
|
|
||||||
[STAT_HIT_POLICY_B] = "hit_policy_B",
|
|
||||||
|
|
||||||
// dev nf interface
|
// dev nf interface
|
||||||
[STAT_RAW_PKT_RX_PKT] = "raw_rx_pkt",
|
[STAT_RAW_PKT_RX_PKT] = "raw_rx_pkt",
|
||||||
[STAT_RAW_PKT_RX_B] = "raw_rx_B",
|
[STAT_RAW_PKT_RX_B] = "raw_rx_B",
|
||||||
|
|
||||||
[STAT_RAW_PKT_TX_PKT] = "raw_tx_pkt",
|
[STAT_RAW_PKT_TX_PKT] = "raw_tx_pkt",
|
||||||
[STAT_RAW_PKT_TX_B] = "raw_tx_B",
|
[STAT_RAW_PKT_TX_B] = "raw_tx_B",
|
||||||
|
|
||||||
@@ -77,26 +81,44 @@ static const char *stat_map[] =
|
|||||||
[STAT_DECRYPTED_RX_PKT] = "decrypt_rx_pkt",
|
[STAT_DECRYPTED_RX_PKT] = "decrypt_rx_pkt",
|
||||||
[STAT_DECRYPTED_RX_B] = "decrypt_rx_B",
|
[STAT_DECRYPTED_RX_B] = "decrypt_rx_B",
|
||||||
|
|
||||||
// control packet
|
[STAT_RAW_PKT_BYPASS_PKT] = "raw_bypass_pkt",
|
||||||
[STAT_CONTROL_RX_PKT] = "ctrl_rx_pkt",
|
[STAT_RAW_PKT_BYPASS_B] = "raw_bypass_B",
|
||||||
[STAT_CONTROL_RX_B] = "ctrl_rx_B",
|
|
||||||
[STAT_CONTROL_TX_PKT] = "ctrl_tx_pkt",
|
[STAT_DECRYPT_RXDROP_PKT] = "dec_rxdrop_pkt",
|
||||||
[STAT_CONTROL_TX_B] = "ctrl_tx_B",
|
[STAT_DECRYPT_RXDROP_B] = "dec_rxdrop_B",
|
||||||
|
|
||||||
// tap packet
|
// tap packet
|
||||||
[STAT_TAP_RX_PKT] = "tap_rx_pkt",
|
[STAT_TAP_RX_PKT] = "tap_rx_pkt",
|
||||||
[STAT_TAP_RX_B] = "tap_rx_B",
|
[STAT_TAP_RX_B] = "tap_rx_B",
|
||||||
[STAT_TAP_TX_PKT] = "tap_tx_pkt",
|
[STAT_TAP_TX_PKT] = "tap_tx_pkt",
|
||||||
[STAT_TAP_TX_B] = "tap_tx_B",
|
[STAT_TAP_TX_B] = "tap_tx_B",
|
||||||
|
[STAT_TAP_RXDROP_PKT] = "tap_rxdrop_pkt",
|
||||||
|
[STAT_TAP_RXDROP_B] = "tap_rxdrop_B",
|
||||||
|
|
||||||
|
// tap_c packet
|
||||||
[STAT_TAP_C_RX_PKT] = "tap_c_rx_pkt",
|
[STAT_TAP_C_RX_PKT] = "tap_c_rx_pkt",
|
||||||
[STAT_TAP_C_RX_B] = "tap_c_rx_B",
|
[STAT_TAP_C_RX_B] = "tap_c_rx_B",
|
||||||
[STAT_TAP_C_TX_PKT] = "tap_c_tx_pkt",
|
[STAT_TAP_C_TX_PKT] = "tap_c_tx_pkt",
|
||||||
[STAT_TAP_C_TX_B] = "tap_c_tx_B",
|
[STAT_TAP_C_TX_B] = "tap_c_tx_B",
|
||||||
|
|
||||||
|
// tap_s packet
|
||||||
[STAT_TAP_S_RX_PKT] = "tap_s_rx_pkt",
|
[STAT_TAP_S_RX_PKT] = "tap_s_rx_pkt",
|
||||||
[STAT_TAP_S_RX_B] = "tap_s_rx_B",
|
[STAT_TAP_S_RX_B] = "tap_s_rx_B",
|
||||||
[STAT_TAP_S_TX_PKT] = "tap_s_tx_pkt",
|
[STAT_TAP_S_TX_PKT] = "tap_s_tx_pkt",
|
||||||
[STAT_TAP_S_TX_B] = "tap_s_tx_B",
|
[STAT_TAP_S_TX_B] = "tap_s_tx_B",
|
||||||
|
|
||||||
|
// keepalived packet
|
||||||
|
[STAT_KEEPALIVED_RX_PKT] = "keep_rx_pkt",
|
||||||
|
[STAT_KEEPALIVED_RX_B] = "keep_rx_B",
|
||||||
|
[STAT_KEEPALIVED_TX_PKT] = "keep_tx_pkt",
|
||||||
|
[STAT_KEEPALIVED_TX_B] = "keep_tx_B",
|
||||||
|
|
||||||
|
// control packet
|
||||||
|
[STAT_CONTROL_RX_PKT] = "ctrl_rx_pkt",
|
||||||
|
[STAT_CONTROL_RX_B] = "ctrl_rx_B",
|
||||||
|
[STAT_CONTROL_TX_PKT] = "ctrl_tx_pkt",
|
||||||
|
[STAT_CONTROL_TX_B] = "ctrl_tx_B",
|
||||||
|
|
||||||
[STAT_CTRL_PKT_OPENING] = "ctrl_pkt_open",
|
[STAT_CTRL_PKT_OPENING] = "ctrl_pkt_open",
|
||||||
[STAT_CTRL_PKT_ACTIVE] = "ctrl_pkt_avtive",
|
[STAT_CTRL_PKT_ACTIVE] = "ctrl_pkt_avtive",
|
||||||
[STAT_CTRL_PKT_CLOSING] = "ctrl_pkt_close",
|
[STAT_CTRL_PKT_CLOSING] = "ctrl_pkt_close",
|
||||||
@@ -104,7 +126,8 @@ static const char *stat_map[] =
|
|||||||
[STAT_CTRL_PKT_ERROR] = "ctrl_pkt_error",
|
[STAT_CTRL_PKT_ERROR] = "ctrl_pkt_error",
|
||||||
|
|
||||||
// send log
|
// send log
|
||||||
[STAT_SEND_LOG] = "send_log",
|
[STAT_SESSION_NUM] = "session_num",
|
||||||
|
[STAT_SESSION_LOG] = "session_log",
|
||||||
|
|
||||||
[STAT_MAX] = NULL
|
[STAT_MAX] = NULL
|
||||||
};
|
};
|
||||||
@@ -119,21 +142,22 @@ void throughput_metrics_inc(struct throughput_metrics *iterm, uint64_t n_pkts, u
|
|||||||
__atomic_fetch_add(&iterm->n_pkts, n_pkts, __ATOMIC_RELAXED);
|
__atomic_fetch_add(&iterm->n_pkts, n_pkts, __ATOMIC_RELAXED);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct packet_io_fs *packet_io_fs_create()
|
struct packet_io_fs *packet_io_fs_create(const char *profile)
|
||||||
{
|
{
|
||||||
int value=0, i=0;
|
int value=0;
|
||||||
const char* app_name="packet_io";
|
const char* app_name="packet_io";
|
||||||
const char* fieldstat_output="log/packet_io.fs2";
|
const char* fieldstat_output="log/packet_io.fs2";
|
||||||
|
|
||||||
struct packet_io_fs *handle = (struct packet_io_fs *)calloc(1, sizeof(struct packet_io_fs));
|
struct packet_io_fs *handle = (struct packet_io_fs *)calloc(1, sizeof(struct packet_io_fs));
|
||||||
|
|
||||||
handle->fs_handle=FS_create_handle();
|
handle->fs_handle=FS_create_handle();
|
||||||
|
FS_set_para(handle->fs_handle, APP_NAME, app_name, strlen(app_name)+1);
|
||||||
FS_set_para(handle->fs_handle, OUTPUT_DEVICE, fieldstat_output, strlen(fieldstat_output)+1);
|
FS_set_para(handle->fs_handle, OUTPUT_DEVICE, fieldstat_output, strlen(fieldstat_output)+1);
|
||||||
value = 1;
|
value = 1;
|
||||||
|
FS_set_para(handle->fs_handle, OUTPUT_PROMETHEUS, &value, sizeof(value));
|
||||||
|
value=1;
|
||||||
FS_set_para(handle->fs_handle, PRINT_MODE, &value, sizeof(value));
|
FS_set_para(handle->fs_handle, PRINT_MODE, &value, sizeof(value));
|
||||||
value=0;
|
value=0;
|
||||||
FS_set_para(handle->fs_handle, CREATE_THREAD, &value, sizeof(value));
|
FS_set_para(handle->fs_handle, CREATE_THREAD, &value, sizeof(value));
|
||||||
FS_set_para(handle->fs_handle, APP_NAME, app_name, strlen(app_name)+1);
|
|
||||||
|
|
||||||
for (int i = 0; i < STAT_MAX; i++)
|
for (int i = 0; i < STAT_MAX; i++)
|
||||||
{
|
{
|
||||||
@@ -147,7 +171,6 @@ void packet_io_fs_destory(struct packet_io_fs *handle)
|
|||||||
{
|
{
|
||||||
if (handle)
|
if (handle)
|
||||||
{
|
{
|
||||||
FS_library_destroy();
|
|
||||||
free(handle);
|
free(handle);
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
}
|
}
|
||||||
@@ -157,49 +180,59 @@ void packet_io_fs_dump(struct packet_io_fs *handle)
|
|||||||
{
|
{
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
return;
|
return;
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_HIT_POLICY_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->hit_policy.n_pkts), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_HIT_POLICY_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->hit_policy.n_bytes), 0, __ATOMIC_RELAXED));
|
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPTED_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_BYPASS_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_bypass.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_RAW_PKT_BYPASS_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->raw_bypass.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPT_RXDROP_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_rxdrop.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_DECRYPT_RXDROP_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->decrypt_rxdrop.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_RXDROP_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rxdrop.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_RXDROP_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rxdrop.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_s_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_s_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_s_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_s_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
|
// keepalived packet
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_KEEPALIVED_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->keepalived_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_KEEPALIVED_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->keepalived_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_KEEPALIVED_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->keepalived_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_KEEPALIVED_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->keepalived_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
// control packet
|
// control packet
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CONTROL_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_C_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_c_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_RX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rx.n_pkts), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_RX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_rx.n_bytes), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_TX_PKT], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_tx.n_pkts), 0, __ATOMIC_RELAXED));
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_TAP_S_TX_B], 0, FS_OP_SET, __atomic_fetch_add(&(handle->tap_pkt_tx.n_bytes), 0, __ATOMIC_RELAXED));
|
|
||||||
|
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_OPENING], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_opening_num), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_OPENING], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_opening_num), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_ACTIVE], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_active_num), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_ACTIVE], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_active_num), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_CLOSING], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_closing_num), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_CLOSING], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_closing_num), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_RESETALL], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_resetall_num), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_RESETALL], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_resetall_num), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_ERROR], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_error_num), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_CTRL_PKT_ERROR], 0, FS_OP_SET, __atomic_fetch_add(&(handle->ctrl_pkt_error_num), 0, __ATOMIC_RELAXED));
|
||||||
|
|
||||||
// send log
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_SESSION_NUM], 0, FS_OP_SET, __atomic_fetch_add(&(handle->session_num), 0, __ATOMIC_RELAXED));
|
||||||
FS_operate(handle->fs_handle, handle->fs_id[STAT_SEND_LOG], 0, FS_OP_SET, __atomic_fetch_add(&(handle->send_log), 0, __ATOMIC_RELAXED));
|
FS_operate(handle->fs_handle, handle->fs_id[STAT_SESSION_LOG], 0, FS_OP_SET, __atomic_fetch_add(&(handle->session_log), 0, __ATOMIC_RELAXED));
|
||||||
|
FS_passive_output(handle->fs_handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,16 +76,16 @@ static const char *layer_type2str(enum layer_type this_type);
|
|||||||
static uint16_t parse_gtphdr_len(const struct gtp_hdr *gtph);
|
static uint16_t parse_gtphdr_len(const struct gtp_hdr *gtph);
|
||||||
|
|
||||||
// parser protocol
|
// parser protocol
|
||||||
static const void *parse_ether(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_ether(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_ipv4(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_ipv4(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_ipv6(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_ipv6(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_tcp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_tcp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_udp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_udp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_pppoe_ses(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_pppoe_ses(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_vxlan(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_vxlan(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_vlan8021q(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_vlan8021q(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_gtpv1_u(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_gtpv1_u(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
static const void *parse_mpls(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type);
|
static const void *parse_mpls(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Public API
|
* Public API
|
||||||
@@ -103,17 +103,17 @@ void raw_packet_parser_init(struct raw_pkt_parser *handler, uint64_t pkt_trace_i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return most inner payload
|
// return most inner payload
|
||||||
const void *raw_packet_parser_parse(struct raw_pkt_parser *handler, const void *data, size_t length)
|
const void *raw_packet_parser_parse(struct raw_pkt_parser *handler, const void *data, size_t length, void *logger)
|
||||||
{
|
{
|
||||||
handler->ptr_pkt_start = data;
|
handler->ptr_pkt_start = data;
|
||||||
|
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ether(handler, data, length, LAYER_TYPE_ETHER);
|
return parse_ether(handler, data, length, LAYER_TYPE_ETHER, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int raw_packet_parser_get_most_inner_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr)
|
int raw_packet_parser_get_most_inner_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger)
|
||||||
{
|
{
|
||||||
const char *l3_layer_data = NULL;
|
const char *l3_layer_data = NULL;
|
||||||
const char *l4_layer_data = NULL;
|
const char *l4_layer_data = NULL;
|
||||||
@@ -127,7 +127,7 @@ int raw_packet_parser_get_most_inner_tuple4(struct raw_pkt_parser *handler, stru
|
|||||||
const struct layer_result *layer = &results->layers[i];
|
const struct layer_result *layer = &results->layers[i];
|
||||||
enum layer_type type = layer->type;
|
enum layer_type type = layer->type;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: find most inner tuple4, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
TFE_LOG_DEBUG(logger, "%s: find most inner tuple4, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
||||||
|
|
||||||
// first get L4 layer
|
// first get L4 layer
|
||||||
if (type & LAYER_TYPE_L4)
|
if (type & LAYER_TYPE_L4)
|
||||||
@@ -168,7 +168,7 @@ int raw_packet_parser_get_most_inner_tuple4(struct raw_pkt_parser *handler, stru
|
|||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr)
|
int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger)
|
||||||
{
|
{
|
||||||
const char *l3_layer_data = NULL;
|
const char *l3_layer_data = NULL;
|
||||||
const char *l4_layer_data = NULL;
|
const char *l4_layer_data = NULL;
|
||||||
@@ -182,7 +182,7 @@ int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, stru
|
|||||||
const struct layer_result *layer = &results->layers[i];
|
const struct layer_result *layer = &results->layers[i];
|
||||||
enum layer_type type = layer->type;
|
enum layer_type type = layer->type;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: find most outer tuple4, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
TFE_LOG_DEBUG(logger, "%s: find most outer tuple4, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
||||||
|
|
||||||
// first get L3 layer
|
// first get L3 layer
|
||||||
if (type & LAYER_TYPE_L3)
|
if (type & LAYER_TYPE_L3)
|
||||||
@@ -223,7 +223,7 @@ int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, stru
|
|||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int raw_packet_parser_get_most_inner_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr)
|
int raw_packet_parser_get_most_inner_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger)
|
||||||
{
|
{
|
||||||
const char *l3_layer_data = NULL;
|
const char *l3_layer_data = NULL;
|
||||||
struct layer_results *results = &handler->results;
|
struct layer_results *results = &handler->results;
|
||||||
@@ -234,7 +234,7 @@ int raw_packet_parser_get_most_inner_address(struct raw_pkt_parser *handler, str
|
|||||||
const struct layer_result *layer = &results->layers[i];
|
const struct layer_result *layer = &results->layers[i];
|
||||||
enum layer_type type = layer->type;
|
enum layer_type type = layer->type;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: find most inner address, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
TFE_LOG_DEBUG(logger, "%s: find most inner address, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
||||||
if (type & LAYER_TYPE_L3)
|
if (type & LAYER_TYPE_L3)
|
||||||
{
|
{
|
||||||
l3_layer_data = (const char *)handler->ptr_pkt_start + layer->offset;
|
l3_layer_data = (const char *)handler->ptr_pkt_start + layer->offset;
|
||||||
@@ -248,7 +248,7 @@ int raw_packet_parser_get_most_inner_address(struct raw_pkt_parser *handler, str
|
|||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : error
|
// return -1 : error
|
||||||
int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr)
|
int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger)
|
||||||
{
|
{
|
||||||
const char *l3_layer_data = NULL;
|
const char *l3_layer_data = NULL;
|
||||||
struct layer_results *results = &handler->results;
|
struct layer_results *results = &handler->results;
|
||||||
@@ -259,7 +259,7 @@ int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, str
|
|||||||
const struct layer_result *layer = &results->layers[i];
|
const struct layer_result *layer = &results->layers[i];
|
||||||
enum layer_type type = layer->type;
|
enum layer_type type = layer->type;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: find most outer address, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
TFE_LOG_DEBUG(logger, "%s: find most outer address, pkt_trace_id: %lu, layer[%d/%d]: %s", LOG_TAG_RAWPKT, handler->pkt_trace_id, i, results->layers_size, layer_type2str(type));
|
||||||
if (type & LAYER_TYPE_L3)
|
if (type & LAYER_TYPE_L3)
|
||||||
{
|
{
|
||||||
l3_layer_data = (const char *)handler->ptr_pkt_start + layer->offset;
|
l3_layer_data = (const char *)handler->ptr_pkt_start + layer->offset;
|
||||||
@@ -271,7 +271,7 @@ int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, str
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal)
|
uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal, void *logger)
|
||||||
{
|
{
|
||||||
uint64_t temp = 0;
|
uint64_t temp = 0;
|
||||||
uint64_t hash_value = 1;
|
uint64_t hash_value = 1;
|
||||||
@@ -293,12 +293,12 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
|
|||||||
return hash_value;
|
return hash_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw_packet_parser_get_most_inner_address(handler, &inner_addr) == -1)
|
if (raw_packet_parser_get_most_inner_address(handler, &inner_addr, logger) == -1)
|
||||||
{
|
{
|
||||||
return hash_value;
|
return hash_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw_packet_parser_get_most_outer_address(handler, &outer_addr) == -1)
|
if (raw_packet_parser_get_most_outer_address(handler, &outer_addr, logger) == -1)
|
||||||
{
|
{
|
||||||
return hash_value;
|
return hash_value;
|
||||||
}
|
}
|
||||||
@@ -391,7 +391,7 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
|
|||||||
|
|
||||||
char *inner_addr_str = addr_tuple4_to_str(&inner_addr);
|
char *inner_addr_str = addr_tuple4_to_str(&inner_addr);
|
||||||
char *outer_addr_str = addr_tuple4_to_str(&outer_addr);
|
char *outer_addr_str = addr_tuple4_to_str(&outer_addr);
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, outer_addr: %s, inner_addr: %s, is_internal: %d, hash_method: %s, hash_value: %lu",
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, outer_addr: %s, inner_addr: %s, is_internal: %d, hash_method: %s, hash_value: %lu",
|
||||||
LOG_TAG_RAWPKT, handler->pkt_trace_id, outer_addr_str, inner_addr_str, dir_is_internal, ldbc_method_to_string(method), hash_value);
|
LOG_TAG_RAWPKT, handler->pkt_trace_id, outer_addr_str, inner_addr_str, dir_is_internal, ldbc_method_to_string(method), hash_value);
|
||||||
free(inner_addr_str);
|
free(inner_addr_str);
|
||||||
free(outer_addr_str);
|
free(outer_addr_str);
|
||||||
@@ -582,11 +582,11 @@ static uint16_t parse_gtphdr_len(const struct gtp_hdr *gtph)
|
|||||||
return (char *)p_ext_hdr - (char *)gtph;
|
return (char *)p_ext_hdr - (char *)gtph;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_ether(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_ether(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct ethhdr))
|
if (length < sizeof(struct ethhdr))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,38 +601,38 @@ static const void *parse_ether(struct raw_pkt_parser *handler, const void *data,
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
switch (next_proto)
|
switch (next_proto)
|
||||||
{
|
{
|
||||||
case ETH_P_8021Q:
|
case ETH_P_8021Q:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_vlan8021q(handler, data_next_layer, data_next_length, LAYER_TYPE_VLAN);
|
return parse_vlan8021q(handler, data_next_layer, data_next_length, LAYER_TYPE_VLAN, logger);
|
||||||
case ETH_P_8021AD:
|
case ETH_P_8021AD:
|
||||||
// TODO
|
// TODO
|
||||||
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER);
|
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER, logger);
|
||||||
case ETH_P_IP:
|
case ETH_P_IP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4);
|
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4, logger);
|
||||||
case ETH_P_IPV6:
|
case ETH_P_IPV6:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6);
|
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6, logger);
|
||||||
case ETH_P_PPP_SES:
|
case ETH_P_PPP_SES:
|
||||||
// TODO
|
// TODO
|
||||||
return parse_pppoe_ses(handler, data_next_layer, data_next_length, LAYER_TYPE_PPPOE);
|
return parse_pppoe_ses(handler, data_next_layer, data_next_length, LAYER_TYPE_PPPOE, logger);
|
||||||
case ETH_P_MPLS_UC:
|
case ETH_P_MPLS_UC:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_mpls(handler, data_next_layer, data_next_length, LAYER_TYPE_MPLS);
|
return parse_mpls(handler, data_next_layer, data_next_length, LAYER_TYPE_MPLS, logger);
|
||||||
default:
|
default:
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_ipv4(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_ipv4(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct ip))
|
if (length < sizeof(struct ip))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,32 +647,32 @@ static const void *parse_ipv4(struct raw_pkt_parser *handler, const void *data,
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
switch (next_proto)
|
switch (next_proto)
|
||||||
{
|
{
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_tcp(handler, data_next_layer, data_next_length, LAYER_TYPE_TCP);
|
return parse_tcp(handler, data_next_layer, data_next_length, LAYER_TYPE_TCP, logger);
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_udp(handler, data_next_layer, data_next_length, LAYER_TYPE_UDP);
|
return parse_udp(handler, data_next_layer, data_next_length, LAYER_TYPE_UDP, logger);
|
||||||
case IPPROTO_IPIP:
|
case IPPROTO_IPIP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4);
|
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4, logger);
|
||||||
case IPPROTO_IPV6:
|
case IPPROTO_IPV6:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6);
|
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6, logger);
|
||||||
default:
|
default:
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_ipv6(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_ipv6(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct ip6_hdr))
|
if (length < sizeof(struct ip6_hdr))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,32 +687,32 @@ static const void *parse_ipv6(struct raw_pkt_parser *handler, const void *data,
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
switch (next_proto)
|
switch (next_proto)
|
||||||
{
|
{
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_tcp(handler, data_next_layer, data_next_length, LAYER_TYPE_TCP);
|
return parse_tcp(handler, data_next_layer, data_next_length, LAYER_TYPE_TCP, logger);
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_udp(handler, data_next_layer, data_next_length, LAYER_TYPE_UDP);
|
return parse_udp(handler, data_next_layer, data_next_length, LAYER_TYPE_UDP, logger);
|
||||||
case IPPROTO_IPIP:
|
case IPPROTO_IPIP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4);
|
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4, logger);
|
||||||
case IPPROTO_IPV6:
|
case IPPROTO_IPV6:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6);
|
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6, logger);
|
||||||
default:
|
default:
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_tcp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_tcp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct tcphdr))
|
if (length < sizeof(struct tcphdr))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,16 +726,16 @@ static const void *parse_tcp(struct raw_pkt_parser *handler, const void *data, s
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
|
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_udp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_udp(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct udp_hdr))
|
if (length < sizeof(struct udp_hdr))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,27 +749,27 @@ static const void *parse_udp(struct raw_pkt_parser *handler, const void *data, s
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
switch (ntohs(hdr->uh_dport))
|
switch (ntohs(hdr->uh_dport))
|
||||||
{
|
{
|
||||||
// VXLAN_DPORT
|
// VXLAN_DPORT
|
||||||
case 4789:
|
case 4789:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_vxlan(handler, data_next_layer, data_next_length, LAYER_TYPE_G_VXLAN);
|
return parse_vxlan(handler, data_next_layer, data_next_length, LAYER_TYPE_G_VXLAN, logger);
|
||||||
// GTP1U_PORT
|
// GTP1U_PORT
|
||||||
case 2152:
|
case 2152:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_gtpv1_u(handler, data_next_layer, data_next_length, LAYER_TYPE_GTPV1_U);
|
return parse_gtpv1_u(handler, data_next_layer, data_next_length, LAYER_TYPE_GTPV1_U, logger);
|
||||||
default:
|
default:
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_pppoe_ses(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_pppoe_ses(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < 8)
|
if (length < 8)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -783,28 +783,28 @@ static const void *parse_pppoe_ses(struct raw_pkt_parser *handler, const void *d
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
switch (next_proto)
|
switch (next_proto)
|
||||||
{
|
{
|
||||||
// PPPOE_TYPE_IPV4
|
// PPPOE_TYPE_IPV4
|
||||||
case 0x2100:
|
case 0x2100:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4);
|
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4, logger);
|
||||||
// PPPOE_TYPE_IPV6
|
// PPPOE_TYPE_IPV6
|
||||||
case 0x5700:
|
case 0x5700:
|
||||||
// TODO
|
// TODO
|
||||||
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6);
|
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6, logger);
|
||||||
default:
|
default:
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_vxlan(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_vxlan(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct vxlan_hdr))
|
if (length < sizeof(struct vxlan_hdr))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -818,16 +818,16 @@ static const void *parse_vxlan(struct raw_pkt_parser *handler, const void *data,
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER);
|
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_vlan8021q(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_vlan8021q(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct vlan_hdr))
|
if (length < sizeof(struct vlan_hdr))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -842,35 +842,35 @@ static const void *parse_vlan8021q(struct raw_pkt_parser *handler, const void *d
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
switch (next_proto)
|
switch (next_proto)
|
||||||
{
|
{
|
||||||
case ETH_P_8021Q:
|
case ETH_P_8021Q:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_vlan8021q(handler, data_next_layer, data_next_length, LAYER_TYPE_VLAN);
|
return parse_vlan8021q(handler, data_next_layer, data_next_length, LAYER_TYPE_VLAN, logger);
|
||||||
case ETH_P_IP:
|
case ETH_P_IP:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4);
|
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4, logger);
|
||||||
case ETH_P_IPV6:
|
case ETH_P_IPV6:
|
||||||
// TODO
|
// TODO
|
||||||
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6);
|
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6, logger);
|
||||||
case ETH_P_PPP_SES:
|
case ETH_P_PPP_SES:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_pppoe_ses(handler, data_next_layer, data_next_length, LAYER_TYPE_PPPOE);
|
return parse_pppoe_ses(handler, data_next_layer, data_next_length, LAYER_TYPE_PPPOE, logger);
|
||||||
case ETH_P_MPLS_UC:
|
case ETH_P_MPLS_UC:
|
||||||
// TODO
|
// TODO
|
||||||
return parse_mpls(handler, data_next_layer, data_next_length, LAYER_TYPE_MPLS);
|
return parse_mpls(handler, data_next_layer, data_next_length, LAYER_TYPE_MPLS, logger);
|
||||||
default:
|
default:
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_gtpv1_u(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_gtpv1_u(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < sizeof(struct gtp_hdr))
|
if (length < sizeof(struct gtp_hdr))
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -889,26 +889,26 @@ static const void *parse_gtpv1_u(struct raw_pkt_parser *handler, const void *dat
|
|||||||
const void *data_next_layer = (const char *)data + hdr_len;
|
const void *data_next_layer = (const char *)data + hdr_len;
|
||||||
size_t data_next_length = length - hdr_len;
|
size_t data_next_length = length - hdr_len;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
switch (next_proto)
|
switch (next_proto)
|
||||||
{
|
{
|
||||||
case 4:
|
case 4:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4);
|
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4, logger);
|
||||||
case 6:
|
case 6:
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6);
|
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6, logger);
|
||||||
default:
|
default:
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, stop parse next protocol %d", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), next_proto);
|
||||||
return data_next_layer;
|
return data_next_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *parse_mpls(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type)
|
static const void *parse_mpls(struct raw_pkt_parser *handler, const void *data, size_t length, enum layer_type this_type, void *logger)
|
||||||
{
|
{
|
||||||
if (length < 4)
|
if (length < 4)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
TFE_LOG_ERROR(logger, "%s: pkt_trace_id: %lu, this_layer: %s, err: data not enough", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -962,33 +962,33 @@ static const void *parse_mpls(struct raw_pkt_parser *handler, const void *data,
|
|||||||
data_next_layer = (const char *)data_next_layer + 4;
|
data_next_layer = (const char *)data_next_layer + 4;
|
||||||
data_next_length = data_next_length - 4;
|
data_next_length = data_next_length - 4;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER);
|
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER, logger);
|
||||||
}
|
}
|
||||||
else if (ip_version == 4)
|
else if (ip_version == 4)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4);
|
return parse_ipv4(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV4, logger);
|
||||||
}
|
}
|
||||||
else if (ip_version == 6)
|
else if (ip_version == 6)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
// TODO
|
// TODO
|
||||||
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6);
|
return parse_ipv6(handler, data_next_layer, data_next_length, LAYER_TYPE_IPV6, logger);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
// TODO
|
// TODO
|
||||||
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER);
|
return parse_ether(handler, data_next_layer, data_next_length, LAYER_TYPE_ETHER, logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
|
||||||
// TESTED
|
// TESTED
|
||||||
return parse_mpls(handler, data_next_layer, data_next_length, LAYER_TYPE_MPLS);
|
return parse_mpls(handler, data_next_layer, data_next_length, LAYER_TYPE_MPLS, logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "tfe_session_table.h"
|
#include "tfe_session_table.h"
|
||||||
#include <tfe_utils.h>
|
#include <tfe_utils.h>
|
||||||
|
|
||||||
|
extern void * g_packet_io_logger;
|
||||||
|
|
||||||
struct session_table
|
struct session_table
|
||||||
{
|
{
|
||||||
struct session_node *root_by_id;
|
struct session_node *root_by_id;
|
||||||
@@ -90,7 +92,7 @@ int session_table_insert(struct session_table *table, uint64_t session_id, const
|
|||||||
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
|
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
|
||||||
if (temp)
|
if (temp)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: insert: key %lu exists", LOG_TAG_STABLE, session_id);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: insert: key %lu exists", LOG_TAG_STABLE, session_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +107,7 @@ int session_table_insert(struct session_table *table, uint64_t session_id, const
|
|||||||
HASH_ADD(hh1, table->root_by_id, session_id, sizeof(temp->session_id), temp);
|
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);
|
HASH_ADD(hh2, table->root_by_addr, session_addr, sizeof(temp->session_addr), temp);
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: insert: key %lu success", LOG_TAG_STABLE, session_id);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: insert: key %lu success", LOG_TAG_STABLE, session_id);
|
||||||
table->session_node_count++;
|
table->session_node_count++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -117,7 +119,7 @@ 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);
|
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: delete: key %lu not exists", LOG_TAG_STABLE, session_id);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: delete: key %lu not exists", LOG_TAG_STABLE, session_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +135,7 @@ int session_table_delete_by_id(struct session_table *table, uint64_t session_id)
|
|||||||
free(temp);
|
free(temp);
|
||||||
temp = NULL;
|
temp = NULL;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: delete: key %lu success", LOG_TAG_STABLE, session_id);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: delete: key %lu success", LOG_TAG_STABLE, session_id);
|
||||||
table->session_node_count--;
|
table->session_node_count--;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -151,7 +153,7 @@ 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);
|
HASH_FIND(hh2, table->root_by_addr, &reverse_addr, sizeof(struct addr_tuple4), temp);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: delete: key %s not exists", LOG_TAG_STABLE, addr_str);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: delete: key %s not exists", LOG_TAG_STABLE, addr_str);
|
||||||
free(addr_str);
|
free(addr_str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -169,7 +171,7 @@ int session_table_delete_by_addr(struct session_table *table, const struct addr_
|
|||||||
free(temp);
|
free(temp);
|
||||||
temp = NULL;
|
temp = NULL;
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: delete: key %s success", LOG_TAG_STABLE, addr_str);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: delete: key %s success", LOG_TAG_STABLE, addr_str);
|
||||||
free(addr_str);
|
free(addr_str);
|
||||||
addr_str = NULL;
|
addr_str = NULL;
|
||||||
table->session_node_count--;
|
table->session_node_count--;
|
||||||
@@ -183,11 +185,11 @@ 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);
|
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: search: key %lu not exists", LOG_TAG_STABLE, session_id);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: search: key %lu not exists", LOG_TAG_STABLE, session_id);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: search: key %lu success", LOG_TAG_STABLE, session_id);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: search: key %lu success", LOG_TAG_STABLE, session_id);
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
@@ -204,14 +206,14 @@ 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);
|
HASH_FIND(hh2, table->root_by_addr, &reverse_addr, sizeof(struct addr_tuple4), temp);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
{
|
{
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: search: key %s not exists", LOG_TAG_STABLE, addr_str);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: search: key %s not exists", LOG_TAG_STABLE, addr_str);
|
||||||
free(addr_str);
|
free(addr_str);
|
||||||
addr_str = NULL;
|
addr_str = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TFE_LOG_DEBUG(g_default_logger, "%s: search: key %s success", LOG_TAG_STABLE, addr_str);
|
TFE_LOG_DEBUG(g_packet_io_logger, "%s: search: key %s success", LOG_TAG_STABLE, addr_str);
|
||||||
free(addr_str);
|
free(addr_str);
|
||||||
addr_str = NULL;
|
addr_str = NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
// TEST(MPACK, PARSE)
|
// TEST(MPACK, PARSE)
|
||||||
// {
|
// {
|
||||||
// struct ctrl_pkt_parser handler;
|
// struct ctrl_pkt_parser handler;
|
||||||
// parse_messagepack();
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|||||||
@@ -18,3 +18,4 @@ http.DEBUG "./log/http.log.%d(%F)";
|
|||||||
http2.DEBUG "./log/http2.log.%d(%F)";
|
http2.DEBUG "./log/http2.log.%d(%F)";
|
||||||
doh.DEBUG "./log/doh_pxy.log.%d(%F)";
|
doh.DEBUG "./log/doh_pxy.log.%d(%F)";
|
||||||
tsg_http.DEBUG "./log/tsg_http_pxy.log.%d(%F)";
|
tsg_http.DEBUG "./log/tsg_http_pxy.log.%d(%F)";
|
||||||
|
packet_io.DEBUG "./log/packet_io.log.%d(%F)";
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
struct tfe_proxy;
|
struct tfe_proxy;
|
||||||
|
|
||||||
struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const char *profile, void *logger);
|
struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const char *profile);
|
||||||
void acceptor_kni_v4_destroy();
|
void acceptor_kni_v4_destroy();
|
||||||
|
|||||||
@@ -21,34 +21,35 @@
|
|||||||
#include "tfe_session_table.h"
|
#include "tfe_session_table.h"
|
||||||
|
|
||||||
|
|
||||||
static int tfe_tap_read_per_thread(int tap_fd, char *buff, int buff_size, void *logger)
|
void * g_packet_io_logger = NULL;
|
||||||
|
|
||||||
|
static int tap_read(int tap_fd, char *buff, int buff_size, void *logger)
|
||||||
{
|
{
|
||||||
int ret = read(tap_fd, buff, buff_size);
|
int ret = read(tap_fd, buff, buff_size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
if (errno != EWOULDBLOCK && errno != EAGAIN)
|
if (errno != EWOULDBLOCK && errno != EAGAIN)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: unable to read data from tapfd %d, aborting: %s", LOG_TAG_PKTIO, tap_fd, strerror(errno));
|
TFE_LOG_ERROR(logger, "%s: unable to read data from tapfd %d, aborting: %s", LOG_TAG_PKTIO, tap_fd, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void acceptor_ctx_destory(struct acceptor_kni_v4 * ctx)
|
void acceptor_kni_v4_destroy(struct acceptor_kni_v4 *ctx)
|
||||||
{
|
{
|
||||||
if (ctx)
|
if (ctx)
|
||||||
{
|
{
|
||||||
packet_io_destory(ctx->io);
|
packet_io_destory(ctx->io);
|
||||||
packet_io_fs_destory(ctx->packet_io_fs);
|
packet_io_fs_destory(ctx->packet_io_fs);
|
||||||
|
|
||||||
free(ctx);
|
free(ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile)
|
struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile, void *logger)
|
||||||
{
|
{
|
||||||
struct acceptor_kni_v4 *ctx = ALLOC(struct acceptor_kni_v4, 1);
|
struct acceptor_kni_v4 *ctx = ALLOC(struct acceptor_kni_v4, 1);
|
||||||
|
|
||||||
@@ -66,13 +67,13 @@ struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile)
|
|||||||
CPU_SET(cpu_id, &ctx->coremask);
|
CPU_SET(cpu_id, &ctx->coremask);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->io = packet_io_create(profile, ctx->nr_worker_threads, &ctx->coremask);
|
ctx->io = packet_io_create(profile, ctx->nr_worker_threads, &ctx->coremask, logger);
|
||||||
if (ctx->io == NULL)
|
if (ctx->io == NULL)
|
||||||
{
|
{
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->packet_io_fs = packet_io_fs_create();
|
ctx->packet_io_fs = packet_io_fs_create(profile);
|
||||||
if (ctx->packet_io_fs == NULL)
|
if (ctx->packet_io_fs == NULL)
|
||||||
{
|
{
|
||||||
goto error_out;
|
goto error_out;
|
||||||
@@ -81,7 +82,7 @@ struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile)
|
|||||||
return ctx;
|
return ctx;
|
||||||
|
|
||||||
error_out:
|
error_out:
|
||||||
acceptor_ctx_destory(ctx);
|
acceptor_kni_v4_destroy(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,18 +90,19 @@ static void *worker_thread_cycle(void *arg)
|
|||||||
{
|
{
|
||||||
struct packet_io_thread_ctx *thread_ctx = (struct packet_io_thread_ctx *)arg;
|
struct packet_io_thread_ctx *thread_ctx = (struct packet_io_thread_ctx *)arg;
|
||||||
struct packet_io *handle = thread_ctx->ref_io;
|
struct packet_io *handle = thread_ctx->ref_io;
|
||||||
|
void * logger = thread_ctx->logger;
|
||||||
|
|
||||||
int pkg_len = 0;
|
int pkg_len = 0;
|
||||||
char thread_name[16];
|
char thread_name[32];
|
||||||
int n_pkt_recv_from_nf = 0;
|
int n_pkt_recv_from_nf = 0;
|
||||||
int n_pkt_recv_from_tap = 0;
|
int n_pkt_recv_from_tap = 0;
|
||||||
int n_pkt_recv_from_tap_c = 0;
|
int n_pkt_recv_from_tap_c = 0;
|
||||||
int n_pkt_recv_from_tap_s = 0;
|
int n_pkt_recv_from_tap_s = 0;
|
||||||
|
|
||||||
snprintf(thread_name, sizeof(thread_name), "kni:worker-%d", thread_ctx->thread_index);
|
snprintf(thread_name, sizeof(thread_name), "packet-io:worker-%d", thread_ctx->thread_index);
|
||||||
prctl(PR_SET_NAME, (unsigned long long)thread_name, NULL, NULL, NULL);
|
prctl(PR_SET_NAME, (unsigned long long)thread_name, NULL, NULL, NULL);
|
||||||
|
|
||||||
if (packet_io_thread_init(handle, thread_ctx) != 0)
|
if (packet_io_thread_init(handle, thread_ctx, logger) != 0)
|
||||||
{
|
{
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
@@ -115,7 +117,7 @@ static void *worker_thread_cycle(void *arg)
|
|||||||
thread_ctx->tap_ctx->buff = ALLOC(char, thread_ctx->tap_ctx->buff_size);
|
thread_ctx->tap_ctx->buff = ALLOC(char, thread_ctx->tap_ctx->buff_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFE_LOG_INFO(g_default_logger, "%s: worker thread %d is running", "LOG_TAG_KNI", thread_ctx->thread_index);
|
TFE_LOG_INFO(logger, "%s: worker thread %d is running", "LOG_TAG_KNI", thread_ctx->thread_index);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
n_pkt_recv_from_nf = packet_io_polling_nf_interface(handle, thread_ctx->thread_index, thread_ctx);
|
n_pkt_recv_from_nf = packet_io_polling_nf_interface(handle, thread_ctx->thread_index, thread_ctx);
|
||||||
@@ -125,23 +127,22 @@ static void *worker_thread_cycle(void *arg)
|
|||||||
n_pkt_recv_from_tap_s = io_uring_peek_ready_entrys(thread_ctx->tap_ctx->io_uring_s);
|
n_pkt_recv_from_tap_s = io_uring_peek_ready_entrys(thread_ctx->tap_ctx->io_uring_s);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((pkg_len = tfe_tap_read_per_thread(thread_ctx->tap_ctx->tap_fd, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, g_default_logger)) > 0)
|
if ((pkg_len = tap_read(thread_ctx->tap_ctx->tap_fd, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, logger)) > 0)
|
||||||
{
|
{
|
||||||
handle_raw_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
handle_raw_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pkg_len = tfe_tap_read_per_thread(thread_ctx->tap_ctx->tap_c, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, g_default_logger)) > 0)
|
if ((pkg_len = tap_read(thread_ctx->tap_ctx->tap_c, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, logger)) > 0)
|
||||||
{
|
{
|
||||||
handle_decryption_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
handle_decryption_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pkg_len = tfe_tap_read_per_thread(thread_ctx->tap_ctx->tap_s, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, g_default_logger)) > 0)
|
if ((pkg_len = tap_read(thread_ctx->tap_ctx->tap_s, thread_ctx->tap_ctx->buff, thread_ctx->tap_ctx->buff_size, logger)) > 0)
|
||||||
{
|
{
|
||||||
handle_decryption_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
handle_decryption_packet_from_tap(thread_ctx->tap_ctx->buff, pkg_len, thread_ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (n_pkt_recv_from_nf == 0 && n_pkt_recv_from_tap == 0 && n_pkt_recv_from_tap_c == 0 && n_pkt_recv_from_tap_s == 0)
|
if (n_pkt_recv_from_nf == 0 && n_pkt_recv_from_tap == 0 && n_pkt_recv_from_tap_c == 0 && n_pkt_recv_from_tap_s == 0)
|
||||||
{
|
{
|
||||||
packet_io_thread_wait(handle, thread_ctx, -1);
|
packet_io_thread_wait(handle, thread_ctx, -1);
|
||||||
@@ -155,25 +156,18 @@ static void *worker_thread_cycle(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_out:
|
error_out:
|
||||||
TFE_LOG_ERROR(g_default_logger, "%s: worker thread %d exiting", LOG_TAG_SCE, thread_ctx->thread_index);
|
TFE_LOG_ERROR(logger, "%s: worker thread %d exiting", LOG_TAG_SCE, thread_ctx->thread_index);
|
||||||
return (void *)NULL;
|
return (void *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void acceptor_kni_v4_destroy(struct acceptor_kni_v4 *ctx)
|
struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const char *profile)
|
||||||
{
|
{
|
||||||
if (ctx)
|
void *packet_io_logger = NULL;
|
||||||
{
|
packet_io_logger = MESA_create_runtime_log_handle("packet_io", RLOG_LV_DEBUG);
|
||||||
packet_io_destory(ctx->io);
|
assert(packet_io_logger != NULL);
|
||||||
|
|
||||||
free(ctx);
|
g_packet_io_logger = packet_io_logger;
|
||||||
ctx = NULL;
|
struct acceptor_kni_v4 *acceptor_ctx = acceptor_ctx_create(profile, packet_io_logger);
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const char *profile, void *logger)
|
|
||||||
{
|
|
||||||
struct acceptor_kni_v4 *acceptor_ctx = acceptor_ctx_create(profile);
|
|
||||||
if (acceptor_ctx == NULL)
|
if (acceptor_ctx == NULL)
|
||||||
goto error_out;
|
goto error_out;
|
||||||
|
|
||||||
@@ -181,6 +175,7 @@ struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const ch
|
|||||||
for (int i = 0; i < acceptor_ctx->nr_worker_threads; i++) {
|
for (int i = 0; i < acceptor_ctx->nr_worker_threads; i++) {
|
||||||
acceptor_ctx->work_threads[i].tid = 0;
|
acceptor_ctx->work_threads[i].tid = 0;
|
||||||
acceptor_ctx->work_threads[i].thread_index = i;
|
acceptor_ctx->work_threads[i].thread_index = i;
|
||||||
|
acceptor_ctx->work_threads[i].ref_io = acceptor_ctx->io;
|
||||||
acceptor_ctx->work_threads[i].ref_acceptor_ctx = acceptor_ctx;
|
acceptor_ctx->work_threads[i].ref_acceptor_ctx = acceptor_ctx;
|
||||||
|
|
||||||
acceptor_ctx->work_threads[i].tap_ctx = tfe_tap_ctx_create(&acceptor_ctx->work_threads[i]);
|
acceptor_ctx->work_threads[i].tap_ctx = tfe_tap_ctx_create(&acceptor_ctx->work_threads[i]);
|
||||||
@@ -188,10 +183,9 @@ struct acceptor_kni_v4 *acceptor_kni_v4_create(struct tfe_proxy *proxy, const ch
|
|||||||
goto error_out;
|
goto error_out;
|
||||||
|
|
||||||
acceptor_ctx->work_threads[i].session_table = session_table_create();
|
acceptor_ctx->work_threads[i].session_table = session_table_create();
|
||||||
acceptor_ctx->work_threads[i].ref_io = acceptor_ctx->io;
|
|
||||||
acceptor_ctx->work_threads[i].ref_proxy = proxy;
|
acceptor_ctx->work_threads[i].ref_proxy = proxy;
|
||||||
acceptor_ctx->work_threads[i].ret_fs_state = acceptor_ctx->packet_io_fs;
|
acceptor_ctx->work_threads[i].ret_fs_state = acceptor_ctx->packet_io_fs;
|
||||||
acceptor_ctx->work_threads[i].ref_acceptor_ctx = acceptor_ctx;
|
acceptor_ctx->work_threads[i].logger = packet_io_logger;
|
||||||
acceptor_ctx->work_threads[i].session_table_need_reset = 0;
|
acceptor_ctx->work_threads[i].session_table_need_reset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -564,7 +564,7 @@ void tfe_proxy_acceptor_init(struct tfe_proxy * proxy, const char * profile)
|
|||||||
|
|
||||||
if (proxy->en_kni_v4_acceptor)
|
if (proxy->en_kni_v4_acceptor)
|
||||||
{
|
{
|
||||||
g_default_proxy->kni_v4_acceptor = acceptor_kni_v4_create(g_default_proxy, profile, g_default_logger);
|
g_default_proxy->kni_v4_acceptor = acceptor_kni_v4_create(g_default_proxy, profile);
|
||||||
CHECK_OR_EXIT(g_default_proxy->kni_v4_acceptor, "Failed at init KNIv4 acceptor. Exit. ");
|
CHECK_OR_EXIT(g_default_proxy->kni_v4_acceptor, "Failed at init KNIv4 acceptor. Exit. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user