summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuxueli <[email protected]>2023-06-06 17:07:59 +0800
committerliuxueli <[email protected]>2023-06-06 17:07:59 +0800
commit78f9aa6601f8f09979b8001397526d0f33b7a36b (patch)
treeb5757bf48b07bf78471de3aaf0ce659903eedc1e
parent4c8eecdb414b6fb2897cd628acb7bbcfc19c1556 (diff)
增加L7 protocol识别结果通知更新的测试用例
-rw-r--r--src/tsg_entry.cpp17
-rw-r--r--test/src/gtest_common.cpp13
-rw-r--r--test/src/gtest_common.h4
-rw-r--r--test/src/gtest_master.cpp34
-rw-r--r--test/src/gtest_protocol.cpp13
5 files changed, 72 insertions, 9 deletions
diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp
index 5abf504..f26f705 100644
--- a/src/tsg_entry.cpp
+++ b/src/tsg_entry.cpp
@@ -1128,15 +1128,18 @@ int session_application_metrics_update(const struct streaminfo *a_stream, struct
static int session_app_gather_results_set_l7_protocol(const struct streaminfo *a_stream, enum TSG_PROTOCOL protocol)
{
struct gather_app_result *gather_result=(struct gather_app_result *)session_gather_app_results_get(a_stream);
- if(gather_result!=NULL)
+ if(gather_result==NULL)
+ {
+ gather_result=(struct gather_app_result *)dictator_malloc(a_stream->threadnum, sizeof(struct gather_app_result)*ORIGIN_MAX);
+ memset(gather_result, 0, sizeof(struct gather_app_result)*ORIGIN_MAX);
+ session_gather_app_results_async(a_stream, (void *)gather_result);
+ }
+
+ if(gather_result[ORIGIN_BASIC_PROTOCOL].app_num>0)
{
return 0;
}
- gather_result=(struct gather_app_result *)dictator_malloc(a_stream->threadnum, sizeof(struct gather_app_result)*ORIGIN_MAX);
- memset(gather_result, 0, sizeof(struct gather_app_result)*ORIGIN_MAX);
- session_gather_app_results_async(a_stream, (void *)gather_result);
-
int app_id=tsg_l7_protocol_name2id(g_tsg_proto_name2id[protocol].name);
if(app_id>0)
{
@@ -1530,7 +1533,7 @@ struct maat_rule *matched_rules_decision_criteria(struct maat_rule *rules, size_
return p_result;
}
-static int session_l7_protocol_identify(const struct streaminfo *a_stream, struct session_runtime_process_context *srt_process_context, void *a_packet)
+int session_l7_protocol_identify(const struct streaminfo *a_stream, struct session_runtime_process_context *srt_process_context, void *a_packet)
{
int ret=0;
@@ -2043,7 +2046,7 @@ int session_flags_identify_result_cb(const struct streaminfo *a_stream, int brid
return 0;
}
-static size_t session_pending_state_deal(const struct streaminfo *a_stream, struct session_runtime_process_context *srt_process_context, struct maat_rule *results, int n_results, void *a_packet)
+size_t session_pending_state_deal(const struct streaminfo *a_stream, struct session_runtime_process_context *srt_process_context, struct maat_rule *results, int n_results, void *a_packet)
{
size_t hit_num=0;
int ret=session_l7_protocol_identify(a_stream, srt_process_context, a_packet);
diff --git a/test/src/gtest_common.cpp b/test/src/gtest_common.cpp
index 71eebfd..f3e3718 100644
--- a/test/src/gtest_common.cpp
+++ b/test/src/gtest_common.cpp
@@ -250,9 +250,20 @@ extern "C" int ftp_control_identify(struct streaminfo *a_tcp)
return 0;
}
+int g_gtest_ftp_data_flag=0;
+void gtest_set_ftp_data_flag(void)
+{
+ g_gtest_ftp_data_flag=1;
+}
+
+void gtest_clean_ftp_data_flag(void)
+{
+ g_gtest_ftp_data_flag=0;
+}
+
extern "C" int ftp_data_identify(struct streaminfo *a_tcp)
{
- return 0;
+ return g_gtest_ftp_data_flag;
}
extern "C" int mail_protocol_identify_by_first_payload(struct streaminfo *a_tcp, char *payload, int payload_len, int thread_seq)
diff --git a/test/src/gtest_common.h b/test/src/gtest_common.h
index 31dd827..e32ab01 100644
--- a/test/src/gtest_common.h
+++ b/test/src/gtest_common.h
@@ -9,4 +9,8 @@ int TLD_convert_json(struct TLD_handle_t *_handle, char *buff, unsigned int buff
int set_app_id(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream);
int set_shaping_rule_ids(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream);
+void gtest_set_ftp_data_flag(void);
+void gtest_clean_ftp_data_flag(void);
+extern "C" int ftp_data_identify(struct streaminfo *a_tcp);
+
diff --git a/test/src/gtest_master.cpp b/test/src/gtest_master.cpp
index 90febc9..cd95e95 100644
--- a/test/src/gtest_master.cpp
+++ b/test/src/gtest_master.cpp
@@ -968,6 +968,40 @@ TEST(TSGMaster, ShapingPolicySendLog)
EXPECT_EQ(nullptr, hited_shaping);
}
+extern size_t session_pending_state_deal(const struct streaminfo *a_stream, struct session_runtime_process_context *srt_process_context, struct maat_rule *results, int n_results, void *a_packet);
+
+TEST(TSGMaster, SessionDealStatePending)
+{
+ struct streaminfo a_stream={0};
+ struct tcpdetail pdetail={0};
+ a_stream.type=STREAM_TYPE_TCP;
+ a_stream.ptcpdetail=&pdetail;
+
+ struct maat_rule matched_rules[MAX_RESULT_NUM]={0};
+ struct session_runtime_process_context srt_process_context={0};
+
+ gtest_set_ftp_data_flag();
+
+ size_t n_matched_rules=session_pending_state_deal((const struct streaminfo *)&a_stream, &srt_process_context, matched_rules, MAX_RESULT_NUM, NULL);
+ EXPECT_EQ(0, n_matched_rules);
+ EXPECT_EQ(PROTO_FTP, srt_process_context.proto);
+
+ struct gather_app_result *gather_result=(struct gather_app_result *)session_gather_app_results_get(&a_stream);
+ EXPECT_NE(nullptr, gather_result);
+
+ EXPECT_EQ(1, gather_result[ORIGIN_BASIC_PROTOCOL].app_num);
+ EXPECT_EQ(45, gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id);
+ EXPECT_EQ(0, gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].surrogate_id);
+
+ free(gather_result);
+ session_gather_app_results_async(&a_stream, NULL);
+ EXPECT_EQ(nullptr, session_gather_app_results_get(&a_stream));
+
+ gtest_clean_ftp_data_flag();
+ EXPECT_EQ(0, ftp_data_identify(&a_stream));
+
+}
+
int main(int argc, char *argv[])
{
TSG_MASTER_INIT();
diff --git a/test/src/gtest_protocol.cpp b/test/src/gtest_protocol.cpp
index 2103ba6..14a2266 100644
--- a/test/src/gtest_protocol.cpp
+++ b/test/src/gtest_protocol.cpp
@@ -19,9 +19,20 @@ extern "C" int ftp_control_identify(struct streaminfo *a_tcp)
return 0;
}
+int g_gtest_ftp_data_flag=0;
+void gtest_set_ftp_data_flag(void)
+{
+ g_gtest_ftp_data_flag=1;
+}
+
+void gtest_clean_ftp_data_flag(void)
+{
+ g_gtest_ftp_data_flag=0;
+}
+
extern "C" int ftp_data_identify(struct streaminfo *a_tcp)
{
- return 0;
+ return g_gtest_ftp_data_flag;
}
extern "C" int mail_protocol_identify_by_first_payload(struct streaminfo *a_tcp, char *payload, int payload_len, int thread_seq)