summaryrefslogtreecommitdiff
path: root/plugin/business/doh/src/logger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/business/doh/src/logger.cpp')
-rw-r--r--plugin/business/doh/src/logger.cpp68
1 files changed, 52 insertions, 16 deletions
diff --git a/plugin/business/doh/src/logger.cpp b/plugin/business/doh/src/logger.cpp
index f269969..db5c0ac 100644
--- a/plugin/business/doh/src/logger.cpp
+++ b/plugin/business/doh/src/logger.cpp
@@ -299,6 +299,42 @@ int doh_kafka_init(const char *profile, struct doh_conf *conf)
return 0;
}
+static int doh_get_ip_client_geolocation(struct tfe_cmsg * cmsg, cJSON *common_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(common_obj, client_geo_area_map[j], opt_val);
+ }
+ j++;
+ }
+ return 0;
+}
+
+static int doh_get_ip_server_geolocation(struct tfe_cmsg * cmsg, cJSON *common_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(common_obj, server_geo_area_map[j], opt_val);
+ }
+ j++;
+ }
+ return 0;
+}
+
int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, const struct tfe_stream *stream, struct doh_ctx *ctx)
{
struct doh_maat_rule_t *result = ctx->result;
@@ -394,7 +430,7 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
default:
break;
}
- size_t c2s_byte_num = 0, s2c_byte_num = 0;
+ size_t ret=0, c2s_byte_num = 0, s2c_byte_num = 0;
tfe_stream_info_get(stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &c2s_byte_num, sizeof(c2s_byte_num));
tfe_stream_info_get(stream, INFO_FROM_UPSTREAM_RX_OFFSET, &s2c_byte_num, sizeof(s2c_byte_num));
@@ -432,22 +468,22 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
cJSON_AddStringToObject(common_obj, resp_fields[i].log_filed_name, tmp_val);
}
}
-
- if (ctx->location_client)
- {
- cJSON_AddStringToObject(common_obj, "client_geolocation", ctx->location_client);
- }
- if (ctx->location_server)
- {
- cJSON_AddStringToObject(common_obj, "server_geolocation", ctx->location_server);
- }
- if (ctx->asn_client)
- {
- cJSON_AddStringToObject(common_obj, "client_asn", ctx->asn_client);
- }
- if (ctx->asn_server)
+
+ if (cmsg!=NULL)
{
- cJSON_AddStringToObject(common_obj, "server_asn", ctx->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(common_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(common_obj, "server_asn", dst_asn);
+ }
+ doh_get_ip_client_geolocation(cmsg, common_obj);
+ doh_get_ip_server_geolocation(cmsg, common_obj);
}
add_dns_info_to_log(common_obj, dns_info);