summaryrefslogtreecommitdiff
path: root/plugin/business/tsg-http/src
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2024-10-30 16:26:38 +0800
committerfengweihao <[email protected]>2024-10-30 16:26:38 +0800
commit2b7d35c5c837cdf54f117d280a682057665123bf (patch)
tree6d00ef718610e2667422c842d5c007077762b97c /plugin/business/tsg-http/src
parentedd0209fcd2efe2ebb45719b6facc3f4de74467f (diff)
TSG-23072 Change the Policies-Manipulation log field from proxy_rule_list to proxy_rule_uuid_listv4.10.6-20241030
TSG-23090 Change the action field in the Metric structure proxy_rule_hits to the string type
Diffstat (limited to 'plugin/business/tsg-http/src')
-rw-r--r--plugin/business/tsg-http/src/tsg_http.cpp126
-rw-r--r--plugin/business/tsg-http/src/tsg_logger.cpp2
2 files changed, 70 insertions, 58 deletions
diff --git a/plugin/business/tsg-http/src/tsg_http.cpp b/plugin/business/tsg-http/src/tsg_http.cpp
index 02b28ce..d468699 100644
--- a/plugin/business/tsg-http/src/tsg_http.cpp
+++ b/plugin/business/tsg-http/src/tsg_http.cpp
@@ -461,57 +461,9 @@ unsigned char log_option_type_str2idx(const char *log_option)
return i;
}
-void policy_action_param_new(const char *table_name, const char* key, const char* table_line, void **ad, long argl, void* argp)
+void policy_set_param_by_action(struct policy_action_param* param, cJSON *action_parameter)
{
- cJSON* pxy_ctrl_rule = cJSON_Parse(table_line);
- if(pxy_ctrl_rule == NULL)
- {
- TFE_LOG_ERROR(g_proxy_rt->local_logger, "PXY_CTRL_RULE parse table_line failed. table_line:%s", table_line);
- return;
- }
-
- struct policy_action_param* param=ALLOC(struct policy_action_param, 1);
-
- cJSON *uuid = cJSON_GetObjectItem(pxy_ctrl_rule, "uuid");
- if(uuid && uuid->type==cJSON_String)
- {
- param->hit_rule.config_uuid_string = strdup(uuid->valuestring);
- uuid_parse(uuid->valuestring, param->hit_rule.config_uuid);
- }
-
- cJSON *action = cJSON_GetObjectItem(pxy_ctrl_rule, "action");
- if(action && action->type==cJSON_String)
- {
- param->hit_rule.action=action_type_str2idx(action->valuestring);
- }
-
- cJSON *blacklist_option = cJSON_GetObjectItem(pxy_ctrl_rule, "blacklist_option");
- if(blacklist_option && blacklist_option->type==cJSON_Number)
- {
- param->hit_rule.do_blacklist=blacklist_option->valueint;
- }
-
- cJSON *log_option = cJSON_GetObjectItem(pxy_ctrl_rule, "log_option");
- if(log_option && log_option->type==cJSON_String)
- {
- param->hit_rule.do_log=log_option_type_str2idx(log_option->valuestring);
- }
-
- cJSON *action_parameter = cJSON_GetObjectItem(pxy_ctrl_rule, "action_parameter");
- if(action_parameter == NULL || action_parameter->type!=cJSON_Object)
- {
- FREE(&param);
- TFE_LOG_ERROR(g_proxy_rt->local_logger, "invalid policy parameter: id = %s", param->hit_rule.config_uuid_string);
- return;
- }
-
- param->ref_cnt=1;
- pthread_mutex_init(&(param->lock), NULL);
- param->hit_rule.action_parameter = cJSON_PrintUnformatted(action_parameter);
-
- int rule_id=0;
- cJSON *rules=NULL, *item=NULL, *sub_item=NULL;
-
+ cJSON *item=NULL;
switch(param->hit_rule.action)
{
case PX_ACTION_REDIRECT:
@@ -586,13 +538,13 @@ void policy_action_param_new(const char *table_name, const char* key, const char
default:
break;
}
+ return;
+}
- cJSON *method=cJSON_GetObjectItem(action_parameter, "sub_action");
- if(method && method->type==cJSON_String)
- {
- param->action=manipulate_action_str2idx(method->valuestring);
- }
-
+void policy_set_param_by_sub_action(struct policy_action_param* param, cJSON *action_parameter)
+{
+ int rule_id=0;
+ cJSON *rules=NULL, *item=NULL, *sub_item=NULL;
switch(param->action)
{
case MA_ACTION_REPLACE_TEXT:
@@ -748,6 +700,66 @@ void policy_action_param_new(const char *table_name, const char* key, const char
default:
break;
}
+
+ return;
+}
+
+void policy_action_param_new(const char *table_name, const char* key, const char* table_line, void **ad, long argl, void* argp)
+{
+ cJSON* pxy_ctrl_rule = cJSON_Parse(table_line);
+ if(pxy_ctrl_rule == NULL)
+ {
+ TFE_LOG_ERROR(g_proxy_rt->local_logger, "PXY_CTRL_RULE parse table_line failed. table_line:%s", table_line);
+ return;
+ }
+
+ struct policy_action_param* param=ALLOC(struct policy_action_param, 1);
+
+ cJSON *uuid = cJSON_GetObjectItem(pxy_ctrl_rule, "uuid");
+ if(uuid && uuid->type==cJSON_String)
+ {
+ param->hit_rule.config_uuid_string = strdup(uuid->valuestring);
+ uuid_parse(uuid->valuestring, param->hit_rule.config_uuid);
+ }
+
+ cJSON *action = cJSON_GetObjectItem(pxy_ctrl_rule, "action");
+ if(action && action->type==cJSON_String)
+ {
+ param->hit_rule.action=action_type_str2idx(action->valuestring);
+ }
+
+ cJSON *blacklist_option = cJSON_GetObjectItem(pxy_ctrl_rule, "blacklist_option");
+ if(blacklist_option && blacklist_option->type==cJSON_Number)
+ {
+ param->hit_rule.do_blacklist=blacklist_option->valueint;
+ }
+
+ cJSON *log_option = cJSON_GetObjectItem(pxy_ctrl_rule, "log_option");
+ if(log_option && log_option->type==cJSON_String)
+ {
+ param->hit_rule.do_log=log_option_type_str2idx(log_option->valuestring);
+ }
+
+ cJSON *action_parameter = cJSON_GetObjectItem(pxy_ctrl_rule, "action_parameter");
+ if(action_parameter == NULL || action_parameter->type!=cJSON_Object)
+ {
+ FREE(&param);
+ TFE_LOG_ERROR(g_proxy_rt->local_logger, "invalid policy parameter: id = %s", param->hit_rule.config_uuid_string);
+ return;
+ }
+
+ param->ref_cnt=1;
+ pthread_mutex_init(&(param->lock), NULL);
+ param->hit_rule.action_parameter = cJSON_PrintUnformatted(action_parameter);
+ policy_set_param_by_action(param, action_parameter);
+
+ cJSON *method=cJSON_GetObjectItem(action_parameter, "sub_action");
+ if(method && method->type==cJSON_String)
+ {
+ param->action=manipulate_action_str2idx(method->valuestring);
+ }
+ policy_set_param_by_sub_action(param, action_parameter);
+
*ad=param;
TFE_LOG_INFO(g_proxy_rt->local_logger, "Add ctrl policy: %s", param->hit_rule.config_uuid_string);
cJSON_Delete(pxy_ctrl_rule);
@@ -1519,7 +1531,7 @@ void proxy_send_metric_log(const struct tfe_stream * stream, struct proxy_http_c
{
fieldstat->tags[thread_id][TAG_VSYS_ID].value_longlong = ctx->enforce_rules[i].vsys_id;
fieldstat->tags[thread_id][TAG_RULE_ID].value_str = ctx->enforce_rules[i].config_uuid_string;
- fieldstat->tags[thread_id][TAG_ACTION].value_longlong = PX_ACTION_MANIPULATE;
+ fieldstat->tags[thread_id][TAG_ACTION].value_str = "manipulate";
if(ctx->enforce_rules[i].action == PX_ACTION_MANIPULATE)
{
fieldstat->tags[thread_id][TAG_SUB_ACTION].value_str = manipulate_action_map[ctx->param->action];
diff --git a/plugin/business/tsg-http/src/tsg_logger.cpp b/plugin/business/tsg-http/src/tsg_logger.cpp
index 256a5d5..5511200 100644
--- a/plugin/business/tsg-http/src/tsg_logger.cpp
+++ b/plugin/business/tsg-http/src/tsg_logger.cpp
@@ -391,7 +391,7 @@ int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
config_id[0]=log_msg->result[i].config_uuid_string;
proxy_rule_list = cJSON_CreateStringArray((const char **)config_id, 1);
}
- cJSON_AddItemToObject(per_hit_obj, "proxy_rule_list", proxy_rule_list);
+ cJSON_AddItemToObject(per_hit_obj, "proxy_rule_uuid_list", proxy_rule_list);
cJSON_AddNumberToObject(per_hit_obj, "vsys_id", log_msg->result[i].vsys_id);
if(log_msg->result[i].action == LG_ACTION_MANIPULATE)
{