Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HTTP actions |
| 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 | dcc048a | 2020-06-04 19:11:43 +0200 | [diff] [blame] | 19 | #include <haproxy/acl.h> |
Willy Tarreau | 122eba9 | 2020-06-04 10:15:32 +0200 | [diff] [blame] | 20 | #include <haproxy/action.h> |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 21 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 22 | #include <haproxy/arg.h> |
| 23 | #include <haproxy/capture-t.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 24 | #include <haproxy/cfgparse.h> |
Willy Tarreau | c13ed53 | 2020-06-02 10:22:45 +0200 | [diff] [blame] | 25 | #include <haproxy/chunk.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 26 | #include <haproxy/global.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 27 | #include <haproxy/http.h> |
Willy Tarreau | c2b1ff0 | 2020-06-04 21:21:03 +0200 | [diff] [blame] | 28 | #include <haproxy/http_ana.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 29 | #include <haproxy/http_htx.h> |
Willy Tarreau | c761f84 | 2020-06-04 11:40:28 +0200 | [diff] [blame] | 30 | #include <haproxy/http_rules.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 31 | #include <haproxy/log.h> |
Willy Tarreau | 225a90a | 2020-06-04 15:06:28 +0200 | [diff] [blame] | 32 | #include <haproxy/pattern.h> |
Willy Tarreau | d0ef439 | 2020-06-02 09:38:52 +0200 | [diff] [blame] | 33 | #include <haproxy/pool.h> |
Willy Tarreau | 7cd8b6e | 2020-06-02 17:32:26 +0200 | [diff] [blame] | 34 | #include <haproxy/regex.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 35 | #include <haproxy/sample.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 36 | #include <haproxy/stream_interface.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 37 | #include <haproxy/tools.h> |
Willy Tarreau | 8c42b8a | 2020-06-04 19:27:34 +0200 | [diff] [blame] | 38 | #include <haproxy/uri_auth-t.h> |
Tim Duesterhus | d2bedcc | 2021-04-15 21:45:57 +0200 | [diff] [blame] | 39 | #include <haproxy/uri_normalizer.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 | |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 43 | /* Release memory allocated by most of HTTP actions. Concretly, it releases |
| 44 | * <arg.http>. |
| 45 | */ |
| 46 | static void release_http_action(struct act_rule *rule) |
| 47 | { |
| 48 | struct logformat_node *lf, *lfb; |
| 49 | |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 50 | istfree(&rule->arg.http.str); |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 51 | if (rule->arg.http.re) |
| 52 | regex_free(rule->arg.http.re); |
| 53 | list_for_each_entry_safe(lf, lfb, &rule->arg.http.fmt, list) { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 54 | LIST_DELETE(&lf->list); |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 55 | release_sample_expr(lf->expr); |
| 56 | free(lf->arg); |
| 57 | free(lf); |
| 58 | } |
| 59 | } |
| 60 | |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 61 | /* Release memory allocated by HTTP actions relying on an http reply. Concretly, |
| 62 | * it releases <.arg.http_reply> |
| 63 | */ |
| 64 | static void release_act_http_reply(struct act_rule *rule) |
| 65 | { |
| 66 | release_http_reply(rule->arg.http_reply); |
| 67 | rule->arg.http_reply = NULL; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /* Check function for HTTP actions relying on an http reply. The function |
| 72 | * returns 1 in success case, otherwise, it returns 0 and err is filled. |
| 73 | */ |
| 74 | static int check_act_http_reply(struct act_rule *rule, struct proxy *px, char **err) |
| 75 | { |
| 76 | struct http_reply *reply = rule->arg.http_reply; |
| 77 | |
| 78 | if (!http_check_http_reply(reply, px, err)) { |
| 79 | release_act_http_reply(rule); |
| 80 | return 0; |
| 81 | } |
| 82 | return 1; |
| 83 | } |
| 84 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 85 | |
| 86 | /* This function executes one of the set-{method,path,query,uri} actions. It |
| 87 | * builds a string in the trash from the specified format string. It finds |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 88 | * the action to be performed in <.action>, previously filled by function |
Ilya Shipitsin | c02a23f | 2020-05-06 00:53:22 +0500 | [diff] [blame] | 89 | * parse_set_req_line(). The replacement action is executed by the function |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 90 | * http_action_set_req_line(). On success, it returns ACT_RET_CONT. If an error |
| 91 | * occurs while soft rewrites are enabled, the action is canceled, but the rule |
| 92 | * processing continue. Otherwsize ACT_RET_ERR is returned. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 93 | */ |
| 94 | static enum act_return http_action_set_req_line(struct act_rule *rule, struct proxy *px, |
| 95 | struct session *sess, struct stream *s, int flags) |
| 96 | { |
| 97 | struct buffer *replace; |
Christopher Faulet | 1340376 | 2019-12-13 09:01:57 +0100 | [diff] [blame] | 98 | enum act_return ret = ACT_RET_CONT; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 99 | |
| 100 | replace = alloc_trash_chunk(); |
| 101 | if (!replace) |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 102 | goto fail_alloc; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 103 | |
| 104 | /* If we have to create a query string, prepare a '?'. */ |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 105 | if (rule->action == 2) // set-query |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 106 | replace->area[replace->data++] = '?'; |
| 107 | replace->data += build_logline(s, replace->area + replace->data, |
| 108 | replace->size - replace->data, |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 109 | &rule->arg.http.fmt); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 110 | |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 111 | if (http_req_replace_stline(rule->action, replace->area, replace->data, px, s) == -1) |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 112 | goto fail_rewrite; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 113 | |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 114 | leave: |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 115 | free_trash_chunk(replace); |
| 116 | return ret; |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 117 | |
| 118 | fail_alloc: |
| 119 | if (!(s->flags & SF_ERR_MASK)) |
| 120 | s->flags |= SF_ERR_RESOURCE; |
| 121 | ret = ACT_RET_ERR; |
| 122 | goto leave; |
| 123 | |
| 124 | fail_rewrite: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 125 | _HA_ATOMIC_INC(&sess->fe->fe_counters.failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 126 | if (s->flags & SF_BE_ASSIGNED) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 127 | _HA_ATOMIC_INC(&s->be->be_counters.failed_rewrites); |
William Lallemand | 36119de | 2021-03-08 15:26:48 +0100 | [diff] [blame] | 128 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 129 | _HA_ATOMIC_INC(&sess->listener->counters->failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 130 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 131 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 132 | |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 133 | if (!(s->txn->req.flags & HTTP_MSGF_SOFT_RW)) { |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 134 | ret = ACT_RET_ERR; |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 135 | if (!(s->flags & SF_ERR_MASK)) |
| 136 | s->flags |= SF_ERR_PRXCOND; |
| 137 | } |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 138 | goto leave; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* parse an http-request action among : |
| 142 | * set-method |
| 143 | * set-path |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 144 | * set-pathq |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 145 | * set-query |
| 146 | * set-uri |
| 147 | * |
| 148 | * All of them accept a single argument of type string representing a log-format. |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 149 | * The resulting rule makes use of <http.fmt> to store the log-format list head, |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 150 | * and <.action> to store the action type as an int (0=method, 1=path, 2=query, |
| 151 | * 3=uri). It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 152 | */ |
| 153 | static enum act_parse_ret parse_set_req_line(const char **args, int *orig_arg, struct proxy *px, |
| 154 | struct act_rule *rule, char **err) |
| 155 | { |
| 156 | int cur_arg = *orig_arg; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 157 | int cap = 0; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 158 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 159 | switch (args[0][4]) { |
| 160 | case 'm' : |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 161 | rule->action = 0; // set-method |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 162 | break; |
| 163 | case 'p' : |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 164 | if (args[0][8] == 'q') |
| 165 | rule->action = 4; // set-pathq |
| 166 | else |
| 167 | rule->action = 1; // set-path |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 168 | break; |
| 169 | case 'q' : |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 170 | rule->action = 2; // set-query |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 171 | break; |
| 172 | case 'u' : |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 173 | rule->action = 3; // set-uri |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 174 | break; |
| 175 | default: |
| 176 | memprintf(err, "internal error: unhandled action '%s'", args[0]); |
| 177 | return ACT_RET_PRS_ERR; |
| 178 | } |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 179 | rule->action_ptr = http_action_set_req_line; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 180 | rule->release_ptr = release_http_action; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 181 | |
| 182 | if (!*args[cur_arg] || |
| 183 | (*args[cur_arg + 1] && strcmp(args[cur_arg + 1], "if") != 0 && strcmp(args[cur_arg + 1], "unless") != 0)) { |
| 184 | memprintf(err, "expects exactly 1 argument <format>"); |
| 185 | return ACT_RET_PRS_ERR; |
| 186 | } |
| 187 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 188 | LIST_INIT(&rule->arg.http.fmt); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 189 | px->conf.args.ctx = ARGC_HRQ; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 190 | if (px->cap & PR_CAP_FE) |
| 191 | cap |= SMP_VAL_FE_HRQ_HDR; |
| 192 | if (px->cap & PR_CAP_BE) |
| 193 | cap |= SMP_VAL_BE_HRQ_HDR; |
| 194 | if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) { |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 195 | return ACT_RET_PRS_ERR; |
| 196 | } |
| 197 | |
| 198 | (*orig_arg)++; |
| 199 | return ACT_RET_PRS_OK; |
| 200 | } |
| 201 | |
Tim Duesterhus | d2bedcc | 2021-04-15 21:45:57 +0200 | [diff] [blame] | 202 | /* This function executes the http-request normalize-uri action. |
| 203 | * `rule->action` is expected to be a value from `enum act_normalize_uri`. |
| 204 | * |
| 205 | * On success, it returns ACT_RET_CONT. If an error |
| 206 | * occurs while soft rewrites are enabled, the action is canceled, but the rule |
| 207 | * processing continue. Otherwsize ACT_RET_ERR is returned. |
| 208 | */ |
| 209 | static enum act_return http_action_normalize_uri(struct act_rule *rule, struct proxy *px, |
| 210 | struct session *sess, struct stream *s, int flags) |
| 211 | { |
| 212 | enum act_return ret = ACT_RET_CONT; |
| 213 | struct htx *htx = htxbuf(&s->req.buf); |
| 214 | const struct ist uri = htx_sl_req_uri(http_get_stline(htx)); |
| 215 | struct buffer *replace = alloc_trash_chunk(); |
| 216 | enum uri_normalizer_err err = URI_NORMALIZER_ERR_INTERNAL_ERROR; |
| 217 | |
| 218 | if (!replace) |
| 219 | goto fail_alloc; |
| 220 | |
| 221 | switch ((enum act_normalize_uri) rule->action) { |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 222 | case ACT_NORMALIZE_URI_PATH_MERGE_SLASHES: { |
Tim Duesterhus | d371e99 | 2021-04-15 21:45:58 +0200 | [diff] [blame] | 223 | const struct ist path = http_get_path(uri); |
| 224 | struct ist newpath = ist2(replace->area, replace->size); |
| 225 | |
| 226 | if (!isttest(path)) |
| 227 | goto leave; |
| 228 | |
| 229 | err = uri_normalizer_path_merge_slashes(iststop(path, '?'), &newpath); |
| 230 | |
| 231 | if (err != URI_NORMALIZER_ERR_NONE) |
| 232 | break; |
| 233 | |
| 234 | if (!http_replace_req_path(htx, newpath, 0)) |
| 235 | goto fail_rewrite; |
| 236 | |
| 237 | break; |
| 238 | } |
Maximilian Mader | ff3bb8b | 2021-04-21 00:22:50 +0200 | [diff] [blame] | 239 | case ACT_NORMALIZE_URI_PATH_STRIP_DOT: { |
| 240 | const struct ist path = http_get_path(uri); |
| 241 | struct ist newpath = ist2(replace->area, replace->size); |
| 242 | |
| 243 | if (!isttest(path)) |
| 244 | goto leave; |
| 245 | |
| 246 | err = uri_normalizer_path_dot(iststop(path, '?'), &newpath); |
| 247 | |
| 248 | if (err != URI_NORMALIZER_ERR_NONE) |
| 249 | break; |
| 250 | |
| 251 | if (!http_replace_req_path(htx, newpath, 0)) |
| 252 | goto fail_rewrite; |
| 253 | |
| 254 | break; |
| 255 | } |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 256 | case ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT: |
| 257 | case ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL: { |
Tim Duesterhus | 9982fc2 | 2021-04-15 21:45:59 +0200 | [diff] [blame] | 258 | const struct ist path = http_get_path(uri); |
| 259 | struct ist newpath = ist2(replace->area, replace->size); |
| 260 | |
| 261 | if (!isttest(path)) |
| 262 | goto leave; |
| 263 | |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 264 | err = uri_normalizer_path_dotdot(iststop(path, '?'), rule->action == ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL, &newpath); |
Tim Duesterhus | 9982fc2 | 2021-04-15 21:45:59 +0200 | [diff] [blame] | 265 | |
| 266 | if (err != URI_NORMALIZER_ERR_NONE) |
| 267 | break; |
| 268 | |
| 269 | if (!http_replace_req_path(htx, newpath, 0)) |
| 270 | goto fail_rewrite; |
| 271 | |
| 272 | break; |
| 273 | } |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 274 | case ACT_NORMALIZE_URI_QUERY_SORT_BY_NAME: { |
Tim Duesterhus | d7b89be | 2021-04-15 21:46:01 +0200 | [diff] [blame] | 275 | const struct ist path = http_get_path(uri); |
| 276 | struct ist newquery = ist2(replace->area, replace->size); |
| 277 | |
| 278 | if (!isttest(path)) |
| 279 | goto leave; |
| 280 | |
| 281 | err = uri_normalizer_query_sort(istfind(path, '?'), '&', &newquery); |
| 282 | |
| 283 | if (err != URI_NORMALIZER_ERR_NONE) |
| 284 | break; |
| 285 | |
| 286 | if (!http_replace_req_query(htx, newquery)) |
| 287 | goto fail_rewrite; |
| 288 | |
| 289 | break; |
| 290 | } |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 291 | case ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE: |
| 292 | case ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT: { |
Tim Duesterhus | a407193 | 2021-04-15 21:46:02 +0200 | [diff] [blame] | 293 | const struct ist path = http_get_path(uri); |
| 294 | struct ist newpath = ist2(replace->area, replace->size); |
| 295 | |
| 296 | if (!isttest(path)) |
| 297 | goto leave; |
| 298 | |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 299 | err = uri_normalizer_percent_upper(path, rule->action == ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT, &newpath); |
Tim Duesterhus | a407193 | 2021-04-15 21:46:02 +0200 | [diff] [blame] | 300 | |
| 301 | if (err != URI_NORMALIZER_ERR_NONE) |
| 302 | break; |
| 303 | |
| 304 | if (!http_replace_req_path(htx, newpath, 1)) |
| 305 | goto fail_rewrite; |
| 306 | |
| 307 | break; |
| 308 | } |
Tim Duesterhus | 2e4a18e | 2021-04-21 21:20:36 +0200 | [diff] [blame] | 309 | case ACT_NORMALIZE_URI_PERCENT_DECODE_UNRESERVED: |
| 310 | case ACT_NORMALIZE_URI_PERCENT_DECODE_UNRESERVED_STRICT: { |
| 311 | const struct ist path = http_get_path(uri); |
| 312 | struct ist newpath = ist2(replace->area, replace->size); |
| 313 | |
| 314 | if (!isttest(path)) |
| 315 | goto leave; |
| 316 | |
| 317 | err = uri_normalizer_percent_decode_unreserved(path, rule->action == ACT_NORMALIZE_URI_PERCENT_DECODE_UNRESERVED_STRICT, &newpath); |
| 318 | |
| 319 | if (err != URI_NORMALIZER_ERR_NONE) |
| 320 | break; |
| 321 | |
| 322 | if (!http_replace_req_path(htx, newpath, 1)) |
| 323 | goto fail_rewrite; |
| 324 | |
| 325 | break; |
| 326 | } |
Tim Duesterhus | c9e05ab | 2021-05-10 17:28:25 +0200 | [diff] [blame] | 327 | case ACT_NORMALIZE_URI_FRAGMENT_STRIP: { |
| 328 | const struct ist path = http_get_path(uri); |
| 329 | struct ist newpath = ist2(replace->area, replace->size); |
| 330 | |
| 331 | if (!isttest(path)) |
| 332 | goto leave; |
| 333 | |
| 334 | err = uri_normalizer_fragment_strip(path, &newpath); |
| 335 | |
| 336 | if (err != URI_NORMALIZER_ERR_NONE) |
| 337 | break; |
| 338 | |
| 339 | if (!http_replace_req_path(htx, newpath, 1)) |
| 340 | goto fail_rewrite; |
| 341 | |
| 342 | break; |
| 343 | } |
Tim Duesterhus | dec1c36 | 2021-05-10 17:28:26 +0200 | [diff] [blame] | 344 | case ACT_NORMALIZE_URI_FRAGMENT_ENCODE: { |
| 345 | const struct ist path = http_get_path(uri); |
| 346 | struct ist newpath = ist2(replace->area, replace->size); |
| 347 | |
| 348 | if (!isttest(path)) |
| 349 | goto leave; |
| 350 | |
| 351 | err = uri_normalizer_fragment_encode(path, &newpath); |
| 352 | |
| 353 | if (err != URI_NORMALIZER_ERR_NONE) |
| 354 | break; |
| 355 | |
| 356 | if (!http_replace_req_path(htx, newpath, 1)) |
| 357 | goto fail_rewrite; |
| 358 | |
| 359 | break; |
| 360 | } |
Tim Duesterhus | d2bedcc | 2021-04-15 21:45:57 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | switch (err) { |
| 364 | case URI_NORMALIZER_ERR_NONE: |
| 365 | break; |
| 366 | case URI_NORMALIZER_ERR_INTERNAL_ERROR: |
| 367 | ret = ACT_RET_ERR; |
| 368 | break; |
| 369 | case URI_NORMALIZER_ERR_INVALID_INPUT: |
| 370 | ret = ACT_RET_INV; |
| 371 | break; |
| 372 | case URI_NORMALIZER_ERR_ALLOC: |
| 373 | goto fail_alloc; |
| 374 | } |
| 375 | |
| 376 | leave: |
| 377 | free_trash_chunk(replace); |
| 378 | return ret; |
| 379 | |
| 380 | fail_alloc: |
| 381 | if (!(s->flags & SF_ERR_MASK)) |
| 382 | s->flags |= SF_ERR_RESOURCE; |
| 383 | ret = ACT_RET_ERR; |
| 384 | goto leave; |
| 385 | |
| 386 | fail_rewrite: |
| 387 | _HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1); |
| 388 | if (s->flags & SF_BE_ASSIGNED) |
| 389 | _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1); |
| 390 | if (sess->listener && sess->listener->counters) |
| 391 | _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1); |
| 392 | if (objt_server(s->target)) |
| 393 | _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1); |
| 394 | |
| 395 | if (!(s->txn->req.flags & HTTP_MSGF_SOFT_RW)) { |
| 396 | ret = ACT_RET_ERR; |
| 397 | if (!(s->flags & SF_ERR_MASK)) |
| 398 | s->flags |= SF_ERR_PRXCOND; |
| 399 | } |
| 400 | goto leave; |
| 401 | } |
| 402 | |
| 403 | /* Parses the http-request normalize-uri action. It expects a single <normalizer> |
| 404 | * argument, corresponding too a value in `enum act_normalize_uri`. |
| 405 | * |
| 406 | * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 407 | */ |
| 408 | static enum act_parse_ret parse_http_normalize_uri(const char **args, int *orig_arg, struct proxy *px, |
| 409 | struct act_rule *rule, char **err) |
| 410 | { |
| 411 | int cur_arg = *orig_arg; |
| 412 | |
| 413 | rule->action_ptr = http_action_normalize_uri; |
| 414 | rule->release_ptr = NULL; |
| 415 | |
| 416 | if (!*args[cur_arg]) { |
| 417 | memprintf(err, "missing argument <normalizer>"); |
| 418 | return ACT_RET_PRS_ERR; |
| 419 | } |
| 420 | |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 421 | if (strcmp(args[cur_arg], "path-merge-slashes") == 0) { |
Tim Duesterhus | d371e99 | 2021-04-15 21:45:58 +0200 | [diff] [blame] | 422 | cur_arg++; |
Tim Duesterhus | d2bedcc | 2021-04-15 21:45:57 +0200 | [diff] [blame] | 423 | |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 424 | rule->action = ACT_NORMALIZE_URI_PATH_MERGE_SLASHES; |
Tim Duesterhus | d2bedcc | 2021-04-15 21:45:57 +0200 | [diff] [blame] | 425 | } |
Maximilian Mader | ff3bb8b | 2021-04-21 00:22:50 +0200 | [diff] [blame] | 426 | else if (strcmp(args[cur_arg], "path-strip-dot") == 0) { |
| 427 | cur_arg++; |
| 428 | |
| 429 | rule->action = ACT_NORMALIZE_URI_PATH_STRIP_DOT; |
| 430 | } |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 431 | else if (strcmp(args[cur_arg], "path-strip-dotdot") == 0) { |
Tim Duesterhus | 9982fc2 | 2021-04-15 21:45:59 +0200 | [diff] [blame] | 432 | cur_arg++; |
| 433 | |
Tim Duesterhus | 560e1a6 | 2021-04-15 21:46:00 +0200 | [diff] [blame] | 434 | if (strcmp(args[cur_arg], "full") == 0) { |
| 435 | cur_arg++; |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 436 | rule->action = ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL; |
Tim Duesterhus | 560e1a6 | 2021-04-15 21:46:00 +0200 | [diff] [blame] | 437 | } |
| 438 | else if (!*args[cur_arg]) { |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 439 | rule->action = ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT; |
Tim Duesterhus | 560e1a6 | 2021-04-15 21:46:00 +0200 | [diff] [blame] | 440 | } |
| 441 | else if (strcmp(args[cur_arg], "if") != 0 && strcmp(args[cur_arg], "unless") != 0) { |
Tim Duesterhus | 2f41313 | 2021-05-10 23:21:20 +0200 | [diff] [blame] | 442 | memprintf(err, "unknown argument '%s' for 'path-strip-dotdot' normalizer", args[cur_arg]); |
Tim Duesterhus | 560e1a6 | 2021-04-15 21:46:00 +0200 | [diff] [blame] | 443 | return ACT_RET_PRS_ERR; |
| 444 | } |
Tim Duesterhus | 9982fc2 | 2021-04-15 21:45:59 +0200 | [diff] [blame] | 445 | } |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 446 | else if (strcmp(args[cur_arg], "query-sort-by-name") == 0) { |
Tim Duesterhus | d7b89be | 2021-04-15 21:46:01 +0200 | [diff] [blame] | 447 | cur_arg++; |
| 448 | |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 449 | rule->action = ACT_NORMALIZE_URI_QUERY_SORT_BY_NAME; |
Tim Duesterhus | d7b89be | 2021-04-15 21:46:01 +0200 | [diff] [blame] | 450 | } |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 451 | else if (strcmp(args[cur_arg], "percent-to-uppercase") == 0) { |
Tim Duesterhus | a407193 | 2021-04-15 21:46:02 +0200 | [diff] [blame] | 452 | cur_arg++; |
| 453 | |
| 454 | if (strcmp(args[cur_arg], "strict") == 0) { |
| 455 | cur_arg++; |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 456 | rule->action = ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT; |
Tim Duesterhus | a407193 | 2021-04-15 21:46:02 +0200 | [diff] [blame] | 457 | } |
| 458 | else if (!*args[cur_arg]) { |
Tim Duesterhus | 5be6ab2 | 2021-04-17 11:21:10 +0200 | [diff] [blame] | 459 | rule->action = ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE; |
Tim Duesterhus | a407193 | 2021-04-15 21:46:02 +0200 | [diff] [blame] | 460 | } |
| 461 | else if (strcmp(args[cur_arg], "if") != 0 && strcmp(args[cur_arg], "unless") != 0) { |
Tim Duesterhus | 2f41313 | 2021-05-10 23:21:20 +0200 | [diff] [blame] | 462 | memprintf(err, "unknown argument '%s' for 'percent-to-uppercase' normalizer", args[cur_arg]); |
Tim Duesterhus | a407193 | 2021-04-15 21:46:02 +0200 | [diff] [blame] | 463 | return ACT_RET_PRS_ERR; |
| 464 | } |
| 465 | } |
Tim Duesterhus | 2e4a18e | 2021-04-21 21:20:36 +0200 | [diff] [blame] | 466 | else if (strcmp(args[cur_arg], "percent-decode-unreserved") == 0) { |
| 467 | cur_arg++; |
| 468 | |
| 469 | if (strcmp(args[cur_arg], "strict") == 0) { |
| 470 | cur_arg++; |
| 471 | rule->action = ACT_NORMALIZE_URI_PERCENT_DECODE_UNRESERVED_STRICT; |
| 472 | } |
| 473 | else if (!*args[cur_arg]) { |
| 474 | rule->action = ACT_NORMALIZE_URI_PERCENT_DECODE_UNRESERVED; |
| 475 | } |
| 476 | else if (strcmp(args[cur_arg], "if") != 0 && strcmp(args[cur_arg], "unless") != 0) { |
| 477 | memprintf(err, "unknown argument '%s' for 'percent-decode-unreserved' normalizer", args[cur_arg]); |
| 478 | return ACT_RET_PRS_ERR; |
| 479 | } |
| 480 | } |
Tim Duesterhus | c9e05ab | 2021-05-10 17:28:25 +0200 | [diff] [blame] | 481 | else if (strcmp(args[cur_arg], "fragment-strip") == 0) { |
| 482 | cur_arg++; |
| 483 | |
| 484 | rule->action = ACT_NORMALIZE_URI_FRAGMENT_STRIP; |
| 485 | } |
Tim Duesterhus | dec1c36 | 2021-05-10 17:28:26 +0200 | [diff] [blame] | 486 | else if (strcmp(args[cur_arg], "fragment-encode") == 0) { |
| 487 | cur_arg++; |
| 488 | |
| 489 | rule->action = ACT_NORMALIZE_URI_FRAGMENT_ENCODE; |
| 490 | } |
Tim Duesterhus | d2bedcc | 2021-04-15 21:45:57 +0200 | [diff] [blame] | 491 | else { |
| 492 | memprintf(err, "unknown normalizer '%s'", args[cur_arg]); |
| 493 | return ACT_RET_PRS_ERR; |
| 494 | } |
| 495 | |
| 496 | *orig_arg = cur_arg; |
| 497 | return ACT_RET_PRS_OK; |
| 498 | } |
| 499 | |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 500 | /* This function executes a replace-uri action. It finds its arguments in |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 501 | * <rule>.arg.http. It builds a string in the trash from the format string |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 502 | * previously filled by function parse_replace_uri() and will execute the regex |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 503 | * in <http.re> to replace the URI. It uses the format string present in |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 504 | * <http.fmt>. The component to act on (path/uri) is taken from <.action> which |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 505 | * contains 1 for the path or 3 for the URI (values used by |
| 506 | * http_req_replace_stline()). On success, it returns ACT_RET_CONT. If an error |
| 507 | * occurs while soft rewrites are enabled, the action is canceled, but the rule |
| 508 | * processing continue. Otherwsize ACT_RET_ERR is returned. |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 509 | */ |
| 510 | static enum act_return http_action_replace_uri(struct act_rule *rule, struct proxy *px, |
| 511 | struct session *sess, struct stream *s, int flags) |
| 512 | { |
Christopher Faulet | 1340376 | 2019-12-13 09:01:57 +0100 | [diff] [blame] | 513 | enum act_return ret = ACT_RET_CONT; |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 514 | struct buffer *replace, *output; |
| 515 | struct ist uri; |
| 516 | int len; |
| 517 | |
| 518 | replace = alloc_trash_chunk(); |
| 519 | output = alloc_trash_chunk(); |
| 520 | if (!replace || !output) |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 521 | goto fail_alloc; |
Christopher Faulet | 12c28b6 | 2019-07-15 16:30:24 +0200 | [diff] [blame] | 522 | uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf))); |
Willy Tarreau | 262c3f1 | 2019-12-17 06:52:51 +0100 | [diff] [blame] | 523 | |
Christopher Faulet | 1fa0cc1 | 2020-09-02 11:10:38 +0200 | [diff] [blame] | 524 | if (rule->action == 1) // replace-path |
| 525 | uri = iststop(http_get_path(uri), '?'); |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 526 | else if (rule->action == 4) // replace-pathq |
| 527 | uri = http_get_path(uri); |
Willy Tarreau | 262c3f1 | 2019-12-17 06:52:51 +0100 | [diff] [blame] | 528 | |
Christopher Faulet | 5d24269 | 2022-04-08 10:44:21 +0200 | [diff] [blame] | 529 | if (!istlen(uri)) |
| 530 | goto leave; |
| 531 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 532 | if (!regex_exec_match2(rule->arg.http.re, uri.ptr, uri.len, MAX_MATCH, pmatch, 0)) |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 533 | goto leave; |
| 534 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 535 | replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt); |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 536 | |
| 537 | /* note: uri.ptr doesn't need to be zero-terminated because it will |
| 538 | * only be used to pick pmatch references. |
| 539 | */ |
| 540 | len = exp_replace(output->area, output->size, uri.ptr, replace->area, pmatch); |
| 541 | if (len == -1) |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 542 | goto fail_rewrite; |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 543 | |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 544 | if (http_req_replace_stline(rule->action, output->area, len, px, s) == -1) |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 545 | goto fail_rewrite; |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 546 | |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 547 | leave: |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 548 | free_trash_chunk(output); |
| 549 | free_trash_chunk(replace); |
| 550 | return ret; |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 551 | |
| 552 | fail_alloc: |
| 553 | if (!(s->flags & SF_ERR_MASK)) |
| 554 | s->flags |= SF_ERR_RESOURCE; |
| 555 | ret = ACT_RET_ERR; |
| 556 | goto leave; |
| 557 | |
| 558 | fail_rewrite: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 559 | _HA_ATOMIC_INC(&sess->fe->fe_counters.failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 560 | if (s->flags & SF_BE_ASSIGNED) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 561 | _HA_ATOMIC_INC(&s->be->be_counters.failed_rewrites); |
William Lallemand | 36119de | 2021-03-08 15:26:48 +0100 | [diff] [blame] | 562 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 563 | _HA_ATOMIC_INC(&sess->listener->counters->failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 564 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 565 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 566 | |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 567 | if (!(s->txn->req.flags & HTTP_MSGF_SOFT_RW)) { |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 568 | ret = ACT_RET_ERR; |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 569 | if (!(s->flags & SF_ERR_MASK)) |
| 570 | s->flags |= SF_ERR_PRXCOND; |
| 571 | } |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 572 | goto leave; |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 575 | /* parse a "replace-uri", "replace-path" or "replace-pathq" |
| 576 | * http-request action. |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 577 | * This action takes 2 arguments (a regex and a replacement format string). |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 578 | * The resulting rule makes use of <.action> to store the action (1/3 for now), |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 579 | * <http.re> to store the compiled regex, and <http.fmt> to store the log-format |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 580 | * list head. It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 581 | */ |
| 582 | static enum act_parse_ret parse_replace_uri(const char **args, int *orig_arg, struct proxy *px, |
| 583 | struct act_rule *rule, char **err) |
| 584 | { |
| 585 | int cur_arg = *orig_arg; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 586 | int cap = 0; |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 587 | char *error = NULL; |
| 588 | |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 589 | switch (args[0][8]) { |
| 590 | case 'p': |
| 591 | if (args[0][12] == 'q') |
| 592 | rule->action = 4; // replace-pathq, same as set-pathq |
| 593 | else |
| 594 | rule->action = 1; // replace-path, same as set-path |
| 595 | break; |
| 596 | case 'u': |
Christopher Faulet | 2c22a69 | 2019-12-18 15:39:56 +0100 | [diff] [blame] | 597 | rule->action = 3; // replace-uri, same as set-uri |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 598 | break; |
| 599 | default: |
| 600 | memprintf(err, "internal error: unhandled action '%s'", args[0]); |
| 601 | return ACT_RET_PRS_ERR; |
| 602 | } |
Willy Tarreau | 262c3f1 | 2019-12-17 06:52:51 +0100 | [diff] [blame] | 603 | |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 604 | rule->action_ptr = http_action_replace_uri; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 605 | rule->release_ptr = release_http_action; |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 606 | |
| 607 | if (!*args[cur_arg] || !*args[cur_arg+1] || |
| 608 | (*args[cur_arg+2] && strcmp(args[cur_arg+2], "if") != 0 && strcmp(args[cur_arg+2], "unless") != 0)) { |
| 609 | memprintf(err, "expects exactly 2 arguments <match-regex> and <replace-format>"); |
| 610 | return ACT_RET_PRS_ERR; |
| 611 | } |
| 612 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 613 | if (!(rule->arg.http.re = regex_comp(args[cur_arg], 1, 1, &error))) { |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 614 | memprintf(err, "failed to parse the regex : %s", error); |
| 615 | free(error); |
| 616 | return ACT_RET_PRS_ERR; |
| 617 | } |
| 618 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 619 | LIST_INIT(&rule->arg.http.fmt); |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 620 | px->conf.args.ctx = ARGC_HRQ; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 621 | if (px->cap & PR_CAP_FE) |
| 622 | cap |= SMP_VAL_FE_HRQ_HDR; |
| 623 | if (px->cap & PR_CAP_BE) |
| 624 | cap |= SMP_VAL_BE_HRQ_HDR; |
| 625 | if (!parse_logformat_string(args[cur_arg + 1], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) { |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 626 | regex_free(rule->arg.http.re); |
Willy Tarreau | 3381022 | 2019-06-12 17:44:02 +0200 | [diff] [blame] | 627 | return ACT_RET_PRS_ERR; |
| 628 | } |
| 629 | |
| 630 | (*orig_arg) += 2; |
| 631 | return ACT_RET_PRS_OK; |
| 632 | } |
| 633 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 634 | /* This function is just a compliant action wrapper for "set-status". */ |
| 635 | static enum act_return action_http_set_status(struct act_rule *rule, struct proxy *px, |
| 636 | struct session *sess, struct stream *s, int flags) |
| 637 | { |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 638 | if (http_res_set_status(rule->arg.http.i, rule->arg.http.str, s) == -1) { |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 639 | _HA_ATOMIC_INC(&sess->fe->fe_counters.failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 640 | if (s->flags & SF_BE_ASSIGNED) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 641 | _HA_ATOMIC_INC(&s->be->be_counters.failed_rewrites); |
William Lallemand | 36119de | 2021-03-08 15:26:48 +0100 | [diff] [blame] | 642 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 643 | _HA_ATOMIC_INC(&sess->listener->counters->failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 644 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 645 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.failed_rewrites); |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 646 | |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 647 | if (!(s->txn->req.flags & HTTP_MSGF_SOFT_RW)) { |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 648 | if (!(s->flags & SF_ERR_MASK)) |
| 649 | s->flags |= SF_ERR_PRXCOND; |
Christopher Faulet | 692a6c2 | 2020-02-07 10:22:31 +0100 | [diff] [blame] | 650 | return ACT_RET_ERR; |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 651 | } |
Christopher Faulet | e00d06c | 2019-12-16 17:18:42 +0100 | [diff] [blame] | 652 | } |
| 653 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 654 | return ACT_RET_CONT; |
| 655 | } |
| 656 | |
| 657 | /* parse set-status action: |
| 658 | * This action accepts a single argument of type int representing |
| 659 | * an http status code. It returns ACT_RET_PRS_OK on success, |
| 660 | * ACT_RET_PRS_ERR on error. |
| 661 | */ |
| 662 | static enum act_parse_ret parse_http_set_status(const char **args, int *orig_arg, struct proxy *px, |
| 663 | struct act_rule *rule, char **err) |
| 664 | { |
| 665 | char *error; |
| 666 | |
| 667 | rule->action = ACT_CUSTOM; |
| 668 | rule->action_ptr = action_http_set_status; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 669 | rule->release_ptr = release_http_action; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 670 | |
| 671 | /* Check if an argument is available */ |
| 672 | if (!*args[*orig_arg]) { |
| 673 | memprintf(err, "expects 1 argument: <status>; or 3 arguments: <status> reason <fmt>"); |
| 674 | return ACT_RET_PRS_ERR; |
| 675 | } |
| 676 | |
| 677 | /* convert status code as integer */ |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 678 | rule->arg.http.i = strtol(args[*orig_arg], &error, 10); |
| 679 | if (*error != '\0' || rule->arg.http.i < 100 || rule->arg.http.i > 999) { |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 680 | memprintf(err, "expects an integer status code between 100 and 999"); |
| 681 | return ACT_RET_PRS_ERR; |
| 682 | } |
| 683 | |
| 684 | (*orig_arg)++; |
| 685 | |
| 686 | /* set custom reason string */ |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 687 | rule->arg.http.str = ist(NULL); // If null, we use the default reason for the status code. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 688 | if (*args[*orig_arg] && strcmp(args[*orig_arg], "reason") == 0 && |
| 689 | (*args[*orig_arg + 1] && strcmp(args[*orig_arg + 1], "if") != 0 && strcmp(args[*orig_arg + 1], "unless") != 0)) { |
| 690 | (*orig_arg)++; |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 691 | rule->arg.http.str.ptr = strdup(args[*orig_arg]); |
| 692 | rule->arg.http.str.len = strlen(rule->arg.http.str.ptr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 693 | (*orig_arg)++; |
| 694 | } |
| 695 | |
Christopher Faulet | c20b371 | 2020-01-27 15:51:56 +0100 | [diff] [blame] | 696 | LIST_INIT(&rule->arg.http.fmt); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 697 | return ACT_RET_PRS_OK; |
| 698 | } |
| 699 | |
| 700 | /* This function executes the "reject" HTTP action. It clears the request and |
| 701 | * response buffer without sending any response. It can be useful as an HTTP |
| 702 | * alternative to the silent-drop action to defend against DoS attacks, and may |
| 703 | * also be used with HTTP/2 to close a connection instead of just a stream. |
| 704 | * The txn status is unchanged, indicating no response was sent. The termination |
Christopher Faulet | 90d22a8 | 2020-03-06 11:18:39 +0100 | [diff] [blame] | 705 | * flags will indicate "PR". It always returns ACT_RET_ABRT. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 706 | */ |
| 707 | static enum act_return http_action_reject(struct act_rule *rule, struct proxy *px, |
| 708 | struct session *sess, struct stream *s, int flags) |
| 709 | { |
Willy Tarreau | 0f9cd7b | 2019-01-31 19:02:43 +0100 | [diff] [blame] | 710 | si_must_kill_conn(chn_prod(&s->req)); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 711 | channel_abort(&s->req); |
| 712 | channel_abort(&s->res); |
Christopher Faulet | d4a824e | 2020-03-06 15:07:09 +0100 | [diff] [blame] | 713 | s->req.analysers &= AN_REQ_FLT_END; |
| 714 | s->res.analysers &= AN_RES_FLT_END; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 715 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 716 | _HA_ATOMIC_INC(&s->be->be_counters.denied_req); |
| 717 | _HA_ATOMIC_INC(&sess->fe->fe_counters.denied_req); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 718 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 719 | _HA_ATOMIC_INC(&sess->listener->counters->denied_req); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 720 | |
| 721 | if (!(s->flags & SF_ERR_MASK)) |
| 722 | s->flags |= SF_ERR_PRXCOND; |
| 723 | if (!(s->flags & SF_FINST_MASK)) |
| 724 | s->flags |= SF_FINST_R; |
| 725 | |
Christopher Faulet | 90d22a8 | 2020-03-06 11:18:39 +0100 | [diff] [blame] | 726 | return ACT_RET_ABRT; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /* parse the "reject" action: |
| 730 | * This action takes no argument and returns ACT_RET_PRS_OK on success, |
| 731 | * ACT_RET_PRS_ERR on error. |
| 732 | */ |
| 733 | static enum act_parse_ret parse_http_action_reject(const char **args, int *orig_arg, struct proxy *px, |
| 734 | struct act_rule *rule, char **err) |
| 735 | { |
| 736 | rule->action = ACT_CUSTOM; |
| 737 | rule->action_ptr = http_action_reject; |
| 738 | return ACT_RET_PRS_OK; |
| 739 | } |
| 740 | |
Olivier Houchard | 602bf7d | 2019-05-10 13:59:15 +0200 | [diff] [blame] | 741 | /* This function executes the "disable-l7-retry" HTTP action. |
| 742 | * It disables L7 retries (all retry except for a connection failure). This |
| 743 | * can be useful for example to avoid retrying on POST requests. |
| 744 | * It just removes the L7 retry flag on the stream_interface, and always |
| 745 | * return ACT_RET_CONT; |
| 746 | */ |
| 747 | static enum act_return http_req_disable_l7_retry(struct act_rule *rule, struct proxy *px, |
| 748 | struct session *sess, struct stream *s, int flags) |
| 749 | { |
| 750 | struct stream_interface *si = &s->si[1]; |
| 751 | |
| 752 | /* In theory, the SI_FL_L7_RETRY flags isn't set at this point, but |
| 753 | * let's be future-proof and remove it anyway. |
| 754 | */ |
| 755 | si->flags &= ~SI_FL_L7_RETRY; |
| 756 | si->flags |= SI_FL_D_L7_RETRY; |
| 757 | return ACT_RET_CONT; |
| 758 | } |
| 759 | |
| 760 | /* parse the "disable-l7-retry" action: |
| 761 | * This action takes no argument and returns ACT_RET_PRS_OK on success, |
| 762 | * ACT_RET_PRS_ERR on error. |
| 763 | */ |
| 764 | static enum act_parse_ret parse_http_req_disable_l7_retry(const char **args, |
| 765 | int *orig_args, struct proxy *px, |
| 766 | struct act_rule *rule, char **err) |
| 767 | { |
| 768 | rule->action = ACT_CUSTOM; |
| 769 | rule->action_ptr = http_req_disable_l7_retry; |
| 770 | return ACT_RET_PRS_OK; |
| 771 | } |
| 772 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 773 | /* This function executes the "capture" action. It executes a fetch expression, |
| 774 | * turns the result into a string and puts it in a capture slot. It always |
| 775 | * returns 1. If an error occurs the action is cancelled, but the rule |
| 776 | * processing continues. |
| 777 | */ |
| 778 | static enum act_return http_action_req_capture(struct act_rule *rule, struct proxy *px, |
| 779 | struct session *sess, struct stream *s, int flags) |
| 780 | { |
| 781 | struct sample *key; |
| 782 | struct cap_hdr *h = rule->arg.cap.hdr; |
| 783 | char **cap = s->req_cap; |
| 784 | int len; |
| 785 | |
| 786 | key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.cap.expr, SMP_T_STR); |
| 787 | if (!key) |
| 788 | return ACT_RET_CONT; |
| 789 | |
| 790 | if (cap[h->index] == NULL) |
| 791 | cap[h->index] = pool_alloc(h->pool); |
| 792 | |
| 793 | if (cap[h->index] == NULL) /* no more capture memory */ |
| 794 | return ACT_RET_CONT; |
| 795 | |
| 796 | len = key->data.u.str.data; |
| 797 | if (len > h->len) |
| 798 | len = h->len; |
| 799 | |
| 800 | memcpy(cap[h->index], key->data.u.str.area, len); |
| 801 | cap[h->index][len] = 0; |
| 802 | return ACT_RET_CONT; |
| 803 | } |
| 804 | |
| 805 | /* This function executes the "capture" action and store the result in a |
| 806 | * capture slot if exists. It executes a fetch expression, turns the result |
| 807 | * into a string and puts it in a capture slot. It always returns 1. If an |
| 808 | * error occurs the action is cancelled, but the rule processing continues. |
| 809 | */ |
| 810 | static enum act_return http_action_req_capture_by_id(struct act_rule *rule, struct proxy *px, |
| 811 | struct session *sess, struct stream *s, int flags) |
| 812 | { |
| 813 | struct sample *key; |
| 814 | struct cap_hdr *h; |
| 815 | char **cap = s->req_cap; |
| 816 | struct proxy *fe = strm_fe(s); |
| 817 | int len; |
| 818 | int i; |
| 819 | |
| 820 | /* Look for the original configuration. */ |
| 821 | for (h = fe->req_cap, i = fe->nb_req_cap - 1; |
| 822 | h != NULL && i != rule->arg.capid.idx ; |
| 823 | i--, h = h->next); |
| 824 | if (!h) |
| 825 | return ACT_RET_CONT; |
| 826 | |
| 827 | key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR); |
| 828 | if (!key) |
| 829 | return ACT_RET_CONT; |
| 830 | |
| 831 | if (cap[h->index] == NULL) |
| 832 | cap[h->index] = pool_alloc(h->pool); |
| 833 | |
| 834 | if (cap[h->index] == NULL) /* no more capture memory */ |
| 835 | return ACT_RET_CONT; |
| 836 | |
| 837 | len = key->data.u.str.data; |
| 838 | if (len > h->len) |
| 839 | len = h->len; |
| 840 | |
| 841 | memcpy(cap[h->index], key->data.u.str.area, len); |
| 842 | cap[h->index][len] = 0; |
| 843 | return ACT_RET_CONT; |
| 844 | } |
| 845 | |
| 846 | /* Check an "http-request capture" action. |
| 847 | * |
| 848 | * The function returns 1 in success case, otherwise, it returns 0 and err is |
| 849 | * filled. |
| 850 | */ |
| 851 | static int check_http_req_capture(struct act_rule *rule, struct proxy *px, char **err) |
| 852 | { |
| 853 | if (rule->action_ptr != http_action_req_capture_by_id) |
| 854 | return 1; |
| 855 | |
Baptiste Assmann | 19a69b3 | 2020-01-16 14:34:22 +0100 | [diff] [blame] | 856 | /* capture slots can only be declared in frontends, so we can't check their |
| 857 | * existence in backends at configuration parsing step |
| 858 | */ |
| 859 | if (px->cap & PR_CAP_FE && rule->arg.capid.idx >= px->nb_req_cap) { |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 860 | memprintf(err, "unable to find capture id '%d' referenced by http-request capture rule", |
| 861 | rule->arg.capid.idx); |
| 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | return 1; |
| 866 | } |
| 867 | |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 868 | /* Release memory allocate by an http capture action */ |
| 869 | static void release_http_capture(struct act_rule *rule) |
| 870 | { |
| 871 | if (rule->action_ptr == http_action_req_capture) |
| 872 | release_sample_expr(rule->arg.cap.expr); |
| 873 | else |
| 874 | release_sample_expr(rule->arg.capid.expr); |
| 875 | } |
| 876 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 877 | /* parse an "http-request capture" action. It takes a single argument which is |
| 878 | * a sample fetch expression. It stores the expression into arg->act.p[0] and |
| 879 | * the allocated hdr_cap struct or the preallocated "id" into arg->act.p[1]. |
| 880 | * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 881 | */ |
| 882 | static enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, struct proxy *px, |
| 883 | struct act_rule *rule, char **err) |
| 884 | { |
| 885 | struct sample_expr *expr; |
| 886 | struct cap_hdr *hdr; |
| 887 | int cur_arg; |
| 888 | int len = 0; |
| 889 | |
| 890 | for (cur_arg = *orig_arg; cur_arg < *orig_arg + 3 && *args[cur_arg]; cur_arg++) |
| 891 | if (strcmp(args[cur_arg], "if") == 0 || |
| 892 | strcmp(args[cur_arg], "unless") == 0) |
| 893 | break; |
| 894 | |
| 895 | if (cur_arg < *orig_arg + 3) { |
| 896 | memprintf(err, "expects <expression> [ 'len' <length> | id <idx> ]"); |
| 897 | return ACT_RET_PRS_ERR; |
| 898 | } |
| 899 | |
| 900 | cur_arg = *orig_arg; |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 901 | expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line, err, &px->conf.args, NULL); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 902 | if (!expr) |
| 903 | return ACT_RET_PRS_ERR; |
| 904 | |
| 905 | if (!(expr->fetch->val & SMP_VAL_FE_HRQ_HDR)) { |
| 906 | memprintf(err, |
| 907 | "fetch method '%s' extracts information from '%s', none of which is available here", |
| 908 | args[cur_arg-1], sample_src_names(expr->fetch->use)); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 909 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 910 | return ACT_RET_PRS_ERR; |
| 911 | } |
| 912 | |
| 913 | if (!args[cur_arg] || !*args[cur_arg]) { |
| 914 | memprintf(err, "expects 'len or 'id'"); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 915 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 916 | return ACT_RET_PRS_ERR; |
| 917 | } |
| 918 | |
| 919 | if (strcmp(args[cur_arg], "len") == 0) { |
| 920 | cur_arg++; |
| 921 | |
| 922 | if (!(px->cap & PR_CAP_FE)) { |
| 923 | memprintf(err, "proxy '%s' has no frontend capability", px->id); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 924 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 925 | return ACT_RET_PRS_ERR; |
| 926 | } |
| 927 | |
| 928 | px->conf.args.ctx = ARGC_CAP; |
| 929 | |
| 930 | if (!args[cur_arg]) { |
| 931 | memprintf(err, "missing length value"); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 932 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 933 | return ACT_RET_PRS_ERR; |
| 934 | } |
| 935 | /* we copy the table name for now, it will be resolved later */ |
| 936 | len = atoi(args[cur_arg]); |
| 937 | if (len <= 0) { |
| 938 | memprintf(err, "length must be > 0"); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 939 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 940 | return ACT_RET_PRS_ERR; |
| 941 | } |
| 942 | cur_arg++; |
| 943 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 944 | hdr = calloc(1, sizeof(*hdr)); |
Remi Tricot-Le Breton | 737d8b5 | 2021-05-12 17:54:17 +0200 | [diff] [blame] | 945 | if (!hdr) { |
| 946 | memprintf(err, "out of memory"); |
| 947 | release_sample_expr(expr); |
| 948 | return ACT_RET_PRS_ERR; |
| 949 | } |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 950 | hdr->next = px->req_cap; |
| 951 | hdr->name = NULL; /* not a header capture */ |
| 952 | hdr->namelen = 0; |
| 953 | hdr->len = len; |
| 954 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
| 955 | hdr->index = px->nb_req_cap++; |
| 956 | |
| 957 | px->req_cap = hdr; |
| 958 | px->to_log |= LW_REQHDR; |
| 959 | |
| 960 | rule->action = ACT_CUSTOM; |
| 961 | rule->action_ptr = http_action_req_capture; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 962 | rule->release_ptr = release_http_capture; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 963 | rule->arg.cap.expr = expr; |
| 964 | rule->arg.cap.hdr = hdr; |
| 965 | } |
| 966 | |
| 967 | else if (strcmp(args[cur_arg], "id") == 0) { |
| 968 | int id; |
| 969 | char *error; |
| 970 | |
| 971 | cur_arg++; |
| 972 | |
| 973 | if (!args[cur_arg]) { |
| 974 | memprintf(err, "missing id value"); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 975 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 976 | return ACT_RET_PRS_ERR; |
| 977 | } |
| 978 | |
| 979 | id = strtol(args[cur_arg], &error, 10); |
| 980 | if (*error != '\0') { |
| 981 | memprintf(err, "cannot parse id '%s'", args[cur_arg]); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 982 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 983 | return ACT_RET_PRS_ERR; |
| 984 | } |
| 985 | cur_arg++; |
| 986 | |
| 987 | px->conf.args.ctx = ARGC_CAP; |
| 988 | |
| 989 | rule->action = ACT_CUSTOM; |
| 990 | rule->action_ptr = http_action_req_capture_by_id; |
| 991 | rule->check_ptr = check_http_req_capture; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 992 | rule->release_ptr = release_http_capture; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 993 | rule->arg.capid.expr = expr; |
| 994 | rule->arg.capid.idx = id; |
| 995 | } |
| 996 | |
| 997 | else { |
| 998 | memprintf(err, "expects 'len' or 'id', found '%s'", args[cur_arg]); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 999 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1000 | return ACT_RET_PRS_ERR; |
| 1001 | } |
| 1002 | |
| 1003 | *orig_arg = cur_arg; |
| 1004 | return ACT_RET_PRS_OK; |
| 1005 | } |
| 1006 | |
| 1007 | /* This function executes the "capture" action and store the result in a |
| 1008 | * capture slot if exists. It executes a fetch expression, turns the result |
| 1009 | * into a string and puts it in a capture slot. It always returns 1. If an |
| 1010 | * error occurs the action is cancelled, but the rule processing continues. |
| 1011 | */ |
| 1012 | static enum act_return http_action_res_capture_by_id(struct act_rule *rule, struct proxy *px, |
| 1013 | struct session *sess, struct stream *s, int flags) |
| 1014 | { |
| 1015 | struct sample *key; |
| 1016 | struct cap_hdr *h; |
| 1017 | char **cap = s->res_cap; |
| 1018 | struct proxy *fe = strm_fe(s); |
| 1019 | int len; |
| 1020 | int i; |
| 1021 | |
| 1022 | /* Look for the original configuration. */ |
| 1023 | for (h = fe->rsp_cap, i = fe->nb_rsp_cap - 1; |
| 1024 | h != NULL && i != rule->arg.capid.idx ; |
| 1025 | i--, h = h->next); |
| 1026 | if (!h) |
| 1027 | return ACT_RET_CONT; |
| 1028 | |
| 1029 | key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR); |
| 1030 | if (!key) |
| 1031 | return ACT_RET_CONT; |
| 1032 | |
| 1033 | if (cap[h->index] == NULL) |
| 1034 | cap[h->index] = pool_alloc(h->pool); |
| 1035 | |
| 1036 | if (cap[h->index] == NULL) /* no more capture memory */ |
| 1037 | return ACT_RET_CONT; |
| 1038 | |
| 1039 | len = key->data.u.str.data; |
| 1040 | if (len > h->len) |
| 1041 | len = h->len; |
| 1042 | |
| 1043 | memcpy(cap[h->index], key->data.u.str.area, len); |
| 1044 | cap[h->index][len] = 0; |
| 1045 | return ACT_RET_CONT; |
| 1046 | } |
| 1047 | |
| 1048 | /* Check an "http-response capture" action. |
| 1049 | * |
| 1050 | * The function returns 1 in success case, otherwise, it returns 0 and err is |
| 1051 | * filled. |
| 1052 | */ |
| 1053 | static int check_http_res_capture(struct act_rule *rule, struct proxy *px, char **err) |
| 1054 | { |
| 1055 | if (rule->action_ptr != http_action_res_capture_by_id) |
| 1056 | return 1; |
| 1057 | |
Tim Duesterhus | f3f4aa0 | 2020-07-03 13:43:42 +0200 | [diff] [blame] | 1058 | /* capture slots can only be declared in frontends, so we can't check their |
| 1059 | * existence in backends at configuration parsing step |
| 1060 | */ |
| 1061 | if (px->cap & PR_CAP_FE && rule->arg.capid.idx >= px->nb_rsp_cap) { |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1062 | memprintf(err, "unable to find capture id '%d' referenced by http-response capture rule", |
| 1063 | rule->arg.capid.idx); |
| 1064 | return 0; |
| 1065 | } |
| 1066 | |
| 1067 | return 1; |
| 1068 | } |
| 1069 | |
| 1070 | /* parse an "http-response capture" action. It takes a single argument which is |
| 1071 | * a sample fetch expression. It stores the expression into arg->act.p[0] and |
Thayne McCombs | 8f0cc5c | 2021-01-07 21:35:52 -0700 | [diff] [blame] | 1072 | * the allocated hdr_cap struct of the preallocated id into arg->act.p[1]. |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1073 | * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 1074 | */ |
| 1075 | static enum act_parse_ret parse_http_res_capture(const char **args, int *orig_arg, struct proxy *px, |
| 1076 | struct act_rule *rule, char **err) |
| 1077 | { |
| 1078 | struct sample_expr *expr; |
| 1079 | int cur_arg; |
| 1080 | int id; |
| 1081 | char *error; |
| 1082 | |
| 1083 | for (cur_arg = *orig_arg; cur_arg < *orig_arg + 3 && *args[cur_arg]; cur_arg++) |
| 1084 | if (strcmp(args[cur_arg], "if") == 0 || |
| 1085 | strcmp(args[cur_arg], "unless") == 0) |
| 1086 | break; |
| 1087 | |
| 1088 | if (cur_arg < *orig_arg + 3) { |
| 1089 | memprintf(err, "expects <expression> id <idx>"); |
| 1090 | return ACT_RET_PRS_ERR; |
| 1091 | } |
| 1092 | |
| 1093 | cur_arg = *orig_arg; |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 1094 | expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line, err, &px->conf.args, NULL); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1095 | if (!expr) |
| 1096 | return ACT_RET_PRS_ERR; |
| 1097 | |
| 1098 | if (!(expr->fetch->val & SMP_VAL_FE_HRS_HDR)) { |
| 1099 | memprintf(err, |
| 1100 | "fetch method '%s' extracts information from '%s', none of which is available here", |
| 1101 | args[cur_arg-1], sample_src_names(expr->fetch->use)); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1102 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1103 | return ACT_RET_PRS_ERR; |
| 1104 | } |
| 1105 | |
| 1106 | if (!args[cur_arg] || !*args[cur_arg]) { |
| 1107 | memprintf(err, "expects 'id'"); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1108 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1109 | return ACT_RET_PRS_ERR; |
| 1110 | } |
| 1111 | |
| 1112 | if (strcmp(args[cur_arg], "id") != 0) { |
| 1113 | memprintf(err, "expects 'id', found '%s'", args[cur_arg]); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1114 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1115 | return ACT_RET_PRS_ERR; |
| 1116 | } |
| 1117 | |
| 1118 | cur_arg++; |
| 1119 | |
| 1120 | if (!args[cur_arg]) { |
| 1121 | memprintf(err, "missing id value"); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1122 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1123 | return ACT_RET_PRS_ERR; |
| 1124 | } |
| 1125 | |
| 1126 | id = strtol(args[cur_arg], &error, 10); |
| 1127 | if (*error != '\0') { |
| 1128 | memprintf(err, "cannot parse id '%s'", args[cur_arg]); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1129 | release_sample_expr(expr); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1130 | return ACT_RET_PRS_ERR; |
| 1131 | } |
| 1132 | cur_arg++; |
| 1133 | |
| 1134 | px->conf.args.ctx = ARGC_CAP; |
| 1135 | |
| 1136 | rule->action = ACT_CUSTOM; |
| 1137 | rule->action_ptr = http_action_res_capture_by_id; |
| 1138 | rule->check_ptr = check_http_res_capture; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1139 | rule->release_ptr = release_http_capture; |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 1140 | rule->arg.capid.expr = expr; |
| 1141 | rule->arg.capid.idx = id; |
| 1142 | |
| 1143 | *orig_arg = cur_arg; |
| 1144 | return ACT_RET_PRS_OK; |
| 1145 | } |
| 1146 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1147 | /* Parse a "allow" action for a request or a response rule. It takes no argument. It |
| 1148 | * returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 1149 | */ |
| 1150 | static enum act_parse_ret parse_http_allow(const char **args, int *orig_arg, struct proxy *px, |
| 1151 | struct act_rule *rule, char **err) |
| 1152 | { |
| 1153 | rule->action = ACT_ACTION_ALLOW; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 1154 | rule->flags |= ACT_FLAG_FINAL; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1155 | return ACT_RET_PRS_OK; |
| 1156 | } |
| 1157 | |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 1158 | /* Parse "deny" or "tarpit" actions for a request rule or "deny" action for a |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1159 | * response rule. It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on |
| 1160 | * error. It relies on http_parse_http_reply() to set |
| 1161 | * <.arg.http_reply>. |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1162 | */ |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 1163 | static enum act_parse_ret parse_http_deny(const char **args, int *orig_arg, struct proxy *px, |
| 1164 | struct act_rule *rule, char **err) |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1165 | { |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1166 | int default_status; |
| 1167 | int cur_arg, arg = 0; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1168 | |
| 1169 | cur_arg = *orig_arg; |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 1170 | if (rule->from == ACT_F_HTTP_REQ) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1171 | if (strcmp(args[cur_arg - 1], "tarpit") == 0) { |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 1172 | rule->action = ACT_HTTP_REQ_TARPIT; |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1173 | default_status = 500; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1174 | } |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 1175 | else { |
| 1176 | rule->action = ACT_ACTION_DENY; |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1177 | default_status = 403; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1178 | } |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1179 | } |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 1180 | else { |
Christopher Faulet | 554c0eb | 2020-01-14 12:00:28 +0100 | [diff] [blame] | 1181 | rule->action = ACT_ACTION_DENY; |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1182 | default_status = 502; |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 1183 | } |
Christopher Faulet | 040c8cd | 2020-01-13 16:43:45 +0100 | [diff] [blame] | 1184 | |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1185 | /* If no args or only a deny_status specified, fallback on the legacy |
| 1186 | * mode and use default error files despite the fact that |
| 1187 | * default-errorfiles is not used. Otherwise, parse an http reply. |
| 1188 | */ |
Christopher Faulet | 040c8cd | 2020-01-13 16:43:45 +0100 | [diff] [blame] | 1189 | |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1190 | /* Prepare parsing of log-format strings */ |
| 1191 | px->conf.args.ctx = ((rule->from == ACT_F_HTTP_REQ) ? ARGC_HRQ : ARGC_HRS); |
Christopher Faulet | 554c0eb | 2020-01-14 12:00:28 +0100 | [diff] [blame] | 1192 | |
Christopher Faulet | 9467f18 | 2020-06-30 09:32:01 +0200 | [diff] [blame] | 1193 | if (!*(args[cur_arg]) || strcmp(args[cur_arg], "if") == 0 || strcmp(args[cur_arg], "unless") == 0) { |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1194 | rule->arg.http_reply = http_parse_http_reply((const char *[]){"default-errorfiles", ""}, &arg, px, default_status, err); |
| 1195 | goto end; |
Christopher Faulet | 554c0eb | 2020-01-14 12:00:28 +0100 | [diff] [blame] | 1196 | } |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1197 | |
| 1198 | if (strcmp(args[cur_arg], "deny_status") == 0) { |
Christopher Faulet | 9467f18 | 2020-06-30 09:32:01 +0200 | [diff] [blame] | 1199 | if (!*(args[cur_arg+2]) || strcmp(args[cur_arg+2], "if") == 0 || strcmp(args[cur_arg+2], "unless") == 0) { |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1200 | rule->arg.http_reply = http_parse_http_reply((const char *[]){"status", args[cur_arg+1], "default-errorfiles", ""}, |
| 1201 | &arg, px, default_status, err); |
| 1202 | *orig_arg += 2; |
| 1203 | goto end; |
Christopher Faulet | 554c0eb | 2020-01-14 12:00:28 +0100 | [diff] [blame] | 1204 | } |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1205 | args[cur_arg] += 5; /* skip "deny_" for the parsing */ |
Christopher Faulet | 554c0eb | 2020-01-14 12:00:28 +0100 | [diff] [blame] | 1206 | } |
| 1207 | |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1208 | rule->arg.http_reply = http_parse_http_reply(args, orig_arg, px, default_status, err); |
Christopher Faulet | 554c0eb | 2020-01-14 12:00:28 +0100 | [diff] [blame] | 1209 | |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 1210 | end: |
| 1211 | if (!rule->arg.http_reply) |
| 1212 | return ACT_RET_PRS_ERR; |
| 1213 | |
| 1214 | rule->flags |= ACT_FLAG_FINAL; |
| 1215 | rule->check_ptr = check_act_http_reply; |
| 1216 | rule->release_ptr = release_act_http_reply; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1217 | return ACT_RET_PRS_OK; |
| 1218 | } |
| 1219 | |
Christopher Faulet | b304883 | 2020-05-27 15:26:43 +0200 | [diff] [blame] | 1220 | |
| 1221 | /* This function executes a auth action. It builds an 401/407 HTX message using |
| 1222 | * the corresponding proxy's error message. On success, it returns |
| 1223 | * ACT_RET_ABRT. If an error occurs ACT_RET_ERR is returned. |
| 1224 | */ |
| 1225 | static enum act_return http_action_auth(struct act_rule *rule, struct proxy *px, |
| 1226 | struct session *sess, struct stream *s, int flags) |
| 1227 | { |
| 1228 | struct channel *req = &s->req; |
| 1229 | struct channel *res = &s->res; |
| 1230 | struct htx *htx = htx_from_buf(&res->buf); |
| 1231 | struct http_reply *reply; |
| 1232 | const char *auth_realm; |
| 1233 | struct http_hdr_ctx ctx; |
| 1234 | struct ist hdr; |
| 1235 | |
| 1236 | /* Auth might be performed on regular http-req rules as well as on stats */ |
| 1237 | auth_realm = rule->arg.http.str.ptr; |
| 1238 | if (!auth_realm) { |
| 1239 | if (px->uri_auth && s->current_rule_list == &px->uri_auth->http_req_rules) |
| 1240 | auth_realm = STATS_DEFAULT_REALM; |
| 1241 | else |
| 1242 | auth_realm = px->id; |
| 1243 | } |
| 1244 | |
| 1245 | if (!(s->txn->flags & TX_USE_PX_CONN)) { |
| 1246 | s->txn->status = 401; |
| 1247 | hdr = ist("WWW-Authenticate"); |
| 1248 | } |
| 1249 | else { |
| 1250 | s->txn->status = 407; |
| 1251 | hdr = ist("Proxy-Authenticate"); |
| 1252 | } |
| 1253 | reply = http_error_message(s); |
| 1254 | channel_htx_truncate(res, htx); |
| 1255 | |
| 1256 | if (chunk_printf(&trash, "Basic realm=\"%s\"", auth_realm) == -1) |
| 1257 | goto fail; |
| 1258 | |
| 1259 | /* Write the generic 40x message */ |
| 1260 | if (http_reply_to_htx(s, htx, reply) == -1) |
| 1261 | goto fail; |
| 1262 | |
| 1263 | /* Remove all existing occurrences of the XXX-Authenticate header */ |
| 1264 | ctx.blk = NULL; |
| 1265 | while (http_find_header(htx, hdr, &ctx, 1)) |
| 1266 | http_remove_header(htx, &ctx); |
| 1267 | |
| 1268 | /* Now a the right XXX-Authenticate header */ |
| 1269 | if (!http_add_header(htx, hdr, ist2(b_orig(&trash), b_data(&trash)))) |
| 1270 | goto fail; |
| 1271 | |
| 1272 | /* Finally forward the reply */ |
| 1273 | htx_to_buf(htx, &res->buf); |
| 1274 | if (!http_forward_proxy_resp(s, 1)) |
| 1275 | goto fail; |
| 1276 | |
| 1277 | /* Note: Only eval on the request */ |
| 1278 | s->logs.tv_request = now; |
| 1279 | req->analysers &= AN_REQ_FLT_END; |
| 1280 | |
| 1281 | if (s->sess->fe == s->be) /* report it if the request was intercepted by the frontend */ |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1282 | _HA_ATOMIC_INC(&s->sess->fe->fe_counters.intercepted_req); |
Christopher Faulet | b304883 | 2020-05-27 15:26:43 +0200 | [diff] [blame] | 1283 | |
| 1284 | if (!(s->flags & SF_ERR_MASK)) |
| 1285 | s->flags |= SF_ERR_LOCAL; |
| 1286 | if (!(s->flags & SF_FINST_MASK)) |
| 1287 | s->flags |= SF_FINST_R; |
| 1288 | |
| 1289 | stream_inc_http_err_ctr(s); |
| 1290 | return ACT_RET_ABRT; |
| 1291 | |
| 1292 | fail: |
| 1293 | /* If an error occurred, remove the incomplete HTTP response from the |
| 1294 | * buffer */ |
| 1295 | channel_htx_truncate(res, htx); |
| 1296 | return ACT_RET_ERR; |
| 1297 | } |
| 1298 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1299 | /* Parse a "auth" action. It may take 2 optional arguments to define a "realm" |
| 1300 | * parameter. It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 1301 | */ |
| 1302 | static enum act_parse_ret parse_http_auth(const char **args, int *orig_arg, struct proxy *px, |
| 1303 | struct act_rule *rule, char **err) |
| 1304 | { |
| 1305 | int cur_arg; |
| 1306 | |
Christopher Faulet | b304883 | 2020-05-27 15:26:43 +0200 | [diff] [blame] | 1307 | rule->action = ACT_CUSTOM; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 1308 | rule->flags |= ACT_FLAG_FINAL; |
Christopher Faulet | b304883 | 2020-05-27 15:26:43 +0200 | [diff] [blame] | 1309 | rule->action_ptr = http_action_auth; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1310 | rule->release_ptr = release_http_action; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1311 | |
| 1312 | cur_arg = *orig_arg; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1313 | if (strcmp(args[cur_arg], "realm") == 0) { |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1314 | cur_arg++; |
| 1315 | if (!*args[cur_arg]) { |
| 1316 | memprintf(err, "missing realm value.\n"); |
| 1317 | return ACT_RET_PRS_ERR; |
| 1318 | } |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1319 | rule->arg.http.str.ptr = strdup(args[cur_arg]); |
| 1320 | rule->arg.http.str.len = strlen(rule->arg.http.str.ptr); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1321 | cur_arg++; |
| 1322 | } |
| 1323 | |
Christopher Faulet | c20b371 | 2020-01-27 15:51:56 +0100 | [diff] [blame] | 1324 | LIST_INIT(&rule->arg.http.fmt); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1325 | *orig_arg = cur_arg; |
| 1326 | return ACT_RET_PRS_OK; |
| 1327 | } |
| 1328 | |
| 1329 | /* Parse a "set-nice" action. It takes the nice value as argument. It returns |
| 1330 | * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 1331 | */ |
| 1332 | static enum act_parse_ret parse_http_set_nice(const char **args, int *orig_arg, struct proxy *px, |
| 1333 | struct act_rule *rule, char **err) |
| 1334 | { |
| 1335 | int cur_arg; |
| 1336 | |
| 1337 | rule->action = ACT_HTTP_SET_NICE; |
| 1338 | |
| 1339 | cur_arg = *orig_arg; |
| 1340 | if (!*args[cur_arg]) { |
| 1341 | memprintf(err, "expects exactly 1 argument (integer value)"); |
| 1342 | return ACT_RET_PRS_ERR; |
| 1343 | } |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1344 | rule->arg.http.i = atoi(args[cur_arg]); |
| 1345 | if (rule->arg.http.i < -1024) |
| 1346 | rule->arg.http.i = -1024; |
| 1347 | else if (rule->arg.http.i > 1024) |
| 1348 | rule->arg.http.i = 1024; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1349 | |
Christopher Faulet | c20b371 | 2020-01-27 15:51:56 +0100 | [diff] [blame] | 1350 | LIST_INIT(&rule->arg.http.fmt); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1351 | *orig_arg = cur_arg + 1; |
| 1352 | return ACT_RET_PRS_OK; |
| 1353 | } |
| 1354 | |
| 1355 | /* Parse a "set-tos" action. It takes the TOS value as argument. It returns |
| 1356 | * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 1357 | */ |
| 1358 | static enum act_parse_ret parse_http_set_tos(const char **args, int *orig_arg, struct proxy *px, |
| 1359 | struct act_rule *rule, char **err) |
| 1360 | { |
| 1361 | #ifdef IP_TOS |
| 1362 | char *endp; |
| 1363 | int cur_arg; |
| 1364 | |
| 1365 | rule->action = ACT_HTTP_SET_TOS; |
| 1366 | |
| 1367 | cur_arg = *orig_arg; |
| 1368 | if (!*args[cur_arg]) { |
| 1369 | memprintf(err, "expects exactly 1 argument (integer/hex value)"); |
| 1370 | return ACT_RET_PRS_ERR; |
| 1371 | } |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1372 | rule->arg.http.i = strtol(args[cur_arg], &endp, 0); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1373 | if (endp && *endp != '\0') { |
| 1374 | memprintf(err, "invalid character starting at '%s' (integer/hex value expected)", endp); |
| 1375 | return ACT_RET_PRS_ERR; |
| 1376 | } |
| 1377 | |
Christopher Faulet | c20b371 | 2020-01-27 15:51:56 +0100 | [diff] [blame] | 1378 | LIST_INIT(&rule->arg.http.fmt); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1379 | *orig_arg = cur_arg + 1; |
| 1380 | return ACT_RET_PRS_OK; |
| 1381 | #else |
| 1382 | memprintf(err, "not supported on this platform (IP_TOS undefined)"); |
| 1383 | return ACT_RET_PRS_ERR; |
| 1384 | #endif |
| 1385 | } |
| 1386 | |
| 1387 | /* Parse a "set-mark" action. It takes the MARK value as argument. It returns |
| 1388 | * ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 1389 | */ |
| 1390 | static enum act_parse_ret parse_http_set_mark(const char **args, int *orig_arg, struct proxy *px, |
| 1391 | struct act_rule *rule, char **err) |
| 1392 | { |
| 1393 | #ifdef SO_MARK |
| 1394 | char *endp; |
| 1395 | int cur_arg; |
| 1396 | |
| 1397 | rule->action = ACT_HTTP_SET_MARK; |
| 1398 | |
| 1399 | cur_arg = *orig_arg; |
| 1400 | if (!*args[cur_arg]) { |
| 1401 | memprintf(err, "expects exactly 1 argument (integer/hex value)"); |
| 1402 | return ACT_RET_PRS_ERR; |
| 1403 | } |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1404 | rule->arg.http.i = strtoul(args[cur_arg], &endp, 0); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1405 | if (endp && *endp != '\0') { |
| 1406 | memprintf(err, "invalid character starting at '%s' (integer/hex value expected)", endp); |
| 1407 | return ACT_RET_PRS_ERR; |
| 1408 | } |
| 1409 | |
Christopher Faulet | c20b371 | 2020-01-27 15:51:56 +0100 | [diff] [blame] | 1410 | LIST_INIT(&rule->arg.http.fmt); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1411 | *orig_arg = cur_arg + 1; |
| 1412 | global.last_checks |= LSTCHK_NETADM; |
| 1413 | return ACT_RET_PRS_OK; |
| 1414 | #else |
| 1415 | memprintf(err, "not supported on this platform (SO_MARK undefined)"); |
| 1416 | return ACT_RET_PRS_ERR; |
| 1417 | #endif |
| 1418 | } |
| 1419 | |
| 1420 | /* Parse a "set-log-level" action. It takes the level value as argument. It |
| 1421 | * returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
| 1422 | */ |
| 1423 | static enum act_parse_ret parse_http_set_log_level(const char **args, int *orig_arg, struct proxy *px, |
| 1424 | struct act_rule *rule, char **err) |
| 1425 | { |
| 1426 | int cur_arg; |
| 1427 | |
| 1428 | rule->action = ACT_HTTP_SET_LOGL; |
| 1429 | |
| 1430 | cur_arg = *orig_arg; |
| 1431 | if (!*args[cur_arg]) { |
| 1432 | bad_log_level: |
| 1433 | memprintf(err, "expects exactly 1 argument (log level name or 'silent')"); |
| 1434 | return ACT_RET_PRS_ERR; |
| 1435 | } |
| 1436 | if (strcmp(args[cur_arg], "silent") == 0) |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1437 | rule->arg.http.i = -1; |
| 1438 | else if ((rule->arg.http.i = get_log_level(args[cur_arg]) + 1) == 0) |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1439 | goto bad_log_level; |
| 1440 | |
Christopher Faulet | c20b371 | 2020-01-27 15:51:56 +0100 | [diff] [blame] | 1441 | LIST_INIT(&rule->arg.http.fmt); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1442 | *orig_arg = cur_arg + 1; |
| 1443 | return ACT_RET_PRS_OK; |
| 1444 | } |
| 1445 | |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1446 | /* This function executes a early-hint action. It adds an HTTP Early Hint HTTP |
| 1447 | * 103 response header with <.arg.http.str> name and with a value built |
| 1448 | * according to <.arg.http.fmt> log line format. If it is the first early-hint |
Ilya Shipitsin | c02a23f | 2020-05-06 00:53:22 +0500 | [diff] [blame] | 1449 | * rule of series, the 103 response start-line is added first. At the end, if |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1450 | * the next rule is not an early-hint rule or if it is the last rule, the EOH |
| 1451 | * block is added to terminate the response. On success, it returns |
| 1452 | * ACT_RET_CONT. If an error occurs while soft rewrites are enabled, the action |
| 1453 | * is canceled, but the rule processing continue. Otherwsize ACT_RET_ERR is |
| 1454 | * returned. |
| 1455 | */ |
| 1456 | static enum act_return http_action_early_hint(struct act_rule *rule, struct proxy *px, |
| 1457 | struct session *sess, struct stream *s, int flags) |
| 1458 | { |
Christopher Faulet | c68a7fa | 2022-07-05 16:24:15 +0200 | [diff] [blame] | 1459 | struct act_rule *next_rule; |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1460 | struct channel *res = &s->res; |
| 1461 | struct htx *htx = htx_from_buf(&res->buf); |
| 1462 | struct buffer *value = alloc_trash_chunk(); |
| 1463 | enum act_return ret = ACT_RET_CONT; |
| 1464 | |
| 1465 | if (!(s->txn->req.flags & HTTP_MSGF_VER_11)) |
| 1466 | goto leave; |
| 1467 | |
| 1468 | if (!value) { |
| 1469 | if (!(s->flags & SF_ERR_MASK)) |
| 1470 | s->flags |= SF_ERR_RESOURCE; |
| 1471 | goto error; |
| 1472 | } |
| 1473 | |
Christopher Faulet | c68a7fa | 2022-07-05 16:24:15 +0200 | [diff] [blame] | 1474 | /* if there is no pending 103 response, start a new response. Otherwise, |
| 1475 | * continue to add link to a previously started response |
| 1476 | */ |
| 1477 | if (s->txn->status != 103) { |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1478 | struct htx_sl *sl; |
| 1479 | unsigned int flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11| |
| 1480 | HTX_SL_F_XFER_LEN|HTX_SL_F_BODYLESS); |
| 1481 | |
| 1482 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, |
| 1483 | ist("HTTP/1.1"), ist("103"), ist("Early Hints")); |
| 1484 | if (!sl) |
| 1485 | goto error; |
| 1486 | sl->info.res.status = 103; |
Christopher Faulet | c68a7fa | 2022-07-05 16:24:15 +0200 | [diff] [blame] | 1487 | s->txn->status = 103; |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /* Add the HTTP Early Hint HTTP 103 response heade */ |
| 1491 | value->data = build_logline(s, b_tail(value), b_room(value), &rule->arg.http.fmt); |
| 1492 | if (!htx_add_header(htx, rule->arg.http.str, ist2(b_head(value), b_data(value)))) |
| 1493 | goto error; |
| 1494 | |
Christopher Faulet | c68a7fa | 2022-07-05 16:24:15 +0200 | [diff] [blame] | 1495 | /* if it is the last rule or the next one is not an early-hint or an |
| 1496 | * conditional early-hint, terminate the current response. |
| 1497 | */ |
| 1498 | next_rule = LIST_NEXT(&rule->list, typeof(rule), list); |
| 1499 | if (&next_rule->list == s->current_rule_list || next_rule->action_ptr != http_action_early_hint || next_rule->cond) { |
| 1500 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1501 | goto error; |
Christopher Faulet | a72a7e4 | 2020-01-28 09:28:11 +0100 | [diff] [blame] | 1502 | if (!http_forward_proxy_resp(s, 0)) |
| 1503 | goto error; |
Christopher Faulet | c68a7fa | 2022-07-05 16:24:15 +0200 | [diff] [blame] | 1504 | s->txn->status = 0; |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | leave: |
| 1508 | free_trash_chunk(value); |
| 1509 | return ret; |
| 1510 | |
| 1511 | error: |
| 1512 | /* If an error occurred during an Early-hint rule, remove the incomplete |
| 1513 | * HTTP 103 response from the buffer */ |
| 1514 | channel_htx_truncate(res, htx); |
| 1515 | ret = ACT_RET_ERR; |
Christopher Faulet | c68a7fa | 2022-07-05 16:24:15 +0200 | [diff] [blame] | 1516 | s->txn->status = 0; |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1517 | goto leave; |
| 1518 | } |
| 1519 | |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1520 | /* This function executes a set-header or add-header actions. It builds a string |
| 1521 | * in the trash from the specified format string. It finds the action to be |
| 1522 | * performed in <.action>, previously filled by function parse_set_header(). The |
Ilya Shipitsin | c02a23f | 2020-05-06 00:53:22 +0500 | [diff] [blame] | 1523 | * replacement action is executed by the function http_action_set_header(). On |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1524 | * success, it returns ACT_RET_CONT. If an error occurs while soft rewrites are |
| 1525 | * enabled, the action is canceled, but the rule processing continue. Otherwsize |
| 1526 | * ACT_RET_ERR is returned. |
| 1527 | */ |
| 1528 | static enum act_return http_action_set_header(struct act_rule *rule, struct proxy *px, |
| 1529 | struct session *sess, struct stream *s, int flags) |
| 1530 | { |
Christopher Faulet | 91e31d8 | 2020-01-24 15:37:13 +0100 | [diff] [blame] | 1531 | struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp); |
| 1532 | struct htx *htx = htxbuf(&msg->chn->buf); |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1533 | enum act_return ret = ACT_RET_CONT; |
| 1534 | struct buffer *replace; |
| 1535 | struct http_hdr_ctx ctx; |
| 1536 | struct ist n, v; |
| 1537 | |
| 1538 | replace = alloc_trash_chunk(); |
| 1539 | if (!replace) |
| 1540 | goto fail_alloc; |
| 1541 | |
| 1542 | replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt); |
| 1543 | n = rule->arg.http.str; |
| 1544 | v = ist2(replace->area, replace->data); |
| 1545 | |
| 1546 | if (rule->action == 0) { // set-header |
| 1547 | /* remove all occurrences of the header */ |
| 1548 | ctx.blk = NULL; |
| 1549 | while (http_find_header(htx, n, &ctx, 1)) |
| 1550 | http_remove_header(htx, &ctx); |
| 1551 | } |
| 1552 | |
| 1553 | /* Now add header */ |
| 1554 | if (!http_add_header(htx, n, v)) |
| 1555 | goto fail_rewrite; |
| 1556 | |
| 1557 | leave: |
| 1558 | free_trash_chunk(replace); |
| 1559 | return ret; |
| 1560 | |
| 1561 | fail_alloc: |
| 1562 | if (!(s->flags & SF_ERR_MASK)) |
| 1563 | s->flags |= SF_ERR_RESOURCE; |
| 1564 | ret = ACT_RET_ERR; |
| 1565 | goto leave; |
| 1566 | |
| 1567 | fail_rewrite: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1568 | _HA_ATOMIC_INC(&sess->fe->fe_counters.failed_rewrites); |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1569 | if (s->flags & SF_BE_ASSIGNED) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1570 | _HA_ATOMIC_INC(&s->be->be_counters.failed_rewrites); |
William Lallemand | 36119de | 2021-03-08 15:26:48 +0100 | [diff] [blame] | 1571 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1572 | _HA_ATOMIC_INC(&sess->listener->counters->failed_rewrites); |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1573 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1574 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.failed_rewrites); |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1575 | |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 1576 | if (!(msg->flags & HTTP_MSGF_SOFT_RW)) { |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1577 | ret = ACT_RET_ERR; |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 1578 | if (!(s->flags & SF_ERR_MASK)) |
| 1579 | s->flags |= SF_ERR_PRXCOND; |
| 1580 | } |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1581 | goto leave; |
| 1582 | } |
| 1583 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1584 | /* Parse a "set-header", "add-header" or "early-hint" actions. It takes an |
| 1585 | * header name and a log-format string as arguments. It returns ACT_RET_PRS_OK |
| 1586 | * on success, ACT_RET_PRS_ERR on error. |
| 1587 | * |
| 1588 | * Note: same function is used for the request and the response. However |
| 1589 | * "early-hint" rules are only supported for request rules. |
| 1590 | */ |
| 1591 | static enum act_parse_ret parse_http_set_header(const char **args, int *orig_arg, struct proxy *px, |
| 1592 | struct act_rule *rule, char **err) |
| 1593 | { |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 1594 | int cap = 0, cur_arg; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1595 | |
Christopher Faulet | 91b3ec1 | 2020-01-17 22:30:06 +0100 | [diff] [blame] | 1596 | if (args[*orig_arg-1][0] == 'e') { |
| 1597 | rule->action = ACT_CUSTOM; |
| 1598 | rule->action_ptr = http_action_early_hint; |
| 1599 | } |
Christopher Faulet | d1f27e3 | 2019-12-17 09:33:38 +0100 | [diff] [blame] | 1600 | else { |
| 1601 | if (args[*orig_arg-1][0] == 's') |
| 1602 | rule->action = 0; // set-header |
| 1603 | else |
| 1604 | rule->action = 1; // add-header |
| 1605 | rule->action_ptr = http_action_set_header; |
| 1606 | } |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1607 | rule->release_ptr = release_http_action; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1608 | |
| 1609 | cur_arg = *orig_arg; |
| 1610 | if (!*args[cur_arg] || !*args[cur_arg+1]) { |
| 1611 | memprintf(err, "expects exactly 2 arguments"); |
| 1612 | return ACT_RET_PRS_ERR; |
| 1613 | } |
| 1614 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1615 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1616 | rule->arg.http.str.ptr = strdup(args[cur_arg]); |
| 1617 | rule->arg.http.str.len = strlen(rule->arg.http.str.ptr); |
| 1618 | LIST_INIT(&rule->arg.http.fmt); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1619 | |
| 1620 | if (rule->from == ACT_F_HTTP_REQ) { |
| 1621 | px->conf.args.ctx = ARGC_HRQ; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 1622 | if (px->cap & PR_CAP_FE) |
| 1623 | cap |= SMP_VAL_FE_HRQ_HDR; |
| 1624 | if (px->cap & PR_CAP_BE) |
| 1625 | cap |= SMP_VAL_BE_HRQ_HDR; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1626 | } |
| 1627 | else{ |
| 1628 | px->conf.args.ctx = ARGC_HRS; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 1629 | if (px->cap & PR_CAP_FE) |
| 1630 | cap |= SMP_VAL_FE_HRS_HDR; |
| 1631 | if (px->cap & PR_CAP_BE) |
| 1632 | cap |= SMP_VAL_BE_HRS_HDR; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | cur_arg++; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1636 | if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) { |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 1637 | istfree(&rule->arg.http.str); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1638 | return ACT_RET_PRS_ERR; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1639 | } |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1640 | |
| 1641 | free(px->conf.lfs_file); |
| 1642 | px->conf.lfs_file = strdup(px->conf.args.file); |
| 1643 | px->conf.lfs_line = px->conf.args.line; |
| 1644 | |
| 1645 | *orig_arg = cur_arg + 1; |
| 1646 | return ACT_RET_PRS_OK; |
| 1647 | } |
| 1648 | |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1649 | /* This function executes a replace-header or replace-value actions. It |
| 1650 | * builds a string in the trash from the specified format string. It finds |
| 1651 | * the action to be performed in <.action>, previously filled by function |
Ilya Shipitsin | c02a23f | 2020-05-06 00:53:22 +0500 | [diff] [blame] | 1652 | * parse_replace_header(). The replacement action is executed by the function |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1653 | * http_action_replace_header(). On success, it returns ACT_RET_CONT. If an error |
| 1654 | * occurs while soft rewrites are enabled, the action is canceled, but the rule |
| 1655 | * processing continue. Otherwsize ACT_RET_ERR is returned. |
| 1656 | */ |
| 1657 | static enum act_return http_action_replace_header(struct act_rule *rule, struct proxy *px, |
| 1658 | struct session *sess, struct stream *s, int flags) |
| 1659 | { |
Christopher Faulet | 91e31d8 | 2020-01-24 15:37:13 +0100 | [diff] [blame] | 1660 | struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp); |
| 1661 | struct htx *htx = htxbuf(&msg->chn->buf); |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1662 | enum act_return ret = ACT_RET_CONT; |
| 1663 | struct buffer *replace; |
| 1664 | int r; |
| 1665 | |
| 1666 | replace = alloc_trash_chunk(); |
| 1667 | if (!replace) |
| 1668 | goto fail_alloc; |
| 1669 | |
| 1670 | replace->data = build_logline(s, replace->area, replace->size, &rule->arg.http.fmt); |
| 1671 | |
| 1672 | r = http_replace_hdrs(s, htx, rule->arg.http.str, replace->area, rule->arg.http.re, (rule->action == 0)); |
| 1673 | if (r == -1) |
| 1674 | goto fail_rewrite; |
| 1675 | |
| 1676 | leave: |
| 1677 | free_trash_chunk(replace); |
| 1678 | return ret; |
| 1679 | |
| 1680 | fail_alloc: |
| 1681 | if (!(s->flags & SF_ERR_MASK)) |
| 1682 | s->flags |= SF_ERR_RESOURCE; |
| 1683 | ret = ACT_RET_ERR; |
| 1684 | goto leave; |
| 1685 | |
| 1686 | fail_rewrite: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1687 | _HA_ATOMIC_INC(&sess->fe->fe_counters.failed_rewrites); |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1688 | if (s->flags & SF_BE_ASSIGNED) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1689 | _HA_ATOMIC_INC(&s->be->be_counters.failed_rewrites); |
William Lallemand | 36119de | 2021-03-08 15:26:48 +0100 | [diff] [blame] | 1690 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1691 | _HA_ATOMIC_INC(&sess->listener->counters->failed_rewrites); |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1692 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1693 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.failed_rewrites); |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1694 | |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 1695 | if (!(msg->flags & HTTP_MSGF_SOFT_RW)) { |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1696 | ret = ACT_RET_ERR; |
Christopher Faulet | 333bf8c | 2020-01-22 14:38:05 +0100 | [diff] [blame] | 1697 | if (!(s->flags & SF_ERR_MASK)) |
| 1698 | s->flags |= SF_ERR_PRXCOND; |
| 1699 | } |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1700 | goto leave; |
| 1701 | } |
| 1702 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1703 | /* Parse a "replace-header" or "replace-value" actions. It takes an header name, |
| 1704 | * a regex and replacement string as arguments. It returns ACT_RET_PRS_OK on |
| 1705 | * success, ACT_RET_PRS_ERR on error. |
| 1706 | */ |
| 1707 | static enum act_parse_ret parse_http_replace_header(const char **args, int *orig_arg, struct proxy *px, |
| 1708 | struct act_rule *rule, char **err) |
| 1709 | { |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 1710 | int cap = 0, cur_arg; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1711 | |
Christopher Faulet | 92d34fe | 2019-12-17 09:20:34 +0100 | [diff] [blame] | 1712 | if (args[*orig_arg-1][8] == 'h') |
| 1713 | rule->action = 0; // replace-header |
| 1714 | else |
| 1715 | rule->action = 1; // replace-value |
| 1716 | rule->action_ptr = http_action_replace_header; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1717 | rule->release_ptr = release_http_action; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1718 | |
| 1719 | cur_arg = *orig_arg; |
| 1720 | if (!*args[cur_arg] || !*args[cur_arg+1] || !*args[cur_arg+2]) { |
| 1721 | memprintf(err, "expects exactly 3 arguments"); |
| 1722 | return ACT_RET_PRS_ERR; |
| 1723 | } |
| 1724 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1725 | rule->arg.http.str.ptr = strdup(args[cur_arg]); |
| 1726 | rule->arg.http.str.len = strlen(rule->arg.http.str.ptr); |
| 1727 | LIST_INIT(&rule->arg.http.fmt); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1728 | |
| 1729 | cur_arg++; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1730 | if (!(rule->arg.http.re = regex_comp(args[cur_arg], 1, 1, err))) { |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 1731 | istfree(&rule->arg.http.str); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1732 | return ACT_RET_PRS_ERR; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1733 | } |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1734 | |
| 1735 | if (rule->from == ACT_F_HTTP_REQ) { |
| 1736 | px->conf.args.ctx = ARGC_HRQ; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 1737 | if (px->cap & PR_CAP_FE) |
| 1738 | cap |= SMP_VAL_FE_HRQ_HDR; |
| 1739 | if (px->cap & PR_CAP_BE) |
| 1740 | cap |= SMP_VAL_BE_HRQ_HDR; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1741 | } |
| 1742 | else{ |
| 1743 | px->conf.args.ctx = ARGC_HRS; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 1744 | if (px->cap & PR_CAP_FE) |
| 1745 | cap |= SMP_VAL_FE_HRS_HDR; |
| 1746 | if (px->cap & PR_CAP_BE) |
| 1747 | cap |= SMP_VAL_BE_HRS_HDR; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | cur_arg++; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1751 | if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) { |
Tim Duesterhus | ed52637 | 2020-03-05 17:56:33 +0100 | [diff] [blame] | 1752 | istfree(&rule->arg.http.str); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1753 | regex_free(rule->arg.http.re); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1754 | return ACT_RET_PRS_ERR; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 1755 | } |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1756 | |
| 1757 | free(px->conf.lfs_file); |
| 1758 | px->conf.lfs_file = strdup(px->conf.args.file); |
| 1759 | px->conf.lfs_line = px->conf.args.line; |
| 1760 | |
| 1761 | *orig_arg = cur_arg + 1; |
| 1762 | return ACT_RET_PRS_OK; |
| 1763 | } |
| 1764 | |
Maciej Zdeb | ebdd4c5 | 2020-11-20 13:58:48 +0000 | [diff] [blame] | 1765 | /* This function executes a del-header action with selected matching mode for |
| 1766 | * header name. It finds the matching method to be performed in <.action>, previously |
| 1767 | * filled by function parse_http_del_header(). On success, it returns ACT_RET_CONT. |
| 1768 | * Otherwise ACT_RET_ERR is returned. |
| 1769 | */ |
| 1770 | static enum act_return http_action_del_header(struct act_rule *rule, struct proxy *px, |
| 1771 | struct session *sess, struct stream *s, int flags) |
| 1772 | { |
| 1773 | struct http_hdr_ctx ctx; |
| 1774 | struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp); |
| 1775 | struct htx *htx = htxbuf(&msg->chn->buf); |
| 1776 | enum act_return ret = ACT_RET_CONT; |
| 1777 | |
| 1778 | /* remove all occurrences of the header */ |
| 1779 | ctx.blk = NULL; |
| 1780 | switch (rule->action) { |
| 1781 | case PAT_MATCH_STR: |
| 1782 | while (http_find_header(htx, rule->arg.http.str, &ctx, 1)) |
| 1783 | http_remove_header(htx, &ctx); |
| 1784 | break; |
| 1785 | case PAT_MATCH_BEG: |
| 1786 | while (http_find_pfx_header(htx, rule->arg.http.str, &ctx, 1)) |
| 1787 | http_remove_header(htx, &ctx); |
| 1788 | break; |
| 1789 | case PAT_MATCH_END: |
| 1790 | while (http_find_sfx_header(htx, rule->arg.http.str, &ctx, 1)) |
| 1791 | http_remove_header(htx, &ctx); |
| 1792 | break; |
| 1793 | case PAT_MATCH_SUB: |
| 1794 | while (http_find_sub_header(htx, rule->arg.http.str, &ctx, 1)) |
| 1795 | http_remove_header(htx, &ctx); |
| 1796 | break; |
| 1797 | case PAT_MATCH_REG: |
| 1798 | while (http_match_header(htx, rule->arg.http.re, &ctx, 1)) |
| 1799 | http_remove_header(htx, &ctx); |
| 1800 | break; |
| 1801 | default: |
| 1802 | return ACT_RET_ERR; |
| 1803 | } |
| 1804 | return ret; |
| 1805 | } |
| 1806 | |
| 1807 | /* Parse a "del-header" action. It takes string as a required argument, |
| 1808 | * optional flag (currently only -m) and optional matching method of input string |
| 1809 | * with header name to be deleted. Default matching method is exact match (-m str). |
| 1810 | * It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1811 | */ |
| 1812 | static enum act_parse_ret parse_http_del_header(const char **args, int *orig_arg, struct proxy *px, |
| 1813 | struct act_rule *rule, char **err) |
| 1814 | { |
| 1815 | int cur_arg; |
Maciej Zdeb | ebdd4c5 | 2020-11-20 13:58:48 +0000 | [diff] [blame] | 1816 | int pat_idx; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1817 | |
Maciej Zdeb | ebdd4c5 | 2020-11-20 13:58:48 +0000 | [diff] [blame] | 1818 | /* set exact matching (-m str) as default */ |
| 1819 | rule->action = PAT_MATCH_STR; |
| 1820 | rule->action_ptr = http_action_del_header; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1821 | rule->release_ptr = release_http_action; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1822 | |
| 1823 | cur_arg = *orig_arg; |
| 1824 | if (!*args[cur_arg]) { |
Maciej Zdeb | ebdd4c5 | 2020-11-20 13:58:48 +0000 | [diff] [blame] | 1825 | memprintf(err, "expects at least 1 argument"); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1826 | return ACT_RET_PRS_ERR; |
| 1827 | } |
| 1828 | |
Christopher Faulet | 96bff76 | 2019-12-17 13:46:18 +0100 | [diff] [blame] | 1829 | rule->arg.http.str.ptr = strdup(args[cur_arg]); |
| 1830 | rule->arg.http.str.len = strlen(rule->arg.http.str.ptr); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1831 | px->conf.args.ctx = (rule->from == ACT_F_HTTP_REQ ? ARGC_HRQ : ARGC_HRS); |
| 1832 | |
Maciej Zdeb | 6dee996 | 2020-11-23 16:03:09 +0000 | [diff] [blame] | 1833 | LIST_INIT(&rule->arg.http.fmt); |
Maciej Zdeb | ebdd4c5 | 2020-11-20 13:58:48 +0000 | [diff] [blame] | 1834 | if (strcmp(args[cur_arg+1], "-m") == 0) { |
| 1835 | cur_arg++; |
| 1836 | if (!*args[cur_arg+1]) { |
| 1837 | memprintf(err, "-m flag expects exactly 1 argument"); |
| 1838 | return ACT_RET_PRS_ERR; |
| 1839 | } |
| 1840 | |
| 1841 | cur_arg++; |
| 1842 | pat_idx = pat_find_match_name(args[cur_arg]); |
| 1843 | switch (pat_idx) { |
| 1844 | case PAT_MATCH_REG: |
| 1845 | if (!(rule->arg.http.re = regex_comp(rule->arg.http.str.ptr, 1, 1, err))) |
| 1846 | return ACT_RET_PRS_ERR; |
| 1847 | /* fall through */ |
| 1848 | case PAT_MATCH_STR: |
| 1849 | case PAT_MATCH_BEG: |
| 1850 | case PAT_MATCH_END: |
| 1851 | case PAT_MATCH_SUB: |
| 1852 | rule->action = pat_idx; |
| 1853 | break; |
| 1854 | default: |
| 1855 | memprintf(err, "-m with unsupported matching method '%s'", args[cur_arg]); |
| 1856 | return ACT_RET_PRS_ERR; |
| 1857 | } |
| 1858 | } |
| 1859 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1860 | *orig_arg = cur_arg + 1; |
| 1861 | return ACT_RET_PRS_OK; |
| 1862 | } |
| 1863 | |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1864 | /* Release memory allocated by an http redirect action. */ |
| 1865 | static void release_http_redir(struct act_rule *rule) |
| 1866 | { |
| 1867 | struct logformat_node *lf, *lfb; |
| 1868 | struct redirect_rule *redir; |
| 1869 | |
| 1870 | redir = rule->arg.redir; |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1871 | LIST_DELETE(&redir->list); |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1872 | if (redir->cond) { |
| 1873 | prune_acl_cond(redir->cond); |
| 1874 | free(redir->cond); |
| 1875 | } |
| 1876 | free(redir->rdr_str); |
| 1877 | free(redir->cookie_str); |
| 1878 | list_for_each_entry_safe(lf, lfb, &redir->rdr_fmt, list) { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1879 | LIST_DELETE(&lf->list); |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1880 | free(lf); |
| 1881 | } |
| 1882 | free(redir); |
| 1883 | } |
| 1884 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1885 | /* Parse a "redirect" action. It returns ACT_RET_PRS_OK on success, |
| 1886 | * ACT_RET_PRS_ERR on error. |
| 1887 | */ |
| 1888 | static enum act_parse_ret parse_http_redirect(const char **args, int *orig_arg, struct proxy *px, |
| 1889 | struct act_rule *rule, char **err) |
| 1890 | { |
| 1891 | struct redirect_rule *redir; |
| 1892 | int dir, cur_arg; |
| 1893 | |
| 1894 | rule->action = ACT_HTTP_REDIR; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 1895 | rule->flags |= ACT_FLAG_FINAL; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1896 | rule->release_ptr = release_http_redir; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 1897 | |
| 1898 | cur_arg = *orig_arg; |
| 1899 | |
| 1900 | dir = (rule->from == ACT_F_HTTP_REQ ? 0 : 1); |
| 1901 | if ((redir = http_parse_redirect_rule(px->conf.args.file, px->conf.args.line, px, &args[cur_arg], err, 1, dir)) == NULL) |
| 1902 | return ACT_RET_PRS_ERR; |
| 1903 | |
| 1904 | rule->arg.redir = redir; |
| 1905 | rule->cond = redir->cond; |
| 1906 | redir->cond = NULL; |
| 1907 | |
| 1908 | /* skip all arguments */ |
| 1909 | while (*args[cur_arg]) |
| 1910 | cur_arg++; |
| 1911 | |
| 1912 | *orig_arg = cur_arg; |
| 1913 | return ACT_RET_PRS_OK; |
| 1914 | } |
| 1915 | |
Christopher Faulet | 046cf44 | 2019-12-17 15:45:23 +0100 | [diff] [blame] | 1916 | /* This function executes a add-acl, del-acl, set-map or del-map actions. On |
| 1917 | * success, it returns ACT_RET_CONT. Otherwsize ACT_RET_ERR is returned. |
| 1918 | */ |
| 1919 | static enum act_return http_action_set_map(struct act_rule *rule, struct proxy *px, |
| 1920 | struct session *sess, struct stream *s, int flags) |
| 1921 | { |
| 1922 | struct pat_ref *ref; |
| 1923 | struct buffer *key = NULL, *value = NULL; |
| 1924 | enum act_return ret = ACT_RET_CONT; |
| 1925 | |
| 1926 | /* collect reference */ |
| 1927 | ref = pat_ref_lookup(rule->arg.map.ref); |
| 1928 | if (!ref) |
| 1929 | goto leave; |
| 1930 | |
| 1931 | /* allocate key */ |
| 1932 | key = alloc_trash_chunk(); |
| 1933 | if (!key) |
| 1934 | goto fail_alloc; |
| 1935 | |
| 1936 | /* collect key */ |
| 1937 | key->data = build_logline(s, key->area, key->size, &rule->arg.map.key); |
| 1938 | key->area[key->data] = '\0'; |
| 1939 | |
| 1940 | switch (rule->action) { |
| 1941 | case 0: // add-acl |
| 1942 | /* add entry only if it does not already exist */ |
| 1943 | HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); |
| 1944 | if (pat_ref_find_elt(ref, key->area) == NULL) |
| 1945 | pat_ref_add(ref, key->area, NULL, NULL); |
| 1946 | HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); |
| 1947 | break; |
| 1948 | |
| 1949 | case 1: // set-map |
| 1950 | /* allocate value */ |
| 1951 | value = alloc_trash_chunk(); |
| 1952 | if (!value) |
| 1953 | goto fail_alloc; |
| 1954 | |
| 1955 | /* collect value */ |
| 1956 | value->data = build_logline(s, value->area, value->size, &rule->arg.map.value); |
| 1957 | value->area[value->data] = '\0'; |
| 1958 | |
| 1959 | HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); |
| 1960 | if (pat_ref_find_elt(ref, key->area) != NULL) { |
| 1961 | /* update entry if it exists */ |
| 1962 | pat_ref_set(ref, key->area, value->area, NULL); |
| 1963 | } |
| 1964 | else { |
| 1965 | /* insert a new entry */ |
| 1966 | pat_ref_add(ref, key->area, value->area, NULL); |
| 1967 | } |
| 1968 | HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); |
| 1969 | break; |
| 1970 | |
| 1971 | case 2: // del-acl |
| 1972 | case 3: // del-map |
| 1973 | /* returned code: 1=ok, 0=ko */ |
| 1974 | HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); |
| 1975 | pat_ref_delete(ref, key->area); |
| 1976 | HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); |
| 1977 | break; |
| 1978 | |
| 1979 | default: |
| 1980 | ret = ACT_RET_ERR; |
| 1981 | } |
| 1982 | |
| 1983 | |
| 1984 | leave: |
| 1985 | free_trash_chunk(key); |
| 1986 | free_trash_chunk(value); |
| 1987 | return ret; |
| 1988 | |
| 1989 | fail_alloc: |
| 1990 | if (!(s->flags & SF_ERR_MASK)) |
| 1991 | s->flags |= SF_ERR_RESOURCE; |
| 1992 | ret = ACT_RET_ERR; |
| 1993 | goto leave; |
| 1994 | } |
| 1995 | |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 1996 | /* Release memory allocated by an http map/acl action. */ |
| 1997 | static void release_http_map(struct act_rule *rule) |
| 1998 | { |
| 1999 | struct logformat_node *lf, *lfb; |
| 2000 | |
| 2001 | free(rule->arg.map.ref); |
| 2002 | list_for_each_entry_safe(lf, lfb, &rule->arg.map.key, list) { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 2003 | LIST_DELETE(&lf->list); |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 2004 | release_sample_expr(lf->expr); |
| 2005 | free(lf->arg); |
| 2006 | free(lf); |
| 2007 | } |
| 2008 | if (rule->action == 1) { |
| 2009 | list_for_each_entry_safe(lf, lfb, &rule->arg.map.value, list) { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 2010 | LIST_DELETE(&lf->list); |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 2011 | release_sample_expr(lf->expr); |
| 2012 | free(lf->arg); |
| 2013 | free(lf); |
| 2014 | } |
| 2015 | } |
| 2016 | } |
| 2017 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2018 | /* Parse a "add-acl", "del-acl", "set-map" or "del-map" actions. It takes one or |
Christopher Faulet | 046cf44 | 2019-12-17 15:45:23 +0100 | [diff] [blame] | 2019 | * two log-format string as argument depending on the action. The action is |
| 2020 | * stored in <.action> as an int (0=add-acl, 1=set-map, 2=del-acl, |
| 2021 | * 3=del-map). It returns ACT_RET_PRS_OK on success, ACT_RET_PRS_ERR on error. |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2022 | */ |
| 2023 | static enum act_parse_ret parse_http_set_map(const char **args, int *orig_arg, struct proxy *px, |
| 2024 | struct act_rule *rule, char **err) |
| 2025 | { |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 2026 | int cap = 0, cur_arg; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2027 | |
Christopher Faulet | 046cf44 | 2019-12-17 15:45:23 +0100 | [diff] [blame] | 2028 | if (args[*orig_arg-1][0] == 'a') // add-acl |
| 2029 | rule->action = 0; |
| 2030 | else if (args[*orig_arg-1][0] == 's') // set-map |
| 2031 | rule->action = 1; |
| 2032 | else if (args[*orig_arg-1][4] == 'a') // del-acl |
| 2033 | rule->action = 2; |
| 2034 | else if (args[*orig_arg-1][4] == 'm') // del-map |
| 2035 | rule->action = 3; |
| 2036 | else { |
| 2037 | memprintf(err, "internal error: unhandled action '%s'", args[0]); |
| 2038 | return ACT_RET_PRS_ERR; |
| 2039 | } |
| 2040 | rule->action_ptr = http_action_set_map; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 2041 | rule->release_ptr = release_http_map; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2042 | |
| 2043 | cur_arg = *orig_arg; |
Christopher Faulet | 046cf44 | 2019-12-17 15:45:23 +0100 | [diff] [blame] | 2044 | if (rule->action == 1 && (!*args[cur_arg] || !*args[cur_arg+1])) { |
| 2045 | /* 2 args for set-map */ |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2046 | memprintf(err, "expects exactly 2 arguments"); |
| 2047 | return ACT_RET_PRS_ERR; |
| 2048 | } |
| 2049 | else if (!*args[cur_arg]) { |
Christopher Faulet | 046cf44 | 2019-12-17 15:45:23 +0100 | [diff] [blame] | 2050 | /* only one arg for other actions */ |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2051 | memprintf(err, "expects exactly 1 arguments"); |
| 2052 | return ACT_RET_PRS_ERR; |
| 2053 | } |
| 2054 | |
| 2055 | /* |
| 2056 | * '+ 8' for 'set-map(' (same for del-map) |
| 2057 | * '- 9' for 'set-map(' + trailing ')' (same for del-map) |
| 2058 | */ |
| 2059 | rule->arg.map.ref = my_strndup(args[cur_arg-1] + 8, strlen(args[cur_arg-1]) - 9); |
| 2060 | |
| 2061 | if (rule->from == ACT_F_HTTP_REQ) { |
| 2062 | px->conf.args.ctx = ARGC_HRQ; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 2063 | if (px->cap & PR_CAP_FE) |
| 2064 | cap |= SMP_VAL_FE_HRQ_HDR; |
| 2065 | if (px->cap & PR_CAP_BE) |
| 2066 | cap |= SMP_VAL_BE_HRQ_HDR; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2067 | } |
| 2068 | else{ |
| 2069 | px->conf.args.ctx = ARGC_HRS; |
Christopher Faulet | 5f802b3 | 2021-10-13 17:22:17 +0200 | [diff] [blame] | 2070 | if (px->cap & PR_CAP_FE) |
| 2071 | cap |= SMP_VAL_FE_HRS_HDR; |
| 2072 | if (px->cap & PR_CAP_BE) |
| 2073 | cap |= SMP_VAL_BE_HRS_HDR; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | /* key pattern */ |
| 2077 | LIST_INIT(&rule->arg.map.key); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 2078 | if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.key, LOG_OPT_HTTP, cap, err)) { |
| 2079 | free(rule->arg.map.ref); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2080 | return ACT_RET_PRS_ERR; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 2081 | } |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2082 | |
Christopher Faulet | 046cf44 | 2019-12-17 15:45:23 +0100 | [diff] [blame] | 2083 | if (rule->action == 1) { |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2084 | /* value pattern for set-map only */ |
| 2085 | cur_arg++; |
| 2086 | LIST_INIT(&rule->arg.map.value); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 2087 | if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.value, LOG_OPT_HTTP, cap, err)) { |
| 2088 | free(rule->arg.map.ref); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2089 | return ACT_RET_PRS_ERR; |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 2090 | } |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | free(px->conf.lfs_file); |
| 2094 | px->conf.lfs_file = strdup(px->conf.args.file); |
| 2095 | px->conf.lfs_line = px->conf.args.line; |
| 2096 | |
| 2097 | *orig_arg = cur_arg + 1; |
| 2098 | return ACT_RET_PRS_OK; |
| 2099 | } |
| 2100 | |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2101 | /* This function executes a track-sc* actions. On success, it returns |
| 2102 | * ACT_RET_CONT. Otherwsize ACT_RET_ERR is returned. |
| 2103 | */ |
| 2104 | static enum act_return http_action_track_sc(struct act_rule *rule, struct proxy *px, |
| 2105 | struct session *sess, struct stream *s, int flags) |
| 2106 | { |
| 2107 | struct stktable *t; |
| 2108 | struct stksess *ts; |
| 2109 | struct stktable_key *key; |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2110 | void *ptr1, *ptr2, *ptr3, *ptr4, *ptr5, *ptr6; |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2111 | int opt; |
| 2112 | |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2113 | ptr1 = ptr2 = ptr3 = ptr4 = ptr5 = ptr6 = NULL; |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2114 | opt = ((rule->from == ACT_F_HTTP_REQ) ? SMP_OPT_DIR_REQ : SMP_OPT_DIR_RES) | SMP_OPT_FINAL; |
| 2115 | |
| 2116 | t = rule->arg.trk_ctr.table.t; |
Emeric Brun | 362d25e | 2021-03-10 16:58:03 +0100 | [diff] [blame] | 2117 | |
| 2118 | if (stkctr_entry(&s->stkctr[rule->action])) |
| 2119 | goto end; |
| 2120 | |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2121 | key = stktable_fetch_key(t, s->be, sess, s, opt, rule->arg.trk_ctr.expr, NULL); |
| 2122 | |
| 2123 | if (!key) |
| 2124 | goto end; |
| 2125 | ts = stktable_get_entry(t, key); |
| 2126 | if (!ts) |
| 2127 | goto end; |
| 2128 | |
| 2129 | stream_track_stkctr(&s->stkctr[rule->action], t, ts); |
| 2130 | |
| 2131 | /* let's count a new HTTP request as it's the first time we do it */ |
| 2132 | ptr1 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT); |
| 2133 | ptr2 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE); |
| 2134 | |
| 2135 | /* When the client triggers a 4xx from the server, it's most often due |
| 2136 | * to a missing object or permission. These events should be tracked |
| 2137 | * because if they happen often, it may indicate a brute force or a |
| 2138 | * vulnerability scan. Normally this is done when receiving the response |
| 2139 | * but here we're tracking after this ought to have been done so we have |
| 2140 | * to do it on purpose. |
| 2141 | */ |
| 2142 | if (rule->from == ACT_F_HTTP_RES && (unsigned)(s->txn->status - 400) < 100) { |
| 2143 | ptr3 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT); |
| 2144 | ptr4 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE); |
| 2145 | } |
| 2146 | |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2147 | if (rule->from == ACT_F_HTTP_RES && (unsigned)(s->txn->status - 500) < 100 && |
| 2148 | s->txn->status != 501 && s->txn->status != 505) { |
| 2149 | ptr5 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_CNT); |
| 2150 | ptr6 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_RATE); |
| 2151 | } |
| 2152 | |
| 2153 | if (ptr1 || ptr2 || ptr3 || ptr4 || ptr5 || ptr6) { |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2154 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2155 | |
| 2156 | if (ptr1) |
| 2157 | stktable_data_cast(ptr1, http_req_cnt)++; |
| 2158 | if (ptr2) |
| 2159 | update_freq_ctr_period(&stktable_data_cast(ptr2, http_req_rate), |
| 2160 | t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1); |
| 2161 | if (ptr3) |
| 2162 | stktable_data_cast(ptr3, http_err_cnt)++; |
| 2163 | if (ptr4) |
| 2164 | update_freq_ctr_period(&stktable_data_cast(ptr4, http_err_rate), |
| 2165 | t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2166 | if (ptr5) |
| 2167 | stktable_data_cast(ptr5, http_fail_cnt)++; |
| 2168 | if (ptr6) |
| 2169 | update_freq_ctr_period(&stktable_data_cast(ptr6, http_fail_rate), |
| 2170 | t->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u, 1); |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2171 | |
| 2172 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2173 | |
| 2174 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2175 | stktable_touch_local(t, ts, 0); |
| 2176 | } |
| 2177 | |
| 2178 | stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_CONTENT); |
| 2179 | if (sess->fe != s->be) |
| 2180 | stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_BACKEND); |
| 2181 | |
| 2182 | end: |
| 2183 | return ACT_RET_CONT; |
| 2184 | } |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2185 | |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 2186 | static void release_http_track_sc(struct act_rule *rule) |
| 2187 | { |
| 2188 | release_sample_expr(rule->arg.trk_ctr.expr); |
| 2189 | } |
| 2190 | |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2191 | /* Parse a "track-sc*" actions. It returns ACT_RET_PRS_OK on success, |
| 2192 | * ACT_RET_PRS_ERR on error. |
| 2193 | */ |
| 2194 | static enum act_parse_ret parse_http_track_sc(const char **args, int *orig_arg, struct proxy *px, |
| 2195 | struct act_rule *rule, char **err) |
| 2196 | { |
| 2197 | struct sample_expr *expr; |
| 2198 | unsigned int where; |
| 2199 | unsigned int tsc_num; |
| 2200 | const char *tsc_num_str; |
| 2201 | int cur_arg; |
| 2202 | |
| 2203 | tsc_num_str = &args[*orig_arg-1][8]; |
| 2204 | if (cfg_parse_track_sc_num(&tsc_num, tsc_num_str, tsc_num_str + strlen(tsc_num_str), err) == -1) |
| 2205 | return ACT_RET_PRS_ERR; |
| 2206 | |
| 2207 | cur_arg = *orig_arg; |
| 2208 | expr = sample_parse_expr((char **)args, &cur_arg, px->conf.args.file, px->conf.args.line, |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 2209 | err, &px->conf.args, NULL); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2210 | if (!expr) |
| 2211 | return ACT_RET_PRS_ERR; |
| 2212 | |
| 2213 | where = 0; |
| 2214 | if (px->cap & PR_CAP_FE) |
| 2215 | where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_FE_HRS_HDR); |
| 2216 | if (px->cap & PR_CAP_BE) |
| 2217 | where |= (rule->from == ACT_F_HTTP_REQ ? SMP_VAL_BE_HRQ_HDR : SMP_VAL_BE_HRS_HDR); |
| 2218 | |
| 2219 | if (!(expr->fetch->val & where)) { |
| 2220 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", |
| 2221 | args[cur_arg-1], sample_src_names(expr->fetch->use)); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 2222 | release_sample_expr(expr); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2223 | return ACT_RET_PRS_ERR; |
| 2224 | } |
| 2225 | |
| 2226 | if (strcmp(args[cur_arg], "table") == 0) { |
| 2227 | cur_arg++; |
| 2228 | if (!*args[cur_arg]) { |
| 2229 | memprintf(err, "missing table name"); |
Christopher Faulet | 1337b32 | 2020-01-14 14:50:55 +0100 | [diff] [blame] | 2230 | release_sample_expr(expr); |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2231 | return ACT_RET_PRS_ERR; |
| 2232 | } |
| 2233 | |
| 2234 | /* we copy the table name for now, it will be resolved later */ |
| 2235 | rule->arg.trk_ctr.table.n = strdup(args[cur_arg]); |
| 2236 | cur_arg++; |
| 2237 | } |
| 2238 | |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2239 | rule->action = tsc_num; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2240 | rule->arg.trk_ctr.expr = expr; |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 2241 | rule->action_ptr = http_action_track_sc; |
Christopher Faulet | 2eb5396 | 2020-01-14 14:47:34 +0100 | [diff] [blame] | 2242 | rule->release_ptr = release_http_track_sc; |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2243 | rule->check_ptr = check_trk_action; |
| 2244 | |
| 2245 | *orig_arg = cur_arg; |
| 2246 | return ACT_RET_PRS_OK; |
| 2247 | } |
| 2248 | |
Amaury Denoyelle | 8d22823 | 2020-12-10 13:43:54 +0100 | [diff] [blame] | 2249 | static enum act_return action_timeout_set_stream_timeout(struct act_rule *rule, |
| 2250 | struct proxy *px, |
| 2251 | struct session *sess, |
| 2252 | struct stream *s, |
| 2253 | int flags) |
| 2254 | { |
| 2255 | struct sample *key; |
| 2256 | |
| 2257 | if (rule->arg.timeout.expr) { |
| 2258 | key = sample_fetch_as_type(px, sess, s, SMP_OPT_FINAL, rule->arg.timeout.expr, SMP_T_SINT); |
| 2259 | if (!key) |
| 2260 | return ACT_RET_CONT; |
| 2261 | |
| 2262 | stream_set_timeout(s, rule->arg.timeout.type, MS_TO_TICKS(key->data.u.sint)); |
| 2263 | } |
| 2264 | else { |
| 2265 | stream_set_timeout(s, rule->arg.timeout.type, MS_TO_TICKS(rule->arg.timeout.value)); |
| 2266 | } |
| 2267 | |
| 2268 | return ACT_RET_CONT; |
| 2269 | } |
| 2270 | |
| 2271 | /* Parse a "set-timeout" action. Returns ACT_RET_PRS_ERR if parsing error. |
| 2272 | */ |
| 2273 | static enum act_parse_ret parse_http_set_timeout(const char **args, |
| 2274 | int *orig_arg, |
| 2275 | struct proxy *px, |
| 2276 | struct act_rule *rule, char **err) |
| 2277 | { |
| 2278 | int cur_arg; |
| 2279 | |
| 2280 | rule->action = ACT_CUSTOM; |
| 2281 | rule->action_ptr = action_timeout_set_stream_timeout; |
| 2282 | rule->release_ptr = release_timeout_action; |
| 2283 | |
| 2284 | cur_arg = *orig_arg; |
| 2285 | if (!*args[cur_arg] || !*args[cur_arg + 1]) { |
| 2286 | memprintf(err, "expects exactly 2 arguments"); |
| 2287 | return ACT_RET_PRS_ERR; |
| 2288 | } |
| 2289 | |
| 2290 | if (!(px->cap & PR_CAP_BE)) { |
| 2291 | memprintf(err, "proxy '%s' has no backend capability", px->id); |
| 2292 | return ACT_RET_PRS_ERR; |
| 2293 | } |
| 2294 | |
| 2295 | if (cfg_parse_rule_set_timeout(args, cur_arg, |
| 2296 | &rule->arg.timeout.value, |
| 2297 | &rule->arg.timeout.type, |
| 2298 | &rule->arg.timeout.expr, |
| 2299 | err, |
| 2300 | px->conf.args.file, |
| 2301 | px->conf.args.line, &px->conf.args) == -1) { |
| 2302 | return ACT_RET_PRS_ERR; |
| 2303 | } |
| 2304 | |
| 2305 | *orig_arg = cur_arg + 2; |
| 2306 | |
| 2307 | return ACT_RET_PRS_OK; |
| 2308 | } |
| 2309 | |
Christopher Faulet | 46f9554 | 2019-12-20 10:07:22 +0100 | [diff] [blame] | 2310 | /* This function executes a strict-mode actions. On success, it always returns |
| 2311 | * ACT_RET_CONT |
| 2312 | */ |
| 2313 | static enum act_return http_action_strict_mode(struct act_rule *rule, struct proxy *px, |
| 2314 | struct session *sess, struct stream *s, int flags) |
| 2315 | { |
| 2316 | struct http_msg *msg = ((rule->from == ACT_F_HTTP_REQ) ? &s->txn->req : &s->txn->rsp); |
| 2317 | |
| 2318 | if (rule->action == 0) // strict-mode on |
| 2319 | msg->flags &= ~HTTP_MSGF_SOFT_RW; |
| 2320 | else // strict-mode off |
| 2321 | msg->flags |= HTTP_MSGF_SOFT_RW; |
| 2322 | return ACT_RET_CONT; |
| 2323 | } |
| 2324 | |
| 2325 | /* Parse a "strict-mode" action. It returns ACT_RET_PRS_OK on success, |
| 2326 | * ACT_RET_PRS_ERR on error. |
| 2327 | */ |
| 2328 | static enum act_parse_ret parse_http_strict_mode(const char **args, int *orig_arg, struct proxy *px, |
| 2329 | struct act_rule *rule, char **err) |
| 2330 | { |
| 2331 | int cur_arg; |
| 2332 | |
Christopher Faulet | 46f9554 | 2019-12-20 10:07:22 +0100 | [diff] [blame] | 2333 | cur_arg = *orig_arg; |
| 2334 | if (!*args[cur_arg]) { |
| 2335 | memprintf(err, "expects exactly 1 arguments"); |
| 2336 | return ACT_RET_PRS_ERR; |
| 2337 | } |
| 2338 | |
| 2339 | if (strcasecmp(args[cur_arg], "on") == 0) |
| 2340 | rule->action = 0; // strict-mode on |
| 2341 | else if (strcasecmp(args[cur_arg], "off") == 0) |
| 2342 | rule->action = 1; // strict-mode off |
| 2343 | else { |
| 2344 | memprintf(err, "Unexpected value '%s'. Only 'on' and 'off' are supported", args[cur_arg]); |
| 2345 | return ACT_RET_PRS_ERR; |
| 2346 | } |
| 2347 | rule->action_ptr = http_action_strict_mode; |
| 2348 | |
| 2349 | *orig_arg = cur_arg + 1; |
| 2350 | return ACT_RET_PRS_OK; |
| 2351 | } |
| 2352 | |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2353 | /* This function executes a return action. It builds an HTX message from an |
| 2354 | * errorfile, an raw file or a log-format string, depending on <.action> |
| 2355 | * value. On success, it returns ACT_RET_ABRT. If an error occurs ACT_RET_ERR is |
| 2356 | * returned. |
| 2357 | */ |
| 2358 | static enum act_return http_action_return(struct act_rule *rule, struct proxy *px, |
| 2359 | struct session *sess, struct stream *s, int flags) |
| 2360 | { |
| 2361 | struct channel *req = &s->req; |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2362 | |
Christopher Faulet | 2d36df2 | 2021-02-19 11:41:01 +0100 | [diff] [blame] | 2363 | s->txn->status = rule->arg.http_reply->status; |
Christopher Faulet | 0e2ad61 | 2020-05-13 16:38:37 +0200 | [diff] [blame] | 2364 | if (http_reply_message(s, rule->arg.http_reply) == -1) |
| 2365 | return ACT_RET_ERR; |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2366 | |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2367 | if (rule->from == ACT_F_HTTP_REQ) { |
| 2368 | /* let's log the request time */ |
| 2369 | s->logs.tv_request = now; |
| 2370 | req->analysers &= AN_REQ_FLT_END; |
| 2371 | |
| 2372 | if (s->sess->fe == s->be) /* report it if the request was intercepted by the frontend */ |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 2373 | _HA_ATOMIC_INC(&s->sess->fe->fe_counters.intercepted_req); |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | if (!(s->flags & SF_ERR_MASK)) |
| 2377 | s->flags |= SF_ERR_LOCAL; |
| 2378 | if (!(s->flags & SF_FINST_MASK)) |
| 2379 | s->flags |= ((rule->from == ACT_F_HTTP_REQ) ? SF_FINST_R : SF_FINST_H); |
| 2380 | |
Christopher Faulet | 0e2ad61 | 2020-05-13 16:38:37 +0200 | [diff] [blame] | 2381 | return ACT_RET_ABRT; |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2382 | } |
| 2383 | |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2384 | /* Parse a "return" action. It returns ACT_RET_PRS_OK on success, |
Christopher Faulet | 47e791e | 2020-05-13 14:36:55 +0200 | [diff] [blame] | 2385 | * ACT_RET_PRS_ERR on error. It relies on http_parse_http_reply() to set |
| 2386 | * <.arg.http_reply>. |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2387 | */ |
| 2388 | static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, struct proxy *px, |
| 2389 | struct act_rule *rule, char **err) |
| 2390 | { |
Christopher Faulet | 47e791e | 2020-05-13 14:36:55 +0200 | [diff] [blame] | 2391 | /* Prepare parsing of log-format strings */ |
| 2392 | px->conf.args.ctx = ((rule->from == ACT_F_HTTP_REQ) ? ARGC_HRQ : ARGC_HRS); |
| 2393 | rule->arg.http_reply = http_parse_http_reply(args, orig_arg, px, 200, err); |
| 2394 | if (!rule->arg.http_reply) |
| 2395 | return ACT_RET_PRS_ERR; |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2396 | |
Christopher Faulet | ba946bf | 2020-05-13 08:50:07 +0200 | [diff] [blame] | 2397 | rule->flags |= ACT_FLAG_FINAL; |
Christopher Faulet | 5ff0c64 | 2020-05-12 18:33:37 +0200 | [diff] [blame] | 2398 | rule->action = ACT_CUSTOM; |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 2399 | rule->check_ptr = check_act_http_reply; |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2400 | rule->action_ptr = http_action_return; |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 2401 | rule->release_ptr = release_act_http_reply; |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2402 | return ACT_RET_PRS_OK; |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
Christopher Faulet | 021a8e4 | 2021-03-29 10:46:38 +0200 | [diff] [blame] | 2405 | |
| 2406 | |
| 2407 | /* This function executes a wait-for-body action. It waits for the message |
| 2408 | * payload for a max configured time (.arg.p[0]) and eventually for only first |
| 2409 | * <arg.p[1]> bytes (0 means no limit). It relies on http_wait_for_msg_body() |
| 2410 | * function. it returns ACT_RET_CONT when conditions are met to stop to wait. |
| 2411 | * Otherwise ACT_RET_YIELD is returned to wait for more data. ACT_RET_INV is |
| 2412 | * returned if a parsing error is raised by lower level and ACT_RET_ERR if an |
Ilya Shipitsin | b2be9a1 | 2021-04-24 13:25:42 +0500 | [diff] [blame] | 2413 | * internal error occurred. Finally ACT_RET_ABRT is returned when a timeout |
| 2414 | * occurred. |
Christopher Faulet | 021a8e4 | 2021-03-29 10:46:38 +0200 | [diff] [blame] | 2415 | */ |
| 2416 | static enum act_return http_action_wait_for_body(struct act_rule *rule, struct proxy *px, |
| 2417 | struct session *sess, struct stream *s, int flags) |
| 2418 | { |
| 2419 | struct channel *chn = ((rule->from == ACT_F_HTTP_REQ) ? &s->req : &s->res); |
| 2420 | unsigned int time = (uintptr_t)rule->arg.act.p[0]; |
| 2421 | unsigned int bytes = (uintptr_t)rule->arg.act.p[1]; |
| 2422 | |
| 2423 | switch (http_wait_for_msg_body(s, chn, time, bytes)) { |
| 2424 | case HTTP_RULE_RES_CONT: |
| 2425 | return ACT_RET_CONT; |
| 2426 | case HTTP_RULE_RES_YIELD: |
| 2427 | return ACT_RET_YIELD; |
| 2428 | case HTTP_RULE_RES_BADREQ: |
| 2429 | return ACT_RET_INV; |
| 2430 | case HTTP_RULE_RES_ERROR: |
| 2431 | return ACT_RET_ERR; |
| 2432 | case HTTP_RULE_RES_ABRT: |
| 2433 | return ACT_RET_ABRT; |
| 2434 | default: |
| 2435 | return ACT_RET_ERR; |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | /* Parse a "wait-for-body" action. It returns ACT_RET_PRS_OK on success, |
| 2440 | * ACT_RET_PRS_ERR on error. |
| 2441 | */ |
| 2442 | static enum act_parse_ret parse_http_wait_for_body(const char **args, int *orig_arg, struct proxy *px, |
| 2443 | struct act_rule *rule, char **err) |
| 2444 | { |
| 2445 | int cur_arg; |
| 2446 | unsigned int time, bytes; |
| 2447 | const char *res; |
| 2448 | |
| 2449 | cur_arg = *orig_arg; |
| 2450 | if (!*args[cur_arg]) { |
| 2451 | memprintf(err, "expects time <time> [ at-least <bytes> ]"); |
| 2452 | return ACT_RET_PRS_ERR; |
| 2453 | } |
| 2454 | |
| 2455 | time = UINT_MAX; /* To be sure it is set */ |
| 2456 | bytes = 0; /* Default value, wait all the body */ |
| 2457 | while (*(args[cur_arg])) { |
| 2458 | if (strcmp(args[cur_arg], "time") == 0) { |
| 2459 | if (!*args[cur_arg + 1]) { |
| 2460 | memprintf(err, "missing argument for '%s'", args[cur_arg]); |
| 2461 | return ACT_RET_PRS_ERR; |
| 2462 | } |
| 2463 | res = parse_time_err(args[cur_arg+1], &time, TIME_UNIT_MS); |
| 2464 | if (res == PARSE_TIME_OVER) { |
| 2465 | memprintf(err, "time overflow (maximum value is 2147483647 ms or ~24.8 days)"); |
| 2466 | return ACT_RET_PRS_ERR; |
| 2467 | } |
| 2468 | if (res == PARSE_TIME_UNDER) { |
| 2469 | memprintf(err, "time underflow (minimum non-null value is 1 ms)"); |
| 2470 | return ACT_RET_PRS_ERR; |
| 2471 | } |
| 2472 | if (res) { |
| 2473 | memprintf(err, "unexpected character '%c'", *res); |
| 2474 | return ACT_RET_PRS_ERR; |
| 2475 | } |
| 2476 | cur_arg++; |
| 2477 | } |
| 2478 | else if (strcmp(args[cur_arg], "at-least") == 0) { |
| 2479 | if (!*args[cur_arg + 1]) { |
| 2480 | memprintf(err, "missing argument for '%s'", args[cur_arg]); |
| 2481 | return ACT_RET_PRS_ERR; |
| 2482 | } |
| 2483 | res = parse_size_err(args[cur_arg+1], &bytes); |
| 2484 | if (res) { |
| 2485 | memprintf(err, "unexpected character '%c'", *res); |
| 2486 | return ACT_RET_PRS_ERR; |
| 2487 | } |
| 2488 | cur_arg++; |
| 2489 | } |
| 2490 | else |
| 2491 | break; |
| 2492 | cur_arg++; |
| 2493 | } |
| 2494 | |
| 2495 | if (time == UINT_MAX) { |
| 2496 | memprintf(err, "expects time <time> [ at-least <bytes> ]"); |
| 2497 | return ACT_RET_PRS_ERR; |
| 2498 | } |
| 2499 | |
| 2500 | rule->arg.act.p[0] = (void *)(uintptr_t)time; |
| 2501 | rule->arg.act.p[1] = (void *)(uintptr_t)bytes; |
| 2502 | |
| 2503 | *orig_arg = cur_arg; |
| 2504 | |
| 2505 | rule->action = ACT_CUSTOM; |
| 2506 | rule->action_ptr = http_action_wait_for_body; |
| 2507 | return ACT_RET_PRS_OK; |
| 2508 | } |
| 2509 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2510 | /************************************************************************/ |
| 2511 | /* All supported http-request action keywords must be declared here. */ |
| 2512 | /************************************************************************/ |
| 2513 | |
| 2514 | static struct action_kw_list http_req_actions = { |
| 2515 | .kw = { |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2516 | { "add-acl", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2517 | { "add-header", parse_http_set_header, 0 }, |
| 2518 | { "allow", parse_http_allow, 0 }, |
| 2519 | { "auth", parse_http_auth, 0 }, |
| 2520 | { "capture", parse_http_req_capture, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2521 | { "del-acl", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2522 | { "del-header", parse_http_del_header, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2523 | { "del-map", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 2524 | { "deny", parse_http_deny, 0 }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2525 | { "disable-l7-retry", parse_http_req_disable_l7_retry, 0 }, |
| 2526 | { "early-hint", parse_http_set_header, 0 }, |
Amaury Denoyelle | a9e639a | 2021-05-06 15:50:12 +0200 | [diff] [blame] | 2527 | { "normalize-uri", parse_http_normalize_uri, KWF_EXPERIMENTAL }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2528 | { "redirect", parse_http_redirect, 0 }, |
| 2529 | { "reject", parse_http_action_reject, 0 }, |
| 2530 | { "replace-header", parse_http_replace_header, 0 }, |
| 2531 | { "replace-path", parse_replace_uri, 0 }, |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 2532 | { "replace-pathq", parse_replace_uri, 0 }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2533 | { "replace-uri", parse_replace_uri, 0 }, |
| 2534 | { "replace-value", parse_http_replace_header, 0 }, |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2535 | { "return", parse_http_return, 0 }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2536 | { "set-header", parse_http_set_header, 0 }, |
| 2537 | { "set-log-level", parse_http_set_log_level, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2538 | { "set-map", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2539 | { "set-method", parse_set_req_line, 0 }, |
| 2540 | { "set-mark", parse_http_set_mark, 0 }, |
| 2541 | { "set-nice", parse_http_set_nice, 0 }, |
| 2542 | { "set-path", parse_set_req_line, 0 }, |
Christopher Faulet | 312294f | 2020-09-02 17:17:44 +0200 | [diff] [blame] | 2543 | { "set-pathq", parse_set_req_line, 0 }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2544 | { "set-query", parse_set_req_line, 0 }, |
| 2545 | { "set-tos", parse_http_set_tos, 0 }, |
| 2546 | { "set-uri", parse_set_req_line, 0 }, |
Christopher Faulet | 46f9554 | 2019-12-20 10:07:22 +0100 | [diff] [blame] | 2547 | { "strict-mode", parse_http_strict_mode, 0 }, |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 2548 | { "tarpit", parse_http_deny, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2549 | { "track-sc", parse_http_track_sc, KWF_MATCH_PREFIX }, |
Amaury Denoyelle | 8d22823 | 2020-12-10 13:43:54 +0100 | [diff] [blame] | 2550 | { "set-timeout", parse_http_set_timeout, 0 }, |
Christopher Faulet | 021a8e4 | 2021-03-29 10:46:38 +0200 | [diff] [blame] | 2551 | { "wait-for-body", parse_http_wait_for_body, 0 }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2552 | { NULL, NULL } |
| 2553 | } |
| 2554 | }; |
| 2555 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 2556 | INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_actions); |
| 2557 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2558 | static struct action_kw_list http_res_actions = { |
| 2559 | .kw = { |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2560 | { "add-acl", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2561 | { "add-header", parse_http_set_header, 0 }, |
| 2562 | { "allow", parse_http_allow, 0 }, |
| 2563 | { "capture", parse_http_res_capture, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2564 | { "del-acl", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2565 | { "del-header", parse_http_del_header, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2566 | { "del-map", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | e0fca29 | 2020-01-13 21:49:03 +0100 | [diff] [blame] | 2567 | { "deny", parse_http_deny, 0 }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2568 | { "redirect", parse_http_redirect, 0 }, |
| 2569 | { "replace-header", parse_http_replace_header, 0 }, |
| 2570 | { "replace-value", parse_http_replace_header, 0 }, |
Christopher Faulet | 24231ab | 2020-01-24 17:44:23 +0100 | [diff] [blame] | 2571 | { "return", parse_http_return, 0 }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2572 | { "set-header", parse_http_set_header, 0 }, |
| 2573 | { "set-log-level", parse_http_set_log_level, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2574 | { "set-map", parse_http_set_map, KWF_MATCH_PREFIX }, |
Christopher Faulet | 81e2017 | 2019-12-12 16:40:30 +0100 | [diff] [blame] | 2575 | { "set-mark", parse_http_set_mark, 0 }, |
| 2576 | { "set-nice", parse_http_set_nice, 0 }, |
| 2577 | { "set-status", parse_http_set_status, 0 }, |
| 2578 | { "set-tos", parse_http_set_tos, 0 }, |
Christopher Faulet | 46f9554 | 2019-12-20 10:07:22 +0100 | [diff] [blame] | 2579 | { "strict-mode", parse_http_strict_mode, 0 }, |
Amaury Denoyelle | e4a617c | 2021-05-06 15:33:09 +0200 | [diff] [blame] | 2580 | { "track-sc", parse_http_track_sc, KWF_MATCH_PREFIX }, |
Christopher Faulet | 021a8e4 | 2021-03-29 10:46:38 +0200 | [diff] [blame] | 2581 | { "wait-for-body", parse_http_wait_for_body, 0 }, |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2582 | { NULL, NULL } |
| 2583 | } |
| 2584 | }; |
| 2585 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 2586 | INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_actions); |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2587 | |
Christopher Faulet | 6d0c3df | 2020-01-22 09:26:35 +0100 | [diff] [blame] | 2588 | static struct action_kw_list http_after_res_actions = { |
| 2589 | .kw = { |
| 2590 | { "add-header", parse_http_set_header, 0 }, |
| 2591 | { "allow", parse_http_allow, 0 }, |
| 2592 | { "del-header", parse_http_del_header, 0 }, |
| 2593 | { "replace-header", parse_http_replace_header, 0 }, |
| 2594 | { "replace-value", parse_http_replace_header, 0 }, |
| 2595 | { "set-header", parse_http_set_header, 0 }, |
| 2596 | { "set-status", parse_http_set_status, 0 }, |
| 2597 | { "strict-mode", parse_http_strict_mode, 0 }, |
| 2598 | { NULL, NULL } |
| 2599 | } |
| 2600 | }; |
| 2601 | |
| 2602 | INITCALL1(STG_REGISTER, http_after_res_keywords_register, &http_after_res_actions); |
| 2603 | |
Willy Tarreau | 79e5733 | 2018-10-02 16:01:16 +0200 | [diff] [blame] | 2604 | /* |
| 2605 | * Local variables: |
| 2606 | * c-indent-level: 8 |
| 2607 | * c-basic-offset: 8 |
| 2608 | * End: |
| 2609 | */ |