blob: 7f8fae43fbc125310573d2f4904b1f66039d5706 [file] [log] [blame]
Christopher Fauletd7c91962015-04-30 11:48:27 +02001/*
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>
19#include <common/namespace.h>
20#include <common/standard.h>
21
22#include <types/filters.h>
23#include <types/proto_http.h>
24
25#include <proto/compression.h>
26#include <proto/filters.h>
Christopher Faulet92d36382015-11-05 13:35:03 +010027#include <proto/flt_http_comp.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020028#include <proto/proto_http.h>
29#include <proto/stream.h>
30#include <proto/stream_interface.h>
31
32/* Pool used to allocate filters */
33struct pool_head *pool2_filter = NULL;
34
35static int handle_analyzer_result(struct stream *s, struct channel *chn, unsigned int an_bit, int ret);
36
37/* - RESUME_FILTER_LOOP and RESUME_FILTER_END must always be used together.
38 * The first one begins a loop and the seconds one ends it.
39 *
40 * - BREAK_EXECUTION must be used to break the loop and set the filter from
41 * which to resume the next time.
42 *
43 * Here is an exemple:
44 *
45 * RESUME_FILTER_LOOP(stream, channel) {
46 * ...
47 * if (cond)
48 * BREAK_EXECUTION(stream, channel, label);
49 * ...
50 * } RESUME_FILTER_END;
51 * ...
52 * label:
53 * ...
54 *
55 */
56#define RESUME_FILTER_LOOP(strm, chn) \
57 do { \
58 struct filter *filter; \
59 \
Christopher Fauletda02e172015-12-04 09:25:05 +010060 if (strm_flt(strm)->current[CHN_IDX(chn)]) { \
61 filter = strm_flt(strm)->current[CHN_IDX(chn)]; \
62 strm_flt(strm)->current[CHN_IDX(chn)] = NULL; \
Christopher Fauletd7c91962015-04-30 11:48:27 +020063 goto resume_execution; \
64 } \
65 \
Christopher Fauletfcf035c2015-12-03 11:48:03 +010066 list_for_each_entry(filter, &strm_flt(s)->filters, list) { \
Christopher Fauletda02e172015-12-04 09:25:05 +010067 resume_execution:
Christopher Fauletd7c91962015-04-30 11:48:27 +020068
69#define RESUME_FILTER_END \
70 } \
71 } while(0)
72
Christopher Fauletda02e172015-12-04 09:25:05 +010073#define BREAK_EXECUTION(strm, chn, label) \
74 do { \
75 strm_flt(strm)->current[CHN_IDX(chn)] = filter; \
76 goto label; \
Christopher Fauletd7c91962015-04-30 11:48:27 +020077 } while (0)
78
79
80/* List head of all known filter keywords */
81static struct flt_kw_list flt_keywords = {
82 .list = LIST_HEAD_INIT(flt_keywords.list)
83};
84
85/*
86 * Registers the filter keyword list <kwl> as a list of valid keywords for next
87 * parsing sessions.
88 */
89void
90flt_register_keywords(struct flt_kw_list *kwl)
91{
92 LIST_ADDQ(&flt_keywords.list, &kwl->list);
93}
94
95/*
96 * Returns a pointer to the filter keyword <kw>, or NULL if not found. If the
97 * keyword is found with a NULL ->parse() function, then an attempt is made to
98 * find one with a valid ->parse() function. This way it is possible to declare
99 * platform-dependant, known keywords as NULL, then only declare them as valid
100 * if some options are met. Note that if the requested keyword contains an
101 * opening parenthesis, everything from this point is ignored.
102 */
103struct flt_kw *
104flt_find_kw(const char *kw)
105{
106 int index;
107 const char *kwend;
108 struct flt_kw_list *kwl;
109 struct flt_kw *ret = NULL;
110
111 kwend = strchr(kw, '(');
112 if (!kwend)
113 kwend = kw + strlen(kw);
114
115 list_for_each_entry(kwl, &flt_keywords.list, list) {
116 for (index = 0; kwl->kw[index].kw != NULL; index++) {
117 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
118 kwl->kw[index].kw[kwend-kw] == 0) {
119 if (kwl->kw[index].parse)
120 return &kwl->kw[index]; /* found it !*/
121 else
122 ret = &kwl->kw[index]; /* may be OK */
123 }
124 }
125 }
126 return ret;
127}
128
129/*
130 * Dumps all registered "filter" keywords to the <out> string pointer. The
131 * unsupported keywords are only dumped if their supported form was not found.
132 */
133void
134flt_dump_kws(char **out)
135{
136 struct flt_kw_list *kwl;
137 int index;
138
139 *out = NULL;
140 list_for_each_entry(kwl, &flt_keywords.list, list) {
141 for (index = 0; kwl->kw[index].kw != NULL; index++) {
142 if (kwl->kw[index].parse ||
143 flt_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) {
144 memprintf(out, "%s[%4s] %s%s\n", *out ? *out : "",
145 kwl->scope,
146 kwl->kw[index].kw,
147 kwl->kw[index].parse ? "" : " (not supported)");
148 }
149 }
150 }
151}
152
153/*
Christopher Fauletb3f4e142016-03-07 12:46:38 +0100154 * Lists the known filters on <out>
155 */
156void
157list_filters(FILE *out)
158{
159 char *filters, *p, *f;
160
161 fprintf(out, "Available filters :\n");
162 flt_dump_kws(&filters);
163 for (p = filters; (f = strtok_r(p,"\n",&p));)
164 fprintf(out, "\t%s\n", f);
165 free(filters);
166}
167
168/*
Christopher Fauletd7c91962015-04-30 11:48:27 +0200169 * Parses the "filter" keyword. All keywords must be handled by filters
170 * themselves
171 */
172static int
173parse_filter(char **args, int section_type, struct proxy *curpx,
174 struct proxy *defpx, const char *file, int line, char **err)
175{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100176 struct flt_conf *fconf = NULL;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200177
178 /* Filter cannot be defined on a default proxy */
179 if (curpx == defpx) {
Christopher Fauletcc7317d2016-04-04 10:51:17 +0200180 memprintf(err, "parsing [%s:%d] : %s is not allowed in a 'default' section.",
Christopher Fauletd7c91962015-04-30 11:48:27 +0200181 file, line, args[0]);
182 return -1;
183 }
184 if (!strcmp(args[0], "filter")) {
185 struct flt_kw *kw;
186 int cur_arg;
187
188 if (!*args[1]) {
189 memprintf(err,
190 "parsing [%s:%d] : missing argument for '%s' in %s '%s'.",
191 file, line, args[0], proxy_type_str(curpx), curpx->id);
192 goto error;
193 }
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100194 fconf = calloc(1, sizeof(*fconf));
195 if (!fconf) {
Christopher Fauletd7c91962015-04-30 11:48:27 +0200196 memprintf(err, "'%s' : out of memory", args[0]);
197 goto error;
198 }
Christopher Fauletd7c91962015-04-30 11:48:27 +0200199
200 cur_arg = 1;
201 kw = flt_find_kw(args[cur_arg]);
202 if (kw) {
203 if (!kw->parse) {
204 memprintf(err, "parsing [%s:%d] : '%s' : "
205 "'%s' option is not implemented in this version (check build options).",
206 file, line, args[0], args[cur_arg]);
207 goto error;
208 }
Thierry Fournier3610c392016-04-13 18:27:51 +0200209 if (kw->parse(args, &cur_arg, curpx, fconf, err, kw->private) != 0) {
Christopher Fauletd7c91962015-04-30 11:48:27 +0200210 if (err && *err)
211 memprintf(err, "'%s' : '%s'",
212 args[0], *err);
213 else
214 memprintf(err, "'%s' : error encountered while processing '%s'",
215 args[0], args[cur_arg]);
216 goto error;
217 }
218 }
219 else {
220 flt_dump_kws(err);
221 indent_msg(err, 4);
222 memprintf(err, "'%s' : unknown keyword '%s'.%s%s",
223 args[0], args[cur_arg],
224 err && *err ? " Registered keywords :" : "", err && *err ? *err : "");
225 goto error;
226 }
227 if (*args[cur_arg]) {
228 memprintf(err, "'%s %s' : unknown keyword '%s'.",
229 args[0], args[1], args[cur_arg]);
230 goto error;
231 }
Christopher Faulet00e818a2016-04-19 17:00:44 +0200232 if (fconf->ops == NULL) {
233 memprintf(err, "'%s %s' : no callbacks defined.",
234 args[0], args[1]);
235 goto error;
236 }
Christopher Fauletd7c91962015-04-30 11:48:27 +0200237
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100238 LIST_ADDQ(&curpx->filter_configs, &fconf->list);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200239 }
240 return 0;
241
242 error:
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100243 free(fconf);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200244 return -1;
245
246
247}
248
249/*
250 * Calls 'init' callback for all filters attached to a proxy. This happens after
251 * the configuration parsing. Filters can finish to fill their config. Returns
252 * (ERR_ALERT|ERR_FATAL) if an error occurs, 0 otherwise.
253 */
254int
255flt_init(struct proxy *proxy)
256{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100257 struct flt_conf *fconf;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200258
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100259 list_for_each_entry(fconf, &proxy->filter_configs, list) {
260 if (fconf->ops->init && fconf->ops->init(proxy, fconf) < 0)
Christopher Fauletd7c91962015-04-30 11:48:27 +0200261 return ERR_ALERT|ERR_FATAL;
262 }
263 return 0;
264}
265
266/*
267 * Calls 'check' callback for all filters attached to a proxy. This happens
268 * after the configuration parsing but before filters initialization. Returns
269 * the number of encountered errors.
270 */
271int
272flt_check(struct proxy *proxy)
273{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100274 struct flt_conf *fconf;
275 int err = 0;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200276
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100277 list_for_each_entry(fconf, &proxy->filter_configs, list) {
278 if (fconf->ops->check)
279 err += fconf->ops->check(proxy, fconf);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200280 }
Christopher Faulet92d36382015-11-05 13:35:03 +0100281 err += check_legacy_http_comp_flt(proxy);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200282 return err;
283}
284
285/*
286 * Calls 'denit' callback for all filters attached to a proxy. This happens when
287 * HAProxy is stopped.
288 */
289void
290flt_deinit(struct proxy *proxy)
291{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100292 struct flt_conf *fconf, *back;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200293
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100294 list_for_each_entry_safe(fconf, back, &proxy->filter_configs, list) {
295 if (fconf->ops->deinit)
296 fconf->ops->deinit(proxy, fconf);
297 LIST_DEL(&fconf->list);
298 free(fconf);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200299 }
300}
301
Christopher Faulet92d36382015-11-05 13:35:03 +0100302/* Attaches a filter to a stream. Returns -1 if an error occurs, 0 otherwise. */
303static int
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100304flt_stream_add_filter(struct stream *s, struct flt_conf *fconf, unsigned int flags)
Christopher Faulet92d36382015-11-05 13:35:03 +0100305{
306 struct filter *f = pool_alloc2(pool2_filter);
307 if (!f) /* not enough memory */
308 return -1;
309 memset(f, 0, sizeof(*f));
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100310 f->config = fconf;
Christopher Fauletda02e172015-12-04 09:25:05 +0100311 f->flags |= flags;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100312 LIST_ADDQ(&strm_flt(s)->filters, &f->list);
Christopher Fauletda02e172015-12-04 09:25:05 +0100313 strm_flt(s)->flags |= STRM_FLT_FL_HAS_FILTERS;
Christopher Faulet92d36382015-11-05 13:35:03 +0100314 return 0;
315}
316
317/*
318 * Called when a stream is created. It attaches all frontend filters to the
319 * stream. Returns -1 if an error occurs, 0 otherwise.
320 */
321int
322flt_stream_init(struct stream *s)
323{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100324 struct flt_conf *fconf;
Christopher Faulet92d36382015-11-05 13:35:03 +0100325
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100326 memset(strm_flt(s), 0, sizeof(*strm_flt(s)));
327 LIST_INIT(&strm_flt(s)->filters);
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100328 list_for_each_entry(fconf, &strm_fe(s)->filter_configs, list) {
329 if (flt_stream_add_filter(s, fconf, 0) < 0)
Christopher Faulet92d36382015-11-05 13:35:03 +0100330 return -1;
331 }
332 return 0;
333}
334
335/*
336 * Called when a stream is closed or when analyze ends (For an HTTP stream, this
337 * happens after each request/response exchange). When analyze ends, backend
338 * filters are removed. When the stream is closed, all filters attached to the
339 * stream are removed.
340 */
341void
342flt_stream_release(struct stream *s, int only_backend)
343{
344 struct filter *filter, *back;
345
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100346 list_for_each_entry_safe(filter, back, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100347 if (!only_backend || (filter->flags & FLT_FL_IS_BACKEND_FILTER)) {
Christopher Faulet92d36382015-11-05 13:35:03 +0100348 LIST_DEL(&filter->list);
349 pool_free2(pool2_filter, filter);
350 }
351 }
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100352 if (LIST_ISEMPTY(&strm_flt(s)->filters))
Christopher Fauletda02e172015-12-04 09:25:05 +0100353 strm_flt(s)->flags &= ~STRM_FLT_FL_HAS_FILTERS;
Christopher Faulet92d36382015-11-05 13:35:03 +0100354}
355
Christopher Fauletd7c91962015-04-30 11:48:27 +0200356/*
357 * Calls 'stream_start' for all filters attached to a stream. This happens when
358 * the stream is created, just after calling flt_stream_init
359 * function. Returns -1 if an error occurs, 0 otherwise.
360 */
361int
362flt_stream_start(struct stream *s)
363{
364 struct filter *filter;
365
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100366 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100367 if (FLT_OPS(filter)->stream_start && FLT_OPS(filter)->stream_start(s, filter) < 0)
Christopher Fauletd7c91962015-04-30 11:48:27 +0200368 return -1;
369 }
370 return 0;
371}
372
373/*
374 * Calls 'stream_stop' for all filters attached to a stream. This happens when
375 * the stream is stopped, just before calling flt_stream_release function.
376 */
377void
378flt_stream_stop(struct stream *s)
379{
380 struct filter *filter;
381
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100382 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100383 if (FLT_OPS(filter)->stream_stop)
384 FLT_OPS(filter)->stream_stop(s, filter);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200385 }
386}
387
Christopher Faulet92d36382015-11-05 13:35:03 +0100388/*
389 * Called when a backend is set for a stream. If the frontend and the backend
390 * are the same, this function does nothing. Else it attaches all backend
391 * filters to the stream. Returns -1 if an error occurs, 0 otherwise.
392 */
393int
394flt_set_stream_backend(struct stream *s, struct proxy *be)
395{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100396 struct flt_conf *fconf;
Christopher Faulet92d36382015-11-05 13:35:03 +0100397
398 if (strm_fe(s) == be)
399 return 0;
400
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100401 list_for_each_entry(fconf, &be->filter_configs, list) {
402 if (flt_stream_add_filter(s, fconf, FLT_FL_IS_BACKEND_FILTER) < 0)
Christopher Faulet92d36382015-11-05 13:35:03 +0100403 return -1;
404 }
405 return 0;
406}
407
Christopher Fauletd7c91962015-04-30 11:48:27 +0200408/*
409 * Calls 'http_data' callback for all "data" filters attached to a stream. This
410 * function is called when incoming data are available (excluding chunks
411 * envelope for chunked messages) in the AN_REQ_HTTP_XFER_BODY and
412 * AN_RES_HTTP_XFER_BODY analyzers. It takes care to update the next offset of
413 * filters and adjusts available data to be sure that a filter cannot parse more
414 * data than its predecessors. A filter can choose to not consume all available
415 * data. Returns -1 if an error occurs, the number of consumed bytes otherwise.
416 */
417int
418flt_http_data(struct stream *s, struct http_msg *msg)
419{
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100420 struct filter *filter;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200421 unsigned int buf_i;
Christopher Faulet55048a42016-06-21 10:44:32 +0200422 int delta = 0, ret = 0;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200423
Christopher Fauletd7c91962015-04-30 11:48:27 +0200424 /* Save buffer state */
Christopher Faulet55048a42016-06-21 10:44:32 +0200425 buf_i = msg->chn->buf->i;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100426
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100427 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100428 unsigned int *nxt;
429
430 /* Call "data" filters only */
431 if (!IS_DATA_FILTER(filter, msg->chn))
432 continue;
433
Christopher Faulet2fb28802015-12-01 10:40:57 +0100434 /* If the HTTP parser is ahead, we update the next offset of the
435 * current filter. This happens for chunked messages, at the
436 * begining of a new chunk. */
Christopher Fauletda02e172015-12-04 09:25:05 +0100437 nxt = &FLT_NXT(filter, msg->chn);
438 if (msg->next > *nxt)
439 *nxt = msg->next;
440
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100441 if (FLT_OPS(filter)->http_data) {
Christopher Faulet55048a42016-06-21 10:44:32 +0200442 unsigned int i = msg->chn->buf->i;
443
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100444 ret = FLT_OPS(filter)->http_data(s, filter, msg);
Christopher Fauletda02e172015-12-04 09:25:05 +0100445 if (ret < 0)
Christopher Fauletd7c91962015-04-30 11:48:27 +0200446 break;
Christopher Faulet55048a42016-06-21 10:44:32 +0200447 delta += (int)(msg->chn->buf->i - i);
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100448
449 /* Update the next offset of the current filter */
Christopher Fauletda02e172015-12-04 09:25:05 +0100450 *nxt += ret;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100451
452 /* And set this value as the bound for the next
453 * filter. It will not able to parse more data than this
454 * one. */
Christopher Faulet55048a42016-06-21 10:44:32 +0200455 msg->chn->buf->i = *nxt;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200456 }
457 else {
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100458 /* Consume all available data and update the next offset
459 * of the current filter. buf->i is untouched here. */
Christopher Faulet55048a42016-06-21 10:44:32 +0200460 ret = MIN(msg->chunk_len + msg->next, msg->chn->buf->i) - *nxt;
Christopher Fauletda02e172015-12-04 09:25:05 +0100461 *nxt += ret;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200462 }
Christopher Fauletd7c91962015-04-30 11:48:27 +0200463 }
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100464
Christopher Fauletd7c91962015-04-30 11:48:27 +0200465 /* Restore the original buffer state */
Christopher Faulet55048a42016-06-21 10:44:32 +0200466 msg->chn->buf->i = buf_i + delta;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100467
Christopher Fauletd7c91962015-04-30 11:48:27 +0200468 return ret;
469}
470
Christopher Fauletd7c91962015-04-30 11:48:27 +0200471/*
472 * Calls 'http_chunk_trailers' callback for all "data" filters attached to a
473 * stream. This function is called for chunked messages only when a part of the
474 * trailers was parsed in the AN_REQ_HTTP_XFER_BODY and AN_RES_HTTP_XFER_BODY
475 * analyzers. Filters can know how much data were parsed by the HTTP parsing
476 * until the last call with the msg->sol value. Returns a negative value if an
477 * error occurs, any other value otherwise.
478 */
479int
480flt_http_chunk_trailers(struct stream *s, struct http_msg *msg)
481{
Christopher Faulet2fb28802015-12-01 10:40:57 +0100482 struct filter *filter;
Christopher Fauletda02e172015-12-04 09:25:05 +0100483 int ret = 1;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200484
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100485 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100486 unsigned int *nxt;
487
488 /* Call "data" filters only */
489 if (!IS_DATA_FILTER(filter, msg->chn))
490 continue;
491
Christopher Faulet2fb28802015-12-01 10:40:57 +0100492 /* Be sure to set the next offset of the filter at the right
493 * place. This is really useful when the first part of the
494 * trailers was parsed. */
Christopher Fauletda02e172015-12-04 09:25:05 +0100495 nxt = &FLT_NXT(filter, msg->chn);
496 *nxt = msg->next;
497
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100498 if (FLT_OPS(filter)->http_chunk_trailers) {
499 ret = FLT_OPS(filter)->http_chunk_trailers(s, filter, msg);
Christopher Faulet2fb28802015-12-01 10:40:57 +0100500 if (ret < 0)
501 break;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200502 }
Christopher Faulet2fb28802015-12-01 10:40:57 +0100503 /* Update the next offset of the current filter. Here all data
504 * are always consumed. */
Christopher Fauletda02e172015-12-04 09:25:05 +0100505 *nxt += msg->sol;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100506 }
Christopher Fauletd7c91962015-04-30 11:48:27 +0200507 return ret;
508}
509
510/*
511 * Calls 'http_end' callback for all filters attached to a stream. All filters
512 * are called here, but only if there is at least one "data" filter. This
513 * functions is called when all data were parsed and forwarded. 'http_end'
514 * callback is resumable, so this function returns a negative value if an error
515 * occurs, 0 if it needs to wait for some reason, any other value otherwise.
516 */
517int
518flt_http_end(struct stream *s, struct http_msg *msg)
519{
520 int ret = 1;
521
Christopher Fauletd7c91962015-04-30 11:48:27 +0200522 RESUME_FILTER_LOOP(s, msg->chn) {
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100523 if (FLT_OPS(filter)->http_end) {
524 ret = FLT_OPS(filter)->http_end(s, filter, msg);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200525 if (ret <= 0)
526 BREAK_EXECUTION(s, msg->chn, end);
527 }
Christopher Fauletd7c91962015-04-30 11:48:27 +0200528 } RESUME_FILTER_END;
529end:
530 return ret;
531}
532
533/*
534 * Calls 'http_reset' callback for all filters attached to a stream. This
535 * happens when a 100-continue response is received.
536 */
537void
538flt_http_reset(struct stream *s, struct http_msg *msg)
539{
540 struct filter *filter;
541
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100542 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100543 if (FLT_OPS(filter)->http_reset)
544 FLT_OPS(filter)->http_reset(s, filter, msg);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200545 }
546}
547
548/*
549 * Calls 'http_reply' callback for all filters attached to a stream when HA
550 * decides to stop the HTTP message processing.
551 */
552void
553flt_http_reply(struct stream *s, short status, const struct chunk *msg)
554{
555 struct filter *filter;
556
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100557 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100558 if (FLT_OPS(filter)->http_reply)
559 FLT_OPS(filter)->http_reply(s, filter, status, msg);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200560 }
561}
562
563/*
564 * Calls 'http_forward_data' callback for all "data" filters attached to a
565 * stream. This function is called when some data can be forwarded in the
566 * AN_REQ_HTTP_XFER_BODY and AN_RES_HTTP_XFER_BODY analyzers. It takes care to
567 * update the forward offset of filters and adjusts "forwardable" data to be
568 * sure that a filter cannot forward more data than its predecessors. A filter
569 * can choose to not forward all parsed data. Returns a negative value if an
570 * error occurs, else the number of forwarded bytes.
571 */
572int
573flt_http_forward_data(struct stream *s, struct http_msg *msg, unsigned int len)
574{
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100575 struct filter *filter;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200576 int ret = len;
577
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100578 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100579 unsigned int *nxt, *fwd;
580
581 /* Call "data" filters only */
582 if (!IS_DATA_FILTER(filter, msg->chn))
583 continue;
584
Christopher Faulet2fb28802015-12-01 10:40:57 +0100585 /* If the HTTP parser is ahead, we update the next offset of the
586 * current filter. This happens for chunked messages, when the
587 * chunk envelope is parsed. */
Christopher Fauletda02e172015-12-04 09:25:05 +0100588 nxt = &FLT_NXT(filter, msg->chn);
589 fwd = &FLT_FWD(filter, msg->chn);
590 if (msg->next > *nxt)
591 *nxt = msg->next;
592
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100593 if (FLT_OPS(filter)->http_forward_data) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100594 /* Remove bytes that the current filter considered as
595 * forwarded */
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100596 ret = FLT_OPS(filter)->http_forward_data(s, filter, msg, ret - *fwd);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200597 if (ret < 0)
598 goto end;
599 }
600
601 /* Adjust bytes that the current filter considers as
602 * forwarded */
Christopher Fauletda02e172015-12-04 09:25:05 +0100603 *fwd += ret;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200604
605 /* And set this value as the bound for the next filter. It will
606 * not able to forward more data than the current one. */
Christopher Fauletda02e172015-12-04 09:25:05 +0100607 ret = *fwd;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200608 }
609
610 if (!ret)
611 goto end;
612
613 /* Finally, adjust filters offsets by removing data that HAProxy will
614 * forward. */
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100615 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100616 if (!IS_DATA_FILTER(filter, msg->chn))
617 continue;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200618 FLT_NXT(filter, msg->chn) -= ret;
619 FLT_FWD(filter, msg->chn) -= ret;
620 }
621 end:
622 return ret;
623}
624
625/*
626 * Calls 'channel_start_analyze' callback for all filters attached to a
627 * stream. This function is called when we start to analyze a request or a
628 * response. For frontend filters, it is called before all other analyzers. For
629 * backend ones, it is called before all backend
630 * analyzers. 'channel_start_analyze' callback is resumable, so this function
631 * returns 0 if an error occurs or if it needs to wait, any other value
632 * otherwise.
633 */
634int
635flt_start_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
636{
637 int ret = 1;
638
639 /* If this function is called, this means there is at least one filter,
640 * so we do not need to check the filter list's emptiness. */
641
642 RESUME_FILTER_LOOP(s, chn) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100643 if (an_bit == AN_FLT_START_BE && !(filter->flags & FLT_FL_IS_BACKEND_FILTER))
Christopher Fauletd7c91962015-04-30 11:48:27 +0200644 continue;
645
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100646 FLT_NXT(filter, chn) = 0;
647 FLT_FWD(filter, chn) = 0;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200648
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100649 if (FLT_OPS(filter)->channel_start_analyze) {
650 ret = FLT_OPS(filter)->channel_start_analyze(s, filter, chn);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200651 if (ret <= 0)
652 BREAK_EXECUTION(s, chn, end);
653 }
654 } RESUME_FILTER_END;
655
656 end:
657 return handle_analyzer_result(s, chn, an_bit, ret);
658}
659
660/*
Christopher Faulet3a394fa2016-05-11 17:13:39 +0200661 * Calls 'channel_pre_analyze' callback for all filters attached to a
662 * stream. This function is called BEFORE each analyzer attached to a channel,
663 * expects analyzers responsible for data sending. 'channel_pre_analyze'
664 * callback is resumable, so this function returns 0 if an error occurs or if it
665 * needs to wait, any other value otherwise.
666 *
667 * Note this function can be called many times for the same analyzer. In fact,
668 * it is called until the analyzer finishes its processing.
Christopher Fauletd7c91962015-04-30 11:48:27 +0200669 */
670int
Christopher Faulet3a394fa2016-05-11 17:13:39 +0200671flt_pre_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
Christopher Fauletd7c91962015-04-30 11:48:27 +0200672{
673 int ret = 1;
674
Christopher Fauletd7c91962015-04-30 11:48:27 +0200675 RESUME_FILTER_LOOP(s, chn) {
Christopher Faulet3a394fa2016-05-11 17:13:39 +0200676 if (FLT_OPS(filter)->channel_pre_analyze && (filter->pre_analyzers & an_bit)) {
677 ret = FLT_OPS(filter)->channel_pre_analyze(s, filter, chn, an_bit);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200678 if (ret <= 0)
679 BREAK_EXECUTION(s, chn, check_result);
680 }
681 } RESUME_FILTER_END;
682
683 check_result:
Christopher Faulet309c6412015-12-02 09:57:32 +0100684 return handle_analyzer_result(s, chn, 0, ret);
685}
686
687/*
Christopher Faulet3a394fa2016-05-11 17:13:39 +0200688 * Calls 'channel_post_analyze' callback for all filters attached to a
689 * stream. This function is called AFTER each analyzer attached to a channel,
690 * expects analyzers responsible for data sending. 'channel_post_analyze'
691 * callback is NOT resumable, so this function returns a 0 if an error occurs,
692 * any other value otherwise.
693 *
694 * Here, AFTER means when the analyzer finishes its processing.
695 */
696int
697flt_post_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
698{
699 struct filter *filter;
700 int ret = 1;
701
702 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
703 if (FLT_OPS(filter)->channel_post_analyze && (filter->post_analyzers & an_bit)) {
704 ret = FLT_OPS(filter)->channel_post_analyze(s, filter, chn, an_bit);
705 if (ret < 0)
706 break;
707 }
708 }
709 return handle_analyzer_result(s, chn, 0, ret);
710}
711
712/*
Christopher Faulet1339d742016-05-11 16:48:33 +0200713 * This function is the AN_FLT_HTTP_HDRS analyzer, used to filter HTTP headers
714 * or a request or a response. Returns 0 if an error occurs or if it needs to
715 * wait, any other value otherwise.
Christopher Faulet309c6412015-12-02 09:57:32 +0100716 */
717int
718flt_analyze_http_headers(struct stream *s, struct channel *chn, unsigned int an_bit)
719{
Christopher Faulet1339d742016-05-11 16:48:33 +0200720 struct filter *filter;
721 struct http_msg *msg;
722 int ret = 1;
Christopher Faulet309c6412015-12-02 09:57:32 +0100723
Christopher Faulet1339d742016-05-11 16:48:33 +0200724 msg = ((chn->flags & CF_ISRESP) ? &s->txn->rsp : &s->txn->req);
Christopher Faulet309c6412015-12-02 09:57:32 +0100725 RESUME_FILTER_LOOP(s, chn) {
Christopher Faulet1339d742016-05-11 16:48:33 +0200726 if (FLT_OPS(filter)->http_headers) {
727 ret = FLT_OPS(filter)->http_headers(s, filter, msg);
Christopher Faulet309c6412015-12-02 09:57:32 +0100728 if (ret <= 0)
729 BREAK_EXECUTION(s, chn, check_result);
730 }
731 } RESUME_FILTER_END;
732
733 /* We increase next offset of all "data" filters after all processing on
734 * headers because any filter can alter them. So the definitive size of
735 * headers (msg->sov) is only known when all filters have been
736 * called. */
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100737 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100738 /* Handle "data" filters only */
739 if (!IS_DATA_FILTER(filter, chn))
740 continue;
Christopher Faulet1339d742016-05-11 16:48:33 +0200741 FLT_NXT(filter, chn) = msg->sov;
Christopher Faulet309c6412015-12-02 09:57:32 +0100742 }
743
744 check_result:
745 return handle_analyzer_result(s, chn, an_bit, ret);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200746}
747
748/*
749 * Calls 'channel_end_analyze' callback for all filters attached to a
750 * stream. This function is called when we stop to analyze a request or a
751 * response. It is called after all other analyzers. 'channel_end_analyze'
752 * callback is resumable, so this function returns 0 if an error occurs or if it
753 * needs to wait, any other value otherwise.
754 */
755int
756flt_end_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
757{
758 int ret = 1;
759
Christopher Fauletd7c91962015-04-30 11:48:27 +0200760 RESUME_FILTER_LOOP(s, chn) {
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100761 FLT_NXT(filter, chn) = 0;
762 FLT_FWD(filter, chn) = 0;
Christopher Fauletda02e172015-12-04 09:25:05 +0100763 unregister_data_filter(s, chn, filter);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200764
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100765 if (FLT_OPS(filter)->channel_end_analyze) {
766 ret = FLT_OPS(filter)->channel_end_analyze(s, filter, chn);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200767 if (ret <= 0)
768 BREAK_EXECUTION(s, chn, end);
769 }
770 } RESUME_FILTER_END;
771
772end:
773 ret = handle_analyzer_result(s, chn, an_bit, ret);
Christopher Faulet02c7b222015-12-22 12:01:29 +0100774
775 /* Check if 'channel_end_analyze' callback has been called for the
776 * request and the response. */
777 if (!(s->req.analysers & AN_FLT_END) && !(s->res.analysers & AN_FLT_END)) {
Christopher Faulet02c7b222015-12-22 12:01:29 +0100778 /* When we are waiting for a new request, so we must reset
779 * stream analyzers. The input must not be closed the request
780 * channel, else it is useless to wait. */
781 if (s->txn && (s->txn->flags & TX_WAIT_NEXT_RQ) && !channel_input_closed(&s->req)) {
782 s->req.analysers = strm_li(s) ? strm_li(s)->analysers : 0;
783 s->res.analysers = 0;
784 }
Christopher Fauletd7c91962015-04-30 11:48:27 +0200785
Christopher Faulet92d36382015-11-05 13:35:03 +0100786 /* Remove backend filters from the list */
787 flt_stream_release(s, 1);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200788 }
789 else if (ret) {
790 /* Analyzer ends only for one channel. So wake up the stream to
791 * be sure to process it for the other side as soon as
792 * possible. */
793 task_wakeup(s->task, TASK_WOKEN_MSG);
794 }
795 return ret;
796}
797
798
799/*
800 * Calls 'tcp_data' callback for all "data" filters attached to a stream. This
801 * function is called when incoming data are available. It takes care to update
802 * the next offset of filters and adjusts available data to be sure that a
803 * filter cannot parse more data than its predecessors. A filter can choose to
804 * not consume all available data. Returns -1 if an error occurs, the number of
805 * consumed bytes otherwise.
806 */
807static int
808flt_data(struct stream *s, struct channel *chn)
809{
Christopher Fauletda02e172015-12-04 09:25:05 +0100810 struct filter *filter;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200811 unsigned int buf_i;
Christopher Faulet55048a42016-06-21 10:44:32 +0200812 int delta = 0, ret = 0;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200813
814 /* Save buffer state */
Christopher Faulet55048a42016-06-21 10:44:32 +0200815 buf_i = chn->buf->i;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100816
817 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100818 unsigned int *nxt;
819
820 /* Call "data" filters only */
821 if (!IS_DATA_FILTER(filter, chn))
822 continue;
823
824 nxt = &FLT_NXT(filter, chn);
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100825 if (FLT_OPS(filter)->tcp_data) {
Christopher Faulet55048a42016-06-21 10:44:32 +0200826 unsigned int i = chn->buf->i;
827
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100828 ret = FLT_OPS(filter)->tcp_data(s, filter, chn);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200829 if (ret < 0)
830 break;
Christopher Faulet55048a42016-06-21 10:44:32 +0200831 delta += (int)(chn->buf->i - i);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200832
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100833 /* Increase next offset of the current filter */
Christopher Fauletda02e172015-12-04 09:25:05 +0100834 *nxt += ret;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100835
836 /* And set this value as the bound for the next
837 * filter. It will not able to parse more data than the
838 * current one. */
Christopher Faulet55048a42016-06-21 10:44:32 +0200839 chn->buf->i = *nxt;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100840 }
841 else {
842 /* Consume all available data */
Christopher Faulet55048a42016-06-21 10:44:32 +0200843 *nxt = chn->buf->i;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100844 }
Christopher Fauletd7c91962015-04-30 11:48:27 +0200845
846 /* Update <ret> value to be sure to have the last one when we
Christopher Fauletda02e172015-12-04 09:25:05 +0100847 * exit from the loop. This value will be used to know how much
848 * data are "forwardable" */
849 ret = *nxt;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200850 }
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100851
852 /* Restore the original buffer state */
Christopher Faulet55048a42016-06-21 10:44:32 +0200853 chn->buf->i = buf_i + delta;
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100854
Christopher Fauletd7c91962015-04-30 11:48:27 +0200855 return ret;
856}
857
858/*
859 * Calls 'tcp_forward_data' callback for all "data" filters attached to a
860 * stream. This function is called when some data can be forwarded. It takes
861 * care to update the forward offset of filters and adjusts "forwardable" data
862 * to be sure that a filter cannot forward more data than its predecessors. A
863 * filter can choose to not forward all parsed data. Returns a negative value if
864 * an error occurs, else the number of forwarded bytes.
865 */
866static int
867flt_forward_data(struct stream *s, struct channel *chn, unsigned int len)
868{
Christopher Fauletda02e172015-12-04 09:25:05 +0100869 struct filter *filter;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200870 int ret = len;
871
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100872 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100873 unsigned int *fwd;
874
875 /* Call "data" filters only */
876 if (!IS_DATA_FILTER(filter, chn))
877 continue;
878
879 fwd = &FLT_FWD(filter, chn);
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100880 if (FLT_OPS(filter)->tcp_forward_data) {
Christopher Fauletd7c91962015-04-30 11:48:27 +0200881 /* Remove bytes that the current filter considered as
882 * forwarded */
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100883 ret = FLT_OPS(filter)->tcp_forward_data(s, filter, chn, ret - *fwd);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200884 if (ret < 0)
885 goto end;
886 }
887
Christopher Fauletda02e172015-12-04 09:25:05 +0100888 /* Adjust bytes that the current filter considers as
Christopher Fauletd7c91962015-04-30 11:48:27 +0200889 * forwarded */
Christopher Fauletda02e172015-12-04 09:25:05 +0100890 *fwd += ret;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200891
892 /* And set this value as the bound for the next filter. It will
893 * not able to forward more data than the current one. */
Christopher Fauletda02e172015-12-04 09:25:05 +0100894 ret = *fwd;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200895 }
896
897 if (!ret)
898 goto end;
899
Christopher Fauletda02e172015-12-04 09:25:05 +0100900 /* Finally, adjust filters offsets by removing data that HAProxy will
901 * forward. */
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100902 list_for_each_entry(filter, &strm_flt(s)->filters, list) {
Christopher Fauletda02e172015-12-04 09:25:05 +0100903 if (!IS_DATA_FILTER(filter, chn))
904 continue;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200905 FLT_NXT(filter, chn) -= ret;
906 FLT_FWD(filter, chn) -= ret;
907 }
908
Christopher Fauletd7c91962015-04-30 11:48:27 +0200909 end:
910 return ret;
911}
912
913/*
914 * Called when TCP data must be filtered on a channel. This function is the
915 * AN_FLT_XFER_DATA analyzer. When called, it is responsible to forward data
916 * when the proxy is not in http mode. Behind the scene, it calls consecutively
917 * 'tcp_data' and 'tcp_forward_data' callbacks for all "data" filters attached
918 * to a stream. Returns 0 if an error occurs or if it needs to wait, any other
919 * value otherwise.
920 */
921int
922flt_xfer_data(struct stream *s, struct channel *chn, unsigned int an_bit)
923{
924 int ret = 1;
925
Christopher Fauletda02e172015-12-04 09:25:05 +0100926 /* If there is no "data" filters, we do nothing */
927 if (!HAS_DATA_FILTERS(s, chn))
928 goto end;
Christopher Fauletd7c91962015-04-30 11:48:27 +0200929
930 /* Be sure that the output is still opened. Else we stop the data
931 * filtering. */
932 if ((chn->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) ||
933 ((chn->flags & CF_SHUTW) && (chn->to_forward || chn->buf->o)))
934 goto end;
935
936 /* Let all "data" filters parsing incoming data */
937 ret = flt_data(s, chn);
938 if (ret < 0)
939 goto end;
940
941 /* And forward them */
942 ret = flt_forward_data(s, chn, ret);
943 if (ret < 0)
944 goto end;
945
Christopher Fauletda02e172015-12-04 09:25:05 +0100946 /* Consume data that all filters consider as forwarded. */
947 b_adv(chn->buf, ret);
948
Christopher Fauletd7c91962015-04-30 11:48:27 +0200949 /* Stop waiting data if the input in closed and no data is pending or if
950 * the output is closed. */
951 if ((chn->flags & CF_SHUTW) ||
952 ((chn->flags & CF_SHUTR) && !buffer_pending(chn->buf))) {
953 ret = 1;
954 goto end;
955 }
956
957 /* Wait for data */
958 return 0;
959 end:
960 /* Terminate the data filtering. If <ret> is negative, an error was
961 * encountered during the filtering. */
962 return handle_analyzer_result(s, chn, an_bit, ret);
963}
964
965/*
966 * Handles result of filter's analyzers. It returns 0 if an error occurs or if
967 * it needs to wait, any other value otherwise.
968 */
969static int
970handle_analyzer_result(struct stream *s, struct channel *chn,
971 unsigned int an_bit, int ret)
972{
973 int finst;
974
975 if (ret < 0)
976 goto return_bad_req;
977 else if (!ret)
978 goto wait;
979
980 /* End of job, return OK */
981 if (an_bit) {
982 chn->analysers &= ~an_bit;
983 chn->analyse_exp = TICK_ETERNITY;
984 }
985 return 1;
986
987 return_bad_req:
988 /* An error occurs */
989 channel_abort(&s->req);
990 channel_abort(&s->res);
991
992 if (!(chn->flags & CF_ISRESP)) {
993 s->req.analysers &= AN_FLT_END;
994 finst = SF_FINST_R;
995 /* FIXME: incr counters */
996 }
997 else {
998 s->res.analysers &= AN_FLT_END;
999 finst = SF_FINST_H;
1000 /* FIXME: incr counters */
1001 }
1002
1003 if (s->txn) {
1004 /* Do not do that when we are waiting for the next request */
1005 if (s->txn->status)
1006 http_reply_and_close(s, s->txn->status, NULL);
1007 else {
1008 s->txn->status = 400;
1009 http_reply_and_close(s, 400, http_error_message(s, HTTP_ERR_400));
1010 }
1011 }
1012
1013 if (!(s->flags & SF_ERR_MASK))
1014 s->flags |= SF_ERR_PRXCOND;
1015 if (!(s->flags & SF_FINST_MASK))
1016 s->flags |= finst;
1017 return 0;
1018
1019 wait:
1020 if (!(chn->flags & CF_ISRESP))
1021 channel_dont_connect(chn);
1022 return 0;
1023}
1024
1025
1026/* Note: must not be declared <const> as its list will be overwritten.
1027 * Please take care of keeping this list alphabetically sorted, doing so helps
1028 * all code contributors.
1029 * Optional keywords are also declared with a NULL ->parse() function so that
1030 * the config parser can report an appropriate error when a known keyword was
1031 * not enabled. */
1032static struct cfg_kw_list cfg_kws = {ILH, {
1033 { CFG_LISTEN, "filter", parse_filter },
1034 { 0, NULL, NULL },
1035 }
1036};
1037
1038__attribute__((constructor))
1039static void
1040__filters_init(void)
1041{
1042 pool2_filter = create_pool("filter", sizeof(struct filter), MEM_F_SHARED);
1043 cfg_register_keywords(&cfg_kws);
1044}
1045
1046__attribute__((destructor))
1047static void
1048__filters_deinit(void)
1049{
1050 pool_destroy2(pool2_filter);
1051}
1052
1053/*
1054 * Local variables:
1055 * c-indent-level: 8
1056 * c-basic-offset: 8
1057 * End:
1058 */