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 | |
| parent | 123fcf1559cbd9791614033e0d3c070171d7e678 (diff) | |
TSG-7832: 支持非标端口8443,支持配置文件配置支持识别的端口QUIC_PORT_LIST=443;8443;v1.4.4
| -rw-r--r-- | src/gquic_process.cpp | 35 | ||||
| -rw-r--r-- | src/quic_analysis.cpp | 78 | ||||
| -rw-r--r-- | src/quic_analysis.h | 3 | ||||
| -rw-r--r-- | test/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | test/pcap/port-8443/1-iquic-29-192.168.50.49.58445-45.77.96.66.8443.pcap | bin | 0 -> 50179 bytes | |||
| -rw-r--r-- | test/pcap/port-8443/quic_result.json | 6 |
6 files changed, 109 insertions, 14 deletions
diff --git a/src/gquic_process.cpp b/src/gquic_process.cpp index 9e9c3ee..f878fb7 100644 --- a/src/gquic_process.cpp +++ b/src/gquic_process.cpp @@ -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)
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; } diff --git a/src/quic_analysis.h b/src/quic_analysis.h index 29a4375..a3b3cd2 100644 --- a/src/quic_analysis.h +++ b/src/quic_analysis.h @@ -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; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 21eb5af..726506f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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}) diff --git a/test/pcap/port-8443/1-iquic-29-192.168.50.49.58445-45.77.96.66.8443.pcap b/test/pcap/port-8443/1-iquic-29-192.168.50.49.58445-45.77.96.66.8443.pcap Binary files differnew file mode 100644 index 0000000..dd8e74a --- /dev/null +++ b/test/pcap/port-8443/1-iquic-29-192.168.50.49.58445-45.77.96.66.8443.pcap diff --git a/test/pcap/port-8443/quic_result.json b/test/pcap/port-8443/quic_result.json new file mode 100644 index 0000000..89070bb --- /dev/null +++ b/test/pcap/port-8443/quic_result.json @@ -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" +}] |
