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 | |
| 25 | #include <types/stick_table.h> |
| 26 | |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 27 | enum act_from { |
| 28 | ACT_F_TCP_REQ_CON, /* tcp-request connection */ |
| 29 | ACT_F_TCP_REQ_CNT, /* tcp-request content */ |
| 30 | ACT_F_TCP_RES_CNT, /* tcp-response content */ |
| 31 | ACT_F_HTTP_REQ, /* http-request */ |
| 32 | ACT_F_HTTP_RES, /* http-response */ |
| 33 | }; |
| 34 | |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 35 | enum act_return { |
| 36 | ACT_RET_CONT, /* continue processing. */ |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 37 | ACT_RET_STOP, /* stop processing. */ |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 38 | ACT_RET_YIELD, /* call me again. */ |
| 39 | ACT_RET_ERR, /* processing error. */ |
| 40 | }; |
| 41 | |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 42 | enum act_parse_ret { |
| 43 | ACT_RET_PRS_OK, /* continue processing. */ |
| 44 | ACT_RET_PRS_ERR, /* abort processing. */ |
| 45 | }; |
| 46 | |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 47 | enum act_name { |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 48 | ACT_CUSTOM = 0, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 49 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 50 | /* common action */ |
| 51 | ACT_ACTION_ALLOW, |
| 52 | ACT_ACTION_DENY, |
| 53 | |
| 54 | /* common http actions .*/ |
| 55 | ACT_HTTP_ADD_HDR, |
| 56 | ACT_HTTP_REPLACE_HDR, |
| 57 | ACT_HTTP_REPLACE_VAL, |
| 58 | ACT_HTTP_SET_HDR, |
| 59 | ACT_HTTP_DEL_HDR, |
| 60 | ACT_HTTP_REDIR, |
| 61 | ACT_HTTP_SET_NICE, |
| 62 | ACT_HTTP_SET_LOGL, |
| 63 | ACT_HTTP_SET_TOS, |
| 64 | ACT_HTTP_SET_MARK, |
| 65 | ACT_HTTP_ADD_ACL, |
| 66 | ACT_HTTP_DEL_ACL, |
| 67 | ACT_HTTP_DEL_MAP, |
| 68 | ACT_HTTP_SET_MAP, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 69 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 70 | /* http request actions. */ |
| 71 | ACT_HTTP_REQ_TARPIT, |
| 72 | ACT_HTTP_REQ_AUTH, |
| 73 | ACT_HTTP_REQ_SET_SRC, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 74 | |
| 75 | /* tcp actions */ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 76 | ACT_TCP_EXPECT_PX, |
| 77 | ACT_TCP_CLOSE, /* close at the sender's */ |
| 78 | ACT_TCP_CAPTURE, /* capture a fetched sample */ |
| 79 | |
| 80 | /* track stick counters */ |
| 81 | ACT_ACTION_TRK_SC0, |
| 82 | /* SC1, SC2, ... SCn */ |
| 83 | ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1, |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 86 | struct act_rule { |
| 87 | struct list list; |
| 88 | struct acl_cond *cond; /* acl condition to meet */ |
Thierry FOURNIER | 91f6ba0 | 2015-08-06 08:30:11 +0200 | [diff] [blame] | 89 | enum act_name action; /* ACT_ACTION_* */ |
Thierry FOURNIER | 5563e4b | 2015-08-14 19:20:07 +0200 | [diff] [blame] | 90 | enum act_from from; /* ACT_F_* */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 91 | short deny_status; /* HTTP status to return to user when denying */ |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 92 | enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, |
| 93 | struct session *sess, struct stream *s); /* ptr to custom action */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 94 | union { |
| 95 | struct { |
| 96 | char *realm; |
| 97 | } auth; /* arg used by "auth" */ |
| 98 | struct { |
| 99 | char *name; /* header name */ |
| 100 | int name_len; /* header name's length */ |
| 101 | struct list fmt; /* log-format compatible expression */ |
| 102 | struct my_regex re; /* used by replace-header and replace-value */ |
| 103 | } hdr_add; /* args used by "add-header" and "set-header" */ |
| 104 | struct redirect_rule *redir; /* redirect rule or "http-request redirect" */ |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 105 | int nice; /* nice value for ACT_HTTP_SET_NICE */ |
| 106 | int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */ |
| 107 | int tos; /* tos value for ACT_HTTP_SET_TOS */ |
| 108 | int mark; /* nfmark value for ACT_HTTP_SET_MARK */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 109 | struct { |
| 110 | char *ref; /* MAP or ACL file name to update */ |
| 111 | struct list key; /* pattern to retrieve MAP or ACL key */ |
| 112 | struct list value; /* pattern to retrieve MAP value */ |
| 113 | } map; |
Thierry FOURNIER | a002dc9 | 2015-07-31 08:50:51 +0200 | [diff] [blame] | 114 | struct sample_expr *expr; |
Thierry FOURNIER | 8855a92 | 2015-07-31 08:54:25 +0200 | [diff] [blame] | 115 | struct { |
| 116 | struct list logfmt; |
| 117 | int action; |
| 118 | } http; |
Thierry FOURNIER | 32b1500 | 2015-07-31 08:56:16 +0200 | [diff] [blame] | 119 | struct { |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 120 | struct sample_expr *expr; /* expression used as the key */ |
| 121 | struct cap_hdr *hdr; /* the capture storage */ |
Thierry FOURNIER | 32b1500 | 2015-07-31 08:56:16 +0200 | [diff] [blame] | 122 | } cap; |
Thierry FOURNIER | e209797 | 2015-07-31 08:56:35 +0200 | [diff] [blame] | 123 | struct { |
Thierry FOURNIER | 35d70ef | 2015-08-26 16:21:56 +0200 | [diff] [blame] | 124 | unsigned int code; /* HTTP status code */ |
| 125 | } status; |
| 126 | struct { |
Thierry FOURNIER | e209797 | 2015-07-31 08:56:35 +0200 | [diff] [blame] | 127 | struct sample_expr *expr; |
| 128 | int idx; |
| 129 | } capid; |
Thierry FOURNIER | 231ef1d | 2015-07-30 19:03:55 +0200 | [diff] [blame] | 130 | struct hlua_rule *hlua_rule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 131 | struct { |
Thierry FOURNIER | f8c1dce | 2015-07-30 19:12:50 +0200 | [diff] [blame] | 132 | struct sample_expr *expr; |
| 133 | const char *name; |
| 134 | enum vars_scope scope; |
| 135 | } vars; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 136 | struct { |
| 137 | int sc; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 138 | } gpc; |
| 139 | struct { |
| 140 | int sc; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 141 | long long int value; |
| 142 | } gpt; |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 143 | struct track_ctr_prm trk_ctr; |
Thierry FOURNIER | f8c1dce | 2015-07-30 19:12:50 +0200 | [diff] [blame] | 144 | struct { |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 145 | void *p[4]; |
| 146 | } act; /* generic pointers to be used by custom actions */ |
| 147 | } arg; /* arguments used by some actions */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 150 | struct action_kw { |
| 151 | const char *kw; |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 152 | enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px, |
| 153 | struct act_rule *rule, char **err); |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 154 | int match_pfx; |
| 155 | }; |
| 156 | |
| 157 | struct action_kw_list { |
| 158 | struct list list; |
| 159 | struct action_kw kw[VAR_ARRAY]; |
| 160 | }; |
| 161 | |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 162 | #endif /* _TYPES_ACTION_H */ |