blob: 96bbb66395835b90a9a404770bfb4822c0aedf44 [file] [log] [blame]
Dragan Dosen93b38d92015-06-29 16:43:25 +02001#include <stdio.h>
2
3#include <common/cfgparse.h>
4#include <common/chunk.h>
James Rosewella28bbd52015-09-18 18:28:52 +01005#include <common/buffer.h>
Willy Tarreau9f3f2542016-12-21 20:30:05 +01006#include <common/errors.h>
Ben51Degrees4ddf59d2019-02-05 13:24:00 +00007#include <common/hathreads.h>
Willy Tarreau0108d902018-11-25 19:14:37 +01008#include <common/initcall.h>
Willy Tarreau80713382018-11-26 10:19:54 +01009#include <types/global.h>
Dragan Dosen93b38d92015-06-29 16:43:25 +020010#include <proto/arg.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020011#include <proto/http_fetch.h>
Ben51Degrees31a51f22019-06-12 15:19:12 +010012#include <proto/http_htx.h>
Dragan Dosen93b38d92015-06-29 16:43:25 +020013#include <proto/log.h>
Christopher Fauletfc9cfe42019-07-16 14:54:53 +020014#include <proto/http_ana.h>
Dragan Dosen93b38d92015-06-29 16:43:25 +020015#include <proto/sample.h>
16#include <import/xxhash.h>
Dragan Dosen105c8e62015-06-29 16:43:26 +020017#include <import/lru.h>
Willy Tarreaub7a67142016-12-21 21:18:44 +010018#include <51Degrees.h>
Dragan Dosen93b38d92015-06-29 16:43:25 +020019
20struct _51d_property_names {
21 struct list list;
22 char *name;
23};
24
James Rosewella28bbd52015-09-18 18:28:52 +010025#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Dragan Dosen105c8e62015-06-29 16:43:26 +020026static struct lru64_head *_51d_lru_tree = NULL;
27static unsigned long long _51d_lru_seed;
Ben51Degrees4ddf59d2019-02-05 13:24:00 +000028
29__decl_spinlock(_51d_lru_lock);
James Rosewella28bbd52015-09-18 18:28:52 +010030#endif
Dragan Dosen105c8e62015-06-29 16:43:26 +020031
Willy Tarreaub7a67142016-12-21 21:18:44 +010032static struct {
33 char property_separator; /* the separator to use in the response for the values. this is taken from 51degrees-property-separator from config. */
34 struct list property_names; /* list of properties to load into the data set. this is taken from 51degrees-property-name-list from config. */
35 char *data_file_path;
36 int header_count; /* number of HTTP headers related to device detection. */
Willy Tarreau83061a82018-07-13 11:56:34 +020037 struct buffer *header_names; /* array of HTTP header names. */
Willy Tarreaub7a67142016-12-21 21:18:44 +010038 fiftyoneDegreesDataSet data_set; /* data set used with the pattern and trie detection methods. */
39#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
40 fiftyoneDegreesWorksetPool *pool; /* pool of worksets to avoid creating a new one for each request. */
41#endif
42#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
43 int32_t *header_offsets; /* offsets to the HTTP header name string. */
Ben51Degrees4ddf59d2019-02-05 13:24:00 +000044#ifdef FIFTYONEDEGREES_NO_THREADING
Willy Tarreaub7a67142016-12-21 21:18:44 +010045 fiftyoneDegreesDeviceOffsets device_offsets; /* Memory used for device offsets. */
46#endif
Ben51Degrees4ddf59d2019-02-05 13:24:00 +000047#endif
Willy Tarreaub7a67142016-12-21 21:18:44 +010048 int cache_size;
49} global_51degrees = {
50 .property_separator = ',',
51 .property_names = LIST_HEAD_INIT(global_51degrees.property_names),
52 .data_file_path = NULL,
53#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
54 .data_set = { },
55#endif
56 .cache_size = 0,
57};
58
Dragan Dosen93b38d92015-06-29 16:43:25 +020059static int _51d_data_file(char **args, int section_type, struct proxy *curpx,
60 struct proxy *defpx, const char *file, int line,
61 char **err)
62{
63 if (*(args[1]) == 0) {
64 memprintf(err,
65 "'%s' expects a filepath to a 51Degrees trie or pattern data file.",
66 args[0]);
67 return -1;
68 }
69
Willy Tarreaub7a67142016-12-21 21:18:44 +010070 if (global_51degrees.data_file_path)
71 free(global_51degrees.data_file_path);
72 global_51degrees.data_file_path = strdup(args[1]);
Dragan Dosen93b38d92015-06-29 16:43:25 +020073
74 return 0;
75}
76
77static int _51d_property_name_list(char **args, int section_type, struct proxy *curpx,
James Rosewella28bbd52015-09-18 18:28:52 +010078 struct proxy *defpx, const char *file, int line,
79 char **err)
Dragan Dosen93b38d92015-06-29 16:43:25 +020080{
81 int cur_arg = 1;
82 struct _51d_property_names *name;
83
84 if (*(args[cur_arg]) == 0) {
85 memprintf(err,
86 "'%s' expects at least one 51Degrees property name.",
87 args[0]);
88 return -1;
89 }
90
91 while (*(args[cur_arg])) {
Vincent Bernat02779b62016-04-03 13:48:43 +020092 name = calloc(1, sizeof(*name));
Dragan Dosen93b38d92015-06-29 16:43:25 +020093 name->name = strdup(args[cur_arg]);
Willy Tarreaub7a67142016-12-21 21:18:44 +010094 LIST_ADDQ(&global_51degrees.property_names, &name->list);
Dragan Dosen93b38d92015-06-29 16:43:25 +020095 ++cur_arg;
96 }
97
98 return 0;
99}
100
101static int _51d_property_separator(char **args, int section_type, struct proxy *curpx,
102 struct proxy *defpx, const char *file, int line,
103 char **err)
104{
105 if (*(args[1]) == 0) {
106 memprintf(err,
107 "'%s' expects a single character.",
108 args[0]);
109 return -1;
110 }
111 if (strlen(args[1]) > 1) {
112 memprintf(err,
113 "'%s' expects a single character, got '%s'.",
114 args[0], args[1]);
115 return -1;
116 }
117
Willy Tarreaub7a67142016-12-21 21:18:44 +0100118 global_51degrees.property_separator = *args[1];
Dragan Dosen93b38d92015-06-29 16:43:25 +0200119
120 return 0;
121}
122
Dragan Dosen105c8e62015-06-29 16:43:26 +0200123static int _51d_cache_size(char **args, int section_type, struct proxy *curpx,
124 struct proxy *defpx, const char *file, int line,
125 char **err)
126{
127 if (*(args[1]) == 0) {
128 memprintf(err,
129 "'%s' expects a positive numeric value.",
130 args[0]);
131 return -1;
132 }
133
Willy Tarreaub7a67142016-12-21 21:18:44 +0100134 global_51degrees.cache_size = atoi(args[1]);
135 if (global_51degrees.cache_size < 0) {
Dragan Dosen105c8e62015-06-29 16:43:26 +0200136 memprintf(err,
137 "'%s' expects a positive numeric value, got '%s'.",
138 args[0], args[1]);
139 return -1;
140 }
141
James Rosewella28bbd52015-09-18 18:28:52 +0100142 return 0;
143}
144
145static int _51d_fetch_check(struct arg *arg, char **err_msg)
146{
Willy Tarreaub7a67142016-12-21 21:18:44 +0100147 if (global_51degrees.data_file_path)
James Rosewella28bbd52015-09-18 18:28:52 +0100148 return 1;
149
150 memprintf(err_msg, "51Degrees data file is not specified (parameter '51degrees-data-file')");
Dragan Dosen105c8e62015-06-29 16:43:26 +0200151 return 0;
152}
153
Dragan Dosen9373fc52015-08-07 16:41:23 +0200154static int _51d_conv_check(struct arg *arg, struct sample_conv *conv,
James Rosewella28bbd52015-09-18 18:28:52 +0100155 const char *file, int line, char **err_msg)
Dragan Dosen9373fc52015-08-07 16:41:23 +0200156{
Willy Tarreaub7a67142016-12-21 21:18:44 +0100157 if (global_51degrees.data_file_path)
Dragan Dosen9373fc52015-08-07 16:41:23 +0200158 return 1;
159
James Rosewella28bbd52015-09-18 18:28:52 +0100160 memprintf(err_msg, "51Degrees data file is not specified (parameter '51degrees-data-file')");
Dragan Dosen9373fc52015-08-07 16:41:23 +0200161 return 0;
162}
163
James Rosewella28bbd52015-09-18 18:28:52 +0100164#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
ben@51degrees.comc9dfa242016-01-08 13:47:46 +0000165static void _51d_lru_free(void *cache_entry)
166{
Willy Tarreau83061a82018-07-13 11:56:34 +0200167 struct buffer *ptr = cache_entry;
ben@51degrees.comc9dfa242016-01-08 13:47:46 +0000168
169 if (!ptr)
170 return;
171
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200172 free(ptr->area);
ben@51degrees.comc9dfa242016-01-08 13:47:46 +0000173 free(ptr);
174}
175
176/* Allocates memory freeing space in the cache if necessary.
177*/
178static void *_51d_malloc(int size)
179{
180 void *ptr = malloc(size);
181
182 if (!ptr) {
183 /* free the oldest 10 entries from lru to free up some memory
184 * then try allocating memory again */
185 lru64_kill_oldest(_51d_lru_tree, 10);
186 ptr = malloc(size);
187 }
188
189 return ptr;
190}
191
James Rosewell63426cb2015-09-18 19:53:05 +0100192/* Insert the data associated with the sample into the cache as a fresh item.
193 */
ben@51degrees.com82a9d762016-01-08 13:42:41 +0000194static void _51d_insert_cache_entry(struct sample *smp, struct lru64 *lru, void* domain)
James Rosewell63426cb2015-09-18 19:53:05 +0100195{
Willy Tarreau83061a82018-07-13 11:56:34 +0200196 struct buffer *cache_entry = _51d_malloc(sizeof(*cache_entry));
James Rosewell63426cb2015-09-18 19:53:05 +0100197
198 if (!cache_entry)
199 return;
200
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200201 cache_entry->area = _51d_malloc(smp->data.u.str.data + 1);
202 if (!cache_entry->area) {
ben@51degrees.comc9dfa242016-01-08 13:47:46 +0000203 free(cache_entry);
James Rosewell63426cb2015-09-18 19:53:05 +0100204 return;
ben@51degrees.comc9dfa242016-01-08 13:47:46 +0000205 }
James Rosewell63426cb2015-09-18 19:53:05 +0100206
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200207 memcpy(cache_entry->area, smp->data.u.str.area, smp->data.u.str.data);
208 cache_entry->area[smp->data.u.str.data] = 0;
209 cache_entry->data = smp->data.u.str.data;
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000210 HA_SPIN_LOCK(OTHER_LOCK, &_51d_lru_lock);
ben@51degrees.comc9dfa242016-01-08 13:47:46 +0000211 lru64_commit(lru, cache_entry, domain, 0, _51d_lru_free);
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000212 HA_SPIN_UNLOCK(OTHER_LOCK, &_51d_lru_lock);
James Rosewell63426cb2015-09-18 19:53:05 +0100213}
214
215/* Retrieves the data from the cache and sets the sample data to this string.
216 */
217static void _51d_retrieve_cache_entry(struct sample *smp, struct lru64 *lru)
218{
Willy Tarreau83061a82018-07-13 11:56:34 +0200219 struct buffer *cache_entry = lru->data;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200220 smp->data.u.str.area = cache_entry->area;
221 smp->data.u.str.data = cache_entry->data;
James Rosewell63426cb2015-09-18 19:53:05 +0100222}
223#endif
224
225#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
James Rosewella28bbd52015-09-18 18:28:52 +0100226/* Sets the important HTTP headers ahead of the detection
227 */
228static void _51d_set_headers(struct sample *smp, fiftyoneDegreesWorkset *ws)
Dragan Dosen93b38d92015-06-29 16:43:25 +0200229{
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200230 struct channel *chn;
231 struct htx *htx;
232 struct http_hdr_ctx ctx;
233 struct ist name;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200234 int i;
James Rosewella28bbd52015-09-18 18:28:52 +0100235
James Rosewella28bbd52015-09-18 18:28:52 +0100236 ws->importantHeadersCount = 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200237 chn = (smp->strm ? &smp->strm->req : NULL);
Ben51Degrees31a51f22019-06-12 15:19:12 +0100238
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200239 // No need to null check as this has already been carried out in the
240 // calling method
241 htx = smp_prefetch_htx(smp, chn, 1);
Ben51Degrees31a51f22019-06-12 15:19:12 +0100242
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200243 for (i = 0; i < global_51degrees.header_count; i++) {
244 name.ptr = (global_51degrees.header_names + i)->area;
245 name.len = (global_51degrees.header_names + i)->data;
246 ctx.blk = NULL;
Ben51Degrees31a51f22019-06-12 15:19:12 +0100247
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200248 if (http_find_header(htx, name, &ctx, 1)) {
249 ws->importantHeaders[ws->importantHeadersCount].header = ws->dataSet->httpHeaders + i;
250 ws->importantHeaders[ws->importantHeadersCount].headerValue = ctx.value.ptr;
251 ws->importantHeaders[ws->importantHeadersCount].headerValueLength = ctx.value.len;
252 ws->importantHeadersCount++;
James Rosewella28bbd52015-09-18 18:28:52 +0100253 }
254 }
255}
Dragan Dosen93b38d92015-06-29 16:43:25 +0200256#endif
James Rosewella28bbd52015-09-18 18:28:52 +0100257
Dragan Dosen93b38d92015-06-29 16:43:25 +0200258#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000259static void _51d_init_device_offsets(fiftyoneDegreesDeviceOffsets *offsets) {
260 int i;
261 for (i = 0; i < global_51degrees.data_set.uniqueHttpHeaders.count; i++) {
262 offsets->firstOffset[i].userAgent = NULL;
263 }
264}
265
266static void _51d_set_device_offsets(struct sample *smp, fiftyoneDegreesDeviceOffsets *offsets)
James Rosewella28bbd52015-09-18 18:28:52 +0100267{
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200268 struct channel *chn;
269 struct htx *htx;
270 struct http_hdr_ctx ctx;
271 struct ist name;
Ben51Degrees31a51f22019-06-12 15:19:12 +0100272 int i;
Dragan Dosen105c8e62015-06-29 16:43:26 +0200273
James Rosewella28bbd52015-09-18 18:28:52 +0100274 offsets->size = 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200275 chn = (smp->strm ? &smp->strm->req : NULL);
Ben51Degrees31a51f22019-06-12 15:19:12 +0100276
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200277 // No need to null check as this has already been carried out in the
278 // calling method
279 htx = smp_prefetch_htx(smp, chn, 1);
Ben51Degrees31a51f22019-06-12 15:19:12 +0100280
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200281 for (i = 0; i < global_51degrees.header_count; i++) {
282 name.ptr = (global_51degrees.header_names + i)->area;
283 name.len = (global_51degrees.header_names + i)->data;
284 ctx.blk = NULL;
Ben51Degrees31a51f22019-06-12 15:19:12 +0100285
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200286 if (http_find_header(htx, name, &ctx, 1)) {
287 (offsets->firstOffset + offsets->size)->httpHeaderOffset = *(global_51degrees.header_offsets + i);
288 (offsets->firstOffset + offsets->size)->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global_51degrees.data_set, ctx.value.ptr);
289 offsets->size++;
Ben51Degrees31a51f22019-06-12 15:19:12 +0100290 }
Ben51Degrees31a51f22019-06-12 15:19:12 +0100291 }
Ben51Degrees31a51f22019-06-12 15:19:12 +0100292
James Rosewella28bbd52015-09-18 18:28:52 +0100293}
294#endif
Dragan Dosen93b38d92015-06-29 16:43:25 +0200295
296#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
James Rosewella28bbd52015-09-18 18:28:52 +0100297/* Provides a hash code for the important HTTP headers.
298 */
299unsigned long long _51d_req_hash(const struct arg *args, fiftyoneDegreesWorkset* ws)
300{
301 unsigned long long seed = _51d_lru_seed ^ (long)args;
302 unsigned long long hash = 0;
303 int i;
304 for(i = 0; i < ws->importantHeadersCount; i++) {
305 hash ^= ws->importantHeaders[i].header->headerNameOffset;
306 hash ^= XXH64(ws->importantHeaders[i].headerValue,
307 ws->importantHeaders[i].headerValueLength,
308 seed);
309 }
310 return hash;
311}
Dragan Dosen93b38d92015-06-29 16:43:25 +0200312#endif
313
Dragan Dosen93b38d92015-06-29 16:43:25 +0200314#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
James Rosewella28bbd52015-09-18 18:28:52 +0100315static void _51d_process_match(const struct arg *args, struct sample *smp, fiftyoneDegreesWorkset* ws)
316{
317 char *methodName;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200318#endif
319#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000320static void _51d_process_match(const struct arg *args, struct sample *smp, fiftyoneDegreesDeviceOffsets *offsets)
James Rosewella28bbd52015-09-18 18:28:52 +0100321{
322 char valuesBuffer[1024];
Willy Tarreaub7a67142016-12-21 21:18:44 +0100323 const char **requiredProperties = fiftyoneDegreesGetRequiredPropertiesNames(&global_51degrees.data_set);
324 int requiredPropertiesCount = fiftyoneDegreesGetRequiredPropertiesCount(&global_51degrees.data_set);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200325#endif
326
James Rosewella28bbd52015-09-18 18:28:52 +0100327 char no_data[] = "NoData"; /* response when no data could be found */
Willy Tarreau83061a82018-07-13 11:56:34 +0200328 struct buffer *temp = get_trash_chunk();
James Rosewella28bbd52015-09-18 18:28:52 +0100329 int j, i = 0, found;
330 const char* property_name;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200331
332 /* Loop through property names passed to the filter and fetch them from the dataset. */
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200333 while (args[i].data.str.area) {
Dragan Dosen93b38d92015-06-29 16:43:25 +0200334 /* Try to find request property in dataset. */
Dragan Dosen93b38d92015-06-29 16:43:25 +0200335 found = 0;
James Rosewella28bbd52015-09-18 18:28:52 +0100336#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200337 if (strcmp("Method", args[i].data.str.area) == 0) {
James Rosewella28bbd52015-09-18 18:28:52 +0100338 switch(ws->method) {
339 case EXACT: methodName = "Exact"; break;
340 case NUMERIC: methodName = "Numeric"; break;
341 case NEAREST: methodName = "Nearest"; break;
342 case CLOSEST: methodName = "Closest"; break;
343 default:
344 case NONE: methodName = "None"; break;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200345 }
James Rosewella28bbd52015-09-18 18:28:52 +0100346 chunk_appendf(temp, "%s", methodName);
347 found = 1;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200348 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200349 else if (strcmp("Difference", args[i].data.str.area) == 0) {
James Rosewella28bbd52015-09-18 18:28:52 +0100350 chunk_appendf(temp, "%d", ws->difference);
351 found = 1;
352 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200353 else if (strcmp("Rank", args[i].data.str.area) == 0) {
James Rosewella28bbd52015-09-18 18:28:52 +0100354 chunk_appendf(temp, "%d", fiftyoneDegreesGetSignatureRank(ws));
355 found = 1;
356 }
357 else {
358 for (j = 0; j < ws->dataSet->requiredPropertyCount; j++) {
359 property_name = fiftyoneDegreesGetPropertyName(ws->dataSet, ws->dataSet->requiredProperties[j]);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200360 if (strcmp(property_name, args[i].data.str.area) == 0) {
James Rosewella28bbd52015-09-18 18:28:52 +0100361 found = 1;
362 fiftyoneDegreesSetValues(ws, j);
363 chunk_appendf(temp, "%s", fiftyoneDegreesGetValueName(ws->dataSet, *ws->values));
364 break;
365 }
366 }
Dragan Dosen93b38d92015-06-29 16:43:25 +0200367 }
368#endif
369#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
James Rosewella28bbd52015-09-18 18:28:52 +0100370 found = 0;
371 for (j = 0; j < requiredPropertiesCount; j++) {
372 property_name = requiredProperties[j];
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200373 if (strcmp(property_name, args[i].data.str.area) == 0 &&
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000374 fiftyoneDegreesGetValueFromOffsets(&global_51degrees.data_set, offsets, j, valuesBuffer, 1024) > 0) {
James Rosewella28bbd52015-09-18 18:28:52 +0100375 found = 1;
376 chunk_appendf(temp, "%s", valuesBuffer);
377 break;
378 }
Dragan Dosen93b38d92015-06-29 16:43:25 +0200379 }
James Rosewella28bbd52015-09-18 18:28:52 +0100380#endif
ben@51degrees.comd3842522016-01-08 13:52:32 +0000381 if (!found)
Dragan Dosen93b38d92015-06-29 16:43:25 +0200382 chunk_appendf(temp, "%s", no_data);
ben@51degrees.comd3842522016-01-08 13:52:32 +0000383
Dragan Dosen93b38d92015-06-29 16:43:25 +0200384 /* Add separator. */
Willy Tarreaub7a67142016-12-21 21:18:44 +0100385 chunk_appendf(temp, "%c", global_51degrees.property_separator);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200386 ++i;
387 }
388
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200389 if (temp->data) {
390 --temp->data;
391 temp->area[temp->data] = '\0';
Dragan Dosen93b38d92015-06-29 16:43:25 +0200392 }
393
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200394 smp->data.u.str.area = temp->area;
395 smp->data.u.str.data = temp->data;
James Rosewella28bbd52015-09-18 18:28:52 +0100396}
397
398static int _51d_fetch(const struct arg *args, struct sample *smp, const char *kw, void *private)
399{
400#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
401 fiftyoneDegreesWorkset* ws; /* workset for detection */
402 struct lru64 *lru = NULL;
403#endif
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000404#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
405 fiftyoneDegreesDeviceOffsets *offsets; /* Offsets for detection */
Ben51Degrees31a51f22019-06-12 15:19:12 +0100406
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000407#endif
Ben51Degrees31a51f22019-06-12 15:19:12 +0100408 struct channel *chn;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200409 struct htx *htx;
410
Ben51Degrees31a51f22019-06-12 15:19:12 +0100411 chn = (smp->strm ? &smp->strm->req : NULL);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200412 htx = smp_prefetch_htx(smp, chn, 1);
413 if (!htx)
414 return 0;
James Rosewella28bbd52015-09-18 18:28:52 +0100415
Ben51Degrees31a51f22019-06-12 15:19:12 +0100416 /*
James Rosewella28bbd52015-09-18 18:28:52 +0100417 * Data type has to be reset to ensure the string output is processed
418 * correctly.
419 */
James Rosewella28bbd52015-09-18 18:28:52 +0100420 smp->data.type = SMP_T_STR;
421
ben@51degrees.com82a9d762016-01-08 13:42:41 +0000422 /* Flags the sample to show it uses constant memory*/
423 smp->flags |= SMP_F_CONST;
424
James Rosewella28bbd52015-09-18 18:28:52 +0100425#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
426
427 /* Get only the headers needed for device detection so they can be used
428 * with the cache to return previous results. Pattern is slower than
429 * Trie so caching will help improve performance.
430 */
431
432 /* Get a workset from the pool which will later contain detection results. */
Willy Tarreaub7a67142016-12-21 21:18:44 +0100433 ws = fiftyoneDegreesWorksetPoolGet(global_51degrees.pool);
James Rosewella28bbd52015-09-18 18:28:52 +0100434 if (!ws)
435 return 0;
436
437 /* Set the important HTTP headers for this request in the workset. */
438 _51d_set_headers(smp, ws);
439
440 /* Check the cache to see if there's results for these headers already. */
441 if (_51d_lru_tree) {
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000442 HA_SPIN_LOCK(OTHER_LOCK, &_51d_lru_lock);
443
James Rosewella28bbd52015-09-18 18:28:52 +0100444 lru = lru64_get(_51d_req_hash(args, ws),
ben@51degrees.com82a9d762016-01-08 13:42:41 +0000445 _51d_lru_tree, (void*)args, 0);
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000446
James Rosewella28bbd52015-09-18 18:28:52 +0100447 if (lru && lru->domain) {
Willy Tarreaub7a67142016-12-21 21:18:44 +0100448 fiftyoneDegreesWorksetPoolRelease(global_51degrees.pool, ws);
James Rosewell63426cb2015-09-18 19:53:05 +0100449 _51d_retrieve_cache_entry(smp, lru);
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000450 HA_SPIN_UNLOCK(OTHER_LOCK, &_51d_lru_lock);
James Rosewella28bbd52015-09-18 18:28:52 +0100451 return 1;
452 }
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000453 HA_SPIN_UNLOCK(OTHER_LOCK, &_51d_lru_lock);
James Rosewella28bbd52015-09-18 18:28:52 +0100454 }
455
456 fiftyoneDegreesMatchForHttpHeaders(ws);
457
458 _51d_process_match(args, smp, ws);
459
460#endif
461
462#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000463#ifndef FIFTYONEDEGREES_NO_THREADING
464 offsets = fiftyoneDegreesCreateDeviceOffsets(&global_51degrees.data_set);
465 _51d_init_device_offsets(offsets);
466#else
467 offsets = &global_51degrees.device_offsets;
468#endif
James Rosewella28bbd52015-09-18 18:28:52 +0100469
470 /* Trie is very fast so all the headers can be passed in and the result
471 * returned faster than the hashing algorithm process.
472 */
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000473 _51d_set_device_offsets(smp, offsets);
474 _51d_process_match(args, smp, offsets);
James Rosewella28bbd52015-09-18 18:28:52 +0100475
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000476#ifndef FIFTYONEDEGREES_NO_THREADING
477 fiftyoneDegreesFreeDeviceOffsets(offsets);
James Rosewella28bbd52015-09-18 18:28:52 +0100478#endif
479
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000480#endif
481
James Rosewella28bbd52015-09-18 18:28:52 +0100482#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Willy Tarreaub7a67142016-12-21 21:18:44 +0100483 fiftyoneDegreesWorksetPoolRelease(global_51degrees.pool, ws);
ben@51degrees.comd3842522016-01-08 13:52:32 +0000484 if (lru)
ben@51degrees.com82a9d762016-01-08 13:42:41 +0000485 _51d_insert_cache_entry(smp, lru, (void*)args);
James Rosewella28bbd52015-09-18 18:28:52 +0100486#endif
487
488 return 1;
489}
Dragan Dosen93b38d92015-06-29 16:43:25 +0200490
James Rosewella28bbd52015-09-18 18:28:52 +0100491static int _51d_conv(const struct arg *args, struct sample *smp, void *private)
492{
Dragan Dosen93b38d92015-06-29 16:43:25 +0200493#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
James Rosewella28bbd52015-09-18 18:28:52 +0100494 fiftyoneDegreesWorkset* ws; /* workset for detection */
495 struct lru64 *lru = NULL;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200496#endif
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000497#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
498 fiftyoneDegreesDeviceOffsets *offsets; /* Offsets for detection */
499#endif
ben@51degrees.com82a9d762016-01-08 13:42:41 +0000500 /* Flags the sample to show it uses constant memory*/
501 smp->flags |= SMP_F_CONST;
502
James Rosewella28bbd52015-09-18 18:28:52 +0100503#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
504
505 /* Look in the list. */
506 if (_51d_lru_tree) {
507 unsigned long long seed = _51d_lru_seed ^ (long)args;
508
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000509 HA_SPIN_LOCK(OTHER_LOCK, &_51d_lru_lock);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200510 lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
ben@51degrees.com82a9d762016-01-08 13:42:41 +0000511 _51d_lru_tree, (void*)args, 0);
James Rosewella28bbd52015-09-18 18:28:52 +0100512 if (lru && lru->domain) {
James Rosewell63426cb2015-09-18 19:53:05 +0100513 _51d_retrieve_cache_entry(smp, lru);
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000514 HA_SPIN_UNLOCK(OTHER_LOCK, &_51d_lru_lock);
James Rosewella28bbd52015-09-18 18:28:52 +0100515 return 1;
516 }
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000517 HA_SPIN_UNLOCK(OTHER_LOCK, &_51d_lru_lock);
James Rosewella28bbd52015-09-18 18:28:52 +0100518 }
519
520 /* Create workset. This will later contain detection results. */
Willy Tarreaub7a67142016-12-21 21:18:44 +0100521 ws = fiftyoneDegreesWorksetPoolGet(global_51degrees.pool);
James Rosewella28bbd52015-09-18 18:28:52 +0100522 if (!ws)
523 return 0;
524#endif
525
526 /* Duplicate the data and remove the "const" flag before device detection. */
527 if (!smp_dup(smp))
528 return 0;
529
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200530 smp->data.u.str.area[smp->data.u.str.data] = '\0';
James Rosewella28bbd52015-09-18 18:28:52 +0100531
532 /* Perform detection. */
533#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200534 fiftyoneDegreesMatch(ws, smp->data.u.str.area);
James Rosewella28bbd52015-09-18 18:28:52 +0100535 _51d_process_match(args, smp, ws);
536#endif
537#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000538#ifndef FIFTYONEDEGREES_NO_THREADING
539 offsets = fiftyoneDegreesCreateDeviceOffsets(&global_51degrees.data_set);
540 _51d_init_device_offsets(offsets);
541#else
542 offsets = &global_51degrees.device_offsets;
543#endif
544
545 offsets->firstOffset->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global_51degrees.data_set,
546 smp->data.u.str.area);
547 offsets->size = 1;
548 _51d_process_match(args, smp, offsets);
James Rosewella28bbd52015-09-18 18:28:52 +0100549#endif
550
551#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Willy Tarreaub7a67142016-12-21 21:18:44 +0100552 fiftyoneDegreesWorksetPoolRelease(global_51degrees.pool, ws);
ben@51degrees.comd3842522016-01-08 13:52:32 +0000553 if (lru)
ben@51degrees.com82a9d762016-01-08 13:42:41 +0000554 _51d_insert_cache_entry(smp, lru, (void*)args);
James Rosewella28bbd52015-09-18 18:28:52 +0100555#endif
Dragan Dosen105c8e62015-06-29 16:43:26 +0200556
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000557#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
558#ifndef FIFTYONEDEGREES_NO_THREADING
559 fiftyoneDegreesFreeDeviceOffsets(offsets);
560#endif
561#endif
562
Dragan Dosen93b38d92015-06-29 16:43:25 +0200563 return 1;
564}
565
James Rosewella28bbd52015-09-18 18:28:52 +0100566#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
567void _51d_init_http_headers()
568{
569 int index = 0;
570 const fiftyoneDegreesAsciiString *headerName;
Willy Tarreaub7a67142016-12-21 21:18:44 +0100571 fiftyoneDegreesDataSet *ds = &global_51degrees.data_set;
572 global_51degrees.header_count = ds->httpHeadersCount;
Willy Tarreau83061a82018-07-13 11:56:34 +0200573 global_51degrees.header_names = malloc(global_51degrees.header_count * sizeof(struct buffer));
Willy Tarreaub7a67142016-12-21 21:18:44 +0100574 for (index = 0; index < global_51degrees.header_count; index++) {
James Rosewella28bbd52015-09-18 18:28:52 +0100575 headerName = fiftyoneDegreesGetString(ds, ds->httpHeaders[index].headerNameOffset);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200576 (global_51degrees.header_names + index)->area = (char*)&headerName->firstByte;
577 (global_51degrees.header_names + index)->data = headerName->length - 1;
578 (global_51degrees.header_names + index)->size = (global_51degrees.header_names + index)->data;
James Rosewella28bbd52015-09-18 18:28:52 +0100579 }
580}
581#endif
582
583#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
584void _51d_init_http_headers()
585{
586 int index = 0;
Willy Tarreaub7a67142016-12-21 21:18:44 +0100587 fiftyoneDegreesDataSet *ds = &global_51degrees.data_set;
588 global_51degrees.header_count = fiftyoneDegreesGetHttpHeaderCount(ds);
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000589#ifdef FIFTYONEDEGREES_NO_THREADING
Willy Tarreaub7a67142016-12-21 21:18:44 +0100590 global_51degrees.device_offsets.firstOffset = malloc(
591 global_51degrees.header_count * sizeof(fiftyoneDegreesDeviceOffset));
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000592 _51d_init_device_offsets(&global_51degrees.device_offsets);
593#endif
Willy Tarreau83061a82018-07-13 11:56:34 +0200594 global_51degrees.header_names = malloc(global_51degrees.header_count * sizeof(struct buffer));
Willy Tarreaub7a67142016-12-21 21:18:44 +0100595 global_51degrees.header_offsets = malloc(global_51degrees.header_count * sizeof(int32_t));
596 for (index = 0; index < global_51degrees.header_count; index++) {
597 global_51degrees.header_offsets[index] = fiftyoneDegreesGetHttpHeaderNameOffset(ds, index);
Ben51Degreese0f6a2a2019-02-05 13:23:06 +0000598 global_51degrees.header_names[index].area = (char*)fiftyoneDegreesGetHttpHeaderNamePointer(ds, index);
599 global_51degrees.header_names[index].data = strlen(global_51degrees.header_names[index].area);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200600 global_51degrees.header_names[index].size = global_51degrees.header_names->data;
James Rosewella28bbd52015-09-18 18:28:52 +0100601 }
602}
603#endif
604
Willy Tarreau9f3f2542016-12-21 20:30:05 +0100605/*
606 * module init / deinit functions. Returns 0 if OK, or a combination of ERR_*.
607 */
608static int init_51degrees(void)
Dragan Dosen93b38d92015-06-29 16:43:25 +0200609{
610 int i = 0;
Willy Tarreau83061a82018-07-13 11:56:34 +0200611 struct buffer *temp;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200612 struct _51d_property_names *name;
613 char **_51d_property_list = NULL;
614 fiftyoneDegreesDataSetInitStatus _51d_dataset_status = DATA_SET_INIT_STATUS_NOT_SET;
615
Willy Tarreaub7a67142016-12-21 21:18:44 +0100616 if (!global_51degrees.data_file_path)
Willy Tarreau9f3f2542016-12-21 20:30:05 +0100617 return 0;
Dragan Dosen9373fc52015-08-07 16:41:23 +0200618
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000619 if (global.nbthread < 1) {
620 ha_alert("51Degrees: The thread count cannot be zero or negative.\n");
Christopher Faulete8ca4342017-10-25 17:23:02 +0200621 return (ERR_FATAL | ERR_ALERT);
622 }
623
Willy Tarreaub7a67142016-12-21 21:18:44 +0100624 if (!LIST_ISEMPTY(&global_51degrees.property_names)) {
Dragan Dosen93b38d92015-06-29 16:43:25 +0200625 i = 0;
Willy Tarreaub7a67142016-12-21 21:18:44 +0100626 list_for_each_entry(name, &global_51degrees.property_names, list)
Dragan Dosen93b38d92015-06-29 16:43:25 +0200627 ++i;
628 _51d_property_list = calloc(i, sizeof(char *));
629
630 i = 0;
Willy Tarreaub7a67142016-12-21 21:18:44 +0100631 list_for_each_entry(name, &global_51degrees.property_names, list)
Dragan Dosen93b38d92015-06-29 16:43:25 +0200632 _51d_property_list[i++] = name->name;
633 }
634
Willy Tarreaub7a67142016-12-21 21:18:44 +0100635 _51d_dataset_status = fiftyoneDegreesInitWithPropertyArray(global_51degrees.data_file_path, &global_51degrees.data_set, (const char**)_51d_property_list, i);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200636
637 temp = get_trash_chunk();
638 chunk_reset(temp);
639
640 switch (_51d_dataset_status) {
641 case DATA_SET_INIT_STATUS_SUCCESS:
James Rosewella28bbd52015-09-18 18:28:52 +0100642#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000643 global_51degrees.pool = fiftyoneDegreesWorksetPoolCreate(&global_51degrees.data_set, NULL, global.nbthread);
James Rosewella28bbd52015-09-18 18:28:52 +0100644#endif
645 _51d_init_http_headers();
Dragan Dosen93b38d92015-06-29 16:43:25 +0200646 break;
647 case DATA_SET_INIT_STATUS_INSUFFICIENT_MEMORY:
648 chunk_printf(temp, "Insufficient memory.");
649 break;
650 case DATA_SET_INIT_STATUS_CORRUPT_DATA:
651#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
652 chunk_printf(temp, "Corrupt data file. Check that the data file provided is uncompressed and Pattern data format.");
653#endif
654#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
655 chunk_printf(temp, "Corrupt data file. Check that the data file provided is uncompressed and Trie data format.");
656#endif
657 break;
658 case DATA_SET_INIT_STATUS_INCORRECT_VERSION:
659#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
660 chunk_printf(temp, "Incorrect version. Check that the data file provided is uncompressed and Pattern data format.");
661#endif
662#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
663 chunk_printf(temp, "Incorrect version. Check that the data file provided is uncompressed and Trie data format.");
664#endif
665 break;
666 case DATA_SET_INIT_STATUS_FILE_NOT_FOUND:
667 chunk_printf(temp, "File not found.");
668 break;
ben51degrees1f077eb2016-07-06 12:07:21 +0100669 case DATA_SET_INIT_STATUS_NULL_POINTER:
670 chunk_printf(temp, "Null pointer to the existing dataset or memory location.");
671 break;
672 case DATA_SET_INIT_STATUS_POINTER_OUT_OF_BOUNDS:
673 chunk_printf(temp, "Allocated continuous memory containing 51Degrees data file appears to be smaller than expected. Most likely"
674 " because the data file was not fully loaded into the allocated memory.");
675 break;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200676 case DATA_SET_INIT_STATUS_NOT_SET:
677 chunk_printf(temp, "Data set not initialised.");
678 break;
Dragan Dosen483b93c2017-09-27 12:46:44 +0200679 default:
680 chunk_printf(temp, "Other error.");
681 break;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200682 }
683 if (_51d_dataset_status != DATA_SET_INIT_STATUS_SUCCESS) {
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200684 if (temp->data)
685 ha_alert("51Degrees Setup - Error reading 51Degrees data file. %s\n",
686 temp->area);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200687 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100688 ha_alert("51Degrees Setup - Error reading 51Degrees data file.\n");
Willy Tarreau9f3f2542016-12-21 20:30:05 +0100689 return ERR_ALERT | ERR_FATAL;
Dragan Dosen93b38d92015-06-29 16:43:25 +0200690 }
691 free(_51d_property_list);
692
James Rosewella28bbd52015-09-18 18:28:52 +0100693#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Dragan Dosen105c8e62015-06-29 16:43:26 +0200694 _51d_lru_seed = random();
Willy Tarreaub7a67142016-12-21 21:18:44 +0100695 if (global_51degrees.cache_size) {
696 _51d_lru_tree = lru64_new(global_51degrees.cache_size);
James Rosewella28bbd52015-09-18 18:28:52 +0100697 }
698#endif
Dragan Dosen105c8e62015-06-29 16:43:26 +0200699
Dragan Dosen93b38d92015-06-29 16:43:25 +0200700 return 0;
701}
702
Willy Tarreau7ac4c202016-12-21 20:59:01 +0100703static void deinit_51degrees(void)
Dragan Dosen93b38d92015-06-29 16:43:25 +0200704{
705 struct _51d_property_names *_51d_prop_name, *_51d_prop_nameb;
706
Willy Tarreaub7a67142016-12-21 21:18:44 +0100707 free(global_51degrees.header_names);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200708#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Dragan Dosenbc6218e2019-03-07 15:24:23 +0100709 if (global_51degrees.pool)
710 fiftyoneDegreesWorksetPoolFree(global_51degrees.pool);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200711#endif
712#ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000713#ifdef FIFTYONEDEGREES_NO_THREADING
Willy Tarreaub7a67142016-12-21 21:18:44 +0100714 free(global_51degrees.device_offsets.firstOffset);
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000715#endif
Willy Tarreaub7a67142016-12-21 21:18:44 +0100716 free(global_51degrees.header_offsets);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200717#endif
Willy Tarreaub7a67142016-12-21 21:18:44 +0100718 fiftyoneDegreesDataSetFree(&global_51degrees.data_set);
Dragan Dosen93b38d92015-06-29 16:43:25 +0200719
Willy Tarreaub7a67142016-12-21 21:18:44 +0100720 free(global_51degrees.data_file_path); global_51degrees.data_file_path = NULL;
721 list_for_each_entry_safe(_51d_prop_name, _51d_prop_nameb, &global_51degrees.property_names, list) {
Dragan Dosen93b38d92015-06-29 16:43:25 +0200722 LIST_DEL(&_51d_prop_name->list);
723 free(_51d_prop_name);
724 }
Dragan Dosen105c8e62015-06-29 16:43:26 +0200725
James Rosewella28bbd52015-09-18 18:28:52 +0100726#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
Dragan Dosen105c8e62015-06-29 16:43:26 +0200727 while (lru64_destroy(_51d_lru_tree));
James Rosewella28bbd52015-09-18 18:28:52 +0100728#endif
Dragan Dosen93b38d92015-06-29 16:43:25 +0200729}
730
731static struct cfg_kw_list _51dcfg_kws = {{ }, {
732 { CFG_GLOBAL, "51degrees-data-file", _51d_data_file },
733 { CFG_GLOBAL, "51degrees-property-name-list", _51d_property_name_list },
734 { CFG_GLOBAL, "51degrees-property-separator", _51d_property_separator },
Dragan Dosen105c8e62015-06-29 16:43:26 +0200735 { CFG_GLOBAL, "51degrees-cache-size", _51d_cache_size },
Dragan Dosen93b38d92015-06-29 16:43:25 +0200736 { 0, NULL, NULL },
737}};
738
Willy Tarreau0108d902018-11-25 19:14:37 +0100739INITCALL1(STG_REGISTER, cfg_register_keywords, &_51dcfg_kws);
740
Dragan Dosen93b38d92015-06-29 16:43:25 +0200741/* Note: must not be declared <const> as its list will be overwritten */
James Rosewella28bbd52015-09-18 18:28:52 +0100742static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
743 { "51d.all", _51d_fetch, ARG5(1,STR,STR,STR,STR,STR), _51d_fetch_check, SMP_T_STR, SMP_USE_HRQHV },
744 { NULL, NULL, 0, 0, 0 },
745}};
746
Willy Tarreau0108d902018-11-25 19:14:37 +0100747INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords);
748
James Rosewella28bbd52015-09-18 18:28:52 +0100749/* Note: must not be declared <const> as its list will be overwritten */
Dragan Dosen93b38d92015-06-29 16:43:25 +0200750static struct sample_conv_kw_list conv_kws = {ILH, {
James Rosewella28bbd52015-09-18 18:28:52 +0100751 { "51d.single", _51d_conv, ARG5(1,STR,STR,STR,STR,STR), _51d_conv_check, SMP_T_STR, SMP_T_STR },
Dragan Dosen93b38d92015-06-29 16:43:25 +0200752 { NULL, NULL, 0, 0, 0 },
753}};
754
Willy Tarreau0108d902018-11-25 19:14:37 +0100755INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
756
Willy Tarreau172f5ce2018-11-26 11:21:50 +0100757REGISTER_POST_CHECK(init_51degrees);
758REGISTER_POST_DEINIT(deinit_51degrees);
Ben51Degreesf4a82fb2019-06-13 16:51:59 +0100759
760#if defined(FIFTYONEDEGREES_H_PATTERN_INCLUDED)
761#ifndef FIFTYONEDEGREES_DUMMY_LIB
762 REGISTER_BUILD_OPTS("Built with 51Degrees Pattern support.");
763#else
764 REGISTER_BUILD_OPTS("Built with 51Degrees Pattern support (dummy library).");
765#endif
766#elif defined(FIFTYONEDEGREES_H_TRIE_INCLUDED)
767#ifndef FIFTYONEDEGREES_DUMMY_LIB
768 REGISTER_BUILD_OPTS("Built with 51Degrees Trie support.");
769#else
770 REGISTER_BUILD_OPTS("Built with 51Degrees Trie support (dummy library).");
771#endif
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200772#endif