blob: b6fce4df84b333b5e04854dd3cc5648635c69275 [file] [log] [blame]
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +01001/*
2 * MAP management functions.
3 *
4 * Copyright 2000-2013 Willy Tarreau <w@1wt.eu>
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 <limits.h>
14#include <stdio.h>
15
16#include <common/standard.h>
17
William Lallemandad8be612016-11-18 19:26:17 +010018#include <types/applet.h>
19#include <types/cli.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010020#include <types/global.h>
21#include <types/map.h>
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010022#include <types/pattern.h>
William Lallemandad8be612016-11-18 19:26:17 +010023#include <types/stats.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010024
William Lallemandad8be612016-11-18 19:26:17 +010025#include <proto/applet.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010026#include <proto/arg.h>
William Lallemandad8be612016-11-18 19:26:17 +010027#include <proto/cli.h>
Thierry FOURNIERb0c0a0f2013-12-10 15:05:34 +010028#include <proto/map.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010029#include <proto/pattern.h>
William Lallemandad8be612016-11-18 19:26:17 +010030#include <proto/stream_interface.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010031#include <proto/sample.h>
32
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020033/* Parse an IPv4 or IPv6 address and store it into the sample.
34 * The output type is IPv4 or IPv6.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010035 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020036int map_parse_ip(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010037{
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020038 int len = strlen(text);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010039
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020040 if (buf2ip(text, len, &data->u.ipv4)) {
41 data->type = SMP_T_IPV4;
42 return 1;
43 }
44 if (buf2ip6(text, len, &data->u.ipv6)) {
45 data->type = SMP_T_IPV6;
46 return 1;
47 }
48 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010049}
50
51/* Parse a string and store a pointer to it into the sample. The original
52 * string must be left in memory because we return a direct memory reference.
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +010053 * The output type is SMP_T_STR. There is no risk that the data will be
54 * overwritten because sample_conv_map() makes a const sample with this
55 * output.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010056 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020057int map_parse_str(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010058{
Thierry FOURNIER136f9d32015-08-19 09:07:19 +020059 data->u.str.str = (char *)text;
60 data->u.str.len = strlen(text);
61 data->u.str.size = data->u.str.len + 1;
Thierry FOURNIER503bb092015-08-19 08:35:43 +020062 data->type = SMP_T_STR;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010063 return 1;
64}
65
66/* Parse an integer and convert it to a sample. The output type is SINT if the
67 * number is negative, or UINT if it is positive or null. The function returns
68 * zero (error) if the number is too large.
69 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020070int map_parse_int(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010071{
Thierry FOURNIER503bb092015-08-19 08:35:43 +020072 data->type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +020073 data->u.sint = read_int64(&text, text + strlen(text));
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020074 if (*text != '\0')
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010075 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010076 return 1;
77}
78
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010079/* This crete and initialize map descriptor.
80 * Return NULL if out of memory error
81 */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010082static struct map_descriptor *map_create_descriptor(struct sample_conv *conv)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010083{
84 struct map_descriptor *desc;
85
86 desc = calloc(1, sizeof(*desc));
87 if (!desc)
88 return NULL;
89
90 desc->conv = conv;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010091
92 return desc;
93}
94
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010095/* This function load the map file according with data type declared into
96 * the "struct sample_conv".
97 *
98 * This function choose the indexation type (ebtree or list) according with
99 * the type of match needed.
100 */
Thierry FOURNIER3def3932015-04-07 11:27:54 +0200101int sample_load_map(struct arg *arg, struct sample_conv *conv,
102 const char *file, int line, char **err)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100103{
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100104 struct map_descriptor *desc;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100105
106 /* create new map descriptor */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100107 desc = map_create_descriptor(conv);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100108 if (!desc) {
109 memprintf(err, "out of memory");
110 return 0;
111 }
112
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100113 /* Initialize pattern */
114 pattern_init_head(&desc->pat);
115
116 /* This is original pattern, must free */
117 desc->do_free = 1;
118
119 /* Set the match method. */
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100120 desc->pat.match = pat_match_fcts[(long)conv->private];
121 desc->pat.parse = pat_parse_fcts[(long)conv->private];
122 desc->pat.index = pat_index_fcts[(long)conv->private];
123 desc->pat.delete = pat_delete_fcts[(long)conv->private];
124 desc->pat.prune = pat_prune_fcts[(long)conv->private];
125 desc->pat.expect_type = pat_match_types[(long)conv->private];
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100126
127 /* Set the output parse method. */
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100128 switch (desc->conv->out_type) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100129 case SMP_T_STR: desc->pat.parse_smp = map_parse_str; break;
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200130 case SMP_T_SINT: desc->pat.parse_smp = map_parse_int; break;
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200131 case SMP_T_ADDR: desc->pat.parse_smp = map_parse_ip; break;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100132 default:
133 memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.",
134 conv->out_type);
Andreas Seltenreich78f35952016-03-03 20:32:23 +0100135 free(desc);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100136 return 0;
137 }
138
Thierry FOURNIER39bef452014-01-29 13:29:45 +0100139 /* Load map. */
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +0200140 if (!pattern_read_from_file(&desc->pat, PAT_REF_MAP, arg[0].data.str.str, PAT_MF_NO_DNS,
Thierry FOURNIER94580c92014-02-11 14:36:45 +0100141 1, err, file, line))
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100142 return 0;
Thierry FOURNIER0ffe78c2013-12-05 14:40:25 +0100143
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200144 /* the maps of type IP have a string as defaultvalue. This
145 * string canbe anipv4 or an ipv6, we must convert it.
146 */
147 if (desc->conv->out_type == SMP_T_ADDR) {
148 struct sample_data data;
149 if (!map_parse_ip(arg[1].data.str.str, &data)) {
150 memprintf(err, "map: cannot parse default ip <%s>.", arg[1].data.str.str);
151 return 0;
152 }
153 if (data.type == SMP_T_IPV4) {
154 arg[1].type = ARGT_IPV4;
155 arg[1].data.ipv4 = data.u.ipv4;
156 } else {
157 arg[1].type = ARGT_IPV6;
158 arg[1].data.ipv6 = data.u.ipv6;
159 }
160 }
161
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100162 /* replace the first argument by this definition */
163 arg[0].type = ARGT_MAP;
164 arg[0].data.map = desc;
165
166 return 1;
167}
168
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +0200169static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *private)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100170{
171 struct map_descriptor *desc;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100172 struct pattern *pat;
Thierry Fournier8feaa662016-02-10 22:55:20 +0100173 struct chunk *str;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100174
175 /* get config */
176 desc = arg_p[0].data.map;
177
178 /* Execute the match function. */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100179 pat = pattern_exec_match(&desc->pat, smp, 1);
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100180
181 /* Match case. */
182 if (pat) {
Thierry FOURNIER503bb092015-08-19 08:35:43 +0200183 if (pat->data) {
Thierry Fournier8feaa662016-02-10 22:55:20 +0100184 /* In the regm case, merge the sample with the input. */
185 if ((long)private == PAT_MATCH_REGM) {
186 str = get_trash_chunk();
187 str->len = exp_replace(str->str, str->size, smp->data.u.str.str,
188 pat->data->u.str.str,
189 (regmatch_t *)smp->ctx.a[0]);
190 if (str->len == -1)
191 return 0;
192 smp->data.u.str = *str;
193 return 1;
194 }
195 /* Copy sample. */
Thierry FOURNIER5cc18d42015-08-19 09:02:36 +0200196 smp->data = *pat->data;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100197 smp->flags |= SMP_F_CONST;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100198 return 1;
199 }
200
201 /* Return just int sample containing 1. */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200202 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200203 smp->data.u.sint = 1;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100204 return 1;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100205 }
206
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100207 /* If no default value avalaible, the converter fails. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100208 if (arg_p[1].type == ARGT_STOP)
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100209 return 0;
210
211 /* Return the default value. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100212 switch (desc->conv->out_type) {
213
214 case SMP_T_STR:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200215 smp->data.type = SMP_T_STR;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100216 smp->flags |= SMP_F_CONST;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200217 smp->data.u.str = arg_p[1].data.str;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100218 break;
219
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200220 case SMP_T_SINT:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200221 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200222 smp->data.u.sint = arg_p[1].data.sint;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100223 break;
224
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200225 case SMP_T_ADDR:
226 if (arg_p[1].type == ARGT_IPV4) {
227 smp->data.type = SMP_T_IPV4;
228 smp->data.u.ipv4 = arg_p[1].data.ipv4;
229 } else {
230 smp->data.type = SMP_T_IPV6;
231 smp->data.u.ipv6 = arg_p[1].data.ipv6;
232 }
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100233 break;
234 }
235
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100236 return 1;
237}
238
William Lallemandad8be612016-11-18 19:26:17 +0100239/* This function is used with map and acl management. It permits to browse
240 * each reference. The variable <getnext> must contain the current node,
241 * <end> point to the root node and the <flags> permit to filter required
242 * nodes.
243 */
244static inline
245struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end,
246 unsigned int flags)
247{
248 struct pat_ref *ref = getnext;
249
250 while (1) {
251
252 /* Get next list entry. */
253 ref = LIST_NEXT(&ref->list, struct pat_ref *, list);
254
255 /* If the entry is the last of the list, return NULL. */
256 if (&ref->list == end)
257 return NULL;
258
259 /* If the entry match the flag, return it. */
260 if (ref->flags & flags)
261 return ref;
262 }
263}
264
265static inline
266struct pat_ref *pat_ref_lookup_ref(const char *reference)
267{
268 int id;
269 char *error;
270
271 /* If the reference starts by a '#', this is numeric id. */
272 if (reference[0] == '#') {
273 /* Try to convert the numeric id. If the conversion fails, the lookup fails. */
274 id = strtol(reference + 1, &error, 10);
275 if (*error != '\0')
276 return NULL;
277
278 /* Perform the unique id lookup. */
279 return pat_ref_lookupid(id);
280 }
281
282 /* Perform the string lookup. */
283 return pat_ref_lookup(reference);
284}
285
286/* This function is used with map and acl management. It permits to browse
287 * each reference.
288 */
289static inline
290struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end)
291{
292 struct pattern_expr *expr;
293 expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list);
294 if (&expr->list == end)
295 return NULL;
296 return expr;
297}
298
299static int cli_io_handler_pat_list(struct appctx *appctx)
300{
301 struct stream_interface *si = appctx->owner;
302
303 switch (appctx->st2) {
304
305 case STAT_ST_INIT:
306 /* Init to the first entry. The list cannot be change */
307 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head,
308 struct pat_ref_elt *, list);
309 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
310 appctx->ctx.map.elt = NULL;
311 appctx->st2 = STAT_ST_LIST;
312 /* fall through */
313
314 case STAT_ST_LIST:
315 while (appctx->ctx.map.elt) {
316 chunk_reset(&trash);
317
318 /* build messages */
319 if (appctx->ctx.map.elt->sample)
320 chunk_appendf(&trash, "%p %s %s\n",
321 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern,
322 appctx->ctx.map.elt->sample);
323 else
324 chunk_appendf(&trash, "%p %s\n",
325 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern);
326
327 if (bi_putchk(si_ic(si), &trash) == -1) {
328 /* let's try again later from this stream. We add ourselves into
329 * this stream's users so that it can remove us upon termination.
330 */
331 si_applet_cant_put(si);
332 return 0;
333 }
334
335 /* get next list entry and check the end of the list */
336 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list,
337 struct pat_ref_elt *, list);
338 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
339 break;
340 }
341
342 appctx->st2 = STAT_ST_FIN;
343 /* fall through */
344
345 default:
346 appctx->st2 = STAT_ST_FIN;
347 return 1;
348 }
349}
350
351static int cli_io_handler_pats_list(struct appctx *appctx)
352{
353 struct stream_interface *si = appctx->owner;
354
355 switch (appctx->st2) {
356 case STAT_ST_INIT:
357 /* Display the column headers. If the message cannot be sent,
358 * quit the fucntion with returning 0. The function is called
359 * later and restart at the state "STAT_ST_INIT".
360 */
361 chunk_reset(&trash);
362 chunk_appendf(&trash, "# id (file) description\n");
363 if (bi_putchk(si_ic(si), &trash) == -1) {
364 si_applet_cant_put(si);
365 return 0;
366 }
367
368 /* Now, we start the browsing of the references lists.
369 * Note that the following call to LIST_ELEM return bad pointer. The only
370 * available field of this pointer is <list>. It is used with the function
371 * pat_list_get_next() for retruning the first available entry
372 */
373 appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list);
374 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
375 appctx->ctx.map.display_flags);
376 appctx->st2 = STAT_ST_LIST;
377 /* fall through */
378
379 case STAT_ST_LIST:
380 while (appctx->ctx.map.ref) {
381 chunk_reset(&trash);
382
383 /* Build messages. If the reference is used by another category than
384 * the listed categorie, display the information in the massage.
385 */
386 chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id,
387 appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "",
388 appctx->ctx.map.ref->display);
389
390 if (bi_putchk(si_ic(si), &trash) == -1) {
391 /* let's try again later from this stream. We add ourselves into
392 * this stream's users so that it can remove us upon termination.
393 */
394 si_applet_cant_put(si);
395 return 0;
396 }
397
398 /* get next list entry and check the end of the list */
399 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
400 appctx->ctx.map.display_flags);
401 }
402
403 appctx->st2 = STAT_ST_FIN;
404 /* fall through */
405
406 default:
407 appctx->st2 = STAT_ST_FIN;
408 return 1;
409 }
410 return 0;
411}
412
413static int cli_io_handler_map_lookup(struct appctx *appctx)
414{
415 struct stream_interface *si = appctx->owner;
416 struct sample sample;
417 struct pattern *pat;
418 int match_method;
419
420 switch (appctx->st2) {
421 case STAT_ST_INIT:
422 /* Init to the first entry. The list cannot be change */
423 appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list);
424 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat);
425 appctx->st2 = STAT_ST_LIST;
426 /* fall through */
427
428 case STAT_ST_LIST:
429 /* for each lookup type */
430 while (appctx->ctx.map.expr) {
431 /* initialise chunk to build new message */
432 chunk_reset(&trash);
433
434 /* execute pattern matching */
435 sample.data.type = SMP_T_STR;
436 sample.flags = SMP_F_CONST;
437 sample.data.u.str.len = appctx->ctx.map.chunk.len;
438 sample.data.u.str.str = appctx->ctx.map.chunk.str;
439 if (appctx->ctx.map.expr->pat_head->match &&
440 sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type))
441 pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1);
442 else
443 pat = NULL;
444
445 /* build return message: set type of match */
446 for (match_method=0; match_method<PAT_MATCH_NUM; match_method++)
447 if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method])
448 break;
449 if (match_method >= PAT_MATCH_NUM)
450 chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match);
451 else
452 chunk_appendf(&trash, "type=%s", pat_match_names[match_method]);
453
454 /* case sensitive */
455 if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE)
456 chunk_appendf(&trash, ", case=insensitive");
457 else
458 chunk_appendf(&trash, ", case=sensitive");
459
460 /* Display no match, and set default value */
461 if (!pat) {
462 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
463 chunk_appendf(&trash, ", found=no");
464 else
465 chunk_appendf(&trash, ", match=no");
466 }
467
468 /* Display match and match info */
469 else {
470 /* display match */
471 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
472 chunk_appendf(&trash, ", found=yes");
473 else
474 chunk_appendf(&trash, ", match=yes");
475
476 /* display index mode */
477 if (pat->sflags & PAT_SF_TREE)
478 chunk_appendf(&trash, ", idx=tree");
479 else
480 chunk_appendf(&trash, ", idx=list");
481
482 /* display pattern */
483 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
484 if (pat->ref && pat->ref->pattern)
485 chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern);
486 else
487 chunk_appendf(&trash, ", key=unknown");
488 }
489 else {
490 if (pat->ref && pat->ref->pattern)
491 chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern);
492 else
493 chunk_appendf(&trash, ", pattern=unknown");
494 }
495
496 /* display return value */
497 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
498 if (pat->data && pat->ref && pat->ref->sample)
499 chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample,
500 smp_to_type[pat->data->type]);
501 else
502 chunk_appendf(&trash, ", value=none");
503 }
504 }
505
506 chunk_appendf(&trash, "\n");
507
508 /* display response */
509 if (bi_putchk(si_ic(si), &trash) == -1) {
510 /* let's try again later from this stream. We add ourselves into
511 * this stream's users so that it can remove us upon termination.
512 */
513 si_applet_cant_put(si);
514 return 0;
515 }
516
517 /* get next entry */
518 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr,
519 &appctx->ctx.map.ref->pat);
520 }
521
522 appctx->st2 = STAT_ST_FIN;
523 /* fall through */
524
525 default:
526 appctx->st2 = STAT_ST_FIN;
527 free(appctx->ctx.map.chunk.str);
528 return 1;
529 }
530}
531
532static void cli_release_mlook(struct appctx *appctx)
533{
534 free(appctx->ctx.map.chunk.str);
535 appctx->ctx.map.chunk.str = NULL;
536}
537
538
539static int cli_parse_get_map(char **args, struct appctx *appctx, void *private)
540{
541 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
542 /* Set flags. */
543 if (args[1][0] == 'm')
544 appctx->ctx.map.display_flags = PAT_REF_MAP;
545 else
546 appctx->ctx.map.display_flags = PAT_REF_ACL;
547
548 /* No parameter. */
549 if (!*args[2] || !*args[3]) {
550 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
551 appctx->ctx.cli.msg = "Missing map identifier and/or key.\n";
552 else
553 appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100554 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100555 return 1;
556 }
557
558 /* lookup into the maps */
559 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
560 if (!appctx->ctx.map.ref) {
561 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
562 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
563 else
564 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100565 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100566 return 1;
567 }
568
569 /* copy input string. The string must be allocated because
570 * it may be used over multiple iterations. It's released
571 * at the end and upon abort anyway.
572 */
573 appctx->ctx.map.chunk.len = strlen(args[3]);
574 appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1;
575 appctx->ctx.map.chunk.str = strdup(args[3]);
576 if (!appctx->ctx.map.chunk.str) {
577 appctx->ctx.cli.msg = "Out of memory error.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100578 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100579 return 1;
580 }
581
582 return 0;
583 }
584 return 1;
585}
586
587static int cli_parse_show_map(char **args, struct appctx *appctx, void *private)
588{
589 if (strcmp(args[1], "map") == 0 ||
590 strcmp(args[1], "acl") == 0) {
591
592 /* Set ACL or MAP flags. */
593 if (args[1][0] == 'm')
594 appctx->ctx.map.display_flags = PAT_REF_MAP;
595 else
596 appctx->ctx.map.display_flags = PAT_REF_ACL;
597
598 /* no parameter: display all map available */
599 if (!*args[2]) {
William Lallemandad8be612016-11-18 19:26:17 +0100600 appctx->io_handler = cli_io_handler_pats_list;
601 return 0;
602 }
603
604 /* lookup into the refs and check the map flag */
605 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
606 if (!appctx->ctx.map.ref ||
607 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
608 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
609 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
610 else
611 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100612 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100613 return 1;
614 }
William Lallemandad8be612016-11-18 19:26:17 +0100615 appctx->io_handler = cli_io_handler_pat_list;
616 return 0;
617 }
618
619 return 0;
620}
621
622static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
623{
624 if (strcmp(args[1], "map") == 0) {
625 char *err;
626
627 /* Set flags. */
628 appctx->ctx.map.display_flags = PAT_REF_MAP;
629
630 /* Expect three parameters: map name, key and new value. */
631 if (!*args[2] || !*args[3] || !*args[4]) {
632 appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100633 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100634 return 1;
635 }
636
637 /* Lookup the reference in the maps. */
638 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
639 if (!appctx->ctx.map.ref) {
640 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100641 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100642 return 1;
643 }
644
645 /* If the entry identifier start with a '#', it is considered as
646 * pointer id
647 */
648 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
649 struct pat_ref_elt *ref;
650 long long int conv;
651 char *error;
652
653 /* Convert argument to integer value. */
654 conv = strtoll(&args[3][1], &error, 16);
655 if (*error != '\0') {
656 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100657 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100658 return 1;
659 }
660
661 /* Convert and check integer to pointer. */
662 ref = (struct pat_ref_elt *)(long)conv;
663 if ((long long int)(long)ref != conv) {
664 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100665 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100666 return 1;
667 }
668
669 /* Try to delete the entry. */
670 err = NULL;
671 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
672 if (err)
673 memprintf(&err, "%s.\n", err);
674 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100675 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100676 return 1;
677 }
678 }
679 else {
680 /* Else, use the entry identifier as pattern
681 * string, and update the value.
682 */
683 err = NULL;
684 if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
685 if (err)
686 memprintf(&err, "%s.\n", err);
687 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100688 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100689 return 1;
690 }
691 }
692
693 /* The set is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100694 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100695 return 0;
696 }
697 return 1;
698}
699
700static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
701{
702 if (strcmp(args[1], "map") == 0 ||
703 strcmp(args[1], "acl") == 0) {
704 int ret;
705 char *err;
706
707 /* Set flags. */
708 if (args[1][0] == 'm')
709 appctx->ctx.map.display_flags = PAT_REF_MAP;
710 else
711 appctx->ctx.map.display_flags = PAT_REF_ACL;
712
713 /* If the keywork is "map", we expect three parameters, if it
714 * is "acl", we expect only two parameters
715 */
716 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
717 if (!*args[2] || !*args[3] || !*args[4]) {
718 appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100719 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100720 return 1;
721 }
722 }
723 else {
724 if (!*args[2] || !*args[3]) {
725 appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100726 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100727 return 1;
728 }
729 }
730
731 /* Lookup for the reference. */
732 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
733 if (!appctx->ctx.map.ref) {
734 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
735 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
736 else
737 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100738 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100739 return 1;
740 }
741
742 /* The command "add acl" is prohibited if the reference
743 * use samples.
744 */
745 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
746 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
747 appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
748 "You must use the command 'add map' to add values.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100749 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100750 return 1;
751 }
752
753 /* Add value. */
754 err = NULL;
755 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
756 ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err);
757 else
758 ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err);
759 if (!ret) {
760 if (err)
761 memprintf(&err, "%s.\n", err);
762 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100763 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100764 return 1;
765 }
766
767 /* The add is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100768 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100769 return 1;
770 }
771
772 return 0;
773}
774
775static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
776{
777 if (args[1][0] == 'm')
778 appctx->ctx.map.display_flags = PAT_REF_MAP;
779 else
780 appctx->ctx.map.display_flags = PAT_REF_ACL;
781
782 /* Expect two parameters: map name and key. */
783 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
784 if (!*args[2] || !*args[3]) {
785 appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100786 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100787 return 1;
788 }
789 }
790
791 else {
792 if (!*args[2] || !*args[3]) {
793 appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100794 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100795 return 1;
796 }
797 }
798
799 /* Lookup the reference in the maps. */
800 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
801 if (!appctx->ctx.map.ref ||
802 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
803 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100804 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100805 return 1;
806 }
807
808 /* If the entry identifier start with a '#', it is considered as
809 * pointer id
810 */
811 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
812 struct pat_ref_elt *ref;
813 long long int conv;
814 char *error;
815
816 /* Convert argument to integer value. */
817 conv = strtoll(&args[3][1], &error, 16);
818 if (*error != '\0') {
819 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100820 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100821 return 1;
822 }
823
824 /* Convert and check integer to pointer. */
825 ref = (struct pat_ref_elt *)(long)conv;
826 if ((long long int)(long)ref != conv) {
827 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100828 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100829 return 1;
830 }
831
832 /* Try to delete the entry. */
833 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
834 /* The entry is not found, send message. */
835 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100836 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100837 return 1;
838 }
839 }
840 else {
841 /* Else, use the entry identifier as pattern
842 * string and try to delete the entry.
843 */
844 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
845 /* The entry is not found, send message. */
846 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100847 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100848 return 1;
849 }
850 }
851
852 /* The deletion is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100853 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100854 return 1;
855}
856
857
858static int cli_parse_clear_map(char **args, struct appctx *appctx, void *private)
859{
860 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
861 /* Set ACL or MAP flags. */
862 if (args[1][0] == 'm')
863 appctx->ctx.map.display_flags = PAT_REF_MAP;
864 else
865 appctx->ctx.map.display_flags = PAT_REF_ACL;
866
867 /* no parameter */
868 if (!*args[2]) {
869 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
870 appctx->ctx.cli.msg = "Missing map identifier.\n";
871 else
872 appctx->ctx.cli.msg = "Missing ACL identifier.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100873 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100874 return 1;
875 }
876
877 /* lookup into the refs and check the map flag */
878 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
879 if (!appctx->ctx.map.ref ||
880 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
881 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
882 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
883 else
884 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100885 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100886 return 1;
887 }
888
889 /* Clear all. */
890 pat_ref_prune(appctx->ctx.map.ref);
891
892 /* return response */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100893 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100894 return 1;
895 }
896 return 0;
897}
898
899/* register cli keywords */
900
901static struct cli_kw_list cli_kws = {{ },{
902 { { "add", "acl", NULL }, "add acl : add acl entry", cli_parse_add_map, NULL },
903 { { "clear", "acl", NULL }, "clear acl <id> : clear the content of this acl", cli_parse_clear_map, NULL },
904 { { "del", "acl", NULL }, "del acl : delete acl entry", cli_parse_del_map, NULL },
905 { { "get", "acl", NULL }, "get acl : report the patterns matching a sample for an ACL", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook },
906 { { "show", "acl", NULL }, "show acl [id] : report available acls or dump an acl's contents", cli_parse_show_map, NULL },
907 { { "add", "map", NULL }, "add map : add map entry", cli_parse_add_map, NULL },
908 { { "clear", "map", NULL }, "clear map <id> : clear the content of this map", cli_parse_clear_map, NULL },
909 { { "del", "map", NULL }, "del map : delete map entry", cli_parse_del_map, NULL },
910 { { "get", "map", NULL }, "get map : report the keys and values matching a sample for a map", cli_parse_get_map, NULL },
911 { { "set", "map", NULL }, "set map : modify map entry", cli_parse_set_map, NULL },
912 { { "show", "map", NULL }, "show map [id] : report available maps or dump a map's contents", cli_parse_show_map, NULL },
913 { { NULL }, NULL, NULL, NULL }
914}};
915
916
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100917/* Note: must not be declared <const> as its list will be overwritten
918 *
919 * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function
920 * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the
921 * file can be parsed.
922 *
923 * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function
924 * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file.
925 *
926 * The map_* keywords only emit strings.
927 *
928 * The output type is only used during the configuration parsing. It is used for detecting
929 * compatibility problems.
930 *
931 * The arguments are: <file>[,<default value>]
932 */
933static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100934 { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
935 { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
936 { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG },
937 { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB },
938 { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR },
939 { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM },
940 { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END },
941 { "map_reg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_REG },
Thierry Fournier8feaa662016-02-10 22:55:20 +0100942 { "map_regm", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_REGM},
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200943 { "map_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_STR, (void *)PAT_MATCH_INT },
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100944 { "map_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_STR, (void *)PAT_MATCH_IP },
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100945
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +0200946 { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR },
947 { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG },
948 { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB },
949 { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR },
950 { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM },
951 { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END },
952 { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG },
953 { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT },
954 { "map_ip_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_ADDR, SMP_T_SINT, (void *)PAT_MATCH_IP },
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100955
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200956 { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR },
957 { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG },
958 { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB },
959 { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR },
960 { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM },
961 { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END },
962 { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG },
963 { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT },
964 { "map_ip_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_ADDR, (void *)PAT_MATCH_IP },
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100965
966 { /* END */ },
967}};
968
969__attribute__((constructor))
970static void __map_init(void)
971{
972 /* register format conversion keywords */
973 sample_register_convs(&sample_conv_kws);
William Lallemandad8be612016-11-18 19:26:17 +0100974 cli_register_kw(&cli_kws);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100975}