diff --git a/decoders/CMakeLists.txt b/decoders/CMakeLists.txt index 0875131..7946822 100644 --- a/decoders/CMakeLists.txt +++ b/decoders/CMakeLists.txt @@ -1,4 +1,4 @@ -#add_subdirectory(lpi_plus) +add_subdirectory(lpi_plus) #add_subdirectory(http) #add_subdirectory(socks) #add_subdirectory(stratum) diff --git a/decoders/lpi_plus/CMakeLists.txt b/decoders/lpi_plus/CMakeLists.txt index 91b097f..291c626 100644 --- a/decoders/lpi_plus/CMakeLists.txt +++ b/decoders/lpi_plus/CMakeLists.txt @@ -8,6 +8,3 @@ target_include_directories(lpi_plus PUBLIC ${CMAKE_SOURCE_DIR}/decoders/) target_link_libraries(lpi_plus libprotoident) set_target_properties(lpi_plus PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/version.map") - -#install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/stellar_plugin COMPONENT LIBRARIES) - diff --git a/decoders/lpi_plus/lpi_plus_internal.h b/decoders/lpi_plus/lpi_plus_internal.h deleted file mode 100644 index 8536dc3..0000000 --- a/decoders/lpi_plus/lpi_plus_internal.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "stellar/lpi_plus.h" - -#define MAX_APPID_NUM 8 -#define LPIP_APPID_MESSAGE_TOPIC "TOPIC_LPIP_APPID" - -struct lpi_plus_appid_message -{ - struct session *sess; - uint32_t appid_num; - int32_t appid[MAX_APPID_NUM]; - int32_t packet_sequence[MAX_APPID_NUM]; -}; - -const char *lpi_plus_appid2name(struct lpi_plus *lpip, int appid); \ No newline at end of file diff --git a/decoders/lpi_plus/lpip_module.c b/decoders/lpi_plus/lpip_module.c index 171b586..ff51b88 100644 --- a/decoders/lpi_plus/lpip_module.c +++ b/decoders/lpi_plus/lpip_module.c @@ -17,10 +17,13 @@ #include "stellar/packet.h" #include "stellar/session.h" -#include "lpi_plus_internal.h" +#include "stellar/lpi_plus.h" + #include "lpip_extend.h" +#define MAX_APPID_NUM 8 + const char *l7_protocol_file = (char *)"./tsgconf/tsg_l7_protocol.conf"; struct lpi_plus_appid_info @@ -42,9 +45,10 @@ struct lpi_plus { unsigned int max_pkts; int lpip_session_exdata_idx; - int topic_appid; + int lpip_packet_exdata_idx; struct module_manager *mod_mgr; struct lpi_plus_mapper *mapper; + struct session_manager *sess_mgr; }; struct lpi_plus_per_session_ctx @@ -57,13 +61,12 @@ struct lpi_plus_per_session_ctx size_t appid_num; }; -static void lpi_plus_get_host_order_port(struct session *sess __unused, unsigned short *sport, unsigned short *dport) +static void lpi_plus_get_host_order_port(struct packet *pkt, struct session *sess, unsigned short *sport, unsigned short *dport) { *sport=0; *dport=0; //get host order port from stellar session api - const struct packet *pkt = session_get_current_packet(sess); enum flow_type flow_type=session_get_flow_type(sess); if(pkt && (flow_type==FLOW_TYPE_C2S || flow_type==FLOW_TYPE_S2C)) { @@ -90,19 +93,6 @@ static void lpi_plus_get_host_order_port(struct session *sess __unused, unsigned return; } -static struct lpi_plus_appid_message *lpi_plus_message_new(struct session *sess, int *id_array, int *packet_sequence_array, size_t id_num) -{ - struct lpi_plus_appid_message *result=CALLOC(struct lpi_plus_appid_message, 1); - result->sess=sess; - result->appid_num=id_num; - for(unsigned int i=0; iappid_num; i++) - { - result->appid[i]=id_array[i]; - result->packet_sequence[i]=packet_sequence_array[i]; - } - - return result; -} static int lpi_plus_appid_update(int current_id_array[], size_t *current_id_num, int incoming_id) { @@ -204,7 +194,7 @@ static void lpi_plus_mapper_free(struct lpi_plus_mapper *mapper) free(mapper); } -void lpi_plus_context_update(struct session *sess, struct lpi_plus_detect_context *ctx, +void lpi_plus_context_update(struct packet *pkt, struct session *sess, struct lpi_plus_detect_context *ctx, const char *scan_data, int scan_data_len) { lpi_data_t *data = &ctx->lpi_data; @@ -252,7 +242,7 @@ void lpi_plus_context_update(struct session *sess, struct lpi_plus_detect_contex uint16_t source=0; uint16_t dest=0; - lpi_plus_get_host_order_port(sess,&source ,&dest); + lpi_plus_get_host_order_port(pkt, sess,&source ,&dest); data->client_port = source; data->server_port = dest; @@ -285,14 +275,21 @@ static int lpi_plus_detect(struct lpi_plus_detect_context *ctx, struct lpi_plus_ return new_appid; } -static void lpi_plus_on_session(struct session *sess, enum session_state state, struct packet *pkt, void *args) +void lpi_plus_on_packet(struct packet *pkt, struct module *mod) { - if (state == SESSION_STATE_CLOSED) + if(pkt==NULL||mod==NULL)return; + + struct lpi_plus *env=(struct lpi_plus *)module_get_ctx(mod); + struct session *sess=packet_exdata_to_session(env->sess_mgr, pkt); + + if(sess==NULL)return; + + if (session_get_current_state(sess) == SESSION_STATE_CLOSED) { assert(pkt == NULL); return; } - struct lpi_plus *env=(struct lpi_plus *)args; + struct lpi_plus_per_session_ctx *lpip_sess_ctx = (struct lpi_plus_per_session_ctx *)session_get_exdata(sess, env->lpip_session_exdata_idx); if(lpip_sess_ctx==NULL) { @@ -307,21 +304,29 @@ static void lpi_plus_on_session(struct session *sess, enum session_state state, if (payload!=NULL && payload_len>0)//detect packet with payload only { if(lpip_sess_ctx->detector_ctx==NULL)lpip_sess_ctx->detector_ctx=CALLOC(struct lpi_plus_detect_context, 1); - lpi_plus_context_update(sess, lpip_sess_ctx->detector_ctx, payload, payload_len); + lpi_plus_context_update(pkt, sess, lpip_sess_ctx->detector_ctx, payload, payload_len); int appid=lpi_plus_detect(lpip_sess_ctx->detector_ctx, env->mapper, payload, payload_len, &lpip_sess_ctx->stop_detect); lpip_sess_ctx->detected_pkt_cnt+=1; if(appid>0 && lpi_plus_appid_update(lpip_sess_ctx->appid, &(lpip_sess_ctx->appid_num), appid)) { lpip_sess_ctx->packet_sequence[lpip_sess_ctx->appid_num-1]=lpip_sess_ctx->detected_pkt_cnt; - struct lpi_plus_appid_message *msg=lpi_plus_message_new(sess, lpip_sess_ctx->appid, lpip_sess_ctx->packet_sequence, lpip_sess_ctx->appid_num); - if(0 > mq_runtime_publish_message(module_manager_get_mq_runtime(env->mod_mgr), - env->topic_appid, - msg))FREE(msg); + packet_set_exdata(pkt, env->lpip_packet_exdata_idx, lpip_sess_ctx); } } return; } +int32_t *packet_exdata_to_lpip_appid(struct lpi_plus *lpip, struct packet *pkt, size_t *appid_num) +{ + if(lpip==NULL || pkt==NULL || appid_num==NULL)return NULL; + + struct lpi_plus_per_session_ctx *lpip_sess_ctx=(struct lpi_plus_per_session_ctx *)packet_get_exdata(pkt, lpip->lpip_packet_exdata_idx); + if(lpip_sess_ctx==NULL)return NULL; + + *appid_num=lpip_sess_ctx->appid_num; + return lpip_sess_ctx->appid; +} + static void lpi_plus_exdata_free(int idx __unused, void *ex_ptr, void *arg __unused) { if(ex_ptr==NULL)return; @@ -343,86 +348,39 @@ void lpi_plus_exit(struct module_manager *mod_mgr, struct module *mod) } } -static void appid_message_free(void *msg, void *msg_free_arg __unused) -{ - if(msg==NULL)return; - FREE(msg); -} -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-function-type" - -static void lpi_plus_appid_on_msg_dispatch(int topic_id __unused, - void *msg, - on_msg_cb_func* on_msg_cb, - void *on_msg_cb_arg, - void *dispatch_arg __unused) -{ - lpi_plus_on_appid_callback *appid_cb = (lpi_plus_on_appid_callback *)on_msg_cb; - struct lpi_plus_appid_message *appid_msg=(struct lpi_plus_appid_message *)msg; - appid_cb(appid_msg->sess, appid_msg->appid, appid_msg->packet_sequence, appid_msg->appid_num, on_msg_cb_arg); -} - -int lpi_plus_appid_subscribe(struct lpi_plus *lpip, lpi_plus_on_appid_callback *cb, void *args) -{ - if(lpip==NULL)return -1; - struct module_manager *mod_mgr=lpip->mod_mgr; - int appid_topic_id=mq_schema_get_topic_id(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC); - if(appid_topic_id<0) - { - appid_topic_id=mq_schema_create_topic(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC, lpi_plus_appid_on_msg_dispatch, mod_mgr, appid_message_free, NULL); - } - return mq_schema_subscribe(module_manager_get_mq_schema(mod_mgr), appid_topic_id, (on_msg_cb_func *)cb, args); -} - -#pragma GCC diagnostic pop - -int lpi_plus_create_appid_topic(struct module_manager *mod_mgr) -{ - int app_topic_id=mq_schema_get_topic_id(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC); - if(app_topic_id < 0) - { - app_topic_id=mq_schema_create_topic(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC, lpi_plus_appid_on_msg_dispatch, NULL,appid_message_free, NULL); - } - return app_topic_id; -} struct module *lpi_plus_init(struct module_manager *mod_mgr) { if(mod_mgr==NULL)return NULL; + struct module *sess_mgr_mod=module_manager_get_module(mod_mgr, SESSION_MANAGER_MODULE_NAME); + struct module *pkt_mgr_mod=module_manager_get_module(mod_mgr, PACKET_MANAGER_MODULE_NAME); + if(sess_mgr_mod==NULL || pkt_mgr_mod == NULL) + { + return NULL; + } + struct lpi_plus *env=CALLOC(struct lpi_plus, 1); struct module *mod=module_new("LPI_PLUS", env); env->mod_mgr=mod_mgr; env->max_pkts=16;//TODO: load from toml - struct module *sess_mgr_mod=module_manager_get_module(mod_mgr, SESSION_MANAGER_MODULE_NAME); - struct session_manager *sess_mgr=module_to_session_manager(sess_mgr_mod); - struct mq_schema *mq_s=module_manager_get_mq_schema(mod_mgr); - - if(sess_mgr==NULL || mq_s==NULL) - { - goto INIT_ERROR; - } + env->sess_mgr=module_to_session_manager(sess_mgr_mod); if(lpi_init_library()<0) { goto INIT_ERROR; } - env->mapper=lpi_plus_mapper_new(l7_protocol_file);// TODO: load path from toml + env->mapper=lpi_plus_mapper_new(l7_protocol_file);// TODO: load from toml if(env->mapper == NULL) { goto INIT_ERROR; } - session_manager_subscribe_tcp(sess_mgr,lpi_plus_on_session, env); - session_manager_subscribe_udp(sess_mgr, lpi_plus_on_session, env); + env->lpip_session_exdata_idx = session_manager_new_session_exdata_index(env->sess_mgr, "EXDATA_LPI", lpi_plus_exdata_free, NULL); - env->lpip_session_exdata_idx = session_manager_new_session_exdata_index(sess_mgr, "EXDATA_LPI", lpi_plus_exdata_free, NULL); - env->topic_appid=lpi_plus_create_appid_topic(mod_mgr); - if(env->topic_appid<0) - { - goto INIT_ERROR; - } + struct packet_manager *pkt_mgr = module_to_packet_manager(pkt_mgr_mod); + env->lpip_packet_exdata_idx = packet_manager_new_packet_exdata_index(pkt_mgr, "EXDATA_LPI", NULL, NULL); return mod; diff --git a/decoders/lpi_plus/version.map b/decoders/lpi_plus/version.map index 6028219..d9ba6ff 100644 --- a/decoders/lpi_plus/version.map +++ b/decoders/lpi_plus/version.map @@ -3,7 +3,10 @@ global: extern "C" { lpi_plus_init; lpi_plus_exit; - lpi_plus_appid_subscribe; + lpi_plus_on_packet; + module_to_lpi_plus; + lpi_plus_appid2name; + packet_exdata_to_lpip_appid; GIT_VERSION_*; }; diff --git a/include/stellar/lpi_plus.h b/include/stellar/lpi_plus.h index cfb99c5..6b07fdc 100644 --- a/include/stellar/lpi_plus.h +++ b/include/stellar/lpi_plus.h @@ -6,15 +6,21 @@ extern "C" #endif #include "stellar/module.h" -#include "stellar/session.h" +#include "stellar/packet.h" #define LPI_PLUS_MODULE_NAME "LPI_PLUS" +struct module *lpi_plus_init(struct module_manager *mod_mgr); +void lpi_plus_exit(struct module_manager *mod_mgr, struct module *mod); + struct lpi_plus; struct lpi_plus *module_to_lpi_plus(struct module *mod); -typedef void lpi_plus_on_appid_callback(struct session *sess, int appid[], int packet_sequence[], size_t appid_num, void *args); -int lpi_plus_appid_subscribe(struct lpi_plus *lpip, lpi_plus_on_appid_callback *cb, void *args); +const char *lpi_plus_appid2name(struct lpi_plus *lpip, int appid); + +void lpi_plus_on_packet(struct packet *pkt, struct module *mod); +int32_t *packet_exdata_to_lpip_appid(struct lpi_plus *lpip, struct packet *pkt, size_t *appid_num); + #ifdef __cplusplus } diff --git a/include/stellar/stellar.h b/include/stellar/stellar.h index af21029..b612c52 100644 --- a/include/stellar/stellar.h +++ b/include/stellar/stellar.h @@ -8,6 +8,7 @@ extern "C" #include #include "stellar/log.h" +#include "stellar/module.h" struct stellar; struct stellar *stellar_new(const char *toml_file); @@ -16,6 +17,7 @@ void stellar_free(struct stellar *st); void stellar_loopbreak(struct stellar *st); void stellar_reload_log_level(struct stellar *st); struct logger *stellar_get_logger(struct stellar *st); +struct module_manager *stellar_get_module_manager(struct stellar *st); #ifdef __cplusplus } diff --git a/infra/CMakeLists.txt b/infra/CMakeLists.txt index 179ca25..fe127c2 100644 --- a/infra/CMakeLists.txt +++ b/infra/CMakeLists.txt @@ -1,6 +1,6 @@ set(INFRA exdata tuple packet_manager packet_io ip_reassembly tcp_reassembly session_manager module_manager monitor) set(DEPS bitmap dablooms interval_tree logger nmx_pool rbtree timeout toml ringbuf) -#set(DECODERS lpi_plus) +set(DECODERS lpi_plus) set(WHOLE_ARCHIVE ${DEPS} ${INFRA} ${DECODERS}) set(LIBS fieldstat4) diff --git a/infra/stellar_core.c b/infra/stellar_core.c index 3a18cf2..f575b25 100644 --- a/infra/stellar_core.c +++ b/infra/stellar_core.c @@ -129,12 +129,14 @@ static void stellar_thread_join(struct stellar *st) #include "stellar/monitor.h" #include "stellar/session.h" +#include "stellar/lpi_plus.h" struct module_hooks mod_hooks[] = { {monitor_on_init, monitor_on_exit, NULL, NULL}, {packet_manager_on_init, packet_manager_on_exit, packet_manager_on_thread_init, packet_manager_on_thread_exit}, {session_manager_on_init, session_manager_on_exit, session_manager_on_thread_init, session_manager_on_thread_exit}, {session_monitor_on_init, session_monitor_on_exit, NULL, NULL}, + {lpi_plus_init, lpi_plus_exit, NULL, NULL}, }; @@ -151,7 +153,8 @@ struct packet_node_spec struct packet_node_spec packet_nodes[] = { {SESSION_MANAGER_MODULE_NAME, "session_manager",PACKET_STAGE_FORWARD, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, session_manager_on_packet_forward}, - {SESSION_MANAGER_MODULE_NAME, "session_manager",PACKET_STAGE_OUTPUT, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, session_manager_on_packet_output} + {SESSION_MANAGER_MODULE_NAME, "session_manager",PACKET_STAGE_OUTPUT, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, session_manager_on_packet_output}, + {LPI_PLUS_MODULE_NAME, "lpi_plus",PACKET_STAGE_FORWARD, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, lpi_plus_on_packet}, }; @@ -312,4 +315,16 @@ struct logger *stellar_get_logger(struct stellar *st) { return NULL; } +} + +struct module_manager *stellar_get_module_manager(struct stellar *st) +{ + if (st) + { + return st->mod_mgr; + } + else + { + return NULL; + } } \ No newline at end of file diff --git a/infra/version.map b/infra/version.map index e635773..2bc8950 100644 --- a/infra/version.map +++ b/infra/version.map @@ -74,6 +74,7 @@ global: stellar_loopbreak; stellar_get_logger; stellar_reload_log_level; + stellar_get_module_manager; log_print; log_check_level; @@ -86,7 +87,8 @@ global: lpi_plus_init; lpi_plus_exit; - lpi_plus_appid_subscribe; + lpi_plus_appid2name; + packet_exdata_to_lpip_appid; monitor_on_init; monitor_on_exit; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8b080ac..cc3398a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ #add_subdirectory(packet_inject) add_subdirectory(packet_tool) #add_subdirectory(session_debugger) -#add_subdirectory(lpi_plus) +add_subdirectory(lpi_plus) #add_subdirectory(decoders/http) #add_subdirectory(decoders/socks) #add_subdirectory(decoders/stratum) diff --git a/test/lpi_plus/CMakeLists.txt b/test/lpi_plus/CMakeLists.txt index 9f63273..5eb5094 100644 --- a/test/lpi_plus/CMakeLists.txt +++ b/test/lpi_plus/CMakeLists.txt @@ -4,7 +4,7 @@ target_include_directories(gtest_lpip PRIVATE ${CMAKE_SOURCE_DIR}/deps/) target_include_directories(gtest_lpip PRIVATE ${CMAKE_SOURCE_DIR}/decoders/) target_link_libraries( - gtest_lpip PRIVATE stellar_lib cjson-static lpi_plus + gtest_lpip PRIVATE stellar_lib cjson-static dl "-rdynamic" gtest gmock ) @@ -20,7 +20,6 @@ add_test(NAME ${TEST_NAME}.SETUP COMMAND sh -c " mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/log && mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/tsgconf && cp ${CMAKE_SOURCE_DIR}/conf/stellar.toml ${CMAKE_CURRENT_BINARY_DIR}/conf/ && - cat ${CMAKE_CURRENT_SOURCE_DIR}/test_config/spec.toml >> ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml && cp ${CMAKE_CURRENT_SOURCE_DIR}/test_config/tsg_l7_protocol.conf ${CMAKE_CURRENT_BINARY_DIR}/tsgconf/ && tomlq -t -i '.packet_io.pcap_path=\"-\"' ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml && tomlq -t -i '.packet_io.mode=\"pcaplist\"' ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml diff --git a/test/lpi_plus/gtest_lpip.h b/test/lpi_plus/gtest_lpip.h index 9b13571..1080048 100644 --- a/test/lpi_plus/gtest_lpip.h +++ b/test/lpi_plus/gtest_lpip.h @@ -5,12 +5,16 @@ extern "C" { #endif -int stellar_test_result_setup(); - +void stellar_test_result_setup(); char *stellar_test_result_json_export(); - void stellar_test_result_cleanup(); +#define GTEST_LPIP_MODULE_NAME "TEST_LPIP" +void gtest_lpip_on_packet(struct packet *pkt, struct module *mod); + +struct module *gtest_lpip_module_init(struct module_manager *mod_mgr); +void gtest_lpip_module_exit(struct module_manager *mod_mgr, struct module *mod); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/test/lpi_plus/gtest_lpip_main.cpp b/test/lpi_plus/gtest_lpip_main.cpp index 6745832..63306b8 100644 --- a/test/lpi_plus/gtest_lpip_main.cpp +++ b/test/lpi_plus/gtest_lpip_main.cpp @@ -113,6 +113,10 @@ static void gtest_result_free(struct gtest_json_result *para) * GTEST MAIN * **********************************************/ +#include "stellar/packet.h" + +extern "C" void gtest_lpip_on_packet(struct packet *pkt, struct module *mod); + int main(int argc, char ** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -126,6 +130,16 @@ int main(int argc, char ** argv) struct stellar *st=stellar_new("./conf/stellar.toml"); + struct module_manager *mod_mgr=stellar_get_module_manager(st); + + struct module *pkt_mgr_mod=module_manager_get_module(mod_mgr, PACKET_MANAGER_MODULE_NAME); + + struct packet_manager *pkt_mgr=module_to_packet_manager(pkt_mgr_mod); + + struct module *gtest_lpip_mod=gtest_lpip_module_init(mod_mgr); + + packet_manager_register_node(pkt_mgr, "LPI_PLUS", PACKET_STAGE_FORWARD, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, gtest_lpip_on_packet, gtest_lpip_mod); + stellar_test_result_setup(); EXPECT_TRUE(st!=NULL); @@ -133,6 +147,8 @@ int main(int argc, char ** argv) stellar_free(st); + gtest_lpip_module_exit(mod_mgr, gtest_lpip_mod); + char *test_result_json=stellar_test_result_json_export(); g_test_para->test_json_root=cJSON_Parse(test_result_json); free(test_result_json); diff --git a/test/lpi_plus/gtest_lpip_module.c b/test/lpi_plus/gtest_lpip_module.c index c6998dc..00e0a28 100644 --- a/test/lpi_plus/gtest_lpip_module.c +++ b/test/lpi_plus/gtest_lpip_module.c @@ -12,16 +12,22 @@ #include "cjson/cJSON.h" -#include "lpi_plus/lpi_plus_internal.h" +#include "stellar/lpi_plus.h" +#include "gtest_lpip.h" struct test_lpip_env { struct module_manager *mod_mgr; + struct session_manager *sess_mgr; struct lpi_plus *lpip; int l7_exdata_idx; int session_num; }; +#ifndef MAX_APPID_NUM +#define MAX_APPID_NUM 8 +#endif + struct test_lpip_exdata { int appid[MAX_APPID_NUM]; @@ -35,6 +41,7 @@ void stellar_test_result_setup() { if(g_result_json!=NULL)return; g_result_json=cJSON_CreateArray(); + return; } char *stellar_test_result_json_export() @@ -111,41 +118,25 @@ static void gtest_lpip_exdata_free(int idx __attribute__((unused)), void *ex_ptr } -static void gtest_lpip_on_appid_msg(struct session *sess, int appid[], int packet_sequence[],size_t appid_num, void *args) +void gtest_lpip_on_packet(struct packet *pkt, struct module *mod) { - if(sess==NULL || appid==NULL || args==NULL)return; - struct test_lpip_env *env = (struct test_lpip_env *)args; - struct test_lpip_exdata *test_appid_exdata=session_get_exdata(sess, env->l7_exdata_idx); - if(test_appid_exdata==NULL) + + struct test_lpip_env *env = (struct test_lpip_env *)module_get_ctx(mod); + struct session *sess=packet_exdata_to_session(env->sess_mgr, pkt); + struct test_lpip_exdata *test_appid_exdata=session_get_exdata(sess, env->l7_exdata_idx); + if (test_appid_exdata==NULL) { test_appid_exdata = CALLOC(struct test_lpip_exdata, 1); test_appid_exdata->sess=sess; - - } - memcpy(test_appid_exdata->appid, appid, appid_num*sizeof(appid[0])); - test_appid_exdata->appid_num=appid_num; - session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata); - return; -} - -static void on_session(struct session *sess, enum session_state state, struct packet *pkt, void *args) -{ - if (state == SESSION_STATE_CLOSED) - { - assert(pkt == NULL); - return; + session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata); } - struct test_lpip_env *env = (struct test_lpip_env *)args; - if (session_get_current_state(sess) == SESSION_STATE_OPENING) + size_t appid_num=0; + int32_t *appid = packet_exdata_to_lpip_appid(env->lpip, pkt, &appid_num); + if(appid_num>0 && appid!=NULL) { - struct test_lpip_exdata *test_appid_exdata = session_get_exdata(sess, env->l7_exdata_idx); - if (test_appid_exdata == NULL) - { - test_appid_exdata = CALLOC(struct test_lpip_exdata, 1); - test_appid_exdata->sess=sess; - session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata); - } + test_appid_exdata->appid_num=appid_num; + memcpy(test_appid_exdata->appid, appid, sizeof(*appid)*appid_num); } return; } @@ -156,27 +147,19 @@ struct module *gtest_lpip_module_init(struct module_manager *mod_mgr) struct module *lpip_mod = module_manager_get_module(mod_mgr, LPI_PLUS_MODULE_NAME); env->lpip=module_to_lpi_plus(lpip_mod); struct module *sess_mgr_mod=module_manager_get_module(mod_mgr, SESSION_MANAGER_MODULE_NAME); - struct session_manager *sess_mgr = module_to_session_manager(sess_mgr_mod); - if(sess_mgr == NULL) + env->sess_mgr = module_to_session_manager(sess_mgr_mod); + if(env->sess_mgr == NULL) { perror("gtest_lpi_plugin_load:stellar_module_get_session_manager failed !!!\n"); exit(-1); } - - session_manager_subscribe_udp(sess_mgr, on_session, env); - session_manager_subscribe_tcp(sess_mgr, on_session, env); - - env->l7_exdata_idx = session_manager_new_session_exdata_index(sess_mgr, "EXDATA_L7", gtest_lpip_exdata_free, env); - - lpi_plus_appid_subscribe(env->lpip, gtest_lpip_on_appid_msg, env); + env->l7_exdata_idx = session_manager_new_session_exdata_index(env->sess_mgr, "EXDATA_L7", gtest_lpip_exdata_free, env); printf("gtest_lpip_module_init OK!\n"); - - return module_new("TEST_LPIP", env); + return module_new(GTEST_LPIP_MODULE_NAME, env); } -void gtest_lpip_module_exit(struct module_manager *mod_mgr, struct module *mod) +void gtest_lpip_module_exit(struct module_manager *mod_mgr __unused, struct module *mod) { - assert(mod_mgr!=NULL); struct test_lpip_env *env = (struct test_lpip_env *)module_get_ctx(mod); free(env); printf("gtest_lpip_module_exit OK!\n"); diff --git a/test/lpi_plus/test_config/spec.toml b/test/lpi_plus/test_config/spec.toml deleted file mode 100644 index 329f401..0000000 --- a/test/lpi_plus/test_config/spec.toml +++ /dev/null @@ -1,11 +0,0 @@ -# stellar_plugin.toml -# -[[module]] -path = "" -init = "lpi_plus_init" -exit = "lpi_plus_exit" - -[[module]] -path = "" -init = "gtest_lpip_module_init" -exit = "gtest_lpip_module_exit"