]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-act/tcp-act: Add "set-nice" for tcp content rules
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 25 Jun 2021 12:46:02 +0000 (14:46 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 25 Jun 2021 14:11:53 +0000 (16:11 +0200)
It is now possible to set the "nice" factor of the current stream from a
"tcp-request content" or "tcp-response content" ruleset. To do so, the
action parsing is moved in stream.c and the action evaluation is handled in
a dedicated function.

This patch may be backported as far as 2.2 if necessary.

doc/configuration.txt
include/haproxy/action-t.h
src/http_act.c
src/http_ana.c
src/stream.c

index d94bdf2f1435f872ba3526ecc496053350066e4d..7843e04401d62bb0f52640a308170b5d94ab71f2 100644 (file)
@@ -12057,6 +12057,7 @@ tcp-request content <action> [{if | unless} <condition>]
     - set-dst <expr>
     - set-dst-port <expr>
     - set-log-level <level>
+    - set-nice <nice>
     - set-src <expr>
     - set-src-port <expr>
     - set-var(<var-name>) <expr>
@@ -12112,6 +12113,9 @@ tcp-request content <action> [{if | unless} <condition>]
   The "set-log-level" is used to set the log level of the current session. More
   information on how to use it at "http-request set-log-level".
 
+  The "set-nice" is used to set the "nice" factor of the current session. More
+  information on how to use it at "http-request set-nice".
+
   The "set-src" and "set-src-port" are used to set respectively the source IP
   and port. More information on how to use it at "http-request set-src".
 
@@ -12359,6 +12363,11 @@ tcp-response content <action> [{if | unless} <condition>]
         session. More information on how to use it at "http-response
         set-log-level".
 
+    - set-nice <nice>
+        The "set-nice" is used to set the "nice" factor of the current
+        session. More information on how to use it at "http-response
+        set-nice".
+
     - set-var(<var-name>) <expr>
         Sets a variable.
 
index 2e56848d8f200d47556873b3dfd0e9dc55eec3b2..4f0216372d9c43d2538b46633051236fa96540fd 100644 (file)
@@ -81,7 +81,6 @@ enum act_name {
 
        /* common http actions .*/
        ACT_HTTP_REDIR,
-       ACT_HTTP_SET_NICE,
        ACT_HTTP_SET_TOS,
        ACT_HTTP_SET_MARK,
 
index 3bc72d79430e667a3265a14b189369f4b055ff10..9e49d3373961d30f5c51278e3293f06fdddeeeb0 100644 (file)
@@ -1315,32 +1315,6 @@ static enum act_parse_ret parse_http_auth(const char **args, int *orig_arg, stru
        return ACT_RET_PRS_OK;
 }
 
-/* Parse a "set-nice" action. It takes the nice value as argument. It returns
- * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
- */
-static enum act_parse_ret parse_http_set_nice(const char **args, int *orig_arg, struct proxy *px,
-                                             struct act_rule *rule, char **err)
-{
-       int cur_arg;
-
-       rule->action = ACT_HTTP_SET_NICE;
-
-       cur_arg = *orig_arg;
-       if (!*args[cur_arg]) {
-               memprintf(err, "expects exactly 1 argument (integer value)");
-               return ACT_RET_PRS_ERR;
-       }
-       rule->arg.http.i = atoi(args[cur_arg]);
-       if (rule->arg.http.i < -1024)
-               rule->arg.http.i = -1024;
-       else if (rule->arg.http.i > 1024)
-               rule->arg.http.i = 1024;
-
-       LIST_INIT(&rule->arg.http.fmt);
-       *orig_arg = cur_arg + 1;
-       return ACT_RET_PRS_OK;
-}
-
 /* Parse a "set-tos" action. It takes the TOS value as argument. It returns
  * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
  */
@@ -2485,7 +2459,6 @@ static struct action_kw_list http_req_actions = {
                { "set-map",          parse_http_set_map,              KWF_MATCH_PREFIX },
                { "set-method",       parse_set_req_line,              0 },
                { "set-mark",         parse_http_set_mark,             0 },
-               { "set-nice",         parse_http_set_nice,             0 },
                { "set-path",         parse_set_req_line,              0 },
                { "set-pathq",        parse_set_req_line,              0 },
                { "set-query",        parse_set_req_line,              0 },
@@ -2519,7 +2492,6 @@ static struct action_kw_list http_res_actions = {
                { "set-header",      parse_http_set_header,     0 },
                { "set-map",         parse_http_set_map,        KWF_MATCH_PREFIX },
                { "set-mark",        parse_http_set_mark,       0 },
-               { "set-nice",        parse_http_set_nice,       0 },
                { "set-status",      parse_http_set_status,     0 },
                { "set-tos",         parse_http_set_tos,        0 },
                { "strict-mode",     parse_http_strict_mode,    0 },
index 29a9806b67d58531586e0a5ff2de785e504d8a8f..fc0b5bccc24c854d771824ce75aa8de7e41689d3 100644 (file)
@@ -2831,10 +2831,6 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
                                        rule_ret = HTTP_RULE_RES_ERROR;
                                goto end;
 
-                       case ACT_HTTP_SET_NICE:
-                               s->task->nice = rule->arg.http.i;
-                               break;
-
                        case ACT_HTTP_SET_TOS:
                                conn_set_tos(objt_conn(sess->origin), rule->arg.http.i);
                                break;
@@ -2962,10 +2958,6 @@ resume_execution:
                                rule_ret = HTTP_RULE_RES_DENY;
                                goto end;
 
-                       case ACT_HTTP_SET_NICE:
-                               s->task->nice = rule->arg.http.i;
-                               break;
-
                        case ACT_HTTP_SET_TOS:
                                conn_set_tos(objt_conn(sess->origin), rule->arg.http.i);
                                break;
index 3525bc42e7405e4bb9b602525ff335f3769c004c..31913e08b3dd3c0728e29bb08adc1e4a4aeb6e4d 100644 (file)
@@ -2885,6 +2885,43 @@ static enum act_parse_ret stream_parse_set_log_level(const char **args, int *cur
        return ACT_RET_PRS_OK;
 }
 
+static enum act_return stream_action_set_nice(struct act_rule *rule, struct proxy *px,
+                                             struct session *sess, struct stream *s, int flags)
+{
+       s->task->nice = (uintptr_t)rule->arg.act.p[0];
+       return ACT_RET_CONT;
+}
+
+
+/* Parse a "set-nice" action. It takes the nice value as argument. It returns
+ * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
+ */
+static enum act_parse_ret stream_parse_set_nice(const char **args, int *cur_arg, struct proxy *px,
+                                               struct act_rule *rule, char **err)
+{
+       int nice;
+
+       if (!*args[*cur_arg]) {
+         bad_log_level:
+               memprintf(err, "expects exactly 1 argument (integer value)");
+               return ACT_RET_PRS_ERR;
+       }
+
+       nice = atoi(args[*cur_arg]);
+       if (nice < -1024)
+               nice = -1024;
+       else if (nice > 1024)
+               nice = 1024;
+
+       (*cur_arg)++;
+
+       /* Register processing function. */
+       rule->action_ptr = stream_action_set_nice;
+       rule->action = ACT_CUSTOM;
+       rule->arg.act.p[0] = (void *)(uintptr_t)nice;
+       return ACT_RET_PRS_OK;
+}
+
 
 static enum act_return tcp_action_switch_stream_mode(struct act_rule *rule, struct proxy *px,
                                                  struct session *sess, struct stream *s, int flags)
@@ -3743,6 +3780,7 @@ INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
 /* main configuration keyword registration. */
 static struct action_kw_list stream_tcp_req_keywords = { ILH, {
        { "set-log-level", stream_parse_set_log_level },
+       { "set-nice",      stream_parse_set_nice },
        { "switch-mode",   stream_parse_switch_mode },
        { "use-service",   stream_parse_use_service },
        { /* END */ }
@@ -3753,6 +3791,7 @@ INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &stream_tcp_req_keywords
 /* main configuration keyword registration. */
 static struct action_kw_list stream_tcp_res_keywords = { ILH, {
        { "set-log-level", stream_parse_set_log_level },
+       { "set-nice",     stream_parse_set_nice },
        { /* END */ }
 }};
 
@@ -3760,6 +3799,7 @@ INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &stream_tcp_res_keywords
 
 static struct action_kw_list stream_http_req_keywords = { ILH, {
        { "set-log-level", stream_parse_set_log_level },
+       { "set-nice",      stream_parse_set_nice },
        { "use-service",   stream_parse_use_service },
        { /* END */ }
 }};
@@ -3768,6 +3808,7 @@ INITCALL1(STG_REGISTER, http_req_keywords_register, &stream_http_req_keywords);
 
 static struct action_kw_list stream_http_res_keywords = { ILH, {
        { "set-log-level", stream_parse_set_log_level },
+       { "set-nice",      stream_parse_set_nice },
        { /* END */ }
 }};