Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 2 | * include/types/acl.h |
| 3 | * This file provides structures and types for ACLs. |
| 4 | * |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 5 | * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 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 | */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 21 | |
| 22 | #ifndef _TYPES_ACL_H |
| 23 | #define _TYPES_ACL_H |
| 24 | |
| 25 | #include <common/compat.h> |
| 26 | #include <common/config.h> |
| 27 | #include <common/mini-clist.h> |
| 28 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 29 | #include <types/arg.h> |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 30 | #include <types/auth.h> |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 31 | #include <types/proxy.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 32 | #include <types/sample.h> |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 33 | #include <types/server.h> |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 34 | #include <types/session.h> |
| 35 | |
Willy Tarreau | 438b0f3 | 2010-05-10 22:29:06 +0200 | [diff] [blame] | 36 | #include <ebmbtree.h> |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 37 | |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 38 | /* Pattern matching function result. |
| 39 | * |
| 40 | * We're using a 3-state matching system : |
| 41 | * - PASS : at least one pattern already matches |
| 42 | * - MISS : some data is missing to decide if some rules may finally match. |
| 43 | * - FAIL : no mattern may ever match |
| 44 | * |
| 45 | * We assign values 0, 1 and 3 to FAIL, MISS and PASS respectively, so that we |
| 46 | * can make use of standard arithmetics for the truth tables below : |
| 47 | * |
| 48 | * x | !x x&y | F(0) | M(1) | P(3) x|y | F(0) | M(1) | P(3) |
| 49 | * ------+----- -----+------+------+----- -----+------+------+----- |
| 50 | * F(0) | P(3) F(0)| F(0) | F(0) | F(0) F(0)| F(0) | M(1) | P(3) |
| 51 | * M(1) | M(1) M(1)| F(0) | M(1) | M(1) M(1)| M(1) | M(1) | P(3) |
| 52 | * P(3) | F(0) P(3)| F(0) | M(1) | P(3) P(3)| P(3) | P(3) | P(3) |
| 53 | * |
| 54 | * neg(x) = (3 >> x) and(x,y) = (x & y) or(x,y) = (x | y) |
| 55 | * |
| 56 | */ |
| 57 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 58 | enum { |
| 59 | ACL_PAT_FAIL = 0, /* test failed */ |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 60 | ACL_PAT_MISS = 1, /* test may pass with more info */ |
| 61 | ACL_PAT_PASS = 3, /* test passed */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* Condition polarity. It makes it easier for any option to choose between |
| 65 | * IF/UNLESS if it can store that information within the condition itself. |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 66 | * Those should be interpreted as "IF/UNLESS result == PASS". |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 67 | */ |
| 68 | enum { |
| 69 | ACL_COND_NONE, /* no polarity set yet */ |
| 70 | ACL_COND_IF, /* positive condition (after 'if') */ |
| 71 | ACL_COND_UNLESS, /* negative condition (after 'unless') */ |
| 72 | }; |
| 73 | |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 74 | /* possible flags for expressions or patterns */ |
| 75 | enum { |
| 76 | ACL_PAT_F_IGNORE_CASE = 1 << 0, /* ignore case */ |
| 77 | ACL_PAT_F_FROM_FILE = 1 << 1, /* pattern comes from a file */ |
Willy Tarreau | 438b0f3 | 2010-05-10 22:29:06 +0200 | [diff] [blame] | 78 | ACL_PAT_F_TREE_OK = 1 << 2, /* the pattern parser is allowed to build a tree */ |
| 79 | ACL_PAT_F_TREE = 1 << 3, /* some patterns are arranged in a tree */ |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 82 | /* what capabilities an ACL uses. These flags are set during parsing, which |
| 83 | * allows for flexible ACLs typed by their contents. |
| 84 | */ |
| 85 | enum { |
Willy Tarreau | 0ceba5a | 2008-07-25 19:31:03 +0200 | [diff] [blame] | 86 | ACL_USE_NOTHING = 0, /* no need for anything beyond internal information */ |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 87 | ACL_USE_TCP4_PERMANENT = 1 << 0, /* unchanged TCPv4 data (eg: source IP) */ |
| 88 | ACL_USE_TCP4_CACHEABLE = 1 << 1, /* cacheable TCPv4 data (eg: src conns) */ |
| 89 | ACL_USE_TCP4_VOLATILE = 1 << 2, /* volatile TCPv4 data (eg: RTT) */ |
| 90 | ACL_USE_TCP4_ANY = (ACL_USE_TCP4_PERMANENT | ACL_USE_TCP4_CACHEABLE | ACL_USE_TCP4_VOLATILE), |
| 91 | |
| 92 | ACL_USE_TCP6_PERMANENT = 1 << 3, /* unchanged TCPv6 data (eg: source IP) */ |
| 93 | ACL_USE_TCP6_CACHEABLE = 1 << 4, /* cacheable TCPv6 data (eg: src conns) */ |
| 94 | ACL_USE_TCP6_VOLATILE = 1 << 5, /* volatile TCPv6 data (eg: RTT) */ |
| 95 | ACL_USE_TCP6_ANY = (ACL_USE_TCP6_PERMANENT | ACL_USE_TCP6_CACHEABLE | ACL_USE_TCP6_VOLATILE), |
| 96 | |
| 97 | ACL_USE_TCP_PERMANENT = 1 << 6, /* unchanged TCPv4/v6 data (eg: source IP) */ |
| 98 | ACL_USE_TCP_CACHEABLE = 1 << 7, /* cacheable TCPv4/v6 data (eg: src conns) */ |
| 99 | ACL_USE_TCP_VOLATILE = 1 << 8, /* volatile TCPv4/v6 data (eg: RTT) */ |
| 100 | ACL_USE_TCP_ANY = (ACL_USE_TCP_PERMANENT | ACL_USE_TCP_CACHEABLE | ACL_USE_TCP_VOLATILE), |
| 101 | |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 102 | ACL_USE_L6REQ_PERMANENT = 1 << 9, /* unchanged layer6 request data */ |
| 103 | ACL_USE_L6REQ_CACHEABLE = 1 << 10, /* cacheable layer6 request data (eg: length) */ |
| 104 | ACL_USE_L6REQ_VOLATILE = 1 << 11, /* volatile layer6 request data (eg: contents) */ |
| 105 | ACL_USE_L6REQ_ANY = (ACL_USE_L6REQ_PERMANENT | ACL_USE_L6REQ_CACHEABLE | ACL_USE_L6REQ_VOLATILE), |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 106 | |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 107 | ACL_USE_L6RTR_PERMANENT = 1 << 12, /* unchanged layer6 response data */ |
| 108 | ACL_USE_L6RTR_CACHEABLE = 1 << 13, /* cacheable layer6 response data (eg: length) */ |
| 109 | ACL_USE_L6RTR_VOLATILE = 1 << 14, /* volatile layer6 response data (eg: contents) */ |
| 110 | ACL_USE_L6RTR_ANY = (ACL_USE_L6RTR_PERMANENT | ACL_USE_L6RTR_CACHEABLE | ACL_USE_L6RTR_VOLATILE), |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 111 | |
| 112 | ACL_USE_L7REQ_PERMANENT = 1 << 15, /* unchanged layer7 request data (eg: method) */ |
| 113 | ACL_USE_L7REQ_CACHEABLE = 1 << 16, /* cacheable layer7 request data (eg: content-length) */ |
| 114 | ACL_USE_L7REQ_VOLATILE = 1 << 17, /* volatile layer7 request data (eg: cookie) */ |
| 115 | ACL_USE_L7REQ_ANY = (ACL_USE_L7REQ_PERMANENT | ACL_USE_L7REQ_CACHEABLE | ACL_USE_L7REQ_VOLATILE), |
| 116 | |
| 117 | ACL_USE_L7RTR_PERMANENT = 1 << 18, /* unchanged layer7 response data (eg: status) */ |
| 118 | ACL_USE_L7RTR_CACHEABLE = 1 << 19, /* cacheable layer7 response data (eg: content-length) */ |
| 119 | ACL_USE_L7RTR_VOLATILE = 1 << 20, /* volatile layer7 response data (eg: cookie) */ |
| 120 | ACL_USE_L7RTR_ANY = (ACL_USE_L7RTR_PERMANENT | ACL_USE_L7RTR_CACHEABLE | ACL_USE_L7RTR_VOLATILE), |
| 121 | |
| 122 | /* those ones are used for ambiguous "hdr_xxx" verbs */ |
| 123 | ACL_USE_HDR_CACHEABLE = 1 << 21, /* cacheable request or response header (eg: content-length) */ |
| 124 | ACL_USE_HDR_VOLATILE = 1 << 22, /* volatile request or response header (eg: cookie) */ |
| 125 | ACL_USE_HDR_ANY = (ACL_USE_HDR_CACHEABLE | ACL_USE_HDR_VOLATILE), |
| 126 | |
Willy Tarreau | 930bd6b | 2011-02-23 15:17:24 +0100 | [diff] [blame] | 127 | /* This one indicates that we need an internal parameter known in the response only */ |
| 128 | ACL_USE_RTR_INTERNAL = 1 << 23, /* volatile response information */ |
| 129 | |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 130 | /* information which remains during response */ |
| 131 | ACL_USE_REQ_PERMANENT = (ACL_USE_TCP4_PERMANENT | ACL_USE_TCP6_PERMANENT | ACL_USE_TCP_PERMANENT | |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 132 | ACL_USE_L6REQ_PERMANENT | ACL_USE_L7REQ_PERMANENT), |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 133 | ACL_USE_REQ_CACHEABLE = (ACL_USE_TCP4_CACHEABLE | ACL_USE_TCP6_CACHEABLE | ACL_USE_TCP_CACHEABLE | |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 134 | ACL_USE_L6REQ_CACHEABLE | ACL_USE_L7REQ_CACHEABLE | ACL_USE_HDR_CACHEABLE), |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 135 | |
| 136 | /* information which does not remain during response */ |
| 137 | ACL_USE_REQ_VOLATILE = (ACL_USE_TCP4_VOLATILE | ACL_USE_TCP6_VOLATILE | ACL_USE_TCP_VOLATILE | |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 138 | ACL_USE_L6REQ_VOLATILE | ACL_USE_L7REQ_VOLATILE), |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 139 | |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 140 | /* any type of layer 6 contents information (random data available in a buffer) */ |
| 141 | ACL_USE_L6_ANY = (ACL_USE_L6REQ_ANY | ACL_USE_L6RTR_ANY), |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 142 | |
| 143 | /* any type of layer 7 information */ |
| 144 | ACL_USE_L7_ANY = (ACL_USE_L7REQ_ANY | ACL_USE_L7RTR_ANY | ACL_USE_HDR_ANY), |
| 145 | |
| 146 | /* any type of response information */ |
Willy Tarreau | 930bd6b | 2011-02-23 15:17:24 +0100 | [diff] [blame] | 147 | ACL_USE_RTR_ANY = (ACL_USE_L6RTR_ANY | ACL_USE_L7RTR_ANY | ACL_USE_RTR_INTERNAL), |
Willy Tarreau | 438b0f3 | 2010-05-10 22:29:06 +0200 | [diff] [blame] | 148 | |
| 149 | /* some flags indicating if a keyword supports exact pattern matching, |
| 150 | * so that patterns may be arranged in lookup trees. Let's put those |
| 151 | * flags at the end to leave some space for the other ones above. |
| 152 | */ |
| 153 | ACL_MAY_LOOKUP = 1 << 31, /* exact pattern lookup */ |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | /* filtering hooks */ |
| 157 | enum { |
| 158 | /* hooks on the request path */ |
| 159 | ACL_HOOK_REQ_FE_TCP = 0, |
| 160 | ACL_HOOK_REQ_FE_TCP_CONTENT, |
| 161 | ACL_HOOK_REQ_FE_HTTP_IN, |
| 162 | ACL_HOOK_REQ_FE_SWITCH, |
| 163 | ACL_HOOK_REQ_BE_TCP_CONTENT, |
| 164 | ACL_HOOK_REQ_BE_HTTP_IN, |
| 165 | ACL_HOOK_REQ_BE_SWITCH, |
| 166 | ACL_HOOK_REQ_FE_HTTP_OUT, |
| 167 | ACL_HOOK_REQ_BE_HTTP_OUT, |
| 168 | /* hooks on the response path */ |
| 169 | ACL_HOOK_RTR_BE_TCP_CONTENT, |
| 170 | ACL_HOOK_RTR_BE_HTTP_IN, |
| 171 | ACL_HOOK_RTR_FE_TCP_CONTENT, |
| 172 | ACL_HOOK_RTR_FE_HTTP_IN, |
| 173 | ACL_HOOK_RTR_BE_HTTP_OUT, |
| 174 | ACL_HOOK_RTR_FE_HTTP_OUT, |
| 175 | }; |
| 176 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 177 | /* How to store a time range and the valid days in 29 bits */ |
| 178 | struct acl_time { |
| 179 | int dow:7; /* 1 bit per day of week: 0-6 */ |
| 180 | int h1:5, m1:6; /* 0..24:0..60. Use 0:0 for all day. */ |
| 181 | int h2:5, m2:6; /* 0..24:0..60. Use 24:0 for all day. */ |
| 182 | }; |
| 183 | |
Willy Tarreau | c92ddbc | 2012-04-27 22:10:57 +0200 | [diff] [blame] | 184 | /* This describes one ACL pattern, which might be a single value or a tree of |
| 185 | * values. All patterns for a single ACL expression are linked together. Some |
| 186 | * of them might have a type (eg: IP). Right now, the types are shared with |
| 187 | * the samples, though it is possible that in the future this will change to |
| 188 | * accommodate for other types (eg: meth, regex). Unsigned and constant types |
| 189 | * are preferred when there is a doubt. |
| 190 | */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 191 | struct acl_pattern { |
| 192 | struct list list; /* chaining */ |
Willy Tarreau | c92ddbc | 2012-04-27 22:10:57 +0200 | [diff] [blame] | 193 | int type; /* type of the ACL pattern (SMP_T_*) */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 194 | union { |
| 195 | int i; /* integer value */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 196 | struct { |
| 197 | signed long long min, max; |
| 198 | int min_set :1; |
| 199 | int max_set :1; |
| 200 | } range; /* integer range */ |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 201 | struct { |
| 202 | struct in_addr addr; |
| 203 | struct in_addr mask; |
| 204 | } ipv4; /* IPv4 address */ |
Willy Tarreau | ceb4ac9 | 2012-04-28 00:41:46 +0200 | [diff] [blame] | 205 | struct { |
| 206 | struct in6_addr addr; |
| 207 | unsigned char mask; /* number of bits */ |
| 208 | } ipv6; /* IPv6 address/mask */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 209 | struct acl_time time; /* valid hours and days */ |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 210 | unsigned int group_mask; |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 211 | struct eb_root *tree; /* tree storing all values if any */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 212 | } val; /* direct value */ |
| 213 | union { |
| 214 | void *ptr; /* any data */ |
| 215 | char *str; /* any string */ |
| 216 | regex_t *reg; /* a compiled regex */ |
| 217 | } ptr; /* indirect values, allocated */ |
Krzysztof Piotr Oledzki | 8001d61 | 2008-05-31 13:53:23 +0200 | [diff] [blame] | 218 | void(*freeptrbuf)(void *ptr); /* a destructor able to free objects from the ptr */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 219 | int len; /* data length when required */ |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 220 | int flags; /* expr or pattern flags. */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 223 | /* some dummy declarations to silent the compiler */ |
| 224 | struct proxy; |
| 225 | struct session; |
| 226 | |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 227 | /* |
Willy Tarreau | c92ddbc | 2012-04-27 22:10:57 +0200 | [diff] [blame] | 228 | * ACL keyword: Associates keywords with parsers, methods to retrieve the value and testers. |
| 229 | */ |
| 230 | /* |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 231 | * NOTE: |
| 232 | * The 'parse' function is called to parse words in the configuration. It must |
| 233 | * return the number of valid words read. 0 = error. The 'opaque' argument may |
| 234 | * be used by functions which need to maintain a context between consecutive |
| 235 | * values. It is initialized to zero before the first call, and passed along |
| 236 | * successive calls. |
| 237 | */ |
| 238 | |
Willy Tarreau | 97be145 | 2007-06-10 11:47:14 +0200 | [diff] [blame] | 239 | struct acl_expr; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 240 | struct acl_keyword { |
| 241 | const char *kw; |
Willy Tarreau | 7dcb648 | 2012-04-27 17:52:25 +0200 | [diff] [blame] | 242 | int (*parse)(const char **text, struct acl_pattern *pattern, int *opaque, char **err); |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 243 | int (*fetch)(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 244 | const struct arg *args, struct sample *smp); |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 245 | int (*match)(struct sample *smp, struct acl_pattern *pattern); |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 246 | unsigned int requires; /* bit mask of all ACL_USE_* required to evaluate this keyword */ |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 247 | int arg_mask; /* mask describing up to 7 arg types */ |
Willy Tarreau | ae52f06 | 2012-04-26 12:13:35 +0200 | [diff] [blame] | 248 | int (*val_args)(struct arg *arg_p, char **err_msg); /* argument validation function */ |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 249 | /* must be after the config params */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 250 | int use_cnt; |
| 251 | }; |
| 252 | |
| 253 | /* |
| 254 | * A keyword list. It is a NULL-terminated array of keywords. It embeds a |
| 255 | * struct list in order to be linked to other lists, allowing it to easily |
| 256 | * be declared where it is needed, and linked without duplicating data nor |
| 257 | * allocating memory. |
| 258 | */ |
| 259 | struct acl_kw_list { |
| 260 | struct list list; |
| 261 | struct acl_keyword kw[VAR_ARRAY]; |
| 262 | }; |
| 263 | |
| 264 | /* |
| 265 | * Description of an ACL expression. |
| 266 | * It contains a subject and a set of patterns to test against it. |
| 267 | * - the function get() is called to retrieve the subject from the |
| 268 | * current session or transaction and build a test. |
| 269 | * - the function test() is called to evaluate the test based on the |
| 270 | * available patterns and return ACL_PAT_* |
| 271 | * Both of those functions are available through the keyword. |
| 272 | */ |
| 273 | struct acl_expr { |
| 274 | struct list list; /* chaining */ |
| 275 | struct acl_keyword *kw; /* back-reference to the keyword */ |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 276 | struct arg *args; /* optional argument list (eg: header or cookie name) */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 277 | struct list patterns; /* list of acl_patterns */ |
Willy Tarreau | 438b0f3 | 2010-05-10 22:29:06 +0200 | [diff] [blame] | 278 | struct eb_root pattern_tree; /* may be used for lookup in large datasets */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 279 | }; |
| 280 | |
Willy Tarreau | c92ddbc | 2012-04-27 22:10:57 +0200 | [diff] [blame] | 281 | /* The acl will be linked to from the proxy where it is declared */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 282 | struct acl { |
| 283 | struct list list; /* chaining */ |
| 284 | char *name; /* acl name */ |
| 285 | struct list expr; /* list of acl_exprs */ |
| 286 | int cache_idx; /* ACL index in cache */ |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 287 | unsigned int requires; /* or'ed bit mask of all acl_expr's ACL_USE_* */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | /* the condition will be linked to from an action in a proxy */ |
| 291 | struct acl_term { |
| 292 | struct list list; /* chaining */ |
| 293 | struct acl *acl; /* acl pointed to by this term */ |
| 294 | int neg; /* 1 if the ACL result must be negated */ |
| 295 | }; |
| 296 | |
| 297 | struct acl_term_suite { |
| 298 | struct list list; /* chaining of term suites */ |
| 299 | struct list terms; /* list of acl_terms */ |
| 300 | }; |
| 301 | |
| 302 | struct acl_cond { |
| 303 | struct list list; /* Some specific tests may use multiple conditions */ |
| 304 | struct list suites; /* list of acl_term_suites */ |
| 305 | int pol; /* polarity: ACL_COND_IF / ACL_COND_UNLESS */ |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 306 | unsigned int requires; /* or'ed bit mask of all acl's ACL_USE_* */ |
Willy Tarreau | 8892235 | 2009-10-04 22:02:50 +0200 | [diff] [blame] | 307 | const char *file; /* config file where the condition is declared */ |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 308 | int line; /* line in the config file where the condition is declared */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | |
| 312 | #endif /* _TYPES_ACL_H */ |
| 313 | |
| 314 | /* |
| 315 | * Local variables: |
| 316 | * c-indent-level: 8 |
| 317 | * c-basic-offset: 8 |
| 318 | * End: |
| 319 | */ |