review code; 代码调整

This commit is contained in:
liuxueli
2020-05-22 18:44:00 +08:00
parent 37cab4076d
commit 8eb02b5fd3
8 changed files with 1064 additions and 1468 deletions

View File

@@ -8,6 +8,12 @@
#ifndef SRC_GQUIC_H_ #ifndef SRC_GQUIC_H_
#define SRC_GQUIC_H_ #define SRC_GQUIC_H_
enum GQUIC_VERSION
{
GQUIC_UNKNOWN=0,
GQUIC_OTHERS,
GQUIC_Q046
};
#include <MESA/stream.h> #include <MESA/stream.h>
@@ -87,13 +93,4 @@ struct quic_stream {
uint64_t output_region_flag; 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_ */ #endif /* SRC_GQUIC_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -196,20 +196,13 @@ struct gquic_pkt_hdr{
UINT8 gquic_process(struct streaminfo *pstream, struct quic_stream* a_quic_stream, UINT8 gquic_process(struct streaminfo *pstream, struct quic_stream* a_quic_stream, int thread_seq, void* a_packet);
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);
UINT32 read_offset_len(UINT8 frame_type); UINT32 read_offset_len(UINT8 frame_type);
UINT32 read_stream_len(UINT8 frame_type); UINT32 read_stream_len(UINT8 frame_type);
UINT32 read_largest_observed_len(UINT8 frame_type); UINT32 read_largest_observed_len(UINT8 frame_type);
UINT32 read_missing_packet_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_stream_id(char* g_data_t, UINT8 frame_type, UINT32 *skip_len);
UINT32 get_pkn(char* g_data_t, UINT32 offset, UINT8 pkn_len);
UINT32 read_seq_num_len(UINT8 flags); UINT32 read_seq_num_len(UINT8 flags);
int read_conn_id_len(UINT8 flags); int read_conn_id_len(UINT8 flags);

View File

@@ -9,41 +9,222 @@
#include "gquic_process.h" #include "gquic_process.h"
#include <stdio.h> #include <stdio.h>
#include <MESA/stream_inc/stream_base.h> #include <MESA/stream_inc/stream_base.h>
#include <MESA/MESA_handle_logger.h>
#include <MESA/MESA_prof_load.h>
struct quic_param_t g_quic_param; 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
int QUIC_INIT(void) 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; 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;
}
}
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)); 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; return -1;
} }
if(((fp = fopen(g_quic_regionname_conffile, "r"))!=NULL))
{
while(fgets(buf, sizeof(buf), fp))
{
ret = sscanf(buf, "%d\t%s", &region_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; return 0;
}/*QUICINIT*/ }/*QUICINIT*/
void QUIC_DESTROY(void) extern "C" void QUIC_DESTROY(void)
{ {
return ; return ;
}/*QUICDESTROY*/ }/*QUICDESTROY*/
void QUIC_GETPLUGID(unsigned short plugid) extern "C" void QUIC_GETPLUGID(unsigned short plugid)
{ {
g_quic_param.quic_plugid = 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){ if(0==protflag){
return; 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; return;
}/*PROT_FUNSTAT*/ }/*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; unsigned long long i=0;
for(i=0;i<g_quic_param.quic_region_cnt;i++) for(i=0;i<g_quic_param.quic_region_cnt;i++)
@@ -56,7 +237,7 @@ unsigned long long quic_getRegionID(char *string, int str_len,const char g_strin
return 0; return 0;
} }
long long QUIC_FLAG_CHANGE(char* flag_str) extern "C" long long QUIC_FLAG_CHANGE(char* flag_str)
{ {
if(flag_str==NULL) return -1; if(flag_str==NULL) return -1;
long long protflag = 0; long long protflag = 0;
@@ -83,350 +264,63 @@ long long QUIC_FLAG_CHANGE(char* flag_str)
region_id = quic_getRegionID(region_name, strlen(region_name), g_quic_param.quic_conf_regionname); region_id = quic_getRegionID(region_name, strlen(region_name), g_quic_param.quic_conf_regionname);
if(-1==region_id) if(-1==region_id)
{ {
#ifdef PRINTF MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_FLAG_CHANGE", "Read %s error, flag_str: %d", region_name, flag_str);
printf( "quic.so : PROT_CHANGE %s read %s error\n", flag_str, region_name);
#endif
return -1; return -1;
} }
protflag |= ((long long)1)<<region_id; protflag |= ((long long)1)<<region_id;
memset(region_name, 0, REGION_NAME_LEN); memset(region_name, 0, REGION_NAME_LEN);
} }
MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_FLAG_CHANGE", "protflag: %llu", protflag);
return protflag; return protflag;
} }
char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq, void *a_pcaket) extern "C" char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq, void *a_packet)
{ {
uint8_t return_val=0; uint8_t return_val=0;
switch(quic_doWithInsterestedRegion(pstream)) struct quic_stream *a_quic_stream=(struct quic_stream *)*pme;
if(g_quic_param.quic_interested_region_flag<QUIC_KEY)
{ {
case APP_STATE_DROPME: MESA_handle_runtime_log(g_quic_param.logger,
RLOG_LV_FATAL,
"QUIC_INSTEREST",
"No business register QUIC, interested_region_flag: %llu QUIC_KEY: %d",
g_quic_param.quic_interested_region_flag,
QUIC_KEY,
printaddr(&pstream->addr, thread_seq));
return APP_STATE_DROPME; 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) switch(pstream->opstate)
{ {
case OP_STATE_PENDING: 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: case OP_STATE_DATA:
return_val = quic_analyseStream(pstream, pme, thread_seq, a_pcaket); return_val=gquic_process(pstream, a_quic_stream, thread_seq, a_packet);
if(return_val == QUIC_RETURN_DROPME){
quic_release_stream(pstream, pme, thread_seq, a_pcaket);
*pme = NULL;
return APP_STATE_DROPME;
}
break; break;
case OP_STATE_CLOSE: case OP_STATE_CLOSE:
a_quic_stream = (struct quic_stream *)*pme; a_quic_stream->fin_flag=QUIC_TRUE;
if(a_quic_stream!=NULL) return_val=gquic_process(pstream, a_quic_stream, thread_seq, a_packet);
{ break;
a_quic_stream->fin_flag = QUIC_TRUE; default:
break;
} }
return_val = quic_analyseStream(pstream, pme, thread_seq, a_pcaket);
if(a_quic_stream!=NULL) if(return_val==QUIC_RETURN_DROPME || pstream->opstate==OP_STATE_CLOSE)
{ {
quic_release_stream(pstream, pme, thread_seq, a_pcaket); quic_release_stream(pstream, pme, thread_seq);
*pme = NULL; *pme=NULL;
}
return APP_STATE_DROPME; return APP_STATE_DROPME;
} }
return APP_STATE_GIVEME; return APP_STATE_GIVEME;
}/*QUICNIT*/ }/*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;i<tag_num;i++)
{
stClientHello->ext_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;i<tag_num;i++)
// {
// stClientHello->ext_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;i<tag_num;i++)
{
// stServerHello->ext_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)
{
/*ҵ<><D2B5><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4>*/
if(g_quic_param.quic_interested_region_flag < QUIC_KEY){
return APP_STATE_DROPME;
}
return QUIC_RETURN_NORM;
}/*ssl_doWithInsterestedRegion*/

