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