修正Pangu HTTP业务层中关于错误判断监测优先级的问题。

* 原实现在只命中监测动作时,误认为监测动作与NONE动作优先级一致,从而不执行监测动作,现修正。
* 使用构造器初始化action_weight()数组,避免每次使用时填充。
This commit is contained in:
Lu Qiuwen
2018-10-23 10:41:16 +08:00
parent bcfe14055f
commit d963a6ccdc

View File

@@ -375,7 +375,7 @@ static void pangu_http_ctx_free(struct pangu_http_ctx * ctx)
FREE(&ctx); FREE(&ctx);
} }
inline void addr_tfe2sapp(const struct tfe_stream_addr * tfe_addr, struct ipaddr * sapp_addr) static inline void addr_tfe2sapp(const struct tfe_stream_addr * tfe_addr, struct ipaddr * sapp_addr)
{ {
if(tfe_addr->addrtype==TFE_ADDR_STREAM_TUPLE4_V4||tfe_addr->addrtype==TFE_ADDR_IPV4) if(tfe_addr->addrtype==TFE_ADDR_STREAM_TUPLE4_V4||tfe_addr->addrtype==TFE_ADDR_IPV4)
{ {
@@ -388,17 +388,24 @@ inline void addr_tfe2sapp(const struct tfe_stream_addr * tfe_addr, struct ipaddr
sapp_addr->paddr = (char *) tfe_addr->paddr; sapp_addr->paddr = (char *) tfe_addr->paddr;
return; return;
} }
int action_cmp(enum pangu_action a1, enum pangu_action a2)
static int pangu_action_weight[__PG_ACTION_MAX] = {0};
void __pangu_action_weight_init() __attribute__((constructor, used));
void __pangu_action_weight_init()
{ {
int weight[__PG_ACTION_MAX]; pangu_action_weight[PG_ACTION_NONE] = 0;
memset(weight, 0, sizeof(weight)); pangu_action_weight[PG_ACTION_MONIT] = 1;
weight[PG_ACTION_MONIT] = 0; pangu_action_weight[PG_ACTION_REPLACE] = 2;
weight[PG_ACTION_REPLACE] = 1; pangu_action_weight[PG_ACTION_REDIRECT] = 3;
weight[PG_ACTION_REDIRECT] = 2; pangu_action_weight[PG_ACTION_REJECT] = 4;
weight[PG_ACTION_REJECT] = 3; pangu_action_weight[PG_ACTION_WHITELIST] = 5;
weight[PG_ACTION_WHITELIST] = 4;
return weight[a1]-weight[a2];
} }
static inline int action_cmp(enum pangu_action a1, enum pangu_action a2)
{
return pangu_action_weight[a1] - pangu_action_weight[a2];
}
//enforce_rules[0] contains execute action. //enforce_rules[0] contains execute action.
static enum pangu_action decide_ctrl_action(const struct Maat_rule_t * hit_rules, size_t n_hit, static enum pangu_action decide_ctrl_action(const struct Maat_rule_t * hit_rules, size_t n_hit,
struct Maat_rule_t ** enforce_rules, size_t * n_enforce) struct Maat_rule_t ** enforce_rules, size_t * n_enforce)