TSG-7832: 支持非标端口8443,支持配置文件配置支持识别的端口QUIC_PORT_LIST=443;8443;

This commit is contained in:
liuxueli
2021-09-18 17:15:54 +08:00
parent 123fcf1559
commit 56db00e24f
6 changed files with 109 additions and 14 deletions

View File

@@ -127,30 +127,47 @@ int is_iquic(enum _QUIC_VERSION quic_version)
return FALSE;
}
int check_port(unsigned short port)
{
int i=0;
for(i=0; i< g_quic_param.quic_port_num; i++)
{
if(g_quic_param.quic_port_list[i]==port)
{
return 1;
}
}
return 0;
}
int is_quic_port(struct streaminfo *pstream)
{
unsigned short source=0, dest=0;
switch(pstream->addr.addrtype)
{
case ADDR_TYPE_IPV4:
case __ADDR_TYPE_IP_PAIR_V4:
if(ntohs(pstream->addr.ipv4->source)!=443 && ntohs(pstream->addr.ipv4->dest)!=443)
{
return 0;
}
source=(unsigned short)ntohs(pstream->addr.ipv4->source);
dest=(unsigned short)ntohs(pstream->addr.ipv4->dest);
break;
case ADDR_TYPE_IPV6:
case __ADDR_TYPE_IP_PAIR_V6:
if(ntohs(pstream->addr.ipv6->source)!=443 && ntohs(pstream->addr.ipv6->dest)!=443)
{
return 0;
}
source=(unsigned short)ntohs(pstream->addr.ipv6->source);
dest=(unsigned short)ntohs(pstream->addr.ipv6->dest);
break;
default:
return 0;
break;
}
return 1;
if(check_port(source) || check_port(dest))
{
return 1;
}
return 0;
}
static int get_value(unsigned char *payload, int *offset, int len)

View File

@@ -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", &region_id, region_name);
ret = sscanf(buff, "%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);
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;
}

View File

@@ -7,6 +7,7 @@
#define TRUE 0x01
#define MAYBE 0x02
#define SUPPORT_QUIC_PORT_NUM 128
#define QUIC_HALF_CLOSE 0x01
#define QUIC_WHOLE_CLOSE 0x02
@@ -25,7 +26,9 @@ struct _quic_param_t
unsigned long long quic_region_cnt;
unsigned short quic_plugid;
int level;
int quic_port_num;
int dump_packet_switch;
unsigned short quic_port_list[SUPPORT_QUIC_PORT_NUM];
char quic_conf_regionname[MAX_REGION_NUM][REGION_NAME_LEN];
char log_path[128];
void *logger;

View File

@@ -54,3 +54,4 @@ add_test(NAME GQUIC_50_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/
add_test(NAME MVFST_01_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/pcap/mvfst/01/${lib_name}_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/pcap/mvfst/01/ -name *.pcap|sort -V" WORKING_DIRECTORY ${PROTO_TEST_RUN_DIR})
add_test(NAME MVFST_02_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/pcap/mvfst/02/${lib_name}_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/pcap/mvfst/02/ -name *.pcap|sort -V" WORKING_DIRECTORY ${PROTO_TEST_RUN_DIR})
add_test(NAME TQUIC_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/pcap/tquic/${lib_name}_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/pcap/tquic/ -name *.pcap|sort -V" WORKING_DIRECTORY ${PROTO_TEST_RUN_DIR})
add_test(NAME IQUIC_PORT_8443_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/pcap/port-8443/${lib_name}_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/pcap/port-8443/ -name *.pcap|sort -V" WORKING_DIRECTORY ${PROTO_TEST_RUN_DIR})

View File

@@ -0,0 +1,6 @@
[{
"Tuple4": "192.168.50.49.58445>45.77.96.66.8443",
"VERSION": "IETF QUIC 29",
"SNI": "quic.tech",
"name": "QUIC_RESULT_1"
}]