]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: actions: remove ACTION_STOP
authorThierry FOURNIER <tfournier@arpalert.org>
Wed, 2 Sep 2015 15:17:33 +0000 (17:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 2 Sep 2015 16:36:38 +0000 (18:36 +0200)
Before this patch, two type of custom actions exists: ACT_ACTION_CONT and
ACT_ACTION_STOP. ACT_ACTION_CONT is a non terminal action and ACT_ACTION_STOP is
a terminal action.

Note that ACT_ACTION_STOP is not used in HAProxy.

This patch remove this behavior. Only type type of custom action exists, and it
is called ACT_CUSTOM. Now, the custion action can return a code indicating the
required behavior. ACT_RET_CONT wants that HAProxy continue the current rule
list evaluation, and ACT_RET_STOP wants that HAPRoxy stops the the current rule
list evaluation.

include/types/action.h
src/hlua.c
src/proto_http.c
src/proto_tcp.c
src/stick_table.c
src/vars.c

index f28cae5876f65739439f8351cf962eef8a2e2093..a1dd638d93fe87b772716205d32ca4dd3ad76832 100644 (file)
@@ -34,6 +34,7 @@ enum act_from {
 
 enum act_return {
        ACT_RET_CONT,  /* continue processing. */
+       ACT_RET_STOP,  /* stop processing. */
        ACT_RET_YIELD, /* call me again. */
        ACT_RET_ERR,   /* processing error. */
 };
@@ -44,8 +45,7 @@ enum act_parse_ret {
 };
 
 enum act_name {
-       ACT_ACTION_CONT = 0,
-       ACT_ACTION_STOP,
+       ACT_CUSTOM = 0,
 
        /* common action */
        ACT_ACTION_ALLOW,
index aa23696c1b5d18a1d2c1177dba010c96f6681f4a..61e28d00146c90ce1c6a0a8d832e2495b3ede066 100644 (file)
@@ -4465,7 +4465,7 @@ static enum act_parse_ret action_register_lua(const char **args, int *cur_arg, s
        /* TODO: later accept arguments. */
        rule->arg.hlua_rule->args = NULL;
 
-       rule->action = ACT_ACTION_CONT;
+       rule->action = ACT_CUSTOM;
        rule->action_ptr = hlua_action;
        return ACT_RET_PRS_OK;
 }
index 7887791ce1361a754718f98b325a823687b8c695..bb1ef698a3679c57910572b322177068e568f42e 100644 (file)
@@ -3712,26 +3712,19 @@ resume_execution:
                        break;
                        }
 
-               case ACT_ACTION_CONT:
+               case ACT_CUSTOM:
                        switch (rule->action_ptr(rule, px, s->sess, s)) {
                        case ACT_RET_ERR:
                        case ACT_RET_CONT:
                                break;
+                       case ACT_RET_STOP:
+                               return HTTP_RULE_RES_DONE;
                        case ACT_RET_YIELD:
                                s->current_rule = rule;
                                return HTTP_RULE_RES_YIELD;
                        }
                        break;
 
-               case ACT_ACTION_STOP:
-                       switch (rule->action_ptr(rule, px, s->sess, s)) {
-                       case ACT_RET_YIELD:
-                       case ACT_RET_ERR:
-                       case ACT_RET_CONT:
-                               return HTTP_RULE_RES_DONE;
-                       }
-                       break;
-
                case ACT_ACTION_TRK_SC0 ... ACT_ACTION_TRK_SCMAX:
                        /* Note: only the first valid tracking parameter of each
                         * applies.
@@ -4001,21 +3994,19 @@ resume_execution:
                                return HTTP_RULE_RES_BADREQ;
                        return HTTP_RULE_RES_DONE;
 
-               case ACT_ACTION_CONT:
+               case ACT_CUSTOM:
                        switch (rule->action_ptr(rule, px, s->sess, s)) {
                        case ACT_RET_ERR:
                        case ACT_RET_CONT:
                                break;
+                       case ACT_RET_STOP:
+                               return HTTP_RULE_RES_STOP;
                        case ACT_RET_YIELD:
                                s->current_rule = rule;
                                return HTTP_RULE_RES_YIELD;
                        }
                        break;
 
-               case ACT_ACTION_STOP:
-                       rule->action_ptr(rule, px, s->sess, s);
-                       return HTTP_RULE_RES_STOP;
-
                /* other flags exists, but normaly, they never be matched. */
                default:
                        break;
@@ -12428,7 +12419,7 @@ enum act_parse_ret parse_set_req_line(const char **args, int *orig_arg, struct p
 {
        int cur_arg = *orig_arg;
 
-       rule->action = ACT_ACTION_CONT;
+       rule->action = ACT_CUSTOM;
 
        switch (args[0][4]) {
        case 'm' :
@@ -12478,7 +12469,7 @@ enum act_parse_ret parse_http_set_status(const char **args, int *orig_arg, struc
 {
        char *error;
 
-       rule->action = ACT_ACTION_CONT;
+       rule->action = ACT_CUSTOM;
        rule->action_ptr = action_http_set_status;
 
        /* Check if an argument is available */
@@ -12654,7 +12645,7 @@ enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, stru
                px->req_cap = hdr;
                px->to_log |= LW_REQHDR;
 
-               rule->action       = ACT_ACTION_CONT;
+               rule->action       = ACT_CUSTOM;
                rule->action_ptr   = http_action_req_capture;
                rule->arg.cap.expr = expr;
                rule->arg.cap.hdr  = hdr;
@@ -12682,7 +12673,7 @@ enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, stru
 
                proxy->conf.args.ctx = ARGC_CAP;
 
-               rule->action       = ACT_ACTION_CONT;
+               rule->action       = ACT_CUSTOM;
                rule->action_ptr   = http_action_req_capture_by_id;
                rule->arg.capid.expr = expr;
                rule->arg.capid.idx  = id;
@@ -12805,7 +12796,7 @@ enum act_parse_ret parse_http_res_capture(const char **args, int *orig_arg, stru
 
        proxy->conf.args.ctx = ARGC_CAP;
 
-       rule->action       = ACT_ACTION_CONT;
+       rule->action       = ACT_CUSTOM;
        rule->action_ptr   = http_action_res_capture_by_id;
        rule->arg.capid.expr = expr;
        rule->arg.capid.idx  = id;
index c89360c01aef32dc862e5bc07d9ba9a5909e5de8..e671e41404a844bd7577da0fbb591ee833e5829c 100644 (file)
@@ -1163,21 +1163,19 @@ resume_execution:
                        }
                        else {
                                /* Custom keywords. */
-                               if (rule->action_ptr) {
-                                       switch (rule->action_ptr(rule, s->be, s->sess, s)) {
-                                       case ACT_RET_ERR:
-                                       case ACT_RET_CONT:
-                                               break;
-                                       case ACT_RET_YIELD:
-                                               s->current_rule = rule;
-                                               goto missing_data;
-                                       }
-                               }
-
-                               /* accept */
-                               if (rule->action == ACT_ACTION_STOP)
+                               if (!rule->action_ptr)
+                                       continue;
+                               switch (rule->action_ptr(rule, s->be, s->sess, s)) {
+                               case ACT_RET_ERR:
+                               case ACT_RET_CONT:
+                                       continue;
+                               case ACT_RET_STOP:
                                        break;
-                               /* otherwise continue */
+                               case ACT_RET_YIELD:
+                                       s->current_rule = rule;
+                                       goto missing_data;
+                               }
+                               break; /* ACT_RET_STOP */
                        }
                }
        }
@@ -1294,22 +1292,20 @@ resume_execution:
                        }
                        else {
                                /* Custom keywords. */
-                               if (rule->action_ptr) {
-                                       switch (rule->action_ptr(rule, s->be, s->sess, s)) {
-                                       case ACT_RET_ERR:
-                                       case ACT_RET_CONT:
-                                               break;
-                                       case ACT_RET_YIELD:
-                                               channel_dont_close(rep);
-                                               s->current_rule = rule;
-                                               return 0;
-                                       }
-                               }
-
-                               /* accept */
-                               if (rule->action == ACT_ACTION_STOP)
+                               if (!rule->action_ptr)
+                                       continue;
+                               switch (rule->action_ptr(rule, s->be, s->sess, s)) {
+                               case ACT_RET_ERR:
+                               case ACT_RET_CONT:
+                                       continue;
+                               case ACT_RET_STOP:
                                        break;
-                               /* otherwise continue */
+                               case ACT_RET_YIELD:
+                                       channel_dont_close(rep);
+                                       s->current_rule = rule;
+                                       return 0;
+                               }
+                               break; /* ACT_RET_STOP */
                        }
                }
        }
@@ -1384,26 +1380,24 @@ int tcp_exec_req_rules(struct session *sess)
                        }
                        else {
                                /* Custom keywords. */
-                               if (rule->action_ptr) {
-                                       switch (rule->action_ptr(rule, sess->fe, sess, NULL)) {
-                                       case ACT_RET_YIELD:
-                                               /* yield is not allowed at this point. If this return code is
-                                                * used it is a bug, so I prefer to abort the process.
-                                                */
-                                               send_log(sess->fe, LOG_WARNING,
-                                                        "Internal error: yield not allowed with tcp-request connection actions.");
-                                       case ACT_RET_CONT:
-                                               break;
-                                       case ACT_RET_ERR:
-                                               result = 0;
-                                               break;
-                                       }
-                                       if (rule->action == ACT_ACTION_CONT)
-                                               continue;
+                               if (rule->action_ptr)
+                                       break;
+                               switch (rule->action_ptr(rule, sess->fe, sess, NULL)) {
+                               case ACT_RET_YIELD:
+                                       /* yield is not allowed at this point. If this return code is
+                                        * used it is a bug, so I prefer to abort the process.
+                                        */
+                                       send_log(sess->fe, LOG_WARNING,
+                                                "Internal error: yield not allowed with tcp-request connection actions.");
+                               case ACT_RET_STOP:
+                                       break;
+                               case ACT_RET_CONT:
+                                       continue;
+                               case ACT_RET_ERR:
+                                       result = 0;
+                                       break;
                                }
-
-                               /* otherwise it's an accept */
-                               break;
+                               break; /* ACT_RET_STOP */
                        }
                }
        }
