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 | |
| 16 | #include <common/standard.h> |
| 17 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 18 | #include <types/applet.h> |
| 19 | #include <types/cli.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 20 | #include <types/global.h> |
| 21 | #include <types/map.h> |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 22 | #include <types/pattern.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 23 | #include <types/stats.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 24 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 25 | #include <proto/applet.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 26 | #include <proto/arg.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 27 | #include <proto/cli.h> |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 28 | #include <proto/log.h> |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 29 | #include <proto/map.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 30 | #include <proto/pattern.h> |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 31 | #include <proto/stream_interface.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 32 | #include <proto/sample.h> |
| 33 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 34 | /* Parse an IPv4 or IPv6 address and store it into the sample. |
| 35 | * The output type is IPv4 or IPv6. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 36 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 37 | int map_parse_ip(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 38 | { |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 39 | int len = strlen(text); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 40 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 41 | if (buf2ip(text, len, &data->u.ipv4)) { |
| 42 | data->type = SMP_T_IPV4; |
| 43 | return 1; |
| 44 | } |
| 45 | if (buf2ip6(text, len, &data->u.ipv6)) { |
| 46 | data->type = SMP_T_IPV6; |
| 47 | return 1; |
| 48 | } |
| 49 | return 0; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* Parse a string and store a pointer to it into the sample. The original |
| 53 | * 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] | 54 | * The output type is SMP_T_STR. There is no risk that the data will be |
| 55 | * overwritten because sample_conv_map() makes a const sample with this |
| 56 | * output. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 57 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 58 | int map_parse_str(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 59 | { |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 60 | data->u.str.str = (char *)text; |
| 61 | data->u.str.len = strlen(text); |
| 62 | data->u.str.size = data->u.str.len + 1; |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 63 | data->type = SMP_T_STR; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 64 | return 1; |
| 65 | } |
| 66 | |
| 67 | /* Parse an integer and convert it to a sample. The output type is SINT if the |
| 68 | * number is negative, or UINT if it is positive or null. The function returns |
| 69 | * zero (error) if the number is too large. |
| 70 | */ |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 71 | int map_parse_int(const char *text, struct sample_data *data) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 72 | { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 73 | data->type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 74 | data->u.sint = read_int64(&text, text + strlen(text)); |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 75 | if (*text != '\0') |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 76 | return 0; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 77 | return 1; |
| 78 | } |
| 79 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 80 | /* This crete and initialize map descriptor. |
| 81 | * Return NULL if out of memory error |
| 82 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 83 | static struct map_descriptor *map_create_descriptor(struct sample_conv *conv) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 84 | { |
| 85 | struct map_descriptor *desc; |
| 86 | |
| 87 | desc = calloc(1, sizeof(*desc)); |
| 88 | if (!desc) |
| 89 | return NULL; |
| 90 | |
| 91 | desc->conv = conv; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 92 | |
| 93 | return desc; |
| 94 | } |
| 95 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 96 | /* This function load the map file according with data type declared into |
| 97 | * the "struct sample_conv". |
| 98 | * |
| 99 | * This function choose the indexation type (ebtree or list) according with |
| 100 | * the type of match needed. |
| 101 | */ |
Thierry FOURNIER | 3def393 | 2015-04-07 11:27:54 +0200 | [diff] [blame] | 102 | int sample_load_map(struct arg *arg, struct sample_conv *conv, |
| 103 | const char *file, int line, char **err) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 104 | { |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 105 | struct map_descriptor *desc; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 106 | |
| 107 | /* create new map descriptor */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 108 | desc = map_create_descriptor(conv); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 109 | if (!desc) { |
| 110 | memprintf(err, "out of memory"); |
| 111 | return 0; |
| 112 | } |
| 113 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 114 | /* Initialize pattern */ |
| 115 | pattern_init_head(&desc->pat); |
| 116 | |
| 117 | /* This is original pattern, must free */ |
| 118 | desc->do_free = 1; |
| 119 | |
| 120 | /* Set the match method. */ |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 121 | desc->pat.match = pat_match_fcts[(long)conv->private]; |
| 122 | desc->pat.parse = pat_parse_fcts[(long)conv->private]; |
| 123 | desc->pat.index = pat_index_fcts[(long)conv->private]; |
| 124 | desc->pat.delete = pat_delete_fcts[(long)conv->private]; |
| 125 | desc->pat.prune = pat_prune_fcts[(long)conv->private]; |
| 126 | desc->pat.expect_type = pat_match_types[(long)conv->private]; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 127 | |
| 128 | /* Set the output parse method. */ |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 129 | switch (desc->conv->out_type) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 130 | case SMP_T_STR: desc->pat.parse_smp = map_parse_str; break; |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 131 | case SMP_T_SINT: desc->pat.parse_smp = map_parse_int; break; |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 132 | case SMP_T_ADDR: desc->pat.parse_smp = map_parse_ip; break; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 133 | default: |
| 134 | memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.", |
| 135 | conv->out_type); |
Andreas Seltenreich | 78f3595 | 2016-03-03 20:32:23 +0100 | [diff] [blame] | 136 | free(desc); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
Thierry FOURNIER | 39bef45 | 2014-01-29 13:29:45 +0100 | [diff] [blame] | 140 | /* Load map. */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 141 | if (!pattern_read_from_file(&desc->pat, PAT_REF_MAP, arg[0].data.str.str, PAT_MF_NO_DNS, |
Thierry FOURNIER | 94580c9 | 2014-02-11 14:36:45 +0100 | [diff] [blame] | 142 | 1, err, file, line)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 143 | return 0; |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 144 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 145 | /* the maps of type IP have a string as defaultvalue. This |
| 146 | * string canbe anipv4 or an ipv6, we must convert it. |
| 147 | */ |
| 148 | if (desc->conv->out_type == SMP_T_ADDR) { |
| 149 | struct sample_data data; |
| 150 | if (!map_parse_ip(arg[1].data.str.str, &data)) { |
| 151 | memprintf(err, "map: cannot parse default ip <%s>.", arg[1].data.str.str); |
| 152 | return 0; |
| 153 | } |
| 154 | if (data.type == SMP_T_IPV4) { |
| 155 | arg[1].type = ARGT_IPV4; |
| 156 | arg[1].data.ipv4 = data.u.ipv4; |
| 157 | } else { |
| 158 | arg[1].type = ARGT_IPV6; |
| 159 | arg[1].data.ipv6 = data.u.ipv6; |
| 160 | } |
| 161 | } |
| 162 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 163 | /* replace the first argument by this definition */ |
| 164 | arg[0].type = ARGT_MAP; |
| 165 | arg[0].data.map = desc; |
| 166 | |
| 167 | return 1; |
| 168 | } |
| 169 | |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 170 | 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] | 171 | { |
| 172 | struct map_descriptor *desc; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 173 | struct pattern *pat; |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 174 | struct chunk *str; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 175 | |
| 176 | /* get config */ |
| 177 | desc = arg_p[0].data.map; |
| 178 | |
| 179 | /* Execute the match function. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 180 | pat = pattern_exec_match(&desc->pat, smp, 1); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 181 | |
| 182 | /* Match case. */ |
| 183 | if (pat) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 184 | if (pat->data) { |
Thierry Fournier | 8feaa66 | 2016-02-10 22:55:20 +0100 | [diff] [blame] | 185 | /* In the regm case, merge the sample with the input. */ |
| 186 | if ((long)private == PAT_MATCH_REGM) { |
| 187 | str = get_trash_chunk(); |
| 188 | str->len = exp_replace(str->str, str->size, smp->data.u.str.str, |
| 189 | pat->data->u.str.str, |
| 190 | (regmatch_t *)smp->ctx.a[0]); |
| 191 | if (str->len == -1) |
| 192 | return 0; |
| 193 | smp->data.u.str = *str; |
| 194 | return 1; |
| 195 | } |
| 196 | /* Copy sample. */ |
Thierry FOURNIER | 5cc18d4 | 2015-08-19 09:02:36 +0200 | [diff] [blame] | 197 | smp->data = *pat->data; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 198 | smp->flags |= SMP_F_CONST; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 199 | return 1; |
| 200 | } |
| 201 | |
| 202 | /* Return just int sample containing 1. */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 203 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 204 | smp->data.u.sint = 1; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 205 | return 1; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 208 | /* If no default value avalaible, the converter fails. */ |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 209 | if (arg_p[1].type == ARGT_STOP) |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 210 | return 0; |
| 211 | |
| 212 | /* Return the default value. */ |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 213 | switch (desc->conv->out_type) { |
| 214 | |
| 215 | case SMP_T_STR: |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 216 | smp->data.type = SMP_T_STR; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 217 | smp->flags |= SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 218 | smp->data.u.str = arg_p[1].data.str; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 219 | break; |
| 220 | |
Thierry FOURNIER | 07ee64e | 2015-07-06 23:43:03 +0200 | [diff] [blame] | 221 | case SMP_T_SINT: |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 222 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 223 | smp->data.u.sint = arg_p[1].data.sint; |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 224 | break; |
| 225 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 226 | case SMP_T_ADDR: |
| 227 | if (arg_p[1].type == ARGT_IPV4) { |
| 228 | smp->data.type = SMP_T_IPV4; |
| 229 | smp->data.u.ipv4 = arg_p[1].data.ipv4; |
| 230 | } else { |
| 231 | smp->data.type = SMP_T_IPV6; |
| 232 | smp->data.u.ipv6 = arg_p[1].data.ipv6; |
| 233 | } |
Thierry FOURNIER | 933e5de | 2015-03-13 00:10:16 +0100 | [diff] [blame] | 234 | break; |
| 235 | } |
| 236 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 237 | return 1; |
| 238 | } |
| 239 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 240 | /* This function is used with map and acl management. It permits to browse |
| 241 | * each reference. The variable <getnext> must contain the current node, |
| 242 | * <end> point to the root node and the <flags> permit to filter required |
| 243 | * nodes. |
| 244 | */ |
| 245 | static inline |
| 246 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 247 | unsigned int flags) |
| 248 | { |
| 249 | struct pat_ref *ref = getnext; |
| 250 | |
| 251 | while (1) { |
| 252 | |
| 253 | /* Get next list entry. */ |
| 254 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
| 255 | |
| 256 | /* If the entry is the last of the list, return NULL. */ |
| 257 | if (&ref->list == end) |
| 258 | return NULL; |
| 259 | |
| 260 | /* If the entry match the flag, return it. */ |
| 261 | if (ref->flags & flags) |
| 262 | return ref; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | static inline |
| 267 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 268 | { |
| 269 | int id; |
| 270 | char *error; |
| 271 | |
| 272 | /* If the reference starts by a '#', this is numeric id. */ |
| 273 | if (reference[0] == '#') { |
| 274 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 275 | id = strtol(reference + 1, &error, 10); |
| 276 | if (*error != '\0') |
| 277 | return NULL; |
| 278 | |
| 279 | /* Perform the unique id lookup. */ |
| 280 | return pat_ref_lookupid(id); |
| 281 | } |
| 282 | |
| 283 | /* Perform the string lookup. */ |
| 284 | return pat_ref_lookup(reference); |
| 285 | } |
| 286 | |
| 287 | /* This function is used with map and acl management. It permits to browse |
| 288 | * each reference. |
| 289 | */ |
| 290 | static inline |
| 291 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 292 | { |
| 293 | struct pattern_expr *expr; |
| 294 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 295 | if (&expr->list == end) |
| 296 | return NULL; |
| 297 | return expr; |
| 298 | } |
| 299 | |
| 300 | static int cli_io_handler_pat_list(struct appctx *appctx) |
| 301 | { |
| 302 | struct stream_interface *si = appctx->owner; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 303 | struct pat_ref_elt *elt; |
| 304 | |
| 305 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
| 306 | /* If we're forced to shut down, we might have to remove our |
| 307 | * reference to the last ref_elt being dumped. |
| 308 | */ |
| 309 | if (appctx->st2 == STAT_ST_LIST) { |
| 310 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 311 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 312 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 313 | } |
| 314 | } |
| 315 | return 1; |
| 316 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 317 | |
| 318 | switch (appctx->st2) { |
| 319 | |
| 320 | case STAT_ST_INIT: |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 321 | /* the function had not been called yet, let's prepare the |
| 322 | * buffer for a response. We initialize the current stream |
| 323 | * pointer to the first in the global list. When a target |
| 324 | * stream is being destroyed, it is responsible for updating |
| 325 | * this pointer. We know we have reached the end when this |
| 326 | * pointer points back to the head of the streams list. |
| 327 | */ |
| 328 | LIST_INIT(&appctx->ctx.map.bref.users); |
| 329 | appctx->ctx.map.bref.ref = appctx->ctx.map.ref->head.n; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 330 | appctx->st2 = STAT_ST_LIST; |
| 331 | /* fall through */ |
| 332 | |
| 333 | case STAT_ST_LIST: |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 334 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) { |
| 335 | LIST_DEL(&appctx->ctx.map.bref.users); |
| 336 | LIST_INIT(&appctx->ctx.map.bref.users); |
| 337 | } |
| 338 | |
| 339 | while (appctx->ctx.map.bref.ref != &appctx->ctx.map.ref->head) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 340 | chunk_reset(&trash); |
| 341 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 342 | elt = LIST_ELEM(appctx->ctx.map.bref.ref, struct pat_ref_elt *, list); |
| 343 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 344 | /* build messages */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 345 | if (elt->sample) |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 346 | chunk_appendf(&trash, "%p %s %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 347 | elt, elt->pattern, |
| 348 | elt->sample); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 349 | else |
| 350 | chunk_appendf(&trash, "%p %s\n", |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 351 | elt, elt->pattern); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 352 | |
| 353 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 354 | /* let's try again later from this stream. We add ourselves into |
| 355 | * this stream's users so that it can remove us upon termination. |
| 356 | */ |
| 357 | si_applet_cant_put(si); |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 358 | LIST_ADDQ(&elt->back_refs, &appctx->ctx.map.bref.users); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /* get next list entry and check the end of the list */ |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 363 | appctx->ctx.map.bref.ref = elt->list.n; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | appctx->st2 = STAT_ST_FIN; |
| 367 | /* fall through */ |
| 368 | |
| 369 | default: |
| 370 | appctx->st2 = STAT_ST_FIN; |
| 371 | return 1; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | static int cli_io_handler_pats_list(struct appctx *appctx) |
| 376 | { |
| 377 | struct stream_interface *si = appctx->owner; |
| 378 | |
| 379 | switch (appctx->st2) { |
| 380 | case STAT_ST_INIT: |
| 381 | /* Display the column headers. If the message cannot be sent, |
| 382 | * quit the fucntion with returning 0. The function is called |
| 383 | * later and restart at the state "STAT_ST_INIT". |
| 384 | */ |
| 385 | chunk_reset(&trash); |
| 386 | chunk_appendf(&trash, "# id (file) description\n"); |
| 387 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 388 | si_applet_cant_put(si); |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | /* Now, we start the browsing of the references lists. |
| 393 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 394 | * available field of this pointer is <list>. It is used with the function |
| 395 | * pat_list_get_next() for retruning the first available entry |
| 396 | */ |
| 397 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 398 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 399 | appctx->ctx.map.display_flags); |
| 400 | appctx->st2 = STAT_ST_LIST; |
| 401 | /* fall through */ |
| 402 | |
| 403 | case STAT_ST_LIST: |
| 404 | while (appctx->ctx.map.ref) { |
| 405 | chunk_reset(&trash); |
| 406 | |
| 407 | /* Build messages. If the reference is used by another category than |
| 408 | * the listed categorie, display the information in the massage. |
| 409 | */ |
| 410 | chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id, |
| 411 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 412 | appctx->ctx.map.ref->display); |
| 413 | |
| 414 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 415 | /* let's try again later from this stream. We add ourselves into |
| 416 | * this stream's users so that it can remove us upon termination. |
| 417 | */ |
| 418 | si_applet_cant_put(si); |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | /* get next list entry and check the end of the list */ |
| 423 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 424 | appctx->ctx.map.display_flags); |
| 425 | } |
| 426 | |
| 427 | appctx->st2 = STAT_ST_FIN; |
| 428 | /* fall through */ |
| 429 | |
| 430 | default: |
| 431 | appctx->st2 = STAT_ST_FIN; |
| 432 | return 1; |
| 433 | } |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | static int cli_io_handler_map_lookup(struct appctx *appctx) |
| 438 | { |
| 439 | struct stream_interface *si = appctx->owner; |
| 440 | struct sample sample; |
| 441 | struct pattern *pat; |
| 442 | int match_method; |
| 443 | |
| 444 | switch (appctx->st2) { |
| 445 | case STAT_ST_INIT: |
| 446 | /* Init to the first entry. The list cannot be change */ |
| 447 | appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list); |
| 448 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat); |
| 449 | appctx->st2 = STAT_ST_LIST; |
| 450 | /* fall through */ |
| 451 | |
| 452 | case STAT_ST_LIST: |
| 453 | /* for each lookup type */ |
| 454 | while (appctx->ctx.map.expr) { |
| 455 | /* initialise chunk to build new message */ |
| 456 | chunk_reset(&trash); |
| 457 | |
| 458 | /* execute pattern matching */ |
| 459 | sample.data.type = SMP_T_STR; |
| 460 | sample.flags = SMP_F_CONST; |
| 461 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 462 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
| 463 | if (appctx->ctx.map.expr->pat_head->match && |
| 464 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
| 465 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 466 | else |
| 467 | pat = NULL; |
| 468 | |
| 469 | /* build return message: set type of match */ |
| 470 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 471 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 472 | break; |
| 473 | if (match_method >= PAT_MATCH_NUM) |
| 474 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 475 | else |
| 476 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
| 477 | |
| 478 | /* case sensitive */ |
| 479 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 480 | chunk_appendf(&trash, ", case=insensitive"); |
| 481 | else |
| 482 | chunk_appendf(&trash, ", case=sensitive"); |
| 483 | |
| 484 | /* Display no match, and set default value */ |
| 485 | if (!pat) { |
| 486 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 487 | chunk_appendf(&trash, ", found=no"); |
| 488 | else |
| 489 | chunk_appendf(&trash, ", match=no"); |
| 490 | } |
| 491 | |
| 492 | /* Display match and match info */ |
| 493 | else { |
| 494 | /* display match */ |
| 495 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 496 | chunk_appendf(&trash, ", found=yes"); |
| 497 | else |
| 498 | chunk_appendf(&trash, ", match=yes"); |
| 499 | |
| 500 | /* display index mode */ |
| 501 | if (pat->sflags & PAT_SF_TREE) |
| 502 | chunk_appendf(&trash, ", idx=tree"); |
| 503 | else |
| 504 | chunk_appendf(&trash, ", idx=list"); |
| 505 | |
| 506 | /* display pattern */ |
| 507 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 508 | if (pat->ref && pat->ref->pattern) |
| 509 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 510 | else |
| 511 | chunk_appendf(&trash, ", key=unknown"); |
| 512 | } |
| 513 | else { |
| 514 | if (pat->ref && pat->ref->pattern) |
| 515 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 516 | else |
| 517 | chunk_appendf(&trash, ", pattern=unknown"); |
| 518 | } |
| 519 | |
| 520 | /* display return value */ |
| 521 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 522 | if (pat->data && pat->ref && pat->ref->sample) |
| 523 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
| 524 | smp_to_type[pat->data->type]); |
| 525 | else |
| 526 | chunk_appendf(&trash, ", value=none"); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | chunk_appendf(&trash, "\n"); |
| 531 | |
| 532 | /* display response */ |
| 533 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 534 | /* let's try again later from this stream. We add ourselves into |
| 535 | * this stream's users so that it can remove us upon termination. |
| 536 | */ |
| 537 | si_applet_cant_put(si); |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | /* get next entry */ |
| 542 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 543 | &appctx->ctx.map.ref->pat); |
| 544 | } |
| 545 | |
| 546 | appctx->st2 = STAT_ST_FIN; |
| 547 | /* fall through */ |
| 548 | |
| 549 | default: |
| 550 | appctx->st2 = STAT_ST_FIN; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 551 | return 1; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | static void cli_release_mlook(struct appctx *appctx) |
| 556 | { |
| 557 | free(appctx->ctx.map.chunk.str); |
| 558 | appctx->ctx.map.chunk.str = NULL; |
| 559 | } |
| 560 | |
| 561 | |
| 562 | static int cli_parse_get_map(char **args, struct appctx *appctx, void *private) |
| 563 | { |
| 564 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 565 | /* Set flags. */ |
| 566 | if (args[1][0] == 'm') |
| 567 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 568 | else |
| 569 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 570 | |
| 571 | /* No parameter. */ |
| 572 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 573 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 574 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 575 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 576 | } |
| 577 | else { |
| 578 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 579 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 580 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 581 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 582 | return 1; |
| 583 | } |
| 584 | |
| 585 | /* lookup into the maps */ |
| 586 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 587 | if (!appctx->ctx.map.ref) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 588 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 589 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 590 | 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] | 591 | } |
| 592 | else { |
| 593 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 594 | 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] | 595 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 596 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 597 | return 1; |
| 598 | } |
| 599 | |
| 600 | /* copy input string. The string must be allocated because |
| 601 | * it may be used over multiple iterations. It's released |
| 602 | * at the end and upon abort anyway. |
| 603 | */ |
| 604 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 605 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 606 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 607 | if (!appctx->ctx.map.chunk.str) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 608 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 609 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
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 | return 0; |
| 615 | } |
| 616 | return 1; |
| 617 | } |
| 618 | |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 619 | static void cli_release_show_map(struct appctx *appctx) |
| 620 | { |
| 621 | if (appctx->st2 == STAT_ST_LIST) { |
| 622 | if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) |
| 623 | LIST_DEL(&appctx->ctx.map.bref.users); |
| 624 | } |
| 625 | } |
| 626 | |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 627 | static int cli_parse_show_map(char **args, struct appctx *appctx, void *private) |
| 628 | { |
| 629 | if (strcmp(args[1], "map") == 0 || |
| 630 | strcmp(args[1], "acl") == 0) { |
| 631 | |
| 632 | /* Set ACL or MAP flags. */ |
| 633 | if (args[1][0] == 'm') |
| 634 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 635 | else |
| 636 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 637 | |
| 638 | /* no parameter: display all map available */ |
| 639 | if (!*args[2]) { |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 640 | appctx->io_handler = cli_io_handler_pats_list; |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | /* lookup into the refs and check the map flag */ |
| 645 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 646 | if (!appctx->ctx.map.ref || |
| 647 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 648 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 649 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 650 | 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] | 651 | } |
| 652 | else { |
| 653 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 654 | 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] | 655 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 656 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 657 | return 1; |
| 658 | } |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 659 | appctx->io_handler = cli_io_handler_pat_list; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 660 | appctx->io_release = cli_release_show_map; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int cli_parse_set_map(char **args, struct appctx *appctx, void *private) |
| 668 | { |
| 669 | if (strcmp(args[1], "map") == 0) { |
| 670 | char *err; |
| 671 | |
| 672 | /* Set flags. */ |
| 673 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 674 | |
| 675 | /* Expect three parameters: map name, key and new value. */ |
| 676 | if (!*args[2] || !*args[3] || !*args[4]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 677 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 678 | 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] | 679 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 680 | return 1; |
| 681 | } |
| 682 | |
| 683 | /* Lookup the reference in the maps. */ |
| 684 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 685 | if (!appctx->ctx.map.ref) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 686 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 687 | 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] | 688 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 689 | return 1; |
| 690 | } |
| 691 | |
| 692 | /* If the entry identifier start with a '#', it is considered as |
| 693 | * pointer id |
| 694 | */ |
| 695 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 696 | struct pat_ref_elt *ref; |
| 697 | long long int conv; |
| 698 | char *error; |
| 699 | |
| 700 | /* Convert argument to integer value. */ |
| 701 | conv = strtoll(&args[3][1], &error, 16); |
| 702 | if (*error != '\0') { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 703 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 704 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 705 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 706 | return 1; |
| 707 | } |
| 708 | |
| 709 | /* Convert and check integer to pointer. */ |
| 710 | ref = (struct pat_ref_elt *)(long)conv; |
| 711 | if ((long long int)(long)ref != conv) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 712 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 713 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 714 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 715 | return 1; |
| 716 | } |
| 717 | |
| 718 | /* Try to delete the entry. */ |
| 719 | err = NULL; |
| 720 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 721 | if (err) |
| 722 | memprintf(&err, "%s.\n", err); |
| 723 | appctx->ctx.cli.err = err; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 724 | appctx->st0 = CLI_ST_PRINT_FREE; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 725 | return 1; |
| 726 | } |
| 727 | } |
| 728 | else { |
| 729 | /* Else, use the entry identifier as pattern |
| 730 | * string, and update the value. |
| 731 | */ |
| 732 | err = NULL; |
| 733 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 734 | if (err) |
| 735 | memprintf(&err, "%s.\n", err); |
| 736 | appctx->ctx.cli.err = err; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 737 | appctx->st0 = CLI_ST_PRINT_FREE; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 738 | return 1; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | /* The set is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 743 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 744 | return 0; |
| 745 | } |
| 746 | return 1; |
| 747 | } |
| 748 | |
| 749 | static int cli_parse_add_map(char **args, struct appctx *appctx, void *private) |
| 750 | { |
| 751 | if (strcmp(args[1], "map") == 0 || |
| 752 | strcmp(args[1], "acl") == 0) { |
| 753 | int ret; |
| 754 | char *err; |
| 755 | |
| 756 | /* Set flags. */ |
| 757 | if (args[1][0] == 'm') |
| 758 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 759 | else |
| 760 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 761 | |
| 762 | /* If the keywork is "map", we expect three parameters, if it |
| 763 | * is "acl", we expect only two parameters |
| 764 | */ |
| 765 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 766 | if (!*args[2] || !*args[3] || !*args[4]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 767 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 768 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 769 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 770 | return 1; |
| 771 | } |
| 772 | } |
| 773 | else { |
| 774 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 775 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 776 | 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] | 777 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 778 | return 1; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /* Lookup for the reference. */ |
| 783 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 784 | if (!appctx->ctx.map.ref) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 785 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 786 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 787 | 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] | 788 | } |
| 789 | else { |
| 790 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 791 | 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] | 792 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 793 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 794 | return 1; |
| 795 | } |
| 796 | |
| 797 | /* The command "add acl" is prohibited if the reference |
| 798 | * use samples. |
| 799 | */ |
| 800 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 801 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 802 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 803 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 804 | "You must use the command 'add map' to add values.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 805 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 806 | return 1; |
| 807 | } |
| 808 | |
| 809 | /* Add value. */ |
| 810 | err = NULL; |
| 811 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 812 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err); |
| 813 | else |
| 814 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
| 815 | if (!ret) { |
| 816 | if (err) |
| 817 | memprintf(&err, "%s.\n", err); |
| 818 | appctx->ctx.cli.err = err; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 819 | appctx->st0 = CLI_ST_PRINT_FREE; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 820 | return 1; |
| 821 | } |
| 822 | |
| 823 | /* The add is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 824 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 825 | return 1; |
| 826 | } |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int cli_parse_del_map(char **args, struct appctx *appctx, void *private) |
| 832 | { |
| 833 | if (args[1][0] == 'm') |
| 834 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 835 | else |
| 836 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 837 | |
| 838 | /* Expect two parameters: map name and key. */ |
| 839 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 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 = "This command expects two parameters: map identifier and key.\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 | else { |
| 849 | if (!*args[2] || !*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 850 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 851 | 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] | 852 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 853 | return 1; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | /* Lookup the reference in the maps. */ |
| 858 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 859 | if (!appctx->ctx.map.ref || |
| 860 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 861 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 862 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 863 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 864 | return 1; |
| 865 | } |
| 866 | |
| 867 | /* If the entry identifier start with a '#', it is considered as |
| 868 | * pointer id |
| 869 | */ |
| 870 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 871 | struct pat_ref_elt *ref; |
| 872 | long long int conv; |
| 873 | char *error; |
| 874 | |
| 875 | /* Convert argument to integer value. */ |
| 876 | conv = strtoll(&args[3][1], &error, 16); |
| 877 | if (*error != '\0') { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 878 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 879 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 880 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 881 | return 1; |
| 882 | } |
| 883 | |
| 884 | /* Convert and check integer to pointer. */ |
| 885 | ref = (struct pat_ref_elt *)(long)conv; |
| 886 | if ((long long int)(long)ref != conv) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 887 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 888 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 889 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 890 | return 1; |
| 891 | } |
| 892 | |
| 893 | /* Try to delete the entry. */ |
| 894 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 895 | /* The entry is not found, send message. */ |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 896 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 897 | appctx->ctx.cli.msg = "Key not found.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 898 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 899 | return 1; |
| 900 | } |
| 901 | } |
| 902 | else { |
| 903 | /* Else, use the entry identifier as pattern |
| 904 | * string and try to delete the entry. |
| 905 | */ |
| 906 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 907 | /* The entry is not found, send message. */ |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 908 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 909 | appctx->ctx.cli.msg = "Key not found.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 910 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 911 | return 1; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | /* The deletion is done, send message. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 916 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 917 | return 1; |
| 918 | } |
| 919 | |
| 920 | |
| 921 | static int cli_parse_clear_map(char **args, struct appctx *appctx, void *private) |
| 922 | { |
| 923 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 924 | /* Set ACL or MAP flags. */ |
| 925 | if (args[1][0] == 'm') |
| 926 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 927 | else |
| 928 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 929 | |
| 930 | /* no parameter */ |
| 931 | if (!*args[2]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 932 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 933 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 934 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 935 | } |
| 936 | else { |
| 937 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 938 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 939 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 940 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 941 | return 1; |
| 942 | } |
| 943 | |
| 944 | /* lookup into the refs and check the map flag */ |
| 945 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
| 946 | if (!appctx->ctx.map.ref || |
| 947 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 948 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 949 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 950 | 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] | 951 | } |
| 952 | else { |
| 953 | appctx->ctx.cli.severity = LOG_ERR; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 954 | 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] | 955 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 956 | appctx->st0 = CLI_ST_PRINT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 957 | return 1; |
| 958 | } |
| 959 | |
| 960 | /* Clear all. */ |
| 961 | pat_ref_prune(appctx->ctx.map.ref); |
| 962 | |
| 963 | /* return response */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 964 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 965 | return 1; |
| 966 | } |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | /* register cli keywords */ |
| 971 | |
| 972 | static struct cli_kw_list cli_kws = {{ },{ |
| 973 | { { "add", "acl", NULL }, "add acl : add acl entry", cli_parse_add_map, NULL }, |
| 974 | { { "clear", "acl", NULL }, "clear acl <id> : clear the content of this acl", cli_parse_clear_map, NULL }, |
| 975 | { { "del", "acl", NULL }, "del acl : delete acl entry", cli_parse_del_map, NULL }, |
| 976 | { { "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 }, |
| 977 | { { "show", "acl", NULL }, "show acl [id] : report available acls or dump an acl's contents", cli_parse_show_map, NULL }, |
| 978 | { { "add", "map", NULL }, "add map : add map entry", cli_parse_add_map, NULL }, |
| 979 | { { "clear", "map", NULL }, "clear map <id> : clear the content of this map", cli_parse_clear_map, NULL }, |
| 980 | { { "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] | 981 | { { "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] | 982 | { { "set", "map", NULL }, "set map : modify map entry", cli_parse_set_map, NULL }, |
| 983 | { { "show", "map", NULL }, "show map [id] : report available maps or dump a map's contents", cli_parse_show_map, NULL }, |
| 984 | { { NULL }, NULL, NULL, NULL } |
| 985 | }}; |
| 986 | |
| 987 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 988 | /* Note: must not be declared <const> as its list will be overwritten |
| 989 | * |
| 990 | * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function |
| 991 | * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the |
| 992 | * file can be parsed. |
| 993 | * |
| 994 | * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function |
| 995 | * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file. |
| 996 | * |
| 997 | * The map_* keywords only emit strings. |
| 998 | * |
| 999 | * The output type is only used during the configuration parsing. It is used for detecting |
| 1000 | * compatibility problems. |
| 1001 | * |
| 1002 | * The arguments are: <file>[,<default value>] |
| 1003 | */ |
| 1004 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Thierry FOURNIER | 1edc971 | 2014-12-15 16:18:39 +0100 | [diff] [blame] | 1005 | { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR }, |
| 1006 | { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR }, |
| 1007 | { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG }, |
| 1008 | { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB }, |
| 1009 | { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR }, |
| 1010 | { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM }, |
| 1011 | { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END }, |
| 1012 | { "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] | 1013 | { "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] | 1014 | { "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] | 1015 | { "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] | 1016 | |
Thierry FOURNIER | bf65cd4 | 2015-07-20 17:45:02 +0200 | [diff] [blame] | 1017 | { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR }, |
| 1018 | { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG }, |
| 1019 | { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB }, |
| 1020 | { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR }, |
| 1021 | { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM }, |
| 1022 | { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END }, |
| 1023 | { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG }, |
| 1024 | { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT }, |
| 1025 | { "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] | 1026 | |
Thierry FOURNIER | b2f8f08 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 1027 | { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR }, |
| 1028 | { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG }, |
| 1029 | { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB }, |
| 1030 | { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR }, |
| 1031 | { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM }, |
| 1032 | { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END }, |
| 1033 | { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG }, |
| 1034 | { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT }, |
| 1035 | { "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] | 1036 | |
| 1037 | { /* END */ }, |
| 1038 | }}; |
| 1039 | |
| 1040 | __attribute__((constructor)) |
| 1041 | static void __map_init(void) |
| 1042 | { |
| 1043 | /* register format conversion keywords */ |
| 1044 | sample_register_convs(&sample_conv_kws); |
William Lallemand | ad8be61 | 2016-11-18 19:26:17 +0100 | [diff] [blame] | 1045 | cli_register_kw(&cli_kws); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1046 | } |