~ubuntu-branches/debian/stretch/haproxy/stretch

« back to all changes in this revision

Viewing changes to include/types/acl.h

  • Committer: Package Import Robot
  • Author(s): Apollon Oikonomopoulos
  • Date: 2014-06-20 11:05:17 UTC
  • mfrom: (1.1.15) (15.1.12 experimental)
  • Revision ID: package-import@ubuntu.com-20140620110517-u6q5p9kyy2f3ozw9
Tags: 1.5.0-1
* New upstream stable series. Notable changes since the 1.4 series:
  + Native SSL support on both sides with SNI/NPN/ALPN and OCSP stapling.
  + IPv6 and UNIX sockets are supported everywhere
  + End-to-end HTTP keep-alive for better support of NTLM and improved
    efficiency in static farms
  + HTTP/1.1 response compression (deflate, gzip) to save bandwidth
  + PROXY protocol versions 1 and 2 on both sides
  + Data sampling on everything in request or response, including payload
  + ACLs can use any matching method with any input sample
  + Maps and dynamic ACLs updatable from the CLI
  + Stick-tables support counters to track activity on any input sample
  + Custom format for logs, unique-id, header rewriting, and redirects
  + Improved health checks (SSL, scripted TCP, check agent, ...)
  + Much more scalable configuration supports hundreds of thousands of
    backends and certificates without sweating

* Upload to unstable, merge all 1.5 work from experimental. Most important
  packaging changes since 1.4.25-1 include:
  + systemd support.
  + A more sane default config file.
  + Zero-downtime upgrades between 1.5 releases by gracefully reloading
    HAProxy during upgrades.
  + HTML documentation shipped in the haproxy-doc package.
  + kqueue support for kfreebsd.

* Packaging changes since 1.5~dev26-2:
  + Drop patches merged upstream:
    o Fix-reference-location-in-manpage.patch
    o 0001-BUILD-stats-workaround-stupid-and-bogus-Werror-forma.patch
  + d/watch: look for stable 1.5 releases
  + systemd: respect CONFIG and EXTRAOPTS when specified in
    /etc/default/haproxy.
  + initscript: test the configuration before start or reload.
  + initscript: remove the ENABLED flag and logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * include/types/acl.h
3
3
 * This file provides structures and types for ACLs.
4
4
 *
5
 
 * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
 
5
 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
6
6
 *
7
7
 * This library is free software; you can redistribute it and/or
8
8
 * modify it under the terms of the GNU Lesser General Public
26
26
#include <common/config.h>
27
27
#include <common/mini-clist.h>
28
28
 
 
29
#include <types/arg.h>
29
30
#include <types/auth.h>
 
31
#include <types/pattern.h>
30
32
#include <types/proxy.h>
31
33
#include <types/server.h>
32
34
#include <types/session.h>
33
35
 
34
36
#include <ebmbtree.h>
35
37
 
36
 
/* Pattern matching function result.
 
38
/* ACL test result.
37
39
 *
38
40
 * We're using a 3-state matching system :
39
41
 *   - PASS : at least one pattern already matches
51
53
 *
52
54
 *  neg(x) = (3 >> x)       and(x,y) = (x & y)           or(x,y) = (x | y)
53
55
 *
 
56
 * For efficiency, the ACL return flags are directly mapped from the pattern
 
57
 * match flags. See include/pattern.h for existing values.
54
58
 */
55
 
 
56
 
enum {
57
 
        ACL_PAT_FAIL = 0,           /* test failed */
58
 
        ACL_PAT_MISS = 1,           /* test may pass with more info */
59
 
        ACL_PAT_PASS = 3,           /* test passed */
 
59
enum acl_test_res {
 
60
        ACL_TEST_FAIL = 0,           /* test failed */
 
61
        ACL_TEST_MISS = 1,           /* test may pass with more info */
 
62
        ACL_TEST_PASS = 3,           /* test passed */
60
63
};
61
64
 
62
65
/* Condition polarity. It makes it easier for any option to choose between
63
66
 * IF/UNLESS if it can store that information within the condition itself.
64
67
 * Those should be interpreted as "IF/UNLESS result == PASS".
65
68
 */
66
 
enum {
 
69
enum acl_cond_pol {
67
70
        ACL_COND_NONE,          /* no polarity set yet */
68
71
        ACL_COND_IF,            /* positive condition (after 'if') */
69
72
        ACL_COND_UNLESS,        /* negative condition (after 'unless') */
70
73
};
71
74
 
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),
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) */
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 */
90
 
        ACL_TEST_F_NULL_MATCH = 1 << 11,/* call expr->kw->match with NULL pattern if expr->patterns is empty */
