解析tag_num出现异常时支持存数据包
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <MESA/stream.h>
|
#include <MESA/stream.h>
|
||||||
#include <MESA/MESA_handle_logger.h>
|
#include <MESA/MESA_handle_logger.h>
|
||||||
|
|
||||||
@@ -19,12 +20,32 @@
|
|||||||
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
|
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
|
||||||
#endif
|
#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 dump_packet(struct streaminfo *pstream)
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret=0;
|
||||||
|
char buff[2048]={0};
|
||||||
char filename[512]={0};
|
char filename[512]={0};
|
||||||
void *p_eth_rawpkt=NULL;
|
void *p_eth_rawpkt=NULL;
|
||||||
int eth_rawpkt_len=0;
|
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);
|
ret=get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &p_eth_rawpkt);
|
||||||
if(ret==0)
|
if(ret==0)
|
||||||
@@ -34,11 +55,20 @@ int dump_packet(struct streaminfo *pstream)
|
|||||||
{
|
{
|
||||||
return -1;
|
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+");
|
FILE *fp=fopen(filename, "a+");
|
||||||
if(fp)
|
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);
|
fclose(fp);
|
||||||
fp=NULL;
|
fp=NULL;
|
||||||
@@ -641,7 +671,16 @@ int parse_extension_tag(struct streaminfo *pstream, struct _quic_stream **quic_s
|
|||||||
int tag_type=0;
|
int tag_type=0;
|
||||||
int total_tag_len=0,tag_len=0;
|
int total_tag_len=0,tag_len=0;
|
||||||
int tag_offset_end=0,pre_tag_offset_end=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;
|
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)
|
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
|
*used_len+=2; //padding
|
||||||
break;
|
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)
|
switch(message_tag)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user