Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/types/action.h |
Thierry FOURNIER | 322a124 | 2015-08-19 09:07:47 +0200 | [diff] [blame] | 3 | * This file contains actions definitions. |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4 | * |
| 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 FOURNIER | 007ff4c | 2015-09-11 08:33:33 +0200 | [diff] [blame] | 25 | #include <common/regex.h> |
| 26 | |
Thierry FOURNIER | 5a363e7 | 2015-09-27 19:29:33 +0200 | [diff] [blame] | 27 | #include <types/applet.h> |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 28 | #include <types/stick_table.h> |
| 29 | |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 30 | enum act_from { |
| 31 | ACT_F_TCP_REQ_CON, /* tcp-request connection */ |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 32 | ACT_F_TCP_REQ_SES, /* tcp-request session */ |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 33 | 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 FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 39 | enum act_return { |
| 40 | ACT_RET_CONT, /* continue processing. */ |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 41 | ACT_RET_STOP, /* stop processing. */ |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 42 | ACT_RET_YIELD, /* call me again. */ |
| 43 | ACT_RET_ERR, /* processing error. */ |
| 44 | }; |
| 45 | |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 46 | enum act_parse_ret { |
| 47 | ACT_RET_PRS_OK, /* continue processing. */ |
| 48 | ACT_RET_PRS_ERR, /* abort processing. */ |
| 49 | }; |
| 50 | |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 51 | /* flags passed to custom actions */ |
| 52 | enum act_flag { |
| 53 | ACT_FLAG_NONE = 0x00000000, /* no flag */ |
Willy Tarreau | c1b10d3 | 2015-09-27 10:06:24 +0200 | [diff] [blame] | 54 | ACT_FLAG_FINAL = 0x00000001, /* last call, cannot yield */ |
Willy Tarreau | acc9800 | 2015-09-27 23:34:39 +0200 | [diff] [blame] | 55 | ACT_FLAG_FIRST = 0x00000002, /* first call for this action */ |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 56 | }; |
| 57 | |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 58 | enum act_name { |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 59 | ACT_CUSTOM = 0, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 60 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 61 | /* common action */ |
| 62 | ACT_ACTION_ALLOW, |
| 63 | ACT_ACTION_DENY, |
| 64 | |
| 65 | /* common http actions .*/ |
| 66 | ACT_HTTP_ADD_HDR, |
| 67 | ACT_HTTP_REPLACE_HDR, |
| 68 | ACT_HTTP_REPLACE_VAL, |
| 69 | ACT_HTTP_SET_HDR, |
| 70 | ACT_HTTP_DEL_HDR, |
| 71 | ACT_HTTP_REDIR, |
| 72 | ACT_HTTP_SET_NICE, |
| 73 | ACT_HTTP_SET_LOGL, |
| 74 | ACT_HTTP_SET_TOS, |
| 75 | ACT_HTTP_SET_MARK, |
| 76 | ACT_HTTP_ADD_ACL, |
| 77 | ACT_HTTP_DEL_ACL, |
| 78 | ACT_HTTP_DEL_MAP, |
| 79 | ACT_HTTP_SET_MAP, |
Frédéric Lécaille | a985e38 | 2018-11-06 10:55:34 +0100 | [diff] [blame] | 80 | ACT_HTTP_EARLY_HINT, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 81 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 82 | /* http request actions. */ |
| 83 | ACT_HTTP_REQ_TARPIT, |
| 84 | ACT_HTTP_REQ_AUTH, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 85 | |
| 86 | /* tcp actions */ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 87 | ACT_TCP_EXPECT_PX, |
Bertrand Jacquin | 9075968 | 2016-06-06 15:35:39 +0100 | [diff] [blame] | 88 | ACT_TCP_EXPECT_CIP, |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 89 | ACT_TCP_CLOSE, /* close at the sender's */ |
| 90 | ACT_TCP_CAPTURE, /* capture a fetched sample */ |
| 91 | |
| 92 | /* track stick counters */ |
| 93 | ACT_ACTION_TRK_SC0, |
| 94 | /* SC1, SC2, ... SCn */ |
| 95 | ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 98 | struct act_rule { |
| 99 | struct list list; |
| 100 | struct acl_cond *cond; /* acl condition to meet */ |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 101 | enum act_name action; /* ACT_ACTION_* */ |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 102 | enum act_from from; /* ACT_F_* */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 103 | short deny_status; /* HTTP status to return to user when denying */ |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 104 | enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, /* ptr to custom action */ |
| 105 | struct session *sess, struct stream *s, int flags); |
Christopher Faulet | 6d950b9 | 2017-09-18 15:12:39 +0200 | [diff] [blame] | 106 | int (*check_ptr)(struct act_rule *rule, struct proxy *px, char **err); /* ptr to check function */ |
Thierry FOURNIER | 85c6c97 | 2015-09-22 19:14:35 +0200 | [diff] [blame] | 107 | struct action_kw *kw; |
Thierry FOURNIER | 5a363e7 | 2015-09-27 19:29:33 +0200 | [diff] [blame] | 108 | struct applet applet; /* used for the applet registration. */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 109 | union { |
| 110 | struct { |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 111 | struct sample_expr *expr; |
| 112 | char *varname; |
| 113 | char *resolvers_id; |
| 114 | struct dns_resolvers *resolvers; |
| 115 | struct dns_options dns_opts; |
| 116 | } dns; /* dns resolution */ |
| 117 | struct { |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 118 | char *realm; |
| 119 | } auth; /* arg used by "auth" */ |
| 120 | struct { |
| 121 | char *name; /* header name */ |
| 122 | int name_len; /* header name's length */ |
| 123 | struct list fmt; /* log-format compatible expression */ |
Dragan Dosen | 2674303 | 2019-04-30 15:54:36 +0200 | [diff] [blame] | 124 | struct my_regex *re; /* used by replace-header and replace-value */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 125 | } hdr_add; /* args used by "add-header" and "set-header" */ |
Frédéric Lécaille | 0ebbcb6 | 2018-11-06 14:30:19 +0100 | [diff] [blame] | 126 | struct { |
| 127 | char *name; /* header name */ |
| 128 | int name_len; /* header name's length */ |
| 129 | struct list fmt; /* log-format compatible expression */ |
| 130 | } early_hint; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 131 | struct redirect_rule *redir; /* redirect rule or "http-request redirect" */ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 132 | int nice; /* nice value for ACT_HTTP_SET_NICE */ |
| 133 | int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */ |
| 134 | int tos; /* tos value for ACT_HTTP_SET_TOS */ |
| 135 | int mark; /* nfmark value for ACT_HTTP_SET_MARK */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 136 | struct { |
| 137 | char *ref; /* MAP or ACL file name to update */ |
| 138 | struct list key; /* pattern to retrieve MAP or ACL key */ |
| 139 | struct list value; /* pattern to retrieve MAP value */ |
| 140 | } map; |
Thierry FOURNIER | a002dc9 | 2015-07-31 08:50:51 +0200 | [diff] [blame] | 141 | struct sample_expr *expr; |
Thierry FOURNIER | 8855a92 | 2015-07-31 08:54:25 +0200 | [diff] [blame] | 142 | struct { |
| 143 | struct list logfmt; |
| 144 | int action; |
| 145 | } http; |
Thierry FOURNIER | 32b1500 | 2015-07-31 08:56:16 +0200 | [diff] [blame] | 146 | struct { |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 147 | struct sample_expr *expr; /* expression used as the key */ |
| 148 | struct cap_hdr *hdr; /* the capture storage */ |
Thierry FOURNIER | 32b1500 | 2015-07-31 08:56:16 +0200 | [diff] [blame] | 149 | } cap; |
Thierry FOURNIER | e209797 | 2015-07-31 08:56:35 +0200 | [diff] [blame] | 150 | struct { |
Thierry FOURNIER | 35d70ef | 2015-08-26 16:21:56 +0200 | [diff] [blame] | 151 | unsigned int code; /* HTTP status code */ |
Robin H. Johnson | 52f5db2 | 2017-01-01 13:10:52 -0800 | [diff] [blame] | 152 | const char *reason; /* HTTP status reason */ |
Thierry FOURNIER | 35d70ef | 2015-08-26 16:21:56 +0200 | [diff] [blame] | 153 | } status; |
| 154 | struct { |
Thierry FOURNIER | e209797 | 2015-07-31 08:56:35 +0200 | [diff] [blame] | 155 | struct sample_expr *expr; |
| 156 | int idx; |
| 157 | } capid; |
Thierry FOURNIER | 231ef1d | 2015-07-30 19:03:55 +0200 | [diff] [blame] | 158 | struct hlua_rule *hlua_rule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 159 | struct { |
Thierry FOURNIER | f8c1dce | 2015-07-30 19:12:50 +0200 | [diff] [blame] | 160 | struct sample_expr *expr; |
| 161 | const char *name; |
| 162 | enum vars_scope scope; |
| 163 | } vars; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 164 | struct { |
| 165 | int sc; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 166 | } gpc; |
| 167 | struct { |
| 168 | int sc; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 169 | long long int value; |
| 170 | } gpt; |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 171 | struct track_ctr_prm trk_ctr; |
Thierry FOURNIER | f8c1dce | 2015-07-30 19:12:50 +0200 | [diff] [blame] | 172 | struct { |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 173 | void *p[4]; |
| 174 | } act; /* generic pointers to be used by custom actions */ |
| 175 | } arg; /* arguments used by some actions */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 176 | }; |
| 177 | |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 178 | struct action_kw { |
| 179 | const char *kw; |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 180 | enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px, |
| 181 | struct act_rule *rule, char **err); |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 182 | int match_pfx; |
Thierry FOURNIER | 7ea160c | 2015-09-22 18:26:42 +0200 | [diff] [blame] | 183 | void *private; |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | struct action_kw_list { |
| 187 | struct list list; |
| 188 | struct action_kw kw[VAR_ARRAY]; |
| 189 | }; |
| 190 | |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 191 | #endif /* _TYPES_ACTION_H */ |