91
 
};
92
 
 
93
 
/* ACLs can be evaluated on requests and on responses, and on partial or complete data */
94
 
enum {
95
 
        ACL_DIR_REQ = 0,        /* ACL evaluated on request */
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 */
99
 
};
100
 
 
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 */
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 */
107
 
};
108
 
 
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 {
113
 
        ACL_USE_NOTHING         = 0,            /* no need for anything beyond internal information */
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
 
 
129
 
        ACL_USE_L4REQ_PERMANENT = 1 <<  9,      /* unchanged layer4 request data */
130
 
        ACL_USE_L4REQ_CACHEABLE = 1 << 10,      /* cacheable layer4 request data (eg: length) */
131
 
        ACL_USE_L4REQ_VOLATILE  = 1 << 11,      /* volatile  layer4 request data (eg: contents) */
132
 
        ACL_USE_L4REQ_ANY       = (ACL_USE_L4REQ_PERMANENT | ACL_USE_L4REQ_CACHEABLE | ACL_USE_L4REQ_VOLATILE),
133
 
 
134
 
        ACL_USE_L4RTR_PERMANENT = 1 << 12,      /* unchanged layer4 response data */
135
 
        ACL_USE_L4RTR_CACHEABLE = 1 << 13,      /* cacheable layer4 response data (eg: length) */
136
 
        ACL_USE_L4RTR_VOLATILE  = 1 << 14,      /* volatile  layer4 response data (eg: contents) */
137
 
        ACL_USE_L4RTR_ANY       = (ACL_USE_L4RTR_PERMANENT | ACL_USE_L4RTR_CACHEABLE | ACL_USE_L4RTR_VOLATILE),
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
 
 
154
 
        /* information which remains during response */
155
 
        ACL_USE_REQ_PERMANENT   = (ACL_USE_TCP4_PERMANENT | ACL_USE_TCP6_PERMANENT | ACL_USE_TCP_PERMANENT |
156
 
                                   ACL_USE_L4REQ_PERMANENT | ACL_USE_L7REQ_PERMANENT),
157
 
        ACL_USE_REQ_CACHEABLE   = (ACL_USE_TCP4_CACHEABLE | ACL_USE_TCP6_CACHEABLE | ACL_USE_TCP_CACHEABLE |
158
 
                                   ACL_USE_L4REQ_CACHEABLE | ACL_USE_L7REQ_CACHEABLE | ACL_USE_HDR_CACHEABLE),
159
 
 
160
 
        /* information which does not remain during response */
161
 
        ACL_USE_REQ_VOLATILE    = (ACL_USE_TCP4_VOLATILE | ACL_USE_TCP6_VOLATILE | ACL_USE_TCP_VOLATILE |
162
 
                                   ACL_USE_L4REQ_VOLATILE | ACL_USE_L7REQ_VOLATILE),
163
 
 
164
 
        /* any type of layer 4 contents information */
165
 
        ACL_USE_L4_ANY          = (ACL_USE_L4REQ_ANY | ACL_USE_L4RTR_ANY),
166
 
 
167
 
        /* any type of layer 7 information */
168
 
        ACL_USE_L7_ANY          = (ACL_USE_L7REQ_ANY | ACL_USE_L7RTR_ANY | ACL_USE_HDR_ANY),
169
 
 
170
 
        /* any type of response information */
171
 
        ACL_USE_RTR_ANY         = (ACL_USE_L4RTR_ANY | ACL_USE_L7RTR_ANY),
172
 
 
173
 
        /* some flags indicating if a keyword supports exact pattern matching,
174
 
         * so that patterns may be arranged in lookup trees. Let's put those
175
 
         * flags at the end to leave some space for the other ones above.
176
 
         */
177
 
        ACL_MAY_LOOKUP          =  1 << 31,  /* exact pattern lookup */
178
 
};
179
 
 
180
 
/* filtering hooks */
181
 
enum {
182
 
        /* hooks on the request path */
183
 
        ACL_HOOK_REQ_FE_TCP = 0,
184
 
        ACL_HOOK_REQ_FE_TCP_CONTENT,
185
 
