blob: 1a5a59405d2555d0f865e46f111e64284e7ea812 [file] [log] [blame]
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02001/*
2 * include/types/action.h
Thierry FOURNIER322a1242015-08-19 09:07:47 +02003 * This file contains actions definitions.
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004 *
5 * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _TYPES_ACTION_H
23#define _TYPES_ACTION_H
24
Thierry FOURNIER007ff4c2015-09-11 08:33:33 +020025#include <common/regex.h>
26
Thierry FOURNIER5a363e72015-09-27 19:29:33 +020027#include <types/applet.h>
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020028#include <types/stick_table.h>
29
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020030enum act_from {
31 ACT_F_TCP_REQ_CON, /* tcp-request connection */
Willy Tarreau620408f2016-10-21 16:37:51 +020032 ACT_F_TCP_REQ_SES, /* tcp-request session */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020033 ACT_F_TCP_REQ_CNT, /* tcp-request content */
34 ACT_F_TCP_RES_CNT, /* tcp-response content */
35 ACT_F_HTTP_REQ, /* http-request */
36 ACT_F_HTTP_RES, /* http-response */
Gaetan Rivet707b52f2020-02-21 18:14:59 +010037 ACT_F_TCP_CHK, /* tcp-check. */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020038};
39
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020040enum act_return {
Christopher Faulet30a2a372019-12-16 12:25:43 +010041 ACT_RET_CONT, /* continue processing. */
42 ACT_RET_STOP, /* stop processing. */
43 ACT_RET_YIELD, /* call me again. */
44 ACT_RET_ERR, /* internal processing error. */
45 ACT_RET_DONE, /* processing done, stop processing */
46 ACT_RET_DENY, /* deny, must be handled by the caller */
47 ACT_RET_ABRT, /* abort, handled by action itsleft. */
48 ACT_RET_INV, /* invalid request/response */
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020049};
50
Thierry FOURNIERafa80492015-08-19 09:04:15 +020051enum act_parse_ret {
52 ACT_RET_PRS_OK, /* continue processing. */
53 ACT_RET_PRS_ERR, /* abort processing. */
54};
55
Christopher Faulet105ba6c2019-12-18 14:41:51 +010056/* Option flags passed to custom actions */
57enum act_opt {
58 ACT_OPT_NONE = 0x00000000, /* no flag */
59 ACT_OPT_FINAL = 0x00000001, /* last call, cannot yield */
60 ACT_OPT_FIRST = 0x00000002, /* first call for this action */
Willy Tarreau658b85b2015-09-27 10:00:49 +020061};
62
Christopher Faulet245cf792019-12-18 14:58:12 +010063/* Flags used to describe the action. */
64enum act_flag {
65 ACT_FLAG_FINAL = 1 << 0, /* the action stops the rules evaluation when executed */
66};
67
68
Christopher Fauletcd26e8a2019-12-18 11:13:39 +010069/* known actions to be used without any action function pointer. This enum is
70 * typically used in a switch case, iff .action_ptr is undefined. So if an
71 * action function is defined for one of following action types, the function
72 * have the priority over the switch.
73 */
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020074enum act_name {
Thierry FOURNIER42148732015-09-02 17:17:33 +020075 ACT_CUSTOM = 0,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020076
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020077 /* common action */
78 ACT_ACTION_ALLOW,
79 ACT_ACTION_DENY,
80
81 /* common http actions .*/
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020082 ACT_HTTP_DEL_HDR,
83 ACT_HTTP_REDIR,
84 ACT_HTTP_SET_NICE,
85 ACT_HTTP_SET_LOGL,
86 ACT_HTTP_SET_TOS,
87 ACT_HTTP_SET_MARK,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020088
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020089 /* http request actions. */
90 ACT_HTTP_REQ_TARPIT,
91 ACT_HTTP_REQ_AUTH,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020092
93 /* tcp actions */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020094 ACT_TCP_EXPECT_PX,
Bertrand Jacquin90759682016-06-06 15:35:39 +010095 ACT_TCP_EXPECT_CIP,
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020096 ACT_TCP_CLOSE, /* close at the sender's */
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020097};
98
Christopher Fauletcd26e8a2019-12-18 11:13:39 +010099/* NOTE: if <.action_ptr> is defined, the referenced function will always be
100 * called regardless the action type. */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200101struct act_rule {
102 struct list list;
103 struct acl_cond *cond; /* acl condition to meet */
Christopher Faulet006f6502019-12-18 15:10:29 +0100104 unsigned int action; /* ACT_* or any meaningful value if action_ptr is defined */
Christopher Faulet245cf792019-12-18 14:58:12 +0100105 unsigned int flags; /* ACT_FLAG_* */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +0200106 enum act_from from; /* ACT_F_* */
Willy Tarreau658b85b2015-09-27 10:00:49 +0200107 enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, /* ptr to custom action */
Christopher Faulet105ba6c2019-12-18 14:41:51 +0100108 struct session *sess, struct stream *s, int opts);
Christopher Faulet6d950b92017-09-18 15:12:39 +0200109 int (*check_ptr)(struct act_rule *rule, struct proxy *px, char **err); /* ptr to check function */
Christopher Faulet58b35642019-12-17 11:48:42 +0100110 void (*release_ptr)(struct act_rule *rule); /* ptr to release function */
Thierry FOURNIER85c6c972015-09-22 19:14:35 +0200111 struct action_kw *kw;
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200112 struct applet applet; /* used for the applet registration. */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200113 union {
114 struct {
Baptiste Assmann333939c2019-01-21 08:34:50 +0100115 struct sample_expr *expr;
116 char *varname;
117 char *resolvers_id;
118 struct dns_resolvers *resolvers;
Christopher Fauleta4168432020-01-24 18:08:42 +0100119 struct dns_options *dns_opts;
Christopher Faulet96bff762019-12-17 13:46:18 +0100120 } dns; /* dns resolution */
Baptiste Assmann333939c2019-01-21 08:34:50 +0100121 struct {
Christopher Faulet96bff762019-12-17 13:46:18 +0100122 int i; /* integer param (status, nice, loglevel, ..) */
123 struct ist str; /* string param (reason, header name, ...) */
Frédéric Lécaille0ebbcb62018-11-06 14:30:19 +0100124 struct list fmt; /* log-format compatible expression */
Christopher Faulet96bff762019-12-17 13:46:18 +0100125 struct my_regex *re; /* used by replace-header/value/uri/path */
126 } http; /* args used by some HTTP rules */
Christopher Faulet554c0eb2020-01-14 12:00:28 +0100127 struct {
128 int status; /* status code */
129 struct buffer *errmsg; /* HTTP error message, may be NULL */
130 } http_deny; /* args used by HTTP deny rules */
Christopher Faulet24231ab2020-01-24 17:44:23 +0100131 struct {
132 int status;
133 char *ctype;
Christopher Faulet4a2c1422020-01-31 17:36:01 +0100134 struct list *hdrs;
Christopher Faulet24231ab2020-01-24 17:44:23 +0100135 union {
136 struct list fmt;
137 struct buffer obj;
138 struct buffer *errmsg;
139 } body;
140 } http_return;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200141 struct redirect_rule *redir; /* redirect rule or "http-request redirect" */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200142 struct {
143 char *ref; /* MAP or ACL file name to update */
144 struct list key; /* pattern to retrieve MAP or ACL key */
145 struct list value; /* pattern to retrieve MAP value */
146 } map;
Thierry FOURNIERa002dc92015-07-31 08:50:51 +0200147 struct sample_expr *expr;
Thierry FOURNIER8855a922015-07-31 08:54:25 +0200148 struct {
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +0200149 struct sample_expr *expr; /* expression used as the key */
150 struct cap_hdr *hdr; /* the capture storage */
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200151 } cap;
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200152 struct {
153 struct sample_expr *expr;
154 int idx;
155 } capid;
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200156 struct hlua_rule *hlua_rule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200157 struct {
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200158 struct sample_expr *expr;
159 const char *name;
160 enum vars_scope scope;
161 } vars;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200162 struct {
163 int sc;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +0200164 } gpc;
165 struct {
166 int sc;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200167 long long int value;
Cédric Dufour0d7712d2019-11-06 18:38:53 +0100168 struct sample_expr *expr;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200169 } gpt;
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +0200170 struct track_ctr_prm trk_ctr;
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200171 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200172 void *p[4];
173 } act; /* generic pointers to be used by custom actions */
174 } arg; /* arguments used by some actions */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200175};
176
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200177struct action_kw {
178 const char *kw;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200179 enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
180 struct act_rule *rule, char **err);
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200181 int match_pfx;
Thierry FOURNIER7ea160c2015-09-22 18:26:42 +0200182 void *private;
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200183};
184
185struct action_kw_list {
186 struct list list;
187 struct action_kw kw[VAR_ARRAY];
188};
189
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200190#endif /* _TYPES_ACTION_H */