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> |
Christopher Faulet | 5ff0c64 | 2020-05-12 18:33:37 +0200 | [diff] [blame] | 29 | #include <types/http_htx.h> |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 30 | |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 31 | enum act_from { |
| 32 | ACT_F_TCP_REQ_CON, /* tcp-request connection */ |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 33 | ACT_F_TCP_REQ_SES, /* tcp-request session */ |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 34 | ACT_F_TCP_REQ_CNT, /* tcp-request content */ |
| 35 | ACT_F_TCP_RES_CNT, /* tcp-response content */ |
| 36 | ACT_F_HTTP_REQ, /* http-request */ |
| 37 | ACT_F_HTTP_RES, /* http-response */ |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 38 | ACT_F_TCP_CHK, /* tcp-check. */ |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 41 | enum act_return { |
Christopher Faulet | 30a2a37 | 2019-12-16 12:25:43 +0100 | [diff] [blame] | 42 | ACT_RET_CONT, /* continue processing. */ |
| 43 | ACT_RET_STOP, /* stop processing. */ |
| 44 | ACT_RET_YIELD, /* call me again. */ |
| 45 | ACT_RET_ERR, /* internal processing error. */ |
| 46 | ACT_RET_DONE, /* processing done, stop processing */ |
| 47 | ACT_RET_DENY, /* deny, must be handled by the caller */ |
| 48 | ACT_RET_ABRT, /* abort, handled by action itsleft. */ |
| 49 | ACT_RET_INV, /* invalid request/response */ |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 52 | enum act_parse_ret { |
| 53 | ACT_RET_PRS_OK, /* continue processing. */ |
| 54 | ACT_RET_PRS_ERR, /* abort processing. */ |
| 55 | }; |
| 56 | |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 57 | /* Option flags passed to custom actions */ |
| 58 | enum act_opt { |
| 59 | ACT_OPT_NONE = 0x00000000, /* no flag */ |
| 60 | ACT_OPT_FINAL = 0x00000001, /* last call, cannot yield */ |
| 61 | ACT_OPT_FIRST = 0x00000002, /* first call for this action */ |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 64 | /* Flags used to describe the action. */ |
| 65 | enum act_flag { |
| 66 | ACT_FLAG_FINAL = 1 << 0, /* the action stops the rules evaluation when executed */ |
| 67 | }; |
| 68 | |
| 69 | |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 70 | /* known actions to be used without any action function pointer. This enum is |
| 71 | * typically used in a switch case, iff .action_ptr is undefined. So if an |
| 72 | * action function is defined for one of following action types, the function |
| 73 | * have the priority over the switch. |
| 74 | */ |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 75 | enum act_name { |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 76 | ACT_CUSTOM = 0, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 77 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 78 | /* common action */ |
| 79 | ACT_ACTION_ALLOW, |
| 80 | ACT_ACTION_DENY, |
| 81 | |
| 82 | /* common http actions .*/ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 83 | ACT_HTTP_DEL_HDR, |
| 84 | ACT_HTTP_REDIR, |
| 85 | ACT_HTTP_SET_NICE, |
| 86 | ACT_HTTP_SET_LOGL, |
| 87 | ACT_HTTP_SET_TOS, |
| 88 | ACT_HTTP_SET_MARK, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 89 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 90 | /* http request actions. */ |
| 91 | ACT_HTTP_REQ_TARPIT, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 92 | |
| 93 | /* tcp actions */ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 94 | ACT_TCP_EXPECT_PX, |
Bertrand Jacquin | 9075968 | 2016-06-06 15:35:39 +0100 | [diff] [blame] | 95 | ACT_TCP_EXPECT_CIP, |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 96 | ACT_TCP_CLOSE, /* close at the sender's */ |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 99 | /* NOTE: if <.action_ptr> is defined, the referenced function will always be |
| 100 | * called regardless the action type. */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 101 | struct act_rule { |
| 102 | struct list list; |
| 103 | struct acl_cond *cond; /* acl condition to meet */ |
Christopher Faulet | 006f650 | 2019-12-18 15:10:29 +0100 | [diff] [blame] | 104 | unsigned int action; /* ACT_* or any meaningful value if action_ptr is defined */ |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 105 | unsigned int flags; /* ACT_FLAG_* */ |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 106 | enum act_from from; /* ACT_F_* */ |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 107 | enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, /* ptr to custom action */ |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 108 | struct session *sess, struct stream *s, int opts); |
Christopher Faulet | 6d950b9 | 2017-09-18 15:12:39 +0200 | [diff] [blame] | 109 | int (*check_ptr)(struct act_rule *rule, struct proxy *px, char **err); /* ptr to check function */ |
Christopher Faulet | 58b3564 | 2019-12-17 11:48:42 +0100 | [diff] [blame] | 110 | void (*release_ptr)(struct act_rule *rule); /* ptr to release function */ |
Thierry FOURNIER | 85c6c97 | 2015-09-22 19:14:35 +0200 | [diff] [blame] | 111 | struct action_kw *kw; |
Thierry FOURNIER | 5a363e7 | 2015-09-27 19:29:33 +0200 | [diff] [blame] | 112 | struct applet applet; /* used for the applet registration. */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 113 | union { |
| 114 | struct { |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 115 | struct sample_expr *expr; |
| 116 | char *varname; |
| 117 | char *resolvers_id; |
| 118 | struct dns_resolvers *resolvers; |
Christopher Faulet | a416843 | 2020-01-24 18:08:42 +0100 | [diff] [blame] | 119 | struct dns_options *dns_opts; |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 120 | } dns; /* dns resolution */ |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 121 | struct { |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 122 | int i; /* integer param (status, nice, loglevel, ..) */ |
| 123 | struct ist str; /* string param (reason, header name, ...) */ |
Frédéric Lécaille | 0ebbcb6 | 2018-11-06 14:30:19 +0100 | [diff] [blame] | 124 | struct list fmt; /* log-format compatible expression */ |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 125 | struct my_regex *re; /* used by replace-header/value/uri/path */ |
| 126 | } http; /* args used by some HTTP rules */ |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 127 | struct http_reply *http_reply; /* HTTP response to be used by return/deny/tarpit rules */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 128 | struct redirect_rule *redir; /* redirect rule or "http-request redirect" */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 129 | struct { |
| 130 | char *ref; /* MAP or ACL file name to update */ |
| 131 | struct list key; /* pattern to retrieve MAP or ACL key */ |
| 132 | struct list value; /* pattern to retrieve MAP value */ |
| 133 | } map; |
Thierry FOURNIER | a002dc9 | 2015-07-31 08:50:51 +0200 | [diff] [blame] | 134 | struct sample_expr *expr; |
Thierry FOURNIER | 8855a92 | 2015-07-31 08:54:25 +0200 | [diff] [blame] | 135 | struct { |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 136 | struct sample_expr *expr; /* expression used as the key */ |
| 137 | struct cap_hdr *hdr; /* the capture storage */ |
Thierry FOURNIER | 32b1500 | 2015-07-31 08:56:16 +0200 | [diff] [blame] | 138 | } cap; |
Thierry FOURNIER | e209797 | 2015-07-31 08:56:35 +0200 | [diff] [blame] | 139 | struct { |
| 140 | struct sample_expr *expr; |
| 141 | int idx; |
| 142 | } capid; |
Thierry FOURNIER | 231ef1d | 2015-07-30 19:03:55 +0200 | [diff] [blame] | 143 | struct hlua_rule *hlua_rule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 144 | struct { |
Thierry FOURNIER | f8c1dce | 2015-07-30 19:12:50 +0200 | [diff] [blame] | 145 | struct sample_expr *expr; |
| 146 | const char *name; |
| 147 | enum vars_scope scope; |
| 148 | } vars; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 149 | struct { |
| 150 | int sc; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 151 | } gpc; |
| 152 | struct { |
| 153 | int sc; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 154 | long long int value; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 155 | struct sample_expr *expr; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 156 | } gpt; |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 157 | struct track_ctr_prm trk_ctr; |
Thierry FOURNIER | f8c1dce | 2015-07-30 19:12:50 +0200 | [diff] [blame] | 158 | struct { |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 159 | void *p[4]; |
| 160 | } act; /* generic pointers to be used by custom actions */ |
| 161 | } arg; /* arguments used by some actions */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 162 | }; |
| 163 | |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 164 | struct action_kw { |
| 165 | const char *kw; |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 166 | enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px, |
| 167 | struct act_rule *rule, char **err); |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 168 | int match_pfx; |
Thierry FOURNIER | 7ea160c | 2015-09-22 18:26:42 +0200 | [diff] [blame] | 169 | void *private; |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | struct action_kw_list { |
| 173 | struct list list; |
| 174 | struct action_kw kw[VAR_ARRAY]; |
| 175 | }; |
| 176 | |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 177 | #endif /* _TYPES_ACTION_H */ |