diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp index 9230f89..3853526 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/pangu-http/src/pangu_http.cpp @@ -375,7 +375,7 @@ static void pangu_http_ctx_free(struct pangu_http_ctx * 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) { @@ -388,17 +388,24 @@ inline void addr_tfe2sapp(const struct tfe_stream_addr * tfe_addr, struct ipaddr sapp_addr->paddr = (char *) tfe_addr->paddr; 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]; - memset(weight, 0, sizeof(weight)); - weight[PG_ACTION_MONIT] = 0; - weight[PG_ACTION_REPLACE] = 1; - weight[PG_ACTION_REDIRECT] = 2; - weight[PG_ACTION_REJECT] = 3; - weight[PG_ACTION_WHITELIST] = 4; - return weight[a1]-weight[a2]; + pangu_action_weight[PG_ACTION_NONE] = 0; + pangu_action_weight[PG_ACTION_MONIT] = 1; + pangu_action_weight[PG_ACTION_REPLACE] = 2; + pangu_action_weight[PG_ACTION_REDIRECT] = 3; + pangu_action_weight[PG_ACTION_REJECT] = 4; + pangu_action_weight[PG_ACTION_WHITELIST] = 5; } + +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. 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)