/* * quic_analysis.c * * Created on: 2019Äê4ÔÂ2ÈÕ * Author: root */ #include "gquic.h" #include "quic_analysis.h" #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"; #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)); 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*/ extern "C" void QUIC_DESTROY(void) { return ; }/*QUICDESTROY*/ 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); } extern "C" void QUIC_PROT_FUNSTAT(unsigned long long protflag) { if(0==protflag){ return; } 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*/ 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; } if(*pme==NULL) { quic_init_stream(pme, thread_seq); a_quic_stream=(struct quic_stream *)*pme; } switch(pstream->opstate) { 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; }/*QUICNIT*/