提前释放maa_state和process context

This commit is contained in:
liuxueli
2023-06-08 17:57:12 +08:00
parent cad3ae8cad
commit 7e7b1165ed
4 changed files with 41 additions and 9 deletions

View File

@@ -86,7 +86,7 @@ void session_proxy_log_update_free(const struct streaminfo *a_stream, int bridge
return;
}
void session_runtime_process_context_free(const struct streaminfo *a_stream, int bridge_id, void *data)
void session_runtime_process_context_free_cb(const struct streaminfo *a_stream, int bridge_id, void *data)
{
struct session_runtime_process_context *srt_process_context=(struct session_runtime_process_context *)data;
if(srt_process_context!=NULL)
@@ -263,6 +263,16 @@ const struct session_runtime_attribute *session_runtime_attribute_get(const stru
return (struct session_runtime_attribute *)session_async_bridge_get_data(a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ATTRIBUTE].id);
}
void srt_attribute_free_proxy_tcp_option(const struct streaminfo *a_stream)
{
struct session_runtime_attribute *srt_attribute=(struct session_runtime_attribute *)session_runtime_attribute_get(a_stream);
if(srt_attribute!=NULL && srt_attribute->proxy_tcp_attr!=NULL)
{
dictator_free(a_stream->threadnum, (void *)srt_attribute->proxy_tcp_attr);
srt_attribute->proxy_tcp_attr=NULL;
}
}
int srt_attribute_set_establish_latecy(const struct streaminfo *a_stream)
{
unsigned long long create_time=0;
@@ -506,7 +516,7 @@ const struct session_runtime_process_context *session_runtime_process_context_ne
int ret=session_async_bridge_set_data(a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)srt_attribute);
if(ret<0)
{
session_runtime_process_context_free(a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)srt_attribute);
session_runtime_process_context_free_cb(a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)srt_attribute);
srt_attribute=NULL;
return NULL;
}
@@ -520,6 +530,16 @@ const struct session_runtime_process_context *session_runtime_process_context_ge
return (struct session_runtime_process_context *)session_async_bridge_get_data(a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id);
}
void session_runtime_process_context_free(const struct streaminfo *a_stream)
{
const struct session_runtime_process_context *srt_process_context=session_runtime_process_context_get(a_stream);
if(srt_process_context!=NULL)
{
session_runtime_process_context_free_cb(a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)srt_process_context);
session_runtime_process_context_async(a_stream, NULL);
}
}
enum TSG_PROTOCOL srt_process_context_get_protocol(const struct session_runtime_process_context *srt_process_context)
{
if(srt_process_context!=NULL)
@@ -1056,7 +1076,7 @@ int tsg_bridge_init(const char *conffile)
g_tm_bridge_para[BRIDGE_TYPE_SHAPING_RESULT].free_cb=session_matched_rules_free_by_bridge;
MESA_load_profile_string_def(conffile, "BRIDGE", "DATA_CONTEXT_BRIDGE_NAME", g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].name, MAX_BRIDGE_NAME_LEN, "TSG_DATA_CONTEXT");
g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].free_cb=session_runtime_process_context_free;
g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].free_cb=session_runtime_process_context_free_cb;
MESA_load_profile_string_def(conffile, "BRIDGE", "ALL_RESULT_BRIDGE_NAME", g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].name, MAX_BRIDGE_NAME_LEN, "TSG_ALL_CONTEXT");
g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].free_cb=session_runtime_action_context_free;

View File

