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.
This commit is contained in:
Christopher Faulet 2021-06-25 14:46:02 +02:00
parent 551a641cff
commit 1da374af2f
5 changed files with 50 additions and 37 deletions

View 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.

View 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,

View 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 },

View 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 @@ static enum rule_result http_res_get_intercept_rule(struct proxy *px, struct lis
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;

View 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 */ }
}};