From d963a6ccdc66e4299ec1779a3f61d59b1e662986 Mon Sep 17 00:00:00 2001 From: Lu Qiuwen Date: Tue, 23 Oct 2018 10:41:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Pangu=20HTTP=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=B1=82=E4=B8=AD=E5=85=B3=E4=BA=8E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E7=9B=91=E6=B5=8B=E4=BC=98=E5=85=88=E7=BA=A7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=20*=20=E5=8E=9F=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=8F=AA=E5=91=BD=E4=B8=AD=E7=9B=91=E6=B5=8B?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C=E6=97=B6=EF=BC=8C=E8=AF=AF=E8=AE=A4=E4=B8=BA?= =?UTF-8?q?=E7=9B=91=E6=B5=8B=E5=8A=A8=E4=BD=9C=E4=B8=8ENONE=E5=8A=A8?= =?UTF-8?q?=E4=BD=9C=E4=BC=98=E5=85=88=E7=BA=A7=E4=B8=80=E8=87=B4=EF=BC=8C?= =?UTF-8?q?=E4=BB=8E=E8=80=8C=E4=B8=8D=E6=89=A7=E8=A1=8C=E7=9B=91=E6=B5=8B?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C=EF=BC=8C=E7=8E=B0=E4=BF=AE=E6=AD=A3=E3=80=82?= =?UTF-8?q?=20*=20=E4=BD=BF=E7=94=A8=E6=9E=84=E9=80=A0=E5=99=A8=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96action=5Fweight()=E6=95=B0=E7=BB=84=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=AF=8F=E6=AC=A1=E4=BD=BF=E7=94=A8=E6=97=B6?= =?UTF-8?q?=E5=A1=AB=E5=85=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/business/pangu-http/src/pangu_http.cpp | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) 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)