blob: 6c63c768ed9ef10154aa58e6e44c2c18650707a0 [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
Willy Tarreau0108d902018-11-25 19:14:37 +010016#include <common/initcall.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010017#include <common/standard.h>
18
William Lallemandad8be612016-11-18 19:26:17 +010019#include <types/applet.h>
20#include <types/cli.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010021#include <types/global.h>
22#include <types/map.h>
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010023#include <types/pattern.h>
William Lallemandad8be612016-11-18 19:26:17 +010024#include <types/stats.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010025
William Lallemandad8be612016-11-18 19:26:17 +010026#include <proto/applet.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010027#include <proto/arg.h>
William Lallemandad8be612016-11-18 19:26:17 +010028#include <proto/cli.h>
Andjelko Iharosc3680ec2017-07-20 16:49:14 +020029#include <proto/log.h>
Thierry FOURNIERb0c0a0f2013-12-10 15:05:34 +010030#include <proto/map.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010031#include <proto/pattern.h>
William Lallemandad8be612016-11-18 19:26:17 +010032#include <proto/stream_interface.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010033#include <proto/sample.h>
34
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020035/* Parse an IPv4 or IPv6 address and store it into the sample.
36 * The output type is IPv4 or IPv6.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010037 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020038int map_parse_ip(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010039{
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020040 int len = strlen(text);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010041
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020042 if (buf2ip(text, len, &data->u.ipv4)) {
43 data->type = SMP_T_IPV4;
44 return 1;
45 }
46 if (buf2ip6(text, len, &data->u.ipv6)) {
47 data->type = SMP_T_IPV6;
48 return 1;
49 }
50 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010051}
52
53/* Parse a string and store a pointer to it into the sample. The original
54 * string must be left in memory because we return a direct memory reference.
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +010055 * The output type is SMP_T_STR. There is no risk that the data will be
56 * overwritten because sample_conv_map() makes a const sample with this
57 * output.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010058 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020059int map_parse_str(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010060{
Willy Tarreau843b7cb2018-07-13 10:54:26 +020061 data->u.str.area = (char *)text;
62 data->u.str.data = strlen(text);
63 data->u.str.size = data->u.str.data + 1;
Thierry FOURNIER503bb092015-08-19 08:35:43 +020064 data->type = SMP_T_STR;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010065 return 1;
66}
67
68/* Parse an integer and convert it to a sample. The output type is SINT if the
69 * number is negative, or UINT if it is positive or null. The function returns
70 * zero (error) if the number is too large.
71 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020072int map_parse_int(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010073{
Thierry FOURNIER503bb092015-08-19 08:35:43 +020074 data->type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +020075 data->u.sint = read_int64(&text, text + strlen(text));
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020076 if (*text != '\0')
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010077 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010078 return 1;
79}
80
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010081/* This crete and initialize map descriptor.
82 * Return NULL if out of memory error
83 */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010084static struct map_descriptor *map_create_descriptor(struct sample_conv *conv)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010085{
86 struct map_descriptor *desc;
87
88 desc = calloc(1, sizeof(*desc));
89 if (!desc)
90 return NULL;
91
92 desc->conv = conv;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010093
94 return desc;
95}
96
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010097/* This function load the map file according with data type declared into
98 * the "struct sample_conv".
99 *
100 * This function choose the indexation type (ebtree or list) according with
101 * the type of match needed.
102 */
Thierry FOURNIER3def3932015-04-07 11:27:54 +0200103int sample_load_map(struct arg *arg, struct sample_conv *conv,
104 const char *file, int line, char **err)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100105{
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100106 struct map_descriptor *desc;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100107
Christopher Fauletd1e92562020-08-05 23:23:37 +0200108 if (!(global.mode & MODE_STARTING)) {
109 memprintf(err, "map: cannot load map at runtime");
110 return 0;
111 }
112
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100113 /* create new map descriptor */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100114 desc = map_create_descriptor(conv);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100115 if (!desc) {
116 memprintf(err, "out of memory");
117 return 0;
118 }
119
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100120 /* Initialize pattern */
121 pattern_init_head(&desc->pat);
122
123 /* This is original pattern, must free */
124 desc->do_free = 1;
125
126 /* Set the match method. */
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100127 desc->pat.match = pat_match_fcts[(long)conv->private];
128 desc->pat.parse = pat_parse_fcts[(long)conv->private];
129 desc->pat.index = pat_index_fcts[(long)conv->private];
130 desc->pat.delete = pat_delete_fcts[(long)conv->private];
131 desc->pat.prune = pat_prune_fcts[(long)conv->private];
132 desc->pat.expect_type = pat_match_types[(long)conv->private];
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100133
134 /* Set the output parse method. */
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100135 switch (desc->conv->out_type) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100136 case SMP_T_STR: desc->pat.parse_smp = map_parse_str; break;
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200137 case SMP_T_SINT: desc->pat.parse_smp = map_parse_int; break;
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200138 case SMP_T_ADDR: desc->pat.parse_smp = map_parse_ip; break;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100139 default:
140 memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.",
141 conv->out_type);
Andreas Seltenreich78f35952016-03-03 20:32:23 +0100142 free(desc);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100143 return 0;
144 }
145
Thierry FOURNIER39bef452014-01-29 13:29:45 +0100146 /* Load map. */
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200147 if (!pattern_read_from_file(&desc->pat, PAT_REF_MAP, arg[0].data.str.area, PAT_MF_NO_DNS,
Thierry FOURNIER94580c92014-02-11 14:36:45 +0100148 1, err, file, line))
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100149 return 0;
Thierry FOURNIER0ffe78c2013-12-05 14:40:25 +0100150
Willy Tarreauaa5801b2019-04-19 11:35:22 +0200151 /* the maps of type IP support a string as default value. This
152 * string can be an ipv4 or an ipv6, we must convert it.
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200153 */
Willy Tarreauaa5801b2019-04-19 11:35:22 +0200154 if (arg[1].type != ARGT_STOP && desc->conv->out_type == SMP_T_ADDR) {
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200155 struct sample_data data;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200156 if (!map_parse_ip(arg[1].data.str.area, &data)) {
157 memprintf(err, "map: cannot parse default ip <%s>.",
158 arg[1].data.str.area);
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200159 return 0;
160 }
161 if (data.type == SMP_T_IPV4) {
162 arg[1].type = ARGT_IPV4;
163 arg[1].data.ipv4 = data.u.ipv4;
164 } else {
165 arg[1].type = ARGT_IPV6;
166 arg[1].data.ipv6 = data.u.ipv6;
167 }
168 }
169
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100170 /* replace the first argument by this definition */
171 arg[0].type = ARGT_MAP;
172 arg[0].data.map = desc;
173
174 return 1;
175}
176
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +0200177static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *private)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100178{
179 struct map_descriptor *desc;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100180 struct pattern *pat;
Willy Tarreau83061a82018-07-13 11:56:34 +0200181 struct buffer *str;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100182
183 /* get config */
184 desc = arg_p[0].data.map;
185
186 /* Execute the match function. */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100187 pat = pattern_exec_match(&desc->pat, smp, 1);
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100188
189 /* Match case. */
190 if (pat) {
Thierry FOURNIER503bb092015-08-19 08:35:43 +0200191 if (pat->data) {
Thierry Fournier8feaa662016-02-10 22:55:20 +0100192 /* In the regm case, merge the sample with the input. */
193 if ((long)private == PAT_MATCH_REGM) {
Emeric Brun27102212018-07-17 09:47:07 -0400194 struct buffer *tmptrash;
Willy Tarreau2842e052018-08-22 04:55:43 +0200195 int len;
Emeric Brun27102212018-07-17 09:47:07 -0400196
197 /* Copy the content of the sample because it could
198 be scratched by incoming get_trash_chunk */
199 tmptrash = alloc_trash_chunk();
200 if (!tmptrash)
201 return 0;
202
203 tmptrash->data = smp->data.u.str.data;
204 if (tmptrash->data > (tmptrash->size-1))
205 tmptrash->data = tmptrash->size-1;
206
207 memcpy(tmptrash->area, smp->data.u.str.area, tmptrash->data);
208 tmptrash->area[tmptrash->data] = 0;
209
Thierry Fournier8feaa662016-02-10 22:55:20 +0100210 str = get_trash_chunk();
Willy Tarreau2842e052018-08-22 04:55:43 +0200211 len = exp_replace(str->area, str->size,
212 tmptrash->area,
213 pat->data->u.str.area,
214 (regmatch_t *)smp->ctx.a[0]);
Nenad Merdanovic646b7742019-04-12 22:54:28 +0200215 free_trash_chunk(tmptrash);
216
Willy Tarreau2842e052018-08-22 04:55:43 +0200217 if (len == -1)
Thierry Fournier8feaa662016-02-10 22:55:20 +0100218 return 0;
Willy Tarreau2842e052018-08-22 04:55:43 +0200219
220 str->data = len;
Thierry Fournier8feaa662016-02-10 22:55:20 +0100221 smp->data.u.str = *str;
222 return 1;
223 }
224 /* Copy sample. */
Thierry FOURNIER5cc18d42015-08-19 09:02:36 +0200225 smp->data = *pat->data;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100226 smp->flags |= SMP_F_CONST;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100227 return 1;
228 }
229
230 /* Return just int sample containing 1. */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200231 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200232 smp->data.u.sint = 1;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100233 return 1;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100234 }
235
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800236 /* If no default value available, the converter fails. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100237 if (arg_p[1].type == ARGT_STOP)
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100238 return 0;
239
240 /* Return the default value. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100241 switch (desc->conv->out_type) {
242
243 case SMP_T_STR:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200244 smp->data.type = SMP_T_STR;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100245 smp->flags |= SMP_F_CONST;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200246 smp->data.u.str = arg_p[1].data.str;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100247 break;
248
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200249 case SMP_T_SINT:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200250 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200251 smp->data.u.sint = arg_p[1].data.sint;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100252 break;
253
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200254 case SMP_T_ADDR:
255 if (arg_p[1].type == ARGT_IPV4) {
256 smp->data.type = SMP_T_IPV4;
257 smp->data.u.ipv4 = arg_p[1].data.ipv4;
258 } else {
259 smp->data.type = SMP_T_IPV6;
260 smp->data.u.ipv6 = arg_p[1].data.ipv6;
261 }
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100262 break;
263 }
264
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100265 return 1;
266}
267
William Lallemandad8be612016-11-18 19:26:17 +0100268/* This function is used with map and acl management. It permits to browse
269 * each reference. The variable <getnext> must contain the current node,
270 * <end> point to the root node and the <flags> permit to filter required
271 * nodes.
272 */
273static inline
274struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end,
275 unsigned int flags)
276{
277 struct pat_ref *ref = getnext;
278
279 while (1) {
280
281 /* Get next list entry. */
282 ref = LIST_NEXT(&ref->list, struct pat_ref *, list);
283
284 /* If the entry is the last of the list, return NULL. */
285 if (&ref->list == end)
286 return NULL;
287
288 /* If the entry match the flag, return it. */
289 if (ref->flags & flags)
290 return ref;
291 }
292}
293
294static inline
295struct pat_ref *pat_ref_lookup_ref(const char *reference)
296{
297 int id;
298 char *error;
299
300 /* If the reference starts by a '#', this is numeric id. */
301 if (reference[0] == '#') {
302 /* Try to convert the numeric id. If the conversion fails, the lookup fails. */
303 id = strtol(reference + 1, &error, 10);
304 if (*error != '\0')
305 return NULL;
306
307 /* Perform the unique id lookup. */
308 return pat_ref_lookupid(id);
309 }
310
311 /* Perform the string lookup. */
312 return pat_ref_lookup(reference);
313}
314
315/* This function is used with map and acl management. It permits to browse
316 * each reference.
317 */
318static inline
319struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end)
320{
321 struct pattern_expr *expr;
322 expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list);
323 if (&expr->list == end)
324 return NULL;
325 return expr;
326}
327
328static int cli_io_handler_pat_list(struct appctx *appctx)
329{
330 struct stream_interface *si = appctx->owner;
Emeric Brun8d85aa42017-06-29 15:40:33 +0200331 struct pat_ref_elt *elt;
332
333 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
334 /* If we're forced to shut down, we might have to remove our
335 * reference to the last ref_elt being dumped.
336 */
337 if (appctx->st2 == STAT_ST_LIST) {
Dragan Dosen336a11f2018-05-04 16:27:15 +0200338 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) {
339 LIST_DEL(&appctx->ctx.map.bref.users);
340 LIST_INIT(&appctx->ctx.map.bref.users);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200341 }
342 }
343 return 1;
344 }
William Lallemandad8be612016-11-18 19:26:17 +0100345
346 switch (appctx->st2) {
347
348 case STAT_ST_INIT:
Emeric Brun8d85aa42017-06-29 15:40:33 +0200349 /* the function had not been called yet, let's prepare the
350 * buffer for a response. We initialize the current stream
351 * pointer to the first in the global list. When a target
352 * stream is being destroyed, it is responsible for updating
353 * this pointer. We know we have reached the end when this
354 * pointer points back to the head of the streams list.
355 */
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100356 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200357 LIST_INIT(&appctx->ctx.map.bref.users);
358 appctx->ctx.map.bref.ref = appctx->ctx.map.ref->head.n;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100359 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100360 appctx->st2 = STAT_ST_LIST;
361 /* fall through */
362
363 case STAT_ST_LIST:
Emeric Brunb5997f72017-07-03 11:34:05 +0200364
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100365 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brunb5997f72017-07-03 11:34:05 +0200366
Emeric Brun8d85aa42017-06-29 15:40:33 +0200367 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) {
368 LIST_DEL(&appctx->ctx.map.bref.users);
369 LIST_INIT(&appctx->ctx.map.bref.users);
370 }
371
372 while (appctx->ctx.map.bref.ref != &appctx->ctx.map.ref->head) {
William Lallemandad8be612016-11-18 19:26:17 +0100373 chunk_reset(&trash);
374
Emeric Brun8d85aa42017-06-29 15:40:33 +0200375 elt = LIST_ELEM(appctx->ctx.map.bref.ref, struct pat_ref_elt *, list);
376
William Lallemandad8be612016-11-18 19:26:17 +0100377 /* build messages */
Emeric Brun8d85aa42017-06-29 15:40:33 +0200378 if (elt->sample)
William Lallemandad8be612016-11-18 19:26:17 +0100379 chunk_appendf(&trash, "%p %s %s\n",
Emeric Brun8d85aa42017-06-29 15:40:33 +0200380 elt, elt->pattern,
381 elt->sample);
William Lallemandad8be612016-11-18 19:26:17 +0100382 else
383 chunk_appendf(&trash, "%p %s\n",
Emeric Brun8d85aa42017-06-29 15:40:33 +0200384 elt, elt->pattern);
William Lallemandad8be612016-11-18 19:26:17 +0100385
Willy Tarreau06d80a92017-10-19 14:32:15 +0200386 if (ci_putchk(si_ic(si), &trash) == -1) {
William Lallemandad8be612016-11-18 19:26:17 +0100387 /* let's try again later from this stream. We add ourselves into
388 * this stream's users so that it can remove us upon termination.
389 */
Emeric Brun8d85aa42017-06-29 15:40:33 +0200390 LIST_ADDQ(&elt->back_refs, &appctx->ctx.map.bref.users);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100391 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Willy Tarreaudb398432018-11-15 11:08:52 +0100392 si_rx_room_blk(si);
William Lallemandad8be612016-11-18 19:26:17 +0100393 return 0;
394 }
395
396 /* get next list entry and check the end of the list */
Emeric Brun8d85aa42017-06-29 15:40:33 +0200397 appctx->ctx.map.bref.ref = elt->list.n;
William Lallemandad8be612016-11-18 19:26:17 +0100398 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100399 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100400 /* fall through */
401
402 default:
403 appctx->st2 = STAT_ST_FIN;
404 return 1;
405 }
406}
407
408static int cli_io_handler_pats_list(struct appctx *appctx)
409{
410 struct stream_interface *si = appctx->owner;
411
412 switch (appctx->st2) {
413 case STAT_ST_INIT:
414 /* Display the column headers. If the message cannot be sent,
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800415 * quit the function with returning 0. The function is called
416 * later and restarted at the state "STAT_ST_INIT".
William Lallemandad8be612016-11-18 19:26:17 +0100417 */
418 chunk_reset(&trash);
419 chunk_appendf(&trash, "# id (file) description\n");
Willy Tarreau06d80a92017-10-19 14:32:15 +0200420 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +0100421 si_rx_room_blk(si);
William Lallemandad8be612016-11-18 19:26:17 +0100422 return 0;
423 }
424
425 /* Now, we start the browsing of the references lists.
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800426 * Note that the following call to LIST_ELEM returns a bad pointer. The only
William Lallemandad8be612016-11-18 19:26:17 +0100427 * available field of this pointer is <list>. It is used with the function
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800428 * pat_list_get_next() for returning the first available entry
William Lallemandad8be612016-11-18 19:26:17 +0100429 */
430 appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list);
431 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
432 appctx->ctx.map.display_flags);
433 appctx->st2 = STAT_ST_LIST;
434 /* fall through */
435
436 case STAT_ST_LIST:
437 while (appctx->ctx.map.ref) {
438 chunk_reset(&trash);
439
440 /* Build messages. If the reference is used by another category than
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800441 * the listed categories, display the information in the message.
William Lallemandad8be612016-11-18 19:26:17 +0100442 */
443 chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id,
444 appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "",
445 appctx->ctx.map.ref->display);
446
Willy Tarreau06d80a92017-10-19 14:32:15 +0200447 if (ci_putchk(si_ic(si), &trash) == -1) {
William Lallemandad8be612016-11-18 19:26:17 +0100448 /* let's try again later from this stream. We add ourselves into
449 * this stream's users so that it can remove us upon termination.
450 */
Willy Tarreaudb398432018-11-15 11:08:52 +0100451 si_rx_room_blk(si);
William Lallemandad8be612016-11-18 19:26:17 +0100452 return 0;
453 }
454
455 /* get next list entry and check the end of the list */
456 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
457 appctx->ctx.map.display_flags);
458 }
459
William Lallemandad8be612016-11-18 19:26:17 +0100460 /* fall through */
461
462 default:
463 appctx->st2 = STAT_ST_FIN;
464 return 1;
465 }
466 return 0;
467}
468
469static int cli_io_handler_map_lookup(struct appctx *appctx)
470{
471 struct stream_interface *si = appctx->owner;
472 struct sample sample;
473 struct pattern *pat;
474 int match_method;
475
476 switch (appctx->st2) {
477 case STAT_ST_INIT:
478 /* Init to the first entry. The list cannot be change */
479 appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list);
480 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat);
481 appctx->st2 = STAT_ST_LIST;
482 /* fall through */
483
484 case STAT_ST_LIST:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100485 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100486 /* for each lookup type */
487 while (appctx->ctx.map.expr) {
488 /* initialise chunk to build new message */
489 chunk_reset(&trash);
490
491 /* execute pattern matching */
492 sample.data.type = SMP_T_STR;
493 sample.flags = SMP_F_CONST;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200494 sample.data.u.str.data = appctx->ctx.map.chunk.data;
495 sample.data.u.str.area = appctx->ctx.map.chunk.area;
Emeric Brunb5997f72017-07-03 11:34:05 +0200496
William Lallemandad8be612016-11-18 19:26:17 +0100497 if (appctx->ctx.map.expr->pat_head->match &&
498 sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type))
499 pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1);
500 else
501 pat = NULL;
502
503 /* build return message: set type of match */
504 for (match_method=0; match_method<PAT_MATCH_NUM; match_method++)
505 if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method])
506 break;
507 if (match_method >= PAT_MATCH_NUM)
508 chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match);
509 else
510 chunk_appendf(&trash, "type=%s", pat_match_names[match_method]);
511
512 /* case sensitive */
513 if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE)
514 chunk_appendf(&trash, ", case=insensitive");
515 else
516 chunk_appendf(&trash, ", case=sensitive");
517
518 /* Display no match, and set default value */
519 if (!pat) {
520 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
521 chunk_appendf(&trash, ", found=no");
522 else
523 chunk_appendf(&trash, ", match=no");
524 }
525
526 /* Display match and match info */
527 else {
528 /* display match */
529 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
530 chunk_appendf(&trash, ", found=yes");
531 else
532 chunk_appendf(&trash, ", match=yes");
533
534 /* display index mode */
535 if (pat->sflags & PAT_SF_TREE)
536 chunk_appendf(&trash, ", idx=tree");
537 else
538 chunk_appendf(&trash, ", idx=list");
539
540 /* display pattern */
541 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
542 if (pat->ref && pat->ref->pattern)
543 chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern);
544 else
545 chunk_appendf(&trash, ", key=unknown");
546 }
547 else {
548 if (pat->ref && pat->ref->pattern)
549 chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern);
550 else
551 chunk_appendf(&trash, ", pattern=unknown");
552 }
553
554 /* display return value */
555 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
556 if (pat->data && pat->ref && pat->ref->sample)
557 chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample,
558 smp_to_type[pat->data->type]);
559 else
560 chunk_appendf(&trash, ", value=none");
561 }
562 }
563
564 chunk_appendf(&trash, "\n");
565
566 /* display response */
Willy Tarreau06d80a92017-10-19 14:32:15 +0200567 if (ci_putchk(si_ic(si), &trash) == -1) {
William Lallemandad8be612016-11-18 19:26:17 +0100568 /* let's try again later from this stream. We add ourselves into
569 * this stream's users so that it can remove us upon termination.
570 */
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100571 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Willy Tarreaudb398432018-11-15 11:08:52 +0100572 si_rx_room_blk(si);
William Lallemandad8be612016-11-18 19:26:17 +0100573 return 0;
574 }
575
576 /* get next entry */
577 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr,
578 &appctx->ctx.map.ref->pat);
579 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100580 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100581 /* fall through */
582
583 default:
584 appctx->st2 = STAT_ST_FIN;
William Lallemandad8be612016-11-18 19:26:17 +0100585 return 1;
586 }
587}
588
589static void cli_release_mlook(struct appctx *appctx)
590{
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200591 free(appctx->ctx.map.chunk.area);
592 appctx->ctx.map.chunk.area = NULL;
William Lallemandad8be612016-11-18 19:26:17 +0100593}
594
595
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200596static int cli_parse_get_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100597{
598 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
599 /* Set flags. */
600 if (args[1][0] == 'm')
601 appctx->ctx.map.display_flags = PAT_REF_MAP;
602 else
603 appctx->ctx.map.display_flags = PAT_REF_ACL;
604
605 /* No parameter. */
606 if (!*args[2] || !*args[3]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200607 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
608 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100609 appctx->ctx.cli.msg = "Missing map identifier and/or key.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200610 }
611 else {
612 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100613 appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200614 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100615 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100616 return 1;
617 }
618
619 /* lookup into the maps */
620 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
621 if (!appctx->ctx.map.ref) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200622 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
623 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100624 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200625 }
626 else {
627 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100628 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200629 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100630 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100631 return 1;
632 }
633
634 /* copy input string. The string must be allocated because
635 * it may be used over multiple iterations. It's released
636 * at the end and upon abort anyway.
637 */
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200638 appctx->ctx.map.chunk.data = strlen(args[3]);
639 appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.data + 1;
640 appctx->ctx.map.chunk.area = strdup(args[3]);
641 if (!appctx->ctx.map.chunk.area) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200642 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100643 appctx->ctx.cli.msg = "Out of memory error.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100644 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100645 return 1;
646 }
647
648 return 0;
649 }
650 return 1;
651}
652
Emeric Brun8d85aa42017-06-29 15:40:33 +0200653static void cli_release_show_map(struct appctx *appctx)
654{
655 if (appctx->st2 == STAT_ST_LIST) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100656 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200657 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users))
658 LIST_DEL(&appctx->ctx.map.bref.users);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100659 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200660 }
661}
662
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200663static int cli_parse_show_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100664{
665 if (strcmp(args[1], "map") == 0 ||
666 strcmp(args[1], "acl") == 0) {
667
668 /* Set ACL or MAP flags. */
669 if (args[1][0] == 'm')
670 appctx->ctx.map.display_flags = PAT_REF_MAP;
671 else
672 appctx->ctx.map.display_flags = PAT_REF_ACL;
673
674 /* no parameter: display all map available */
675 if (!*args[2]) {
William Lallemandad8be612016-11-18 19:26:17 +0100676 appctx->io_handler = cli_io_handler_pats_list;
677 return 0;
678 }
679
680 /* lookup into the refs and check the map flag */
681 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
682 if (!appctx->ctx.map.ref ||
683 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200684 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
685 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100686 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200687 }
688 else {
689 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100690 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200691 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100692 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100693 return 1;
694 }
William Lallemandad8be612016-11-18 19:26:17 +0100695 appctx->io_handler = cli_io_handler_pat_list;
Emeric Brun8d85aa42017-06-29 15:40:33 +0200696 appctx->io_release = cli_release_show_map;
William Lallemandad8be612016-11-18 19:26:17 +0100697 return 0;
698 }
699
700 return 0;
701}
702
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200703static int cli_parse_set_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100704{
705 if (strcmp(args[1], "map") == 0) {
706 char *err;
707
708 /* Set flags. */
709 appctx->ctx.map.display_flags = PAT_REF_MAP;
710
711 /* Expect three parameters: map name, key and new value. */
712 if (!*args[2] || !*args[3] || !*args[4]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200713 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100714 appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100715 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100716 return 1;
717 }
718
719 /* Lookup the reference in the maps. */
720 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
721 if (!appctx->ctx.map.ref) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200722 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100723 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100724 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100725 return 1;
726 }
727
728 /* If the entry identifier start with a '#', it is considered as
729 * pointer id
730 */
731 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
732 struct pat_ref_elt *ref;
733 long long int conv;
734 char *error;
735
736 /* Convert argument to integer value. */
737 conv = strtoll(&args[3][1], &error, 16);
738 if (*error != '\0') {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200739 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100740 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100741 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100742 return 1;
743 }
744
745 /* Convert and check integer to pointer. */
746 ref = (struct pat_ref_elt *)(long)conv;
747 if ((long long int)(long)ref != conv) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200748 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100749 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100750 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100751 return 1;
752 }
753
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200754 /* Try to modify the entry. */
William Lallemandad8be612016-11-18 19:26:17 +0100755 err = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100756 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100757 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100758 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200759 if (err) {
William Lallemandad8be612016-11-18 19:26:17 +0100760 memprintf(&err, "%s.\n", err);
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200761 appctx->ctx.cli.err = err;
762 appctx->st0 = CLI_ST_PRINT_FREE;
763 }
764 else {
765 appctx->ctx.cli.severity = LOG_ERR;
766 appctx->ctx.cli.msg = "Failed to update an entry.\n";
767 appctx->st0 = CLI_ST_PRINT;
768 }
William Lallemandad8be612016-11-18 19:26:17 +0100769 return 1;
770 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100771 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100772 }
773 else {
774 /* Else, use the entry identifier as pattern
775 * string, and update the value.
776 */
777 err = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100778 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100779 if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100780 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200781 if (err) {
William Lallemandad8be612016-11-18 19:26:17 +0100782 memprintf(&err, "%s.\n", err);
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200783 appctx->ctx.cli.err = err;
784 appctx->st0 = CLI_ST_PRINT_FREE;
785 }
786 else {
787 appctx->ctx.cli.severity = LOG_ERR;
788 appctx->ctx.cli.msg = "Failed to update an entry.\n";
789 appctx->st0 = CLI_ST_PRINT;
790 }
William Lallemandad8be612016-11-18 19:26:17 +0100791 return 1;
792 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100793 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100794 }
795
796 /* The set is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100797 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100798 return 0;
799 }
800 return 1;
801}
802
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200803static int map_add_key_value(struct appctx *appctx, const char *key, const char *value, char **err)
804{
805 int ret;
806
807 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
808 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
809 ret = pat_ref_add(appctx->ctx.map.ref, key, value, err);
810 else
811 ret = pat_ref_add(appctx->ctx.map.ref, key, NULL, err);
812 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
813
814 return ret;
815}
816
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200817static int cli_parse_add_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100818{
819 if (strcmp(args[1], "map") == 0 ||
820 strcmp(args[1], "acl") == 0) {
821 int ret;
822 char *err;
823
824 /* Set flags. */
825 if (args[1][0] == 'm')
826 appctx->ctx.map.display_flags = PAT_REF_MAP;
827 else
828 appctx->ctx.map.display_flags = PAT_REF_ACL;
829
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200830 /* If the keyword is "map", we expect:
831 * - three parameters if there is no payload
832 * - one parameter if there is a payload
833 * If it is "acl", we expect only two parameters
William Lallemandad8be612016-11-18 19:26:17 +0100834 */
835 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200836 if ((!payload && (!*args[2] || !*args[3] || !*args[4])) ||
837 (payload && !*args[2])) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200838 appctx->ctx.cli.severity = LOG_ERR;
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200839 appctx->ctx.cli.msg = "'add map' expects three parameters (map identifier, key and value) or one parameter (map identifier) and a payload\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100840 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100841 return 1;
842 }
843 }
844 else {
845 if (!*args[2] || !*args[3]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200846 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100847 appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100848 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100849 return 1;
850 }
851 }
852
853 /* Lookup for the reference. */
854 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
855 if (!appctx->ctx.map.ref) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200856 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
857 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100858 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200859 }
860 else {
861 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100862 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200863 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100864 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100865 return 1;
866 }
867
868 /* The command "add acl" is prohibited if the reference
869 * use samples.
870 */
871 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
872 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200873 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100874 appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
875 "You must use the command 'add map' to add values.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100876 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100877 return 1;
878 }
879
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200880 /* Add value(s). */
William Lallemandad8be612016-11-18 19:26:17 +0100881 err = NULL;
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200882 if (!payload) {
883 ret = map_add_key_value(appctx, args[3], args[4], &err);
884 if (!ret) {
885 if (err) {
886 memprintf(&err, "%s.\n", err);
887 appctx->ctx.cli.err = err;
888 appctx->st0 = CLI_ST_PRINT_FREE;
889 }
890 else {
891 appctx->ctx.cli.severity = LOG_ERR;
892 appctx->ctx.cli.msg = "Failed to add an entry.\n";
893 appctx->st0 = CLI_ST_PRINT;
894 }
895 return 1;
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200896 }
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200897 }
898 else {
899 const char *end = payload + strlen(payload);
900
901 while (payload < end) {
902 char *key, *value;
903 size_t l;
904
905 /* key */
906 key = payload;
907 l = strcspn(key, " \t");
908 payload += l;
909
910 if (!*payload && appctx->ctx.map.display_flags == PAT_REF_MAP) {
911 memprintf(&err, "Missing value for key '%s'.\n", key);
912 appctx->ctx.cli.err = err;
913 appctx->st0 = CLI_ST_PRINT_FREE;
914 return 1;
915 }
916 key[l] = 0;
917 payload++;
918
919 /* value */
920 payload += strspn(payload, " \t");
921 value = payload;
922 l = strcspn(value, "\n");
923 payload += l;
924 if (*payload)
925 payload++;
926 value[l] = 0;
927
928 ret = map_add_key_value(appctx, key, value, &err);
929 if (!ret) {
930 if (err) {
931 memprintf(&err, "%s.\n", err);
932 appctx->ctx.cli.err = err;
933 appctx->st0 = CLI_ST_PRINT_FREE;
934 }
935 else {
936 appctx->ctx.cli.severity = LOG_ERR;
937 appctx->ctx.cli.msg = "Failed to add a key.\n";
938 appctx->st0 = CLI_ST_PRINT;
939 }
940 return 1;
941 }
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200942 }
William Lallemandad8be612016-11-18 19:26:17 +0100943 }
944
945 /* The add is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100946 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100947 return 1;
948 }
949
950 return 0;
951}
952
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200953static int cli_parse_del_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100954{
955 if (args[1][0] == 'm')
956 appctx->ctx.map.display_flags = PAT_REF_MAP;
957 else
958 appctx->ctx.map.display_flags = PAT_REF_ACL;
959
960 /* Expect two parameters: map name and key. */
961 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
962 if (!*args[2] || !*args[3]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200963 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100964 appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100965 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100966 return 1;
967 }
968 }
969
970 else {
971 if (!*args[2] || !*args[3]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200972 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100973 appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100974 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100975 return 1;
976 }
977 }
978
979 /* Lookup the reference in the maps. */
980 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
981 if (!appctx->ctx.map.ref ||
982 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +0200983 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +0100984 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100985 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100986 return 1;
987 }
988
989 /* If the entry identifier start with a '#', it is considered as
990 * pointer id
991 */
992 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
993 struct pat_ref_elt *ref;
994 long long int conv;
995 char *error;
996
997 /* Convert argument to integer value. */
998 conv = strtoll(&args[3][1], &error, 16);
999 if (*error != '\0') {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001000 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001001 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01001002 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +01001003 return 1;
1004 }
1005
1006 /* Convert and check integer to pointer. */
1007 ref = (struct pat_ref_elt *)(long)conv;
1008 if ((long long int)(long)ref != conv) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001009 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001010 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01001011 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +01001012 return 1;
1013 }
1014
1015 /* Try to delete the entry. */
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001016 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +01001017 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001018 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +01001019 /* The entry is not found, send message. */
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001020 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001021 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01001022 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +01001023 return 1;
1024 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001025 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +01001026 }
1027 else {
1028 /* Else, use the entry identifier as pattern
1029 * string and try to delete the entry.
1030 */
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001031 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +01001032 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001033 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +01001034 /* The entry is not found, send message. */
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001035 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001036 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01001037 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +01001038 return 1;
1039 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001040 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +01001041 }
1042
1043 /* The deletion is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +01001044 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +01001045 return 1;
1046}
1047
1048
Willy Tarreaub88a37c2019-12-20 18:22:02 +01001049/* continue to clear a map which was started in the parser */
1050static int cli_io_handler_clear_map(struct appctx *appctx)
1051{
1052 struct stream_interface *si = appctx->owner;
1053 int finished;
1054
1055 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
1056 finished = pat_ref_prune(appctx->ctx.map.ref);
1057 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
1058
1059 if (!finished) {
1060 /* let's come back later */
1061 si_rx_endp_more(si);
1062 return 0;
1063 }
1064 return 1;
1065}
1066
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02001067static int cli_parse_clear_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +01001068{
1069 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
1070 /* Set ACL or MAP flags. */
1071 if (args[1][0] == 'm')
1072 appctx->ctx.map.display_flags = PAT_REF_MAP;
1073 else
1074 appctx->ctx.map.display_flags = PAT_REF_ACL;
1075
1076 /* no parameter */
1077 if (!*args[2]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001078 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
1079 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001080 appctx->ctx.cli.msg = "Missing map identifier.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001081 }
1082 else {
1083 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001084 appctx->ctx.cli.msg = "Missing ACL identifier.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001085 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +01001086 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +01001087 return 1;
1088 }
1089
1090 /* lookup into the refs and check the map flag */
1091 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
1092 if (!appctx->ctx.map.ref ||
1093 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001094 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
1095 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001096 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001097 }
1098 else {
1099 appctx->ctx.cli.severity = LOG_ERR;
William Lallemandad8be612016-11-18 19:26:17 +01001100 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02001101 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +01001102 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +01001103 return 1;
1104 }
1105
Willy Tarreaub88a37c2019-12-20 18:22:02 +01001106 /* delegate the clearing to the I/O handler which can yield */
1107 return 0;
William Lallemandad8be612016-11-18 19:26:17 +01001108 }
Willy Tarreaub88a37c2019-12-20 18:22:02 +01001109 return 1;
William Lallemandad8be612016-11-18 19:26:17 +01001110}
1111
1112/* register cli keywords */
1113
1114static struct cli_kw_list cli_kws = {{ },{
1115 { { "add", "acl", NULL }, "add acl : add acl entry", cli_parse_add_map, NULL },
Willy Tarreaub88a37c2019-12-20 18:22:02 +01001116 { { "clear", "acl", NULL }, "clear acl <id> : clear the content of this acl", cli_parse_clear_map, cli_io_handler_clear_map, NULL },
William Lallemandad8be612016-11-18 19:26:17 +01001117 { { "del", "acl", NULL }, "del acl : delete acl entry", cli_parse_del_map, NULL },
1118 { { "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 },
1119 { { "show", "acl", NULL }, "show acl [id] : report available acls or dump an acl's contents", cli_parse_show_map, NULL },
1120 { { "add", "map", NULL }, "add map : add map entry", cli_parse_add_map, NULL },
Willy Tarreaub88a37c2019-12-20 18:22:02 +01001121 { { "clear", "map", NULL }, "clear map <id> : clear the content of this map", cli_parse_clear_map, cli_io_handler_clear_map, NULL },
William Lallemandad8be612016-11-18 19:26:17 +01001122 { { "del", "map", NULL }, "del map : delete map entry", cli_parse_del_map, NULL },
Nenad Merdanovic96c15712017-03-12 22:01:36 +01001123 { { "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 +01001124 { { "set", "map", NULL }, "set map : modify map entry", cli_parse_set_map, NULL },
1125 { { "show", "map", NULL }, "show map [id] : report available maps or dump a map's contents", cli_parse_show_map, NULL },
1126 { { NULL }, NULL, NULL, NULL }
1127}};
1128
Willy Tarreau0108d902018-11-25 19:14:37 +01001129INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
William Lallemandad8be612016-11-18 19:26:17 +01001130
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +01001131/* Note: must not be declared <const> as its list will be overwritten
1132 *
1133 * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function
1134 * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the
1135 * file can be parsed.
1136 *
1137 * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function
1138 * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file.
1139 *
1140 * The map_* keywords only emit strings.
1141 *
1142 * The output type is only used during the configuration parsing. It is used for detecting
1143 * compatibility problems.
1144 *
1145 * The arguments are: <file>[,<default value>]
1146 */
1147static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Thierry FOURNIER1edc9712014-12-15 16:18:39 +01001148 { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
1149 { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
1150 { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG },
1151 { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB },
1152 { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR },
1153 { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM },
1154 { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END },
1155 { "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 +01001156 { "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 +02001157 { "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 +01001158 { "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 +01001159
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +02001160 { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR },
1161 { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG },
1162 { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB },
1163 { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR },
1164 { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM },
1165 { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END },
1166 { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG },
1167 { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT },
1168 { "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 +01001169
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +02001170 { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR },
1171 { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG },
1172 { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB },
1173 { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR },
1174 { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM },
1175 { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END },
1176 { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG },
1177 { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT },
1178 { "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 +01001179
1180 { /* END */ },
1181}};
1182
Willy Tarreau0108d902018-11-25 19:14:37 +01001183INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws);