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