From 72e835353cf83ac5de0db70401aeceb954874a8d Mon Sep 17 00:00:00 2001 From: liuxueli Date: Fri, 10 Sep 2021 15:19:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E6=9E=90tag=5Fnum=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=97=B6=E6=94=AF=E6=8C=81=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gquic_process.cpp | 59 ++++++++++++++++++++++++++++++------------- 1 file 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 #include #include +#include #include #include @@ -19,12 +20,32 @@ #define PRINTADDR(a, b) ((b)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(¤t_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) {