        ACL_HOOK_REQ_FE_HTTP_IN,
186
 
        ACL_HOOK_REQ_FE_SWITCH,
187
 
        ACL_HOOK_REQ_BE_TCP_CONTENT,
188
 
        ACL_HOOK_REQ_BE_HTTP_IN,
189
 
        ACL_HOOK_REQ_BE_SWITCH,
190
 
        ACL_HOOK_REQ_FE_HTTP_OUT,
191
 
        ACL_HOOK_REQ_BE_HTTP_OUT,
192
 
        /* hooks on the response path */
193
 
        ACL_HOOK_RTR_BE_TCP_CONTENT,
194
 
        ACL_HOOK_RTR_BE_HTTP_IN,
195
 
        ACL_HOOK_RTR_FE_TCP_CONTENT,
196
 
        ACL_HOOK_RTR_FE_HTTP_IN,
197
 
        ACL_HOOK_RTR_BE_HTTP_OUT,
198
 
        ACL_HOOK_RTR_FE_HTTP_OUT,
199
 
};
200
 
 
201
 
/* How to store a time range and the valid days in 29 bits */
202
 
struct acl_time {
203
 
        int dow:7;              /* 1 bit per day of week: 0-6 */
204
 
        int h1:5, m1:6;         /* 0..24:0..60. Use 0:0 for all day. */
205
 
        int h2:5, m2:6;         /* 0..24:0..60. Use 24:0 for all day. */
206
 
};
207
 
 
208
 
/* The acl will be linked to from the proxy where it is declared */
209
 
struct acl_pattern {
210
 
        struct list list;                       /* chaining */
211
 
        union {
212
 
                int i;                          /* integer value */
213
 
                struct {
214
 
                        signed long long min, max;
215
 
                        int min_set :1;
216
 
                        int max_set :1;
217
 
                } range; /* integer range */
218
 
                struct {
219
 
                        struct in_addr addr;
220
 
                        struct in_addr mask;
221
 
                } ipv4;                         /* IPv4 address */
222
 
                struct acl_time time;           /* valid hours and days */
223
 
                unsigned int group_mask;
224
 
                struct eb_root *tree;           /* tree storing all values if any */
225
 
        } val;                                  /* direct value */
226
 
        union {
227
 
                void *ptr;              /* any data */
228
 
                char *str;              /* any string  */
229
 
                regex_t *reg;           /* a compiled regex */
230
 
        } ptr;                          /* indirect values, allocated */
231
 
        void(*freeptrbuf)(void *ptr);   /* a destructor able to free objects from the ptr */
232
 
        int len;                        /* data length when required  */
233
 
        int flags;                      /* expr or pattern flags. */
234
 
};
235
 
 
236
 
/* The structure exchanged between an acl_fetch_* function responsible for
237
 
 * retrieving a value, and an acl_match_* function responsible for testing it.
238
 
 */
239
 
struct acl_test {
240
 
        int i;                  /* integer value */
241
 
        char *ptr;              /* pointer to beginning of value */
242
 
        int len;                /* length of value at ptr, otherwise ignored */
243
 
        int flags;              /* ACL_TEST_F_* set to 0 on first call */
244
 
        union {                 /* fetch_* functions context for any purpose */
245
 
                void *p;        /* any pointer */
246
 
                int i;          /* any integer */
247
 
                long long ll;   /* any long long or smaller */
248
 
                double d;       /* any float or double */
249
 
                void *a[8];     /* any array of up to 8 pointers */
250
 
        } ctx;
251
 
};
252
 
 
253
 
 
254
 
/*
255
 
 * ACL keyword: Associates keywords with parsers, methods to retrieve the value and testers.
256
 
 */
257
 
 
258
75
/* some dummy declarations to silent the compiler */
259
76
struct proxy;
260
77
struct session;
261
78
 
262
79
/*
 
80
 * ACL keyword: Associates keywords with parsers, methods to retrieve the value and testers.
 
81
 */
 