View File

@@ -38,9 +38,9 @@ struct quic_param_t
{ {
unsigned long long quic_interested_region_flag; unsigned long long quic_interested_region_flag;
unsigned long long quic_region_cnt; unsigned long long quic_region_cnt;
char quic_conf_filename[256];
unsigned short quic_plugid; unsigned short quic_plugid;
char quic_conf_regionname[MAX_REGION_NUM][REGION_NAME_LEN]; char quic_conf_regionname[MAX_REGION_NUM][REGION_NAME_LEN];
void *logger;
}; };
enum quic_mes_type{ enum quic_mes_type{
@@ -54,25 +54,7 @@ enum quic_mes_type{
MSG_UNKNOWN = 255 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_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_ */ #endif /* SRC_QUIC_ANALYSIS_H_ */

View File

@@ -8,99 +8,57 @@
#include "quic_analysis.h" #include "quic_analysis.h"
extern struct quic_param_t g_quic_param; extern struct quic_param_t g_quic_param;
UCHAR quic_callPlugins(struct quic_stream **a_quic_stream, struct streaminfo *pstream, int quic_getLinkState(struct quic_stream *a_quic_stream)
unsigned long long region_flag, int thread_seq, void *a_packet) {
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_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; stSessionInfo session_info;
region_flag = (region_flag >> (*a_quic_stream)->output_region_mask) % 2; unsigned long long region_flag=a_quic_stream->output_region_flag;
if( QUIC_TRUE==region_flag || (*a_quic_stream)->fin_flag==QUIC_TRUE )
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) if (PROT_STATE_DROPME != a_quic_stream->business->return_value)
{ {
session_info.plugid = g_quic_param.quic_plugid; session_info.plugid = g_quic_param.quic_plugid;
session_info.prot_flag = (((unsigned long long)1)<<(*a_quic_stream)->output_region_mask); session_info.prot_flag = (((unsigned long long)1)<<region_mask);
session_info.session_state = quic_getLinkState(*a_quic_stream) ; session_info.session_state = quic_getLinkState(a_quic_stream) ;
session_info.app_info = (void*)(*a_quic_stream); session_info.app_info = (void*)a_quic_stream;
// session_info.buf = (*a_quic_stream)->p_output_buffer->ptr_value; a_quic_stream->business->return_value = PROT_PROCESS(&session_info, &(a_quic_stream->business->param),thread_seq,pstream, a_packet);
// 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);
} }
} }
return QUIC_RETURN_NORM; 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;
}
*/

View File

@@ -8,10 +8,7 @@
#ifndef SRC_QUIC_CALLBACK_H_ #ifndef SRC_QUIC_CALLBACK_H_
#define SRC_QUIC_CALLBACK_H_ #define SRC_QUIC_CALLBACK_H_
#include "gquic.h" #include "gquic.h"
UCHAR quic_callPlugins(struct quic_stream **a_quic_stream, struct streaminfo *pstream, UCHAR quic_callPlugins(struct quic_stream *a_quic_stream, struct streaminfo *pstream, enum quic_interested_region region_mask, int thread_seq, void *a_packet);
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_doWithVersion(struct quic_stream** a_quic_stream, struct streaminfo *pstream, //UCHAR quic_doWithVersion(struct quic_stream** a_quic_stream, struct streaminfo *pstream,
// unsigned long long region_flag, int thread_seq, void *a_packet); // unsigned long long region_flag, int thread_seq, void *a_packet);

View File

@@ -9,49 +9,6 @@
extern struct quic_param_t g_quic_param; 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", &region_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){ 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); return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
} }