Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * MAP management functions. |
| 3 | * |
| 4 | * Copyright 2000-2013 Willy Tarreau <w@1wt.eu> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <limits.h> |
| 14 | #include <stdio.h> |
| 15 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 16 | #include <common/initcall.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 17 | #include <common/standard.h> |
| 18 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 19 | #include <types/applet.h> |
| 20 | #include <types/cli.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 21 | #include <types/global.h> |
| 22 | #include <types/map.h> |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 23 | #include <types/pattern.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 24 | #include <types/stats.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 25 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 26 | #include <proto/applet.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 27 | #include <proto/arg.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 28 | #include <proto/cli.h> |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 29 | #include <proto/log.h> |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 30 | #include <proto/map.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 31 | #include <proto/pattern.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 32 | #include <proto/stream_interface.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 33 | #include <proto/sample.h> |
| 34 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 35 | /* Parse an IPv4 or IPv6 address and store it into the sample. |
| 36 | * The output type is IPv4 or IPv6. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 37 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 38 | int map_parse_ip(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 39 | { |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 40 | int len = strlen(text); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 41 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 42 | if (buf2ip(text, len, &data->u.ipv4)) { |
| 43 | data->type = SMP_T_IPV4; |
| 44 | return 1; |
| 45 | } |
| 46 | if (buf2ip6(text, len, &data->u.ipv6)) { |
| 47 | data->type = SMP_T_IPV6; |
| 48 | return 1; |
| 49 | } |
| 50 | return 0; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /* Parse a string and store a pointer to it into the sample. The original |
| 54 | * string must be left in memory because we return a direct memory reference. |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 55 | * The output type is SMP_T_STR. There is no risk that the data will be |
| 56 | * overwritten because sample_conv_map() makes a const sample with this |
| 57 | * output. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 58 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 59 | int map_parse_str(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 60 | { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 61 | data->u.str.area = (char *)text; |
| 62 | data->u.str.data = strlen(text); |
| 63 | data->u.str.size = data->u.str.data + 1; |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 64 | data->type = SMP_T_STR; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | /* Parse an integer and convert it to a sample. The output type is SINT if the |
| 69 | * number is negative, or UINT if it is positive or null. The function returns |
| 70 | * zero (error) if the number is too large. |
| 71 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 72 | int map_parse_int(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 73 | { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 74 | data->type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 75 | data->u.sint = read_int64(&text, text + strlen(text)); |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 76 | if (*text != '\0') |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 77 | return 0; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 81 | /* This crete and initialize map descriptor. |
| 82 | * Return NULL if out of memory error |
| 83 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 84 | static struct map_descriptor *map_create_descriptor(struct sample_conv *conv) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 85 | { |
| 86 | struct map_descriptor *desc; |
| 87 | |
| 88 | desc = calloc(1, sizeof(*desc)); |
| 89 | if (!desc) |
| 90 | return NULL; |
| 91 | |
| 92 | desc->conv = conv; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 93 | |
| 94 | return desc; |
| 95 | } |
| 96 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 97 | /* This function load the map file according with data type declared into |
| 98 | * the "struct sample_conv". |
| 99 | * |
| 100 | * This function choose the indexation type (ebtree or list) according with |
| 101 | * the type of match needed. |
| 102 | */ |
Thierry FOURNIER | 3def393 | 2015-04-07 11:27:54 +0200 | [diff] [blame] | 103 | int sample_load_map(struct arg *arg, struct sample_conv *conv, |
| 104 | const char *file, int line, char **err) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 105 | { |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 106 | struct map_descriptor *desc; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 107 | |
| 108 | /* create new map descriptor */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 109 | desc = map_create_descriptor(conv); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 110 | if (!desc) { |
| 111 | memprintf(err, "out of memory"); |
| 112 | return 0; |
| 113 | } |
| 114 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 115 | /* Initialize pattern */ |
| 116 | pattern_init_head(&desc->pat); |
| 117 | |
| 118 | /* This is original pattern, must free */ |
| 119 | desc->do_free = 1; |
| 120 | |
| 121 | /* Set the match method. */ |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 122 | desc->pat.match = pat_match_fcts[(long)conv->private]; |
| 123 | desc->pat.parse = pat_parse_fcts[(long)conv->private]; |
| 124 | desc->pat.index = pat_index_fcts[(long)conv->private]; |
| 125 | desc->pat.delete = pat_delete_fcts[(long)conv->private]; |
| 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 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 146 | /* the maps of type IP have a string as defaultvalue. This |
| 147 | * string canbe anipv4 or an ipv6, we must convert it. |
| 148 | */ |
| 149 | if (desc->conv->out_type == SMP_T_ADDR) { |
| 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 | } |
| 156 | if (data.type == SMP_T_IPV4) { |
| 157 | arg[1].type = ARGT_IPV4; |
| 158 | arg[1].data.ipv4 = data.u.ipv4; |
| 159 | } else { |
| 160 | arg[1].type = ARGT_IPV6; |
| 161 | arg[1].data.ipv6 = data.u.ipv6; |
| 162 | } |
| 163 | } |
| 164 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 165 | /* replace the first argument by this definition */ |
| 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 | |
| 323 | static int cli_io_handler_pat_list(struct appctx *appctx) |
| 324 | { |
| 325 | struct stream_interface *si = appctx->owner; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 326 | struct pat_ref_elt *elt; |
| 327 | |
| 328 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
| 329 | /* If we're forced to shut down, we might have to remove our |
| 330 | * reference to the last ref_elt being dumped. |
| 331 | */ |
| 332 | if (appctx->st2 == STAT_ST_LIST) { |
Dragan Dosen | 336a11f | 2018-05-04 16:27:15 +0200 | [diff] [blame] | 333 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) { |
| 334 | LIST_DEL(&appctx->ctx.map.bref.users); |
| 335 | LIST_INIT(&appctx->ctx.map.bref.users); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | return 1; |
| 339 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 340 | |
| 341 | switch (appctx->st2) { |
| 342 | |
| 343 | case STAT_ST_INIT: |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 344 | /* the function had not been called yet, let's prepare the |
| 345 | * buffer for a response. We initialize the current stream |
| 346 | * pointer to the first in the global list. When a target |
| 347 | * stream is being destroyed, it is responsible for updating |
| 348 | * this pointer. We know we have reached the end when this |
| 349 | * pointer points back to the head of the streams list. |
| 350 | */ |
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 | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 352 | LIST_INIT(&appctx->ctx.map.bref.users); |
| 353 | appctx->ctx.map.bref.ref = appctx->ctx.map.ref->head.n; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 354 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 355 | appctx->st2 = STAT_ST_LIST; |
| 356 | /* fall through */ |
| 357 | |
| 358 | case STAT_ST_LIST: |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 359 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 360 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 361 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 362 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) { |
| 363 | LIST_DEL(&appctx->ctx.map.bref.users); |
| 364 | LIST_INIT(&appctx->ctx.map.bref.users); |
| 365 | } |
| 366 | |
| 367 | while (appctx->ctx.map.bref.ref != &appctx->ctx.map.ref->head) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 368 | chunk_reset(&trash); |
| 369 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 370 | elt = LIST_ELEM(appctx->ctx.map.bref.ref, struct pat_ref_elt *, list); |
| 371 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 372 | /* build messages */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 373 | if (elt->sample) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 374 | chunk_appendf(&trash, "%p %s %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 375 | elt, elt->pattern, |
| 376 | elt->sample); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 377 | else |
| 378 | chunk_appendf(&trash, "%p %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 379 | elt, elt->pattern); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 380 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 381 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 382 | /* let's try again later from this stream. We add ourselves into |
| 383 | * this stream's users so that it can remove us upon termination. |
| 384 | */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 385 | LIST_ADDQ(&elt->back_refs, &appctx->ctx.map.bref.users); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 386 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 387 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | /* get next list entry and check the end of the list */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 392 | appctx->ctx.map.bref.ref = elt->list.n; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 393 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 394 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 395 | /* fall through */ |
| 396 | |
| 397 | default: |
| 398 | appctx->st2 = STAT_ST_FIN; |
| 399 | return 1; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | static int cli_io_handler_pats_list(struct appctx *appctx) |
| 404 | { |
| 405 | struct stream_interface *si = appctx->owner; |
| 406 | |
| 407 | switch (appctx->st2) { |
| 408 | case STAT_ST_INIT: |
| 409 | /* Display the column headers. If the message cannot be sent, |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 410 | * quit the function with returning 0. The function is called |
| 411 | * later and restarted at the state "STAT_ST_INIT". |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 412 | */ |
| 413 | chunk_reset(&trash); |
| 414 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 415 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 416 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | /* Now, we start the browsing of the references lists. |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 421 | * 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] | 422 | * 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] | 423 | * pat_list_get_next() for returning the first available entry |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 424 | */ |
| 425 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 426 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 427 | appctx->ctx.map.display_flags); |
| 428 | appctx->st2 = STAT_ST_LIST; |
| 429 | /* fall through */ |
| 430 | |
| 431 | case STAT_ST_LIST: |
| 432 | while (appctx->ctx.map.ref) { |
| 433 | chunk_reset(&trash); |
| 434 | |
| 435 | /* Build messages. If the reference is used by another category than |
Joseph Herlant | f43b88b | 2018-11-25 11:48:18 -0800 | [diff] [blame] | 436 | * the listed categories, display the information in the message. |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 437 | */ |
| 438 | chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id, |
| 439 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 440 | appctx->ctx.map.ref->display); |
| 441 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 442 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 443 | /* let's try again later from this stream. We add ourselves into |
| 444 | * this stream's users so that it can remove us upon termination. |
| 445 | */ |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 446 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | /* get next list entry and check the end of the list */ |
| 451 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 452 | appctx->ctx.map.display_flags); |
| 453 | } |
| 454 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 455 | /* fall through */ |
| 456 | |
| 457 | default: |
| 458 | appctx->st2 = STAT_ST_FIN; |
| 459 | return 1; |
| 460 | } |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | static int cli_io_handler_map_lookup(struct appctx *appctx) |
| 465 | { |
| 466 | struct stream_interface *si = appctx->owner; |
| 467 | struct sample sample; |
| 468 | struct pattern *pat; |
| 469 | int match_method; |
| 470 | |
| 471 | switch (appctx->st2) { |
| 472 | case STAT_ST_INIT: |
| 473 | /* Init to the first entry. The list cannot be change */ |
| 474 | appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list); |
| 475 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat); |
| 476 | appctx->st2 = STAT_ST_LIST; |
| 477 | /* fall through */ |
| 478 | |
| 479 | case STAT_ST_LIST: |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 480 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 481 | /* for each lookup type */ |
| 482 | while (appctx->ctx.map.expr) { |
| 483 | /* initialise chunk to build new message */ |
| 484 | chunk_reset(&trash); |
| 485 | |
| 486 | /* execute pattern matching */ |
| 487 | sample.data.type = SMP_T_STR; |
| 488 | sample.flags = SMP_F_CONST; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 489 | sample.data.u.str.data = appctx->ctx.map.chunk.data; |
| 490 | sample.data.u.str.area = appctx->ctx.map.chunk.area; |
Emeric Brun | b5997f7 | 2017-07-03 11:34:05 +0200 | [diff] [blame] | 491 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 492 | if (appctx->ctx.map.expr->pat_head->match && |
| 493 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
| 494 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 495 | else |
| 496 | pat = NULL; |
| 497 | |
| 498 | /* build return message: set type of match */ |
| 499 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 500 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 501 | break; |
| 502 | if (match_method >= PAT_MATCH_NUM) |
| 503 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 504 | else |
| 505 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
| 506 | |
| 507 | /* case sensitive */ |
| 508 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 509 | chunk_appendf(&trash, ", case=insensitive"); |
| 510 | else |
| 511 | chunk_appendf(&trash, ", case=sensitive"); |
| 512 | |
| 513 | /* Display no match, and set default value */ |
| 514 | if (!pat) { |
| 515 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 516 | chunk_appendf(&trash, ", found=no"); |
| 517 | else |
| 518 | chunk_appendf(&trash, ", match=no"); |
| 519 | } |
| 520 | |
| 521 | /* Display match and match info */ |
| 522 | else { |
| 523 | /* display match */ |
| 524 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 525 | chunk_appendf(&trash, ", found=yes"); |
| 526 | else |
| 527 | chunk_appendf(&trash, ", match=yes"); |
| 528 | |
| 529 | /* display index mode */ |
| 530 | if (pat->sflags & PAT_SF_TREE) |
| 531 | chunk_appendf(&trash, ", idx=tree"); |
| 532 | else |
| 533 | chunk_appendf(&trash, ", idx=list"); |
| 534 | |
| 535 | /* display pattern */ |
| 536 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 537 | if (pat->ref && pat->ref->pattern) |
| 538 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 539 | else |
| 540 | chunk_appendf(&trash, ", key=unknown"); |
| 541 | } |
| 542 | else { |
| 543 | if (pat->ref && pat->ref->pattern) |
| 544 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 545 | else |
| 546 | chunk_appendf(&trash, ", pattern=unknown"); |
| 547 | } |
| 548 | |
| 549 | /* display return value */ |
| 550 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 551 | if (pat->data && pat->ref && pat->ref->sample) |
| 552 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
| 553 | smp_to_type[pat->data->type]); |
| 554 | else |
| 555 | chunk_appendf(&trash, ", value=none"); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | chunk_appendf(&trash, "\n"); |
| 560 | |
| 561 | /* display response */ |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 562 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 563 | /* let's try again later from this stream. We add ourselves into |
| 564 | * this stream's users so that it can remove us upon termination. |
| 565 | */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 566 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 567 | si_rx_room_blk(si); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | /* get next entry */ |
| 572 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 573 | &appctx->ctx.map.ref->pat); |
| 574 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 575 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 576 | /* fall through */ |
| 577 | |
| 578 | default: |
| 579 | appctx->st2 = STAT_ST_FIN; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 580 | return 1; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | static void cli_release_mlook(struct appctx *appctx) |
| 585 | { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 586 | free(appctx->ctx.map.chunk.area); |
| 587 | appctx->ctx.map.chunk.area = NULL; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 591 | 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] | 592 | { |
| 593 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 594 | /* Set flags. */ |
| 595 | if (args[1][0] == 'm') |
| 596 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 597 | else |
| 598 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 599 | |
| 600 | /* No parameter. */ |
| 601 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 602 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 603 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 604 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 605 | } |
| 606 | else { |
| 607 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 608 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 609 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 610 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | /* lookup into the maps */ |
| 615 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 616 | if (!appctx->ctx.map.ref) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 617 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 618 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 619 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 620 | } |
| 621 | else { |
| 622 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 623 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 624 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 625 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 626 | return 1; |
| 627 | } |
| 628 | |
| 629 | /* copy input string. The string must be allocated because |
| 630 | * it may be used over multiple iterations. It's released |
| 631 | * at the end and upon abort anyway. |
| 632 | */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 633 | appctx->ctx.map.chunk.data = strlen(args[3]); |
| 634 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.data + 1; |
| 635 | appctx->ctx.map.chunk.area = strdup(args[3]); |
| 636 | if (!appctx->ctx.map.chunk.area) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 637 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 638 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 639 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 640 | return 1; |
| 641 | } |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | return 1; |
| 646 | } |
| 647 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 648 | static void cli_release_show_map(struct appctx *appctx) |
| 649 | { |
| 650 | if (appctx->st2 == STAT_ST_LIST) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 651 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 652 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) |
| 653 | LIST_DEL(&appctx->ctx.map.bref.users); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 654 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 658 | 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] | 659 | { |
| 660 | if (strcmp(args[1], "map") == 0 || |
| 661 | strcmp(args[1], "acl") == 0) { |
| 662 | |
| 663 | /* Set ACL or MAP flags. */ |
| 664 | if (args[1][0] == 'm') |
| 665 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 666 | else |
| 667 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 668 | |
| 669 | /* no parameter: display all map available */ |
| 670 | if (!*args[2]) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 671 | appctx->io_handler = cli_io_handler_pats_list; |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | /* lookup into the refs and check the map flag */ |
| 676 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 677 | if (!appctx->ctx.map.ref || |
| 678 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 679 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 680 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 681 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 682 | } |
| 683 | else { |
| 684 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 685 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 686 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 687 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 688 | return 1; |
| 689 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 690 | appctx->io_handler = cli_io_handler_pat_list; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 691 | appctx->io_release = cli_release_show_map; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 698 | 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] | 699 | { |
| 700 | if (strcmp(args[1], "map") == 0) { |
| 701 | char *err; |
| 702 | |
| 703 | /* Set flags. */ |
| 704 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 705 | |
| 706 | /* Expect three parameters: map name, key and new value. */ |
| 707 | if (!*args[2] || !*args[3] || !*args[4]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 708 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 709 | appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 710 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 711 | return 1; |
| 712 | } |
| 713 | |
| 714 | /* Lookup the reference in the maps. */ |
| 715 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 716 | if (!appctx->ctx.map.ref) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 717 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 718 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 719 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 720 | return 1; |
| 721 | } |
| 722 | |
| 723 | /* If the entry identifier start with a '#', it is considered as |
| 724 | * pointer id |
| 725 | */ |
| 726 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 727 | struct pat_ref_elt *ref; |
| 728 | long long int conv; |
| 729 | char *error; |
| 730 | |
| 731 | /* Convert argument to integer value. */ |
| 732 | conv = strtoll(&args[3][1], &error, 16); |
| 733 | if (*error != '\0') { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 734 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 735 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 736 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 737 | return 1; |
| 738 | } |
| 739 | |
| 740 | /* Convert and check integer to pointer. */ |
| 741 | ref = (struct pat_ref_elt *)(long)conv; |
| 742 | if ((long long int)(long)ref != conv) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 743 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 744 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 745 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 746 | return 1; |
| 747 | } |
| 748 | |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 749 | /* Try to modify the entry. */ |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 750 | err = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 751 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 752 | 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] | 753 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 754 | if (err) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 755 | memprintf(&err, "%s.\n", err); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 756 | appctx->ctx.cli.err = err; |
| 757 | appctx->st0 = CLI_ST_PRINT_FREE; |
| 758 | } |
| 759 | else { |
| 760 | appctx->ctx.cli.severity = LOG_ERR; |
| 761 | appctx->ctx.cli.msg = "Failed to update an entry.\n"; |
| 762 | appctx->st0 = CLI_ST_PRINT; |
| 763 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 764 | return 1; |
| 765 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 766 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 767 | } |
| 768 | else { |
| 769 | /* Else, use the entry identifier as pattern |
| 770 | * string, and update the value. |
| 771 | */ |
| 772 | err = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 773 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 774 | 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] | 775 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 776 | if (err) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 777 | memprintf(&err, "%s.\n", err); |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 778 | appctx->ctx.cli.err = err; |
| 779 | appctx->st0 = CLI_ST_PRINT_FREE; |
| 780 | } |
| 781 | else { |
| 782 | appctx->ctx.cli.severity = LOG_ERR; |
| 783 | appctx->ctx.cli.msg = "Failed to update an entry.\n"; |
| 784 | appctx->st0 = CLI_ST_PRINT; |
| 785 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 786 | return 1; |
| 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 | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 798 | static int map_add_key_value(struct appctx *appctx, const char *key, const char *value, char **err) |
| 799 | { |
| 800 | int ret; |
| 801 | |
| 802 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
| 803 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 804 | ret = pat_ref_add(appctx->ctx.map.ref, key, value, err); |
| 805 | else |
| 806 | ret = pat_ref_add(appctx->ctx.map.ref, key, NULL, err); |
| 807 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
| 808 | |
| 809 | return ret; |
| 810 | } |
| 811 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 812 | 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] | 813 | { |
| 814 | if (strcmp(args[1], "map") == 0 || |
| 815 | strcmp(args[1], "acl") == 0) { |
| 816 | int ret; |
| 817 | char *err; |
| 818 | |
| 819 | /* Set flags. */ |
| 820 | if (args[1][0] == 'm') |
| 821 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 822 | else |
| 823 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 824 | |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 825 | /* If the keyword is "map", we expect: |
| 826 | * - three parameters if there is no payload |
| 827 | * - one parameter if there is a payload |
| 828 | * If it is "acl", we expect only two parameters |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 829 | */ |
| 830 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 831 | if ((!payload && (!*args[2] || !*args[3] || !*args[4])) || |
| 832 | (payload && !*args[2])) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 833 | appctx->ctx.cli.severity = LOG_ERR; |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 834 | appctx->ctx.cli.msg = "'add map' expects three parameters (map identifier, key and value) or one parameter (map identifier) and a payload\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 835 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 836 | return 1; |
| 837 | } |
| 838 | } |
| 839 | else { |
| 840 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 841 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 842 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 843 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 844 | return 1; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | /* Lookup for the reference. */ |
| 849 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 850 | if (!appctx->ctx.map.ref) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 851 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 852 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 853 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 854 | } |
| 855 | else { |
| 856 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 857 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 858 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 859 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 860 | return 1; |
| 861 | } |
| 862 | |
| 863 | /* The command "add acl" is prohibited if the reference |
| 864 | * use samples. |
| 865 | */ |
| 866 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 867 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 868 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 869 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 870 | "You must use the command 'add map' to add values.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 871 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 872 | return 1; |
| 873 | } |
| 874 | |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 875 | /* Add value(s). */ |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 876 | err = NULL; |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 877 | if (!payload) { |
| 878 | ret = map_add_key_value(appctx, args[3], args[4], &err); |
| 879 | if (!ret) { |
| 880 | if (err) { |
| 881 | memprintf(&err, "%s.\n", err); |
| 882 | appctx->ctx.cli.err = err; |
| 883 | appctx->st0 = CLI_ST_PRINT_FREE; |
| 884 | } |
| 885 | else { |
| 886 | appctx->ctx.cli.severity = LOG_ERR; |
| 887 | appctx->ctx.cli.msg = "Failed to add an entry.\n"; |
| 888 | appctx->st0 = CLI_ST_PRINT; |
| 889 | } |
| 890 | return 1; |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 891 | } |
Aurélien Nephtali | 25650ce | 2018-04-18 14:04:47 +0200 | [diff] [blame] | 892 | } |
| 893 | else { |
| 894 | const char *end = payload + strlen(payload); |
| 895 | |
| 896 | while (payload < end) { |
| 897 | char *key, *value; |
| 898 | size_t l; |
| 899 | |
| 900 | /* key */ |
| 901 | key = payload; |
| 902 | l = strcspn(key, " \t"); |
| 903 | payload += l; |
| 904 | |
| 905 | if (!*payload && appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 906 | memprintf(&err, "Missing value for key '%s'.\n", key); |
| 907 | appctx->ctx.cli.err = err; |
| 908 | appctx->st0 = CLI_ST_PRINT_FREE; |
| 909 | return 1; |
| 910 | } |
| 911 | key[l] = 0; |
| 912 | payload++; |
| 913 | |
| 914 | /* value */ |
| 915 | payload += strspn(payload, " \t"); |
| 916 | value = payload; |
| 917 | l = strcspn(value, "\n"); |
| 918 | payload += l; |
| 919 | if (*payload) |
| 920 | payload++; |
| 921 | value[l] = 0; |
| 922 | |
| 923 | ret = map_add_key_value(appctx, key, value, &err); |
| 924 | if (!ret) { |
| 925 | if (err) { |
| 926 | memprintf(&err, "%s.\n", err); |
| 927 | appctx->ctx.cli.err = err; |
| 928 | appctx->st0 = CLI_ST_PRINT_FREE; |
| 929 | } |
| 930 | else { |
| 931 | appctx->ctx.cli.severity = LOG_ERR; |
| 932 | appctx->ctx.cli.msg = "Failed to add a key.\n"; |
| 933 | appctx->st0 = CLI_ST_PRINT; |
| 934 | } |
| 935 | return 1; |
| 936 | } |
Aurélien Nephtali | 9a4da68 | 2018-04-16 19:02:42 +0200 | [diff] [blame] | 937 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /* The add is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 941 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 942 | return 1; |
| 943 | } |
| 944 | |
| 945 | return 0; |
| 946 | } |
| 947 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 948 | 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] | 949 | { |
| 950 | if (args[1][0] == 'm') |
| 951 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 952 | else |
| 953 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 954 | |
| 955 | /* Expect two parameters: map name and key. */ |
| 956 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 957 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 958 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 959 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 960 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 961 | return 1; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | else { |
| 966 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 967 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 968 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 969 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 970 | return 1; |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | /* Lookup the reference in the maps. */ |
| 975 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 976 | if (!appctx->ctx.map.ref || |
| 977 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 978 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 979 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 980 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 981 | return 1; |
| 982 | } |
| 983 | |
| 984 | /* If the entry identifier start with a '#', it is considered as |
| 985 | * pointer id |
| 986 | */ |
| 987 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 988 | struct pat_ref_elt *ref; |
| 989 | long long int conv; |
| 990 | char *error; |
| 991 | |
| 992 | /* Convert argument to integer value. */ |
| 993 | conv = strtoll(&args[3][1], &error, 16); |
| 994 | if (*error != '\0') { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 995 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 996 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 997 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 998 | return 1; |
| 999 | } |
| 1000 | |
| 1001 | /* Convert and check integer to pointer. */ |
| 1002 | ref = (struct pat_ref_elt *)(long)conv; |
| 1003 | if ((long long int)(long)ref != conv) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1004 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1005 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1006 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1007 | return 1; |
| 1008 | } |
| 1009 | |
| 1010 | /* Try to delete the entry. */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1011 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1012 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1013 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1014 | /* The entry is not found, send message. */ |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1015 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1016 | appctx->ctx.cli.msg = "Key not found.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1017 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1018 | return 1; |
| 1019 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1020 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1021 | } |
| 1022 | else { |
| 1023 | /* Else, use the entry identifier as pattern |
| 1024 | * string and try to delete the entry. |
| 1025 | */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1026 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1027 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1028 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1029 | /* The entry is not found, send message. */ |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1030 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1031 | appctx->ctx.cli.msg = "Key not found.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1032 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1033 | return 1; |
| 1034 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1035 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /* The deletion is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1039 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1040 | return 1; |
| 1041 | } |
| 1042 | |
| 1043 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1044 | 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] | 1045 | { |
| 1046 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1047 | /* Set ACL or MAP flags. */ |
| 1048 | if (args[1][0] == 'm') |
| 1049 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1050 | else |
| 1051 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 1052 | |
| 1053 | /* no parameter */ |
| 1054 | if (!*args[2]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1055 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1056 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1057 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1058 | } |
| 1059 | else { |
| 1060 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1061 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1062 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1063 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1064 | return 1; |
| 1065 | } |
| 1066 | |
| 1067 | /* lookup into the refs and check the map flag */ |
| 1068 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 1069 | if (!appctx->ctx.map.ref || |
| 1070 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1071 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1072 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1073 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1074 | } |
| 1075 | else { |
| 1076 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1077 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1078 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1079 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1080 | return 1; |
| 1081 | } |
| 1082 | |
| 1083 | /* Clear all. */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1084 | HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1085 | pat_ref_prune(appctx->ctx.map.ref); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1086 | HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1087 | |
| 1088 | /* return response */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1089 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1090 | return 1; |
| 1091 | } |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | /* register cli keywords */ |
| 1096 | |
| 1097 | static struct cli_kw_list cli_kws = {{ },{ |
| 1098 | { { "add", "acl", NULL }, "add acl : add acl entry", cli_parse_add_map, NULL }, |
| 1099 | { { "clear", "acl", NULL }, "clear acl <id> : clear the content of this acl", cli_parse_clear_map, NULL }, |
| 1100 | { { "del", "acl", NULL }, "del acl : delete acl entry", cli_parse_del_map, NULL }, |
| 1101 | { { "get", "acl", NULL }, "get acl : report the patterns matching a sample for an ACL", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook }, |
| 1102 | { { "show", "acl", NULL }, "show acl [id] : report available acls or dump an acl's contents", cli_parse_show_map, NULL }, |
| 1103 | { { "add", "map", NULL }, "add map : add map entry", cli_parse_add_map, NULL }, |
| 1104 | { { "clear", "map", NULL }, "clear map <id> : clear the content of this map", cli_parse_clear_map, NULL }, |
| 1105 | { { "del", "map", NULL }, "del map : delete map entry", cli_parse_del_map, NULL }, |
Nenad Merdanovic | 96c1571 | 2017-03-12 22:01:36 +0100 | [diff] [blame] | 1106 | { { "get", "map", NULL }, "get map : report the keys and values matching a sample for a map", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook }, |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1107 | { { "set", "map", NULL }, "set map : modify map entry", cli_parse_set_map, NULL }, |
| 1108 | { { "show", "map", NULL }, "show map [id] : report available maps or dump a map's contents", cli_parse_show_map, NULL }, |
| 1109 | { { NULL }, NULL, NULL, NULL } |
| 1110 | }}; |
| 1111 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1112 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1113 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1114 | /* Note: must not be declared <const> as its list will be overwritten |
| 1115 | * |
| 1116 | * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function |
| 1117 | * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the |
| 1118 | * file can be parsed. |
| 1119 | * |
| 1120 | * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function |
| 1121 | * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file. |
| 1122 | * |
| 1123 | * The map_* keywords only emit strings. |
| 1124 | * |
| 1125 | * The output type is only used during the configuration parsing. It is used for detecting |
| 1126 | * compatibility problems. |
| 1127 | * |
| 1128 | * The arguments are: <file>[,<default value>] |
| 1129 | */ |
| 1130 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 1131 | { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR }, |
| 1132 | { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR }, |
| 1133 | { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG }, |
| 1134 | { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB }, |
| 1135 | { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR }, |
| 1136 | { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM }, |
| 1137 | { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END }, |
| 1138 | { "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] | 1139 | { "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] | 1140 | { "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] | 1141 | { "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] | 1142 | |
Thierry FOURNIER | bf65cd4 | 2015-07-20 17:45:02 +0200 | [diff] [blame] | 1143 | { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR }, |
| 1144 | { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG }, |
| 1145 | { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB }, |
| 1146 | { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR }, |
| 1147 | { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM }, |
| 1148 | { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END }, |
| 1149 | { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG }, |
| 1150 | { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT }, |
| 1151 | { "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] | 1152 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 1153 | { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR }, |
| 1154 | { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG }, |
| 1155 | { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB }, |
| 1156 | { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR }, |
| 1157 | { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM }, |
| 1158 | { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END }, |
| 1159 | { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG }, |
| 1160 | { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT }, |
| 1161 | { "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] | 1162 | |
| 1163 | { /* END */ }, |
| 1164 | }}; |
| 1165 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1166 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |