blob: 67eca318ae20cb16e4f8fe51f4acbb014616cdd4 [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);
Christopher Faulet7a138dc2020-01-24 19:12:35 +01001128 htx->first = -1;
Christopher Faulet91b3ec12020-01-17 22:30:06 +01001129 res->total += data;
1130 }
1131
1132 leave:
1133 free_trash_chunk(value);
1134 return ret;
1135
1136 error:
1137 /* If an error occurred during an Early-hint rule, remove the incomplete
1138 * HTTP 103 response from the buffer */
1139 channel_htx_truncate(res, htx);
1140 ret = ACT_RET_ERR;
1141 goto leave;
1142}
1143
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001144/* This function executes a set-header or add-header actions. It builds a string
1145 * in the trash from the specified format string. It finds the action to be
1146 * performed in <.action>, previously filled by function parse_set_header(). The
1147 * replacement action is excuted by the function http_action_set_header(). On
1148 * success, it returns ACT_RET_CONT. If an error occurs while soft rewrites are
1149 * enabled, the action is canceled, but the rule processing continue. Otherwsize
1150 * ACT_RET_ERR is returned.
1151 */
1152static enum act_return http_action_set_header(struct act_rule *rule, struct proxy *px,
1153 struct session *sess, struct stream *s, int flags)
1154{
Christopher Faulet91e31d82020-01-24 15:37:13 +01001155 struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp);
1156 struct htx *htx = htxbuf(&msg->chn->buf);
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001157 enum act_return ret = ACT_RET_CONT;
1158 struct buffer *replace;
1159 struct http_hdr_ctx ctx;
1160 struct ist n, v;
1161
1162 replace = alloc_trash_chunk();
1163 if (!replace)
1164 goto fail_alloc;
1165
1166 replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt);
1167 n = rule->arg.http.str;
1168 v = ist2(replace->area, replace->data);
1169
1170 if (rule->action == 0) { // set-header
1171 /* remove all occurrences of the header */
1172 ctx.blk = NULL;
1173 while (http_find_header(htx, n, &ctx, 1))
1174 http_remove_header(htx, &ctx);
1175 }
1176
1177 /* Now add header */
1178 if (!http_add_header(htx, n, v))
1179 goto fail_rewrite;
1180
1181 leave:
1182 free_trash_chunk(replace);
1183 return ret;
1184
1185 fail_alloc:
1186 if (!(s->flags & SF_ERR_MASK))
1187 s->flags |= SF_ERR_RESOURCE;
1188 ret = ACT_RET_ERR;
1189 goto leave;
1190
1191 fail_rewrite:
1192 _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
1193 if (s->flags & SF_BE_ASSIGNED)
1194 _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
1195 if (sess->listener->counters)
1196 _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
1197 if (objt_server(s->target))
1198 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
1199
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001200 if (!(msg->flags & HTTP_MSGF_SOFT_RW)) {
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001201 ret = ACT_RET_ERR;
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001202 if (!(s->flags & SF_ERR_MASK))
1203 s->flags |= SF_ERR_PRXCOND;
1204 }
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001205 goto leave;
1206}
1207
Christopher Faulet81e20172019-12-12 16:40:30 +01001208/* Parse a "set-header", "add-header" or "early-hint" actions. It takes an
1209 * header name and a log-format string as arguments. It returns ACT_RET_PRS_OK
1210 * on success, ACT_RET_PRS_ERR on error.
1211 *
1212 * Note: same function is used for the request and the response. However
1213 * "early-hint" rules are only supported for request rules.
1214 */
1215static enum act_parse_ret parse_http_set_header(const char **args, int *orig_arg, struct proxy *px,
1216 struct act_rule *rule, char **err)
1217{
Christopher Faulet81e20172019-12-12 16:40:30 +01001218 int cap, cur_arg;
1219
Christopher Faulet91b3ec12020-01-17 22:30:06 +01001220 if (args[*orig_arg-1][0] == 'e') {
1221 rule->action = ACT_CUSTOM;
1222 rule->action_ptr = http_action_early_hint;
1223 }
Christopher Fauletd1f27e32019-12-17 09:33:38 +01001224 else {
1225 if (args[*orig_arg-1][0] == 's')
1226 rule->action = 0; // set-header
1227 else
1228 rule->action = 1; // add-header
1229 rule->action_ptr = http_action_set_header;
1230 }
Christopher Faulet2eb53962020-01-14 14:47:34 +01001231 rule->release_ptr = release_http_action;
Christopher Faulet81e20172019-12-12 16:40:30 +01001232
1233 cur_arg = *orig_arg;
1234 if (!*args[cur_arg] || !*args[cur_arg+1]) {
1235 memprintf(err, "expects exactly 2 arguments");
1236 return ACT_RET_PRS_ERR;
1237 }
1238
Christopher Faulet81e20172019-12-12 16:40:30 +01001239
Christopher Faulet96bff762019-12-17 13:46:18 +01001240 rule->arg.http.str.ptr = strdup(args[cur_arg]);
1241 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
1242 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001243
1244 if (rule->from == ACT_F_HTTP_REQ) {
1245 px->conf.args.ctx = ARGC_HRQ;
1246 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
1247 }
1248 else{
1249 px->conf.args.ctx = ARGC_HRS;
1250 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
1251 }
1252
1253 cur_arg++;
Christopher Faulet1337b322020-01-14 14:50:55 +01001254 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) {
1255 free(rule->arg.http.str.ptr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001256 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001257 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001258
1259 free(px->conf.lfs_file);
1260 px->conf.lfs_file = strdup(px->conf.args.file);
1261 px->conf.lfs_line = px->conf.args.line;
1262
1263 *orig_arg = cur_arg + 1;
1264 return ACT_RET_PRS_OK;
1265}
1266
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001267/* This function executes a replace-header or replace-value actions. It
1268 * builds a string in the trash from the specified format string. It finds
1269 * the action to be performed in <.action>, previously filled by function
1270 * parse_replace_header(). The replacement action is excuted by the function
1271 * http_action_replace_header(). On success, it returns ACT_RET_CONT. If an error
1272 * occurs while soft rewrites are enabled, the action is canceled, but the rule
1273 * processing continue. Otherwsize ACT_RET_ERR is returned.
1274 */
1275static enum act_return http_action_replace_header(struct act_rule *rule, struct proxy *px,
1276 struct session *sess, struct stream *s, int flags)
1277{
Christopher Faulet91e31d82020-01-24 15:37:13 +01001278 struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp);
1279 struct htx *htx = htxbuf(&msg->chn->buf);
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001280 enum act_return ret = ACT_RET_CONT;
1281 struct buffer *replace;
1282 int r;
1283
1284 replace = alloc_trash_chunk();
1285 if (!replace)
1286 goto fail_alloc;
1287
1288 replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt);
1289
1290 r = http_replace_hdrs(s, htx, rule->arg.http.str, replace->area, rule->arg.http.re, (rule->action == 0));
1291 if (r == -1)
1292 goto fail_rewrite;
1293
1294 leave:
1295 free_trash_chunk(replace);
1296 return ret;
1297
1298 fail_alloc:
1299 if (!(s->flags & SF_ERR_MASK))
1300 s->flags |= SF_ERR_RESOURCE;
1301 ret = ACT_RET_ERR;
1302 goto leave;
1303
1304 fail_rewrite:
1305 _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
1306 if (s->flags & SF_BE_ASSIGNED)
1307 _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
1308 if (sess->listener->counters)
1309 _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
1310 if (objt_server(s->target))
1311 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
1312
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001313 if (!(msg->flags & HTTP_MSGF_SOFT_RW)) {
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001314 ret = ACT_RET_ERR;
Christopher Faulet333bf8c2020-01-22 14:38:05 +01001315 if (!(s->flags & SF_ERR_MASK))
1316 s->flags |= SF_ERR_PRXCOND;
1317 }
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001318 goto leave;
1319}
1320
Christopher Faulet81e20172019-12-12 16:40:30 +01001321/* Parse a "replace-header" or "replace-value" actions. It takes an header name,
1322 * a regex and replacement string as arguments. It returns ACT_RET_PRS_OK on
1323 * success, ACT_RET_PRS_ERR on error.
1324 */
1325static enum act_parse_ret parse_http_replace_header(const char **args, int *orig_arg, struct proxy *px,
1326 struct act_rule *rule, char **err)
1327{
1328 int cap, cur_arg;
1329
Christopher Faulet92d34fe2019-12-17 09:20:34 +01001330 if (args[*orig_arg-1][8] == 'h')
1331 rule->action = 0; // replace-header
1332 else
1333 rule->action = 1; // replace-value
1334 rule->action_ptr = http_action_replace_header;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001335 rule->release_ptr = release_http_action;
Christopher Faulet81e20172019-12-12 16:40:30 +01001336
1337 cur_arg = *orig_arg;
1338 if (!*args[cur_arg] || !*args[cur_arg+1] || !*args[cur_arg+2]) {
1339 memprintf(err, "expects exactly 3 arguments");
1340 return ACT_RET_PRS_ERR;
1341 }
1342
Christopher Faulet96bff762019-12-17 13:46:18 +01001343 rule->arg.http.str.ptr = strdup(args[cur_arg]);
1344 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
1345 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001346
1347 cur_arg++;
Christopher Faulet1337b322020-01-14 14:50:55 +01001348 if (!(rule->arg.http.re = regex_comp(args[cur_arg], 1, 1, err))) {
1349 free(rule->arg.http.str.ptr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001350 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001351 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001352
1353 if (rule->from == ACT_F_HTTP_REQ) {
1354 px->conf.args.ctx = ARGC_HRQ;
1355 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
1356 }
1357 else{
1358 px->conf.args.ctx = ARGC_HRS;
1359 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
1360 }
1361
1362 cur_arg++;
Christopher Faulet1337b322020-01-14 14:50:55 +01001363 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) {
1364 free(rule->arg.http.str.ptr);
1365 regex_free(rule->arg.http.re);
Christopher Faulet81e20172019-12-12 16:40:30 +01001366 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001367 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001368
1369 free(px->conf.lfs_file);
1370 px->conf.lfs_file = strdup(px->conf.args.file);
1371 px->conf.lfs_line = px->conf.args.line;
1372
1373 *orig_arg = cur_arg + 1;
1374 return ACT_RET_PRS_OK;
1375}
1376
1377/* Parse a "del-header" action. It takes an header name as argument. It returns
1378 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
1379 */
1380static enum act_parse_ret parse_http_del_header(const char **args, int *orig_arg, struct proxy *px,
1381 struct act_rule *rule, char **err)
1382{
1383 int cur_arg;
1384
1385 rule->action = ACT_HTTP_DEL_HDR;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001386 rule->release_ptr = release_http_action;
Christopher Faulet81e20172019-12-12 16:40:30 +01001387
1388 cur_arg = *orig_arg;
1389 if (!*args[cur_arg]) {
1390 memprintf(err, "expects exactly 1 arguments");
1391 return ACT_RET_PRS_ERR;
1392 }
1393
Christopher Faulet96bff762019-12-17 13:46:18 +01001394 rule->arg.http.str.ptr = strdup(args[cur_arg]);
1395 rule->arg.http.str.len = strlen(rule->arg.http.str.ptr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001396
1397 px->conf.args.ctx = (rule->from == ACT_F_HTTP_REQ ? ARGC_HRQ : ARGC_HRS);
1398
Christopher Fauletc20b3712020-01-27 15:51:56 +01001399 LIST_INIT(&rule->arg.http.fmt);
Christopher Faulet81e20172019-12-12 16:40:30 +01001400 *orig_arg = cur_arg + 1;
1401 return ACT_RET_PRS_OK;
1402}
1403
Christopher Faulet2eb53962020-01-14 14:47:34 +01001404/* Release memory allocated by an http redirect action. */
1405static void release_http_redir(struct act_rule *rule)
1406{
1407 struct logformat_node *lf, *lfb;
1408 struct redirect_rule *redir;
1409
1410 redir = rule->arg.redir;
1411 LIST_DEL(&redir->list);
1412 if (redir->cond) {
1413 prune_acl_cond(redir->cond);
1414 free(redir->cond);
1415 }
1416 free(redir->rdr_str);
1417 free(redir->cookie_str);
1418 list_for_each_entry_safe(lf, lfb, &redir->rdr_fmt, list) {
1419 LIST_DEL(&lf->list);
1420 free(lf);
1421 }
1422 free(redir);
1423}
1424
Christopher Faulet81e20172019-12-12 16:40:30 +01001425/* Parse a "redirect" action. It returns ACT_RET_PRS_OK on success,
1426 * ACT_RET_PRS_ERR on error.
1427 */
1428static enum act_parse_ret parse_http_redirect(const char **args, int *orig_arg, struct proxy *px,
1429 struct act_rule *rule, char **err)
1430{
1431 struct redirect_rule *redir;
1432 int dir, cur_arg;
1433
1434 rule->action = ACT_HTTP_REDIR;
Christopher Faulet245cf792019-12-18 14:58:12 +01001435 rule->flags |= ACT_FLAG_FINAL;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001436 rule->release_ptr = release_http_redir;
Christopher Faulet81e20172019-12-12 16:40:30 +01001437
1438 cur_arg = *orig_arg;
1439
1440 dir = (rule->from == ACT_F_HTTP_REQ ? 0 : 1);
1441 if ((redir = http_parse_redirect_rule(px->conf.args.file, px->conf.args.line, px, &args[cur_arg], err, 1, dir)) == NULL)
1442 return ACT_RET_PRS_ERR;
1443
1444 rule->arg.redir = redir;
1445 rule->cond = redir->cond;
1446 redir->cond = NULL;
1447
1448 /* skip all arguments */
1449 while (*args[cur_arg])
1450 cur_arg++;
1451
1452 *orig_arg = cur_arg;
1453 return ACT_RET_PRS_OK;
1454}
1455
Christopher Faulet046cf442019-12-17 15:45:23 +01001456/* This function executes a add-acl, del-acl, set-map or del-map actions. On
1457 * success, it returns ACT_RET_CONT. Otherwsize ACT_RET_ERR is returned.
1458 */
1459static enum act_return http_action_set_map(struct act_rule *rule, struct proxy *px,
1460 struct session *sess, struct stream *s, int flags)
1461{
1462 struct pat_ref *ref;
1463 struct buffer *key = NULL, *value = NULL;
1464 enum act_return ret = ACT_RET_CONT;
1465
1466 /* collect reference */
1467 ref = pat_ref_lookup(rule->arg.map.ref);
1468 if (!ref)
1469 goto leave;
1470
1471 /* allocate key */
1472 key = alloc_trash_chunk();
1473 if (!key)
1474 goto fail_alloc;
1475
1476 /* collect key */
1477 key->data = build_logline(s, key->area, key->size, &rule->arg.map.key);
1478 key->area[key->data] = '\0';
1479
1480 switch (rule->action) {
1481 case 0: // add-acl
1482 /* add entry only if it does not already exist */
1483 HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
1484 if (pat_ref_find_elt(ref, key->area) == NULL)
1485 pat_ref_add(ref, key->area, NULL, NULL);
1486 HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
1487 break;
1488
1489 case 1: // set-map
1490 /* allocate value */
1491 value = alloc_trash_chunk();
1492 if (!value)
1493 goto fail_alloc;
1494
1495 /* collect value */
1496 value->data = build_logline(s, value->area, value->size, &rule->arg.map.value);
1497 value->area[value->data] = '\0';
1498
1499 HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
1500 if (pat_ref_find_elt(ref, key->area) != NULL) {
1501 /* update entry if it exists */
1502 pat_ref_set(ref, key->area, value->area, NULL);
1503 }
1504 else {
1505 /* insert a new entry */
1506 pat_ref_add(ref, key->area, value->area, NULL);
1507 }
1508 HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
1509 break;
1510
1511 case 2: // del-acl
1512 case 3: // del-map
1513 /* returned code: 1=ok, 0=ko */
1514 HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
1515 pat_ref_delete(ref, key->area);
1516 HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
1517 break;
1518
1519 default:
1520 ret = ACT_RET_ERR;
1521 }
1522
1523
1524 leave:
1525 free_trash_chunk(key);
1526 free_trash_chunk(value);
1527 return ret;
1528
1529 fail_alloc:
1530 if (!(s->flags & SF_ERR_MASK))
1531 s->flags |= SF_ERR_RESOURCE;
1532 ret = ACT_RET_ERR;
1533 goto leave;
1534}
1535
Christopher Faulet2eb53962020-01-14 14:47:34 +01001536/* Release memory allocated by an http map/acl action. */
1537static void release_http_map(struct act_rule *rule)
1538{
1539 struct logformat_node *lf, *lfb;
1540
1541 free(rule->arg.map.ref);
1542 list_for_each_entry_safe(lf, lfb, &rule->arg.map.key, list) {
1543 LIST_DEL(&lf->list);
1544 release_sample_expr(lf->expr);
1545 free(lf->arg);
1546 free(lf);
1547 }
1548 if (rule->action == 1) {
1549 list_for_each_entry_safe(lf, lfb, &rule->arg.map.value, list) {
1550 LIST_DEL(&lf->list);
1551 release_sample_expr(lf->expr);
1552 free(lf->arg);
1553 free(lf);
1554 }
1555 }
1556}
1557
Christopher Faulet81e20172019-12-12 16:40:30 +01001558/* Parse a "add-acl", "del-acl", "set-map" or "del-map" actions. It takes one or
Christopher Faulet046cf442019-12-17 15:45:23 +01001559 * two log-format string as argument depending on the action. The action is
1560 * stored in <.action> as an int (0=add-acl, 1=set-map, 2=del-acl,
1561 * 3=del-map). It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
Christopher Faulet81e20172019-12-12 16:40:30 +01001562 */
1563static enum act_parse_ret parse_http_set_map(const char **args, int *orig_arg, struct proxy *px,
1564 struct act_rule *rule, char **err)
1565{
1566 int cap, cur_arg;
1567
Christopher Faulet046cf442019-12-17 15:45:23 +01001568 if (args[*orig_arg-1][0] == 'a') // add-acl
1569 rule->action = 0;
1570 else if (args[*orig_arg-1][0] == 's') // set-map
1571 rule->action = 1;
1572 else if (args[*orig_arg-1][4] == 'a') // del-acl
1573 rule->action = 2;
1574 else if (args[*orig_arg-1][4] == 'm') // del-map
1575 rule->action = 3;
1576 else {
1577 memprintf(err, "internal error: unhandled action '%s'", args[0]);
1578 return ACT_RET_PRS_ERR;
1579 }
1580 rule->action_ptr = http_action_set_map;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001581 rule->release_ptr = release_http_map;
Christopher Faulet81e20172019-12-12 16:40:30 +01001582
1583 cur_arg = *orig_arg;
Christopher Faulet046cf442019-12-17 15:45:23 +01001584 if (rule->action == 1 && (!*args[cur_arg] || !*args[cur_arg+1])) {
1585 /* 2 args for set-map */
Christopher Faulet81e20172019-12-12 16:40:30 +01001586 memprintf(err, "expects exactly 2 arguments");
1587 return ACT_RET_PRS_ERR;
1588 }
1589 else if (!*args[cur_arg]) {
Christopher Faulet046cf442019-12-17 15:45:23 +01001590 /* only one arg for other actions */
Christopher Faulet81e20172019-12-12 16:40:30 +01001591 memprintf(err, "expects exactly 1 arguments");
1592 return ACT_RET_PRS_ERR;
1593 }
1594
1595 /*
1596 * '+ 8' for 'set-map(' (same for del-map)
1597 * '- 9' for 'set-map(' + trailing ')' (same for del-map)
1598 */
1599 rule->arg.map.ref = my_strndup(args[cur_arg-1] + 8, strlen(args[cur_arg-1]) - 9);
1600
1601 if (rule->from == ACT_F_HTTP_REQ) {
1602 px->conf.args.ctx = ARGC_HRQ;
1603 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
1604 }
1605 else{
1606 px->conf.args.ctx = ARGC_HRS;
1607 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
1608 }
1609
1610 /* key pattern */
1611 LIST_INIT(&rule->arg.map.key);
Christopher Faulet1337b322020-01-14 14:50:55 +01001612 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.key, LOG_OPT_HTTP, cap, err)) {
1613 free(rule->arg.map.ref);
Christopher Faulet81e20172019-12-12 16:40:30 +01001614 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001615 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001616
Christopher Faulet046cf442019-12-17 15:45:23 +01001617 if (rule->action == 1) {
Christopher Faulet81e20172019-12-12 16:40:30 +01001618 /* value pattern for set-map only */
1619 cur_arg++;
1620 LIST_INIT(&rule->arg.map.value);
Christopher Faulet1337b322020-01-14 14:50:55 +01001621 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.value, LOG_OPT_HTTP, cap, err)) {
1622 free(rule->arg.map.ref);
Christopher Faulet81e20172019-12-12 16:40:30 +01001623 return ACT_RET_PRS_ERR;
Christopher Faulet1337b322020-01-14 14:50:55 +01001624 }
Christopher Faulet81e20172019-12-12 16:40:30 +01001625 }
1626
1627 free(px->conf.lfs_file);
1628 px->conf.lfs_file = strdup(px->conf.args.file);
1629 px->conf.lfs_line = px->conf.args.line;
1630
1631 *orig_arg = cur_arg + 1;
1632 return ACT_RET_PRS_OK;
1633}
1634
Christopher Fauletac98d812019-12-18 09:20:16 +01001635/* This function executes a track-sc* actions. On success, it returns
1636 * ACT_RET_CONT. Otherwsize ACT_RET_ERR is returned.
1637 */
1638static enum act_return http_action_track_sc(struct act_rule *rule, struct proxy *px,
1639 struct session *sess, struct stream *s, int flags)
1640{
1641 struct stktable *t;
1642 struct stksess *ts;
1643 struct stktable_key *key;
1644 void *ptr1, *ptr2, *ptr3, *ptr4;
1645 int opt;
1646
1647 ptr1 = ptr2 = ptr3 = ptr4 = NULL;
1648 opt = ((rule->from == ACT_F_HTTP_REQ) ? SMP_OPT_DIR_REQ : SMP_OPT_DIR_RES) | SMP_OPT_FINAL;
1649
1650 t = rule->arg.trk_ctr.table.t;
1651 key = stktable_fetch_key(t, s->be, sess, s, opt, rule->arg.trk_ctr.expr, NULL);
1652
1653 if (!key)
1654 goto end;
1655 ts = stktable_get_entry(t, key);
1656 if (!ts)
1657 goto end;
1658
1659 stream_track_stkctr(&s->stkctr[rule->action], t, ts);
1660
1661 /* let's count a new HTTP request as it's the first time we do it */
1662 ptr1 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT);
1663 ptr2 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE);
1664
1665 /* When the client triggers a 4xx from the server, it's most often due
1666 * to a missing object or permission. These events should be tracked
1667 * because if they happen often, it may indicate a brute force or a
1668 * vulnerability scan. Normally this is done when receiving the response
1669 * but here we're tracking after this ought to have been done so we have
1670 * to do it on purpose.
1671 */
1672 if (rule->from == ACT_F_HTTP_RES && (unsigned)(s->txn->status - 400) < 100) {
1673 ptr3 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT);
1674 ptr4 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE);
1675 }
1676
1677 if (ptr1 || ptr2 || ptr3 || ptr4) {
1678 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
1679
1680 if (ptr1)
1681 stktable_data_cast(ptr1, http_req_cnt)++;
1682 if (ptr2)
1683 update_freq_ctr_period(&stktable_data_cast(ptr2, http_req_rate),
1684 t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
1685 if (ptr3)
1686 stktable_data_cast(ptr3, http_err_cnt)++;
1687 if (ptr4)
1688 update_freq_ctr_period(&stktable_data_cast(ptr4, http_err_rate),
1689 t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1);
1690
1691 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
1692
1693 /* If data was modified, we need to touch to re-schedule sync */
1694 stktable_touch_local(t, ts, 0);
1695 }
1696
1697 stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_CONTENT);
1698 if (sess->fe != s->be)
1699 stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_BACKEND);
1700
1701 end:
1702 return ACT_RET_CONT;
1703}
Christopher Faulet81e20172019-12-12 16:40:30 +01001704
Christopher Faulet2eb53962020-01-14 14:47:34 +01001705static void release_http_track_sc(struct act_rule *rule)
1706{
1707 release_sample_expr(rule->arg.trk_ctr.expr);
1708}
1709
Christopher Faulet81e20172019-12-12 16:40:30 +01001710/* Parse a "track-sc*" actions. It returns ACT_RET_PRS_OK on success,
1711 * ACT_RET_PRS_ERR on error.
1712 */
1713static enum act_parse_ret parse_http_track_sc(const char **args, int *orig_arg, struct proxy *px,
1714 struct act_rule *rule, char **err)
1715{
1716 struct sample_expr *expr;
1717 unsigned int where;
1718 unsigned int tsc_num;
1719 const char *tsc_num_str;
1720 int cur_arg;
1721
1722 tsc_num_str = &args[*orig_arg-1][8];
1723 if (cfg_parse_track_sc_num(&tsc_num, tsc_num_str, tsc_num_str + strlen(tsc_num_str), err) == -1)
1724 return ACT_RET_PRS_ERR;
1725
1726 cur_arg = *orig_arg;
1727 expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line,
1728 err, &px->conf.args);
1729 if (!expr)
1730 return ACT_RET_PRS_ERR;
1731
1732 where = 0;
1733 if (px->cap & PR_CAP_FE)
1734 where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_FE_HRS_HDR);
1735 if (px->cap & PR_CAP_BE)
1736 where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_BE_HRQ_HDR : SMP_VAL_BE_HRS_HDR);
1737
1738 if (!(expr->fetch->val & where)) {
1739 memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here",
1740 args[cur_arg-1], sample_src_names(expr->fetch->use));
Christopher Faulet1337b322020-01-14 14:50:55 +01001741 release_sample_expr(expr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001742 return ACT_RET_PRS_ERR;
1743 }
1744
1745 if (strcmp(args[cur_arg], "table") == 0) {
1746 cur_arg++;
1747 if (!*args[cur_arg]) {
1748 memprintf(err, "missing table name");
Christopher Faulet1337b322020-01-14 14:50:55 +01001749 release_sample_expr(expr);
Christopher Faulet81e20172019-12-12 16:40:30 +01001750 return ACT_RET_PRS_ERR;
1751 }
1752
1753 /* we copy the table name for now, it will be resolved later */
1754 rule->arg.trk_ctr.table.n = strdup(args[cur_arg]);
1755 cur_arg++;
1756 }
1757
Christopher Fauletac98d812019-12-18 09:20:16 +01001758 rule->action = tsc_num;
Christopher Faulet81e20172019-12-12 16:40:30 +01001759 rule->arg.trk_ctr.expr = expr;
Christopher Fauletac98d812019-12-18 09:20:16 +01001760 rule->action_ptr = http_action_track_sc;
Christopher Faulet2eb53962020-01-14 14:47:34 +01001761 rule->release_ptr = release_http_track_sc;
Christopher Faulet81e20172019-12-12 16:40:30 +01001762 rule->check_ptr = check_trk_action;
1763
1764 *orig_arg = cur_arg;
1765 return ACT_RET_PRS_OK;
1766}
1767
Christopher Faulet46f95542019-12-20 10:07:22 +01001768/* This function executes a strict-mode actions. On success, it always returns
1769 * ACT_RET_CONT
1770 */
1771static enum act_return http_action_strict_mode(struct act_rule *rule, struct proxy *px,
1772 struct session *sess, struct stream *s, int flags)
1773{
1774 struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp);
1775
1776 if (rule->action == 0) // strict-mode on
1777 msg->flags &= ~HTTP_MSGF_SOFT_RW;
1778 else // strict-mode off
1779 msg->flags |= HTTP_MSGF_SOFT_RW;
1780 return ACT_RET_CONT;
1781}
1782
1783/* Parse a "strict-mode" action. It returns ACT_RET_PRS_OK on success,
1784 * ACT_RET_PRS_ERR on error.
1785 */
1786static enum act_parse_ret parse_http_strict_mode(const char **args, int *orig_arg, struct proxy *px,
1787 struct act_rule *rule, char **err)
1788{
1789 int cur_arg;
1790
1791
1792 cur_arg = *orig_arg;
1793 if (!*args[cur_arg]) {
1794 memprintf(err, "expects exactly 1 arguments");
1795 return ACT_RET_PRS_ERR;
1796 }
1797
1798 if (strcasecmp(args[cur_arg], "on") == 0)
1799 rule->action = 0; // strict-mode on
1800 else if (strcasecmp(args[cur_arg], "off") == 0)
1801 rule->action = 1; // strict-mode off
1802 else {
1803 memprintf(err, "Unexpected value '%s'. Only 'on' and 'off' are supported", args[cur_arg]);
1804 return ACT_RET_PRS_ERR;
1805 }
1806 rule->action_ptr = http_action_strict_mode;
1807
1808 *orig_arg = cur_arg + 1;
1809 return ACT_RET_PRS_OK;
1810}
1811
Willy Tarreau79e57332018-10-02 16:01:16 +02001812/************************************************************************/
1813/* All supported http-request action keywords must be declared here. */
1814/************************************************************************/
1815
1816static struct action_kw_list http_req_actions = {
1817 .kw = {
Christopher Faulet81e20172019-12-12 16:40:30 +01001818 { "add-acl", parse_http_set_map, 1 },
1819 { "add-header", parse_http_set_header, 0 },
1820 { "allow", parse_http_allow, 0 },
1821 { "auth", parse_http_auth, 0 },
1822 { "capture", parse_http_req_capture, 0 },
1823 { "del-acl", parse_http_set_map, 1 },
1824 { "del-header", parse_http_del_header, 0 },
1825 { "del-map", parse_http_set_map, 1 },
Christopher Faulete0fca292020-01-13 21:49:03 +01001826 { "deny", parse_http_deny, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001827 { "disable-l7-retry", parse_http_req_disable_l7_retry, 0 },
1828 { "early-hint", parse_http_set_header, 0 },
1829 { "redirect", parse_http_redirect, 0 },
1830 { "reject", parse_http_action_reject, 0 },
1831 { "replace-header", parse_http_replace_header, 0 },
1832 { "replace-path", parse_replace_uri, 0 },
1833 { "replace-uri", parse_replace_uri, 0 },
1834 { "replace-value", parse_http_replace_header, 0 },
1835 { "set-header", parse_http_set_header, 0 },
1836 { "set-log-level", parse_http_set_log_level, 0 },
1837 { "set-map", parse_http_set_map, 1 },
1838 { "set-method", parse_set_req_line, 0 },
1839 { "set-mark", parse_http_set_mark, 0 },
1840 { "set-nice", parse_http_set_nice, 0 },
1841 { "set-path", parse_set_req_line, 0 },
1842 { "set-query", parse_set_req_line, 0 },
1843 { "set-tos", parse_http_set_tos, 0 },
1844 { "set-uri", parse_set_req_line, 0 },
Christopher Faulet46f95542019-12-20 10:07:22 +01001845 { "strict-mode", parse_http_strict_mode, 0 },
Christopher Faulete0fca292020-01-13 21:49:03 +01001846 { "tarpit", parse_http_deny, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001847 { "track-sc", parse_http_track_sc, 1 },
Willy Tarreau79e57332018-10-02 16:01:16 +02001848 { NULL, NULL }
1849 }
1850};
1851
Willy Tarreau0108d902018-11-25 19:14:37 +01001852INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_actions);
1853
Willy Tarreau79e57332018-10-02 16:01:16 +02001854static struct action_kw_list http_res_actions = {
1855 .kw = {
Christopher Faulet81e20172019-12-12 16:40:30 +01001856 { "add-acl", parse_http_set_map, 1 },
1857 { "add-header", parse_http_set_header, 0 },
1858 { "allow", parse_http_allow, 0 },
1859 { "capture", parse_http_res_capture, 0 },
1860 { "del-acl", parse_http_set_map, 1 },
1861 { "del-header", parse_http_del_header, 0 },
1862 { "del-map", parse_http_set_map, 1 },
Christopher Faulete0fca292020-01-13 21:49:03 +01001863 { "deny", parse_http_deny, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001864 { "redirect", parse_http_redirect, 0 },
1865 { "replace-header", parse_http_replace_header, 0 },
1866 { "replace-value", parse_http_replace_header, 0 },
1867 { "set-header", parse_http_set_header, 0 },
1868 { "set-log-level", parse_http_set_log_level, 0 },
1869 { "set-map", parse_http_set_map, 1 },
1870 { "set-mark", parse_http_set_mark, 0 },
1871 { "set-nice", parse_http_set_nice, 0 },
1872 { "set-status", parse_http_set_status, 0 },
1873 { "set-tos", parse_http_set_tos, 0 },
Christopher Faulet46f95542019-12-20 10:07:22 +01001874 { "strict-mode", parse_http_strict_mode, 0 },
Christopher Faulet81e20172019-12-12 16:40:30 +01001875 { "track-sc", parse_http_track_sc, 1 },
Willy Tarreau79e57332018-10-02 16:01:16 +02001876 { NULL, NULL }
1877 }
1878};
1879
Willy Tarreau0108d902018-11-25 19:14:37 +01001880INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_actions);
Willy Tarreau79e57332018-10-02 16:01:16 +02001881
1882/*
1883 * Local variables:
1884 * c-indent-level: 8
1885 * c-basic-offset: 8
1886 * End:
1887 */