blob: feade6b385152351950ea6af17ffd2c7af9ceaf4 [file] [log] [blame]
William Lallemand82fe75c2012-10-23 10:25:10 +02001/*
2 * HTTP compression.
3 *
4 * Copyright 2012 Exceliance, David Du Colombier <dducolombier@exceliance.fr>
5 * William Lallemand <wlallemand@exceliance.fr>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14#include <stdio.h>
Willy Tarreau34763642012-10-26 15:05:35 +020015
Willy Tarreau418b8c02015-03-29 03:32:06 +020016#if defined(USE_SLZ)
17#include <slz.h>
18#elif defined(USE_ZLIB)
Willy Tarreau34763642012-10-26 15:05:35 +020019/* Note: the crappy zlib and openssl libs both define the "free_func" type.
20 * That's a very clever idea to use such a generic name in general purpose
21 * libraries, really... The zlib one is easier to redefine than openssl's,
22 * so let's only fix this one.
23 */
24#define free_func zlib_free_func
William Lallemand82fe75c2012-10-23 10:25:10 +020025#include <zlib.h>
Willy Tarreau34763642012-10-26 15:05:35 +020026#undef free_func
William Lallemand08289f12012-10-31 11:19:18 +010027#endif /* USE_ZLIB */
William Lallemand82fe75c2012-10-23 10:25:10 +020028
29#include <common/compat.h>
William Lallemand2b502472012-10-30 14:30:39 +010030#include <common/memory.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020031
32#include <types/global.h>
33#include <types/compression.h>
34
William Lallemand727db8b2013-04-20 17:33:20 +020035#include <proto/acl.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020036#include <proto/compression.h>
William Lallemandd85f9172012-11-09 17:05:39 +010037#include <proto/freq_ctr.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020038#include <proto/proto_http.h>
39
William Lallemand2b502472012-10-30 14:30:39 +010040
41#ifdef USE_ZLIB
42
William Lallemand8b52bb32012-11-16 18:06:41 +010043static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size);
44static void free_zlib(void *opaque, void *ptr);
45
William Lallemand2b502472012-10-30 14:30:39 +010046/* zlib allocation */
47static struct pool_head *zlib_pool_deflate_state = NULL;
48static struct pool_head *zlib_pool_window = NULL;
49static struct pool_head *zlib_pool_prev = NULL;
50static struct pool_head *zlib_pool_head = NULL;
51static struct pool_head *zlib_pool_pending_buf = NULL;
52
William Lallemande3a7d992012-11-20 11:25:20 +010053long zlib_used_memory = 0;
William Lallemand9d5f5482012-11-07 16:12:57 +010054
William Lallemand2b502472012-10-30 14:30:39 +010055#endif
56
William Lallemand072a2bf2012-11-20 17:01:01 +010057unsigned int compress_min_idle = 0;
William Lallemand8b52bb32012-11-16 18:06:41 +010058static struct pool_head *pool_comp_ctx = NULL;
59
Willy Tarreau9f640a12015-03-28 15:46:00 +010060static int identity_init(struct comp_ctx **comp_ctx, int level);
61static int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
Willy Tarreau9787efa2015-03-28 19:17:31 +010062static int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out);
63static int identity_finish(struct comp_ctx *comp_ctx, struct buffer *out);
Willy Tarreau9f640a12015-03-28 15:46:00 +010064static int identity_end(struct comp_ctx **comp_ctx);
65
Willy Tarreau418b8c02015-03-29 03:32:06 +020066#if defined(USE_SLZ)
67
68static int rfc1950_init(struct comp_ctx **comp_ctx, int level);
69static int rfc1951_init(struct comp_ctx **comp_ctx, int level);
70static int rfc1952_init(struct comp_ctx **comp_ctx, int level);
71static int rfc195x_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
72static int rfc195x_flush(struct comp_ctx *comp_ctx, struct buffer *out);
73static int rfc195x_finish(struct comp_ctx *comp_ctx, struct buffer *out);
74static int rfc195x_end(struct comp_ctx **comp_ctx);
75
76#elif defined(USE_ZLIB)
Willy Tarreau7b218772015-03-28 22:08:25 +010077
Willy Tarreau9f640a12015-03-28 15:46:00 +010078static int gzip_init(struct comp_ctx **comp_ctx, int level);
Willy Tarreauc91840a2015-03-28 17:00:39 +010079static int raw_def_init(struct comp_ctx **comp_ctx, int level);
Willy Tarreau9f640a12015-03-28 15:46:00 +010080static int deflate_init(struct comp_ctx **comp_ctx, int level);
81static int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
Willy Tarreau9787efa2015-03-28 19:17:31 +010082static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out);
83static int deflate_finish(struct comp_ctx *comp_ctx, struct buffer *out);
Willy Tarreau9f640a12015-03-28 15:46:00 +010084static int deflate_end(struct comp_ctx **comp_ctx);
Willy Tarreau7b218772015-03-28 22:08:25 +010085
Willy Tarreau9f640a12015-03-28 15:46:00 +010086#endif /* USE_ZLIB */
87
William Lallemand2b502472012-10-30 14:30:39 +010088
Cyril Bonté6162c432012-11-10 19:27:47 +010089const struct comp_algo comp_algos[] =
William Lallemand82fe75c2012-10-23 10:25:10 +020090{
Willy Tarreau7b218772015-03-28 22:08:25 +010091 { "identity", 8, "identity", 8, identity_init, identity_add_data, identity_flush, identity_finish, identity_end },
Willy Tarreau418b8c02015-03-29 03:32:06 +020092#if defined(USE_SLZ)
93 { "deflate", 7, "deflate", 7, rfc1950_init, rfc195x_add_data, rfc195x_flush, rfc195x_finish, rfc195x_end },
94 { "raw-deflate", 11, "deflate", 7, rfc1951_init, rfc195x_add_data, rfc195x_flush, rfc195x_finish, rfc195x_end },
95 { "gzip", 4, "gzip", 4, rfc1952_init, rfc195x_add_data, rfc195x_flush, rfc195x_finish, rfc195x_end },
96#elif defined(USE_ZLIB)
Willy Tarreau7b218772015-03-28 22:08:25 +010097 { "deflate", 7, "deflate", 7, deflate_init, deflate_add_data, deflate_flush, deflate_finish, deflate_end },
98 { "raw-deflate", 11, "deflate", 7, raw_def_init, deflate_add_data, deflate_flush, deflate_finish, deflate_end },
99 { "gzip", 4, "gzip", 4, gzip_init, deflate_add_data, deflate_flush, deflate_finish, deflate_end },
William Lallemand82fe75c2012-10-23 10:25:10 +0200100#endif /* USE_ZLIB */
Willy Tarreau615105e2015-03-28 16:40:46 +0100101 { NULL, 0, NULL, 0, NULL , NULL, NULL, NULL, NULL }
William Lallemand82fe75c2012-10-23 10:25:10 +0200102};
103
104/*
105 * Add a content-type in the configuration
106 */
107int comp_append_type(struct comp *comp, const char *type)
108{
109 struct comp_type *comp_type;
110
111 comp_type = calloc(1, sizeof(struct comp_type));
112 comp_type->name_len = strlen(type);
113 comp_type->name = strdup(type);
114 comp_type->next = comp->types;
115 comp->types = comp_type;
116 return 0;
117}
118
119/*
120 * Add an algorithm in the configuration
121 */
122int comp_append_algo(struct comp *comp, const char *algo)
123{
124 struct comp_algo *comp_algo;
125 int i;
126
Willy Tarreau615105e2015-03-28 16:40:46 +0100127 for (i = 0; comp_algos[i].cfg_name; i++) {
128 if (!strcmp(algo, comp_algos[i].cfg_name)) {
William Lallemand82fe75c2012-10-23 10:25:10 +0200129 comp_algo = calloc(1, sizeof(struct comp_algo));
130 memmove(comp_algo, &comp_algos[i], sizeof(struct comp_algo));
131 comp_algo->next = comp->algos;
132 comp->algos = comp_algo;
133 return 0;
134 }
135 }
136 return -1;
137}
138
139/* emit the chunksize followed by a CRLF on the output and return the number of
Willy Tarreau15530d22015-03-28 12:05:47 +0100140 * bytes written. It goes backwards and starts with the byte before <end>. It
141 * returns the number of bytes written which will not exceed 10 (8 digits, CR,
142 * and LF). The caller is responsible for ensuring there is enough room left in
143 * the output buffer for the string.
William Lallemand82fe75c2012-10-23 10:25:10 +0200144 */
Willy Tarreau15530d22015-03-28 12:05:47 +0100145int http_emit_chunk_size(char *end, unsigned int chksz)
William Lallemand82fe75c2012-10-23 10:25:10 +0200146{
Willy Tarreau15530d22015-03-28 12:05:47 +0100147 char *beg = end;
William Lallemand82fe75c2012-10-23 10:25:10 +0200148
Willy Tarreau15530d22015-03-28 12:05:47 +0100149 *--beg = '\n';
150 *--beg = '\r';
William Lallemand82fe75c2012-10-23 10:25:10 +0200151 do {
Willy Tarreau15530d22015-03-28 12:05:47 +0100152 *--beg = hextab[chksz & 0xF];
153 } while (chksz >>= 4);
154 return end - beg;
William Lallemand82fe75c2012-10-23 10:25:10 +0200155}
156
157/*
158 * Init HTTP compression
159 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200160int http_compression_buffer_init(struct stream *s, struct buffer *in, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200161{
Willy Tarreau2aee2212015-03-28 12:20:33 +0100162 /* output stream requires at least 10 bytes for the gzip header, plus
163 * at least 8 bytes for the gzip trailer (crc+len), plus a possible
164 * plus at most 5 bytes per 32kB block and 2 bytes to close the stream.
165 */
166 if (in->size - buffer_len(in) < 20 + 5 * ((in->i + 32767) >> 15))
Willy Tarreaud328af52015-03-28 11:10:56 +0100167 return -1;
William Lallemand82fe75c2012-10-23 10:25:10 +0200168
Willy Tarreaud328af52015-03-28 11:10:56 +0100169 /* prepare an empty output buffer in which we reserve enough room for
Willy Tarreau15530d22015-03-28 12:05:47 +0100170 * copying the output bytes from <in>, plus 10 extra bytes to write
Willy Tarreaud328af52015-03-28 11:10:56 +0100171 * the chunk size. We don't copy the bytes yet so that if we have to
172 * cancel the operation later, it's cheap.
William Lallemand82fe75c2012-10-23 10:25:10 +0200173 */
Willy Tarreau474cf542014-11-24 10:54:47 +0100174 b_reset(out);
Willy Tarreaud328af52015-03-28 11:10:56 +0100175 out->o = in->o;
176 out->p += out->o;
Willy Tarreau15530d22015-03-28 12:05:47 +0100177 out->i = 10;
William Lallemand82fe75c2012-10-23 10:25:10 +0200178 return 0;
179}
180
181/*
182 * Add data to compress
183 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200184int http_compression_buffer_add_data(struct stream *s, struct buffer *in, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200185{
186 struct http_msg *msg = &s->txn.rsp;
William Lallemandbf3ae612012-11-19 12:35:37 +0100187 int consumed_data = 0;
William Lallemand82fe75c2012-10-23 10:25:10 +0200188 int data_process_len;
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200189 int block1, block2;
William Lallemand82fe75c2012-10-23 10:25:10 +0200190
191 /*
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200192 * Temporarily skip already parsed data and chunks to jump to the
193 * actual data block. It is fixed before leaving.
William Lallemand82fe75c2012-10-23 10:25:10 +0200194 */
195 b_adv(in, msg->next);
William Lallemand82fe75c2012-10-23 10:25:10 +0200196
197 /*
198 * select the smallest size between the announced chunk size, the input
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200199 * data, and the available output buffer size. The compressors are
200 * assumed to be able to process all the bytes we pass to them at once.
William Lallemand82fe75c2012-10-23 10:25:10 +0200201 */
202 data_process_len = MIN(in->i, msg->chunk_len);
203 data_process_len = MIN(out->size - buffer_len(out), data_process_len);
204
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200205 block1 = data_process_len;
206 if (block1 > bi_contig_data(in))
207 block1 = bi_contig_data(in);
208 block2 = data_process_len - block1;
William Lallemand82fe75c2012-10-23 10:25:10 +0200209
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200210 /* compressors return < 0 upon error or the amount of bytes read */
211 consumed_data = s->comp_algo->add_data(s->comp_ctx, bi_ptr(in), block1, out);
212 if (consumed_data >= 0 && block2 > 0) {
213 consumed_data = s->comp_algo->add_data(s->comp_ctx, in->data, block2, out);
214 if (consumed_data >= 0)
215 consumed_data += block1;
William Lallemand82fe75c2012-10-23 10:25:10 +0200216 }
217
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200218 /* restore original buffer pointer */
219 b_rew(in, msg->next);
William Lallemand82fe75c2012-10-23 10:25:10 +0200220
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200221 if (consumed_data > 0) {
222 msg->next += consumed_data;
223 msg->chunk_len -= consumed_data;
224 }
William Lallemandbf3ae612012-11-19 12:35:37 +0100225 return consumed_data;
William Lallemand82fe75c2012-10-23 10:25:10 +0200226}
227
228/*
229 * Flush data in process, and write the header and footer of the chunk. Upon
230 * success, in and out buffers are swapped to avoid a copy.
231 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200232int http_compression_buffer_end(struct stream *s, struct buffer **in, struct buffer **out, int end)
William Lallemand82fe75c2012-10-23 10:25:10 +0200233{
Willy Tarreau3ca54482014-04-23 19:31:17 +0200234 int to_forward;
William Lallemand82fe75c2012-10-23 10:25:10 +0200235 int left;
236 struct http_msg *msg = &s->txn.rsp;
237 struct buffer *ib = *in, *ob = *out;
Willy Tarreaud328af52015-03-28 11:10:56 +0100238 char *tail;
William Lallemand08289f12012-10-31 11:19:18 +0100239
Willy Tarreau418b8c02015-03-29 03:32:06 +0200240#if defined(USE_SLZ) || defined(USE_ZLIB)
William Lallemand82fe75c2012-10-23 10:25:10 +0200241 int ret;
242
243 /* flush data here */
244
245 if (end)
Willy Tarreau9787efa2015-03-28 19:17:31 +0100246 ret = s->comp_algo->finish(s->comp_ctx, ob); /* end of data */
William Lallemand82fe75c2012-10-23 10:25:10 +0200247 else
Willy Tarreau9787efa2015-03-28 19:17:31 +0100248 ret = s->comp_algo->flush(s->comp_ctx, ob); /* end of buffer */
William Lallemand82fe75c2012-10-23 10:25:10 +0200249
250 if (ret < 0)
251 return -1; /* flush failed */
252
William Lallemand08289f12012-10-31 11:19:18 +0100253#endif /* USE_ZLIB */
254
Willy Tarreau15530d22015-03-28 12:05:47 +0100255 if (ob->i == 10) {
Willy Tarreaud328af52015-03-28 11:10:56 +0100256 /* No data were appended, let's drop the output buffer and
257 * keep the input buffer unchanged.
258 */
259 return 0;
260 }
William Lallemand82fe75c2012-10-23 10:25:10 +0200261
Willy Tarreaud328af52015-03-28 11:10:56 +0100262 /* OK so at this stage, we have an output buffer <ob> looking like this :
263 *
264 * <-- o --> <------ i ----->
265 * +---------+---+------------+-----------+
266 * | out | c | comp_in | empty |
267 * +---------+---+------------+-----------+
268 * data p size
269 *
270 * <out> is the room reserved to copy ib->o. It starts at ob->data and
271 * has not yet been filled. <c> is the room reserved to write the chunk
Willy Tarreau15530d22015-03-28 12:05:47 +0100272 * size (10 bytes). <comp_in> is the compressed equivalent of the data
Willy Tarreaud328af52015-03-28 11:10:56 +0100273 * part of ib->i. <empty> is the amount of empty bytes at the end of
274 * the buffer, into which we may have to copy the remaining bytes from
275 * ib->i after the data (chunk size, trailers, ...).
276 */
William Lallemand82fe75c2012-10-23 10:25:10 +0200277
Willy Tarreaud328af52015-03-28 11:10:56 +0100278 /* Write real size at the begining of the chunk, no need of wrapping.
Willy Tarreau15530d22015-03-28 12:05:47 +0100279 * We write the chunk using a dynamic length and adjust ob->p and ob->i
280 * accordingly afterwards. That will move <out> away from <data>.
Willy Tarreaud328af52015-03-28 11:10:56 +0100281 */
Willy Tarreau15530d22015-03-28 12:05:47 +0100282 left = 10 - http_emit_chunk_size(ob->p + 10, ob->i - 10);
283 ob->p += left;
284 ob->i -= left;
William Lallemand82fe75c2012-10-23 10:25:10 +0200285
Willy Tarreaud328af52015-03-28 11:10:56 +0100286 /* Copy previous data from ib->o into ob->o */
287 if (ib->o > 0) {
288 left = bo_contig_data(ib);
289 memcpy(ob->p - ob->o, bo_ptr(ib), left);
290 if (ib->o - left) /* second part of the buffer */
291 memcpy(ob->p - ob->o + left, ib->data, ib->o - left);
292 }
293
294 /* chunked encoding requires CRLF after data */
295 tail = ob->p + ob->i;
296 *tail++ = '\r';
297 *tail++ = '\n';
298
299 /* At the end of data, we must write the empty chunk 0<CRLF>,
300 * and terminate the trailers section with a last <CRLF>. If
301 * we're forwarding a chunked-encoded response, we'll have a
302 * trailers section after the empty chunk which needs to be
303 * forwarded and which will provide the last CRLF. Otherwise
304 * we write it ourselves.
305 */
306 if (msg->msg_state >= HTTP_MSG_TRAILERS) {
307 memcpy(tail, "0\r\n", 3);
308 tail += 3;
309 if (msg->msg_state >= HTTP_MSG_DONE) {
310 memcpy(tail, "\r\n", 2);
311 tail += 2;
William Lallemand82fe75c2012-10-23 10:25:10 +0200312 }
William Lallemand82fe75c2012-10-23 10:25:10 +0200313 }
Willy Tarreaud328af52015-03-28 11:10:56 +0100314 ob->i = tail - ob->p;
William Lallemand82fe75c2012-10-23 10:25:10 +0200315
316 to_forward = ob->i;
Willy Tarreau55058a72012-11-21 08:27:21 +0100317
William Lallemandd85f9172012-11-09 17:05:39 +0100318 /* update input rate */
Willy Tarreau55058a72012-11-21 08:27:21 +0100319 if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) {
Willy Tarreau3ca54482014-04-23 19:31:17 +0200320 update_freq_ctr(&global.comp_bps_in, msg->next);
321 s->fe->fe_counters.comp_in += msg->next;
322 s->be->be_counters.comp_in += msg->next;
Willy Tarreau55058a72012-11-21 08:27:21 +0100323 } else {
Willy Tarreau3ca54482014-04-23 19:31:17 +0200324 s->fe->fe_counters.comp_byp += msg->next;
325 s->be->be_counters.comp_byp += msg->next;
Willy Tarreau55058a72012-11-21 08:27:21 +0100326 }
William Lallemandd85f9172012-11-09 17:05:39 +0100327
William Lallemand82fe75c2012-10-23 10:25:10 +0200328 /* copy the remaining data in the tmp buffer. */
Willy Tarreau7f2f8d52014-04-18 00:20:14 +0200329 b_adv(ib, msg->next);
330 msg->next = 0;
331
William Lallemand82fe75c2012-10-23 10:25:10 +0200332 if (ib->i > 0) {
Willy Tarreaud328af52015-03-28 11:10:56 +0100333 left = bi_contig_data(ib);
334 memcpy(ob->p + ob->i, bi_ptr(ib), left);
335 ob->i += left;
336 if (ib->i - left) {
337 memcpy(ob->p + ob->i, ib->data, ib->i - left);
338 ob->i += ib->i - left;
William Lallemand82fe75c2012-10-23 10:25:10 +0200339 }
340 }
341
342 /* swap the buffers */
343 *in = ob;
344 *out = ib;
345
Willy Tarreau55058a72012-11-21 08:27:21 +0100346 if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) {
William Lallemandd85f9172012-11-09 17:05:39 +0100347 update_freq_ctr(&global.comp_bps_out, to_forward);
Willy Tarreau55058a72012-11-21 08:27:21 +0100348 s->fe->fe_counters.comp_out += to_forward;
349 s->be->be_counters.comp_out += to_forward;
350 }
William Lallemandd85f9172012-11-09 17:05:39 +0100351
William Lallemand82fe75c2012-10-23 10:25:10 +0200352 /* forward the new chunk without remaining data */
353 b_adv(ob, to_forward);
354
William Lallemand82fe75c2012-10-23 10:25:10 +0200355 return to_forward;
356}
357
William Lallemand8b52bb32012-11-16 18:06:41 +0100358/*
359 * Alloc the comp_ctx
360 */
361static inline int init_comp_ctx(struct comp_ctx **comp_ctx)
362{
363#ifdef USE_ZLIB
364 z_stream *strm;
365
William Lallemande3a7d992012-11-20 11:25:20 +0100366 if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < sizeof(struct comp_ctx))
William Lallemand8b52bb32012-11-16 18:06:41 +0100367 return -1;
368#endif
369
370 if (unlikely(pool_comp_ctx == NULL))
371 pool_comp_ctx = create_pool("comp_ctx", sizeof(struct comp_ctx), MEM_F_SHARED);
372
373 *comp_ctx = pool_alloc2(pool_comp_ctx);
374 if (*comp_ctx == NULL)
375 return -1;
Willy Tarreau418b8c02015-03-29 03:32:06 +0200376#if defined(USE_SLZ)
377 (*comp_ctx)->direct_ptr = NULL;
378 (*comp_ctx)->direct_len = 0;
379 (*comp_ctx)->queued = NULL;
380#elif defined(USE_ZLIB)
William Lallemande3a7d992012-11-20 11:25:20 +0100381 zlib_used_memory += sizeof(struct comp_ctx);
William Lallemand8b52bb32012-11-16 18:06:41 +0100382
383 strm = &(*comp_ctx)->strm;
384 strm->zalloc = alloc_zlib;
385 strm->zfree = free_zlib;
386 strm->opaque = *comp_ctx;
387#endif
388 return 0;
389}
390
391/*
392 * Dealloc the comp_ctx
393 */
394static inline int deinit_comp_ctx(struct comp_ctx **comp_ctx)
395{
396 if (!*comp_ctx)
397 return 0;
398
399 pool_free2(pool_comp_ctx, *comp_ctx);
400 *comp_ctx = NULL;
401
402#ifdef USE_ZLIB
William Lallemande3a7d992012-11-20 11:25:20 +0100403 zlib_used_memory -= sizeof(struct comp_ctx);
William Lallemand8b52bb32012-11-16 18:06:41 +0100404#endif
William Lallemand8b52bb32012-11-16 18:06:41 +0100405 return 0;
406}
407
William Lallemand82fe75c2012-10-23 10:25:10 +0200408
409/****************************
410 **** Identity algorithm ****
411 ****************************/
412
413/*
414 * Init the identity algorithm
415 */
Willy Tarreau9f640a12015-03-28 15:46:00 +0100416static int identity_init(struct comp_ctx **comp_ctx, int level)
William Lallemand82fe75c2012-10-23 10:25:10 +0200417{
418 return 0;
419}
420
421/*
422 * Process data
William Lallemandbf3ae612012-11-19 12:35:37 +0100423 * Return size of consumed data or -1 on error
William Lallemand82fe75c2012-10-23 10:25:10 +0200424 */
Willy Tarreau9f640a12015-03-28 15:46:00 +0100425static int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200426{
William Lallemandbf3ae612012-11-19 12:35:37 +0100427 char *out_data = bi_end(out);
428 int out_len = out->size - buffer_len(out);
429
William Lallemand82fe75c2012-10-23 10:25:10 +0200430 if (out_len < in_len)
431 return -1;
432
433 memcpy(out_data, in_data, in_len);
434
William Lallemandbf3ae612012-11-19 12:35:37 +0100435 out->i += in_len;
436
William Lallemand82fe75c2012-10-23 10:25:10 +0200437 return in_len;
438}
439
Willy Tarreau9787efa2015-03-28 19:17:31 +0100440static int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200441{
442 return 0;
443}
444
Willy Tarreau9787efa2015-03-28 19:17:31 +0100445static int identity_finish(struct comp_ctx *comp_ctx, struct buffer *out)
446{
447 return 0;
448}
449
Willy Tarreau418b8c02015-03-29 03:32:06 +0200450/*
451 * Deinit the algorithm
452 */
453static int identity_end(struct comp_ctx **comp_ctx)
William Lallemand82fe75c2012-10-23 10:25:10 +0200454{
455 return 0;
456}
457
Willy Tarreau418b8c02015-03-29 03:32:06 +0200458
459#ifdef USE_SLZ
460
461/* SLZ's gzip format (RFC1952). Returns < 0 on error. */
462static int rfc1952_init(struct comp_ctx **comp_ctx, int level)
463{
464 if (init_comp_ctx(comp_ctx) < 0)
465 return -1;
466
467 (*comp_ctx)->cur_lvl = !!level;
468 return slz_rfc1952_init(&(*comp_ctx)->strm, !!level);
469}
470
471/* SLZ's raw deflate format (RFC1951). Returns < 0 on error. */
472static int rfc1951_init(struct comp_ctx **comp_ctx, int level)
473{
474 if (init_comp_ctx(comp_ctx) < 0)
475 return -1;
476
477 (*comp_ctx)->cur_lvl = !!level;
478 return slz_rfc1951_init(&(*comp_ctx)->strm, !!level);
479}
480
481/* SLZ's zlib format (RFC1950). Returns < 0 on error. */
482static int rfc1950_init(struct comp_ctx **comp_ctx, int level)
483{
484 if (init_comp_ctx(comp_ctx) < 0)
485 return -1;
486
487 (*comp_ctx)->cur_lvl = !!level;
488 return slz_rfc1950_init(&(*comp_ctx)->strm, !!level);
489}
490
491/* Return the size of consumed data or -1. The output buffer is unused at this
492 * point, we only keep a reference to the input data or a copy of them if the
493 * reference is already used.
William Lallemand82fe75c2012-10-23 10:25:10 +0200494 */
Willy Tarreau418b8c02015-03-29 03:32:06 +0200495static int rfc195x_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200496{
Willy Tarreau418b8c02015-03-29 03:32:06 +0200497 static struct buffer *tmpbuf = &buf_empty;
498
499 if (in_len <= 0)
500 return 0;
501
502 if (comp_ctx->direct_ptr && !comp_ctx->queued) {
503 /* data already being pointed to, we're in front of fragmented
504 * data and need a buffer now. We reuse the same buffer, as it's
505 * not used out of the scope of a series of add_data()*, end().
506 */
507 if (unlikely(!tmpbuf->size)) {
508 /* this is the first time we need the compression buffer */
509 if (b_alloc(&tmpbuf) == NULL)
510 return -1; /* no memory */
511 }
512 b_reset(tmpbuf);
513 memcpy(bi_end(tmpbuf), comp_ctx->direct_ptr, comp_ctx->direct_len);
514 tmpbuf->i += comp_ctx->direct_len;
515 comp_ctx->direct_ptr = NULL;
516 comp_ctx->direct_len = 0;
517 comp_ctx->queued = tmpbuf;
518 /* fall through buffer copy */
519 }
520
521 if (comp_ctx->queued) {
522 /* data already pending */
523 memcpy(bi_end(comp_ctx->queued), in_data, in_len);
524 comp_ctx->queued->i += in_len;
525 return in_len;
526 }
527
528 comp_ctx->direct_ptr = in_data;
529 comp_ctx->direct_len = in_len;
530 return in_len;
531}
532
533/* Compresses the data accumulated using add_data(), and optionally sends the
534 * format-specific trailer if <finish> is non-null. <out> is expected to have a
535 * large enough free non-wrapping space as verified by http_comp_buffer_init().
536 * The number of bytes emitted is reported.
537 */
538static int rfc195x_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out, int finish)
539{
540 struct slz_stream *strm = &comp_ctx->strm;
541 const char *in_ptr;
542 int in_len;
543 int out_len;
544
545 in_ptr = comp_ctx->direct_ptr;
546 in_len = comp_ctx->direct_len;
547
548 if (comp_ctx->queued) {
549 in_ptr = comp_ctx->queued->p;
550 in_len = comp_ctx->queued->i;
551 }
552
553 out_len = out->i;
554
555 if (in_ptr)
556 out->i += slz_encode(strm, bi_end(out), in_ptr, in_len, !finish);
557
558 if (finish)
559 out->i += slz_finish(strm, bi_end(out));
560
561 out_len = out->i - out_len;
562
563 /* very important, we must wipe the data we've just flushed */
564 comp_ctx->direct_len = 0;
565 comp_ctx->direct_ptr = NULL;
566 comp_ctx->queued = NULL;
567
568 /* Verify compression rate limiting and CPU usage */
569 if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) || /* rate */
570 (idle_pct < compress_min_idle)) { /* idle */
571 if (comp_ctx->cur_lvl > 0)
572 strm->level = --comp_ctx->cur_lvl;
573 }
574 else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel && comp_ctx->cur_lvl < 1) {
575 strm->level = ++comp_ctx->cur_lvl;
576 }
577
578 /* and that's all */
579 return out_len;
580}
581
582static int rfc195x_flush(struct comp_ctx *comp_ctx, struct buffer *out)
583{
584 return rfc195x_flush_or_finish(comp_ctx, out, 0);
585}
586
587static int rfc195x_finish(struct comp_ctx *comp_ctx, struct buffer *out)
588{
589 return rfc195x_flush_or_finish(comp_ctx, out, 1);
590}
591
592/* we just need to free the comp_ctx here, nothing was allocated */
593static int rfc195x_end(struct comp_ctx **comp_ctx)
594{
595 deinit_comp_ctx(comp_ctx);
William Lallemand82fe75c2012-10-23 10:25:10 +0200596 return 0;
597}
598
Willy Tarreau418b8c02015-03-29 03:32:06 +0200599#elif defined(USE_ZLIB) /* ! USE_SLZ */
William Lallemand82fe75c2012-10-23 10:25:10 +0200600
William Lallemand2b502472012-10-30 14:30:39 +0100601/*
602 * This is a tricky allocation function using the zlib.
603 * This is based on the allocation order in deflateInit2.
604 */
605static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size)
606{
607 struct comp_ctx *ctx = opaque;
608 static char round = 0; /* order in deflateInit2 */
609 void *buf = NULL;
Willy Tarreau4f31fc22014-12-24 18:07:55 +0100610 struct pool_head *pool = NULL;
William Lallemand2b502472012-10-30 14:30:39 +0100611
William Lallemande3a7d992012-11-20 11:25:20 +0100612 if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < (long)(items * size))
William Lallemand9d5f5482012-11-07 16:12:57 +0100613 goto end;
William Lallemand9d5f5482012-11-07 16:12:57 +0100614
William Lallemand2b502472012-10-30 14:30:39 +0100615 switch (round) {
616 case 0:
617 if (zlib_pool_deflate_state == NULL)
618 zlib_pool_deflate_state = create_pool("zlib_state", size * items, MEM_F_SHARED);
Willy Tarreau4f31fc22014-12-24 18:07:55 +0100619 pool = zlib_pool_deflate_state;
620 ctx->zlib_deflate_state = buf = pool_alloc2(pool);
William Lallemand2b502472012-10-30 14:30:39 +0100621 break;
622
623 case 1:
624 if (zlib_pool_window == NULL)
625 zlib_pool_window = create_pool("zlib_window", size * items, MEM_F_SHARED);
Willy Tarreau4f31fc22014-12-24 18:07:55 +0100626 pool = zlib_pool_window;
627 ctx->zlib_window = buf = pool_alloc2(pool);
William Lallemand2b502472012-10-30 14:30:39 +0100628 break;
629
630 case 2:
631 if (zlib_pool_prev == NULL)
632 zlib_pool_prev = create_pool("zlib_prev", size * items, MEM_F_SHARED);
Willy Tarreau4f31fc22014-12-24 18:07:55 +0100633 pool = zlib_pool_prev;
634 ctx->zlib_prev = buf = pool_alloc2(pool);
William Lallemand2b502472012-10-30 14:30:39 +0100635 break;
636
637 case 3:
638 if (zlib_pool_head == NULL)
639 zlib_pool_head = create_pool("zlib_head", size * items, MEM_F_SHARED);
Willy Tarreau4f31fc22014-12-24 18:07:55 +0100640 pool = zlib_pool_head;
641 ctx->zlib_head = buf = pool_alloc2(pool);
William Lallemand2b502472012-10-30 14:30:39 +0100642 break;
643
644 case 4:
645 if (zlib_pool_pending_buf == NULL)
646 zlib_pool_pending_buf = create_pool("zlib_pending_buf", size * items, MEM_F_SHARED);
Willy Tarreau4f31fc22014-12-24 18:07:55 +0100647 pool = zlib_pool_pending_buf;
648 ctx->zlib_pending_buf = buf = pool_alloc2(pool);
William Lallemand2b502472012-10-30 14:30:39 +0100649 break;
650 }
William Lallemande3a7d992012-11-20 11:25:20 +0100651 if (buf != NULL)
Willy Tarreau4f31fc22014-12-24 18:07:55 +0100652 zlib_used_memory += pool->size;
William Lallemand9d5f5482012-11-07 16:12:57 +0100653
654end:
William Lallemand2b502472012-10-30 14:30:39 +0100655
Willy Tarreau46909852012-11-15 14:57:56 +0100656 /* deflateInit2() first allocates and checks the deflate_state, then if
657 * it succeeds, it allocates all other 4 areas at ones and checks them
658 * at the end. So we want to correctly count the rounds depending on when
659 * zlib is supposed to abort.
660 */
661 if (buf || round)
662 round = (round + 1) % 5;
William Lallemand2b502472012-10-30 14:30:39 +0100663 return buf;
664}
665
666static void free_zlib(void *opaque, void *ptr)
667{
668 struct comp_ctx *ctx = opaque;
Willy Tarreaub1fbd052012-11-10 17:49:37 +0100669 struct pool_head *pool = NULL;
William Lallemand2b502472012-10-30 14:30:39 +0100670
671 if (ptr == ctx->zlib_window)
William Lallemand9d5f5482012-11-07 16:12:57 +0100672 pool = zlib_pool_window;
William Lallemand2b502472012-10-30 14:30:39 +0100673 else if (ptr == ctx->zlib_deflate_state)
William Lallemand9d5f5482012-11-07 16:12:57 +0100674 pool = zlib_pool_deflate_state;
William Lallemand2b502472012-10-30 14:30:39 +0100675 else if (ptr == ctx->zlib_prev)
William Lallemand9d5f5482012-11-07 16:12:57 +0100676 pool = zlib_pool_prev;
William Lallemand2b502472012-10-30 14:30:39 +0100677 else if (ptr == ctx->zlib_head)
William Lallemand9d5f5482012-11-07 16:12:57 +0100678 pool = zlib_pool_head;
William Lallemand2b502472012-10-30 14:30:39 +0100679 else if (ptr == ctx->zlib_pending_buf)
William Lallemand9d5f5482012-11-07 16:12:57 +0100680 pool = zlib_pool_pending_buf;
William Lallemand2b502472012-10-30 14:30:39 +0100681
William Lallemand9d5f5482012-11-07 16:12:57 +0100682 pool_free2(pool, ptr);
William Lallemande3a7d992012-11-20 11:25:20 +0100683 zlib_used_memory -= pool->size;
William Lallemand2b502472012-10-30 14:30:39 +0100684}
685
William Lallemand82fe75c2012-10-23 10:25:10 +0200686/**************************
687**** gzip algorithm ****
688***************************/
Willy Tarreau9f640a12015-03-28 15:46:00 +0100689static int gzip_init(struct comp_ctx **comp_ctx, int level)
William Lallemand82fe75c2012-10-23 10:25:10 +0200690{
William Lallemand8b52bb32012-11-16 18:06:41 +0100691 z_stream *strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200692
William Lallemand8b52bb32012-11-16 18:06:41 +0100693 if (init_comp_ctx(comp_ctx) < 0)
694 return -1;
William Lallemand9d5f5482012-11-07 16:12:57 +0100695
William Lallemand8b52bb32012-11-16 18:06:41 +0100696 strm = &(*comp_ctx)->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200697
William Lallemand8b52bb32012-11-16 18:06:41 +0100698 if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize + 16, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
699 deinit_comp_ctx(comp_ctx);
William Lallemand82fe75c2012-10-23 10:25:10 +0200700 return -1;
William Lallemand8b52bb32012-11-16 18:06:41 +0100701 }
702
703 (*comp_ctx)->cur_lvl = level;
William Lallemand82fe75c2012-10-23 10:25:10 +0200704
705 return 0;
706}
Willy Tarreauc91840a2015-03-28 17:00:39 +0100707
708/* Raw deflate algorithm */
709static int raw_def_init(struct comp_ctx **comp_ctx, int level)
710{
711 z_stream *strm;
712
713 if (init_comp_ctx(comp_ctx) < 0)
714 return -1;
715
716 strm = &(*comp_ctx)->strm;
717
718 if (deflateInit2(strm, level, Z_DEFLATED, -global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
719 deinit_comp_ctx(comp_ctx);
720 return -1;
721 }
722
723 (*comp_ctx)->cur_lvl = level;
724 return 0;
725}
726
William Lallemand82fe75c2012-10-23 10:25:10 +0200727/**************************
728**** Deflate algorithm ****
729***************************/
730
Willy Tarreau9f640a12015-03-28 15:46:00 +0100731static int deflate_init(struct comp_ctx **comp_ctx, int level)
William Lallemand82fe75c2012-10-23 10:25:10 +0200732{
William Lallemand8b52bb32012-11-16 18:06:41 +0100733 z_stream *strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200734
William Lallemand8b52bb32012-11-16 18:06:41 +0100735 if (init_comp_ctx(comp_ctx) < 0)
736 return -1;
737
738 strm = &(*comp_ctx)->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200739
Willy Tarreauc5599e72013-04-28 08:52:52 +0200740 if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
William Lallemand8b52bb32012-11-16 18:06:41 +0100741 deinit_comp_ctx(comp_ctx);
William Lallemand82fe75c2012-10-23 10:25:10 +0200742 return -1;
William Lallemand8b52bb32012-11-16 18:06:41 +0100743 }
744
745 (*comp_ctx)->cur_lvl = level;
William Lallemand82fe75c2012-10-23 10:25:10 +0200746
747 return 0;
748}
749
William Lallemandbf3ae612012-11-19 12:35:37 +0100750/* Return the size of consumed data or -1 */
Willy Tarreau9f640a12015-03-28 15:46:00 +0100751static int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200752{
William Lallemand82fe75c2012-10-23 10:25:10 +0200753 int ret;
William Lallemandbf3ae612012-11-19 12:35:37 +0100754 z_stream *strm = &comp_ctx->strm;
755 char *out_data = bi_end(out);
756 int out_len = out->size - buffer_len(out);
William Lallemand82fe75c2012-10-23 10:25:10 +0200757
758 if (in_len <= 0)
759 return 0;
760
761
762 if (out_len <= 0)
763 return -1;
764
William Lallemand82fe75c2012-10-23 10:25:10 +0200765 strm->next_in = (unsigned char *)in_data;
766 strm->avail_in = in_len;
767 strm->next_out = (unsigned char *)out_data;
768 strm->avail_out = out_len;
769
770 ret = deflate(strm, Z_NO_FLUSH);
771 if (ret != Z_OK)
772 return -1;
773
774 /* deflate update the available data out */
William Lallemandbf3ae612012-11-19 12:35:37 +0100775 out->i += out_len - strm->avail_out;
William Lallemand82fe75c2012-10-23 10:25:10 +0200776
William Lallemandbf3ae612012-11-19 12:35:37 +0100777 return in_len - strm->avail_in;
William Lallemand82fe75c2012-10-23 10:25:10 +0200778}
779
Willy Tarreau9787efa2015-03-28 19:17:31 +0100780static int deflate_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
William Lallemand82fe75c2012-10-23 10:25:10 +0200781{
782 int ret;
William Lallemand82fe75c2012-10-23 10:25:10 +0200783 int out_len = 0;
William Lallemand1c2d6222012-10-30 15:52:53 +0100784 z_stream *strm = &comp_ctx->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200785
William Lallemand82fe75c2012-10-23 10:25:10 +0200786 strm->next_out = (unsigned char *)bi_end(out);
787 strm->avail_out = out->size - buffer_len(out);
788
789 ret = deflate(strm, flag);
790 if (ret != Z_OK && ret != Z_STREAM_END)
791 return -1;
792
793 out_len = (out->size - buffer_len(out)) - strm->avail_out;
794 out->i += out_len;
795
William Lallemand072a2bf2012-11-20 17:01:01 +0100796 /* compression limit */
797 if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) || /* rate */
798 (idle_pct < compress_min_idle)) { /* idle */
799 /* decrease level */
800 if (comp_ctx->cur_lvl > 0) {
801 comp_ctx->cur_lvl--;
William Lallemandd85f9172012-11-09 17:05:39 +0100802 deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY);
803 }
William Lallemand072a2bf2012-11-20 17:01:01 +0100804
805 } else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel) {
806 /* increase level */
807 comp_ctx->cur_lvl++ ;
808 deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY);
William Lallemandd85f9172012-11-09 17:05:39 +0100809 }
810
William Lallemand82fe75c2012-10-23 10:25:10 +0200811 return out_len;
812}
813
Willy Tarreau9787efa2015-03-28 19:17:31 +0100814static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out)
815{
816 return deflate_flush_or_finish(comp_ctx, out, Z_SYNC_FLUSH);
817}
818
819static int deflate_finish(struct comp_ctx *comp_ctx, struct buffer *out)
820{
821 return deflate_flush_or_finish(comp_ctx, out, Z_FINISH);
822}
823
Willy Tarreau9f640a12015-03-28 15:46:00 +0100824static int deflate_end(struct comp_ctx **comp_ctx)
William Lallemand82fe75c2012-10-23 10:25:10 +0200825{
William Lallemand8b52bb32012-11-16 18:06:41 +0100826 z_stream *strm = &(*comp_ctx)->strm;
827 int ret;
William Lallemand82fe75c2012-10-23 10:25:10 +0200828
William Lallemand8b52bb32012-11-16 18:06:41 +0100829 ret = deflateEnd(strm);
William Lallemand82fe75c2012-10-23 10:25:10 +0200830
William Lallemand8b52bb32012-11-16 18:06:41 +0100831 deinit_comp_ctx(comp_ctx);
832
833 return ret;
William Lallemand82fe75c2012-10-23 10:25:10 +0200834}
835
836#endif /* USE_ZLIB */
837
William Lallemand727db8b2013-04-20 17:33:20 +0200838/* boolean, returns true if compression is used (either gzip or deflate) in the response */
839static int
Willy Tarreau87b09662015-04-03 00:22:06 +0200840smp_fetch_res_comp(struct proxy *px, struct stream *l4, void *l7, unsigned int opt,
Thierry FOURNIERf41a8092014-12-07 18:37:57 +0100841 const struct arg *args, struct sample *smp, const char *kw, void *private)
William Lallemand727db8b2013-04-20 17:33:20 +0200842{
843 smp->type = SMP_T_BOOL;
844 smp->data.uint = (l4->comp_algo != NULL);
845 return 1;
846}
847
848/* string, returns algo */
849static int
Willy Tarreau87b09662015-04-03 00:22:06 +0200850smp_fetch_res_comp_algo(struct proxy *px, struct stream *l4, void *l7, unsigned int opt,
Thierry FOURNIERf41a8092014-12-07 18:37:57 +0100851 const struct arg *args, struct sample *smp, const char *kw, void *private)
William Lallemand727db8b2013-04-20 17:33:20 +0200852{
853 if (!l4->comp_algo)
854 return 0;
855
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +0100856 smp->type = SMP_T_STR;
857 smp->flags = SMP_F_CONST;
Willy Tarreau615105e2015-03-28 16:40:46 +0100858 smp->data.str.str = l4->comp_algo->cfg_name;
859 smp->data.str.len = l4->comp_algo->cfg_name_len;
William Lallemand727db8b2013-04-20 17:33:20 +0200860 return 1;
861}
862
863/* Note: must not be declared <const> as its list will be overwritten */
Willy Tarreaudc13c112013-06-21 23:16:39 +0200864static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau7f6fa692013-04-23 19:39:43 +0200865 { /* END */ },
William Lallemand727db8b2013-04-20 17:33:20 +0200866}};
867
868/* Note: must not be declared <const> as its list will be overwritten */
Willy Tarreaudc13c112013-06-21 23:16:39 +0200869static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
William Lallemand727db8b2013-04-20 17:33:20 +0200870 { "res.comp", smp_fetch_res_comp, 0, NULL, SMP_T_BOOL, SMP_USE_HRSHP },
871 { "res.comp_algo", smp_fetch_res_comp_algo, 0, NULL, SMP_T_STR, SMP_USE_HRSHP },
872 { /* END */ },
873}};
874
875__attribute__((constructor))
876static void __comp_fetch_init(void)
877{
Willy Tarreau418b8c02015-03-29 03:32:06 +0200878#ifdef USE_SLZ
879 slz_make_crc_table();
880 slz_prepare_dist_table();
881#endif
William Lallemand727db8b2013-04-20 17:33:20 +0200882 acl_register_keywords(&acl_kws);
883 sample_register_fetches(&sample_fetch_keywords);
884}