summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorliuxueli <[email protected]>2023-01-11 14:52:48 +0800
committerliuxueli <[email protected]>2023-01-11 14:52:48 +0800
commit7ea9288da4d86e15205e633e307f696e6cafc6cd (patch)
tree11beefd6ae1b5e71513f88a2b5385b97fcf1b886 /src
parent8e48dfd98279582033ce68d8a052ec87cf87d457 (diff)
TSG-13031: 没有原始数据包时获取direction可能存在异常,调整获取direction的时机,即在第一个数据包时获取direction
Diffstat (limited to 'src')
-rw-r--r--src/tsg_entry.cpp56
-rw-r--r--src/tsg_entry.h6
-rw-r--r--src/tsg_send_log.cpp35
3 files changed, 64 insertions, 33 deletions
diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp
index 2443791..94f6b30 100644
--- a/src/tsg_entry.cpp
+++ b/src/tsg_entry.cpp
@@ -265,6 +265,41 @@ static int get_deploy_mode(void)
return 0;
}
+static char get_direction(const struct streaminfo *a_stream)
+{
+ int i_or_e=0;
+ char direction=0;
+
+ i_or_e=MESA_dir_link_to_human(a_stream->routedir);
+ switch(a_stream->curdir)
+ {
+ case DIR_C2S:
+ if(i_or_e=='E' || i_or_e=='e')
+ {
+ direction='E';
+ }
+ else
+ {
+ direction='I';
+ }
+ break;
+ case DIR_S2C:
+ if(i_or_e=='E' || i_or_e=='e')
+ {
+ direction='I';
+ }
+ else
+ {
+ direction='E';
+ }
+ break;
+ default:
+ break;
+ }
+
+ return direction;
+}
+
static int print_hit_path(const struct streaminfo *a_stream, struct master_context *context)
{
if(g_tsg_para.hit_path_switch==0)
@@ -1378,6 +1413,18 @@ int set_bucket_to_tcpall(const struct streaminfo *a_stream, struct leaky_bucket
return 1;
}
+char get_direction_from_tcpall(const struct streaminfo *a_stream)
+{
+ struct tcpall_context *context=(struct tcpall_context *)get_struct_project(a_stream, g_tsg_para.tcpall_project_id);
+ if(context!=NULL)
+ {
+ return context->direction;
+ }
+
+ return -1;
+}
+
+
void set_session_attribute_label(const struct streaminfo *a_stream, enum TSG_ATTRIBUTE_TYPE type, void *value, int value_len, int thread_seq)
{
unsigned long long create_time=0;
@@ -2427,6 +2474,8 @@ extern "C" unsigned char TSG_MASTER_UDP_ENTRY(const struct streaminfo *a_udp, vo
context->all_entry=(struct tcpall_context *)dictator_malloc(thread_seq, sizeof(struct tcpall_context));
memset(context->all_entry, 0, sizeof(struct tcpall_context));
set_struct_project(a_udp, g_tsg_para.tcpall_project_id, (void *)(context->all_entry));
+
+ context->all_entry->direction=get_direction(a_udp);
}
if(context->all_entry->udp_data_dropme==0)
@@ -2456,6 +2505,8 @@ extern "C" unsigned char TSG_MASTER_UDP_ENTRY(const struct streaminfo *a_udp, vo
extern "C" unsigned char TSG_MASTER_TCPALL_ENTRY(const struct streaminfo *a_tcp, void **pme, int thread_seq, const void *a_packet)
{
+ struct tcpall_context *_context=(struct tcpall_context *)(*pme);
+
if(*pme==NULL)
{
*pme=(void *)get_struct_project(a_tcp, g_tsg_para.tcpall_project_id);
@@ -2465,10 +2516,11 @@ extern "C" unsigned char TSG_MASTER_TCPALL_ENTRY(const struct streaminfo *a_tcp,
memset(*pme, 0, sizeof(struct tcpall_context));
set_struct_project(a_tcp, g_tsg_para.tcpall_project_id, (void *)(*pme));
}
+
+ _context=(struct tcpall_context *)(*pme);
+ _context->direction=get_direction(a_tcp);
}
- struct tcpall_context *_context=(struct tcpall_context *)(*pme);
-
if(_context->set_latency_flag==0)
{
_context->set_latency_flag=set_tcp_establish_latency_ms(a_tcp, thread_seq, a_packet);
diff --git a/src/tsg_entry.h b/src/tsg_entry.h
index 02a15b6..ffaaaab 100644
--- a/src/tsg_entry.h
+++ b/src/tsg_entry.h
@@ -287,7 +287,8 @@ struct tcpall_context
{
char udp_data_dropme;
char set_latency_flag;
- char padding[6];
+ char direction;
+ char padding[5];
enum TSG_METHOD_TYPE method_type;
tsg_protocol_t protocol;
union
@@ -487,6 +488,9 @@ int set_method_to_tcpall(const struct streaminfo *a_stream, enum TSG_METHOD_TYPE
int set_protocol_to_tcpall(const struct streaminfo *a_stream, tsg_protocol_t protocol, int thread_seq);
int set_bucket_to_tcpall(const struct streaminfo *a_stream, struct leaky_bucket *bucket, int thread_seq);
int set_after_n_packet_to_tcpall(const struct streaminfo *a_stream, int after_n_packets, int thread_seq);
+
+char get_direction_from_tcpall(const struct streaminfo *a_stream);
+
void security_compile_free(int idx, const struct Maat_rule_t* rule, const char* srv_def_large, MAAT_RULE_EX_DATA* ad, long argl, void *argp);
struct Maat_rule_t *tsg_policy_decision_criteria(struct streaminfo *a_stream, Maat_rule_t *result, int result_num, int thread_seq);
diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp
index 77b814c..6fce17c 100644
--- a/src/tsg_send_log.cpp
+++ b/src/tsg_send_log.cpp
@@ -382,39 +382,14 @@ static int set_location(struct TLD_handle_t *_handle, struct streaminfo *a_strea
static int set_direction(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream)
{
- int direction=0,i_or_e=0;
-
- i_or_e=MESA_dir_link_to_human(a_stream->routedir);
- switch(a_stream->curdir)
+ char direction=get_direction_from_tcpall(a_stream);
+ if(direction>0)
{
- case DIR_C2S:
- if(i_or_e=='E' || i_or_e=='e')
- {
- direction='E';
- }
- else
- {
- direction='I';
- }
- break;
- case DIR_S2C:
- if(i_or_e=='E' || i_or_e=='e')
- {
- direction='I';
- }
- else
- {
- direction='E';
- }
- break;
- default:
- break;
+ TLD_append(_handle, _instance->id2field[LOG_COMMON_DIRECTION].name, (void *)(long)direction, TLD_TYPE_LONG);
+ return 1;
}
-
- TLD_append(_handle, _instance->id2field[LOG_COMMON_DIRECTION].name, (void *)(long)direction, TLD_TYPE_LONG);
-
- return 1;
+ return 0;
}
static int set_address_list(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream)