summaryrefslogtreecommitdiff
path: root/plugin/business/doh/src/logger.cpp
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2024-08-30 10:25:16 +0800
committerfengweihao <[email protected]>2024-08-30 10:25:16 +0800
commit80eed59202b83935d37a12e1b3fb1dc7414f808f (patch)
tree42848fb7f5bf23b01e790a794b21757df29af9f7 /plugin/business/doh/src/logger.cpp
parent9e2b08ab53f2b62e0e0e33b3bb2b7aebbd1a0229 (diff)
TSG-22316 Manipulation支持Device相关策略的扫描与日志发送, TSG-22051 Manipulation日志发送Library相关字段, TSG-22256 Manipulation日志发送Incoming Link ID和Outgoing Link ID等字段
Diffstat (limited to 'plugin/business/doh/src/logger.cpp')
-rw-r--r--plugin/business/doh/src/logger.cpp97
1 files changed, 42 insertions, 55 deletions
diff --git a/plugin/business/doh/src/logger.cpp b/plugin/business/doh/src/logger.cpp
index f099b05..8eca5bf 100644
--- a/plugin/business/doh/src/logger.cpp
+++ b/plugin/business/doh/src/logger.cpp
@@ -1,3 +1,4 @@
+#include "tfe_scan.h"
#include "logger.h"
#include "kafka.h"
@@ -292,7 +293,7 @@ int doh_kafka_init(const char *profile, struct doh_conf *conf)
return 0;
}
-int doh_add_host_to_object(cJSON *common_obj, const char *req_spec_host)
+int doh_get_format_host(cJSON *common_obj, const char *req_spec_host)
{
unsigned int port;
char *format_host=ALLOC(char, strlen(req_spec_host)+1);
@@ -303,27 +304,35 @@ int doh_add_host_to_object(cJSON *common_obj, const char *req_spec_host)
return 0;
}
-int doh_tags_line_to_json_array(cJSON *per_hit_obj, const char *tags_key, char *opt_val)
+int doh_get_integer_by_cmsg(cJSON *common_obj, struct tfe_cmsg * cmsg, enum tfe_cmsg_tlv_type type, const char *keyword)
{
- if(per_hit_obj == NULL || tags_key == NULL || opt_val == NULL)
+ uint16_t opt_out_size = 0;
+ unsigned int integer = 0;
+
+ int ret = tfe_cmsg_get_value(cmsg, type, (unsigned char *)&integer, sizeof(integer), &opt_out_size);
+ if(ret == 0 && type == TFE_CMSG_COMMON_DIRECTION)
+ {
+ const char *direction = (integer == 69) ? "Outbound" : "Inbound";
+ cJSON_AddStringToObject(common_obj, keyword, direction);
+ }
+ if (ret == 0 && type != TFE_CMSG_COMMON_DIRECTION)
{
- return 0;
+ cJSON_AddNumberToObject(common_obj, keyword, integer);
}
+ return 0;
+}
- char *opt_val_tmp = strdup(opt_val);
- cJSON *tags_array = cJSON_CreateArray();
+int doh_get_string_by_cmsg(cJSON *common_obj, struct tfe_cmsg * cmsg, enum tfe_cmsg_tlv_type type, const char *keyword)
+{
+ char opt_val[128]={0};
+ uint16_t opt_out_size = 0;
- char *token = strtok(opt_val_tmp, ",");
- while (token != NULL)
+ int ret=tfe_cmsg_get_value(cmsg, type, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
+ if (ret == 0 && opt_out_size > 0)
{
- while (*token == ' ') token++;
- cJSON_AddItemToArray(tags_array, cJSON_CreateString(token));
- token = strtok(NULL, ",");
- }
- cJSON_AddItemToObject(per_hit_obj, tags_key, tags_array);
-
- FREE(&opt_val_tmp)
- return 1;
+ cJSON_AddStringToObject(common_obj, keyword, opt_val);
+ }
+ 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)
@@ -361,23 +370,25 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
cJSON_AddStringToObject(common_obj, "doh_version", app_proto[http->major_version]);
cJSON_AddStringToObject(common_obj, "decoded_as", "DoH");
- char opt_val[24]={0};
- char source_subscribe_id[64]={0};
- uint16_t opt_out_size;
struct tfe_cmsg *cmsg = tfe_stream_get0_cmsg(stream);
if (cmsg != NULL)
{
- int ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_STREAM_TRACE_ID, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
- if (ret == 0)
- {
- cJSON_AddStringToObject(common_obj, "session_id", opt_val);
- }
- ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_SRC_SUB_ID, (unsigned char *)source_subscribe_id, sizeof(source_subscribe_id), &opt_out_size);
- if (ret==0)
- {
- cJSON_AddStringToObject(common_obj, "subscriber_id", source_subscribe_id);
- }
+ doh_get_string_by_cmsg(common_obj, cmsg, TFE_CMSG_STREAM_TRACE_ID, "session_id");
+ doh_get_string_by_cmsg(common_obj, cmsg, TFE_CMSG_SRC_SUB_ID, "subscriber_id");
+
+ doh_get_string_by_cmsg(common_obj, cmsg, TFE_CMSG_SRC_IMSI_STR, "imsi");
+ doh_get_string_by_cmsg(common_obj, cmsg, TFE_CMSG_SRC_IMEI_STR, "imei");
+ doh_get_string_by_cmsg(common_obj, cmsg, TFE_CMSG_SRC_PHONE_NUM_STR, "phone_number");
+ doh_get_string_by_cmsg(common_obj, cmsg, TFE_CMSG_SRC_APN_STR, "apn");
+
+ doh_get_integer_by_cmsg(common_obj, cmsg, TFE_CMSG_INCOMING_LINK_ID, "in_link_id");
+ doh_get_integer_by_cmsg(common_obj, cmsg, TFE_CMSG_OUTGOING_LINK_ID, "out_link_id");
+ doh_get_integer_by_cmsg(common_obj, cmsg, TFE_CMSG_COMMON_DIRECTION, "direction");
}
+
+ tfe_get_library_tags(stream, common_obj, TFE_CMSG_SRC_IP_TAGS_IDS_STR, "client_ip_tags");
+ tfe_get_library_tags(stream, common_obj, TFE_CMSG_DST_IP_TAGS_IDS_STR, "server_ip_tags");
+ tfe_get_library_tags(stream, common_obj, TFE_CMSG_FQDN_TAGS_IDS_STR, "server_fqdn_tags");
if (http->req)
{
@@ -420,7 +431,7 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
default:
break;
}
- size_t ret=0, c2s_byte_num = 0, s2c_byte_num = 0;
+ size_t 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));
@@ -434,7 +445,7 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
cJSON_AddNumberToObject(common_obj, "sent_bytes", c2s_byte_num);
cJSON_AddNumberToObject(common_obj, "received_bytes", s2c_byte_num);
cJSON_AddStringToObject(common_obj, "doh_url", http->req->req_spec.url);
- doh_add_host_to_object(common_obj, http->req->req_spec.host);
+ doh_get_format_host(common_obj, http->req->req_spec.host);
if(tfe_get_device_tag())
{
@@ -457,30 +468,6 @@ 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 (cmsg!=NULL)
- {
- char opt_val[128]={0}; uint16_t opt_out_size=0;
- ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)64, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
- if (ret == 0 && strlen(opt_val) > 0)
- {
- doh_tags_line_to_json_array(common_obj, "client_ip_tags", opt_val);
- }
-
- memset(opt_val, 0, sizeof(opt_val));
- ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)65, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
- if (ret == 0 && strlen(opt_val) > 0)
- {
- doh_tags_line_to_json_array(common_obj, "server_ip_tags", opt_val);
- }
-
- memset(opt_val, 0, sizeof(opt_val));
- ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)63, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
- if (ret == 0 && strlen(opt_val) > 0)
- {
- doh_tags_line_to_json_array(common_obj, "server_fqdn_tags", opt_val);
- }
- }
add_dns_info_to_log(common_obj, dns_info);
for (size_t i = 0; i < result_num; i++)