TSG-14580: 链接命中shunt动作时不记录任何日志
This commit is contained in:
@@ -704,9 +704,8 @@ int srt_action_context_set_leaky_bucket(const struct streaminfo *a_stream, struc
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char srt_action_context_get_direction(const struct streaminfo *a_stream)
|
char srt_action_context_get_direction(const struct session_runtime_action_context *srt_action_context)
|
||||||
{
|
{
|
||||||
struct session_runtime_action_context *srt_action_context=(struct session_runtime_action_context *)session_async_bridge_get_data(a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id);
|
|
||||||
if(srt_action_context!=NULL)
|
if(srt_action_context!=NULL)
|
||||||
{
|
{
|
||||||
return srt_action_context->direction;
|
return srt_action_context->direction;
|
||||||
@@ -715,6 +714,16 @@ char srt_action_context_get_direction(const struct streaminfo *a_stream)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TSG_METHOD_TYPE srt_action_context_get_method_type(const struct session_runtime_action_context *srt_action_context)
|
||||||
|
{
|
||||||
|
if(srt_action_context!=NULL)
|
||||||
|
{
|
||||||
|
return srt_action_context->method_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSG_METHOD_TYPE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int session_mirror_packets_sync(const struct streaminfo *a_stream, struct maat_rule *rules, struct mirrored_vlan *vlan)
|
int session_mirror_packets_sync(const struct streaminfo *a_stream, struct maat_rule *rules, struct mirrored_vlan *vlan)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -192,7 +192,9 @@ int srt_action_context_set_rule_method(const struct streaminfo * a_stream, enum
|
|||||||
int srt_action_context_set_after_n_packet(const struct streaminfo * a_stream, int after_n_packets, int thread_seq);
|
int srt_action_context_set_after_n_packet(const struct streaminfo * a_stream, int after_n_packets, int thread_seq);
|
||||||
int srt_action_context_set_hitted_app_id(const struct streaminfo * a_stream, int hited_app_id, int thread_seq);
|
int srt_action_context_set_hitted_app_id(const struct streaminfo * a_stream, int hited_app_id, int thread_seq);
|
||||||
|
|
||||||
char srt_action_context_get_direction(const struct streaminfo * a_stream);
|
const struct session_runtime_action_context *session_runtime_action_context_get(const struct streaminfo *a_stream);
|
||||||
|
char srt_action_context_get_direction(const struct session_runtime_action_context *srt_action_context);
|
||||||
|
enum TSG_METHOD_TYPE srt_action_context_get_method_type(const struct session_runtime_action_context *srt_action_context);
|
||||||
|
|
||||||
|
|
||||||
const struct session_runtime_process_context *session_runtime_process_context_new(const struct streaminfo * a_stream);
|
const struct session_runtime_process_context *session_runtime_process_context_new(const struct streaminfo * a_stream);
|
||||||
|
|||||||
@@ -380,7 +380,13 @@ static int set_location(struct TLD_handle_t *_handle, const struct streaminfo *
|
|||||||
|
|
||||||
static int set_direction(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream)
|
static int set_direction(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream)
|
||||||
{
|
{
|
||||||
char direction=srt_action_context_get_direction(a_stream);
|
const struct session_runtime_action_context *srt_action_context=session_runtime_action_context_get(a_stream);
|
||||||
|
if(srt_action_context==NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char direction=srt_action_context_get_direction(srt_action_context);
|
||||||
if(direction>0)
|
if(direction>0)
|
||||||
{
|
{
|
||||||
TLD_append(_handle, _instance->id2field[LOG_COMMON_DIRECTION].name, (void *)(long)direction, TLD_TYPE_LONG);
|
TLD_append(_handle, _instance->id2field[LOG_COMMON_DIRECTION].name, (void *)(long)direction, TLD_TYPE_LONG);
|
||||||
@@ -1573,6 +1579,23 @@ int is_multi_hit_same_policy(struct maat_rule *result, int *policy_id, int *poli
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_hitted_shunt(const struct streaminfo *a_stream)
|
||||||
|
{
|
||||||
|
if(a_stream==NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct session_runtime_action_context *srt_action_context=session_runtime_action_context_get(a_stream);
|
||||||
|
enum TSG_METHOD_TYPE method_type=srt_action_context_get_method_type(srt_action_context);
|
||||||
|
if(method_type==TSG_METHOD_TYPE_SHUNT)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int set_xxxx_from_user_region(struct TLD_handle_t *_handle, struct tsg_log_instance_t *_instance, struct maat_rule *p_result, int thread_seq)
|
static int set_xxxx_from_user_region(struct TLD_handle_t *_handle, struct tsg_log_instance_t *_instance, struct maat_rule *p_result, int thread_seq)
|
||||||
{
|
{
|
||||||
cJSON *item=NULL;
|
cJSON *item=NULL;
|
||||||
@@ -2317,6 +2340,12 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(is_hitted_shunt(a_stream))
|
||||||
|
{
|
||||||
|
TLD_cancel(handle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
TLD_append_streaminfo(instance, handle, a_stream);
|
TLD_append_streaminfo(instance, handle, a_stream);
|
||||||
TLD_append(_handle, _instance->id2field[LOG_COMMON_SLED_IP].name, (void *)(_instance->local_ip_str), TLD_TYPE_STRING);
|
TLD_append(_handle, _instance->id2field[LOG_COMMON_SLED_IP].name, (void *)(_instance->local_ip_str), TLD_TYPE_STRING);
|
||||||
if(strlen(g_tsg_para.device_sn)>0)
|
if(strlen(g_tsg_para.device_sn)>0)
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ TEST(TSG_Bridge, SessionActionContextAsync)
|
|||||||
EXPECT_EQ(session_runtime_action_context_get(&a_stream), context);
|
EXPECT_EQ(session_runtime_action_context_get(&a_stream), context);
|
||||||
EXPECT_EQ(session_runtime_action_context_get(&a_stream), session_runtime_action_context_new(&a_stream));
|
EXPECT_EQ(session_runtime_action_context_get(&a_stream), session_runtime_action_context_new(&a_stream));
|
||||||
context->direction = DIR_S2C;
|
context->direction = DIR_S2C;
|
||||||
EXPECT_EQ(srt_action_context_get_direction(&a_stream), DIR_S2C);
|
EXPECT_EQ(srt_action_context_get_direction(context), DIR_S2C);
|
||||||
session_runtime_action_context_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id, (void *)context);
|
session_runtime_action_context_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id, (void *)context);
|
||||||
session_runtime_action_context_async(&a_stream, NULL);
|
session_runtime_action_context_async(&a_stream, NULL);
|
||||||
EXPECT_EQ(nullptr, session_runtime_action_context_get(&a_stream));
|
EXPECT_EQ(nullptr, session_runtime_action_context_get(&a_stream));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <MESA/stream.h>
|
#include <MESA/stream.h>
|
||||||
|
|
||||||
#include "tsg_rule.h"
|
#include "tsg_rule.h"
|
||||||
|
#include "tsg_bridge.h"
|
||||||
#include "tsg_send_log.h"
|
#include "tsg_send_log.h"
|
||||||
#include "tsg_send_log_internal.h"
|
#include "tsg_send_log_internal.h"
|
||||||
|
|
||||||
@@ -106,9 +107,21 @@ void session_matched_rules_free(const struct streaminfo * a_stream, TSG_SERVICE
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
char srt_action_context_get_direction(const struct streaminfo * a_stream)
|
struct session_runtime_action_context g_session_runtime_action_context;
|
||||||
|
|
||||||
|
const struct session_runtime_action_context *session_runtime_action_context_get(const struct streaminfo *a_stream)
|
||||||
{
|
{
|
||||||
return 0;
|
return (const struct session_runtime_action_context *)&(g_session_runtime_action_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
char srt_action_context_get_direction(const struct session_runtime_action_context * srt_action_context)
|
||||||
|
{
|
||||||
|
return g_session_runtime_action_context.direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TSG_METHOD_TYPE srt_action_context_get_method_type(const struct session_runtime_action_context * srt_action_context)
|
||||||
|
{
|
||||||
|
return g_session_runtime_action_context.method_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsg_get_app_name_by_id(struct maat *feahter, int app_id, char * app_name, int app_name_len, int is_joint_parent)
|
int tsg_get_app_name_by_id(struct maat *feahter, int app_id, char * app_name, int app_name_len, int is_joint_parent)
|
||||||
@@ -146,8 +159,7 @@ TEST(Master, SendInterimRecord)
|
|||||||
|
|
||||||
struct TLD_handle_t * handle=TLD_create(0);
|
struct TLD_handle_t * handle=TLD_create(0);
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_INTERIM_SESSION_RECORD, &rules, 1, 0);
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_INTERIM_SESSION_RECORD, &rules, 1, 0);
|
||||||
int sendlog_cnt=rd_kafka_get_sendlog_cnt();
|
EXPECT_EQ(1, rd_kafka_get_sendlog_cnt());
|
||||||
EXPECT_EQ(1, sendlog_cnt);
|
|
||||||
EXPECT_STREQ("{\"common_server_port\":0,\"common_client_port\":0,\"common_stream_dir\":0,\"common_address_type\":0,\"common_stream_trace_id\":\"5\",\"common_sled_ip\":\"0.0.0.0\",\"common_t_vsys_id\":1,\"common_vsys_id\":1}",rd_kafka_get_sendlog_payload(0));
|
EXPECT_STREQ("{\"common_server_port\":0,\"common_client_port\":0,\"common_stream_dir\":0,\"common_address_type\":0,\"common_stream_trace_id\":\"5\",\"common_sled_ip\":\"0.0.0.0\",\"common_t_vsys_id\":1,\"common_vsys_id\":1}",rd_kafka_get_sendlog_payload(0));
|
||||||
rd_kafka_clean_sendlog_cnt();
|
rd_kafka_clean_sendlog_cnt();
|
||||||
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
@@ -155,8 +167,7 @@ TEST(Master, SendInterimRecord)
|
|||||||
g_tsg_log_instance->send_interim_log=0;
|
g_tsg_log_instance->send_interim_log=0;
|
||||||
handle=TLD_create(0);
|
handle=TLD_create(0);
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_INTERIM_SESSION_RECORD, &rules, 1, 0);
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_INTERIM_SESSION_RECORD, &rules, 1, 0);
|
||||||
sendlog_cnt=rd_kafka_get_sendlog_cnt();
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
EXPECT_EQ(0, sendlog_cnt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Master, SendTranscationRecord)
|
TEST(Master, SendTranscationRecord)
|
||||||
@@ -170,8 +181,7 @@ TEST(Master, SendTranscationRecord)
|
|||||||
|
|
||||||
struct TLD_handle_t * handle=TLD_create(0);
|
struct TLD_handle_t * handle=TLD_create(0);
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_TRANSACTION_RECORD, &rules, 1, 0);
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_TRANSACTION_RECORD, &rules, 1, 0);
|
||||||
int sendlog_cnt=rd_kafka_get_sendlog_cnt();
|
EXPECT_EQ(1, rd_kafka_get_sendlog_cnt());
|
||||||
EXPECT_EQ(1, sendlog_cnt);
|
|
||||||
EXPECT_STREQ("{\"common_server_port\":0,\"common_client_port\":0,\"common_stream_dir\":0,\"common_address_type\":0,\"common_stream_trace_id\":\"5\",\"common_sled_ip\":\"0.0.0.0\",\"common_t_vsys_id\":1,\"common_vsys_id\":1}",rd_kafka_get_sendlog_payload(0));
|
EXPECT_STREQ("{\"common_server_port\":0,\"common_client_port\":0,\"common_stream_dir\":0,\"common_address_type\":0,\"common_stream_trace_id\":\"5\",\"common_sled_ip\":\"0.0.0.0\",\"common_t_vsys_id\":1,\"common_vsys_id\":1}",rd_kafka_get_sendlog_payload(0));
|
||||||
rd_kafka_clean_sendlog_cnt();
|
rd_kafka_clean_sendlog_cnt();
|
||||||
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
@@ -179,8 +189,7 @@ TEST(Master, SendTranscationRecord)
|
|||||||
g_tsg_log_instance->send_transcation_log=0;
|
g_tsg_log_instance->send_transcation_log=0;
|
||||||
handle=TLD_create(0);
|
handle=TLD_create(0);
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_TRANSACTION_RECORD, &rules, 1, 0);
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_TRANSACTION_RECORD, &rules, 1, 0);
|
||||||
sendlog_cnt=rd_kafka_get_sendlog_cnt();
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
EXPECT_EQ(0, sendlog_cnt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Master, SendSessionRecord)
|
TEST(Master, SendSessionRecord)
|
||||||
@@ -194,8 +203,7 @@ TEST(Master, SendSessionRecord)
|
|||||||
|
|
||||||
struct TLD_handle_t * handle=TLD_create(0);
|
struct TLD_handle_t * handle=TLD_create(0);
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
||||||
int sendlog_cnt=rd_kafka_get_sendlog_cnt();
|
EXPECT_EQ(1, rd_kafka_get_sendlog_cnt());
|
||||||
EXPECT_EQ(1, sendlog_cnt);
|
|
||||||
EXPECT_STREQ("{\"common_server_port\":0,\"common_client_port\":0,\"common_stream_dir\":0,\"common_address_type\":0,\"common_stream_trace_id\":\"5\",\"common_sled_ip\":\"0.0.0.0\",\"common_t_vsys_id\":1,\"common_vsys_id\":1}",rd_kafka_get_sendlog_payload(0));
|
EXPECT_STREQ("{\"common_server_port\":0,\"common_client_port\":0,\"common_stream_dir\":0,\"common_address_type\":0,\"common_stream_trace_id\":\"5\",\"common_sled_ip\":\"0.0.0.0\",\"common_t_vsys_id\":1,\"common_vsys_id\":1}",rd_kafka_get_sendlog_payload(0));
|
||||||
rd_kafka_clean_sendlog_cnt();
|
rd_kafka_clean_sendlog_cnt();
|
||||||
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
@@ -206,8 +214,7 @@ TEST(Master, SendSessionRecord)
|
|||||||
a_stream.type=STREAM_TYPE_TCP;
|
a_stream.type=STREAM_TYPE_TCP;
|
||||||
|
|
||||||
handle=TLD_create(0);
|
handle=TLD_create(0);
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
||||||
sendlog_cnt=rd_kafka_get_sendlog_cnt();
|
|
||||||
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
|
|
||||||
//pkts=2, bytes=1500
|
//pkts=2, bytes=1500
|
||||||
@@ -215,10 +222,32 @@ TEST(Master, SendSessionRecord)
|
|||||||
a_stream.ptcpdetail=&pdetail;
|
a_stream.ptcpdetail=&pdetail;
|
||||||
a_stream.type=STREAM_TYPE_TCP;
|
a_stream.type=STREAM_TYPE_TCP;
|
||||||
|
|
||||||
handle=TLD_create(0);
|
handle=TLD_create(0);
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
|
||||||
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
||||||
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Master, SendSessionRecordWithHittedShunt)
|
||||||
|
{
|
||||||
|
struct streaminfo a_stream={0};
|
||||||
|
struct tcpdetail pdetail={NULL, 0, 0, 3, 50, 3, 50, 0, 1};
|
||||||
|
a_stream.ptcpdetail=&pdetail;
|
||||||
|
a_stream.type=STREAM_TYPE_TCP;
|
||||||
|
|
||||||
|
struct maat_rule rules={0, 0, 0, 2, 0, 1};
|
||||||
|
|
||||||
|
struct TLD_handle_t * handle=TLD_create(0);
|
||||||
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
||||||
|
EXPECT_EQ(1, rd_kafka_get_sendlog_cnt());
|
||||||
|
EXPECT_STREQ("{\"common_server_port\":0,\"common_client_port\":0,\"common_stream_dir\":0,\"common_address_type\":0,\"common_stream_trace_id\":\"5\",\"common_sled_ip\":\"0.0.0.0\",\"common_t_vsys_id\":1,\"common_vsys_id\":1}",rd_kafka_get_sendlog_payload(0));
|
||||||
|
rd_kafka_clean_sendlog_cnt();
|
||||||
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
|
|
||||||
|
g_session_runtime_action_context.method_type=TSG_METHOD_TYPE_SHUNT;
|
||||||
|
handle=TLD_create(0);
|
||||||
|
tsg_send_log(g_tsg_log_instance, handle, &a_stream, LOG_TYPE_SESSION_RECORD, &rules, 1, 0);
|
||||||
|
EXPECT_EQ(0, rd_kafka_get_sendlog_cnt());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
Reference in New Issue
Block a user