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