Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HTTP samples fetching |
| 3 | * |
| 4 | * Copyright 2000-2018 Willy Tarreau <w@1wt.eu> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <sys/types.h> |
| 14 | |
| 15 | #include <ctype.h> |
| 16 | #include <string.h> |
| 17 | #include <time.h> |
| 18 | |
| 19 | #include <common/base64.h> |
| 20 | #include <common/chunk.h> |
| 21 | #include <common/compat.h> |
| 22 | #include <common/config.h> |
| 23 | #include <common/debug.h> |
Willy Tarreau | afba57a | 2018-12-11 13:44:24 +0100 | [diff] [blame] | 24 | #include <common/h1.h> |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 25 | #include <common/http.h> |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 26 | #include <common/htx.h> |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 27 | #include <common/initcall.h> |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 28 | #include <common/memory.h> |
| 29 | #include <common/standard.h> |
| 30 | #include <common/version.h> |
| 31 | |
| 32 | #include <types/global.h> |
| 33 | |
| 34 | #include <proto/arg.h> |
| 35 | #include <proto/auth.h> |
Willy Tarreau | 538746a | 2018-12-11 10:59:20 +0100 | [diff] [blame] | 36 | #include <proto/hdr_idx.h> |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 37 | #include <proto/http_fetch.h> |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 38 | #include <proto/http_htx.h> |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 39 | #include <proto/log.h> |
| 40 | #include <proto/obj_type.h> |
| 41 | #include <proto/proto_http.h> |
| 42 | #include <proto/sample.h> |
| 43 | #include <proto/stream.h> |
| 44 | |
| 45 | |
| 46 | /* this struct is used between calls to smp_fetch_hdr() or smp_fetch_cookie() */ |
| 47 | static THREAD_LOCAL struct hdr_ctx static_hdr_ctx; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 48 | static THREAD_LOCAL struct http_hdr_ctx static_http_hdr_ctx; |
Richard Russo | c0968f5 | 2019-07-31 11:45:56 -0700 | [diff] [blame] | 49 | /* this is used to convert raw connection buffers to htx */ |
| 50 | static THREAD_LOCAL struct buffer static_raw_htx_chunk; |
| 51 | static THREAD_LOCAL char *static_raw_htx_buf; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 52 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 53 | #define SMP_REQ_CHN(smp) (smp->strm ? &smp->strm->req : NULL) |
| 54 | #define SMP_RES_CHN(smp) (smp->strm ? &smp->strm->res : NULL) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 55 | |
Richard Russo | c0968f5 | 2019-07-31 11:45:56 -0700 | [diff] [blame] | 56 | /* This function returns the static htx chunk, where raw connections get |
| 57 | * converted to HTX as needed for samplxsing. |
| 58 | */ |
| 59 | struct buffer *get_raw_htx_chunk(void) |
| 60 | { |
| 61 | chunk_reset(&static_raw_htx_chunk); |
| 62 | return &static_raw_htx_chunk; |
| 63 | } |
| 64 | |
| 65 | static int alloc_raw_htx_chunk_per_thread() |
| 66 | { |
| 67 | static_raw_htx_buf = malloc(global.tune.bufsize); |
| 68 | if (!static_raw_htx_buf) |
| 69 | return 0; |
| 70 | chunk_init(&static_raw_htx_chunk, static_raw_htx_buf, global.tune.bufsize); |
| 71 | return 1; |
| 72 | } |
| 73 | |
| 74 | static void free_raw_htx_chunk_per_thread() |
| 75 | { |
| 76 | free(static_raw_htx_buf); |
| 77 | static_raw_htx_buf = NULL; |
| 78 | } |
| 79 | |
| 80 | REGISTER_PER_THREAD_ALLOC(alloc_raw_htx_chunk_per_thread); |
| 81 | REGISTER_PER_THREAD_FREE(free_raw_htx_chunk_per_thread); |
| 82 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 83 | /* |
| 84 | * Returns the data from Authorization header. Function may be called more |
| 85 | * than once so data is stored in txn->auth_data. When no header is found |
| 86 | * or auth method is unknown auth_method is set to HTTP_AUTH_WRONG to avoid |
| 87 | * searching again for something we are unable to find anyway. However, if |
| 88 | * the result if valid, the cache is not reused because we would risk to |
| 89 | * have the credentials overwritten by another stream in parallel. |
| 90 | */ |
| 91 | |
Christopher Faulet | e98411b | 2019-07-15 13:58:29 +0200 | [diff] [blame] | 92 | static int get_http_auth(struct sample *smp, struct htx *htx) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 93 | { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 94 | struct stream *s = smp->strm; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 95 | struct http_txn *txn = s->txn; |
| 96 | struct buffer auth_method; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 97 | char *h, *p; |
| 98 | int len; |
| 99 | |
| 100 | #ifdef DEBUG_AUTH |
| 101 | printf("Auth for stream %p: %d\n", s, txn->auth.method); |
| 102 | #endif |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 103 | if (txn->auth.method == HTTP_AUTH_WRONG) |
| 104 | return 0; |
| 105 | |
| 106 | txn->auth.method = HTTP_AUTH_WRONG; |
| 107 | |
Christopher Faulet | e98411b | 2019-07-15 13:58:29 +0200 | [diff] [blame] | 108 | if (htx) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 109 | /* HTX version */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 110 | struct http_hdr_ctx ctx = { .blk = NULL }; |
| 111 | struct ist hdr; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 112 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 113 | if (txn->flags & TX_USE_PX_CONN) |
| 114 | hdr = ist("Proxy-Authorization"); |
| 115 | else |
| 116 | hdr = ist("Authorization"); |
| 117 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 118 | ctx.blk = NULL; |
| 119 | if (!http_find_header(htx, hdr, &ctx, 0)) |
| 120 | return 0; |
| 121 | |
| 122 | p = memchr(ctx.value.ptr, ' ', ctx.value.len); |
| 123 | len = p - ctx.value.ptr; |
| 124 | if (!p || len <= 0) |
| 125 | return 0; |
| 126 | |
| 127 | if (chunk_initlen(&auth_method, ctx.value.ptr, 0, len) != 1) |
| 128 | return 0; |
| 129 | |
| 130 | chunk_initlen(&txn->auth.method_data, p + 1, 0, ctx.value.len - len - 1); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 131 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 132 | else { |
| 133 | /* LEGACY version */ |
| 134 | struct hdr_ctx ctx = { .idx = 0 }; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 135 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 136 | if (txn->flags & TX_USE_PX_CONN) { |
| 137 | h = "Proxy-Authorization"; |
| 138 | len = strlen(h); |
| 139 | } else { |
| 140 | h = "Authorization"; |
| 141 | len = strlen(h); |
| 142 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 143 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 144 | if (!http_find_header2(h, len, ci_head(&s->req), &txn->hdr_idx, &ctx)) |
| 145 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 146 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 147 | h = ctx.line + ctx.val; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 148 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 149 | p = memchr(h, ' ', ctx.vlen); |
| 150 | len = p - h; |
| 151 | if (!p || len <= 0) |
| 152 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 153 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 154 | if (chunk_initlen(&auth_method, h, 0, len) != 1) |
| 155 | return 0; |
| 156 | |
| 157 | chunk_initlen(&txn->auth.method_data, p + 1, 0, ctx.vlen - len - 1); |
| 158 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 159 | |
| 160 | if (!strncasecmp("Basic", auth_method.area, auth_method.data)) { |
| 161 | struct buffer *http_auth = get_trash_chunk(); |
| 162 | |
| 163 | len = base64dec(txn->auth.method_data.area, |
| 164 | txn->auth.method_data.data, |
| 165 | http_auth->area, global.tune.bufsize - 1); |
| 166 | |
| 167 | if (len < 0) |
| 168 | return 0; |
| 169 | |
| 170 | |
| 171 | http_auth->area[len] = '\0'; |
| 172 | |
| 173 | p = strchr(http_auth->area, ':'); |
| 174 | |
| 175 | if (!p) |
| 176 | return 0; |
| 177 | |
| 178 | txn->auth.user = http_auth->area; |
| 179 | *p = '\0'; |
| 180 | txn->auth.pass = p+1; |
| 181 | |
| 182 | txn->auth.method = HTTP_AUTH_BASIC; |
| 183 | return 1; |
| 184 | } |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | /* This function ensures that the prerequisites for an L7 fetch are ready, |
| 190 | * which means that a request or response is ready. If some data is missing, |
| 191 | * a parsing attempt is made. This is useful in TCP-based ACLs which are able |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 192 | * to extract data from L7. If <vol> is non-null during a prefetch, another |
| 193 | * test is made to ensure the required information is not gone. |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 194 | * |
| 195 | * The function returns : |
| 196 | * NULL with SMP_F_MAY_CHANGE in the sample flags if some data is missing to |
| 197 | * decide whether or not an HTTP message is present ; |
| 198 | * NULL if the requested data cannot be fetched or if it is certain that |
| 199 | * we'll never have any HTTP message there ; |
Willy Tarreau | 91d0b60 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 200 | * NULL if the sample's direction does not match the channel's (i.e. the |
| 201 | * function was asked to work on the wrong channel) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 202 | * The HTX message if ready |
| 203 | */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 204 | struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, int vol) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 205 | { |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 206 | struct stream *s = smp->strm; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 207 | struct http_txn *txn = NULL; |
| 208 | struct htx *htx = NULL; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 209 | struct http_msg *msg; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 210 | struct htx_sl *sl; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 211 | |
| 212 | /* Note: it is possible that <s> is NULL when called before stream |
| 213 | * initialization (eg: tcp-request connection), so this function is the |
| 214 | * one responsible for guarding against this case for all HTTP users. |
| 215 | */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 216 | if (!s || !chn) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 217 | return NULL; |
| 218 | |
Willy Tarreau | 91d0b60 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 219 | if (((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ && (chn->flags & CF_ISRESP)) || |
| 220 | ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES && !(chn->flags & CF_ISRESP))) |
| 221 | return 0; |
| 222 | |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 223 | if (!s->txn) { |
| 224 | if (unlikely(!http_alloc_txn(s))) |
| 225 | return NULL; /* not enough memory */ |
| 226 | http_init_txn(s); |
| 227 | txn = s->txn; |
| 228 | } |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 229 | txn = s->txn; |
| 230 | msg = (!(chn->flags & CF_ISRESP) ? &txn->req : &txn->rsp); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 231 | |
Christopher Faulet | eca8854 | 2019-04-03 10:12:42 +0200 | [diff] [blame] | 232 | if (IS_HTX_STRM(s)) { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 233 | htx = htxbuf(&chn->buf); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 234 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 235 | if (msg->msg_state == HTTP_MSG_ERROR || (htx->flags & HTX_FL_PARSING_ERROR)) |
| 236 | return NULL; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 237 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 238 | if (msg->msg_state < HTTP_MSG_BODY) { |
| 239 | /* Analyse not yet started */ |
Christopher Faulet | 29f1758 | 2019-05-23 11:03:26 +0200 | [diff] [blame] | 240 | if (htx_is_empty(htx) || htx->first == -1) { |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 241 | /* Parsing is done by the mux, just wait */ |
| 242 | smp->flags |= SMP_F_MAY_CHANGE; |
| 243 | return NULL; |
| 244 | } |
| 245 | } |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 246 | sl = http_get_stline(htx); |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 247 | if (vol && !sl) { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 248 | /* The start-line was already forwarded, it is too late to fetch anything */ |
| 249 | return NULL; |
| 250 | } |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 251 | } |
Christopher Faulet | eca8854 | 2019-04-03 10:12:42 +0200 | [diff] [blame] | 252 | else { /* RAW mode */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 253 | struct buffer *buf; |
| 254 | struct h1m h1m; |
Christopher Faulet | e4ab11b | 2019-06-11 15:05:37 +0200 | [diff] [blame] | 255 | struct http_hdr hdrs[global.tune.max_http_hdr]; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 256 | union h1_sl h1sl; |
| 257 | unsigned int flags = HTX_FL_NONE; |
| 258 | int ret; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 259 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 260 | /* no HTTP fetch on the response in TCP mode */ |
| 261 | if (chn->flags & CF_ISRESP) |
| 262 | return NULL; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 263 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 264 | /* Now we are working on the request only */ |
| 265 | buf = &chn->buf; |
| 266 | if (b_head(buf) + b_data(buf) > b_wrap(buf)) |
| 267 | b_slow_realign(buf, trash.area, 0); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 268 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 269 | h1m_init_req(&h1m); |
| 270 | ret = h1_headers_to_hdr_list(b_head(buf), b_stop(buf), |
| 271 | hdrs, sizeof(hdrs)/sizeof(hdrs[0]), &h1m, &h1sl); |
| 272 | if (ret <= 0) { |
| 273 | /* Invalid or too big*/ |
| 274 | if (ret < 0 || channel_full(&s->req, global.tune.maxrewrite)) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 275 | return NULL; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 276 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 277 | /* wait for a full request */ |
| 278 | smp->flags |= SMP_F_MAY_CHANGE; |
| 279 | return NULL; |
| 280 | } |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 281 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 282 | /* OK we just got a valid HTTP mesage. We have to convert it |
| 283 | * into an HTX message. |
| 284 | */ |
| 285 | if (unlikely(h1sl.rq.v.len == 0)) { |
| 286 | /* try to convert HTTP/0.9 requests to HTTP/1.0 */ |
| 287 | if (h1sl.rq.meth != HTTP_METH_GET || !h1sl.rq.u.len) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 288 | return NULL; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 289 | h1sl.rq.v = ist("HTTP/1.0"); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 290 | } |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 291 | |
| 292 | /* Set HTX start-line flags */ |
| 293 | if (h1m.flags & H1_MF_VER_11) |
| 294 | flags |= HTX_SL_F_VER_11; |
| 295 | if (h1m.flags & H1_MF_XFER_ENC) |
| 296 | flags |= HTX_SL_F_XFER_ENC; |
| 297 | flags |= HTX_SL_F_XFER_LEN; |
| 298 | if (h1m.flags & H1_MF_CHNK) |
| 299 | flags |= HTX_SL_F_CHNK; |
| 300 | else if (h1m.flags & H1_MF_CLEN) |
| 301 | flags |= HTX_SL_F_CLEN; |
| 302 | |
Richard Russo | c0968f5 | 2019-07-31 11:45:56 -0700 | [diff] [blame] | 303 | htx = htx_from_buf(get_raw_htx_chunk()); |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 304 | sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, h1sl.rq.m, h1sl.rq.u, h1sl.rq.v); |
| 305 | if (!sl || !htx_add_all_headers(htx, hdrs)) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 306 | return NULL; |
Willy Tarreau | ce9bbf5 | 2019-05-13 08:32:31 +0200 | [diff] [blame] | 307 | sl->info.req.meth = h1sl.rq.meth; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* OK we just got a valid HTTP message. If not already done by |
| 311 | * HTTP analyzers, we have some minor preparation to perform so |
| 312 | * that further checks can rely on HTTP tests. |
| 313 | */ |
| 314 | if (sl && msg->msg_state < HTTP_MSG_BODY) { |
| 315 | if (!(chn->flags & CF_ISRESP)) { |
| 316 | txn->meth = sl->info.req.meth; |
| 317 | if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD) |
| 318 | s->flags |= SF_REDIRECTABLE; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 319 | } |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 320 | else |
| 321 | txn->status = sl->info.res.status; |
| 322 | if (sl->flags & HTX_SL_F_VER_11) |
| 323 | msg->flags |= HTTP_MSGF_VER_11; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* everything's OK */ |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 327 | return htx; |
| 328 | } |
| 329 | |
| 330 | /* This function ensures that the prerequisites for an L7 fetch are ready, |
| 331 | * which means that a request or response is ready. If some data is missing, |
| 332 | * a parsing attempt is made. This is useful in TCP-based ACLs which are able |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 333 | * to extract data from L7. If <req_vol> is non-null during a request prefetch, |
| 334 | * another test is made to ensure the required information is not gone. |
| 335 | * |
| 336 | * The function returns : |
| 337 | * 0 with SMP_F_MAY_CHANGE in the sample flags if some data is missing to |
| 338 | * decide whether or not an HTTP message is present ; |
| 339 | * 0 if the requested data cannot be fetched or if it is certain that |
| 340 | * we'll never have any HTTP message there ; |
| 341 | * 1 if an HTTP message is ready |
| 342 | */ |
| 343 | int smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt, |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 344 | struct channel *chn, struct sample *smp, int req_vol) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 345 | { |
| 346 | struct http_txn *txn; |
| 347 | struct http_msg *msg; |
| 348 | |
| 349 | /* Note: it is possible that <s> is NULL when called before stream |
| 350 | * initialization (eg: tcp-request connection), so this function is the |
| 351 | * one responsible for guarding against this case for all HTTP users. |
| 352 | */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 353 | if (!s || !chn) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 354 | return 0; |
| 355 | |
| 356 | if (!s->txn) { |
| 357 | if (unlikely(!http_alloc_txn(s))) |
| 358 | return 0; /* not enough memory */ |
| 359 | http_init_txn(s); |
| 360 | } |
| 361 | txn = s->txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 362 | smp->data.type = SMP_T_BOOL; |
| 363 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 364 | if (chn->flags & CF_ISRESP) { |
| 365 | /* Check for a dependency on a response */ |
| 366 | if (txn->rsp.msg_state < HTTP_MSG_BODY) { |
| 367 | smp->flags |= SMP_F_MAY_CHANGE; |
| 368 | return 0; |
| 369 | } |
| 370 | goto end; |
| 371 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 372 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 373 | /* Check for a dependency on a request */ |
| 374 | msg = &txn->req; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 375 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 376 | if (req_vol && (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) { |
| 377 | return 0; /* data might have moved and indexes changed */ |
| 378 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 379 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 380 | /* If the buffer does not leave enough free space at the end, we must |
| 381 | * first realign it. |
| 382 | */ |
| 383 | if (ci_head(chn) > b_orig(&chn->buf) && |
| 384 | ci_head(chn) + ci_data(chn) > b_wrap(&chn->buf) - global.tune.maxrewrite) |
| 385 | channel_slow_realign(chn, trash.area); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 386 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 387 | if (unlikely(msg->msg_state < HTTP_MSG_BODY)) { |
| 388 | if (msg->msg_state == HTTP_MSG_ERROR) |
| 389 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 390 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 391 | /* Try to decode HTTP request */ |
| 392 | if (likely(msg->next < ci_data(chn))) |
| 393 | http_msg_analyzer(msg, &txn->hdr_idx); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 394 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 395 | /* Still no valid request ? */ |
| 396 | if (unlikely(msg->msg_state < HTTP_MSG_BODY)) { |
| 397 | if ((msg->msg_state == HTTP_MSG_ERROR) || |
| 398 | channel_full(chn, global.tune.maxrewrite)) { |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 399 | return 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 400 | } |
| 401 | /* wait for final state */ |
| 402 | smp->flags |= SMP_F_MAY_CHANGE; |
| 403 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 406 | /* OK we just got a valid HTTP message. We have some minor |
| 407 | * preparation to perform so that further checks can rely |
| 408 | * on HTTP tests. |
| 409 | */ |
| 410 | |
| 411 | /* If the message was parsed but was too large, we must absolutely |
| 412 | * return an error so that it is not processed. At the moment this |
| 413 | * cannot happen, but if the parsers are to change in the future, |
| 414 | * we want this check to be maintained. |
| 415 | */ |
| 416 | if (unlikely(ci_head(chn) + ci_data(chn) > |
| 417 | b_wrap(&chn->buf) - global.tune.maxrewrite)) { |
| 418 | msg->err_state = msg->msg_state; |
| 419 | msg->msg_state = HTTP_MSG_ERROR; |
| 420 | smp->data.u.sint = 1; |
| 421 | return 1; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 424 | txn->meth = find_http_meth(ci_head(chn), msg->sl.rq.m_l); |
| 425 | if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD) |
| 426 | s->flags |= SF_REDIRECTABLE; |
| 427 | |
| 428 | if (unlikely(msg->sl.rq.v_l == 0) && !http_upgrade_v09_to_v10(txn)) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 429 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 432 | end: |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 433 | /* everything's OK */ |
| 434 | smp->data.u.sint = 1; |
| 435 | return 1; |
| 436 | } |
| 437 | |
| 438 | /* This function fetches the method of current HTTP request and stores |
| 439 | * it in the global pattern struct as a chunk. There are two possibilities : |
| 440 | * - if the method is known (not HTTP_METH_OTHER), its identifier is stored |
| 441 | * in <len> and <ptr> is NULL ; |
| 442 | * - if the method is unknown (HTTP_METH_OTHER), <ptr> points to the text and |
| 443 | * <len> to its length. |
| 444 | * This is intended to be used with pat_match_meth() only. |
| 445 | */ |
| 446 | static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 447 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 448 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 449 | int meth; |
| 450 | struct http_txn *txn; |
| 451 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 452 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 453 | /* HTX version */ |
Willy Tarreau | 91d0b60 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 454 | txn = smp->strm->txn; |
| 455 | if (!txn) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 456 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 457 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 458 | meth = txn->meth; |
| 459 | smp->data.type = SMP_T_METH; |
| 460 | smp->data.u.meth.meth = meth; |
| 461 | if (meth == HTTP_METH_OTHER) { |
Willy Tarreau | 91d0b60 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 462 | struct htx *htx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 463 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 464 | |
Christopher Faulet | b99a3b0 | 2021-04-15 09:28:02 +0200 | [diff] [blame] | 465 | htx = smp_prefetch_htx(smp, chn, 1); |
Willy Tarreau | 91d0b60 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 466 | if (!htx) |
| 467 | return 0; |
| 468 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 469 | if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 470 | /* ensure the indexes are not affected */ |
| 471 | return 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 472 | } |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 473 | sl = http_get_stline(htx); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 474 | smp->flags |= SMP_F_CONST; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 475 | smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl); |
| 476 | smp->data.u.meth.str.data = HTX_SL_REQ_MLEN(sl); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 477 | } |
| 478 | smp->flags |= SMP_F_VOL_1ST; |
| 479 | } |
| 480 | else { |
| 481 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 482 | CHECK_HTTP_MESSAGE_FIRST_PERM(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 483 | |
| 484 | txn = smp->strm->txn; |
| 485 | meth = txn->meth; |
| 486 | smp->data.type = SMP_T_METH; |
| 487 | smp->data.u.meth.meth = meth; |
| 488 | if (meth == HTTP_METH_OTHER) { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 489 | if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 490 | /* ensure the indexes are not affected */ |
| 491 | return 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 492 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 493 | smp->flags |= SMP_F_CONST; |
| 494 | smp->data.u.meth.str.data = txn->req.sl.rq.m_l; |
| 495 | smp->data.u.meth.str.area = ci_head(txn->req.chn); |
| 496 | } |
| 497 | smp->flags |= SMP_F_VOL_1ST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 498 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 499 | return 1; |
| 500 | } |
| 501 | |
| 502 | static int smp_fetch_rqver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 503 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 504 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 505 | struct http_txn *txn; |
| 506 | char *ptr; |
| 507 | int len; |
| 508 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 509 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 510 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 511 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 512 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 513 | |
| 514 | if (!htx) |
| 515 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 516 | |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 517 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 518 | len = HTX_SL_REQ_VLEN(sl); |
| 519 | ptr = HTX_SL_REQ_VPTR(sl); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 520 | } |
| 521 | else { |
| 522 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 523 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 524 | |
| 525 | txn = smp->strm->txn; |
| 526 | len = txn->req.sl.rq.v_l; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 527 | ptr = ci_head(chn) + txn->req.sl.rq.v; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 528 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 529 | |
| 530 | while ((len-- > 0) && (*ptr++ != '/')); |
| 531 | if (len <= 0) |
| 532 | return 0; |
| 533 | |
| 534 | smp->data.type = SMP_T_STR; |
| 535 | smp->data.u.str.area = ptr; |
| 536 | smp->data.u.str.data = len; |
| 537 | |
| 538 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 539 | return 1; |
| 540 | } |
| 541 | |
| 542 | static int smp_fetch_stver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 543 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 544 | struct channel *chn = SMP_RES_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 545 | struct http_txn *txn; |
| 546 | char *ptr; |
| 547 | int len; |
| 548 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 549 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 550 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 551 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 552 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 553 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 554 | if (!htx) |
| 555 | return 0; |
| 556 | |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 557 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 558 | len = HTX_SL_RES_VLEN(sl); |
| 559 | ptr = HTX_SL_RES_VPTR(sl); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 560 | } |
| 561 | else { |
| 562 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 563 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 564 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 565 | txn = smp->strm->txn; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 566 | len = txn->rsp.sl.st.v_l; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 567 | ptr = ci_head(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 568 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 569 | |
| 570 | while ((len-- > 0) && (*ptr++ != '/')); |
| 571 | if (len <= 0) |
| 572 | return 0; |
| 573 | |
| 574 | smp->data.type = SMP_T_STR; |
| 575 | smp->data.u.str.area = ptr; |
| 576 | smp->data.u.str.data = len; |
| 577 | |
| 578 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 579 | return 1; |
| 580 | } |
| 581 | |
| 582 | /* 3. Check on Status Code. We manipulate integers here. */ |
| 583 | static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 584 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 585 | struct channel *chn = SMP_RES_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 586 | struct http_txn *txn; |
| 587 | char *ptr; |
| 588 | int len; |
| 589 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 590 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 591 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 592 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 593 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 594 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 595 | if (!htx) |
| 596 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 597 | |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 598 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 599 | len = HTX_SL_RES_CLEN(sl); |
| 600 | ptr = HTX_SL_RES_CPTR(sl); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 601 | } |
| 602 | else { |
| 603 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 604 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 605 | |
| 606 | txn = smp->strm->txn; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 607 | len = txn->rsp.sl.st.c_l; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 608 | ptr = ci_head(chn) + txn->rsp.sl.st.c; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 609 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 610 | |
| 611 | smp->data.type = SMP_T_SINT; |
| 612 | smp->data.u.sint = __strl2ui(ptr, len); |
| 613 | smp->flags = SMP_F_VOL_1ST; |
| 614 | return 1; |
| 615 | } |
| 616 | |
| 617 | static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 618 | { |
| 619 | if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id)) |
| 620 | return 0; |
| 621 | |
Willy Tarreau | c153462 | 2020-04-29 11:50:38 +0200 | [diff] [blame] | 622 | if (!smp->strm) |
| 623 | return 0; |
| 624 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 625 | if (!smp->strm->unique_id) { |
| 626 | if ((smp->strm->unique_id = pool_alloc(pool_head_uniqueid)) == NULL) |
| 627 | return 0; |
| 628 | smp->strm->unique_id[0] = '\0'; |
Tim Duesterhus | ea23a5c | 2020-02-26 16:20:49 +0100 | [diff] [blame] | 629 | build_logline(smp->strm, smp->strm->unique_id, |
| 630 | UNIQUEID_LEN, &smp->sess->fe->format_unique_id); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 631 | } |
Tim Duesterhus | ea23a5c | 2020-02-26 16:20:49 +0100 | [diff] [blame] | 632 | smp->data.u.str.data = strlen(smp->strm->unique_id); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 633 | smp->data.type = SMP_T_STR; |
| 634 | smp->data.u.str.area = smp->strm->unique_id; |
| 635 | smp->flags = SMP_F_CONST; |
| 636 | return 1; |
| 637 | } |
| 638 | |
| 639 | /* Returns a string block containing all headers including the |
Joseph Herlant | 942eea3 | 2018-11-15 13:57:22 -0800 | [diff] [blame] | 640 | * empty line which separes headers from the body. This is useful |
| 641 | * for some headers analysis. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 642 | */ |
| 643 | static int smp_fetch_hdrs(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 644 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 645 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 646 | struct http_txn *txn; |
| 647 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 648 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 649 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 650 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 651 | struct buffer *temp; |
| 652 | int32_t pos; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 653 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 654 | if (!htx) |
| 655 | return 0; |
| 656 | temp = get_trash_chunk(); |
Christopher Faulet | a3f1550 | 2019-05-13 15:27:23 +0200 | [diff] [blame] | 657 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 658 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 659 | enum htx_blk_type type = htx_get_blk_type(blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 660 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 661 | if (type == HTX_BLK_HDR) { |
| 662 | struct ist n = htx_get_blk_name(htx, blk); |
| 663 | struct ist v = htx_get_blk_value(htx, blk); |
| 664 | |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 665 | if (!htx_hdr_to_h1(n, v, temp)) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 666 | return 0; |
| 667 | } |
| 668 | else if (type == HTX_BLK_EOH) { |
| 669 | if (!chunk_memcat(temp, "\r\n", 2)) |
| 670 | return 0; |
| 671 | break; |
| 672 | } |
| 673 | } |
| 674 | smp->data.type = SMP_T_STR; |
| 675 | smp->data.u.str = *temp; |
| 676 | |
| 677 | } |
| 678 | else { |
| 679 | /* LEGACY version */ |
| 680 | struct http_msg *msg; |
| 681 | struct hdr_idx *idx; |
| 682 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 683 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 684 | |
| 685 | txn = smp->strm->txn; |
| 686 | idx = &txn->hdr_idx; |
| 687 | msg = &txn->req; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 688 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 689 | smp->data.type = SMP_T_STR; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 690 | smp->data.u.str.area = ci_head(chn) + hdr_idx_first_pos(idx); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 691 | smp->data.u.str.data = msg->eoh - hdr_idx_first_pos(idx) + 1 + |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 692 | (ci_head(chn)[msg->eoh] == '\r'); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 693 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 694 | return 1; |
| 695 | } |
| 696 | |
| 697 | /* Returns the header request in a length/value encoded format. |
| 698 | * This is useful for exchanges with the SPOE. |
| 699 | * |
| 700 | * A "length value" is a multibyte code encoding numbers. It uses the |
| 701 | * SPOE format. The encoding is the following: |
| 702 | * |
| 703 | * Each couple "header name" / "header value" is composed |
| 704 | * like this: |
| 705 | * "length value" "header name bytes" |
| 706 | * "length value" "header value bytes" |
| 707 | * When the last header is reached, the header name and the header |
| 708 | * value are empty. Their length are 0 |
| 709 | */ |
| 710 | static int smp_fetch_hdrs_bin(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 711 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 712 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 713 | struct http_txn *txn; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 714 | struct buffer *temp; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 715 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 716 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 717 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 718 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 719 | struct buffer *temp; |
| 720 | char *p, *end; |
| 721 | int32_t pos; |
| 722 | int ret; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 723 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 724 | if (!htx) |
| 725 | return 0; |
| 726 | temp = get_trash_chunk(); |
| 727 | p = temp->area; |
| 728 | end = temp->area + temp->size; |
Christopher Faulet | a3f1550 | 2019-05-13 15:27:23 +0200 | [diff] [blame] | 729 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 730 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 731 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 732 | struct ist n, v; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 733 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 734 | if (type == HTX_BLK_HDR) { |
| 735 | n = htx_get_blk_name(htx,blk); |
| 736 | v = htx_get_blk_value(htx, blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 737 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 738 | /* encode the header name. */ |
| 739 | ret = encode_varint(n.len, &p, end); |
| 740 | if (ret == -1) |
| 741 | return 0; |
| 742 | if (p + n.len > end) |
| 743 | return 0; |
| 744 | memcpy(p, n.ptr, n.len); |
| 745 | p += n.len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 746 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 747 | /* encode the header value. */ |
| 748 | ret = encode_varint(v.len, &p, end); |
| 749 | if (ret == -1) |
| 750 | return 0; |
| 751 | if (p + v.len > end) |
| 752 | return 0; |
| 753 | memcpy(p, v.ptr, v.len); |
| 754 | p += v.len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 755 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 756 | } |
| 757 | else if (type == HTX_BLK_EOH) { |
| 758 | /* encode the end of the header list with empty |
| 759 | * header name and header value. |
| 760 | */ |
| 761 | ret = encode_varint(0, &p, end); |
| 762 | if (ret == -1) |
| 763 | return 0; |
| 764 | ret = encode_varint(0, &p, end); |
| 765 | if (ret == -1) |
| 766 | return 0; |
| 767 | break; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | /* Initialise sample data which will be filled. */ |
| 772 | smp->data.type = SMP_T_BIN; |
| 773 | smp->data.u.str.area = temp->area; |
| 774 | smp->data.u.str.data = p - temp->area; |
| 775 | smp->data.u.str.size = temp->size; |
| 776 | } |
| 777 | else { |
| 778 | /* LEGACY version */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 779 | struct hdr_idx *idx; |
| 780 | const char *cur_ptr, *cur_next, *p; |
| 781 | int old_idx, cur_idx; |
| 782 | struct hdr_idx_elem *cur_hdr; |
| 783 | const char *hn, *hv; |
| 784 | int hnl, hvl; |
| 785 | int ret; |
| 786 | char *buf; |
| 787 | char *end; |
| 788 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 789 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 790 | |
| 791 | temp = get_trash_chunk(); |
| 792 | buf = temp->area; |
| 793 | end = temp->area + temp->size; |
| 794 | |
| 795 | txn = smp->strm->txn; |
| 796 | idx = &txn->hdr_idx; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 797 | |
| 798 | /* Build array of headers. */ |
| 799 | old_idx = 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 800 | cur_next = ci_head(chn) + hdr_idx_first_pos(idx); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 801 | while (1) { |
| 802 | cur_idx = idx->v[old_idx].next; |
| 803 | if (!cur_idx) |
| 804 | break; |
| 805 | old_idx = cur_idx; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 806 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 807 | cur_hdr = &idx->v[cur_idx]; |
| 808 | cur_ptr = cur_next; |
| 809 | cur_next = cur_ptr + cur_hdr->len + cur_hdr->cr + 1; |
| 810 | |
| 811 | /* Now we have one full header at cur_ptr of len cur_hdr->len, |
| 812 | * and the next header starts at cur_next. We'll check |
| 813 | * this header in the list as well as against the default |
| 814 | * rule. |
| 815 | */ |
| 816 | |
| 817 | /* look for ': *'. */ |
| 818 | hn = cur_ptr; |
| 819 | for (p = cur_ptr; p < cur_ptr + cur_hdr->len && *p != ':'; p++); |
| 820 | if (p >= cur_ptr+cur_hdr->len) |
| 821 | continue; |
| 822 | hnl = p - hn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 823 | p++; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 824 | while (p < cur_ptr + cur_hdr->len && (*p == ' ' || *p == '\t')) |
| 825 | p++; |
| 826 | if (p >= cur_ptr + cur_hdr->len) |
| 827 | continue; |
| 828 | hv = p; |
| 829 | hvl = cur_ptr + cur_hdr->len-p; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 830 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 831 | /* encode the header name. */ |
| 832 | ret = encode_varint(hnl, &buf, end); |
| 833 | if (ret == -1) |
| 834 | return 0; |
| 835 | if (buf + hnl > end) |
| 836 | return 0; |
| 837 | memcpy(buf, hn, hnl); |
| 838 | buf += hnl; |
| 839 | |
| 840 | /* encode and copy the value. */ |
| 841 | ret = encode_varint(hvl, &buf, end); |
| 842 | if (ret == -1) |
| 843 | return 0; |
| 844 | if (buf + hvl > end) |
| 845 | return 0; |
| 846 | memcpy(buf, hv, hvl); |
| 847 | buf += hvl; |
| 848 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 849 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 850 | /* encode the end of the header list with empty |
| 851 | * header name and header value. |
| 852 | */ |
| 853 | ret = encode_varint(0, &buf, end); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 854 | if (ret == -1) |
| 855 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 856 | ret = encode_varint(0, &buf, end); |
| 857 | if (ret == -1) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 858 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 859 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 860 | /* Initialise sample data which will be filled. */ |
| 861 | smp->data.type = SMP_T_BIN; |
| 862 | smp->data.u.str.area = temp->area; |
| 863 | smp->data.u.str.data = buf - temp->area; |
| 864 | smp->data.u.str.size = temp->size; |
| 865 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 866 | return 1; |
| 867 | } |
| 868 | |
| 869 | /* returns the longest available part of the body. This requires that the body |
| 870 | * has been waited for using http-buffer-request. |
| 871 | */ |
| 872 | static int smp_fetch_body(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 873 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 874 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 875 | struct buffer *temp; |
| 876 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 877 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 878 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 879 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 880 | int32_t pos; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 881 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 882 | if (!htx) |
| 883 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 884 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 885 | temp = get_trash_chunk(); |
Christopher Faulet | a3f1550 | 2019-05-13 15:27:23 +0200 | [diff] [blame] | 886 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 887 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 888 | enum htx_blk_type type = htx_get_blk_type(blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 889 | |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 890 | if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 891 | break; |
| 892 | if (type == HTX_BLK_DATA) { |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 893 | if (!htx_data_to_h1(htx_get_blk_value(htx, blk), temp, 0)) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 894 | return 0; |
| 895 | } |
| 896 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 897 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 898 | smp->data.type = SMP_T_BIN; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 899 | smp->data.u.str = *temp; |
| 900 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 901 | } |
| 902 | else { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 903 | /* LEGACY version */ |
| 904 | struct http_msg *msg; |
| 905 | unsigned long len; |
| 906 | unsigned long block1; |
| 907 | char *body; |
| 908 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 909 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 910 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 911 | msg = &smp->strm->txn->req; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 912 | len = http_body_bytes(msg); |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 913 | body = c_ptr(chn, -http_data_rewind(msg)); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 914 | |
| 915 | block1 = len; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 916 | if (block1 > b_wrap(&chn->buf) - body) |
| 917 | block1 = b_wrap(&chn->buf) - body; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 918 | |
| 919 | if (block1 == len) { |
| 920 | /* buffer is not wrapped (or empty) */ |
| 921 | smp->data.type = SMP_T_BIN; |
| 922 | smp->data.u.str.area = body; |
| 923 | smp->data.u.str.data = len; |
| 924 | smp->flags = SMP_F_VOL_TEST | SMP_F_CONST; |
| 925 | } |
| 926 | else { |
| 927 | /* buffer is wrapped, we need to defragment it */ |
| 928 | temp = get_trash_chunk(); |
| 929 | memcpy(temp->area, body, block1); |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 930 | memcpy(temp->area + block1, b_orig(&chn->buf), len - block1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 931 | smp->data.type = SMP_T_BIN; |
| 932 | smp->data.u.str.area = temp->area; |
| 933 | smp->data.u.str.data = len; |
| 934 | smp->flags = SMP_F_VOL_TEST; |
| 935 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 936 | } |
| 937 | return 1; |
| 938 | } |
| 939 | |
| 940 | |
| 941 | /* returns the available length of the body. This requires that the body |
| 942 | * has been waited for using http-buffer-request. |
| 943 | */ |
| 944 | static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 945 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 946 | struct channel *chn = SMP_REQ_CHN(smp); |
| 947 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 948 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 949 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 950 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Dragan Dosen | 5a60668 | 2019-02-14 12:30:53 +0100 | [diff] [blame] | 951 | int32_t pos; |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 952 | unsigned long long len = 0; |
| 953 | |
| 954 | if (!htx) |
| 955 | return 0; |
| 956 | |
Christopher Faulet | a3f1550 | 2019-05-13 15:27:23 +0200 | [diff] [blame] | 957 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Dragan Dosen | 5a60668 | 2019-02-14 12:30:53 +0100 | [diff] [blame] | 958 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 959 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 960 | |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 961 | if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 962 | break; |
Dragan Dosen | 5a60668 | 2019-02-14 12:30:53 +0100 | [diff] [blame] | 963 | if (type == HTX_BLK_DATA) |
| 964 | len += htx_get_blksz(blk); |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | smp->data.type = SMP_T_SINT; |
| 968 | smp->data.u.sint = len; |
| 969 | |
| 970 | smp->flags = SMP_F_VOL_TEST; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 971 | } |
| 972 | else { |
| 973 | /* LEGACY version */ |
| 974 | struct http_msg *msg; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 975 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 976 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 977 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 978 | msg = &smp->strm->txn->req; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 979 | smp->data.type = SMP_T_SINT; |
| 980 | smp->data.u.sint = http_body_bytes(msg); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 981 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 982 | smp->flags = SMP_F_VOL_TEST; |
| 983 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 984 | return 1; |
| 985 | } |
| 986 | |
| 987 | |
| 988 | /* returns the advertised length of the body, or the advertised size of the |
| 989 | * chunks available in the buffer. This requires that the body has been waited |
| 990 | * for using http-buffer-request. |
| 991 | */ |
| 992 | static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 993 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 994 | struct channel *chn = SMP_REQ_CHN(smp); |
| 995 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 996 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 997 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 998 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Dragan Dosen | 5a60668 | 2019-02-14 12:30:53 +0100 | [diff] [blame] | 999 | int32_t pos; |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 1000 | unsigned long long len = 0; |
| 1001 | |
| 1002 | if (!htx) |
| 1003 | return 0; |
| 1004 | |
Christopher Faulet | a3f1550 | 2019-05-13 15:27:23 +0200 | [diff] [blame] | 1005 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Dragan Dosen | 5a60668 | 2019-02-14 12:30:53 +0100 | [diff] [blame] | 1006 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 1007 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 1008 | |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 1009 | if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 1010 | break; |
Dragan Dosen | 5a60668 | 2019-02-14 12:30:53 +0100 | [diff] [blame] | 1011 | if (type == HTX_BLK_DATA) |
| 1012 | len += htx_get_blksz(blk); |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 1013 | } |
| 1014 | if (htx->extra != ULLONG_MAX) |
| 1015 | len += htx->extra; |
| 1016 | |
| 1017 | smp->data.type = SMP_T_SINT; |
| 1018 | smp->data.u.sint = len; |
| 1019 | |
| 1020 | smp->flags = SMP_F_VOL_TEST; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1021 | } |
| 1022 | else { |
| 1023 | /* LEGACY version */ |
| 1024 | struct http_msg *msg; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1025 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1026 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1027 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1028 | msg = &smp->strm->txn->req; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1029 | smp->data.type = SMP_T_SINT; |
| 1030 | smp->data.u.sint = msg->body_len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1031 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1032 | smp->flags = SMP_F_VOL_TEST; |
| 1033 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1034 | return 1; |
| 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | /* 4. Check on URL/URI. A pointer to the URI is stored. */ |
| 1039 | static int smp_fetch_url(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1040 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1041 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1042 | struct http_txn *txn; |
| 1043 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1044 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1045 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1046 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1047 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1048 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1049 | if (!htx) |
| 1050 | return 0; |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 1051 | sl = http_get_stline(htx); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1052 | smp->data.type = SMP_T_STR; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1053 | smp->data.u.str.area = HTX_SL_REQ_UPTR(sl); |
| 1054 | smp->data.u.str.data = HTX_SL_REQ_ULEN(sl); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1055 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 1056 | } |
| 1057 | else { |
| 1058 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1059 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1060 | |
| 1061 | txn = smp->strm->txn; |
| 1062 | smp->data.type = SMP_T_STR; |
| 1063 | smp->data.u.str.data = txn->req.sl.rq.u_l; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1064 | smp->data.u.str.area = ci_head(chn) + txn->req.sl.rq.u; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1065 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 1066 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1067 | return 1; |
| 1068 | } |
| 1069 | |
| 1070 | static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1071 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1072 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1073 | struct http_txn *txn; |
| 1074 | struct sockaddr_storage addr; |
| 1075 | |
Amaury Denoyelle | 0ef3a71 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 1076 | memset(&addr, 0, sizeof(addr)); |
| 1077 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1078 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1079 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1080 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1081 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1082 | |
| 1083 | if (!htx) |
| 1084 | return 0; |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 1085 | sl = http_get_stline(htx); |
Amaury Denoyelle | 0ef3a71 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 1086 | if (url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL) < 0) |
| 1087 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1088 | } |
| 1089 | else { |
| 1090 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1091 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1092 | |
| 1093 | txn = smp->strm->txn; |
Amaury Denoyelle | 0ef3a71 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 1094 | if (url2sa(ci_head(chn) + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &addr, NULL) < 0) |
| 1095 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1096 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1097 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1098 | if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) |
| 1099 | return 0; |
| 1100 | |
| 1101 | smp->data.type = SMP_T_IPV4; |
| 1102 | smp->data.u.ipv4 = ((struct sockaddr_in *)&addr)->sin_addr; |
| 1103 | smp->flags = 0; |
| 1104 | return 1; |
| 1105 | } |
| 1106 | |
| 1107 | static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1108 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1109 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1110 | struct http_txn *txn; |
| 1111 | struct sockaddr_storage addr; |
| 1112 | |
Amaury Denoyelle | 0ef3a71 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 1113 | memset(&addr, 0, sizeof(addr)); |
| 1114 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1115 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1116 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1117 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1118 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1119 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1120 | if (!htx) |
| 1121 | return 0; |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 1122 | sl = http_get_stline(htx); |
Amaury Denoyelle | 0ef3a71 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 1123 | if (url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL) < 0) |
| 1124 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1125 | } |
| 1126 | else { |
| 1127 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1128 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1129 | |
| 1130 | txn = smp->strm->txn; |
Amaury Denoyelle | 0ef3a71 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 1131 | if (url2sa(ci_head(chn) + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &addr, NULL) < 0) |
| 1132 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1133 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1134 | if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) |
| 1135 | return 0; |
| 1136 | |
| 1137 | smp->data.type = SMP_T_SINT; |
| 1138 | smp->data.u.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port); |
| 1139 | smp->flags = 0; |
| 1140 | return 1; |
| 1141 | } |
| 1142 | |
| 1143 | /* Fetch an HTTP header. A pointer to the beginning of the value is returned. |
| 1144 | * Accepts an optional argument of type string containing the header field name, |
| 1145 | * and an optional argument of type signed or unsigned integer to request an |
| 1146 | * explicit occurrence of the header. Note that in the event of a missing name, |
| 1147 | * headers are considered from the first one. It does not stop on commas and |
| 1148 | * returns full lines instead (useful for User-Agent or Date for example). |
| 1149 | */ |
| 1150 | static int smp_fetch_fhdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1151 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1152 | /* possible keywords: req.fhdr, res.fhdr */ |
| 1153 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1154 | int occ = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1155 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1156 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1157 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1158 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1159 | struct http_hdr_ctx *ctx = smp->ctx.a[0]; |
| 1160 | struct ist name; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1161 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1162 | if (!ctx) { |
| 1163 | /* first call */ |
| 1164 | ctx = &static_http_hdr_ctx; |
| 1165 | ctx->blk = NULL; |
| 1166 | smp->ctx.a[0] = ctx; |
| 1167 | } |
| 1168 | |
| 1169 | if (args) { |
| 1170 | if (args[0].type != ARGT_STR) |
| 1171 | return 0; |
| 1172 | name.ptr = args[0].data.str.area; |
| 1173 | name.len = args[0].data.str.data; |
| 1174 | |
| 1175 | if (args[1].type == ARGT_SINT) |
| 1176 | occ = args[1].data.sint; |
| 1177 | } |
| 1178 | |
| 1179 | if (!htx) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1180 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1181 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1182 | if (ctx && !(smp->flags & SMP_F_NOT_LAST)) |
| 1183 | /* search for header from the beginning */ |
| 1184 | ctx->blk = NULL; |
| 1185 | |
| 1186 | if (!occ && !(smp->opt & SMP_OPT_ITERATE)) |
| 1187 | /* no explicit occurrence and single fetch => last header by default */ |
| 1188 | occ = -1; |
| 1189 | |
| 1190 | if (!occ) |
| 1191 | /* prepare to report multiple occurrences for ACL fetches */ |
| 1192 | smp->flags |= SMP_F_NOT_LAST; |
| 1193 | |
| 1194 | smp->data.type = SMP_T_STR; |
| 1195 | smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; |
| 1196 | if (http_get_htx_fhdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data)) |
| 1197 | return 1; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1198 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1199 | else { |
| 1200 | /* LEGACY version */ |
| 1201 | struct hdr_idx *idx; |
| 1202 | struct hdr_ctx *ctx = smp->ctx.a[0]; |
| 1203 | const struct http_msg *msg; |
| 1204 | const char *name_str = NULL; |
| 1205 | int name_len = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1206 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1207 | if (!ctx) { |
| 1208 | /* first call */ |
| 1209 | ctx = &static_hdr_ctx; |
| 1210 | ctx->idx = 0; |
| 1211 | smp->ctx.a[0] = ctx; |
| 1212 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1213 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1214 | if (args) { |
| 1215 | if (args[0].type != ARGT_STR) |
| 1216 | return 0; |
| 1217 | name_str = args[0].data.str.area; |
| 1218 | name_len = args[0].data.str.data; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1219 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1220 | if (args[1].type == ARGT_SINT) |
| 1221 | occ = args[1].data.sint; |
| 1222 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1223 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1224 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1225 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1226 | idx = &smp->strm->txn->hdr_idx; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1227 | msg = (!(chn->flags & CF_ISRESP) ? &smp->strm->txn->req : &smp->strm->txn->rsp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1228 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1229 | if (ctx && !(smp->flags & SMP_F_NOT_LAST)) |
| 1230 | /* search for header from the beginning */ |
| 1231 | ctx->idx = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1232 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1233 | if (!occ && !(smp->opt & SMP_OPT_ITERATE)) |
| 1234 | /* no explicit occurrence and single fetch => last header by default */ |
| 1235 | occ = -1; |
| 1236 | |
| 1237 | if (!occ) |
| 1238 | /* prepare to report multiple occurrences for ACL fetches */ |
| 1239 | smp->flags |= SMP_F_NOT_LAST; |
| 1240 | |
| 1241 | smp->data.type = SMP_T_STR; |
| 1242 | smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; |
| 1243 | if (http_get_fhdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data)) |
| 1244 | return 1; |
| 1245 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1246 | smp->flags &= ~SMP_F_NOT_LAST; |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | /* 6. Check on HTTP header count. The number of occurrences is returned. |
| 1251 | * Accepts exactly 1 argument of type string. It does not stop on commas and |
| 1252 | * returns full lines instead (useful for User-Agent or Date for example). |
| 1253 | */ |
| 1254 | static int smp_fetch_fhdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1255 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1256 | /* possible keywords: req.fhdr_cnt, res.fhdr_cnt */ |
| 1257 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1258 | int cnt; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1259 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1260 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1261 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1262 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1263 | struct http_hdr_ctx ctx; |
| 1264 | struct ist name; |
| 1265 | |
| 1266 | if (!htx) |
| 1267 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1268 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1269 | if (args && args->type == ARGT_STR) { |
| 1270 | name.ptr = args->data.str.area; |
| 1271 | name.len = args->data.str.data; |
Olivier Houchard | e2c78cd | 2018-11-21 13:49:48 +0100 | [diff] [blame] | 1272 | } else { |
| 1273 | name.ptr = NULL; |
| 1274 | name.len = 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | ctx.blk = NULL; |
| 1278 | cnt = 0; |
| 1279 | while (http_find_header(htx, name, &ctx, 1)) |
| 1280 | cnt++; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1281 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1282 | else { |
| 1283 | /* LEGACY version */ |
| 1284 | struct hdr_idx *idx; |
| 1285 | struct hdr_ctx ctx; |
| 1286 | const struct http_msg *msg; |
| 1287 | const char *name = NULL; |
| 1288 | int len = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1289 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1290 | if (args && args->type == ARGT_STR) { |
| 1291 | name = args->data.str.area; |
| 1292 | len = args->data.str.data; |
| 1293 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1294 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1295 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1296 | |
| 1297 | idx = &smp->strm->txn->hdr_idx; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1298 | msg = (!(chn->flags & CF_ISRESP) ? &smp->strm->txn->req : &smp->strm->txn->rsp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1299 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1300 | ctx.idx = 0; |
| 1301 | cnt = 0; |
| 1302 | while (http_find_full_header2(name, len, ci_head(msg->chn), idx, &ctx)) |
| 1303 | cnt++; |
| 1304 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1305 | |
| 1306 | smp->data.type = SMP_T_SINT; |
| 1307 | smp->data.u.sint = cnt; |
| 1308 | smp->flags = SMP_F_VOL_HDR; |
| 1309 | return 1; |
| 1310 | } |
| 1311 | |
| 1312 | static int smp_fetch_hdr_names(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1313 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1314 | /* possible keywords: req.hdr_names, res.hdr_names */ |
| 1315 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1316 | struct buffer *temp; |
| 1317 | char del = ','; |
| 1318 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1319 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1320 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1321 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1322 | int32_t pos; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1323 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1324 | if (!htx) |
| 1325 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1326 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1327 | if (args && args->type == ARGT_STR) |
| 1328 | del = *args[0].data.str.area; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1329 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1330 | temp = get_trash_chunk(); |
Christopher Faulet | a3f1550 | 2019-05-13 15:27:23 +0200 | [diff] [blame] | 1331 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1332 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 1333 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 1334 | struct ist n; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1335 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1336 | if (type == HTX_BLK_EOH) |
| 1337 | break; |
| 1338 | if (type != HTX_BLK_HDR) |
| 1339 | continue; |
| 1340 | n = htx_get_blk_name(htx, blk); |
| 1341 | |
| 1342 | if (temp->data) |
| 1343 | temp->area[temp->data++] = del; |
| 1344 | chunk_memcat(temp, n.ptr, n.len); |
| 1345 | } |
| 1346 | } |
| 1347 | else { |
| 1348 | /* LEGACY version */ |
| 1349 | struct hdr_idx *idx; |
| 1350 | struct hdr_ctx ctx; |
| 1351 | const struct http_msg *msg; |
| 1352 | |
| 1353 | if (args && args->type == ARGT_STR) |
| 1354 | del = *args[0].data.str.area; |
| 1355 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1356 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1357 | |
| 1358 | idx = &smp->strm->txn->hdr_idx; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1359 | msg = (!(chn->flags & CF_ISRESP) ? &smp->strm->txn->req : &smp->strm->txn->rsp); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1360 | |
| 1361 | temp = get_trash_chunk(); |
| 1362 | |
| 1363 | ctx.idx = 0; |
| 1364 | while (http_find_next_header(ci_head(msg->chn), idx, &ctx)) { |
| 1365 | if (temp->data) |
| 1366 | temp->area[temp->data++] = del; |
| 1367 | memcpy(temp->area + temp->data, ctx.line, ctx.del); |
| 1368 | temp->data += ctx.del; |
| 1369 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | smp->data.type = SMP_T_STR; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1373 | smp->data.u.str = *temp; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1374 | smp->flags = SMP_F_VOL_HDR; |
| 1375 | return 1; |
| 1376 | } |
| 1377 | |
| 1378 | /* Fetch an HTTP header. A pointer to the beginning of the value is returned. |
| 1379 | * Accepts an optional argument of type string containing the header field name, |
| 1380 | * and an optional argument of type signed or unsigned integer to request an |
| 1381 | * explicit occurrence of the header. Note that in the event of a missing name, |
| 1382 | * headers are considered from the first one. |
| 1383 | */ |
| 1384 | static int smp_fetch_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1385 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1386 | /* possible keywords: req.hdr / hdr, res.hdr / shdr */ |
| 1387 | struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1388 | int occ = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1389 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1390 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1391 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1392 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1393 | struct http_hdr_ctx *ctx = smp->ctx.a[0]; |
| 1394 | struct ist name; |
| 1395 | |
| 1396 | if (!ctx) { |
| 1397 | /* first call */ |
| 1398 | ctx = &static_http_hdr_ctx; |
| 1399 | ctx->blk = NULL; |
| 1400 | smp->ctx.a[0] = ctx; |
| 1401 | } |
| 1402 | |
| 1403 | if (args) { |
| 1404 | if (args[0].type != ARGT_STR) |
| 1405 | return 0; |
| 1406 | name.ptr = args[0].data.str.area; |
| 1407 | name.len = args[0].data.str.data; |
| 1408 | |
| 1409 | if (args[1].type == ARGT_SINT) |
| 1410 | occ = args[1].data.sint; |
| 1411 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1412 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1413 | if (!htx) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1414 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1415 | |
| 1416 | if (ctx && !(smp->flags & SMP_F_NOT_LAST)) |
| 1417 | /* search for header from the beginning */ |
| 1418 | ctx->blk = NULL; |
| 1419 | |
| 1420 | if (!occ && !(smp->opt & SMP_OPT_ITERATE)) |
| 1421 | /* no explicit occurrence and single fetch => last header by default */ |
| 1422 | occ = -1; |
| 1423 | |
| 1424 | if (!occ) |
| 1425 | /* prepare to report multiple occurrences for ACL fetches */ |
| 1426 | smp->flags |= SMP_F_NOT_LAST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1427 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1428 | smp->data.type = SMP_T_STR; |
| 1429 | smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; |
| 1430 | if (http_get_htx_hdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data)) |
| 1431 | return 1; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1432 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1433 | else { |
| 1434 | /* LEGACY version */ |
| 1435 | struct hdr_idx *idx; |
| 1436 | struct hdr_ctx *ctx = smp->ctx.a[0]; |
| 1437 | const struct http_msg *msg; |
| 1438 | const char *name_str = NULL; |
| 1439 | int name_len = 0; |
| 1440 | |
| 1441 | if (!ctx) { |
| 1442 | /* first call */ |
| 1443 | ctx = &static_hdr_ctx; |
| 1444 | ctx->idx = 0; |
| 1445 | smp->ctx.a[0] = ctx; |
| 1446 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1447 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1448 | if (args) { |
| 1449 | if (args[0].type != ARGT_STR) |
| 1450 | return 0; |
| 1451 | name_str = args[0].data.str.area; |
| 1452 | name_len = args[0].data.str.data; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1453 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1454 | if (args[1].type == ARGT_SINT) |
| 1455 | occ = args[1].data.sint; |
| 1456 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1457 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1458 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1459 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1460 | idx = &smp->strm->txn->hdr_idx; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1461 | msg = (!(chn->flags & CF_ISRESP) ? &smp->strm->txn->req : &smp->strm->txn->rsp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1462 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1463 | if (ctx && !(smp->flags & SMP_F_NOT_LAST)) |
| 1464 | /* search for header from the beginning */ |
| 1465 | ctx->idx = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1466 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1467 | if (!occ && !(smp->opt & SMP_OPT_ITERATE)) |
| 1468 | /* no explicit occurrence and single fetch => last header by default */ |
| 1469 | occ = -1; |
| 1470 | |
| 1471 | if (!occ) |
| 1472 | /* prepare to report multiple occurrences for ACL fetches */ |
| 1473 | smp->flags |= SMP_F_NOT_LAST; |
| 1474 | |
| 1475 | smp->data.type = SMP_T_STR; |
| 1476 | smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; |
| 1477 | if (http_get_hdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data)) |
| 1478 | return 1; |
| 1479 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1480 | |
| 1481 | smp->flags &= ~SMP_F_NOT_LAST; |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
Christopher Faulet | c1f40dd | 2019-05-16 10:07:30 +0200 | [diff] [blame] | 1485 | /* Same than smp_fetch_hdr() but only relies on the sample direction to choose |
| 1486 | * the right channel. So instead of duplicating the code, we just change the |
| 1487 | * keyword and then fallback on smp_fetch_hdr(). |
| 1488 | */ |
| 1489 | static int smp_fetch_chn_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1490 | { |
| 1491 | kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.hdr" : "res.hdr"); |
| 1492 | return smp_fetch_hdr(args, smp, kw, private); |
| 1493 | } |
| 1494 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1495 | /* 6. Check on HTTP header count. The number of occurrences is returned. |
| 1496 | * Accepts exactly 1 argument of type string. |
| 1497 | */ |
| 1498 | static int smp_fetch_hdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1499 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1500 | /* possible keywords: req.hdr_cnt / hdr_cnt, res.hdr_cnt / shdr_cnt */ |
| 1501 | struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1502 | int cnt; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1503 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1504 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1505 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1506 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1507 | struct http_hdr_ctx ctx; |
| 1508 | struct ist name; |
| 1509 | |
| 1510 | if (!htx) |
| 1511 | return 0; |
| 1512 | |
| 1513 | if (args && args->type == ARGT_STR) { |
| 1514 | name.ptr = args->data.str.area; |
| 1515 | name.len = args->data.str.data; |
Olivier Houchard | e2c78cd | 2018-11-21 13:49:48 +0100 | [diff] [blame] | 1516 | } else { |
| 1517 | name.ptr = NULL; |
| 1518 | name.len = 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1519 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1520 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1521 | ctx.blk = NULL; |
| 1522 | cnt = 0; |
| 1523 | while (http_find_header(htx, name, &ctx, 0)) |
| 1524 | cnt++; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1525 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1526 | else { |
| 1527 | /* LEGACY version */ |
| 1528 | struct hdr_idx *idx; |
| 1529 | struct hdr_ctx ctx; |
| 1530 | const struct http_msg *msg; |
| 1531 | const char *name = NULL; |
| 1532 | int len = 0; |
| 1533 | |
| 1534 | if (args && args->type == ARGT_STR) { |
| 1535 | name = args->data.str.area; |
| 1536 | len = args->data.str.data; |
| 1537 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1538 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1539 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1540 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1541 | idx = &smp->strm->txn->hdr_idx; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1542 | msg = (!(chn->flags & CF_ISRESP) ? &smp->strm->txn->req : &smp->strm->txn->rsp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1543 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1544 | ctx.idx = 0; |
| 1545 | cnt = 0; |
| 1546 | while (http_find_header2(name, len, ci_head(msg->chn), idx, &ctx)) |
| 1547 | cnt++; |
| 1548 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1549 | |
| 1550 | smp->data.type = SMP_T_SINT; |
| 1551 | smp->data.u.sint = cnt; |
| 1552 | smp->flags = SMP_F_VOL_HDR; |
| 1553 | return 1; |
| 1554 | } |
| 1555 | |
| 1556 | /* Fetch an HTTP header's integer value. The integer value is returned. It |
| 1557 | * takes a mandatory argument of type string and an optional one of type int |
| 1558 | * to designate a specific occurrence. It returns an unsigned integer, which |
| 1559 | * may or may not be appropriate for everything. |
| 1560 | */ |
| 1561 | static int smp_fetch_hdr_val(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1562 | { |
| 1563 | int ret = smp_fetch_hdr(args, smp, kw, private); |
| 1564 | |
| 1565 | if (ret > 0) { |
| 1566 | smp->data.type = SMP_T_SINT; |
| 1567 | smp->data.u.sint = strl2ic(smp->data.u.str.area, |
| 1568 | smp->data.u.str.data); |
| 1569 | } |
| 1570 | |
| 1571 | return ret; |
| 1572 | } |
| 1573 | |
| 1574 | /* Fetch an HTTP header's IP value. takes a mandatory argument of type string |
| 1575 | * and an optional one of type int to designate a specific occurrence. |
Willy Tarreau | d08feaf | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1576 | * It returns an IPv4 or IPv6 address. Addresses surrounded by invalid chars |
| 1577 | * are rejected. However IPv4 addresses may be followed with a colon and a |
| 1578 | * valid port number. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1579 | */ |
| 1580 | static int smp_fetch_hdr_ip(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1581 | { |
Tim Duesterhus | 8ba978b | 2020-06-26 15:44:48 +0200 | [diff] [blame] | 1582 | struct buffer *temp = get_trash_chunk(); |
Willy Tarreau | d08feaf | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1583 | int ret, len; |
| 1584 | int port; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1585 | |
| 1586 | while ((ret = smp_fetch_hdr(args, smp, kw, private)) > 0) { |
Tim Duesterhus | 8ba978b | 2020-06-26 15:44:48 +0200 | [diff] [blame] | 1587 | if (smp->data.u.str.data < temp->size - 1) { |
| 1588 | memcpy(temp->area, smp->data.u.str.area, |
| 1589 | smp->data.u.str.data); |
| 1590 | temp->area[smp->data.u.str.data] = '\0'; |
Willy Tarreau | d08feaf | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1591 | len = url2ipv4((char *) temp->area, &smp->data.u.ipv4); |
Willy Tarreau | 30df20d | 2021-03-31 11:41:36 +0200 | [diff] [blame] | 1592 | if (len > 0 && len == smp->data.u.str.data) { |
Willy Tarreau | d08feaf | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1593 | /* plain IPv4 address */ |
| 1594 | smp->data.type = SMP_T_IPV4; |
| 1595 | break; |
| 1596 | } else if (len > 0 && temp->area[len] == ':' && |
| 1597 | strl2irc(temp->area + len + 1, smp->data.u.str.data - len - 1, &port) == 0 && |
| 1598 | port >= 0 && port <= 65535) { |
| 1599 | /* IPv4 address suffixed with ':' followed by a valid port number */ |
Tim Duesterhus | 8ba978b | 2020-06-26 15:44:48 +0200 | [diff] [blame] | 1600 | smp->data.type = SMP_T_IPV4; |
| 1601 | break; |
| 1602 | } else if (inet_pton(AF_INET6, temp->area, &smp->data.u.ipv6)) { |
| 1603 | smp->data.type = SMP_T_IPV6; |
| 1604 | break; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | /* if the header doesn't match an IP address, fetch next one */ |
| 1609 | if (!(smp->flags & SMP_F_NOT_LAST)) |
| 1610 | return 0; |
| 1611 | } |
| 1612 | return ret; |
| 1613 | } |
| 1614 | |
| 1615 | /* 8. Check on URI PATH. A pointer to the PATH is stored. The path starts at |
| 1616 | * the first '/' after the possible hostname, and ends before the possible '?'. |
| 1617 | */ |
| 1618 | static int smp_fetch_path(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1619 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1620 | struct channel *chn = SMP_REQ_CHN(smp); |
| 1621 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1622 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1623 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1624 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1625 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1626 | struct ist path; |
| 1627 | size_t len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1628 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1629 | if (!htx) |
| 1630 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1631 | |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 1632 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1633 | path = http_get_path(htx_sl_req_uri(sl)); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1634 | if (!path.ptr) |
| 1635 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1636 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1637 | for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++) |
Dragan Dosen | 8861e1c | 2019-02-12 19:50:31 +0100 | [diff] [blame] | 1638 | ; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1639 | |
Dragan Dosen | 8861e1c | 2019-02-12 19:50:31 +0100 | [diff] [blame] | 1640 | /* OK, we got the '/' ! */ |
| 1641 | smp->data.type = SMP_T_STR; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1642 | smp->data.u.str.area = path.ptr; |
| 1643 | smp->data.u.str.data = len; |
| 1644 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 1645 | } |
| 1646 | else { |
| 1647 | struct http_txn *txn; |
| 1648 | char *ptr, *end; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1649 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1650 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1651 | |
| 1652 | txn = smp->strm->txn; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1653 | end = ci_head(chn) + txn->req.sl.rq.u + txn->req.sl.rq.u_l; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1654 | ptr = http_txn_get_path(txn); |
| 1655 | if (!ptr) |
| 1656 | return 0; |
| 1657 | |
| 1658 | /* OK, we got the '/' ! */ |
| 1659 | smp->data.type = SMP_T_STR; |
| 1660 | smp->data.u.str.area = ptr; |
| 1661 | |
| 1662 | while (ptr < end && *ptr != '?') |
| 1663 | ptr++; |
| 1664 | |
| 1665 | smp->data.u.str.data = ptr - smp->data.u.str.area; |
| 1666 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 1667 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1668 | return 1; |
| 1669 | } |
| 1670 | |
| 1671 | /* This produces a concatenation of the first occurrence of the Host header |
| 1672 | * followed by the path component if it begins with a slash ('/'). This means |
| 1673 | * that '*' will not be added, resulting in exactly the first Host entry. |
| 1674 | * If no Host header is found, then the path is returned as-is. The returned |
| 1675 | * value is stored in the trash so it does not need to be marked constant. |
| 1676 | * The returned sample is of type string. |
| 1677 | */ |
| 1678 | static int smp_fetch_base(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1679 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1680 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1681 | struct buffer *temp; |
| 1682 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1683 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1684 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1685 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1686 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1687 | struct http_hdr_ctx ctx; |
| 1688 | struct ist path; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1689 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1690 | if (!htx) |
| 1691 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1692 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1693 | ctx.blk = NULL; |
| 1694 | if (!http_find_header(htx, ist("Host"), &ctx, 0) || !ctx.value.len) |
| 1695 | return smp_fetch_path(args, smp, kw, private); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1696 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1697 | /* OK we have the header value in ctx.value */ |
| 1698 | temp = get_trash_chunk(); |
| 1699 | chunk_memcat(temp, ctx.value.ptr, ctx.value.len); |
| 1700 | |
| 1701 | /* now retrieve the path */ |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 1702 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1703 | path = http_get_path(htx_sl_req_uri(sl)); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1704 | if (path.ptr) { |
| 1705 | size_t len; |
| 1706 | |
Dragan Dosen | 8861e1c | 2019-02-12 19:50:31 +0100 | [diff] [blame] | 1707 | for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++) |
| 1708 | ; |
| 1709 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1710 | if (len && *(path.ptr) == '/') |
| 1711 | chunk_memcat(temp, path.ptr, len); |
| 1712 | } |
| 1713 | |
| 1714 | smp->data.type = SMP_T_STR; |
| 1715 | smp->data.u.str = *temp; |
| 1716 | } |
| 1717 | else { |
| 1718 | /* LEGACY version */ |
| 1719 | struct http_txn *txn; |
| 1720 | char *ptr, *end, *beg; |
| 1721 | struct hdr_ctx ctx; |
| 1722 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1723 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1724 | |
| 1725 | txn = smp->strm->txn; |
| 1726 | ctx.idx = 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1727 | if (!http_find_header2("Host", 4, ci_head(chn), &txn->hdr_idx, &ctx) || !ctx.vlen) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1728 | return smp_fetch_path(args, smp, kw, private); |
| 1729 | |
| 1730 | /* OK we have the header value in ctx.line+ctx.val for ctx.vlen bytes */ |
| 1731 | temp = get_trash_chunk(); |
| 1732 | memcpy(temp->area, ctx.line + ctx.val, ctx.vlen); |
| 1733 | smp->data.type = SMP_T_STR; |
| 1734 | smp->data.u.str.area = temp->area; |
| 1735 | smp->data.u.str.data = ctx.vlen; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1736 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1737 | /* now retrieve the path */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1738 | end = ci_head(chn) + txn->req.sl.rq.u + txn->req.sl.rq.u_l; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1739 | beg = http_txn_get_path(txn); |
| 1740 | if (!beg) |
| 1741 | beg = end; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1742 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1743 | for (ptr = beg; ptr < end && *ptr != '?'; ptr++); |
| 1744 | |
| 1745 | if (beg < ptr && *beg == '/') { |
| 1746 | memcpy(smp->data.u.str.area + smp->data.u.str.data, beg, |
| 1747 | ptr - beg); |
| 1748 | smp->data.u.str.data += ptr - beg; |
| 1749 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | smp->flags = SMP_F_VOL_1ST; |
| 1753 | return 1; |
| 1754 | } |
| 1755 | |
| 1756 | /* This produces a 32-bit hash of the concatenation of the first occurrence of |
| 1757 | * the Host header followed by the path component if it begins with a slash ('/'). |
| 1758 | * This means that '*' will not be added, resulting in exactly the first Host |
| 1759 | * entry. If no Host header is found, then the path is used. The resulting value |
| 1760 | * is hashed using the path hash followed by a full avalanche hash and provides a |
| 1761 | * 32-bit integer value. This fetch is useful for tracking per-path activity on |
| 1762 | * high-traffic sites without having to store whole paths. |
| 1763 | */ |
| 1764 | static int smp_fetch_base32(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1765 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1766 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1767 | unsigned int hash = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1768 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1769 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1770 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1771 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1772 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1773 | struct http_hdr_ctx ctx; |
| 1774 | struct ist path; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1775 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1776 | if (!htx) |
| 1777 | return 0; |
| 1778 | |
| 1779 | ctx.blk = NULL; |
Dragan Dosen | 8861e1c | 2019-02-12 19:50:31 +0100 | [diff] [blame] | 1780 | if (http_find_header(htx, ist("Host"), &ctx, 0)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1781 | /* OK we have the header value in ctx.value */ |
| 1782 | while (ctx.value.len--) |
| 1783 | hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash; |
| 1784 | } |
| 1785 | |
| 1786 | /* now retrieve the path */ |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 1787 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1788 | path = http_get_path(htx_sl_req_uri(sl)); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1789 | if (path.ptr) { |
| 1790 | size_t len; |
| 1791 | |
Dragan Dosen | 8861e1c | 2019-02-12 19:50:31 +0100 | [diff] [blame] | 1792 | for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++) |
| 1793 | ; |
| 1794 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1795 | if (len && *(path.ptr) == '/') { |
| 1796 | while (len--) |
| 1797 | hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash; |
| 1798 | } |
| 1799 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1800 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1801 | else { |
| 1802 | /* LEGACY version */ |
| 1803 | struct http_txn *txn; |
| 1804 | struct hdr_ctx ctx; |
| 1805 | char *ptr, *beg, *end; |
| 1806 | int len; |
| 1807 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1808 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1809 | |
| 1810 | txn = smp->strm->txn; |
| 1811 | ctx.idx = 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1812 | if (http_find_header2("Host", 4, ci_head(chn), &txn->hdr_idx, &ctx)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1813 | /* OK we have the header value in ctx.line+ctx.val for ctx.vlen bytes */ |
| 1814 | ptr = ctx.line + ctx.val; |
| 1815 | len = ctx.vlen; |
| 1816 | while (len--) |
| 1817 | hash = *(ptr++) + (hash << 6) + (hash << 16) - hash; |
| 1818 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1819 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1820 | /* now retrieve the path */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1821 | end = ci_head(chn) + txn->req.sl.rq.u + txn->req.sl.rq.u_l; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1822 | beg = http_txn_get_path(txn); |
| 1823 | if (!beg) |
| 1824 | beg = end; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1825 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1826 | for (ptr = beg; ptr < end && *ptr != '?'; ptr++); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1827 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1828 | if (beg < ptr && *beg == '/') { |
| 1829 | while (beg < ptr) |
| 1830 | hash = *(beg++) + (hash << 6) + (hash << 16) - hash; |
| 1831 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1832 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1833 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1834 | hash = full_hash(hash); |
| 1835 | |
| 1836 | smp->data.type = SMP_T_SINT; |
| 1837 | smp->data.u.sint = hash; |
| 1838 | smp->flags = SMP_F_VOL_1ST; |
| 1839 | return 1; |
| 1840 | } |
| 1841 | |
| 1842 | /* This concatenates the source address with the 32-bit hash of the Host and |
| 1843 | * path as returned by smp_fetch_base32(). The idea is to have per-source and |
| 1844 | * per-path counters. The result is a binary block from 8 to 20 bytes depending |
| 1845 | * on the source address length. The path hash is stored before the address so |
| 1846 | * that in environments where IPv6 is insignificant, truncating the output to |
| 1847 | * 8 bytes would still work. |
| 1848 | */ |
| 1849 | static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1850 | { |
| 1851 | struct buffer *temp; |
| 1852 | struct connection *cli_conn = objt_conn(smp->sess->origin); |
| 1853 | |
| 1854 | if (!cli_conn) |
| 1855 | return 0; |
| 1856 | |
| 1857 | if (!smp_fetch_base32(args, smp, kw, private)) |
| 1858 | return 0; |
| 1859 | |
| 1860 | temp = get_trash_chunk(); |
| 1861 | *(unsigned int *) temp->area = htonl(smp->data.u.sint); |
| 1862 | temp->data += sizeof(unsigned int); |
| 1863 | |
| 1864 | switch (cli_conn->addr.from.ss_family) { |
| 1865 | case AF_INET: |
| 1866 | memcpy(temp->area + temp->data, |
| 1867 | &((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr, |
| 1868 | 4); |
| 1869 | temp->data += 4; |
| 1870 | break; |
| 1871 | case AF_INET6: |
| 1872 | memcpy(temp->area + temp->data, |
| 1873 | &((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_addr, |
| 1874 | 16); |
| 1875 | temp->data += 16; |
| 1876 | break; |
| 1877 | default: |
| 1878 | return 0; |
| 1879 | } |
| 1880 | |
| 1881 | smp->data.u.str = *temp; |
| 1882 | smp->data.type = SMP_T_BIN; |
| 1883 | return 1; |
| 1884 | } |
| 1885 | |
| 1886 | /* Extracts the query string, which comes after the question mark '?'. If no |
| 1887 | * question mark is found, nothing is returned. Otherwise it returns a sample |
| 1888 | * of type string carrying the whole query string. |
| 1889 | */ |
| 1890 | static int smp_fetch_query(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1891 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1892 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1893 | char *ptr, *end; |
| 1894 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1895 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1896 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1897 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1898 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1899 | |
| 1900 | if (!htx) |
| 1901 | return 0; |
| 1902 | |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 1903 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 1904 | ptr = HTX_SL_REQ_UPTR(sl); |
| 1905 | end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1906 | } |
| 1907 | else { |
| 1908 | /* LEGACY version */ |
| 1909 | struct http_txn *txn; |
| 1910 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1911 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1912 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1913 | txn = smp->strm->txn; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1914 | ptr = ci_head(chn) + txn->req.sl.rq.u; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1915 | end = ptr + txn->req.sl.rq.u_l; |
| 1916 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1917 | |
| 1918 | /* look up the '?' */ |
| 1919 | do { |
| 1920 | if (ptr == end) |
| 1921 | return 0; |
| 1922 | } while (*ptr++ != '?'); |
| 1923 | |
| 1924 | smp->data.type = SMP_T_STR; |
| 1925 | smp->data.u.str.area = ptr; |
| 1926 | smp->data.u.str.data = end - ptr; |
| 1927 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 1928 | return 1; |
| 1929 | } |
| 1930 | |
| 1931 | static int smp_fetch_proto_http(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1932 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1933 | struct channel *chn = SMP_REQ_CHN(smp); |
| 1934 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1935 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1936 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1937 | struct htx *htx = smp_prefetch_htx(smp, chn, 0); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1938 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1939 | if (!htx) |
| 1940 | return 0; |
| 1941 | } |
| 1942 | else { |
| 1943 | /* LEGACY version */ |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1944 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1945 | /* Note: hdr_idx.v cannot be NULL in this ACL because the ACL is tagged |
| 1946 | * as a layer7 ACL, which involves automatic allocation of hdr_idx. |
| 1947 | */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1948 | CHECK_HTTP_MESSAGE_FIRST_PERM(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1949 | } |
| 1950 | smp->data.type = SMP_T_BOOL; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1951 | smp->data.u.sint = 1; |
| 1952 | return 1; |
| 1953 | } |
| 1954 | |
| 1955 | /* return a valid test if the current request is the first one on the connection */ |
| 1956 | static int smp_fetch_http_first_req(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1957 | { |
Willy Tarreau | d095c67 | 2020-04-29 11:52:13 +0200 | [diff] [blame] | 1958 | if (!smp->strm) |
| 1959 | return 0; |
| 1960 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1961 | smp->data.type = SMP_T_BOOL; |
| 1962 | smp->data.u.sint = !(smp->strm->txn->flags & TX_NOT_FIRST); |
| 1963 | return 1; |
| 1964 | } |
| 1965 | |
| 1966 | /* Accepts exactly 1 argument of type userlist */ |
| 1967 | static int smp_fetch_http_auth(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1968 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1969 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1970 | |
| 1971 | if (!args || args->type != ARGT_USR) |
| 1972 | return 0; |
| 1973 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 1974 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1975 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 1976 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1977 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1978 | if (!htx) |
| 1979 | return 0; |
Christopher Faulet | e98411b | 2019-07-15 13:58:29 +0200 | [diff] [blame] | 1980 | if (!get_http_auth(smp, htx)) |
| 1981 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1982 | } |
| 1983 | else { |
| 1984 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1985 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | e98411b | 2019-07-15 13:58:29 +0200 | [diff] [blame] | 1986 | if (!get_http_auth(smp, NULL)) |
| 1987 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1988 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1989 | |
| 1990 | smp->data.type = SMP_T_BOOL; |
| 1991 | smp->data.u.sint = check_user(args->data.usr, smp->strm->txn->auth.user, |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1992 | smp->strm->txn->auth.pass); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1993 | return 1; |
| 1994 | } |
| 1995 | |
| 1996 | /* Accepts exactly 1 argument of type userlist */ |
| 1997 | static int smp_fetch_http_auth_grp(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1998 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1999 | struct channel *chn = SMP_REQ_CHN(smp); |
| 2000 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2001 | if (!args || args->type != ARGT_USR) |
| 2002 | return 0; |
| 2003 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 2004 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2005 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 2006 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2007 | |
| 2008 | if (!htx) |
| 2009 | return 0; |
Christopher Faulet | e98411b | 2019-07-15 13:58:29 +0200 | [diff] [blame] | 2010 | if (!get_http_auth(smp, htx)) |
| 2011 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2012 | } |
| 2013 | else { |
| 2014 | /* LEGACY version */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2015 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | e98411b | 2019-07-15 13:58:29 +0200 | [diff] [blame] | 2016 | if (!get_http_auth(smp, NULL)) |
| 2017 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2018 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2019 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2020 | /* if the user does not belong to the userlist or has a wrong password, |
| 2021 | * report that it unconditionally does not match. Otherwise we return |
| 2022 | * a string containing the username. |
| 2023 | */ |
| 2024 | if (!check_user(args->data.usr, smp->strm->txn->auth.user, |
| 2025 | smp->strm->txn->auth.pass)) |
| 2026 | return 0; |
| 2027 | |
| 2028 | /* pat_match_auth() will need the user list */ |
| 2029 | smp->ctx.a[0] = args->data.usr; |
| 2030 | |
| 2031 | smp->data.type = SMP_T_STR; |
| 2032 | smp->flags = SMP_F_CONST; |
| 2033 | smp->data.u.str.area = smp->strm->txn->auth.user; |
| 2034 | smp->data.u.str.data = strlen(smp->strm->txn->auth.user); |
| 2035 | |
| 2036 | return 1; |
| 2037 | } |
| 2038 | |
| 2039 | /* Fetch a captured HTTP request header. The index is the position of |
| 2040 | * the "capture" option in the configuration file |
| 2041 | */ |
| 2042 | static int smp_fetch_capture_req_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2043 | { |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2044 | struct proxy *fe; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2045 | int idx; |
| 2046 | |
| 2047 | if (!args || args->type != ARGT_SINT) |
| 2048 | return 0; |
| 2049 | |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2050 | if (!smp->strm) |
| 2051 | return 0; |
| 2052 | |
| 2053 | fe = strm_fe(smp->strm); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2054 | idx = args->data.sint; |
| 2055 | |
| 2056 | if (idx > (fe->nb_req_cap - 1) || smp->strm->req_cap == NULL || smp->strm->req_cap[idx] == NULL) |
| 2057 | return 0; |
| 2058 | |
| 2059 | smp->data.type = SMP_T_STR; |
| 2060 | smp->flags |= SMP_F_CONST; |
| 2061 | smp->data.u.str.area = smp->strm->req_cap[idx]; |
| 2062 | smp->data.u.str.data = strlen(smp->strm->req_cap[idx]); |
| 2063 | |
| 2064 | return 1; |
| 2065 | } |
| 2066 | |
| 2067 | /* Fetch a captured HTTP response header. The index is the position of |
| 2068 | * the "capture" option in the configuration file |
| 2069 | */ |
| 2070 | static int smp_fetch_capture_res_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2071 | { |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2072 | struct proxy *fe; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2073 | int idx; |
| 2074 | |
| 2075 | if (!args || args->type != ARGT_SINT) |
| 2076 | return 0; |
| 2077 | |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2078 | if (!smp->strm) |
| 2079 | return 0; |
| 2080 | |
| 2081 | fe = strm_fe(smp->strm); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2082 | idx = args->data.sint; |
| 2083 | |
| 2084 | if (idx > (fe->nb_rsp_cap - 1) || smp->strm->res_cap == NULL || smp->strm->res_cap[idx] == NULL) |
| 2085 | return 0; |
| 2086 | |
| 2087 | smp->data.type = SMP_T_STR; |
| 2088 | smp->flags |= SMP_F_CONST; |
| 2089 | smp->data.u.str.area = smp->strm->res_cap[idx]; |
| 2090 | smp->data.u.str.data = strlen(smp->strm->res_cap[idx]); |
| 2091 | |
| 2092 | return 1; |
| 2093 | } |
| 2094 | |
| 2095 | /* Extracts the METHOD in the HTTP request, the txn->uri should be filled before the call */ |
| 2096 | static int smp_fetch_capture_req_method(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2097 | { |
| 2098 | struct buffer *temp; |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2099 | struct http_txn *txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2100 | char *ptr; |
| 2101 | |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2102 | if (!smp->strm) |
| 2103 | return 0; |
| 2104 | |
| 2105 | txn = smp->strm->txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2106 | if (!txn || !txn->uri) |
| 2107 | return 0; |
| 2108 | |
| 2109 | ptr = txn->uri; |
| 2110 | |
| 2111 | while (*ptr != ' ' && *ptr != '\0') /* find first space */ |
| 2112 | ptr++; |
| 2113 | |
| 2114 | temp = get_trash_chunk(); |
| 2115 | temp->area = txn->uri; |
| 2116 | temp->data = ptr - txn->uri; |
| 2117 | smp->data.u.str = *temp; |
| 2118 | smp->data.type = SMP_T_STR; |
| 2119 | smp->flags = SMP_F_CONST; |
| 2120 | |
| 2121 | return 1; |
| 2122 | |
| 2123 | } |
| 2124 | |
| 2125 | /* Extracts the path in the HTTP request, the txn->uri should be filled before the call */ |
| 2126 | static int smp_fetch_capture_req_uri(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2127 | { |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2128 | struct http_txn *txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2129 | struct ist path; |
| 2130 | const char *ptr; |
| 2131 | |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2132 | if (!smp->strm) |
| 2133 | return 0; |
| 2134 | |
| 2135 | txn = smp->strm->txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2136 | if (!txn || !txn->uri) |
| 2137 | return 0; |
| 2138 | |
| 2139 | ptr = txn->uri; |
| 2140 | |
| 2141 | while (*ptr != ' ' && *ptr != '\0') /* find first space */ |
| 2142 | ptr++; |
| 2143 | |
| 2144 | if (!*ptr) |
| 2145 | return 0; |
| 2146 | |
Christopher Faulet | 78337bb | 2018-11-15 14:35:18 +0100 | [diff] [blame] | 2147 | /* skip the first space and find space after URI */ |
| 2148 | path = ist2(++ptr, 0); |
| 2149 | while (*ptr != ' ' && *ptr != '\0') |
| 2150 | ptr++; |
| 2151 | path.len = ptr - path.ptr; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2152 | |
Christopher Faulet | 78337bb | 2018-11-15 14:35:18 +0100 | [diff] [blame] | 2153 | path = http_get_path(path); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2154 | if (!path.ptr) |
| 2155 | return 0; |
| 2156 | |
| 2157 | smp->data.u.str.area = path.ptr; |
| 2158 | smp->data.u.str.data = path.len; |
| 2159 | smp->data.type = SMP_T_STR; |
| 2160 | smp->flags = SMP_F_CONST; |
| 2161 | |
| 2162 | return 1; |
| 2163 | } |
| 2164 | |
| 2165 | /* Retrieves the HTTP version from the request (either 1.0 or 1.1) and emits it |
| 2166 | * as a string (either "HTTP/1.0" or "HTTP/1.1"). |
| 2167 | */ |
| 2168 | static int smp_fetch_capture_req_ver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2169 | { |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2170 | struct http_txn *txn; |
| 2171 | |
| 2172 | if (!smp->strm) |
| 2173 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2174 | |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2175 | txn = smp->strm->txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2176 | if (!txn || txn->req.msg_state < HTTP_MSG_HDR_FIRST) |
| 2177 | return 0; |
| 2178 | |
| 2179 | if (txn->req.flags & HTTP_MSGF_VER_11) |
| 2180 | smp->data.u.str.area = "HTTP/1.1"; |
| 2181 | else |
| 2182 | smp->data.u.str.area = "HTTP/1.0"; |
| 2183 | |
| 2184 | smp->data.u.str.data = 8; |
| 2185 | smp->data.type = SMP_T_STR; |
| 2186 | smp->flags = SMP_F_CONST; |
| 2187 | return 1; |
| 2188 | |
| 2189 | } |
| 2190 | |
| 2191 | /* Retrieves the HTTP version from the response (either 1.0 or 1.1) and emits it |
| 2192 | * as a string (either "HTTP/1.0" or "HTTP/1.1"). |
| 2193 | */ |
| 2194 | static int smp_fetch_capture_res_ver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2195 | { |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2196 | struct http_txn *txn; |
| 2197 | |
| 2198 | if (!smp->strm) |
| 2199 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2200 | |
Willy Tarreau | 79ed467 | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 2201 | txn = smp->strm->txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2202 | if (!txn || txn->rsp.msg_state < HTTP_MSG_HDR_FIRST) |
| 2203 | return 0; |
| 2204 | |
| 2205 | if (txn->rsp.flags & HTTP_MSGF_VER_11) |
| 2206 | smp->data.u.str.area = "HTTP/1.1"; |
| 2207 | else |
| 2208 | smp->data.u.str.area = "HTTP/1.0"; |
| 2209 | |
| 2210 | smp->data.u.str.data = 8; |
| 2211 | smp->data.type = SMP_T_STR; |
| 2212 | smp->flags = SMP_F_CONST; |
| 2213 | return 1; |
| 2214 | |
| 2215 | } |
| 2216 | |
| 2217 | /* Iterate over all cookies present in a message. The context is stored in |
| 2218 | * smp->ctx.a[0] for the in-header position, smp->ctx.a[1] for the |
| 2219 | * end-of-header-value, and smp->ctx.a[2] for the hdr_ctx. Depending on |
| 2220 | * the direction, multiple cookies may be parsed on the same line or not. |
Maciej Zdeb | 22dc68b | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 2221 | * If provided, the searched cookie name is in args, in args->data.str. If |
| 2222 | * the input options indicate that no iterating is desired, then only last |
| 2223 | * value is fetched if any. If no cookie name is provided, the first cookie |
| 2224 | * value found is fetched. The returned sample is of type CSTR. Can be used |
| 2225 | * to parse cookies in other files. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2226 | */ |
| 2227 | static int smp_fetch_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2228 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2229 | /* possible keywords: req.cookie / cookie / cook, res.cookie / scook / set-cookie */ |
| 2230 | struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2231 | char *cook = NULL; |
| 2232 | size_t cook_l = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2233 | int found = 0; |
| 2234 | |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2235 | if (args && args->type == ARGT_STR) { |
| 2236 | cook = args->data.str.area; |
| 2237 | cook_l = args->data.str.data; |
| 2238 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2239 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 2240 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2241 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 2242 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2243 | struct http_hdr_ctx *ctx = smp->ctx.a[2]; |
| 2244 | struct ist hdr; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2245 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2246 | if (!ctx) { |
| 2247 | /* first call */ |
| 2248 | ctx = &static_http_hdr_ctx; |
| 2249 | ctx->blk = NULL; |
| 2250 | smp->ctx.a[2] = ctx; |
| 2251 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2252 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2253 | if (!htx) |
| 2254 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2255 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2256 | hdr = (!(chn->flags & CF_ISRESP) ? ist("Cookie") : ist("Set-Cookie")); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2257 | |
Maciej Zdeb | 22dc68b | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 2258 | /* OK so basically here, either we want only one value or we want to |
| 2259 | * iterate over all of them and we fetch the next one. In this last case |
| 2260 | * SMP_OPT_ITERATE option is set. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2261 | */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2262 | |
| 2263 | if (!(smp->flags & SMP_F_NOT_LAST)) { |
| 2264 | /* search for the header from the beginning, we must first initialize |
| 2265 | * the search parameters. |
| 2266 | */ |
| 2267 | smp->ctx.a[0] = NULL; |
| 2268 | ctx->blk = NULL; |
| 2269 | } |
| 2270 | |
| 2271 | smp->flags |= SMP_F_VOL_HDR; |
| 2272 | while (1) { |
| 2273 | /* Note: smp->ctx.a[0] == NULL every time we need to fetch a new header */ |
| 2274 | if (!smp->ctx.a[0]) { |
| 2275 | if (!http_find_header(htx, hdr, ctx, 0)) |
| 2276 | goto out; |
| 2277 | |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2278 | if (ctx->value.len < cook_l + 1) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2279 | continue; |
| 2280 | |
| 2281 | smp->ctx.a[0] = ctx->value.ptr; |
| 2282 | smp->ctx.a[1] = smp->ctx.a[0] + ctx->value.len; |
| 2283 | } |
| 2284 | |
| 2285 | smp->data.type = SMP_T_STR; |
| 2286 | smp->flags |= SMP_F_CONST; |
| 2287 | smp->ctx.a[0] = http_extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1], |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2288 | cook, cook_l, |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2289 | (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, |
| 2290 | &smp->data.u.str.area, |
| 2291 | &smp->data.u.str.data); |
| 2292 | if (smp->ctx.a[0]) { |
| 2293 | found = 1; |
Maciej Zdeb | 22dc68b | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 2294 | if (smp->opt & SMP_OPT_ITERATE) { |
| 2295 | /* iterate on cookie value */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2296 | smp->flags |= SMP_F_NOT_LAST; |
| 2297 | return 1; |
| 2298 | } |
Maciej Zdeb | 22dc68b | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 2299 | if (args->data.str.data == 0) { |
| 2300 | /* No cookie name, first occurrence returned */ |
| 2301 | break; |
| 2302 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2303 | } |
| 2304 | /* if we're looking for last occurrence, let's loop */ |
| 2305 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2306 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2307 | else { |
| 2308 | /* LEGACY version */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2309 | struct hdr_idx *idx; |
| 2310 | struct hdr_ctx *ctx = smp->ctx.a[2]; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2311 | const char *hdr_name; |
| 2312 | int hdr_name_len; |
| 2313 | char *sol; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2314 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2315 | if (!ctx) { |
| 2316 | /* first call */ |
| 2317 | ctx = &static_hdr_ctx; |
| 2318 | ctx->idx = 0; |
| 2319 | smp->ctx.a[2] = ctx; |
| 2320 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2321 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2322 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2323 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2324 | idx = &smp->strm->txn->hdr_idx; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2325 | if (!(chn->flags & CF_ISRESP)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2326 | hdr_name = "Cookie"; |
| 2327 | hdr_name_len = 6; |
| 2328 | } else { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2329 | hdr_name = "Set-Cookie"; |
| 2330 | hdr_name_len = 10; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2331 | } |
| 2332 | |
Maciej Zdeb | 22dc68b | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 2333 | /* OK so basically here, either we want only one value or we want to |
| 2334 | * iterate over all of them and we fetch the next one. In this last case |
| 2335 | * SMP_OPT_ITERATE option is set. |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2336 | */ |
| 2337 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2338 | sol = ci_head(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2339 | if (!(smp->flags & SMP_F_NOT_LAST)) { |
| 2340 | /* search for the header from the beginning, we must first initialize |
| 2341 | * the search parameters. |
| 2342 | */ |
| 2343 | smp->ctx.a[0] = NULL; |
| 2344 | ctx->idx = 0; |
| 2345 | } |
| 2346 | |
| 2347 | smp->flags |= SMP_F_VOL_HDR; |
| 2348 | |
| 2349 | while (1) { |
| 2350 | /* Note: smp->ctx.a[0] == NULL every time we need to fetch a new header */ |
| 2351 | if (!smp->ctx.a[0]) { |
| 2352 | if (!http_find_header2(hdr_name, hdr_name_len, sol, idx, ctx)) |
| 2353 | goto out; |
| 2354 | |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2355 | if (ctx->vlen < cook_l + 1) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2356 | continue; |
| 2357 | |
| 2358 | smp->ctx.a[0] = ctx->line + ctx->val; |
| 2359 | smp->ctx.a[1] = smp->ctx.a[0] + ctx->vlen; |
| 2360 | } |
| 2361 | |
| 2362 | smp->data.type = SMP_T_STR; |
| 2363 | smp->flags |= SMP_F_CONST; |
| 2364 | smp->ctx.a[0] = http_extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1], |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2365 | cook, cook_l, |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2366 | (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, |
| 2367 | &smp->data.u.str.area, &smp->data.u.str.data); |
| 2368 | if (smp->ctx.a[0]) { |
| 2369 | found = 1; |
Maciej Zdeb | 22dc68b | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 2370 | if (smp->opt & SMP_OPT_ITERATE) { |
| 2371 | /* iterate on cookie value */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2372 | smp->flags |= SMP_F_NOT_LAST; |
| 2373 | return 1; |
| 2374 | } |
Maciej Zdeb | 22dc68b | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 2375 | if (args->data.str.data == 0) { |
| 2376 | /* No cookie name, first occurrence returned */ |
| 2377 | break; |
| 2378 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2379 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2380 | /* if we're looking for last occurrence, let's loop */ |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2381 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2382 | } |
| 2383 | /* all cookie headers and values were scanned. If we're looking for the |
| 2384 | * last occurrence, we may return it now. |
| 2385 | */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2386 | out: |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2387 | smp->flags &= ~SMP_F_NOT_LAST; |
| 2388 | return found; |
| 2389 | } |
| 2390 | |
Christopher Faulet | c1f40dd | 2019-05-16 10:07:30 +0200 | [diff] [blame] | 2391 | /* Same than smp_fetch_cookie() but only relies on the sample direction to |
| 2392 | * choose the right channel. So instead of duplicating the code, we just change |
| 2393 | * the keyword and then fallback on smp_fetch_cookie(). |
| 2394 | */ |
| 2395 | static int smp_fetch_chn_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2396 | { |
| 2397 | kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.cook" : "res.cook"); |
| 2398 | return smp_fetch_cookie(args, smp, kw, private); |
| 2399 | } |
| 2400 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2401 | /* Iterate over all cookies present in a request to count how many occurrences |
| 2402 | * match the name in args and args->data.str.len. If <multi> is non-null, then |
| 2403 | * multiple cookies may be parsed on the same line. The returned sample is of |
| 2404 | * type UINT. Accepts exactly 1 argument of type string. |
| 2405 | */ |
| 2406 | static int smp_fetch_cookie_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2407 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2408 | /* possible keywords: req.cook_cnt / cook_cnt, res.cook_cnt / scook_cnt */ |
| 2409 | struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2410 | char *val_beg, *val_end; |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2411 | char *cook = NULL; |
| 2412 | size_t cook_l = 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2413 | int cnt; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2414 | |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2415 | if (args && args->type == ARGT_STR){ |
| 2416 | cook = args->data.str.area; |
| 2417 | cook_l = args->data.str.data; |
| 2418 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2419 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 2420 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2421 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 2422 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2423 | struct http_hdr_ctx ctx; |
| 2424 | struct ist hdr; |
| 2425 | |
| 2426 | if (!htx) |
| 2427 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2428 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2429 | hdr = (!(chn->flags & CF_ISRESP) ? ist("Cookie") : ist("Set-Cookie")); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2430 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2431 | val_end = val_beg = NULL; |
| 2432 | ctx.blk = NULL; |
| 2433 | cnt = 0; |
| 2434 | while (1) { |
| 2435 | /* Note: val_beg == NULL every time we need to fetch a new header */ |
| 2436 | if (!val_beg) { |
| 2437 | if (!http_find_header(htx, hdr, &ctx, 0)) |
| 2438 | break; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2439 | |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2440 | if (ctx.value.len < cook_l + 1) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2441 | continue; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2442 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2443 | val_beg = ctx.value.ptr; |
| 2444 | val_end = val_beg + ctx.value.len; |
| 2445 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2446 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2447 | smp->data.type = SMP_T_STR; |
| 2448 | smp->flags |= SMP_F_CONST; |
| 2449 | while ((val_beg = http_extract_cookie_value(val_beg, val_end, |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2450 | cook, cook_l, |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2451 | (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, |
| 2452 | &smp->data.u.str.area, |
| 2453 | &smp->data.u.str.data))) { |
| 2454 | cnt++; |
| 2455 | } |
| 2456 | } |
| 2457 | } |
| 2458 | else { |
| 2459 | /* LEGACY version */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2460 | struct hdr_idx *idx; |
| 2461 | struct hdr_ctx ctx; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2462 | const char *hdr_name; |
| 2463 | int hdr_name_len; |
| 2464 | char *sol; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2465 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2466 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2467 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2468 | idx = &smp->strm->txn->hdr_idx; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2469 | if (!(chn->flags & CF_ISRESP)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2470 | hdr_name = "Cookie"; |
| 2471 | hdr_name_len = 6; |
| 2472 | } else { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2473 | hdr_name = "Set-Cookie"; |
| 2474 | hdr_name_len = 10; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2475 | } |
| 2476 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2477 | sol = ci_head(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2478 | val_end = val_beg = NULL; |
| 2479 | ctx.idx = 0; |
| 2480 | cnt = 0; |
| 2481 | |
| 2482 | while (1) { |
| 2483 | /* Note: val_beg == NULL every time we need to fetch a new header */ |
| 2484 | if (!val_beg) { |
| 2485 | if (!http_find_header2(hdr_name, hdr_name_len, sol, idx, &ctx)) |
| 2486 | break; |
| 2487 | |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2488 | if (ctx.vlen < cook_l + 1) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2489 | continue; |
| 2490 | |
| 2491 | val_beg = ctx.line + ctx.val; |
| 2492 | val_end = val_beg + ctx.vlen; |
| 2493 | } |
| 2494 | |
| 2495 | smp->data.type = SMP_T_STR; |
| 2496 | smp->flags |= SMP_F_CONST; |
| 2497 | while ((val_beg = http_extract_cookie_value(val_beg, val_end, |
Christopher Faulet | 08f475b | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 2498 | cook, cook_l, |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2499 | (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, |
| 2500 | &smp->data.u.str.area, &smp->data.u.str.data))) { |
| 2501 | cnt++; |
| 2502 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | smp->data.type = SMP_T_SINT; |
| 2507 | smp->data.u.sint = cnt; |
| 2508 | smp->flags |= SMP_F_VOL_HDR; |
| 2509 | return 1; |
| 2510 | } |
| 2511 | |
| 2512 | /* Fetch an cookie's integer value. The integer value is returned. It |
| 2513 | * takes a mandatory argument of type string. It relies on smp_fetch_cookie(). |
| 2514 | */ |
| 2515 | static int smp_fetch_cookie_val(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2516 | { |
| 2517 | int ret = smp_fetch_cookie(args, smp, kw, private); |
| 2518 | |
| 2519 | if (ret > 0) { |
| 2520 | smp->data.type = SMP_T_SINT; |
| 2521 | smp->data.u.sint = strl2ic(smp->data.u.str.area, |
| 2522 | smp->data.u.str.data); |
| 2523 | } |
| 2524 | |
| 2525 | return ret; |
| 2526 | } |
| 2527 | |
| 2528 | /************************************************************************/ |
| 2529 | /* The code below is dedicated to sample fetches */ |
| 2530 | /************************************************************************/ |
| 2531 | |
| 2532 | /* This scans a URL-encoded query string. It takes an optionally wrapping |
| 2533 | * string whose first contigous chunk has its beginning in ctx->a[0] and end |
| 2534 | * in ctx->a[1], and the optional second part in (ctx->a[2]..ctx->a[3]). The |
| 2535 | * pointers are updated for next iteration before leaving. |
| 2536 | */ |
| 2537 | static int smp_fetch_param(char delim, const char *name, int name_len, const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2538 | { |
| 2539 | const char *vstart, *vend; |
| 2540 | struct buffer *temp; |
| 2541 | const char **chunks = (const char **)smp->ctx.a; |
| 2542 | |
| 2543 | if (!http_find_next_url_param(chunks, name, name_len, |
| 2544 | &vstart, &vend, delim)) |
| 2545 | return 0; |
| 2546 | |
| 2547 | /* Create sample. If the value is contiguous, return the pointer as CONST, |
| 2548 | * if the value is wrapped, copy-it in a buffer. |
| 2549 | */ |
| 2550 | smp->data.type = SMP_T_STR; |
| 2551 | if (chunks[2] && |
| 2552 | vstart >= chunks[0] && vstart <= chunks[1] && |
| 2553 | vend >= chunks[2] && vend <= chunks[3]) { |
| 2554 | /* Wrapped case. */ |
| 2555 | temp = get_trash_chunk(); |
| 2556 | memcpy(temp->area, vstart, chunks[1] - vstart); |
| 2557 | memcpy(temp->area + ( chunks[1] - vstart ), chunks[2], |
| 2558 | vend - chunks[2]); |
| 2559 | smp->data.u.str.area = temp->area; |
| 2560 | smp->data.u.str.data = ( chunks[1] - vstart ) + ( vend - chunks[2] ); |
| 2561 | } else { |
| 2562 | /* Contiguous case. */ |
| 2563 | smp->data.u.str.area = (char *)vstart; |
| 2564 | smp->data.u.str.data = vend - vstart; |
| 2565 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 2566 | } |
| 2567 | |
| 2568 | /* Update context, check wrapping. */ |
| 2569 | chunks[0] = vend; |
| 2570 | if (chunks[2] && vend >= chunks[2] && vend <= chunks[3]) { |
| 2571 | chunks[1] = chunks[3]; |
| 2572 | chunks[2] = NULL; |
| 2573 | } |
| 2574 | |
| 2575 | if (chunks[0] < chunks[1]) |
| 2576 | smp->flags |= SMP_F_NOT_LAST; |
| 2577 | |
| 2578 | return 1; |
| 2579 | } |
| 2580 | |
| 2581 | /* This function iterates over each parameter of the query string. It uses |
| 2582 | * ctx->a[0] and ctx->a[1] to store the beginning and end of the current |
| 2583 | * parameter. Since it uses smp_fetch_param(), ctx->a[2..3] are both NULL. |
| 2584 | * An optional parameter name is passed in args[0], otherwise any parameter is |
| 2585 | * considered. It supports an optional delimiter argument for the beginning of |
| 2586 | * the string in args[1], which defaults to "?". |
| 2587 | */ |
| 2588 | static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2589 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2590 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2591 | char delim = '?'; |
| 2592 | const char *name; |
| 2593 | int name_len; |
| 2594 | |
| 2595 | if (!args || |
| 2596 | (args[0].type && args[0].type != ARGT_STR) || |
| 2597 | (args[1].type && args[1].type != ARGT_STR)) |
| 2598 | return 0; |
| 2599 | |
| 2600 | name = ""; |
| 2601 | name_len = 0; |
| 2602 | if (args->type == ARGT_STR) { |
| 2603 | name = args->data.str.area; |
| 2604 | name_len = args->data.str.data; |
| 2605 | } |
| 2606 | |
| 2607 | if (args[1].type) |
| 2608 | delim = *args[1].data.str.area; |
| 2609 | |
| 2610 | if (!smp->ctx.a[0]) { // first call, find the query string |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 2611 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2612 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 2613 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 2614 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2615 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2616 | if (!htx) |
| 2617 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2618 | |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 2619 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 2620 | smp->ctx.a[0] = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), delim); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2621 | if (!smp->ctx.a[0]) |
| 2622 | return 0; |
| 2623 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 2624 | smp->ctx.a[1] = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2625 | } |
| 2626 | else { |
| 2627 | /* LEGACY version */ |
| 2628 | struct http_msg *msg; |
| 2629 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2630 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2631 | |
| 2632 | msg = &smp->strm->txn->req; |
| 2633 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2634 | smp->ctx.a[0] = http_find_param_list(ci_head(chn) + msg->sl.rq.u, |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2635 | msg->sl.rq.u_l, delim); |
| 2636 | if (!smp->ctx.a[0]) |
| 2637 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2638 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2639 | smp->ctx.a[1] = ci_head(chn) + msg->sl.rq.u + msg->sl.rq.u_l; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2640 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2641 | |
| 2642 | /* Assume that the context is filled with NULL pointer |
| 2643 | * before the first call. |
| 2644 | * smp->ctx.a[2] = NULL; |
| 2645 | * smp->ctx.a[3] = NULL; |
| 2646 | */ |
| 2647 | } |
| 2648 | |
| 2649 | return smp_fetch_param(delim, name, name_len, args, smp, kw, private); |
| 2650 | } |
| 2651 | |
| 2652 | /* This function iterates over each parameter of the body. This requires |
| 2653 | * that the body has been waited for using http-buffer-request. It uses |
| 2654 | * ctx->a[0] and ctx->a[1] to store the beginning and end of the first |
| 2655 | * contigous part of the body, and optionally ctx->a[2..3] to reference the |
| 2656 | * optional second part if the body wraps at the end of the buffer. An optional |
| 2657 | * parameter name is passed in args[0], otherwise any parameter is considered. |
| 2658 | */ |
| 2659 | static int smp_fetch_body_param(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2660 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2661 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2662 | const char *name; |
| 2663 | int name_len; |
| 2664 | |
| 2665 | if (!args || (args[0].type && args[0].type != ARGT_STR)) |
| 2666 | return 0; |
| 2667 | |
| 2668 | name = ""; |
| 2669 | name_len = 0; |
| 2670 | if (args[0].type == ARGT_STR) { |
| 2671 | name = args[0].data.str.area; |
| 2672 | name_len = args[0].data.str.data; |
| 2673 | } |
| 2674 | |
| 2675 | if (!smp->ctx.a[0]) { // first call, find the query string |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 2676 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2677 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 2678 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2679 | struct buffer *temp; |
| 2680 | int32_t pos; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2681 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2682 | if (!htx) |
| 2683 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2684 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2685 | temp = get_trash_chunk(); |
Christopher Faulet | a3f1550 | 2019-05-13 15:27:23 +0200 | [diff] [blame] | 2686 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2687 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 2688 | enum htx_blk_type type = htx_get_blk_type(blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2689 | |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 2690 | if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2691 | break; |
| 2692 | if (type == HTX_BLK_DATA) { |
Christopher Faulet | c59ff23 | 2018-12-03 13:58:44 +0100 | [diff] [blame] | 2693 | if (!htx_data_to_h1(htx_get_blk_value(htx, blk), temp, 0)) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2694 | return 0; |
| 2695 | } |
| 2696 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2697 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2698 | smp->ctx.a[0] = temp->area; |
| 2699 | smp->ctx.a[1] = temp->area + temp->data; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2700 | |
| 2701 | /* Assume that the context is filled with NULL pointer |
| 2702 | * before the first call. |
| 2703 | * smp->ctx.a[2] = NULL; |
| 2704 | * smp->ctx.a[3] = NULL; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2705 | */ |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2706 | } |
| 2707 | else { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2708 | /* LEGACY version */ |
| 2709 | struct http_msg *msg; |
| 2710 | unsigned long len; |
| 2711 | unsigned long block1; |
| 2712 | char *body; |
| 2713 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2714 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2715 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2716 | msg = &smp->strm->txn->req; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2717 | len = http_body_bytes(msg); |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2718 | body = c_ptr(chn, -http_data_rewind(msg)); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2719 | |
| 2720 | block1 = len; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2721 | if (block1 > b_wrap(&chn->buf) - body) |
| 2722 | block1 = b_wrap(&chn->buf) - body; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2723 | |
| 2724 | if (block1 == len) { |
| 2725 | /* buffer is not wrapped (or empty) */ |
| 2726 | smp->ctx.a[0] = body; |
| 2727 | smp->ctx.a[1] = body + len; |
| 2728 | |
| 2729 | /* Assume that the context is filled with NULL pointer |
| 2730 | * before the first call. |
| 2731 | * smp->ctx.a[2] = NULL; |
| 2732 | * smp->ctx.a[3] = NULL; |
| 2733 | */ |
| 2734 | } |
| 2735 | else { |
| 2736 | /* buffer is wrapped, we need to defragment it */ |
| 2737 | smp->ctx.a[0] = body; |
| 2738 | smp->ctx.a[1] = body + block1; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2739 | smp->ctx.a[2] = b_orig(&chn->buf); |
| 2740 | smp->ctx.a[3] = b_orig(&chn->buf) + ( len - block1 ); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2741 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2742 | } |
| 2743 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2744 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2745 | return smp_fetch_param('&', name, name_len, args, smp, kw, private); |
| 2746 | } |
| 2747 | |
| 2748 | /* Return the signed integer value for the specified url parameter (see url_param |
| 2749 | * above). |
| 2750 | */ |
| 2751 | static int smp_fetch_url_param_val(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2752 | { |
| 2753 | int ret = smp_fetch_url_param(args, smp, kw, private); |
| 2754 | |
| 2755 | if (ret > 0) { |
| 2756 | smp->data.type = SMP_T_SINT; |
| 2757 | smp->data.u.sint = strl2ic(smp->data.u.str.area, |
| 2758 | smp->data.u.str.data); |
| 2759 | } |
| 2760 | |
| 2761 | return ret; |
| 2762 | } |
| 2763 | |
| 2764 | /* This produces a 32-bit hash of the concatenation of the first occurrence of |
| 2765 | * the Host header followed by the path component if it begins with a slash ('/'). |
| 2766 | * This means that '*' will not be added, resulting in exactly the first Host |
| 2767 | * entry. If no Host header is found, then the path is used. The resulting value |
| 2768 | * is hashed using the url hash followed by a full avalanche hash and provides a |
| 2769 | * 32-bit integer value. This fetch is useful for tracking per-URL activity on |
| 2770 | * high-traffic sites without having to store whole paths. |
| 2771 | * this differs from the base32 functions in that it includes the url parameters |
| 2772 | * as well as the path |
| 2773 | */ |
| 2774 | static int smp_fetch_url32(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2775 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2776 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2777 | unsigned int hash = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2778 | |
Christopher Faulet | 46575cd | 2019-04-17 11:40:30 +0200 | [diff] [blame] | 2779 | if (smp->px->options2 & PR_O2_USE_HTX) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2780 | /* HTX version */ |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 2781 | struct htx *htx = smp_prefetch_htx(smp, chn, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2782 | struct http_hdr_ctx ctx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 2783 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2784 | struct ist path; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2785 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2786 | if (!htx) |
| 2787 | return 0; |
| 2788 | |
| 2789 | ctx.blk = NULL; |
| 2790 | if (http_find_header(htx, ist("Host"), &ctx, 1)) { |
| 2791 | /* OK we have the header value in ctx.value */ |
| 2792 | while (ctx.value.len--) |
| 2793 | hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash; |
| 2794 | } |
| 2795 | |
| 2796 | /* now retrieve the path */ |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 2797 | sl = http_get_stline(htx); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 2798 | path = http_get_path(htx_sl_req_uri(sl)); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2799 | if (path.len && *(path.ptr) == '/') { |
| 2800 | while (path.len--) |
| 2801 | hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash; |
| 2802 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2803 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2804 | else { |
| 2805 | /* LEGACY version */ |
| 2806 | struct http_txn *txn; |
| 2807 | struct hdr_ctx ctx; |
| 2808 | char *ptr, *beg, *end; |
| 2809 | int len; |
| 2810 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2811 | CHECK_HTTP_MESSAGE_FIRST(chn); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2812 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2813 | txn = smp->strm->txn; |
| 2814 | ctx.idx = 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2815 | if (http_find_header2("Host", 4, ci_head(chn), &txn->hdr_idx, &ctx)) { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2816 | /* OK we have the header value in ctx.line+ctx.val for ctx.vlen bytes */ |
| 2817 | ptr = ctx.line + ctx.val; |
| 2818 | len = ctx.vlen; |
| 2819 | while (len--) |
| 2820 | hash = *(ptr++) + (hash << 6) + (hash << 16) - hash; |
| 2821 | } |
| 2822 | |
| 2823 | /* now retrieve the path */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2824 | end = ci_head(chn) + txn->req.sl.rq.u + txn->req.sl.rq.u_l; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2825 | beg = http_txn_get_path(txn); |
| 2826 | if (!beg) |
| 2827 | beg = end; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2828 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2829 | for (ptr = beg; ptr < end ; ptr++); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2830 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2831 | if (beg < ptr && *beg == '/') { |
| 2832 | while (beg < ptr) |
| 2833 | hash = *(beg++) + (hash << 6) + (hash << 16) - hash; |
| 2834 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2835 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2836 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2837 | hash = full_hash(hash); |
| 2838 | |
| 2839 | smp->data.type = SMP_T_SINT; |
| 2840 | smp->data.u.sint = hash; |
| 2841 | smp->flags = SMP_F_VOL_1ST; |
| 2842 | return 1; |
| 2843 | } |
| 2844 | |
| 2845 | /* This concatenates the source address with the 32-bit hash of the Host and |
| 2846 | * URL as returned by smp_fetch_base32(). The idea is to have per-source and |
| 2847 | * per-url counters. The result is a binary block from 8 to 20 bytes depending |
| 2848 | * on the source address length. The URL hash is stored before the address so |
| 2849 | * that in environments where IPv6 is insignificant, truncating the output to |
| 2850 | * 8 bytes would still work. |
| 2851 | */ |
| 2852 | static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2853 | { |
| 2854 | struct buffer *temp; |
| 2855 | struct connection *cli_conn = objt_conn(smp->sess->origin); |
| 2856 | |
| 2857 | if (!cli_conn) |
| 2858 | return 0; |
| 2859 | |
| 2860 | if (!smp_fetch_url32(args, smp, kw, private)) |
| 2861 | return 0; |
| 2862 | |
| 2863 | temp = get_trash_chunk(); |
| 2864 | *(unsigned int *) temp->area = htonl(smp->data.u.sint); |
| 2865 | temp->data += sizeof(unsigned int); |
| 2866 | |
| 2867 | switch (cli_conn->addr.from.ss_family) { |
| 2868 | case AF_INET: |
| 2869 | memcpy(temp->area + temp->data, |
| 2870 | &((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr, |
| 2871 | 4); |
| 2872 | temp->data += 4; |
| 2873 | break; |
| 2874 | case AF_INET6: |
| 2875 | memcpy(temp->area + temp->data, |
| 2876 | &((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_addr, |
| 2877 | 16); |
| 2878 | temp->data += 16; |
| 2879 | break; |
| 2880 | default: |
| 2881 | return 0; |
| 2882 | } |
| 2883 | |
| 2884 | smp->data.u.str = *temp; |
| 2885 | smp->data.type = SMP_T_BIN; |
| 2886 | return 1; |
| 2887 | } |
| 2888 | |
| 2889 | /************************************************************************/ |
| 2890 | /* Other utility functions */ |
| 2891 | /************************************************************************/ |
| 2892 | |
| 2893 | /* This function is used to validate the arguments passed to any "hdr" fetch |
| 2894 | * keyword. These keywords support an optional positive or negative occurrence |
| 2895 | * number. We must ensure that the number is greater than -MAX_HDR_HISTORY. It |
| 2896 | * is assumed that the types are already the correct ones. Returns 0 on error, |
| 2897 | * non-zero if OK. If <err> is not NULL, it will be filled with a pointer to an |
| 2898 | * error message in case of error, that the caller is responsible for freeing. |
| 2899 | * The initial location must either be freeable or NULL. |
| 2900 | * Note: this function's pointer is checked from Lua. |
| 2901 | */ |
| 2902 | int val_hdr(struct arg *arg, char **err_msg) |
| 2903 | { |
| 2904 | if (arg && arg[1].type == ARGT_SINT && arg[1].data.sint < -MAX_HDR_HISTORY) { |
| 2905 | memprintf(err_msg, "header occurrence must be >= %d", -MAX_HDR_HISTORY); |
| 2906 | return 0; |
| 2907 | } |
| 2908 | return 1; |
| 2909 | } |
| 2910 | |
| 2911 | /************************************************************************/ |
| 2912 | /* All supported sample fetch keywords must be declared here. */ |
| 2913 | /************************************************************************/ |
| 2914 | |
| 2915 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 2916 | static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { |
| 2917 | { "base", smp_fetch_base, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2918 | { "base32", smp_fetch_base32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2919 | { "base32+src", smp_fetch_base32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2920 | |
| 2921 | /* capture are allocated and are permanent in the stream */ |
| 2922 | { "capture.req.hdr", smp_fetch_capture_req_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2923 | |
| 2924 | /* retrieve these captures from the HTTP logs */ |
| 2925 | { "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2926 | { "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2927 | { "capture.req.ver", smp_fetch_capture_req_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2928 | |
| 2929 | { "capture.res.hdr", smp_fetch_capture_res_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRSHP }, |
| 2930 | { "capture.res.ver", smp_fetch_capture_res_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2931 | |
| 2932 | /* cookie is valid in both directions (eg: for "stick ...") but cook* |
| 2933 | * are only here to match the ACL's name, are request-only and are used |
| 2934 | * for ACL compatibility only. |
| 2935 | */ |
| 2936 | { "cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
Christopher Faulet | c1f40dd | 2019-05-16 10:07:30 +0200 | [diff] [blame] | 2937 | { "cookie", smp_fetch_chn_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2938 | { "cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2939 | { "cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2940 | |
| 2941 | /* hdr is valid in both directions (eg: for "stick ...") but hdr_* are |
| 2942 | * only here to match the ACL's name, are request-only and are used for |
| 2943 | * ACL compatibility only. |
| 2944 | */ |
Christopher Faulet | c1f40dd | 2019-05-16 10:07:30 +0200 | [diff] [blame] | 2945 | { "hdr", smp_fetch_chn_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2946 | { "hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2947 | { "hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV }, |
| 2948 | { "hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2949 | |
| 2950 | { "http_auth", smp_fetch_http_auth, ARG1(1,USR), NULL, SMP_T_BOOL, SMP_USE_HRQHV }, |
| 2951 | { "http_auth_group", smp_fetch_http_auth_grp, ARG1(1,USR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2952 | { "http_first_req", smp_fetch_http_first_req, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP }, |
| 2953 | { "method", smp_fetch_meth, 0, NULL, SMP_T_METH, SMP_USE_HRQHP }, |
| 2954 | { "path", smp_fetch_path, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2955 | { "query", smp_fetch_query, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2956 | |
| 2957 | /* HTTP protocol on the request path */ |
| 2958 | { "req.proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP }, |
| 2959 | { "req_proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP }, |
| 2960 | |
| 2961 | /* HTTP version on the request path */ |
| 2962 | { "req.ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2963 | { "req_ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2964 | |
| 2965 | { "req.body", smp_fetch_body, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2966 | { "req.body_len", smp_fetch_body_len, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2967 | { "req.body_size", smp_fetch_body_size, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2968 | { "req.body_param", smp_fetch_body_param, ARG1(0,STR), NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2969 | |
| 2970 | { "req.hdrs", smp_fetch_hdrs, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2971 | { "req.hdrs_bin", smp_fetch_hdrs_bin, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2972 | |
| 2973 | /* HTTP version on the response path */ |
| 2974 | { "res.ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2975 | { "resp_ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2976 | |
| 2977 | /* explicit req.{cook,hdr} are used to force the fetch direction to be request-only */ |
| 2978 | { "req.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2979 | { "req.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2980 | { "req.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2981 | |
| 2982 | { "req.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV }, |
| 2983 | { "req.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2984 | { "req.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV }, |
| 2985 | { "req.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2986 | { "req.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV }, |
| 2987 | { "req.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2988 | { "req.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2989 | |
| 2990 | /* explicit req.{cook,hdr} are used to force the fetch direction to be response-only */ |
| 2991 | { "res.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2992 | { "res.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2993 | { "res.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2994 | |
| 2995 | { "res.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV }, |
| 2996 | { "res.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2997 | { "res.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV }, |
| 2998 | { "res.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2999 | { "res.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV }, |
| 3000 | { "res.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 3001 | { "res.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV }, |
| 3002 | |
| 3003 | /* scook is valid only on the response and is used for ACL compatibility */ |
| 3004 | { "scook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 3005 | { "scook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 3006 | { "scook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 3007 | { "set-cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, /* deprecated */ |
| 3008 | |
| 3009 | /* shdr is valid only on the response and is used for ACL compatibility */ |
| 3010 | { "shdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV }, |
| 3011 | { "shdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 3012 | { "shdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV }, |
| 3013 | { "shdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV }, |
| 3014 | |
| 3015 | { "status", smp_fetch_stcode, 0, NULL, SMP_T_SINT, SMP_USE_HRSHP }, |
| 3016 | { "unique-id", smp_fetch_uniqueid, 0, NULL, SMP_T_STR, SMP_SRC_L4SRV }, |
| 3017 | { "url", smp_fetch_url, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 3018 | { "url32", smp_fetch_url32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 3019 | { "url32+src", smp_fetch_url32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 3020 | { "url_ip", smp_fetch_url_ip, 0, NULL, SMP_T_IPV4, SMP_USE_HRQHV }, |
| 3021 | { "url_port", smp_fetch_url_port, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 3022 | { "url_param", smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 3023 | { "urlp" , smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 3024 | { "urlp_val", smp_fetch_url_param_val, ARG2(0,STR,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 3025 | { /* END */ }, |
| 3026 | }}; |
| 3027 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3028 | INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 3029 | |
| 3030 | /* |
| 3031 | * Local variables: |
| 3032 | * c-indent-level: 8 |
| 3033 | * c-basic-offset: 8 |
| 3034 | * End: |
| 3035 | */ |