diff options
| author | 杨威 <[email protected]> | 2023-01-11 20:07:56 +0800 |
|---|---|---|
| committer | 杨威 <[email protected]> | 2023-01-16 14:42:17 +0800 |
| commit | f6b17b84ed61198eeb5114e4462d0705f04d9865 (patch) | |
| tree | b7d13e4472f64c65e5762cff3de6fba107e8eae6 | |
| parent | 660247773e03be49b107dbe8c58197bc14549edf (diff) | |
🌈 style(deal_tcp.c): reduce linter warning
| -rw-r--r-- | include/public/stream_inc/stream_entry.h | 1 | ||||
| -rw-r--r-- | src/dealpkt/callapp.c | 14 | ||||
| -rw-r--r-- | src/dealpkt/deal_tcp.c | 230 | ||||
| -rw-r--r-- | src/packet_io/packet_io_pcap.c | 57 | ||||
| -rw-r--r-- | src/plugin/src/plugin.c | 251 | ||||
| -rw-r--r-- | src/project/project_requirement.c | 9 | ||||
| -rw-r--r-- | src/project/stream_id.c | 179 | ||||
| -rw-r--r-- | src/sapp_dev/sapp_init.c | 12 | ||||
| -rw-r--r-- | src/support/tomlc99_wrap/tomlc99_wrap.c | 3 | ||||
| -rw-r--r-- | src/support/tomlc99_wrap/tomlc99_wrap.h | 1 | ||||
| -rw-r--r-- | test/test_app_sapp.c | 128 |
11 files changed, 219 insertions, 666 deletions
diff --git a/include/public/stream_inc/stream_entry.h b/include/public/stream_inc/stream_entry.h index 9fda956..7fd7522 100644 --- a/include/public/stream_inc/stream_entry.h +++ b/include/public/stream_inc/stream_entry.h @@ -33,6 +33,7 @@ typedef struct _plugin_session_info extern "C" { #endif +struct streaminfo; typedef char (*STREAM_CB_FUN_T)(const struct streaminfo *pstream,void **pme, int thread_seq,const void *ip_hdr); typedef char (*IPv4_CB_FUN_T)(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *ipv4_hdr); diff --git a/src/dealpkt/callapp.c b/src/dealpkt/callapp.c index ec850a5..d1b26da 100644 --- a/src/dealpkt/callapp.c +++ b/src/dealpkt/callapp.c @@ -350,12 +350,6 @@ char plugin_call_ipentry(int type,IPv4_CB_FUN_T stream_fun,SAPP_PKT_CB_FUN_T sap {
char rec;
-#if 0
- if(g_business_plug_info!=NULL)
- {
- plug_record_start_time(g_business_plug_info->plugid, thread_num);
- }
-#endif
if(type==CALL_FUN_TYPE_RAW)
{
rec=stream_fun(pfstream,routedir,thread_num,this_layer_hdr);
@@ -364,14 +358,6 @@ char plugin_call_ipentry(int type,IPv4_CB_FUN_T stream_fun,SAPP_PKT_CB_FUN_T sap {
rec=sapp_fun(pfstream,this_layer_hdr,raw_pkt);
}
-#if 0
- if(g_business_plug_info!=NULL)
- {
- plug_record_end_time(g_business_plug_info->plugid, thread_num);
-
- }
-#endif
-
return rec;
}
diff --git a/src/dealpkt/deal_tcp.c b/src/dealpkt/deal_tcp.c index 05d7187..b3a1bfc 100644 --- a/src/dealpkt/deal_tcp.c +++ b/src/dealpkt/deal_tcp.c @@ -1612,131 +1612,129 @@ static int tcp_deal_syn_stream(struct streamindex *pindex,const raw_pkt_t *raw_p int thisseq=ntohl (this_tcphdr->th_seq); int thisack=ntohl (this_tcphdr->th_ack); - if(pstream->dir==DIR_C2S) - { - curseq=pdetail_pr->iserverseq; - if(curdir==DIR_S2C) - { - if((this_tcphdr->th_flags & TH_RST)&&(datalen==0)) - { - if(thisack==curseq) - { - pstream->dir=DIR_DOUBLE; /* ����dir */ - pdetail_pr->link_state=STREAM_LINK_RESET; - tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); - return PASS; - } - } - else - //������������������ - if(thisack==curseq) - { - pstream->dir=DIR_DOUBLE; - if(this_tcphdr->th_flags & TH_SYN) - pdetail_pr->iclientseq=thisseq+1; - else - pdetail_pr->iclientseq=thisseq; - if(this_tcphdr->th_flags == (TH_SYN|TH_ACK)){ - pdetail_pr->tcpstateflag=TCP_SYN_RECV; - tcp_parse_opts(pstream_pr, DIR_S2C, (const struct tcphdr *)this_tcphdr); /* 2016-07-07 lijia add, for janus hijack */ - } - return PASS; - } - - } - else //ͬ������ - { - //������ - if(thisseq==curseq) - { - if((this_tcphdr->th_flags & TH_RST)&&(datalen==0)) - { - pdetail_pr->link_state=STREAM_LINK_RESET; - tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); - return PASS; - } - //add by lqy 20130802 �����������������е������� - //�������ڶ���ack - else if((this_tcphdr->th_flags == TH_ACK)&&(datalen==0)) - { - pdetail_pr->tcpstateflag=TCP_SYN_RECV; - return PASS; - } - else - { - //if(TCP_SYN_SENT==pdetail_pr->tcpstateflag ){ - //return DROP; - return PASS; //2014-12-05 lijia modify, for xj serial - //} - } - //end add by lqy 20130802 - } - } - } - else if (pstream->dir == DIR_S2C) - { - curseq=pdetail_pr->iclientseq; - - if(curdir==DIR_C2S) - { - if((this_tcphdr->th_flags & TH_RST)&&(datalen==0)) - { - pstream->dir=DIR_DOUBLE; /* ����dir */ - pdetail_pr->link_state=STREAM_LINK_RESET; - tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); - return PASS; - } - else - { - pstream->dir=DIR_DOUBLE; - if(this_tcphdr->th_flags & TH_SYN) - pdetail_pr->iserverseq=thisseq+1; - else - pdetail_pr->iserverseq=thisseq; - return PASS; - } - } - else //ͬ������ - { - //����rst - if((thisseq==curseq) - &&(this_tcphdr->th_flags & TH_RST) - &&(datalen==0)) - - { - pdetail_pr->link_state=STREAM_LINK_RESET; - tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); - return PASS; - } - } + if (pstream->dir == DIR_C2S) + { + curseq = pdetail_pr->iserverseq; + if (curdir == DIR_S2C) + { + if ((this_tcphdr->th_flags & TH_RST) && (datalen == 0)) + { + if (thisack == curseq) + { + pstream->dir = DIR_DOUBLE; /* ����dir */ + pdetail_pr->link_state = STREAM_LINK_RESET; + tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); + return PASS; + } + } + else + //������������������ + if (thisack == curseq) + { + pstream->dir = DIR_DOUBLE; + if (this_tcphdr->th_flags & TH_SYN) + pdetail_pr->iclientseq = thisseq + 1; + else + pdetail_pr->iclientseq = thisseq; + if (this_tcphdr->th_flags == (TH_SYN | TH_ACK)) + { + pdetail_pr->tcpstateflag = TCP_SYN_RECV; + tcp_parse_opts(pstream_pr, DIR_S2C, + (const struct tcphdr *)this_tcphdr); /* 2016-07-07 lijia add, for janus hijack */ + } + return PASS; + } + } + else //ͬ������ + { + //������ + if (thisseq == curseq) + { + if ((this_tcphdr->th_flags & TH_RST) && (datalen == 0)) + { + pdetail_pr->link_state = STREAM_LINK_RESET; + tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); + return PASS; + } + // add by lqy 20130802 �����������������е������� + //�������ڶ���ack + else if ((this_tcphdr->th_flags == TH_ACK) && (datalen == 0)) + { + pdetail_pr->tcpstateflag = TCP_SYN_RECV; + return PASS; + } + else + { + // if(TCP_SYN_SENT==pdetail_pr->tcpstateflag ){ + // return DROP; + return PASS; // 2014-12-05 lijia modify, for xj serial + //} + } + // end add by lqy 20130802 + } + } + } + else if (pstream->dir == DIR_S2C) + { + curseq = pdetail_pr->iclientseq; - } - //add by lqy 20130805 ˫�����������������������data�� - else if( pstream->dir == DIR_DOUBLE) - { - if((pdetail_pr->tcpstateflag==TCP_SYN_RECV)&&(curdir==DIR_C2S)) - { - if((this_tcphdr->th_flags == TH_ACK)&&(datalen==0)) - { - pdetail_pr->tcpstateflag=TCP_ESTABLISHED; - tcp_change_stream_todata(pindex,this_tcphdr,0); - } - } - } - //syn�ش� + if (curdir == DIR_C2S) + { + if ((this_tcphdr->th_flags & TH_RST) && (datalen == 0)) + { + pstream->dir = DIR_DOUBLE; /* ����dir */ + pdetail_pr->link_state = STREAM_LINK_RESET; + tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); + return PASS; + } + else + { + pstream->dir = DIR_DOUBLE; + if (this_tcphdr->th_flags & TH_SYN) + pdetail_pr->iserverseq = thisseq + 1; + else + pdetail_pr->iserverseq = thisseq; + return PASS; + } + } + else //ͬ������ + { + //����rst + if ((thisseq == curseq) && (this_tcphdr->th_flags & TH_RST) && (datalen == 0)) + + { + pdetail_pr->link_state = STREAM_LINK_RESET; + tcp_free_stream(pindex, this_iphdr, this_tcphdr, raw_pkt); + return PASS; + } + } + } + // add by lqy 20130805 ˫�����������������������data�� + else if (pstream->dir == DIR_DOUBLE) + { + if ((pdetail_pr->tcpstateflag == TCP_SYN_RECV) && (curdir == DIR_C2S)) + { + if ((this_tcphdr->th_flags == TH_ACK) && (datalen == 0)) + { + pdetail_pr->tcpstateflag = TCP_ESTABLISHED; + tcp_change_stream_todata(pindex, this_tcphdr, 0); + } + } + } + //syn�ش� /* TODO, ��Ԫ����ͬ������SYN��, ��Ҫ��һ���ж�SEQ�Ƿ�һ�²������ش�, ��������Ԫ������, ��Ҫreset. */ - if((this_tcphdr->th_flags == TH_SYN)) + if(this_tcphdr->th_flags == TH_SYN) { pdetail_pr->iserverseq=thisseq + 1; pdetail_pr->multisynflag=1; pdetail_pr->tcpstateflag=TCP_SYN_SENT; } - if((this_tcphdr->th_flags == (TH_SYN|TH_ACK))) + if(this_tcphdr->th_flags == (TH_SYN|TH_ACK)) { pdetail_pr->iclientseq=thisseq+1; pdetail_pr->multisynflag=1; @@ -1809,7 +1807,9 @@ static int tcp_deal_ack(struct streaminfo *a_tcp,struct mesa_tcp_hdr *this_tcphd //add by lqy 20150210 if((this_tcphdr->th_flags & TH_SYN) && (this_tcphdr->th_flags & TH_ACK)) - phalf->first_data_seq+=1; + { + phalf->first_data_seq+=1; + } pdetail_pr->S2C_ack_seq = ntohl (this_tcphdr->th_ack); phalf->window = ntohs (this_tcphdr->th_win); @@ -3485,7 +3485,7 @@ static struct buf_unorder *tcp_save_unorder_pkt(struct streaminfo *a_tcp,const v �����İ�, ��ǰ��ͷ��ԭʼ��ͷ�ĵ�ַƫ�����϶���MTU��Χ��, ���������MTU, ��ǰIP���϶�����malloc��, ����Ƭ����İ�. */ - if(abs((char *)this_iphdr - (char *)stack_raw_pkt->raw_pkt_data) > MTU_MAX){ + if(labs((char *)this_iphdr - (char *)stack_raw_pkt->raw_pkt_data) > MTU_MAX){ #endif uo_packet->ip_reassemble_pkt = 1; this_ip_tot_len = get_ip_pkt_tot_len(carry_ip_stream, this_iphdr); diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c index a62493f..3d5f8ae 100644 --- a/src/packet_io/packet_io_pcap.c +++ b/src/packet_io/packet_io_pcap.c @@ -8,6 +8,8 @@ extern "C" { #include <pcap/pcap.h>
#include <sys/types.h>
+#include "tomlc99_wrap.h"
+
#define PROCESS_BAR_SW (1)
@@ -386,29 +388,31 @@ static int sendpacket_tcp_offload(char *raw_data, int raw_datalen, int fd, const send_again:
ret = sendto(fd, tmp_send_buf, this_send_len+fix_hdr_len, 0, (struct sockaddr *)sa, sizeof(struct sockaddr));
- if(ret < 0){
- local_errno = errno;
- if((EAGAIN == local_errno)
- || (EINTR == local_errno)
- || (EWOULDBLOCK==local_errno)
- || (ENOBUFS==local_errno)
- || (ENOMEM==local_errno))
- {
- if(retry_times++ < 3){
- sapp_usleep(1);
- goto send_again;
- }else{
- sapp_runtime_log(RLOG_LV_FATAL,"sendpacket","retry more than %d times, %s\n", retry_times, strerror(local_errno));
- return -1;
- }
- }
- else
- {
- sapp_runtime_log(RLOG_LV_FATAL,"sendpacket","%s\n", strerror(local_errno));
- return -1;
- }
- }
- data += this_send_len;
+ if (ret < 0)
+ {
+ local_errno = errno;
+ if ((EAGAIN == local_errno) || (EINTR == local_errno) || (EWOULDBLOCK == local_errno) ||
+ (ENOBUFS == local_errno) || (ENOMEM == local_errno))
+ {
+ if (retry_times++ < 3)
+ {
+ sapp_usleep(1);
+ goto send_again;
+ }
+ else
+ {
+ sapp_runtime_log(RLOG_LV_FATAL, "sendpacket", "retry more than %d times, %s\n", retry_times,
+ strerror(local_errno));
+ return -1;
+ }
+ }
+ else
+ {
+ sapp_runtime_log(RLOG_LV_FATAL, "sendpacket", "%s\n", strerror(local_errno));
+ return -1;
+ }
+ }
+ data += this_send_len;
leftlen -= this_send_len;
send_seq += this_send_len;
}
@@ -703,7 +707,7 @@ int pcap_dl_io_low_level_send(void *phandle, UINT8 *data,int datalen, /* delete by lijia 2014-12-10, datalen�Ѿ�������mac��ַ���� */
//datalen += sizeof(struct mesa_ethernet_hdr);
- packet_io_hook_sendto(raw_pkt, dir, data, NULL);
+ packet_io_hook_sendto(raw_pkt, dir, (char *)data, NULL);
send_again:
ret = sendto(send_handle->raw_eth_fd, data, datalen, 0, (struct sockaddr *)snd_addr, sizeof(struct sockaddr));
@@ -822,6 +826,8 @@ static void pcap_clear_pkt_queue_left(int thread_index) }
}
+extern void libsapp_destroy_env_per_thread(int tseq);
+
static void *__pcap_work_thread(void *arg)
{
int thread_num = (int)(*((short *)arg));
@@ -929,7 +935,6 @@ static void *__pcap_work_thread(void *arg) sapp_runtime_log(RLOG_LV_INFO, "pcap work thread:%d, TID:%ld, thread exited", thread_num, sapp_global_val->individual_fixed.thread_tid[thread_num]);
-exit:
return NULL;
}
@@ -1050,7 +1055,7 @@ static unsigned int __pcap_dispatch_thread(const u_char *data) disp:
//hash = pcap_dispatch_hash(disp_arg1, disp_arg2, 0xFEEDBEAF);
- hash = dpdk_rte_crc_hash(disp_arg1, disp_arg2, disp_addrlen, 0);
+ hash = dpdk_rte_crc_hash((char *)disp_arg1, (char *)disp_arg2, disp_addrlen, 0);
hash %= g_pcap_work_thread_num;
return hash;
diff --git a/src/plugin/src/plugin.c b/src/plugin/src/plugin.c index aff797b..98fb668 100644 --- a/src/plugin/src/plugin.c +++ b/src/plugin/src/plugin.c @@ -947,257 +947,6 @@ int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname) } return 0; - - -/* - IPv4_CB_FUN_T ip_entry; - IPv6_CB_FUN_T ip_entry_v6; - SAPP_PKT_CB_FUN_T ipv4_raw; - SAPP_PKT_CB_FUN_T ipv6_raw; - STREAM_CB_FUN_T tcp_entry; - STREAM_CB_FUN_T tcp_entry_all; - STREAM_CB_FUN_T udp_entry; - - - //IPV_ENTRY - MESA_load_profile_string_nodef(filename,SECTION_FUN_IP,KEYWORD_FUNFLAG,buf_funflag,PLUGIN_MAX_CONFLEN); - if((buf_funflag[0] != '\0') && ((memcmp(buf_funflag,FUNFLAG_ALL_B,strlen(FUNFLAG_ALL_B)) == 0) || (memcmp(buf_funflag,FUNFLAG_ALL_S,strlen(FUNFLAG_ALL_S)) == 0))) - { - MESA_load_profile_string_nodef(filename,SECTION_FUN_IP,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN); - if(buf_funname == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s\n",filename,SECTION_FUN_IP,KEYWORD_FUNFLAG,KEYWORD_FUNNAME); - return -1; - } - - ip_entry = (char(*)(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *raw_pkt))(dlsym(fp_dlopen,buf_funname)); - if(ip_entry == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile\n",filename,SECTION_FUN_IP,buf_funname,plugname); - return -1; - } - - ret=stream_register_ip(ip_entry); - if(ret==-1) - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register_ip %s entry err!\n",filename,SECTION_FUN_IP); - } - else - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s load %s entry succ!\n",filename,SECTION_FUN_IP); - } - - } - - //IPV6_ENTRY - memset(buf_funflag,0,PLUGIN_MAX_CONFLEN); - memset(buf_funname,0,PLUGIN_MAX_CONFLEN); - - MESA_load_profile_string_nodef(filename,SECTION_FUN_IPV6,KEYWORD_FUNFLAG,buf_funflag,PLUGIN_MAX_CONFLEN); - if((buf_funflag[0] != '\0') && ((memcmp(buf_funflag,FUNFLAG_ALL_B,strlen(FUNFLAG_ALL_B)) == 0) || (memcmp(buf_funflag,FUNFLAG_ALL_S,strlen(FUNFLAG_ALL_S)) == 0))) - { - MESA_load_profile_string_nodef(filename,SECTION_FUN_IPV6,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN); - if(buf_funname == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s\n",filename,SECTION_FUN_IPV6,KEYWORD_FUNFLAG,KEYWORD_FUNNAME); - return -1; - } - - ip_entry_v6= (char(*)(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *raw_pkt))(dlsym(fp_dlopen,buf_funname)); - if(ip_entry_v6 == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile\n",filename,SECTION_FUN_IPV6,buf_funname,plugname); - return -1; - } - - ret=stream_register_ipv6(ip_entry_v6); - if(ret==-1) - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register_ipv6 %s entry err!\n",filename,SECTION_FUN_IPV6); - } - else - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s load %s entry succ!\n",filename,SECTION_FUN_IPV6); - } - } - - //IPV4_RAW_ENTRY - MESA_load_profile_string_nodef(filename,SECTION_FUN_IPV4_RAW,KEYWORD_FUNFLAG,buf_funflag,PLUGIN_MAX_CONFLEN); - if((buf_funflag[0] != '\0') && ((memcmp(buf_funflag,FUNFLAG_ALL_B,strlen(FUNFLAG_ALL_B)) == 0) || (memcmp(buf_funflag,FUNFLAG_ALL_S,strlen(FUNFLAG_ALL_S)) == 0))) - { - MESA_load_profile_string_nodef(filename,SECTION_FUN_IPV4_RAW,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN); - if(buf_funname == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s\n",filename,SECTION_FUN_IPV4_RAW,KEYWORD_FUNFLAG,KEYWORD_FUNNAME); - return -1; - } - - ipv4_raw = (SAPP_PKT_CB_FUN_T)(dlsym(fp_dlopen,buf_funname)); - if(ipv4_raw == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile\n",filename,SECTION_FUN_IPV4_RAW,buf_funname,plugname); - return -1; - } - - ret=stream_register_ip_raw(ipv4_raw); - if(ret==-1) - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register_ip_raw %s entry err!\n",filename,SECTION_FUN_IPV4_RAW); - } - else - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s load %s entry succ!\n",filename,SECTION_FUN_IPV4_RAW); - } - - - - } - - //IPV6_RAW_ENTRY - memset(buf_funflag,0,PLUGIN_MAX_CONFLEN); - memset(buf_funname,0,PLUGIN_MAX_CONFLEN); - - MESA_load_profile_string_nodef(filename,SECTION_FUN_IPV6_RAW,KEYWORD_FUNFLAG,buf_funflag,PLUGIN_MAX_CONFLEN); - if((buf_funflag[0] != '\0') && ((memcmp(buf_funflag,FUNFLAG_ALL_B,strlen(FUNFLAG_ALL_B)) == 0) || (memcmp(buf_funflag,FUNFLAG_ALL_S,strlen(FUNFLAG_ALL_S)) == 0))) - { - MESA_load_profile_string_nodef(filename,SECTION_FUN_IPV6_RAW,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN); - if(buf_funname == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s\n",filename,SECTION_FUN_IPV6_RAW,KEYWORD_FUNFLAG,KEYWORD_FUNNAME); - return -1; - } - - ipv6_raw= (SAPP_PKT_CB_FUN_T)(dlsym(fp_dlopen,buf_funname)); - if(ipv6_raw == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile\n",filename,SECTION_FUN_IPV6_RAW,buf_funname,plugname); - return -1; - } - - ret=stream_register_ipv6_raw(ipv6_raw); - if(ret==-1) - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register_ipv6_raw %s entry err!\n",filename,SECTION_FUN_IPV6_RAW); - } - else - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s load %s entry succ!\n",filename,SECTION_FUN_IPV6_RAW); - } - - - - } - - - //TCP_ENTRY - memset(buf_funflag,0,PLUGIN_MAX_CONFLEN); - memset(buf_funname,0,PLUGIN_MAX_CONFLEN); - - MESA_load_profile_string_nodef(filename,SECTION_FUN_TCP,KEYWORD_FUNFLAG,buf_funflag,PLUGIN_MAX_CONFLEN); - if((buf_funflag[0] != '\0') && ((memcmp(buf_funflag,FUNFLAG_ALL_B,strlen(FUNFLAG_ALL_B)) == 0) || (memcmp(buf_funflag,FUNFLAG_ALL_S,strlen(FUNFLAG_ALL_S)) == 0))) - { - MESA_load_profile_string_nodef(filename,SECTION_FUN_TCP,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN); - if(buf_funname == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s\n",filename,SECTION_FUN_TCP,KEYWORD_FUNFLAG,KEYWORD_FUNNAME); - return -1; - } - - tcp_entry = (char(*)(const struct streaminfo *pstream,void **pme, int thread_seq,const void *raw_pkt))(dlsym(fp_dlopen,buf_funname)); - if(tcp_entry == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile\n",filename,SECTION_FUN_TCP,buf_funname,plugname); - return -1; - } - - ret=stream_register_tcp(tcp_entry); - if(ret==-1) - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register_tcp %s entry err!\n",filename,SECTION_FUN_TCP); - } - else - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s load %s entry succ!\n",filename,SECTION_FUN_TCP); - } - - - - - } - - //TCP_ENTRY_ALL - memset(buf_funflag,0,PLUGIN_MAX_CONFLEN); - memset(buf_funname,0,PLUGIN_MAX_CONFLEN); - - MESA_load_profile_string_nodef(filename,SECTION_FUN_TCP_ALL,KEYWORD_FUNFLAG,buf_funflag,PLUGIN_MAX_CONFLEN); - if((buf_funflag[0] != '\0') && ((memcmp(buf_funflag,FUNFLAG_ALL_B,strlen(FUNFLAG_ALL_B)) == 0) || (memcmp(buf_funflag,FUNFLAG_ALL_S,strlen(FUNFLAG_ALL_S)) == 0))) - { - MESA_load_profile_string_nodef(filename,SECTION_FUN_TCP_ALL,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN); - if(buf_funname == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s\n",filename,SECTION_FUN_TCP_ALL,KEYWORD_FUNFLAG,KEYWORD_FUNNAME); - return -1; - } - - tcp_entry_all= (char(*)(const struct streaminfo *pstream,void **pme, int thread_seq,const void *raw_pkt))(dlsym(fp_dlopen,buf_funname)); - if(tcp_entry_all == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile\n",filename,SECTION_FUN_TCP_ALL,buf_funname,plugname); - return -1; - } - - ret=stream_register_tcp_allpkt(tcp_entry_all); - if(ret==-1) - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register_tcp_allpkt %s entry err!\n",filename,SECTION_FUN_TCP_ALL); - } - else - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s load %s entry succ!\n",filename,SECTION_FUN_TCP_ALL); - } - - - - } - - //UDP_ENTRY - memset(buf_funflag,0,PLUGIN_MAX_CONFLEN); - memset(buf_funname,0,PLUGIN_MAX_CONFLEN); - - MESA_load_profile_string_nodef(filename,SECTION_FUN_UDP,KEYWORD_FUNFLAG,buf_funflag,PLUGIN_MAX_CONFLEN); - if((buf_funflag[0] != '\0') && ((memcmp(buf_funflag,FUNFLAG_ALL_B,strlen(FUNFLAG_ALL_B)) == 0) || (memcmp(buf_funflag,FUNFLAG_ALL_S,strlen(FUNFLAG_ALL_S)) == 0))) - { - MESA_load_profile_string_nodef(filename,SECTION_FUN_UDP,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN); - if(buf_funname == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s\n",filename,SECTION_FUN_UDP,KEYWORD_FUNFLAG,KEYWORD_FUNNAME); - return -1; - } - - - udp_entry = (char(*)(const struct streaminfo *pstream,void **pme, int thread_seq,const void *raw_pkt))(dlsym(fp_dlopen,buf_funname)); - if(udp_entry == NULL) - { - runtime_log(RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile\n",filename,SECTION_FUN_UDP,buf_funname,plugname); - return -1; - } - - ret=stream_register_udp(udp_entry); - if(ret==-1) - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register_tcp_allpkt %s entry err!\n",filename,SECTION_FUN_UDP); - } - else - { - runtime_log(RLOG_LV_INFO, PLUGIN_LOGNAME,"%s load %s entry succ!\n",filename,SECTION_FUN_UDP); - } - - - - } -*/ - - } /**************************************************************************** diff --git a/src/project/project_requirement.c b/src/project/project_requirement.c index 9137cc7..349d523 100644 --- a/src/project/project_requirement.c +++ b/src/project/project_requirement.c @@ -120,7 +120,7 @@ static int project_platform_register(const char *project_req_name, enum pro_type sapp_runtime_log(30, "project_platform_register (%s) FAIL: Empty G_PROJECT_NAME_HASH or Invalid pro_type(%d)", project_req_name, type);
return -1;
}
- int *project_id = (int *)MESA_htable_search(G_PROJECT_NAME_HASH, project_req_name, strlen(project_req_name));
+ int *project_id = (int *)MESA_htable_search(G_PROJECT_NAME_HASH, (const unsigned char *)project_req_name, strlen(project_req_name));
if (project_id != NULL)
{
sapp_runtime_log(30, "project_platform_register (%s) DUPLICATE, exist project_id %d", project_req_name, *project_id);
@@ -141,7 +141,7 @@ static int project_platform_register(const char *project_req_name, enum pro_type G_PROJECT_REQ_MANAGE[G_PROJECT_PLUG_NUM].project_req_type = type;
project_id = (int *)calloc(sizeof(int), 1);
*project_id = pid;
- MESA_htable_add(G_PROJECT_NAME_HASH, project_req_name, strlen(project_req_name), (const void *)project_id);
+ MESA_htable_add(G_PROJECT_NAME_HASH, (const unsigned char*)project_req_name, strlen(project_req_name), (const void *)project_id);
G_PROJECT_PLUG_NUM++;
sapp_runtime_log(20, "project_platform_register (%s) SUCCEED, project_id return %d", project_req_name, pid);
return pid;
@@ -379,11 +379,6 @@ static long long __project_req_get(const struct streaminfo *stream, int project_ pinfo = (project_req_info_t *)(stream_pr->pproject);
- if(NULL == pinfo){
- sapp_runtime_log(RLOG_LV_FATAL, "project get error, id=%d, pproject is NULL!", project_req_id);
- return -1;
- }
-
if(0 == pinfo[project_req_id].valid_flag){ /* ������δ���ù�, ����-1������errno */
errno = ERANGE;
return -1;
diff --git a/src/project/stream_id.c b/src/project/stream_id.c deleted file mode 100644 index 29fd80b..0000000 --- a/src/project/stream_id.c +++ /dev/null @@ -1,179 +0,0 @@ -#ifdef __cplusplus
-extern "C" {
-#endif
-#include "sapp_api.h"
-#include "sapp_private_api.h"
-
-#define STREAMNUM_FILE_NAME "./conf/streamid.txt"
-
-static unsigned int g_stream_num = 0;
-static unsigned int g_old_stream_num = 0;
-static unsigned short g_papp_machineid = 0;
-static pthread_mutex_t g_stream_num_mutex;
-
-static int g_stream_id_switch = PROJECT_MODULE_DISABLE;
-
-static int set_stream_id(unsigned long *p_stream_id)
-{
- unsigned long stream_id;
- int stream_num;
-
- if(PROJECT_MODULE_DISABLE == g_stream_id_switch){
- return -1;
- }
-
- pthread_mutex_lock(&g_stream_num_mutex);
-
- g_stream_num ++;
- stream_num = g_stream_num;
-
- pthread_mutex_unlock(&g_stream_num_mutex);
-
- stream_id = (unsigned long)g_papp_machineid+(unsigned long)(0xffffffff)+stream_num;
-
- *p_stream_id = stream_id;
-
- // printf("papp:stream_id:%lu\n",stream_id);
-
- return 0;
-}
-
-
-unsigned long get_stream_id(struct streaminfo *stream)
-{
- void **p_private;
- unsigned long *p_stream_id;
-
- if(PROJECT_MODULE_DISABLE == g_stream_id_switch){
- printf("stream_id moudle is disabled!\n");
- assert(0);
- return -1;
- }
-
- p_private = project_get_private_info(stream->pproject, PROGECT_REQUIREMENT_STREAM_ID);
- if(NULL == p_private){
- printf("stream_id moudle error, no mem space!\n");
- assert(0);
- return -1;
- }
-
- p_stream_id = (unsigned long *)(*p_private);
-
- return *p_stream_id;
-}
-
-static void *update_streamnum_thread(void *art)
-{
- FILE* fp;
-
- while(1)
- {
- fp = fopen(STREAMNUM_FILE_NAME,"w+");
- if(fp == NULL)
- {
- continue;
- }
-
- if((g_stream_num-g_old_stream_num) > 1000)
- {
- fprintf(fp,"%d\n",g_stream_num);
- }
- else
- {
- fprintf(fp,"%d\n",g_old_stream_num);
- }
-
- if(g_stream_num>0xffffffff)
- {
- g_old_stream_num = g_stream_num = 0;
- }
-
- fclose(fp);
-
- sleep(10);
- }
-
- return NULL;
-}
-
-static unsigned int read_streamnum(void)
-{
- char buf[56] = {0};
- int stream_num;
-
- FILE* fp = fopen(STREAMNUM_FILE_NAME,"a+");
- if(fp == NULL)
- {
- printf("fopen %s error!\n",STREAMNUM_FILE_NAME);
- return -1;
- }
-
- if((fgets(buf,56,fp)) == NULL) //�ı��ĵ�����
- {
- printf("fgets stream id error!\n");
- return -1;
- }
-
- stream_num = atoi(buf);
- if(stream_num < 0)
- {
- return -1;
- }
-
- fclose(fp);
-
- return stream_num;
-}
-
-
-int stream_id_init(int thread_cnt)
-{
- unsigned int conf_num;
-
- (void)thread_cnt;
-
- if(PROJECT_MODULE_DISABLE == g_stream_id_switch){
- return -1;
- }
-
- MESA_load_profile_uint_def((char *)"./conf/main.conf", (char *)"Module", (char *)"machineid", &conf_num , 0);
- g_papp_machineid = (unsigned short)conf_num;
-
- pthread_mutex_init(&g_stream_num_mutex, NULL);
-
- g_stream_num = read_streamnum() + 1000;
- g_old_stream_num = g_stream_num;
-
- pthread_t update_streamnumThread;
- pthread_create(&update_streamnumThread, NULL, update_streamnum_thread ,NULL);
-
- return 0;
-}
-
-void *stream_id_create_struct(int thread_num)
-{
- void *info = dictator_malloc(thread_num, sizeof(long));
- memset(info, 0, sizeof(long));
-
- set_stream_id((unsigned long *)info);
-
- return info;
-}
-
-void stream_id_destroy(int thread_num, void *info)
-{
- dictator_free(thread_num, info);
-}
-
-
-int set_stream_id_switch(int op_switch)
-{
- g_stream_id_switch = op_switch;
- return 0;
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-
diff --git a/src/sapp_dev/sapp_init.c b/src/sapp_dev/sapp_init.c index 3b49389..3319bfd 100644 --- a/src/sapp_dev/sapp_init.c +++ b/src/sapp_dev/sapp_init.c @@ -119,16 +119,16 @@ static void sapp_platform_finish_up(void) return; } +extern int stream_register_overlay_ip(IPv4_CB_FUN_T x); +extern int stream_register_overlay_udp(STREAM_CB_FUN_T x); +extern int gdev_keepalive_plug_init(void); + int MESA_platform_init(int argc, char *argv[]) { - int queue_max_num, ipv6_switch = 0; - char pcap_dev1[128], pcap_dev2[128], snd_dev[128]; + int ipv6_switch = 0; char cap_filter[1024] = {}; char gateway_mac[32] = {}; - //int create_link_mode; int TcpAllEnable = 0; - //pthread_t gettimeThread; - int maxrandval, randkeyval; int load_plug_sw = 1; unsigned short udp_stream_timeout = 300, max_unorder_num; unsigned short link_timeout = 600; @@ -278,7 +278,7 @@ int MESA_platform_init(int argc, char *argv[]) /* 2020-12-23 lijia add, vxlan���������� */ if(DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin){ - stream_register_overlay_ip(gdev_keepalive_ip_entry); + stream_register_overlay_ip((IPv4_CB_FUN_T)gdev_keepalive_ip_entry); stream_register_overlay_udp(gdev_keepalive_udp_entry); if(gdev_keepalive_plug_init() < 0){ diff --git a/src/support/tomlc99_wrap/tomlc99_wrap.c b/src/support/tomlc99_wrap/tomlc99_wrap.c index 0634999..b8eafad 100644 --- a/src/support/tomlc99_wrap/tomlc99_wrap.c +++ b/src/support/tomlc99_wrap/tomlc99_wrap.c @@ -213,7 +213,8 @@ int tomlc99_wrap_load_int_array( } int_val[cfg_array_num] = (int)tmp_long_val; - int_val = (int *)realloc(int_val, sizeof(int) * (cfg_array_num + 2)); + int *tmp = (int *)realloc(int_val, sizeof(int) * (cfg_array_num + 2)); + if(tmp)int_val=tmp; } if(cfg_array_num > *array_num){ diff --git a/src/support/tomlc99_wrap/tomlc99_wrap.h b/src/support/tomlc99_wrap/tomlc99_wrap.h index 2a24b56..56d9850 100644 --- a/src/support/tomlc99_wrap/tomlc99_wrap.h +++ b/src/support/tomlc99_wrap/tomlc99_wrap.h @@ -5,6 +5,7 @@ extern "C" { #endif +#include <stddef.h> enum tomlc99_errno{ TOMLC99_RET_SUCCESS = 0, diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index 5643863..ed417cc 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -11,6 +11,9 @@ extern "C" { #define DEBUG_PRINT 1 #if DEBUG_PRINT #define DPRINT(fmt, args...) printf(fmt, ## args) +#define DFPRINT(fmt, args...) fprintf(fmt, ## args) +#define DSPRINT(fmt, args...) sprintf(fmt, ## args) +#define DSNPRINT(fmt, args...) snprintf(fmt, ## args) #else #define DPRINT(fmt, args...) /* Don't do anything in release builds */ #endif @@ -22,6 +25,13 @@ static unsigned short phony_protocol_plugid; #define TEST_NETWORK_FLOW 1 #define TEST_SAPP_API 1 +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif typedef struct{ int ivalue1; @@ -128,8 +138,6 @@ static void show_hierarchical_layer_stat(void) static int update_hierarchical_layer_stat(const struct hierarchical_layer *stream_hierarchical_layer_stat) { - int i; - if(search_g_hierarchical_layer_stat(stream_hierarchical_layer_stat) == 0){ //不存�? �?新的流结�? memcpy(&g_hierarchical_layer_stat[hierarchical_layer_stat_num], stream_hierarchical_layer_stat, sizeof(struct hierarchical_layer) * MAX_LAYER_DEPTH); hierarchical_layer_stat_num++; @@ -375,7 +383,7 @@ char test_tcp_uni_stream_stats(struct streaminfo *a_tcp, void **pme, int thread /* 2015-12-29 lijia add */ tflow_project = (struct tcp_flow_stat *)project_req_get_struct(a_tcp, test_tcp_flow_id); if(tflow_project){ - DPRINT("from-project: server pkt=%u, count=%lu, client pkt=%u, count=%lu\n", + DPRINT("from-project: server pkt=%u, count=%llu, client pkt=%u, count=%llu\n", tflow_project->C2S_data_pkt,tflow_project->C2S_data_byte, tflow_project->S2C_data_pkt, tflow_project->S2C_data_byte); } @@ -486,11 +494,10 @@ char test_set_stream_timeout(struct streaminfo *pstream, void **pme, int thread return APP_STATE_GIVEME; } -char test_set_stream_timer(struct streaminfo *pstream, void **pme, int thread_seq,void *a_packet) +char test_set_stream_timed(struct streaminfo *pstream, void **pme, int thread_seq,void *a_packet) { int ret; int tout_val; - int opt_len; if(pstream->pktstate== OP_STATE_PENDING){ tout_val = 1; @@ -499,13 +506,13 @@ char test_set_stream_timer(struct streaminfo *pstream, void **pme, int thread_s DPRINT("stream:%p, MESA_set_stream_opt error:\n", pstream); return APP_STATE_DROPME; } - DPRINT("stream: %p %s set timer at %llu!\n", pstream, printaddr(&pstream->addr, thread_seq), time(NULL)); + DPRINT("stream: %p %s set timer at %ld!\n", pstream, printaddr(&pstream->addr, thread_seq), time(NULL)); } if(pstream->pktstate == OP_STATE_TIMED){ - DPRINT("stream timeup: %p %s at %llu!\n", pstream, printaddr(&pstream->addr, thread_seq), time(NULL)); + DPRINT("stream timeup: %p %s at %ld!\n", pstream, printaddr(&pstream->addr, thread_seq), time(NULL)); } if(pstream->pktstate == OP_STATE_CLOSE){ - DPRINT("stream close: %p %s at %llu!\n", pstream, printaddr(&pstream->addr, thread_seq), time(NULL)); + DPRINT("stream close: %p %s at %ld!\n", pstream, printaddr(&pstream->addr, thread_seq), time(NULL)); } return APP_STATE_GIVEME; } @@ -629,7 +636,7 @@ char test_stream_with_platform_in_out_traffic(struct streaminfo *pstream, void } -int test_sapp_get_device_opt(const char *device) +static int test_sapp_get_device_opt(const char *device) { int ret; unsigned char dev_mac[6]; @@ -661,6 +668,7 @@ int test_sapp_get_device_opt(const char *device) }else{ DPRINT("sapp_get_device_opt->%s : SDO_MTU: %d\n", device, dev_mtu); } + return 0; } #endif @@ -806,29 +814,30 @@ test_set_stream_timeout(pstream, pme, thread_seq, a_packet); { if(pdetail != NULL){ DPRINT("%20s: %s, %llu, ", "UdpallstreaM-inter", printaddr(&(pstream->addr), pstream->threadnum), test_get_stream_id(pstream)); - DPRINT("server-pkt=%u, server-count=%lu, client-pkt=%u, client-count=%lu, datalen=%u, ", + DPRINT("server-pkt=%u, server-count=%u, client-pkt=%u, client-count=%u, datalen=%u, ", pdetail->serverpktnum, pdetail->serverbytes, pdetail->clientpktnum,pdetail->clientbytes, pdetail->datalen); DPRINT("total-pkt=%d, ", pdetail->serverpktnum + pdetail->clientpktnum); DPRINT("total-count=%u\n", pdetail->serverbytes + pdetail->clientbytes); - } + DPRINT("%20s: %s, ", "udpallstream-plug", printaddr(&(pstream->addr), pstream->threadnum)); - DPRINT("server-pkt=%u, server-count=%lu, client-pkt=%u, client-count=%lu, datalen=%u, ", + DPRINT("server-pkt=%u, server-count=%llu, client-pkt=%u, client-count=%llu, datalen=%u, ", plug_stat->C2S_pkt,plug_stat->C2S_byte, plug_stat->S2C_pkt,plug_stat->S2C_byte, pdetail->datalen); + } DPRINT("total-pkt=%d, ", plug_stat->C2S_pkt + plug_stat->S2C_pkt); - DPRINT("total-count=%u\n", plug_stat->C2S_byte+plug_stat->S2C_byte); + DPRINT("total-count=%llu\n", plug_stat->C2S_byte+plug_stat->S2C_byte); free(*pme); struct udp_flow_stat *flow_project = (struct udp_flow_stat *)project_req_get_struct(pstream, test_udp_flow_id); if(flow_project != NULL){ DPRINT("%20s: %s, ", "UdpallstreaM-project", printaddr(&(pstream->addr), pstream->threadnum)); - DPRINT("server-pkt=%u, server-count=%lu, client-pkt=%u, client-count=%lu, datalen=%u, ", + DPRINT("server-pkt=%u, server-count=%llu, client-pkt=%u, client-count=%llu, datalen=%u, ", flow_project->C2S_pkt,flow_project->C2S_byte, flow_project->S2C_pkt,flow_project->S2C_byte, pdetail->datalen); DPRINT("total-pkt=%d, ", flow_project->C2S_pkt + flow_project->S2C_pkt); - DPRINT("total-count=%u\n", flow_project->C2S_byte+flow_project->S2C_byte); + DPRINT("total-count=%llu\n", flow_project->C2S_byte+flow_project->S2C_byte); } } return APP_STATE_GIVEME; @@ -862,7 +871,7 @@ char tcp_data_dump(struct streaminfo *pstream,void **pme, int thread_seq,void *a if(pstream->opstate== OP_STATE_PENDING){ inet_ntop(AF_INET, &pstream->addr.tuple4_v4->saddr, sip_str, 20); inet_ntop(AF_INET, &pstream->addr.tuple4_v4->daddr, dip_str, 20); - snDPRINT(file_name, 128, "%s_%u_%s_%u.T%ld.dump", + DSNPRINT(file_name, 128, "%s_%u_%s_%u.T%ld.dump", sip_str, ntohs(pstream->addr.tuple4_v4->source), dip_str, ntohs(pstream->addr.tuple4_v4->dest), (long)time(NULL)); @@ -978,7 +987,6 @@ char testtcpApp_2(struct streaminfo *pstream,void **pme, int thread_seq,void *a_ { struct tcpdetail *raw_pdetail=(struct tcpdetail *)pstream->pdetail; struct tcp_flow_stat *plug_stat; - char addr_str_buf[1024]; if(-1 == test_tcp_flow_id){ test_tcp_flow_id = project_customer_register("tcp_flow_stat", "struct"); @@ -1019,7 +1027,7 @@ test_set_stream_timeout(pstream, pme, thread_seq, a_packet); struct tcp_flow_stat *tflow_inter = ((struct tcpdetail_private *)pstream->pdetail)->flow_stat; if(tflow_inter){ DPRINT("%17s: %s, %llu,", "TcpstreaM-inter", printaddr(&(pstream->addr), pstream->threadnum), test_get_stream_id(pstream)); - DPRINT("opstate=%d, server pkt=%u, count=%lu, client pkt=%u, count=%lu\n", + DPRINT("opstate=%d, server pkt=%u, count=%llu, client pkt=%u, count=%llu\n", pstream->opstate, tflow_inter->C2S_data_pkt,tflow_inter->C2S_data_byte, tflow_inter->S2C_data_pkt, tflow_inter->S2C_data_byte); @@ -1030,7 +1038,7 @@ test_set_stream_timeout(pstream, pme, thread_seq, a_packet); struct tcp_flow_stat *tflow_project = (struct tcp_flow_stat *)project_req_get_struct(pstream, test_tcp_flow_id); if(tflow_project){ DPRINT("%17s: %s, ", "TcpstreaM-project", printaddr(&(pstream->addr), pstream->threadnum)); - DPRINT("opstate=%d, server pkt=%u, count=%lu, client pkt=%u, count=%lu\n", + DPRINT("opstate=%d, server pkt=%u, count=%llu, client pkt=%u, count=%llu\n", pstream->opstate, tflow_project->C2S_data_pkt,tflow_project->C2S_data_byte, tflow_project->S2C_data_pkt, tflow_project->S2C_data_byte); @@ -1082,7 +1090,7 @@ char tcpentry_vlink_info(struct streaminfo *pstream,void **pme, int thread_seq,v char srcstr[INET6_ADDRSTRLEN], dststr[INET6_ADDRSTRLEN]; const struct mesa_ethernet_hdr *ehdr; unsigned char inline_dev_mac[6], local_dev_mac[6]; - unsigned int inline_dev_ip, local_dev_ip; + unsigned int local_dev_ip; if(pstream->opstate== OP_STATE_PENDING) { @@ -1148,7 +1156,7 @@ char tcpentry_vlink_info(struct streaminfo *pstream,void **pme, int thread_seq,v static int test_tcpall_flow_id = -1; -char testtcpApp_allpkt(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet) +char testtcpApp_allpkt(struct streaminfo *pstream,void **pme, int thread_seq, const void *a_packet) { struct tcpdetail *pdetail=(struct tcpdetail *)pstream->pdetail; struct tcpdetail_private *pdetail_pr=(struct tcpdetail_private *)pstream->pdetail; @@ -1184,24 +1192,24 @@ char testtcpApp_allpkt(struct streaminfo *pstream,void **pme, int thread_seq,voi { DPRINT("%20s: %s, ", "tcpallstream-plug", printaddr(&(pstream->addr), pstream->threadnum)); //DPRINT("index=%d,state=%d ",*(int*)((char *)(pstream)-8),*(char *)((char *)(pstream)-4)); - DPRINT("out:%d, final_dir=%d server-pkt=%u, server-count=%lu, client-pkt=%u, client-count=%lu, ", + DPRINT("out:%d, final_dir=%d server-pkt=%u, server-count=%llu, client-pkt=%u, client-count=%llu, ", pdetail_pr->link_state, pstream->dir, tcpallflow->C2S_all_pkt, tcpallflow->C2S_all_byte, tcpallflow->S2C_all_pkt, tcpallflow->S2C_all_byte); DPRINT("total-pkt=%u, ", tcpallflow->C2S_all_pkt + tcpallflow->S2C_all_pkt); - DPRINT("total-count=%lu\n", tcpallflow->C2S_all_byte + tcpallflow->S2C_all_byte); + DPRINT("total-count=%llu\n", tcpallflow->C2S_all_byte + tcpallflow->S2C_all_byte); free(*pme); /* 2015-12-29 lijia add */ struct tcp_flow_stat *tflow_inter = pdetail_pr->flow_stat; if(tflow_inter){ DPRINT("%20s: %s, %llu", "TcpallstreaM-inter", printaddr(&(pstream->addr), pstream->threadnum), test_get_stream_id(pstream)); - DPRINT("out:%d, pktstate=%d, opstate=%d, server-pkt=%u, server-count=%lu, client-pkt=%u, client-count=%lu, ", + DPRINT("out:%d, pktstate=%d, opstate=%d, server-pkt=%u, server-count=%llu, client-pkt=%u, client-count=%llu, ", pdetail_pr->link_state,pstream->pktstate,pstream->opstate, tflow_inter->C2S_all_pkt,tflow_inter->C2S_all_byte, tflow_inter->S2C_all_pkt, tflow_inter->S2C_all_byte); DPRINT("total-pkt=%u, ", tflow_inter->C2S_all_pkt + tflow_inter->S2C_all_pkt); - DPRINT("total-count=%lu\n", tflow_inter->C2S_all_byte + tflow_inter->S2C_all_byte); + DPRINT("total-count=%llu\n", tflow_inter->C2S_all_byte + tflow_inter->S2C_all_byte); } @@ -1210,12 +1218,12 @@ char testtcpApp_allpkt(struct streaminfo *pstream,void **pme, int thread_seq,voi struct tcp_flow_stat *tflow_project = (struct tcp_flow_stat *)project_req_get_struct(pstream, test_tcpall_flow_id); if(tflow_project){ DPRINT("%20s: %s, ", "TcpallstreaM-project", printaddr(&(pstream->addr), pstream->threadnum)); - DPRINT("out:%d, pktstate=%d, opstate=%d, server-pkt=%u, server-count=%lu, client-pkt=%u, client-count=%lu, ", + DPRINT("out:%d, pktstate=%d, opstate=%d, server-pkt=%u, server-count=%llu, client-pkt=%u, client-count=%llu, ", pdetail_pr->link_state,pstream->pktstate,pstream->opstate, tflow_project->C2S_all_pkt,tflow_project->C2S_all_byte, tflow_project->S2C_all_pkt, tflow_project->S2C_all_byte); DPRINT("total-pkt=%u, ", tflow_project->C2S_all_pkt + tflow_project->S2C_all_pkt); - DPRINT("total-count=%lu\n", tflow_project->C2S_all_byte + tflow_project->S2C_all_byte); + DPRINT("total-count=%llu\n", tflow_project->C2S_all_byte + tflow_project->S2C_all_byte); } } } @@ -1423,11 +1431,11 @@ static int check_rst_ip_old (unsigned int sip_net_order, unsigned int dip_net_or { unsigned short window_compute; if (sip_net_order == INADDR_NONE) { - fDPRINT (stderr, "source IP wrong.\n"); + DFPRINT (stderr, "source IP wrong.\n"); return -1; } if (dip_net_order == INADDR_NONE) { - fDPRINT (stderr, "destination IP wrong.\n"); + DFPRINT (stderr, "destination IP wrong.\n"); return -1; } @@ -1438,8 +1446,6 @@ static int check_rst_ip_old (unsigned int sip_net_order, unsigned int dip_net_or return 0; int val = (iMaxRandVal - ipid + sip_net_order%window)/iRandKey; window_compute = (unsigned short)(val+dip_net_order%iRandKey); - if (window == 0 ) - return 0; if (window == 1 ) { if (window_compute == 0 || window_compute == 1 ) return 1; @@ -1511,8 +1517,6 @@ char test_ipv6_frag(const struct streaminfo *pstream,unsigned char routedir,int char test_layer_addr_prefix_ntop(const struct streaminfo *stream,void **pme, int thread_seq,const void *raw_pkt) { - char addr_ntop_str_r[4096]; - char *addr_ntop_str; const char *addr_type_ntop_str; const struct streaminfo *tmp = stream; @@ -1859,7 +1863,7 @@ static void test_inject_tcp_pkt_with_this_hdr(struct streaminfo *stream,void **p 0, NULL, 0, - (unsigned char *)send_thdr); + (char *)send_thdr); sendpacket_build_ipv4(sizeof(struct mesa_tcp_hdr) + sizeof(fake_http_data), 0, @@ -1912,12 +1916,12 @@ char test_inject_tcp_pkt(struct streaminfo *stream,void **pme, int thread_seq,co } } - payload_char_len = SAPP_MIN(g_test_app_val.ivalue1, 4096); + payload_char_len = MIN(g_test_app_val.ivalue1, 4096); payload_buf[payload_char_len] = '\0'; - snDPRINT(payload_with_html_buf, sizeof(payload_with_html_buf), "<html><head>%s</head></html>", payload_buf); + DSNPRINT(payload_with_html_buf, sizeof(payload_with_html_buf), "<html><head>%s</head></html>", payload_buf); total_payload_len = strlen(payload_with_html_buf); - snDPRINT(fake_http_send_buf, sizeof(fake_http_send_buf), fake_http_pattern, total_payload_len, payload_with_html_buf); + DSNPRINT(fake_http_send_buf, sizeof(fake_http_send_buf), fake_http_pattern, total_payload_len, payload_with_html_buf); DPRINT("found key 'hijack', send fake http response, len=%d\n", total_payload_len); //MESA_inject_pkt(stream, fake_http_data, sizeof(fake_http_data), raw_pkt, stream->routedir ^ 1); @@ -1938,7 +1942,6 @@ char test_inject_tcp_pkt2(struct streaminfo *stream,void **pme, int thread_seq,c { char fake_http_data[] = "HTTP/1.1 200 OK\r\nServer: Apache-Coyote/1.1\r\nContent-Type: text/html;charset=UTF-8\r\nContent-Language: zh-CN\r\nContent-Length: 41\r\nConnection: Close\r\n\r\n<html><head>sapp inject pkt</head></html>"; char plug_ret = APP_STATE_DROPME; - int optval; if(OP_STATE_CLOSE == stream->opstate){ return APP_STATE_DROPME; @@ -1965,9 +1968,9 @@ static int send_by_sapp_inject_pkt(struct streaminfo *a_tcp, const struct mesa_i struct mesa_ip4_hdr *send_ip4hdr = (struct mesa_ip4_hdr *)http_hijack_buf; struct mesa_tcp_hdr *send_thdr = (struct mesa_tcp_hdr *)((char *)send_ip4hdr + sizeof(struct mesa_ip4_hdr)); //no options - int hdr_len = snDPRINT(http_hijack_buf+sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_tcp_hdr), - 1500, HIJACK_RESPONSE_HDR, strlen(HIJACK_RESPONSE_BODY)); - int body_len = snDPRINT(http_hijack_buf+sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_tcp_hdr)+hdr_len, + int hdr_len = DSNPRINT(http_hijack_buf+sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_tcp_hdr), + 1460, HIJACK_RESPONSE_HDR, (int)strlen(HIJACK_RESPONSE_BODY)); + int body_len = DSNPRINT(http_hijack_buf+sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_tcp_hdr)+hdr_len, 1500-hdr_len, "%s", HIJACK_RESPONSE_BODY); http_hijack_len = sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_tcp_hdr) + hdr_len + body_len; @@ -1994,10 +1997,10 @@ static int send_by_sapp_inject_pkt(struct streaminfo *a_tcp, const struct mesa_i send_ip4hdr->ip_src.s_addr = raw_ip4hdr->ip_dst.s_addr; send_ip4hdr->ip_dst.s_addr = raw_ip4hdr->ip_src.s_addr; - sendpacket_do_checksum(http_hijack_buf, IPPROTO_TCP, sizeof(struct mesa_tcp_hdr) + hdr_len + body_len); - sendpacket_do_checksum(http_hijack_buf, IPPROTO_IP, sizeof(struct mesa_ip4_hdr)); + sendpacket_do_checksum((unsigned char*)http_hijack_buf, IPPROTO_TCP, sizeof(struct mesa_tcp_hdr) + hdr_len + body_len); + sendpacket_do_checksum((unsigned char*)http_hijack_buf, IPPROTO_IP, sizeof(struct mesa_ip4_hdr)); - sapp_inject_pkt(a_tcp, SIO_EXCLUDE_THIS_LAYER_HDR, http_hijack_buf, http_hijack_len, MESA_dir_reverse(a_tcp->routedir)); + return sapp_inject_pkt(a_tcp, SIO_EXCLUDE_THIS_LAYER_HDR, http_hijack_buf, http_hijack_len, MESA_dir_reverse(a_tcp->routedir)); } @@ -2007,8 +2010,6 @@ char MESA_inject_pkt_for_l2_l3_tcp(struct streaminfo *stream,void **pme, int thr const char *modify_raw_data_c2s = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"; //C2Sԭʼ�ַ������� const char *modify_inject_data_s2c = "HTTP/1.1 200 OK\r\nServer: Microsoft-IIS/8.5\r\nContent-Type: text/html\r\nContent-Length: 4000\r\n\r\n<html><pre> sapp test inject data........."; - char raw_data_s2c[2048]; - char *modify_ptr_c2s, *modify_ptr_s2c; int ret; char ret_flag = 0; @@ -2060,9 +2061,9 @@ char MESA_inject_pkt_for_l2_l3_tcpall(struct streaminfo *stream,void **pme, int && (stream->ptcpdetail->datalen == 0)){ /* ֻ���������ָո���ɺ�, �յ�ACK������һ��get����,������ŶԲ��� */ inet_ntop(AF_INET, &stream->addr.tuple4_v4->daddr, server_ip, 32); - sDPRINT(raw_data_c2s, modify_inject_data_c2s, server_ip); + DSPRINT(raw_data_c2s, modify_inject_data_c2s, server_ip); if(strlen(raw_data_c2s) != 197){ - DPRINT("MESA_inject_pkt_for_l2_l3_tcpall(), C2S inject len is not 197, %s\n", strlen(raw_data_c2s)); //Ҫ���DZ������������һ��, ������SEQ���ܲ��� + DPRINT("MESA_inject_pkt_for_l2_l3_tcpall(), C2S inject len is not 197, %d\n", (int)strlen(raw_data_c2s)); //Ҫ���DZ������������һ��, ������SEQ���ܲ��� return APP_STATE_DROPME; } ret = MESA_inject_pkt(stream, raw_data_c2s, strlen(raw_data_c2s), raw_pkt, stream->routedir); @@ -2318,22 +2319,14 @@ void print_stream_list(const struct streaminfo *pstream) char test_proxy_cb(struct streaminfo *pstream,void **pme, int thread_seq,const void *a_packet) { struct tcpdetail *a_tcp; - //int addr_type; - //void *tuple4; - //int project_req_id; - long stream_id; if(OP_STATE_PENDING == pstream->opstate){ a_tcp = (struct tcpdetail *)pstream->pdetail; - //DPRINT("######### %p, %x\n", a_tcp->pdata, ((char *)a_tcp->pdata)[0]); - //print_tuple4(pstream); DPRINT("into test_proxy_cb----------\n"); print_stream_list(pstream); write(1, a_tcp->pdata, a_tcp->datalen); - //DPRINT("test_tcp_cb-pending: stream:%p, %s, len:%d\n", pstream, printaddr(&pstream->addr, pstream->threadnum), a_tcp->datalen); }else if (OP_STATE_DATA == pstream->opstate){ a_tcp = (struct tcpdetail *)pstream->pdetail; - //DPRINT("test_tcp_cb-data: %s, len:%d\n", printaddr(&pstream->addr, pstream->threadnum), a_tcp->datalen ); }else if(OP_STATE_CLOSE == pstream->opstate){ DPRINT("test_tcp_cb-close: strem %s\n", printaddr(&pstream->addr, pstream->threadnum)); return APP_STATE_DROPME; @@ -2712,7 +2705,7 @@ char stream_bridge_tcp_entry(struct streaminfo *pstream,void **pme, int thread_s void *data = calloc(1, 100); strncpy(data, "abcdefg1234567", 100); stream_bridge_async_data_put(pstream, bridge_id, data); - DPRINT("##### tcp entry bridge put data:%s\n", data); + DPRINT("##### tcp entry bridge put data:%s\n", (char*)data); } return APP_STATE_GIVEME; @@ -2972,8 +2965,8 @@ char TCP_ALL_DUMP_PCAP_PKT(struct streaminfo *pstream, void **pme, int thread_s if(OP_STATE_PENDING == pstream->pktstate){ char tmp_file[32]; - snDPRINT(tmp_file, 32, "%p.pcap", pstream); - FILE *fp = fopen(tmp_file, "a+"); + DSNPRINT(tmp_file, 32, "%p.pcap", pstream); + fp = fopen(tmp_file, "a+"); if(NULL == fp){ DPRINT("fopen ./%p.pcap error!\n", tmp_file); return APP_STATE_DROPME; @@ -3208,7 +3201,7 @@ char INJECT_STREAM(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a } -char TEST_STREAM(struct streaminfo *stream, void **pme, int thread_seq,void *a_packet) +char TEST_STREAM(struct streaminfo *stream, void **pme, int thread_seq, const void *a_packet) { char *data = NULL; int i, datalen = -1, ret; @@ -3220,7 +3213,7 @@ char TEST_STREAM(struct streaminfo *stream, void **pme, int thread_seq,void *a_ return APP_STATE_DROPME; } - int min_num = SAPP_MIN(65535, g_test_app_val.ivalue1+1); //�������ļ���ȡ + int min_num = MIN(65535, g_test_app_val.ivalue1+1); //�������ļ���ȡ for(i = 0; i < min_num; i++){ local_data[i] = rand(); @@ -3232,12 +3225,12 @@ char TEST_STREAM(struct streaminfo *stream, void **pme, int thread_seq,void *a_ } ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_TOT_LEN, &datalen); - if(ret < 0 || NULL == data){ + if(ret < 0 ){ return APP_STATE_GIVEME; } /* ���д�㶫��, �ķ�CPU */ - if((data != NULL) && (datalen > 0)){ + if(datalen > 0){ for(i = 0; i < datalen; i++){ result1[i] = (long)memchr(local_data, data[i], min_num); result2[i] = (long long )memmem((void *)local_data, min_num, (void *)&data[i], datalen-i); @@ -3316,10 +3309,10 @@ static void anti_flood_stat_log(void) fp = fopen("./log/anti_flood_stat.log", "w+"); - fDPRINT(fp, "tcp_syn\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_TCP_SYN]); - fDPRINT(fp, "udp_dns\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_UDP_DNS]); - fDPRINT(fp, "udp_ntp\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_UDP_NTP]); - fDPRINT(fp, "ip_frag\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_IP_FRAG]); + DFPRINT(fp, "tcp_syn\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_TCP_SYN]); + DFPRINT(fp, "udp_dns\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_UDP_DNS]); + DFPRINT(fp, "udp_ntp\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_UDP_NTP]); + DFPRINT(fp, "ip_frag\t %llu\n", tmp_anti_flood_stat[ANTI_FLOOD_IP_FRAG]); fclose(fp); } @@ -3443,6 +3436,7 @@ char arp_plug_entry(const struct streaminfo *pstream,unsigned char routedir,int DPRINT("rev arp response: ip:%s--->mac:%02x-%02x-%02x-%02x-%02x-%02x \n", ip4_str, aph->ar_sha[0],aph->ar_sha[1],aph->ar_sha[2],aph->ar_sha[3],aph->ar_sha[4],aph->ar_sha[5]); + return APP_STATE_GIVEME; } |
