blob: 00297022da064de64976a01e36ccd7ab376400b6 [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
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010013#include <stdio.h>
Willy Tarreau97218ce2021-04-30 14:57:03 +020014#include <syslog.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010015
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020016#include <haproxy/api.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020017#include <haproxy/applet-t.h>
18#include <haproxy/arg.h>
Willy Tarreau83487a82020-06-04 20:19:54 +020019#include <haproxy/cli.h>
Willy Tarreau2cd58092020-06-04 15:10:43 +020020#include <haproxy/map.h>
Willy Tarreau225a90a2020-06-04 15:06:28 +020021#include <haproxy/pattern.h>
Willy Tarreau7cd8b6e2020-06-02 17:32:26 +020022#include <haproxy/regex.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020023#include <haproxy/sample.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020024#include <haproxy/stats-t.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020025#include <haproxy/stream_interface.h>
Willy Tarreau48fbcae2020-06-03 18:09:46 +020026#include <haproxy/tools.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010027
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010028
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020029/* Parse an IPv4 or IPv6 address and store it into the sample.
30 * The output type is IPv4 or IPv6.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010031 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020032int map_parse_ip(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010033{
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020034 int len = strlen(text);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010035
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020036 if (buf2ip(text, len, &data->u.ipv4)) {
37 data->type = SMP_T_IPV4;
38 return 1;
39 }
40 if (buf2ip6(text, len, &data->u.ipv6)) {
41 data->type = SMP_T_IPV6;
42 return 1;
43 }
44 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010045}
46
47/* Parse a string and store a pointer to it into the sample. The original
48 * string must be left in memory because we return a direct memory reference.
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +010049 * The output type is SMP_T_STR. There is no risk that the data will be
50 * overwritten because sample_conv_map() makes a const sample with this
51 * output.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010052 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020053int map_parse_str(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010054{
Willy Tarreau843b7cb2018-07-13 10:54:26 +020055 data->u.str.area = (char *)text;
56 data->u.str.data = strlen(text);
57 data->u.str.size = data->u.str.data + 1;
Thierry FOURNIER503bb092015-08-19 08:35:43 +020058 data->type = SMP_T_STR;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010059 return 1;
60}
61
62/* Parse an integer and convert it to a sample. The output type is SINT if the
63 * number is negative, or UINT if it is positive or null. The function returns
64 * zero (error) if the number is too large.
65 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020066int map_parse_int(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010067{
Thierry FOURNIER503bb092015-08-19 08:35:43 +020068 data->type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +020069 data->u.sint = read_int64(&text, text + strlen(text));
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020070 if (*text != '\0')
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010071 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010072 return 1;
73}
74
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010075/* This crete and initialize map descriptor.
76 * Return NULL if out of memory error
77 */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010078static struct map_descriptor *map_create_descriptor(struct sample_conv *conv)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010079{
80 struct map_descriptor *desc;
81
82 desc = calloc(1, sizeof(*desc));
83 if (!desc)
84 return NULL;
85
86 desc->conv = conv;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010087
88 return desc;
89}
90
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010091/* This function load the map file according with data type declared into
92 * the "struct sample_conv".
93 *
94 * This function choose the indexation type (ebtree or list) according with
95 * the type of match needed.
96 */
Thierry FOURNIER3def3932015-04-07 11:27:54 +020097int sample_load_map(struct arg *arg, struct sample_conv *conv,
98 const char *file, int line, char **err)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010099{
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100100 struct map_descriptor *desc;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100101
Christopher Faulet0eb967d2020-08-05 23:23:37 +0200102 if (!(global.mode & MODE_STARTING)) {
103 memprintf(err, "map: cannot load map at runtime");
104 return 0;
105 }
106
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100107 /* create new map descriptor */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100108 desc = map_create_descriptor(conv);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100109 if (!desc) {
110 memprintf(err, "out of memory");
111 return 0;
112 }
113
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100114 /* Initialize pattern */
115 pattern_init_head(&desc->pat);
116
117 /* This is original pattern, must free */
118 desc->do_free = 1;
119
120 /* Set the match method. */
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100121 desc->pat.match = pat_match_fcts[(long)conv->private];
122 desc->pat.parse = pat_parse_fcts[(long)conv->private];
123 desc->pat.index = pat_index_fcts[(long)conv->private];
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100124 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. */
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200140 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 +0100141 1, err, file, line))
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100142 return 0;
Thierry FOURNIER0ffe78c2013-12-05 14:40:25 +0100143
Willy Tarreauaa5801b2019-04-19 11:35:22 +0200144 /* the maps of type IP support a string as default value. This
145 * string can be an ipv4 or an ipv6, we must convert it.
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200146 */
Willy Tarreauaa5801b2019-04-19 11:35:22 +0200147 if (arg[1].type != ARGT_STOP && desc->conv->out_type == SMP_T_ADDR) {
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200148 struct sample_data data;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200149 if (!map_parse_ip(arg[1].data.str.area, &data)) {
150 memprintf(err, "map: cannot parse default ip <%s>.",
151 arg[1].data.str.area);
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200152 return 0;
153 }
Christopher Faulet6ad7df42020-08-07 11:45:18 +0200154 chunk_destroy(&arg[1].data.str);
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200155 if (data.type == SMP_T_IPV4) {
156 arg[1].type = ARGT_IPV4;
157 arg[1].data.ipv4 = data.u.ipv4;
158 } else {
159 arg[1].type = ARGT_IPV6;
160 arg[1].data.ipv6 = data.u.ipv6;
161 }
162 }
163
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100164 /* replace the first argument by this definition */
Christopher Faulet6ad7df42020-08-07 11:45:18 +0200165 chunk_destroy(&arg[0].data.str);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100166 arg[0].type = ARGT_MAP;
167 arg[0].data.map = desc;
168
169 return 1;
170}
171
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +0200172static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *private)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100173{
174 struct map_descriptor *desc;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100175 struct pattern *pat;
Willy Tarreau83061a82018-07-13 11:56:34 +0200176 struct buffer *str;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100177
178 /* get config */
179 desc = arg_p[0].data.map;
180
181 /* Execute the match function. */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100182 pat = pattern_exec_match(&desc->pat, smp, 1);
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100183
184 /* Match case. */
185 if (pat) {
Thierry FOURNIER503bb092015-08-19 08:35:43 +0200186 if (pat->data) {
Thierry Fournier8feaa662016-02-10 22:55:20 +0100187 /* In the regm case, merge the sample with the input. */
188 if ((long)private == PAT_MATCH_REGM) {
Emeric Brun27102212018-07-17 09:47:07 -0400189 struct buffer *tmptrash;
Willy Tarreau2842e052018-08-22 04:55:43 +0200190 int len;
Emeric Brun27102212018-07-17 09:47:07 -0400191
192 /* Copy the content of the sample because it could
193 be scratched by incoming get_trash_chunk */
194 tmptrash = alloc_trash_chunk();
195 if (!tmptrash)
196 return 0;
197
198 tmptrash->data = smp->data.u.str.data;
199 if (tmptrash->data > (tmptrash->size-1))
200 tmptrash->data = tmptrash->size-1;
201
202 memcpy(tmptrash->area, smp->data.u.str.area, tmptrash->data);
203 tmptrash->area[tmptrash->data] = 0;
204
Thierry Fournier8feaa662016-02-10 22:55:20 +0100205 str = get_trash_chunk();
Willy Tarreau2842e052018-08-22 04:55:43 +0200206 len = exp_replace(str->area, str->size,
207 tmptrash->area,
208 pat->data->u.str.area,
209 (regmatch_t *)smp->ctx.a[0]);
Nenad Merdanovic646b7742019-04-12 22:54:28 +0200210 free_trash_chunk(tmptrash);
211
Willy Tarreau2842e052018-08-22 04:55:43 +0200212 if (len == -1)
Thierry Fournier8feaa662016-02-10 22:55:20 +0100213 return 0;
Willy Tarreau2842e052018-08-22 04:55:43 +0200214
215 str->data = len;
Thierry Fournier8feaa662016-02-10 22:55:20 +0100216 smp->data.u.str = *str;
217 return 1;
218 }
219 /* Copy sample. */
Thierry FOURNIER5cc18d42015-08-19 09:02:36 +0200220 smp->data = *pat->data;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100221 smp->flags |= SMP_F_CONST;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100222 return 1;
223 }
224
225 /* Return just int sample containing 1. */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200226 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200227 smp->data.u.sint = 1;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100228 return 1;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100229 }
230
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800231 /* If no default value available, the converter fails. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100232 if (arg_p[1].type == ARGT_STOP)
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100233 return 0;
234
235 /* Return the default value. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100236 switch (desc->conv->out_type) {
237
238 case SMP_T_STR:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200239 smp->data.type = SMP_T_STR;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100240 smp->flags |= SMP_F_CONST;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200241 smp->data.u.str = arg_p[1].data.str;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100242 break;
243
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200244 case SMP_T_SINT:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200245 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200246 smp->data.u.sint = arg_p[1].data.sint;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100247 break;
248
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200249 case SMP_T_ADDR:
250 if (arg_p[1].type == ARGT_IPV4) {
251 smp->data.type = SMP_T_IPV4;
252 smp->data.u.ipv4 = arg_p[1].data.ipv4;
253 } else {
254 smp->data.type = SMP_T_IPV6;
255 smp->data.u.ipv6 = arg_p[1].data.ipv6;
256 }
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100257 break;
258 }
259
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100260 return 1;
261}
262
William Lallemandad8be612016-11-18 19:26:17 +0100263/* This function is used with map and acl management. It permits to browse
264 * each reference. The variable <getnext> must contain the current node,
265 * <end> point to the root node and the <flags> permit to filter required
266 * nodes.
267 */
268static inline
269struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end,
270 unsigned int flags)
271{
272 struct pat_ref *ref = getnext;
273
274 while (1) {
275
276 /* Get next list entry. */
277 ref = LIST_NEXT(&ref->list, struct pat_ref *, list);
278
279 /* If the entry is the last of the list, return NULL. */
280 if (&ref->list == end)
281 return NULL;
282
283 /* If the entry match the flag, return it. */
284 if (ref->flags & flags)
285 return ref;
286 }
287}
288
289static inline
290struct pat_ref *pat_ref_lookup_ref(const char *reference)
291{
292 int id;
293 char *error;
294
295 /* If the reference starts by a '#', this is numeric id. */
296 if (reference[0] == '#') {
297 /* Try to convert the numeric id. If the conversion fails, the lookup fails. */
298 id = strtol(reference + 1, &error, 10);
299 if (*error != '\0')
300 return NULL;
301
302 /* Perform the unique id lookup. */
303 return pat_ref_lookupid(id);
304 }
305
306 /* Perform the string lookup. */
307 return pat_ref_lookup(reference);
308}
309
310/* This function is used with map and acl management. It permits to browse
311 * each reference.
312 */
313static inline
314struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end)
315{
316 struct pattern_expr *expr;
317 expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list);
318 if (&expr->list == end)
319 return NULL;
320 return expr;
321}
322
Willy Tarreau95f753e2021-04-30 12:09:54 +0200323/* expects the current generation ID in appctx->cli.cli.i0 */
William Lallemandad8be612016-11-18 19:26:17 +0100324static int cli_io_handler_pat_list(struct appctx *appctx)
325{
326 struct stream_interface *si = appctx->owner;
Emeric Brun8d85aa42017-06-29 15:40:33 +0200327 struct pat_ref_elt *elt;
328
329 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
330 /* If we're forced to shut down, we might have to remove our
331 * reference to the last ref_elt being dumped.
332 */
333 if (appctx->st2 == STAT_ST_LIST) {
Dragan Dosen336a11f2018-05-04 16:27:15 +0200334 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) {
Willy Tarreau2b718102021-04-21 07:32:39 +0200335 LIST_DELETE(&appctx->ctx.map.bref.users);
Dragan Dosen336a11f2018-05-04 16:27:15 +0200336 LIST_INIT(&appctx->ctx.map.bref.users);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200337 }
338 }
339 return 1;
340 }
William Lallemandad8be612016-11-18 19:26:17 +0100341
342 switch (appctx->st2) {
343
344 case STAT_ST_INIT:
Emeric Brun8d85aa42017-06-29 15:40:33 +0200345 /* the function had not been called yet, let's prepare the
346 * buffer for a response. We initialize the current stream
347 * pointer to the first in the global list. When a target
348 * stream is being destroyed, it is responsible for updating
349 * this pointer. We know we have reached the end when this
350 * pointer points back to the head of the streams list.
351 */
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100352 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200353 LIST_INIT(&appctx->ctx.map.bref.users);
354 appctx->ctx.map.bref.ref = appctx->ctx.map.ref->head.n;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100355 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100356 appctx->st2 = STAT_ST_LIST;
357 /* fall through */
358
359 case STAT_ST_LIST:
Emeric Brunb5997f72017-07-03 11:34:05 +0200360
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100361 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brunb5997f72017-07-03 11:34:05 +0200362
Emeric Brun8d85aa42017-06-29 15:40:33 +0200363 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) {
Willy Tarreau2b718102021-04-21 07:32:39 +0200364 LIST_DELETE(&appctx->ctx.map.bref.users);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200365 LIST_INIT(&appctx->ctx.map.bref.users);
366 }
367
368 while (appctx->ctx.map.bref.ref != &appctx->ctx.map.ref->head) {
William Lallemandad8be612016-11-18 19:26:17 +0100369 chunk_reset(&trash);
370
Emeric Brun8d85aa42017-06-29 15:40:33 +0200371 elt = LIST_ELEM(appctx->ctx.map.bref.ref, struct pat_ref_elt *, list);
372
Willy Tarreau95f753e2021-04-30 12:09:54 +0200373 if (elt->gen_id != appctx->ctx.cli.i0)
Willy Tarreauc93da692020-10-29 09:41:34 +0100374 goto skip;
375
William Lallemandad8be612016-11-18 19:26:17 +0100376 /* build messages */
Emeric Brun8d85aa42017-06-29 15:40:33 +0200377 if (elt->sample)
William Lallemandad8be612016-11-18 19:26:17 +0100378 chunk_appendf(&trash, "%p %s %s\n",
Emeric Brun8d85aa42017-06-29 15:40:33 +0200379 elt, elt->pattern,
380 elt->sample);
William Lallemandad8be612016-11-18 19:26:17 +0100381 else
382 chunk_appendf(&trash, "%p %s\n",
Emeric Brun8d85aa42017-06-29 15:40:33 +0200383 elt, elt->pattern);
William Lallemandad8be612016-11-18 19:26:17 +0100384
Willy Tarreau06d80a92017-10-19 14:32:15 +0200385 if (ci_putchk(si_ic(si), &trash) == -1) {
William Lallemandad8be612016-11-18 19:26:17 +0100386 /* let's try again later from this stream. We add ourselves into
387 * this stream's users so that it can remove us upon termination.
388 */
Willy Tarreau2b718102021-04-21 07:32:39 +0200389 LIST_APPEND(&elt->back_refs, &appctx->ctx.map.bref.users);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100390 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Willy Tarreaudb398432018-11-15 11:08:52 +0100391 si_rx_room_blk(si);
William Lallemandad8be612016-11-18 19:26:17 +0100392 return 0;
393 }
Willy Tarreauc93da692020-10-29 09:41:34 +0100394 skip:
William Lallemandad8be612016-11-18 19:26:17 +0100395 /* get next list entry and check the end of the list */
Emeric Brun8d85aa42017-06-29 15:40:33 +0200396 appctx->ctx.map.bref.ref = elt->list.n;
William Lallemandad8be612016-11-18 19:26:17 +0100397 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100398 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100399 /* fall through */
400
401 default:
402 appctx->st2 = STAT_ST_FIN;
403 return 1;
404 }
405}
406
407static int cli_io_handler_pats_list(struct appctx *appctx)
408{
409 struct stream_interface *si = appctx->owner;
410
411 switch (appctx->st2) {
412 case STAT_ST_INIT:
413 /* Display the column headers. If the message cannot be sent,
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800414 * quit the function with returning 0. The function is called
415 * later and restarted at the state "STAT_ST_INIT".
William Lallemandad8be612016-11-18 19:26:17 +0100416 */
417 chunk_reset(&trash);
418 chunk_appendf(&trash, "# id (file) description\n");
Willy Tarreau06d80a92017-10-19 14:32:15 +0200419 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +0100420 si_rx_room_blk(si);
William Lallemandad8be612016-11-18 19:26:17 +0100421 return 0;
422 }
423
424 /* Now, we start the browsing of the references lists.
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800425 * Note that the following call to LIST_ELEM returns a bad pointer. The only
William Lallemandad8be612016-11-18 19:26:17 +0100426 * available field of this pointer is <list>. It is used with the function
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800427 * pat_list_get_next() for returning the first available entry
William Lallemandad8be612016-11-18 19:26:17 +0100428 */
429 appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list);
430 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
431 appctx->ctx.map.display_flags);
432 appctx->st2 = STAT_ST_LIST;
433 /* fall through */
434
435 case STAT_ST_LIST:
436 while (appctx->ctx.map.ref) {
437 chunk_reset(&trash);
438
439 /* Build messages. If the reference is used by another category than
Joseph Herlantf43b88b2018-11-25 11:48:18 -0800440 * the listed categories, display the information in the message.
William Lallemandad8be612016-11-18 19:26:17 +0100441 */
Dragan Dosena75eea72021-05-21 16:59:15 +0200442 chunk_appendf(&trash, "%d (%s) %s. curr_ver=%u next_ver=%u entry_cnt=%llu\n", appctx->ctx.map.ref->unique_id,
William Lallemandad8be612016-11-18 19:26:17 +0100443 appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "",
Dragan Dosena75eea72021-05-21 16:59:15 +0200444 appctx->ctx.map.ref->display, appctx->ctx.map.ref->curr_gen, appctx->ctx.map.ref->next_gen,
445 appctx->ctx.map.ref->entry_cnt);
William Lallemandad8be612016-11-18 19:26:17 +0100446
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 Tarreau61cfdf42021-02-20 10:46:51 +0100591 ha_free(&appctx->ctx.map.chunk.area);
William Lallemandad8be612016-11-18 19:26:17 +0100592}
593
594
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200595static int cli_parse_get_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100596{
597 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
598 /* Set flags. */
599 if (args[1][0] == 'm')
600 appctx->ctx.map.display_flags = PAT_REF_MAP;
601 else
602 appctx->ctx.map.display_flags = PAT_REF_ACL;
603
604 /* No parameter. */
605 if (!*args[2] || !*args[3]) {
Willy Tarreau9d008692019-08-09 11:21:01 +0200606 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
607 return cli_err(appctx, "Missing map identifier and/or key.\n");
608 else
609 return cli_err(appctx, "Missing ACL identifier and/or key.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100610 }
611
612 /* lookup into the maps */
613 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
614 if (!appctx->ctx.map.ref) {
Willy Tarreau9d008692019-08-09 11:21:01 +0200615 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
616 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
617 else
618 return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100619 }
620
621 /* copy input string. The string must be allocated because
622 * it may be used over multiple iterations. It's released
623 * at the end and upon abort anyway.
624 */
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200625 appctx->ctx.map.chunk.data = strlen(args[3]);
626 appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.data + 1;
627 appctx->ctx.map.chunk.area = strdup(args[3]);
Willy Tarreau9d008692019-08-09 11:21:01 +0200628 if (!appctx->ctx.map.chunk.area)
629 return cli_err(appctx, "Out of memory error.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100630
631 return 0;
632 }
633 return 1;
634}
635
Willy Tarreau97218ce2021-04-30 14:57:03 +0200636static int cli_parse_prepare_map(char **args, char *payload, struct appctx *appctx, void *private)
637{
638 if (strcmp(args[1], "map") == 0 ||
639 strcmp(args[1], "acl") == 0) {
640 uint next_gen;
641 char *msg = NULL;
642
643 /* Set ACL or MAP flags. */
644 if (args[1][0] == 'm')
645 appctx->ctx.map.display_flags = PAT_REF_MAP;
646 else
647 appctx->ctx.map.display_flags = PAT_REF_ACL;
648
649 /* lookup into the refs and check the map flag */
650 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
651 if (!appctx->ctx.map.ref ||
652 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
653 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
654 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
655 else
656 return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n");
657 }
658 next_gen = pat_ref_newgen(appctx->ctx.map.ref);
659 return cli_dynmsg(appctx, LOG_INFO, memprintf(&msg, "New version created: %u\n", next_gen));
660 }
661
662 return 0;
663}
664
Emeric Brun8d85aa42017-06-29 15:40:33 +0200665static void cli_release_show_map(struct appctx *appctx)
666{
667 if (appctx->st2 == STAT_ST_LIST) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100668 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200669 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users))
Willy Tarreau2b718102021-04-21 07:32:39 +0200670 LIST_DELETE(&appctx->ctx.map.bref.users);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100671 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200672 }
673}
674
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200675static int cli_parse_show_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100676{
677 if (strcmp(args[1], "map") == 0 ||
678 strcmp(args[1], "acl") == 0) {
Willy Tarreau95f753e2021-04-30 12:09:54 +0200679 const char *gen = NULL;
William Lallemandad8be612016-11-18 19:26:17 +0100680
681 /* Set ACL or MAP flags. */
682 if (args[1][0] == 'm')
683 appctx->ctx.map.display_flags = PAT_REF_MAP;
684 else
685 appctx->ctx.map.display_flags = PAT_REF_ACL;
686
687 /* no parameter: display all map available */
688 if (!*args[2]) {
William Lallemandad8be612016-11-18 19:26:17 +0100689 appctx->io_handler = cli_io_handler_pats_list;
690 return 0;
691 }
692
Willy Tarreau95f753e2021-04-30 12:09:54 +0200693 /* For both "map" and "acl" we may have an optional generation
694 * number specified using a "@" character before the pattern
695 * file name.
696 */
697 if (*args[2] == '@') {
698 gen = args[2] + 1;
699 args++;
700 }
701
William Lallemandad8be612016-11-18 19:26:17 +0100702 /* lookup into the refs and check the map flag */
703 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
704 if (!appctx->ctx.map.ref ||
705 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Willy Tarreau9d008692019-08-09 11:21:01 +0200706 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
707 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
708 else
709 return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100710 }
Willy Tarreau95f753e2021-04-30 12:09:54 +0200711
712 /* set the desired generation id in cli.i0 */
713 if (gen)
714 appctx->ctx.cli.i0 = str2uic(gen);
715 else
716 appctx->ctx.cli.i0 = appctx->ctx.map.ref->curr_gen;
717
William Lallemandad8be612016-11-18 19:26:17 +0100718 appctx->io_handler = cli_io_handler_pat_list;
Emeric Brun8d85aa42017-06-29 15:40:33 +0200719 appctx->io_release = cli_release_show_map;
William Lallemandad8be612016-11-18 19:26:17 +0100720 return 0;
721 }
722
723 return 0;
724}
725
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200726static int cli_parse_set_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100727{
728 if (strcmp(args[1], "map") == 0) {
729 char *err;
730
731 /* Set flags. */
732 appctx->ctx.map.display_flags = PAT_REF_MAP;
733
734 /* Expect three parameters: map name, key and new value. */
Willy Tarreau9d008692019-08-09 11:21:01 +0200735 if (!*args[2] || !*args[3] || !*args[4])
736 return cli_err(appctx, "'set map' expects three parameters: map identifier, key and value.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100737
738 /* Lookup the reference in the maps. */
739 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Willy Tarreau9d008692019-08-09 11:21:01 +0200740 if (!appctx->ctx.map.ref)
741 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100742
743 /* If the entry identifier start with a '#', it is considered as
744 * pointer id
745 */
746 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
747 struct pat_ref_elt *ref;
748 long long int conv;
749 char *error;
750
751 /* Convert argument to integer value. */
752 conv = strtoll(&args[3][1], &error, 16);
Willy Tarreau9d008692019-08-09 11:21:01 +0200753 if (*error != '\0')
754 return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100755
756 /* Convert and check integer to pointer. */
757 ref = (struct pat_ref_elt *)(long)conv;
Willy Tarreau9d008692019-08-09 11:21:01 +0200758 if ((long long int)(long)ref != conv)
759 return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100760
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200761 /* Try to modify the entry. */
William Lallemandad8be612016-11-18 19:26:17 +0100762 err = NULL;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100763 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100764 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100765 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Willy Tarreau9d008692019-08-09 11:21:01 +0200766 if (err)
767 return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));
768 else
769 return cli_err(appctx, "Failed to update an entry.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100770 }
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);
Willy Tarreau9d008692019-08-09 11:21:01 +0200781 if (err)
782 return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));
783 else
784 return cli_err(appctx, "Failed to update an entry.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100785 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100786 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100787 }
788
789 /* The set is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100790 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100791 return 0;
792 }
793 return 1;
794}
795
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200796static int cli_parse_add_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100797{
798 if (strcmp(args[1], "map") == 0 ||
799 strcmp(args[1], "acl") == 0) {
Willy Tarreaubb51c442021-04-30 15:23:36 +0200800 const char *gen = NULL;
801 uint genid = 0;
William Lallemandad8be612016-11-18 19:26:17 +0100802 int ret;
803 char *err;
804
805 /* Set flags. */
806 if (args[1][0] == 'm')
807 appctx->ctx.map.display_flags = PAT_REF_MAP;
808 else
809 appctx->ctx.map.display_flags = PAT_REF_ACL;
810
Willy Tarreaubb51c442021-04-30 15:23:36 +0200811 /* For both "map" and "acl" we may have an optional generation
812 * number specified using a "@" character before the pattern
813 * file name.
814 */
815 if (*args[2] == '@') {
816 gen = args[2] + 1;
817 args++;
818 }
819
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200820 /* If the keyword is "map", we expect:
821 * - three parameters if there is no payload
822 * - one parameter if there is a payload
823 * If it is "acl", we expect only two parameters
William Lallemandad8be612016-11-18 19:26:17 +0100824 */
825 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200826 if ((!payload && (!*args[2] || !*args[3] || !*args[4])) ||
Willy Tarreau9d008692019-08-09 11:21:01 +0200827 (payload && !*args[2]))
828 return cli_err(appctx,
829 "'add map' expects three parameters (map identifier, key and value)"
830 " or one parameter (map identifier) and a payload\n");
William Lallemandad8be612016-11-18 19:26:17 +0100831 }
Willy Tarreau9d008692019-08-09 11:21:01 +0200832 else if (!*args[2] || !*args[3])
833 return cli_err(appctx, "'add acl' expects two parameters: ACL identifier and pattern.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100834
835 /* Lookup for the reference. */
836 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
837 if (!appctx->ctx.map.ref) {
Willy Tarreau9d008692019-08-09 11:21:01 +0200838 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
839 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
840 else
841 return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100842 }
843
Willy Tarreaubb51c442021-04-30 15:23:36 +0200844 if (gen) {
845 genid = str2uic(gen);
846 if ((int)(genid - appctx->ctx.map.ref->next_gen) > 0) {
847 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
848 return cli_err(appctx, "Version number in the future, please use 'prepare map' before.\n");
849 else
850 return cli_err(appctx, "Version number in the future, please use 'prepare acl' before.\n");
851 }
852 }
853
William Lallemandad8be612016-11-18 19:26:17 +0100854 /* The command "add acl" is prohibited if the reference
855 * use samples.
856 */
857 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
858 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
Willy Tarreau9d008692019-08-09 11:21:01 +0200859 return cli_err(appctx,
860 "This ACL is shared with a map containing samples. "
861 "You must use the command 'add map' to add values.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100862 }
Willy Tarreauf7dd0e82021-04-29 16:02:48 +0200863
864 /* Add value(s). If no payload is used, key and value are read
865 * from the command line and only one key is set. If a payload
866 * is passed, one key/value pair is read per line till the end
867 * of the payload is reached.
868 */
William Lallemandad8be612016-11-18 19:26:17 +0100869 err = NULL;
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200870
Willy Tarreauf7dd0e82021-04-29 16:02:48 +0200871 do {
872 char *key = args[3];
873 char *value = args[4];
874 size_t l;
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200875
Willy Tarreauf7dd0e82021-04-29 16:02:48 +0200876 if (payload) {
877 /* key and value passed as payload, one pair per line */
878 if (!*payload)
879 break;
880
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200881 key = payload;
882 l = strcspn(key, " \t");
883 payload += l;
884
Willy Tarreau9d008692019-08-09 11:21:01 +0200885 if (!*payload && appctx->ctx.map.display_flags == PAT_REF_MAP)
886 return cli_dynerr(appctx, memprintf(&err, "Missing value for key '%s'.\n", key));
887
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200888 key[l] = 0;
889 payload++;
890
891 /* value */
892 payload += strspn(payload, " \t");
893 value = payload;
894 l = strcspn(value, "\n");
895 payload += l;
896 if (*payload)
897 payload++;
898 value[l] = 0;
Willy Tarreauf7dd0e82021-04-29 16:02:48 +0200899 }
Aurélien Nephtali25650ce2018-04-18 14:04:47 +0200900
Willy Tarreau4053b032021-04-29 16:55:17 +0200901 if (appctx->ctx.map.display_flags != PAT_REF_MAP)
902 value = NULL;
903
904 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Willy Tarreaubb51c442021-04-30 15:23:36 +0200905 ret = !!pat_ref_load(appctx->ctx.map.ref, gen ? genid : appctx->ctx.map.ref->curr_gen, key, value, -1, &err);
Willy Tarreau4053b032021-04-29 16:55:17 +0200906 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
907
Willy Tarreauf7dd0e82021-04-29 16:02:48 +0200908 if (!ret) {
909 if (err)
910 return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));
911 else
912 return cli_err(appctx, "Failed to add a key.\n");
Aurélien Nephtali9a4da682018-04-16 19:02:42 +0200913 }
Willy Tarreauf7dd0e82021-04-29 16:02:48 +0200914 } while (payload && *payload);
William Lallemandad8be612016-11-18 19:26:17 +0100915
916 /* The add is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100917 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100918 return 1;
919 }
920
921 return 0;
922}
923
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200924static int cli_parse_del_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +0100925{
926 if (args[1][0] == 'm')
927 appctx->ctx.map.display_flags = PAT_REF_MAP;
928 else
929 appctx->ctx.map.display_flags = PAT_REF_ACL;
930
931 /* Expect two parameters: map name and key. */
Willy Tarreau9d008692019-08-09 11:21:01 +0200932 if (!*args[2] || !*args[3]) {
933 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
934 return cli_err(appctx, "This command expects two parameters: map identifier and key.\n");
935 else
936 return cli_err(appctx, "This command expects two parameters: ACL identifier and key.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100937 }
938
939 /* Lookup the reference in the maps. */
940 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
941 if (!appctx->ctx.map.ref ||
Willy Tarreau9d008692019-08-09 11:21:01 +0200942 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags))
943 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100944
945 /* If the entry identifier start with a '#', it is considered as
946 * pointer id
947 */
948 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
949 struct pat_ref_elt *ref;
950 long long int conv;
951 char *error;
952
953 /* Convert argument to integer value. */
954 conv = strtoll(&args[3][1], &error, 16);
Willy Tarreau9d008692019-08-09 11:21:01 +0200955 if (*error != '\0')
956 return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100957
958 /* Convert and check integer to pointer. */
959 ref = (struct pat_ref_elt *)(long)conv;
Willy Tarreau9d008692019-08-09 11:21:01 +0200960 if ((long long int)(long)ref != conv)
961 return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100962
963 /* Try to delete the entry. */
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100964 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100965 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100966 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100967 /* The entry is not found, send message. */
Willy Tarreau9d008692019-08-09 11:21:01 +0200968 return cli_err(appctx, "Key not found.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100969 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100970 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100971 }
972 else {
973 /* Else, use the entry identifier as pattern
974 * string and try to delete the entry.
975 */
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100976 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100977 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100978 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100979 /* The entry is not found, send message. */
Willy Tarreau9d008692019-08-09 11:21:01 +0200980 return cli_err(appctx, "Key not found.\n");
William Lallemandad8be612016-11-18 19:26:17 +0100981 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100982 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
William Lallemandad8be612016-11-18 19:26:17 +0100983 }
984
985 /* The deletion is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100986 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100987 return 1;
988}
989
Willy Tarreauff3feeb2021-04-30 13:31:43 +0200990/* continue to clear a map which was started in the parser. The range of
991 * generations this applies to is taken from appctx->ctx.cli.i0 for the oldest
992 * and appctx->ctx.cli.i1 for the latest.
993 */
Willy Tarreaud1d005d2019-12-20 18:22:02 +0100994static int cli_io_handler_clear_map(struct appctx *appctx)
995{
996 struct stream_interface *si = appctx->owner;
997 int finished;
998
999 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
Willy Tarreauff3feeb2021-04-30 13:31:43 +02001000 finished = pat_ref_purge_range(appctx->ctx.map.ref, appctx->ctx.cli.i0, appctx->ctx.cli.i1, 100);
Willy Tarreaud1d005d2019-12-20 18:22:02 +01001001 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
1002
1003 if (!finished) {
1004 /* let's come back later */
1005 si_rx_endp_more(si);
1006 return 0;
1007 }
1008 return 1;
1009}
1010
Willy Tarreauff3feeb2021-04-30 13:31:43 +02001011/* note: sets appctx->ctx.cli.i0 and appctx->ctx.cli.i1 to the oldest and
1012 * latest generations to clear, respectively, and will call the clear_map
1013 * handler.
1014 */
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02001015static int cli_parse_clear_map(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemandad8be612016-11-18 19:26:17 +01001016{
1017 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
Willy Tarreauff3feeb2021-04-30 13:31:43 +02001018 const char *gen = NULL;
1019
William Lallemandad8be612016-11-18 19:26:17 +01001020 /* Set ACL or MAP flags. */
1021 if (args[1][0] == 'm')
1022 appctx->ctx.map.display_flags = PAT_REF_MAP;
1023 else
1024 appctx->ctx.map.display_flags = PAT_REF_ACL;
1025
Willy Tarreauff3feeb2021-04-30 13:31:43 +02001026 /* For both "map" and "acl" we may have an optional generation
1027 * number specified using a "@" character before the pattern
1028 * file name.
1029 */
1030 if (*args[2] == '@') {
1031 gen = args[2] + 1;
1032 args++;
1033 }
1034
William Lallemandad8be612016-11-18 19:26:17 +01001035 /* no parameter */
1036 if (!*args[2]) {
Willy Tarreau9d008692019-08-09 11:21:01 +02001037 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1038 return cli_err(appctx, "Missing map identifier.\n");
1039 else
1040 return cli_err(appctx, "Missing ACL identifier.\n");
William Lallemandad8be612016-11-18 19:26:17 +01001041 }
1042
1043 /* lookup into the refs and check the map flag */
1044 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
1045 if (!appctx->ctx.map.ref ||
1046 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Willy Tarreau9d008692019-08-09 11:21:01 +02001047 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1048 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
1049 else
1050 return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n");
William Lallemandad8be612016-11-18 19:26:17 +01001051 }
1052
Willy Tarreauff3feeb2021-04-30 13:31:43 +02001053 /* set the desired generation id in cli.i0/i1 */
1054 if (gen)
1055 appctx->ctx.cli.i1 = appctx->ctx.cli.i0 = str2uic(gen);
1056 else
1057 appctx->ctx.cli.i1 = appctx->ctx.cli.i0 = appctx->ctx.map.ref->curr_gen;
1058
Willy Tarreaud1d005d2019-12-20 18:22:02 +01001059 /* delegate the clearing to the I/O handler which can yield */
1060 return 0;
William Lallemandad8be612016-11-18 19:26:17 +01001061 }
Willy Tarreaud1d005d2019-12-20 18:22:02 +01001062 return 1;
William Lallemandad8be612016-11-18 19:26:17 +01001063}
1064
Willy Tarreau7a562ca2021-04-30 15:10:01 +02001065/* note: sets appctx->ctx.cli.i0 and appctx->ctx.cli.i1 to the oldest and
1066 * latest generations to clear, respectively, and will call the clear_map
1067 * handler.
1068 */
1069static int cli_parse_commit_map(char **args, char *payload, struct appctx *appctx, void *private)
1070{
1071 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
1072 const char *gen = NULL;
1073 uint genid;
1074 uint ret;
1075
1076 /* Set ACL or MAP flags. */
1077 if (args[1][0] == 'm')
1078 appctx->ctx.map.display_flags = PAT_REF_MAP;
1079 else
1080 appctx->ctx.map.display_flags = PAT_REF_ACL;
1081
1082 if (*args[2] != '@')
1083 return cli_err(appctx, "Missing version number.\n");
1084
1085 /* The generation number is mandatory for a commit. The range
1086 * of generations that get trashed by a commit starts from the
1087 * opposite of the current one and ends at the previous one.
1088 */
1089 gen = args[2] + 1;
1090 genid = str2uic(gen);
1091 appctx->ctx.cli.i1 = genid - 1;
1092 appctx->ctx.cli.i0 = appctx->ctx.cli.i1 - ((~0U) >> 1);
1093
1094 /* no parameter */
1095 if (!*args[3]) {
1096 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1097 return cli_err(appctx, "Missing map identifier.\n");
1098 else
1099 return cli_err(appctx, "Missing ACL identifier.\n");
1100 }
1101
1102 /* lookup into the refs and check the map flag */
1103 appctx->ctx.map.ref = pat_ref_lookup_ref(args[3]);
1104 if (!appctx->ctx.map.ref ||
1105 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
1106 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1107 return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n");
1108 else
1109 return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n");
1110 }
1111
1112 HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
1113 if (genid - (appctx->ctx.map.ref->curr_gen + 1) <
1114 appctx->ctx.map.ref->next_gen - appctx->ctx.map.ref->curr_gen)
1115 ret = pat_ref_commit(appctx->ctx.map.ref, genid);
1116 else
1117 ret = 1;
1118 HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock);
1119
1120 if (ret != 0)
1121 return cli_err(appctx, "Version number out of range.\n");
1122
1123 /* delegate the clearing to the I/O handler which can yield */
1124 return 0;
1125 }
1126 return 1;
1127}
1128
William Lallemandad8be612016-11-18 19:26:17 +01001129/* register cli keywords */
1130
1131static struct cli_kw_list cli_kws = {{ },{
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001132 { { "add", "acl", NULL }, "add acl [@<ver>] <acl> <pattern> : add an acl entry", cli_parse_add_map, NULL },
1133 { { "clear", "acl", NULL }, "clear acl [@<ver>] <acl> : clear the contents of this acl", cli_parse_clear_map, cli_io_handler_clear_map, NULL },
1134 { { "commit","acl", NULL }, "commit acl @<ver> <acl> : commit the ACL at this version", cli_parse_commit_map, cli_io_handler_clear_map, NULL },
1135 { { "del", "acl", NULL }, "del acl <acl> [<key>|#<ref>] : delete acl entries matching <key>", cli_parse_del_map, NULL },
1136 { { "get", "acl", NULL }, "get acl <acl> <value> : report the patterns matching a sample for an ACL", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook },
1137 { { "prepare","acl",NULL }, "prepare acl <acl> : prepare a new version for atomic ACL replacement", cli_parse_prepare_map, NULL },
1138 { { "show", "acl", NULL }, "show acl [@<ver>] <acl>] : report available acls or dump an acl's contents", cli_parse_show_map, NULL },
1139 { { "add", "map", NULL }, "add map [@<ver>] <map> <key> <val> : add a map entry (payload supported instead of key/val)", cli_parse_add_map, NULL },
1140 { { "clear", "map", NULL }, "clear map [@<ver>] <map> : clear the contents of this map", cli_parse_clear_map, cli_io_handler_clear_map, NULL },
1141 { { "commit","map", NULL }, "commit map @<ver> <map> : commit the map at this version", cli_parse_commit_map, cli_io_handler_clear_map, NULL },
1142 { { "del", "map", NULL }, "del map <map> [<key>|#<ref>] : delete map entries matching <key>", cli_parse_del_map, NULL },
1143 { { "get", "map", NULL }, "get map <acl> <value> : report the keys and values matching a sample for a map", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook },
1144 { { "prepare","map",NULL }, "prepare map <acl> : prepare a new version for atomic map replacement", cli_parse_prepare_map, NULL },
1145 { { "set", "map", NULL }, "set map <map> [<key>|#<ref>] <value> : modify a map entry", cli_parse_set_map, NULL },
1146 { { "show", "map", NULL }, "show map [@ver] [map] : report available maps or dump a map's contents", cli_parse_show_map, NULL },
William Lallemandad8be612016-11-18 19:26:17 +01001147 { { NULL }, NULL, NULL, NULL }
1148}};
1149
Willy Tarreau0108d902018-11-25 19:14:37 +01001150INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
William Lallemandad8be612016-11-18 19:26:17 +01001151
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +01001152/* Note: must not be declared <const> as its list will be overwritten
1153 *
1154 * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function
1155 * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the
1156 * file can be parsed.
1157 *
1158 * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function
1159 * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file.
1160 *
1161 * The map_* keywords only emit strings.
1162 *
1163 * The output type is only used during the configuration parsing. It is used for detecting
1164 * compatibility problems.
1165 *
1166 * The arguments are: <file>[,<default value>]
1167 */
1168static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Thierry FOURNIER1edc9712014-12-15 16:18:39 +01001169 { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
1170 { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
1171 { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG },
1172 { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB },
1173 { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR },
1174 { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM },
1175 { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END },
1176 { "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 +01001177 { "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 +02001178 { "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 +01001179 { "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 +01001180
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +02001181 { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR },
1182 { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG },
1183 { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB },
1184 { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR },
1185 { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM },
1186 { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END },
1187 { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG },
1188 { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT },
1189 { "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 +01001190
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +02001191 { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR },
1192 { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG },
1193 { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB },
1194 { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR },
1195 { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM },
1196 { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END },
1197 { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG },
1198 { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT },
1199 { "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 +01001200
1201 { /* END */ },
1202}};
1203
Willy Tarreau0108d902018-11-25 19:14:37 +01001204INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws);