diff options
| author | liuxueli <[email protected]> | 2021-09-18 17:15:54 +0800 |
|---|---|---|
| committer | liuxueli <[email protected]> | 2021-09-18 17:15:54 +0800 |
| commit | 56db00e24f23bf5ae0285883433978c366f2537c (patch) | |
| tree | e4f27ea0a3cb9228db8c460d617907da648757d9 /src/quic_analysis.cpp | |
| parent | 123fcf1559cbd9791614033e0d3c070171d7e678 (diff) | |
TSG-7832: 支持非标端口8443,支持配置文件配置支持识别的端口QUIC_PORT_LIST=443;8443;v1.4.4
Diffstat (limited to 'src/quic_analysis.cpp')
| -rw-r--r-- | src/quic_analysis.cpp | 78 |
1 files changed, 73 insertions, 5 deletions
diff --git a/src/quic_analysis.cpp b/src/quic_analysis.cpp index 3aee5f1..639be64 100644 --- a/src/quic_analysis.cpp +++ b/src/quic_analysis.cpp @@ -41,6 +41,71 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; const char QUIC_VERSION_20200603=0; +static int parse_quic_port(char *port_list, unsigned short *quic_port, int quic_port_num) +{ + int i=0,ret=0; + int port_num=0; + int range_len=0,used_len=0; + char buf[256]={0}; + unsigned short s_port=0,e_port=0; + char *begin=NULL,*end=NULL,*pchr=NULL; + + if(port_list==NULL) + { + return 0; + } + + begin=port_list; + end=NULL; + range_len=strlen(port_list); + + while(range_len>used_len) + { + end=index(begin, ';'); + if(end==NULL) + { + end=begin+range_len-used_len; + } + + if(end==begin) + { + break; + } + + memset(buf, 0, sizeof(buf)); + strncpy(buf, begin, end-begin); + used_len+=end-begin+1; + if(range_len>used_len) + { + begin=end+1; + } + + pchr=strchr(buf, '-'); + if(pchr == NULL) + { + s_port=(unsigned short)atoi(buf); + e_port=s_port; + + } + else + { + ret=sscanf(buf, "%hu-%hu", &s_port, &e_port); + if(ret!=2) + { + continue; + } + } + + for(i=s_port; i<=e_port && port_num<quic_port_num; i++) + { + quic_port[port_num++]=i; + } + } + + return port_num; +} + + int quic_init_stream(void **pme, int thread_seq) { struct _quic_context *_context=(struct _quic_context *)dictator_malloc(thread_seq, sizeof(struct _quic_context)); @@ -110,7 +175,7 @@ extern "C" int QUIC_INIT(void) { int ret=0; FILE *fp=NULL; - char buf[2048]={0}; + char buff[2048]={0}; int region_id=0; char region_name[REGION_NAME_LEN]={0}; @@ -121,6 +186,9 @@ extern "C" int QUIC_INIT(void) MESA_load_profile_int_def(g_quic_proto_conffile, "QUIC", "DUMP_PCAKET_SWITCH", &g_quic_param.dump_packet_switch, 0); + MESA_load_profile_string_def(g_quic_proto_conffile, "QUIC", "QUIC_PORT_LIST", buff, sizeof(buff), "443;8443;"); + g_quic_param.quic_port_num=parse_quic_port(buff, g_quic_param.quic_port_list, SUPPORT_QUIC_PORT_NUM); + g_quic_param.logger=MESA_create_runtime_log_handle(g_quic_param.log_path, g_quic_param.level); if(g_quic_param.logger==NULL) { @@ -130,19 +198,19 @@ extern "C" int QUIC_INIT(void) if(((fp = fopen(g_quic_regionname_conffile, "r"))!=NULL)) { - while(fgets(buf, sizeof(buf), fp)) + while(fgets(buff, sizeof(buff), fp)) { - ret = sscanf(buf, "%d\t%s", ®ion_id, region_name); + ret = sscanf(buff, "%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); + 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, buff); 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); + 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, buff); return -1; } |
