blob: 64c669d54ddc5f5621f2fb07f0d913ed5c5bd0fe [file] [log] [blame]
Christopher Faulet3d97c902015-12-09 14:59:38 +01001/*
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/cfgparse.h>
15#include <common/mini-clist.h>
16#include <common/standard.h>
17
18#include <types/compression.h>
19#include <types/filters.h>
20#include <types/proto_http.h>
21#include <types/proxy.h>
22#include <types/sample.h>
23
24#include <proto/compression.h>
Christopher Faulet92d36382015-11-05 13:35:03 +010025#include <proto/filters.h>
Christopher Faulet3d97c902015-12-09 14:59:38 +010026#include <proto/hdr_idx.h>
27#include <proto/proto_http.h>
28#include <proto/sample.h>
29#include <proto/stream.h>
30
Christopher Faulet92d36382015-11-05 13:35:03 +010031static const char *http_comp_flt_id = "compression filter";
32
33struct flt_ops comp_ops;
34
Christopher Fauleta03d4ad2017-06-26 16:53:33 +020035
36/* Pools used to allocate comp_state structs */
37static struct pool_head *pool2_comp_state = NULL;
38
Christopher Faulet92d36382015-11-05 13:35:03 +010039static struct buffer *tmpbuf = &buf_empty;
Christopher Fauletb77c5c22015-12-07 16:48:42 +010040static struct buffer *zbuf = &buf_empty;
Christopher Faulet92d36382015-11-05 13:35:03 +010041
Christopher Faulet92d36382015-11-05 13:35:03 +010042struct comp_state {
43 struct comp_ctx *comp_ctx; /* compression context */
44 struct comp_algo *comp_algo; /* compression algorithm if not NULL */
Christopher Fauletb77c5c22015-12-07 16:48:42 +010045 int hdrs_len;
46 int tlrs_len;
Christopher Faulet2fb28802015-12-01 10:40:57 +010047 int consumed;
48 int initialized;
Christopher Fauletb77c5c22015-12-07 16:48:42 +010049 int finished;
Christopher Faulet92d36382015-11-05 13:35:03 +010050};
51
Christopher Faulet92d36382015-11-05 13:35:03 +010052static int select_compression_request_header(struct comp_state *st,
53 struct stream *s,
54 struct http_msg *msg);
55static int select_compression_response_header(struct comp_state *st,
56 struct stream *s,
57 struct http_msg *msg);
58
59static int http_compression_buffer_init(struct buffer *in, struct buffer *out);
60static int http_compression_buffer_add_data(struct comp_state *st,
61 struct buffer *in,
62 struct buffer *out, int sz);
63static int http_compression_buffer_end(struct comp_state *st, struct stream *s,
64 struct buffer **in, struct buffer **out,
Christopher Faulet2fb28802015-12-01 10:40:57 +010065 int end);
Christopher Faulet92d36382015-11-05 13:35:03 +010066
67/***********************************************************************/
68static int
Christopher Faulet443ea1a2016-02-04 13:40:26 +010069comp_flt_init(struct proxy *px, struct flt_conf *fconf)
Christopher Faulet92d36382015-11-05 13:35:03 +010070{
71
Christopher Fauletb77c5c22015-12-07 16:48:42 +010072 if (!tmpbuf->size && b_alloc(&tmpbuf) == NULL)
73 return -1;
74 if (!zbuf->size && b_alloc(&zbuf) == NULL)
75 return -1;
Christopher Faulet92d36382015-11-05 13:35:03 +010076 return 0;
77}
78
79static void
Christopher Faulet443ea1a2016-02-04 13:40:26 +010080comp_flt_deinit(struct proxy *px, struct flt_conf *fconf)
Christopher Faulet92d36382015-11-05 13:35:03 +010081{
82 if (tmpbuf->size)
83 b_free(&tmpbuf);
Christopher Fauletb77c5c22015-12-07 16:48:42 +010084 if (zbuf->size)
85 b_free(&zbuf);
Christopher Faulet92d36382015-11-05 13:35:03 +010086}
87
88static int
89comp_start_analyze(struct stream *s, struct filter *filter, struct channel *chn)
90{
91 if (filter->ctx == NULL) {
92 struct comp_state *st;
93
Christopher Fauleta03d4ad2017-06-26 16:53:33 +020094 st = pool_alloc_dirty(pool2_comp_state);
95 if (st == NULL)
Christopher Faulet92d36382015-11-05 13:35:03 +010096 return -1;
97
Christopher Faulet2fb28802015-12-01 10:40:57 +010098 st->comp_algo = NULL;
99 st->comp_ctx = NULL;
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100100 st->hdrs_len = 0;
101 st->tlrs_len = 0;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100102 st->consumed = 0;
103 st->initialized = 0;
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100104 st->finished = 0;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100105 filter->ctx = st;
Christopher Faulet92d36382015-11-05 13:35:03 +0100106 }
107 return 1;
108}
109
110static int
Christopher Faulet92d36382015-11-05 13:35:03 +0100111comp_end_analyze(struct stream *s, struct filter *filter, struct channel *chn)
112{
113 struct comp_state *st = filter->ctx;
Christopher Faulet92d36382015-11-05 13:35:03 +0100114
Christopher Fauletd60b3cf2017-06-26 11:47:13 +0200115 if (!st)
Christopher Faulet92d36382015-11-05 13:35:03 +0100116 goto end;
117
Christopher Faulet92d36382015-11-05 13:35:03 +0100118 /* release any possible compression context */
Christopher Fauletd60b3cf2017-06-26 11:47:13 +0200119 if (st->comp_algo)
120 st->comp_algo->end(&st->comp_ctx);
Christopher Fauleta03d4ad2017-06-26 16:53:33 +0200121 pool_free2(pool2_comp_state, st);
Christopher Faulet92d36382015-11-05 13:35:03 +0100122 filter->ctx = NULL;
123 end:
124 return 1;
125}
126
127static int
Christopher Faulet1339d742016-05-11 16:48:33 +0200128comp_http_headers(struct stream *s, struct filter *filter, struct http_msg *msg)
129{
130 struct comp_state *st = filter->ctx;
131
132 if (!strm_fe(s)->comp && !s->be->comp)
133 goto end;
134
135 if (!(msg->chn->flags & CF_ISRESP))
136 select_compression_request_header(st, s, msg);
137 else {
138 select_compression_response_header(st, s, msg);
139 if (st->comp_algo) {
140 register_data_filter(s, msg->chn, filter);
141 st->hdrs_len = s->txn->rsp.sov;
142 }
143 }
144
145 end:
146 return 1;
147}
148
149static int
Christopher Faulet2fb28802015-12-01 10:40:57 +0100150comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
Christopher Faulet92d36382015-11-05 13:35:03 +0100151{
152 struct comp_state *st = filter->ctx;
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100153 struct buffer *buf = msg->chn->buf;
154 unsigned int *nxt = &flt_rsp_nxt(filter);
Christopher Faulet2fb28802015-12-01 10:40:57 +0100155 unsigned int len;
Christopher Faulet92d36382015-11-05 13:35:03 +0100156 int ret;
157
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100158 len = MIN(msg->chunk_len + msg->next, buf->i) - *nxt;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100159 if (!len)
160 return len;
161
162 if (!st->initialized) {
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100163 unsigned int fwd = flt_rsp_fwd(filter) + st->hdrs_len;
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100164
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100165 b_reset(tmpbuf);
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100166 b_adv(buf, fwd);
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100167 ret = http_compression_buffer_init(buf, zbuf);
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100168 b_rew(buf, fwd);
Christopher Faulet2fb28802015-12-01 10:40:57 +0100169 if (ret < 0) {
170 msg->chn->flags |= CF_WAKE_WRITE;
171 return 0;
172 }
173 }
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100174
175 if (msg->flags & HTTP_MSGF_TE_CHNK) {
Christopher Faulet06ecf3a2016-09-22 15:31:43 +0200176 int block;
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100177
178 len = MIN(tmpbuf->size - buffer_len(tmpbuf), len);
Christopher Faulet06ecf3a2016-09-22 15:31:43 +0200179
180 b_adv(buf, *nxt);
181 block = bi_contig_data(buf);
182 memcpy(bi_end(tmpbuf), bi_ptr(buf), block);
183 if (len > block)
184 memcpy(bi_end(tmpbuf)+block, buf->data, len-block);
185 b_rew(buf, *nxt);
186
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100187 tmpbuf->i += len;
188 ret = len;
189 }
190 else {
191 b_adv(buf, *nxt);
192 ret = http_compression_buffer_add_data(st, buf, zbuf, len);
193 b_rew(buf, *nxt);
194 if (ret < 0)
195 return ret;
196 }
Christopher Faulet92d36382015-11-05 13:35:03 +0100197
Christopher Faulet2fb28802015-12-01 10:40:57 +0100198 st->initialized = 1;
199 msg->next += ret;
200 msg->chunk_len -= ret;
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100201 *nxt = msg->next;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100202 return 0;
Christopher Faulet92d36382015-11-05 13:35:03 +0100203}
204
205static int
Christopher Faulet2fb28802015-12-01 10:40:57 +0100206comp_http_chunk_trailers(struct stream *s, struct filter *filter,
207 struct http_msg *msg)
Christopher Faulet92d36382015-11-05 13:35:03 +0100208{
209 struct comp_state *st = filter->ctx;
Christopher Faulet92d36382015-11-05 13:35:03 +0100210
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100211 if (!st->initialized) {
212 if (!st->finished) {
213 struct buffer *buf = msg->chn->buf;
214 unsigned int fwd = flt_rsp_fwd(filter) + st->hdrs_len;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100215
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100216 b_reset(tmpbuf);
217 b_adv(buf, fwd);
218 http_compression_buffer_init(buf, zbuf);
219 b_rew(buf, fwd);
220 st->initialized = 1;
221 }
222 }
223 st->tlrs_len = msg->sol;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100224 return 1;
Christopher Faulet92d36382015-11-05 13:35:03 +0100225}
226
Christopher Faulet2fb28802015-12-01 10:40:57 +0100227
Christopher Faulet92d36382015-11-05 13:35:03 +0100228static int
229comp_http_forward_data(struct stream *s, struct filter *filter,
230 struct http_msg *msg, unsigned int len)
231{
232 struct comp_state *st = filter->ctx;
Christopher Faulet2fb28802015-12-01 10:40:57 +0100233 int ret;
Christopher Faulet92d36382015-11-05 13:35:03 +0100234
Christopher Faulet2fb28802015-12-01 10:40:57 +0100235 /* To work, previous filters MUST forward all data */
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100236 if (flt_rsp_fwd(filter) + len != flt_rsp_nxt(filter)) {
Christopher Faulet2fb28802015-12-01 10:40:57 +0100237 Warning("HTTP compression failed: unexpected behavior of previous filters\n");
238 return -1;
Christopher Faulet92d36382015-11-05 13:35:03 +0100239 }
240
Christopher Faulet2fb28802015-12-01 10:40:57 +0100241 if (!st->initialized) {
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100242 if (!len) {
243 /* Nothing to foward */
244 ret = len;
245 }
246 else if (st->hdrs_len > len) {
247 /* Forward part of headers */
248 ret = len;
249 st->hdrs_len -= len;
250 }
251 else if (st->hdrs_len > 0) {
252 /* Forward remaining headers */
253 ret = st->hdrs_len;
254 st->hdrs_len = 0;
255 }
256 else if (msg->msg_state < HTTP_MSG_TRAILERS) {
257 /* Do not forward anything for now. This only happens
258 * with chunk-encoded responses. Waiting data are part
259 * of the chunk envelope (the chunk size or the chunk
260 * CRLF). These data will be skipped during the
261 * compression. */
262 ret = 0;
263 }
264 else {
265 /* Forward trailers data */
266 ret = len;
267 }
Christopher Faulet2fb28802015-12-01 10:40:57 +0100268 return ret;
Christopher Faulet92d36382015-11-05 13:35:03 +0100269 }
270
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100271 if (msg->flags & HTTP_MSGF_TE_CHNK) {
272 ret = http_compression_buffer_add_data(st, tmpbuf, zbuf, tmpbuf->i);
273 if (ret != tmpbuf->i) {
274 Warning("HTTP compression failed: Must consume %d bytes but only %d bytes consumed\n",
275 tmpbuf->i, ret);
276 return -1;
277 }
278 }
279
280 st->consumed = len - st->hdrs_len - st->tlrs_len;
281 b_adv(msg->chn->buf, flt_rsp_fwd(filter) + st->hdrs_len);
282 ret = http_compression_buffer_end(st, s, &msg->chn->buf, &zbuf, msg->msg_state >= HTTP_MSG_TRAILERS);
283 b_rew(msg->chn->buf, flt_rsp_fwd(filter) + st->hdrs_len);
Christopher Faulet2fb28802015-12-01 10:40:57 +0100284 if (ret < 0)
285 return ret;
Christopher Faulet92d36382015-11-05 13:35:03 +0100286
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100287 flt_change_forward_size(filter, msg->chn, ret - st->consumed);
288 msg->next += (ret - st->consumed);
289 ret += st->hdrs_len + st->tlrs_len;
290
Christopher Faulet2fb28802015-12-01 10:40:57 +0100291 st->initialized = 0;
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100292 st->finished = (msg->msg_state >= HTTP_MSG_TRAILERS);
293 st->hdrs_len = 0;
294 st->tlrs_len = 0;
Christopher Faulet92d36382015-11-05 13:35:03 +0100295 return ret;
296}
Christopher Faulet3d97c902015-12-09 14:59:38 +0100297
Christopher Fauletd60b3cf2017-06-26 11:47:13 +0200298static int
299comp_http_end(struct stream *s, struct filter *filter,
300 struct http_msg *msg)
301{
302 struct comp_state *st = filter->ctx;
303
304 if (!(msg->chn->flags & CF_ISRESP) || !st || !st->comp_algo)
305 goto end;
306
307 if (strm_fe(s)->mode == PR_MODE_HTTP)
308 strm_fe(s)->fe_counters.p.http.comp_rsp++;
309 if ((s->flags & SF_BE_ASSIGNED) && (s->be->mode == PR_MODE_HTTP))
310 s->be->be_counters.p.http.comp_rsp++;
311 end:
312 return 1;
313}
Christopher Faulet3d97c902015-12-09 14:59:38 +0100314/***********************************************************************/
315/*
316 * Selects a compression algorithm depending on the client request.
317 */
318int
Christopher Faulet92d36382015-11-05 13:35:03 +0100319select_compression_request_header(struct comp_state *st, struct stream *s,
320 struct http_msg *msg)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100321{
322 struct http_txn *txn = s->txn;
Christopher Faulet92d36382015-11-05 13:35:03 +0100323 struct buffer *req = msg->chn->buf;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100324 struct hdr_ctx ctx;
325 struct comp_algo *comp_algo = NULL;
326 struct comp_algo *comp_algo_back = NULL;
327
328 /* Disable compression for older user agents announcing themselves as "Mozilla/4"
329 * unless they are known good (MSIE 6 with XP SP2, or MSIE 7 and later).
330 * See http://zoompf.com/2012/02/lose-the-wait-http-compression for more details.
331 */
332 ctx.idx = 0;
333 if (http_find_header2("User-Agent", 10, req->p, &txn->hdr_idx, &ctx) &&
334 ctx.vlen >= 9 &&
335 memcmp(ctx.line + ctx.val, "Mozilla/4", 9) == 0 &&
336 (ctx.vlen < 31 ||
337 memcmp(ctx.line + ctx.val + 25, "MSIE ", 5) != 0 ||
338 ctx.line[ctx.val + 30] < '6' ||
339 (ctx.line[ctx.val + 30] == '6' &&
340 (ctx.vlen < 54 || memcmp(ctx.line + 51, "SV1", 3) != 0)))) {
Christopher Faulet92d36382015-11-05 13:35:03 +0100341 st->comp_algo = NULL;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100342 return 0;
343 }
344
345 /* search for the algo in the backend in priority or the frontend */
Christopher Faulet92d36382015-11-05 13:35:03 +0100346 if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) ||
347 (strm_fe(s)->comp && (comp_algo_back = strm_fe(s)->comp->algos))) {
Christopher Faulet3d97c902015-12-09 14:59:38 +0100348 int best_q = 0;
349
350 ctx.idx = 0;
351 while (http_find_header2("Accept-Encoding", 15, req->p, &txn->hdr_idx, &ctx)) {
352 const char *qval;
353 int q;
354 int toklen;
355
356 /* try to isolate the token from the optional q-value */
357 toklen = 0;
Willy Tarreau2235b262016-11-05 15:50:20 +0100358 while (toklen < ctx.vlen && HTTP_IS_TOKEN(*(ctx.line + ctx.val + toklen)))
Christopher Faulet3d97c902015-12-09 14:59:38 +0100359 toklen++;
360
361 qval = ctx.line + ctx.val + toklen;
362 while (1) {
Willy Tarreau2235b262016-11-05 15:50:20 +0100363 while (qval < ctx.line + ctx.val + ctx.vlen && HTTP_IS_LWS(*qval))
Christopher Faulet3d97c902015-12-09 14:59:38 +0100364 qval++;
365
366 if (qval >= ctx.line + ctx.val + ctx.vlen || *qval != ';') {
367 qval = NULL;
368 break;
369 }
370 qval++;
371
Willy Tarreau2235b262016-11-05 15:50:20 +0100372 while (qval < ctx.line + ctx.val + ctx.vlen && HTTP_IS_LWS(*qval))
Christopher Faulet3d97c902015-12-09 14:59:38 +0100373 qval++;
374
375 if (qval >= ctx.line + ctx.val + ctx.vlen) {
376 qval = NULL;
377 break;
378 }
379 if (strncmp(qval, "q=", MIN(ctx.line + ctx.val + ctx.vlen - qval, 2)) == 0)
380 break;
381
382 while (qval < ctx.line + ctx.val + ctx.vlen && *qval != ';')
383 qval++;
384 }
385
386 /* here we have qval pointing to the first "q=" attribute or NULL if not found */
387 q = qval ? parse_qvalue(qval + 2, NULL) : 1000;
388
389 if (q <= best_q)
390 continue;
391
392 for (comp_algo = comp_algo_back; comp_algo; comp_algo = comp_algo->next) {
393 if (*(ctx.line + ctx.val) == '*' ||
394 word_match(ctx.line + ctx.val, toklen, comp_algo->ua_name, comp_algo->ua_name_len)) {
Christopher Faulet92d36382015-11-05 13:35:03 +0100395 st->comp_algo = comp_algo;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100396 best_q = q;
397 break;
398 }
399 }
400 }
401 }
402
403 /* remove all occurrences of the header when "compression offload" is set */
Christopher Faulet92d36382015-11-05 13:35:03 +0100404 if (st->comp_algo) {
405 if ((s->be->comp && s->be->comp->offload) ||
406 (strm_fe(s)->comp && strm_fe(s)->comp->offload)) {
Christopher Faulet3d97c902015-12-09 14:59:38 +0100407 http_remove_header2(msg, &txn->hdr_idx, &ctx);
408 ctx.idx = 0;
409 while (http_find_header2("Accept-Encoding", 15, req->p, &txn->hdr_idx, &ctx)) {
410 http_remove_header2(msg, &txn->hdr_idx, &ctx);
411 }
412 }
413 return 1;
414 }
415
416 /* identity is implicit does not require headers */
Christopher Faulet92d36382015-11-05 13:35:03 +0100417 if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) ||
418 (strm_fe(s)->comp && (comp_algo_back = strm_fe(s)->comp->algos))) {
Christopher Faulet3d97c902015-12-09 14:59:38 +0100419 for (comp_algo = comp_algo_back; comp_algo; comp_algo = comp_algo->next) {
420 if (comp_algo->cfg_name_len == 8 && memcmp(comp_algo->cfg_name, "identity", 8) == 0) {
Christopher Faulet92d36382015-11-05 13:35:03 +0100421 st->comp_algo = comp_algo;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100422 return 1;
423 }
424 }
425 }
426
Christopher Faulet92d36382015-11-05 13:35:03 +0100427 st->comp_algo = NULL;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100428 return 0;
429}
430
Christopher Faulet92d36382015-11-05 13:35:03 +0100431
Christopher Faulet3d97c902015-12-09 14:59:38 +0100432/*
433 * Selects a comression algorithm depending of the server response.
434 */
Christopher Faulet92d36382015-11-05 13:35:03 +0100435static int
436select_compression_response_header(struct comp_state *st, struct stream *s, struct http_msg *msg)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100437{
438 struct http_txn *txn = s->txn;
Christopher Faulet92d36382015-11-05 13:35:03 +0100439 struct buffer *res = msg->chn->buf;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100440 struct hdr_ctx ctx;
441 struct comp_type *comp_type;
442
443 /* no common compression algorithm was found in request header */
Christopher Faulet92d36382015-11-05 13:35:03 +0100444 if (st->comp_algo == NULL)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100445 goto fail;
446
447 /* HTTP < 1.1 should not be compressed */
448 if (!(msg->flags & HTTP_MSGF_VER_11) || !(txn->req.flags & HTTP_MSGF_VER_11))
449 goto fail;
450
Christopher Faulet92d36382015-11-05 13:35:03 +0100451 if (txn->meth == HTTP_METH_HEAD)
452 goto fail;
453
Christopher Faulet3d97c902015-12-09 14:59:38 +0100454 /* compress 200,201,202,203 responses only */
455 if ((txn->status != 200) &&
456 (txn->status != 201) &&
457 (txn->status != 202) &&
458 (txn->status != 203))
459 goto fail;
460
461
462 /* Content-Length is null */
463 if (!(msg->flags & HTTP_MSGF_TE_CHNK) && msg->body_len == 0)
464 goto fail;
465
466 /* content is already compressed */
467 ctx.idx = 0;
468 if (http_find_header2("Content-Encoding", 16, res->p, &txn->hdr_idx, &ctx))
469 goto fail;
470
471 /* no compression when Cache-Control: no-transform is present in the message */
472 ctx.idx = 0;
473 while (http_find_header2("Cache-Control", 13, res->p, &txn->hdr_idx, &ctx)) {
474 if (word_match(ctx.line + ctx.val, ctx.vlen, "no-transform", 12))
475 goto fail;
476 }
477
478 comp_type = NULL;
479
480 /* we don't want to compress multipart content-types, nor content-types that are
481 * not listed in the "compression type" directive if any. If no content-type was
482 * found but configuration requires one, we don't compress either. Backend has
483 * the priority.
484 */
485 ctx.idx = 0;
486 if (http_find_header2("Content-Type", 12, res->p, &txn->hdr_idx, &ctx)) {
487 if (ctx.vlen >= 9 && strncasecmp("multipart", ctx.line+ctx.val, 9) == 0)
488 goto fail;
489
490 if ((s->be->comp && (comp_type = s->be->comp->types)) ||
491 (strm_fe(s)->comp && (comp_type = strm_fe(s)->comp->types))) {
492 for (; comp_type; comp_type = comp_type->next) {
493 if (ctx.vlen >= comp_type->name_len &&
494 strncasecmp(ctx.line+ctx.val, comp_type->name, comp_type->name_len) == 0)
495 /* this Content-Type should be compressed */
496 break;
497 }
498 /* this Content-Type should not be compressed */
499 if (comp_type == NULL)
500 goto fail;
501 }
502 }
503 else { /* no content-type header */
Christopher Faulet92d36382015-11-05 13:35:03 +0100504 if ((s->be->comp && s->be->comp->types) ||
505 (strm_fe(s)->comp && strm_fe(s)->comp->types))
Christopher Faulet3d97c902015-12-09 14:59:38 +0100506 goto fail; /* a content-type was required */
507 }
508
509 /* limit compression rate */
510 if (global.comp_rate_lim > 0)
511 if (read_freq_ctr(&global.comp_bps_in) > global.comp_rate_lim)
512 goto fail;
513
514 /* limit cpu usage */
515 if (idle_pct < compress_min_idle)
516 goto fail;
517
518 /* initialize compression */
Christopher Faulet92d36382015-11-05 13:35:03 +0100519 if (st->comp_algo->init(&st->comp_ctx, global.tune.comp_maxlevel) < 0)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100520 goto fail;
521
Christopher Faulet3d97c902015-12-09 14:59:38 +0100522 /* remove Content-Length header */
523 ctx.idx = 0;
524 if ((msg->flags & HTTP_MSGF_CNT_LEN) && http_find_header2("Content-Length", 14, res->p, &txn->hdr_idx, &ctx))
525 http_remove_header2(msg, &txn->hdr_idx, &ctx);
526
527 /* add Transfer-Encoding header */
528 if (!(msg->flags & HTTP_MSGF_TE_CHNK))
529 http_header_add_tail2(&txn->rsp, &txn->hdr_idx, "Transfer-Encoding: chunked", 26);
530
531 /*
532 * Add Content-Encoding header when it's not identity encoding.
533 * RFC 2616 : Identity encoding: This content-coding is used only in the
534 * Accept-Encoding header, and SHOULD NOT be used in the Content-Encoding
535 * header.
536 */
Christopher Faulet92d36382015-11-05 13:35:03 +0100537 if (st->comp_algo->cfg_name_len != 8 || memcmp(st->comp_algo->cfg_name, "identity", 8) != 0) {
Christopher Faulet3d97c902015-12-09 14:59:38 +0100538 trash.len = 18;
539 memcpy(trash.str, "Content-Encoding: ", trash.len);
Christopher Faulet92d36382015-11-05 13:35:03 +0100540 memcpy(trash.str + trash.len, st->comp_algo->ua_name, st->comp_algo->ua_name_len);
541 trash.len += st->comp_algo->ua_name_len;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100542 trash.str[trash.len] = '\0';
543 http_header_add_tail2(&txn->rsp, &txn->hdr_idx, trash.str, trash.len);
544 }
Christopher Faulet92d36382015-11-05 13:35:03 +0100545 msg->flags |= HTTP_MSGF_COMPRESSING;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100546 return 1;
547
548fail:
Christopher Faulet92d36382015-11-05 13:35:03 +0100549 st->comp_algo = NULL;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100550 return 0;
551}
552
553/***********************************************************************/
554/* emit the chunksize followed by a CRLF on the output and return the number of
555 * bytes written. It goes backwards and starts with the byte before <end>. It
556 * returns the number of bytes written which will not exceed 10 (8 digits, CR,
557 * and LF). The caller is responsible for ensuring there is enough room left in
558 * the output buffer for the string.
559 */
560static int
561http_emit_chunk_size(char *end, unsigned int chksz)
562{
563 char *beg = end;
564
565 *--beg = '\n';
566 *--beg = '\r';
567 do {
568 *--beg = hextab[chksz & 0xF];
569 } while (chksz >>= 4);
570 return end - beg;
571}
572
573/*
574 * Init HTTP compression
575 */
Christopher Faulet92d36382015-11-05 13:35:03 +0100576static int
577http_compression_buffer_init(struct buffer *in, struct buffer *out)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100578{
579 /* output stream requires at least 10 bytes for the gzip header, plus
580 * at least 8 bytes for the gzip trailer (crc+len), plus a possible
581 * plus at most 5 bytes per 32kB block and 2 bytes to close the stream.
582 */
583 if (in->size - buffer_len(in) < 20 + 5 * ((in->i + 32767) >> 15))
584 return -1;
585
586 /* prepare an empty output buffer in which we reserve enough room for
587 * copying the output bytes from <in>, plus 10 extra bytes to write
588 * the chunk size. We don't copy the bytes yet so that if we have to
589 * cancel the operation later, it's cheap.
590 */
591 b_reset(out);
592 out->o = in->o;
593 out->p += out->o;
594 out->i = 10;
595 return 0;
596}
597
598/*
599 * Add data to compress
600 */
Christopher Faulet92d36382015-11-05 13:35:03 +0100601static int
602http_compression_buffer_add_data(struct comp_state *st, struct buffer *in,
603 struct buffer *out, int sz)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100604{
Christopher Faulet3d97c902015-12-09 14:59:38 +0100605 int consumed_data = 0;
606 int data_process_len;
607 int block1, block2;
608
Christopher Faulet92d36382015-11-05 13:35:03 +0100609 if (!sz)
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100610 goto end;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100611
Christopher Faulet92d36382015-11-05 13:35:03 +0100612 /* select the smallest size between the announced chunk size, the input
Christopher Faulet3d97c902015-12-09 14:59:38 +0100613 * data, and the available output buffer size. The compressors are
Christopher Faulet92d36382015-11-05 13:35:03 +0100614 * assumed to be able to process all the bytes we pass to them at
615 * once. */
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100616 data_process_len = MIN(out->size - buffer_len(out), sz);
Christopher Faulet92d36382015-11-05 13:35:03 +0100617
Christopher Faulet3d97c902015-12-09 14:59:38 +0100618 block1 = data_process_len;
619 if (block1 > bi_contig_data(in))
620 block1 = bi_contig_data(in);
621 block2 = data_process_len - block1;
622
623 /* compressors return < 0 upon error or the amount of bytes read */
Christopher Faulet92d36382015-11-05 13:35:03 +0100624 consumed_data = st->comp_algo->add_data(st->comp_ctx, bi_ptr(in), block1, out);
Christopher Faulet3e7bc672015-12-07 13:39:08 +0100625 if (consumed_data != block1 || !block2)
626 goto end;
627 consumed_data = st->comp_algo->add_data(st->comp_ctx, in->data, block2, out);
628 if (consumed_data < 0)
629 goto end;
630 consumed_data += block1;
631
632 end:
Christopher Faulet3d97c902015-12-09 14:59:38 +0100633 return consumed_data;
634}
635
636/*
637 * Flush data in process, and write the header and footer of the chunk. Upon
638 * success, in and out buffers are swapped to avoid a copy.
639 */
Christopher Faulet92d36382015-11-05 13:35:03 +0100640static int
641http_compression_buffer_end(struct comp_state *st, struct stream *s,
642 struct buffer **in, struct buffer **out,
Christopher Faulet2fb28802015-12-01 10:40:57 +0100643 int end)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100644{
Christopher Faulet3d97c902015-12-09 14:59:38 +0100645 struct buffer *ib = *in, *ob = *out;
646 char *tail;
Christopher Faulet92d36382015-11-05 13:35:03 +0100647 int to_forward, left;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100648
649#if defined(USE_SLZ) || defined(USE_ZLIB)
650 int ret;
651
652 /* flush data here */
Christopher Faulet3d97c902015-12-09 14:59:38 +0100653 if (end)
Christopher Faulet92d36382015-11-05 13:35:03 +0100654 ret = st->comp_algo->finish(st->comp_ctx, ob); /* end of data */
Christopher Faulet3d97c902015-12-09 14:59:38 +0100655 else
Christopher Faulet92d36382015-11-05 13:35:03 +0100656 ret = st->comp_algo->flush(st->comp_ctx, ob); /* end of buffer */
Christopher Faulet3d97c902015-12-09 14:59:38 +0100657
658 if (ret < 0)
659 return -1; /* flush failed */
660
661#endif /* USE_ZLIB */
Christopher Faulet3d97c902015-12-09 14:59:38 +0100662 if (ob->i == 10) {
663 /* No data were appended, let's drop the output buffer and
664 * keep the input buffer unchanged.
665 */
666 return 0;
667 }
668
669 /* OK so at this stage, we have an output buffer <ob> looking like this :
670 *
671 * <-- o --> <------ i ----->
672 * +---------+---+------------+-----------+
673 * | out | c | comp_in | empty |
674 * +---------+---+------------+-----------+
675 * data p size
676 *
677 * <out> is the room reserved to copy ib->o. It starts at ob->data and
678 * has not yet been filled. <c> is the room reserved to write the chunk
679 * size (10 bytes). <comp_in> is the compressed equivalent of the data
680 * part of ib->i. <empty> is the amount of empty bytes at the end of
681 * the buffer, into which we may have to copy the remaining bytes from
682 * ib->i after the data (chunk size, trailers, ...).
683 */
684
685 /* Write real size at the begining of the chunk, no need of wrapping.
686 * We write the chunk using a dynamic length and adjust ob->p and ob->i
687 * accordingly afterwards. That will move <out> away from <data>.
688 */
689 left = 10 - http_emit_chunk_size(ob->p + 10, ob->i - 10);
690 ob->p += left;
691 ob->i -= left;
692
693 /* Copy previous data from ib->o into ob->o */
694 if (ib->o > 0) {
695 left = bo_contig_data(ib);
696 memcpy(ob->p - ob->o, bo_ptr(ib), left);
697 if (ib->o - left) /* second part of the buffer */
698 memcpy(ob->p - ob->o + left, ib->data, ib->o - left);
699 }
700
701 /* chunked encoding requires CRLF after data */
702 tail = ob->p + ob->i;
703 *tail++ = '\r';
704 *tail++ = '\n';
705
Christopher Faulet2fb28802015-12-01 10:40:57 +0100706 /* At the end of data, we must write the empty chunk 0<CRLF>,
707 * and terminate the trailers section with a last <CRLF>. If
708 * we're forwarding a chunked-encoded response, we'll have a
709 * trailers section after the empty chunk which needs to be
710 * forwarded and which will provide the last CRLF. Otherwise
711 * we write it ourselves.
712 */
713 if (end) {
714 struct http_msg *msg = &s->txn->rsp;
715
716 memcpy(tail, "0\r\n", 3);
717 tail += 3;
Christopher Fauletb77c5c22015-12-07 16:48:42 +0100718 if (!(msg->flags & HTTP_MSGF_TE_CHNK)) {
Christopher Faulet2fb28802015-12-01 10:40:57 +0100719 memcpy(tail, "\r\n", 2);
720 tail += 2;
721 }
722 }
723
Christopher Faulet3d97c902015-12-09 14:59:38 +0100724 ob->i = tail - ob->p;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100725 to_forward = ob->i;
726
727 /* update input rate */
Christopher Faulet92d36382015-11-05 13:35:03 +0100728 if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) {
Christopher Faulet2fb28802015-12-01 10:40:57 +0100729 update_freq_ctr(&global.comp_bps_in, st->consumed);
730 strm_fe(s)->fe_counters.comp_in += st->consumed;
731 s->be->be_counters.comp_in += st->consumed;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100732 } else {
Christopher Faulet2fb28802015-12-01 10:40:57 +0100733 strm_fe(s)->fe_counters.comp_byp += st->consumed;
734 s->be->be_counters.comp_byp += st->consumed;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100735 }
736
737 /* copy the remaining data in the tmp buffer. */
Christopher Faulet2fb28802015-12-01 10:40:57 +0100738 b_adv(ib, st->consumed);
Christopher Faulet3d97c902015-12-09 14:59:38 +0100739 if (ib->i > 0) {
740 left = bi_contig_data(ib);
741 memcpy(ob->p + ob->i, bi_ptr(ib), left);
742 ob->i += left;
743 if (ib->i - left) {
744 memcpy(ob->p + ob->i, ib->data, ib->i - left);
745 ob->i += ib->i - left;
746 }
747 }
748
749 /* swap the buffers */
750 *in = ob;
751 *out = ib;
752
Christopher Faulet92d36382015-11-05 13:35:03 +0100753
754 if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) {
Christopher Faulet3d97c902015-12-09 14:59:38 +0100755 update_freq_ctr(&global.comp_bps_out, to_forward);
756 strm_fe(s)->fe_counters.comp_out += to_forward;
757 s->be->be_counters.comp_out += to_forward;
758 }
759
Christopher Faulet3d97c902015-12-09 14:59:38 +0100760 return to_forward;
761}
762
763
764/***********************************************************************/
Christopher Faulet92d36382015-11-05 13:35:03 +0100765struct flt_ops comp_ops = {
766 .init = comp_flt_init,
767 .deinit = comp_flt_deinit,
768
769 .channel_start_analyze = comp_start_analyze,
Christopher Faulet92d36382015-11-05 13:35:03 +0100770 .channel_end_analyze = comp_end_analyze,
771
Christopher Faulet1339d742016-05-11 16:48:33 +0200772 .http_headers = comp_http_headers,
Christopher Faulet309c6412015-12-02 09:57:32 +0100773 .http_data = comp_http_data,
774 .http_chunk_trailers = comp_http_chunk_trailers,
775 .http_forward_data = comp_http_forward_data,
Christopher Fauletd60b3cf2017-06-26 11:47:13 +0200776 .http_end = comp_http_end,
Christopher Faulet92d36382015-11-05 13:35:03 +0100777};
778
Christopher Faulet3d97c902015-12-09 14:59:38 +0100779static int
780parse_compression_options(char **args, int section, struct proxy *proxy,
781 struct proxy *defpx, const char *file, int line,
782 char **err)
783{
Christopher Faulet92d36382015-11-05 13:35:03 +0100784 struct comp *comp;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100785
786 if (proxy->comp == NULL) {
Vincent Bernat02779b62016-04-03 13:48:43 +0200787 comp = calloc(1, sizeof(*comp));
Christopher Faulet3d97c902015-12-09 14:59:38 +0100788 proxy->comp = comp;
789 }
790 else
791 comp = proxy->comp;
792
793 if (!strcmp(args[1], "algo")) {
794 struct comp_ctx *ctx;
795 int cur_arg = 2;
796
797 if (!*args[cur_arg]) {
798 memprintf(err, "parsing [%s:%d] : '%s' expects <algorithm>\n",
799 file, line, args[0]);
800 return -1;
801 }
802 while (*(args[cur_arg])) {
803 if (comp_append_algo(comp, args[cur_arg]) < 0) {
804 memprintf(err, "'%s' : '%s' is not a supported algorithm.\n",
805 args[0], args[cur_arg]);
806 return -1;
807 }
808 if (proxy->comp->algos->init(&ctx, 9) == 0)
809 proxy->comp->algos->end(&ctx);
810 else {
811 memprintf(err, "'%s' : Can't init '%s' algorithm.\n",
812 args[0], args[cur_arg]);
813 return -1;
814 }
815 cur_arg++;
816 continue;
817 }
818 }
819 else if (!strcmp(args[1], "offload"))
820 comp->offload = 1;
821 else if (!strcmp(args[1], "type")) {
822 int cur_arg = 2;
823
824 if (!*args[cur_arg]) {
825 memprintf(err, "'%s' expects <type>\n", args[0]);
826 return -1;
827 }
828 while (*(args[cur_arg])) {
829 comp_append_type(comp, args[cur_arg]);
830 cur_arg++;
831 continue;
832 }
833 }
834 else {
835 memprintf(err, "'%s' expects 'algo', 'type' or 'offload'\n",
836 args[0]);
837 return -1;
838 }
839
840 return 0;
841}
842
Christopher Faulet92d36382015-11-05 13:35:03 +0100843static int
844parse_http_comp_flt(char **args, int *cur_arg, struct proxy *px,
Thierry Fournier3610c392016-04-13 18:27:51 +0200845 struct flt_conf *fconf, char **err, void *private)
Christopher Faulet92d36382015-11-05 13:35:03 +0100846{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100847 struct flt_conf *fc, *back;
Christopher Faulet92d36382015-11-05 13:35:03 +0100848
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100849 list_for_each_entry_safe(fc, back, &px->filter_configs, list) {
850 if (fc->id == http_comp_flt_id) {
Christopher Faulet92d36382015-11-05 13:35:03 +0100851 memprintf(err, "%s: Proxy supports only one compression filter\n", px->id);
852 return -1;
853 }
854 }
855
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100856 fconf->id = http_comp_flt_id;
857 fconf->conf = NULL;
858 fconf->ops = &comp_ops;
Christopher Faulet92d36382015-11-05 13:35:03 +0100859 (*cur_arg)++;
860
861 return 0;
862}
863
864
865int
866check_legacy_http_comp_flt(struct proxy *proxy)
867{
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100868 struct flt_conf *fconf;
Christopher Faulet92d36382015-11-05 13:35:03 +0100869 int err = 0;
870
871 if (proxy->comp == NULL)
872 goto end;
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100873 if (!LIST_ISEMPTY(&proxy->filter_configs)) {
874 list_for_each_entry(fconf, &proxy->filter_configs, list) {
875 if (fconf->id == http_comp_flt_id)
Christopher Faulet92d36382015-11-05 13:35:03 +0100876 goto end;
877 }
878 Alert("config: %s '%s': require an explicit filter declaration to use HTTP compression\n",
879 proxy_type_str(proxy), proxy->id);
880 err++;
881 goto end;
882 }
883
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100884 fconf = calloc(1, sizeof(*fconf));
885 if (!fconf) {
Christopher Faulet92d36382015-11-05 13:35:03 +0100886 Alert("config: %s '%s': out of memory\n",
887 proxy_type_str(proxy), proxy->id);
888 err++;
889 goto end;
890 }
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100891 fconf->id = http_comp_flt_id;
892 fconf->conf = NULL;
893 fconf->ops = &comp_ops;
894 LIST_ADDQ(&proxy->filter_configs, &fconf->list);
Christopher Faulet92d36382015-11-05 13:35:03 +0100895
896 end:
897 return err;
898}
899
900/*
901 * boolean, returns true if compression is used (either gzip or deflate) in the
902 * response.
903 */
Christopher Faulet3d97c902015-12-09 14:59:38 +0100904static int
Christopher Faulet92d36382015-11-05 13:35:03 +0100905smp_fetch_res_comp(const struct arg *args, struct sample *smp, const char *kw,
906 void *private)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100907{
Willy Tarreaube508f12016-03-10 11:47:01 +0100908 struct http_txn *txn = smp->strm ? smp->strm->txn : NULL;
Christopher Faulet92d36382015-11-05 13:35:03 +0100909
Christopher Faulet3d97c902015-12-09 14:59:38 +0100910 smp->data.type = SMP_T_BOOL;
Christopher Faulet92d36382015-11-05 13:35:03 +0100911 smp->data.u.sint = (txn && (txn->rsp.flags & HTTP_MSGF_COMPRESSING));
Christopher Faulet3d97c902015-12-09 14:59:38 +0100912 return 1;
913}
914
Christopher Faulet92d36382015-11-05 13:35:03 +0100915/*
916 * string, returns algo
917 */
Christopher Faulet3d97c902015-12-09 14:59:38 +0100918static int
Christopher Faulet92d36382015-11-05 13:35:03 +0100919smp_fetch_res_comp_algo(const struct arg *args, struct sample *smp,
920 const char *kw, void *private)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100921{
Willy Tarreaube508f12016-03-10 11:47:01 +0100922 struct http_txn *txn = smp->strm ? smp->strm->txn : NULL;
Christopher Faulet92d36382015-11-05 13:35:03 +0100923 struct filter *filter;
924 struct comp_state *st;
925
926 if (!(txn || !(txn->rsp.flags & HTTP_MSGF_COMPRESSING)))
Christopher Faulet3d97c902015-12-09 14:59:38 +0100927 return 0;
928
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100929 list_for_each_entry(filter, &strm_flt(smp->strm)->filters, list) {
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100930 if (FLT_ID(filter) != http_comp_flt_id)
Christopher Faulet92d36382015-11-05 13:35:03 +0100931 continue;
932
933 if (!(st = filter->ctx))
934 break;
935
936 smp->data.type = SMP_T_STR;
937 smp->flags = SMP_F_CONST;
938 smp->data.u.str.str = st->comp_algo->cfg_name;
939 smp->data.u.str.len = st->comp_algo->cfg_name_len;
940 return 1;
941 }
942 return 0;
Christopher Faulet3d97c902015-12-09 14:59:38 +0100943}
944
945/* Declare the config parser for "compression" keyword */
946static struct cfg_kw_list cfg_kws = {ILH, {
947 { CFG_LISTEN, "compression", parse_compression_options },
948 { 0, NULL, NULL },
949 }
950};
951
Christopher Faulet92d36382015-11-05 13:35:03 +0100952/* Declare the filter parser for "compression" keyword */
953static struct flt_kw_list filter_kws = { "COMP", { }, {
Thierry Fournier3610c392016-04-13 18:27:51 +0200954 { "compression", parse_http_comp_flt, NULL },
955 { NULL, NULL, NULL },
Christopher Faulet92d36382015-11-05 13:35:03 +0100956 }
957};
958
Christopher Faulet3d97c902015-12-09 14:59:38 +0100959/* Note: must not be declared <const> as its list will be overwritten */
960static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
Christopher Faulet92d36382015-11-05 13:35:03 +0100961 { "res.comp", smp_fetch_res_comp, 0, NULL, SMP_T_BOOL, SMP_USE_HRSHP },
962 { "res.comp_algo", smp_fetch_res_comp_algo, 0, NULL, SMP_T_STR, SMP_USE_HRSHP },
963 { /* END */ },
964 }
965};
Christopher Faulet3d97c902015-12-09 14:59:38 +0100966
967__attribute__((constructor))
Christopher Faulet92d36382015-11-05 13:35:03 +0100968static void
969__flt_http_comp_init(void)
Christopher Faulet3d97c902015-12-09 14:59:38 +0100970{
971 cfg_register_keywords(&cfg_kws);
Christopher Faulet92d36382015-11-05 13:35:03 +0100972 flt_register_keywords(&filter_kws);
Christopher Faulet3d97c902015-12-09 14:59:38 +0100973 sample_register_fetches(&sample_fetch_keywords);
Christopher Fauleta03d4ad2017-06-26 16:53:33 +0200974 pool2_comp_state = create_pool("comp_state", sizeof(struct comp_state), MEM_F_SHARED);
Christopher Faulet3d97c902015-12-09 14:59:38 +0100975}