Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1 | /* |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 2 | * include/types/sample.h |
| 3 | * Macros, variables and structures for sample management. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 6 | * Copyright (C) 2012-2013 Willy Tarreau <w@1wt.eu> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 7 | * |
| 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 Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 23 | #ifndef _TYPES_SAMPLE_H |
| 24 | #define _TYPES_SAMPLE_H |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 25 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 26 | #include <sys/socket.h> |
| 27 | #include <netinet/in.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 28 | |
| 29 | #include <common/chunk.h> |
Willy Tarreau | dd2f85e | 2012-09-02 22:34:23 +0200 | [diff] [blame] | 30 | #include <common/mini-clist.h> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 31 | |
Thierry FOURNIER | a9ff994 | 2015-06-09 15:49:44 +0200 | [diff] [blame] | 32 | struct arg; |
| 33 | |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 34 | /* input and output sample types */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 35 | enum { |
Thierry FOURNIER | 9c627e8 | 2015-06-03 20:12:35 +0200 | [diff] [blame] | 36 | SMP_T_ANY = 0, /* any type */ |
| 37 | SMP_T_BOOL, /* boolean */ |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 38 | SMP_T_SINT, /* signed 64bits integer type */ |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 39 | SMP_T_ADDR, /* ipv4 or ipv6, only used for input type compatibility */ |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 40 | SMP_T_IPV4, /* ipv4 type */ |
| 41 | SMP_T_IPV6, /* ipv6 type */ |
| 42 | SMP_T_STR, /* char string type */ |
| 43 | SMP_T_BIN, /* buffer type */ |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 44 | SMP_T_METH, /* contain method */ |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 45 | SMP_TYPES /* number of types, must always be last */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 48 | /* Sample sources are used to establish a relation between fetch keywords and |
| 49 | * the location where they're about to be used. They're reserved for internal |
| 50 | * use and are not meant to be known outside the sample management code. |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 51 | */ |
| 52 | enum { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 53 | SMP_SRC_INTRN, /* internal context-less information */ |
| 54 | SMP_SRC_LISTN, /* listener which accepted the connection */ |
| 55 | SMP_SRC_FTEND, /* frontend which accepted the connection */ |
| 56 | SMP_SRC_L4CLI, /* L4 information about the client */ |
| 57 | SMP_SRC_L5CLI, /* fetch uses client information from embryonic session */ |
| 58 | SMP_SRC_TRACK, /* fetch involves track counters */ |
| 59 | SMP_SRC_L6REQ, /* fetch uses raw information from the request buffer */ |
| 60 | SMP_SRC_HRQHV, /* fetch uses volatile information about HTTP request headers (eg: value) */ |
| 61 | SMP_SRC_HRQHP, /* fetch uses persistent information about HTTP request headers (eg: meth) */ |
| 62 | SMP_SRC_HRQBO, /* fetch uses information about HTTP request body */ |
| 63 | SMP_SRC_BKEND, /* fetch uses information about the backend */ |
| 64 | SMP_SRC_SERVR, /* fetch uses information about the selected server */ |
| 65 | SMP_SRC_L4SRV, /* fetch uses information about the server L4 connection */ |
| 66 | SMP_SRC_L5SRV, /* fetch uses information about the server L5 connection */ |
| 67 | SMP_SRC_L6RES, /* fetch uses raw information from the response buffer */ |
| 68 | SMP_SRC_HRSHV, /* fetch uses volatile information about HTTP response headers (eg: value) */ |
| 69 | SMP_SRC_HRSHP, /* fetch uses persistent information about HTTP response headers (eg: status) */ |
| 70 | SMP_SRC_HRSBO, /* fetch uses information about HTTP response body */ |
| 71 | SMP_SRC_RQFIN, /* final information about request buffer (eg: tot bytes) */ |
| 72 | SMP_SRC_RSFIN, /* final information about response buffer (eg: tot bytes) */ |
| 73 | SMP_SRC_TXFIN, /* final information about the transaction (eg: #comp rate) */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 74 | SMP_SRC_SSFIN, /* final information about the stream (eg: #requests, final flags) */ |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 75 | SMP_SRC_ENTRIES /* nothing after this */ |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 78 | /* Sample checkpoints are a list of places where samples may be used. This is |
| 79 | * an internal enum used only to build SMP_VAL_*. |
| 80 | */ |
| 81 | enum { |
| 82 | SMP_CKP_FE_CON_ACC, /* FE connection accept rules ("tcp request connection") */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 83 | SMP_CKP_FE_SES_ACC, /* FE stream accept rules (to come soon) */ |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 84 | SMP_CKP_FE_REQ_CNT, /* FE request content rules ("tcp request content") */ |
| 85 | SMP_CKP_FE_HRQ_HDR, /* FE HTTP request headers (rules, headers, monitor, stats, redirect) */ |
| 86 | SMP_CKP_FE_HRQ_BDY, /* FE HTTP request body */ |
| 87 | SMP_CKP_FE_SET_BCK, /* FE backend switching rules ("use_backend") */ |
| 88 | SMP_CKP_BE_REQ_CNT, /* BE request content rules ("tcp request content") */ |
| 89 | SMP_CKP_BE_HRQ_HDR, /* BE HTTP request headers (rules, headers, monitor, stats, redirect) */ |
| 90 | SMP_CKP_BE_HRQ_BDY, /* BE HTTP request body */ |
| 91 | SMP_CKP_BE_SET_SRV, /* BE server switching rules ("use_server", "balance", "force-persist", "stick", ...) */ |
| 92 | SMP_CKP_BE_SRV_CON, /* BE server connect (eg: "source") */ |
| 93 | SMP_CKP_BE_RES_CNT, /* BE response content rules ("tcp response content") */ |
| 94 | SMP_CKP_BE_HRS_HDR, /* BE HTTP response headers (rules, headers) */ |
| 95 | SMP_CKP_BE_HRS_BDY, /* BE HTTP response body (stick-store rules are there) */ |
| 96 | SMP_CKP_BE_STO_RUL, /* BE stick-store rules */ |
| 97 | SMP_CKP_FE_RES_CNT, /* FE response content rules ("tcp response content") */ |
| 98 | SMP_CKP_FE_HRS_HDR, /* FE HTTP response headers (rules, headers) */ |
| 99 | SMP_CKP_FE_HRS_BDY, /* FE HTTP response body */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 100 | SMP_CKP_FE_LOG_END, /* FE log at the end of the txn/stream */ |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 101 | SMP_CKP_ENTRIES /* nothing after this */ |
| 102 | }; |
| 103 | |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 104 | /* SMP_USE_* are flags used to declare fetch keywords. Fetch methods are |
| 105 | * associated with bitfields composed of these values, generally only one, to |
| 106 | * indicate where the contents may be sampled. Some fetches are ambiguous as |
| 107 | * they apply to either the request or the response depending on the context, |
| 108 | * so they will have 2 of these bits (eg: hdr(), payload(), ...). These are |
| 109 | * stored in smp->use. |
| 110 | */ |
| 111 | enum { |
| 112 | SMP_USE_INTRN = 1 << SMP_SRC_INTRN, /* internal context-less information */ |
| 113 | SMP_USE_LISTN = 1 << SMP_SRC_LISTN, /* listener which accepted the connection */ |
| 114 | SMP_USE_FTEND = 1 << SMP_SRC_FTEND, /* frontend which accepted the connection */ |
| 115 | SMP_USE_L4CLI = 1 << SMP_SRC_L4CLI, /* L4 information about the client */ |
| 116 | SMP_USE_L5CLI = 1 << SMP_SRC_L5CLI, /* fetch uses client information from embryonic session */ |
| 117 | SMP_USE_TRACK = 1 << SMP_SRC_TRACK, /* fetch involves track counters */ |
| 118 | SMP_USE_L6REQ = 1 << SMP_SRC_L6REQ, /* fetch uses raw information from the request buffer */ |
| 119 | SMP_USE_HRQHV = 1 << SMP_SRC_HRQHV, /* fetch uses volatile information about HTTP request headers (eg: value) */ |
| 120 | SMP_USE_HRQHP = 1 << SMP_SRC_HRQHP, /* fetch uses persistent information about HTTP request headers (eg: meth) */ |
| 121 | SMP_USE_HRQBO = 1 << SMP_SRC_HRQBO, /* fetch uses information about HTTP request body */ |
| 122 | SMP_USE_BKEND = 1 << SMP_SRC_BKEND, /* fetch uses information about the backend */ |
| 123 | SMP_USE_SERVR = 1 << SMP_SRC_SERVR, /* fetch uses information about the selected server */ |
| 124 | SMP_USE_L4SRV = 1 << SMP_SRC_L4SRV, /* fetch uses information about the server L4 connection */ |
| 125 | SMP_USE_L5SRV = 1 << SMP_SRC_L5SRV, /* fetch uses information about the server L5 connection */ |
| 126 | SMP_USE_L6RES = 1 << SMP_SRC_L6RES, /* fetch uses raw information from the response buffer */ |
| 127 | SMP_USE_HRSHV = 1 << SMP_SRC_HRSHV, /* fetch uses volatile information about HTTP response headers (eg: value) */ |
| 128 | SMP_USE_HRSHP = 1 << SMP_SRC_HRSHP, /* fetch uses persistent information about HTTP response headers (eg: status) */ |
| 129 | SMP_USE_HRSBO = 1 << SMP_SRC_HRSBO, /* fetch uses information about HTTP response body */ |
| 130 | SMP_USE_RQFIN = 1 << SMP_SRC_RQFIN, /* final information about request buffer (eg: tot bytes) */ |
| 131 | SMP_USE_RSFIN = 1 << SMP_SRC_RSFIN, /* final information about response buffer (eg: tot bytes) */ |
| 132 | SMP_USE_TXFIN = 1 << SMP_SRC_TXFIN, /* final information about the transaction (eg: #comp rate) */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 133 | SMP_USE_SSFIN = 1 << SMP_SRC_SSFIN, /* final information about the stream (eg: #requests, final flags) */ |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 134 | |
| 135 | /* This composite one is useful to detect if an hdr_idx needs to be allocated */ |
| 136 | SMP_USE_HTTP_ANY = SMP_USE_HRQHV | SMP_USE_HRQHP | SMP_USE_HRQBO | |
| 137 | SMP_USE_HRSHV | SMP_USE_HRSHP | SMP_USE_HRSBO, |
| 138 | }; |
| 139 | |
| 140 | /* Sample validity is computed from the fetch sources above when keywords |
| 141 | * are registered. Each fetch method may be used at different locations. The |
| 142 | * configuration parser will check whether the fetches are compatible with the |
| 143 | * location where they're used. These are stored in smp->val. |
| 144 | */ |
| 145 | enum { |
| 146 | SMP_VAL___________ = 0, /* Just used as a visual marker */ |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 147 | SMP_VAL_FE_CON_ACC = 1 << SMP_CKP_FE_CON_ACC, /* FE connection accept rules ("tcp request connection") */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 148 | SMP_VAL_FE_SES_ACC = 1 << SMP_CKP_FE_SES_ACC, /* FE stream accept rules (to come soon) */ |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 149 | SMP_VAL_FE_REQ_CNT = 1 << SMP_CKP_FE_REQ_CNT, /* FE request content rules ("tcp request content") */ |
| 150 | SMP_VAL_FE_HRQ_HDR = 1 << SMP_CKP_FE_HRQ_HDR, /* FE HTTP request headers (rules, headers, monitor, stats, redirect) */ |
| 151 | SMP_VAL_FE_HRQ_BDY = 1 << SMP_CKP_FE_HRQ_BDY, /* FE HTTP request body */ |
| 152 | SMP_VAL_FE_SET_BCK = 1 << SMP_CKP_FE_SET_BCK, /* FE backend switching rules ("use_backend") */ |
| 153 | SMP_VAL_BE_REQ_CNT = 1 << SMP_CKP_BE_REQ_CNT, /* BE request content rules ("tcp request content") */ |
| 154 | SMP_VAL_BE_HRQ_HDR = 1 << SMP_CKP_BE_HRQ_HDR, /* BE HTTP request headers (rules, headers, monitor, stats, redirect) */ |
| 155 | SMP_VAL_BE_HRQ_BDY = 1 << SMP_CKP_BE_HRQ_BDY, /* BE HTTP request body */ |
| 156 | SMP_VAL_BE_SET_SRV = 1 << SMP_CKP_BE_SET_SRV, /* BE server switching rules ("use_server", "balance", "force-persist", "stick", ...) */ |
| 157 | SMP_VAL_BE_SRV_CON = 1 << SMP_CKP_BE_SRV_CON, /* BE server connect (eg: "source") */ |
| 158 | SMP_VAL_BE_RES_CNT = 1 << SMP_CKP_BE_RES_CNT, /* BE response content rules ("tcp response content") */ |
| 159 | SMP_VAL_BE_HRS_HDR = 1 << SMP_CKP_BE_HRS_HDR, /* BE HTTP response headers (rules, headers) */ |
| 160 | SMP_VAL_BE_HRS_BDY = 1 << SMP_CKP_BE_HRS_BDY, /* BE HTTP response body (stick-store rules are there) */ |
| 161 | SMP_VAL_BE_STO_RUL = 1 << SMP_CKP_BE_STO_RUL, /* BE stick-store rules */ |
| 162 | SMP_VAL_FE_RES_CNT = 1 << SMP_CKP_FE_RES_CNT, /* FE response content rules ("tcp response content") */ |
| 163 | SMP_VAL_FE_HRS_HDR = 1 << SMP_CKP_FE_HRS_HDR, /* FE HTTP response headers (rules, headers) */ |
| 164 | SMP_VAL_FE_HRS_BDY = 1 << SMP_CKP_FE_HRS_BDY, /* FE HTTP response body */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 165 | SMP_VAL_FE_LOG_END = 1 << SMP_CKP_FE_LOG_END, /* FE log at the end of the txn/stream */ |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 166 | |
| 167 | /* a few combinations to decide what direction to try to fetch (useful for logs) */ |
| 168 | SMP_VAL_REQUEST = SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 169 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 170 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 171 | SMP_VAL_BE_SET_SRV, |
| 172 | |
| 173 | SMP_VAL_RESPONSE = SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | SMP_VAL_BE_HRS_HDR | |
| 174 | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | SMP_VAL_FE_RES_CNT | |
| 175 | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | SMP_VAL_FE_LOG_END, |
| 176 | }; |
| 177 | |
| 178 | extern const unsigned int fetch_cap[SMP_SRC_ENTRIES]; |
| 179 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 180 | /* Sample fetch options are passed to sample fetch functions to add precision |
| 181 | * about what is desired : |
| 182 | * - fetch direction (req/resp) |
| 183 | * - intermediary / final fetch |
| 184 | */ |
| 185 | enum { |
| 186 | SMP_OPT_DIR_REQ = 0, /* direction = request */ |
| 187 | SMP_OPT_DIR_RES = 1, /* direction = response */ |
| 188 | SMP_OPT_DIR = (SMP_OPT_DIR_REQ|SMP_OPT_DIR_RES), /* mask to get direction */ |
| 189 | SMP_OPT_FINAL = 2, /* final fetch, contents won't change anymore */ |
Willy Tarreau | 7a777ed | 2012-04-26 11:44:02 +0200 | [diff] [blame] | 190 | SMP_OPT_ITERATE = 4, /* fetches may be iterated if supported (for ACLs) */ |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 191 | }; |
| 192 | |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 193 | /* Flags used to describe fetched samples. MAY_CHANGE indicates that the result |
| 194 | * of the fetch might still evolve, for instance because of more data expected, |
| 195 | * even if the fetch has failed. VOL_* indicates how long a result may be cached. |
| 196 | */ |
| 197 | enum { |
| 198 | SMP_F_NOT_LAST = 1 << 0, /* other occurrences might exist for this sample */ |
| 199 | SMP_F_MAY_CHANGE = 1 << 1, /* sample is unstable and might change (eg: request length) */ |
| 200 | SMP_F_VOL_TEST = 1 << 2, /* result must not survive longer than the test (eg: time) */ |
| 201 | SMP_F_VOL_1ST = 1 << 3, /* result sensitive to changes in first line (eg: URI) */ |
| 202 | SMP_F_VOL_HDR = 1 << 4, /* result sensitive to changes in headers */ |
| 203 | SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */ |
| 204 | SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */ |
| 205 | SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 206 | SMP_F_CONST = 1 << 7, /* This sample use constant memory. May diplicate it before changes */ |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 207 | }; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 208 | |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 209 | /* needed below */ |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 210 | struct session; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 211 | struct stream; |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 212 | |
Thierry FOURNIER | fd7edd3 | 2015-07-23 18:16:33 +0200 | [diff] [blame] | 213 | /* Known HTTP methods */ |
| 214 | enum http_meth_t { |
| 215 | HTTP_METH_NONE = 0, |
| 216 | HTTP_METH_OPTIONS, |
| 217 | HTTP_METH_GET, |
| 218 | HTTP_METH_HEAD, |
| 219 | HTTP_METH_POST, |
| 220 | HTTP_METH_PUT, |
| 221 | HTTP_METH_DELETE, |
| 222 | HTTP_METH_TRACE, |
| 223 | HTTP_METH_CONNECT, |
| 224 | HTTP_METH_OTHER, /* Must be the last entry */ |
| 225 | } __attribute__((packed)); |
| 226 | |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 227 | /* a sample context might be used by any sample fetch function in order to |
| 228 | * store information needed across multiple calls (eg: restart point for a |
| 229 | * next occurrence). By definition it may store up to 8 pointers, or any |
| 230 | * scalar (double, int, long long). |
| 231 | */ |
| 232 | union smp_ctx { |
| 233 | void *p; /* any pointer */ |
| 234 | int i; /* any integer */ |
| 235 | long long ll; /* any long long or smaller */ |
| 236 | double d; /* any float or double */ |
| 237 | void *a[8]; /* any array of up to 8 pointers */ |
| 238 | }; |
| 239 | |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 240 | struct meth { |
| 241 | enum http_meth_t meth; |
| 242 | struct chunk str; |
| 243 | }; |
| 244 | |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 245 | /* a sample is a typed data extracted from a stream. It has a type, contents, |
| 246 | * validity constraints, a context for use in iterative calls. |
| 247 | */ |
| 248 | struct sample { |
| 249 | unsigned int flags; /* SMP_F_* */ |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 250 | int type; /* SMP_T_* */ |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 251 | union { |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 252 | long long int sint; /* used for signed 64bits integers */ |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 253 | struct in_addr ipv4; /* used for ipv4 addresses */ |
| 254 | struct in6_addr ipv6; /* used for ipv6 addresses */ |
| 255 | struct chunk str; /* used for char strings or buffers */ |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 256 | struct meth meth; /* used for http method */ |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 257 | } data; /* sample data */ |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 258 | union smp_ctx ctx; |
Thierry FOURNIER | 6879ad3 | 2015-05-11 11:54:58 +0200 | [diff] [blame] | 259 | |
| 260 | /* Some sample analyzer (sample-fetch or converters) needs to |
| 261 | * known the attached proxy, session and stream. The sample-fetches |
| 262 | * and the converters function pointers cannot be called without |
| 263 | * these 3 pointers filled. |
| 264 | */ |
| 265 | struct proxy *px; |
| 266 | struct session *sess; |
| 267 | struct stream *strm; |
Thierry FOURNIER | 1d33b88 | 2015-05-11 15:25:29 +0200 | [diff] [blame] | 268 | unsigned int opt; /* fetch options (SMP_OPT_*) */ |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 269 | }; |
| 270 | |
Thierry FOURNIER | 8ed9697 | 2013-11-26 10:21:51 +0100 | [diff] [blame] | 271 | /* Used to store sample constant */ |
| 272 | struct sample_storage { |
| 273 | int type; /* SMP_T_* */ |
| 274 | union { |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 275 | long long int sint; /* used for signed 64bits integers */ |
Thierry FOURNIER | 8ed9697 | 2013-11-26 10:21:51 +0100 | [diff] [blame] | 276 | struct in_addr ipv4; /* used for ipv4 addresses */ |
| 277 | struct in6_addr ipv6; /* used for ipv6 addresses */ |
| 278 | struct chunk str; /* used for char strings or buffers */ |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 279 | struct meth meth; /* used for http method */ |
Thierry FOURNIER | 8ed9697 | 2013-11-26 10:21:51 +0100 | [diff] [blame] | 280 | } data; /* sample data */ |
| 281 | }; |
| 282 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 283 | /* Descriptor for a sample conversion */ |
| 284 | struct sample_conv { |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 285 | const char *kw; /* configuration keyword */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 286 | int (*process)(const struct arg *arg_p, |
Thierry FOURNIER | 68a556e | 2015-02-23 15:11:11 +0100 | [diff] [blame] | 287 | struct sample *smp, |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 288 | void *private); /* process function */ |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 289 | unsigned int arg_mask; /* arguments (ARG*()) */ |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 290 | int (*val_args)(struct arg *arg_p, |
Thierry FOURNIER | 9c1d67e | 2013-11-21 13:37:41 +0100 | [diff] [blame] | 291 | struct sample_conv *smp_conv, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 292 | const char *file, int line, |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 293 | char **err_msg); /* argument validation function */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 294 | unsigned int in_type; /* expected input sample type */ |
| 295 | unsigned int out_type; /* output sample type */ |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 296 | void *private; /* private values. only used by maps and Lua */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 297 | }; |
| 298 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 299 | /* sample conversion expression */ |
| 300 | struct sample_conv_expr { |
| 301 | struct list list; /* member of a sample_expr */ |
| 302 | struct sample_conv *conv; /* sample conversion used */ |
| 303 | struct arg *arg_p; /* optional arguments */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 304 | }; |
| 305 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 306 | /* Descriptor for a sample fetch method */ |
| 307 | struct sample_fetch { |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 308 | const char *kw; /* configuration keyword */ |
Thierry FOURNIER | 0786d05 | 2015-05-11 15:42:45 +0200 | [diff] [blame] | 309 | int (*process)(const struct arg *arg_p, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 310 | struct sample *smp, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 311 | const char *kw, /* fetch processing function */ |
| 312 | void *private); /* private value. */ |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 313 | unsigned int arg_mask; /* arguments (ARG*()) */ |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 314 | int (*val_args)(struct arg *arg_p, |
| 315 | char **err_msg); /* argument validation function */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 316 | unsigned long out_type; /* output sample type */ |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 317 | unsigned int use; /* fetch source (SMP_USE_*) */ |
| 318 | unsigned int val; /* fetch validity (SMP_VAL_*) */ |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 319 | void *private; /* private values. only used by Lua */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 320 | }; |
| 321 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 322 | /* sample expression */ |
| 323 | struct sample_expr { |
| 324 | struct list list; /* member of list of sample, currently not used */ |
| 325 | struct sample_fetch *fetch; /* sample fetch method */ |
| 326 | struct arg *arg_p; /* optional pointer to arguments to fetch function */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 327 | struct list conv_exprs; /* list of conversion expression to apply */ |
| 328 | }; |
| 329 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 330 | /* sample fetch keywords list */ |
| 331 | struct sample_fetch_kw_list { |
| 332 | struct list list; /* head of sample fetch keyword list */ |
| 333 | struct sample_fetch kw[VAR_ARRAY]; /* array of sample fetch descriptors */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 334 | }; |
| 335 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 336 | /* sample conversion keywords list */ |
| 337 | struct sample_conv_kw_list { |
| 338 | struct list list; /* head of sample conversion keyword list */ |
| 339 | struct sample_conv kw[VAR_ARRAY]; /* array of sample conversion descriptors */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 340 | }; |
| 341 | |
Thierry FOURNIER | 8af6ff1 | 2013-11-21 10:53:12 +0100 | [diff] [blame] | 342 | typedef int (*sample_cast_fct)(struct sample *smp); |
| 343 | extern sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES]; |
| 344 | |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 345 | #endif /* _TYPES_SAMPLE_H */ |