blob: e86b6160d8962c32c76a8a382b028c06e4e86e32 [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>
Willy Tarreau0f9cd7b2019-01-31 19:02:43 +010040#include <proto/stream_interface.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020041
42
43/* This function executes one of the set-{method,path,query,uri} actions. It
44 * builds a string in the trash from the specified format string. It finds
45 * the action to be performed in <http.action>, previously filled by function
46 * parse_set_req_line(). The replacement action is excuted by the function
47 * http_action_set_req_line(). It always returns ACT_RET_CONT. If an error
48 * occurs the action is canceled, but the rule processing continue.
49 */
50static enum act_return http_action_set_req_line(struct act_rule *rule, struct proxy *px,
51 struct session *sess, struct stream *s, int flags)
52{
53 struct buffer *replace;
54 enum act_return ret = ACT_RET_ERR;
55
56 replace = alloc_trash_chunk();
57 if (!replace)
58 goto leave;
59
60 /* If we have to create a query string, prepare a '?'. */
61 if (rule->arg.http.action == 2)
62 replace->area[replace->data++] = '?';
63 replace->data += build_logline(s, replace->area + replace->data,
64 replace->size - replace->data,
65 &rule->arg.http.logfmt);
66
Christopher Fauletfc9cfe42019-07-16 14:54:53 +020067 http_req_replace_stline(rule->arg.http.action, replace->area,
68 replace->data, px, s);
Willy Tarreau79e57332018-10-02 16:01:16 +020069
70 ret = ACT_RET_CONT;
71
72leave:
73 free_trash_chunk(replace);
74 return ret;
75}
76
77/* parse an http-request action among :
78 * set-method
79 * set-path
80 * set-query
81 * set-uri
82 *
83 * All of them accept a single argument of type string representing a log-format.
84 * The resulting rule makes use of arg->act.p[0..1] to store the log-format list
85 * head, and p[2] to store the action as an int (0=method, 1=path, 2=query, 3=uri).
86 * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
87 */
88static enum act_parse_ret parse_set_req_line(const char **args, int *orig_arg, struct proxy *px,
89 struct act_rule *rule, char **err)
90{
91 int cur_arg = *orig_arg;
92
93 rule->action = ACT_CUSTOM;
94
95 switch (args[0][4]) {
96 case 'm' :
97 rule->arg.http.action = 0;
98 rule->action_ptr = http_action_set_req_line;
99 break;
100 case 'p' :
101 rule->arg.http.action = 1;
102 rule->action_ptr = http_action_set_req_line;
103 break;
104 case 'q' :
105 rule->arg.http.action = 2;
106 rule->action_ptr = http_action_set_req_line;
107 break;
108 case 'u' :
109 rule->arg.http.action = 3;
110 rule->action_ptr = http_action_set_req_line;
111 break;
112 default:
113 memprintf(err, "internal error: unhandled action '%s'", args[0]);
114 return ACT_RET_PRS_ERR;
115 }
116
117 if (!*args[cur_arg] ||
118 (*args[cur_arg + 1] && strcmp(args[cur_arg + 1], "if") != 0 && strcmp(args[cur_arg + 1], "unless") != 0)) {
119 memprintf(err, "expects exactly 1 argument <format>");
120 return ACT_RET_PRS_ERR;
121 }
122
123 LIST_INIT(&rule->arg.http.logfmt);
124 px->conf.args.ctx = ARGC_HRQ;
125 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.logfmt, LOG_OPT_HTTP,
126 (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, err)) {
127 return ACT_RET_PRS_ERR;
128 }
129
130 (*orig_arg)++;
131 return ACT_RET_PRS_OK;
132}
133
Willy Tarreau33810222019-06-12 17:44:02 +0200134/* This function executes a replace-uri action. It finds its arguments in
135 * <rule>.arg.act.p[]. It builds a string in the trash from the format string
136 * previously filled by function parse_replace_uri() and will execute the regex
137 * in p[1] to replace the URI. It uses the format string present in act.p[2..3].
Willy Tarreau262c3f12019-12-17 06:52:51 +0100138 * The component to act on (path/uri) is taken from act.p[0] which contains 1
139 * for the path or 3 for the URI (values used by http_req_replace_stline()).
Willy Tarreau33810222019-06-12 17:44:02 +0200140 * It always returns ACT_RET_CONT. If an error occurs, the action is canceled,
141 * but the rule processing continues.
142 */
143static enum act_return http_action_replace_uri(struct act_rule *rule, struct proxy *px,
144 struct session *sess, struct stream *s, int flags)
145{
146 enum act_return ret = ACT_RET_ERR;
147 struct buffer *replace, *output;
148 struct ist uri;
149 int len;
150
151 replace = alloc_trash_chunk();
152 output = alloc_trash_chunk();
153 if (!replace || !output)
154 goto leave;
Christopher Faulet12c28b62019-07-15 16:30:24 +0200155 uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf)));
Willy Tarreau262c3f12019-12-17 06:52:51 +0100156
157 if (rule->arg.act.p[0] == (void *)1)
158 uri = http_get_path(uri); // replace path
159
Willy Tarreau33810222019-06-12 17:44:02 +0200160 if (!regex_exec_match2(rule->arg.act.p[1], uri.ptr, uri.len, MAX_MATCH, pmatch, 0))
161 goto leave;
162
163 replace->data = build_logline(s, replace->area, replace->size, (struct list *)&rule->arg.act.p[2]);
164
165 /* note: uri.ptr doesn't need to be zero-terminated because it will
166 * only be used to pick pmatch references.
167 */
168 len = exp_replace(output->area, output->size, uri.ptr, replace->area, pmatch);
169 if (len == -1)
170 goto leave;
171
Willy Tarreau262c3f12019-12-17 06:52:51 +0100172 http_req_replace_stline((long)rule->arg.act.p[0], output->area, len, px, s);
Willy Tarreau33810222019-06-12 17:44:02 +0200173
174 ret = ACT_RET_CONT;
175
176leave:
177 free_trash_chunk(output);
178 free_trash_chunk(replace);
179 return ret;
180}
181
Willy Tarreau262c3f12019-12-17 06:52:51 +0100182/* parse a "replace-uri" or "replace-path" http-request action.
Willy Tarreau33810222019-06-12 17:44:02 +0200183 * This action takes 2 arguments (a regex and a replacement format string).
Willy Tarreau262c3f12019-12-17 06:52:51 +0100184 * The resulting rule makes use of arg->act.p[0] to store the action (1/3 for now),
Willy Tarreau33810222019-06-12 17:44:02 +0200185 * p[1] to store the compiled regex, and arg->act.p[2..3] to store the log-format
186 * list head. It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
187 */
188static enum act_parse_ret parse_replace_uri(const char **args, int *orig_arg, struct proxy *px,
189 struct act_rule *rule, char **err)
190{
191 int cur_arg = *orig_arg;
192 char *error = NULL;
193
194 rule->action = ACT_CUSTOM;
Willy Tarreau262c3f12019-12-17 06:52:51 +0100195 if (strcmp(args[cur_arg-1], "replace-path") == 0)
196 rule->arg.act.p[0] = (void *)1; // replace-path
197 else
198 rule->arg.act.p[0] = (void *)3; // replace-uri
199
Willy Tarreau33810222019-06-12 17:44:02 +0200200 rule->action_ptr = http_action_replace_uri;
201
202 if (!*args[cur_arg] || !*args[cur_arg+1] ||
203 (*args[cur_arg+2] && strcmp(args[cur_arg+2], "if") != 0 && strcmp(args[cur_arg+2], "unless") != 0)) {
204 memprintf(err, "expects exactly 2 arguments <match-regex> and <replace-format>");
205 return ACT_RET_PRS_ERR;
206 }
207
208 if (!(rule->arg.act.p[1] = regex_comp(args[cur_arg], 1, 1, &error))) {
209 memprintf(err, "failed to parse the regex : %s", error);
210 free(error);
211 return ACT_RET_PRS_ERR;
212 }
213
214 LIST_INIT((struct list *)&rule->arg.act.p[2]);
215 px->conf.args.ctx = ARGC_HRQ;
216 if (!parse_logformat_string(args[cur_arg + 1], px, (struct list *)&rule->arg.act.p[2], LOG_OPT_HTTP,
217 (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, err)) {
218 return ACT_RET_PRS_ERR;
219 }
220
221 (*orig_arg) += 2;
222 return ACT_RET_PRS_OK;
223}
224
Willy Tarreau79e57332018-10-02 16:01:16 +0200225/* This function is just a compliant action wrapper for "set-status". */
226static enum act_return action_http_set_status(struct act_rule *rule, struct proxy *px,
227 struct session *sess, struct stream *s, int flags)
228{
Christopher Fauletfc9cfe42019-07-16 14:54:53 +0200229 http_res_set_status(rule->arg.status.code, rule->arg.status.reason, s);
Willy Tarreau79e57332018-10-02 16:01:16 +0200230 return ACT_RET_CONT;
231}
232
233/* parse set-status action:
234 * This action accepts a single argument of type int representing
235 * an http status code. It returns ACT_RET_PRS_OK on success,
236 * ACT_RET_PRS_ERR on error.
237 */
238static enum act_parse_ret parse_http_set_status(const char **args, int *orig_arg, struct proxy *px,
239 struct act_rule *rule, char **err)
240{
241 char *error;
242
243 rule->action = ACT_CUSTOM;
244 rule->action_ptr = action_http_set_status;
245
246 /* Check if an argument is available */
247 if (!*args[*orig_arg]) {
248 memprintf(err, "expects 1 argument: <status>; or 3 arguments: <status> reason <fmt>");
249 return ACT_RET_PRS_ERR;
250 }
251
252 /* convert status code as integer */
253 rule->arg.status.code = strtol(args[*orig_arg], &error, 10);
254 if (*error != '\0' || rule->arg.status.code < 100 || rule->arg.status.code > 999) {
255 memprintf(err, "expects an integer status code between 100 and 999");
256 return ACT_RET_PRS_ERR;
257 }
258
259 (*orig_arg)++;
260
261 /* set custom reason string */
262 rule->arg.status.reason = NULL; // If null, we use the default reason for the status code.
263 if (*args[*orig_arg] && strcmp(args[*orig_arg], "reason") == 0 &&
264 (*args[*orig_arg + 1] && strcmp(args[*orig_arg + 1], "if") != 0 && strcmp(args[*orig_arg + 1], "unless") != 0)) {
265 (*orig_arg)++;
266 rule->arg.status.reason = strdup(args[*orig_arg]);
267 (*orig_arg)++;
268 }
269
270 return ACT_RET_PRS_OK;
271}
272
273/* This function executes the "reject" HTTP action. It clears the request and
274 * response buffer without sending any response. It can be useful as an HTTP
275 * alternative to the silent-drop action to defend against DoS attacks, and may
276 * also be used with HTTP/2 to close a connection instead of just a stream.
277 * The txn status is unchanged, indicating no response was sent. The termination
Christopher Faulet8f1aa772019-07-04 11:27:15 +0200278 * flags will indicate "PR". It always returns ACT_RET_DONE.
Willy Tarreau79e57332018-10-02 16:01:16 +0200279 */
280static enum act_return http_action_reject(struct act_rule *rule, struct proxy *px,
281 struct session *sess, struct stream *s, int flags)
282{
Willy Tarreau0f9cd7b2019-01-31 19:02:43 +0100283 si_must_kill_conn(chn_prod(&s->req));
Willy Tarreau79e57332018-10-02 16:01:16 +0200284 channel_abort(&s->req);
285 channel_abort(&s->res);
286 s->req.analysers = 0;
287 s->res.analysers = 0;
288
Olivier Houcharda798bf52019-03-08 18:52:00 +0100289 _HA_ATOMIC_ADD(&s->be->be_counters.denied_req, 1);
290 _HA_ATOMIC_ADD(&sess->fe->fe_counters.denied_req, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200291 if (sess->listener && sess->listener->counters)
Olivier Houcharda798bf52019-03-08 18:52:00 +0100292 _HA_ATOMIC_ADD(&sess->listener->counters->denied_req, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200293
294 if (!(s->flags & SF_ERR_MASK))
295 s->flags |= SF_ERR_PRXCOND;
296 if (!(s->flags & SF_FINST_MASK))
297 s->flags |= SF_FINST_R;
298
Christopher Faulet8f1aa772019-07-04 11:27:15 +0200299 return ACT_RET_DONE;
Willy Tarreau79e57332018-10-02 16:01:16 +0200300}
301
302/* parse the "reject" action:
303 * This action takes no argument and returns ACT_RET_PRS_OK on success,
304 * ACT_RET_PRS_ERR on error.
305 */
306static enum act_parse_ret parse_http_action_reject(const char **args, int *orig_arg, struct proxy *px,
307 struct act_rule *rule, char **err)
308{
309 rule->action = ACT_CUSTOM;
310 rule->action_ptr = http_action_reject;
311 return ACT_RET_PRS_OK;
312}
313
Olivier Houchard602bf7d2019-05-10 13:59:15 +0200314/* This function executes the "disable-l7-retry" HTTP action.
315 * It disables L7 retries (all retry except for a connection failure). This
316 * can be useful for example to avoid retrying on POST requests.
317 * It just removes the L7 retry flag on the stream_interface, and always
318 * return ACT_RET_CONT;
319 */
320static enum act_return http_req_disable_l7_retry(struct act_rule *rule, struct proxy *px,
321 struct session *sess, struct stream *s, int flags)
322{
323 struct stream_interface *si = &s->si[1];
324
325 /* In theory, the SI_FL_L7_RETRY flags isn't set at this point, but
326 * let's be future-proof and remove it anyway.
327 */
328 si->flags &= ~SI_FL_L7_RETRY;
329 si->flags |= SI_FL_D_L7_RETRY;
330 return ACT_RET_CONT;
331}
332
333/* parse the "disable-l7-retry" action:
334 * This action takes no argument and returns ACT_RET_PRS_OK on success,
335 * ACT_RET_PRS_ERR on error.
336 */
337static enum act_parse_ret parse_http_req_disable_l7_retry(const char **args,
338 int *orig_args, struct proxy *px,
339 struct act_rule *rule, char **err)
340{
341 rule->action = ACT_CUSTOM;
342 rule->action_ptr = http_req_disable_l7_retry;
343 return ACT_RET_PRS_OK;
344}
345
Willy Tarreau79e57332018-10-02 16:01:16 +0200346/* This function executes the "capture" action. It executes a fetch expression,
347 * turns the result into a string and puts it in a capture slot. It always
348 * returns 1. If an error occurs the action is cancelled, but the rule
349 * processing continues.
350 */
351static enum act_return http_action_req_capture(struct act_rule *rule, struct proxy *px,
352 struct session *sess, struct stream *s, int flags)
353{
354 struct sample *key;
355 struct cap_hdr *h = rule->arg.cap.hdr;
356 char **cap = s->req_cap;
357 int len;
358
359 key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.cap.expr, SMP_T_STR);
360 if (!key)
361 return ACT_RET_CONT;
362
363 if (cap[h->index] == NULL)
364 cap[h->index] = pool_alloc(h->pool);
365
366 if (cap[h->index] == NULL) /* no more capture memory */
367 return ACT_RET_CONT;
368
369 len = key->data.u.str.data;
370 if (len > h->len)
371 len = h->len;
372
373 memcpy(cap[h->index], key->data.u.str.area, len);
374 cap[h->index][len] = 0;
375 return ACT_RET_CONT;
376}
377
378/* This function executes the "capture" action and store the result in a
379 * capture slot if exists. It executes a fetch expression, turns the result
380 * into a string and puts it in a capture slot. It always returns 1. If an
381 * error occurs the action is cancelled, but the rule processing continues.
382 */
383static enum act_return http_action_req_capture_by_id(struct act_rule *rule, struct proxy *px,
384 struct session *sess, struct stream *s, int flags)
385{
386 struct sample *key;
387 struct cap_hdr *h;
388 char **cap = s->req_cap;
389 struct proxy *fe = strm_fe(s);
390 int len;
391 int i;
392
393 /* Look for the original configuration. */
394 for (h = fe->req_cap, i = fe->nb_req_cap - 1;
395 h != NULL && i != rule->arg.capid.idx ;
396 i--, h = h->next);
397 if (!h)
398 return ACT_RET_CONT;
399
400 key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR);
401 if (!key)
402 return ACT_RET_CONT;
403
404 if (cap[h->index] == NULL)
405 cap[h->index] = pool_alloc(h->pool);
406
407 if (cap[h->index] == NULL) /* no more capture memory */
408 return ACT_RET_CONT;
409
410 len = key->data.u.str.data;
411 if (len > h->len)
412 len = h->len;
413
414 memcpy(cap[h->index], key->data.u.str.area, len);
415 cap[h->index][len] = 0;
416 return ACT_RET_CONT;
417}
418
419/* Check an "http-request capture" action.
420 *
421 * The function returns 1 in success case, otherwise, it returns 0 and err is
422 * filled.
423 */
424static int check_http_req_capture(struct act_rule *rule, struct proxy *px, char **err)
425{
426 if (rule->action_ptr != http_action_req_capture_by_id)
427 return 1;
428
429 if (rule->arg.capid.idx >= px->nb_req_cap) {
430 memprintf(err, "unable to find capture id '%d' referenced by http-request capture rule",
431 rule->arg.capid.idx);
432 return 0;
433 }
434
435 return 1;
436}
437
438/* parse an "http-request capture" action. It takes a single argument which is
439 * a sample fetch expression. It stores the expression into arg->act.p[0] and
440 * the allocated hdr_cap struct or the preallocated "id" into arg->act.p[1].
441 * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
442 */
443static enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, struct proxy *px,
444 struct act_rule *rule, char **err)
445{
446 struct sample_expr *expr;
447 struct cap_hdr *hdr;
448 int cur_arg;
449 int len = 0;
450
451 for (cur_arg = *orig_arg; cur_arg < *orig_arg + 3 && *args[cur_arg]; cur_arg++)
452 if (strcmp(args[cur_arg], "if") == 0 ||
453 strcmp(args[cur_arg], "unless") == 0)
454 break;
455
456 if (cur_arg < *orig_arg + 3) {
457 memprintf(err, "expects <expression> [ 'len' <length> | id <idx> ]");
458 return ACT_RET_PRS_ERR;
459 }
460
461 cur_arg = *orig_arg;
462 expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line, err, &px->conf.args);
463 if (!expr)
464 return ACT_RET_PRS_ERR;
465
466 if (!(expr->fetch->val & SMP_VAL_FE_HRQ_HDR)) {
467 memprintf(err,
468 "fetch method '%s' extracts information from '%s', none of which is available here",
469 args[cur_arg-1], sample_src_names(expr->fetch->use));
470 free(expr);
471 return ACT_RET_PRS_ERR;
472 }
473
474 if (!args[cur_arg] || !*args[cur_arg]) {
475 memprintf(err, "expects 'len or 'id'");
476 free(expr);
477 return ACT_RET_PRS_ERR;
478 }
479
480 if (strcmp(args[cur_arg], "len") == 0) {
481 cur_arg++;
482
483 if (!(px->cap & PR_CAP_FE)) {
484 memprintf(err, "proxy '%s' has no frontend capability", px->id);
485 return ACT_RET_PRS_ERR;
486 }
487
488 px->conf.args.ctx = ARGC_CAP;
489
490 if (!args[cur_arg]) {
491 memprintf(err, "missing length value");
492 free(expr);
493 return ACT_RET_PRS_ERR;
494 }
495 /* we copy the table name for now, it will be resolved later */
496 len = atoi(args[cur_arg]);
497 if (len <= 0) {
498 memprintf(err, "length must be > 0");
499 free(expr);
500 return ACT_RET_PRS_ERR;
501 }
502 cur_arg++;
503
Willy Tarreau79e57332018-10-02 16:01:16 +0200504 hdr = calloc(1, sizeof(*hdr));
505 hdr->next = px->req_cap;
506 hdr->name = NULL; /* not a header capture */
507 hdr->namelen = 0;
508 hdr->len = len;
509 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
510 hdr->index = px->nb_req_cap++;
511
512 px->req_cap = hdr;
513 px->to_log |= LW_REQHDR;
514
515 rule->action = ACT_CUSTOM;
516 rule->action_ptr = http_action_req_capture;
517 rule->arg.cap.expr = expr;
518 rule->arg.cap.hdr = hdr;
519 }
520
521 else if (strcmp(args[cur_arg], "id") == 0) {
522 int id;
523 char *error;
524
525 cur_arg++;
526
527 if (!args[cur_arg]) {
528 memprintf(err, "missing id value");
529 free(expr);
530 return ACT_RET_PRS_ERR;
531 }
532
533 id = strtol(args[cur_arg], &error, 10);
534 if (*error != '\0') {
535 memprintf(err, "cannot parse id '%s'", args[cur_arg]);
536 free(expr);
537 return ACT_RET_PRS_ERR;
538 }
539 cur_arg++;
540
541 px->conf.args.ctx = ARGC_CAP;
542
543 rule->action = ACT_CUSTOM;
544 rule->action_ptr = http_action_req_capture_by_id;
545 rule->check_ptr = check_http_req_capture;
546 rule->arg.capid.expr = expr;
547 rule->arg.capid.idx = id;
548 }
549
550 else {
551 memprintf(err, "expects 'len' or 'id', found '%s'", args[cur_arg]);
552 free(expr);
553 return ACT_RET_PRS_ERR;
554 }
555
556 *orig_arg = cur_arg;
557 return ACT_RET_PRS_OK;
558}
559
560/* This function executes the "capture" action and store the result in a
561 * capture slot if exists. It executes a fetch expression, turns the result
562 * into a string and puts it in a capture slot. It always returns 1. If an
563 * error occurs the action is cancelled, but the rule processing continues.
564 */
565static enum act_return http_action_res_capture_by_id(struct act_rule *rule, struct proxy *px,
566 struct session *sess, struct stream *s, int flags)
567{
568 struct sample *key;
569 struct cap_hdr *h;
570 char **cap = s->res_cap;
571 struct proxy *fe = strm_fe(s);
572 int len;
573 int i;
574
575 /* Look for the original configuration. */
576 for (h = fe->rsp_cap, i = fe->nb_rsp_cap - 1;
577 h != NULL && i != rule->arg.capid.idx ;
578 i--, h = h->next);
579 if (!h)
580 return ACT_RET_CONT;
581
582 key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR);
583 if (!key)
584 return ACT_RET_CONT;
585
586 if (cap[h->index] == NULL)
587 cap[h->index] = pool_alloc(h->pool);
588
589 if (cap[h->index] == NULL) /* no more capture memory */
590 return ACT_RET_CONT;
591
592 len = key->data.u.str.data;
593 if (len > h->len)
594 len = h->len;
595
596 memcpy(cap[h->index], key->data.u.str.area, len);
597 cap[h->index][len] = 0;
598 return ACT_RET_CONT;
599}
600
601/* Check an "http-response capture" action.
602 *
603 * The function returns 1 in success case, otherwise, it returns 0 and err is
604 * filled.
605 */
606static int check_http_res_capture(struct act_rule *rule, struct proxy *px, char **err)
607{
608 if (rule->action_ptr != http_action_res_capture_by_id)
609 return 1;
610
611 if (rule->arg.capid.idx >= px->nb_rsp_cap) {
612 memprintf(err, "unable to find capture id '%d' referenced by http-response capture rule",
613 rule->arg.capid.idx);
614 return 0;
615 }
616
617 return 1;
618}
619
620/* parse an "http-response capture" action. It takes a single argument which is
621 * a sample fetch expression. It stores the expression into arg->act.p[0] and
622 * the allocated hdr_cap struct od the preallocated id into arg->act.p[1].
623 * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
624 */
625static enum act_parse_ret parse_http_res_capture(const char **args, int *orig_arg, struct proxy *px,
626 struct act_rule *rule, char **err)
627{
628 struct sample_expr *expr;
629 int cur_arg;
630 int id;
631 char *error;
632
633 for (cur_arg = *orig_arg; cur_arg < *orig_arg + 3 && *args[cur_arg]; cur_arg++)
634 if (strcmp(args[cur_arg], "if") == 0 ||
635 strcmp(args[cur_arg], "unless") == 0)
636 break;
637
638 if (cur_arg < *orig_arg + 3) {
639 memprintf(err, "expects <expression> id <idx>");
640 return ACT_RET_PRS_ERR;
641 }
642
643 cur_arg = *orig_arg;
644 expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line, err, &px->conf.args);
645 if (!expr)
646 return ACT_RET_PRS_ERR;
647
648 if (!(expr->fetch->val & SMP_VAL_FE_HRS_HDR)) {
649 memprintf(err,
650 "fetch method '%s' extracts information from '%s', none of which is available here",
651 args[cur_arg-1], sample_src_names(expr->fetch->use));
652 free(expr);
653 return ACT_RET_PRS_ERR;
654 }
655
656 if (!args[cur_arg] || !*args[cur_arg]) {
657 memprintf(err, "expects 'id'");
658 free(expr);
659 return ACT_RET_PRS_ERR;
660 }
661
662 if (strcmp(args[cur_arg], "id") != 0) {
663 memprintf(err, "expects 'id', found '%s'", args[cur_arg]);
664 free(expr);
665 return ACT_RET_PRS_ERR;
666 }
667
668 cur_arg++;
669
670 if (!args[cur_arg]) {
671 memprintf(err, "missing id value");
672 free(expr);
673 return ACT_RET_PRS_ERR;
674 }
675
676 id = strtol(args[cur_arg], &error, 10);
677 if (*error != '\0') {
678 memprintf(err, "cannot parse id '%s'", args[cur_arg]);
679 free(expr);
680 return ACT_RET_PRS_ERR;
681 }
682 cur_arg++;
683
684 px->conf.args.ctx = ARGC_CAP;
685
686 rule->action = ACT_CUSTOM;
687 rule->action_ptr = http_action_res_capture_by_id;
688 rule->check_ptr = check_http_res_capture;
689 rule->arg.capid.expr = expr;
690 rule->arg.capid.idx = id;
691
692 *orig_arg = cur_arg;
693 return ACT_RET_PRS_OK;
694}
695
Christopher Faulet81e20172019-12-12 16:40:30 +0100696/* Parse a "allow" action for a request or a response rule. It takes no argument. It
697 * returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
698 */
699static enum act_parse_ret parse_http_allow(const char **args, int *orig_arg, struct proxy *px,
700 struct act_rule *rule, char **err)
701{
702 rule->action = ACT_ACTION_ALLOW;
703 return ACT_RET_PRS_OK;
704}
705
706/* Parse "deny" or "tarpit" actions for a request rule. It may take 2 optional arguments
707 * to define the status code. It returns ACT_RET_PRS_OK on success,
708 * ACT_RET_PRS_ERR on error.
709 */
710static enum act_parse_ret parse_http_req_deny(const char **args, int *orig_arg, struct proxy *px,
711 struct act_rule *rule, char **err)
712{
713 int code, hc, cur_arg;
714
715 cur_arg = *orig_arg;
716 if (!strcmp(args[cur_arg-1], "tarpit")) {
717 rule->action = ACT_HTTP_REQ_TARPIT;
718 rule->deny_status = HTTP_ERR_500;
719 }
720 else {
721 rule->action = ACT_ACTION_DENY;
722 rule->deny_status = HTTP_ERR_403;
723 }
724
725 if (strcmp(args[cur_arg], "deny_status") == 0) {
726 cur_arg++;
727 if (!*args[cur_arg]) {
728 memprintf(err, "missing status code.\n");
729 return ACT_RET_PRS_ERR;
730 }
731
732 code = atol(args[cur_arg]);
733 cur_arg++;
734 for (hc = 0; hc < HTTP_ERR_SIZE; hc++) {
735 if (http_err_codes[hc] == code) {
736 rule->deny_status = hc;
737 break;
738 }
739 }
740 if (hc >= HTTP_ERR_SIZE)
741 memprintf(err, "status code %d not handled, using default code %d",
742 code, http_err_codes[rule->deny_status]);
743 }
744
745 *orig_arg = cur_arg;
746 return ACT_RET_PRS_OK;
747}
748
749/* Parse a "deny" action for a response rule. It takes no argument. It returns
750 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
751 */
752static enum act_parse_ret parse_http_res_deny(const char **args, int *orig_arg, struct proxy *px,
753 struct act_rule *rule, char **err)
754{
755 rule->action = ACT_ACTION_DENY;
756 return ACT_RET_PRS_OK;
757}
758
759/* Parse a "auth" action. It may take 2 optional arguments to define a "realm"
760 * parameter. It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
761 */
762static enum act_parse_ret parse_http_auth(const char **args, int *orig_arg, struct proxy *px,
763 struct act_rule *rule, char **err)
764{
765 int cur_arg;
766
767 rule->action = ACT_HTTP_REQ_AUTH;
768
769 cur_arg = *orig_arg;
770 if (!strcmp(args[cur_arg], "realm")) {
771 cur_arg++;
772 if (!*args[cur_arg]) {
773 memprintf(err, "missing realm value.\n");
774 return ACT_RET_PRS_ERR;
775 }
776 rule->arg.auth.realm = strdup(args[cur_arg]);
777 cur_arg++;
778 }
779
780 *orig_arg = cur_arg;
781 return ACT_RET_PRS_OK;
782}
783
784/* Parse a "set-nice" action. It takes the nice value as argument. It returns
785 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
786 */
787static enum act_parse_ret parse_http_set_nice(const char **args, int *orig_arg, struct proxy *px,
788 struct act_rule *rule, char **err)
789{
790 int cur_arg;
791
792 rule->action = ACT_HTTP_SET_NICE;
793
794 cur_arg = *orig_arg;
795 if (!*args[cur_arg]) {
796 memprintf(err, "expects exactly 1 argument (integer value)");
797 return ACT_RET_PRS_ERR;
798 }
799 rule->arg.nice = atoi(args[cur_arg]);
800 if (rule->arg.nice < -1024)
801 rule->arg.nice = -1024;
802 else if (rule->arg.nice > 1024)
803 rule->arg.nice = 1024;
804
805 *orig_arg = cur_arg + 1;
806 return ACT_RET_PRS_OK;
807}
808
809/* Parse a "set-tos" action. It takes the TOS value as argument. It returns
810 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
811 */
812static enum act_parse_ret parse_http_set_tos(const char **args, int *orig_arg, struct proxy *px,
813 struct act_rule *rule, char **err)
814{
815#ifdef IP_TOS
816 char *endp;
817 int cur_arg;
818
819 rule->action = ACT_HTTP_SET_TOS;
820
821 cur_arg = *orig_arg;
822 if (!*args[cur_arg]) {
823 memprintf(err, "expects exactly 1 argument (integer/hex value)");
824 return ACT_RET_PRS_ERR;
825 }
826 rule->arg.tos = strtol(args[cur_arg], &endp, 0);
827 if (endp && *endp != '\0') {
828 memprintf(err, "invalid character starting at '%s' (integer/hex value expected)", endp);
829 return ACT_RET_PRS_ERR;
830 }
831
832 *orig_arg = cur_arg + 1;
833 return ACT_RET_PRS_OK;
834#else
835 memprintf(err, "not supported on this platform (IP_TOS undefined)");
836 return ACT_RET_PRS_ERR;
837#endif
838}
839
840/* Parse a "set-mark" action. It takes the MARK value as argument. It returns
841 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
842 */
843static enum act_parse_ret parse_http_set_mark(const char **args, int *orig_arg, struct proxy *px,
844 struct act_rule *rule, char **err)
845{
846#ifdef SO_MARK
847 char *endp;
848 int cur_arg;
849
850 rule->action = ACT_HTTP_SET_MARK;
851
852 cur_arg = *orig_arg;
853 if (!*args[cur_arg]) {
854 memprintf(err, "expects exactly 1 argument (integer/hex value)");
855 return ACT_RET_PRS_ERR;
856 }
857 rule->arg.mark = strtoul(args[cur_arg], &endp, 0);
858 if (endp && *endp != '\0') {
859 memprintf(err, "invalid character starting at '%s' (integer/hex value expected)", endp);
860 return ACT_RET_PRS_ERR;
861 }
862
863 *orig_arg = cur_arg + 1;
864 global.last_checks |= LSTCHK_NETADM;
865 return ACT_RET_PRS_OK;
866#else
867 memprintf(err, "not supported on this platform (SO_MARK undefined)");
868 return ACT_RET_PRS_ERR;
869#endif
870}
871
872/* Parse a "set-log-level" action. It takes the level value as argument. It
873 * returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
874 */
875static enum act_parse_ret parse_http_set_log_level(const char **args, int *orig_arg, struct proxy *px,
876 struct act_rule *rule, char **err)
877{
878 int cur_arg;
879
880 rule->action = ACT_HTTP_SET_LOGL;
881
882 cur_arg = *orig_arg;
883 if (!*args[cur_arg]) {
884 bad_log_level:
885 memprintf(err, "expects exactly 1 argument (log level name or 'silent')");
886 return ACT_RET_PRS_ERR;
887 }
888 if (strcmp(args[cur_arg], "silent") == 0)
889 rule->arg.loglevel = -1;
890 else if ((rule->arg.loglevel = get_log_level(args[cur_arg]) + 1) == 0)
891 goto bad_log_level;
892
893 *orig_arg = cur_arg + 1;
894 return ACT_RET_PRS_OK;
895}
896
897/* Parse a "set-header", "add-header" or "early-hint" actions. It takes an
898 * header name and a log-format string as arguments. It returns ACT_RET_PRS_OK
899 * on success, ACT_RET_PRS_ERR on error.
900 *
901 * Note: same function is used for the request and the response. However
902 * "early-hint" rules are only supported for request rules.
903 */
904static enum act_parse_ret parse_http_set_header(const char **args, int *orig_arg, struct proxy *px,
905 struct act_rule *rule, char **err)
906{
907 char **hdr_name;
908 int *hdr_name_len;
909 struct list *fmt;
910 int cap, cur_arg;
911
912 rule->action = (*args[*orig_arg-1] == 'a' ? ACT_HTTP_ADD_HDR :
913 *args[*orig_arg-1] == 's' ? ACT_HTTP_SET_HDR : ACT_HTTP_EARLY_HINT);
914
915 cur_arg = *orig_arg;
916 if (!*args[cur_arg] || !*args[cur_arg+1]) {
917 memprintf(err, "expects exactly 2 arguments");
918 return ACT_RET_PRS_ERR;
919 }
920
921 hdr_name = (*args[cur_arg-1] == 'e' ? &rule->arg.early_hint.name : &rule->arg.hdr_add.name);
922 hdr_name_len = (*args[cur_arg-1] == 'e' ? &rule->arg.early_hint.name_len : &rule->arg.hdr_add.name_len);
923 fmt = (*args[cur_arg-1] == 'e' ? &rule->arg.early_hint.fmt : &rule->arg.hdr_add.fmt);
924
925 *hdr_name = strdup(args[cur_arg]);
926 *hdr_name_len = strlen(*hdr_name);
927 LIST_INIT(fmt);
928
929 if (rule->from == ACT_F_HTTP_REQ) {
930 px->conf.args.ctx = ARGC_HRQ;
931 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
932 }
933 else{
934 px->conf.args.ctx = ARGC_HRS;
935 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
936 }
937
938 cur_arg++;
939 if (!parse_logformat_string(args[cur_arg], px, fmt, LOG_OPT_HTTP, cap, err))
940 return ACT_RET_PRS_ERR;
941
942 free(px->conf.lfs_file);
943 px->conf.lfs_file = strdup(px->conf.args.file);
944 px->conf.lfs_line = px->conf.args.line;
945
946 *orig_arg = cur_arg + 1;
947 return ACT_RET_PRS_OK;
948}
949
950/* Parse a "replace-header" or "replace-value" actions. It takes an header name,
951 * a regex and replacement string as arguments. It returns ACT_RET_PRS_OK on
952 * success, ACT_RET_PRS_ERR on error.
953 */
954static enum act_parse_ret parse_http_replace_header(const char **args, int *orig_arg, struct proxy *px,
955 struct act_rule *rule, char **err)
956{
957 int cap, cur_arg;
958
959 rule->action = args[*orig_arg-1][8] == 'h' ? ACT_HTTP_REPLACE_HDR : ACT_HTTP_REPLACE_VAL;
960
961 cur_arg = *orig_arg;
962 if (!*args[cur_arg] || !*args[cur_arg+1] || !*args[cur_arg+2]) {
963 memprintf(err, "expects exactly 3 arguments");
964 return ACT_RET_PRS_ERR;
965 }
966
967 rule->arg.hdr_add.name = strdup(args[cur_arg]);
968 rule->arg.hdr_add.name_len = strlen(rule->arg.hdr_add.name);
969 LIST_INIT(&rule->arg.hdr_add.fmt);
970
971 cur_arg++;
972 if (!(rule->arg.hdr_add.re = regex_comp(args[cur_arg], 1, 1, err)))
973 return ACT_RET_PRS_ERR;
974
975 if (rule->from == ACT_F_HTTP_REQ) {
976 px->conf.args.ctx = ARGC_HRQ;
977 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
978 }
979 else{
980 px->conf.args.ctx = ARGC_HRS;
981 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
982 }
983
984 cur_arg++;
985 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP, cap, err))
986 return ACT_RET_PRS_ERR;
987
988 free(px->conf.lfs_file);
989 px->conf.lfs_file = strdup(px->conf.args.file);
990 px->conf.lfs_line = px->conf.args.line;
991
992 *orig_arg = cur_arg + 1;
993 return ACT_RET_PRS_OK;
994}
995
996/* Parse a "del-header" action. It takes an header name as argument. It returns
997 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
998 */
999static enum act_parse_ret parse_http_del_header(const char **args, int *orig_arg, struct proxy *px,
1000 struct act_rule *rule, char **err)
1001{
1002 int cur_arg;
1003
1004 rule->action = ACT_HTTP_DEL_HDR;
1005
1006 cur_arg = *orig_arg;
1007 if (!*args[cur_arg]) {
1008 memprintf(err, "expects exactly 1 arguments");
1009 return ACT_RET_PRS_ERR;
1010 }
1011
1012 rule->arg.hdr_add.name = strdup(args[cur_arg]);
1013 rule->arg.hdr_add.name_len = strlen(rule->arg.hdr_add.name);
1014
1015 px->conf.args.ctx = (rule->from == ACT_F_HTTP_REQ ? ARGC_HRQ : ARGC_HRS);
1016
1017 *orig_arg = cur_arg + 1;
1018 return ACT_RET_PRS_OK;
1019}
1020
1021/* Parse a "redirect" action. It returns ACT_RET_PRS_OK on success,
1022 * ACT_RET_PRS_ERR on error.
1023 */
1024static enum act_parse_ret parse_http_redirect(const char **args, int *orig_arg, struct proxy *px,
1025 struct act_rule *rule, char **err)
1026{
1027 struct redirect_rule *redir;
1028 int dir, cur_arg;
1029
1030 rule->action = ACT_HTTP_REDIR;
1031
1032 cur_arg = *orig_arg;
1033
1034 dir = (rule->from == ACT_F_HTTP_REQ ? 0 : 1);
1035 if ((redir = http_parse_redirect_rule(px->conf.args.file, px->conf.args.line, px, &args[cur_arg], err, 1, dir)) == NULL)
1036 return ACT_RET_PRS_ERR;
1037
1038 rule->arg.redir = redir;
1039 rule->cond = redir->cond;
1040 redir->cond = NULL;
1041
1042 /* skip all arguments */
1043 while (*args[cur_arg])
1044 cur_arg++;
1045
1046 *orig_arg = cur_arg;
1047 return ACT_RET_PRS_OK;
1048}
1049
1050/* Parse a "add-acl", "del-acl", "set-map" or "del-map" actions. It takes one or
1051 * two log-format string as argument depending on the action. It returns
1052 * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error.
1053 */
1054static enum act_parse_ret parse_http_set_map(const char **args, int *orig_arg, struct proxy *px,
1055 struct act_rule *rule, char **err)
1056{
1057 int cap, cur_arg;
1058
1059 rule->action = (args[*orig_arg-1][0] == 'a' ? ACT_HTTP_ADD_ACL :
1060 (args[*orig_arg-1][0] == 's' ? ACT_HTTP_SET_MAP :
1061 (args[*orig_arg-1][4] == 'a' ? ACT_HTTP_DEL_ACL : ACT_HTTP_DEL_MAP)));
1062
1063 cur_arg = *orig_arg;
1064 if (rule->action == ACT_HTTP_SET_MAP && (!*args[cur_arg] || !*args[cur_arg+1])) {
1065 memprintf(err, "expects exactly 2 arguments");
1066 return ACT_RET_PRS_ERR;
1067 }
1068 else if (!*args[cur_arg]) {
1069 memprintf(err, "expects exactly 1 arguments");
1070 return ACT_RET_PRS_ERR;
1071 }
1072
1073 /*
1074 * '+ 8' for 'set-map(' (same for del-map)
1075 * '- 9' for 'set-map(' + trailing ')' (same for del-map)
1076 */
1077 rule->arg.map.ref = my_strndup(args[cur_arg-1] + 8, strlen(args[cur_arg-1]) - 9);
1078
1079 if (rule->from == ACT_F_HTTP_REQ) {
1080 px->conf.args.ctx = ARGC_HRQ;
1081 cap = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
1082 }
1083 else{
1084 px->conf.args.ctx = ARGC_HRS;
1085 cap = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
1086 }
1087
1088 /* key pattern */
1089 LIST_INIT(&rule->arg.map.key);
1090 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.key, LOG_OPT_HTTP, cap, err))
1091 return ACT_RET_PRS_ERR;
1092
1093 if (rule->action == ACT_HTTP_SET_MAP) {
1094 /* value pattern for set-map only */
1095 cur_arg++;
1096 LIST_INIT(&rule->arg.map.value);
1097 if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.value, LOG_OPT_HTTP, cap, err))
1098 return ACT_RET_PRS_ERR;
1099 }
1100
1101 free(px->conf.lfs_file);
1102 px->conf.lfs_file = strdup(px->conf.args.file);
1103 px->conf.lfs_line = px->conf.args.line;
1104
1105 *orig_arg = cur_arg + 1;
1106 return ACT_RET_PRS_OK;
1107}
1108
1109
1110/* Parse a "track-sc*" actions. It returns ACT_RET_PRS_OK on success,
1111 * ACT_RET_PRS_ERR on error.
1112 */
1113static enum act_parse_ret parse_http_track_sc(const char **args, int *orig_arg, struct proxy *px,
1114 struct act_rule *rule, char **err)
1115{
1116 struct sample_expr *expr;
1117 unsigned int where;
1118 unsigned int tsc_num;
1119 const char *tsc_num_str;
1120 int cur_arg;
1121
1122 tsc_num_str = &args[*orig_arg-1][8];
1123 if (cfg_parse_track_sc_num(&tsc_num, tsc_num_str, tsc_num_str + strlen(tsc_num_str), err) == -1)
1124 return ACT_RET_PRS_ERR;
1125
1126 cur_arg = *orig_arg;
1127 expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line,
1128 err, &px->conf.args);
1129 if (!expr)
1130 return ACT_RET_PRS_ERR;
1131
1132 where = 0;
1133 if (px->cap & PR_CAP_FE)
1134 where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_FE_HRS_HDR);
1135 if (px->cap & PR_CAP_BE)
1136 where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_BE_HRQ_HDR : SMP_VAL_BE_HRS_HDR);
1137
1138 if (!(expr->fetch->val & where)) {
1139 memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here",
1140 args[cur_arg-1], sample_src_names(expr->fetch->use));
1141 return ACT_RET_PRS_ERR;
1142 }
1143
1144 if (strcmp(args[cur_arg], "table") == 0) {
1145 cur_arg++;
1146 if (!*args[cur_arg]) {
1147 memprintf(err, "missing table name");
1148 return ACT_RET_PRS_ERR;
1149 }
1150
1151 /* we copy the table name for now, it will be resolved later */
1152 rule->arg.trk_ctr.table.n = strdup(args[cur_arg]);
1153 cur_arg++;
1154 }
1155
1156 rule->arg.trk_ctr.expr = expr;
1157 rule->action = ACT_ACTION_TRK_SC0 + tsc_num;
1158 rule->check_ptr = check_trk_action;
1159
1160 *orig_arg = cur_arg;
1161 return ACT_RET_PRS_OK;
1162}
1163
Willy Tarreau79e57332018-10-02 16:01:16 +02001164/************************************************************************/
1165/* All supported http-request action keywords must be declared here. */
1166/************************************************************************/
1167
1168static struct action_kw_list http_req_actions = {
1169 .kw = {
Christopher Faulet81e20172019-12-12 16:40:30 +01001170 { "add-acl", parse_http_set_map, 1 },
1171 { "add-header", parse_http_set_header, 0 },
1172 { "allow", parse_http_allow, 0 },
1173 { "auth", parse_http_auth, 0 },
1174 { "capture", parse_http_req_capture, 0 },
1175 { "del-acl", parse_http_set_map, 1 },
1176 { "del-header", parse_http_del_header, 0 },
1177 { "del-map", parse_http_set_map, 1 },
1178 { "deny", parse_http_req_deny, 0 },
1179 { "disable-l7-retry", parse_http_req_disable_l7_retry, 0 },
1180 { "early-hint", parse_http_set_header, 0 },
1181 { "redirect", parse_http_redirect, 0 },
1182 { "reject", parse_http_action_reject, 0 },
1183 { "replace-header", parse_http_replace_header, 0 },
1184 { "replace-path", parse_replace_uri, 0 },
1185 { "replace-uri", parse_replace_uri, 0 },
1186 { "replace-value", parse_http_replace_header, 0 },
1187 { "set-header", parse_http_set_header, 0 },
1188 { "set-log-level", parse_http_set_log_level, 0 },
1189 { "set-map", parse_http_set_map, 1 },
1190 { "set-method", parse_set_req_line, 0 },
1191 { "set-mark", parse_http_set_mark, 0 },
1192 { "set-nice", parse_http_set_nice, 0 },
1193 { "set-path", parse_set_req_line, 0 },
1194 { "set-query", parse_set_req_line, 0 },
1195 { "set-tos", parse_http_set_tos, 0 },
1196 { "set-uri", parse_set_req_line, 0 },
1197 { "tarpit", parse_http_req_deny, 0 },
1198 { "track-sc", parse_http_track_sc, 1 },
Willy Tarreau79e57332018-10-02 16:01:16 +02001199 { NULL, NULL }
1200 }
1201};
1202
Willy Tarreau0108d902018-11-25 19:14:37 +01001203INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_actions);
1204
Willy Tarreau79e57332018-10-02 16:01:16 +02001205static struct action_kw_list http_res_actions = {
1206 .kw = {
Christopher Faulet81e20172019-12-12 16:40:30 +01001207 { "add-acl", parse_http_set_map, 1 },
1208 { "add-header", parse_http_set_header, 0 },
1209 { "allow", parse_http_allow, 0 },
1210 { "capture", parse_http_res_capture, 0 },
1211 { "del-acl", parse_http_set_map, 1 },
1212 { "del-header", parse_http_del_header, 0 },
1213 { "del-map", parse_http_set_map, 1 },
1214 { "deny", parse_http_res_deny, 0 },
1215 { "redirect", parse_http_redirect, 0 },
1216 { "replace-header", parse_http_replace_header, 0 },
1217 { "replace-value", parse_http_replace_header, 0 },
1218 { "set-header", parse_http_set_header, 0 },
1219 { "set-log-level", parse_http_set_log_level, 0 },
1220 { "set-map", parse_http_set_map, 1 },
1221 { "set-mark", parse_http_set_mark, 0 },
1222 { "set-nice", parse_http_set_nice, 0 },
1223 { "set-status", parse_http_set_status, 0 },
1224 { "set-tos", parse_http_set_tos, 0 },
1225 { "track-sc", parse_http_track_sc, 1 },
Willy Tarreau79e57332018-10-02 16:01:16 +02001226 { NULL, NULL }
1227 }
1228};
1229
Willy Tarreau0108d902018-11-25 19:14:37 +01001230INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_actions);
Willy Tarreau79e57332018-10-02 16:01:16 +02001231
1232/*
1233 * Local variables:
1234 * c-indent-level: 8
1235 * c-basic-offset: 8
1236 * End:
1237 */