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