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, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 80 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 81 | /* http request actions. */ |
| 82 | ACT_HTTP_REQ_TARPIT, |
| 83 | ACT_HTTP_REQ_AUTH, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 84 | |
| 85 | /* tcp actions */ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 86 | ACT_TCP_EXPECT_PX, |
Bertrand Jacquin | 9075968 | 2016-06-06 15:35:39 +0100 | [diff] [blame] | 87 | ACT_TCP_EXPECT_CIP, |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 88 | ACT_TCP_CLOSE, /* close at the sender's */ |
| 89 | ACT_TCP_CAPTURE, /* capture a fetched sample */ |
| 90 | |
| 91 | /* track stick counters */ |
| 92 | ACT_ACTION_TRK_SC0, |
| 93 | /* SC1, SC2, ... SCn */ |
| 94 | ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 95 | }; |
| 96 | |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 97 | struct act_rule { |
| 98 | struct list list; |
| 99 | struct acl_cond *cond; /* acl condition to meet */ |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 100 | enum act_name action; /* ACT_ACTION_* */ |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 101 | enum act_from from; /* ACT_F_* */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 102 | short deny_status; /* HTTP status to return to user when denying */ |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 103 | enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, /* ptr to custom action */ |
| 104 | struct session *sess, struct stream *s, int flags); |
Thierry FOURNIER | 85c6c97 | 2015-09-22 19:14:35 +0200 | [diff] [blame] | 105 | struct action_kw *kw; |
Thierry FOURNIER | 5a363e7 | 2015-09-27 19:29:33 +0200 | [diff] [blame] | 106 | struct applet applet; /* used for the applet registration. */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 107 | union { |
| 108 | struct { |
| 109 | char *realm; |
| 110 | } auth; /* arg used by "auth" */ |
| 111 | struct { |
| 112 | char *name; /* header name */ |
| 113 | int name_len; /* header name's length */ |
| 114 | struct list fmt; /* log-format compatible expression */ |
| 115 | struct my_regex re; /* used by replace-header and replace-value */ |
| 116 | } hdr_add; /* args used by "add-header" and "set-header" */ |
| 117 | struct redirect_rule *redir; /* redirect rule or "http-request redirect" */ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 118 | int nice; /* nice value for ACT_HTTP_SET_NICE */ |
| 119 | int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */ |
| 120 | int tos; /* tos value for ACT_HTTP_SET_TOS */ |
| 121 | int mark; /* nfmark value for ACT_HTTP_SET_MARK */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 122 | struct { |
| 123 | char *ref; /* MAP or ACL file name to update */ |
| 124 | struct list key; /* pattern to retrieve MAP or ACL key */ |
| 125 | struct list value; /* pattern to retrieve MAP value */ |
| 126 | } map; |
Thierry FOURNIER | a002dc9 | 2015-07-31 08:50:51 +0200 | [diff] [blame] | 127 | struct sample_expr *expr; |
Thierry FOURNIER | 8855a92 | 2015-07-31 08:54:25 +0200 | [diff] [blame] | 128 | struct { |
| 129 | struct list logfmt; |
| 130 | int action; |
| 131 | } http; |
Thierry FOURNIER | 32b1500 | 2015-07-31 08:56:16 +0200 | [diff] [blame] | 132 | struct { |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 133 | struct sample_expr *expr; /* expression used as the key */ |
| 134 | struct cap_hdr *hdr; /* the capture storage */ |
Thierry FOURNIER | 32b1500 | 2015-07-31 08:56:16 +0200 | [diff] [blame] | 135 | } cap; |
Thierry FOURNIER | e209797 | 2015-07-31 08:56:35 +0200 | [diff] [blame] | 136 | struct { |
Thierry FOURNIER | 35d70ef | 2015-08-26 16:21:56 +0200 | [diff] [blame] | 137 | unsigned int code; /* HTTP status code */ |
| 138 | } status; |
| 139 | struct { |
Thierry FOURNIER | e209797 | 2015-07-31 08:56:35 +0200 | [diff] [blame] | 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; |
| 155 | } gpt; |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 156 | struct track_ctr_prm trk_ctr; |
Thierry FOURNIER | f8c1dce | 2015-07-30 19:12:50 +0200 | [diff] [blame] | 157 | struct { |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 158 | void *p[4]; |
| 159 | } act; /* generic pointers to be used by custom actions */ |
| 160 | } arg; /* arguments used by some actions */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 161 | }; |
| 162 | |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 163 | struct action_kw { |
| 164 | const char *kw; |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 165 | enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px, |
| 166 | struct act_rule *rule, char **err); |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 167 | int match_pfx; |
Thierry FOURNIER | 7ea160c | 2015-09-22 18:26:42 +0200 | [diff] [blame] | 168 | void *private; |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | struct action_kw_list { |
| 172 | struct list list; |
| 173 | struct action_kw kw[VAR_ARRAY]; |
| 174 | }; |
| 175 | |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 176 | #endif /* _TYPES_ACTION_H */ |