共享链接属性流标签结构体:https://jira.geedge.net/browse/TSG-2848
This commit is contained in:
@@ -54,5 +54,6 @@ install(FILES bin/tsg_maat.json DESTINATION ${CMAKE_INSTALL_PREFIX}/tsgconf COMP
|
||||
install(FILES inc/tsg_send_log.h DESTINATION /opt/MESA/include/tsg COMPONENT HEADER)
|
||||
install(FILES inc/tsg_rule.h DESTINATION /opt/MESA/include/tsg COMPONENT HEADER)
|
||||
install(FILES inc/tsg_statistic.h DESTINATION /opt/MESA/include/tsg COMPONENT HEADER)
|
||||
install(FILES inc/tsg_label.h DESTINATION /opt/MESA/include/tsg COMPONENT HEADER)
|
||||
|
||||
include(Package)
|
||||
|
||||
78
inc/tsg_label.h
Normal file
78
inc/tsg_label.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef __TSG_LABEL_H__
|
||||
#define __TSG_LABEL_H__
|
||||
|
||||
#define MAX_STR_FIELD_LEN 64
|
||||
|
||||
typedef enum _tsg_protocol
|
||||
{
|
||||
PROTO_UNKONWN=0,
|
||||
PROTO_IPv4=1,
|
||||
PROTO_IPv6,
|
||||
PROTO_TCP,
|
||||
PROTO_UDP,
|
||||
PROTO_HTTP,
|
||||
PROTO_MAIL,
|
||||
PROTO_DNS,
|
||||
PROTO_FTP,
|
||||
PROTO_SSL,
|
||||
PROTO_SIP,
|
||||
PROTO_BGP,
|
||||
PROTO_STREAMING_MEDIA,
|
||||
PROTO_QUIC,
|
||||
PROTO_MAX
|
||||
}tsg_protocol_t;
|
||||
|
||||
|
||||
struct _asn_info_t
|
||||
{
|
||||
int ref_cnt;
|
||||
int addr_type;
|
||||
int table_id;
|
||||
char start_ip[MAX_STR_FIELD_LEN];
|
||||
char end_ip[MAX_STR_FIELD_LEN];
|
||||
char asn[MAX_STR_FIELD_LEN];
|
||||
char organization[MAX_STR_FIELD_LEN*4];
|
||||
};
|
||||
|
||||
struct _location_info_t
|
||||
{
|
||||
int geoname_id;
|
||||
int table_id;
|
||||
int ref_cnt;
|
||||
int addr_type;
|
||||
double latitude;
|
||||
double longitude;
|
||||
double coords;
|
||||
char start_ip[MAX_STR_FIELD_LEN];
|
||||
char end_ip[MAX_STR_FIELD_LEN];
|
||||
char language[MAX_STR_FIELD_LEN];
|
||||
char continent_abbr[MAX_STR_FIELD_LEN*4];
|
||||
char continent_full[MAX_STR_FIELD_LEN*4];
|
||||
char country_abbr[MAX_STR_FIELD_LEN*4];
|
||||
char country_full[MAX_STR_FIELD_LEN*4];
|
||||
char province_abbr[MAX_STR_FIELD_LEN*4];
|
||||
char province_full[MAX_STR_FIELD_LEN*4];
|
||||
char city_full[MAX_STR_FIELD_LEN*4];
|
||||
char time_zone[MAX_STR_FIELD_LEN*4];
|
||||
};
|
||||
|
||||
struct _subscribe_id_info_t
|
||||
{
|
||||
int ref_cnt;
|
||||
int table_id;
|
||||
char subscribe_id[MAX_STR_FIELD_LEN*4];
|
||||
};
|
||||
|
||||
struct _session_attribute_label_t
|
||||
{
|
||||
tsg_protocol_t proto;
|
||||
long establish_latency_ms;
|
||||
struct _asn_info_t *client_asn;
|
||||
struct _asn_info_t *server_asn;
|
||||
struct _location_info_t *client_location;
|
||||
struct _location_info_t *server_location;
|
||||
struct _subscribe_id_info_t *client_subscribe_id;
|
||||
struct _subscribe_id_info_t *server_subscribe_id;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <MESA/Maat_rule.h>
|
||||
|
||||
#include "tsg_label.h"
|
||||
|
||||
#define TSG_ACTION_NONE 0x00
|
||||
#define TSG_ACTION_MONITOR 0x01
|
||||
#define TSG_ACTION_INTERCEPT 0x02
|
||||
@@ -22,27 +24,6 @@ enum TSG_ETHOD_TYPE
|
||||
TSG_METHOD_TYPE_MAX
|
||||
};
|
||||
|
||||
|
||||
typedef enum _tsg_protocol
|
||||
{
|
||||
PROTO_UNKONWN=0,
|
||||
PROTO_IPv4=1,
|
||||
PROTO_IPv6,
|
||||
PROTO_TCP,
|
||||
PROTO_UDP,
|
||||
PROTO_HTTP,
|
||||
PROTO_MAIL,
|
||||
PROTO_DNS,
|
||||
PROTO_FTP,
|
||||
PROTO_SSL,
|
||||
PROTO_SIP,
|
||||
PROTO_BGP,
|
||||
PROTO_STREAMING_MEDIA,
|
||||
PROTO_QUIC,
|
||||
PROTO_MAX
|
||||
}tsg_protocol_t;
|
||||
|
||||
|
||||
#define MAX_RESULT_NUM 8
|
||||
#define MAX_DOAMIN_LEN 2048
|
||||
|
||||
@@ -53,18 +34,6 @@ struct _identify_info
|
||||
char domain[MAX_DOAMIN_LEN];
|
||||
};
|
||||
|
||||
struct _internal_label
|
||||
{
|
||||
tsg_protocol_t proto;
|
||||
long establish_latency_ms;
|
||||
struct _asn_info *client_asn;
|
||||
struct _asn_info *server_asn;
|
||||
struct _location_info *client_location;
|
||||
struct _location_info *server_location;
|
||||
struct _subscribe_id_info *client_subscribe_id;
|
||||
struct _subscribe_id_info *server_subscribe_id;
|
||||
};
|
||||
|
||||
|
||||
typedef enum _PULL_RESULT_TYPE
|
||||
{
|
||||
|
||||
@@ -117,9 +117,9 @@ static void free_policy_label(int thread_seq, void *project_req_value)
|
||||
project_req_value=NULL;
|
||||
}
|
||||
|
||||
static void free_internal_label(int thread_seq, void *project_req_value)
|
||||
static void free_session_attribute_label(int thread_seq, void *project_req_value)
|
||||
{
|
||||
struct _internal_label *label=(struct _internal_label *)project_req_value;
|
||||
struct _session_attribute_label_t *label=(struct _session_attribute_label_t *)project_req_value;
|
||||
|
||||
if(label!=NULL)
|
||||
{
|
||||
@@ -531,7 +531,7 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t
|
||||
Maat_rule_t all_result[MAX_RESULT_NUM];
|
||||
policy_priority_label_t *priority_label=NULL;
|
||||
struct _master_context *_context=(struct _master_context *)*pme;
|
||||
struct _internal_label *internal_label=NULL;
|
||||
struct _session_attribute_label_t *internal_label=NULL;
|
||||
switch(a_tcp->opstate)
|
||||
{
|
||||
case OP_STATE_PENDING:
|
||||
@@ -540,8 +540,8 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t
|
||||
memset(&identify_info, 0, sizeof(identify_info));
|
||||
identify_application_protocol(a_tcp, &identify_info, a_packet);
|
||||
|
||||
internal_label=(struct _internal_label *)dictator_malloc(1, sizeof(struct _internal_label));
|
||||
memset(internal_label, 0, sizeof(struct _internal_label));
|
||||
internal_label=(struct _session_attribute_label_t *)dictator_malloc(1, sizeof(struct _session_attribute_label_t));
|
||||
memset(internal_label, 0, sizeof(struct _session_attribute_label_t));
|
||||
internal_label->proto=identify_info.proto;
|
||||
|
||||
if(identify_info.proto==PROTO_HTTP)
|
||||
@@ -731,7 +731,7 @@ extern "C" char TSG_MASTER_UDP_ENTRY(struct streaminfo *a_udp, void **pme, int t
|
||||
Maat_rule_t result[MAX_RESULT_NUM]={0};
|
||||
struct _identify_info identify_info;
|
||||
struct _master_context *_context=(struct _master_context *)*pme;
|
||||
struct _internal_label *internal_label=NULL;
|
||||
struct _session_attribute_label_t *internal_label=NULL;
|
||||
|
||||
switch(a_udp->opstate)
|
||||
{
|
||||
@@ -739,8 +739,8 @@ extern "C" char TSG_MASTER_UDP_ENTRY(struct streaminfo *a_udp, void **pme, int t
|
||||
memset(&identify_info, 0, sizeof(identify_info));
|
||||
identify_application_protocol(a_udp, &identify_info, a_packet);
|
||||
|
||||
internal_label=(struct _internal_label *)dictator_malloc(1, sizeof(struct _internal_label));
|
||||
memset(internal_label, 0, sizeof(struct _internal_label));
|
||||
internal_label=(struct _session_attribute_label_t *)dictator_malloc(1, sizeof(struct _session_attribute_label_t));
|
||||
memset(internal_label, 0, sizeof(struct _session_attribute_label_t));
|
||||
internal_label->proto=identify_info.proto;
|
||||
|
||||
ret=project_req_add_struct(a_udp, g_tsg_para.internal_project_id, (const void *)internal_label);
|
||||
@@ -934,7 +934,7 @@ extern "C" int TSG_MASTER_INIT()
|
||||
}
|
||||
|
||||
MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "TSG_MASTER_INTERNAL_LABEL", label_buff, sizeof(label_buff), "TSG_MASTER_INTERNAL_LABEL");
|
||||
g_tsg_para.internal_project_id=project_producer_register(label_buff, PROJECT_VAL_TYPE_STRUCT, free_internal_label);
|
||||
g_tsg_para.internal_project_id=project_producer_register(label_buff, PROJECT_VAL_TYPE_STRUCT, free_session_attribute_label);
|
||||
if(g_tsg_para.internal_project_id<0)
|
||||
{
|
||||
MESA_handle_runtime_log(g_tsg_para.logger,
|
||||
|
||||
@@ -61,45 +61,6 @@ struct _str2index
|
||||
char *type;
|
||||
};
|
||||
|
||||
struct _asn_info
|
||||
{
|
||||
int ref_cnt;
|
||||
int addr_type;
|
||||
char start_ip[40];
|
||||
char end_ip[40];
|
||||
char asn[40];
|
||||
char organization[256];
|
||||
int table_id;
|
||||
};
|
||||
|
||||
struct _location_info
|
||||
{
|
||||
int ref_cnt;
|
||||
int addr_type;
|
||||
char start_ip[40];
|
||||
char end_ip[40];
|
||||
double latitude;
|
||||
double longitude;
|
||||
double coords;
|
||||
char language[40];
|
||||
char continent_abbr[256];
|
||||
char continent_full[256];
|
||||
char country_abbr[256];
|
||||
char country_full[256];
|
||||
char province_abbr[256];
|
||||
char province_full[256];
|
||||
char city_full[256];
|
||||
char time_zone[128];
|
||||
int geoname_id;
|
||||
int table_id;
|
||||
};
|
||||
|
||||
struct _subscribe_id_info
|
||||
{
|
||||
int ref_cnt;
|
||||
int table_id;
|
||||
char subscribe_id[256];
|
||||
};
|
||||
|
||||
typedef struct _policy_priority_label
|
||||
{
|
||||
@@ -138,8 +99,6 @@ typedef struct _tsg_para
|
||||
|
||||
extern g_tsg_para_t g_tsg_para;
|
||||
|
||||
|
||||
|
||||
typedef enum _tsg_statis_field_id
|
||||
{
|
||||
STATIS_UNKNOWN=0,
|
||||
|
||||
@@ -96,7 +96,7 @@ static char* str_unescape(char* s)
|
||||
void ASN_dup_data(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void* argp)
|
||||
{
|
||||
void *logger=argp;
|
||||
struct _asn_info *asn=(struct _asn_info *)(*from);
|
||||
struct _asn_info_t *asn=(struct _asn_info_t *)(*from);
|
||||
|
||||
atomic_inc(&asn->ref_cnt);
|
||||
*to=*from;
|
||||
@@ -121,8 +121,8 @@ void ASN_new_data(int table_id, const char* key, const char* table_line, MAAT_PL
|
||||
void *logger=argp;
|
||||
int ret=0,id=0,is_valid=0;
|
||||
|
||||
struct _asn_info *asn=NULL;
|
||||
asn=(struct _asn_info *)calloc(1, sizeof(struct _asn_info));
|
||||
struct _asn_info_t *asn=NULL;
|
||||
asn=(struct _asn_info_t *)calloc(1, sizeof(struct _asn_info_t));
|
||||
|
||||
ret=sscanf(table_line, "%d\t%d\t%s\t%s\t%s\t%s\t%d", &id, &asn->addr_type, asn->start_ip, asn->end_ip, asn->asn, asn->organization, &is_valid);
|
||||
if(ret!=7)
|
||||
@@ -164,7 +164,7 @@ void ASN_new_data(int table_id, const char* key, const char* table_line, MAAT_PL
|
||||
void ASN_free_data(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
||||
{
|
||||
void *logger=argp;
|
||||
struct _asn_info *asn=(struct _asn_info *)(*ad);
|
||||
struct _asn_info_t *asn=(struct _asn_info_t *)(*ad);
|
||||
|
||||
MESA_handle_runtime_log(logger,
|
||||
RLOG_LV_DEBUG,
|
||||
@@ -191,7 +191,7 @@ void ASN_free_data(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
||||
void location_dup_data(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void* argp)
|
||||
{
|
||||
void *logger=argp;
|
||||
struct _location_info *location=(struct _location_info *)(*from);
|
||||
struct _location_info_t *location=(struct _location_info_t *)(*from);
|
||||
|
||||
atomic_inc(&location->ref_cnt);
|
||||
*to=*from;
|
||||
@@ -217,9 +217,9 @@ void location_new_data(int table_id, const char* key, const char* table_line, MA
|
||||
{
|
||||
void *logger=argp;
|
||||
int ret=0,id=0,is_valid=0;
|
||||
struct _location_info *location=NULL;
|
||||
struct _location_info_t *location=NULL;
|
||||
|
||||
location=(struct _location_info *)calloc(1, sizeof(struct _location_info));
|
||||
location=(struct _location_info_t *)calloc(1, sizeof(struct _location_info_t));
|
||||
|
||||
ret=sscanf(table_line,
|
||||
"%d\t%d\t%d\t%s\t%s\t%lf\t%lf\t%lf\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d",
|
||||
@@ -286,7 +286,7 @@ void location_new_data(int table_id, const char* key, const char* table_line, MA
|
||||
void location_free_data(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
||||
{
|
||||
void *logger=argp;
|
||||
struct _location_info *location=(struct _location_info *)(*ad);
|
||||
struct _location_info_t *location=(struct _location_info_t *)(*ad);
|
||||
|
||||
MESA_handle_runtime_log(logger,
|
||||
RLOG_LV_DEBUG,
|
||||
@@ -317,7 +317,7 @@ void location_free_data(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void*
|
||||
void subscribe_id_dup_data(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void* argp)
|
||||
{
|
||||
void *logger=argp;
|
||||
struct _subscribe_id_info *subscribe_id=(struct _subscribe_id_info *)(*from);
|
||||
struct _subscribe_id_info_t *subscribe_id=(struct _subscribe_id_info_t *)(*from);
|
||||
|
||||
atomic_inc(&subscribe_id->ref_cnt);
|
||||
*to=*from;
|
||||
@@ -332,9 +332,9 @@ void subscribe_id_new_data(int table_id, const char* key, const char* table_line
|
||||
void *logger=argp;
|
||||
int ret=0,id=0,type=0,is_valid=0;
|
||||
char ip_addr[MAX_IPV6_ADDR_LEN]={0};
|
||||
struct _subscribe_id_info *subscribe_id=NULL;
|
||||
struct _subscribe_id_info_t *subscribe_id=NULL;
|
||||
|
||||
subscribe_id=(struct _subscribe_id_info *)calloc(1, sizeof(struct _subscribe_id_info));
|
||||
subscribe_id=(struct _subscribe_id_info_t *)calloc(1, sizeof(struct _subscribe_id_info_t));
|
||||
|
||||
ret=sscanf(table_line, "%d\t%d\t%s\t%s\t%d", &id, &type, ip_addr, subscribe_id->subscribe_id, &is_valid);
|
||||
if(ret!=5)
|
||||
@@ -373,7 +373,7 @@ void subscribe_id_new_data(int table_id, const char* key, const char* table_line
|
||||
void subscribe_id_free_data(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
||||
{
|
||||
void *logger=argp;
|
||||
struct _subscribe_id_info *subscribe_id=(struct _subscribe_id_info *)(*ad);
|
||||
struct _subscribe_id_info_t *subscribe_id=(struct _subscribe_id_info_t *)(*ad);
|
||||
|
||||
MESA_handle_runtime_log(logger, RLOG_LV_DEBUG, "SUBSCRIBE_ID", "Delete(table_id: %d ) subscribe_id: %s ref_cnt: %d", table_id, subscribe_id->subscribe_id, subscribe_id->ref_cnt);
|
||||
|
||||
@@ -738,7 +738,7 @@ int tsg_get_ip_location(const struct streaminfo *a_stream, int table_id, MAAT_PL
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsg_get_subscribe_id(const struct streaminfo *a_stream, struct _subscribe_id_info **source_subscribe_id, struct _subscribe_id_info **dest_subscribe_id)
|
||||
int tsg_get_subscribe_id(const struct streaminfo *a_stream, struct _subscribe_id_info_t **source_subscribe_id, struct _subscribe_id_info_t **dest_subscribe_id)
|
||||
{
|
||||
char source_ip[MAX_IPV6_ADDR_LEN]={0};
|
||||
char dest_ip[MAX_IPV6_ADDR_LEN]={0};
|
||||
@@ -763,18 +763,18 @@ int tsg_get_subscribe_id(const struct streaminfo *a_stream, struct _subscribe_id
|
||||
|
||||
if(strlen(dest_ip)>0 && *dest_subscribe_id==NULL)
|
||||
{
|
||||
*dest_subscribe_id = (struct _subscribe_id_info *)Maat_plugin_get_EX_data(g_tsg_dynamic_maat_feather, g_tsg_para.dyn_subscribe_ip_table_id, dest_ip);
|
||||
*dest_subscribe_id = (struct _subscribe_id_info_t *)Maat_plugin_get_EX_data(g_tsg_dynamic_maat_feather, g_tsg_para.dyn_subscribe_ip_table_id, dest_ip);
|
||||
}
|
||||
|
||||
if(strlen(source_ip)>0 && *source_subscribe_id==NULL)
|
||||
{
|
||||
*source_subscribe_id = (struct _subscribe_id_info *)Maat_plugin_get_EX_data(g_tsg_dynamic_maat_feather, g_tsg_para.dyn_subscribe_ip_table_id, source_ip);
|
||||
*source_subscribe_id = (struct _subscribe_id_info_t *)Maat_plugin_get_EX_data(g_tsg_dynamic_maat_feather, g_tsg_para.dyn_subscribe_ip_table_id, source_ip);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tsg_scan_ip_asn(Maat_feather_t maat_feather, const struct streaminfo *a_stream, struct _asn_info *asn, enum MASTER_TABLE idx, scan_status_t *mid, Maat_rule_t*result, int result_num)
|
||||
int tsg_scan_ip_asn(Maat_feather_t maat_feather, const struct streaminfo *a_stream, struct _asn_info_t *asn, enum MASTER_TABLE idx, scan_status_t *mid, Maat_rule_t*result, int result_num)
|
||||
{
|
||||
int ret=0;
|
||||
|
||||
@@ -834,7 +834,7 @@ int tsg_scan_ip_asn(Maat_feather_t maat_feather, const struct streaminfo *a_stre
|
||||
}
|
||||
|
||||
|
||||
int tsg_scan_ip_location(Maat_feather_t maat_feather, const struct streaminfo *a_stream, struct _location_info *location, enum MASTER_TABLE idx, scan_status_t *mid, Maat_rule_t*result, int result_num)
|
||||
int tsg_scan_ip_location(Maat_feather_t maat_feather, const struct streaminfo *a_stream, struct _location_info_t *location, enum MASTER_TABLE idx, scan_status_t *mid, Maat_rule_t*result, int result_num)
|
||||
{
|
||||
int ret=0;
|
||||
char buff[1024]={0};
|
||||
@@ -903,7 +903,7 @@ int tsg_scan_nesting_addr(Maat_feather_t maat_feather, const struct streaminfo *
|
||||
int hit_num=0,tans_proto=0;
|
||||
int is_scan_addr=1, maat_ret=0,found_pos=0;
|
||||
const struct streaminfo *cur_stream = a_stream;
|
||||
struct _internal_label *internal_label=NULL;
|
||||
struct _session_attribute_label_t *internal_label=NULL;
|
||||
|
||||
if(result==NULL || result_num<=0 || a_stream==NULL || maat_feather==NULL)
|
||||
{
|
||||
@@ -1035,11 +1035,11 @@ int tsg_scan_nesting_addr(Maat_feather_t maat_feather, const struct streaminfo *
|
||||
}
|
||||
}
|
||||
|
||||
internal_label=(struct _internal_label *)project_req_get_struct(a_stream, g_tsg_para.internal_project_id);
|
||||
internal_label=(struct _session_attribute_label_t *)project_req_get_struct(a_stream, g_tsg_para.internal_project_id);
|
||||
if(internal_label==NULL)
|
||||
{
|
||||
internal_label=(struct _internal_label *)calloc(1, sizeof(struct _internal_label));
|
||||
memset(internal_label, 0, sizeof(struct _internal_label));
|
||||
internal_label=(struct _session_attribute_label_t *)calloc(1, sizeof(struct _session_attribute_label_t));
|
||||
memset(internal_label, 0, sizeof(struct _session_attribute_label_t));
|
||||
}
|
||||
|
||||
if(hit_num<result_num)
|
||||
|
||||
@@ -186,10 +186,10 @@ static int set_common_sub_action(struct TLD_handle_t *handle, char *field_name,
|
||||
int set_common_field_from_label(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream)
|
||||
{
|
||||
char buff[512]={0};
|
||||
struct _location_info *location=NULL;
|
||||
struct _internal_label *internal_label=NULL;
|
||||
struct _location_info_t *location=NULL;
|
||||
struct _session_attribute_label_t *internal_label=NULL;
|
||||
|
||||
internal_label=(struct _internal_label *)project_req_get_struct(a_stream, _instance->internal_project_id);
|
||||
internal_label=(struct _session_attribute_label_t *)project_req_get_struct(a_stream, _instance->internal_project_id);
|
||||
if(internal_label!=NULL)
|
||||
{
|
||||
TLD_append(_handle, _instance->id2field[LOG_COMMON_ESTABLISH_LATENCY_MS].name, (void *)internal_label->establish_latency_ms, TLD_TYPE_LONG);
|
||||
|
||||
Reference in New Issue
Block a user