82
/*
263
83
 * NOTE:
264
84
 * The 'parse' function is called to parse words in the configuration. It must
265
85
 * return the number of valid words read. 0 = error. The 'opaque' argument may
271
91
struct acl_expr;
272
92
struct acl_keyword {
273
93
        const char *kw;
274
 
        int (*parse)(const char **text, struct acl_pattern *pattern, int *opaque);
275
 
        int (*fetch)(struct proxy *px, struct session *l4, void *l7, int dir,
276
 
                     struct acl_expr *expr, struct acl_test *test);
277
 
        int (*match)(struct acl_test *test, struct acl_pattern *pattern);
278
 
        unsigned int requires;   /* bit mask of all ACL_USE_* required to evaluate this keyword */
279
 
        int use_cnt;
 
94
        char *fetch_kw;
 
95
        int match_type; /* Contain PAT_MATCH_* */
 
96
        int (*parse)(const char *text, struct pattern *pattern, int flags, char **err);
 
97
        int (*index)(struct pattern_expr *expr, struct pattern *pattern, char **err);
 
98
        void (*delete)(struct pattern_expr *expr, struct pat_ref_elt *);
 
99
        void (*prune)(struct pattern_expr *expr);
 
100
        struct pattern *(*match)(struct sample *smp, struct pattern_expr *expr, int fill);
 
101
        /* must be after the config params */
 
102
        struct sample_fetch *smp; /* the sample fetch we depend on */
280
103
};
281
104
 
282
105
/*
292
115
 
293
116
/*
294
117
 * Description of an ACL expression.
295
 
 * It contains a subject and a set of patterns to test against it.
296
 
 *  - the function get() is called to retrieve the subject from the
297
 
 *    current session or transaction and build a test.
298
 
 *  - the function test() is called to evaluate the test based on the
299
 
 *    available patterns and return ACL_PAT_*
300
 
 * Both of those functions are available through the keyword.
 
118
 * The expression is part of a list. It contains pointers to the keyword, the
 
119
 * sample fetch descriptor which defaults to the keyword's, and the associated
 
120
 * pattern matching. The structure is organized so that the hot parts are
 
121
 * grouped together in order to optimize caching.
301
122
 */
302
123
struct acl_expr {
303
 
        struct list list;           /* chaining */
304
 
        struct acl_keyword *kw;     /* back-reference to the keyword */
305
 
        union {                     /* optional argument of the subject (eg: header or cookie name) */
306
 
                char *str;
307
 
                struct userlist *ul;
308
 
                struct server *srv;
309
 
        } arg;
310
 
        int arg_len;                /* optional argument length */
311
 
        struct list patterns;       /* list of acl_patterns */
312
 
        struct eb_root pattern_tree;  /* may be used for lookup in large datasets */
 
124
        struct sample_expr *smp;      /* the sample expression we depend on */
 
125
        struct pattern_head pat;      /* the pattern matching expression */
 
126
        struct list list;             /* chaining */
 
127
        const char *kw;               /* points to the ACL kw's name or fetch's name (must not free) */
313
128
};
314
129
 
 
130
/* The acl will be linked to from the proxy where it is declared */
315
131
struct acl {
316
132
        struct list list;           /* chaining */
317
133
        char *name;                 /* acl name */
318
134
        struct list expr;           /* list of acl_exprs */
319
135
        int cache_idx;              /* ACL index in cache */
320
 
        unsigned int requires;      /* or'ed bit mask of all acl_expr's ACL_USE_* */
 
136
        unsigned int use;           /* or'ed bit mask of all acl_expr's SMP_USE_* */
 
137
        unsigned int val;           /* or'ed bit mask of all acl_expr's SMP_VAL_* */
321
138
};
322
139
 
323
140
/* the condition will be linked to from an action in a proxy */
335
152
struct acl_cond {
336
153
        struct list list;           /* Some specific tests may use multiple conditions */
337
154
        struct list suites;         /* list of acl_term_suites */
338
 
        int pol;                    /* polarity: ACL_COND_IF / ACL_COND_UNLESS */
339
 
        unsigned int requires;      /* or'ed bit mask of all acl's ACL_USE_* */
 
155
        enum acl_cond_pol pol;      /* polarity: ACL_COND_IF / ACL_COND_UNLESS */
 
156
        unsigned int use;           /* or'ed bit mask of all suites's SMP_USE_* */
 
157
        unsigned int val;           /* or'ed bit mask of all suites's SMP_VAL_* */
340
158
        const char *file;           /* config file where the condition is declared */
341
159
        int line;                   /* line in the config file where the condition is declared */
342
160
};
343
161
 
344
 
 
345
162
#endif /* _TYPES_ACL_H */
346
163
 
347
164
/*