blob: c37959564b454d3aae7b15869fff5ccf249fa545 [file] [log] [blame]
Emeric Brun107ca302010-01-04 16:16:05 +01001/*
2 * include/types/pattern.h
3 * Macros, variables and structures for patterns management.
4 *
5 * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
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_PATTERN_H
23#define _TYPES_PATTERN_H
24
Emeric Brun107ca302010-01-04 16:16:05 +010025#include <sys/socket.h>
26#include <netinet/in.h>
Willy Tarreauecfb8e82012-04-20 12:29:52 +020027#include <types/arg.h>
28#include <types/buffers.h>
Emeric Brun107ca302010-01-04 16:16:05 +010029
Willy Tarreau422aa072012-04-20 20:49:27 +020030/* input and output sample types */
Emeric Brun107ca302010-01-04 16:16:05 +010031enum {
Willy Tarreau422aa072012-04-20 20:49:27 +020032 SMP_T_BOOL = 0, /* boolean */
33 SMP_T_UINT, /* unsigned 32bits integer type */
34 SMP_T_SINT, /* signed 32bits integer type */
35 SMP_T_IPV4, /* ipv4 type */
36 SMP_T_IPV6, /* ipv6 type */
37 SMP_T_STR, /* char string type */
38 SMP_T_BIN, /* buffer type */
39 SMP_T_CSTR, /* constant char string type, data need dup before conversion */
40 SMP_T_CBIN, /* constant buffer type, data need dup before conversion */
41 SMP_TYPES /* number of types, must always be last */
Emeric Brun107ca302010-01-04 16:16:05 +010042};
43
Willy Tarreau16c31b02012-04-23 14:24:58 +020044/* Flags used to describe fetched samples. MAY_CHANGE indicates that the result
45 * of the fetch might still evolve, for instance because of more data expected,
46 * even if the fetch has failed. VOL_* indicates how long a result may be cached.
47 */
48enum {
49 SMP_F_NOT_LAST = 1 << 0, /* other occurrences might exist for this sample */
50 SMP_F_MAY_CHANGE = 1 << 1, /* sample is unstable and might change (eg: request length) */
51 SMP_F_VOL_TEST = 1 << 2, /* result must not survive longer than the test (eg: time) */
52 SMP_F_VOL_1ST = 1 << 3, /* result sensitive to changes in first line (eg: URI) */
53 SMP_F_VOL_HDR = 1 << 4, /* result sensitive to changes in headers */
54 SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */
55 SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */
56 SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
57
58 SMP_F_READ_ONLY = 1 << 7, /* returned data must not be altered */
59 SMP_F_RES_SET = 1 << 8, /* migration: ACL match must reflect the RES_PASS flag */
60 SMP_F_RES_PASS = 1 << 9, /* migration: returned data is a TRUE boolean */
61 SMP_F_SET_RES_PASS = (SMP_F_RES_SET|SMP_F_RES_PASS), /* migration: force ACLs to PASS */
62 SMP_F_SET_RES_FAIL = (SMP_F_RES_SET), /* migration: force ACLs to FAIL */
63
64 SMP_F_MUST_FREE = 1 << 10, /* migration: this sample must be freed ASAP */
65
66};
Emeric Brun485479d2010-09-23 18:02:19 +020067
Emeric Brun107ca302010-01-04 16:16:05 +010068/* pattern fetch direction */
69#define PATTERN_FETCH_REQ 1
70#define PATTERN_FETCH_RTR 2
71
Emeric Brun485479d2010-09-23 18:02:19 +020072
Emeric Brun107ca302010-01-04 16:16:05 +010073/* pattern result data */
74union pattern_data {
Willy Tarreau422aa072012-04-20 20:49:27 +020075 unsigned int uint; /* used for unsigned 32bits integers and booleans */
76 int sint; /* used for signed 32bits integers */
77 struct in_addr ipv4; /* used for ipv4 addresses */
78 struct in6_addr ipv6; /* used for ipv6 addresses */
79 struct chunk str; /* used for char strings or buffers */
Emeric Brun107ca302010-01-04 16:16:05 +010080};
81
82/* pattern result */
83struct pattern {
84 int type; /* current type of data */
85 union pattern_data data; /* data */
86};
87
Willy Tarreau16c31b02012-04-23 14:24:58 +020088/* a sample context might be used by any sample fetch function in order to
89 * store information needed across multiple calls (eg: restart point for a
90 * next occurrence). By definition it may store up to 8 pointers, or any
91 * scalar (double, int, long long).
92 */
93union smp_ctx {
94 void *p; /* any pointer */
95 int i; /* any integer */
96 long long ll; /* any long long or smaller */
97 double d; /* any float or double */
98 void *a[8]; /* any array of up to 8 pointers */
99};
100
101/* a sample is a typed data extracted from a stream. It has a type, contents,
102 * validity constraints, a context for use in iterative calls.
103 */
104struct sample {
105 unsigned int flags; /* SMP_F_* */
Willy Tarreau422aa072012-04-20 20:49:27 +0200106 int type; /* SMP_T_* */
Willy Tarreau16c31b02012-04-23 14:24:58 +0200107 union pattern_data data;
108 union smp_ctx ctx;
109};
110
Emeric Brun107ca302010-01-04 16:16:05 +0100111/* pattern conversion */
112struct pattern_conv {
113 const char *kw; /* configuration keyword */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200114 int (*process)(const struct arg *arg_p,
Willy Tarreauf9954102012-04-20 14:03:29 +0200115 union pattern_data *data); /* process function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +0200116 unsigned int arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +0200117 int (*val_args)(struct arg *arg_p,
118 char **err_msg); /* argument validation function */
Emeric Brun485479d2010-09-23 18:02:19 +0200119 unsigned int in_type; /* input needed pattern type */
120 unsigned int out_type; /* output pattern type */
Emeric Brun107ca302010-01-04 16:16:05 +0100121};
122
123/* pattern conversion expression */
124struct pattern_conv_expr {
125 struct list list; /* member of a pattern expression */
126 struct pattern_conv *conv; /* pattern conversion */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200127 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +0100128};
129
130/* pattern fetch */
131struct pattern_fetch {
132 const char *kw; /* configuration keyword */
133 int (*process)(struct proxy *px,
134 struct session *l4,
135 void *l7,
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200136 int dir, const struct arg *arg_p,
Emeric Brun107ca302010-01-04 16:16:05 +0100137 union pattern_data *data); /* fetch processing function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +0200138 unsigned int arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +0200139 int (*val_args)(struct arg *arg_p,
140 char **err_msg); /* argument validation function */
Emeric Brun107ca302010-01-04 16:16:05 +0100141 unsigned long out_type; /* output pattern type */
142 int dir; /* usable directions */
143};
144
145/* pattern expression */
146struct pattern_expr {
147 struct list list; /* member of list of pattern, currently not used */
148 struct pattern_fetch *fetch; /* pattern fetch */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200149 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +0100150 struct list conv_exprs; /* list of conversion expression to apply */
151};
152
153/* pattern fetch keywords list */
154struct pattern_fetch_kw_list {
155 struct list list; /* head of pattern fetch keyword list */
156 struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */
157};
158
159/* pattern conversion keywords list */
160struct pattern_conv_kw_list {
161 struct list list; /* head of pattern conversion keyword list */
162 struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */
163};
164
165#endif /* _TYPES_PATTERN_H */