MINOR: http-act/tcp-act: Add "set-nice" for tcp content rules
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.
diff --git a/doc/configuration.txt b/doc/configuration.txt
index d94bdf2..7843e04 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -12057,6 +12057,7 @@
- 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 @@
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 @@
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.
diff --git a/include/haproxy/action-t.h b/include/haproxy/action-t.h
index 2e56848..4f02163 100644
--- a/include/haproxy/action-t.h
+++ b/include/haproxy/action-t.h
@@ -81,7 +81,6 @@
/* common http actions .*/
ACT_HTTP_REDIR,
- ACT_HTTP_SET_NICE,
ACT_HTTP_SET_TOS,
ACT_HTTP_SET_MARK,
diff --git a/src/http_act.c b/src/http_act.c
index 3bc72d7..9e49d33 100644
--- a/src/http_act.c
+++ b/src/http_act.c
@@ -1315,32 +1315,6 @@
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 @@
{ "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 @@
{ "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 },
diff --git a/src/http_ana.c b/src/http_ana.c
index 29a9806..fc0b5bc 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -2831,10 +2831,6 @@
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 @@
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;
diff --git a/src/stream.c b/src/stream.c
index 3525bc4..31913e0 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -2885,6 +2885,43 @@
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 @@
/* 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 @@
/* 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 @@
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 @@
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 */ }
}};