TSG-8364: 支持配置文件配置最多解析N数据包

This commit is contained in:
liuxueli
2021-11-10 19:39:17 +03:00
parent 11c3aa538a
commit 895e4c08bb
13 changed files with 96 additions and 33 deletions

View File

@@ -18,9 +18,14 @@
#include "quic_process.h"
#include "quic_deprotection.h"
#define PARSE_RESULT_UNKNOWN 0
#define PARSE_RESULT_VERSION 1
#define PARSE_RESULT_CLIENT_HELLO 2
enum PARSE_RESULT
{
PARSE_RESULT_UNKNOWN,
PARSE_RESULT_VERSION,
PARSE_RESULT_CLIENT_HELLO,
PARSE_RESULT_PAYLOAD,
PARSE_RESULT_MAX
};
#ifndef PRINTADDR
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
@@ -748,7 +753,7 @@ enum QUIC_VERSION is_quic_protocol(const char *payload, int payload_len, int *pa
return quic_version;
}
int parse_quic_all_version(struct quic_info *quic_info, const char *payload, int payload_len, int thread_seq)
unsigned char parse_quic_all_version(struct quic_info *quic_info, const char *payload, int payload_len, int thread_seq)
{
int ret=0, payload_offset=0;
unsigned char decrypt_payload[2048]={0};
@@ -803,24 +808,59 @@ int parse_quic_all_version(struct quic_info *quic_info, const char *payload, int
unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context* context, int thread_seq, void* a_packet)
{
int ret=PARSE_RESULT_UNKNOWN;
unsigned char parse_result=PARSE_RESULT_UNKNOWN;
char state=APP_STATE_GIVEME;
if(pstream==NULL || pstream->pudpdetail==NULL)
{
return APP_STATE_DROPME;
}
struct udpdetail *udp_detail=pstream->pudpdetail;
ret=parse_quic_all_version(&(context->quic_info), (const char *)udp_detail->pdata, udp_detail->datalen, thread_seq);
switch(ret)
switch(context->pre_parse_state)
{
case PARSE_RESULT_VERSION:
return quic_call_business_plug(pstream, context, (void *)&(context->quic_info.quic_version), sizeof(unsigned int), QUIC_USEING_VERSION_MASK, a_packet);
case PARSE_RESULT_CLIENT_HELLO:
return quic_call_business_plug(pstream, context, (void *)&(context->quic_info), sizeof(void *), QUIC_CLIENT_HELLO_MASK, a_packet);
case PARSE_RESULT_CLIENT_HELLO:
parse_result=PARSE_RESULT_PAYLOAD;
break;
case PARSE_RESULT_VERSION:
parse_result=parse_quic_all_version(&(context->quic_info), (const char *)udp_detail->pdata, udp_detail->datalen, thread_seq);
if(parse_result==PARSE_RESULT_VERSION || parse_result==PARSE_RESULT_UNKNOWN)
{
parse_result=PARSE_RESULT_PAYLOAD;
}
break;
case PARSE_RESULT_PAYLOAD:
case PARSE_RESULT_UNKNOWN:
default:
if((context->parse_pkt_cnt++)>=g_quic_param.max_parse_pkt_num)
{
parse_result=PARSE_RESULT_PAYLOAD;
break;
}
parse_result=parse_quic_all_version(&(context->quic_info), (const char *)udp_detail->pdata, udp_detail->datalen, thread_seq);
break;
}
switch(parse_result)
{
case PARSE_RESULT_VERSION:
context->pre_parse_state=PARSE_RESULT_VERSION;
state=quic_call_business_plug(pstream, context, (void *)&(context->quic_info.quic_version), sizeof(unsigned int), QUIC_USEING_VERSION_MASK, a_packet);
break;
case PARSE_RESULT_CLIENT_HELLO:
context->pre_parse_state=PARSE_RESULT_CLIENT_HELLO;
state=quic_call_business_plug(pstream, context, (void *)&(context->quic_info), sizeof(void *), QUIC_CLIENT_HELLO_MASK, a_packet);
break;
case PARSE_RESULT_PAYLOAD:
state=quic_call_business_plug(pstream, context, udp_detail->pdata, udp_detail->datalen, QUIC_APPLICATION_DATA_MASK, a_packet);
break;
default:
return APP_STATE_DROPME;
break;
}
return APP_STATE_DROPME;
return state;
}
static int copy_client_hello_extension(char *src, char *dest, int d_len)
@@ -839,7 +879,7 @@ static int copy_client_hello_extension(char *src, char *dest, int d_len)
unsigned int quic_protocol_identify(struct streaminfo *a_stream, void *a_packet, char *out_sni, int *out_sni_len, char *out_ua, int *out_ua_len)
{
int ret=APP_STATE_GIVEME;
unsigned char parse_result=APP_STATE_GIVEME;
struct quic_info quic_info={0, NULL};
unsigned int quic_version=QUIC_VERSION_UNKNOWN;
@@ -848,8 +888,8 @@ unsigned int quic_protocol_identify(struct streaminfo *a_stream, void *a_packet,
return quic_version;
}
ret=parse_quic_all_version(&quic_info, (const char *)a_stream->pudpdetail->pdata, a_stream->pudpdetail->datalen, a_stream->threadnum);
if(ret!=PARSE_RESULT_UNKNOWN)
parse_result=parse_quic_all_version(&quic_info, (const char *)a_stream->pudpdetail->pdata, a_stream->pudpdetail->datalen, a_stream->threadnum);
if(parse_result!=PARSE_RESULT_UNKNOWN)
{
if(quic_info.client_hello!=NULL)
{