summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author杨威 <[email protected]>2019-05-24 11:11:37 +0800
committer杨威 <[email protected]>2019-05-24 11:11:37 +0800
commit7aa858405319bbe5ff14d04a52678a278ca9fe55 (patch)
tree037277eae2ca341250ae3433760a59abc74a7bc2
parentdd0e2992df363cc0921e5623930950a0e68adfc3 (diff)
parentcbfa143e269631fb95815d8adb6b350efcc310af (diff)
Merge branch 'pangu_develop_tcp_timeout_reset' into 'pangu_develop_parallel'
Pangu develop tcp timeout reset See merge request MESA_Platform/sapp!13
-rw-r--r--dealpkt/deal_tcp.c59
-rw-r--r--dealpkt/plug_support.c14
-rw-r--r--dealpkt/stream_manage.c6
-rw-r--r--include/stream_inc/stream_control.h9
-rw-r--r--include/stream_internal.h3
-rw-r--r--packet_io/packet_io_pcap.c51
-rw-r--r--run/conf/main.conf2
-rw-r--r--test_so/test_app_sapp.c17
8 files changed, 136 insertions, 25 deletions
diff --git a/dealpkt/deal_tcp.c b/dealpkt/deal_tcp.c
index 4c77606..4960dd8 100644
--- a/dealpkt/deal_tcp.c
+++ b/dealpkt/deal_tcp.c
@@ -1232,10 +1232,12 @@ void tcp_free_stream(struct streamindex *pindex, const void *this_ip_hdr, const
if(pstream_pr->syn_opt_array){
dictator_free(threadnum, pstream_pr->syn_opt_array);
+ pstream_pr->syn_opt_array = NULL;
}
if(pstream_pr->synack_opt_array){
dictator_free(threadnum, pstream_pr->synack_opt_array);
+ pstream_pr->synack_opt_array = NULL;
}
free_streamindex(threadnum,pindex);
@@ -1243,7 +1245,12 @@ void tcp_free_stream(struct streamindex *pindex, const void *this_ip_hdr, const
return;
}
-static void tcp_reset_stream(struct streamindex *pindex,struct mesa_tcp_hdr *this_tcphdr,int datalen)
+/*
+ return value:
+ 1: reset and create new stream;
+ 0: reset but free current stream;
+*/
+static int tcp_reset_stream(struct streamindex *pindex,struct mesa_tcp_hdr *this_tcphdr,int datalen)
{
struct stream_list *plist=NULL;
struct streaminfo_private *pstream_pr=&(pindex->stream);
@@ -1252,6 +1259,7 @@ static void tcp_reset_stream(struct streamindex *pindex,struct mesa_tcp_hdr *thi
struct tcpdetail *pdetail = &pdetail_pr->tcpdetail_public;
UCHAR threadnum = pstream->threadnum;
UCHAR saved_curdir;
+ int ret = 0;
//add by lqy 20150107 ���˼���
if(pstream->curdir==DIR_S2C)
@@ -1314,7 +1322,7 @@ static void tcp_reset_stream(struct streamindex *pindex,struct mesa_tcp_hdr *thi
pstream->opstate=OP_STATE_CLOSE;
stream_process_tcp(pstream,NULL, NULL,NULL,&(pdetail_pr->apme),&(pstream->opstate));
pdetail_pr->apme=NULL;
- }
+ }
if(pdetail_pr->pclient!=NULL)
{
tcp_free_half(pdetail_pr->pclient,threadnum);
@@ -1358,13 +1366,31 @@ static void tcp_reset_stream(struct streamindex *pindex,struct mesa_tcp_hdr *thi
if(this_tcphdr->th_flags & TH_SYN){
tcp_add_new_stream_bysyn(pindex,this_tcphdr,datalen,REUSE_OLD_LINK);
+ ret = 1;
}else{
if(TCP_CTEAT_LINK_BYDATA & tcp_creatlink_model){
tcp_add_new_stream_bydata(pindex,this_tcphdr,datalen,REUSE_OLD_LINK);
+ ret = 1;
+ }else{
+ /* 20190506 lijia add, reset֮�������������, ֱ��free�� */
+ hash_del_stream(pindex);
+ if(pstream->pdetail != NULL)
+ {
+ dictator_free(threadnum,pstream->pdetail);
+ pstream->pdetail=NULL;
+ }
+ if(pstream_pr->timeout > link_default_nopkt_time){ /* ���Ӷ��г�ʱʱ��, ���ټ��� */
+ sapp_global_mthread[threadnum].tcp_stream_special_timeout_num--;
+ }
+ free_heap_stream_info(pstream, 0);
+ free_streamindex(threadnum,pindex);
+ ret = 0;
}
}
g_SysInputInfo[threadnum][SYS_TCP_LINK_RESET]++;
+
+ return ret;
}
@@ -2306,7 +2332,8 @@ static int tcp_deal_nouse_stream(struct streamindex *pindex,const void *this_iph
if((pstream->opstate == OP_STATE_PENDING)
&& (datalen>0)
&& (!(this_tcphdr->th_flags & TH_FIN))
- && (!(this_tcphdr->th_flags & TH_RST)))
+ && (!(this_tcphdr->th_flags & TH_RST))
+ && (TCP_CTEAT_LINK_BYDATA & tcp_creatlink_model))
{
tcp_change_stream_todata(pindex,this_tcphdr,datalen);
return tcp_deal_data_stream(pindex,this_iphdr,raw_pkt,this_tcphdr,datalen);
@@ -2425,21 +2452,21 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s
int try_to_update_addr_info = 0;
pindex_tcp = findstreamindex (pindex, raw_pkt);
if(unlikely(!pindex_tcp)){
- if(this_tcphdr->th_flags & TH_SYN)
+ if(this_tcphdr->th_flags & TH_SYN)
{
//add by yw to detect synflood attack
//if(g_RunSYNFloodDetect == 1)
if (unlikely(TCP_SYNFLOOD_DETECT_ON & tcp_flood_detect_model))
{
if( synflood_detector(pstream->threadnum) == ATTACKING)
- {
- tcp_creatlink_model = TCP_CTEAT_LINK_BYDATA;
+ {
+ tcp_creatlink_model = TCP_CTEAT_LINK_BYDATA;
return PASS;
- }
- else
- {
- tcp_creatlink_model = TCP_CTEAT_LINK_BYSYN;
- }
+ }
+ else
+ {
+ tcp_creatlink_model = TCP_CTEAT_LINK_BYSYN;
+ }
}
//end of add by yw to detect synflood attack
@@ -2513,6 +2540,11 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s
//MESA_kill_tcp(pstream, raw_pkt);
MESA_kill_tcp_remedy(pstream, raw_pkt);
}
+
+ pdetail_pr = (struct tcpdetail_private *)(pindex_tcp->stream.stream_public.pdetail);
+ if(pdetail_pr->tcpall_valid_after_kill != 0){
+ tcp_processallpkt(pstream,this_iphdr,this_tcphdr,tcplen,raw_pkt);
+ }
return DROP;
}
@@ -2573,7 +2605,10 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s
/* note: reset�����ü���, ����clientbytes+=, clientpktnum++����֮�� */
if(1 == lrustream(pindex_tcp)){
- tcp_reset_stream(pindex_tcp, this_tcphdr, tcplen);
+ ret = tcp_reset_stream(pindex_tcp, this_tcphdr, tcplen);
+ if(0 == ret){
+ return PASS;
+ }
}
pdetail->lastmtime=g_CurrentTime;
diff --git a/dealpkt/plug_support.c b/dealpkt/plug_support.c
index d09d5b9..35d2466 100644
--- a/dealpkt/plug_support.c
+++ b/dealpkt/plug_support.c
@@ -361,6 +361,20 @@ int MESA_set_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o
}
break;
+ case MSO_TCPALL_VALID_AFTER_KILL:
+ {
+ if(STREAM_TYPE_TCP != pstream->type){
+ printf("MESA_set_stream_opt() error: stream type is not tcp!\n");
+ ret = -1;
+ break;
+ }
+ unsigned char tcpall_valid = *((unsigned char *)opt_val);
+ struct tcpdetail_private *pdetail_pr = (struct tcpdetail_private*)(pstream->pdetail);
+ pdetail_pr->tcpall_valid_after_kill = (tcpall_valid == 1 ? 1 : 0);
+ ret = 0;
+ }
+ break;
+
default:
printf("MESA_set_stream_opt() error: unsupport MESA_stream_opt type!\n");
ret = -1;
diff --git a/dealpkt/stream_manage.c b/dealpkt/stream_manage.c
index 5bf1524..b95a299 100644
--- a/dealpkt/stream_manage.c
+++ b/dealpkt/stream_manage.c
@@ -44,14 +44,14 @@
extern "C" {
#endif
-int Stream_Analyse_Process_Platform_version_VERSION_20181116; /* nm sapp | grep version */
-int sapp_args_v = 20181116; /* ./sapp -v */
+int Stream_Analyse_Process_Platform_version_VERSION_20190423; /* nm sapp | grep version */
+int sapp_args_v = 20190423; /* ./sapp -v */
/*
����İ汾������packet_io_libУ��, ��ֹƽ̨��dl.so��ƥ�䵼�������쳣, �����޸���BUGδ����.
*/
#if IOMODE_PCAP
-int sapp_packet_io_v = 20180808;
+int sapp_packet_io_v = 20190506;
#elif IOMODE_PAG
int sapp_packet_io_v = 20151106;
#elif IOMODE_PFRING
diff --git a/include/stream_inc/stream_control.h b/include/stream_inc/stream_control.h
index 80993c3..fb92732 100644
--- a/include/stream_inc/stream_control.h
+++ b/include/stream_inc/stream_control.h
@@ -5,7 +5,7 @@
extern "C" {
#endif
-#define STREAM_CONTROL_H_VERSION (20181024)
+#define STREAM_CONTROL_H_VERSION (20190423)
#define TCP_CTEAT_LINK_BYSYN 0x01 /* for MESA_stream_opt->MSO_TCP_CREATE_LINK_MODE */
#define TCP_CTEAT_LINK_BYDATA 0x02 /* for MESA_stream_opt->MSO_TCP_CREATE_LINK_MODE */
@@ -18,10 +18,10 @@ extern "C" {
enum MESA_stream_opt{
__MSO_PAD = 0, /* placeholder */
MSO_MAX_UNORDER = 1, /* opt_val type must be struct max_unorder_opt */
- MSO_NEED_ACK, /* opt_val type must be unsigned char */
- MSO_TAKEOVER, /* opt_val type must be int */
+ MSO_NEED_ACK, /* opt_val type must be unsigned char, value only be [0,1] */
+ MSO_TAKEOVER, /* opt_val type must be int, value only be [0,1] */
MSO_TIMEOUT, /* opt_val type must be unsigned short */
- MSO_IGNORE_RST_FIN, /* opt_val type must be unsigned char */
+ MSO_IGNORE_RST_FIN, /* opt_val type must be unsigned char, value only be [0,1] */
MSO_TCP_CREATE_LINK_MODE, /* opt_val must be unsigned char, refer to TCP_CTEAT_LINK_xxx */
MSO_TCP_ISN_C2S, /* Host-order, opt_val type must be unsigned int */
MSO_TCP_ISN_S2C, /* Host-order, opt_val type must be unsigned int */
@@ -30,6 +30,7 @@ enum MESA_stream_opt{
MSO_STREAM_TUNNEL_TYPE, /* opt_val must be unsigned short, refer to enum stream_carry_tunnel_t */
MSO_STREAM_CLOSE_REASON, /* opt_val type must be unsigned char, refer to stream_close_reason_t */
MSO_STREAM_VXLAN_INFO, /* opt_val type must be struct vxlan_info */
+ MSO_TCPALL_VALID_AFTER_KILL, /* opt_val type must be unsigned char, value only be [0,1] */
__MSO_MAX,
};
diff --git a/include/stream_internal.h b/include/stream_internal.h
index c2dc5af..de383e8 100644
--- a/include/stream_internal.h
+++ b/include/stream_internal.h
@@ -170,7 +170,8 @@ struct tcpdetail_private
/* ---8 bytes-- */
UCHAR multisynflag:2; // multi syn
- UCHAR ignore_rst_fin:2;//������rst, fin����, ֻ����ʱ��lru����
+ UCHAR ignore_rst_fin:1; //������rst, fin����, ֻ����ʱ��lru����
+ UCHAR tcpall_valid_after_kill:1; //kill_tcp��, TCPALL�����Ȼ��Ч, ���������������ݰ�
UCHAR needackflag:2; //��Ҫ�ϴ�ack����
UCHAR takeoverflag:2;
UCHAR tcpstateflag; // ���ڼ�¼tcp�ĻỰSYN���״̬
diff --git a/packet_io/packet_io_pcap.c b/packet_io/packet_io_pcap.c
index 6b5f56f..f45a39d 100644
--- a/packet_io/packet_io_pcap.c
+++ b/packet_io/packet_io_pcap.c
@@ -2,6 +2,7 @@
extern "C" {
#endif
+#include "MESA_prof_load.h"
#include "stream_internal.h"
#include "packet_io.h"
#include "packet_io_internal.h"
@@ -22,8 +23,8 @@ extern "C" {
#define PROCESS_BAR_SW (1)
-int g_pcap_version_VERSION_20180808;
-static int g_pcap_version_internal = 20180808;
+int g_pcap_version_VERSION_20190506;
+static int g_pcap_version_internal = 20190506;
#define PCAP_SNAPLEN_MAX (65535)
@@ -125,6 +126,20 @@ static unsigned long dumpfile_read_size = 0;
static unsigned long dump_times;
static char process_bar[100][101];
static unsigned long PKTps = 500000;
+static int dumpfile_according_timestamp = 0;
+static long long dumpfile_timestamp_diff_with_start = 0; /* ��ǰ��������ʱ�����յ���һ������ʱ����IJ�ֵ */
+
+static long long __get_current_time_in_ms(void)
+{
+ struct timeval t;
+ long long tms;
+
+ gettimeofday(&t, NULL);
+
+ tms = t.tv_sec * 1000 + t.tv_usec/1000;
+
+ return tms;
+}
static unsigned long __get_file_length(const char *file_name)
{
@@ -656,6 +671,21 @@ static inline int pcap_raw_pkt_check(const struct pcap_pkthdr *hdr, u_char *user
}
+static void dumpfile_wait_according_timestamp(const struct pcap_pkthdr *hdr)
+{
+ long long cur_time_ms;
+ long long pkt_time_ms;
+
+ pkt_time_ms = hdr->ts.tv_sec * 1000 + hdr->ts.tv_usec / 1000;
+ cur_time_ms = __get_current_time_in_ms() - dumpfile_timestamp_diff_with_start;
+
+ while(pkt_time_ms > cur_time_ms){
+ usleep(100);
+ cur_time_ms = __get_current_time_in_ms() - dumpfile_timestamp_diff_with_start;
+ }
+}
+
+
static void __pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data)
{
pkt_queue_t pkt_queue_node;
@@ -669,12 +699,19 @@ static void __pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const
thread_num = __pcap_dispatch_thread(data);
-#if PROCESS_BAR_SW
if(CAP_MODEL_PCAP_DUMPFILE == g_pcap_cap_mode){
+#if PROCESS_BAR_SW
process_bar_print(hdr->caplen);
+#endif
+ if((dumpfile_according_timestamp != 0)){
+ if(0 == dumpfile_timestamp_diff_with_start){ /* first time */
+ dumpfile_timestamp_diff_with_start = __get_current_time_in_ms() - (hdr->ts.tv_sec * 1000 + hdr->ts.tv_usec / 1000);
+ }
+
+ dumpfile_wait_according_timestamp(hdr);
+ }
}
-#endif
#if 0
retry:
@@ -1098,6 +1135,7 @@ int dl_io_init(int argc, char *argv[])
{
char pcap_errbuf[PCAP_ERRBUF_SIZE];
int opt_len;
+ char cfg_buf[256];
#if PCAP_CAP_FROM_IP
printf("\033[41m Warning! 'PCAP_CAP_FROM_IP' is enable!. \033[0m\n");
@@ -1178,6 +1216,11 @@ int dl_io_init(int argc, char *argv[])
dispatch_thread_rnd_num = rand();
+ MESA_load_profile_string_def("conf/main.conf", "Module", "dumpfile_speed", cfg_buf, sizeof(cfg_buf), "topspeed");
+ if(strncasecmp(cfg_buf, "timestamp", strlen("timestamp")) == 0){
+ dumpfile_according_timestamp = 1;
+ }
+
return 0;
}
diff --git a/run/conf/main.conf b/run/conf/main.conf
index b9b832f..ab31134 100644
--- a/run/conf/main.conf
+++ b/run/conf/main.conf
@@ -104,7 +104,7 @@ pkt_dump_switch=1
pkt_dump_mode=2
pkt_dump_cmd_port=12345
pkt_dump_bpf_filter=
-
+pkt_dump_file_root_dir=
#config 'pkt_dump_total_size' means summation of all files size in 'root_dir', unit:MB.
pkt_dump_total_size=29900
diff --git a/test_so/test_app_sapp.c b/test_so/test_app_sapp.c
index 74d5af8..bc7f644 100644
--- a/test_so/test_app_sapp.c
+++ b/test_so/test_app_sapp.c
@@ -648,6 +648,7 @@ test_set_stream_timeout(pstream, pme, thread_seq, a_packet);
}
static int test_tcpall_flow_id = -1;
+
char testtcpApp_allpkt(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet)
{
struct tcpdetail *pdetail=(struct tcpdetail *)pstream->pdetail;
@@ -721,6 +722,22 @@ char testtcpApp_allpkt(struct streaminfo *pstream,void **pme, int thread_seq,voi
}
return APP_STATE_GIVEME;
}
+
+char tcpall_valid_after_kill(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet)
+{
+ unsigned char mopt = 1;
+
+ MESA_kill_tcp(pstream, a_packet);
+
+ if(pstream->pktstate== OP_STATE_PENDING){
+ if(MESA_set_stream_opt(pstream, MSO_TCPALL_VALID_AFTER_KILL, &mopt, sizeof(mopt)) < 0){
+ abort();
+ }
+ }
+
+ return testtcpApp_allpkt(pstream, pme, thread_seq, a_packet);
+}
+
struct stream_static
{
int pktnum;