TSG-20137 Proxy支持Geolication Object和Asn Object及对应日志展示
This commit is contained in:
@@ -137,6 +137,42 @@ error_out:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int get_ip_client_geolocation(struct tfe_cmsg * cmsg, cJSON *per_hit_obj)
|
||||
{
|
||||
unsigned int i=0, j=0;
|
||||
char opt_val[128]={0}; uint16_t opt_out_size;
|
||||
const char *client_geo_area_map[] = {"client_country","client_province","client_city","client_subdivision"};
|
||||
|
||||
for(i=TFE_CMSG_SRC_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2)
|
||||
{
|
||||
int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
|
||||
if (ret == 0)
|
||||
{
|
||||
cJSON_AddStringToObject(per_hit_obj, client_geo_area_map[j], opt_val);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_ip_server_geolocation(struct tfe_cmsg * cmsg, cJSON *per_hit_obj)
|
||||
{
|
||||
unsigned int i=0, j=0;
|
||||
char opt_val[128]={0}; uint16_t opt_out_size;
|
||||
const char *server_geo_area_map[] = {"server_country","server_province","server_city","server_subdivision"};
|
||||
|
||||
for(i=TFE_CMSG_DST_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2)
|
||||
{
|
||||
int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
|
||||
if (ret == 0)
|
||||
{
|
||||
cJSON_AddStringToObject(per_hit_obj, server_geo_area_map[j], opt_val);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
|
||||
{
|
||||
const struct tfe_http_session* http=log_msg->http;
|
||||
@@ -390,21 +426,21 @@ int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
|
||||
{
|
||||
cJSON_AddStringToObject(per_hit_obj, "proxy_action", panggu_action_map[(unsigned char)(log_msg->result[i].action)]);
|
||||
}
|
||||
if(log_msg->location_client)
|
||||
{
|
||||
cJSON_AddStringToObject(per_hit_obj, "client_geolocation", log_msg->location_client);
|
||||
}
|
||||
if(log_msg->location_server)
|
||||
{
|
||||
cJSON_AddStringToObject(per_hit_obj, "server_geolocation", log_msg->location_server);
|
||||
}
|
||||
if(log_msg->asn_client)
|
||||
if (cmsg!=NULL)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "client_asn", log_msg->asn_client);
|
||||
}
|
||||
if (log_msg->asn_server)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "server_asn", log_msg->asn_server);
|
||||
uint64_t src_asn=0, dst_asn=0;
|
||||
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_SRC_ASN_VAL, (unsigned char *)&src_asn, sizeof(src_asn), &opt_out_size);
|
||||
if (ret == 0)
|
||||
{
|
||||
cJSON_AddNumberToObject(per_hit_obj, "client_asn", src_asn);
|
||||
}
|
||||
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_DST_ASN_VAL, (unsigned char *)&dst_asn, sizeof(dst_asn), &opt_out_size);
|
||||
if (ret == 0)
|
||||
{
|
||||
cJSON_AddNumberToObject(per_hit_obj, "server_asn", dst_asn);
|
||||
}
|
||||
get_ip_client_geolocation(cmsg, per_hit_obj);
|
||||
get_ip_server_geolocation(cmsg, per_hit_obj);
|
||||
}
|
||||
|
||||
log_payload = cJSON_PrintUnformatted(per_hit_obj);
|
||||
|
||||
Reference in New Issue
Block a user