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 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 13 | #include <stdio.h> |
Willy Tarreau | 97218ce | 2021-04-30 14:57:03 +0200 | [diff] [blame] | 14 | #include <syslog.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 15 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 16 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 17 | #include <haproxy/applet-t.h> |
| 18 | #include <haproxy/arg.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 19 | #include <haproxy/cli.h> |
Willy Tarreau | 2cd5809 | 2020-06-04 15:10:43 +0200 | [diff] [blame] | 20 | #include <haproxy/map.h> |
Willy Tarreau | 225a90a | 2020-06-04 15:06:28 +0200 | [diff] [blame] | 21 | #include <haproxy/pattern.h> |
Willy Tarreau | 7cd8b6e | 2020-06-02 17:32:26 +0200 | [diff] [blame] | 22 | #include <haproxy/regex.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 23 | #include <haproxy/sample.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 24 | #include <haproxy/stats-t.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 25 | #include <haproxy/stream_interface.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 26 | #include <haproxy/tools.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 27 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 28 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 29 | /* Parse an IPv4 or IPv6 address and store it into the sample. |
| 30 | * The output type is IPv4 or IPv6. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 31 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 32 | int map_parse_ip(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 33 | { |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 34 | int len = strlen(text); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 35 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 36 | 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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 45 | } |
| 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 FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 49 | * 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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 52 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 53 | int map_parse_str(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 54 | { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 55 | data->u.str.area = (char *)text; |
| 56 | data->u.str.data = strlen(text); |
| 57 | data->u.str.size = data->u.str.data + 1; |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 58 | data->type = SMP_T_STR; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 59 | 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 FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 66 | int map_parse_int(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 67 | { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 68 | data->type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 69 | data->u.sint = read_int64(&text, text + strlen(text)); |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 70 | if (*text != '\0') |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 71 | return 0; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 72 | return 1; |
| 73 | } |
| 74 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 75 | /* This crete and initialize map descriptor. |
| 76 | * Return NULL if out of memory error |
| 77 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 78 | static struct map_descriptor *map_create_descriptor(struct sample_conv *conv) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 79 | { |
| 80 | struct map_descriptor *desc; |
| 81 | |
| 82 | desc = calloc(1, sizeof(*desc)); |
| 83 | if (!desc) |
| 84 | return NULL; |
| 85 | |
| 86 | desc->conv = conv; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 87 | |
| 88 | return desc; |
| 89 | } |
| 90 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 91 | /* 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 FOURNIER | 3def393 | 2015-04-07 11:27:54 +0200 | [diff] [blame] | 97 | int sample_load_map(struct arg *arg, struct sample_conv *conv, |
| 98 | const char *file, int line, char **err) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 99 | { |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 100 | struct map_descriptor *desc; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 101 | |
Christopher Faulet | 0eb967d | 2020-08-05 23:23:37 +0200 | [diff] [blame] | 102 | if (!(global.mode & MODE_STARTING)) { |
| 103 | memprintf(err, "map: cannot load map at runtime"); |
| 104 | return 0; |
| 105 | } |
| 106 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 107 | /* create new map descriptor */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 108 | desc = map_create_descriptor(conv); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 109 | if (!desc) { |
| 110 | memprintf(err, "out of memory"); |
| 111 | return 0; |
| 112 | } |
| 113 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 114 | /* 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 FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 121 | 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 FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 124 | desc->pat.prune = pat_prune_fcts[(long)conv->private]; |
| 125 | desc->pat.expect_type = pat_match_types[(long)conv->private]; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 126 | |
| 127 | /* Set the output parse method. */ |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 128 | switch (desc->conv->out_type) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 129 | case SMP_T_STR: desc->pat.parse_smp = map_parse_str; break; |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 130 | case SMP_T_SINT: desc->pat.parse_smp = map_parse_int; break; |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 131 | case SMP_T_ADDR: desc->pat.parse_smp = map_parse_ip; break; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 132 | default: |
| 133 | memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.", |
| 134 | conv->out_type); |
Andreas Seltenreich | 78f3595 | 2016-03-03 20:32:23 +0100 | [diff] [blame] | 135 | free(desc); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
Thierry FOURNIER | 39bef45 | 2014-01-29 13:29:45 +0100 | [diff] [blame] | 139 | /* Load map. */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 140 | 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] | 141 | 1, err, file, line)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 142 | return 0; |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 143 | |
Willy Tarreau | aa5801b | 2019-04-19 11:35:22 +0200 | [diff] [blame] | 144 | /* 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 FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 146 | */ |
Willy Tarreau | aa5801b | 2019-04-19 11:35:22 +0200 | [diff] [blame] | 147 | 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] | 148 | struct sample_data data; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 149 | 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 FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 152 | return 0; |
| 153 | } |
Christopher Faulet | 6ad7df4 | 2020-08-07 11:45:18 +0200 | [diff] [blame] | 154 | chunk_destroy(&arg[1].data.str); |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 155 | 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 FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 164 | /* replace the first argument by this definition */ |
Christopher Faulet | 6ad7df4 | 2020-08-07 11:45:18 +0200 | [diff] [blame] | 165 | chunk_destroy(&arg[0].data.str); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 166 | arg[0].type = ARGT_MAP; |
| 167 | arg[0].data.map = desc; |
| 168 | |
| 169 | return 1; |
| 170 | } |
| 171 | |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 172 | 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] | 173 | { |
| 174 | struct map_descriptor *desc; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 175 | struct pattern *pat; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 176 | struct buffer *str; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 177 | |
| 178 | /* get config */ |
| 179 | desc = arg_p[0].data.map; |
| 180 | |
| 181 | /* Execute the match function. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 182 | pat = pattern_exec_match(&desc->pat, smp, 1); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 183 | |
| 184 | /* Match case. */ |
| 185 | if (pat) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 186 | if (pat->data) { |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 187 | /* In the regm case, merge the sample with the input. */ |
| 188 | if ((long)private == PAT_MATCH_REGM) { |
Emeric Brun | 2710221 | 2018-07-17 09:47:07 -0400 | [diff] [blame] | 189 | struct buffer *tmptrash; |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 190 | int len; |
Emeric Brun | 2710221 | 2018-07-17 09:47:07 -0400 | [diff] [blame] | 191 | |
| 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 Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 205 | str = get_trash_chunk(); |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 206 | len = exp_replace(str->area, str->size, |
| 207 | tmptrash->area, |
| 208 | pat->data->u.str.area, |
| 209 | (regmatch_t *)smp->ctx.a[0]); |
Nenad Merdanovic | 646b774 | 2019-04-12 22:54:28 +0200 | [diff] [blame] | 210 | free_trash_chunk(tmptrash); |
| 211 | |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 212 | if (len == -1) |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 213 | return 0; |
Willy Tarreau | 2842e05 | 2018-08-22 04:55:43 +0200 | [diff] [blame] | 214 | |
| 215 | str->data = len; |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 216 | smp->data.u.str = *str; |
| 217 | return 1; |
| 218 | } |
| 219 | /* Copy sample. */ |
Thierry FOURNIER | 5cc18d4 | 2015-08-19 09:02:36 +0200 | [diff] [blame] | 220 | smp->data = *pat->data; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 221 | smp->flags |= SMP_F_CONST; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 222 | return 1; |
| 223 | } |
| 224 | |
| 225 | /* Return just int sample containing 1. */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 226 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 227 | smp->data.u.sint = 1; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 228 | return 1; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 231 | /* If no default value available, the converter fails. */ |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 232 | if (arg_p[1].type == ARGT_STOP) |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 233 | return 0; |
| 234 | |
| 235 | /* Return the default value. */ |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 236 | switch (desc->conv->out_type) { |
| 237 | |
| 238 | case SMP_T_STR: |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 239 | smp->data.type = SMP_T_STR; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 240 | smp->flags |= SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 241 | smp->data.u.str = arg_p[1].data.str; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 242 | break; |
| 243 | |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 244 | case SMP_T_SINT: |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 245 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 246 | smp->data.u.sint = arg_p[1].data.sint; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 247 | break; |
| 248 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 249 | 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 FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 257 | break; |
| 258 | } |
| 259 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 260 | return 1; |
| 261 | } |
| 262 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 263 | /* 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 | */ |
| 268 | static inline |
| 269 | struct 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 | |
| 289 | static inline |
| 290 | struct 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 | */ |
| 313 | static inline |
| 314 | struct 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 Tarreau | 95f753e | 2021-04-30 12:09:54 +0200 | [diff] [blame] | 323 | /* expects the current generation ID in appctx->cli.cli.i0 */ |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 324 | static int cli_io_handler_pat_list(struct appctx *appctx) |
| 325 | { |
| 326 | struct stream_interface *si = appctx->owner; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 327 | 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) { |
Willy Tarreau | f1c627d | 2022-05-03 15:19:49 +0200 | [diff] [blame] | 334 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Dragan Dosen | 336a11f | 2018-05-04 16:27:15 +0200 | [diff] [blame] | 335 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 336 | LIST_DELETE(&appctx->ctx.map.bref.users); |
Dragan Dosen | 336a11f | 2018-05-04 16:27:15 +0200 | [diff] [blame] | 337 | LIST_INIT(&appctx->ctx.map.bref.users); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 338 | } |
Willy Tarreau | f1c627d | 2022-05-03 15:19:49 +0200 | [diff] [blame] | 339 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 340 | } |
| 341 | return 1; |
| 342 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 343 | |
| 344 | switch (appctx->st2) { |
| 345 | |
| 346 | case STAT_ST_INIT: |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 347 | appctx->st2 = STAT_ST_LIST; |
| 348 | /* fall through */ |
| 349 | |
| 350 | case STAT_ST_LIST: |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 351 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 352 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 353 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 354 | LIST_DELETE(&appctx->ctx.map.bref.users); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 355 | LIST_INIT(&appctx->ctx.map.bref.users); |
Willy Tarreau | b360440 | 2022-05-03 15:26:27 +0200 | [diff] [blame] | 356 | } else { |
| 357 | appctx->ctx.map.bref.ref = appctx->ctx.map.ref->head.n; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | while (appctx->ctx.map.bref.ref != &appctx->ctx.map.ref->head) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 361 | chunk_reset(&trash); |
| 362 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 363 | elt = LIST_ELEM(appctx->ctx.map.bref.ref, struct pat_ref_elt *, list); |
| 364 | |
Willy Tarreau | 95f753e | 2021-04-30 12:09:54 +0200 | [diff] [blame] | 365 | if (elt->gen_id != appctx->ctx.cli.i0) |
Willy Tarreau | c93da69 | 2020-10-29 09:41:34 +0100 | [diff] [blame] | 366 | goto skip; |
| 367 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 368 | /* build messages */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 369 | if (elt->sample) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 370 | chunk_appendf(&trash, "%p %s %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 371 | elt, elt->pattern, |
| 372 | elt->sample); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 373 | else |
| 374 | chunk_appendf(&trash, "%p %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 375 | elt, elt->pattern); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 376 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 377 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 378 | /* let's try again later from this stream. We add ourselves into |
| 379 | * this stream's users so that it can remove us upon termination. |
| 380 | */ |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 381 | LIST_APPEND(&elt->back_refs, &appctx->ctx.map.bref.users); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 382 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 383 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 384 | return 0; |
| 385 | } |
Willy Tarreau | c93da69 | 2020-10-29 09:41:34 +0100 | [diff] [blame] | 386 | skip: |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 387 | /* get next list entry and check the end of the list */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 388 | appctx->ctx.map.bref.ref = elt->list.n; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 389 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 390 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 391 | /* fall through */ |
| 392 | |
| 393 | default: |
| 394 | appctx->st2 = STAT_ST_FIN; |
| 395 | return 1; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | static int cli_io_handler_pats_list(struct appctx *appctx) |
| 400 | { |
| 401 | struct stream_interface *si = appctx->owner; |
| 402 | |
| 403 | switch (appctx->st2) { |
| 404 | case STAT_ST_INIT: |
| 405 | /* Display the column headers. If the message cannot be sent, |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 406 | * quit the function with returning 0. The function is called |
| 407 | * later and restarted at the state "STAT_ST_INIT". |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 408 | */ |
| 409 | chunk_reset(&trash); |
| 410 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 411 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 412 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | /* Now, we start the browsing of the references lists. |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 417 | * 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] | 418 | * 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] | 419 | * pat_list_get_next() for returning the first available entry |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 420 | */ |
| 421 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 422 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 423 | appctx->ctx.map.display_flags); |
| 424 | appctx->st2 = STAT_ST_LIST; |
| 425 | /* fall through */ |
| 426 | |
| 427 | case STAT_ST_LIST: |
| 428 | while (appctx->ctx.map.ref) { |
| 429 | chunk_reset(&trash); |
| 430 | |
| 431 | /* Build messages. If the reference is used by another category than |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 432 | * the listed categories, display the information in the message. |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 433 | */ |
Willy Tarreau | e3a42a6 | 2021-04-30 10:55:53 +0200 | [diff] [blame] | 434 | chunk_appendf(&trash, "%d (%s) %s. curr_ver=%u next_ver=%u\n", appctx->ctx.map.ref->unique_id, |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 435 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
Willy Tarreau | e3a42a6 | 2021-04-30 10:55:53 +0200 | [diff] [blame] | 436 | appctx->ctx.map.ref->display, appctx->ctx.map.ref->curr_gen, appctx->ctx.map.ref->next_gen); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 437 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 438 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 439 | /* let's try again later from this stream. We add ourselves into |
| 440 | * this stream's users so that it can remove us upon termination. |
| 441 | */ |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 442 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | /* get next list entry and check the end of the list */ |
| 447 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 448 | appctx->ctx.map.display_flags); |
| 449 | } |
| 450 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 451 | /* fall through */ |
| 452 | |
| 453 | default: |
| 454 | appctx->st2 = STAT_ST_FIN; |
| 455 | return 1; |
| 456 | } |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static int cli_io_handler_map_lookup(struct appctx *appctx) |
| 461 | { |
| 462 | struct stream_interface *si = appctx->owner; |
| 463 | struct sample sample; |
| 464 | struct pattern *pat; |
| 465 | int match_method; |
| 466 | |
| 467 | switch (appctx->st2) { |
| 468 | case STAT_ST_INIT: |
| 469 | /* Init to the first entry. The list cannot be change */ |
| 470 | appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list); |
| 471 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat); |
| 472 | appctx->st2 = STAT_ST_LIST; |
| 473 | /* fall through */ |
| 474 | |
| 475 | case STAT_ST_LIST: |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 476 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 477 | /* for each lookup type */ |
| 478 | while (appctx->ctx.map.expr) { |
| 479 | /* initialise chunk to build new message */ |
| 480 | chunk_reset(&trash); |
| 481 | |
| 482 | /* execute pattern matching */ |
| 483 | sample.data.type = SMP_T_STR; |
| 484 | sample.flags = SMP_F_CONST; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 485 | sample.data.u.str.data = appctx->ctx.map.chunk.data; |
| 486 | sample.data.u.str.area = appctx->ctx.map.chunk.area; |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 487 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 488 | if (appctx->ctx.map.expr->pat_head->match && |
| 489 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
| 490 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 491 | else |
| 492 | pat = NULL; |
| 493 | |
| 494 | /* build return message: set type of match */ |
| 495 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 496 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 497 | break; |
| 498 | if (match_method >= PAT_MATCH_NUM) |
| 499 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 500 | else |
| 501 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
| 502 | |
| 503 | /* case sensitive */ |
| 504 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 505 | chunk_appendf(&trash, ", case=insensitive"); |
| 506 | else |
| 507 | chunk_appendf(&trash, ", case=sensitive"); |
| 508 | |
| 509 | /* Display no match, and set default value */ |
| 510 | if (!pat) { |
| 511 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 512 | chunk_appendf(&trash, ", found=no"); |
| 513 | else |
| 514 | chunk_appendf(&trash, ", match=no"); |
| 515 | } |
| 516 | |
| 517 | /* Display match and match info */ |
| 518 | else { |
| 519 | /* display match */ |
| 520 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 521 | chunk_appendf(&trash, ", found=yes"); |
| 522 | else |
| 523 | chunk_appendf(&trash, ", match=yes"); |
| 524 | |
| 525 | /* display index mode */ |
| 526 | if (pat->sflags & PAT_SF_TREE) |
| 527 | chunk_appendf(&trash, ", idx=tree"); |
| 528 | else |
| 529 | chunk_appendf(&trash, ", idx=list"); |
| 530 | |
| 531 | /* display pattern */ |
| 532 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 533 | if (pat->ref && pat->ref->pattern) |
| 534 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 535 | else |
| 536 | chunk_appendf(&trash, ", key=unknown"); |
| 537 | } |
| 538 | else { |
| 539 | if (pat->ref && pat->ref->pattern) |
| 540 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 541 | else |
| 542 | chunk_appendf(&trash, ", pattern=unknown"); |
| 543 | } |
| 544 | |
| 545 | /* display return value */ |
| 546 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 547 | if (pat->data && pat->ref && pat->ref->sample) |
| 548 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
| 549 | smp_to_type[pat->data->type]); |
| 550 | else |
| 551 | chunk_appendf(&trash, ", value=none"); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | chunk_appendf(&trash, "\n"); |
| 556 | |
| 557 | /* display response */ |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 558 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 559 | /* let's try again later from this stream. We add ourselves into |
| 560 | * this stream's users so that it can remove us upon termination. |
| 561 | */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 562 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 563 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | /* get next entry */ |
| 568 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 569 | &appctx->ctx.map.ref->pat); |
| 570 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 571 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 572 | /* fall through */ |
| 573 | |
| 574 | default: |
| 575 | appctx->st2 = STAT_ST_FIN; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 576 | return 1; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | static void cli_release_mlook(struct appctx *appctx) |
| 581 | { |
Willy Tarreau | 61cfdf4 | 2021-02-20 10:46:51 +0100 | [diff] [blame] | 582 | ha_free(&appctx->ctx.map.chunk.area); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 586 | 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] | 587 | { |
| 588 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 589 | /* Set flags. */ |
| 590 | if (args[1][0] == 'm') |
| 591 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 592 | else |
| 593 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 594 | |
| 595 | /* No parameter. */ |
| 596 | if (!*args[2] || !*args[3]) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 597 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 598 | return cli_err(appctx, "Missing map identifier and/or key.\n"); |
| 599 | else |
| 600 | return cli_err(appctx, "Missing ACL identifier and/or key.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /* lookup into the maps */ |
| 604 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 605 | if (!appctx->ctx.map.ref) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 606 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 607 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
| 608 | else |
| 609 | return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* copy input string. The string must be allocated because |
| 613 | * it may be used over multiple iterations. It's released |
| 614 | * at the end and upon abort anyway. |
| 615 | */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 616 | appctx->ctx.map.chunk.data = strlen(args[3]); |
| 617 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.data + 1; |
| 618 | appctx->ctx.map.chunk.area = strdup(args[3]); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 619 | if (!appctx->ctx.map.chunk.area) |
| 620 | return cli_err(appctx, "Out of memory error.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | return 1; |
| 625 | } |
| 626 | |
Willy Tarreau | 97218ce | 2021-04-30 14:57:03 +0200 | [diff] [blame] | 627 | static int cli_parse_prepare_map(char **args, char *payload, struct appctx *appctx, void *private) |
| 628 | { |
| 629 | if (strcmp(args[1], "map") == 0 || |
| 630 | strcmp(args[1], "acl") == 0) { |
| 631 | uint next_gen; |
| 632 | char *msg = NULL; |
| 633 | |
| 634 | /* Set ACL or MAP flags. */ |
| 635 | if (args[1][0] == 'm') |
| 636 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 637 | else |
| 638 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 639 | |
| 640 | /* lookup into the refs and check the map flag */ |
| 641 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 642 | if (!appctx->ctx.map.ref || |
| 643 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 644 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 645 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
| 646 | else |
| 647 | return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n"); |
| 648 | } |
| 649 | next_gen = pat_ref_newgen(appctx->ctx.map.ref); |
| 650 | return cli_dynmsg(appctx, LOG_INFO, memprintf(&msg, "New version created: %u\n", next_gen)); |
| 651 | } |
| 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 656 | static void cli_release_show_map(struct appctx *appctx) |
| 657 | { |
| 658 | if (appctx->st2 == STAT_ST_LIST) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 659 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 660 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 661 | LIST_DELETE(&appctx->ctx.map.bref.users); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 662 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 666 | 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] | 667 | { |
| 668 | if (strcmp(args[1], "map") == 0 || |
| 669 | strcmp(args[1], "acl") == 0) { |
Willy Tarreau | 95f753e | 2021-04-30 12:09:54 +0200 | [diff] [blame] | 670 | const char *gen = NULL; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 671 | |
| 672 | /* Set ACL or MAP flags. */ |
| 673 | if (args[1][0] == 'm') |
| 674 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 675 | else |
| 676 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 677 | |
| 678 | /* no parameter: display all map available */ |
| 679 | if (!*args[2]) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 680 | appctx->io_handler = cli_io_handler_pats_list; |
| 681 | return 0; |
| 682 | } |
| 683 | |
Willy Tarreau | 95f753e | 2021-04-30 12:09:54 +0200 | [diff] [blame] | 684 | /* For both "map" and "acl" we may have an optional generation |
| 685 | * number specified using a "@" character before the pattern |
| 686 | * file name. |
| 687 | */ |
| 688 | if (*args[2] == '@') { |
| 689 | gen = args[2] + 1; |
| 690 | args++; |
| 691 | } |
| 692 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 693 | /* lookup into the refs and check the map flag */ |
| 694 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 695 | if (!appctx->ctx.map.ref || |
| 696 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 697 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 698 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
| 699 | else |
| 700 | return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 701 | } |
Willy Tarreau | 95f753e | 2021-04-30 12:09:54 +0200 | [diff] [blame] | 702 | |
| 703 | /* set the desired generation id in cli.i0 */ |
| 704 | if (gen) |
| 705 | appctx->ctx.cli.i0 = str2uic(gen); |
| 706 | else |
| 707 | appctx->ctx.cli.i0 = appctx->ctx.map.ref->curr_gen; |
| 708 | |
Willy Tarreau | b360440 | 2022-05-03 15:26:27 +0200 | [diff] [blame] | 709 | LIST_INIT(&appctx->ctx.map.bref.users); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 710 | appctx->io_handler = cli_io_handler_pat_list; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 711 | appctx->io_release = cli_release_show_map; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 718 | 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] | 719 | { |
| 720 | if (strcmp(args[1], "map") == 0) { |
| 721 | char *err; |
| 722 | |
| 723 | /* Set flags. */ |
| 724 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 725 | |
| 726 | /* Expect three parameters: map name, key and new value. */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 727 | if (!*args[2] || !*args[3] || !*args[4]) |
| 728 | return cli_err(appctx, "'set map' expects three parameters: map identifier, key and value.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 729 | |
| 730 | /* Lookup the reference in the maps. */ |
| 731 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 732 | if (!appctx->ctx.map.ref) |
| 733 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 734 | |
| 735 | /* If the entry identifier start with a '#', it is considered as |
| 736 | * pointer id |
| 737 | */ |
| 738 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 739 | struct pat_ref_elt *ref; |
| 740 | long long int conv; |
| 741 | char *error; |
| 742 | |
| 743 | /* Convert argument to integer value. */ |
| 744 | conv = strtoll(&args[3][1], &error, 16); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 745 | if (*error != '\0') |
| 746 | return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 747 | |
| 748 | /* Convert and check integer to pointer. */ |
| 749 | ref = (struct pat_ref_elt *)(long)conv; |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 750 | if ((long long int)(long)ref != conv) |
| 751 | return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 752 | |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 753 | /* Try to modify the entry. */ |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 754 | err = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 755 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 756 | 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] | 757 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 758 | if (err) |
| 759 | return cli_dynerr(appctx, memprintf(&err, "%s.\n", err)); |
| 760 | else |
| 761 | return cli_err(appctx, "Failed to update an entry.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 762 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 763 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 764 | } |
| 765 | else { |
| 766 | /* Else, use the entry identifier as pattern |
| 767 | * string, and update the value. |
| 768 | */ |
| 769 | err = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 770 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 771 | 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] | 772 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 773 | if (err) |
| 774 | return cli_dynerr(appctx, memprintf(&err, "%s.\n", err)); |
| 775 | else |
| 776 | return cli_err(appctx, "Failed to update an entry.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 777 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 778 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* The set is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 782 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 783 | return 0; |
| 784 | } |
| 785 | return 1; |
| 786 | } |
| 787 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 788 | 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] | 789 | { |
| 790 | if (strcmp(args[1], "map") == 0 || |
| 791 | strcmp(args[1], "acl") == 0) { |
Willy Tarreau | bb51c44 | 2021-04-30 15:23:36 +0200 | [diff] [blame] | 792 | const char *gen = NULL; |
| 793 | uint genid = 0; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 794 | int ret; |
| 795 | char *err; |
| 796 | |
| 797 | /* Set flags. */ |
| 798 | if (args[1][0] == 'm') |
| 799 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 800 | else |
| 801 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 802 | |
Willy Tarreau | bb51c44 | 2021-04-30 15:23:36 +0200 | [diff] [blame] | 803 | /* For both "map" and "acl" we may have an optional generation |
| 804 | * number specified using a "@" character before the pattern |
| 805 | * file name. |
| 806 | */ |
| 807 | if (*args[2] == '@') { |
| 808 | gen = args[2] + 1; |
| 809 | args++; |
| 810 | } |
| 811 | |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 812 | /* If the keyword is "map", we expect: |
| 813 | * - three parameters if there is no payload |
| 814 | * - one parameter if there is a payload |
| 815 | * If it is "acl", we expect only two parameters |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 816 | */ |
| 817 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 818 | if ((!payload && (!*args[2] || !*args[3] || !*args[4])) || |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 819 | (payload && !*args[2])) |
| 820 | return cli_err(appctx, |
| 821 | "'add map' expects three parameters (map identifier, key and value)" |
| 822 | " or one parameter (map identifier) and a payload\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 823 | } |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 824 | else if (!*args[2] || !*args[3]) |
| 825 | return cli_err(appctx, "'add acl' expects two parameters: ACL identifier and pattern.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 826 | |
| 827 | /* Lookup for the reference. */ |
| 828 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 829 | if (!appctx->ctx.map.ref) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 830 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 831 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
| 832 | else |
| 833 | return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 834 | } |
| 835 | |
Willy Tarreau | bb51c44 | 2021-04-30 15:23:36 +0200 | [diff] [blame] | 836 | if (gen) { |
| 837 | genid = str2uic(gen); |
| 838 | if ((int)(genid - appctx->ctx.map.ref->next_gen) > 0) { |
| 839 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 840 | return cli_err(appctx, "Version number in the future, please use 'prepare map' before.\n"); |
| 841 | else |
| 842 | return cli_err(appctx, "Version number in the future, please use 'prepare acl' before.\n"); |
| 843 | } |
| 844 | } |
| 845 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 846 | /* The command "add acl" is prohibited if the reference |
| 847 | * use samples. |
| 848 | */ |
| 849 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 850 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 851 | return cli_err(appctx, |
| 852 | "This ACL is shared with a map containing samples. " |
| 853 | "You must use the command 'add map' to add values.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 854 | } |
Willy Tarreau | f7dd0e8 | 2021-04-29 16:02:48 +0200 | [diff] [blame] | 855 | |
| 856 | /* Add value(s). If no payload is used, key and value are read |
| 857 | * from the command line and only one key is set. If a payload |
| 858 | * is passed, one key/value pair is read per line till the end |
| 859 | * of the payload is reached. |
| 860 | */ |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 861 | err = NULL; |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 862 | |
Willy Tarreau | f7dd0e8 | 2021-04-29 16:02:48 +0200 | [diff] [blame] | 863 | do { |
| 864 | char *key = args[3]; |
| 865 | char *value = args[4]; |
| 866 | size_t l; |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 867 | |
Willy Tarreau | f7dd0e8 | 2021-04-29 16:02:48 +0200 | [diff] [blame] | 868 | if (payload) { |
| 869 | /* key and value passed as payload, one pair per line */ |
| 870 | if (!*payload) |
| 871 | break; |
| 872 | |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 873 | key = payload; |
| 874 | l = strcspn(key, " \t"); |
| 875 | payload += l; |
| 876 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 877 | if (!*payload && appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 878 | return cli_dynerr(appctx, memprintf(&err, "Missing value for key '%s'.\n", key)); |
| 879 | |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 880 | key[l] = 0; |
| 881 | payload++; |
| 882 | |
| 883 | /* value */ |
| 884 | payload += strspn(payload, " \t"); |
| 885 | value = payload; |
| 886 | l = strcspn(value, "\n"); |
| 887 | payload += l; |
| 888 | if (*payload) |
| 889 | payload++; |
| 890 | value[l] = 0; |
Willy Tarreau | f7dd0e8 | 2021-04-29 16:02:48 +0200 | [diff] [blame] | 891 | } |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 892 | |
Willy Tarreau | 4053b03 | 2021-04-29 16:55:17 +0200 | [diff] [blame] | 893 | if (appctx->ctx.map.display_flags != PAT_REF_MAP) |
| 894 | value = NULL; |
| 895 | |
| 896 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | bb51c44 | 2021-04-30 15:23:36 +0200 | [diff] [blame] | 897 | ret = !!pat_ref_load(appctx->ctx.map.ref, gen ? genid : appctx->ctx.map.ref->curr_gen, key, value, -1, &err); |
Willy Tarreau | 4053b03 | 2021-04-29 16:55:17 +0200 | [diff] [blame] | 898 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
| 899 | |
Willy Tarreau | f7dd0e8 | 2021-04-29 16:02:48 +0200 | [diff] [blame] | 900 | if (!ret) { |
| 901 | if (err) |
| 902 | return cli_dynerr(appctx, memprintf(&err, "%s.\n", err)); |
| 903 | else |
| 904 | return cli_err(appctx, "Failed to add a key.\n"); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 905 | } |
Willy Tarreau | f7dd0e8 | 2021-04-29 16:02:48 +0200 | [diff] [blame] | 906 | } while (payload && *payload); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 907 | |
| 908 | /* The add is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 909 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 910 | return 1; |
| 911 | } |
| 912 | |
| 913 | return 0; |
| 914 | } |
| 915 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 916 | 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] | 917 | { |
| 918 | if (args[1][0] == 'm') |
| 919 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 920 | else |
| 921 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 922 | |
| 923 | /* Expect two parameters: map name and key. */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 924 | if (!*args[2] || !*args[3]) { |
| 925 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 926 | return cli_err(appctx, "This command expects two parameters: map identifier and key.\n"); |
| 927 | else |
| 928 | return cli_err(appctx, "This command expects two parameters: ACL identifier and key.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /* Lookup the reference in the maps. */ |
| 932 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 933 | if (!appctx->ctx.map.ref || |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 934 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) |
| 935 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 936 | |
| 937 | /* If the entry identifier start with a '#', it is considered as |
| 938 | * pointer id |
| 939 | */ |
| 940 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 941 | struct pat_ref_elt *ref; |
| 942 | long long int conv; |
| 943 | char *error; |
| 944 | |
| 945 | /* Convert argument to integer value. */ |
| 946 | conv = strtoll(&args[3][1], &error, 16); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 947 | if (*error != '\0') |
| 948 | return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 949 | |
| 950 | /* Convert and check integer to pointer. */ |
| 951 | ref = (struct pat_ref_elt *)(long)conv; |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 952 | if ((long long int)(long)ref != conv) |
| 953 | return cli_err(appctx, "Malformed identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 954 | |
| 955 | /* Try to delete the entry. */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 956 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 957 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 958 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 959 | /* The entry is not found, send message. */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 960 | return cli_err(appctx, "Key not found.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 961 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 962 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 963 | } |
| 964 | else { |
| 965 | /* Else, use the entry identifier as pattern |
| 966 | * string and try to delete the entry. |
| 967 | */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 968 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 969 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 970 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 971 | /* The entry is not found, send message. */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 972 | return cli_err(appctx, "Key not found.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 973 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 974 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /* The deletion is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 978 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 979 | return 1; |
| 980 | } |
| 981 | |
Willy Tarreau | ff3feeb | 2021-04-30 13:31:43 +0200 | [diff] [blame] | 982 | /* continue to clear a map which was started in the parser. The range of |
| 983 | * generations this applies to is taken from appctx->ctx.cli.i0 for the oldest |
| 984 | * and appctx->ctx.cli.i1 for the latest. |
| 985 | */ |
Willy Tarreau | d1d005d | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 986 | static int cli_io_handler_clear_map(struct appctx *appctx) |
| 987 | { |
| 988 | struct stream_interface *si = appctx->owner; |
| 989 | int finished; |
| 990 | |
| 991 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | ff3feeb | 2021-04-30 13:31:43 +0200 | [diff] [blame] | 992 | finished = pat_ref_purge_range(appctx->ctx.map.ref, appctx->ctx.cli.i0, appctx->ctx.cli.i1, 100); |
Willy Tarreau | d1d005d | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 993 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
| 994 | |
| 995 | if (!finished) { |
| 996 | /* let's come back later */ |
| 997 | si_rx_endp_more(si); |
| 998 | return 0; |
| 999 | } |
Willy Tarreau | e6a2a0b | 2023-11-04 07:55:37 +0100 | [diff] [blame] | 1000 | |
| 1001 | #if defined(HA_HAVE_MALLOC_TRIM) |
| 1002 | if (finished) { |
| 1003 | malloc_trim(0); |
| 1004 | } |
| 1005 | #endif |
Willy Tarreau | d1d005d | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1006 | return 1; |
| 1007 | } |
| 1008 | |
Willy Tarreau | ff3feeb | 2021-04-30 13:31:43 +0200 | [diff] [blame] | 1009 | /* note: sets appctx->ctx.cli.i0 and appctx->ctx.cli.i1 to the oldest and |
| 1010 | * latest generations to clear, respectively, and will call the clear_map |
| 1011 | * handler. |
| 1012 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1013 | 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] | 1014 | { |
| 1015 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
Willy Tarreau | ff3feeb | 2021-04-30 13:31:43 +0200 | [diff] [blame] | 1016 | const char *gen = NULL; |
| 1017 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1018 | /* Set ACL or MAP flags. */ |
| 1019 | if (args[1][0] == 'm') |
| 1020 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1021 | else |
| 1022 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 1023 | |
Willy Tarreau | ff3feeb | 2021-04-30 13:31:43 +0200 | [diff] [blame] | 1024 | /* For both "map" and "acl" we may have an optional generation |
| 1025 | * number specified using a "@" character before the pattern |
| 1026 | * file name. |
| 1027 | */ |
| 1028 | if (*args[2] == '@') { |
| 1029 | gen = args[2] + 1; |
| 1030 | args++; |
| 1031 | } |
| 1032 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1033 | /* no parameter */ |
| 1034 | if (!*args[2]) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 1035 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1036 | return cli_err(appctx, "Missing map identifier.\n"); |
| 1037 | else |
| 1038 | return cli_err(appctx, "Missing ACL identifier.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | /* lookup into the refs and check the map flag */ |
| 1042 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 1043 | if (!appctx->ctx.map.ref || |
| 1044 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 1045 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1046 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
| 1047 | else |
| 1048 | return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n"); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
Willy Tarreau | ff3feeb | 2021-04-30 13:31:43 +0200 | [diff] [blame] | 1051 | /* set the desired generation id in cli.i0/i1 */ |
| 1052 | if (gen) |
| 1053 | appctx->ctx.cli.i1 = appctx->ctx.cli.i0 = str2uic(gen); |
| 1054 | else |
| 1055 | appctx->ctx.cli.i1 = appctx->ctx.cli.i0 = appctx->ctx.map.ref->curr_gen; |
| 1056 | |
Willy Tarreau | d1d005d | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1057 | /* delegate the clearing to the I/O handler which can yield */ |
| 1058 | return 0; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1059 | } |
Willy Tarreau | d1d005d | 2019-12-20 18:22:02 +0100 | [diff] [blame] | 1060 | return 1; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
Willy Tarreau | 7a562ca | 2021-04-30 15:10:01 +0200 | [diff] [blame] | 1063 | /* note: sets appctx->ctx.cli.i0 and appctx->ctx.cli.i1 to the oldest and |
| 1064 | * latest generations to clear, respectively, and will call the clear_map |
| 1065 | * handler. |
| 1066 | */ |
| 1067 | static int cli_parse_commit_map(char **args, char *payload, struct appctx *appctx, void *private) |
| 1068 | { |
| 1069 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1070 | const char *gen = NULL; |
| 1071 | uint genid; |
| 1072 | uint ret; |
| 1073 | |
| 1074 | /* Set ACL or MAP flags. */ |
| 1075 | if (args[1][0] == 'm') |
| 1076 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1077 | else |
| 1078 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 1079 | |
| 1080 | if (*args[2] != '@') |
| 1081 | return cli_err(appctx, "Missing version number.\n"); |
| 1082 | |
| 1083 | /* The generation number is mandatory for a commit. The range |
| 1084 | * of generations that get trashed by a commit starts from the |
| 1085 | * opposite of the current one and ends at the previous one. |
| 1086 | */ |
| 1087 | gen = args[2] + 1; |
| 1088 | genid = str2uic(gen); |
| 1089 | appctx->ctx.cli.i1 = genid - 1; |
| 1090 | appctx->ctx.cli.i0 = appctx->ctx.cli.i1 - ((~0U) >> 1); |
| 1091 | |
| 1092 | /* no parameter */ |
| 1093 | if (!*args[3]) { |
| 1094 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1095 | return cli_err(appctx, "Missing map identifier.\n"); |
| 1096 | else |
| 1097 | return cli_err(appctx, "Missing ACL identifier.\n"); |
| 1098 | } |
| 1099 | |
| 1100 | /* lookup into the refs and check the map flag */ |
| 1101 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[3]); |
| 1102 | if (!appctx->ctx.map.ref || |
| 1103 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1104 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1105 | return cli_err(appctx, "Unknown map identifier. Please use #<id> or <file>.\n"); |
| 1106 | else |
| 1107 | return cli_err(appctx, "Unknown ACL identifier. Please use #<id> or <file>.\n"); |
| 1108 | } |
| 1109 | |
| 1110 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
| 1111 | if (genid - (appctx->ctx.map.ref->curr_gen + 1) < |
| 1112 | appctx->ctx.map.ref->next_gen - appctx->ctx.map.ref->curr_gen) |
| 1113 | ret = pat_ref_commit(appctx->ctx.map.ref, genid); |
| 1114 | else |
| 1115 | ret = 1; |
| 1116 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
| 1117 | |
| 1118 | if (ret != 0) |
| 1119 | return cli_err(appctx, "Version number out of range.\n"); |
| 1120 | |
| 1121 | /* delegate the clearing to the I/O handler which can yield */ |
| 1122 | return 0; |
| 1123 | } |
| 1124 | return 1; |
| 1125 | } |
| 1126 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1127 | /* register cli keywords */ |
| 1128 | |
| 1129 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1130 | { { "add", "acl", NULL }, "add acl [@<ver>] <acl> <pattern> : add an acl entry", cli_parse_add_map, NULL }, |
| 1131 | { { "clear", "acl", NULL }, "clear acl [@<ver>] <acl> : clear the contents of this acl", cli_parse_clear_map, cli_io_handler_clear_map, NULL }, |
| 1132 | { { "commit","acl", NULL }, "commit acl @<ver> <acl> : commit the ACL at this version", cli_parse_commit_map, cli_io_handler_clear_map, NULL }, |
| 1133 | { { "del", "acl", NULL }, "del acl <acl> [<key>|#<ref>] : delete acl entries matching <key>", cli_parse_del_map, NULL }, |
| 1134 | { { "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 }, |
| 1135 | { { "prepare","acl",NULL }, "prepare acl <acl> : prepare a new version for atomic ACL replacement", cli_parse_prepare_map, NULL }, |
| 1136 | { { "show", "acl", NULL }, "show acl [@<ver>] <acl>] : report available acls or dump an acl's contents", cli_parse_show_map, NULL }, |
| 1137 | { { "add", "map", NULL }, "add map [@<ver>] <map> <key> <val> : add a map entry (payload supported instead of key/val)", cli_parse_add_map, NULL }, |
| 1138 | { { "clear", "map", NULL }, "clear map [@<ver>] <map> : clear the contents of this map", cli_parse_clear_map, cli_io_handler_clear_map, NULL }, |
| 1139 | { { "commit","map", NULL }, "commit map @<ver> <map> : commit the map at this version", cli_parse_commit_map, cli_io_handler_clear_map, NULL }, |
| 1140 | { { "del", "map", NULL }, "del map <map> [<key>|#<ref>] : delete map entries matching <key>", cli_parse_del_map, NULL }, |
| 1141 | { { "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 }, |
| 1142 | { { "prepare","map",NULL }, "prepare map <acl> : prepare a new version for atomic map replacement", cli_parse_prepare_map, NULL }, |
| 1143 | { { "set", "map", NULL }, "set map <map> [<key>|#<ref>] <value> : modify a map entry", cli_parse_set_map, NULL }, |
| 1144 | { { "show", "map", NULL }, "show map [@ver] [map] : report available maps or dump a map's contents", cli_parse_show_map, NULL }, |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1145 | { { NULL }, NULL, NULL, NULL } |
| 1146 | }}; |
| 1147 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1148 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1149 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1150 | /* Note: must not be declared <const> as its list will be overwritten |
| 1151 | * |
| 1152 | * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function |
| 1153 | * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the |
| 1154 | * file can be parsed. |
| 1155 | * |
| 1156 | * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function |
| 1157 | * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file. |
| 1158 | * |
| 1159 | * The map_* keywords only emit strings. |
| 1160 | * |
| 1161 | * The output type is only used during the configuration parsing. It is used for detecting |
| 1162 | * compatibility problems. |
| 1163 | * |
| 1164 | * The arguments are: <file>[,<default value>] |
| 1165 | */ |
| 1166 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 1167 | { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR }, |
| 1168 | { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR }, |
| 1169 | { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG }, |
| 1170 | { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB }, |
| 1171 | { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR }, |
| 1172 | { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM }, |
| 1173 | { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END }, |
| 1174 | { "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] | 1175 | { "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] | 1176 | { "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] | 1177 | { "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] | 1178 | |
Thierry FOURNIER | bf65cd4 | 2015-07-20 17:45:02 +0200 | [diff] [blame] | 1179 | { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR }, |
| 1180 | { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG }, |
| 1181 | { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB }, |
| 1182 | { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR }, |
| 1183 | { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM }, |
| 1184 | { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END }, |
| 1185 | { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG }, |
| 1186 | { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT }, |
| 1187 | { "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] | 1188 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 1189 | { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR }, |
| 1190 | { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG }, |
| 1191 | { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB }, |
| 1192 | { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR }, |
| 1193 | { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM }, |
| 1194 | { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END }, |
| 1195 | { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG }, |
| 1196 | { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT }, |
| 1197 | { "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] | 1198 | |
| 1199 | { /* END */ }, |
| 1200 | }}; |
| 1201 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1202 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |