blob: e8c6a2acbf05c36e9edca717ab60fc34a43d7472 [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;
William Lallemandad8be612016-11-18 19:26:17 +0100527 return 1;
528 }
529}
530
531static void cli_release_mlook(struct appctx *appctx)
532{
533 free(appctx->ctx.map.chunk.str);
534 appctx->ctx.map.chunk.str = NULL;
535}
536
537
538static int cli_parse_get_map(char **args, struct appctx *appctx, void *private)
539{
540 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
541 /* Set flags. */
542 if (args[1][0] == 'm')
543 appctx->ctx.map.display_flags = PAT_REF_MAP;
544 else
545 appctx->ctx.map.display_flags = PAT_REF_ACL;
546
547 /* No parameter. */
548 if (!*args[2] || !*args[3]) {
549 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
550 appctx->ctx.cli.msg = "Missing map identifier and/or key.\n";
551 else
552 appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100553 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100554 return 1;
555 }
556
557 /* lookup into the maps */
558 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
559 if (!appctx->ctx.map.ref) {
560 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
561 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
562 else
563 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100564 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100565 return 1;
566 }
567
568 /* copy input string. The string must be allocated because
569 * it may be used over multiple iterations. It's released
570 * at the end and upon abort anyway.
571 */
572 appctx->ctx.map.chunk.len = strlen(args[3]);
573 appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1;
574 appctx->ctx.map.chunk.str = strdup(args[3]);
575 if (!appctx->ctx.map.chunk.str) {
576 appctx->ctx.cli.msg = "Out of memory error.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100577 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100578 return 1;
579 }
580
581 return 0;
582 }
583 return 1;
584}
585
586static int cli_parse_show_map(char **args, struct appctx *appctx, void *private)
587{
588 if (strcmp(args[1], "map") == 0 ||
589 strcmp(args[1], "acl") == 0) {
590
591 /* Set ACL or MAP flags. */
592 if (args[1][0] == 'm')
593 appctx->ctx.map.display_flags = PAT_REF_MAP;
594 else
595 appctx->ctx.map.display_flags = PAT_REF_ACL;
596
597 /* no parameter: display all map available */
598 if (!*args[2]) {
William Lallemandad8be612016-11-18 19:26:17 +0100599 appctx->io_handler = cli_io_handler_pats_list;
600 return 0;
601 }
602
603 /* lookup into the refs and check the map flag */
604 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
605 if (!appctx->ctx.map.ref ||
606 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
607 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
608 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
609 else
610 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100611 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100612 return 1;
613 }
William Lallemandad8be612016-11-18 19:26:17 +0100614 appctx->io_handler = cli_io_handler_pat_list;
615 return 0;
616 }
617
618 return 0;
619}
620
621static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
622{
623 if (strcmp(args[1], "map") == 0) {
624 char *err;
625
626 /* Set flags. */
627 appctx->ctx.map.display_flags = PAT_REF_MAP;
628
629 /* Expect three parameters: map name, key and new value. */
630 if (!*args[2] || !*args[3] || !*args[4]) {
631 appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100632 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100633 return 1;
634 }
635
636 /* Lookup the reference in the maps. */
637 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
638 if (!appctx->ctx.map.ref) {
639 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100640 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100641 return 1;
642 }
643
644 /* If the entry identifier start with a '#', it is considered as
645 * pointer id
646 */
647 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
648 struct pat_ref_elt *ref;
649 long long int conv;
650 char *error;
651
652 /* Convert argument to integer value. */
653 conv = strtoll(&args[3][1], &error, 16);
654 if (*error != '\0') {
655 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100656 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100657 return 1;
658 }
659
660 /* Convert and check integer to pointer. */
661 ref = (struct pat_ref_elt *)(long)conv;
662 if ((long long int)(long)ref != conv) {
663 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100664 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100665 return 1;
666 }
667
668 /* Try to delete the entry. */
669 err = NULL;
670 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
671 if (err)
672 memprintf(&err, "%s.\n", err);
673 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100674 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100675 return 1;
676 }
677 }
678 else {
679 /* Else, use the entry identifier as pattern
680 * string, and update the value.
681 */
682 err = NULL;
683 if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
684 if (err)
685 memprintf(&err, "%s.\n", err);
686 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100687 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100688 return 1;
689 }
690 }
691
692 /* The set is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100693 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100694 return 0;
695 }
696 return 1;
697}
698
699static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
700{
701 if (strcmp(args[1], "map") == 0 ||
702 strcmp(args[1], "acl") == 0) {
703 int ret;
704 char *err;
705
706 /* Set flags. */
707 if (args[1][0] == 'm')
708 appctx->ctx.map.display_flags = PAT_REF_MAP;
709 else
710 appctx->ctx.map.display_flags = PAT_REF_ACL;
711
712 /* If the keywork is "map", we expect three parameters, if it
713 * is "acl", we expect only two parameters
714 */
715 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
716 if (!*args[2] || !*args[3] || !*args[4]) {
717 appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100718 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100719 return 1;
720 }
721 }
722 else {
723 if (!*args[2] || !*args[3]) {
724 appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100725 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100726 return 1;
727 }
728 }
729
730 /* Lookup for the reference. */
731 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
732 if (!appctx->ctx.map.ref) {
733 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
734 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
735 else
736 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100737 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100738 return 1;
739 }
740
741 /* The command "add acl" is prohibited if the reference
742 * use samples.
743 */
744 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
745 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
746 appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
747 "You must use the command 'add map' to add values.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100748 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100749 return 1;
750 }
751
752 /* Add value. */
753 err = NULL;
754 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
755 ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err);
756 else
757 ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err);
758 if (!ret) {
759 if (err)
760 memprintf(&err, "%s.\n", err);
761 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100762 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100763 return 1;
764 }
765
766 /* The add is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100767 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100768 return 1;
769 }
770
771 return 0;
772}
773
774static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
775{
776 if (args[1][0] == 'm')
777 appctx->ctx.map.display_flags = PAT_REF_MAP;
778 else
779 appctx->ctx.map.display_flags = PAT_REF_ACL;
780
781 /* Expect two parameters: map name and key. */
782 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
783 if (!*args[2] || !*args[3]) {
784 appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100785 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100786 return 1;
787 }
788 }
789
790 else {
791 if (!*args[2] || !*args[3]) {
792 appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100793 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100794 return 1;
795 }
796 }
797
798 /* Lookup the reference in the maps. */
799 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
800 if (!appctx->ctx.map.ref ||
801 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
802 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100803 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100804 return 1;
805 }
806
807 /* If the entry identifier start with a '#', it is considered as
808 * pointer id
809 */
810 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
811 struct pat_ref_elt *ref;
812 long long int conv;
813 char *error;
814
815 /* Convert argument to integer value. */
816 conv = strtoll(&args[3][1], &error, 16);
817 if (*error != '\0') {
818 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100819 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100820 return 1;
821 }
822
823 /* Convert and check integer to pointer. */
824 ref = (struct pat_ref_elt *)(long)conv;
825 if ((long long int)(long)ref != conv) {
826 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100827 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100828 return 1;
829 }
830
831 /* Try to delete the entry. */
832 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
833 /* The entry is not found, send message. */
834 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100835 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100836 return 1;
837 }
838 }
839 else {
840 /* Else, use the entry identifier as pattern
841 * string and try to delete the entry.
842 */
843 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
844 /* The entry is not found, send message. */
845 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100846 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100847 return 1;
848 }
849 }
850
851 /* The deletion is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100852 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100853 return 1;
854}
855
856
857static int cli_parse_clear_map(char **args, struct appctx *appctx, void *private)
858{
859 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
860 /* Set ACL or MAP flags. */
861 if (args[1][0] == 'm')
862 appctx->ctx.map.display_flags = PAT_REF_MAP;
863 else
864 appctx->ctx.map.display_flags = PAT_REF_ACL;
865
866 /* no parameter */
867 if (!*args[2]) {
868 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
869 appctx->ctx.cli.msg = "Missing map identifier.\n";
870 else
871 appctx->ctx.cli.msg = "Missing ACL identifier.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100872 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100873 return 1;
874 }
875
876 /* lookup into the refs and check the map flag */
877 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
878 if (!appctx->ctx.map.ref ||
879 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
880 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
881 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
882 else
883 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100884 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100885 return 1;
886 }
887
888 /* Clear all. */
889 pat_ref_prune(appctx->ctx.map.ref);
890
891 /* return response */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100892 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100893 return 1;
894 }
895 return 0;
896}
897
898/* register cli keywords */
899
900static struct cli_kw_list cli_kws = {{ },{
901 { { "add", "acl", NULL }, "add acl : add acl entry", cli_parse_add_map, NULL },
902 { { "clear", "acl", NULL }, "clear acl <id> : clear the content of this acl", cli_parse_clear_map, NULL },
903 { { "del", "acl", NULL }, "del acl : delete acl entry", cli_parse_del_map, NULL },
904 { { "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 },
905 { { "show", "acl", NULL }, "show acl [id] : report available acls or dump an acl's contents", cli_parse_show_map, NULL },
906 { { "add", "map", NULL }, "add map : add map entry", cli_parse_add_map, NULL },
907 { { "clear", "map", NULL }, "clear map <id> : clear the content of this map", cli_parse_clear_map, NULL },
908 { { "del", "map", NULL }, "del map : delete map entry", cli_parse_del_map, NULL },
Nenad Merdanovic96c15712017-03-12 22:01:36 +0100909 { { "get", "map", NULL }, "get map : report the keys and values matching a sample for a map", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook },
William Lallemandad8be612016-11-18 19:26:17 +0100910 { { "set", "map", NULL }, "set map : modify map entry", cli_parse_set_map, NULL },
911 { { "show", "map", NULL }, "show map [id] : report available maps or dump a map's contents", cli_parse_show_map, NULL },
912 { { NULL }, NULL, NULL, NULL }
913}};
914
915
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100916/* Note: must not be declared <const> as its list will be overwritten
917 *
918 * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function
919 * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the
920 * file can be parsed.
921 *
922 * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function
923 * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file.
924 *
925 * The map_* keywords only emit strings.
926 *
927 * The output type is only used during the configuration parsing. It is used for detecting
928 * compatibility problems.
929 *
930 * The arguments are: <file>[,<default value>]
931 */
932static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100933 { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
934 { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
935 { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG },
936 { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB },
937 { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR },
938 { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM },
939 { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END },
940 { "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 +0100941 { "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 +0200942 { "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 +0100943 { "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 +0100944
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +0200945 { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR },
946 { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG },
947 { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB },
948 { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR },
949 { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM },
950 { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END },
951 { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG },
952 { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT },
953 { "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 +0100954
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200955 { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR },
956 { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG },
957 { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB },
958 { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR },
959 { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM },
960 { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END },
961 { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG },
962 { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT },
963 { "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 +0100964
965 { /* END */ },
966}};
967
968__attribute__((constructor))
969static void __map_init(void)
970{
971 /* register format conversion keywords */
972 sample_register_convs(&sample_conv_kws);
William Lallemandad8be612016-11-18 19:26:17 +0100973 cli_register_kw(&cli_kws);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100974}