summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorliuxueli <[email protected]>2021-09-10 15:19:28 +0800
committerliuxueli <[email protected]>2021-09-10 15:19:28 +0800
commit72e835353cf83ac5de0db70401aeceb954874a8d (patch)
tree1acd637f80133cc6d8a77dd216118bae6db97d78 /src
parentfc462eb0b59ae4d3e96fe87c3559a86ac7e76b78 (diff)
解析tag_num出现异常时支持存数据包
Diffstat (limited to 'src')
-rw-r--r--src/gquic_process.cpp59
1 files changed, 42 insertions, 17 deletions
diff --git a/src/gquic_process.cpp b/src/gquic_process.cpp
index cb5c3be..31159b9 100644
--- a/src/gquic_process.cpp
+++ b/src/gquic_process.cpp
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
+#include <sys/time.h>
#include <MESA/stream.h>
#include <MESA/MESA_handle_logger.h>
@@ -19,12 +20,32 @@
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
#endif
+const unsigned char PCAP_FILE_HEAD[24] = {0xD4, 0xC3, 0xB2, 0xA1, 0x02, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
+
+struct pcap_hdr
+{
+ unsigned int tv_sec;
+ unsigned int tv_usec;
+ unsigned int len;
+ unsigned int caplen;
+};
+
int dump_packet(struct streaminfo *pstream)
{
int ret=0;
+ char buff[2048]={0};
char filename[512]={0};
void *p_eth_rawpkt=NULL;
int eth_rawpkt_len=0;
+ struct pcap_hdr pcap_hdr;
+ struct timeval current_time;
+
+ if(g_quic_param.dump_packet_switch==0)
+ {
+ return 0;
+ }
ret=get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &p_eth_rawpkt);
if(ret==0)
@@ -34,11 +55,20 @@ int dump_packet(struct streaminfo *pstream)
{
return -1;
}
- snprintf(filename, sizeof(filename), "%s-%s", g_quic_param.log_path, printaddr(&(pstream->addr), pstream->threadnum));
+ snprintf(filename, sizeof(filename), "%s-%s.pcap", g_quic_param.log_path, printaddr(&(pstream->addr), pstream->threadnum));
FILE *fp=fopen(filename, "a+");
if(fp)
{
- fwrite(p_eth_rawpkt, eth_rawpkt_len, 1, fp);
+ gettimeofday(&current_time, NULL);
+ pcap_hdr.tv_sec = current_time.tv_sec;
+ pcap_hdr.tv_usec = current_time.tv_usec;
+ pcap_hdr.caplen = eth_rawpkt_len;
+ pcap_hdr.len = pcap_hdr.caplen;
+
+ memcpy(buff, PCAP_FILE_HEAD, 24);
+ memcpy(buff+24, &pcap_hdr, sizeof(pcap_hdr));
+ memcpy(buff+24+sizeof(pcap_hdr), p_eth_rawpkt, eth_rawpkt_len);
+ fwrite(buff, eth_rawpkt_len+24+sizeof(pcap_hdr), 1, fp);
fclose(fp);
fp=NULL;
@@ -641,7 +671,16 @@ int parse_extension_tag(struct streaminfo *pstream, struct _quic_stream **quic_s
int tag_type=0;
int total_tag_len=0,tag_len=0;
int tag_offset_end=0,pre_tag_offset_end=0;
-
+
+ if(tag_num>64 || tag_num<0)
+ {
+ (*used_len)=payload_len;
+
+ dump_packet(pstream);
+ MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_TAG_NUM", "QUIC_TAG_NUM:%d addr: %s", tag_num, printaddr(&pstream->addr, pstream->threadnum));
+ return -1;
+ }
+
struct _quic_stream *stream=*quic_stream;
int tag_value_start=tag_num*4*2+(*used_len); // skip length of type and offset, type(offset)=szieof(int)
@@ -766,20 +805,6 @@ int gquic_frame_type_stream(struct streaminfo *pstream, struct _quic_context* _c
*used_len+=2; //padding
break;
}
-
- if(tag_num>40 || tag_num<0)
- {
- MESA_handle_runtime_log(g_quic_param.logger,
- RLOG_LV_FATAL,
- "QUIC_TAG_NUM",
- "Quic version: 0X%X addr: %s",
- _context->quic_info.quic_hdr.quic_version,
- printaddr(&pstream->addr, pstream->threadnum)
- );
- dump_packet(pstream);
-
- return state;
- }
switch(message_tag)
{