blob: b806a12c5828097c4a837bbf346f40a0848ec652 [file] [log] [blame]
Emeric Brun107ca302010-01-04 16:16:05 +01001/*
Willy Tarreaucd3b0942012-04-27 21:52:18 +02002 * include/types/sample.h
3 * Macros, variables and structures for sample management.
Emeric Brun107ca302010-01-04 16:16:05 +01004 *
5 * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
Willy Tarreaucd3b0942012-04-27 21:52:18 +02006 * Copyright (C) 2012 Willy Tarreau <w@1wt.eu>
Emeric Brun107ca302010-01-04 16:16:05 +01007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
Willy Tarreaucd3b0942012-04-27 21:52:18 +020023#ifndef _TYPES_SAMPLE_H
24#define _TYPES_SAMPLE_H
Emeric Brun107ca302010-01-04 16:16:05 +010025
Emeric Brun107ca302010-01-04 16:16:05 +010026#include <sys/socket.h>
27#include <netinet/in.h>
Willy Tarreauecfb8e82012-04-20 12:29:52 +020028#include <types/arg.h>
29#include <types/buffers.h>
Emeric Brun107ca302010-01-04 16:16:05 +010030
Willy Tarreau422aa072012-04-20 20:49:27 +020031/* input and output sample types */
Emeric Brun107ca302010-01-04 16:16:05 +010032enum {
Willy Tarreau422aa072012-04-20 20:49:27 +020033 SMP_T_BOOL = 0, /* boolean */
34 SMP_T_UINT, /* unsigned 32bits integer type */
35 SMP_T_SINT, /* signed 32bits integer type */
36 SMP_T_IPV4, /* ipv4 type */
37 SMP_T_IPV6, /* ipv6 type */
38 SMP_T_STR, /* char string type */
39 SMP_T_BIN, /* buffer type */
40 SMP_T_CSTR, /* constant char string type, data need dup before conversion */
41 SMP_T_CBIN, /* constant buffer type, data need dup before conversion */
42 SMP_TYPES /* number of types, must always be last */
Emeric Brun107ca302010-01-04 16:16:05 +010043};
44
Willy Tarreau32a6f2e2012-04-25 10:13:36 +020045/* Sample fetch capabilities are used to declare keywords. Right now only
46 * the supportd fetch directions are specified.
47 */
48enum {
49 SMP_CAP_REQ = 1 << 0, /* fetch supported on request */
50 SMP_CAP_RES = 1 << 1, /* fetch supported on response */
51};
52
53/* Sample fetch options are passed to sample fetch functions to add precision
54 * about what is desired :
55 * - fetch direction (req/resp)
56 * - intermediary / final fetch
57 */
58enum {
59 SMP_OPT_DIR_REQ = 0, /* direction = request */
60 SMP_OPT_DIR_RES = 1, /* direction = response */
61 SMP_OPT_DIR = (SMP_OPT_DIR_REQ|SMP_OPT_DIR_RES), /* mask to get direction */
62 SMP_OPT_FINAL = 2, /* final fetch, contents won't change anymore */
Willy Tarreau7a777ed2012-04-26 11:44:02 +020063 SMP_OPT_ITERATE = 4, /* fetches may be iterated if supported (for ACLs) */
Willy Tarreau32a6f2e2012-04-25 10:13:36 +020064};
65
Willy Tarreau16c31b02012-04-23 14:24:58 +020066/* Flags used to describe fetched samples. MAY_CHANGE indicates that the result
67 * of the fetch might still evolve, for instance because of more data expected,
68 * even if the fetch has failed. VOL_* indicates how long a result may be cached.
69 */
70enum {
71 SMP_F_NOT_LAST = 1 << 0, /* other occurrences might exist for this sample */
72 SMP_F_MAY_CHANGE = 1 << 1, /* sample is unstable and might change (eg: request length) */
73 SMP_F_VOL_TEST = 1 << 2, /* result must not survive longer than the test (eg: time) */
74 SMP_F_VOL_1ST = 1 << 3, /* result sensitive to changes in first line (eg: URI) */
75 SMP_F_VOL_HDR = 1 << 4, /* result sensitive to changes in headers */
76 SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */
77 SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */
78 SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
Willy Tarreau16c31b02012-04-23 14:24:58 +020079};
Emeric Brun485479d2010-09-23 18:02:19 +020080
Willy Tarreau16c31b02012-04-23 14:24:58 +020081/* a sample context might be used by any sample fetch function in order to
82 * store information needed across multiple calls (eg: restart point for a
83 * next occurrence). By definition it may store up to 8 pointers, or any
84 * scalar (double, int, long long).
85 */
86union smp_ctx {
87 void *p; /* any pointer */
88 int i; /* any integer */
89 long long ll; /* any long long or smaller */
90 double d; /* any float or double */
91 void *a[8]; /* any array of up to 8 pointers */
92};
93
94/* a sample is a typed data extracted from a stream. It has a type, contents,
95 * validity constraints, a context for use in iterative calls.
96 */
97struct sample {
98 unsigned int flags; /* SMP_F_* */
Willy Tarreau422aa072012-04-20 20:49:27 +020099 int type; /* SMP_T_* */
Willy Tarreau342acb42012-04-23 22:03:39 +0200100 union {
101 unsigned int uint; /* used for unsigned 32bits integers and booleans */
102 int sint; /* used for signed 32bits integers */
103 struct in_addr ipv4; /* used for ipv4 addresses */
104 struct in6_addr ipv6; /* used for ipv6 addresses */
105 struct chunk str; /* used for char strings or buffers */
106 } data; /* sample data */
Willy Tarreau16c31b02012-04-23 14:24:58 +0200107 union smp_ctx ctx;
108};
109
Willy Tarreau12785782012-04-27 21:37:17 +0200110/* Descriptor for a sample conversion */
111struct sample_conv {
Emeric Brun107ca302010-01-04 16:16:05 +0100112 const char *kw; /* configuration keyword */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200113 int (*process)(const struct arg *arg_p,
Willy Tarreau342acb42012-04-23 22:03:39 +0200114 struct sample *smp); /* process function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +0200115 unsigned int arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +0200116 int (*val_args)(struct arg *arg_p,
117 char **err_msg); /* argument validation function */
Willy Tarreau12785782012-04-27 21:37:17 +0200118 unsigned int in_type; /* expected input sample type */
119 unsigned int out_type; /* output sample type */
Emeric Brun107ca302010-01-04 16:16:05 +0100120};
121
Willy Tarreau12785782012-04-27 21:37:17 +0200122/* sample conversion expression */
123struct sample_conv_expr {
124 struct list list; /* member of a sample_expr */
125 struct sample_conv *conv; /* sample conversion used */
126 struct arg *arg_p; /* optional arguments */
Emeric Brun107ca302010-01-04 16:16:05 +0100127};
128
Willy Tarreau12785782012-04-27 21:37:17 +0200129/* Descriptor for a sample fetch method */
130struct sample_fetch {
Emeric Brun107ca302010-01-04 16:16:05 +0100131 const char *kw; /* configuration keyword */
132 int (*process)(struct proxy *px,
133 struct session *l4,
134 void *l7,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +0200135 unsigned int opt, /* fetch options (SMP_OPT_*) */
136 const struct arg *arg_p,
Willy Tarreau342acb42012-04-23 22:03:39 +0200137 struct sample *smp); /* 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 */
Willy Tarreau12785782012-04-27 21:37:17 +0200141 unsigned long out_type; /* output sample type */
Willy Tarreau32a6f2e2012-04-25 10:13:36 +0200142 unsigned int cap; /* fetch capabilities (SMP_CAP_*) */
Emeric Brun107ca302010-01-04 16:16:05 +0100143};
144
Willy Tarreau12785782012-04-27 21:37:17 +0200145/* sample expression */
146struct sample_expr {
147 struct list list; /* member of list of sample, currently not used */
148 struct sample_fetch *fetch; /* sample fetch method */
149 struct arg *arg_p; /* optional pointer to arguments to fetch function */
Emeric Brun107ca302010-01-04 16:16:05 +0100150 struct list conv_exprs; /* list of conversion expression to apply */
151};
152
Willy Tarreau12785782012-04-27 21:37:17 +0200153/* sample fetch keywords list */
154struct sample_fetch_kw_list {
155 struct list list; /* head of sample fetch keyword list */
156 struct sample_fetch kw[VAR_ARRAY]; /* array of sample fetch descriptors */
Emeric Brun107ca302010-01-04 16:16:05 +0100157};
158
Willy Tarreau12785782012-04-27 21:37:17 +0200159/* sample conversion keywords list */
160struct sample_conv_kw_list {
161 struct list list; /* head of sample conversion keyword list */
162 struct sample_conv kw[VAR_ARRAY]; /* array of sample conversion descriptors */
Emeric Brun107ca302010-01-04 16:16:05 +0100163};
164
Willy Tarreaucd3b0942012-04-27 21:52:18 +0200165#endif /* _TYPES_SAMPLE_H */