/* * quic_analysis.c * * Created on: 2019年4月2日 * Author: root */ #include "gquic.h" #include "quic_analysis.h" #include "gquic_process.h" #include #include struct quic_param_t g_quic_param; int QUIC_INIT(void) { 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)){ return -1; } return 0; }/*QUICINIT*/ void QUIC_DESTROY(void) { return ; }/*QUICDESTROY*/ void QUIC_GETPLUGID(unsigned short plugid) { g_quic_param.quic_plugid = plugid; } void QUIC_PROT_FUNSTAT(unsigned long long protflag) { if(0==protflag){ return; } g_quic_param.quic_interested_region_flag = protflag; return; }/*PROT_FUNSTAT*/ 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;iopstate) { 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; } return APP_STATE_DROPME; } 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*/