From 8eb02b5fd3bf744b4ee3a814f8375fd68a4d96ab Mon Sep 17 00:00:00 2001 From: liuxueli Date: Fri, 22 May 2020 18:44:00 +0800 Subject: [PATCH] =?UTF-8?q?review=20code;=20=E4=BB=A3=E7=A0=81=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gquic.h | 15 +- src/gquic_process.c | 1732 +++++++++++++++++++------------------------ src/gquic_process.h | 11 +- src/quic_analysis.c | 572 ++++++-------- src/quic_analysis.h | 20 +- src/quic_callback.c | 134 ++-- src/quic_callback.h | 5 +- src/quic_util.c | 43 -- 8 files changed, 1064 insertions(+), 1468 deletions(-) diff --git a/src/gquic.h b/src/gquic.h index 1ec79fd..2349548 100644 --- a/src/gquic.h +++ b/src/gquic.h @@ -8,6 +8,12 @@ #ifndef SRC_GQUIC_H_ #define SRC_GQUIC_H_ +enum GQUIC_VERSION +{ + GQUIC_UNKNOWN=0, + GQUIC_OTHERS, + GQUIC_Q046 +}; #include @@ -87,13 +93,4 @@ struct quic_stream { uint64_t output_region_flag; }; -//struct st_quic_client_hello* quic_get_clienthello(void* app_info); -//struct st_quic_server_hello* quic_get_serverhello(void* app_info); -//uint32_t quic_get_version(void* app_info); -//quic_tlv_t* quic_get_cert_chain(void* app_info); -//quic_tlv_t* quic_get_cached_cert(void* app_info); -//quic_tlv_t* quic_get_common_cert(void* app_info); -//void* quic_get_application_data(void* app_info); - - #endif /* SRC_GQUIC_H_ */ diff --git a/src/gquic_process.c b/src/gquic_process.c index 13c0818..c91b264 100644 --- a/src/gquic_process.c +++ b/src/gquic_process.c @@ -10,6 +10,7 @@ #include #include #include +#include #define C2S 0x01 @@ -17,958 +18,787 @@ #define GQUIC_HANDSHAKE_LEN 12+1+1+4+4 #define DIVERSIFICATION_NONCE_LEN 32 -enum gquic_type { - GQUIC=1, UNKNOWN_QUIC_TYPE +extern struct quic_param_t g_quic_param; + +enum gquic_type +{ + GQUIC=1, + UNKNOWN_QUIC_TYPE }; -enum gquic_handshake_type { - QUIC_Crypto=1, UNKNOWN_HANDSHAKE_TYPE +enum gquic_handshake_type +{ + QUIC_Crypto=1, + UNKNOWN_HANDSHAKE_TYPE }; + +int get_quic_tlv(char *start_pos, quic_tlv_t *tlv, int len, int type, int thread_seq) +{ + if(tlv->ptr_value==NULL && len>0) + { + tlv->ptr_value=(char *)dictator_malloc(thread_seq, len); + memset(tlv->ptr_value, 0, len); + tlv->length=len; + tlv->type=type; + memcpy(tlv->ptr_value, start_pos, tlv->length); + } + + return 0; +} + +UINT32 get_stream_id(struct streaminfo *pstream, char* quic_data, UINT8 frame_type, UINT32 *skip_len) +{ + UINT16 data_length=0; + UINT32 stream_id=0; + UINT8 stream_id_len=0; + UINT8 len_data=0,len_stream=0, len_offset=0; + + len_stream = read_stream_len(frame_type); + switch(len_stream) + { + case 1: + stream_id=quic_data[*skip_len]; + break; + case 2: + stream_id=a_pletoh16((void *)quic_data, *skip_len); + break; + case 3: + stream_id=a_pletoh24((void *)quic_data, *skip_len); + break; + default: + stream_id=a_pletoh32((void *)quic_data, *skip_len); + break; + } + + *skip_len+=len_stream; // stream ID length + + if(frame_type&STREAM_D) + { + data_length=ntohs(a_pletoh16((void *)quic_data, *skip_len)); + *skip_len+=2; //data length + } + + len_offset=read_offset_len(frame_type); + *skip_len+=len_offset; + + MESA_handle_runtime_log(g_quic_param.logger, + RLOG_LV_DEBUG, + "QUIC_FRAME", + "stream_id: %u data length: %u offset length: %u addr: %s", + stream_id, + data_length, + len_offset, + printaddr(&pstream->addr, pstream->threadnum)); + + return stream_id; +} + +UINT32 get_packet_number(char* g_data_t, UINT32 offset, UINT8 pkn_len) +{ + switch(pkn_len) + { + case 1: + return g_data_t[offset]; + break; + case 2: + return ntohs(a_pletoh16((void *)g_data_t, offset)); + break; + case 4: + return a_pletoh32((void *)g_data_t, offset); + break; + default: + return a_pletoh48((void *)g_data_t, offset); + break; + } + + return 0; +} + +enum GQUIC_VERSION is_gquic_protocol(struct streaminfo *pstream, char *payload, uint32_t payload_len, uint8_t *pub_flags, uint32_t *version, uint32_t *skip_len) +{ + uint32_t is_q064=0; + uint64_t connection_id = 0; + int connection_id_len = 0; + enum GQUIC_VERSION quic_version=GQUIC_UNKNOWN; + + if(a_canRead(5, payload_len, *skip_len)) + { + *skip_len+=1; + strncpy((char*)&is_q064, payload+(*skip_len), 4); + if(ntohl(is_q064)==VER_Q046) + { + *skip_len += 2; + *version=(payload[*skip_len]&0x0f)*10 + (payload[*skip_len+1]&0x0f); + *skip_len += 2; + + MESA_handle_runtime_log(g_quic_param.logger, + RLOG_LV_DEBUG, + "QUIC_PUB_FLAGS", + "version: Q0%u addr: %s", + *version, + printaddr(&pstream->addr, pstream->threadnum)); + + return GQUIC_Q046; + } + + *skip_len-=1; + } + + *pub_flags=payload[*skip_len]; // public flags + *skip_len+=1; + + if(*pub_flags>PACKET_PUBLIC_FLAGS_MAX) + { + return quic_version; + } + + connection_id_len=read_conn_id_len(*pub_flags); + connection_id=(connection_id_len==0) ? 0 : (a_pntoh64((void *)payload, *skip_len)); + *skip_len+=connection_id_len; // CID length + + if(payload[*skip_len]==PUBLIC_FLAG_VER_FST_BYTE && *pub_flags&PUBLIC_FLAG_VER) + { + *skip_len += 2; + *version=(payload[*skip_len]&0x0f)*10 + (payload[*skip_len+1]&0x0f); + *skip_len += 2; + quic_version=GQUIC_OTHERS; + } + + if(*pub_flags==PUBLIC_FLAG_NONCE) + { + *skip_len+=32; //diversification nonce + } + + UINT8 pkt_seq_len=read_seq_num_len(*pub_flags); + UINT32 pkt_seq=get_packet_number(payload, *skip_len, pkt_seq_len); + *skip_len+=pkt_seq_len; // skip pkt_num + + if(*pub_flags&PUBLIC_FLAG_VER) + { + //message authentication hash + *skip_len+=MSG_AUTH_HASH_LEN; + + if(*version>0 && *version<34) + { + *skip_len+=1; //private flags + } + } + + MESA_handle_runtime_log(g_quic_param.logger, + RLOG_LV_DEBUG, + "QUIC_IDETIFY", + "pub_flags: 0X%02X connection_id: %llu version: Q%03u packet number: %u dir(1: C2S;2: S2C): %d addr: %s", + *pub_flags, + connection_id, + *version, + pkt_seq, + pstream->curdir, + printaddr(&pstream->addr, pstream->threadnum)); + + return quic_version; +} + +void gquic_proc_tag(struct streaminfo *pstream, struct quic_stream *a_quic_stream, UINT16 tag_num, UINT8 direction, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 *used_len) +{ + UCHAR return_val; + UINT32 tag_type; + UINT32 total_tag_len=0, tag_len=0; + UINT32 tag_value_start=tag_num*4*2+(*used_len); // skip length of type and offset, type(offset)=szieof(int) + UINT32 tag_offset_end=0, pre_tag_offset_end=0; + int tag_type_len=4, tag_offset_len=4,num=0; + enum quic_interested_region region_mask=QUIC_INTEREST_KEY_MASK; + + while(tag_num > 0 && a_canRead(tag_type_len+tag_offset_len, quic_data_len, *used_len)) + { + tag_type=a_pntoh32(quic_data, *used_len); + *used_len+=4; + + tag_offset_end=a_pletoh32(quic_data, *used_len); + *used_len+=4; + + tag_len=tag_offset_end-pre_tag_offset_end; + if(tag_len<0 || (tag_offset_end>=quic_data_len) || (tag_len>quic_data_len-tag_value_start)) + { + return ; + } + + switch(tag_type) + { + case TAG_PAD: + break; + case TAG_CCS: //common_cert + region_mask=QUIC_COMM_CERT_MASK; + get_quic_tlv(quic_data+tag_value_start, &a_quic_stream->common_cert, tag_len, tag_type, pstream->threadnum); + break; + case TAG_CCRT: //cached_cert + region_mask=QUIC_CACHED_CERT_MASK; + get_quic_tlv(quic_data+tag_value_start, &a_quic_stream->cached_cert, tag_len, tag_type, pstream->threadnum); + break; + case TAG_CRT: //cert_chain ????? length need change + if(a_quic_stream->cert_chain.length==0) + { + //tag_value_start += a_quic_stream->cert_chain.length; + tag_len=(tag_len>(quic_data_len-tag_value_start+1) ? (quic_data_len-tag_value_start+1) : tag_len); + get_quic_tlv(quic_data+tag_value_start, &a_quic_stream->cached_cert, tag_len, tag_type, pstream->threadnum); + region_mask=QUIC_CERT_CHAIN_MASK; + } + break; + case TAG_SNI: + if(a_quic_stream->st_client_hello.server_name_len==0) + { + a_quic_stream->st_client_hello.server_name_len=(tag_len>SERVER_NAME_LEN ? SERVER_NAME_LEN : tag_len); + memcpy(a_quic_stream->st_client_hello.server_name, quic_data + tag_value_start, tag_len); + MESA_handle_runtime_log(g_quic_param.logger, + RLOG_LV_DEBUG, + "QUIC_SNI", + "SNI: %s addr: %s", + a_quic_stream->st_client_hello.server_name, + printaddr(&pstream->addr, pstream->threadnum)); + + } + break; + case TAG_UAID: + if(a_quic_stream->st_client_hello.user_agent_len==0) + { + a_quic_stream->st_client_hello.user_agent_len=(tag_len>USER_AGENT_LEN ? USER_AGENT_LEN : tag_len); + memcpy(a_quic_stream->st_client_hello.user_agent, quic_data + tag_value_start, a_quic_stream->st_client_hello.user_agent_len); + } + break; + default: + if(direction == 0x01 && num < a_quic_stream->st_client_hello.ext_tag_num) + { + a_quic_stream->st_client_hello.ext_tags[num]=(quic_tlv_t *)dictator_malloc(pstream->threadnum, sizeof(quic_tlv_t)); + get_quic_tlv(quic_data+tag_value_start, a_quic_stream->st_client_hello.ext_tags[num], (tag_len>MAX_TAG_VALUE_LEN-1 ? MAX_TAG_VALUE_LEN-1 : tag_len), tag_type, pstream->threadnum); + } + else if(num < a_quic_stream->st_server_hello.ext_tag_num) + { + a_quic_stream->st_server_hello.ext_tags[num]=(quic_tlv_t *)dictator_malloc(pstream->threadnum, sizeof(quic_tlv_t)); + get_quic_tlv(quic_data+tag_value_start, a_quic_stream->st_server_hello.ext_tags[num], (tag_len>MAX_TAG_VALUE_LEN-1 ? MAX_TAG_VALUE_LEN-1 : tag_len), tag_type, pstream->threadnum); + } + num++; + break; + } + + tag_num--; + tag_value_start+=tag_len; + total_tag_len+=tag_len; + pre_tag_offset_end=tag_offset_end; + + return_val=quic_callPlugins(a_quic_stream, pstream, region_mask, pstream->threadnum, a_packet); + region_mask=QUIC_INTEREST_KEY_MASK; + } + + *used_len += total_tag_len; + + return; +} + +int gquic_frame_type_ack(struct quic_stream* a_quic_stream, char * quic_data, UINT32 quic_data_len, UINT8 frame_type, UINT32 *used_len) +{ + UINT8 num_timestamp, num_ranges, num_revived, num_blocks; + UINT32 len_largest_observed=0, len_missing_packet=0; + + *used_len+=1; + len_largest_observed = read_largest_observed_len(frame_type); + len_missing_packet = read_missing_packet_len(frame_type); + //No longer Entropy after Q034 + if(a_quic_stream->version < 34) + { + //Send Entropy + *used_len += 1; + *used_len += len_largest_observed; + *used_len += 2; //ack delay time + strncpy((char*)&num_timestamp, quic_data+*used_len,1); + *used_len += 1; + if(num_timestamp > 0) + { + *used_len += 1; + *used_len += 4; + *used_len += (num_timestamp - 1)*(1+2); + } + if(frame_type & ACK_N) + { + strncpy((char*)&num_ranges, quic_data+*used_len,1); + *used_len += 1; + + *used_len += num_ranges*(len_missing_packet+1); + + strncpy((char*)&num_revived, quic_data+*used_len,1); + *used_len += 1; + + //Num Revived x Length Largest Observed + *used_len += num_revived*len_largest_observed; + } + } + else + { + *used_len += len_largest_observed; //Largest Acked + *used_len += 2; //Largest Acked Delta Time + + if(frame_type & ACK_N) //Ack Block + { + strncpy((char*)&num_blocks, quic_data+*used_len,1); + *used_len += 1; + } + + *used_len += len_missing_packet; //First Ack Block Length + if(num_blocks) + { + //Gap to next block + *used_len += 1; + num_blocks -= 1; + *used_len += (num_blocks - 1)*len_missing_packet; + } + + strncpy((char*)&num_timestamp, quic_data+*used_len,1); //Timestamp + *used_len += 1; + if(num_timestamp > 0) + { + *used_len += 1; //Delta Largest Acked + *used_len += 4; //Time Since Largest Acked + + //Num Timestamp x (Delta Largest Acked + Time Since Previous Timestamp) + *used_len += (num_timestamp - 1)*(1+2); + } + } + + return 0; +} + +// return value: Have no meaning, only numerical value +int gquic_frame_type_control(struct quic_stream* a_quic_stream, char * quic_data, UINT32 quic_data_len, UINT8 frame_type, uint32_t pkt_num_len, UINT32 *used_len) +{ + UINT16 len_reason; + *used_len+=1; + + switch(frame_type) + { + case RST_STREAM: + *used_len +=4; //stream id + *used_len+=8; //Byte Offset + *used_len+=4; //Error Code + a_quic_stream->fin_flag=QUIC_TRUE; + break; + case CONNECTION_CLOSE: + len_reason = 0; + *used_len += 4; //Error Code + len_reason = a_pntoh16(quic_data, *used_len); //Reason Phrase Length + *used_len += 2; + //Reason Phrase,If length remaining == len_reason, it is Connection Close + if(get_remaining_len(quic_data_len, *used_len) == len_reason) + { + return QUIC_DATA; + } + a_quic_stream->fin_flag=(a_quic_stream->fin_flag==QUIC_FALSE) ? QUIC_HALF_CLOSE : QUIC_TRUE; + break; + case GOAWAY: + len_reason = 0; + *used_len += 4; //Error Code + *used_len += 4; //Last Good Stream ID + len_reason = a_pntoh16(quic_data, *used_len); //Reason Phrase Length + *used_len += 2; + *used_len += len_reason; //Reason Phrase + break; + case WINDOW_UPDATE: + *used_len += 4; //Stream ID + *used_len += 8; //Byte Offset + break; + case BLOCKED: + *used_len += 4; //Stream ID + break; + case STOP_WAITING: + //No longer Entropy after Q034 + if(a_quic_stream->version < 34) + { + *used_len += 1; // Send Entropy + } + //Least Unacked Delta + *used_len += pkt_num_len; + break; + case PING: //No Payload + case PADDING: + default: + return QUIC_FALSE; + break; + } + + return QUIC_TRUE; +} + +int gquic_frame_type_stream(struct streaminfo *pstream, struct quic_stream* a_quic_stream, char *quic_data, UINT32 quic_data_len, UINT8 frame_type, UINT32 *used_len, void* a_packet) +{ + UINT8 return_val; + UINT16 tag_num = 0; + UINT32 stream_id, message_tag; + if(frame_type&STREAM_F) + { + a_quic_stream->fin_flag=QUIC_TRUE; + } + + stream_id=get_stream_id(pstream, quic_data, frame_type, used_len); + + if(stream_id==1) //handshake + { + message_tag = a_pntoh32((void *)quic_data, *used_len); + *used_len += 4; + tag_num = a_pletoh16(quic_data, *used_len); + *used_len += 2; //tag_num + *used_len += 2; //padding + switch(message_tag) + { + case CHLO: //MTAG_CHLO; + if(a_quic_stream->st_client_hello.ext_tags==NULL) + { + a_quic_stream->st_client_hello.ext_tags=(quic_tlv_t **)dictator_malloc(pstream->threadnum, tag_num*sizeof(quic_tlv_t*)); + a_quic_stream->st_client_hello.ext_tag_num = tag_num; + } + else + { + if(a_quic_stream->st_server_hello.ext_tag_num && tag_num>a_quic_stream->st_client_hello.ext_tag_num) + { + quic_release_exts(pstream->threadnum, a_quic_stream->st_client_hello.ext_tags, a_quic_stream->st_client_hello.ext_tag_num); + a_quic_stream->st_client_hello.ext_tags=(quic_tlv_t **)dictator_malloc(pstream->threadnum, tag_num*sizeof(quic_tlv_t*)); + a_quic_stream->st_client_hello.ext_tag_num = tag_num; + } + else + { + return -1; + } + } + gquic_proc_tag(pstream, a_quic_stream, tag_num, C2S, a_packet, quic_data, quic_data_len, used_len); + if(a_quic_stream->st_client_hello.server_name_len>0 || a_quic_stream->st_client_hello.user_agent_len>0) + { + quic_callPlugins(a_quic_stream, pstream, QUIC_CLIENT_HELLO_MASK, pstream->threadnum, a_packet); + } + break; + case SHLO: //MTAG_SHLO; + if(a_quic_stream->st_server_hello.ext_tags==NULL) + { + return -2; + } + + a_quic_stream->st_server_hello.ext_tags=(quic_tlv_t **)dictator_malloc(pstream->threadnum, tag_num*sizeof(quic_tlv_t*)); + a_quic_stream->st_server_hello.ext_tag_num=tag_num; + + gquic_proc_tag(pstream, a_quic_stream, tag_num, S2C, a_packet, quic_data, quic_data_len, used_len); + + if(a_quic_stream->st_server_hello.ext_tags != NULL) + { + quic_callPlugins(a_quic_stream, pstream, QUIC_SERVER_HELLO_MASK, pstream->threadnum, a_packet); + } + break; + case REJ: //MTAG_REJ; + if(a_quic_stream->st_server_hello.ext_tags!=NULL) + { + return -3; + + } + + a_quic_stream->st_server_hello.ext_tags=(quic_tlv_t **)dictator_malloc(pstream->threadnum, tag_num*sizeof(quic_tlv_t*)); + a_quic_stream->st_server_hello.ext_tag_num=tag_num; + + gquic_proc_tag(pstream, a_quic_stream, tag_num, S2C, a_packet, quic_data, quic_data_len, used_len); + if(a_quic_stream->st_server_hello.ext_tags != NULL) + { + quic_callPlugins(a_quic_stream, pstream, QUIC_SERVER_HELLO_MASK, pstream->threadnum, a_packet); + } + break; + default: + break; + } + } + + return 0; +} + +//frame type->stream->offset->data length +void gquic_proc_unencrypt(struct streaminfo *pstream, struct quic_stream* a_quic_stream, uint32_t pkt_num_len, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 *used_len) +{ + UINT8 frame_type; + UINT32 ret=0; + + while(*used_lenversion > 0 && a_quic_stream->version < 34){ - offset += 1; - } - - while(offset < quic_data_len){ - frame_type = quic_data[offset]; - //offset+=1; - if(!(frame_type & FRAM_SPECIAL)){ - offset += 1; - UINT16 len_reason; - switch(frame_type){ - case PADDING: - return QUIC_FALSE; - break; - case RST_STREAM: - //stream id - offset += 4; - //Byte Offset - offset += 8; - //Error Code - offset += 4; - break; - case CONNECTION_CLOSE: - len_reason = 0; - //Error Code - offset += 4; - //Reason Phrase Length - if (get_remaining_len(quic_data_len, offset) <= 2){ - return QUIC_FALSE; - } - len_reason = a_pntoh16(quic_data, offset); - offset += 2; - //Reason Phrase,If length remaining == len_reason, it is Connection Close - if (get_remaining_len(quic_data_len, offset) == len_reason){ - return QUIC_DATA; - } - break; - case GOAWAY:{ - len_reason = 0; - //Error Code - offset += 4; - //Last Good Stream ID - offset += 4; - //Reason Phrase Length - if (get_remaining_len(quic_data_len, offset) <= 2){ - return QUIC_FALSE; - } - len_reason = a_pntoh16(quic_data, offset); - offset += 2; - //Reason Phrase - offset += len_reason; - } - break; - case WINDOW_UPDATE: - //Stream ID - offset += 4; - //Byte Offset - offset += 8; - break; - case BLOCKED: - //Stream ID - offset += 4; - break; - case STOP_WAITING: - //No longer Entropy after Q034 - if(a_quic_stream->version > 0 && a_quic_stream->version < 34){ - // Send Entropy - offset += 1; - } - //Least Unacked Delta - offset += pkt_num_len; - break; - case PING: //No Payload - default: - return QUIC_FALSE; - break; + while(*used_len < quic_data_len) + { + frame_type = quic_data[*used_len]; + + if(!(frame_type & FRAM_SPECIAL)) + { + ret=gquic_frame_type_control(a_quic_stream, quic_data, quic_data_len, frame_type, pkt_num_len, used_len); + a_quic_stream->fin_flag=QUIC_FALSE; // is_handshake_pkt don't identify QUIC; but function set QUIC_TRUE + if(ret!=QUIC_TRUE) + { + return ret; } - }else{ - if(frame_type & STREAM){ - if(frame_type & STREAM_D){ - len_data = 2; + } + else + { + if(frame_type&STREAM) + { + if(frame_type&STREAM_D) + { + *used_len+=2; } - len_offset = read_offset_len(frame_type); - len_stream = read_stream_len(frame_type); - offset+=1; - offset+=len_stream; - offset+=len_offset; - offset+=len_data; - if (get_remaining_len(quic_data_len, offset) <= 4){ + *used_len+=1; + *used_len+=read_stream_len(frame_type); + *used_len+=read_offset_len(frame_type); + + if((quic_data_len-*used_len)<=4) + { return QUIC_FALSE; } - UINT32 message_tag; - strncpy((char*)&message_tag, quic_data+offset, 4); - if(ntohl(message_tag) == CHLO || ntohl(message_tag) == SHLO || ntohl(message_tag) == REJ){ + + strncpy((char*)&message_tag, quic_data+*used_len, 4); + if(ntohl(message_tag)==CHLO || ntohl(message_tag)==SHLO || ntohl(message_tag)==REJ) + { return QUIC_TRUE; } - }else if(frame_type & ACK){ - offset+=1; - len_largest_observed = read_largest_observed_len(frame_type); - len_missing_packet = read_missing_packet_len(frame_type); - //No longer Entropy after Q034 - if(a_quic_stream->version < 34 && a_quic_stream->version > 0){ - //Send Entropy - offset += 1; - offset += len_largest_observed; - offset += 2; //ack delay time - if(get_remaining_len(quic_data_len, offset) <= 1){ - return QUIC_FALSE; - } - strncpy((char*)&num_timestamp, quic_data+offset,1); - offset += 1; - if(num_timestamp > 0){ - offset += 1; - offset += 4; //first timestamp - offset += (num_timestamp - 1)*(1+2); - } - if(frame_type & ACK_N){ - //Num Ranges - if (get_remaining_len(quic_data_len, offset) <= 1){ - return QUIC_FALSE; - } - strncpy((char*)&num_ranges, quic_data+offset,1); - offset += 1; - - //Num Range x (Missing Packet + Range Length) - offset += num_ranges*(len_missing_packet+1); - - //Num Revived - if (get_remaining_len(quic_data_len, offset) <= 1){ - return QUIC_FALSE; - } - strncpy((char*)&num_revived, quic_data+offset,1); - offset += 1; - //Num Revived x Length Largest Observed - offset += num_revived*len_largest_observed; - } - }else{ - //Largest Acked - offset += len_largest_observed; - //Largest Acked Delta Time - offset += 2; - //Ack Block - if(frame_type & ACK_N){ - if (get_remaining_len(quic_data_len, offset) <= 1){ - return QUIC_FALSE; - } - strncpy((char*)&num_blocks, quic_data+offset,1); - offset += 1; - } - //First Ack Block Length - offset += len_missing_packet; - if(num_blocks){ - //Gap to next block - offset += 1; - num_blocks -= 1; - offset += (num_blocks - 1)*len_missing_packet; - } - //Timestamp - if (get_remaining_len(quic_data_len, offset) <= 1){ - return QUIC_FALSE; - } - strncpy((char*)&num_timestamp, quic_data+offset,1); - offset += 1; - if(num_timestamp > 0){ - //Delta Largest Acked - offset += 1; - //Time Since Largest Acked - offset += 4; - //Num Timestamp x (Delta Largest Acked + Time Since Previous Timestamp) - offset += (num_timestamp - 1)*(1+2); - } - } - }else{ - offset +=1; + } + else if(frame_type&ACK) + { + gquic_frame_type_ack(a_quic_stream, quic_data, quic_data_len, frame_type, used_len); + } + else + { + *used_len +=1; return QUIC_FALSE; } } } + return QUIC_FALSE; } -void gquic_proc_tag(struct streaminfo *pstream, struct quic_stream *a_quic_stream, UINT16 tag_num, UINT8 direction, - unsigned long long region_flag, int thread_seq, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 g_pos_t){ - UINT32 total_tag_len = 0, tag_len = 0; - UINT32 tag_value_start = tag_num * 4 * 2 + g_pos_t; - UINT32 tag_offset_end = 0, pre_tag_offset_end = 0; - UCHAR return_val; - int tag_type_len = 4, tag_offset_len = 4, num = 0; - - - while(tag_num > 0 && a_canRead(tag_type_len + tag_offset_len, quic_data_len, g_pos_t)){ - UINT32 tag_type; - if(!a_canRead(tag_type_len, quic_data_len, g_pos_t)){ - return; - } - - tag_type = a_pntoh32(quic_data, g_pos_t); - g_pos_t += 4; - if(!a_canRead(tag_type_len, quic_data_len, g_pos_t)){ - return; - } - tag_offset_end = a_pletoh32(quic_data, g_pos_t); - if(tag_offset_end < pre_tag_offset_end){ - return; - } - if(tag_offset_end >= quic_data_len) { - return ; - } - g_pos_t += 4; - tag_len = tag_offset_end - pre_tag_offset_end; - if(!a_canRead(tag_len, quic_data_len, tag_value_start)){ - return ; - } - total_tag_len += tag_len; - if(tag_len == 0){ - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; - continue; - } - if(tag_type == TAG_PAD){ - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; - continue; - } - //common_cert - if(tag_type == TAG_CCS){ - if(a_quic_stream->common_cert.ptr_value == NULL){ - a_quic_stream->common_cert.ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*tag_len); - memset(a_quic_stream->common_cert.ptr_value, 0, tag_len); - a_quic_stream->common_cert.length = tag_len; - memcpy(a_quic_stream->common_cert.ptr_value, quic_data + tag_value_start, tag_len); - if(a_quic_stream->common_cert.ptr_value != NULL){ - return_val = quic_proc_interest_region(QUIC_COMM_CERT_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - } - } - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; - continue; - } - //cached_cert - if(tag_type == TAG_CCRT){ - if(a_quic_stream->cached_cert.ptr_value == NULL){ - a_quic_stream->cached_cert.ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*tag_len); - memset(a_quic_stream->cached_cert.ptr_value, 0, tag_len); - a_quic_stream->cached_cert.length = tag_len; - memcpy(a_quic_stream->cached_cert.ptr_value, quic_data + tag_value_start, tag_len); - if(a_quic_stream->cached_cert.ptr_value != NULL){ - return_val = quic_proc_interest_region(QUIC_CACHED_CERT_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - } - } - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; - continue; - } - //cert_chain?????length need change - if(tag_type == TAG_CRT){ - if(a_quic_stream->cert_chain.length == 0 && a_quic_stream->cert_chain.ptr_value == NULL){ - a_quic_stream->cert_chain.length = tag_len > (quic_data_len-tag_value_start+1) ? (quic_data_len-tag_value_start+1) : tag_len; - a_quic_stream->cert_chain.ptr_value = (char *)dictator_malloc(thread_seq, a_quic_stream->cert_chain.length); - memset(a_quic_stream->cert_chain.ptr_value, 0, a_quic_stream->cert_chain.length); - memcpy(a_quic_stream->cert_chain.ptr_value, quic_data + tag_value_start, a_quic_stream->cert_chain.length); - tag_num--; - tag_value_start += a_quic_stream->cert_chain.length; - pre_tag_offset_end = tag_offset_end; - if(a_quic_stream->cert_chain.ptr_value != NULL){ - return_val = quic_proc_interest_region(QUIC_CERT_CHAIN_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - } - }else{ - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; - } - continue; - } - if(tag_type == TAG_SNI){ - if(a_quic_stream->st_client_hello.server_name_len ==0){ - assert(tag_len < SERVER_NAME_LEN); - a_quic_stream->st_client_hello.server_name_len = tag_len > SERVER_NAME_LEN ? SERVER_NAME_LEN : tag_len; - strncpy(a_quic_stream->st_client_hello.server_name, quic_data + tag_value_start, tag_len); - a_quic_stream->st_client_hello.server_name_len = tag_len; -// printf("SNI:%s\n",a_quic_stream->st_client_hello.server_name); - } - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; - continue; - } - if(tag_type == TAG_UAID){ - assert(tag_len < USER_AGENT_LEN); - if(a_quic_stream->st_client_hello.user_agent_len==0){ - a_quic_stream->st_client_hello.user_agent_len = tag_len > USER_AGENT_LEN ? USER_AGENT_LEN : tag_len; - strncpy(a_quic_stream->st_client_hello.user_agent, quic_data + tag_value_start, a_quic_stream->st_client_hello.user_agent_len); - -// printf("UA:%s\n",a_quic_stream->st_client_hello.user_agent); - } - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; - continue; - } - - if(direction == 0x01 && num < a_quic_stream->st_client_hello.ext_tag_num){ - a_quic_stream->st_client_hello.ext_tags[num]->type = tag_type; - a_quic_stream->st_client_hello.ext_tags[num]->length = tag_len > MAX_TAG_VALUE_LEN-1 ? tag_len > MAX_TAG_VALUE_LEN-1 : tag_len; - memcpy(a_quic_stream->st_client_hello.ext_tags[num]->ptr_value, quic_data+tag_value_start, a_quic_stream->st_client_hello.ext_tags[num]->length); -// a_readBytes(a_quic_stream->st_client_hello.ext_tags[num]->ptr_value, -// a_quic_stream->st_client_hello.ext_tags[num]->length, quic_data, quic_data_len, &tag_value_start); - ((unsigned char*)(a_quic_stream->st_client_hello.ext_tags[num]->ptr_value))[MAX_TAG_VALUE_LEN-1] = '\0'; - - }else if(num < a_quic_stream->st_server_hello.ext_tag_num){ - a_quic_stream->st_server_hello.ext_tags[num]->type = tag_type; - a_quic_stream->st_server_hello.ext_tags[num]->length = tag_len > MAX_TAG_VALUE_LEN-1 ? tag_len > MAX_TAG_VALUE_LEN-1 : tag_len; - memcpy(a_quic_stream->st_server_hello.ext_tags[num]->ptr_value, quic_data+tag_value_start, a_quic_stream->st_server_hello.ext_tags[num]->length); -// a_readBytes(a_quic_stream->st_server_hello.ext_tags[num]->ptr_value, -// a_quic_stream->st_server_hello.ext_tags[num]->length, quic_data, quic_data_len, &tag_value_start); - ((unsigned char*)(a_quic_stream->st_server_hello.ext_tags[num]->ptr_value))[MAX_TAG_VALUE_LEN-1] = '\0'; - } - num++; - tag_num--; - tag_value_start += tag_len; - pre_tag_offset_end = tag_offset_end; +UINT8 parse_gquic_Q046(struct streaminfo *pstream, void* a_packet, char * payload, uint32_t payload_len, uint32_t *used_len, struct quic_stream* a_quic_stream, uint8_t pub_flags) +{ + uint8_t frame_type; + uint16_t tag_num=0; + uint32_t stream_id, message_tag; + + if(!a_canRead(25, payload_len, *used_len)) + { + return QUIC_RETURN_DROPME; } - g_pos_t = tag_value_start; - return; -} - -//frame type->stream->offset->data length -void gquic_proc_unencrypt(struct streaminfo *pstream, struct quic_stream* a_quic_stream, uint32_t pkt_num_len, - unsigned long long region_flag, int thread_seq, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 g_pos_t){ - UINT8 frame_type, num_timestamp, num_ranges, num_revived, num_blocks; - UINT32 len_largest_observed = 0, len_missing_packet = 0; - - g_pos_t += MSG_AUTH_HASH_LEN; - //private flags - if(a_quic_stream->version <34){ - g_pos_t += 1; - } - while(g_pos_t < quic_data_len){ - a_readUInt8(&frame_type, quic_data, quic_data_len, &g_pos_t); - if(!(frame_type & FRAM_SPECIAL)){ - g_pos_t += 1; - UINT16 len_reason; - switch(frame_type){ - case PADDING: - return; - break; - case RST_STREAM: - //stream id - g_pos_t += 4; - //Byte Offset - g_pos_t += 8; - //Error Code - g_pos_t += 4; - a_quic_stream->fin_flag = QUIC_TRUE; - break; - case CONNECTION_CLOSE: - len_reason = 0; - //Error Code - g_pos_t += 4; - //Reason Phrase Length - len_reason = a_pntoh16(quic_data, g_pos_t); - g_pos_t += 2; - //Reason Phrase,If length remaining == len_reason, it is Connection Close - if (get_remaining_len(quic_data_len, g_pos_t) == len_reason){ - return; - } - if(a_quic_stream->fin_flag == QUIC_FALSE){ - a_quic_stream->fin_flag = QUIC_HALF_CLOSE; - }else{ - a_quic_stream->fin_flag = QUIC_TRUE; - } - break; - case GOAWAY:{ - len_reason = 0; - //Error Code - g_pos_t += 4; - //Last Good Stream ID - g_pos_t += 4; - //Reason Phrase Length - len_reason = a_pntoh16(quic_data, g_pos_t); - g_pos_t += 2; - //Reason Phrase - g_pos_t += len_reason; - } - break; - case WINDOW_UPDATE: - //Stream ID - g_pos_t += 4; - //Byte Offset - g_pos_t += 8; - break; - case BLOCKED: - //Stream ID - g_pos_t += 4; - break; - case STOP_WAITING: - //No longer Entropy after Q034 - if(a_quic_stream->version < 34){ - // Send Entropy - g_pos_t += 1; - } - //Least Unacked Delta - g_pos_t += pkt_num_len; - break; - case PING: //No Payload - default: - return; - break; - } - }else{ - //special packet - if(frame_type & STREAM){ - UINT8 len_data = 0, len_stream = 0, len_offset = 0, return_val; - UINT16 tag_num = 0; - UINT32 stream_id, message_tag; - if(frame_type & STREAM_F){ - a_quic_stream->fin_flag = QUIC_TRUE; - } - if(frame_type & STREAM_D){ - len_data = 2; - } - len_stream = read_stream_len(frame_type); - stream_id = get_stream_id(quic_data, g_pos_t, len_stream); - g_pos_t += len_stream; - - len_offset = read_offset_len(frame_type); - g_pos_t += len_offset; - - g_pos_t += len_data; - //handshake - if(stream_id == 1){ - message_tag = a_pntoh32((void *)quic_data, g_pos_t); - g_pos_t += 4; - tag_num = a_pletoh16(quic_data, g_pos_t); - g_pos_t += 2; //tag_num - g_pos_t += 2; //padding - switch(message_tag){ - case CHLO: - //MTAG_CHLO; - if(a_quic_stream->st_client_hello.ext_tags == NULL){ -// a_quic_stream->st_client_hello = (struct quic_client_hello*)dictator_malloc(thread_seq,sizeof(struct quic_client_hello)); -// memset(a_quic_stream->st_client_hello, 0, sizeof(struct quic_client_hello)); - quic_init_clientHello(&a_quic_stream->st_client_hello, tag_num, thread_seq); - }else if(a_quic_stream->st_server_hello.ext_tag_num){ - if(tag_num > a_quic_stream->st_client_hello.ext_tag_num){ -// a_quic_stream->is_0rtt = QUIC_TRUE; - quic_release_clientHello(thread_seq, &a_quic_stream->st_client_hello); - quic_init_clientHello(&a_quic_stream->st_client_hello, tag_num, thread_seq); - }else{ - return; - } - }else{ - return; + + *used_len += 25; + + while(*used_len < payload_len) + { + a_readUInt8(&frame_type, payload, payload_len, used_len); + if(frame_type & STREAM) + { + stream_id=get_stream_id(pstream, payload, frame_type, used_len); + if(stream_id==1) + { + message_tag = a_pntoh32((void *)payload, *used_len); + *used_len += 4; + tag_num = a_pletoh16(payload, *used_len); + *used_len += 2; //tag_num + *used_len += 2; //padding + switch(message_tag) + { + case CHLO: //MTAG_CHLO; + if(a_quic_stream->st_client_hello.ext_tags==NULL && tag_num>0) + { + a_quic_stream->st_client_hello.ext_tags=(quic_tlv_t **)dictator_malloc(pstream->threadnum, tag_num*sizeof(quic_tlv_t*)); + a_quic_stream->st_client_hello.ext_tag_num = tag_num; } - gquic_proc_tag(pstream, a_quic_stream, tag_num, C2S, region_flag, thread_seq, a_packet, quic_data, quic_data_len, g_pos_t); - if(a_quic_stream->st_client_hello.server_name_len > 0 || a_quic_stream->st_client_hello.user_agent_len > 0){ - quic_proc_interest_region(QUIC_CLIENT_HELLO_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); + + gquic_proc_tag(pstream, a_quic_stream, tag_num, C2S, a_packet, payload, payload_len, used_len); + + if(a_quic_stream->st_client_hello.server_name_len > 0 || a_quic_stream->st_client_hello.user_agent_len > 0) + { + quic_callPlugins(a_quic_stream, pstream, QUIC_CLIENT_HELLO_MASK, pstream->threadnum, a_packet); } - -// if(return_val != QUIC_RETURN_NORM){ -// return return_val; -// } - break; - case SHLO: - //MTAG_SHLO; - if(a_quic_stream->st_server_hello.ext_tags == NULL){ -// a_quic_stream->st_server_hello = (struct quic_server_hello*)dictator_malloc(thread_seq,sizeof(struct quic_server_hello)); -// memset(a_quic_stream->st_server_hello, 0, sizeof(struct quic_server_hello)); - quic_init_serverHello(&a_quic_stream->st_server_hello, tag_num, thread_seq); - }else{ - return; - } - gquic_proc_tag(pstream, a_quic_stream, tag_num, S2C, region_flag, thread_seq, a_packet, quic_data, quic_data_len, g_pos_t); - - if(a_quic_stream->st_server_hello.ext_tags != NULL){ - quic_proc_interest_region(QUIC_SERVER_HELLO_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - } -// if(return_val != QUIC_RETURN_NORM){ -// return return_val; -// } - break; - case REJ: - //MTAG_REJ; - if(a_quic_stream->st_server_hello.ext_tags == NULL){ -// a_quic_stream->st_server_hello = (struct quic_server_hello*)dictator_malloc(thread_seq,sizeof(struct quic_server_hello)); -// memset(a_quic_stream->st_server_hello, 0, sizeof(struct quic_server_hello)); - quic_init_serverHello(&a_quic_stream->st_server_hello, tag_num, thread_seq); - }else{ - return; - } - gquic_proc_tag(pstream, a_quic_stream, tag_num, S2C, region_flag, thread_seq, a_packet, quic_data, quic_data_len, g_pos_t); - if(a_quic_stream->st_server_hello.ext_tags != NULL){ - quic_proc_interest_region(QUIC_SERVER_HELLO_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - } -// if(return_val != QUIC_RETURN_NORM){ -// return return_val; -// } break; default: break; - } - } - }else if(frame_type & ACK){ - g_pos_t+=1; - len_largest_observed = read_largest_observed_len(frame_type); - len_missing_packet = read_missing_packet_len(frame_type); - //No longer Entropy after Q034 - if(a_quic_stream->version < 34){ - //Send Entropy - g_pos_t += 1; - g_pos_t += len_largest_observed; - g_pos_t += 2; //ack delay time - strncpy((char*)&num_timestamp, quic_data+g_pos_t,1); - g_pos_t += 1; - if(num_timestamp > 0){ - g_pos_t += 1; - g_pos_t += 4; - g_pos_t += (num_timestamp - 1)*(1+2); - } - if(frame_type & ACK_N){ - strncpy((char*)&num_ranges, quic_data+g_pos_t,1); - g_pos_t += 1; - g_pos_t += num_ranges*(len_missing_packet+1); - strncpy((char*)&num_revived, quic_data+g_pos_t,1); - g_pos_t += 1; - //Num Revived x Length Largest Observed - g_pos_t += num_revived*len_largest_observed; - } - }else{ - //Largest Acked - g_pos_t += len_largest_observed; - //Largest Acked Delta Time - g_pos_t += 2; - //Ack Block - if(frame_type & ACK_N){ - strncpy((char*)&num_blocks, quic_data+g_pos_t,1); - g_pos_t += 1; - } - //First Ack Block Length - g_pos_t += len_missing_packet; - if(num_blocks){ - //Gap to next block - g_pos_t += 1; - num_blocks -= 1; - g_pos_t += (num_blocks - 1)*len_missing_packet; - } - //Timestamp - strncpy((char*)&num_timestamp, quic_data+g_pos_t,1); - g_pos_t += 1; - if(num_timestamp > 0){ - //Delta Largest Acked - g_pos_t += 1; - //Time Since Largest Acked - g_pos_t += 4; - //Num Timestamp x (Delta Largest Acked + Time Since Previous Timestamp) - g_pos_t += (num_timestamp - 1)*(1+2); - } - } - }else{ - g_pos_t +=1; - return; - } - } - } - return; -} - -UINT8 parse_gquic_Q046(struct streaminfo *pstream, unsigned long long region_flag, void* a_packet, - int thread_seq, char * payload, uint32_t payload_len, struct quic_stream* a_quic_stream){ - uint32_t g_pos_t = 0; - if (!a_canRead(5, payload_len, g_pos_t)) { - return QUIC_RETURN_DROPME; - } - uint32_t version; - g_pos_t += 1; - strncpy((char*)&version, payload+g_pos_t, 4); - if(ntohl(version) != VER_Q046){ - return QUIC_RETURN_DROPME; - } - g_pos_t += 2; - a_quic_stream->version = (payload[g_pos_t] & 0x0f) * 10 + (payload[g_pos_t+1] & 0x0f); - a_quic_stream->is_quic_stream = QUIC_TRUE; - quic_proc_interest_region(QUIC_VERSION_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - g_pos_t += 2; - if (!a_canRead(25, payload_len, g_pos_t)) { - return QUIC_RETURN_DROPME; - } - g_pos_t += 25; - uint8_t frame_type; - while(g_pos_t < payload_len){ - a_readUInt8(&frame_type, payload, payload_len, &g_pos_t); - if(frame_type & STREAM){ - uint8_t len_data = 0, len_stream = 0, len_offset = 0; - uint16_t tag_num = 0; - uint32_t stream_id, message_tag; - if(frame_type & STREAM_D){ - len_data = 2; - } - len_stream = read_stream_len(frame_type); - stream_id = get_stream_id(payload, g_pos_t, len_stream); - g_pos_t += len_stream; - - len_offset = read_offset_len(frame_type); - g_pos_t += len_offset; - - g_pos_t += len_data; - if(stream_id == 1){ - message_tag = a_pntoh32((void *)payload, g_pos_t); - g_pos_t += 4; - tag_num = a_pletoh16(payload, g_pos_t); - g_pos_t += 2; //tag_num - g_pos_t += 2; //padding - char sni[1024]; - uint32_t sni_len = 0; - char uaid[1024]; - uint32_t uaid_len = 0; - switch(message_tag){ - case CHLO: - //MTAG_CHLO; - if(a_quic_stream->st_client_hello.ext_tags == NULL){ - quic_init_clientHello(&a_quic_stream->st_client_hello, tag_num, thread_seq); - } - gquic_proc_tag(pstream, a_quic_stream, tag_num, C2S, region_flag, thread_seq, a_packet, payload, payload_len, g_pos_t); - if(a_quic_stream->st_client_hello.server_name_len > 0 || a_quic_stream->st_client_hello.user_agent_len > 0){ - quic_proc_interest_region(QUIC_CLIENT_HELLO_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - } -// *chello = (struct quic_pme *)malloc(sizeof(struct quic_pme) + sni_len + uaid_len + 2); -// memset(*chello, 0, sizeof(struct quic_pme) + sni_len + uaid_len + 2); - -// *chello = (struct quic_pme *)malloc(sizeof(struct quic_pme)); -// memset(*chello, 0, sizeof(struct quic_pme)); - - -// if(sni_len > 128){ -// sni_len = GQUIC_SNI_LEN; -// } -// a_quic_stream->st_client_hello->server_name_len = sni_len; -// memcpy((chello)->sni, sni, sni_len); -// (chello)->sni[127] = '\0'; -// if(uaid_len > 512){ -// uaid_len = GQUIC_UAID_LEN; -// } -// (chello)->user_agent_len = uaid_len; -// memcpy((chello)->user_agent, uaid, uaid_len); -// (chello)->user_agent[511] = '\0'; - -// char * p, *q; -// p = (char*)(*chello) + sizeof(struct quic_pme); -// q = (char*)(*chello) + sizeof(struct quic_pme) + sni_len + 1; -// memcpy(p, sni, sni_len); -// memset(p+sni_len, '\0', 1); -// (*chello)->sni = p; -// memcpy(q, uaid, uaid_len); -// memset(q+uaid_len, '\0', 1); -// (*chello)->user_agent = q; -// printf("46 chello_sni_len:%d, chello_sni:%s\n",(*chello)->sni_len, (*chello)->sni); -// printf("46 chello_uaid_len:%d, chello_uaid:%s\n",(*chello)->user_agent_len, (*chello)->user_agent); - break; - default: - break; } } } } + return QUIC_RETURN_NORM; } -UINT8 parse_gquic(struct streaminfo *pstream, unsigned long long region_flag, void* a_packet, - int thread_seq, char * payload, uint32_t payload_len, struct quic_stream* a_quic_stream){ - uint8_t pub_flags = 0; - uint8_t nonce_flag = 0; - uint8_t reset_flag = 0; - uint8_t version_flag = 0; - int ret = QUIC_RETURN_DROPME; - uint32_t g_pos_t = 0; - uint64_t connection_id = 0; - int connection_id_len = 0; - uint32_t pkt_num = 0; +UINT8 parse_gquic(struct streaminfo *pstream, void* a_packet, char * payload, uint32_t payload_len, uint32_t *used_len, struct quic_stream* a_quic_stream, uint8_t pub_flags) +{ + int is_handshake=0; uint32_t pkt_num_len = 0; - uint32_t version; - strncpy((char *)&pub_flags, payload + g_pos_t, 1); - g_pos_t += 1; - if (pub_flags > PACKET_PUBLIC_FLAGS_MAX) { - return QUIC_RETURN_DROPME; - } - nonce_flag = (pub_flags & PUBLIC_FLAG_NONCE) != 0; - reset_flag = (pub_flags & PUBLIC_FLAG_RST) != 0; - version_flag = (pub_flags & PUBLIC_FLAG_VER) != 0; - if (reset_flag && version_flag) { - return QUIC_RETURN_DROPME; - } - if(reset_flag){ - return QUIC_RETURN_DROPME; - } - connection_id_len = read_conn_id_len(pub_flags); - if(connection_id_len == -1){ - return QUIC_RETURN_DROPME; - }else if(connection_id_len == 0){ - connection_id = 0; - }else{ - if (!a_canRead(connection_id_len, payload_len, g_pos_t)) { - return QUIC_RETURN_DROPME; - } - connection_id = a_pntoh64((void *)payload, g_pos_t); - g_pos_t += connection_id_len; - } - pkt_num_len = read_seq_num_len(pub_flags); - if (!a_canRead(VERSION_LEN, payload_len, g_pos_t)) { - return QUIC_RETURN_DROPME; - } - if(payload[g_pos_t] != PUBLIC_FLAG_VER_FST_BYTE){ - return QUIC_RETURN_DROPME; - } - g_pos_t += 2; - version = (payload[g_pos_t] & 0x0f) * 10 + (payload[g_pos_t+1] & 0x0f); - a_quic_stream->version = version; - quic_proc_interest_region(QUIC_VERSION_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - - g_pos_t += 2; - if (!a_canRead(pkt_num_len, payload_len, g_pos_t)) { - return QUIC_RETURN_DROPME; - } - pkt_num = get_pkn(payload, g_pos_t, pkt_num_len); - g_pos_t += pkt_num_len; + uint32_t skip_len=0; + + pkt_num_len=read_seq_num_len(pub_flags); + //version 协商 - if(!version_flag && a_quic_stream->version && !a_quic_stream->version_cfm){ + if(!(PUBLIC_FLAG_VER&pub_flags!=0) && a_quic_stream->version && !a_quic_stream->version_cfm) + { a_quic_stream->version_cfm = QUIC_TRUE; - quic_proc_interest_region(QUIC_VERSION_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); + quic_callPlugins(a_quic_stream, pstream, QUIC_VERSION_MASK, pstream->threadnum, a_packet); + MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_DEBUG, "QUIC_VERSION", "version: %u addr: %s", a_quic_stream->version, printaddr(&pstream->addr, pstream->threadnum)); } - ret = is_handshake_pkt(a_quic_stream, pkt_num_len, payload, payload_len, g_pos_t); - if(ret == QUIC_TRUE){ - //handshake - if(!a_quic_stream->is_quic_stream){ + skip_len=*used_len; + is_handshake=is_handshake_pkt(a_quic_stream, pkt_num_len, payload, payload_len, &skip_len); // just identify + switch(is_handshake) + { + case QUIC_TRUE: //handshake a_quic_stream->is_quic_stream = QUIC_TRUE; - } - gquic_proc_unencrypt(pstream, a_quic_stream, pkt_num_len, region_flag, thread_seq, a_packet, payload, payload_len, g_pos_t); - ret = QUIC_RETURN_NORM; - }else if(ret == QUIC_DATA){ - //ack or special stream - a_quic_stream->is_quic_stream = QUIC_TRUE; - ret = QUIC_RETURN_NORM; - }else{ - //gquic data or not gquic packet - if(a_quic_stream->is_quic_stream){ - quic_proc_interest_region(QUIC_APPLICATION_DATA_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - ret = QUIC_RETURN_NORM; - }else{ - ret = QUIC_RETURN_DROPME; - } + gquic_proc_unencrypt(pstream, a_quic_stream, pkt_num_len, a_packet, payload, payload_len, used_len); + break; + case QUIC_DATA: //ack or special stream + a_quic_stream->is_quic_stream = QUIC_TRUE; + break; + default: //gquic data or not gquic packet + if(!a_quic_stream->is_quic_stream) + { + return QUIC_RETURN_DROPME; + } + + quic_callPlugins(a_quic_stream, pstream, QUIC_APPLICATION_DATA_MASK, pstream->threadnum, a_packet); + break; } - return ret; + + return QUIC_RETURN_NORM; } - - //cid->version->nounce->pkt num->ahn hash(12) -UINT8 gquic_process(struct streaminfo *pstream, struct quic_stream* a_quic_stream, - unsigned long long region_flag, int thread_seq, void* a_packet, char* quic_data, UINT32 quic_data_len) { +UINT8 gquic_process(struct streaminfo *pstream, struct quic_stream* a_quic_stream, int thread_seq, void* a_packet) +{ + uint8_t pub_flags = 0; + uint32_t used_len = 0; + int ret=QUIC_RETURN_DROPME; + enum GQUIC_VERSION is_gquic=GQUIC_UNKNOWN; + struct udpdetail *udp_detail=(struct udpdetail *)pstream->pdetail; - int ret = parse_gquic(pstream, region_flag, a_packet, thread_seq, quic_data, quic_data_len, a_quic_stream); - if(ret == QUIC_RETURN_DROPME){ - ret = parse_gquic_Q046(pstream, region_flag, a_packet, thread_seq, quic_data, quic_data_len, a_quic_stream); + if(!a_quic_stream->is_quic_stream && udp_detail->datalen<=GQUIC_HEADER_LEN) + { + MESA_handle_runtime_log(g_quic_param.logger, + RLOG_LV_DEBUG, + "QUIC", + "This is not quic (!a_quic_stream->is_quic_stream)=%d, or packet length is litter udp_detail->datalen<=GQUIC_HEADER_LEN(%d<=%d) addr: %s", + !a_quic_stream->is_quic_stream, + udp_detail->datalen, + GQUIC_HEADER_LEN, + printaddr(&pstream->addr, thread_seq)); + return QUIC_RETURN_DROPME; } + + if(udp_detail->pdata==NULL || udp_detail->datalen<=0) + { + return QUIC_RETURN_NORM; + } + + is_gquic=is_gquic_protocol(pstream, (char *)udp_detail->pdata, udp_detail->datalen, &pub_flags, &a_quic_stream->version, &used_len); + if(is_gquic!=GQUIC_UNKNOWN) + { + a_quic_stream->is_quic_stream=QUIC_TRUE; + quic_callPlugins(a_quic_stream, pstream, QUIC_VERSION_MASK, thread_seq, a_packet); + + switch(is_gquic) + { + case GQUIC_OTHERS: + ret=parse_gquic(pstream, a_packet, (char *)udp_detail->pdata, udp_detail->datalen, &used_len, a_quic_stream, pub_flags); + break; + case GQUIC_Q046: + ret=parse_gquic_Q046(pstream, a_packet, (char *)udp_detail->pdata, udp_detail->datalen, &used_len, a_quic_stream, pub_flags); + break; + default: + break; + } + } + + if(a_quic_stream->is_quic_stream==QUIC_TRUE) + { + return QUIC_RETURN_NORM; + } + return ret; - -/* - - UINT8 pub_flags; - UCHAR return_val = QUIC_RETURN_NORM; - UINT32 g_pos_t = 0; - strncpy((char *)&pub_flags, quic_data + g_pos_t, 1); - g_pos_t += 1; - if (pub_flags > PACKET_PUBLIC_FLAGS_MAX) { - return QUIC_RETURN_DROPME; - } - struct gquic_pkt_hdr gquic_hdr = {}; - memset(&gquic_hdr, 0, sizeof(struct gquic_pkt_hdr)); - gquic_hdr.nonce_flag = (pub_flags & PUBLIC_FLAG_NONCE) != 0; - gquic_hdr.reset_flag = (pub_flags & PUBLIC_FLAG_RST) != 0; - gquic_hdr.version_flag = (pub_flags & PUBLIC_FLAG_VER) != 0; - if (gquic_hdr.reset_flag && gquic_hdr.version_flag) { - return QUIC_RETURN_DROPME; - } - if(gquic_hdr.reset_flag){ - return QUIC_RETURN_DROPME; - } - gquic_hdr.connection_id_len = read_conn_id_len(pub_flags); - if(gquic_hdr.connection_id_len == -1){ - return QUIC_RETURN_DROPME; - }else if(gquic_hdr.connection_id_len == 0){ - gquic_hdr.connection_id = 0; - }else{ - if (!a_canRead(gquic_hdr.connection_id_len, quic_data_len, g_pos_t)) { - return QUIC_RETURN_DROPME; - } - if(a_quic_stream->gquic_cID == 0){ - gquic_hdr.connection_id = a_pntoh64((void *)quic_data, g_pos_t); - a_quic_stream->gquic_cID = gquic_hdr.connection_id; - } - - g_pos_t+=gquic_hdr.connection_id_len; - } - if(gquic_hdr.nonce_flag && pstream->curdir == 0x02){ - g_pos_t+=DIVERSIFICATION_NONCE_LEN; - } - gquic_hdr.packet_number_len = read_seq_num_len(pub_flags); - if (gquic_hdr.version_flag) { - //c2s - if(pstream->curdir == 0x01){ - if (!a_canRead(4, quic_data_len, g_pos_t)) { - return QUIC_RETURN_DROPME; - } - if(quic_data[g_pos_t] != PUBLIC_FLAG_VER_FST_BYTE){ - return QUIC_RETURN_DROPME; - } - g_pos_t += 2; - a_quic_stream->version_flag = QUIC_TRUE; - gquic_hdr.version = (quic_data[g_pos_t] & 0x0f) * 10 + (quic_data[g_pos_t+1] & 0x0f); - g_pos_t += 2; - a_quic_stream->version = gquic_hdr.version; - printf("VERSION:%d\n",a_quic_stream->version); - } - } - - if(!gquic_hdr.version_flag && pstream->curdir == 0x02 && a_quic_stream->version_flag == QUIC_TRUE){ - a_quic_stream->version_flag = QUIC_FALSE; - return_val = quic_proc_interest_region(QUIC_VERSION_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); -// if(return_val != QUIC_RETURN_NORM){ -// char info[256]; -// sprintf(info, "VERSION CALLBACK ERROR\t%s_%s_%d\t", __FILE__, __FUNCTION__, __LINE__); -// printf("%s\n", info); -// return return_val; -// } - } - if(!a_canRead(gquic_hdr.packet_number_len, quic_data_len, g_pos_t)){ - return QUIC_RETURN_DROPME; - } - UINT32 pkt_num = get_pkn(quic_data, g_pos_t, gquic_hdr.packet_number_len); - gquic_hdr.packet_number = pkt_num; - g_pos_t += gquic_hdr.packet_number_len; - - char sip[32],dip[32]; - memset(sip, 0, sizeof(sip)); - memset(dip, 0, sizeof(dip)); - a_ntoa(pstream->addr.tuple4_v4->saddr, sip); - a_ntoa(pstream->addr.tuple4_v4->daddr, dip); - - return_val = is_handshake_pkt(a_quic_stream, &gquic_hdr, quic_data, quic_data_len, g_pos_t); - if(return_val == QUIC_TRUE){ - //handshake - if(!a_quic_stream->is_quic_stream){ - a_quic_stream->is_quic_stream = QUIC_TRUE; - } - gquic_proc_unencrypt(pstream, &gquic_hdr, a_quic_stream, region_flag, thread_seq, a_packet, quic_data, quic_data_len, g_pos_t); - return_val = QUIC_RETURN_NORM; - }else if(return_val == QUIC_DATA){ - //ack or special stream - if(!a_quic_stream->is_quic_stream){ - a_quic_stream->is_quic_stream = QUIC_TRUE; - } - }else{ - //gquic data or not gquic packet - if(a_quic_stream->is_quic_stream){ - return_val = quic_proc_interest_region(QUIC_APPLICATION_DATA_MASK, &a_quic_stream, pstream, region_flag, thread_seq, a_packet); - }else{ - return_val = QUIC_RETURN_DROPME; - } - } - -// if(a_quic_stream->type == GQUIC){ -// if(pstream->curdir == 0x01){ -// printf("QUIC\tC2S\tSIP=%s\tDIP=%s\tPKN=%d\tVERSION=%d\tthread_seq=%d\n",sip,dip,pkt_num,gquic_hdr.version,thread_seq); -// }else{ -// printf("QUIC\tS2C\tSIP=%s\tDIP=%s\tPKN=%d\tVERSION=%d\tthread_seq=%d\n",sip,dip,pkt_num,gquic_hdr.version,thread_seq); -// } -// } -// else{ -// if(pstream->curdir == 0x01){ -// printf("UNKN\tC2S\tSIP=%s\tDIP=%s\tPKN=%d\tVERSION=%d\tthread_seq=%d\n",sip,dip,pkt_num,gquic_hdr.version,thread_seq); -// }else{ -// printf("UNKN\tS2C\tSIP=%s\tDIP=%s\tPKN=%d\tVERSION=%d\tthread_seq=%d\n",sip,dip,pkt_num,gquic_hdr.version,thread_seq); -// } -// } - return return_val; - */ } -UINT32 read_offset_len(UINT8 frame_type){ - switch((frame_type & STREAM_OOO) >> 2){ +UINT32 read_offset_len(UINT8 frame_type) +{ + switch((frame_type&STREAM_OOO)>>2) + { case 0: return 0; - break; + break; case 1: return 2; - break; + break; case 2: return 3; - break; + break; case 3: return 4; - break; + break; case 4: return 5; - break; + break; case 5: return 6; - break; + break; case 6: return 7; - break; + break; case 7: return 8; - break; + break; default: - break; + break; } + return 0; } -UINT32 read_stream_len(UINT8 frame_type){ +UINT32 read_stream_len(UINT8 frame_type) +{ UINT32 stream_len = 0; - switch(frame_type & STREAM_SS){ + switch(frame_type&STREAM_SS) + { case STREAM_ID_1BYTE: stream_len = 1; break; @@ -984,99 +814,87 @@ UINT32 read_stream_len(UINT8 frame_type){ default: break; } + return stream_len; } -int read_conn_id_len(UINT8 flags) { - switch (flags & BYTE_CNTID_8) { +int read_conn_id_len(UINT8 flags) +{ + switch (flags&BYTE_CNTID_8) + { case BYTE_CNTID_8: return 8; case BYTE_CNTID_0: return 0; default: - return -1; + return 0; // modify by liuxueli 20200522 + //return -1; } } -UINT32 read_seq_num_len(UINT8 flags) { - switch (flags & PKT_NUM_6) { - case PKT_NUM_6: - return 6; - case PKT_NUM_4: - return 4; - case PKT_NUM_2: - return 2; - case PKT_NUM_1: - return 1; - default: - break; - } +UINT32 read_seq_num_len(UINT8 flags) +{ + switch (flags & PKT_NUM_6) + { + case PKT_NUM_6: + return 6; + case PKT_NUM_4: + return 4; + case PKT_NUM_2: + return 2; + case PKT_NUM_1: + return 1; + default: + break; + } + return 1; } -UINT32 read_largest_observed_len(UINT8 frame_type){ - switch((frame_type & ACK_LL) >> 2){ - case 0: - return 1; - break; - case 1: - return 2; - break; - case 2: - return 4; - break; - case 3: - return 6; - break; - default: - break; - } - return 1; -} - -UINT32 read_missing_packet_len(UINT8 frame_type){ - switch(frame_type & ACK_MM){ - case 0: - return 1; - break; - case 1: - return 2; - break; - case 2: - return 4; - break; - case 3: - return 6; - break; - default: - break; - } - return 1; -} - - - -UINT32 get_stream_id(char* g_data_t, UINT32 offset, UINT8 stream_id_len){ - if(stream_id_len == 1){ - return g_data_t[offset]; - }else if(stream_id_len == 2){ - return a_pletoh16((void *)g_data_t, offset); - }else if(stream_id_len == 3){ - return a_pletoh24((void *)g_data_t, offset); - }else{ - return a_pletoh32((void *)g_data_t, offset); +UINT32 read_largest_observed_len(UINT8 frame_type) +{ + switch((frame_type & ACK_LL) >> 2) + { + case 0: + return 1; + break; + case 1: + return 2; + break; + case 2: + return 4; + break; + case 3: + return 6; + break; + default: + break; } + + return 1; } -UINT32 get_pkn(char* g_data_t, UINT32 offset, UINT8 pkn_len){ - if(pkn_len == 1){ - return g_data_t[offset]; - }else if(pkn_len == 2){ - return a_pletoh16((void *)g_data_t, offset); - }else if(pkn_len == 4){ - return a_pletoh32((void *)g_data_t, offset); - }else{//6 - return a_pletoh48((void *)g_data_t, offset); +UINT32 read_missing_packet_len(UINT8 frame_type) +{ + switch(frame_type & ACK_MM) + { + case 0: + return 1; + break; + case 1: + return 2; + break; + case 2: + return 4; + break; + case 3: + return 6; + break; + default: + break; } + + return 1; } + diff --git a/src/gquic_process.h b/src/gquic_process.h index 5091c2f..b7d3f0c 100644 --- a/src/gquic_process.h +++ b/src/gquic_process.h @@ -196,20 +196,13 @@ struct gquic_pkt_hdr{ -UINT8 gquic_process(struct streaminfo *pstream, struct quic_stream* a_quic_stream, - unsigned long long region_flag, int thread_seq, void* a_packet, char* quic_data, UINT32 quic_data_len); -//UCHAR is_handshake_pkt(struct quic_stream* a_quic_stream, struct gquic_pkt_hdr* gquic_hdr, char * quic_data, UINT32 quic_data_len, UINT32 offset); -//void gquic_proc_unencrypt(struct streaminfo *pstream, struct gquic_pkt_hdr* gquic_hdr, struct quic_stream* a_quic_stream, -// unsigned long long region_flag, int thread_seq, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 g_pos_t); -//UINT8 gquic_proc_tag(struct streaminfo *pstream, struct gquic_pkt_hdr* gquic_hdr, struct quic_stream *a_quic_stream, UINT16 tag_num, UINT8 direction, -// unsigned long long region_flag, int thread_seq, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 g_pos_t); +UINT8 gquic_process(struct streaminfo *pstream, struct quic_stream* a_quic_stream, int thread_seq, void* a_packet); UINT32 read_offset_len(UINT8 frame_type); UINT32 read_stream_len(UINT8 frame_type); UINT32 read_largest_observed_len(UINT8 frame_type); UINT32 read_missing_packet_len(UINT8 frame_type); -UINT32 get_stream_id(char* g_data_t, UINT32 offset, UINT8 stream_id_len); -UINT32 get_pkn(char* g_data_t, UINT32 offset, UINT8 pkn_len); +UINT32 get_stream_id(char* g_data_t, UINT8 frame_type, UINT32 *skip_len); UINT32 read_seq_num_len(UINT8 flags); int read_conn_id_len(UINT8 flags); diff --git a/src/quic_analysis.c b/src/quic_analysis.c index 4dfa502..59cd4bd 100644 --- a/src/quic_analysis.c +++ b/src/quic_analysis.c @@ -9,41 +9,222 @@ #include "gquic_process.h" #include #include - +#include +#include struct quic_param_t g_quic_param; +const char *g_quic_proto_conffile="./conf/quic/main.conf"; +const char *g_quic_regionname_conffile="./conf/quic/quic.conf"; - -int QUIC_INIT(void) +#ifdef __cplusplus +extern "C" { +#endif + +#define GIT_VERSION_CATTER(v) __attribute__((__used__)) const char * GIT_VERSION_##v = NULL +#define GIT_VERSION_EXPEND(v) GIT_VERSION_CATTER(v) + +/* VERSION TAG */ +#ifdef GIT_VERSION +GIT_VERSION_EXPEND(GIT_VERSION); +#else +static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; +#endif +#undef GIT_VERSION_CATTER +#undef GIT_VERSION_EXPEND + +#ifdef __cplusplus +} +#endif + +const char QUIC_VERSION_20200522=0; + + +int quic_init_stream(void **pme, int thread_seq) +{ + struct quic_stream *a_quic_stream=(struct quic_stream *)*pme; + + a_quic_stream=(struct quic_stream *)dictator_malloc(thread_seq, sizeof(struct quic_stream)); + memset(a_quic_stream,0,sizeof(struct quic_stream)); + + a_quic_stream->output_region_flag = g_quic_param.quic_interested_region_flag; + a_quic_stream->output_region_mask = QUIC_INTEREST_KEY_MASK; + + a_quic_stream->is_quic_stream = QUIC_FALSE; + a_quic_stream->version_cfm = QUIC_FALSE; + a_quic_stream->version = 0; + a_quic_stream->link_state = QUIC_FALSE; + a_quic_stream->fin_flag = QUIC_FALSE; + a_quic_stream->business = (struct quic_business_info *)dictator_malloc(thread_seq,sizeof(struct quic_business_info)); + a_quic_stream->business->param = NULL; + a_quic_stream->business->return_value = PROT_STATE_GIVEME; + + *pme = (void*)a_quic_stream; + + return 0; +} + +void quic_release_clientHello(int thread_seq, struct quic_client_hello* st_client_hello) +{ + if(st_client_hello!=NULL) + { + if(st_client_hello->ext_tags!=NULL) + { + quic_release_exts(thread_seq, st_client_hello->ext_tags, st_client_hello->ext_tag_num); + dictator_free(thread_seq, st_client_hello->ext_tags); + st_client_hello->ext_tags = NULL; + } + } + + return; +} + +void quic_release_exts(int thread_seq, quic_tlv_t** ext_tags, UINT16 ext_tag_num) +{ + int i=0; + + if(ext_tags!=NULL) + { + for(i=0; iptr_value != NULL) + { + dictator_free(thread_seq, ext_tags[i]->ptr_value); + ext_tags[i]->ptr_value = NULL; + } + + dictator_free(thread_seq, ext_tags[i]); + ext_tags[i] = NULL; + } + } + + dictator_free(thread_seq, ext_tags); + ext_tags=NULL; + } +} + +void quic_release_stream(struct streaminfo *a_tcp, void** pme, int thread_seq) +{ + struct quic_stream *a_quic_stream = (struct quic_stream *)*pme; + if(NULL!=a_quic_stream) + { + a_quic_stream->fin_flag = QUIC_TRUE; + + if(NULL!=a_quic_stream->business) + { + if(a_quic_stream->business->param!=NULL) + { + dictator_free(thread_seq,a_quic_stream->business->param); + a_quic_stream->business->param = NULL; + } + dictator_free(thread_seq,a_quic_stream->business); + a_quic_stream->business = NULL; + } + if(NULL!=a_quic_stream->cert_chain.ptr_value) + { + dictator_free(thread_seq,a_quic_stream->cert_chain.ptr_value); + a_quic_stream->cert_chain.ptr_value = NULL; + } + if(NULL!=a_quic_stream->common_cert.ptr_value) + { + dictator_free(thread_seq,a_quic_stream->common_cert.ptr_value); + a_quic_stream->common_cert.ptr_value = NULL; + } + if(NULL!=a_quic_stream->cached_cert.ptr_value) + { + dictator_free(thread_seq,a_quic_stream->cached_cert.ptr_value); + a_quic_stream->cached_cert.ptr_value = NULL; + } + + quic_release_exts(thread_seq, a_quic_stream->st_client_hello.ext_tags, a_quic_stream->st_client_hello.ext_tag_num); + quic_release_exts(thread_seq, a_quic_stream->st_server_hello.ext_tags, a_quic_stream->st_server_hello.ext_tag_num); + + dictator_free(thread_seq,a_quic_stream); + a_quic_stream = NULL; + } + + return; +} + +extern "C" int QUIC_INIT(void) +{ + int ret=0,level=30; + char log_path[1024]={0}; + FILE *fp=NULL; + char buf[2048]={0}; + int region_id=0; + char region_name[REGION_NAME_LEN]={0}; + memset(&g_quic_param,0,sizeof(struct quic_param_t)); - strcat(g_quic_param.quic_conf_filename, "./conf/quic/quic.conf"); - if(0!=readconf(g_quic_param.quic_conf_filename)){ + + MESA_load_profile_int_def(g_quic_proto_conffile, "QUIC", "LOG_LEVEL", &level, RLOG_LV_FATAL); + MESA_load_profile_string_def(g_quic_proto_conffile, "QUIC", "LOG_PATH", log_path, sizeof(log_path), "./log/quic/quic"); + + g_quic_param.logger=MESA_create_runtime_log_handle(log_path, level); + if(g_quic_param.logger==NULL) + { + printf("MESA_create_runtime_log_handle failed, level: %d log_path: %s", level, log_path); return -1; } + + if(((fp = fopen(g_quic_regionname_conffile, "r"))!=NULL)) + { + while(fgets(buf, sizeof(buf), fp)) + { + ret = sscanf(buf, "%d\t%s", ®ion_id, region_name); + if(2>ret) + { + fclose(fp); + MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_READCONF", "Read error, Please check %s, region_line: %s", g_quic_regionname_conffile, buf); + return -1; + } + if(region_id>MAX_REGION_NUM) + { + fclose(fp); + MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_READCONF", "Read error, Please check %s, bigger than MAX_REGION_NUM, region_line: %s", g_quic_regionname_conffile, buf); + return -1; + } + + strncpy(g_quic_param.quic_conf_regionname[region_id], region_name, strlen(region_name)); + g_quic_param.quic_region_cnt++; + memset(region_name, 0, sizeof(region_name)); + } + + fclose(fp); + } + else + { + MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_READCONF", "Open %s error, Please check %s", g_quic_regionname_conffile, g_quic_regionname_conffile); + return -1; + } + return 0; }/*QUICINIT*/ -void QUIC_DESTROY(void) +extern "C" void QUIC_DESTROY(void) { return ; }/*QUICDESTROY*/ -void QUIC_GETPLUGID(unsigned short plugid) +extern "C" void QUIC_GETPLUGID(unsigned short plugid) { g_quic_param.quic_plugid = plugid; + MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_GETPLUGID", "quic_plugid: %d", plugid); } -void QUIC_PROT_FUNSTAT(unsigned long long protflag) +extern "C" void QUIC_PROT_FUNSTAT(unsigned long long protflag) { if(0==protflag){ return; } - g_quic_param.quic_interested_region_flag = protflag; + g_quic_param.quic_interested_region_flag=protflag; + MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_PROT_FUNSTAT", "interested_region_flag: %llu", g_quic_param.quic_interested_region_flag); return; }/*PROT_FUNSTAT*/ -unsigned long long quic_getRegionID(char *string, int str_len,const char g_string[MAX_REGION_NUM][REGION_NAME_LEN]) +extern "C" unsigned long long quic_getRegionID(char *string, int str_len,const char g_string[MAX_REGION_NUM][REGION_NAME_LEN]) { unsigned long long i=0; for(i=0;iaddr, thread_seq)); return APP_STATE_DROPME; - default: - break; } - struct quic_stream* a_quic_stream = NULL; + + if(*pme==NULL) + { + quic_init_stream(pme, thread_seq); + a_quic_stream=(struct quic_stream *)*pme; + } + switch(pstream->opstate) { - case OP_STATE_PENDING: - return_val = quic_init_stream(pstream, pme, thread_seq); - if(return_val < 0){ -#ifdef PRINTF - printf("initQuicStream error\n"); -#endif - return APP_STATE_DROPME; - } - case OP_STATE_DATA: - return_val = quic_analyseStream(pstream, pme, thread_seq, a_pcaket); - if(return_val == QUIC_RETURN_DROPME){ - quic_release_stream(pstream, pme, thread_seq, a_pcaket); - *pme = NULL; - return APP_STATE_DROPME; - } - break; - - case OP_STATE_CLOSE: - a_quic_stream = (struct quic_stream *)*pme; - if(a_quic_stream!=NULL) - { - a_quic_stream->fin_flag = QUIC_TRUE; - } - return_val = quic_analyseStream(pstream, pme, thread_seq, a_pcaket); - if(a_quic_stream!=NULL) - { - quic_release_stream(pstream, pme, thread_seq, a_pcaket); - *pme = NULL; - } + case OP_STATE_PENDING: + case OP_STATE_DATA: + return_val=gquic_process(pstream, a_quic_stream, thread_seq, a_packet); + break; + case OP_STATE_CLOSE: + a_quic_stream->fin_flag=QUIC_TRUE; + return_val=gquic_process(pstream, a_quic_stream, thread_seq, a_packet); + break; + default: + break; + } + + if(return_val==QUIC_RETURN_DROPME || pstream->opstate==OP_STATE_CLOSE) + { + quic_release_stream(pstream, pme, thread_seq); + *pme=NULL; return APP_STATE_DROPME; } - return APP_STATE_GIVEME; + + return APP_STATE_GIVEME; }/*QUICNIT*/ -void quic_init_clientHello(struct quic_client_hello* stClientHello, UINT32 tag_num, int thread_seq) -{ - if(stClientHello==NULL) return ; - - if(tag_num == 0){ - }else{ - (stClientHello->ext_tags) = (quic_tlv_t **)dictator_malloc(thread_seq,tag_num*sizeof(quic_tlv_t*)); - int i=0; - for(i=0;iext_tags[i] = (quic_tlv_t *)dictator_malloc(thread_seq, sizeof(quic_tlv_t) ); - memset(stClientHello->ext_tags[i], 0, sizeof(quic_tlv_t)); - stClientHello->ext_tags[i]->ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*MAX_TAG_VALUE_LEN); - stClientHello->ext_tags[i]->length = 0; - stClientHello->ext_tags[i]->type = 0; - } - } - -// stClientHello->ext_tag_len = 0; - stClientHello->ext_tag_num = tag_num; - memset(stClientHello->server_name, 0, SERVER_NAME_LEN); - memset(stClientHello->user_agent, 0, SERVER_NAME_LEN); - return; -} - -//void quic_init_clientHello(struct quic_client_hello* stClientHello, UINT32 tag_num, int thread_seq) -//{ -// if(stClientHello==NULL) return ; -// stClientHello->session.ptr_value = NULL; -// stClientHello->session.length = 0; -// stClientHello->ciphersuits.ptr_value = NULL; -// stClientHello->ciphersuits.length = 0; -// stClientHello->com_method.ptr_value = NULL; -// stClientHello->com_method.length = 0; -// memset(&stClientHello->random, 0, RANDOM_LEN); -// (stClientHello->ext_tags) = (struct quic_tlv_t **)dictator_malloc(thread_seq,tag_num*sizeof(struct quic_tlv_t*)); -// -// int i=0; -// for(i=0;iext_tags[i] = (struct quic_tlv_t *)dictator_malloc(thread_seq, sizeof(struct quic_tlv_t) ); -// memset(stClientHello->ext_tags[i], 0, sizeof(struct quic_tlv_t)); -// stClientHello->ext_tags[i]->ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*MAX_TAG_VALUE_LEN); -// stClientHello->ext_tags[i]->length = 0; -// stClientHello->ext_tags[i]->type = 0; -// } -// stClientHello->ext_tag_len = 0; -// stClientHello->ext_tag_num = tag_num; -// memset(&stClientHello->server_name, 0, sizeof(stClientHello->server_name)); -// memset(&stClientHello->user_agent, 0, sizeof(stClientHello->user_agent)); -// return; -//} - -void quic_init_serverHello(struct quic_server_hello* stServerHello, UINT32 tag_num, int thread_seq) -{ - if(stServerHello==NULL) return ; -// stServerHello->session.ptr_value = NULL; -// stServerHello->session.length = 0; -// memset(&stServerHello->random, 0, RANDOM_LEN); - if(tag_num == 0){ - }else{ - (stServerHello->ext_tags) = (quic_tlv_t **)dictator_malloc(thread_seq,tag_num*sizeof(quic_tlv_t*)); - int i=0; - for(i=0;iext_tags[i] = (struct quic_tlv_t *)dictator_malloc(thread_seq, sizeof(quic_tlv_t)*20); - stServerHello->ext_tags[i] = (quic_tlv_t *)dictator_malloc(thread_seq, sizeof(quic_tlv_t)); - memset(stServerHello->ext_tags[i], 0, sizeof(quic_tlv_t)); - stServerHello->ext_tags[i]->ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*MAX_TAG_VALUE_LEN); - stServerHello->ext_tags[i]->length = 0; - stServerHello->ext_tags[i]->type = 0; - } - } - - stServerHello->ext_tag_num = tag_num; - return; -} - -int quic_init_stream(struct streaminfo *pstream, void **pme, int thread_seq){ - - struct quic_stream *a_quic_stream = (struct quic_stream *)*pme; - if(NULL != a_quic_stream) - return -1; - a_quic_stream = (struct quic_stream *)dictator_malloc(thread_seq, sizeof(struct quic_stream)); - memset(a_quic_stream,0,sizeof(struct quic_stream)); - if (NULL == a_quic_stream) - { - return -1; - } - a_quic_stream->output_region_flag = g_quic_param.quic_interested_region_flag; - a_quic_stream->output_region_mask = QUIC_INTEREST_KEY_MASK; -// a_quic_stream->type = UNKNOWN_QUIC_TYPE; -// a_quic_stream->handshake_type = UNKNOWN_HANDSHAKE_TYPE; - a_quic_stream->is_quic_stream = QUIC_FALSE; - a_quic_stream->version_cfm = QUIC_FALSE; - a_quic_stream->version = 0; - a_quic_stream->link_state = QUIC_FALSE; - a_quic_stream->fin_flag = QUIC_FALSE; -// a_quic_stream->p_output_buffer = (struct quic_tlv_t*)dictator_malloc(thread_seq, sizeof(struct quic_tlv_t)); -// a_quic_stream->p_output_buffer->length = 0; -// a_quic_stream->p_output_buffer->ptr_value = 0; - a_quic_stream->business = (struct quic_business_info *)dictator_malloc(thread_seq,sizeof(struct quic_business_info)); - a_quic_stream->business->param = NULL; - a_quic_stream->business->return_value = PROT_STATE_GIVEME; - - *pme = (void*)a_quic_stream; - return 0; -} - -void quic_release_clientHello(int thread_seq, struct quic_client_hello* st_client_hello) -{ - if(st_client_hello==NULL) return ; -// if(st_client_hello->random.ptr_value!=NULL) -// { -// dictator_free(thread_seq,st_client_hello->random.ptr_value); -// st_client_hello->random.ptr_value = NULL; -// } -// if(st_client_hello->session.ptr_value!=NULL) -// { -// dictator_free(thread_seq,st_client_hello->session.ptr_value); -// st_client_hello->session.ptr_value = NULL; -// } -// if(st_client_hello->ciphersuits.ptr_value!=NULL) -// { -// dictator_free(thread_seq,st_client_hello->ciphersuits.ptr_value); -// st_client_hello->ciphersuits.ptr_value = NULL; -// } -// if(st_client_hello->com_method.ptr_value!=NULL) -// { -// dictator_free(thread_seq,st_client_hello->com_method.ptr_value); -// st_client_hello->com_method.ptr_value = NULL; -// } - if(st_client_hello->ext_tags != NULL){ - quic_release_exts(thread_seq, st_client_hello->ext_tags, st_client_hello->ext_tag_num); - dictator_free(thread_seq, st_client_hello->ext_tags); - st_client_hello->ext_tags = NULL; - } - return; -} - - - -void quic_release_serverHello(int thread_seq,struct quic_server_hello* st_server_hello) -{ - if(st_server_hello==NULL) return ; -// if(st_server_hello->session.ptr_value!=NULL) -// { -// dictator_free(thread_seq,st_server_hello->session.ptr_value); -// st_server_hello->session.ptr_value = NULL; -// } - if(st_server_hello->ext_tags != NULL){ - quic_release_exts(thread_seq, st_server_hello->ext_tags, st_server_hello->ext_tag_num); - dictator_free(thread_seq, st_server_hello->ext_tags); - st_server_hello->ext_tags = NULL; - } - return ; -} - -void quic_release_exts(int thread_seq, quic_tlv_t** ext_tags, UINT16 ext_tag_num){ - if(ext_tags == NULL) return; - int i = 0; - for(i = 0; i < ext_tag_num; i++){ - if(ext_tags[i] != NULL){ - if(ext_tags[i]->ptr_value != NULL){ - dictator_free(thread_seq, ext_tags[i]->ptr_value); - ext_tags[i]->ptr_value = NULL; - } - dictator_free(thread_seq, ext_tags[i]); - ext_tags[i] = NULL; - } - } - -} - -void quic_release_stream(struct streaminfo *a_tcp, void** pme, int thread_seq,void *a_packet) -{ - struct quic_stream *a_quic_stream = (struct quic_stream *)*pme; - if(NULL == a_quic_stream) return; - a_quic_stream->fin_flag = QUIC_TRUE; -// if(NULL != a_quic_stream->p_output_buffer) -// { -// if(a_quic_stream->p_output_buffer->ptr_value!=NULL) -// { -// dictator_free(thread_seq,a_quic_stream->p_output_buffer->ptr_value); -// a_quic_stream->p_output_buffer->ptr_value = NULL; -// } -// dictator_free(thread_seq,a_quic_stream->p_output_buffer); -// a_quic_stream->p_output_buffer = NULL; -// } - if(NULL != a_quic_stream->business) - { - if(a_quic_stream->business->param !=NULL){ - dictator_free(thread_seq,a_quic_stream->business->param); - a_quic_stream->business->param = NULL; - } - dictator_free(thread_seq,a_quic_stream->business); - a_quic_stream->business = NULL; - } - if(NULL != a_quic_stream->cert_chain.ptr_value) - { - dictator_free(thread_seq,a_quic_stream->cert_chain.ptr_value); - a_quic_stream->cert_chain.ptr_value = NULL; - } - if(NULL != a_quic_stream->common_cert.ptr_value) - { - dictator_free(thread_seq,a_quic_stream->common_cert.ptr_value); - a_quic_stream->common_cert.ptr_value = NULL; - } - if(NULL != a_quic_stream->cached_cert.ptr_value) - { - dictator_free(thread_seq,a_quic_stream->cached_cert.ptr_value); - a_quic_stream->cached_cert.ptr_value = NULL; - } - quic_release_serverHello(thread_seq, &a_quic_stream->st_server_hello); - quic_release_clientHello(thread_seq, &a_quic_stream->st_client_hello); - - dictator_free(thread_seq,a_quic_stream); - a_quic_stream = NULL; - return; -} - - -UINT8 quic_analyseStream(struct streaminfo *pstream, void** pme, int thread_seq, void *a_packet){ - struct quic_stream* a_quic_stream = (struct quic_stream *)*pme; - if(a_quic_stream == NULL){ - return QUIC_RETURN_DROPME; - } - UINT8 return_val = QUIC_RETURN_NORM; - struct udpdetail *udp_detail = (struct udpdetail *) pstream->pdetail; - if(udp_detail->datalen <= 0){ - return QUIC_RETURN_NORM; - } - - char* g_data_t = (char *)udp_detail->pdata; - UINT32 g_len_t = udp_detail->datalen; - - if(!a_quic_stream->is_quic_stream){ - if(g_len_t <= GQUIC_HEADER_LEN){ - return QUIC_RETURN_DROPME; - } - if(g_len_t > GQUIC_HEADER_LEN){ - return_val = gquic_process(pstream, a_quic_stream, a_quic_stream->output_region_flag, thread_seq, a_packet, g_data_t, g_len_t); - } - }else if(a_quic_stream->is_quic_stream){ - if(g_len_t > GQUIC_HEADER_LEN){ - gquic_process(pstream, a_quic_stream, a_quic_stream->output_region_flag, thread_seq, a_packet, g_data_t, g_len_t); - } - return QUIC_RETURN_NORM; - } - return return_val; -} - - -int quic_getLinkState(struct quic_stream *a_quic_stream) -{ - UCHAR state = 0; - if(QUIC_FALSE==(a_quic_stream)->link_state) - { - if(QUIC_TRUE==(a_quic_stream)->fin_flag) - state = SESSION_STATE_CLOSE | SESSION_STATE_PENDING; - else - state = SESSION_STATE_PENDING; - } - else - { - if(QUIC_TRUE==(a_quic_stream)->fin_flag) - { - state = SESSION_STATE_CLOSE; - } - else - state = SESSION_STATE_DATA; - } - (a_quic_stream)->link_state = QUIC_TRUE; - return state; -} - -UCHAR quic_doWithInsterestedRegion(struct streaminfo *pstream) -{ - /*业务层没有注册兴趣域*/ - if(g_quic_param.quic_interested_region_flag < QUIC_KEY){ - return APP_STATE_DROPME; - } - return QUIC_RETURN_NORM; -}/*ssl_doWithInsterestedRegion*/ - - - - diff --git a/src/quic_analysis.h b/src/quic_analysis.h index 1649e8f..7423504 100644 --- a/src/quic_analysis.h +++ b/src/quic_analysis.h @@ -38,9 +38,9 @@ struct quic_param_t { unsigned long long quic_interested_region_flag; unsigned long long quic_region_cnt; - char quic_conf_filename[256]; unsigned short quic_plugid; char quic_conf_regionname[MAX_REGION_NUM][REGION_NAME_LEN]; + void *logger; }; enum quic_mes_type{ @@ -54,25 +54,7 @@ enum quic_mes_type{ MSG_UNKNOWN = 255 }; -int QUIC_INIT(void); -char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq,void *a_pcaket); -void QUIC_DESTROY(void); -void QUIC_GETPLUGID(unsigned short plugid); -void QUIC_PROT_FUNSTAT(unsigned long long protflag); -long long QUIC_FLAG_CHANGE(char* flag_str); -unsigned long long quic_getRegionID(char *string, int str_len, -const char g_string[MAX_REGION_NUM][REGION_NAME_LEN]); -UINT8 quic_analyseStream(struct streaminfo *pstream, void** pme, int thread_seq,void *a_packet); -int quic_init_stream(struct streaminfo *pstream, void **pme, int thread_seq); -void quic_init_clientHello(struct quic_client_hello* stClientHello, UINT32 tag_num, int thread_seq); -void quic_init_serverHello(struct quic_server_hello* stServerHello, UINT32 tag_num, int thread_seq); void quic_release_exts(int thread_seq, quic_tlv_t** ext_tags, UINT16 ext_tag_num); -void quic_release_clientHello(int thread_seq,struct quic_client_hello* stClientHello); -void quic_release_serverHello(int thread_seq,struct quic_server_hello* stServerHello); -void quic_release_stream(struct streaminfo *a_tcp, void** pme, int thread_seq,void *a_packet); -UINT8 quic_analyseStream(struct streaminfo *pstream, void** pme, int thread_seq,void *a_packet); -int quic_getLinkState(struct quic_stream *a_quic_stream); -UCHAR quic_doWithInsterestedRegion(struct streaminfo *pstream); #endif /* SRC_QUIC_ANALYSIS_H_ */ diff --git a/src/quic_callback.c b/src/quic_callback.c index aab49d9..81824c5 100644 --- a/src/quic_callback.c +++ b/src/quic_callback.c @@ -8,99 +8,57 @@ #include "quic_analysis.h" extern struct quic_param_t g_quic_param; -UCHAR quic_callPlugins(struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet) +int quic_getLinkState(struct quic_stream *a_quic_stream) { - stSessionInfo session_info; - region_flag = (region_flag >> (*a_quic_stream)->output_region_mask) % 2; - if( QUIC_TRUE==region_flag || (*a_quic_stream)->fin_flag==QUIC_TRUE ) + UCHAR state = 0; + + if(QUIC_FALSE==a_quic_stream->link_state) { - if (PROT_STATE_DROPME != (*a_quic_stream)->business->return_value) + if(QUIC_TRUE==a_quic_stream->fin_flag) { - session_info.plugid = g_quic_param.quic_plugid; - session_info.prot_flag = (((unsigned long long)1)<<(*a_quic_stream)->output_region_mask); - session_info.session_state = quic_getLinkState(*a_quic_stream) ; - session_info.app_info = (void*)(*a_quic_stream); -// session_info.buf = (*a_quic_stream)->p_output_buffer->ptr_value; -// session_info.buflen = (*a_quic_stream)->p_output_buffer->length; - (*a_quic_stream)->business->return_value = PROT_PROCESS(&session_info, - &((*a_quic_stream)->business->param),thread_seq,pstream, a_packet); + state=SESSION_STATE_CLOSE|SESSION_STATE_PENDING; + } + else + { + state=SESSION_STATE_PENDING; } } + else + { + if(QUIC_TRUE==(a_quic_stream)->fin_flag) + { + state=SESSION_STATE_CLOSE; + } + else + { + state=SESSION_STATE_DATA; + } + } + + a_quic_stream->link_state=QUIC_TRUE; + + return state; +} + +UCHAR quic_callPlugins(struct quic_stream *a_quic_stream, struct streaminfo *pstream, enum quic_interested_region region_mask, int thread_seq, void *a_packet) +{ + stSessionInfo session_info; + unsigned long long region_flag=a_quic_stream->output_region_flag; + + region_flag = (region_flag >> region_mask) % 2; + + if(QUIC_TRUE==region_flag || a_quic_stream->fin_flag==QUIC_TRUE) + { + if (PROT_STATE_DROPME != a_quic_stream->business->return_value) + { + session_info.plugid = g_quic_param.quic_plugid; + session_info.prot_flag = (((unsigned long long)1)<business->return_value = PROT_PROCESS(&session_info, &(a_quic_stream->business->param),thread_seq,pstream, a_packet); + } + } + return QUIC_RETURN_NORM; } -UCHAR quic_proc_interest_region(enum quic_interested_region region_mask,struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet) -{ - UCHAR return_val = QUIC_RETURN_NORM; - (*a_quic_stream)->output_region_mask = region_mask; - return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet); - (*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK; - return return_val; -} -/* -UCHAR quic_doWithVersion(struct quic_stream** a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet) -{ - UCHAR return_val = QUIC_RETURN_NORM; - if(!(g_quic_param.quic_interested_region_flag & QUIC_VERSION)) return return_val; - - (*a_quic_stream)->output_region_mask = QUIC_VERSION_MASK; - (*a_quic_stream)->p_output_buffer->ptr_value = (void*)(*a_quic_stream)->version; - (*a_quic_stream)->p_output_buffer->length = 4; - return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet); - (*a_quic_stream)->p_output_buffer->ptr_value = NULL; - (*a_quic_stream)->p_output_buffer->length = 0; - (*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK; - return return_val; -} - -UCHAR quic_doWithApplicationData(char *pc_quic_data, int data_len, struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet) -{ - UCHAR return_val = QUIC_RETURN_NORM; - (*a_quic_stream)->output_region_mask = QUIC_APPLICATION_DATA_MASK; - (*a_quic_stream)->p_output_buffer->ptr_value = pc_quic_data; - (*a_quic_stream)->p_output_buffer->length = data_len; - return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet); - (*a_quic_stream)->p_output_buffer->ptr_value = NULL; - (*a_quic_stream)->p_output_buffer->length = 0; - (*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK; - return return_val; -} - -UCHAR quic_doWithClientHello(struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet) -{ - UCHAR return_val = QUIC_RETURN_NORM; - (*a_quic_stream)->output_region_mask = QUIC_CLIENT_HELLO_MASK; - return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet); - (*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK; - return return_val; -} - -UCHAR quic_doWithServerHello(struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet) -{ - UCHAR return_val = QUIC_RETURN_NORM; - (*a_quic_stream)->output_region_mask = QUIC_SERVER_HELLO_MASK; - return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet); - (*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK; - return return_val; -} - -UCHAR quic_doWithCert(char *pc_quic_data, int data_len, enum quic_interested_region cert, struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet) -{ - UCHAR return_val = QUIC_RETURN_NORM; - (*a_quic_stream)->output_region_mask = cert; - (*a_quic_stream)->p_output_buffer->ptr_value = pc_quic_data; - (*a_quic_stream)->p_output_buffer->length = data_len; - return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet); - (*a_quic_stream)->p_output_buffer->ptr_value = NULL; - (*a_quic_stream)->p_output_buffer->length = 0; - (*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK; - return return_val; -} -*/ diff --git a/src/quic_callback.h b/src/quic_callback.h index af706de..4402146 100644 --- a/src/quic_callback.h +++ b/src/quic_callback.h @@ -8,10 +8,7 @@ #ifndef SRC_QUIC_CALLBACK_H_ #define SRC_QUIC_CALLBACK_H_ #include "gquic.h" -UCHAR quic_callPlugins(struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet); -UCHAR quic_proc_interest_region(enum quic_interested_region region_mask,struct quic_stream **a_quic_stream, struct streaminfo *pstream, - unsigned long long region_flag, int thread_seq, void *a_packet); +UCHAR quic_callPlugins(struct quic_stream *a_quic_stream, struct streaminfo *pstream, enum quic_interested_region region_mask, int thread_seq, void *a_packet); //UCHAR quic_doWithVersion(struct quic_stream** a_quic_stream, struct streaminfo *pstream, // unsigned long long region_flag, int thread_seq, void *a_packet); diff --git a/src/quic_util.c b/src/quic_util.c index 6ea2cc3..e00b3e2 100644 --- a/src/quic_util.c +++ b/src/quic_util.c @@ -9,49 +9,6 @@ extern struct quic_param_t g_quic_param; -int readconf(const char* filename) -{ - FILE *fp = NULL; - char buf[2048] = {0}; - int region_id = 0; - int temp = 0; - char region_name[REGION_NAME_LEN] = {0}; - - if(((fp = fopen(filename, "r"))!=NULL)) - { - while( fgets(buf, sizeof(buf), fp)) - { - temp = sscanf(buf, "%d\t%s", ®ion_id, region_name); - if ( 2 > temp ) - { -#ifdef PRINTF - printf( "quic.so : quic.conf %s read error\n", filename); -#endif - return -1; - } - if(region_id>MAX_REGION_NUM) - { -#ifdef PRINTF - printf( "quic.so : quic.conf %d bigger than MAX_REGION_NUM\n", region_id); -#endif - return -1; - } - strncpy(g_quic_param.quic_conf_regionname[region_id], region_name, strlen(region_name)); - g_quic_param.quic_region_cnt++; - memset(region_name, 0, sizeof(region_name)); - } - fclose(fp); - } - else - { -#ifdef PRINTF - printf( "quic.so : quic.conf %s open error\n", filename); -#endif - return -1; - } - return 0; -} - bool a_readUInt64(UINT64* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){ return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset); }