summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-04-15 19:39:24 +0800
committeryangwei <[email protected]>2024-04-16 09:41:54 +0800
commit6c1e6a601220a9281744f5ed626d7468b2871b8f (patch)
treea8558157a3f1f402e9d8bb8d4e60cf88e8c1d81a
parent020d83f07d272d0d25ea7c4198d74c3ba36b41d5 (diff)
🐞 fix(no use timeout): 切换到nouse后,同步插件设置的特殊超时时间v4.3.44
-rw-r--r--bin/etc/sapp.toml1
-rw-r--r--include/private/sapp_global_val.h1
-rw-r--r--include/private/stream_internal.h2
-rw-r--r--src/config/config_parse.cpp1
-rw-r--r--src/dealpkt/deal_tcp.c18
-rw-r--r--src/dealpkt/deal_udp.c3
-rw-r--r--src/dealpkt/stream_manage.c72
7 files changed, 56 insertions, 42 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml
index 150e510..ed4d3a6 100644
--- a/bin/etc/sapp.toml
+++ b/bin/etc/sapp.toml
@@ -146,6 +146,7 @@
analyse_option_enabled=1
tuple4_reuse_time_interval=30
+ #nouse_set_special_timeout=1
#reorder_on_closing=0
#max_opening_per_sec=5000
#max_timeouts_per_sec=5000
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h
index 798bc36..bb7905f 100644
--- a/include/private/sapp_global_val.h
+++ b/include/private/sapp_global_val.h
@@ -108,6 +108,7 @@ typedef struct{
int max_timeouts_per_sec;
int max_opening_per_sec;
int reorder_on_closing;
+ int nouse_set_special_timeout;
}sapp_config_stream_tcp_t;
diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h
index 697e892..0307009 100644
--- a/include/private/stream_internal.h
+++ b/include/private/stream_internal.h
@@ -203,7 +203,7 @@ struct streaminfo_private
UCHAR stream_dir:1; /* ��������������Ч, ���Ĵ洢�ĵ�ַ�Ƿ��Ĭ�Ϲ���"��˿��ǿͻ���"��ͬ */
UCHAR stream_c2s_route_dir:1; /* c2s����İ�, ��Ӧ����·route dir����, ���ڻ�ȡinbound, outbound���� */
UCHAR addr_use_as_hash:1; /* �����addr�Ƿ���ΪHASH����ͱȽϵIJ���, ��:MAC��ַ��������� */
- UCHAR __pad1:1;/*��MPLS���಻�Գ�, �����ǻ���һ����MPLS, ��һ��û��MPLS����, �˱���=1��ʾ���⹹���IJ�, ����ʱ����Ϊ��ַ�Ƚ�, ����ʱҲҪ���� */
+ UCHAR set_special_timeout:1;
UCHAR need_update_opposite_addr:1;/*�����addr�Ƿ��ڶԲ�����ʱ���£��磺MPLS��ǩ�ǶԳ�ʱ��Ҫ��S2C���һ������¼�����ǩ,��ֵĬ��Ϊ0��������Ҫ����*/
UCHAR stream_killed_flag:1; /* 2014-08-22 lijia add, ����ģʽ��, �Ѿ������Kill, ֮�������ֱ��Drop��Kill, �����ٸ��ϲ��� */
UCHAR dirreverse; /* ��������ʱ�Ƿ������ip��ַ��ת, ����"��˿��ǿͻ���"�����෴ */
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index dd1e010..21ea84f 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -1767,6 +1767,7 @@ int sapp_parse_config(void)
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"syn_mandatory", (int *)&pconfig->stream.tcp.syn_mandatory, 1);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"reorder_pkt_max", (int *)&pconfig->stream.tcp.reorder_pkt_max, 5);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"reorder_on_closing", (int *)&pconfig->stream.tcp.reorder_on_closing, 0);
+ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"nouse_set_special_timeout", (int *)&pconfig->stream.tcp.nouse_set_special_timeout, 1);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"analyse_option_enabled", (int *)&pconfig->stream.tcp.analyse_option_enabled, 1);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"tuple4_reuse_time_interval", (int *)&pconfig->stream.tcp.tuple4_reuse_time_interval, 30);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"meaningful_statistics_minimum_pkt", (int *)&pconfig->stream.tcp.meaningful_statistics_minimum_pkt, 3);
diff --git a/src/dealpkt/deal_tcp.c b/src/dealpkt/deal_tcp.c
index 49a3ac3..06a56f7 100644
--- a/src/dealpkt/deal_tcp.c
+++ b/src/dealpkt/deal_tcp.c
@@ -771,7 +771,7 @@ static struct streamindex *tcp_add_new_stream_bysyn(struct streamindex *pindex,
if(pdetail_pr->pserver){
pdetail_pr->pserver->maxunorder = tcp_default_unorder;
}
-
+ pstream_pr->set_special_timeout=0;
pstream_pr->timeout=link_default_nopkt_time;
pdetail_pr->creat_mod=TCP_CTEAT_LINK_BYSYN;
@@ -804,7 +804,6 @@ static struct streamindex *tcp_add_new_stream_bysyn(struct streamindex *pindex,
//pdetail->serverpkt++; //adjust by lqy 20140515 ֻ���½�ʱ����
pdetail_pr->C2S_first_ack_seq = ntohl (this_tcphdr->th_ack);
}
- pstream_pr->timeout=link_default_nopkt_time;
pdetail->lastmtime=g_CurrentTime;
pstream_pr->stream_lastupdate_timestamp_ms=g_CurrentTime_ms;
pdetail_pr->link_state=STREAM_LINK_JUST_EST;
@@ -1046,7 +1045,7 @@ static struct streamindex *tcp_add_new_stream_bydata(struct streamindex *pindex,
//set_stream_addr(pstream->pfather, this_tcphdr->th_dport, this_tcphdr->th_sport, pstream);
}
#endif
-
+ pstream_pr->set_special_timeout=0;
pstream_pr->timeout=link_default_nopkt_time;
pdetail_pr->creat_mod=TCP_CTEAT_LINK_BYDATA;
pstream->opstate=OP_STATE_PENDING;
@@ -1453,7 +1452,7 @@ int tcp_free_stream(struct streamindex *pindex, const void *this_ip_hdr, const v
- if(pstream_pr->timeout > link_default_nopkt_time){ /* ���Ӷ��г�ʱʱ��, ���ټ��� */
+ if(pstream_pr->set_special_timeout != 0){ /* ���Ӷ��г�ʱʱ��, ���ټ��� */
sapp_global_mthread[threadnum].tcp_stream_special_timeout_num--;
}
@@ -1642,7 +1641,7 @@ static int tcp_reset_stream(struct streamindex *pindex,const void *this_iphdr,
((raw_pkt_t *)raw_pkt)->prepend_list=NULL;
}
- if (pstream_pr->timeout > link_default_nopkt_time)
+ if (pstream_pr->set_special_timeout != 0)
{ /* ���Ӷ��г�ʱʱ��, ���ټ��� */
sapp_global_mthread[threadnum].tcp_stream_special_timeout_num--;
}
@@ -2575,7 +2574,7 @@ static int tcp_deal_data_stream(struct streamindex *pindex,const void *this_iphd
//���ϲ�ر����ӣ����ߴ������������rst����
- if((pstream->opstate==OP_STATE_CLOSE)&&(pstream->pktstate==OP_STATE_CLOSE )&&(pdetail_pr->link_state!=STREAM_LINK_RESET))
+ if((pstream->opstate==OP_STATE_CLOSE)&&(pdetail_pr->link_state!=STREAM_LINK_RESET))
{
tcp_change_stream_tonouse(pindex);
return ret;
@@ -2697,6 +2696,13 @@ static int tcp_deal_nouse_stream(struct streamindex *pindex,const void *this_iph
}
return PASS;
}
+
+ if(this_tcphdr->th_flags & TH_FIN || this_tcphdr->th_flags & TH_RST)
+ {
+ struct stream_list *lru_list_root=&(G_MESA_GLOBAL_STREAM[pstream->threadnum]->tcpList[pstream->stream_state]);
+ timeouts_add(lru_list_root->streamindex_timer, &pindex->timeout, tcp_closing_timeout*1000+g_CurrentTime_ms);
+ }
+
return PASS;
}
diff --git a/src/dealpkt/deal_udp.c b/src/dealpkt/deal_udp.c
index 1799770..833e7d5 100644
--- a/src/dealpkt/deal_udp.c
+++ b/src/dealpkt/deal_udp.c
@@ -207,6 +207,7 @@ static struct streamindex *udp_add_new_stream(struct streamindex *pindex,
plist=&(G_MESA_GLOBAL_STREAM[threadnum]->udpList[UDP_ONE_STATE]);
pstream_udp->stream_state=UDP_ONE_STATE;
+ pstream_udp_pr->set_special_timeout=0;
pstream_udp_pr->timeout=udp_reset_time;
hash_add_stream(pindex_udp);
@@ -362,7 +363,7 @@ void udp_free_stream(struct streamindex *pindex)
pstream->pdetail=NULL;
- if(pstream_pr->timeout > udp_reset_time){ /* ���Ӷ��г�ʱʱ��, ���ټ��� */
+ if(pstream_pr->set_special_timeout != 0){ /* ���Ӷ��г�ʱʱ��, ���ټ��� */
sapp_global_mthread[threadnum].udp_stream_special_timeout_num--;
}
diff --git a/src/dealpkt/stream_manage.c b/src/dealpkt/stream_manage.c
index 81a980e..fa91548 100644
--- a/src/dealpkt/stream_manage.c
+++ b/src/dealpkt/stream_manage.c
@@ -249,7 +249,7 @@ int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned s
pindex = sapp_get_struct_header(pstream_pr, struct streamindex, stream);
if (STREAM_TYPE_UDP == pstream->type)
{
- if (pstream_pr->timeout == udp_reset_time)
+ if (pstream_pr->set_special_timeout == 0)
{
/* �������������ó�ʱʱ��, ��ǰ����һ�����ó�ʱʱ���¼���� */
sapp_global_mthread[pstream->threadnum].udp_stream_special_timeout_num++;
@@ -257,7 +257,7 @@ int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned s
}
else if (STREAM_TYPE_TCP == pstream->type)
{
- if (pstream_pr->timeout == link_default_nopkt_time)
+ if (pstream_pr->set_special_timeout == 0)
{
/* �������������ó�ʱʱ��, ��ǰ����һ�����ó�ʱʱ���¼���� */
sapp_global_mthread[pstream->threadnum].tcp_stream_special_timeout_num++;
@@ -267,13 +267,13 @@ int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned s
{
goto err; /* ��֧��TCP��UDP�� */
}
-
if(pstream_pr->plugin_process_context != 0)
{
stream_timeout_shift_lrulist(pindex, timeout);
}
pstream_pr->timeout=timeout;
+ pstream_pr->set_special_timeout=1;
return ret;
err:
@@ -378,23 +378,26 @@ void streamaddlist(struct streamindex *pindex,struct stream_list *plist)
}
struct streaminfo *pstream=(struct streaminfo *)(&(pindex->stream));
+ struct streaminfo_private *pstream_pr = (struct streaminfo_private *)(&(pindex->stream));
time_t next_timeout_ms=0;
timeout_init(&pindex->timeout, TIMEOUT_ABS);
- if(pstream->stream_state==TCP_NOUSE_STATE && pstream->type == STREAM_TYPE_TCP)
- {
- next_timeout_ms= tcp_closing_timeout*1000+g_CurrentTime_ms;
- }
- else if(pstream->stream_state==TCP_SYN_STATE && pstream->type == STREAM_TYPE_TCP)
- {
- next_timeout_ms= tcp_opening_timeout*1000+g_CurrentTime_ms;
- }
- else
- {
- long set_timeout = pindex->stream.timeout;
- if(set_timeout == 0)set_timeout = MAX_DEFALUT_TIMEOUT_S;
- next_timeout_ms=set_timeout*1000+g_CurrentTime_ms;
- }
- timeouts_add(plist->streamindex_timer, &pindex->timeout, next_timeout_ms);
+ if (pstream->stream_state == TCP_SYN_STATE && pstream->type == STREAM_TYPE_TCP)
+ {
+ next_timeout_ms = tcp_opening_timeout * 1000 + g_CurrentTime_ms;
+ }
+ else if ((pstream->stream_state == TCP_NOUSE_STATE && pstream->type == STREAM_TYPE_TCP) &&
+ (pstream_pr->set_special_timeout == 0 || sapp_global_val->config.stream.tcp.nouse_set_special_timeout == 0))
+ {
+ next_timeout_ms = tcp_closing_timeout * 1000 + g_CurrentTime_ms;
+ }
+ else
+ {
+ long set_timeout = pindex->stream.timeout;
+ if (set_timeout == 0)
+ set_timeout = MAX_DEFALUT_TIMEOUT_S;
+ next_timeout_ms = set_timeout * 1000 + g_CurrentTime_ms;
+ }
+ timeouts_add(plist->streamindex_timer, &pindex->timeout, next_timeout_ms);
sapp_runtime_log(RLOG_LV_DEBUG, "streamaddlist timeout_add: %s, thread:%d, stream_type:%d, stream_state:%d, curtime:%ld, next_timeout_s:%ld!",
printaddr(&pindex->stream.stream_public.addr, pindex->stream.stream_public.threadnum),
pindex->stream.stream_public.threadnum,
@@ -596,22 +599,23 @@ int lrustream(struct streamindex *pindex)
}
else
{
- if (pstream->stream_state == TCP_NOUSE_STATE && pstream->type == STREAM_TYPE_TCP)
- {
- timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_closing_timeout*1000 + g_CurrentTime_ms);
- }
- else if (pstream->stream_state == TCP_SYN_STATE && pstream->type == STREAM_TYPE_TCP)
- {
- timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_opening_timeout*1000 + g_CurrentTime_ms);
- }
- else
- {
- long set_timeout = pindex->stream.timeout;
- if (set_timeout == 0)
- set_timeout = MAX_DEFALUT_TIMEOUT_S;
- timeouts_add(plist->streamindex_timer, &pindex->timeout, set_timeout*1000 + g_CurrentTime_ms);
- }
- }
+ if (pstream->stream_state == TCP_SYN_STATE && pstream->type == STREAM_TYPE_TCP)
+ {
+ timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_opening_timeout * 1000 + g_CurrentTime_ms);
+ }
+ else if (pstream->stream_state == TCP_NOUSE_STATE && pstream->type == STREAM_TYPE_TCP &&
+ (pstream_pr->set_special_timeout == 0 || sapp_global_val->config.stream.tcp.nouse_set_special_timeout == 0))
+ {
+ timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_closing_timeout * 1000 + g_CurrentTime_ms);
+ }
+ else
+ {
+ long set_timeout = pindex->stream.timeout;
+ if (set_timeout == 0)
+ set_timeout = MAX_DEFALUT_TIMEOUT_S;
+ timeouts_add(plist->streamindex_timer, &pindex->timeout, set_timeout * 1000 + g_CurrentTime_ms);
+ }
+ }
return 0;
}