blob: 5d3d2e27948a280b3962eb0bc739dd19745191d9 [file] [log] [blame]
Willy Tarreau79e57332018-10-02 16:01:16 +02001/*
2 * HTTP actions
3 *
4 * Copyright 2000-2018 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <sys/types.h>
14
15#include <ctype.h>
16#include <string.h>
17#include <time.h>
18
Christopher Faulet81e20172019-12-12 16:40:30 +010019#include <common/cfgparse.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020020#include <common/chunk.h>
21#include <common/compat.h>
22#include <common/config.h>
23#include <common/debug.h>
24#include <common/http.h>
Willy Tarreau0108d902018-11-25 19:14:37 +010025#include <common/initcall.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020026#include <common/memory.h>
27#include <common/standard.h>
28#include <common/version.h>
29
30#include <types/capture.h>
31#include <types/global.h>
32
33#include <proto/acl.h>
34#include <proto/arg.h>
Christopher Faulet81e20172019-12-12 16:40:30 +010035#include <proto/action.h>
Willy Tarreau61c112a2018-10-02 16:43:32 +020036#include <proto/http_rules.h>
Willy Tarreau33810222019-06-12 17:44:02 +020037#include <proto/http_htx.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020038#include <proto/log.h>
Christopher Fauletfc9cfe42019-07-16 14:54:53 +020039#include <proto/http_ana.h>
Christopher Faulet046cf442019-12-17 15:45:23 +010040#include <proto/pattern.h>
Willy Tarreau0f9cd7b2019-01-31 19:02:43 +010041#include <proto/stream_interface.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020042
Christopher Faulet2eb53962020-01-14 14:47:34 +010043/* Release memory allocated by most of HTTP actions. Concretly, it releases
44 * <arg.http>.
45 */
46static void release_http_action(struct act_rule *rule)
47{
48 struct logformat_node *lf, *lfb;
49
50 if (rule->arg.http.str.ptr)
51 free(rule->arg.http.str.ptr);
52 if (rule->arg.http.re)
53 regex_free(rule->arg.http.re);
54 list_for_each_entry_safe(lf, lfb, &rule->arg.http.fmt, list) {
55 LIST_DEL(&lf->list);
56 release_sample_expr(lf->expr);
57 free(lf->arg);
58 free(lf);
59 }
60}
61
Willy Tarreau79e57332018-10-02 16:01:16 +020062
63/* This function executes one of the set-{method,path,query,uri} actions. It
64 * builds a string in the trash from the specified format string. It finds
Christopher Faulet2c22a692019-12-18 15:39:56 +010065 * the action to be performed in <.action>, previously filled by function
Willy Tarreau79e57332018-10-02 16:01:16 +020066 * parse_set_req_line(). The replacement action is excuted by the function
Christopher Faulete00d06c2019-12-16 17:18:42 +010067 * http_action_set_req_line(). On success, it returns ACT_RET_CONT. If an error
68 * occurs while soft rewrites are enabled, the action is canceled, but the rule
69 * processing continue. Otherwsize ACT_RET_ERR is returned.
Willy Tarreau79e57332018-10-02 16:01:16 +020070 */
71static enum act_return http_action_set_req_line(struct act_rule *rule, struct proxy *px,
72 struct session *sess, struct stream *s, int flags)
73{
74 struct buffer *replace;
Christopher Faulet13403762019-12-13 09:01:57 +010075 enum act_return ret = ACT_RET_CONT;
Willy Tarreau79e57332018-10-02 16:01:16 +020076
77 replace = alloc_trash_chunk();
78 if (!replace)
Christopher Faulete00d06c2019-12-16 17:18:42 +010079 goto fail_alloc;
Willy Tarreau79e57332018-10-02 16:01:16 +020080
81 /* If we have to create a query string, prepare a '?'. */
Christopher Faulet2c22a692019-12-18 15:39:56 +010082 if (rule->action == 2) // set-query
Willy Tarreau79e57332018-10-02 16:01:16 +020083 replace->area[replace->data++] = '?';
84 replace->data += build_logline(s, replace->area + replace->data,
85 replace->size - replace->data,
Christopher Faulet96bff762019-12-17 13:46:18 +010086 &rule->arg.http.fmt);
Willy Tarreau79e57332018-10-02 16:01:16 +020087
Christopher Faulet2c22a692019-12-18 15:39:56 +010088 if (http_req_replace_stline(rule->action, replace->area, replace->data, px, s) == -1)
Christopher Faulete00d06c2019-12-16 17:18:42 +010089 goto fail_rewrite;
Willy Tarreau79e57332018-10-02 16:01:16 +020090
Christopher Faulete00d06c2019-12-16 17:18:42 +010091 leave:
Willy Tarreau79e57332018-10-02 16:01:16 +020092 free_trash_chunk(replace);
93 return ret;
Christopher Faulete00d06c2019-12-16 17:18:42 +010094
95 fail_alloc:
96 if (!(s->flags & SF_ERR_MASK))
97 s->flags |= SF_ERR_RESOURCE;
98 ret = ACT_RET_ERR;
99 goto leave;
100
101 fail_rewrite:
102 _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
103 if (s->flags & SF_BE_ASSIGNED)
104 _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
105 if (sess->listener->counters)
106 _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
107 if (objt_server(s->target))
108 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
109
Christopher Faulet333bf8c2020-01-22 14:38:05 +0100110 if (!(s->txn->req.flags & HTTP_MSGF_SOFT_RW)) {
Christopher Faulete00d06c2019-12-16 17:18:42 +0100111 ret = ACT_RET_ERR;
Christopher Faulet333bf8c2020-01-22 14:38:05 +0100112 if (!(s->flags & SF_ERR_MASK))
113 s->flags |= SF_ERR_PRXCOND;
114 }
Christopher Faulete00d06c2019-12-16 17:18:42 +0100115 goto leave;
Willy Tarreau79e57332018-10-02 16:01:16 +0200116}
117
118/* parse an http-request action among :
119 * set-method
120 * set-path
121 * set-query
122 * set-uri
123 *
124 * All of them accept a single argument of type string representing a log-format.
Christopher Faulet96bff762019-12-17 13:46:18 +0100125 * The resulting rule makes use of <http.fmt> to store the log-format list head,
Christopher Faulet2c22a692019-12-18 15:39:56 +0100126 * and <.action> to store the action type as an int (0=method, 1=path, 2=query,
127 * 3=uri). It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
Willy Tarreau79e57332018-10-02 16:01:16 +0200128 */
129static enum act_parse_ret parse_set_req_line(const char **args, int *orig_arg, struct proxy *px,
130 struct act_rule *rule, char **err)
131{
132 int cur_arg = *orig_arg;
133
Willy Tarreau79e57332018-10-02 16:01:16 +0200134 switch (args[0][4]) {
135 case 'm' :
Christopher Faulet2c22a692019-12-18 15:39:56 +0100136 rule->action = 0; // set-method
Willy Tarreau79e57332018-10-02 16:01:16 +0200137 break;
138 case 'p' :
Christopher Faulet2c22a692019-12-18 15:39:56 +0100139 rule->action = 1; // set-path
Willy Tarreau79e57332018-10-02 16:01:16 +0200140 break;
141 case 'q' :
Christopher Faulet2c22a692019-12-18 15:39:56 +0100142 rule->action = 2; // set-query
Willy Tarreau79e57332018-10-02 16:01:16 +0200143 break;
144 case 'u' :
Christopher Faulet2c22a692019-12-18 15:39:56 +0100145 rule->action = 3; // set-uri
Willy Tarreau79e57332018-10-02 16:01:16 +0200146 break;
147 default:
148 memprintf(err, "internal error: unhandled action '%s'", args[0]);
149 return ACT_RET_PRS_ERR;
150 }
Christopher Faulet96bff762019-12-17 13:46:18 +0100151 rule->action_ptr = http_action_set_req_line;
Christopher Faulet2eb53962020-01-14 14:47:34 +0100152 rule->release_ptr = release_http_action;
Willy Tarreau79e57332018-10-02 16:01:16 +0200153
154 if (!*args[cur_arg] ||
155 (*args[cur_arg + 1] && strcmp(args[cur_arg + 1], "if") != 0 && strcmp(args[cur_arg + 1], "unless") != 0)) {
156 memprintf(err, "expects exactly 1 argument <format>");
157 return ACT_RET_PRS_ERR;
158 }
159
Christopher Faulet96bff762019-12-17 13:46:18 +0100160 LIST_INIT(&rule->arg.http.fmt);
Willy Tarreau79e57332018-10-02 16:01:16 +0200161 px->conf.args.ctx = ARGC_HRQ;
Christopher Faulet96bff762019-12-17 13:46:18 +0100162 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP,
Willy Tarreau79e57332018-10-02 16:01:16 +0200163 (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, err)) {
164 return ACT_RET_PRS_ERR;
165 }
166
167 (*orig_arg)++;
168 return ACT_RET_PRS_OK;
169}
170
Willy Tarreau33810222019-06-12 17:44:02 +0200171/* This function executes a replace-uri action. It finds its arguments in
Christopher Faulet96bff762019-12-17 13:46:18 +0100172 * <rule>.arg.http. It builds a string in the trash from the format string
Willy Tarreau33810222019-06-12 17:44:02 +0200173 * previously filled by function parse_replace_uri() and will execute the regex
Christopher Faulet96bff762019-12-17 13:46:18 +0100174 * in <http.re> to replace the URI. It uses the format string present in
Christopher Faulet2c22a692019-12-18 15:39:56 +0100175 * <http.fmt>. The component to act on (path/uri) is taken from <.action> which
Christopher Faulet96bff762019-12-17 13:46:18 +0100176 * contains 1 for the path or 3 for the URI (values used by
177 * http_req_replace_stline()). On success, it returns ACT_RET_CONT. If an error
178 * occurs while soft rewrites are enabled, the action is canceled, but the rule
179 * processing continue. Otherwsize ACT_RET_ERR is returned.
Willy Tarreau33810222019-06-12 17:44:02 +0200180 */
181static enum act_return http_action_replace_uri(struct act_rule *rule, struct proxy *px,
182 struct session *sess, struct stream *s, int flags)
183{
Christopher Faulet13403762019-12-13 09:01:57 +0100184 enum act_return ret = ACT_RET_CONT;
Willy Tarreau33810222019-06-12 17:44:02 +0200185 struct buffer *replace, *output;
186 struct ist uri;
187 int len;
188
189 replace = alloc_trash_chunk();
190 output = alloc_trash_chunk();
191 if (!replace || !output)
Christopher Faulete00d06c2019-12-16 17:18:42 +0100192 goto fail_alloc;
Christopher Faulet12c28b62019-07-15 16:30:24 +0200193 uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf)));
Willy Tarreau262c3f12019-12-17 06:52:51 +0100194
Christopher Faulet2c22a692019-12-18 15:39:56 +0100195 if (rule->action == 1) // replace-path
Christopher Faulet96bff762019-12-17 13:46:18 +0100196 uri = http_get_path(uri);
Willy Tarreau262c3f12019-12-17 06:52:51 +0100197
Christopher Faulet96bff762019-12-17 13:46:18 +0100198 if (!regex_exec_match2(rule->arg.http.re, uri.ptr, uri.len, MAX_MATCH, pmatch, 0))
Willy Tarreau33810222019-06-12 17:44:02 +0200199 goto leave;
200
Christopher Faulet96bff762019-12-17 13:46:18 +0100201 replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt);
Willy Tarreau33810222019-06-12 17:44:02 +0200202
203 /* note: uri.ptr doesn't need to be zero-terminated because it will
204 * only be used to pick pmatch references.
205 */
206 len = exp_replace(output->area, output->size, uri.ptr, replace->area, pmatch);
207 if (len == -1)
Christopher Faulete00d06c2019-12-16 17:18:42 +0100208 goto fail_rewrite;
Willy Tarreau33810222019-06-12 17:44:02 +0200209
Christopher Faulet2c22a692019-12-18 15:39:56 +0100210 if (http_req_replace_stline(rule->action, output->area, len, px, s) == -1)
Christopher Faulete00d06c2019-12-16 17:18:42 +0100211 goto fail_rewrite;
Willy Tarreau33810222019-06-12 17:44:02 +0200212
Christopher Faulete00d06c2019-12-16 17:18:42 +0100213 leave:
Willy Tarreau33810222019-06-12 17:44:02 +0200214 free_trash_chunk(output);
215 free_trash_chunk(replace);
216 return ret;
Christopher Faulete00d06c2019-12-16 17:18:42 +0100217
218 fail_alloc:
219 if (!(s->flags & SF_ERR_MASK))
220 s->flags |= SF_ERR_RESOURCE;
221 ret = ACT_RET_ERR;
222 goto leave;
223
224 fail_rewrite:
225 _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
226 if (s->flags & SF_BE_ASSIGNED)
227 _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
228 if (sess->listener->counters)
229 _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
230 if (objt_server(s->target))
231 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
232
Christopher Faulet333bf8c2020-01-22 14:38:05 +0100233 if (!(s->txn->req.flags & HTTP_MSGF_SOFT_RW)) {
Christopher Faulete00d06c2019-12-16 17:18:42 +0100234 ret = ACT_RET_ERR;
Christopher Faulet333bf8c2020-01-22 14:38:05 +0100235 if (!(s->flags & SF_ERR_MASK))
236 s->flags |= SF_ERR_PRXCOND;
237 }
Christopher Faulete00d06c2019-12-16 17:18:42 +0100238 goto leave;
Willy Tarreau33810222019-06-12 17:44:02 +0200239}
240
Willy Tarreau262c3f12019-12-17 06:52:51 +0100241/* parse a "replace-uri" or "replace-path" http-request action.
Willy Tarreau33810222019-06-12 17:44:02 +0200242 * This action takes 2 arguments (a regex and a replacement format string).
Christopher Faulet2c22a692019-12-18 15:39:56 +0100243 * The resulting rule makes use of <.action> to store the action (1/3 for now),
Christopher Faulet96bff762019-12-17 13:46:18 +0100244 * <http.re> to store the compiled regex, and <http.fmt> to store the log-format
Willy Tarreau33810222019-06-12 17:44:02 +0200245 * list head. It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
246 */
247static enum act_parse_ret parse_replace_uri(const char **args, int *orig_arg, struct proxy *px,
248 struct act_rule *rule, char **err)
249{
250 int cur_arg = *orig_arg;
251 char *error = NULL;
252
Willy Tarreau262c3f12019-12-17 06:52:51 +0100253 if (strcmp(args[cur_arg-1], "replace-path") == 0)
Christopher Faulet2c22a692019-12-18 15:39:56 +0100254 rule->action = 1; // replace-path, same as set-path
Willy Tarreau262c3f12019-12-17 06:52:51 +0100255 else
Christopher Faulet2c22a692019-12-18 15:39:56 +0100256 rule->action = 3; // replace-uri, same as set-uri
Willy Tarreau262c3f12019-12-17 06:52:51 +0100257
Willy Tarreau33810222019-06-12 17:44:02 +0200258 rule->action_ptr = http_action_replace_uri;
Christopher Faulet2eb53962020-01-14 14:47:34 +0100259 rule->release_ptr = release_http_action;
Willy Tarreau33810222019-06-12 17:44:02 +0200260
261 if (!*args[cur_arg] || !*args[cur_arg+1] ||
262 (*args[cur_arg+2] && strcmp(args[cur_arg+2], "if") != 0 && strcmp(args[cur_arg+2], "unless") != 0)) {
263 memprintf(err, "expects exactly 2 arguments <match-regex> and <replace-format>");
264 return ACT_RET_PRS_ERR;
265 }
266
Christopher Faulet96bff762019-12-17 13:46:18 +0100267 if (!(rule->arg.http.re = regex_comp(args[cur_arg], 1, 1, &error))) {
Willy Tarreau33810222019-06-12 17:44:02 +0200268 memprintf(err, "failed to parse the regex : %s", error);
269 free(error);
270 return ACT_RET_PRS_ERR;
271 }
272
Christopher Faulet96bff762019-12-17 13:46:18 +0100273 LIST_INIT(&rule->arg.http.fmt);
Willy Tarreau33810222019-06-12 17:44:02 +0200274 px->conf.args.ctx = ARGC_HRQ;
Christopher Faulet96bff762019-12-17 13:46:18 +0100275 if (!parse_logformat_string(args[cur_arg + 1], px, &rule->arg.http.fmt, LOG_OPT_HTTP,
Willy Tarreau33810222019-06-12 17:44:02 +0200276 (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, err)) {
Christopher Faulet1337b322020-01-14 14:50:55 +0100277 regex_free(rule->arg.http.re);
Willy Tarreau33810222019-06-12 17:44:02 +0200278 return ACT_RET_PRS_ERR;
279 }
280
281 (*orig_arg) += 2;
282 return ACT_RET_PRS_OK;
283}
284
Willy Tarreau79e57332018-10-02 16:01:16 +0200285/* This function is just a compliant action wrapper for "set-status". */
286static enum act_return action_http_set_status(struct act_rule *rule, struct proxy *px,
287 struct session *sess, struct stream *s, int flags)
288{
Christopher Faulet96bff762019-12-17 13:46:18 +0100289 if (http_res_set_status(rule->arg.http.i, rule->arg.http.str, s) == -1) {
Christopher Faulete00d06c2019-12-16 17:18:42 +0100290 _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
291 if (s->flags & SF_BE_ASSIGNED)
292 _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
293 if (sess->listener->counters)
294 _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
295 if (objt_server(s->target))
296 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
297
Christopher Faulet333bf8c2020-01-22 14:38:05 +0100298 if (!(s->txn->req.flags & HTTP_MSGF_SOFT_RW)) {
Christopher Faulete00d06c2019-12-16 17:18:42 +0100299 return ACT_RET_ERR;
Christopher Faulet333bf8c2020-01-22 14:38:05 +0100300 if (!(s->flags & SF_ERR_MASK))
301 s->flags |= SF_ERR_PRXCOND;
302 }
Christopher Faulete00d06c2019-12-16 17:18:42 +0100303 }
304
Willy Tarreau79e57332018-10-02 16:01:16 +0200305 return ACT_RET_CONT;
306}
307
308/* parse set-status action:
309 * This action accepts a single argument of type int representing
310 * an http status code. It returns ACT_RET_PRS_OK on success,
311 * ACT_RET_PRS_ERR on error.
312 */
313static enum act_parse_ret parse_http_set_status(const char **args, int *orig_arg, struct proxy *px,
314 struct act_rule *rule, char **err)
315{
316 char *error;
317
318 rule->action = ACT_CUSTOM;
319 rule->action_ptr = action_http_set_status;
Christopher Faulet2eb53962020-01-14 14:47:34 +0100320 rule->release_ptr = release_http_action;
Willy Tarreau79e57332018-10-02 16:01:16 +0200321
322 /* Check if an argument is available */
323 if (!*args[*orig_arg]) {
324 memprintf(err, "expects 1 argument: <status>; or 3 arguments: <status> reason <fmt>");
325 return ACT_RET_PRS_ERR;
326 }
327
328 /* convert status code as integer */
Christopher Faulet96bff762019-12-17 13:46:18 +0100329 rule->arg.http.i = strtol(args[*orig_arg], &error, 10);
330 if (*error != '\0' || rule->arg.http.i < 100 || rule->arg.http.i > 999) {
Willy Tarreau79e57332018-10-02 16:01:16 +0200331 memprintf(err, "expects an integer status code between 100 and 999");
332 return ACT_RET_PRS_ERR;
333 }
334
335 (*orig_arg)++;
336
337 /* set custom reason string */
Christopher Faulet96bff762019-12-17 13:46:18 +0100338 rule->arg.http.str = ist(NULL); // If null, we use the default reason for the status code.
Willy Tarreau79e57332018-10-02 16:01:16 +0200339 if (*args[*orig_arg] && strcmp(args[*orig_arg], "reason") == 0 &&
340 (*args[*orig_arg + 1] && strcmp(args[*orig_arg + 1], "if") != 0 && strcmp(args[*orig_arg + 1], "unless") != 0)) {
341 (*orig_arg)++;
Christopher Faulet96bff762019-12-17 13:46:18 +0100342 rule->arg.http.str.ptr = strdup(args[*orig_arg]);
343 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200344 (*orig_arg)++;
345 }
346
Christopher Fauletc20b3712020-01-27 15:51:56 +0100347 LIST_INIT(&rule->arg.http.fmt);
Willy Tarreau79e57332018-10-02 16:01:16 +0200348 return ACT_RET_PRS_OK;
349}
350
351/* This function executes the "reject" HTTP action. It clears the request and
352 * response buffer without sending any response. It can be useful as an HTTP
353 * alternative to the silent-drop action to defend against DoS attacks, and may
354 * also be used with HTTP/2 to close a connection instead of just a stream.
355 * The txn status is unchanged, indicating no response was sent. The termination
Christopher Faulet8f1aa772019-07-04 11:27:15 +0200356 * flags will indicate "PR". It always returns ACT_RET_DONE.
Willy Tarreau79e57332018-10-02 16:01:16 +0200357 */
358static enum act_return http_action_reject(struct act_rule *rule, struct proxy *px,
359 struct session *sess, struct stream *s, int flags)
360{
Willy Tarreau0f9cd7b2019-01-31 19:02:43 +0100361 si_must_kill_conn(chn_prod(&s->req));
Willy Tarreau79e57332018-10-02 16:01:16 +0200362 channel_abort(&s->req);
363 channel_abort(&s->res);
364 s->req.analysers = 0;
365 s->res.analysers = 0;
366
Olivier Houcharda798bf52019-03-08 18:52:00 +0100367 _HA_ATOMIC_ADD(&s->be->be_counters.denied_req, 1);
368 _HA_ATOMIC_ADD(&sess->fe->fe_counters.denied_req, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200369 if (sess->listener && sess->listener->counters)
Olivier Houcharda798bf52019-03-08 18:52:00 +0100370 _HA_ATOMIC_ADD(&sess->listener->counters->denied_req, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200371
372 if (!(s->flags & SF_ERR_MASK))
373 s->flags |= SF_ERR_PRXCOND;
374 if (!(s->flags & SF_FINST_MASK))
375 s->flags |= SF_FINST_R;
376
Christopher Faulet8f1aa772019-07-04 11:27:15 +0200377 return ACT_RET_DONE;
Willy Tarreau79e57332018-10-02 16:01:16 +0200378}
379
380/* parse the "reject" action:
381 * This action takes no argument and returns ACT_RET_PRS_OK on success,
382 * ACT_RET_PRS_ERR on error.
383 */
384static enum act_parse_ret parse_http_action_reject(const char **args, int *orig_arg, struct proxy *px,
385 struct act_rule *rule, char **err)
386{
387 rule->action = ACT_CUSTOM;
388 rule->action_ptr = http_action_reject;
389 return ACT_RET_PRS_OK;
390}
391
Olivier Houchard602bf7d2019-05-10 13:59:15 +0200392/* This function executes the "disable-l7-retry" HTTP action.
393 * It disables L7 retries (all retry except for a connection failure). This
394 * can be useful for example to avoid retrying on POST requests.
395 * It just removes the L7 retry flag on the stream_interface, and always
396 * return ACT_RET_CONT;
397 */
398static enum act_return http_req_disable_l7_retry(struct act_rule *rule, struct proxy *px,
399 struct session *sess, struct stream *s, int flags)
400{
401 struct stream_interface *si = &s->si[1];
402
403 /* In theory, the SI_FL_L7_RETRY flags isn't set at this point, but
404 * let's be future-proof and remove it anyway.
405 */
406 si->flags &= ~SI_FL_L7_RETRY;
407 si->flags |= SI_FL_D_L7_RETRY;
408 return ACT_RET_CONT;
409}
410
411/* parse the "disable-l7-retry" action:
412 * This action takes no argument and returns ACT_RET_PRS_OK on success,
413 * ACT_RET_PRS_ERR on error.
414 */
415static enum act_parse_ret parse_http_req_disable_l7_retry(const char **args,
416 int *orig_args, struct proxy *px,
417 struct act_rule *rule, char **err)
418{
419 rule->action = ACT_CUSTOM;
420 rule->action_ptr = http_req_disable_l7_retry;
421 return ACT_RET_PRS_OK;
422}
423
Willy Tarreau79e57332018-10-02 16:01:16 +0200424/* This function executes the "capture" action. It executes a fetch expression,
425 * turns the result into a string and puts it in a capture slot. It always
426 * returns 1. If an error occurs the action is cancelled, but the rule
427 * processing continues.
428 */
429static enum act_return http_action_req_capture(struct act_rule *rule, struct proxy *px,
430 struct session *sess, struct stream *s, int flags)
431{
432 struct sample *key;
433 struct cap_hdr *h = rule->arg.cap.hdr;
434 char **cap = s->req_cap;
435 int len;
436
437 key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.cap.expr, SMP_T_STR);
438 if (!key)
439 return ACT_RET_CONT;
440
441 if (cap[h->index] == NULL)
442 cap[h->index] = pool_alloc(h->pool);
443
444 if (cap[h->index] == NULL) /* no more capture memory */
445 return ACT_RET_CONT;
446
447 len = key->data.u.str.data;
448 if (len > h->len)
449 len = h->len;
450
451 memcpy(cap[h->index], key->data.u.str.area, len);
452 cap[h->index][len] = 0;
453 return ACT_RET_CONT;
454}
455
456/* This function executes the "capture" action and store the result in a
457 * capture slot if exists. It executes a fetch expression, turns the result
458 * into a string and puts it in a capture slot. It always returns 1. If an
459 * error occurs the action is cancelled, but the rule processing continues.
460 */
461static enum act_return http_action_req_capture_by_id(struct act_rule *rule, struct proxy *px,
462 struct session *sess, struct stream *s, int flags)
463{
464 struct sample *key;
465 struct cap_hdr *h;
466 char **cap = s->req_cap;
467 struct proxy *fe = strm_fe(s);
468 int len;
469 int i;
470
471 /* Look for the original configuration. */
472 for (h = fe->req_cap, i = fe->nb_req_cap - 1;
473 h != NULL && i != rule->arg.capid.idx ;
474 i--, h = h->next);
475 if (!h)
476 return ACT_RET_CONT;
477
478 key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR);
479 if (!key)
480 return ACT_RET_CONT;
481
482 if (cap[h->index] == NULL)
483 cap[h->index] = pool_alloc(h->pool);
484
485 if (cap[h->index] == NULL) /* no more capture memory */
486 return ACT_RET_CONT;
487
488 len = key->data.u.str.data;
489 if (len > h->len)
490 len = h->len;
491
492 memcpy(cap[h->index], key->data.u.str.area, len);
493 cap[h->index][len] = 0;
494 return ACT_RET_CONT;
495}
496
497/* Check an "http-request capture" action.
498 *
499 * The function returns 1 in success case, otherwise, it returns 0 and err is
500 * filled.
501 */
502static int check_http_req_capture(struct act_rule *rule, struct proxy *px, char **err)
503{
504 if (rule->action_ptr != http_action_req_capture_by_id)
505 return 1;
506
Baptiste Assmann19a69b32020-01-16 14:34:22 +0100507 /* capture slots can only be declared in frontends, so we can't check their
508 * existence in backends at configuration parsing step
509 */
510 if (px->cap & PR_CAP_FE && rule->arg.capid.idx >= px->nb_req_cap) {
Willy Tarreau79e57332018-10-02 16:01:16 +0200511 memprintf(err, "unable to find capture id '%d' referenced by http-request capture rule",
512 rule->arg.capid.idx);
513 return 0;
514 }
515
516 return 1;
517}
518
Christopher Faulet2eb53962020-01-14 14:47:34 +0100519/* Release memory allocate by an http capture action */
520static void release_http_capture(struct act_rule *rule)
521{
522 if (rule->action_ptr == http_action_req_capture)
523 release_sample_expr(rule->arg.cap.expr);
524 else
525 release_sample_expr(rule->arg.capid.expr);
526}
527
Willy Tarreau79e57332018-10-02 16:01:16 +0200528/* parse an "http-request capture" action. It takes a single argument which is
529 * a sample fetch expression. It stores the expression into arg->act.p[0] and
530 * the allocated hdr_cap struct or the preallocated "id" into arg->act.p[1].
531 * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
532 */
533static enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, struct proxy *px,
534 struct act_rule *rule, char **err)
535{
536 struct sample_expr *expr;
537 struct cap_hdr *hdr;
538 int cur_arg;
539 int len = 0;
540
541 for (cur_arg = *orig_arg; cur_arg < *orig_arg + 3 && *args[cur_arg]; cur_arg++)
542 if (strcmp(args[cur_arg], "if") == 0 ||
543 strcmp(args[cur_arg], "unless") == 0)
544 break;
545
546 if (cur_arg < *orig_arg + 3) {
547 memprintf(err, "expects <expression> [ 'len' <length> | id <idx> ]");
548 return ACT_RET_PRS_ERR;
549 }
550
551 cur_arg = *orig_arg;
552 expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line, err, &px->conf.args);
553 if (!expr)
554 return ACT_RET_PRS_ERR;
555
556 if (!(expr->fetch->val & SMP_VAL_FE_HRQ_HDR)) {
557 memprintf(err,
558 "fetch method '%s' extracts information from '%s', none of which is available here",
559 args[cur_arg-1], sample_src_names(expr->fetch->use));
Christopher Faulet1337b322020-01-14 14:50:55 +0100560 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200561 return ACT_RET_PRS_ERR;
562 }
563
564 if (!args[cur_arg] || !*args[cur_arg]) {
565 memprintf(err, "expects 'len or 'id'");
Christopher Faulet1337b322020-01-14 14:50:55 +0100566 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200567 return ACT_RET_PRS_ERR;
568 }
569
570 if (strcmp(args[cur_arg], "len") == 0) {
571 cur_arg++;
572
573 if (!(px->cap & PR_CAP_FE)) {
574 memprintf(err, "proxy '%s' has no frontend capability", px->id);
Christopher Faulet1337b322020-01-14 14:50:55 +0100575 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200576 return ACT_RET_PRS_ERR;
577 }
578
579 px->conf.args.ctx = ARGC_CAP;
580
581 if (!args[cur_arg]) {
582 memprintf(err, "missing length value");
Christopher Faulet1337b322020-01-14 14:50:55 +0100583 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200584 return ACT_RET_PRS_ERR;
585 }
586 /* we copy the table name for now, it will be resolved later */
587 len = atoi(args[cur_arg]);
588 if (len <= 0) {
589 memprintf(err, "length must be > 0");
Christopher Faulet1337b322020-01-14 14:50:55 +0100590 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200591 return ACT_RET_PRS_ERR;
592 }
593 cur_arg++;
594
Willy Tarreau79e57332018-10-02 16:01:16 +0200595 hdr = calloc(1, sizeof(*hdr));
596 hdr->next = px->req_cap;
597 hdr->name = NULL; /* not a header capture */
598 hdr->namelen = 0;
599 hdr->len = len;
600 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
601 hdr->index = px->nb_req_cap++;
602
603 px->req_cap = hdr;
604 px->to_log |= LW_REQHDR;
605
606 rule->action = ACT_CUSTOM;
607 rule->action_ptr = http_action_req_capture;
Christopher Faulet2eb53962020-01-14 14:47:34 +0100608 rule->release_ptr = release_http_capture;
Willy Tarreau79e57332018-10-02 16:01:16 +0200609 rule->arg.cap.expr = expr;
610 rule->arg.cap.hdr = hdr;
611 }
612
613 else if (strcmp(args[cur_arg], "id") == 0) {
614 int id;
615 char *error;
616
617 cur_arg++;
618
619 if (!args[cur_arg]) {
620 memprintf(err, "missing id value");
Christopher Faulet1337b322020-01-14 14:50:55 +0100621 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200622 return ACT_RET_PRS_ERR;
623 }
624
625 id = strtol(args[cur_arg], &error, 10);
626 if (*error != '\0') {
627 memprintf(err, "cannot parse id '%s'", args[cur_arg]);
Christopher Faulet1337b322020-01-14 14:50:55 +0100628 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200629 return ACT_RET_PRS_ERR;
630 }
631 cur_arg++;
632
633 px->conf.args.ctx = ARGC_CAP;
634
635 rule->action = ACT_CUSTOM;
636 rule->action_ptr = http_action_req_capture_by_id;
637 rule->check_ptr = check_http_req_capture;
Christopher Faulet2eb53962020-01-14 14:47:34 +0100638 rule->release_ptr = release_http_capture;
Willy Tarreau79e57332018-10-02 16:01:16 +0200639 rule->arg.capid.expr = expr;
640 rule->arg.capid.idx = id;
641 }
642
643 else {
644 memprintf(err, "expects 'len' or 'id', found '%s'", args[cur_arg]);
Christopher Faulet1337b322020-01-14 14:50:55 +0100645 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200646 return ACT_RET_PRS_ERR;
647 }
648
649 *orig_arg = cur_arg;
650 return ACT_RET_PRS_OK;
651}
652
653/* This function executes the "capture" action and store the result in a
654 * capture slot if exists. It executes a fetch expression, turns the result
655 * into a string and puts it in a capture slot. It always returns 1. If an
656 * error occurs the action is cancelled, but the rule processing continues.
657 */
658static enum act_return http_action_res_capture_by_id(struct act_rule *rule, struct proxy *px,
659 struct session *sess, struct stream *s, int flags)
660{
661 struct sample *key;
662 struct cap_hdr *h;
663 char **cap = s->res_cap;
664 struct proxy *fe = strm_fe(s);
665 int len;
666 int i;
667
668 /* Look for the original configuration. */
669 for (h = fe->rsp_cap, i = fe->nb_rsp_cap - 1;
670 h != NULL && i != rule->arg.capid.idx ;
671 i--, h = h->next);
672 if (!h)
673 return ACT_RET_CONT;
674
675 key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR);
676 if (!key)
677 return ACT_RET_CONT;
678
679 if (cap[h->index] == NULL)
680 cap[h->index] = pool_alloc(h->pool);
681
682 if (cap[h->index] == NULL) /* no more capture memory */
683 return ACT_RET_CONT;
684
685 len = key->data.u.str.data;
686 if (len > h->len)
687 len = h->len;
688
689 memcpy(cap[h->index], key->data.u.str.area, len);
690 cap[h->index][len] = 0;
691 return ACT_RET_CONT;
692}
693
694/* Check an "http-response capture" action.
695 *
696 * The function returns 1 in success case, otherwise, it returns 0 and err is
697 * filled.
698 */
699static int check_http_res_capture(struct act_rule *rule, struct proxy *px, char **err)
700{
701 if (rule->action_ptr != http_action_res_capture_by_id)
702 return 1;
703
704 if (rule->arg.capid.idx >= px->nb_rsp_cap) {
705 memprintf(err, "unable to find capture id '%d' referenced by http-response capture rule",
706 rule->arg.capid.idx);
707 return 0;
708 }
709
710 return 1;
711}
712
713/* parse an "http-response capture" action. It takes a single argument which is
714 * a sample fetch expression. It stores the expression into arg->act.p[0] and
715 * the allocated hdr_cap struct od the preallocated id into arg->act.p[1].
716 * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
717 */
718static enum act_parse_ret parse_http_res_capture(const char **args, int *orig_arg, struct proxy *px,
719 struct act_rule *rule, char **err)
720{
721 struct sample_expr *expr;
722 int cur_arg;
723 int id;
724 char *error;
725
726 for (cur_arg = *orig_arg; cur_arg < *orig_arg + 3 && *args[cur_arg]; cur_arg++)
727 if (strcmp(args[cur_arg], "if") == 0 ||
728 strcmp(args[cur_arg], "unless") == 0)
729 break;
730
731 if (cur_arg < *orig_arg + 3) {
732 memprintf(err, "expects <expression> id <idx>");
733 return ACT_RET_PRS_ERR;
734 }
735
736 cur_arg = *orig_arg;
737 expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line, err, &px->conf.args);
738 if (!expr)
739 return ACT_RET_PRS_ERR;
740
741 if (!(expr->fetch->val & SMP_VAL_FE_HRS_HDR)) {
742 memprintf(err,
743 "fetch method '%s' extracts information from '%s', none of which is available here",
744 args[cur_arg-1], sample_src_names(expr->fetch->use));
Christopher Faulet1337b322020-01-14 14:50:55 +0100745 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200746 return ACT_RET_PRS_ERR;
747 }
748
749 if (!args[cur_arg] || !*args[cur_arg]) {
750 memprintf(err, "expects 'id'");
Christopher Faulet1337b322020-01-14 14:50:55 +0100751 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200752 return ACT_RET_PRS_ERR;
753 }
754
755 if (strcmp(args[cur_arg], "id") != 0) {
756 memprintf(err, "expects 'id', found '%s'", args[cur_arg]);
Christopher Faulet1337b322020-01-14 14:50:55 +0100757 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200758 return ACT_RET_PRS_ERR;
759 }
760
761 cur_arg++;
762
763 if (!args[cur_arg]) {
764 memprintf(err, "missing id value");
Christopher Faulet1337b322020-01-14 14:50:55 +0100765 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200766 return ACT_RET_PRS_ERR;
767 }
768
769 id = strtol(args[cur_arg], &error, 10);
770 if (*error != '\0') {
771 memprintf(err, "cannot parse id '%s'", args[cur_arg]);
Christopher Faulet1337b322020-01-14 14:50:55 +0100772 release_sample_expr(expr);
Willy Tarreau79e57332018-10-02 16:01:16 +0200773 return ACT_RET_PRS_ERR;
774 }
775 cur_arg++;
776
777 px->conf.args.ctx = ARGC_CAP;
778
779 rule->action = ACT_CUSTOM;
780 rule->action_ptr = http_action_res_capture_by_id;
781 rule->check_ptr = check_http_res_capture;
Christopher Faulet2eb53962020-01-14 14:47:34 +0100782 rule->release_ptr = release_http_capture;
Willy Tarreau79e57332018-10-02 16:01:16 +0200783 rule->arg.capid.expr = expr;
784 rule->arg.capid.idx = id;
785
786 *orig_arg = cur_arg;
787 return ACT_RET_PRS_OK;
788}
789
Christopher Faulet81e20172019-12-12 16:40:30 +0100790/* Parse a "allow" action for a request or a response rule. It takes no argument. It
791 * returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
792 */
793static enum act_parse_ret parse_http_allow(const char **args, int *orig_arg, struct proxy *px,
794 struct act_rule *rule, char **err)
795{
796 rule->action = ACT_ACTION_ALLOW;
Christopher Faulet245cf792019-12-18 14:58:12 +0100797 rule->flags |= ACT_FLAG_FINAL;
Christopher Faulet81e20172019-12-12 16:40:30 +0100798 return ACT_RET_PRS_OK;
799}
800
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100801/* Check an "http-request deny" action when an http-errors section is referenced.
802 *
803 * The function returns 1 in success case, otherwise, it returns 0 and err is
804 * filled.
805 */
806static int check_http_deny_action(struct act_rule *rule, struct proxy *px, char **err)
807{
808 struct http_errors *http_errs;
809 int status = (intptr_t)(rule->arg.act.p[0]);
810 int ret = 1;
811
812 list_for_each_entry(http_errs, &http_errors_list, list) {
813 if (strcmp(http_errs->id, (char *)rule->arg.act.p[1]) == 0) {
814 free(rule->arg.act.p[1]);
815 rule->arg.http_deny.status = status;
816 rule->arg.http_deny.errmsg = http_errs->errmsg[http_get_status_idx(status)];
817 if (!rule->arg.http_deny.errmsg)
818 ha_warning("Proxy '%s': status '%d' referenced by http deny rule "
819 "not declared in http-errors section '%s'.\n",
820 px->id, status, http_errs->id);
821 break;
822 }
823 }
824
825 if (&http_errs->list == &http_errors_list) {
826 memprintf(err, "unknown http-errors section '%s' referenced by http deny rule",
827 (char *)rule->arg.act.p[1]);
828 free(rule->arg.act.p[1]);
829 ret = 0;
830 }
831
832 return ret;
833}
834
Christopher Faulete0fca292020-01-13 21:49:03 +0100835/* Parse "deny" or "tarpit" actions for a request rule or "deny" action for a
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100836 * response rule. It may take optional arguments to define the status code, the
837 * error file or the http-errors section to use. It returns ACT_RET_PRS_OK on
838 * success, ACT_RET_PRS_ERR on error.
Christopher Faulet81e20172019-12-12 16:40:30 +0100839 */
Christopher Faulete0fca292020-01-13 21:49:03 +0100840static enum act_parse_ret parse_http_deny(const char **args, int *orig_arg, struct proxy *px,
841 struct act_rule *rule, char **err)
Christopher Faulet81e20172019-12-12 16:40:30 +0100842{
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100843 int default_status, status, hc, cur_arg;
844
Christopher Faulet81e20172019-12-12 16:40:30 +0100845
846 cur_arg = *orig_arg;
Christopher Faulete0fca292020-01-13 21:49:03 +0100847 if (rule->from == ACT_F_HTTP_REQ) {
848 if (!strcmp(args[cur_arg-1], "tarpit")) {
849 rule->action = ACT_HTTP_REQ_TARPIT;
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100850 default_status = status = 500;
Christopher Faulet81e20172019-12-12 16:40:30 +0100851 }
Christopher Faulete0fca292020-01-13 21:49:03 +0100852 else {
853 rule->action = ACT_ACTION_DENY;
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100854 default_status = status = 403;
Christopher Faulet81e20172019-12-12 16:40:30 +0100855 }
Christopher Faulet81e20172019-12-12 16:40:30 +0100856 }
Christopher Faulete0fca292020-01-13 21:49:03 +0100857 else {
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100858 rule->action = ACT_ACTION_DENY;
859 default_status = status = 502;
Christopher Faulete0fca292020-01-13 21:49:03 +0100860 }
Christopher Faulet245cf792019-12-18 14:58:12 +0100861 rule->flags |= ACT_FLAG_FINAL;
Christopher Faulet040c8cd2020-01-13 16:43:45 +0100862
863 if (strcmp(args[cur_arg], "deny_status") == 0) {
864 cur_arg++;
865 if (!*args[cur_arg]) {
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100866 memprintf(err, "'%s' expects <status_code> as argument", args[cur_arg-1]);
Christopher Faulet040c8cd2020-01-13 16:43:45 +0100867 return ACT_RET_PRS_ERR;
868 }
869
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100870 status = atol(args[cur_arg]);
Christopher Faulet040c8cd2020-01-13 16:43:45 +0100871 cur_arg++;
872 for (hc = 0; hc < HTTP_ERR_SIZE; hc++) {
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100873 if (http_err_codes[hc] == status)
Christopher Faulet040c8cd2020-01-13 16:43:45 +0100874 break;
Christopher Faulet040c8cd2020-01-13 16:43:45 +0100875 }
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100876 if (hc >= HTTP_ERR_SIZE) {
877 memprintf(err, "status code '%d' not handled, using default code '%d'",
878 status, default_status);
879 status = default_status;
880 hc = http_get_status_idx(status);
881 }
Christopher Faulet040c8cd2020-01-13 16:43:45 +0100882 }
883
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100884 if (strcmp(args[cur_arg], "errorfile") == 0) {
885 cur_arg++;
886 if (!*args[cur_arg]) {
887 memprintf(err, "'%s' expects <file> as argument", args[cur_arg-1]);
888 return ACT_RET_PRS_ERR;
889 }
890
891 rule->arg.http_deny.errmsg = http_load_errorfile(args[cur_arg], err);
892 if (!rule->arg.http_deny.errmsg)
893 return ACT_RET_PRS_ERR;
894 cur_arg++;
895 }
896 else if (strcmp(args[cur_arg], "errorfiles") == 0) {
897 cur_arg++;
898 if (!*args[cur_arg]) {
899 memprintf(err, "'%s' expects <http_errors_name> as argument", args[cur_arg-1]);
900 return ACT_RET_PRS_ERR;
901 }
902 /* Must be resolved during the config validity check */
903 rule->arg.act.p[0] = (void *)((intptr_t)status);
904 rule->arg.act.p[1] = strdup(args[cur_arg]);
905 rule->check_ptr = check_http_deny_action;
906 cur_arg++;
907 goto out;
908 }
909
910 rule->arg.http_deny.status = status;
911
912 out:
Christopher Faulet040c8cd2020-01-13 16:43:45 +0100913 *orig_arg = cur_arg;
Christopher Faulet81e20172019-12-12 16:40:30 +0100914 return ACT_RET_PRS_OK;
915}
916
917/* Parse a "auth" action. It may take 2 optional arguments to define a "realm"
918 * parameter. It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
919 */
920static enum act_parse_ret parse_http_auth(const char **args, int *orig_arg, struct proxy *px,
921 struct act_rule *rule, char **err)
922{
923 int cur_arg;
924
925 rule->action = ACT_HTTP_REQ_AUTH;
Christopher Faulet245cf792019-12-18 14:58:12 +0100926 rule->flags |= ACT_FLAG_FINAL;
Christopher Faulet2eb53962020-01-14 14:47:34 +0100927 rule->release_ptr = release_http_action;
Christopher Faulet81e20172019-12-12 16:40:30 +0100928
929 cur_arg = *orig_arg;
930 if (!strcmp(args[cur_arg], "realm")) {
931 cur_arg++;
932 if (!*args[cur_arg]) {
933 memprintf(err, "missing realm value.\n");
934 return ACT_RET_PRS_ERR;
935 }
Christopher Faulet96bff762019-12-17 13:46:18 +0100936 rule->arg.http.str.ptr = strdup(args[cur_arg]);
937 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
Christopher Faulet81e20172019-12-12 16:40:30 +0100938 cur_arg++;
939 }
940
Christopher Fauletc20b3712020-01-27 15:51:56 +0100941 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +0100942 *orig_arg = cur_arg;
943 return ACT_RET_PRS_OK;
944}
945
946/* Parse a "set-nice" action. It takes the nice value as argument. It returns
947 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
948 */
949static enum act_parse_ret parse_http_set_nice(const char **args, int *orig_arg, struct proxy *px,
950 struct act_rule *rule, char **err)
951{
952 int cur_arg;
953
954 rule->action = ACT_HTTP_SET_NICE;
955
956 cur_arg = *orig_arg;
957 if (!*args[cur_arg]) {
958 memprintf(err, "expects exactly 1 argument (integer value)");
959 return ACT_RET_PRS_ERR;
960 }
Christopher Faulet96bff762019-12-17 13:46:18 +0100961 rule->arg.http.i = atoi(args[cur_arg]);
962 if (rule->arg.http.i < -1024)
963 rule->arg.http.i = -1024;
964 else if (rule->arg.http.i > 1024)
965 rule->arg.http.i = 1024;
Christopher Faulet81e20172019-12-12 16:40:30 +0100966
Christopher Fauletc20b3712020-01-27 15:51:56 +0100967 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +0100968 *orig_arg = cur_arg + 1;
969 return ACT_RET_PRS_OK;
970}
971
972/* Parse a "set-tos" action. It takes the TOS value as argument. It returns
973 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
974 */
975static enum act_parse_ret parse_http_set_tos(const char **args, int *orig_arg, struct proxy *px,
976 struct act_rule *rule, char **err)
977{
978#ifdef IP_TOS
979 char *endp;
980 int cur_arg;
981
982 rule->action = ACT_HTTP_SET_TOS;
983
984 cur_arg = *orig_arg;
985 if (!*args[cur_arg]) {
986 memprintf(err, "expects exactly 1 argument (integer/hex value)");
987 return ACT_RET_PRS_ERR;
988 }
Christopher Faulet96bff762019-12-17 13:46:18 +0100989 rule->arg.http.i = strtol(args[cur_arg], &endp, 0);
Christopher Faulet81e20172019-12-12 16:40:30 +0100990 if (endp && *endp != '\0') {
991 memprintf(err, "invalid character starting at '%s' (integer/hex value expected)", endp);
992 return ACT_RET_PRS_ERR;
993 }
994
Christopher Fauletc20b3712020-01-27 15:51:56 +0100995 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +0100996 *orig_arg = cur_arg + 1;
997 return ACT_RET_PRS_OK;
998#else
999 memprintf(err, "not supported on this platform (IP_TOS undefined)");
1000 return ACT_RET_PRS_ERR;
1001#endif
1002}
1003
1004/* Parse a "set-mark" action. It takes the MARK value as argument. It returns
1005 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
1006 */
1007static enum act_parse_ret parse_http_set_mark(const char **args, int *orig_arg, struct proxy *px,
1008 struct act_rule *rule, char **err)
1009{
1010#ifdef SO_MARK
1011 char *endp;
1012 int cur_arg;
1013
1014 rule->action = ACT_HTTP_SET_MARK;
1015
1016 cur_arg = *orig_arg;
1017 if (!*args[cur_arg]) {
1018 memprintf(err, "expects exactly 1 argument (integer/hex value)");
1019 return ACT_RET_PRS_ERR;
1020 }
Christopher Faulet96bff762019-12-17 13:46:18 +01001021 rule->arg.http.i = strtoul(args[cur_arg], &endp, 0);
Christopher Faulet81e20172019-12-12 16:40:30 +01001022 if (endp && *endp != '\0') {
1023 memprintf(err, "invalid character starting at '%s' (integer/hex value expected)", endp);
1024 return ACT_RET_PRS_ERR;
1025 }
1026
Christopher Fauletc20b3712020-01-27 15:51:56 +01001027 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001028 *orig_arg = cur_arg + 1;
1029 global.last_checks |= LSTCHK_NETADM;
1030 return ACT_RET_PRS_OK;
1031#else
1032 memprintf(err, "not supported on this platform (SO_MARK undefined)");
1033 return ACT_RET_PRS_ERR;
1034#endif
1035}
1036
1037/* Parse a "set-log-level" action. It takes the level value as argument. It
1038 * returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
1039 */
1040static enum act_parse_ret parse_http_set_log_level(const char **args, int *orig_arg, struct proxy *px,
1041 struct act_rule *rule, char **err)
1042{
1043 int cur_arg;
1044
1045 rule->action = ACT_HTTP_SET_LOGL;
1046
1047 cur_arg = *orig_arg;
1048 if (!*args[cur_arg]) {
1049 bad_log_level:
1050 memprintf(err, "expects exactly 1 argument (log level name or 'silent')");
1051 return ACT_RET_PRS_ERR;
1052 }
1053 if (strcmp(args[cur_arg], "silent") == 0)
Christopher Faulet96bff762019-12-17 13:46:18 +01001054 rule->arg.http.i = -1;
1055 else if ((rule->arg.http.i = get_log_level(args[cur_arg]) + 1) == 0)
Christopher Faulet81e20172019-12-12 16:40:30 +01001056 goto bad_log_level;
1057
Christopher Fauletc20b3712020-01-27 15:51:56 +01001058 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001059 *orig_arg = cur_arg + 1;
1060 return ACT_RET_PRS_OK;
1061}
1062
Christopher Faulet91b3ec12020-01-17 22:30:06 +01001063/* This function executes a early-hint action. It adds an HTTP Early Hint HTTP
1064 * 103 response header with <.arg.http.str> name and with a value built
1065 * according to <.arg.http.fmt> log line format. If it is the first early-hint
1066 * rule of a serie, the 103 response start-line is added first. At the end, if
1067 * the next rule is not an early-hint rule or if it is the last rule, the EOH
1068 * block is added to terminate the response. On success, it returns
1069 * ACT_RET_CONT. If an error occurs while soft rewrites are enabled, the action
1070 * is canceled, but the rule processing continue. Otherwsize ACT_RET_ERR is
1071 * returned.
1072 */
1073static enum act_return http_action_early_hint(struct act_rule *rule, struct proxy *px,
1074 struct session *sess, struct stream *s, int flags)
1075{
1076 struct act_rule *prev_rule, *next_rule;
1077 struct channel *res = &s->res;
1078 struct htx *htx = htx_from_buf(&res->buf);
1079 struct buffer *value = alloc_trash_chunk();
1080 enum act_return ret = ACT_RET_CONT;
1081
1082 if (!(s->txn->req.flags & HTTP_MSGF_VER_11))
1083 goto leave;
1084
1085 if (!value) {
1086 if (!(s->flags & SF_ERR_MASK))
1087 s->flags |= SF_ERR_RESOURCE;
1088 goto error;
1089 }
1090
1091 /* get previous and next rules */
1092 prev_rule = LIST_PREV(&rule->list, typeof(rule), list);
1093 next_rule = LIST_NEXT(&rule->list, typeof(rule), list);
1094
1095 /* if no previous rule or previous rule is not early-hint, start a new response. Otherwise,
1096 * continue to add link to a previously started response */
1097 if (&prev_rule->list == s->current_rule_list || prev_rule->action_ptr != http_action_early_hint) {
1098 struct htx_sl *sl;
1099 unsigned int flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|
1100 HTX_SL_F_XFER_LEN|HTX_SL_F_BODYLESS);
1101
1102 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags,
1103 ist("HTTP/1.1"), ist("103"), ist("Early Hints"));
1104 if (!sl)
1105 goto error;
1106 sl->info.res.status = 103;
1107 }
1108
1109 /* Add the HTTP Early Hint HTTP 103 response heade */
1110 value->data = build_logline(s, b_tail(value), b_room(value), &rule->arg.http.fmt);
1111 if (!htx_add_header(htx, rule->arg.http.str, ist2(b_head(value), b_data(value))))
1112 goto error;
1113
1114 /* if it is the last rule or the next one is not an early-hint, terminate the current
1115 * response. */
1116 if (&next_rule->list == s->current_rule_list || next_rule->action_ptr != http_action_early_hint) {
1117 size_t data;
1118
1119 if (!htx_add_endof(htx, HTX_BLK_EOH)) {
1120 /* If an error occurred during an Early-hint rule,
1121 * remove the incomplete HTTP 103 response from the
1122 * buffer */
1123 goto error;
1124 }
1125
1126 data = htx->data - co_data(res);
1127 c_adv(res, data);
1128 res->total += data;
1129 }
1130
1131 leave:
1132 free_trash_chunk(value);
1133 return ret;
1134
1135 error:
1136 /* If an error occurred during an Early-hint rule, remove the incomplete
1137 * HTTP 103 response from the buffer */
1138 channel_htx_truncate(res, htx);
1139 ret = ACT_RET_ERR;
1140 goto leave;
1141}
1142
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001143/* This function executes a set-header or add-header actions. It builds a string
1144 * in the trash from the specified format string. It finds the action to be
1145 * performed in <.action>, previously filled by function parse_set_header(). The
1146 * replacement action is excuted by the function http_action_set_header(). On
1147 * success, it returns ACT_RET_CONT. If an error occurs while soft rewrites are
1148 * enabled, the action is canceled, but the rule processing continue. Otherwsize
1149 * ACT_RET_ERR is returned.
1150 */
1151static enum act_return http_action_set_header(struct act_rule *rule, struct proxy *px,
1152 struct session *sess, struct stream *s, int flags)
1153{
Christopher Faulet91e31d82020-01-24 15:37:13 +01001154 struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp);
1155 struct htx *htx = htxbuf(&msg->chn->buf);
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001156 enum act_return ret = ACT_RET_CONT;
1157 struct buffer *replace;
1158 struct http_hdr_ctx ctx;
1159 struct ist n, v;
1160
1161 replace = alloc_trash_chunk();
1162 if (!replace)
1163 goto fail_alloc;
1164
1165 replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt);
1166 n = rule->arg.http.str;
1167 v = ist2(replace->area, replace->data);
1168
1169 if (rule->action == 0) { // set-header
1170 /* remove all occurrences of the header */
1171 ctx.blk = NULL;
1172 while (http_find_header(htx, n, &ctx, 1))
1173 http_remove_header(htx, &ctx);
1174 }
1175
1176 /* Now add header */
1177 if (!http_add_header(htx, n, v))
1178 goto fail_rewrite;
1179
1180 leave:
1181 free_trash_chunk(replace);
1182 return ret;
1183
1184 fail_alloc:
1185 if (!(s->flags & SF_ERR_MASK))
1186 s->flags |= SF_ERR_RESOURCE;
1187 ret = ACT_RET_ERR;
1188 goto leave;
1189
1190 fail_rewrite:
1191 _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
1192 if (s->flags & SF_BE_ASSIGNED)
1193 _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
1194 if (sess->listener->counters)
1195 _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
1196 if (objt_server(s->target))
1197 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
1198
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001199 if (!(msg->flags & HTTP_MSGF_SOFT_RW)) {
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001200 ret = ACT_RET_ERR;
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001201 if (!(s->flags & SF_ERR_MASK))
1202 s->flags |= SF_ERR_PRXCOND;
1203 }
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001204 goto leave;
1205}
1206
Christopher Faulet81e20172019-12-12 16:40:30 +01001207/* Parse a "set-header", "add-header" or "early-hint" actions. It takes an
1208 * header name and a log-format string as arguments. It returns ACT_RET_PRS_OK
1209 * on success, ACT_RET_PRS_ERR on error.
1210 *
1211 * Note: same function is used for the request and the response. However
1212 * "early-hint" rules are only supported for request rules.
1213 */
1214static enum act_parse_ret parse_http_set_header(const char **args, int *orig_arg, struct proxy *px,
1215 struct act_rule *rule, char **err)
1216{
Christopher Faulet81e20172019-12-12 16:40:30 +01001217 int cap, cur_arg;
1218
Christopher Faulet91b3ec12020-01-17 22:30:06 +01001219 if (args[*orig_arg-1][0] == 'e') {
1220 rule->action = ACT_CUSTOM;
1221 rule->action_ptr = http_action_early_hint;
1222 }
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001223 else {
1224 if (args[*orig_arg-1][0] == 's')
1225 rule->action = 0; // set-header
1226 else
1227 rule->action = 1; // add-header
1228 rule->action_ptr = http_action_set_header;
1229 }
Christopher Faulet2eb53962020-01-14 14:47:34 +01001230 rule->release_ptr = release_http_action;
Christopher Faulet81e20172019-12-12 16:40:30 +01001231
1232 cur_arg = *orig_arg;
1233 if (!*args[cur_arg] || !*args[cur_arg+1]) {
1234 memprintf(err, "expects exactly 2 arguments");
1235 return ACT_RET_PRS_ERR;
1236 }
1237
Christopher Faulet81e20172019-12-12 16:40:30 +01001238
Christopher Faulet96bff762019-12-17 13:46:18 +01001239 rule->arg.http.str.ptr = strdup(args[cur_arg]);
1240 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
1241 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001242
1243 if (rule->from == ACT_F_HTTP_REQ) {
1244 px->conf.args.ctx = ARGC_HRQ;
1245 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
1246 }
1247 else{
1248 px->conf.args.ctx = ARGC_HRS;
1249 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
1250 }
1251
1252 cur_arg++;
Christopher Faulet1337b322020-01-14 14:50:55 +01001253 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) {
1254 free(rule->arg.http.str.ptr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001255 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001256 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001257
1258 free(px->conf.lfs_file);
1259 px->conf.lfs_file = strdup(px->conf.args.file);
1260 px->conf.lfs_line = px->conf.args.line;
1261
1262 *orig_arg = cur_arg + 1;
1263 return ACT_RET_PRS_OK;
1264}
1265
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001266/* This function executes a replace-header or replace-value actions. It
1267 * builds a string in the trash from the specified format string. It finds
1268 * the action to be performed in <.action>, previously filled by function
1269 * parse_replace_header(). The replacement action is excuted by the function
1270 * http_action_replace_header(). On success, it returns ACT_RET_CONT. If an error
1271 * occurs while soft rewrites are enabled, the action is canceled, but the rule
1272 * processing continue. Otherwsize ACT_RET_ERR is returned.
1273 */
1274static enum act_return http_action_replace_header(struct act_rule *rule, struct proxy *px,
1275 struct session *sess, struct stream *s, int flags)
1276{
Christopher Faulet91e31d82020-01-24 15:37:13 +01001277 struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp);
1278 struct htx *htx = htxbuf(&msg->chn->buf);
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001279 enum act_return ret = ACT_RET_CONT;
1280 struct buffer *replace;
1281 int r;
1282
1283 replace = alloc_trash_chunk();
1284 if (!replace)
1285 goto fail_alloc;
1286
1287 replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt);
1288
1289 r = http_replace_hdrs(s, htx, rule->arg.http.str, replace->area, rule->arg.http.re, (rule->action == 0));
1290 if (r == -1)
1291 goto fail_rewrite;
1292
1293 leave:
1294 free_trash_chunk(replace);
1295 return ret;
1296
1297 fail_alloc:
1298 if (!(s->flags & SF_ERR_MASK))
1299 s->flags |= SF_ERR_RESOURCE;
1300 ret = ACT_RET_ERR;
1301 goto leave;
1302
1303 fail_rewrite:
1304 _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
1305 if (s->flags & SF_BE_ASSIGNED)
1306 _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
1307 if (sess->listener->counters)
1308 _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
1309 if (objt_server(s->target))
1310 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
1311
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001312 if (!(msg->flags & HTTP_MSGF_SOFT_RW)) {
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001313 ret = ACT_RET_ERR;
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001314 if (!(s->flags & SF_ERR_MASK))
1315 s->flags |= SF_ERR_PRXCOND;
1316 }
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001317 goto leave;
1318}
1319
Christopher Faulet81e20172019-12-12 16:40:30 +01001320/* Parse a "replace-header" or "replace-value" actions. It takes an header name,
1321 * a regex and replacement string as arguments. It returns ACT_RET_PRS_OK on
1322 * success, ACT_RET_PRS_ERR on error.
1323 */
1324static enum act_parse_ret parse_http_replace_header(const char **args, int *orig_arg, struct proxy *px,
1325 struct act_rule *rule, char **err)
1326{
1327 int cap, cur_arg;
1328
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001329 if (args[*orig_arg-1][8] == 'h')
1330 rule->action = 0; // replace-header
1331 else
1332 rule->action = 1; // replace-value
1333 rule->action_ptr = http_action_replace_header;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001334 rule->release_ptr = release_http_action;
Christopher Faulet81e20172019-12-12 16:40:30 +01001335
1336 cur_arg = *orig_arg;
1337 if (!*args[cur_arg] || !*args[cur_arg+1] || !*args[cur_arg+2]) {
1338 memprintf(err, "expects exactly 3 arguments");
1339 return ACT_RET_PRS_ERR;
1340 }
1341
Christopher Faulet96bff762019-12-17 13:46:18 +01001342 rule->arg.http.str.ptr = strdup(args[cur_arg]);
1343 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
1344 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001345
1346 cur_arg++;
Christopher Faulet1337b322020-01-14 14:50:55 +01001347 if (!(rule->arg.http.re = regex_comp(args[cur_arg], 1, 1, err))) {
1348 free(rule->arg.http.str.ptr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001349 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001350 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001351
1352 if (rule->from == ACT_F_HTTP_REQ) {
1353 px->conf.args.ctx = ARGC_HRQ;
1354 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
1355 }
1356 else{
1357 px->conf.args.ctx = ARGC_HRS;
1358 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
1359 }
1360
1361 cur_arg++;
Christopher Faulet1337b322020-01-14 14:50:55 +01001362 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) {
1363 free(rule->arg.http.str.ptr);
1364 regex_free(rule->arg.http.re);
Christopher Faulet81e20172019-12-12 16:40:30 +01001365 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001366 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001367
1368 free(px->conf.lfs_file);
1369 px->conf.lfs_file = strdup(px->conf.args.file);
1370 px->conf.lfs_line = px->conf.args.line;
1371
1372 *orig_arg = cur_arg + 1;
1373 return ACT_RET_PRS_OK;
1374}
1375
1376/* Parse a "del-header" action. It takes an header name as argument. It returns
1377 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
1378 */
1379static enum act_parse_ret parse_http_del_header(const char **args, int *orig_arg, struct proxy *px,
1380 struct act_rule *rule, char **err)
1381{
1382 int cur_arg;
1383
1384 rule->action = ACT_HTTP_DEL_HDR;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001385 rule->release_ptr = release_http_action;
Christopher Faulet81e20172019-12-12 16:40:30 +01001386
1387 cur_arg = *orig_arg;
1388 if (!*args[cur_arg]) {
1389 memprintf(err, "expects exactly 1 arguments");
1390 return ACT_RET_PRS_ERR;
1391 }
1392
Christopher Faulet96bff762019-12-17 13:46:18 +01001393 rule->arg.http.str.ptr = strdup(args[cur_arg]);
1394 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001395
1396 px->conf.args.ctx = (rule->from == ACT_F_HTTP_REQ ? ARGC_HRQ : ARGC_HRS);
1397
Christopher Fauletc20b3712020-01-27 15:51:56 +01001398 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001399 *orig_arg = cur_arg + 1;
1400 return ACT_RET_PRS_OK;
1401}
1402
Christopher Faulet2eb53962020-01-14 14:47:34 +01001403/* Release memory allocated by an http redirect action. */
1404static void release_http_redir(struct act_rule *rule)
1405{
1406 struct logformat_node *lf, *lfb;
1407 struct redirect_rule *redir;
1408
1409 redir = rule->arg.redir;
1410 LIST_DEL(&redir->list);
1411 if (redir->cond) {
1412 prune_acl_cond(redir->cond);
1413 free(redir->cond);
1414 }
1415 free(redir->rdr_str);
1416 free(redir->cookie_str);
1417 list_for_each_entry_safe(lf, lfb, &redir->rdr_fmt, list) {
1418 LIST_DEL(&lf->list);
1419 free(lf);
1420 }
1421 free(redir);
1422}
1423
Christopher Faulet81e20172019-12-12 16:40:30 +01001424/* Parse a "redirect" action. It returns ACT_RET_PRS_OK on success,
1425 * ACT_RET_PRS_ERR on error.
1426 */
1427static enum act_parse_ret parse_http_redirect(const char **args, int *orig_arg, struct proxy *px,
1428 struct act_rule *rule, char **err)
1429{
1430 struct redirect_rule *redir;
1431 int dir, cur_arg;
1432
1433 rule->action = ACT_HTTP_REDIR;
Christopher Faulet245cf792019-12-18 14:58:12 +01001434 rule->flags |= ACT_FLAG_FINAL;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001435 rule->release_ptr = release_http_redir;
Christopher Faulet81e20172019-12-12 16:40:30 +01001436
1437 cur_arg = *orig_arg;
1438
1439 dir = (rule->from == ACT_F_HTTP_REQ ? 0 : 1);
1440 if ((redir = http_parse_redirect_rule(px->conf.args.file, px->conf.args.line, px, &args[cur_arg], err, 1, dir)) == NULL)
1441 return ACT_RET_PRS_ERR;
1442
1443 rule->arg.redir = redir;
1444 rule->cond = redir->cond;
1445 redir->cond = NULL;
1446
1447 /* skip all arguments */
1448 while (*args[cur_arg])
1449 cur_arg++;
1450
1451 *orig_arg = cur_arg;
1452 return ACT_RET_PRS_OK;
1453}
1454
Christopher Faulet046cf442019-12-17 15:45:23 +01001455/* This function executes a add-acl, del-acl, set-map or del-map actions. On
1456 * success, it returns ACT_RET_CONT. Otherwsize ACT_RET_ERR is returned.
1457 */
1458static enum act_return http_action_set_map(struct act_rule *rule, struct proxy *px,
1459 struct session *sess, struct stream *s, int flags)
1460{
1461 struct pat_ref *ref;
1462 struct buffer *key = NULL, *value = NULL;
1463 enum act_return ret = ACT_RET_CONT;
1464
1465 /* collect reference */
1466 ref = pat_ref_lookup(rule->arg.map.ref);
1467 if (!ref)
1468 goto leave;
1469
1470 /* allocate key */
1471 key = alloc_trash_chunk();
1472 if (!key)
1473 goto fail_alloc;
1474
1475 /* collect key */
1476 key->data = build_logline(s, key->area, key->size, &rule->arg.map.key);
1477 key->area[key->data] = '\0';
1478
1479 switch (rule->action) {
1480 case 0: // add-acl
1481 /* add entry only if it does not already exist */
1482 HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
1483 if (pat_ref_find_elt(ref, key->area) == NULL)
1484 pat_ref_add(ref, key->area, NULL, NULL);
1485 HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
1486 break;
1487
1488 case 1: // set-map
1489 /* allocate value */
1490 value = alloc_trash_chunk();
1491 if (!value)
1492 goto fail_alloc;
1493
1494 /* collect value */
1495 value->data = build_logline(s, value->area, value->size, &rule->arg.map.value);
1496 value->area[value->data] = '\0';
1497
1498 HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
1499 if (pat_ref_find_elt(ref, key->area) != NULL) {
1500 /* update entry if it exists */
1501 pat_ref_set(ref, key->area, value->area, NULL);
1502 }
1503 else {
1504 /* insert a new entry */
1505 pat_ref_add(ref, key->area, value->area, NULL);
1506 }
1507 HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
1508 break;
1509
1510 case 2: // del-acl
1511 case 3: // del-map
1512 /* returned code: 1=ok, 0=ko */
1513 HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
1514 pat_ref_delete(ref, key->area);
1515 HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
1516 break;
1517
1518 default:
1519 ret = ACT_RET_ERR;
1520 }
1521
1522
1523 leave:
1524 free_trash_chunk(key);
1525 free_trash_chunk(value);
1526 return ret;
1527
1528 fail_alloc:
1529 if (!(s->flags & SF_ERR_MASK))
1530 s->flags |= SF_ERR_RESOURCE;
1531 ret = ACT_RET_ERR;
1532 goto leave;
1533}
1534
Christopher Faulet2eb53962020-01-14 14:47:34 +01001535/* Release memory allocated by an http map/acl action. */
1536static void release_http_map(struct act_rule *rule)
1537{
1538 struct logformat_node *lf, *lfb;
1539
1540 free(rule->arg.map.ref);
1541 list_for_each_entry_safe(lf, lfb, &rule->arg.map.key, list) {
1542 LIST_DEL(&lf->list);
1543 release_sample_expr(lf->expr);
1544 free(lf->arg);
1545 free(lf);
1546 }
1547 if (rule->action == 1) {
1548 list_for_each_entry_safe(lf, lfb, &rule->arg.map.value, list) {
1549 LIST_DEL(&lf->list);
1550 release_sample_expr(lf->expr);
1551 free(lf->arg);
1552 free(lf);
1553 }
1554 }
1555}
1556
Christopher Faulet81e20172019-12-12 16:40:30 +01001557/* Parse a "add-acl", "del-acl", "set-map" or "del-map" actions. It takes one or
Christopher Faulet046cf442019-12-17 15:45:23 +01001558 * two log-format string as argument depending on the action. The action is
1559 * stored in <.action> as an int (0=add-acl, 1=set-map, 2=del-acl,
1560 * 3=del-map). It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
Christopher Faulet81e20172019-12-12 16:40:30 +01001561 */
1562static enum act_parse_ret parse_http_set_map(const char **args, int *orig_arg, struct proxy *px,
1563 struct act_rule *rule, char **err)
1564{
1565 int cap, cur_arg;
1566
Christopher Faulet046cf442019-12-17 15:45:23 +01001567 if (args[*orig_arg-1][0] == 'a') // add-acl
1568 rule->action = 0;
1569 else if (args[*orig_arg-1][0] == 's') // set-map
1570 rule->action = 1;
1571 else if (args[*orig_arg-1][4] == 'a') // del-acl
1572 rule->action = 2;
1573 else if (args[*orig_arg-1][4] == 'm') // del-map
1574 rule->action = 3;
1575 else {
1576 memprintf(err, "internal error: unhandled action '%s'", args[0]);
1577 return ACT_RET_PRS_ERR;
1578 }
1579 rule->action_ptr = http_action_set_map;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001580 rule->release_ptr = release_http_map;
Christopher Faulet81e20172019-12-12 16:40:30 +01001581
1582 cur_arg = *orig_arg;
Christopher Faulet046cf442019-12-17 15:45:23 +01001583 if (rule->action == 1 && (!*args[cur_arg] || !*args[cur_arg+1])) {
1584 /* 2 args for set-map */
Christopher Faulet81e20172019-12-12 16:40:30 +01001585 memprintf(err, "expects exactly 2 arguments");
1586 return ACT_RET_PRS_ERR;
1587 }
1588 else if (!*args[cur_arg]) {
Christopher Faulet046cf442019-12-17 15:45:23 +01001589 /* only one arg for other actions */
Christopher Faulet81e20172019-12-12 16:40:30 +01001590 memprintf(err, "expects exactly 1 arguments");
1591 return ACT_RET_PRS_ERR;
1592 }
1593
1594 /*
1595 * '+ 8' for 'set-map(' (same for del-map)
1596 * '- 9' for 'set-map(' + trailing ')' (same for del-map)
1597 */
1598 rule->arg.map.ref = my_strndup(args[cur_arg-1] + 8, strlen(args[cur_arg-1]) - 9);
1599
1600 if (rule->from == ACT_F_HTTP_REQ) {
1601 px->conf.args.ctx = ARGC_HRQ;
1602 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
1603 }
1604 else{
1605 px->conf.args.ctx = ARGC_HRS;
1606 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
1607 }
1608
1609 /* key pattern */
1610 LIST_INIT(&rule->arg.map.key);
Christopher Faulet1337b322020-01-14 14:50:55 +01001611 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.key, LOG_OPT_HTTP, cap, err)) {
1612 free(rule->arg.map.ref);
Christopher Faulet81e20172019-12-12 16:40:30 +01001613 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001614 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001615
Christopher Faulet046cf442019-12-17 15:45:23 +01001616 if (rule->action == 1) {
Christopher Faulet81e20172019-12-12 16:40:30 +01001617 /* value pattern for set-map only */
1618 cur_arg++;
1619 LIST_INIT(&rule->arg.map.value);
Christopher Faulet1337b322020-01-14 14:50:55 +01001620 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.value, LOG_OPT_HTTP, cap, err)) {
1621 free(rule->arg.map.ref);
Christopher Faulet81e20172019-12-12 16:40:30 +01001622 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001623 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001624 }
1625
1626 free(px->conf.lfs_file);
1627 px->conf.lfs_file = strdup(px->conf.args.file);
1628 px->conf.lfs_line = px->conf.args.line;
1629
1630 *orig_arg = cur_arg + 1;
1631 return ACT_RET_PRS_OK;
1632}
1633
Christopher Fauletac98d812019-12-18 09:20:16 +01001634/* This function executes a track-sc* actions. On success, it returns
1635 * ACT_RET_CONT. Otherwsize ACT_RET_ERR is returned.
1636 */
1637static enum act_return http_action_track_sc(struct act_rule *rule, struct proxy *px,
1638 struct session *sess, struct stream *s, int flags)
1639{
1640 struct stktable *t;
1641 struct stksess *ts;
1642 struct stktable_key *key;
1643 void *ptr1, *ptr2, *ptr3, *ptr4;
1644 int opt;
1645
1646 ptr1 = ptr2 = ptr3 = ptr4 = NULL;
1647 opt = ((rule->from == ACT_F_HTTP_REQ) ? SMP_OPT_DIR_REQ : SMP_OPT_DIR_RES) | SMP_OPT_FINAL;
1648
1649 t = rule->arg.trk_ctr.table.t;
1650 key = stktable_fetch_key(t, s->be, sess, s, opt, rule->arg.trk_ctr.expr, NULL);
1651
1652 if (!key)
1653 goto end;
1654 ts = stktable_get_entry(t, key);
1655 if (!ts)
1656 goto end;
1657
1658 stream_track_stkctr(&s->stkctr[rule->action], t, ts);
1659
1660 /* let's count a new HTTP request as it's the first time we do it */
1661 ptr1 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT);
1662 ptr2 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE);
1663
1664 /* When the client triggers a 4xx from the server, it's most often due
1665 * to a missing object or permission. These events should be tracked
1666 * because if they happen often, it may indicate a brute force or a
1667 * vulnerability scan. Normally this is done when receiving the response
1668 * but here we're tracking after this ought to have been done so we have
1669 * to do it on purpose.
1670 */
1671 if (rule->from == ACT_F_HTTP_RES && (unsigned)(s->txn->status - 400) < 100) {
1672 ptr3 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT);
1673 ptr4 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE);
1674 }
1675
1676 if (ptr1 || ptr2 || ptr3 || ptr4) {
1677 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
1678
1679 if (ptr1)
1680 stktable_data_cast(ptr1, http_req_cnt)++;
1681 if (ptr2)
1682 update_freq_ctr_period(&stktable_data_cast(ptr2, http_req_rate),
1683 t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
1684 if (ptr3)
1685 stktable_data_cast(ptr3, http_err_cnt)++;
1686 if (ptr4)
1687 update_freq_ctr_period(&stktable_data_cast(ptr4, http_err_rate),
1688 t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1);
1689
1690 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
1691
1692 /* If data was modified, we need to touch to re-schedule sync */
1693 stktable_touch_local(t, ts, 0);
1694 }
1695
1696 stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_CONTENT);
1697 if (sess->fe != s->be)
1698 stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_BACKEND);
1699
1700 end:
1701 return ACT_RET_CONT;
1702}
Christopher Faulet81e20172019-12-12 16:40:30 +01001703
Christopher Faulet2eb53962020-01-14 14:47:34 +01001704static void release_http_track_sc(struct act_rule *rule)
1705{
1706 release_sample_expr(rule->arg.trk_ctr.expr);
1707}
1708
Christopher Faulet81e20172019-12-12 16:40:30 +01001709/* Parse a "track-sc*" actions. It returns ACT_RET_PRS_OK on success,
1710 * ACT_RET_PRS_ERR on error.
1711 */
1712static enum act_parse_ret parse_http_track_sc(const char **args, int *orig_arg, struct proxy *px,
1713 struct act_rule *rule, char **err)
1714{
1715 struct sample_expr *expr;
1716 unsigned int where;
1717 unsigned int tsc_num;
1718 const char *tsc_num_str;
1719 int cur_arg;
1720
1721 tsc_num_str = &args[*orig_arg-1][8];
1722 if (cfg_parse_track_sc_num(&tsc_num, tsc_num_str, tsc_num_str + strlen(tsc_num_str), err) == -1)
1723 return ACT_RET_PRS_ERR;
1724
1725 cur_arg = *orig_arg;
1726 expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line,
1727 err, &px->conf.args);
1728 if (!expr)
1729 return ACT_RET_PRS_ERR;
1730
1731 where = 0;
1732 if (px->cap & PR_CAP_FE)
1733 where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_FE_HRS_HDR);
1734 if (px->cap & PR_CAP_BE)
1735 where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_BE_HRQ_HDR : SMP_VAL_BE_HRS_HDR);
1736
1737 if (!(expr->fetch->val & where)) {
1738 memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here",
1739 args[cur_arg-1], sample_src_names(expr->fetch->use));
Christopher Faulet1337b322020-01-14 14:50:55 +01001740 release_sample_expr(expr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001741 return ACT_RET_PRS_ERR;
1742 }
1743
1744 if (strcmp(args[cur_arg], "table") == 0) {
1745 cur_arg++;
1746 if (!*args[cur_arg]) {
1747 memprintf(err, "missing table name");
Christopher Faulet1337b322020-01-14 14:50:55 +01001748 release_sample_expr(expr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001749 return ACT_RET_PRS_ERR;
1750 }
1751
1752 /* we copy the table name for now, it will be resolved later */
1753 rule->arg.trk_ctr.table.n = strdup(args[cur_arg]);
1754 cur_arg++;
1755 }
1756
Christopher Fauletac98d812019-12-18 09:20:16 +01001757 rule->action = tsc_num;
Christopher Faulet81e20172019-12-12 16:40:30 +01001758 rule->arg.trk_ctr.expr = expr;
Christopher Fauletac98d812019-12-18 09:20:16 +01001759 rule->action_ptr = http_action_track_sc;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001760 rule->release_ptr = release_http_track_sc;
Christopher Faulet81e20172019-12-12 16:40:30 +01001761 rule->check_ptr = check_trk_action;
1762
1763 *orig_arg = cur_arg;
1764 return ACT_RET_PRS_OK;
1765}
1766
Christopher Faulet46f95542019-12-20 10:07:22 +01001767/* This function executes a strict-mode actions. On success, it always returns
1768 * ACT_RET_CONT
1769 */
1770static enum act_return http_action_strict_mode(struct act_rule *rule, struct proxy *px,
1771 struct session *sess, struct stream *s, int flags)
1772{
1773 struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp);
1774
1775 if (rule->action == 0) // strict-mode on
1776 msg->flags &= ~HTTP_MSGF_SOFT_RW;
1777 else // strict-mode off
1778 msg->flags |= HTTP_MSGF_SOFT_RW;
1779 return ACT_RET_CONT;
1780}
1781
1782/* Parse a "strict-mode" action. It returns ACT_RET_PRS_OK on success,
1783 * ACT_RET_PRS_ERR on error.
1784 */
1785static enum act_parse_ret parse_http_strict_mode(const char **args, int *orig_arg, struct proxy *px,
1786 struct act_rule *rule, char **err)
1787{
1788 int cur_arg;
1789
1790
1791 cur_arg = *orig_arg;
1792 if (!*args[cur_arg]) {
1793 memprintf(err, "expects exactly 1 arguments");
1794 return ACT_RET_PRS_ERR;
1795 }
1796
1797 if (strcasecmp(args[cur_arg], "on") == 0)
1798 rule->action = 0; // strict-mode on
1799 else if (strcasecmp(args[cur_arg], "off") == 0)
1800 rule->action = 1; // strict-mode off
1801 else {
1802 memprintf(err, "Unexpected value '%s'. Only 'on' and 'off' are supported", args[cur_arg]);
1803 return ACT_RET_PRS_ERR;
1804 }
1805 rule->action_ptr = http_action_strict_mode;
1806
1807 *orig_arg = cur_arg + 1;
1808 return ACT_RET_PRS_OK;
1809}
1810
Willy Tarreau79e57332018-10-02 16:01:16 +02001811/************************************************************************/
1812/* All supported http-request action keywords must be declared here. */
1813/************************************************************************/
1814
1815static struct action_kw_list http_req_actions = {
1816 .kw = {
Christopher Faulet81e20172019-12-12 16:40:30 +01001817 { "add-acl", parse_http_set_map, 1 },
1818 { "add-header", parse_http_set_header, 0 },
1819 { "allow", parse_http_allow, 0 },
1820 { "auth", parse_http_auth, 0 },
1821 { "capture", parse_http_req_capture, 0 },
1822 { "del-acl", parse_http_set_map, 1 },
1823 { "del-header", parse_http_del_header, 0 },
1824 { "del-map", parse_http_set_map, 1 },
Christopher Faulete0fca292020-01-13 21:49:03 +01001825 { "deny", parse_http_deny, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001826 { "disable-l7-retry", parse_http_req_disable_l7_retry, 0 },
1827 { "early-hint", parse_http_set_header, 0 },
1828 { "redirect", parse_http_redirect, 0 },
1829 { "reject", parse_http_action_reject, 0 },
1830 { "replace-header", parse_http_replace_header, 0 },
1831 { "replace-path", parse_replace_uri, 0 },
1832 { "replace-uri", parse_replace_uri, 0 },
1833 { "replace-value", parse_http_replace_header, 0 },
1834 { "set-header", parse_http_set_header, 0 },
1835 { "set-log-level", parse_http_set_log_level, 0 },
1836 { "set-map", parse_http_set_map, 1 },
1837 { "set-method", parse_set_req_line, 0 },
1838 { "set-mark", parse_http_set_mark, 0 },
1839 { "set-nice", parse_http_set_nice, 0 },
1840 { "set-path", parse_set_req_line, 0 },
1841 { "set-query", parse_set_req_line, 0 },
1842 { "set-tos", parse_http_set_tos, 0 },
1843 { "set-uri", parse_set_req_line, 0 },
Christopher Faulet46f95542019-12-20 10:07:22 +01001844 { "strict-mode", parse_http_strict_mode, 0 },
Christopher Faulete0fca292020-01-13 21:49:03 +01001845 { "tarpit", parse_http_deny, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001846 { "track-sc", parse_http_track_sc, 1 },
Willy Tarreau79e57332018-10-02 16:01:16 +02001847 { NULL, NULL }
1848 }
1849};
1850
Willy Tarreau0108d902018-11-25 19:14:37 +01001851INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_actions);
1852
Willy Tarreau79e57332018-10-02 16:01:16 +02001853static struct action_kw_list http_res_actions = {
1854 .kw = {
Christopher Faulet81e20172019-12-12 16:40:30 +01001855 { "add-acl", parse_http_set_map, 1 },
1856 { "add-header", parse_http_set_header, 0 },
1857 { "allow", parse_http_allow, 0 },
1858 { "capture", parse_http_res_capture, 0 },
1859 { "del-acl", parse_http_set_map, 1 },
1860 { "del-header", parse_http_del_header, 0 },
1861 { "del-map", parse_http_set_map, 1 },
Christopher Faulete0fca292020-01-13 21:49:03 +01001862 { "deny", parse_http_deny, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001863 { "redirect", parse_http_redirect, 0 },
1864 { "replace-header", parse_http_replace_header, 0 },
1865 { "replace-value", parse_http_replace_header, 0 },
1866 { "set-header", parse_http_set_header, 0 },
1867 { "set-log-level", parse_http_set_log_level, 0 },
1868 { "set-map", parse_http_set_map, 1 },
1869 { "set-mark", parse_http_set_mark, 0 },
1870 { "set-nice", parse_http_set_nice, 0 },
1871 { "set-status", parse_http_set_status, 0 },
1872 { "set-tos", parse_http_set_tos, 0 },
Christopher Faulet46f95542019-12-20 10:07:22 +01001873 { "strict-mode", parse_http_strict_mode, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001874 { "track-sc", parse_http_track_sc, 1 },
Willy Tarreau79e57332018-10-02 16:01:16 +02001875 { NULL, NULL }
1876 }
1877};
1878
Willy Tarreau0108d902018-11-25 19:14:37 +01001879INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_actions);
Willy Tarreau79e57332018-10-02 16:01:16 +02001880
1881/*
1882 * Local variables:
1883 * c-indent-level: 8
1884 * c-basic-offset: 8
1885 * End:
1886 */