blob: 54a6f71a4b050fffe57c7d0c6bcb50c4604cd741 [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 */
37};
38
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020039enum act_return {
40 ACT_RET_CONT, /* continue processing. */
Thierry FOURNIER42148732015-09-02 17:17:33 +020041 ACT_RET_STOP, /* stop processing. */
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020042 ACT_RET_YIELD, /* call me again. */
43 ACT_RET_ERR, /* processing error. */
Christopher Faulet2e4843d2019-07-04 11:08:38 +020044 ACT_RET_DONE, /* processing done, stop processing */
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020045};
46
Thierry FOURNIERafa80492015-08-19 09:04:15 +020047enum act_parse_ret {
48 ACT_RET_PRS_OK, /* continue processing. */
49 ACT_RET_PRS_ERR, /* abort processing. */
50};
51
Willy Tarreau658b85b2015-09-27 10:00:49 +020052/* flags passed to custom actions */
53enum act_flag {
54 ACT_FLAG_NONE = 0x00000000, /* no flag */
Willy Tarreauc1b10d32015-09-27 10:06:24 +020055 ACT_FLAG_FINAL = 0x00000001, /* last call, cannot yield */
Willy Tarreauacc98002015-09-27 23:34:39 +020056 ACT_FLAG_FIRST = 0x00000002, /* first call for this action */
Willy Tarreau658b85b2015-09-27 10:00:49 +020057};
58
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020059enum act_name {
Thierry FOURNIER42148732015-09-02 17:17:33 +020060 ACT_CUSTOM = 0,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020061
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020062 /* common action */
63 ACT_ACTION_ALLOW,
64 ACT_ACTION_DENY,
65
66 /* common http actions .*/
67 ACT_HTTP_ADD_HDR,
68 ACT_HTTP_REPLACE_HDR,
69 ACT_HTTP_REPLACE_VAL,
70 ACT_HTTP_SET_HDR,
71 ACT_HTTP_DEL_HDR,
72 ACT_HTTP_REDIR,
73 ACT_HTTP_SET_NICE,
74 ACT_HTTP_SET_LOGL,
75 ACT_HTTP_SET_TOS,
76 ACT_HTTP_SET_MARK,
77 ACT_HTTP_ADD_ACL,
78 ACT_HTTP_DEL_ACL,
79 ACT_HTTP_DEL_MAP,
80 ACT_HTTP_SET_MAP,
Frédéric Lécaillea985e382018-11-06 10:55:34 +010081 ACT_HTTP_EARLY_HINT,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020082
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020083 /* http request actions. */
84 ACT_HTTP_REQ_TARPIT,
85 ACT_HTTP_REQ_AUTH,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020086
87 /* tcp actions */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020088 ACT_TCP_EXPECT_PX,
Bertrand Jacquin90759682016-06-06 15:35:39 +010089 ACT_TCP_EXPECT_CIP,
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020090 ACT_TCP_CLOSE, /* close at the sender's */
91 ACT_TCP_CAPTURE, /* capture a fetched sample */
92
93 /* track stick counters */
94 ACT_ACTION_TRK_SC0,
95 /* SC1, SC2, ... SCn */
96 ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020097};
98
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020099struct act_rule {
100 struct list list;
101 struct acl_cond *cond; /* acl condition to meet */
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +0200102 enum act_name action; /* ACT_ACTION_* */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +0200103 enum act_from from; /* ACT_F_* */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200104 short deny_status; /* HTTP status to return to user when denying */
Willy Tarreau658b85b2015-09-27 10:00:49 +0200105 enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, /* ptr to custom action */
106 struct session *sess, struct stream *s, int flags);
Christopher Faulet6d950b92017-09-18 15:12:39 +0200107 int (*check_ptr)(struct act_rule *rule, struct proxy *px, char **err); /* ptr to check function */
Thierry FOURNIER85c6c972015-09-22 19:14:35 +0200108 struct action_kw *kw;
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200109 struct applet applet; /* used for the applet registration. */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200110 union {
111 struct {
Baptiste Assmann333939c2019-01-21 08:34:50 +0100112 struct sample_expr *expr;
113 char *varname;
114 char *resolvers_id;
115 struct dns_resolvers *resolvers;
116 struct dns_options dns_opts;
117 } dns; /* dns resolution */
118 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200119 char *realm;
120 } auth; /* arg used by "auth" */
121 struct {
122 char *name; /* header name */
123 int name_len; /* header name's length */
124 struct list fmt; /* log-format compatible expression */
Dragan Dosen26743032019-04-30 15:54:36 +0200125 struct my_regex *re; /* used by replace-header and replace-value */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200126 } hdr_add; /* args used by "add-header" and "set-header" */
Frédéric Lécaille0ebbcb62018-11-06 14:30:19 +0100127 struct {
128 char *name; /* header name */
129 int name_len; /* header name's length */
130 struct list fmt; /* log-format compatible expression */
131 } early_hint;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200132 struct redirect_rule *redir; /* redirect rule or "http-request redirect" */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +0200133 int nice; /* nice value for ACT_HTTP_SET_NICE */
134 int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */
135 int tos; /* tos value for ACT_HTTP_SET_TOS */
136 int mark; /* nfmark value for ACT_HTTP_SET_MARK */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200137 struct {
138 char *ref; /* MAP or ACL file name to update */
139 struct list key; /* pattern to retrieve MAP or ACL key */
140 struct list value; /* pattern to retrieve MAP value */
141 } map;
Thierry FOURNIERa002dc92015-07-31 08:50:51 +0200142 struct sample_expr *expr;
Thierry FOURNIER8855a922015-07-31 08:54:25 +0200143 struct {
144 struct list logfmt;
145 int action;
146 } http;
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200147 struct {
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +0200148 struct sample_expr *expr; /* expression used as the key */
149 struct cap_hdr *hdr; /* the capture storage */
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200150 } cap;
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200151 struct {
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +0200152 unsigned int code; /* HTTP status code */
Robin H. Johnson52f5db22017-01-01 13:10:52 -0800153 const char *reason; /* HTTP status reason */
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +0200154 } status;
155 struct {
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200156 struct sample_expr *expr;
157 int idx;
158 } capid;
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200159 struct hlua_rule *hlua_rule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200160 struct {
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200161 struct sample_expr *expr;
162 const char *name;
163 enum vars_scope scope;
164 } vars;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200165 struct {
166 int sc;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +0200167 } gpc;
168 struct {
169 int sc;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200170 long long int value;
171 } gpt;
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +0200172 struct track_ctr_prm trk_ctr;
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200173 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200174 void *p[4];
175 } act; /* generic pointers to be used by custom actions */
176 } arg; /* arguments used by some actions */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200177};
178
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200179struct action_kw {
180 const char *kw;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200181 enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
182 struct act_rule *rule, char **err);
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200183 int match_pfx;
Thierry FOURNIER7ea160c2015-09-22 18:26:42 +0200184 void *private;
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200185};
186
187struct action_kw_list {
188 struct list list;
189 struct action_kw kw[VAR_ARRAY];
190};
191
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200192#endif /* _TYPES_ACTION_H */