第一个数据包仅解析一次,节省cpu
This commit is contained in:
@@ -31,10 +31,6 @@ enum PARSE_RESULT
|
||||
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
struct quic_client_hello_msg_hdr
|
||||
{
|
||||
uint8_t handshake_type;
|
||||
@@ -57,7 +53,7 @@ int check_port(unsigned short port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_quic_port(struct streaminfo *pstream)
|
||||
int is_quic_port(const struct streaminfo *pstream)
|
||||
{
|
||||
unsigned short source=0, dest=0;
|
||||
|
||||
@@ -152,7 +148,7 @@ int quic_call_business_state(struct quic_context *context)
|
||||
return state;
|
||||
}
|
||||
|
||||
unsigned char quic_call_business_plug(struct streaminfo *pstream, struct quic_context *context, void *buff, int buff_len, enum quic_interested_region region_mask, void *a_packet)
|
||||
unsigned char quic_call_business_plug(const struct streaminfo *pstream, struct quic_context *context, void *buff, int buff_len, enum quic_interested_region region_mask, const void *a_packet)
|
||||
{
|
||||
char state=PROT_STATE_GIVEME;
|
||||
char app_state=APP_STATE_GIVEME;
|
||||
@@ -176,7 +172,7 @@ unsigned char quic_call_business_plug(struct streaminfo *pstream, struct quic_co
|
||||
session_info.buf=buff;
|
||||
session_info.buflen=buff_len;
|
||||
}
|
||||
state=PROT_PROCESS(&session_info, &(context->business_pme), pstream->threadnum, pstream, a_packet);
|
||||
state=PROT_PROCESS(&session_info, &(context->business_pme), pstream->threadnum, (struct streaminfo *)pstream, a_packet);
|
||||
|
||||
if(state&PROT_STATE_DROPPKT)
|
||||
{
|
||||
@@ -812,12 +808,12 @@ unsigned char parse_quic_all_version(struct quic_info *quic_info, const char *pa
|
||||
}
|
||||
|
||||
|
||||
unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context* context, int thread_seq, void* a_packet)
|
||||
unsigned char quic_analyze_entry(const struct streaminfo *pstream, struct quic_context* context, int thread_seq, const void* a_packet)
|
||||
{
|
||||
unsigned char parse_result=PARSE_RESULT_UNKNOWN;
|
||||
char state=APP_STATE_GIVEME;
|
||||
|
||||
if(pstream==NULL || pstream->pudpdetail==NULL)
|
||||
if(pstream==NULL || pstream->pudpdetail==NULL || context==NULL)
|
||||
{
|
||||
return APP_STATE_DROPME;
|
||||
}
|
||||
@@ -826,7 +822,7 @@ unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context
|
||||
|
||||
switch(context->pre_parse_state)
|
||||
{
|
||||
case PARSE_RESULT_CLIENT_HELLO:
|
||||
case PARSE_RESULT_CLIENT_HELLO:
|
||||
parse_result=PARSE_RESULT_PAYLOAD;
|
||||
break;
|
||||
case PARSE_RESULT_VERSION:
|
||||
@@ -839,6 +835,20 @@ unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context
|
||||
case PARSE_RESULT_PAYLOAD:
|
||||
case PARSE_RESULT_UNKNOWN:
|
||||
default:
|
||||
if(context->parse_first_pkt==1)
|
||||
{
|
||||
context->parse_first_pkt=0;
|
||||
if(context->quic_info.client_hello==NULL)
|
||||
{
|
||||
parse_result=PARSE_RESULT_VERSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
parse_result=PARSE_RESULT_CLIENT_HELLO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if((context->parse_pkt_cnt++)>=g_quic_param.max_parse_pkt_num)
|
||||
{
|
||||
parse_result=PARSE_RESULT_PAYLOAD;
|
||||
@@ -869,49 +879,30 @@ unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context
|
||||
return state;
|
||||
}
|
||||
|
||||
static int copy_client_hello_extension(char *src, char *dest, int d_len)
|
||||
struct quic_info *quic_protocol_identify(const struct streaminfo *a_stream)
|
||||
{
|
||||
if(src==NULL || dest==NULL || d_len<=0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int len=MIN((int)strlen(src), d_len-1);
|
||||
memcpy(dest, src, len);
|
||||
dest[len]='\0';
|
||||
|
||||
return 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)
|
||||
{
|
||||
unsigned char parse_result=APP_STATE_GIVEME;
|
||||
struct quic_info quic_info={0, NULL};
|
||||
unsigned int quic_version=QUIC_VERSION_UNKNOWN;
|
||||
|
||||
if(!is_quic_port(a_stream) || a_stream==NULL || a_stream->pudpdetail==NULL)
|
||||
{
|
||||
return quic_version;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
parse_result=parse_quic_all_version(&quic_info, (const char *)a_stream->pudpdetail->pdata, a_stream->pudpdetail->datalen, a_stream->threadnum);
|
||||
struct quic_info tmp_quic_info={0, NULL};
|
||||
unsigned char parse_result=APP_STATE_GIVEME;
|
||||
|
||||
parse_result=parse_quic_all_version(&tmp_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)
|
||||
{
|
||||
*out_sni_len=copy_client_hello_extension(quic_info.client_hello->sni, out_sni, *out_sni_len);
|
||||
*out_ua_len=copy_client_hello_extension(quic_info.client_hello->user_agent, out_ua, *out_ua_len);
|
||||
quic_free_client_hello(quic_info.client_hello, a_stream->threadnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
*out_sni_len=0;
|
||||
*out_ua_len=0;
|
||||
}
|
||||
|
||||
quic_version=quic_info.quic_version;
|
||||
struct quic_context *context=(struct quic_context *)dictator_malloc(a_stream->threadnum, sizeof(struct quic_context));
|
||||
memset(context, 0, sizeof(struct quic_context));
|
||||
context->quic_info=tmp_quic_info;
|
||||
context->parse_first_pkt=1;
|
||||
context->pre_parse_state=PARSE_RESULT_UNKNOWN;
|
||||
|
||||
stream_bridge_async_data_put(a_stream, g_quic_param.context_bridge_id, (void *)context);
|
||||
|
||||
return &(context->quic_info);
|
||||
}
|
||||
|
||||
return quic_version;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user