From ab492252a91f77bee363377358dbb57928a741ff Mon Sep 17 00:00:00 2001 From: fengweihao Date: Fri, 3 Apr 2020 16:16:07 +0800 Subject: [PATCH] =?UTF-8?q?TSG-1167=20proxy-event-log=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/business/pangu-http/src/pangu_http.cpp | 6 +++++- plugin/business/pangu-http/src/pangu_logger.cpp | 1 + plugin/business/pangu-http/src/pangu_logger.h | 1 + plugin/business/pangu-http/src/pattern_replace.h | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp index ec744ae..4066d77 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/pangu-http/src/pangu_http.cpp @@ -1041,6 +1041,7 @@ struct pangu_http_ctx struct policy_action_param *param; struct evbuffer* log_req_body, *log_resp_body; + size_t inject_sz; struct replace_ctx * rep_ctx; struct insert_ctx * ins_ctx; @@ -1696,6 +1697,7 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e ctx->action = PG_ACTION_NONE; return; } + ctx->inject_sz = hijack_size; char cont_len_str[16]; @@ -1748,6 +1750,7 @@ static int format_insert_rule(int profile_id, struct insert_rule *rule) rule->script = tfe_strdup(insert_profile->profile_msg); rule->type = tfe_strdup(insert_profile->profile_type); rule->position = tfe_strdup(insert_profile->profile_position); + rule->inject_sz = insert_profile->msg_len; ma_profile_table_free(insert_profile); insert_profile = NULL; @@ -1787,6 +1790,7 @@ static void http_insert(const struct tfe_stream * stream, const struct tfe_http_ ctx->action = PG_ACTION_NONE; return; } + ctx->inject_sz = ins_ctx->rule->inject_sz; } else { @@ -2474,7 +2478,7 @@ void pangu_on_http_end(const struct tfe_stream * stream, } } struct pangu_log log_msg = {.stream=stream, .http=session, .result=ctx->enforce_rules, .result_num=ctx->n_enforce, - .req_body= ctx->log_req_body, .resp_body=ctx->log_resp_body, .action=0}; + .req_body=ctx->log_req_body, .resp_body=ctx->log_resp_body, .action=0, .inject_sz=ctx->inject_sz}; if(ctx->action == PG_ACTION_MANIPULATE) { diff --git a/plugin/business/pangu-http/src/pangu_logger.cpp b/plugin/business/pangu-http/src/pangu_logger.cpp index df36e55..3a66b19 100644 --- a/plugin/business/pangu-http/src/pangu_logger.cpp +++ b/plugin/business/pangu-http/src/pangu_logger.cpp @@ -303,6 +303,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) if(log_msg->result[i].action == LG_ACTION_MANIPULATE) { cJSON_AddStringToObject(per_hit_obj, "common_sub_action", manipulate_action_map[log_msg->action]); + cJSON_AddNumberToObject(per_hit_obj, "http_action_file_sz", log_msg->inject_sz); } else { diff --git a/plugin/business/pangu-http/src/pangu_logger.h b/plugin/business/pangu-http/src/pangu_logger.h index 2da32fb..91ca8cb 100644 --- a/plugin/business/pangu-http/src/pangu_logger.h +++ b/plugin/business/pangu-http/src/pangu_logger.h @@ -12,6 +12,7 @@ struct pangu_log size_t result_num; struct evbuffer* req_body, *resp_body; unsigned char action; + size_t inject_sz; }; struct pangu_logger; struct pangu_logger* pangu_log_handle_create(const char* profile, const char* section, void* local_logger); diff --git a/plugin/business/pangu-http/src/pattern_replace.h b/plugin/business/pangu-http/src/pattern_replace.h index 4160b5c..2e85b67 100644 --- a/plugin/business/pangu-http/src/pattern_replace.h +++ b/plugin/business/pangu-http/src/pattern_replace.h @@ -23,6 +23,7 @@ struct replace_rule struct insert_rule { + int inject_sz; char * script; char * type; char * position;