🦄 refactor(decoder glimpse detector): rename to lpi plugin

This commit is contained in:
yangwei
2024-08-28 20:45:57 +08:00
parent b2647a5a75
commit 2f586a456b
648 changed files with 125 additions and 181 deletions

View File

@@ -1,5 +1,5 @@
add_subdirectory(packet_inject)
add_subdirectory(packet_tool)
add_subdirectory(debug_plugin)
add_subdirectory(glimpse_detector)
add_subdirectory(lpi_plugin)
add_subdirectory(decoders/http)

View File

@@ -1,11 +0,0 @@
# stellar_plugin.toml
#
[[plugin]]
path = ""
init = "APP_GLIMPSE_DETECTOR_LOAD"
exit = "APP_GLIMPSE_DETECTOR_UNLOAD"
[[plugin]]
path = ""
init = "GLIMPSE_DETECTOR_TEST_PLUG_LOAD"
exit = "GLIMPSE_DETECTOR_TEST_PLUG_UNLOAD"

View File

@@ -1,20 +1,20 @@
add_executable(gtest_glimpse_detector gtest_glimpse_detector_main.cpp gtest_glimpse_detector_plugin.cpp)
add_executable(gtest_lpi gtest_lpi_main.cpp gtest_lpi_plugin.cpp)
target_include_directories(gtest_glimpse_detector PRIVATE ${CMAKE_SOURCE_DIR}/deps/)
target_include_directories(gtest_glimpse_detector PRIVATE ${CMAKE_SOURCE_DIR}/decoders/glimpse_detector)
target_include_directories(gtest_lpi PRIVATE ${CMAKE_SOURCE_DIR}/deps/)
target_include_directories(gtest_lpi PRIVATE ${CMAKE_SOURCE_DIR}/decoders/lpi)
target_link_libraries(
gtest_glimpse_detector PRIVATE stellar_devel glimpse_detector cjson-static
dl "-rdynamic"
gtest gmock
gtest_lpi PRIVATE stellar_devel cjson-static
dl "-rdynamic"
gtest gmock
)
target_link_libraries(gtest_glimpse_detector PRIVATE -Wl,--whole-archive glimpse_detector -Wl,--no-whole-archive)
target_link_libraries(gtest_lpi PRIVATE -Wl,--whole-archive lpi -Wl,--no-whole-archive)
set(TEST_NAME "LPI_TEST")
set(TEST_MAIN ${CMAKE_CURRENT_BINARY_DIR}/gtest_lpi)
set(TEST_MAIN ${CMAKE_CURRENT_BINARY_DIR}/gtest_glimpse_detector)
add_test(NAME GLIMPSE_TEST_SETUP COMMAND sh -c "
add_test(NAME ${TEST_NAME}.setup COMMAND sh -c "
mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/conf &&
mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/plugin &&
mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/log &&
@@ -28,26 +28,31 @@ add_test(NAME GLIMPSE_TEST_SETUP COMMAND sh -c "
")
set_tests_properties(GLIMPSE_TEST_SETUP
PROPERTIES FIXTURES_SETUP GLIMPSE_TEST_SETUP)
set_tests_properties(${TEST_NAME}.setup
PROPERTIES FIXTURES_SETUP ${TEST_NAME}.setup)
add_test(NAME GLIMPSE_TEST_APP
add_test(NAME ${TEST_NAME}.app
COMMAND sh -c "find ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/app_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/app_pcap.json")
add_test(NAME GLIMPSE_TEST_DNS
add_test(NAME ${TEST_NAME}.dns
COMMAND sh -c "find ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/dns_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/dns_pcap.json")
add_test(NAME GLIMPSE_TEST_MIXED
add_test(NAME ${TEST_NAME}.mixed
COMMAND sh -c "find ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/mixed_pcap -type f | sort -V |${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/mixed_pcap.json")
add_test(NAME GLIMPSE_TEST_OPENVPN
add_test(NAME ${TEST_NAME}.openvpn
COMMAND sh -c "find ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/openvpn_pcap -type f | sort -V |${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/openvpn_pcap.json")
add_test(NAME GLIMPSE_TEST_PPP
add_test(NAME ${TEST_NAME}.ppp
COMMAND sh -c "find ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/ppp_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/ppp_pcap.json")
add_test(NAME GLIMPSE_TEST_SOCKS
add_test(NAME ${TEST_NAME}.socks
COMMAND sh -c "find ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/socks_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/socks_pcap.json")
set_tests_properties(GLIMPSE_TEST_APP GLIMPSE_TEST_DNS GLIMPSE_TEST_MIXED GLIMPSE_TEST_OPENVPN GLIMPSE_TEST_PPP GLIMPSE_TEST_SOCKS
PROPERTIES FIXTURES_REQUIRED GLIMPSE_TEST_SETUP)
set_tests_properties(${TEST_NAME}.app
${TEST_NAME}.dns
${TEST_NAME}.mixed
${TEST_NAME}.openvpn
${TEST_NAME}.ppp
${TEST_NAME}.socks
PROPERTIES FIXTURES_REQUIRED ${TEST_NAME}.setup)

View File

@@ -5,7 +5,7 @@
#include <unistd.h>
#include <assert.h>
#include "app_l7_protocol.h"
#include "lpi_plugin.h"
#include "stellar/stellar.h"
#include "stellar/session.h"
@@ -16,7 +16,7 @@
#define MAX_APP_ID_VALUE 10000
struct glimpse_detector_test_plugin_env
struct lpi_test_plugin_env
{
int test_exdata_idx;
int l7_exdata_idx;
@@ -26,7 +26,7 @@ struct glimpse_detector_test_plugin_env
char *g_proto_id2name[MAX_APP_ID_VALUE];
};
static int load_l7_protocol_mapper(const char *filename, struct glimpse_detector_test_plugin_env *env)
static int load_l7_protocol_mapper(const char *filename, struct lpi_test_plugin_env *env)
{
memset(env->g_proto_id2name, 0, sizeof(env->g_proto_id2name));
int ret=0, proto_id=0;;
@@ -62,7 +62,7 @@ static int load_l7_protocol_mapper(const char *filename, struct glimpse_detector
return ret;
}
static void publish_session_test_result(struct glimpse_detector_test_plugin_env *env, cJSON *ctx, struct session *sess)
static void publish_session_test_result(struct lpi_test_plugin_env *env, cJSON *ctx, struct session *sess)
{
assert(env->l7_exdata_idx >= 0 && ctx != NULL);
struct l7_protocol_label *label = (struct l7_protocol_label *)session_exdata_get(sess, env->l7_exdata_idx);;
@@ -109,7 +109,7 @@ static void publish_session_test_result(struct glimpse_detector_test_plugin_env
}
void *glimpse_detector_test_ctx_new(struct session *sess, void *plugin_env)
void *lpi_test_ctx_new(struct session *sess, void *plugin_env)
{
cJSON *ctx =cJSON_CreateObject();
cJSON_AddStringToObject(ctx, "Tuple4", session_get0_readable_addr(sess));
@@ -125,45 +125,37 @@ static void publish_session_test_result(struct glimpse_detector_test_plugin_env
return ctx;
}
static void APP_TEST_ON_SESSION_MSG(struct session *sess, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env)
static void gtest_lpi_plugin_on_msg(struct session *sess, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env)
{
if(session_get_current_state(sess)==SESSION_STATE_CLOSED)
{
publish_session_test_result((struct glimpse_detector_test_plugin_env*)plugin_env, (cJSON *)per_session_ctx, sess);
publish_session_test_result((struct lpi_test_plugin_env*)plugin_env, (cJSON *)per_session_ctx, sess);
}
return;
}
extern "C" void *GLIMPSE_DETECTOR_TEST_PLUG_LOAD(struct stellar *st)
extern "C" void *gtest_lpi_plugin_load(struct stellar *st)
{
struct glimpse_detector_test_plugin_env *env = (struct glimpse_detector_test_plugin_env *)calloc(1, sizeof(struct glimpse_detector_test_plugin_env));
struct lpi_test_plugin_env *env = (struct lpi_test_plugin_env *)calloc(1, sizeof(struct lpi_test_plugin_env));
env->st=st;
const char *l7_proto_name=(const char*)"./tsgconf/tsg_l7_protocol.conf";
#if 0
const char *l7_label_name=(const char*)"L7_PROTOCOL_LABEL";
const char *l7_bridge_name=(const char*)"APP_BRIDGE";
MESA_load_profile_string_def("./tsgconf/main.conf", "SYSTEM", "L7_LABEL_NAME", l7_label_name, sizeof(l7_label_name), "L7_PROTOCOL_LABEL");
MESA_load_profile_string_def("./tsgconf/main.conf", "SYSTEM", "APP_BRIDGE_NAME", l7_bridge_name, sizeof(l7_bridge_name), "APP_BRIDGE");
MESA_load_profile_string_def("./tsgconf/main.conf", "SYSTEM", "L7_PROTOCOL_FILE", l7_proto_name, sizeof(l7_proto_name), "./tsgconf/tsg_l7_protocol.conf");
#endif
env->l7_exdata_idx= stellar_exdata_new_index(st, "L7_PROTOCOL", stellar_exdata_free_default, NULL);
env->test_exdata_idx= stellar_exdata_new_index(st, "APP_PROTO_TEST", stellar_exdata_free_default, NULL);
if(env->l7_exdata_idx<0 || env->test_exdata_idx<0)
{
perror("GLIMPSE_DETECTOR_TEST_PLUG_INIT:stellar_session_get_ex_new_index faild!!!\n");
perror("gtest_lpi_plugin_load:stellar_session_get_ex_new_index faild!!!\n");
exit(-1);
}
if(load_l7_protocol_mapper(l7_proto_name, env)<0)
{
perror("GLIMPSE_DETECTOR_TEST_PLUG_INIT:l7_protocol_mapper failed !!!\n");
perror("gtest_lpi_plugin_load:l7_protocol_mapper failed !!!\n");
exit(-1);
}
env->test_app_plugin_id=stellar_session_plugin_register(st, glimpse_detector_test_ctx_new, NULL, env);
env->test_app_plugin_id=stellar_session_plugin_register(st, lpi_test_ctx_new, NULL, env);
if(env->test_app_plugin_id < 0)
{
perror("GLIMPSE_DETECTOR_TEST_PLUG_INIT:stellar_plugin_register failed !!!\n");
perror("gtest_lpi_plugin_load:stellar_plugin_register failed !!!\n");
exit(-1);
}
@@ -171,26 +163,26 @@ extern "C" void *GLIMPSE_DETECTOR_TEST_PLUG_LOAD(struct stellar *st)
int udp_topic_id=stellar_mq_get_topic_id(st, TOPIC_UDP_INPUT);
if(tcp_topic_id < 0 || udp_topic_id < 0)
{
perror("GLIMPSE_DETECTOR_TEST get tcp or udp topic id failed\n");
perror("gtest_lpi_plugin_load get tcp or udp topic id failed\n");
exit(-1);
}
stellar_session_mq_subscribe(st, tcp_topic_id, APP_TEST_ON_SESSION_MSG, env->test_app_plugin_id);
stellar_session_mq_subscribe(st, udp_topic_id, APP_TEST_ON_SESSION_MSG, env->test_app_plugin_id);
stellar_session_mq_subscribe(st, tcp_topic_id, gtest_lpi_plugin_on_msg, env->test_app_plugin_id);
stellar_session_mq_subscribe(st, udp_topic_id, gtest_lpi_plugin_on_msg, env->test_app_plugin_id);
env->expect_json_topic_id = stellar_mq_create_topic(st, "EXPECT_JSON", stellar_msg_free_default, NULL);
printf("GLIMPSE_DETECTOR_TEST_PLUG_LOAD OK!\n");
printf("gtest_lpi_plugin_load OK!\n");
return env;
}
extern "C" void GLIMPSE_DETECTOR_TEST_PLUG_UNLOAD(void *plugin_env)
extern "C" void gtest_lpi_plugin_unload(void *plugin_env)
{
struct glimpse_detector_test_plugin_env *env = (struct glimpse_detector_test_plugin_env *)plugin_env;
struct lpi_test_plugin_env *env = (struct lpi_test_plugin_env *)plugin_env;
for(int i = 0; i < MAX_APP_ID_VALUE; i++)
{
if(env->g_proto_id2name[i])free(env->g_proto_id2name[i]);
}
free(env);
printf("GLIMPSE_DETECTOR_TEST_PLUG_UNLOAD OK!\n");
printf("gtest_lpi_plugin_unload OK!\n");
return ;
}

View File

@@ -0,0 +1,11 @@
# stellar_plugin.toml
#
[[plugin]]
path = ""
init = "lpi_plugin_load"
exit = "lpi_plugin_unload"
[[plugin]]
path = ""
init = "gtest_lpi_plugin_load"
exit = "gtest_lpi_plugin_unload"