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 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 19 | #include <haproxy/api.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 20 | #include <haproxy/arg.h> |
Willy Tarreau | ac13aea | 2020-06-04 10:36:03 +0200 | [diff] [blame] | 21 | #include <haproxy/auth.h> |
Willy Tarreau | 8d36697 | 2020-05-27 16:10:29 +0200 | [diff] [blame] | 22 | #include <haproxy/base64.h> |
Willy Tarreau | f1d32c4 | 2020-06-04 21:07:02 +0200 | [diff] [blame] | 23 | #include <haproxy/channel.h> |
Willy Tarreau | c13ed53 | 2020-06-02 10:22:45 +0200 | [diff] [blame] | 24 | #include <haproxy/chunk.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 25 | #include <haproxy/connection.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 26 | #include <haproxy/global.h> |
Willy Tarreau | 5413a87 | 2020-06-02 19:33:08 +0200 | [diff] [blame] | 27 | #include <haproxy/h1.h> |
Willy Tarreau | c6fe884 | 2020-06-04 09:00:02 +0200 | [diff] [blame] | 28 | #include <haproxy/h1_htx.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 29 | #include <haproxy/http.h> |
Willy Tarreau | c2b1ff0 | 2020-06-04 21:21:03 +0200 | [diff] [blame] | 30 | #include <haproxy/http_ana.h> |
Willy Tarreau | 126ba3a | 2020-06-04 18:26:43 +0200 | [diff] [blame] | 31 | #include <haproxy/http_fetch.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 32 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 33 | #include <haproxy/htx.h> |
Willy Tarreau | 8efbdfb | 2020-06-04 11:29:21 +0200 | [diff] [blame] | 34 | #include <haproxy/obj_type.h> |
Willy Tarreau | d0ef439 | 2020-06-02 09:38:52 +0200 | [diff] [blame] | 35 | #include <haproxy/pool.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 36 | #include <haproxy/sample.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 37 | #include <haproxy/sc_strm.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 38 | #include <haproxy/stream.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 39 | #include <haproxy/tools.h> |
Willy Tarreau | d678805 | 2020-05-27 15:59:00 +0200 | [diff] [blame] | 40 | #include <haproxy/version.h> |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 41 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 42 | |
| 43 | /* this struct is used between calls to smp_fetch_hdr() or smp_fetch_cookie() */ |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 44 | static THREAD_LOCAL struct http_hdr_ctx static_http_hdr_ctx; |
Richard Russo | 458eafb | 2019-07-31 11:45:56 -0700 | [diff] [blame] | 45 | /* this is used to convert raw connection buffers to htx */ |
| 46 | static THREAD_LOCAL struct buffer static_raw_htx_chunk; |
| 47 | static THREAD_LOCAL char *static_raw_htx_buf; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 48 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 49 | #define SMP_REQ_CHN(smp) (smp->strm ? &smp->strm->req : NULL) |
| 50 | #define SMP_RES_CHN(smp) (smp->strm ? &smp->strm->res : NULL) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 51 | |
Richard Russo | 458eafb | 2019-07-31 11:45:56 -0700 | [diff] [blame] | 52 | /* This function returns the static htx chunk, where raw connections get |
| 53 | * converted to HTX as needed for samplxsing. |
| 54 | */ |
| 55 | struct buffer *get_raw_htx_chunk(void) |
| 56 | { |
| 57 | chunk_reset(&static_raw_htx_chunk); |
| 58 | return &static_raw_htx_chunk; |
| 59 | } |
| 60 | |
| 61 | static int alloc_raw_htx_chunk_per_thread() |
| 62 | { |
| 63 | static_raw_htx_buf = malloc(global.tune.bufsize); |
| 64 | if (!static_raw_htx_buf) |
| 65 | return 0; |
| 66 | chunk_init(&static_raw_htx_chunk, static_raw_htx_buf, global.tune.bufsize); |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | static void free_raw_htx_chunk_per_thread() |
| 71 | { |
Willy Tarreau | 61cfdf4 | 2021-02-20 10:46:51 +0100 | [diff] [blame] | 72 | ha_free(&static_raw_htx_buf); |
Richard Russo | 458eafb | 2019-07-31 11:45:56 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | REGISTER_PER_THREAD_ALLOC(alloc_raw_htx_chunk_per_thread); |
| 76 | REGISTER_PER_THREAD_FREE(free_raw_htx_chunk_per_thread); |
| 77 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 78 | /* |
| 79 | * Returns the data from Authorization header. Function may be called more |
| 80 | * than once so data is stored in txn->auth_data. When no header is found |
| 81 | * or auth method is unknown auth_method is set to HTTP_AUTH_WRONG to avoid |
| 82 | * searching again for something we are unable to find anyway. However, if |
| 83 | * the result if valid, the cache is not reused because we would risk to |
| 84 | * have the credentials overwritten by another stream in parallel. |
Willy Tarreau | eae8372 | 2020-04-29 11:52:51 +0200 | [diff] [blame] | 85 | * The caller is responsible for passing a sample with a valid stream/txn, |
| 86 | * and a valid htx. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 87 | */ |
| 88 | |
Christopher Faulet | cd76195 | 2019-07-15 13:58:29 +0200 | [diff] [blame] | 89 | static int get_http_auth(struct sample *smp, struct htx *htx) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 90 | { |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 91 | struct stream *s = smp->strm; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 92 | struct http_txn *txn = s->txn; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 93 | struct http_hdr_ctx ctx = { .blk = NULL }; |
| 94 | struct ist hdr; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 95 | struct buffer auth_method; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 96 | char *p; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 97 | int len; |
| 98 | |
| 99 | #ifdef DEBUG_AUTH |
| 100 | printf("Auth for stream %p: %d\n", s, txn->auth.method); |
| 101 | #endif |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 102 | if (txn->auth.method == HTTP_AUTH_WRONG) |
| 103 | return 0; |
| 104 | |
| 105 | txn->auth.method = HTTP_AUTH_WRONG; |
| 106 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 107 | if (txn->flags & TX_USE_PX_CONN) |
| 108 | hdr = ist("Proxy-Authorization"); |
| 109 | else |
| 110 | hdr = ist("Authorization"); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 111 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 112 | ctx.blk = NULL; |
| 113 | if (!http_find_header(htx, hdr, &ctx, 0)) |
| 114 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 115 | |
Willy Tarreau | 1725493 | 2020-09-02 07:08:47 +0200 | [diff] [blame] | 116 | p = memchr(ctx.value.ptr, ' ', ctx.value.len); |
| 117 | if (!p || p == ctx.value.ptr) /* if no space was found or if the space is the first character */ |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 118 | return 0; |
Willy Tarreau | 1725493 | 2020-09-02 07:08:47 +0200 | [diff] [blame] | 119 | len = p - ctx.value.ptr; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 120 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 121 | if (chunk_initlen(&auth_method, ctx.value.ptr, 0, len) != 1) |
| 122 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 123 | |
Remi Tricot-Le Breton | 68c4eae | 2021-10-29 15:25:18 +0200 | [diff] [blame] | 124 | /* According to RFC7235, there could be multiple spaces between the |
| 125 | * scheme and its value, we must skip all of them. |
| 126 | */ |
| 127 | while (p < istend(ctx.value) && *p == ' ') |
| 128 | ++p; |
| 129 | |
| 130 | chunk_initlen(&txn->auth.method_data, p, 0, istend(ctx.value) - p); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 131 | |
| 132 | if (!strncasecmp("Basic", auth_method.area, auth_method.data)) { |
| 133 | struct buffer *http_auth = get_trash_chunk(); |
| 134 | |
| 135 | len = base64dec(txn->auth.method_data.area, |
| 136 | txn->auth.method_data.data, |
| 137 | http_auth->area, global.tune.bufsize - 1); |
| 138 | |
| 139 | if (len < 0) |
| 140 | return 0; |
| 141 | |
| 142 | |
| 143 | http_auth->area[len] = '\0'; |
| 144 | |
| 145 | p = strchr(http_auth->area, ':'); |
| 146 | |
| 147 | if (!p) |
| 148 | return 0; |
| 149 | |
| 150 | txn->auth.user = http_auth->area; |
| 151 | *p = '\0'; |
| 152 | txn->auth.pass = p+1; |
| 153 | |
| 154 | txn->auth.method = HTTP_AUTH_BASIC; |
| 155 | return 1; |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 156 | } else if (!strncasecmp("Bearer", auth_method.area, auth_method.data)) { |
| 157 | txn->auth.method = HTTP_AUTH_BEARER; |
| 158 | return 1; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /* This function ensures that the prerequisites for an L7 fetch are ready, |
| 165 | * which means that a request or response is ready. If some data is missing, |
| 166 | * 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] | 167 | * to extract data from L7. If <vol> is non-null during a prefetch, another |
| 168 | * test is made to ensure the required information is not gone. |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 169 | * |
| 170 | * The function returns : |
| 171 | * NULL with SMP_F_MAY_CHANGE in the sample flags if some data is missing to |
| 172 | * decide whether or not an HTTP message is present ; |
| 173 | * NULL if the requested data cannot be fetched or if it is certain that |
Willy Tarreau | eae8372 | 2020-04-29 11:52:51 +0200 | [diff] [blame] | 174 | * we'll never have any HTTP message there; this includes null strm or chn. |
Willy Tarreau | a6d9879 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 175 | * NULL if the sample's direction does not match the channel's (i.e. the |
| 176 | * function was asked to work on the wrong channel) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 177 | * The HTX message if ready |
| 178 | */ |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 179 | struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, struct check *check, int vol) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 180 | { |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 181 | struct stream *s = smp->strm; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 182 | struct http_txn *txn = NULL; |
| 183 | struct htx *htx = NULL; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 184 | struct http_msg *msg; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 185 | struct htx_sl *sl; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 186 | |
Willy Tarreau | a6d9879 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 187 | if (chn && |
| 188 | (((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ && (chn->flags & CF_ISRESP)) || |
| 189 | ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES && !(chn->flags & CF_ISRESP)))) |
| 190 | return 0; |
| 191 | |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 192 | /* Note: it is possible that <s> is NULL when called before stream |
| 193 | * initialization (eg: tcp-request connection), so this function is the |
| 194 | * one responsible for guarding against this case for all HTTP users. |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 195 | * |
| 196 | * In the health check context, the stream and the channel must be NULL |
| 197 | * and <check> must be set. In this case, only the input buffer, |
| 198 | * corresponding to the response, is considered. It is the caller |
| 199 | * responsibility to provide <check>. |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 200 | */ |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 201 | BUG_ON(check && (s || chn)); |
| 202 | if (!s || !chn) { |
| 203 | if (check) { |
| 204 | htx = htxbuf(&check->bi); |
| 205 | |
| 206 | /* Analyse not yet started */ |
| 207 | if (htx_is_empty(htx) || htx->first == -1) |
| 208 | return NULL; |
| 209 | |
| 210 | sl = http_get_stline(htx); |
| 211 | if (vol && !sl) { |
| 212 | /* The start-line was already forwarded, it is too late to fetch anything */ |
| 213 | return NULL; |
| 214 | } |
| 215 | goto end; |
| 216 | } |
| 217 | |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 218 | return NULL; |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 219 | } |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 220 | |
Christopher Faulet | 75f619a | 2021-03-08 19:12:58 +0100 | [diff] [blame] | 221 | if (!s->txn && !http_create_txn(s)) |
| 222 | return NULL; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 223 | txn = s->txn; |
| 224 | msg = (!(chn->flags & CF_ISRESP) ? &txn->req : &txn->rsp); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 225 | |
Christopher Faulet | eca8854 | 2019-04-03 10:12:42 +0200 | [diff] [blame] | 226 | if (IS_HTX_STRM(s)) { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 227 | htx = htxbuf(&chn->buf); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 228 | |
Christopher Faulet | 5aab0a3 | 2023-01-13 10:58:20 +0100 | [diff] [blame^] | 229 | if (htx->flags & HTX_FL_PARSING_ERROR) |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 230 | return NULL; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 231 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 232 | if (msg->msg_state < HTTP_MSG_BODY) { |
| 233 | /* Analyse not yet started */ |
Christopher Faulet | 29f1758 | 2019-05-23 11:03:26 +0200 | [diff] [blame] | 234 | if (htx_is_empty(htx) || htx->first == -1) { |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 235 | /* Parsing is done by the mux, just wait */ |
| 236 | smp->flags |= SMP_F_MAY_CHANGE; |
| 237 | return NULL; |
| 238 | } |
| 239 | } |
Christopher Faulet | 297fbb4 | 2019-05-13 14:41:27 +0200 | [diff] [blame] | 240 | sl = http_get_stline(htx); |
Christopher Faulet | 5ec8bcb | 2019-04-17 12:04:12 +0200 | [diff] [blame] | 241 | if (vol && !sl) { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 242 | /* The start-line was already forwarded, it is too late to fetch anything */ |
| 243 | return NULL; |
| 244 | } |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 245 | } |
Christopher Faulet | eca8854 | 2019-04-03 10:12:42 +0200 | [diff] [blame] | 246 | else { /* RAW mode */ |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 247 | struct buffer *buf; |
| 248 | struct h1m h1m; |
Christopher Faulet | e4ab11b | 2019-06-11 15:05:37 +0200 | [diff] [blame] | 249 | struct http_hdr hdrs[global.tune.max_http_hdr]; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 250 | union h1_sl h1sl; |
| 251 | unsigned int flags = HTX_FL_NONE; |
| 252 | int ret; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 253 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 254 | /* no HTTP fetch on the response in TCP mode */ |
| 255 | if (chn->flags & CF_ISRESP) |
| 256 | return NULL; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 257 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 258 | /* Now we are working on the request only */ |
| 259 | buf = &chn->buf; |
| 260 | if (b_head(buf) + b_data(buf) > b_wrap(buf)) |
| 261 | b_slow_realign(buf, trash.area, 0); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 262 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 263 | h1m_init_req(&h1m); |
| 264 | ret = h1_headers_to_hdr_list(b_head(buf), b_stop(buf), |
| 265 | hdrs, sizeof(hdrs)/sizeof(hdrs[0]), &h1m, &h1sl); |
| 266 | if (ret <= 0) { |
| 267 | /* Invalid or too big*/ |
| 268 | if (ret < 0 || channel_full(&s->req, global.tune.maxrewrite)) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 269 | return NULL; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 270 | |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 271 | /* wait for a full request */ |
| 272 | smp->flags |= SMP_F_MAY_CHANGE; |
| 273 | return NULL; |
| 274 | } |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 275 | |
Ilya Shipitsin | 46a030c | 2020-07-05 16:36:08 +0500 | [diff] [blame] | 276 | /* OK we just got a valid HTTP message. We have to convert it |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 277 | * into an HTX message. |
| 278 | */ |
| 279 | if (unlikely(h1sl.rq.v.len == 0)) { |
| 280 | /* try to convert HTTP/0.9 requests to HTTP/1.0 */ |
| 281 | if (h1sl.rq.meth != HTTP_METH_GET || !h1sl.rq.u.len) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 282 | return NULL; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 283 | h1sl.rq.v = ist("HTTP/1.0"); |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 284 | } |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 285 | |
| 286 | /* Set HTX start-line flags */ |
| 287 | if (h1m.flags & H1_MF_VER_11) |
| 288 | flags |= HTX_SL_F_VER_11; |
| 289 | if (h1m.flags & H1_MF_XFER_ENC) |
| 290 | flags |= HTX_SL_F_XFER_ENC; |
| 291 | flags |= HTX_SL_F_XFER_LEN; |
| 292 | if (h1m.flags & H1_MF_CHNK) |
| 293 | flags |= HTX_SL_F_CHNK; |
| 294 | else if (h1m.flags & H1_MF_CLEN) |
| 295 | flags |= HTX_SL_F_CLEN; |
| 296 | |
Richard Russo | 458eafb | 2019-07-31 11:45:56 -0700 | [diff] [blame] | 297 | htx = htx_from_buf(get_raw_htx_chunk()); |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 298 | sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, h1sl.rq.m, h1sl.rq.u, h1sl.rq.v); |
| 299 | if (!sl || !htx_add_all_headers(htx, hdrs)) |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 300 | return NULL; |
Willy Tarreau | ce9bbf5 | 2019-05-13 08:32:31 +0200 | [diff] [blame] | 301 | sl->info.req.meth = h1sl.rq.meth; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* OK we just got a valid HTTP message. If not already done by |
| 305 | * HTTP analyzers, we have some minor preparation to perform so |
| 306 | * that further checks can rely on HTTP tests. |
| 307 | */ |
| 308 | if (sl && msg->msg_state < HTTP_MSG_BODY) { |
| 309 | if (!(chn->flags & CF_ISRESP)) { |
| 310 | txn->meth = sl->info.req.meth; |
| 311 | if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD) |
| 312 | s->flags |= SF_REDIRECTABLE; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 313 | } |
Christopher Faulet | 31850b4 | 2023-01-04 10:11:32 +0100 | [diff] [blame] | 314 | else if (txn->status == -1) |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 315 | txn->status = sl->info.res.status; |
| 316 | if (sl->flags & HTX_SL_F_VER_11) |
| 317 | msg->flags |= HTTP_MSGF_VER_11; |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /* everything's OK */ |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 321 | end: |
Christopher Faulet | ef453ed | 2018-10-24 21:39:27 +0200 | [diff] [blame] | 322 | return htx; |
| 323 | } |
| 324 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 325 | /* This function fetches the method of current HTTP request and stores |
| 326 | * it in the global pattern struct as a chunk. There are two possibilities : |
| 327 | * - if the method is known (not HTTP_METH_OTHER), its identifier is stored |
| 328 | * in <len> and <ptr> is NULL ; |
| 329 | * - if the method is unknown (HTTP_METH_OTHER), <ptr> points to the text and |
| 330 | * <len> to its length. |
| 331 | * This is intended to be used with pat_match_meth() only. |
| 332 | */ |
| 333 | static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 334 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 335 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 336 | struct http_txn *txn; |
Willy Tarreau | 2e2b79d | 2022-10-04 09:18:34 +0200 | [diff] [blame] | 337 | struct htx *htx = NULL; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 338 | int meth; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 339 | |
Christopher Faulet | 12f6dbb | 2022-07-06 17:53:02 +0200 | [diff] [blame] | 340 | txn = (smp->strm ? smp->strm->txn : NULL); |
Willy Tarreau | a6d9879 | 2020-08-12 14:04:52 +0200 | [diff] [blame] | 341 | if (!txn) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 342 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 343 | |
Willy Tarreau | a88e8bf | 2022-07-10 13:13:52 +0200 | [diff] [blame] | 344 | meth = txn->meth; |
| 345 | if (meth == HTTP_METH_OTHER) { |
Christopher Faulet | dbbdb25 | 2022-06-22 17:16:41 +0200 | [diff] [blame] | 346 | htx = smp_prefetch_htx(smp, chn, NULL, 1); |
| 347 | if (!htx) |
| 348 | return 0; |
Christopher Faulet | eefcd8a | 2022-10-04 08:58:02 +0200 | [diff] [blame] | 349 | meth = txn->meth; |
Christopher Faulet | dbbdb25 | 2022-06-22 17:16:41 +0200 | [diff] [blame] | 350 | } |
| 351 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 352 | smp->data.type = SMP_T_METH; |
| 353 | smp->data.u.meth.meth = meth; |
| 354 | if (meth == HTTP_METH_OTHER) { |
| 355 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 356 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 357 | sl = http_get_stline(htx); |
| 358 | smp->flags |= SMP_F_CONST; |
| 359 | smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl); |
| 360 | smp->data.u.meth.str.data = HTX_SL_REQ_MLEN(sl); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 361 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 362 | smp->flags |= SMP_F_VOL_1ST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 363 | return 1; |
| 364 | } |
| 365 | |
| 366 | static int smp_fetch_rqver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 367 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 368 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 369 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 370 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 371 | char *ptr; |
| 372 | int len; |
| 373 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 374 | if (!htx) |
| 375 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 376 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 377 | sl = http_get_stline(htx); |
| 378 | len = HTX_SL_REQ_VLEN(sl); |
| 379 | ptr = HTX_SL_REQ_VPTR(sl); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 380 | |
| 381 | while ((len-- > 0) && (*ptr++ != '/')); |
| 382 | if (len <= 0) |
| 383 | return 0; |
| 384 | |
| 385 | smp->data.type = SMP_T_STR; |
| 386 | smp->data.u.str.area = ptr; |
| 387 | smp->data.u.str.data = len; |
| 388 | |
| 389 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 390 | return 1; |
| 391 | } |
| 392 | |
| 393 | static int smp_fetch_stver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 394 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 395 | struct channel *chn = SMP_RES_CHN(smp); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 396 | struct check *check = objt_check(smp->sess->origin); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 397 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 398 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 399 | char *ptr; |
| 400 | int len; |
| 401 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 402 | if (!htx) |
| 403 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 404 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 405 | sl = http_get_stline(htx); |
| 406 | len = HTX_SL_RES_VLEN(sl); |
| 407 | ptr = HTX_SL_RES_VPTR(sl); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 408 | |
| 409 | while ((len-- > 0) && (*ptr++ != '/')); |
| 410 | if (len <= 0) |
| 411 | return 0; |
| 412 | |
| 413 | smp->data.type = SMP_T_STR; |
| 414 | smp->data.u.str.area = ptr; |
| 415 | smp->data.u.str.data = len; |
| 416 | |
| 417 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 418 | return 1; |
| 419 | } |
| 420 | |
| 421 | /* 3. Check on Status Code. We manipulate integers here. */ |
| 422 | static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 423 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 424 | struct channel *chn = SMP_RES_CHN(smp); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 425 | struct check *check = objt_check(smp->sess->origin); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 426 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 427 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 428 | char *ptr; |
| 429 | int len; |
| 430 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 431 | if (!htx) |
| 432 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 433 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 434 | sl = http_get_stline(htx); |
| 435 | len = HTX_SL_RES_CLEN(sl); |
| 436 | ptr = HTX_SL_RES_CPTR(sl); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 437 | |
| 438 | smp->data.type = SMP_T_SINT; |
| 439 | smp->data.u.sint = __strl2ui(ptr, len); |
| 440 | smp->flags = SMP_F_VOL_1ST; |
| 441 | return 1; |
| 442 | } |
| 443 | |
| 444 | static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 445 | { |
Tim Duesterhus | a17e662 | 2020-03-05 20:19:02 +0100 | [diff] [blame] | 446 | struct ist unique_id; |
Tim Duesterhus | 2825b4b | 2020-02-28 15:13:34 +0100 | [diff] [blame] | 447 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 448 | if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id)) |
| 449 | return 0; |
| 450 | |
Willy Tarreau | a1062a4 | 2020-04-29 11:50:38 +0200 | [diff] [blame] | 451 | if (!smp->strm) |
| 452 | return 0; |
| 453 | |
Tim Duesterhus | a17e662 | 2020-03-05 20:19:02 +0100 | [diff] [blame] | 454 | unique_id = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id); |
| 455 | if (!isttest(unique_id)) |
Tim Duesterhus | 2825b4b | 2020-02-28 15:13:34 +0100 | [diff] [blame] | 456 | return 0; |
| 457 | |
Tim Duesterhus | a17e662 | 2020-03-05 20:19:02 +0100 | [diff] [blame] | 458 | smp->data.u.str.area = smp->strm->unique_id.ptr; |
| 459 | smp->data.u.str.data = smp->strm->unique_id.len; |
Tim Duesterhus | 2825b4b | 2020-02-28 15:13:34 +0100 | [diff] [blame] | 460 | smp->data.type = SMP_T_STR; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 461 | smp->flags = SMP_F_CONST; |
| 462 | return 1; |
| 463 | } |
| 464 | |
| 465 | /* Returns a string block containing all headers including the |
Joseph Herlant | 942eea3 | 2018-11-15 13:57:22 -0800 | [diff] [blame] | 466 | * empty line which separes headers from the body. This is useful |
| 467 | * for some headers analysis. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 468 | */ |
| 469 | static int smp_fetch_hdrs(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 470 | { |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 471 | /* possible keywords: req.hdrs, res.hdrs */ |
| 472 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 473 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 474 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 475 | struct buffer *temp; |
| 476 | int32_t pos; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 477 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 478 | if (!htx) |
| 479 | return 0; |
| 480 | temp = get_trash_chunk(); |
| 481 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 482 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 483 | enum htx_blk_type type = htx_get_blk_type(blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 484 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 485 | if (type == HTX_BLK_HDR) { |
| 486 | struct ist n = htx_get_blk_name(htx, blk); |
| 487 | struct ist v = htx_get_blk_value(htx, blk); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 488 | |
Christopher Faulet | 53a899b | 2019-10-08 16:38:42 +0200 | [diff] [blame] | 489 | if (!h1_format_htx_hdr(n, v, temp)) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 490 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 491 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 492 | else if (type == HTX_BLK_EOH) { |
| 493 | if (!chunk_memcat(temp, "\r\n", 2)) |
| 494 | return 0; |
| 495 | break; |
| 496 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 497 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 498 | smp->data.type = SMP_T_STR; |
| 499 | smp->data.u.str = *temp; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 500 | return 1; |
| 501 | } |
| 502 | |
| 503 | /* Returns the header request in a length/value encoded format. |
| 504 | * This is useful for exchanges with the SPOE. |
| 505 | * |
| 506 | * A "length value" is a multibyte code encoding numbers. It uses the |
| 507 | * SPOE format. The encoding is the following: |
| 508 | * |
| 509 | * Each couple "header name" / "header value" is composed |
| 510 | * like this: |
| 511 | * "length value" "header name bytes" |
| 512 | * "length value" "header value bytes" |
| 513 | * When the last header is reached, the header name and the header |
| 514 | * value are empty. Their length are 0 |
| 515 | */ |
| 516 | static int smp_fetch_hdrs_bin(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 517 | { |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 518 | /* possible keywords: req.hdrs_bin, res.hdrs_bin */ |
| 519 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 520 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 521 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 522 | struct buffer *temp; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 523 | char *p, *end; |
| 524 | int32_t pos; |
| 525 | int ret; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 526 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 527 | if (!htx) |
| 528 | return 0; |
| 529 | temp = get_trash_chunk(); |
| 530 | p = temp->area; |
| 531 | end = temp->area + temp->size; |
| 532 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 533 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 534 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 535 | struct ist n, v; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 536 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 537 | if (type == HTX_BLK_HDR) { |
| 538 | n = htx_get_blk_name(htx,blk); |
| 539 | v = htx_get_blk_value(htx, blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 540 | |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 541 | /* encode the header name. */ |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 542 | ret = encode_varint(n.len, &p, end); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 543 | if (ret == -1) |
| 544 | return 0; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 545 | if (p + n.len > end) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 546 | return 0; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 547 | memcpy(p, n.ptr, n.len); |
| 548 | p += n.len; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 549 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 550 | /* encode the header value. */ |
| 551 | ret = encode_varint(v.len, &p, end); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 552 | if (ret == -1) |
| 553 | return 0; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 554 | if (p + v.len > end) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 555 | return 0; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 556 | memcpy(p, v.ptr, v.len); |
| 557 | p += v.len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 558 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 559 | } |
| 560 | else if (type == HTX_BLK_EOH) { |
| 561 | /* encode the end of the header list with empty |
| 562 | * header name and header value. |
| 563 | */ |
| 564 | ret = encode_varint(0, &p, end); |
| 565 | if (ret == -1) |
| 566 | return 0; |
| 567 | ret = encode_varint(0, &p, end); |
| 568 | if (ret == -1) |
| 569 | return 0; |
| 570 | break; |
| 571 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 572 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 573 | |
| 574 | /* Initialise sample data which will be filled. */ |
| 575 | smp->data.type = SMP_T_BIN; |
| 576 | smp->data.u.str.area = temp->area; |
| 577 | smp->data.u.str.data = p - temp->area; |
| 578 | smp->data.u.str.size = temp->size; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 579 | return 1; |
| 580 | } |
| 581 | |
| 582 | /* returns the longest available part of the body. This requires that the body |
| 583 | * has been waited for using http-buffer-request. |
| 584 | */ |
| 585 | static int smp_fetch_body(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 586 | { |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 587 | /* possible keywords: req.body, res.body */ |
| 588 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 589 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 590 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 591 | struct buffer *temp; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 592 | int32_t pos; |
Christopher Faulet | a9ffc41 | 2020-11-25 08:08:08 +0100 | [diff] [blame] | 593 | int finished = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 594 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 595 | if (!htx) |
| 596 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 597 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 598 | temp = get_trash_chunk(); |
| 599 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 600 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 601 | enum htx_blk_type type = htx_get_blk_type(blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 602 | |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 603 | if (type == HTX_BLK_TLR || type == HTX_BLK_EOT) { |
Christopher Faulet | a9ffc41 | 2020-11-25 08:08:08 +0100 | [diff] [blame] | 604 | finished = 1; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 605 | break; |
Christopher Faulet | a9ffc41 | 2020-11-25 08:08:08 +0100 | [diff] [blame] | 606 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 607 | if (type == HTX_BLK_DATA) { |
Christopher Faulet | 53a899b | 2019-10-08 16:38:42 +0200 | [diff] [blame] | 608 | if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0)) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 609 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 610 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 611 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 612 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 613 | smp->data.type = SMP_T_BIN; |
| 614 | smp->data.u.str = *temp; |
| 615 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 9dc92b2 | 2020-06-15 18:01:10 +0200 | [diff] [blame] | 616 | |
Christopher Faulet | a9ffc41 | 2020-11-25 08:08:08 +0100 | [diff] [blame] | 617 | if (!finished && (check || (chn && !channel_full(chn, global.tune.maxrewrite) && |
Christopher Faulet | 4b490b7 | 2023-01-04 11:55:15 +0100 | [diff] [blame] | 618 | !(chn->flags & (CF_EOI|CF_SHUTR))))) |
Willy Tarreau | 9dc92b2 | 2020-06-15 18:01:10 +0200 | [diff] [blame] | 619 | smp->flags |= SMP_F_MAY_CHANGE; |
| 620 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 621 | return 1; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | /* returns the available length of the body. This requires that the body |
| 626 | * has been waited for using http-buffer-request. |
| 627 | */ |
| 628 | static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 629 | { |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 630 | /* possible keywords: req.body_len, res.body_len */ |
| 631 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 632 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 633 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 634 | int32_t pos; |
| 635 | unsigned long long len = 0; |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 636 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 637 | if (!htx) |
| 638 | return 0; |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 639 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 640 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 641 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 642 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 643 | |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 644 | if (type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 645 | break; |
| 646 | if (type == HTX_BLK_DATA) |
| 647 | len += htx_get_blksz(blk); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 648 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 649 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 650 | smp->data.type = SMP_T_SINT; |
| 651 | smp->data.u.sint = len; |
| 652 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 653 | return 1; |
| 654 | } |
| 655 | |
| 656 | |
| 657 | /* returns the advertised length of the body, or the advertised size of the |
| 658 | * chunks available in the buffer. This requires that the body has been waited |
| 659 | * for using http-buffer-request. |
| 660 | */ |
| 661 | static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 662 | { |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 663 | /* possible keywords: req.body_size, res.body_size */ |
| 664 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 665 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 666 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 667 | int32_t pos; |
| 668 | unsigned long long len = 0; |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 669 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 670 | if (!htx) |
| 671 | return 0; |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 672 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 673 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 674 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 675 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | c16317d | 2018-12-12 14:11:22 +0100 | [diff] [blame] | 676 | |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 677 | if (type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 678 | break; |
| 679 | if (type == HTX_BLK_DATA) |
| 680 | len += htx_get_blksz(blk); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 681 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 682 | if (htx->extra != ULLONG_MAX) |
| 683 | len += htx->extra; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 684 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 685 | smp->data.type = SMP_T_SINT; |
| 686 | smp->data.u.sint = len; |
| 687 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 688 | return 1; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | /* 4. Check on URL/URI. A pointer to the URI is stored. */ |
| 693 | static int smp_fetch_url(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 694 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 695 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 696 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 697 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 698 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 699 | if (!htx) |
| 700 | return 0; |
| 701 | sl = http_get_stline(htx); |
| 702 | smp->data.type = SMP_T_STR; |
| 703 | smp->data.u.str.area = HTX_SL_REQ_UPTR(sl); |
| 704 | smp->data.u.str.data = HTX_SL_REQ_ULEN(sl); |
| 705 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 706 | return 1; |
| 707 | } |
| 708 | |
| 709 | static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 710 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 711 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 712 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 713 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 714 | struct sockaddr_storage addr; |
| 715 | |
Amaury Denoyelle | c89d533 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 716 | memset(&addr, 0, sizeof(addr)); |
| 717 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 718 | if (!htx) |
| 719 | return 0; |
| 720 | sl = http_get_stline(htx); |
Amaury Denoyelle | c89d533 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 721 | if (url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL) < 0) |
| 722 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 723 | |
Willy Tarreau | 4858464 | 2021-05-09 10:32:54 +0200 | [diff] [blame] | 724 | if (addr.ss_family != AF_INET) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 725 | return 0; |
| 726 | |
| 727 | smp->data.type = SMP_T_IPV4; |
| 728 | smp->data.u.ipv4 = ((struct sockaddr_in *)&addr)->sin_addr; |
| 729 | smp->flags = 0; |
| 730 | return 1; |
| 731 | } |
| 732 | |
| 733 | static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 734 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 735 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 736 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 737 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 738 | struct sockaddr_storage addr; |
| 739 | |
Amaury Denoyelle | c89d533 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 740 | memset(&addr, 0, sizeof(addr)); |
| 741 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 742 | if (!htx) |
| 743 | return 0; |
| 744 | sl = http_get_stline(htx); |
Amaury Denoyelle | c89d533 | 2021-05-10 11:23:34 +0200 | [diff] [blame] | 745 | if (url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL) < 0) |
| 746 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 747 | |
Willy Tarreau | 4858464 | 2021-05-09 10:32:54 +0200 | [diff] [blame] | 748 | if (addr.ss_family != AF_INET) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 749 | return 0; |
| 750 | |
| 751 | smp->data.type = SMP_T_SINT; |
Willy Tarreau | 4858464 | 2021-05-09 10:32:54 +0200 | [diff] [blame] | 752 | smp->data.u.sint = get_host_port(&addr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 753 | smp->flags = 0; |
| 754 | return 1; |
| 755 | } |
| 756 | |
| 757 | /* Fetch an HTTP header. A pointer to the beginning of the value is returned. |
| 758 | * Accepts an optional argument of type string containing the header field name, |
| 759 | * and an optional argument of type signed or unsigned integer to request an |
| 760 | * explicit occurrence of the header. Note that in the event of a missing name, |
| 761 | * headers are considered from the first one. It does not stop on commas and |
| 762 | * returns full lines instead (useful for User-Agent or Date for example). |
| 763 | */ |
| 764 | static int smp_fetch_fhdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 765 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 766 | /* possible keywords: req.fhdr, res.fhdr */ |
| 767 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 768 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 769 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 770 | struct http_hdr_ctx *ctx = smp->ctx.a[0]; |
| 771 | struct ist name; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 772 | int occ = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 773 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 774 | if (!ctx) { |
| 775 | /* first call */ |
| 776 | ctx = &static_http_hdr_ctx; |
| 777 | ctx->blk = NULL; |
| 778 | smp->ctx.a[0] = ctx; |
| 779 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 780 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 781 | if (args[0].type != ARGT_STR) |
| 782 | return 0; |
Tim Duesterhus | 92c696e | 2021-02-28 16:11:36 +0100 | [diff] [blame] | 783 | name = ist2(args[0].data.str.area, args[0].data.str.data); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 784 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 785 | if (args[1].type == ARGT_SINT) |
| 786 | occ = args[1].data.sint; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 787 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 788 | if (!htx) |
| 789 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 790 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 791 | if (ctx && !(smp->flags & SMP_F_NOT_LAST)) |
| 792 | /* search for header from the beginning */ |
| 793 | ctx->blk = NULL; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 794 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 795 | if (!occ && !(smp->opt & SMP_OPT_ITERATE)) |
| 796 | /* no explicit occurrence and single fetch => last header by default */ |
| 797 | occ = -1; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 798 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 799 | if (!occ) |
| 800 | /* prepare to report multiple occurrences for ACL fetches */ |
| 801 | smp->flags |= SMP_F_NOT_LAST; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 802 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 803 | smp->data.type = SMP_T_STR; |
| 804 | smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; |
| 805 | if (http_get_htx_fhdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data)) |
| 806 | return 1; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 807 | smp->flags &= ~SMP_F_NOT_LAST; |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | /* 6. Check on HTTP header count. The number of occurrences is returned. |
| 812 | * Accepts exactly 1 argument of type string. It does not stop on commas and |
| 813 | * returns full lines instead (useful for User-Agent or Date for example). |
| 814 | */ |
| 815 | static int smp_fetch_fhdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 816 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 817 | /* possible keywords: req.fhdr_cnt, res.fhdr_cnt */ |
| 818 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 819 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 820 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 821 | struct http_hdr_ctx ctx; |
| 822 | struct ist name; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 823 | int cnt; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 824 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 825 | if (!htx) |
| 826 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 827 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 828 | if (args->type == ARGT_STR) { |
Tim Duesterhus | 92c696e | 2021-02-28 16:11:36 +0100 | [diff] [blame] | 829 | name = ist2(args->data.str.area, args->data.str.data); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 830 | } else { |
Tim Duesterhus | 68a088d | 2021-02-28 16:11:37 +0100 | [diff] [blame] | 831 | name = IST_NULL; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 832 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 833 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 834 | ctx.blk = NULL; |
| 835 | cnt = 0; |
| 836 | while (http_find_header(htx, name, &ctx, 1)) |
| 837 | cnt++; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 838 | smp->data.type = SMP_T_SINT; |
| 839 | smp->data.u.sint = cnt; |
| 840 | smp->flags = SMP_F_VOL_HDR; |
| 841 | return 1; |
| 842 | } |
| 843 | |
| 844 | static int smp_fetch_hdr_names(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 845 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 846 | /* possible keywords: req.hdr_names, res.hdr_names */ |
| 847 | struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 848 | struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 849 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 850 | struct buffer *temp; |
| 851 | char del = ','; |
| 852 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 853 | int32_t pos; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 854 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 855 | if (!htx) |
| 856 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 857 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 858 | if (args->type == ARGT_STR) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 859 | del = *args[0].data.str.area; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 860 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 861 | temp = get_trash_chunk(); |
| 862 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 863 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 864 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 865 | struct ist n; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 866 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 867 | if (type == HTX_BLK_EOH) |
| 868 | break; |
| 869 | if (type != HTX_BLK_HDR) |
| 870 | continue; |
| 871 | n = htx_get_blk_name(htx, blk); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 872 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 873 | if (temp->data) |
| 874 | temp->area[temp->data++] = del; |
Tim Duesterhus | 9f7ed8a | 2021-11-08 09:05:04 +0100 | [diff] [blame] | 875 | chunk_istcat(temp, n); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | smp->data.type = SMP_T_STR; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 879 | smp->data.u.str = *temp; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 880 | smp->flags = SMP_F_VOL_HDR; |
| 881 | return 1; |
| 882 | } |
| 883 | |
| 884 | /* Fetch an HTTP header. A pointer to the beginning of the value is returned. |
| 885 | * Accepts an optional argument of type string containing the header field name, |
| 886 | * and an optional argument of type signed or unsigned integer to request an |
| 887 | * explicit occurrence of the header. Note that in the event of a missing name, |
| 888 | * headers are considered from the first one. |
| 889 | */ |
| 890 | static int smp_fetch_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 891 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 892 | /* possible keywords: req.hdr / hdr, res.hdr / shdr */ |
| 893 | struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 894 | struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 895 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 896 | struct http_hdr_ctx *ctx = smp->ctx.a[0]; |
| 897 | struct ist name; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 898 | int occ = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 899 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 900 | if (!ctx) { |
| 901 | /* first call */ |
| 902 | ctx = &static_http_hdr_ctx; |
| 903 | ctx->blk = NULL; |
| 904 | smp->ctx.a[0] = ctx; |
| 905 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 906 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 907 | if (args[0].type != ARGT_STR) |
| 908 | return 0; |
Tim Duesterhus | 92c696e | 2021-02-28 16:11:36 +0100 | [diff] [blame] | 909 | name = ist2(args[0].data.str.area, args[0].data.str.data); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 910 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 911 | if (args[1].type == ARGT_SINT) |
| 912 | occ = args[1].data.sint; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 913 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 914 | if (!htx) |
| 915 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 916 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 917 | if (ctx && !(smp->flags & SMP_F_NOT_LAST)) |
| 918 | /* search for header from the beginning */ |
| 919 | ctx->blk = NULL; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 920 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 921 | if (!occ && !(smp->opt & SMP_OPT_ITERATE)) |
| 922 | /* no explicit occurrence and single fetch => last header by default */ |
| 923 | occ = -1; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 924 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 925 | if (!occ) |
| 926 | /* prepare to report multiple occurrences for ACL fetches */ |
| 927 | smp->flags |= SMP_F_NOT_LAST; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 928 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 929 | smp->data.type = SMP_T_STR; |
| 930 | smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; |
| 931 | if (http_get_htx_hdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data)) |
| 932 | return 1; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 933 | |
| 934 | smp->flags &= ~SMP_F_NOT_LAST; |
| 935 | return 0; |
| 936 | } |
| 937 | |
Christopher Faulet | c1f40dd | 2019-05-16 10:07:30 +0200 | [diff] [blame] | 938 | /* Same than smp_fetch_hdr() but only relies on the sample direction to choose |
| 939 | * the right channel. So instead of duplicating the code, we just change the |
| 940 | * keyword and then fallback on smp_fetch_hdr(). |
| 941 | */ |
| 942 | static int smp_fetch_chn_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 943 | { |
| 944 | kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.hdr" : "res.hdr"); |
| 945 | return smp_fetch_hdr(args, smp, kw, private); |
| 946 | } |
| 947 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 948 | /* 6. Check on HTTP header count. The number of occurrences is returned. |
| 949 | * Accepts exactly 1 argument of type string. |
| 950 | */ |
| 951 | static int smp_fetch_hdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 952 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 953 | /* possible keywords: req.hdr_cnt / hdr_cnt, res.hdr_cnt / shdr_cnt */ |
| 954 | struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 955 | struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 956 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 957 | struct http_hdr_ctx ctx; |
| 958 | struct ist name; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 959 | int cnt; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 960 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 961 | if (!htx) |
| 962 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 963 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 964 | if (args->type == ARGT_STR) { |
Tim Duesterhus | 92c696e | 2021-02-28 16:11:36 +0100 | [diff] [blame] | 965 | name = ist2(args->data.str.area, args->data.str.data); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 966 | } else { |
Tim Duesterhus | 68a088d | 2021-02-28 16:11:37 +0100 | [diff] [blame] | 967 | name = IST_NULL; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 968 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 969 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 970 | ctx.blk = NULL; |
| 971 | cnt = 0; |
| 972 | while (http_find_header(htx, name, &ctx, 0)) |
| 973 | cnt++; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 974 | |
| 975 | smp->data.type = SMP_T_SINT; |
| 976 | smp->data.u.sint = cnt; |
| 977 | smp->flags = SMP_F_VOL_HDR; |
| 978 | return 1; |
| 979 | } |
| 980 | |
| 981 | /* Fetch an HTTP header's integer value. The integer value is returned. It |
| 982 | * takes a mandatory argument of type string and an optional one of type int |
| 983 | * to designate a specific occurrence. It returns an unsigned integer, which |
| 984 | * may or may not be appropriate for everything. |
| 985 | */ |
| 986 | static int smp_fetch_hdr_val(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 987 | { |
| 988 | int ret = smp_fetch_hdr(args, smp, kw, private); |
| 989 | |
| 990 | if (ret > 0) { |
| 991 | smp->data.type = SMP_T_SINT; |
| 992 | smp->data.u.sint = strl2ic(smp->data.u.str.area, |
| 993 | smp->data.u.str.data); |
| 994 | } |
| 995 | |
| 996 | return ret; |
| 997 | } |
| 998 | |
| 999 | /* Fetch an HTTP header's IP value. takes a mandatory argument of type string |
| 1000 | * and an optional one of type int to designate a specific occurrence. |
Willy Tarreau | 7b0e00d | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1001 | * It returns an IPv4 or IPv6 address. Addresses surrounded by invalid chars |
| 1002 | * are rejected. However IPv4 addresses may be followed with a colon and a |
| 1003 | * valid port number. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1004 | */ |
| 1005 | static int smp_fetch_hdr_ip(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1006 | { |
Tim Duesterhus | 5cd0087 | 2020-06-26 15:44:48 +0200 | [diff] [blame] | 1007 | struct buffer *temp = get_trash_chunk(); |
Willy Tarreau | 7b0e00d | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1008 | int ret, len; |
| 1009 | int port; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1010 | |
| 1011 | while ((ret = smp_fetch_hdr(args, smp, kw, private)) > 0) { |
Tim Duesterhus | 5cd0087 | 2020-06-26 15:44:48 +0200 | [diff] [blame] | 1012 | if (smp->data.u.str.data < temp->size - 1) { |
| 1013 | memcpy(temp->area, smp->data.u.str.area, |
| 1014 | smp->data.u.str.data); |
| 1015 | temp->area[smp->data.u.str.data] = '\0'; |
Willy Tarreau | 7b0e00d | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1016 | len = url2ipv4((char *) temp->area, &smp->data.u.ipv4); |
Willy Tarreau | 645dc08 | 2021-03-31 11:41:36 +0200 | [diff] [blame] | 1017 | if (len > 0 && len == smp->data.u.str.data) { |
Willy Tarreau | 7b0e00d | 2021-03-25 14:12:29 +0100 | [diff] [blame] | 1018 | /* plain IPv4 address */ |
| 1019 | smp->data.type = SMP_T_IPV4; |
| 1020 | break; |
| 1021 | } else if (len > 0 && temp->area[len] == ':' && |
| 1022 | strl2irc(temp->area + len + 1, smp->data.u.str.data - len - 1, &port) == 0 && |
| 1023 | port >= 0 && port <= 65535) { |
| 1024 | /* IPv4 address suffixed with ':' followed by a valid port number */ |
Tim Duesterhus | 5cd0087 | 2020-06-26 15:44:48 +0200 | [diff] [blame] | 1025 | smp->data.type = SMP_T_IPV4; |
| 1026 | break; |
| 1027 | } else if (inet_pton(AF_INET6, temp->area, &smp->data.u.ipv6)) { |
| 1028 | smp->data.type = SMP_T_IPV6; |
| 1029 | break; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1033 | /* if the header doesn't match an IP address, fetch next one */ |
| 1034 | if (!(smp->flags & SMP_F_NOT_LAST)) |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1035 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1036 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1037 | return ret; |
| 1038 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1039 | |
Christopher Faulet | e720c32 | 2020-09-02 17:25:18 +0200 | [diff] [blame] | 1040 | /* 8. Check on URI PATH. A pointer to the PATH is stored. The path starts at the |
| 1041 | * first '/' after the possible hostname. It ends before the possible '?' except |
| 1042 | * for 'pathq' keyword. |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1043 | */ |
| 1044 | static int smp_fetch_path(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1045 | { |
| 1046 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1047 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1048 | struct htx_sl *sl; |
| 1049 | struct ist path; |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1050 | struct http_uri_parser parser; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1051 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1052 | if (!htx) |
| 1053 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1054 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1055 | sl = http_get_stline(htx); |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1056 | parser = http_uri_parser_init(htx_sl_req_uri(sl)); |
Christopher Faulet | e720c32 | 2020-09-02 17:25:18 +0200 | [diff] [blame] | 1057 | |
Yves Lafon | b4d3708 | 2021-02-11 11:01:28 +0100 | [diff] [blame] | 1058 | if (kw[4] == 'q' && (kw[0] == 'p' || kw[0] == 'b')) // pathq or baseq |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1059 | path = http_parse_path(&parser); |
Christopher Faulet | e720c32 | 2020-09-02 17:25:18 +0200 | [diff] [blame] | 1060 | else |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1061 | path = iststop(http_parse_path(&parser), '?'); |
Christopher Faulet | e720c32 | 2020-09-02 17:25:18 +0200 | [diff] [blame] | 1062 | |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 1063 | if (!isttest(path)) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1064 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1065 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1066 | /* OK, we got the '/' ! */ |
| 1067 | smp->data.type = SMP_T_STR; |
| 1068 | smp->data.u.str.area = path.ptr; |
Jerome Magnin | 4fb196c | 2020-02-21 10:49:12 +0100 | [diff] [blame] | 1069 | smp->data.u.str.data = path.len; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1070 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1071 | return 1; |
| 1072 | } |
| 1073 | |
| 1074 | /* This produces a concatenation of the first occurrence of the Host header |
| 1075 | * followed by the path component if it begins with a slash ('/'). This means |
| 1076 | * that '*' will not be added, resulting in exactly the first Host entry. |
| 1077 | * If no Host header is found, then the path is returned as-is. The returned |
| 1078 | * value is stored in the trash so it does not need to be marked constant. |
| 1079 | * The returned sample is of type string. |
| 1080 | */ |
| 1081 | static int smp_fetch_base(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1082 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1083 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1084 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1085 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1086 | struct buffer *temp; |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1087 | struct http_hdr_ctx ctx; |
| 1088 | struct ist path; |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1089 | struct http_uri_parser parser; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1090 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1091 | if (!htx) |
| 1092 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1093 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1094 | ctx.blk = NULL; |
| 1095 | if (!http_find_header(htx, ist("Host"), &ctx, 0) || !ctx.value.len) |
| 1096 | return smp_fetch_path(args, smp, kw, private); |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1097 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1098 | /* OK we have the header value in ctx.value */ |
| 1099 | temp = get_trash_chunk(); |
Tim Duesterhus | 7750850 | 2022-03-15 13:11:06 +0100 | [diff] [blame] | 1100 | chunk_istcat(temp, ctx.value); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1101 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1102 | /* now retrieve the path */ |
| 1103 | sl = http_get_stline(htx); |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1104 | parser = http_uri_parser_init(htx_sl_req_uri(sl)); |
| 1105 | path = http_parse_path(&parser); |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 1106 | if (isttest(path)) { |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1107 | size_t len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1108 | |
Yves Lafon | b4d3708 | 2021-02-11 11:01:28 +0100 | [diff] [blame] | 1109 | if (kw[4] == 'q' && kw[0] == 'b') { // baseq |
| 1110 | len = path.len; |
| 1111 | } else { |
| 1112 | for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++) |
| 1113 | ; |
| 1114 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1115 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1116 | if (len && *(path.ptr) == '/') |
| 1117 | chunk_memcat(temp, path.ptr, len); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1120 | smp->data.type = SMP_T_STR; |
| 1121 | smp->data.u.str = *temp; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1122 | smp->flags = SMP_F_VOL_1ST; |
| 1123 | return 1; |
| 1124 | } |
| 1125 | |
| 1126 | /* This produces a 32-bit hash of the concatenation of the first occurrence of |
| 1127 | * the Host header followed by the path component if it begins with a slash ('/'). |
| 1128 | * This means that '*' will not be added, resulting in exactly the first Host |
| 1129 | * entry. If no Host header is found, then the path is used. The resulting value |
| 1130 | * is hashed using the path hash followed by a full avalanche hash and provides a |
| 1131 | * 32-bit integer value. This fetch is useful for tracking per-path activity on |
| 1132 | * high-traffic sites without having to store whole paths. |
| 1133 | */ |
| 1134 | static int smp_fetch_base32(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1135 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1136 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1137 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1138 | struct htx_sl *sl; |
| 1139 | struct http_hdr_ctx ctx; |
| 1140 | struct ist path; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1141 | unsigned int hash = 0; |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1142 | struct http_uri_parser parser; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1143 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1144 | if (!htx) |
| 1145 | return 0; |
Dragan Dosen | 8861e1c | 2019-02-12 19:50:31 +0100 | [diff] [blame] | 1146 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1147 | ctx.blk = NULL; |
| 1148 | if (http_find_header(htx, ist("Host"), &ctx, 0)) { |
| 1149 | /* OK we have the header value in ctx.value */ |
| 1150 | while (ctx.value.len--) |
| 1151 | hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1152 | } |
| 1153 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1154 | /* now retrieve the path */ |
| 1155 | sl = http_get_stline(htx); |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1156 | parser = http_uri_parser_init(htx_sl_req_uri(sl)); |
| 1157 | path = http_parse_path(&parser); |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 1158 | if (isttest(path)) { |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1159 | size_t len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1160 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1161 | for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++) |
| 1162 | ; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1163 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1164 | if (len && *(path.ptr) == '/') { |
| 1165 | while (len--) |
| 1166 | hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1167 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1168 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1169 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1170 | hash = full_hash(hash); |
| 1171 | |
| 1172 | smp->data.type = SMP_T_SINT; |
| 1173 | smp->data.u.sint = hash; |
| 1174 | smp->flags = SMP_F_VOL_1ST; |
| 1175 | return 1; |
| 1176 | } |
| 1177 | |
| 1178 | /* This concatenates the source address with the 32-bit hash of the Host and |
| 1179 | * path as returned by smp_fetch_base32(). The idea is to have per-source and |
| 1180 | * per-path counters. The result is a binary block from 8 to 20 bytes depending |
| 1181 | * on the source address length. The path hash is stored before the address so |
| 1182 | * that in environments where IPv6 is insignificant, truncating the output to |
| 1183 | * 8 bytes would still work. |
| 1184 | */ |
| 1185 | static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1186 | { |
Willy Tarreau | d68ff01 | 2022-05-27 08:57:21 +0200 | [diff] [blame] | 1187 | const struct sockaddr_storage *src = (smp->strm ? sc_src(smp->strm->scf) : NULL); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1188 | struct buffer *temp; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1189 | |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 1190 | if (!src) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1191 | return 0; |
| 1192 | |
| 1193 | if (!smp_fetch_base32(args, smp, kw, private)) |
| 1194 | return 0; |
| 1195 | |
| 1196 | temp = get_trash_chunk(); |
| 1197 | *(unsigned int *) temp->area = htonl(smp->data.u.sint); |
| 1198 | temp->data += sizeof(unsigned int); |
| 1199 | |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 1200 | switch (src->ss_family) { |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1201 | case AF_INET: |
| 1202 | memcpy(temp->area + temp->data, |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 1203 | &((struct sockaddr_in *)src)->sin_addr, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1204 | 4); |
| 1205 | temp->data += 4; |
| 1206 | break; |
| 1207 | case AF_INET6: |
| 1208 | memcpy(temp->area + temp->data, |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 1209 | &((struct sockaddr_in6 *)src)->sin6_addr, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1210 | 16); |
| 1211 | temp->data += 16; |
| 1212 | break; |
| 1213 | default: |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | smp->data.u.str = *temp; |
| 1218 | smp->data.type = SMP_T_BIN; |
| 1219 | return 1; |
| 1220 | } |
| 1221 | |
| 1222 | /* Extracts the query string, which comes after the question mark '?'. If no |
| 1223 | * question mark is found, nothing is returned. Otherwise it returns a sample |
| 1224 | * of type string carrying the whole query string. |
| 1225 | */ |
| 1226 | static int smp_fetch_query(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1227 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1228 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1229 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1230 | struct htx_sl *sl; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1231 | char *ptr, *end; |
| 1232 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1233 | if (!htx) |
| 1234 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1235 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1236 | sl = http_get_stline(htx); |
| 1237 | ptr = HTX_SL_REQ_UPTR(sl); |
| 1238 | end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1239 | |
| 1240 | /* look up the '?' */ |
| 1241 | do { |
| 1242 | if (ptr == end) |
| 1243 | return 0; |
| 1244 | } while (*ptr++ != '?'); |
| 1245 | |
| 1246 | smp->data.type = SMP_T_STR; |
| 1247 | smp->data.u.str.area = ptr; |
| 1248 | smp->data.u.str.data = end - ptr; |
| 1249 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 1250 | return 1; |
| 1251 | } |
| 1252 | |
| 1253 | static int smp_fetch_proto_http(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1254 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1255 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1256 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 0); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1257 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1258 | if (!htx) |
| 1259 | return 0; |
| 1260 | smp->data.type = SMP_T_BOOL; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1261 | smp->data.u.sint = 1; |
| 1262 | return 1; |
| 1263 | } |
| 1264 | |
| 1265 | /* return a valid test if the current request is the first one on the connection */ |
| 1266 | static int smp_fetch_http_first_req(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1267 | { |
Willy Tarreau | 79512b6 | 2020-04-29 11:52:13 +0200 | [diff] [blame] | 1268 | if (!smp->strm) |
| 1269 | return 0; |
| 1270 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1271 | smp->data.type = SMP_T_BOOL; |
| 1272 | smp->data.u.sint = !(smp->strm->txn->flags & TX_NOT_FIRST); |
| 1273 | return 1; |
| 1274 | } |
| 1275 | |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 1276 | /* Fetch the authentication method if there is an Authorization header. It |
| 1277 | * relies on get_http_auth() |
| 1278 | */ |
| 1279 | static int smp_fetch_http_auth_type(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1280 | { |
| 1281 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1282 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 1283 | struct http_txn *txn; |
| 1284 | |
| 1285 | if (!htx) |
| 1286 | return 0; |
| 1287 | |
| 1288 | txn = smp->strm->txn; |
| 1289 | if (!get_http_auth(smp, htx)) |
| 1290 | return 0; |
| 1291 | |
| 1292 | switch (txn->auth.method) { |
| 1293 | case HTTP_AUTH_BASIC: |
| 1294 | smp->data.u.str.area = "Basic"; |
| 1295 | smp->data.u.str.data = 5; |
| 1296 | break; |
| 1297 | case HTTP_AUTH_DIGEST: |
| 1298 | /* Unexpected because not supported */ |
| 1299 | smp->data.u.str.area = "Digest"; |
| 1300 | smp->data.u.str.data = 6; |
| 1301 | break; |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 1302 | case HTTP_AUTH_BEARER: |
| 1303 | smp->data.u.str.area = "Bearer"; |
| 1304 | smp->data.u.str.data = 6; |
| 1305 | break; |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 1306 | default: |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | smp->data.type = SMP_T_STR; |
| 1311 | smp->flags = SMP_F_CONST; |
| 1312 | return 1; |
| 1313 | } |
| 1314 | |
| 1315 | /* Fetch the user supplied if there is an Authorization header. It relies on |
| 1316 | * get_http_auth() |
| 1317 | */ |
| 1318 | static int smp_fetch_http_auth_user(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1319 | { |
| 1320 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1321 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 1322 | struct http_txn *txn; |
| 1323 | |
| 1324 | if (!htx) |
| 1325 | return 0; |
| 1326 | |
| 1327 | txn = smp->strm->txn; |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 1328 | if (!get_http_auth(smp, htx) || txn->auth.method != HTTP_AUTH_BASIC) |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 1329 | return 0; |
| 1330 | |
| 1331 | smp->data.type = SMP_T_STR; |
| 1332 | smp->data.u.str.area = txn->auth.user; |
| 1333 | smp->data.u.str.data = strlen(txn->auth.user); |
| 1334 | smp->flags = SMP_F_CONST; |
| 1335 | return 1; |
| 1336 | } |
| 1337 | |
| 1338 | /* Fetch the password supplied if there is an Authorization header. It relies on |
| 1339 | * get_http_auth() |
| 1340 | */ |
| 1341 | static int smp_fetch_http_auth_pass(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1342 | { |
| 1343 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1344 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 1345 | struct http_txn *txn; |
| 1346 | |
| 1347 | if (!htx) |
| 1348 | return 0; |
| 1349 | |
| 1350 | txn = smp->strm->txn; |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 1351 | if (!get_http_auth(smp, htx) || txn->auth.method != HTTP_AUTH_BASIC) |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 1352 | return 0; |
| 1353 | |
| 1354 | smp->data.type = SMP_T_STR; |
| 1355 | smp->data.u.str.area = txn->auth.pass; |
| 1356 | smp->data.u.str.data = strlen(txn->auth.pass); |
| 1357 | smp->flags = SMP_F_CONST; |
| 1358 | return 1; |
| 1359 | } |
| 1360 | |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 1361 | static int smp_fetch_http_auth_bearer(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1362 | { |
| 1363 | struct channel *chn = SMP_REQ_CHN(smp); |
| 1364 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
| 1365 | struct http_txn *txn; |
| 1366 | struct buffer bearer_val = {}; |
| 1367 | |
| 1368 | if (!htx) |
| 1369 | return 0; |
| 1370 | |
| 1371 | if (args->type == ARGT_STR) { |
| 1372 | struct http_hdr_ctx ctx; |
| 1373 | struct ist hdr_name = ist2(args->data.str.area, args->data.str.data); |
| 1374 | |
| 1375 | ctx.blk = NULL; |
| 1376 | if (http_find_header(htx, hdr_name, &ctx, 0)) { |
Remi Tricot-Le Breton | 7da35bf | 2021-10-29 15:25:19 +0200 | [diff] [blame] | 1377 | struct ist type = istsplit(&ctx.value, ' '); |
| 1378 | |
| 1379 | /* There must be "at least" one space character between |
| 1380 | * the scheme and the following value so ctx.value might |
| 1381 | * still have leading spaces here (see RFC7235). |
| 1382 | */ |
| 1383 | ctx.value = istskip(ctx.value, ' '); |
| 1384 | |
| 1385 | if (isteqi(type, ist("Bearer")) && istlen(ctx.value)) |
| 1386 | chunk_initlen(&bearer_val, istptr(ctx.value), 0, istlen(ctx.value)); |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | else { |
| 1390 | txn = smp->strm->txn; |
| 1391 | if (!get_http_auth(smp, htx) || txn->auth.method != HTTP_AUTH_BEARER) |
| 1392 | return 0; |
| 1393 | |
| 1394 | bearer_val = txn->auth.method_data; |
| 1395 | } |
| 1396 | |
| 1397 | smp->data.type = SMP_T_STR; |
| 1398 | smp->data.u.str = bearer_val; |
| 1399 | smp->flags = SMP_F_CONST; |
| 1400 | return 1; |
| 1401 | } |
| 1402 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1403 | /* Accepts exactly 1 argument of type userlist */ |
| 1404 | static int smp_fetch_http_auth(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1405 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1406 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1407 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1408 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1409 | if (args->type != ARGT_USR) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1410 | return 0; |
| 1411 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1412 | if (!htx) |
| 1413 | return 0; |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 1414 | if (!get_http_auth(smp, htx) || smp->strm->txn->auth.method != HTTP_AUTH_BASIC) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1415 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1416 | |
| 1417 | smp->data.type = SMP_T_BOOL; |
| 1418 | 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] | 1419 | smp->strm->txn->auth.pass); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1420 | return 1; |
| 1421 | } |
| 1422 | |
| 1423 | /* Accepts exactly 1 argument of type userlist */ |
| 1424 | static int smp_fetch_http_auth_grp(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1425 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1426 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1427 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1428 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1429 | if (args->type != ARGT_USR) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1430 | return 0; |
| 1431 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1432 | if (!htx) |
| 1433 | return 0; |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 1434 | if (!get_http_auth(smp, htx) || smp->strm->txn->auth.method != HTTP_AUTH_BASIC) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1435 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1436 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1437 | /* if the user does not belong to the userlist or has a wrong password, |
| 1438 | * report that it unconditionally does not match. Otherwise we return |
| 1439 | * a string containing the username. |
| 1440 | */ |
| 1441 | if (!check_user(args->data.usr, smp->strm->txn->auth.user, |
| 1442 | smp->strm->txn->auth.pass)) |
| 1443 | return 0; |
| 1444 | |
| 1445 | /* pat_match_auth() will need the user list */ |
| 1446 | smp->ctx.a[0] = args->data.usr; |
| 1447 | |
| 1448 | smp->data.type = SMP_T_STR; |
| 1449 | smp->flags = SMP_F_CONST; |
| 1450 | smp->data.u.str.area = smp->strm->txn->auth.user; |
| 1451 | smp->data.u.str.data = strlen(smp->strm->txn->auth.user); |
| 1452 | |
| 1453 | return 1; |
| 1454 | } |
| 1455 | |
| 1456 | /* Fetch a captured HTTP request header. The index is the position of |
| 1457 | * the "capture" option in the configuration file |
| 1458 | */ |
| 1459 | static int smp_fetch_capture_req_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1460 | { |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1461 | struct proxy *fe; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1462 | int idx; |
| 1463 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1464 | if (args->type != ARGT_SINT) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1465 | return 0; |
| 1466 | |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1467 | if (!smp->strm) |
| 1468 | return 0; |
| 1469 | |
| 1470 | fe = strm_fe(smp->strm); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1471 | idx = args->data.sint; |
| 1472 | |
| 1473 | if (idx > (fe->nb_req_cap - 1) || smp->strm->req_cap == NULL || smp->strm->req_cap[idx] == NULL) |
| 1474 | return 0; |
| 1475 | |
| 1476 | smp->data.type = SMP_T_STR; |
| 1477 | smp->flags |= SMP_F_CONST; |
| 1478 | smp->data.u.str.area = smp->strm->req_cap[idx]; |
| 1479 | smp->data.u.str.data = strlen(smp->strm->req_cap[idx]); |
| 1480 | |
| 1481 | return 1; |
| 1482 | } |
| 1483 | |
| 1484 | /* Fetch a captured HTTP response header. The index is the position of |
| 1485 | * the "capture" option in the configuration file |
| 1486 | */ |
| 1487 | static int smp_fetch_capture_res_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1488 | { |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1489 | struct proxy *fe; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1490 | int idx; |
| 1491 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1492 | if (args->type != ARGT_SINT) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1493 | return 0; |
| 1494 | |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1495 | if (!smp->strm) |
| 1496 | return 0; |
| 1497 | |
| 1498 | fe = strm_fe(smp->strm); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1499 | idx = args->data.sint; |
| 1500 | |
| 1501 | if (idx > (fe->nb_rsp_cap - 1) || smp->strm->res_cap == NULL || smp->strm->res_cap[idx] == NULL) |
| 1502 | return 0; |
| 1503 | |
| 1504 | smp->data.type = SMP_T_STR; |
| 1505 | smp->flags |= SMP_F_CONST; |
| 1506 | smp->data.u.str.area = smp->strm->res_cap[idx]; |
| 1507 | smp->data.u.str.data = strlen(smp->strm->res_cap[idx]); |
| 1508 | |
| 1509 | return 1; |
| 1510 | } |
| 1511 | |
| 1512 | /* Extracts the METHOD in the HTTP request, the txn->uri should be filled before the call */ |
| 1513 | static int smp_fetch_capture_req_method(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1514 | { |
| 1515 | struct buffer *temp; |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1516 | struct http_txn *txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1517 | char *ptr; |
| 1518 | |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1519 | if (!smp->strm) |
| 1520 | return 0; |
| 1521 | |
| 1522 | txn = smp->strm->txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1523 | if (!txn || !txn->uri) |
| 1524 | return 0; |
| 1525 | |
| 1526 | ptr = txn->uri; |
| 1527 | |
| 1528 | while (*ptr != ' ' && *ptr != '\0') /* find first space */ |
| 1529 | ptr++; |
| 1530 | |
| 1531 | temp = get_trash_chunk(); |
| 1532 | temp->area = txn->uri; |
| 1533 | temp->data = ptr - txn->uri; |
| 1534 | smp->data.u.str = *temp; |
| 1535 | smp->data.type = SMP_T_STR; |
| 1536 | smp->flags = SMP_F_CONST; |
| 1537 | |
| 1538 | return 1; |
| 1539 | |
| 1540 | } |
| 1541 | |
| 1542 | /* Extracts the path in the HTTP request, the txn->uri should be filled before the call */ |
| 1543 | static int smp_fetch_capture_req_uri(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1544 | { |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1545 | struct http_txn *txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1546 | struct ist path; |
| 1547 | const char *ptr; |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1548 | struct http_uri_parser parser; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1549 | |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1550 | if (!smp->strm) |
| 1551 | return 0; |
| 1552 | |
| 1553 | txn = smp->strm->txn; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1554 | if (!txn || !txn->uri) |
| 1555 | return 0; |
| 1556 | |
| 1557 | ptr = txn->uri; |
| 1558 | |
| 1559 | while (*ptr != ' ' && *ptr != '\0') /* find first space */ |
| 1560 | ptr++; |
| 1561 | |
| 1562 | if (!*ptr) |
| 1563 | return 0; |
| 1564 | |
Christopher Faulet | 78337bb | 2018-11-15 14:35:18 +0100 | [diff] [blame] | 1565 | /* skip the first space and find space after URI */ |
| 1566 | path = ist2(++ptr, 0); |
| 1567 | while (*ptr != ' ' && *ptr != '\0') |
| 1568 | ptr++; |
| 1569 | path.len = ptr - path.ptr; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1570 | |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 1571 | parser = http_uri_parser_init(path); |
| 1572 | path = http_parse_path(&parser); |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 1573 | if (!isttest(path)) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1574 | return 0; |
| 1575 | |
| 1576 | smp->data.u.str.area = path.ptr; |
| 1577 | smp->data.u.str.data = path.len; |
| 1578 | smp->data.type = SMP_T_STR; |
| 1579 | smp->flags = SMP_F_CONST; |
| 1580 | |
| 1581 | return 1; |
| 1582 | } |
| 1583 | |
| 1584 | /* Retrieves the HTTP version from the request (either 1.0 or 1.1) and emits it |
| 1585 | * as a string (either "HTTP/1.0" or "HTTP/1.1"). |
| 1586 | */ |
| 1587 | static int smp_fetch_capture_req_ver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1588 | { |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1589 | struct http_txn *txn; |
| 1590 | |
| 1591 | if (!smp->strm) |
| 1592 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1593 | |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1594 | txn = smp->strm->txn; |
Christopher Faulet | 09f8836 | 2021-04-01 16:00:29 +0200 | [diff] [blame] | 1595 | if (!txn || txn->req.msg_state < HTTP_MSG_BODY) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1596 | return 0; |
| 1597 | |
| 1598 | if (txn->req.flags & HTTP_MSGF_VER_11) |
| 1599 | smp->data.u.str.area = "HTTP/1.1"; |
| 1600 | else |
| 1601 | smp->data.u.str.area = "HTTP/1.0"; |
| 1602 | |
| 1603 | smp->data.u.str.data = 8; |
| 1604 | smp->data.type = SMP_T_STR; |
| 1605 | smp->flags = SMP_F_CONST; |
| 1606 | return 1; |
| 1607 | |
| 1608 | } |
| 1609 | |
| 1610 | /* Retrieves the HTTP version from the response (either 1.0 or 1.1) and emits it |
| 1611 | * as a string (either "HTTP/1.0" or "HTTP/1.1"). |
| 1612 | */ |
| 1613 | static int smp_fetch_capture_res_ver(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1614 | { |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1615 | struct http_txn *txn; |
| 1616 | |
| 1617 | if (!smp->strm) |
| 1618 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1619 | |
Willy Tarreau | 0898c2d | 2020-04-29 11:44:54 +0200 | [diff] [blame] | 1620 | txn = smp->strm->txn; |
Christopher Faulet | 09f8836 | 2021-04-01 16:00:29 +0200 | [diff] [blame] | 1621 | if (!txn || txn->rsp.msg_state < HTTP_MSG_BODY) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1622 | return 0; |
| 1623 | |
| 1624 | if (txn->rsp.flags & HTTP_MSGF_VER_11) |
| 1625 | smp->data.u.str.area = "HTTP/1.1"; |
| 1626 | else |
| 1627 | smp->data.u.str.area = "HTTP/1.0"; |
| 1628 | |
| 1629 | smp->data.u.str.data = 8; |
| 1630 | smp->data.type = SMP_T_STR; |
| 1631 | smp->flags = SMP_F_CONST; |
| 1632 | return 1; |
| 1633 | |
| 1634 | } |
| 1635 | |
| 1636 | /* Iterate over all cookies present in a message. The context is stored in |
| 1637 | * smp->ctx.a[0] for the in-header position, smp->ctx.a[1] for the |
| 1638 | * end-of-header-value, and smp->ctx.a[2] for the hdr_ctx. Depending on |
| 1639 | * the direction, multiple cookies may be parsed on the same line or not. |
Maciej Zdeb | dea7c20 | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 1640 | * If provided, the searched cookie name is in args, in args->data.str. If |
| 1641 | * the input options indicate that no iterating is desired, then only last |
| 1642 | * value is fetched if any. If no cookie name is provided, the first cookie |
| 1643 | * value found is fetched. The returned sample is of type CSTR. Can be used |
| 1644 | * to parse cookies in other files. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1645 | */ |
| 1646 | static int smp_fetch_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1647 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1648 | /* possible keywords: req.cookie / cookie / cook, res.cookie / scook / set-cookie */ |
| 1649 | struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 1650 | struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 1651 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1652 | struct http_hdr_ctx *ctx = smp->ctx.a[2]; |
| 1653 | struct ist hdr; |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1654 | char *cook = NULL; |
| 1655 | size_t cook_l = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1656 | int found = 0; |
| 1657 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1658 | if (args->type == ARGT_STR) { |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1659 | cook = args->data.str.area; |
| 1660 | cook_l = args->data.str.data; |
| 1661 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1662 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1663 | if (!ctx) { |
| 1664 | /* first call */ |
| 1665 | ctx = &static_http_hdr_ctx; |
| 1666 | ctx->blk = NULL; |
| 1667 | smp->ctx.a[2] = ctx; |
| 1668 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1669 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1670 | if (!htx) |
| 1671 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1672 | |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 1673 | hdr = (!(check || (chn && chn->flags & CF_ISRESP)) ? ist("Cookie") : ist("Set-Cookie")); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1674 | |
Maciej Zdeb | dea7c20 | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 1675 | /* OK so basically here, either we want only one value or we want to |
| 1676 | * iterate over all of them and we fetch the next one. In this last case |
| 1677 | * SMP_OPT_ITERATE option is set. |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1678 | */ |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1679 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1680 | if (!(smp->flags & SMP_F_NOT_LAST)) { |
| 1681 | /* search for the header from the beginning, we must first initialize |
| 1682 | * the search parameters. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1683 | */ |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1684 | smp->ctx.a[0] = NULL; |
| 1685 | ctx->blk = NULL; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1686 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1687 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1688 | smp->flags |= SMP_F_VOL_HDR; |
| 1689 | while (1) { |
| 1690 | /* Note: smp->ctx.a[0] == NULL every time we need to fetch a new header */ |
| 1691 | if (!smp->ctx.a[0]) { |
| 1692 | if (!http_find_header(htx, hdr, ctx, 0)) |
| 1693 | goto out; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1694 | |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1695 | if (ctx->value.len < cook_l + 1) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1696 | continue; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1697 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1698 | smp->ctx.a[0] = ctx->value.ptr; |
| 1699 | smp->ctx.a[1] = smp->ctx.a[0] + ctx->value.len; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1700 | } |
| 1701 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1702 | smp->data.type = SMP_T_STR; |
| 1703 | smp->flags |= SMP_F_CONST; |
| 1704 | smp->ctx.a[0] = http_extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1], |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1705 | cook, cook_l, |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1706 | (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, |
| 1707 | &smp->data.u.str.area, |
| 1708 | &smp->data.u.str.data); |
| 1709 | if (smp->ctx.a[0]) { |
| 1710 | found = 1; |
Maciej Zdeb | dea7c20 | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 1711 | if (smp->opt & SMP_OPT_ITERATE) { |
| 1712 | /* iterate on cookie value */ |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1713 | smp->flags |= SMP_F_NOT_LAST; |
| 1714 | return 1; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1715 | } |
Maciej Zdeb | dea7c20 | 2020-11-13 09:38:06 +0000 | [diff] [blame] | 1716 | if (args->data.str.data == 0) { |
| 1717 | /* No cookie name, first occurrence returned */ |
| 1718 | break; |
| 1719 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1720 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1721 | /* if we're looking for last occurrence, let's loop */ |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1722 | } |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1723 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1724 | /* all cookie headers and values were scanned. If we're looking for the |
| 1725 | * last occurrence, we may return it now. |
| 1726 | */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1727 | out: |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1728 | smp->flags &= ~SMP_F_NOT_LAST; |
| 1729 | return found; |
| 1730 | } |
| 1731 | |
Christopher Faulet | c1f40dd | 2019-05-16 10:07:30 +0200 | [diff] [blame] | 1732 | /* Same than smp_fetch_cookie() but only relies on the sample direction to |
| 1733 | * choose the right channel. So instead of duplicating the code, we just change |
| 1734 | * the keyword and then fallback on smp_fetch_cookie(). |
| 1735 | */ |
| 1736 | static int smp_fetch_chn_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1737 | { |
| 1738 | kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.cook" : "res.cook"); |
| 1739 | return smp_fetch_cookie(args, smp, kw, private); |
| 1740 | } |
| 1741 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1742 | /* Iterate over all cookies present in a request to count how many occurrences |
| 1743 | * match the name in args and args->data.str.len. If <multi> is non-null, then |
| 1744 | * multiple cookies may be parsed on the same line. The returned sample is of |
| 1745 | * type UINT. Accepts exactly 1 argument of type string. |
| 1746 | */ |
| 1747 | static int smp_fetch_cookie_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1748 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1749 | /* possible keywords: req.cook_cnt / cook_cnt, res.cook_cnt / scook_cnt */ |
| 1750 | struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp)); |
Christopher Faulet | f98e626 | 2020-05-06 09:42:04 +0200 | [diff] [blame] | 1751 | struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL); |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 1752 | struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1753 | struct http_hdr_ctx ctx; |
| 1754 | struct ist hdr; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1755 | char *val_beg, *val_end; |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1756 | char *cook = NULL; |
| 1757 | size_t cook_l = 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1758 | int cnt; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1759 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1760 | if (args->type == ARGT_STR){ |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1761 | cook = args->data.str.area; |
| 1762 | cook_l = args->data.str.data; |
| 1763 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1764 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1765 | if (!htx) |
| 1766 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1767 | |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 1768 | hdr = (!(check || (chn && chn->flags & CF_ISRESP)) ? ist("Cookie") : ist("Set-Cookie")); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1769 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1770 | val_end = val_beg = NULL; |
| 1771 | ctx.blk = NULL; |
| 1772 | cnt = 0; |
| 1773 | while (1) { |
| 1774 | /* Note: val_beg == NULL every time we need to fetch a new header */ |
| 1775 | if (!val_beg) { |
| 1776 | if (!http_find_header(htx, hdr, &ctx, 0)) |
| 1777 | break; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1778 | |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1779 | if (ctx.value.len < cook_l + 1) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1780 | continue; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1781 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1782 | val_beg = ctx.value.ptr; |
| 1783 | val_end = val_beg + ctx.value.len; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1784 | } |
| 1785 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1786 | smp->data.type = SMP_T_STR; |
| 1787 | smp->flags |= SMP_F_CONST; |
| 1788 | while ((val_beg = http_extract_cookie_value(val_beg, val_end, |
Christopher Faulet | 97fc8da | 2020-11-13 13:41:04 +0100 | [diff] [blame] | 1789 | cook, cook_l, |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1790 | (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, |
| 1791 | &smp->data.u.str.area, |
| 1792 | &smp->data.u.str.data))) { |
| 1793 | cnt++; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | smp->data.type = SMP_T_SINT; |
| 1798 | smp->data.u.sint = cnt; |
| 1799 | smp->flags |= SMP_F_VOL_HDR; |
| 1800 | return 1; |
| 1801 | } |
| 1802 | |
| 1803 | /* Fetch an cookie's integer value. The integer value is returned. It |
| 1804 | * takes a mandatory argument of type string. It relies on smp_fetch_cookie(). |
| 1805 | */ |
| 1806 | static int smp_fetch_cookie_val(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1807 | { |
| 1808 | int ret = smp_fetch_cookie(args, smp, kw, private); |
| 1809 | |
| 1810 | if (ret > 0) { |
| 1811 | smp->data.type = SMP_T_SINT; |
| 1812 | smp->data.u.sint = strl2ic(smp->data.u.str.area, |
| 1813 | smp->data.u.str.data); |
| 1814 | } |
| 1815 | |
| 1816 | return ret; |
| 1817 | } |
| 1818 | |
| 1819 | /************************************************************************/ |
| 1820 | /* The code below is dedicated to sample fetches */ |
| 1821 | /************************************************************************/ |
| 1822 | |
| 1823 | /* This scans a URL-encoded query string. It takes an optionally wrapping |
Ilya Shipitsin | 46a030c | 2020-07-05 16:36:08 +0500 | [diff] [blame] | 1824 | * string whose first contiguous chunk has its beginning in ctx->a[0] and end |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1825 | * in ctx->a[1], and the optional second part in (ctx->a[2]..ctx->a[3]). The |
| 1826 | * pointers are updated for next iteration before leaving. |
| 1827 | */ |
| 1828 | 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) |
| 1829 | { |
| 1830 | const char *vstart, *vend; |
| 1831 | struct buffer *temp; |
| 1832 | const char **chunks = (const char **)smp->ctx.a; |
| 1833 | |
| 1834 | if (!http_find_next_url_param(chunks, name, name_len, |
| 1835 | &vstart, &vend, delim)) |
| 1836 | return 0; |
| 1837 | |
| 1838 | /* Create sample. If the value is contiguous, return the pointer as CONST, |
| 1839 | * if the value is wrapped, copy-it in a buffer. |
| 1840 | */ |
| 1841 | smp->data.type = SMP_T_STR; |
| 1842 | if (chunks[2] && |
| 1843 | vstart >= chunks[0] && vstart <= chunks[1] && |
| 1844 | vend >= chunks[2] && vend <= chunks[3]) { |
| 1845 | /* Wrapped case. */ |
| 1846 | temp = get_trash_chunk(); |
| 1847 | memcpy(temp->area, vstart, chunks[1] - vstart); |
| 1848 | memcpy(temp->area + ( chunks[1] - vstart ), chunks[2], |
| 1849 | vend - chunks[2]); |
| 1850 | smp->data.u.str.area = temp->area; |
| 1851 | smp->data.u.str.data = ( chunks[1] - vstart ) + ( vend - chunks[2] ); |
| 1852 | } else { |
| 1853 | /* Contiguous case. */ |
| 1854 | smp->data.u.str.area = (char *)vstart; |
| 1855 | smp->data.u.str.data = vend - vstart; |
| 1856 | smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; |
| 1857 | } |
| 1858 | |
| 1859 | /* Update context, check wrapping. */ |
| 1860 | chunks[0] = vend; |
| 1861 | if (chunks[2] && vend >= chunks[2] && vend <= chunks[3]) { |
| 1862 | chunks[1] = chunks[3]; |
| 1863 | chunks[2] = NULL; |
| 1864 | } |
| 1865 | |
| 1866 | if (chunks[0] < chunks[1]) |
| 1867 | smp->flags |= SMP_F_NOT_LAST; |
| 1868 | |
| 1869 | return 1; |
| 1870 | } |
| 1871 | |
| 1872 | /* This function iterates over each parameter of the query string. It uses |
| 1873 | * ctx->a[0] and ctx->a[1] to store the beginning and end of the current |
| 1874 | * parameter. Since it uses smp_fetch_param(), ctx->a[2..3] are both NULL. |
| 1875 | * An optional parameter name is passed in args[0], otherwise any parameter is |
| 1876 | * considered. It supports an optional delimiter argument for the beginning of |
| 1877 | * the string in args[1], which defaults to "?". |
| 1878 | */ |
| 1879 | static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1880 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 1881 | struct channel *chn = SMP_REQ_CHN(smp); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1882 | char delim = '?'; |
| 1883 | const char *name; |
| 1884 | int name_len; |
| 1885 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1886 | if ((args[0].type && args[0].type != ARGT_STR) || |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1887 | (args[1].type && args[1].type != ARGT_STR)) |
| 1888 | return 0; |
| 1889 | |
| 1890 | name = ""; |
| 1891 | name_len = 0; |
| 1892 | if (args->type == ARGT_STR) { |
| 1893 | name = args->data.str.area; |
| 1894 | name_len = args->data.str.data; |
| 1895 | } |
| 1896 | |
| 1897 | if (args[1].type) |
| 1898 | delim = *args[1].data.str.area; |
| 1899 | |
| 1900 | if (!smp->ctx.a[0]) { // first call, find the query string |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 1901 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1902 | struct htx_sl *sl; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1903 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1904 | if (!htx) |
| 1905 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1906 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1907 | sl = http_get_stline(htx); |
| 1908 | smp->ctx.a[0] = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), delim); |
| 1909 | if (!smp->ctx.a[0]) |
| 1910 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1911 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1912 | smp->ctx.a[1] = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1913 | |
| 1914 | /* Assume that the context is filled with NULL pointer |
| 1915 | * before the first call. |
| 1916 | * smp->ctx.a[2] = NULL; |
| 1917 | * smp->ctx.a[3] = NULL; |
| 1918 | */ |
| 1919 | } |
| 1920 | |
| 1921 | return smp_fetch_param(delim, name, name_len, args, smp, kw, private); |
| 1922 | } |
| 1923 | |
| 1924 | /* This function iterates over each parameter of the body. This requires |
| 1925 | * that the body has been waited for using http-buffer-request. It uses |
| 1926 | * ctx->a[0] and ctx->a[1] to store the beginning and end of the first |
Ilya Shipitsin | 46a030c | 2020-07-05 16:36:08 +0500 | [diff] [blame] | 1927 | * contiguous part of the body, and optionally ctx->a[2..3] to reference the |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1928 | * optional second part if the body wraps at the end of the buffer. An optional |
| 1929 | * parameter name is passed in args[0], otherwise any parameter is considered. |
| 1930 | */ |
| 1931 | static int smp_fetch_body_param(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); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1934 | const char *name; |
| 1935 | int name_len; |
| 1936 | |
Christopher Faulet | 623af93 | 2021-01-29 11:22:15 +0100 | [diff] [blame] | 1937 | if (args[0].type && args[0].type != ARGT_STR) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1938 | return 0; |
| 1939 | |
| 1940 | name = ""; |
| 1941 | name_len = 0; |
| 1942 | if (args[0].type == ARGT_STR) { |
| 1943 | name = args[0].data.str.area; |
| 1944 | name_len = args[0].data.str.data; |
| 1945 | } |
| 1946 | |
| 1947 | if (!smp->ctx.a[0]) { // first call, find the query string |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 1948 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1949 | struct buffer *temp; |
| 1950 | int32_t pos; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1951 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1952 | if (!htx) |
| 1953 | return 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1954 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1955 | temp = get_trash_chunk(); |
| 1956 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 1957 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 1958 | enum htx_blk_type type = htx_get_blk_type(blk); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1959 | |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 1960 | if (type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1961 | break; |
| 1962 | if (type == HTX_BLK_DATA) { |
Christopher Faulet | 53a899b | 2019-10-08 16:38:42 +0200 | [diff] [blame] | 1963 | if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0)) |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1964 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1965 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1966 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1967 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1968 | smp->ctx.a[0] = temp->area; |
| 1969 | smp->ctx.a[1] = temp->area + temp->data; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1970 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 1971 | /* Assume that the context is filled with NULL pointer |
| 1972 | * before the first call. |
| 1973 | * smp->ctx.a[2] = NULL; |
| 1974 | * smp->ctx.a[3] = NULL; |
| 1975 | */ |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 1976 | |
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 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1979 | return smp_fetch_param('&', name, name_len, args, smp, kw, private); |
| 1980 | } |
| 1981 | |
| 1982 | /* Return the signed integer value for the specified url parameter (see url_param |
| 1983 | * above). |
| 1984 | */ |
| 1985 | static int smp_fetch_url_param_val(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1986 | { |
| 1987 | int ret = smp_fetch_url_param(args, smp, kw, private); |
| 1988 | |
| 1989 | if (ret > 0) { |
| 1990 | smp->data.type = SMP_T_SINT; |
| 1991 | smp->data.u.sint = strl2ic(smp->data.u.str.area, |
| 1992 | smp->data.u.str.data); |
| 1993 | } |
| 1994 | |
| 1995 | return ret; |
| 1996 | } |
| 1997 | |
| 1998 | /* This produces a 32-bit hash of the concatenation of the first occurrence of |
| 1999 | * the Host header followed by the path component if it begins with a slash ('/'). |
| 2000 | * This means that '*' will not be added, resulting in exactly the first Host |
| 2001 | * entry. If no Host header is found, then the path is used. The resulting value |
| 2002 | * is hashed using the url hash followed by a full avalanche hash and provides a |
| 2003 | * 32-bit integer value. This fetch is useful for tracking per-URL activity on |
| 2004 | * high-traffic sites without having to store whole paths. |
| 2005 | * this differs from the base32 functions in that it includes the url parameters |
| 2006 | * as well as the path |
| 2007 | */ |
| 2008 | static int smp_fetch_url32(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2009 | { |
Christopher Faulet | 89dc499 | 2019-04-17 12:02:59 +0200 | [diff] [blame] | 2010 | struct channel *chn = SMP_REQ_CHN(smp); |
Christopher Faulet | 778f5ed | 2020-04-29 15:51:55 +0200 | [diff] [blame] | 2011 | struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 2012 | struct http_hdr_ctx ctx; |
| 2013 | struct htx_sl *sl; |
| 2014 | struct ist path; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2015 | unsigned int hash = 0; |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 2016 | struct http_uri_parser parser; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2017 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 2018 | if (!htx) |
| 2019 | return 0; |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2020 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 2021 | ctx.blk = NULL; |
| 2022 | if (http_find_header(htx, ist("Host"), &ctx, 1)) { |
| 2023 | /* OK we have the header value in ctx.value */ |
| 2024 | while (ctx.value.len--) |
| 2025 | hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2026 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2027 | |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 2028 | /* now retrieve the path */ |
| 2029 | sl = http_get_stline(htx); |
Amaury Denoyelle | c453f95 | 2021-07-06 11:40:12 +0200 | [diff] [blame] | 2030 | parser = http_uri_parser_init(htx_sl_req_uri(sl)); |
| 2031 | path = http_parse_path(&parser); |
Christopher Faulet | 6d1dd46 | 2019-07-15 14:36:03 +0200 | [diff] [blame] | 2032 | if (path.len && *(path.ptr) == '/') { |
| 2033 | while (path.len--) |
| 2034 | hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2035 | } |
Christopher Faulet | 311c7ea | 2018-10-24 21:41:55 +0200 | [diff] [blame] | 2036 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2037 | hash = full_hash(hash); |
| 2038 | |
| 2039 | smp->data.type = SMP_T_SINT; |
| 2040 | smp->data.u.sint = hash; |
| 2041 | smp->flags = SMP_F_VOL_1ST; |
| 2042 | return 1; |
| 2043 | } |
| 2044 | |
| 2045 | /* This concatenates the source address with the 32-bit hash of the Host and |
| 2046 | * URL as returned by smp_fetch_base32(). The idea is to have per-source and |
| 2047 | * per-url counters. The result is a binary block from 8 to 20 bytes depending |
| 2048 | * on the source address length. The URL hash is stored before the address so |
| 2049 | * that in environments where IPv6 is insignificant, truncating the output to |
| 2050 | * 8 bytes would still work. |
| 2051 | */ |
| 2052 | static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2053 | { |
Willy Tarreau | d68ff01 | 2022-05-27 08:57:21 +0200 | [diff] [blame] | 2054 | const struct sockaddr_storage *src = (smp->strm ? sc_src(smp->strm->scf) : NULL); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2055 | struct buffer *temp; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2056 | |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 2057 | if (!src) |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2058 | return 0; |
| 2059 | |
| 2060 | if (!smp_fetch_url32(args, smp, kw, private)) |
| 2061 | return 0; |
| 2062 | |
| 2063 | temp = get_trash_chunk(); |
| 2064 | *(unsigned int *) temp->area = htonl(smp->data.u.sint); |
| 2065 | temp->data += sizeof(unsigned int); |
| 2066 | |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 2067 | switch (src->ss_family) { |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2068 | case AF_INET: |
| 2069 | memcpy(temp->area + temp->data, |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 2070 | &((struct sockaddr_in *)src)->sin_addr, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2071 | 4); |
| 2072 | temp->data += 4; |
| 2073 | break; |
| 2074 | case AF_INET6: |
| 2075 | memcpy(temp->area + temp->data, |
Christopher Faulet | 6fc817a | 2021-10-25 07:48:27 +0200 | [diff] [blame] | 2076 | &((struct sockaddr_in6 *)src)->sin6_addr, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2077 | 16); |
| 2078 | temp->data += 16; |
| 2079 | break; |
| 2080 | default: |
| 2081 | return 0; |
| 2082 | } |
| 2083 | |
| 2084 | smp->data.u.str = *temp; |
| 2085 | smp->data.type = SMP_T_BIN; |
| 2086 | return 1; |
| 2087 | } |
| 2088 | |
| 2089 | /************************************************************************/ |
| 2090 | /* Other utility functions */ |
| 2091 | /************************************************************************/ |
| 2092 | |
| 2093 | /* This function is used to validate the arguments passed to any "hdr" fetch |
| 2094 | * keyword. These keywords support an optional positive or negative occurrence |
| 2095 | * number. We must ensure that the number is greater than -MAX_HDR_HISTORY. It |
| 2096 | * is assumed that the types are already the correct ones. Returns 0 on error, |
| 2097 | * non-zero if OK. If <err> is not NULL, it will be filled with a pointer to an |
| 2098 | * error message in case of error, that the caller is responsible for freeing. |
| 2099 | * The initial location must either be freeable or NULL. |
| 2100 | * Note: this function's pointer is checked from Lua. |
| 2101 | */ |
| 2102 | int val_hdr(struct arg *arg, char **err_msg) |
| 2103 | { |
| 2104 | if (arg && arg[1].type == ARGT_SINT && arg[1].data.sint < -MAX_HDR_HISTORY) { |
| 2105 | memprintf(err_msg, "header occurrence must be >= %d", -MAX_HDR_HISTORY); |
| 2106 | return 0; |
| 2107 | } |
| 2108 | return 1; |
| 2109 | } |
| 2110 | |
| 2111 | /************************************************************************/ |
| 2112 | /* All supported sample fetch keywords must be declared here. */ |
| 2113 | /************************************************************************/ |
| 2114 | |
| 2115 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 2116 | static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { |
| 2117 | { "base", smp_fetch_base, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2118 | { "base32", smp_fetch_base32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2119 | { "base32+src", smp_fetch_base32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
Yves Lafon | b4d3708 | 2021-02-11 11:01:28 +0100 | [diff] [blame] | 2120 | { "baseq", smp_fetch_base, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2121 | |
| 2122 | /* capture are allocated and are permanent in the stream */ |
| 2123 | { "capture.req.hdr", smp_fetch_capture_req_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2124 | |
| 2125 | /* retrieve these captures from the HTTP logs */ |
| 2126 | { "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2127 | { "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2128 | { "capture.req.ver", smp_fetch_capture_req_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2129 | |
| 2130 | { "capture.res.hdr", smp_fetch_capture_res_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRSHP }, |
| 2131 | { "capture.res.ver", smp_fetch_capture_res_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP }, |
| 2132 | |
| 2133 | /* cookie is valid in both directions (eg: for "stick ...") but cook* |
| 2134 | * are only here to match the ACL's name, are request-only and are used |
| 2135 | * for ACL compatibility only. |
| 2136 | */ |
| 2137 | { "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] | 2138 | { "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] | 2139 | { "cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2140 | { "cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2141 | |
| 2142 | /* hdr is valid in both directions (eg: for "stick ...") but hdr_* are |
| 2143 | * only here to match the ACL's name, are request-only and are used for |
| 2144 | * ACL compatibility only. |
| 2145 | */ |
Christopher Faulet | c1f40dd | 2019-05-16 10:07:30 +0200 | [diff] [blame] | 2146 | { "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] | 2147 | { "hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2148 | { "hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV }, |
| 2149 | { "hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2150 | |
Christopher Faulet | a406356 | 2019-08-02 11:51:37 +0200 | [diff] [blame] | 2151 | { "http_auth_type", smp_fetch_http_auth_type, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2152 | { "http_auth_user", smp_fetch_http_auth_user, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2153 | { "http_auth_pass", smp_fetch_http_auth_pass, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
Remi Tricot-Le Breton | f5dd337 | 2021-10-01 15:36:53 +0200 | [diff] [blame] | 2154 | { "http_auth_bearer", smp_fetch_http_auth_bearer, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2155 | { "http_auth", smp_fetch_http_auth, ARG1(1,USR), NULL, SMP_T_BOOL, SMP_USE_HRQHV }, |
| 2156 | { "http_auth_group", smp_fetch_http_auth_grp, ARG1(1,USR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2157 | { "http_first_req", smp_fetch_http_first_req, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP }, |
| 2158 | { "method", smp_fetch_meth, 0, NULL, SMP_T_METH, SMP_USE_HRQHP }, |
| 2159 | { "path", smp_fetch_path, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
Christopher Faulet | e720c32 | 2020-09-02 17:25:18 +0200 | [diff] [blame] | 2160 | { "pathq", smp_fetch_path, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2161 | { "query", smp_fetch_query, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2162 | |
| 2163 | /* HTTP protocol on the request path */ |
| 2164 | { "req.proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP }, |
| 2165 | { "req_proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP }, |
| 2166 | |
| 2167 | /* HTTP version on the request path */ |
| 2168 | { "req.ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2169 | { "req_ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2170 | |
| 2171 | { "req.body", smp_fetch_body, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2172 | { "req.body_len", smp_fetch_body_len, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2173 | { "req.body_size", smp_fetch_body_size, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2174 | { "req.body_param", smp_fetch_body_param, ARG1(0,STR), NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2175 | |
| 2176 | { "req.hdrs", smp_fetch_hdrs, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2177 | { "req.hdrs_bin", smp_fetch_hdrs_bin, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2178 | |
| 2179 | /* HTTP version on the response path */ |
| 2180 | { "res.ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2181 | { "resp_ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2182 | |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 2183 | { "res.body", smp_fetch_body, 0, NULL, SMP_T_BIN, SMP_USE_HRSHV }, |
| 2184 | { "res.body_len", smp_fetch_body_len, 0, NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2185 | { "res.body_size", smp_fetch_body_size, 0, NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2186 | |
| 2187 | { "res.hdrs", smp_fetch_hdrs, 0, NULL, SMP_T_BIN, SMP_USE_HRSHV }, |
| 2188 | { "res.hdrs_bin", smp_fetch_hdrs_bin, 0, NULL, SMP_T_BIN, SMP_USE_HRSHV }, |
| 2189 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2190 | /* explicit req.{cook,hdr} are used to force the fetch direction to be request-only */ |
| 2191 | { "req.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2192 | { "req.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2193 | { "req.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2194 | |
| 2195 | { "req.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV }, |
| 2196 | { "req.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2197 | { "req.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV }, |
| 2198 | { "req.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2199 | { "req.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV }, |
| 2200 | { "req.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2201 | { "req.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2202 | |
| 2203 | /* explicit req.{cook,hdr} are used to force the fetch direction to be response-only */ |
| 2204 | { "res.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2205 | { "res.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2206 | { "res.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2207 | |
| 2208 | { "res.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV }, |
| 2209 | { "res.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2210 | { "res.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV }, |
| 2211 | { "res.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2212 | { "res.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV }, |
| 2213 | { "res.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2214 | { "res.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2215 | |
| 2216 | /* scook is valid only on the response and is used for ACL compatibility */ |
| 2217 | { "scook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, |
| 2218 | { "scook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2219 | { "scook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2220 | |
| 2221 | /* shdr is valid only on the response and is used for ACL compatibility */ |
| 2222 | { "shdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV }, |
| 2223 | { "shdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2224 | { "shdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV }, |
| 2225 | { "shdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV }, |
| 2226 | |
| 2227 | { "status", smp_fetch_stcode, 0, NULL, SMP_T_SINT, SMP_USE_HRSHP }, |
| 2228 | { "unique-id", smp_fetch_uniqueid, 0, NULL, SMP_T_STR, SMP_SRC_L4SRV }, |
| 2229 | { "url", smp_fetch_url, 0, NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2230 | { "url32", smp_fetch_url32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2231 | { "url32+src", smp_fetch_url32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV }, |
| 2232 | { "url_ip", smp_fetch_url_ip, 0, NULL, SMP_T_IPV4, SMP_USE_HRQHV }, |
| 2233 | { "url_port", smp_fetch_url_port, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
| 2234 | { "url_param", smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2235 | { "urlp" , smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV }, |
| 2236 | { "urlp_val", smp_fetch_url_param_val, ARG2(0,STR,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV }, |
Christopher Faulet | 16032ab | 2020-04-30 11:30:00 +0200 | [diff] [blame] | 2237 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2238 | { /* END */ }, |
| 2239 | }}; |
| 2240 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 2241 | INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2242 | |
| 2243 | /* |
| 2244 | * Local variables: |
| 2245 | * c-indent-level: 8 |
| 2246 | * c-basic-offset: 8 |
| 2247 | * End: |
| 2248 | */ |