@@ -101,7 +101,7 @@ struct session_runtime_action_context
char udp_data_dropme;
char set_latency_flag;
char direction;
char padding[1];
char padding[5];
enum TSG_METHOD_TYPE method_type;
enum TSG_PROTOCOL protocol;
char *l4_protocol;
@@ -183,6 +183,8 @@ int srt_attribute_set_establish_latecy(const struct streaminfo * a_stream);
int srt_attribute_set_ja3_fingprint(const struct streaminfo *a_stream, const char *ja3_fingerprint);
int srt_attribute_set_reponse_size(const struct streaminfo *a_stream, int http_action_file_size);
void srt_attribute_free_proxy_tcp_option(const struct streaminfo *a_stream);
//gather app identify result
int session_gather_app_results_async(const struct streaminfo * a_stream, void * data);
void *session_gather_app_results_get(const struct streaminfo * a_stream);
@@ -204,3 +206,6 @@ enum TSG_METHOD_TYPE srt_action_context_get_method_type(const struct session_run
const struct session_runtime_process_context *session_runtime_process_context_new(const struct streaminfo * a_stream);
void session_runtime_process_context_free(const struct streaminfo *a_stream);

View File

@@ -1957,7 +1957,7 @@ unsigned char session_matched_rules_deal(const struct streaminfo *a_stream, stru
int session_app_identify_result_cb(const struct streaminfo *a_stream, int bridge_id, void *data)
{
if(data==NULL)
if(data==NULL || a_stream->opstate==OP_STATE_CLOSE)
{
return 0;
}
@@ -2024,7 +2024,7 @@ int session_app_identify_result_cb(const struct streaminfo *a_stream, int bridge
int session_flags_identify_result_cb(const struct streaminfo *a_stream, int bridge_id, void *data)
{
if(data==NULL)
if(data==NULL || a_stream->opstate==OP_STATE_CLOSE)
{
return 0;
}
@@ -2171,6 +2171,8 @@ static unsigned char tsg_master_data_entry(const struct streaminfo *a_stream, vo
}
state=session_matched_rules_deal(a_stream, srt_process_context, matched_rules, hit_num, a_packet);
srt_process_context->deal_pkt_num++;
srt_attribute_free_proxy_tcp_option(a_stream);
}
switch(a_stream->opstate)
@@ -2239,6 +2241,11 @@ static unsigned char tsg_master_data_entry(const struct streaminfo *a_stream, vo
if((a_stream->opstate==OP_STATE_CLOSE) || (state&APP_STATE_DROPME)==APP_STATE_DROPME)
{
session_runtime_process_context_free(a_stream);
maat_state_free(srt_process_context->mid);
srt_process_context->mid=NULL;
*pme=NULL;
}

View File

@@ -354,14 +354,14 @@ TEST(TSG_Bridge, AppSignatureResultAsync)
}
extern const struct session_runtime_process_context *session_runtime_process_context_new(const struct streaminfo *a_stream);
extern void session_runtime_process_context_free(const struct streaminfo *a_stream, int bridge_id, void *data);
extern void session_runtime_process_context_free_cb(const struct streaminfo *a_stream, int bridge_id, void *data);
TEST(TSG_Bridge, SessionProcessContextAsync)
{
const struct streaminfo a_stream = {0};
const struct session_runtime_process_context *context = session_runtime_process_context_new(&a_stream);
EXPECT_EQ(session_runtime_process_context_get(&a_stream), context);
EXPECT_EQ(session_runtime_process_context_get(&a_stream), session_runtime_process_context_new(&a_stream));
session_runtime_process_context_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)context);
session_runtime_process_context_free_cb(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)context);
session_runtime_process_context_async(&a_stream, NULL);
EXPECT_EQ(nullptr, session_runtime_process_context_get(&a_stream));
}
@@ -403,7 +403,7 @@ TEST(TSG_Bridge, ProcessAndActionContextAsync)
EXPECT_STREQ(process_test->domain, "thisisdomain");
EXPECT_STREQ(process_test->http_url, "thisishttp_url");
session_runtime_action_context_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id, (void *)action_ctx);
session_runtime_process_context_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)process_test);
session_runtime_process_context_free_cb(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)process_test);
session_runtime_action_context_async(&a_stream, NULL);
EXPECT_EQ(nullptr, session_runtime_action_context_get(&a_stream));
session_runtime_process_context_async(&a_stream, NULL);