index 7f3a5a75266c1aa031398bccad22d2bb5405d47b..a51bde3be5126ec49001951a44ffd3b7f1a24a18 100644 (file)
@@ -1373,7 +1373,7 @@ static enum act_parse_ret parse_inc_gpc0(const char **args, int *arg, struct pro
                        return ACT_RET_PRS_ERR;
                }
        }
-       rule->action = ACT_ACTION_CONT;
+       rule->action = ACT_CUSTOM;
        rule->action_ptr = action_inc_gpc0;
        return ACT_RET_PRS_OK;
 }
@@ -1450,7 +1450,7 @@ static enum act_parse_ret parse_set_gpt0(const char **args, int *arg, struct pro
        }
        (*arg)++;
 
-       rule->action = ACT_ACTION_CONT;
+       rule->action = ACT_CUSTOM;
        rule->action_ptr = action_set_gpt0;
 
        return ACT_RET_PRS_OK;
index d1d05cc17d64e3289af6159ad744b05f09df2556..d20839ca1a5f35d2a46f64a5dd954073ebd92ae8 100644 (file)
@@ -588,7 +588,7 @@ static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy
                return ACT_RET_PRS_ERR;
        }
 
-       rule->action     = ACT_ACTION_CONT;
+       rule->action     = ACT_CUSTOM;
        rule->action_ptr = action_store;
        return ACT_RET_PRS_OK;
 }