Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfeae04470 | ||
|
|
513732e4f1 | ||
|
|
96f9ce34ca | ||
|
|
ffb443ed7e |
@@ -126,6 +126,7 @@ release_build_debug_for_centos7:
|
||||
BUILD_TYPE: Debug
|
||||
PACKAGE: 1
|
||||
UPLOAD_RPM: 1
|
||||
ASAN_OPTION: ADDRESS
|
||||
PULP3_REPO_NAME: protocol-stable-x86_64.el7
|
||||
PULP3_DIST_NAME: protocol-stable-x86_64.el7
|
||||
extends: .build_by_travis_for_centos7
|
||||
@@ -217,6 +218,7 @@ release_build_debug_for_centos8:
|
||||
BUILD_TYPE: Debug
|
||||
PACKAGE: 1
|
||||
UPLOAD_RPM: 1
|
||||
ASAN_OPTION: ADDRESS
|
||||
PULP3_REPO_NAME: protocol-stable-x86_64.el8
|
||||
PULP3_DIST_NAME: protocol-stable-x86_64.el8
|
||||
extends: .build_by_travis_for_centos8
|
||||
|
||||
70
demo/parse_quic_transport_parameter.cpp
Normal file
70
demo/parse_quic_transport_parameter.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
//https://jira.geedge.net/browse/OMPUB-527
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int msb2_varint_decode(const unsigned char *buf, long *out)
|
||||
{
|
||||
unsigned long val = buf[0] & 0x3f;
|
||||
unsigned int nfollow = 1<<(buf[0]>>6);
|
||||
switch (nfollow-1)
|
||||
{
|
||||
case 7: val = (val << 8) | buf[nfollow - 7]; /*fail through*/
|
||||
case 6: val = (val << 8) | buf[nfollow - 6]; /*fail through*/
|
||||
case 5: val = (val << 8) | buf[nfollow - 5]; /*fail through*/
|
||||
case 4: val = (val << 8) | buf[nfollow - 4]; /*fail through*/
|
||||
case 3: val = (val << 8) | buf[nfollow - 3]; /*fail through*/
|
||||
case 2: val = (val << 8) | buf[nfollow - 2]; /*fail through*/
|
||||
case 1: val = (val << 8) | buf[nfollow-1];
|
||||
case 0: break;
|
||||
}
|
||||
*out=val;
|
||||
|
||||
return nfollow;
|
||||
}
|
||||
|
||||
int parse_quic_transport_parameter(const char *quic_para, int quic_para_len, int thread_seq)
|
||||
{
|
||||
int one_para_length=0;
|
||||
int para_offset=0;
|
||||
long one_para_type=0;
|
||||
|
||||
while(quic_para_len > para_offset)
|
||||
{
|
||||
para_offset+=msb2_varint_decode((const unsigned char *)(quic_para+para_offset), &one_para_type);
|
||||
switch(one_para_type)
|
||||
{
|
||||
//case EXT_QUIC_PARAM_USER_AGENT: // 2021-10-20 deprecated
|
||||
case 0x3129:
|
||||
one_para_length=quic_para[para_offset++]; // length=1
|
||||
if(one_para_length+para_offset>quic_para_len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
//para_offset+=copy_extension_tag(quic_para+para_offset, one_para_length, &client_hello->user_agent, thread_seq);
|
||||
return 1;
|
||||
default:
|
||||
one_para_length=(int)(quic_para[para_offset++]); // length=1
|
||||
if(one_para_length<0 || one_para_length>quic_para_len)
|
||||
{
|
||||
break;
|
||||
}
|
||||
para_offset+=one_para_length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buff1[106]={0x80, 0x0, 0x47, 0x52, 0x4, 0x0, 0x0, 0x0, 0x1, 0x20, 0x4, 0x80, 0x1, 0x0, 0x0, 0xf, 0x0, 0x4, 0x4, 0x80, 0xf0, 0x0, 0x0, 0x8, 0x2, 0x40, 0x64, 0x7, 0x4, 0x80, 0x60, 0x0, 0x0, 0x9, 0x2, 0x40, 0x67, 0x6, 0x4, 0x80, 0x60, 0x0, 0x0, 0x80, 0xff, 0x73, 0xdb, 0xc, 0x0, 0x0, 0x0, 0x1, 0x3a, 0x6a, 0x9b, 0xaa, 0x4f, 0x2f, 0xbd, 0xc, 0xd5, 0xe2, 0xae, 0x32, 0x45, 0x6, 0x2e, 0xf, 0xc5, 0x82, 0x94, 0x3d, 0x5d, 0xb2, 0x69, 0x2c, 0x25, 0xbd, 0xd5, 0x85, 0x99, 0x72, 0xeb, 0x3, 0x2, 0x45, 0xc0, 0x1, 0x4, 0x80, 0x0, 0x75, 0x30, 0x71, 0x28, 0x4, 0x52, 0x56, 0x43, 0x4d, 0x5, 0x4, 0x80, 0x60, 0x0, 0x0};
|
||||
char buff2[99]={0x71, 0x27, 0x4, 0x80, 0x2, 0xa5, 0xb2, 0xe4, 0xcf, 0x74, 0x5b, 0xf5, 0x6, 0x41, 0x20, 0x0, 0x8, 0x2, 0x40, 0x64, 0x4, 0x4, 0x80, 0xd4, 0x9f, 0xb7, 0x6f, 0xdf, 0xed, 0x48, 0x94, 0x18, 0xd7, 0x53, 0xf7, 0x92, 0x6, 0x94, 0xa0, 0x0, 0x0, 0x1, 0x4, 0x80, 0x0, 0x75, 0x30, 0xf, 0x0, 0x80, 0xff, 0x73, 0xdb, 0xc, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x8a, 0x7a, 0x8a, 0x3a, 0x9, 0x2, 0x40, 0x67, 0x3, 0x2, 0x45, 0xc0, 0x5, 0x4, 0x80, 0x60, 0x0, 0x0, 0x71, 0x28, 0x4, 0x52, 0x56, 0x43, 0x4d, 0x20, 0x4, 0x80, 0x1, 0x0, 0x0, 0x7, 0x4, 0x80, 0x60, 0x0, 0x0};
|
||||
|
||||
parse_quic_transport_parameter(buff1, 106, 0);
|
||||
parse_quic_transport_parameter(buff2, 99, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ struct quic_info
|
||||
|
||||
//buff_len minimun 32bytes
|
||||
int quic_version_int2string(unsigned int version, char *buff, int buff_len);
|
||||
//ret: 0: not quic, >0: quic version
|
||||
unsigned int quic_protocol_identify(struct streaminfo *a_stream, void *a_packet, char *out_sni, int *out_sni_len, char *out_ua, int *out_ua_len);
|
||||
//ret: NULL: not quic, quic_info: quic version
|
||||
struct quic_info *quic_protocol_identify(const struct streaminfo *a_stream);
|
||||
|
||||
#endif /* SRC__QUIC_H__ */
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <MESA/stream_inc/stream_base.h>
|
||||
#include <MESA/MESA_handle_logger.h>
|
||||
|
||||
#include <MESA/stream.h>
|
||||
#include <MESA/MESA_prof_load.h>
|
||||
#include <MESA/MESA_handle_logger.h>
|
||||
|
||||
#include "quic.h"
|
||||
#include "quic_entry.h"
|
||||
#include "quic_process.h"
|
||||
@@ -141,47 +143,44 @@ void quic_free_client_hello(struct quic_client_hello *client_hello, int thread_s
|
||||
return ;
|
||||
}
|
||||
|
||||
void quic_free_context(void** pme, int thread_seq)
|
||||
void quic_free_context(const struct streaminfo *a_stream, int bridge_id, void *data)
|
||||
{
|
||||
if(NULL==*pme)
|
||||
if(NULL!=data)
|
||||
{
|
||||
return ;
|
||||
struct quic_context *context = (struct quic_context *)data;
|
||||
quic_free_client_hello(context->quic_info.client_hello, a_stream->threadnum);
|
||||
|
||||
dictator_free(a_stream->threadnum, data);
|
||||
}
|
||||
|
||||
struct quic_context *context = (struct quic_context *)*pme;
|
||||
quic_free_client_hello(context->quic_info.client_hello, thread_seq);
|
||||
|
||||
dictator_free(thread_seq, *pme);
|
||||
*pme=NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
extern "C" unsigned char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq, void *a_packet)
|
||||
extern "C" unsigned char QUIC_ENTRY(const struct streaminfo *pstream, void**pme, int thread_seq, const void *a_packet)
|
||||
{
|
||||
unsigned char state=0;
|
||||
struct quic_context *context=(struct quic_context *)*pme;
|
||||
|
||||
if((g_quic_param.quic_interested_region_flag<QUIC_KEY) || (!is_quic_port(pstream)))
|
||||
{
|
||||
return APP_STATE_DROPME;
|
||||
}
|
||||
|
||||
if(*pme==NULL)
|
||||
if(pstream->opstate==OP_STATE_PENDING)
|
||||
{
|
||||
quic_init_context(pme, thread_seq);
|
||||
context=(struct quic_context *)*pme;
|
||||
*pme=stream_bridge_async_data_get(pstream, g_quic_param.context_bridge_id);
|
||||
if(*pme==NULL)
|
||||
{
|
||||
*pme=dictator_malloc(thread_seq, sizeof(struct quic_context));
|
||||
memset(*pme, 0, sizeof(struct quic_context));
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char state=0;
|
||||
struct quic_context *context=(struct quic_context *)*pme;
|
||||
|
||||
state=quic_analyze_entry(pstream, context, thread_seq, a_packet);
|
||||
if(pstream->opstate==OP_STATE_CLOSE)
|
||||
{
|
||||
state=quic_call_business_plug(pstream, context, NULL, 0, QUIC_INTEREST_KEY_MASK, a_packet);
|
||||
}
|
||||
state=quic_analyze_entry(pstream, context, thread_seq, a_packet);
|
||||
|
||||
if(state&APP_STATE_DROPME || state&APP_STATE_DROPPKT || pstream->opstate==OP_STATE_CLOSE)
|
||||
{
|
||||
quic_free_context(pme, thread_seq);
|
||||
if(state&APP_STATE_DROPME || pstream->opstate==OP_STATE_CLOSE)
|
||||
{
|
||||
quic_call_business_plug(pstream, context, NULL, 0, QUIC_INTEREST_KEY_MASK, a_packet);
|
||||
quic_free_context(pstream, g_quic_param.context_bridge_id, *pme);
|
||||
stream_bridge_async_data_put(pstream, g_quic_param.context_bridge_id, NULL);
|
||||
*pme=NULL;
|
||||
return state;
|
||||
}
|
||||
@@ -233,7 +232,7 @@ extern "C" int QUIC_INIT(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(g_quic_param.quic_conf_regionname[region_id], region_name, strlen(region_name));
|
||||
memcpy(g_quic_param.quic_conf_regionname[region_id], region_name, MIN(sizeof(g_quic_param.quic_conf_regionname[region_id])-1, strlen(region_name)));
|
||||
g_quic_param.quic_region_cnt++;
|
||||
memset(region_name, 0, sizeof(region_name));
|
||||
}
|
||||
@@ -246,6 +245,9 @@ extern "C" int QUIC_INIT(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_quic_param.context_bridge_id=stream_bridge_build("QUIC_CONTEXT", "w");
|
||||
stream_bridge_register_data_free_cb(g_quic_param.context_bridge_id, quic_free_context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#include "quic.h"
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define FALSE 0x00
|
||||
#define TRUE 0x01
|
||||
#define MAYBE 0x02
|
||||
@@ -29,6 +33,7 @@ struct quic_param
|
||||
int quic_port_num;
|
||||
int decrypted_switch;
|
||||
int max_parse_pkt_num;
|
||||
int context_bridge_id;
|
||||
unsigned short quic_port_list[SUPPORT_QUIC_PORT_NUM];
|
||||
char quic_conf_regionname[MAX_REGION_NUM][REGION_NAME_LEN];
|
||||
char log_path[128];
|
||||
@@ -47,8 +52,7 @@ enum quic_mes_type{
|
||||
};
|
||||
|
||||
extern struct quic_param g_quic_param;
|
||||
int is_quic_port(struct streaminfo *pstream);
|
||||
void quic_free_client_hello(struct quic_client_hello *client_hello, int thread_seq);
|
||||
int is_quic_port(const struct streaminfo *pstream);
|
||||
|
||||
#endif /* SRC_QUIC_ANALYSIS_H_ */
|
||||
|
||||
|
||||
@@ -31,10 +31,6 @@ enum PARSE_RESULT
|
||||
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
struct quic_client_hello_msg_hdr
|
||||
{
|
||||
uint8_t handshake_type;
|
||||
@@ -57,7 +53,7 @@ int check_port(unsigned short port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_quic_port(struct streaminfo *pstream)
|
||||
int is_quic_port(const struct streaminfo *pstream)
|
||||
{
|
||||
unsigned short source=0, dest=0;
|
||||
|
||||
@@ -152,7 +148,7 @@ int quic_call_business_state(struct quic_context *context)
|
||||
return state;
|
||||
}
|
||||
|
||||
unsigned char quic_call_business_plug(struct streaminfo *pstream, struct quic_context *context, void *buff, int buff_len, enum quic_interested_region region_mask, void *a_packet)
|
||||
unsigned char quic_call_business_plug(const struct streaminfo *pstream, struct quic_context *context, void *buff, int buff_len, enum quic_interested_region region_mask, const void *a_packet)
|
||||
{
|
||||
char state=PROT_STATE_GIVEME;
|
||||
char app_state=APP_STATE_GIVEME;
|
||||
@@ -176,7 +172,7 @@ unsigned char quic_call_business_plug(struct streaminfo *pstream, struct quic_co
|
||||
session_info.buf=buff;
|
||||
session_info.buflen=buff_len;
|
||||
}
|
||||
state=PROT_PROCESS(&session_info, &(context->business_pme), pstream->threadnum, pstream, a_packet);
|
||||
state=PROT_PROCESS(&session_info, &(context->business_pme), pstream->threadnum, (struct streaminfo *)pstream, a_packet);
|
||||
|
||||
if(state&PROT_STATE_DROPPKT)
|
||||
{
|
||||
@@ -376,7 +372,11 @@ int parse_quic_transport_parameter(struct quic_client_hello *client_hello, const
|
||||
para_offset+=copy_extension_tag(quic_para+para_offset, one_para_length, &client_hello->user_agent, thread_seq);
|
||||
return 1;
|
||||
default:
|
||||
one_para_length=quic_para[para_offset++]; // length=1
|
||||
one_para_length=(int)(quic_para[para_offset++]); // length=1
|
||||
if(one_para_length<0 || one_para_length>quic_para_len)
|
||||
{
|
||||
break;
|
||||
}
|
||||
para_offset+=one_para_length;
|
||||
break;
|
||||
}
|
||||
@@ -808,12 +808,12 @@ unsigned char parse_quic_all_version(struct quic_info *quic_info, const char *pa
|
||||
}
|
||||
|
||||
|
||||
unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context* context, int thread_seq, void* a_packet)
|
||||
unsigned char quic_analyze_entry(const struct streaminfo *pstream, struct quic_context* context, int thread_seq, const void* a_packet)
|
||||
{
|
||||
unsigned char parse_result=PARSE_RESULT_UNKNOWN;
|
||||
char state=APP_STATE_GIVEME;
|
||||
|
||||
if(pstream==NULL || pstream->pudpdetail==NULL)
|
||||
if(pstream==NULL || pstream->pudpdetail==NULL || context==NULL)
|
||||
{
|
||||
return APP_STATE_DROPME;
|
||||
}
|
||||
@@ -822,7 +822,7 @@ unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context
|
||||
|
||||
switch(context->pre_parse_state)
|
||||
{
|
||||
case PARSE_RESULT_CLIENT_HELLO:
|
||||
case PARSE_RESULT_CLIENT_HELLO:
|
||||
parse_result=PARSE_RESULT_PAYLOAD;
|
||||
break;
|
||||
case PARSE_RESULT_VERSION:
|
||||
@@ -835,6 +835,20 @@ unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context
|
||||
case PARSE_RESULT_PAYLOAD:
|
||||
case PARSE_RESULT_UNKNOWN:
|
||||
default:
|
||||
if(context->parse_first_pkt==1)
|
||||
{
|
||||
context->parse_first_pkt=0;
|
||||
if(context->quic_info.client_hello==NULL)
|
||||
{
|
||||
parse_result=PARSE_RESULT_VERSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
parse_result=PARSE_RESULT_CLIENT_HELLO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if((context->parse_pkt_cnt++)>=g_quic_param.max_parse_pkt_num)
|
||||
{
|
||||
parse_result=PARSE_RESULT_PAYLOAD;
|
||||
@@ -865,49 +879,30 @@ unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context
|
||||
return state;
|
||||
}
|
||||
|
||||
static int copy_client_hello_extension(char *src, char *dest, int d_len)
|
||||
struct quic_info *quic_protocol_identify(const struct streaminfo *a_stream)
|
||||
{
|
||||
if(src==NULL || dest==NULL || d_len<=0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int len=MIN((int)strlen(src), d_len-1);
|
||||
memcpy(dest, src, len);
|
||||
dest[len]='\0';
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
unsigned int quic_protocol_identify(struct streaminfo *a_stream, void *a_packet, char *out_sni, int *out_sni_len, char *out_ua, int *out_ua_len)
|
||||
{
|
||||
unsigned char parse_result=APP_STATE_GIVEME;
|
||||
struct quic_info quic_info={0, NULL};
|
||||
unsigned int quic_version=QUIC_VERSION_UNKNOWN;
|
||||
|
||||
if(!is_quic_port(a_stream) || a_stream==NULL || a_stream->pudpdetail==NULL)
|
||||
{
|
||||
return quic_version;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
parse_result=parse_quic_all_version(&quic_info, (const char *)a_stream->pudpdetail->pdata, a_stream->pudpdetail->datalen, a_stream->threadnum);
|
||||
struct quic_info tmp_quic_info={0, NULL};
|
||||
unsigned char parse_result=APP_STATE_GIVEME;
|
||||
|
||||
parse_result=parse_quic_all_version(&tmp_quic_info, (const char *)a_stream->pudpdetail->pdata, a_stream->pudpdetail->datalen, a_stream->threadnum);
|
||||
if(parse_result!=PARSE_RESULT_UNKNOWN)
|
||||
{
|
||||
if(quic_info.client_hello!=NULL)
|
||||
{
|
||||
*out_sni_len=copy_client_hello_extension(quic_info.client_hello->sni, out_sni, *out_sni_len);
|
||||
*out_ua_len=copy_client_hello_extension(quic_info.client_hello->user_agent, out_ua, *out_ua_len);
|
||||
quic_free_client_hello(quic_info.client_hello, a_stream->threadnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
*out_sni_len=0;
|
||||
*out_ua_len=0;
|
||||
}
|
||||
|
||||
quic_version=quic_info.quic_version;
|
||||
struct quic_context *context=(struct quic_context *)dictator_malloc(a_stream->threadnum, sizeof(struct quic_context));
|
||||
memset(context, 0, sizeof(struct quic_context));
|
||||
context->quic_info=tmp_quic_info;
|
||||
context->parse_first_pkt=1;
|
||||
context->pre_parse_state=PARSE_RESULT_UNKNOWN;
|
||||
|
||||
stream_bridge_async_data_put(a_stream, g_quic_param.context_bridge_id, (void *)context);
|
||||
|
||||
return &(context->quic_info);
|
||||
}
|
||||
|
||||
return quic_version;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -284,13 +284,14 @@ struct quic_context
|
||||
unsigned char link_state;
|
||||
unsigned char parse_pkt_cnt;
|
||||
unsigned char pre_parse_state;
|
||||
unsigned char padding[5];
|
||||
unsigned char parse_first_pkt;
|
||||
unsigned char padding[4];
|
||||
void *business_pme;
|
||||
struct quic_info quic_info;
|
||||
};
|
||||
|
||||
unsigned char quic_analyze_entry(struct streaminfo *pstream, struct quic_context* context, int thread_seq, void* a_packet);
|
||||
unsigned char quic_call_business_plug(struct streaminfo *pstream, struct quic_context *context, void *buff, int buff_len, enum quic_interested_region region_mask, void *a_packet);
|
||||
unsigned char quic_analyze_entry(const struct streaminfo *pstream, struct quic_context* context, int thread_seq, const void* a_packet);
|
||||
unsigned char quic_call_business_plug(const struct streaminfo *pstream, struct quic_context *context, void *buff, int buff_len, enum quic_interested_region region_mask, const void *a_packet);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user