Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1 | /* |
| 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 Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 16 | #include <common/initcall.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 17 | #include <common/standard.h> |
| 18 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 19 | #include <types/applet.h> |
| 20 | #include <types/cli.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 21 | #include <types/global.h> |
| 22 | #include <types/map.h> |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 23 | #include <types/pattern.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 24 | #include <types/stats.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 25 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 26 | #include <proto/applet.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 27 | #include <proto/arg.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 28 | #include <proto/cli.h> |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 29 | #include <proto/log.h> |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 30 | #include <proto/map.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 31 | #include <proto/pattern.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 32 | #include <proto/stream_interface.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 33 | #include <proto/sample.h> |
| 34 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 35 | /* Parse an IPv4 or IPv6 address and store it into the sample. |
| 36 | * The output type is IPv4 or IPv6. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 37 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 38 | int map_parse_ip(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 39 | { |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 40 | int len = strlen(text); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 41 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 42 | 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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 51 | } |
| 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 FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 55 | * 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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 58 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 59 | int map_parse_str(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 60 | { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 61 | data->u.str.area = (char *)text; |
| 62 | data->u.str.data = strlen(text); |
| 63 | data->u.str.size = data->u.str.data + 1; |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 64 | data->type = SMP_T_STR; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 65 | 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 FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 72 | int map_parse_int(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 73 | { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 74 | data->type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 75 | data->u.sint = read_int64(&text, text + strlen(text)); |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 76 | if (*text != '\0') |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 77 | return 0; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 81 | /* This crete and initialize map descriptor. |
| 82 | * Return NULL if out of memory error |
| 83 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 84 | static struct map_descriptor *map_create_descriptor(struct sample_conv *conv) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 85 | { |
| 86 | struct map_descriptor *desc; |
| 87 | |
| 88 | desc = calloc(1, sizeof(*desc)); |
| 89 | if (!desc) |
| 90 | return NULL; |
| 91 | |
| 92 | desc->conv = conv; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 93 | |
| 94 | return desc; |
| 95 | } |
| 96 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 97 | /* 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 FOURNIER | 3def393 | 2015-04-07 11:27:54 +0200 | [diff] [blame] | 103 | int sample_load_map(struct arg *arg, struct sample_conv *conv, |
| 104 | const char *file, int line, char **err) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 105 | { |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 106 | struct map_descriptor *desc; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 107 | |
Christopher Faulet | d1e9256 | 2020-08-05 23:23:37 +0200 | [diff] [blame] | 108 | if (!(global.mode & MODE_STARTING)) { |
| 109 | memprintf(err, "map: cannot load map at runtime"); |
| 110 | return 0; |
| 111 | } |
| 112 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 113 | /* create new map descriptor */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 114 | desc = map_create_descriptor(conv); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 115 | if (!desc) { |
| 116 | memprintf(err, "out of memory"); |
| 117 | return 0; |
| 118 | } |
| 119 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 120 | /* 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 FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 127 | 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 FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 133 | |
| 134 | /* Set the output parse method. */ |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 135 | switch (desc->conv->out_type) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 136 | case SMP_T_STR: desc->pat.parse_smp = map_parse_str; break; |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 137 | case SMP_T_SINT: desc->pat.parse_smp = map_parse_int; break; |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 138 | case SMP_T_ADDR: desc->pat.parse_smp = map_parse_ip; break; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 139 | default: |
| 140 | memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.", |
| 141 | conv->out_type); |
Andreas Seltenreich | 78f3595 | 2016-03-03 20:32:23 +0100 | [diff] [blame] | 142 | free(desc); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
Thierry FOURNIER | 39bef45 | 2014-01-29 13:29:45 +0100 | [diff] [blame] | 146 | /* Load map. */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 147 | if (!pattern_read_from_file(&desc->pat, PAT_REF_MAP, arg[0].data.str.area, PAT_MF_NO_DNS, |
Thierry FOURNIER | 94580c9 | 2014-02-11 14:36:45 +0100 | [diff] [blame] | 148 | 1, err, file, line)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 149 | return 0; |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 150 | |
Willy Tarreau | aa5801b | 2019-04-19 11:35:22 +0200 | [diff] [blame] | 151 | /* 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 FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 153 | */ |
Willy Tarreau | aa5801b | 2019-04-19 11:35:22 +0200 | [diff] [blame] | 154 | if (arg[1].type != ARGT_STOP && desc->conv->out_type == SMP_T_ADDR) { |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 155 | struct sample_data data; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 156 | 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 FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 159 | 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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 170 | /* 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 FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 177 | static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *private) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 178 | { |
| 179 | struct map_descriptor *desc; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 180 | struct pattern *pat; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 181 | struct buffer *str; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 182 | |
| 183 | /* get config */ |
| 184 | desc = arg_p[0].data.map; |
| 185 | |
| 186 | /* Execute the match function. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 187 | pat = pattern_exec_match(&desc->pat, smp, 1); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 188 | |
| 189 | /* Match case. */ |
| 190 | if (pat) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 191 | if (pat->data) { |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 192 | /* In the regm case, merge the sample with the input. */ |
| 193 | if ((long)private == PAT_MATCH_REGM) { |
Emeric Brun | 2710221 | 2018-07-17 09:47:07 -0400 | [diff] [blame] | 194 | struct buffer *tmptrash; |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 195 | int len; |
Emeric Brun | 2710221 | 2018-07-17 09:47:07 -0400 | [diff] [blame] | 196 | |
| 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 Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 210 | str = get_trash_chunk(); |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 211 | len = exp_replace(str->area, str->size, |
| 212 | tmptrash->area, |
| 213 | pat->data->u.str.area, |
| 214 | (regmatch_t *)smp->ctx.a[0]); |
Nenad Merdanovic | 646b774 | 2019-04-12 22:54:28 +0200 | [diff] [blame] | 215 | free_trash_chunk(tmptrash); |
| 216 | |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 217 | if (len == -1) |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 218 | return 0; |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 219 | |
| 220 | str->data = len; |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 221 | smp->data.u.str = *str; |
| 222 | return 1; |
| 223 | } |
| 224 | /* Copy sample. */ |
Thierry FOURNIER | 5cc18d4 | 2015-08-19 09:02:36 +0200 | [diff] [blame] | 225 | smp->data = *pat->data; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 226 | smp->flags |= SMP_F_CONST; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 227 | return 1; |
| 228 | } |
| 229 | |
| 230 | /* Return just int sample containing 1. */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 231 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 232 | smp->data.u.sint = 1; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 233 | return 1; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 236 | /* If no default value available, the converter fails. */ |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 237 | if (arg_p[1].type == ARGT_STOP) |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 238 | return 0; |
| 239 | |
| 240 | /* Return the default value. */ |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 241 | switch (desc->conv->out_type) { |
| 242 | |
| 243 | case SMP_T_STR: |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 244 | smp->data.type = SMP_T_STR; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 245 | smp->flags |= SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 246 | smp->data.u.str = arg_p[1].data.str; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 247 | break; |
| 248 | |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 249 | case SMP_T_SINT: |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 250 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 251 | smp->data.u.sint = arg_p[1].data.sint; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 252 | break; |
| 253 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 254 | 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 FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 262 | break; |
| 263 | } |
| 264 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 265 | return 1; |
| 266 | } |
| 267 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 268 | /* 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 | */ |
| 273 | static inline |
| 274 | struct 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 | |
| 294 | static inline |
| 295 | struct 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 | */ |
| 318 | static inline |
| 319 | struct 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 | |
| 328 | static int cli_io_handler_pat_list(struct appctx *appctx) |
| 329 | { |
| 330 | struct stream_interface *si = appctx->owner; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 331 | 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 Dosen | 336a11f | 2018-05-04 16:27:15 +0200 | [diff] [blame] | 338 | 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 Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | return 1; |
| 344 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 345 | |
| 346 | switch (appctx->st2) { |
| 347 | |
| 348 | case STAT_ST_INIT: |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 349 | /* 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 Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 356 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 357 | LIST_INIT(&appctx->ctx.map.bref.users); |
| 358 | appctx->ctx.map.bref.ref = appctx->ctx.map.ref->head.n; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 359 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 360 | appctx->st2 = STAT_ST_LIST; |
| 361 | /* fall through */ |
| 362 | |
| 363 | case STAT_ST_LIST: |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 364 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 365 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 366 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 367 | 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 Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 373 | chunk_reset(&trash); |
| 374 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 375 | elt = LIST_ELEM(appctx->ctx.map.bref.ref, struct pat_ref_elt *, list); |
| 376 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 377 | /* build messages */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 378 | if (elt->sample) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 379 | chunk_appendf(&trash, "%p %s %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 380 | elt, elt->pattern, |
| 381 | elt->sample); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 382 | else |
| 383 | chunk_appendf(&trash, "%p %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 384 | elt, elt->pattern); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 385 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 386 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 387 | /* 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 Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 390 | LIST_ADDQ(&elt->back_refs, &appctx->ctx.map.bref.users); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 391 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 392 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | /* get next list entry and check the end of the list */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 397 | appctx->ctx.map.bref.ref = elt->list.n; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 398 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 399 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 400 | /* fall through */ |
| 401 | |
| 402 | default: |
| 403 | appctx->st2 = STAT_ST_FIN; |
| 404 | return 1; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | static 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 Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 415 | * quit the function with returning 0. The function is called |
| 416 | * later and restarted at the state "STAT_ST_INIT". |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 417 | */ |
| 418 | chunk_reset(&trash); |
| 419 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 420 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 421 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | /* Now, we start the browsing of the references lists. |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 426 | * Note that the following call to LIST_ELEM returns a bad pointer. The only |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 427 | * available field of this pointer is <list>. It is used with the function |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 428 | * pat_list_get_next() for returning the first available entry |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 429 | */ |
| 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 Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 441 | * the listed categories, display the information in the message. |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 442 | */ |
| 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 Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 447 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 448 | /* 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 Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 451 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 452 | 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 Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 460 | /* fall through */ |
| 461 | |
| 462 | default: |
| 463 | appctx->st2 = STAT_ST_FIN; |
| 464 | return 1; |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static 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 Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 485 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 486 | /* 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 Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 494 | sample.data.u.str.data = appctx->ctx.map.chunk.data; |
| 495 | sample.data.u.str.area = appctx->ctx.map.chunk.area; |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 496 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 497 | 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 Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 567 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 568 | /* 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 Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 571 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 572 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 573 | 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 Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 580 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 581 | /* fall through */ |
| 582 | |
| 583 | default: |
| 584 | appctx->st2 = STAT_ST_FIN; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 585 | return 1; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | static void cli_release_mlook(struct appctx *appctx) |
| 590 | { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 591 | free(appctx->ctx.map.chunk.area); |
| 592 | appctx->ctx.map.chunk.area = NULL; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 596 | static int cli_parse_get_map(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 597 | { |
| 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 607 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 608 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 609 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 610 | } |
| 611 | else { |
| 612 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 613 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 614 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 615 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 616 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 622 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 623 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 624 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 625 | } |
| 626 | else { |
| 627 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 628 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 629 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 630 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 631 | 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 Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 638 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 642 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 643 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 644 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 645 | return 1; |
| 646 | } |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | return 1; |
| 651 | } |
| 652 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 653 | static void cli_release_show_map(struct appctx *appctx) |
| 654 | { |
| 655 | if (appctx->st2 == STAT_ST_LIST) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 656 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 657 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) |
| 658 | LIST_DEL(&appctx->ctx.map.bref.users); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 659 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 663 | static int cli_parse_show_map(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 664 | { |
| 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 Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 676 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 684 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 685 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 686 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 687 | } |
| 688 | else { |
| 689 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 690 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 691 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 692 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 693 | return 1; |
| 694 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 695 | appctx->io_handler = cli_io_handler_pat_list; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 696 | appctx->io_release = cli_release_show_map; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 703 | static int cli_parse_set_map(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 704 | { |
| 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 713 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 714 | appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 715 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 716 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 722 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 723 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 724 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 725 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 739 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 740 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 741 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 742 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 748 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 749 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 750 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 751 | return 1; |
| 752 | } |
| 753 | |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 754 | /* Try to modify the entry. */ |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 755 | err = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 756 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 757 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 758 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 759 | if (err) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 760 | memprintf(&err, "%s.\n", err); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 761 | 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 Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 769 | return 1; |
| 770 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 771 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 772 | } |
| 773 | else { |
| 774 | /* Else, use the entry identifier as pattern |
| 775 | * string, and update the value. |
| 776 | */ |
| 777 | err = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 778 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 779 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 780 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 781 | if (err) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 782 | memprintf(&err, "%s.\n", err); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 783 | 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 Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 791 | return 1; |
| 792 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 793 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | /* The set is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 797 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 798 | return 0; |
| 799 | } |
| 800 | return 1; |
| 801 | } |
| 802 | |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 803 | static 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 Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 817 | static int cli_parse_add_map(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 818 | { |
| 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 Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 830 | /* 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 Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 834 | */ |
| 835 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 836 | if ((!payload && (!*args[2] || !*args[3] || !*args[4])) || |
| 837 | (payload && !*args[2])) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 838 | appctx->ctx.cli.severity = LOG_ERR; |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 839 | appctx->ctx.cli.msg = "'add map' expects three parameters (map identifier, key and value) or one parameter (map identifier) and a payload\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 840 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 841 | return 1; |
| 842 | } |
| 843 | } |
| 844 | else { |
| 845 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 846 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 847 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 848 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 849 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 856 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 857 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 858 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 859 | } |
| 860 | else { |
| 861 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 862 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 863 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 864 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 865 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 873 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 874 | 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 Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 876 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 877 | return 1; |
| 878 | } |
| 879 | |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 880 | /* Add value(s). */ |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 881 | err = NULL; |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 882 | 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 Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 896 | } |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 897 | } |
| 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 Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 942 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | /* The add is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 946 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 947 | return 1; |
| 948 | } |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 953 | static int cli_parse_del_map(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 954 | { |
| 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 963 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 964 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 965 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 966 | return 1; |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | else { |
| 971 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 972 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 973 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 974 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 975 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 983 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 984 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 985 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 986 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1000 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1001 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1002 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1003 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1009 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1010 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1011 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1012 | return 1; |
| 1013 | } |
| 1014 | |
| 1015 | /* Try to delete the entry. */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1016 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1017 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1018 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1019 | /* The entry is not found, send message. */ |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1020 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1021 | appctx->ctx.cli.msg = "Key not found.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1022 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1023 | return 1; |
| 1024 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1025 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1026 | } |
| 1027 | else { |
| 1028 | /* Else, use the entry identifier as pattern |
| 1029 | * string and try to delete the entry. |
| 1030 | */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1031 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1032 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1033 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1034 | /* The entry is not found, send message. */ |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1035 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1036 | appctx->ctx.cli.msg = "Key not found.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1037 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1038 | return 1; |
| 1039 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1040 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* The deletion is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1044 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1045 | return 1; |
| 1046 | } |
| 1047 | |
| 1048 | |
Willy Tarreau | b88a37c | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1049 | /* continue to clear a map which was started in the parser */ |
| 1050 | static 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 Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1067 | static int cli_parse_clear_map(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1068 | { |
| 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1078 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1079 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1080 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1081 | } |
| 1082 | else { |
| 1083 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1084 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1085 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1086 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1087 | 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 Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1094 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1095 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1096 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1097 | } |
| 1098 | else { |
| 1099 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1100 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1101 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1102 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1103 | return 1; |
| 1104 | } |
| 1105 | |
Willy Tarreau | b88a37c | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1106 | /* delegate the clearing to the I/O handler which can yield */ |
| 1107 | return 0; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1108 | } |
Willy Tarreau | b88a37c | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1109 | return 1; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /* register cli keywords */ |
| 1113 | |
| 1114 | static struct cli_kw_list cli_kws = {{ },{ |
| 1115 | { { "add", "acl", NULL }, "add acl : add acl entry", cli_parse_add_map, NULL }, |
Willy Tarreau | b88a37c | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1116 | { { "clear", "acl", NULL }, "clear acl <id> : clear the content of this acl", cli_parse_clear_map, cli_io_handler_clear_map, NULL }, |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1117 | { { "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 Tarreau | b88a37c | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1121 | { { "clear", "map", NULL }, "clear map <id> : clear the content of this map", cli_parse_clear_map, cli_io_handler_clear_map, NULL }, |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1122 | { { "del", "map", NULL }, "del map : delete map entry", cli_parse_del_map, NULL }, |
Nenad Merdanovic | 96c1571 | 2017-03-12 22:01:36 +0100 | [diff] [blame] | 1123 | { { "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 Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1124 | { { "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 Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1129 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1130 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1131 | /* 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 | */ |
| 1147 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 1148 | { "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 Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 1156 | { "map_regm", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_REGM}, |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 1157 | { "map_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_STR, (void *)PAT_MATCH_INT }, |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 1158 | { "map_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_STR, (void *)PAT_MATCH_IP }, |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1159 | |
Thierry FOURNIER | bf65cd4 | 2015-07-20 17:45:02 +0200 | [diff] [blame] | 1160 | { "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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1169 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 1170 | { "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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1179 | |
| 1180 | { /* END */ }, |
| 1181 | }}; |
| 1182 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1183 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |