Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Stream filters related variables and functions. |
| 3 | * |
| 4 | * Copyright (C) 2015 Qualys Inc., Christopher Faulet <cfaulet@qualys.com> |
| 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 <common/buffer.h> |
| 14 | #include <common/debug.h> |
| 15 | #include <common/cfgparse.h> |
| 16 | #include <common/compat.h> |
| 17 | #include <common/config.h> |
| 18 | #include <common/errors.h> |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 19 | #include <common/htx.h> |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 20 | #include <common/initcall.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 21 | #include <common/namespace.h> |
| 22 | #include <common/standard.h> |
Christopher Faulet | 71a6a8e | 2017-07-27 16:33:28 +0200 | [diff] [blame] | 23 | #include <common/hathreads.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 24 | |
| 25 | #include <types/filters.h> |
| 26 | #include <types/proto_http.h> |
| 27 | |
| 28 | #include <proto/compression.h> |
| 29 | #include <proto/filters.h> |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 30 | #include <proto/flt_http_comp.h> |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 31 | #include <proto/http_htx.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 32 | #include <proto/proto_http.h> |
| 33 | #include <proto/stream.h> |
| 34 | #include <proto/stream_interface.h> |
| 35 | |
| 36 | /* Pool used to allocate filters */ |
Willy Tarreau | 8ceae72 | 2018-11-26 11:58:30 +0100 | [diff] [blame] | 37 | DECLARE_STATIC_POOL(pool_head_filter, "filter", sizeof(struct filter)); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 38 | |
| 39 | static int handle_analyzer_result(struct stream *s, struct channel *chn, unsigned int an_bit, int ret); |
| 40 | |
| 41 | /* - RESUME_FILTER_LOOP and RESUME_FILTER_END must always be used together. |
| 42 | * The first one begins a loop and the seconds one ends it. |
| 43 | * |
| 44 | * - BREAK_EXECUTION must be used to break the loop and set the filter from |
| 45 | * which to resume the next time. |
| 46 | * |
Bertrand Jacquin | 874a35c | 2018-09-10 21:26:07 +0100 | [diff] [blame] | 47 | * Here is an example: |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 48 | * |
| 49 | * RESUME_FILTER_LOOP(stream, channel) { |
| 50 | * ... |
| 51 | * if (cond) |
| 52 | * BREAK_EXECUTION(stream, channel, label); |
| 53 | * ... |
| 54 | * } RESUME_FILTER_END; |
| 55 | * ... |
| 56 | * label: |
| 57 | * ... |
| 58 | * |
| 59 | */ |
| 60 | #define RESUME_FILTER_LOOP(strm, chn) \ |
| 61 | do { \ |
| 62 | struct filter *filter; \ |
| 63 | \ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 64 | if (strm_flt(strm)->current[CHN_IDX(chn)]) { \ |
| 65 | filter = strm_flt(strm)->current[CHN_IDX(chn)]; \ |
| 66 | strm_flt(strm)->current[CHN_IDX(chn)] = NULL; \ |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 67 | goto resume_execution; \ |
| 68 | } \ |
| 69 | \ |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 70 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { \ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 71 | resume_execution: |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 72 | |
| 73 | #define RESUME_FILTER_END \ |
| 74 | } \ |
| 75 | } while(0) |
| 76 | |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 77 | #define BREAK_EXECUTION(strm, chn, label) \ |
| 78 | do { \ |
| 79 | strm_flt(strm)->current[CHN_IDX(chn)] = filter; \ |
| 80 | goto label; \ |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 81 | } while (0) |
| 82 | |
| 83 | |
| 84 | /* List head of all known filter keywords */ |
| 85 | static struct flt_kw_list flt_keywords = { |
| 86 | .list = LIST_HEAD_INIT(flt_keywords.list) |
| 87 | }; |
| 88 | |
| 89 | /* |
| 90 | * Registers the filter keyword list <kwl> as a list of valid keywords for next |
| 91 | * parsing sessions. |
| 92 | */ |
| 93 | void |
| 94 | flt_register_keywords(struct flt_kw_list *kwl) |
| 95 | { |
| 96 | LIST_ADDQ(&flt_keywords.list, &kwl->list); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Returns a pointer to the filter keyword <kw>, or NULL if not found. If the |
| 101 | * keyword is found with a NULL ->parse() function, then an attempt is made to |
| 102 | * find one with a valid ->parse() function. This way it is possible to declare |
| 103 | * platform-dependant, known keywords as NULL, then only declare them as valid |
| 104 | * if some options are met. Note that if the requested keyword contains an |
| 105 | * opening parenthesis, everything from this point is ignored. |
| 106 | */ |
| 107 | struct flt_kw * |
| 108 | flt_find_kw(const char *kw) |
| 109 | { |
| 110 | int index; |
| 111 | const char *kwend; |
| 112 | struct flt_kw_list *kwl; |
| 113 | struct flt_kw *ret = NULL; |
| 114 | |
| 115 | kwend = strchr(kw, '('); |
| 116 | if (!kwend) |
| 117 | kwend = kw + strlen(kw); |
| 118 | |
| 119 | list_for_each_entry(kwl, &flt_keywords.list, list) { |
| 120 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 121 | if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) && |
| 122 | kwl->kw[index].kw[kwend-kw] == 0) { |
| 123 | if (kwl->kw[index].parse) |
| 124 | return &kwl->kw[index]; /* found it !*/ |
| 125 | else |
| 126 | ret = &kwl->kw[index]; /* may be OK */ |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Dumps all registered "filter" keywords to the <out> string pointer. The |
| 135 | * unsupported keywords are only dumped if their supported form was not found. |
| 136 | */ |
| 137 | void |
| 138 | flt_dump_kws(char **out) |
| 139 | { |
| 140 | struct flt_kw_list *kwl; |
| 141 | int index; |
| 142 | |
| 143 | *out = NULL; |
| 144 | list_for_each_entry(kwl, &flt_keywords.list, list) { |
| 145 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 146 | if (kwl->kw[index].parse || |
| 147 | flt_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) { |
| 148 | memprintf(out, "%s[%4s] %s%s\n", *out ? *out : "", |
| 149 | kwl->scope, |
| 150 | kwl->kw[index].kw, |
| 151 | kwl->kw[index].parse ? "" : " (not supported)"); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /* |
Christopher Faulet | b3f4e14 | 2016-03-07 12:46:38 +0100 | [diff] [blame] | 158 | * Lists the known filters on <out> |
| 159 | */ |
| 160 | void |
| 161 | list_filters(FILE *out) |
| 162 | { |
| 163 | char *filters, *p, *f; |
| 164 | |
| 165 | fprintf(out, "Available filters :\n"); |
| 166 | flt_dump_kws(&filters); |
| 167 | for (p = filters; (f = strtok_r(p,"\n",&p));) |
| 168 | fprintf(out, "\t%s\n", f); |
| 169 | free(filters); |
| 170 | } |
| 171 | |
| 172 | /* |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 173 | * Parses the "filter" keyword. All keywords must be handled by filters |
| 174 | * themselves |
| 175 | */ |
| 176 | static int |
| 177 | parse_filter(char **args, int section_type, struct proxy *curpx, |
| 178 | struct proxy *defpx, const char *file, int line, char **err) |
| 179 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 180 | struct flt_conf *fconf = NULL; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 181 | |
| 182 | /* Filter cannot be defined on a default proxy */ |
| 183 | if (curpx == defpx) { |
Christopher Faulet | cc7317d | 2016-04-04 10:51:17 +0200 | [diff] [blame] | 184 | memprintf(err, "parsing [%s:%d] : %s is not allowed in a 'default' section.", |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 185 | file, line, args[0]); |
| 186 | return -1; |
| 187 | } |
| 188 | if (!strcmp(args[0], "filter")) { |
| 189 | struct flt_kw *kw; |
| 190 | int cur_arg; |
| 191 | |
| 192 | if (!*args[1]) { |
| 193 | memprintf(err, |
| 194 | "parsing [%s:%d] : missing argument for '%s' in %s '%s'.", |
| 195 | file, line, args[0], proxy_type_str(curpx), curpx->id); |
| 196 | goto error; |
| 197 | } |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 198 | fconf = calloc(1, sizeof(*fconf)); |
| 199 | if (!fconf) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 200 | memprintf(err, "'%s' : out of memory", args[0]); |
| 201 | goto error; |
| 202 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 203 | |
| 204 | cur_arg = 1; |
| 205 | kw = flt_find_kw(args[cur_arg]); |
| 206 | if (kw) { |
| 207 | if (!kw->parse) { |
| 208 | memprintf(err, "parsing [%s:%d] : '%s' : " |
| 209 | "'%s' option is not implemented in this version (check build options).", |
| 210 | file, line, args[0], args[cur_arg]); |
| 211 | goto error; |
| 212 | } |
Thierry Fournier | 3610c39 | 2016-04-13 18:27:51 +0200 | [diff] [blame] | 213 | if (kw->parse(args, &cur_arg, curpx, fconf, err, kw->private) != 0) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 214 | if (err && *err) |
| 215 | memprintf(err, "'%s' : '%s'", |
| 216 | args[0], *err); |
| 217 | else |
| 218 | memprintf(err, "'%s' : error encountered while processing '%s'", |
| 219 | args[0], args[cur_arg]); |
| 220 | goto error; |
| 221 | } |
| 222 | } |
| 223 | else { |
| 224 | flt_dump_kws(err); |
| 225 | indent_msg(err, 4); |
| 226 | memprintf(err, "'%s' : unknown keyword '%s'.%s%s", |
| 227 | args[0], args[cur_arg], |
| 228 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 229 | goto error; |
| 230 | } |
| 231 | if (*args[cur_arg]) { |
| 232 | memprintf(err, "'%s %s' : unknown keyword '%s'.", |
| 233 | args[0], args[1], args[cur_arg]); |
| 234 | goto error; |
| 235 | } |
Christopher Faulet | 00e818a | 2016-04-19 17:00:44 +0200 | [diff] [blame] | 236 | if (fconf->ops == NULL) { |
| 237 | memprintf(err, "'%s %s' : no callbacks defined.", |
| 238 | args[0], args[1]); |
| 239 | goto error; |
| 240 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 241 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 242 | LIST_ADDQ(&curpx->filter_configs, &fconf->list); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 243 | } |
| 244 | return 0; |
| 245 | |
| 246 | error: |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 247 | free(fconf); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 248 | return -1; |
| 249 | |
| 250 | |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | * Calls 'init' callback for all filters attached to a proxy. This happens after |
| 255 | * the configuration parsing. Filters can finish to fill their config. Returns |
| 256 | * (ERR_ALERT|ERR_FATAL) if an error occurs, 0 otherwise. |
| 257 | */ |
Willy Tarreau | 64bca59 | 2016-12-21 20:13:11 +0100 | [diff] [blame] | 258 | static int |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 259 | flt_init(struct proxy *proxy) |
| 260 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 261 | struct flt_conf *fconf; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 262 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 263 | list_for_each_entry(fconf, &proxy->filter_configs, list) { |
| 264 | if (fconf->ops->init && fconf->ops->init(proxy, fconf) < 0) |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 265 | return ERR_ALERT|ERR_FATAL; |
| 266 | } |
| 267 | return 0; |
| 268 | } |
| 269 | |
Christopher Faulet | 71a6a8e | 2017-07-27 16:33:28 +0200 | [diff] [blame] | 270 | /* |
| 271 | * Calls 'init_per_thread' callback for all filters attached to a proxy for each |
| 272 | * threads. This happens after the thread creation. Filters can finish to fill |
| 273 | * their config. Returns (ERR_ALERT|ERR_FATAL) if an error occurs, 0 otherwise. |
| 274 | */ |
| 275 | static int |
| 276 | flt_init_per_thread(struct proxy *proxy) |
| 277 | { |
| 278 | struct flt_conf *fconf; |
| 279 | |
| 280 | list_for_each_entry(fconf, &proxy->filter_configs, list) { |
| 281 | if (fconf->ops->init_per_thread && fconf->ops->init_per_thread(proxy, fconf) < 0) |
| 282 | return ERR_ALERT|ERR_FATAL; |
| 283 | } |
| 284 | return 0; |
| 285 | } |
| 286 | |
Willy Tarreau | 64bca59 | 2016-12-21 20:13:11 +0100 | [diff] [blame] | 287 | /* Calls flt_init() for all proxies, see above */ |
| 288 | static int |
| 289 | flt_init_all() |
| 290 | { |
| 291 | struct proxy *px; |
| 292 | int err_code = 0; |
| 293 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 294 | for (px = proxies_list; px; px = px->next) { |
Christopher Faulet | 73e7d1c | 2020-11-02 16:08:09 +0100 | [diff] [blame] | 295 | if (px->state == PR_STSTOPPED) { |
| 296 | flt_deinit(px); |
| 297 | continue; |
| 298 | } |
Willy Tarreau | 64bca59 | 2016-12-21 20:13:11 +0100 | [diff] [blame] | 299 | err_code |= flt_init(px); |
| 300 | if (err_code & (ERR_ABORT|ERR_FATAL)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 301 | ha_alert("Failed to initialize filters for proxy '%s'.\n", |
| 302 | px->id); |
Willy Tarreau | 64bca59 | 2016-12-21 20:13:11 +0100 | [diff] [blame] | 303 | return err_code; |
| 304 | } |
| 305 | } |
| 306 | return 0; |
| 307 | } |
| 308 | |
Joseph Herlant | b35ea68 | 2018-11-15 12:24:23 -0800 | [diff] [blame] | 309 | /* Calls flt_init_per_thread() for all proxies, see above. Be careful here, it |
| 310 | * returns 0 if an error occurred. This is the opposite of flt_init_all. */ |
Christopher Faulet | 71a6a8e | 2017-07-27 16:33:28 +0200 | [diff] [blame] | 311 | static int |
| 312 | flt_init_all_per_thread() |
| 313 | { |
| 314 | struct proxy *px; |
| 315 | int err_code = 0; |
| 316 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 317 | for (px = proxies_list; px; px = px->next) { |
Christopher Faulet | 73e7d1c | 2020-11-02 16:08:09 +0100 | [diff] [blame] | 318 | if (px->state == PR_STSTOPPED) |
| 319 | continue; |
| 320 | |
Christopher Faulet | 71a6a8e | 2017-07-27 16:33:28 +0200 | [diff] [blame] | 321 | err_code = flt_init_per_thread(px); |
| 322 | if (err_code & (ERR_ABORT|ERR_FATAL)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 323 | ha_alert("Failed to initialize filters for proxy '%s' for thread %u.\n", |
| 324 | px->id, tid); |
Christopher Faulet | 71a6a8e | 2017-07-27 16:33:28 +0200 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | } |
| 328 | return 1; |
| 329 | } |
| 330 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 331 | /* |
| 332 | * Calls 'check' callback for all filters attached to a proxy. This happens |
| 333 | * after the configuration parsing but before filters initialization. Returns |
| 334 | * the number of encountered errors. |
| 335 | */ |
| 336 | int |
| 337 | flt_check(struct proxy *proxy) |
| 338 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 339 | struct flt_conf *fconf; |
| 340 | int err = 0; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 341 | |
Christopher Faulet | ff17b18 | 2019-01-07 15:03:22 +0100 | [diff] [blame] | 342 | err += check_implicit_http_comp_flt(proxy); |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 343 | list_for_each_entry(fconf, &proxy->filter_configs, list) { |
| 344 | if (fconf->ops->check) |
| 345 | err += fconf->ops->check(proxy, fconf); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 346 | } |
| 347 | return err; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Calls 'denit' callback for all filters attached to a proxy. This happens when |
| 352 | * HAProxy is stopped. |
| 353 | */ |
| 354 | void |
| 355 | flt_deinit(struct proxy *proxy) |
| 356 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 357 | struct flt_conf *fconf, *back; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 358 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 359 | list_for_each_entry_safe(fconf, back, &proxy->filter_configs, list) { |
Christopher Faulet | df36d43 | 2020-11-03 16:40:37 +0100 | [diff] [blame] | 360 | if (fconf->ops->deinit) |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 361 | fconf->ops->deinit(proxy, fconf); |
| 362 | LIST_DEL(&fconf->list); |
| 363 | free(fconf); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
Christopher Faulet | 71a6a8e | 2017-07-27 16:33:28 +0200 | [diff] [blame] | 367 | /* |
| 368 | * Calls 'denit_per_thread' callback for all filters attached to a proxy for |
| 369 | * each threads. This happens before exiting a thread. |
| 370 | */ |
| 371 | void |
| 372 | flt_deinit_per_thread(struct proxy *proxy) |
| 373 | { |
| 374 | struct flt_conf *fconf, *back; |
| 375 | |
| 376 | list_for_each_entry_safe(fconf, back, &proxy->filter_configs, list) { |
| 377 | if (fconf->ops->deinit_per_thread) |
| 378 | fconf->ops->deinit_per_thread(proxy, fconf); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | |
| 383 | /* Calls flt_deinit_per_thread() for all proxies, see above */ |
| 384 | static void |
| 385 | flt_deinit_all_per_thread() |
| 386 | { |
| 387 | struct proxy *px; |
| 388 | |
Christopher Faulet | df36d43 | 2020-11-03 16:40:37 +0100 | [diff] [blame] | 389 | for (px = proxies_list; px; px = px->next) |
| 390 | flt_deinit_per_thread(px); |
Christopher Faulet | 71a6a8e | 2017-07-27 16:33:28 +0200 | [diff] [blame] | 391 | } |
| 392 | |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 393 | /* Attaches a filter to a stream. Returns -1 if an error occurs, 0 otherwise. */ |
| 394 | static int |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 395 | flt_stream_add_filter(struct stream *s, struct flt_conf *fconf, unsigned int flags) |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 396 | { |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 397 | struct filter *f; |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 398 | |
Christopher Faulet | 0f17a9b | 2019-04-05 10:11:38 +0200 | [diff] [blame] | 399 | if (IS_HTX_STRM(s) && !(fconf->flags & FLT_CFG_FL_HTX)) |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 400 | return 0; |
| 401 | |
| 402 | f = pool_alloc(pool_head_filter); |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 403 | if (!f) /* not enough memory */ |
| 404 | return -1; |
| 405 | memset(f, 0, sizeof(*f)); |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 406 | f->config = fconf; |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 407 | f->flags |= flags; |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 408 | |
| 409 | if (FLT_OPS(f)->attach) { |
| 410 | int ret = FLT_OPS(f)->attach(s, f); |
| 411 | if (ret <= 0) { |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 412 | pool_free(pool_head_filter, f); |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 413 | return ret; |
| 414 | } |
| 415 | } |
| 416 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 417 | LIST_ADDQ(&strm_flt(s)->filters, &f->list); |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 418 | strm_flt(s)->flags |= STRM_FLT_FL_HAS_FILTERS; |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Called when a stream is created. It attaches all frontend filters to the |
| 424 | * stream. Returns -1 if an error occurs, 0 otherwise. |
| 425 | */ |
| 426 | int |
| 427 | flt_stream_init(struct stream *s) |
| 428 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 429 | struct flt_conf *fconf; |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 430 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 431 | memset(strm_flt(s), 0, sizeof(*strm_flt(s))); |
| 432 | LIST_INIT(&strm_flt(s)->filters); |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 433 | list_for_each_entry(fconf, &strm_fe(s)->filter_configs, list) { |
| 434 | if (flt_stream_add_filter(s, fconf, 0) < 0) |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 435 | return -1; |
| 436 | } |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Called when a stream is closed or when analyze ends (For an HTTP stream, this |
| 442 | * happens after each request/response exchange). When analyze ends, backend |
| 443 | * filters are removed. When the stream is closed, all filters attached to the |
| 444 | * stream are removed. |
| 445 | */ |
| 446 | void |
| 447 | flt_stream_release(struct stream *s, int only_backend) |
| 448 | { |
| 449 | struct filter *filter, *back; |
| 450 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 451 | list_for_each_entry_safe(filter, back, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 452 | if (!only_backend || (filter->flags & FLT_FL_IS_BACKEND_FILTER)) { |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 453 | if (FLT_OPS(filter)->detach) |
| 454 | FLT_OPS(filter)->detach(s, filter); |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 455 | LIST_DEL(&filter->list); |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 456 | pool_free(pool_head_filter, filter); |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 457 | } |
| 458 | } |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 459 | if (LIST_ISEMPTY(&strm_flt(s)->filters)) |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 460 | strm_flt(s)->flags &= ~STRM_FLT_FL_HAS_FILTERS; |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 463 | /* |
| 464 | * Calls 'stream_start' for all filters attached to a stream. This happens when |
| 465 | * the stream is created, just after calling flt_stream_init |
| 466 | * function. Returns -1 if an error occurs, 0 otherwise. |
| 467 | */ |
| 468 | int |
| 469 | flt_stream_start(struct stream *s) |
| 470 | { |
| 471 | struct filter *filter; |
| 472 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 473 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 474 | if (FLT_OPS(filter)->stream_start && FLT_OPS(filter)->stream_start(s, filter) < 0) |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 475 | return -1; |
| 476 | } |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * Calls 'stream_stop' for all filters attached to a stream. This happens when |
| 482 | * the stream is stopped, just before calling flt_stream_release function. |
| 483 | */ |
| 484 | void |
| 485 | flt_stream_stop(struct stream *s) |
| 486 | { |
| 487 | struct filter *filter; |
| 488 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 489 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 490 | if (FLT_OPS(filter)->stream_stop) |
| 491 | FLT_OPS(filter)->stream_stop(s, filter); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 495 | /* |
Christopher Faulet | a00d817 | 2016-11-10 14:58:05 +0100 | [diff] [blame] | 496 | * Calls 'check_timeouts' for all filters attached to a stream. This happens when |
| 497 | * the stream is woken up because of expired timer. |
| 498 | */ |
| 499 | void |
| 500 | flt_stream_check_timeouts(struct stream *s) |
| 501 | { |
| 502 | struct filter *filter; |
| 503 | |
| 504 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
| 505 | if (FLT_OPS(filter)->check_timeouts) |
| 506 | FLT_OPS(filter)->check_timeouts(s, filter); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | /* |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 511 | * Called when a backend is set for a stream. If the frontend and the backend |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 512 | * are not the same, this function attaches all backend filters to the |
| 513 | * stream. Returns -1 if an error occurs, 0 otherwise. |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 514 | */ |
| 515 | int |
| 516 | flt_set_stream_backend(struct stream *s, struct proxy *be) |
| 517 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 518 | struct flt_conf *fconf; |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 519 | struct filter *filter; |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 520 | |
| 521 | if (strm_fe(s) == be) |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 522 | goto end; |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 523 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 524 | list_for_each_entry(fconf, &be->filter_configs, list) { |
| 525 | if (flt_stream_add_filter(s, fconf, FLT_FL_IS_BACKEND_FILTER) < 0) |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 526 | return -1; |
| 527 | } |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 528 | |
| 529 | end: |
| 530 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
| 531 | if (FLT_OPS(filter)->stream_set_backend && |
| 532 | FLT_OPS(filter)->stream_set_backend(s, filter, be) < 0) |
| 533 | return -1; |
| 534 | } |
| 535 | |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 539 | /* |
| 540 | * Calls 'http_data' callback for all "data" filters attached to a stream. This |
| 541 | * function is called when incoming data are available (excluding chunks |
| 542 | * envelope for chunked messages) in the AN_REQ_HTTP_XFER_BODY and |
| 543 | * AN_RES_HTTP_XFER_BODY analyzers. It takes care to update the next offset of |
| 544 | * filters and adjusts available data to be sure that a filter cannot parse more |
| 545 | * data than its predecessors. A filter can choose to not consume all available |
| 546 | * data. Returns -1 if an error occurs, the number of consumed bytes otherwise. |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 547 | * |
| 548 | * DEPRECATED FUNCTION - CALLED FROM LEGACY HTTP ANALYZERS |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 549 | */ |
| 550 | int |
| 551 | flt_http_data(struct stream *s, struct http_msg *msg) |
| 552 | { |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 553 | struct filter *filter; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 554 | unsigned int buf_i; |
Christopher Faulet | 55048a4 | 2016-06-21 10:44:32 +0200 | [diff] [blame] | 555 | int delta = 0, ret = 0; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 556 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 557 | /* Save buffer state */ |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 558 | buf_i = ci_data(msg->chn); |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 559 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 560 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 561 | unsigned int *nxt; |
| 562 | |
| 563 | /* Call "data" filters only */ |
| 564 | if (!IS_DATA_FILTER(filter, msg->chn)) |
| 565 | continue; |
| 566 | |
Christopher Faulet | 2fb2880 | 2015-12-01 10:40:57 +0100 | [diff] [blame] | 567 | /* If the HTTP parser is ahead, we update the next offset of the |
| 568 | * current filter. This happens for chunked messages, at the |
Joseph Herlant | b35ea68 | 2018-11-15 12:24:23 -0800 | [diff] [blame] | 569 | * beginning of a new chunk. */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 570 | nxt = &FLT_NXT(filter, msg->chn); |
| 571 | if (msg->next > *nxt) |
| 572 | *nxt = msg->next; |
| 573 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 574 | if (FLT_OPS(filter)->http_data) { |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 575 | unsigned int i = ci_data(msg->chn); |
Christopher Faulet | 55048a4 | 2016-06-21 10:44:32 +0200 | [diff] [blame] | 576 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 577 | ret = FLT_OPS(filter)->http_data(s, filter, msg); |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 578 | if (ret < 0) |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 579 | break; |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 580 | delta += (int)(ci_data(msg->chn) - i); |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 581 | |
| 582 | /* Update the next offset of the current filter */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 583 | *nxt += ret; |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 584 | |
| 585 | /* And set this value as the bound for the next |
| 586 | * filter. It will not able to parse more data than this |
| 587 | * one. */ |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 588 | b_set_data(&msg->chn->buf, co_data(msg->chn) + *nxt); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 589 | } |
| 590 | else { |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 591 | /* Consume all available data and update the next offset |
| 592 | * of the current filter. buf->i is untouched here. */ |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 593 | ret = MIN(msg->chunk_len + msg->next, ci_data(msg->chn)) - *nxt; |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 594 | *nxt += ret; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 595 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 596 | } |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 597 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 598 | /* Restore the original buffer state */ |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 599 | b_set_data(&msg->chn->buf, co_data(msg->chn) + buf_i + delta); |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 600 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 601 | return ret; |
| 602 | } |
| 603 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 604 | /* |
| 605 | * Calls 'http_chunk_trailers' callback for all "data" filters attached to a |
| 606 | * stream. This function is called for chunked messages only when a part of the |
| 607 | * trailers was parsed in the AN_REQ_HTTP_XFER_BODY and AN_RES_HTTP_XFER_BODY |
| 608 | * analyzers. Filters can know how much data were parsed by the HTTP parsing |
| 609 | * until the last call with the msg->sol value. Returns a negative value if an |
| 610 | * error occurs, any other value otherwise. |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 611 | * |
| 612 | * DEPRECATED FUNCTION - CALLED FROM LEGACY HTTP ANALYZERS |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 613 | */ |
| 614 | int |
| 615 | flt_http_chunk_trailers(struct stream *s, struct http_msg *msg) |
| 616 | { |
Christopher Faulet | 2fb2880 | 2015-12-01 10:40:57 +0100 | [diff] [blame] | 617 | struct filter *filter; |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 618 | int ret = 1; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 619 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 620 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 621 | unsigned int *nxt; |
| 622 | |
| 623 | /* Call "data" filters only */ |
| 624 | if (!IS_DATA_FILTER(filter, msg->chn)) |
| 625 | continue; |
| 626 | |
Christopher Faulet | 2fb2880 | 2015-12-01 10:40:57 +0100 | [diff] [blame] | 627 | /* Be sure to set the next offset of the filter at the right |
| 628 | * place. This is really useful when the first part of the |
| 629 | * trailers was parsed. */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 630 | nxt = &FLT_NXT(filter, msg->chn); |
| 631 | *nxt = msg->next; |
| 632 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 633 | if (FLT_OPS(filter)->http_chunk_trailers) { |
| 634 | ret = FLT_OPS(filter)->http_chunk_trailers(s, filter, msg); |
Christopher Faulet | 2fb2880 | 2015-12-01 10:40:57 +0100 | [diff] [blame] | 635 | if (ret < 0) |
| 636 | break; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 637 | } |
Christopher Faulet | 2fb2880 | 2015-12-01 10:40:57 +0100 | [diff] [blame] | 638 | /* Update the next offset of the current filter. Here all data |
| 639 | * are always consumed. */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 640 | *nxt += msg->sol; |
Christopher Faulet | 2fb2880 | 2015-12-01 10:40:57 +0100 | [diff] [blame] | 641 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * Calls 'http_end' callback for all filters attached to a stream. All filters |
| 647 | * are called here, but only if there is at least one "data" filter. This |
| 648 | * functions is called when all data were parsed and forwarded. 'http_end' |
| 649 | * callback is resumable, so this function returns a negative value if an error |
| 650 | * occurs, 0 if it needs to wait for some reason, any other value otherwise. |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 651 | * |
| 652 | * Be carefull, this function can be called from the HTTP legacy analyzers or |
| 653 | * from HTX analyzers. If your filter is compatible with the two modes, use |
| 654 | * IS_HTX_STRM macro on the stream. |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 655 | */ |
| 656 | int |
| 657 | flt_http_end(struct stream *s, struct http_msg *msg) |
| 658 | { |
Christopher Faulet | da4576d | 2020-11-16 10:10:38 +0100 | [diff] [blame] | 659 | unsigned long long *strm_off = &FLT_STRM_OFF(s, msg->chn); |
| 660 | unsigned int offset = 0; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 661 | int ret = 1; |
| 662 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 663 | RESUME_FILTER_LOOP(s, msg->chn) { |
Christopher Faulet | da4576d | 2020-11-16 10:10:38 +0100 | [diff] [blame] | 664 | unsigned long long flt_off = FLT_OFF(filter, msg->chn); |
| 665 | offset = flt_off - *strm_off; |
| 666 | |
Christopher Faulet | 7102f54 | 2020-11-24 09:49:01 +0100 | [diff] [blame] | 667 | /* Call http_end for data filters only. But the filter offset is |
| 668 | * still valid for all filters |
| 669 | . */ |
| 670 | if (!IS_DATA_FILTER(filter, msg->chn)) |
| 671 | continue; |
| 672 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 673 | if (FLT_OPS(filter)->http_end) { |
| 674 | ret = FLT_OPS(filter)->http_end(s, filter, msg); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 675 | if (ret <= 0) |
| 676 | BREAK_EXECUTION(s, msg->chn, end); |
| 677 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 678 | } RESUME_FILTER_END; |
Christopher Faulet | da4576d | 2020-11-16 10:10:38 +0100 | [diff] [blame] | 679 | |
| 680 | c_adv(msg->chn, offset); |
| 681 | *strm_off += offset; |
| 682 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 683 | end: |
| 684 | return ret; |
| 685 | } |
| 686 | |
| 687 | /* |
| 688 | * Calls 'http_reset' callback for all filters attached to a stream. This |
| 689 | * happens when a 100-continue response is received. |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 690 | * |
| 691 | * Be carefull, this function can be called from the HTTP legacy analyzers or |
| 692 | * from HTX analyzers. If your filter is compatible with the two modes, use |
| 693 | * IS_HTX_STRM macro on the stream. |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 694 | */ |
| 695 | void |
| 696 | flt_http_reset(struct stream *s, struct http_msg *msg) |
| 697 | { |
| 698 | struct filter *filter; |
| 699 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 700 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 701 | if (FLT_OPS(filter)->http_reset) |
| 702 | FLT_OPS(filter)->http_reset(s, filter, msg); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | * Calls 'http_reply' callback for all filters attached to a stream when HA |
| 708 | * decides to stop the HTTP message processing. |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 709 | * |
| 710 | * Be carefull, this function can be called from the HTTP legacy analyzers or |
| 711 | * from HTX analyzers. If your filter is compatible with the two modes, use |
| 712 | * IS_HTX_STRM macro on the stream. |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 713 | */ |
| 714 | void |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 715 | flt_http_reply(struct stream *s, short status, const struct buffer *msg) |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 716 | { |
| 717 | struct filter *filter; |
| 718 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 719 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 720 | if (FLT_OPS(filter)->http_reply) |
| 721 | FLT_OPS(filter)->http_reply(s, filter, status, msg); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | |
| 725 | /* |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 726 | * Calls 'http_forward_data' callback for all "data" filters attached to a HTTP |
| 727 | * legacy stream. This function is called when some data can be forwarded in the |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 728 | * AN_REQ_HTTP_XFER_BODY and AN_RES_HTTP_XFER_BODY analyzers. It takes care to |
| 729 | * update the forward offset of filters and adjusts "forwardable" data to be |
| 730 | * sure that a filter cannot forward more data than its predecessors. A filter |
| 731 | * can choose to not forward all parsed data. Returns a negative value if an |
| 732 | * error occurs, else the number of forwarded bytes. |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 733 | * |
| 734 | * DEPRECATED FUNCTION - CALLED FROM LEGACY HTTP ANALYZERS |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 735 | */ |
| 736 | int |
| 737 | flt_http_forward_data(struct stream *s, struct http_msg *msg, unsigned int len) |
| 738 | { |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 739 | struct filter *filter; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 740 | int ret = len; |
| 741 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 742 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 743 | unsigned int *nxt, *fwd; |
| 744 | |
| 745 | /* Call "data" filters only */ |
| 746 | if (!IS_DATA_FILTER(filter, msg->chn)) |
| 747 | continue; |
| 748 | |
Christopher Faulet | 2fb2880 | 2015-12-01 10:40:57 +0100 | [diff] [blame] | 749 | /* If the HTTP parser is ahead, we update the next offset of the |
| 750 | * current filter. This happens for chunked messages, when the |
| 751 | * chunk envelope is parsed. */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 752 | nxt = &FLT_NXT(filter, msg->chn); |
| 753 | fwd = &FLT_FWD(filter, msg->chn); |
| 754 | if (msg->next > *nxt) |
| 755 | *nxt = msg->next; |
| 756 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 757 | if (FLT_OPS(filter)->http_forward_data) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 758 | /* Remove bytes that the current filter considered as |
| 759 | * forwarded */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 760 | ret = FLT_OPS(filter)->http_forward_data(s, filter, msg, ret - *fwd); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 761 | if (ret < 0) |
| 762 | goto end; |
| 763 | } |
| 764 | |
| 765 | /* Adjust bytes that the current filter considers as |
| 766 | * forwarded */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 767 | *fwd += ret; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 768 | |
| 769 | /* And set this value as the bound for the next filter. It will |
| 770 | * not able to forward more data than the current one. */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 771 | ret = *fwd; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | if (!ret) |
| 775 | goto end; |
| 776 | |
| 777 | /* Finally, adjust filters offsets by removing data that HAProxy will |
| 778 | * forward. */ |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 779 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 780 | if (!IS_DATA_FILTER(filter, msg->chn)) |
| 781 | continue; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 782 | FLT_NXT(filter, msg->chn) -= ret; |
| 783 | FLT_FWD(filter, msg->chn) -= ret; |
| 784 | } |
| 785 | end: |
| 786 | return ret; |
| 787 | } |
| 788 | |
| 789 | /* |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 790 | * Calls 'http_payload' callback for all "data" filters attached to a |
| 791 | * stream. This function is called when some data can be forwarded in the |
| 792 | * AN_REQ_HTTP_XFER_BODY and AN_RES_HTTP_XFER_BODY analyzers. It takes care to |
| 793 | * update the filters and the stream offset to be sure that a filter cannot |
| 794 | * forward more data than its predecessors. A filter can choose to not forward |
| 795 | * all data. Returns a negative value if an error occurs, else the number of |
| 796 | * forwarded bytes. |
| 797 | * |
| 798 | * Be carefull, this callback is only called from HTX analyzers. So the |
| 799 | * channel's buffer must be considered as an HTX structured. Of course, your |
| 800 | * filter must support HTX streams. |
| 801 | */ |
| 802 | int |
| 803 | flt_http_payload(struct stream *s, struct http_msg *msg, unsigned int len) |
| 804 | { |
| 805 | struct filter *filter; |
| 806 | unsigned long long *strm_off = &FLT_STRM_OFF(s, msg->chn); |
Christopher Faulet | 421e769 | 2019-06-13 11:16:45 +0200 | [diff] [blame] | 807 | unsigned int out = co_data(msg->chn); |
Christopher Faulet | 11920a4 | 2020-02-26 15:47:22 +0100 | [diff] [blame] | 808 | int ret, data; |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 809 | |
Christopher Faulet | f127c3e | 2021-01-25 12:02:00 +0100 | [diff] [blame] | 810 | strm_flt(s)->flags &= ~STRM_FLT_FL_HOLD_HTTP_HDRS; |
| 811 | |
Christopher Faulet | 11920a4 | 2020-02-26 15:47:22 +0100 | [diff] [blame] | 812 | ret = data = len - out; |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 813 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | 7102f54 | 2020-11-24 09:49:01 +0100 | [diff] [blame] | 814 | unsigned long long *flt_off = &FLT_OFF(filter, msg->chn); |
| 815 | unsigned int offset = *flt_off - *strm_off; |
| 816 | |
| 817 | /* Call http_payload for filters only. Forward all data for |
| 818 | * others and update the filter offset |
| 819 | */ |
| 820 | if (!IS_DATA_FILTER(filter, msg->chn)) { |
| 821 | *flt_off += data - offset; |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 822 | continue; |
Christopher Faulet | 7102f54 | 2020-11-24 09:49:01 +0100 | [diff] [blame] | 823 | } |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 824 | |
Christopher Faulet | 7102f54 | 2020-11-24 09:49:01 +0100 | [diff] [blame] | 825 | if (FLT_OPS(filter)->http_payload) { |
Christopher Faulet | a2f67b3 | 2020-02-07 16:40:33 +0100 | [diff] [blame] | 826 | ret = FLT_OPS(filter)->http_payload(s, filter, msg, out + offset, data - offset); |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 827 | if (ret < 0) |
| 828 | goto end; |
Christopher Faulet | 31df636 | 2020-02-24 16:20:09 +0100 | [diff] [blame] | 829 | data = ret + *flt_off - *strm_off; |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 830 | *flt_off += ret; |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 831 | } |
| 832 | } |
Christopher Faulet | a2f67b3 | 2020-02-07 16:40:33 +0100 | [diff] [blame] | 833 | |
Christopher Faulet | f127c3e | 2021-01-25 12:02:00 +0100 | [diff] [blame] | 834 | /* If nothing was forwarded yet, we take care to hold the headers if |
| 835 | * following conditions are met : |
| 836 | * |
| 837 | * - *strm_off == 0 (nothing forwarded yet) |
| 838 | * - ret == 0 (no data forwarded at all on this turn) |
| 839 | * - STRM_FLT_FL_HOLD_HTTP_HDRS flag set (at least one filter want to hold the headers) |
| 840 | * |
| 841 | * Be careful, STRM_FLT_FL_HOLD_HTTP_HDRS is removed before each http_payload loop. |
| 842 | * Thus, it must explicitly be set when necessary. We must do that to hold the headers |
| 843 | * when there is no payload. |
| 844 | */ |
| 845 | if (!ret && !*strm_off && (strm_flt(s)->flags & STRM_FLT_FL_HOLD_HTTP_HDRS)) |
| 846 | goto end; |
| 847 | |
| 848 | ret = data; |
| 849 | *strm_off += ret; |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 850 | end: |
| 851 | return ret; |
| 852 | } |
| 853 | |
| 854 | /* |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 855 | * Calls 'channel_start_analyze' callback for all filters attached to a |
| 856 | * stream. This function is called when we start to analyze a request or a |
| 857 | * response. For frontend filters, it is called before all other analyzers. For |
| 858 | * backend ones, it is called before all backend |
| 859 | * analyzers. 'channel_start_analyze' callback is resumable, so this function |
| 860 | * returns 0 if an error occurs or if it needs to wait, any other value |
| 861 | * otherwise. |
| 862 | */ |
| 863 | int |
| 864 | flt_start_analyze(struct stream *s, struct channel *chn, unsigned int an_bit) |
| 865 | { |
| 866 | int ret = 1; |
| 867 | |
| 868 | /* If this function is called, this means there is at least one filter, |
| 869 | * so we do not need to check the filter list's emptiness. */ |
| 870 | |
Christopher Faulet | e600624 | 2017-03-10 11:52:44 +0100 | [diff] [blame] | 871 | /* Set flag on channel to tell that the channel is filtered */ |
| 872 | chn->flags |= CF_FLT_ANALYZE; |
| 873 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 874 | RESUME_FILTER_LOOP(s, chn) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 875 | if (!(chn->flags & CF_ISRESP)) { |
| 876 | if (an_bit == AN_REQ_FLT_START_BE && |
| 877 | !(filter->flags & FLT_FL_IS_BACKEND_FILTER)) |
| 878 | continue; |
| 879 | } |
| 880 | else { |
| 881 | if (an_bit == AN_RES_FLT_START_BE && |
| 882 | !(filter->flags & FLT_FL_IS_BACKEND_FILTER)) |
| 883 | continue; |
| 884 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 885 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 886 | FLT_NXT(filter, chn) = 0; |
| 887 | FLT_FWD(filter, chn) = 0; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 888 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 889 | if (FLT_OPS(filter)->channel_start_analyze) { |
| 890 | ret = FLT_OPS(filter)->channel_start_analyze(s, filter, chn); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 891 | if (ret <= 0) |
| 892 | BREAK_EXECUTION(s, chn, end); |
| 893 | } |
| 894 | } RESUME_FILTER_END; |
| 895 | |
| 896 | end: |
| 897 | return handle_analyzer_result(s, chn, an_bit, ret); |
| 898 | } |
| 899 | |
| 900 | /* |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 901 | * Calls 'channel_pre_analyze' callback for all filters attached to a |
| 902 | * stream. This function is called BEFORE each analyzer attached to a channel, |
| 903 | * expects analyzers responsible for data sending. 'channel_pre_analyze' |
| 904 | * callback is resumable, so this function returns 0 if an error occurs or if it |
| 905 | * needs to wait, any other value otherwise. |
| 906 | * |
| 907 | * Note this function can be called many times for the same analyzer. In fact, |
| 908 | * it is called until the analyzer finishes its processing. |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 909 | */ |
| 910 | int |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 911 | flt_pre_analyze(struct stream *s, struct channel *chn, unsigned int an_bit) |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 912 | { |
| 913 | int ret = 1; |
| 914 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 915 | RESUME_FILTER_LOOP(s, chn) { |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 916 | if (FLT_OPS(filter)->channel_pre_analyze && (filter->pre_analyzers & an_bit)) { |
| 917 | ret = FLT_OPS(filter)->channel_pre_analyze(s, filter, chn, an_bit); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 918 | if (ret <= 0) |
| 919 | BREAK_EXECUTION(s, chn, check_result); |
| 920 | } |
| 921 | } RESUME_FILTER_END; |
| 922 | |
| 923 | check_result: |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 924 | return handle_analyzer_result(s, chn, 0, ret); |
| 925 | } |
| 926 | |
| 927 | /* |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 928 | * Calls 'channel_post_analyze' callback for all filters attached to a |
| 929 | * stream. This function is called AFTER each analyzer attached to a channel, |
| 930 | * expects analyzers responsible for data sending. 'channel_post_analyze' |
| 931 | * callback is NOT resumable, so this function returns a 0 if an error occurs, |
| 932 | * any other value otherwise. |
| 933 | * |
| 934 | * Here, AFTER means when the analyzer finishes its processing. |
| 935 | */ |
| 936 | int |
| 937 | flt_post_analyze(struct stream *s, struct channel *chn, unsigned int an_bit) |
| 938 | { |
| 939 | struct filter *filter; |
| 940 | int ret = 1; |
| 941 | |
| 942 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
| 943 | if (FLT_OPS(filter)->channel_post_analyze && (filter->post_analyzers & an_bit)) { |
| 944 | ret = FLT_OPS(filter)->channel_post_analyze(s, filter, chn, an_bit); |
| 945 | if (ret < 0) |
| 946 | break; |
| 947 | } |
| 948 | } |
| 949 | return handle_analyzer_result(s, chn, 0, ret); |
| 950 | } |
| 951 | |
| 952 | /* |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 953 | * This function is the AN_REQ/RES_FLT_HTTP_HDRS analyzer, used to filter HTTP |
| 954 | * headers or a request or a response. Returns 0 if an error occurs or if it |
| 955 | * needs to wait, any other value otherwise. |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 956 | * |
| 957 | * Be carefull, this function can be called from the HTTP legacy analyzers or |
| 958 | * from HTX analyzers. If your filter is compatible with the two modes, use |
| 959 | * IS_HTX_STRM macro on the stream. |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 960 | */ |
| 961 | int |
| 962 | flt_analyze_http_headers(struct stream *s, struct channel *chn, unsigned int an_bit) |
| 963 | { |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 964 | struct filter *filter; |
| 965 | struct http_msg *msg; |
| 966 | int ret = 1; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 967 | |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 968 | msg = ((chn->flags & CF_ISRESP) ? &s->txn->rsp : &s->txn->req); |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 969 | RESUME_FILTER_LOOP(s, chn) { |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 970 | if (FLT_OPS(filter)->http_headers) { |
| 971 | ret = FLT_OPS(filter)->http_headers(s, filter, msg); |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 972 | if (ret <= 0) |
| 973 | BREAK_EXECUTION(s, chn, check_result); |
| 974 | } |
| 975 | } RESUME_FILTER_END; |
| 976 | |
Christopher Faulet | df7d681 | 2020-02-12 15:31:20 +0100 | [diff] [blame] | 977 | if (IS_HTX_STRM(s)) { |
| 978 | if (HAS_DATA_FILTERS(s, chn)) { |
| 979 | size_t data = http_get_hdrs_size(htxbuf(&chn->buf)); |
| 980 | struct filter *f; |
| 981 | |
Christopher Faulet | 7102f54 | 2020-11-24 09:49:01 +0100 | [diff] [blame] | 982 | list_for_each_entry(f, &strm_flt(s)->filters, list) |
| 983 | FLT_OFF(f, chn) = data; |
Christopher Faulet | df7d681 | 2020-02-12 15:31:20 +0100 | [diff] [blame] | 984 | } |
| 985 | } |
Christopher Faulet | 75bc913 | 2018-11-30 15:18:09 +0100 | [diff] [blame] | 986 | else { |
| 987 | /* We increase next offset of all "data" filters after all processing on |
| 988 | * headers because any filter can alter them. So the definitive size of |
| 989 | * headers (msg->sov) is only known when all filters have been |
| 990 | * called. */ |
| 991 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
| 992 | /* Handle "data" filters only */ |
| 993 | if (!IS_DATA_FILTER(filter, chn)) |
| 994 | continue; |
| 995 | FLT_NXT(filter, chn) = msg->sov; |
| 996 | } |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | check_result: |
| 1000 | return handle_analyzer_result(s, chn, an_bit, ret); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | /* |
| 1004 | * Calls 'channel_end_analyze' callback for all filters attached to a |
| 1005 | * stream. This function is called when we stop to analyze a request or a |
| 1006 | * response. It is called after all other analyzers. 'channel_end_analyze' |
| 1007 | * callback is resumable, so this function returns 0 if an error occurs or if it |
| 1008 | * needs to wait, any other value otherwise. |
| 1009 | */ |
| 1010 | int |
| 1011 | flt_end_analyze(struct stream *s, struct channel *chn, unsigned int an_bit) |
| 1012 | { |
| 1013 | int ret = 1; |
| 1014 | |
Christopher Faulet | e600624 | 2017-03-10 11:52:44 +0100 | [diff] [blame] | 1015 | /* Check if all filters attached on the stream have finished their |
| 1016 | * processing on this channel. */ |
| 1017 | if (!(chn->flags & CF_FLT_ANALYZE)) |
| 1018 | goto sync; |
| 1019 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1020 | RESUME_FILTER_LOOP(s, chn) { |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1021 | FLT_NXT(filter, chn) = 0; |
| 1022 | FLT_FWD(filter, chn) = 0; |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1023 | unregister_data_filter(s, chn, filter); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1024 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 1025 | if (FLT_OPS(filter)->channel_end_analyze) { |
| 1026 | ret = FLT_OPS(filter)->channel_end_analyze(s, filter, chn); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1027 | if (ret <= 0) |
| 1028 | BREAK_EXECUTION(s, chn, end); |
| 1029 | } |
| 1030 | } RESUME_FILTER_END; |
| 1031 | |
Christopher Faulet | e600624 | 2017-03-10 11:52:44 +0100 | [diff] [blame] | 1032 | end: |
| 1033 | /* We don't remove yet this analyzer because we need to synchronize the |
| 1034 | * both channels. So here, we just remove the flag CF_FLT_ANALYZE. */ |
| 1035 | ret = handle_analyzer_result(s, chn, 0, ret); |
Christopher Faulet | 570f799 | 2017-07-06 15:53:02 +0200 | [diff] [blame] | 1036 | if (ret) { |
Christopher Faulet | e600624 | 2017-03-10 11:52:44 +0100 | [diff] [blame] | 1037 | chn->flags &= ~CF_FLT_ANALYZE; |
Christopher Faulet | 02c7b22 | 2015-12-22 12:01:29 +0100 | [diff] [blame] | 1038 | |
Christopher Faulet | 570f799 | 2017-07-06 15:53:02 +0200 | [diff] [blame] | 1039 | /* Pretend there is an activity on both channels. Flag on the |
| 1040 | * current one will be automatically removed, so only the other |
| 1041 | * one will remain. This is a way to be sure that |
| 1042 | * 'channel_end_analyze' callback will have a chance to be |
| 1043 | * called at least once for the other side to finish the current |
Joseph Herlant | b35ea68 | 2018-11-15 12:24:23 -0800 | [diff] [blame] | 1044 | * processing. Of course, this is the filter responsibility to |
Christopher Faulet | 570f799 | 2017-07-06 15:53:02 +0200 | [diff] [blame] | 1045 | * wakeup the stream if it choose to loop on this callback. */ |
| 1046 | s->req.flags |= CF_WAKE_ONCE; |
| 1047 | s->res.flags |= CF_WAKE_ONCE; |
| 1048 | } |
| 1049 | |
| 1050 | |
Christopher Faulet | e600624 | 2017-03-10 11:52:44 +0100 | [diff] [blame] | 1051 | sync: |
| 1052 | /* Now we can check if filters have finished their work on the both |
| 1053 | * channels */ |
| 1054 | if (!(s->req.flags & CF_FLT_ANALYZE) && !(s->res.flags & CF_FLT_ANALYZE)) { |
| 1055 | /* Sync channels by removing this analyzer for the both channels */ |
| 1056 | s->req.analysers &= ~AN_REQ_FLT_END; |
| 1057 | s->res.analysers &= ~AN_RES_FLT_END; |
Christopher Faulet | c6062be | 2016-10-31 11:22:37 +0100 | [diff] [blame] | 1058 | |
Christopher Faulet | e600624 | 2017-03-10 11:52:44 +0100 | [diff] [blame] | 1059 | /* Clean up the HTTP transaction if needed */ |
| 1060 | if (s->txn && (s->txn->flags & TX_WAIT_CLEANUP)) |
| 1061 | http_end_txn_clean_session(s); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1062 | |
Christopher Faulet | e600624 | 2017-03-10 11:52:44 +0100 | [diff] [blame] | 1063 | /* Remove backend filters from the list */ |
| 1064 | flt_stream_release(s, 1); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1065 | } |
Christopher Faulet | 2b553de | 2017-03-30 11:13:22 +0200 | [diff] [blame] | 1066 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1067 | return ret; |
| 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | /* |
| 1072 | * Calls 'tcp_data' callback for all "data" filters attached to a stream. This |
| 1073 | * function is called when incoming data are available. It takes care to update |
| 1074 | * the next offset of filters and adjusts available data to be sure that a |
| 1075 | * filter cannot parse more data than its predecessors. A filter can choose to |
| 1076 | * not consume all available data. Returns -1 if an error occurs, the number of |
| 1077 | * consumed bytes otherwise. |
| 1078 | */ |
| 1079 | static int |
| 1080 | flt_data(struct stream *s, struct channel *chn) |
| 1081 | { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1082 | struct filter *filter; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1083 | unsigned int buf_i; |
Christopher Faulet | 55048a4 | 2016-06-21 10:44:32 +0200 | [diff] [blame] | 1084 | int delta = 0, ret = 0; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1085 | |
| 1086 | /* Save buffer state */ |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 1087 | buf_i = ci_data(chn); |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1088 | |
| 1089 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1090 | unsigned int *nxt; |
| 1091 | |
| 1092 | /* Call "data" filters only */ |
| 1093 | if (!IS_DATA_FILTER(filter, chn)) |
| 1094 | continue; |
| 1095 | |
| 1096 | nxt = &FLT_NXT(filter, chn); |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 1097 | if (FLT_OPS(filter)->tcp_data) { |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 1098 | unsigned int i = ci_data(chn); |
Christopher Faulet | 55048a4 | 2016-06-21 10:44:32 +0200 | [diff] [blame] | 1099 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 1100 | ret = FLT_OPS(filter)->tcp_data(s, filter, chn); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1101 | if (ret < 0) |
| 1102 | break; |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 1103 | delta += (int)(ci_data(chn) - i); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1104 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1105 | /* Increase next offset of the current filter */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1106 | *nxt += ret; |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1107 | |
| 1108 | /* And set this value as the bound for the next |
| 1109 | * filter. It will not able to parse more data than the |
| 1110 | * current one. */ |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 1111 | b_set_data(&chn->buf, co_data(chn) + *nxt); |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1112 | } |
| 1113 | else { |
| 1114 | /* Consume all available data */ |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 1115 | *nxt = ci_data(chn); |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1116 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1117 | |
| 1118 | /* Update <ret> value to be sure to have the last one when we |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1119 | * exit from the loop. This value will be used to know how much |
| 1120 | * data are "forwardable" */ |
| 1121 | ret = *nxt; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1122 | } |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1123 | |
| 1124 | /* Restore the original buffer state */ |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 1125 | b_set_data(&chn->buf, co_data(chn) + buf_i + delta); |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1126 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1127 | return ret; |
| 1128 | } |
| 1129 | |
| 1130 | /* |
| 1131 | * Calls 'tcp_forward_data' callback for all "data" filters attached to a |
| 1132 | * stream. This function is called when some data can be forwarded. It takes |
| 1133 | * care to update the forward offset of filters and adjusts "forwardable" data |
| 1134 | * to be sure that a filter cannot forward more data than its predecessors. A |
| 1135 | * filter can choose to not forward all parsed data. Returns a negative value if |
| 1136 | * an error occurs, else the number of forwarded bytes. |
| 1137 | */ |
| 1138 | static int |
| 1139 | flt_forward_data(struct stream *s, struct channel *chn, unsigned int len) |
| 1140 | { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1141 | struct filter *filter; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1142 | int ret = len; |
| 1143 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1144 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1145 | unsigned int *fwd; |
| 1146 | |
| 1147 | /* Call "data" filters only */ |
| 1148 | if (!IS_DATA_FILTER(filter, chn)) |
| 1149 | continue; |
| 1150 | |
| 1151 | fwd = &FLT_FWD(filter, chn); |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 1152 | if (FLT_OPS(filter)->tcp_forward_data) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1153 | /* Remove bytes that the current filter considered as |
| 1154 | * forwarded */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 1155 | ret = FLT_OPS(filter)->tcp_forward_data(s, filter, chn, ret - *fwd); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1156 | if (ret < 0) |
| 1157 | goto end; |
| 1158 | } |
| 1159 | |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1160 | /* Adjust bytes that the current filter considers as |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1161 | * forwarded */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1162 | *fwd += ret; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1163 | |
| 1164 | /* And set this value as the bound for the next filter. It will |
| 1165 | * not able to forward more data than the current one. */ |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1166 | ret = *fwd; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | if (!ret) |
| 1170 | goto end; |
| 1171 | |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1172 | /* Finally, adjust filters offsets by removing data that HAProxy will |
| 1173 | * forward. */ |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 1174 | list_for_each_entry(filter, &strm_flt(s)->filters, list) { |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1175 | if (!IS_DATA_FILTER(filter, chn)) |
| 1176 | continue; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1177 | FLT_NXT(filter, chn) -= ret; |
| 1178 | FLT_FWD(filter, chn) -= ret; |
| 1179 | } |
| 1180 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1181 | end: |
| 1182 | return ret; |
| 1183 | } |
| 1184 | |
| 1185 | /* |
| 1186 | * Called when TCP data must be filtered on a channel. This function is the |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 1187 | * AN_REQ/RES_FLT_XFER_DATA analyzer. When called, it is responsible to forward |
| 1188 | * data when the proxy is not in http mode. Behind the scene, it calls |
| 1189 | * consecutively 'tcp_data' and 'tcp_forward_data' callbacks for all "data" |
| 1190 | * filters attached to a stream. Returns 0 if an error occurs or if it needs to |
| 1191 | * wait, any other value otherwise. |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1192 | */ |
| 1193 | int |
| 1194 | flt_xfer_data(struct stream *s, struct channel *chn, unsigned int an_bit) |
| 1195 | { |
| 1196 | int ret = 1; |
| 1197 | |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1198 | /* If there is no "data" filters, we do nothing */ |
Christopher Faulet | 166bd75 | 2019-11-08 15:31:49 +0100 | [diff] [blame] | 1199 | if (!HAS_DATA_FILTERS(s, chn) || (s->flags & SF_HTX)) |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1200 | goto end; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1201 | |
| 1202 | /* Be sure that the output is still opened. Else we stop the data |
| 1203 | * filtering. */ |
| 1204 | if ((chn->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) || |
Willy Tarreau | 44a41a8 | 2018-06-19 07:16:31 +0200 | [diff] [blame] | 1205 | ((chn->flags & CF_SHUTW) && (chn->to_forward || co_data(chn)))) |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1206 | goto end; |
| 1207 | |
| 1208 | /* Let all "data" filters parsing incoming data */ |
| 1209 | ret = flt_data(s, chn); |
| 1210 | if (ret < 0) |
| 1211 | goto end; |
| 1212 | |
| 1213 | /* And forward them */ |
| 1214 | ret = flt_forward_data(s, chn, ret); |
| 1215 | if (ret < 0) |
| 1216 | goto end; |
| 1217 | |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1218 | /* Consume data that all filters consider as forwarded. */ |
Willy Tarreau | bcbd393 | 2018-06-06 07:13:22 +0200 | [diff] [blame] | 1219 | c_adv(chn, ret); |
Christopher Faulet | da02e17 | 2015-12-04 09:25:05 +0100 | [diff] [blame] | 1220 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1221 | /* Stop waiting data if the input in closed and no data is pending or if |
| 1222 | * the output is closed. */ |
| 1223 | if ((chn->flags & CF_SHUTW) || |
Willy Tarreau | 5ba6552 | 2018-06-15 15:14:53 +0200 | [diff] [blame] | 1224 | ((chn->flags & CF_SHUTR) && !ci_data(chn))) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1225 | ret = 1; |
| 1226 | goto end; |
| 1227 | } |
| 1228 | |
| 1229 | /* Wait for data */ |
| 1230 | return 0; |
| 1231 | end: |
| 1232 | /* Terminate the data filtering. If <ret> is negative, an error was |
| 1233 | * encountered during the filtering. */ |
| 1234 | return handle_analyzer_result(s, chn, an_bit, ret); |
| 1235 | } |
| 1236 | |
| 1237 | /* |
| 1238 | * Handles result of filter's analyzers. It returns 0 if an error occurs or if |
| 1239 | * it needs to wait, any other value otherwise. |
| 1240 | */ |
| 1241 | static int |
| 1242 | handle_analyzer_result(struct stream *s, struct channel *chn, |
| 1243 | unsigned int an_bit, int ret) |
| 1244 | { |
| 1245 | int finst; |
Christopher Faulet | eab13f0 | 2019-09-06 15:24:55 +0200 | [diff] [blame] | 1246 | int status = 0; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1247 | |
| 1248 | if (ret < 0) |
| 1249 | goto return_bad_req; |
| 1250 | else if (!ret) |
| 1251 | goto wait; |
| 1252 | |
| 1253 | /* End of job, return OK */ |
| 1254 | if (an_bit) { |
| 1255 | chn->analysers &= ~an_bit; |
| 1256 | chn->analyse_exp = TICK_ETERNITY; |
| 1257 | } |
| 1258 | return 1; |
| 1259 | |
| 1260 | return_bad_req: |
| 1261 | /* An error occurs */ |
| 1262 | channel_abort(&s->req); |
| 1263 | channel_abort(&s->res); |
| 1264 | |
| 1265 | if (!(chn->flags & CF_ISRESP)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 1266 | s->req.analysers &= AN_REQ_FLT_END; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1267 | finst = SF_FINST_R; |
Christopher Faulet | eab13f0 | 2019-09-06 15:24:55 +0200 | [diff] [blame] | 1268 | status = 400; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1269 | /* FIXME: incr counters */ |
| 1270 | } |
| 1271 | else { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 1272 | s->res.analysers &= AN_RES_FLT_END; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1273 | finst = SF_FINST_H; |
Christopher Faulet | eab13f0 | 2019-09-06 15:24:55 +0200 | [diff] [blame] | 1274 | status = 502; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1275 | /* FIXME: incr counters */ |
| 1276 | } |
| 1277 | |
| 1278 | if (s->txn) { |
| 1279 | /* Do not do that when we are waiting for the next request */ |
Christopher Faulet | eab13f0 | 2019-09-06 15:24:55 +0200 | [diff] [blame] | 1280 | if (s->txn->status > 0) |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1281 | http_reply_and_close(s, s->txn->status, NULL); |
| 1282 | else { |
Christopher Faulet | eab13f0 | 2019-09-06 15:24:55 +0200 | [diff] [blame] | 1283 | s->txn->status = status; |
| 1284 | http_reply_and_close(s, status, http_error_message(s)); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | if (!(s->flags & SF_ERR_MASK)) |
| 1289 | s->flags |= SF_ERR_PRXCOND; |
| 1290 | if (!(s->flags & SF_FINST_MASK)) |
| 1291 | s->flags |= finst; |
| 1292 | return 0; |
| 1293 | |
| 1294 | wait: |
| 1295 | if (!(chn->flags & CF_ISRESP)) |
| 1296 | channel_dont_connect(chn); |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | /* Note: must not be declared <const> as its list will be overwritten. |
| 1302 | * Please take care of keeping this list alphabetically sorted, doing so helps |
| 1303 | * all code contributors. |
| 1304 | * Optional keywords are also declared with a NULL ->parse() function so that |
| 1305 | * the config parser can report an appropriate error when a known keyword was |
| 1306 | * not enabled. */ |
| 1307 | static struct cfg_kw_list cfg_kws = {ILH, { |
| 1308 | { CFG_LISTEN, "filter", parse_filter }, |
| 1309 | { 0, NULL, NULL }, |
| 1310 | } |
| 1311 | }; |
| 1312 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1313 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |
| 1314 | |
Willy Tarreau | 172f5ce | 2018-11-26 11:21:50 +0100 | [diff] [blame] | 1315 | REGISTER_POST_CHECK(flt_init_all); |
| 1316 | REGISTER_PER_THREAD_INIT(flt_init_all_per_thread); |
| 1317 | REGISTER_PER_THREAD_DEINIT(flt_deinit_all_per_thread); |
| 1318 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1319 | /* |
| 1320 | * Local variables: |
| 1321 | * c-indent-level: 8 |
| 1322 | * c-basic-offset: 8 |
| 1323 | * End: |
| 1324 | */ |