2020-05-12 12:18:02 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* quic_analysis.c
|
|
|
|
|
|
*
|
|
|
|
|
|
* Created on: 2019<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD>
|
|
|
|
|
|
* Author: root
|
|
|
|
|
|
*/
|
|
|
|
|
|
#include "gquic.h"
|
|
|
|
|
|
#include "quic_analysis.h"
|
|
|
|
|
|
#include "gquic_process.h"
|
2021-09-03 14:51:29 +08:00
|
|
|
|
#include "parser_quic.h"
|
|
|
|
|
|
|
2020-05-12 12:18:02 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <MESA/stream_inc/stream_base.h>
|
2020-05-22 18:44:00 +08:00
|
|
|
|
#include <MESA/MESA_handle_logger.h>
|
|
|
|
|
|
#include <MESA/MESA_prof_load.h>
|
2020-05-12 12:18:02 +08:00
|
|
|
|
|
2020-05-29 15:10:01 +08:00
|
|
|
|
struct _quic_param_t g_quic_param;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
2020-06-03 15:43:00 +08:00
|
|
|
|
const char QUIC_VERSION_20200603=0;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
|
|
|
|
|
int quic_init_stream(void **pme, int thread_seq)
|
|
|
|
|
|
{
|
2020-06-03 15:43:00 +08:00
|
|
|
|
struct _quic_context *_context=(struct _quic_context *)dictator_malloc(thread_seq, sizeof(struct _quic_context));
|
2020-05-29 15:10:01 +08:00
|
|
|
|
memset(_context, 0, sizeof(struct _quic_context));
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
2020-05-29 15:10:01 +08:00
|
|
|
|
*pme=(void*)_context;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-29 15:10:01 +08:00
|
|
|
|
void quic_release_exts(int thread_seq, quic_tlv_t *ext_tags, int ext_tag_num)
|
2020-05-22 18:44:00 +08:00
|
|
|
|
{
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
|
|
|
|
if(ext_tags!=NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(i=0; i<ext_tag_num; i++)
|
|
|
|
|
|
{
|
2020-05-29 15:10:01 +08:00
|
|
|
|
if(ext_tags[i].value!=NULL)
|
2020-05-22 18:44:00 +08:00
|
|
|
|
{
|
2020-05-29 15:10:01 +08:00
|
|
|
|
dictator_free(thread_seq, ext_tags[i].value);
|
|
|
|
|
|
ext_tags[i].value=NULL;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dictator_free(thread_seq, ext_tags);
|
|
|
|
|
|
ext_tags=NULL;
|
|
|
|
|
|
}
|
2020-05-29 15:10:01 +08:00
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-03 15:43:00 +08:00
|
|
|
|
void quic_release_stream(void** pme, int thread_seq)
|
2020-05-22 18:44:00 +08:00
|
|
|
|
{
|
2020-05-29 15:10:01 +08:00
|
|
|
|
struct _quic_context *_context = (struct _quic_context *)*pme;
|
|
|
|
|
|
if(NULL!=_context)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_context->quic_info.client_hello!=NULL)
|
2020-05-22 18:44:00 +08:00
|
|
|
|
{
|
2020-05-29 15:10:01 +08:00
|
|
|
|
quic_release_exts(thread_seq, _context->quic_info.client_hello->ext_tags, _context->quic_info.client_hello->ext_tag_num);
|
|
|
|
|
|
dictator_free(thread_seq, _context->quic_info.client_hello);
|
|
|
|
|
|
_context->quic_info.client_hello=NULL;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
}
|
2020-05-29 15:10:01 +08:00
|
|
|
|
|
|
|
|
|
|
if(_context->quic_info.server_hello!=NULL)
|
2020-05-22 18:44:00 +08:00
|
|
|
|
{
|
2020-05-29 15:10:01 +08:00
|
|
|
|
quic_release_exts(thread_seq, _context->quic_info.server_hello->ext_tags, _context->quic_info.server_hello->ext_tag_num);
|
|
|
|
|
|
dictator_free(thread_seq, _context->quic_info.server_hello);
|
|
|
|
|
|
_context->quic_info.server_hello=NULL;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
}
|
2020-05-29 15:10:01 +08:00
|
|
|
|
|
2020-06-01 17:16:23 +08:00
|
|
|
|
if(_context->quic_info.rejection!=NULL)
|
2020-05-22 18:44:00 +08:00
|
|
|
|
{
|
2020-06-01 17:16:23 +08:00
|
|
|
|
quic_release_exts(thread_seq, _context->quic_info.rejection->ext_tags, _context->quic_info.rejection->ext_tag_num);
|
|
|
|
|
|
dictator_free(thread_seq, _context->quic_info.rejection);
|
|
|
|
|
|
_context->quic_info.rejection=NULL;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
}
|
2020-05-12 12:18:02 +08:00
|
|
|
|
|
2020-05-29 15:10:01 +08:00
|
|
|
|
dictator_free(thread_seq, _context);
|
|
|
|
|
|
_context=NULL;
|
|
|
|
|
|
*pme=NULL;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-05-12 12:18:02 +08:00
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
extern "C" int QUIC_INIT(void)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
2021-09-10 13:19:28 +08:00
|
|
|
|
int ret=0;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
FILE *fp=NULL;
|
|
|
|
|
|
char buf[2048]={0};
|
|
|
|
|
|
int region_id=0;
|
|
|
|
|
|
char region_name[REGION_NAME_LEN]={0};
|
|
|
|
|
|
|
2020-05-29 15:10:01 +08:00
|
|
|
|
memset(&g_quic_param,0,sizeof(struct _quic_param_t));
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
2021-09-10 13:19:28 +08:00
|
|
|
|
MESA_load_profile_int_def(g_quic_proto_conffile, "QUIC", "LOG_LEVEL", &g_quic_param.level, RLOG_LV_FATAL);
|
|
|
|
|
|
MESA_load_profile_string_def(g_quic_proto_conffile, "QUIC", "LOG_PATH", g_quic_param.log_path, sizeof(g_quic_param.log_path), "./log/quic/quic");
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
2021-09-10 13:19:28 +08:00
|
|
|
|
MESA_load_profile_int_def(g_quic_proto_conffile, "QUIC", "DUMP_PCAKET_SWITCH", &g_quic_param.dump_packet_switch, 0);
|
|
|
|
|
|
|
|
|
|
|
|
g_quic_param.logger=MESA_create_runtime_log_handle(g_quic_param.log_path, g_quic_param.level);
|
2020-05-22 18:44:00 +08:00
|
|
|
|
if(g_quic_param.logger==NULL)
|
|
|
|
|
|
{
|
2021-09-10 13:19:28 +08:00
|
|
|
|
printf("MESA_create_runtime_log_handle failed, level: %d log_path: %s", g_quic_param.level, g_quic_param.log_path);
|
2020-05-12 12:18:02 +08:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-03 14:51:29 +08:00
|
|
|
|
gcry_init();
|
|
|
|
|
|
|
2020-05-12 12:18:02 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}/*QUICINIT*/
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
extern "C" void QUIC_DESTROY(void)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
return ;
|
|
|
|
|
|
}/*QUICDESTROY*/
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
extern "C" void QUIC_GETPLUGID(unsigned short plugid)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
g_quic_param.quic_plugid = plugid;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_GETPLUGID", "quic_plugid: %d", plugid);
|
2020-05-12 12:18:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
extern "C" void QUIC_PROT_FUNSTAT(unsigned long long protflag)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(0==protflag){
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-05-22 18:44:00 +08:00
|
|
|
|
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);
|
2020-05-12 12:18:02 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}/*PROT_FUNSTAT*/
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
extern "C" unsigned long long quic_getRegionID(char *string, int str_len,const char g_string[MAX_REGION_NUM][REGION_NAME_LEN])
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
unsigned long long i=0;
|
|
|
|
|
|
for(i=0;i<g_quic_param.quic_region_cnt;i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(0==strcasecmp(g_string[i], string))
|
|
|
|
|
|
{
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
extern "C" long long QUIC_FLAG_CHANGE(char* flag_str)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(flag_str==NULL) return -1;
|
|
|
|
|
|
long long protflag = 0;
|
|
|
|
|
|
long long region_id = 0;
|
|
|
|
|
|
char *start_token = flag_str;
|
|
|
|
|
|
char *end_token = flag_str;
|
|
|
|
|
|
char *end_pos = flag_str+strlen(flag_str);
|
|
|
|
|
|
char region_name[REGION_NAME_LEN] = {0};
|
|
|
|
|
|
|
|
|
|
|
|
while (end_token < end_pos)
|
|
|
|
|
|
{
|
|
|
|
|
|
end_token = (char*)memchr(start_token, ',', end_pos-start_token);
|
|
|
|
|
|
if(end_token!=NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
memcpy(region_name, start_token, end_token-start_token);
|
|
|
|
|
|
start_token = end_token+1;
|
|
|
|
|
|
end_token += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
memcpy(region_name, start_token, end_pos-start_token);
|
|
|
|
|
|
end_token = end_pos;
|
|
|
|
|
|
}
|
|
|
|
|
|
region_id = quic_getRegionID(region_name, strlen(region_name), g_quic_param.quic_conf_regionname);
|
|
|
|
|
|
if(-1==region_id)
|
|
|
|
|
|
{
|
2020-05-22 18:44:00 +08:00
|
|
|
|
MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_FLAG_CHANGE", "Read %s error, flag_str: %d", region_name, flag_str);
|
2020-05-12 12:18:02 +08:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
protflag |= ((long long)1)<<region_id;
|
|
|
|
|
|
memset(region_name, 0, REGION_NAME_LEN);
|
|
|
|
|
|
}
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MESA_handle_runtime_log(g_quic_param.logger, RLOG_LV_FATAL, "QUIC_FLAG_CHANGE", "protflag: %llu", protflag);
|
2020-05-12 12:18:02 +08:00
|
|
|
|
return protflag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
extern "C" char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq, void *a_packet)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
2020-05-29 15:10:01 +08:00
|
|
|
|
int ret=0;
|
|
|
|
|
|
struct _quic_context *_context=(struct _quic_context *)*pme;
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
|
|
|
|
|
if(g_quic_param.quic_interested_region_flag<QUIC_KEY)
|
2020-11-22 19:50:03 +06:00
|
|
|
|
{
|
2020-05-12 12:18:02 +08:00
|
|
|
|
return APP_STATE_DROPME;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-03 14:51:29 +08:00
|
|
|
|
if(!is_quic_port(pstream))
|
|
|
|
|
|
{
|
|
|
|
|
|
return APP_STATE_DROPME;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
if(*pme==NULL)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
2020-05-22 18:44:00 +08:00
|
|
|
|
quic_init_stream(pme, thread_seq);
|
2020-05-29 15:10:01 +08:00
|
|
|
|
_context=(struct _quic_context *)*pme;
|
2020-06-01 17:44:32 +08:00
|
|
|
|
_context->call_business=TRUE;
|
2020-05-12 12:18:02 +08:00
|
|
|
|
}
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
|
|
|
|
|
switch(pstream->opstate)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
2020-05-22 18:44:00 +08:00
|
|
|
|
case OP_STATE_PENDING:
|
|
|
|
|
|
case OP_STATE_DATA:
|
2020-05-29 15:10:01 +08:00
|
|
|
|
ret=quic_process(pstream, _context, thread_seq, a_packet);
|
2020-05-22 18:44:00 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case OP_STATE_CLOSE:
|
2020-05-29 15:10:01 +08:00
|
|
|
|
ret=quic_process(pstream, _context, thread_seq, a_packet);
|
2020-11-22 16:55:49 +06:00
|
|
|
|
quic_callPlugins(pstream, _context, NULL, 0, QUIC_INTEREST_KEY_MASK, a_packet);
|
2020-05-22 18:44:00 +08:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
2020-05-12 12:18:02 +08:00
|
|
|
|
}
|
2020-05-22 18:44:00 +08:00
|
|
|
|
|
2020-12-30 00:44:26 +06:00
|
|
|
|
if(ret&APP_STATE_DROPME || ret&APP_STATE_DROPPKT || pstream->opstate==OP_STATE_CLOSE)
|
2020-05-12 12:18:02 +08:00
|
|
|
|
{
|
2020-06-03 15:43:00 +08:00
|
|
|
|
quic_release_stream(pme, thread_seq);
|
2020-05-22 18:44:00 +08:00
|
|
|
|
*pme=NULL;
|
2020-05-29 15:10:01 +08:00
|
|
|
|
return ret;
|
2020-05-12 12:18:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-22 18:44:00 +08:00
|
|
|
|
return APP_STATE_GIVEME;
|
2020-06-03 15:43:00 +08:00
|
|
|
|
}
|
2020-05-12 12:18:02 +08:00
|
|
|
|
|