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 | |
| 18 | #include <types/global.h> |
| 19 | #include <types/map.h> |
| 20 | |
| 21 | #include <proto/arg.h> |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 22 | #include <proto/map.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 23 | #include <proto/pattern.h> |
| 24 | #include <proto/sample.h> |
| 25 | |
Thierry FOURNIER | 275db69 | 2013-12-06 10:39:36 +0100 | [diff] [blame] | 26 | struct list maps = LIST_HEAD_INIT(maps); /* list of struct map_reference */ |
| 27 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 28 | /* This function return existing map reference or return NULL. */ |
Thierry FOURNIER | 2d4771b | 2013-12-06 10:39:48 +0100 | [diff] [blame] | 29 | struct map_reference *map_get_reference(const char *reference) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 30 | { |
| 31 | struct map_reference *ref; |
| 32 | |
| 33 | /* process the lookup */ |
| 34 | list_for_each_entry(ref, &maps, list) |
| 35 | if (strcmp(ref->reference, reference) == 0) |
| 36 | return ref; |
| 37 | return NULL; |
| 38 | } |
| 39 | |
| 40 | /* Parse an IPv4 address and store it into the sample. |
| 41 | * The output type is IPV4. |
| 42 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 43 | int map_parse_ip(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 44 | { |
| 45 | if (!buf2ip(text, strlen(text), &smp->data.ipv4)) |
| 46 | return 0; |
| 47 | smp->type = SMP_T_IPV4; |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | /* Parse an IPv6 address and store it into the sample. |
| 52 | * The output type is IPV6. |
| 53 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 54 | int map_parse_ip6(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 55 | { |
| 56 | if (!buf2ip6(text, strlen(text), &smp->data.ipv6)) |
| 57 | return 0; |
| 58 | smp->type = SMP_T_IPV6; |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | /* Parse a string and store a pointer to it into the sample. The original |
| 63 | * string must be left in memory because we return a direct memory reference. |
| 64 | * The output type is CSTR. |
| 65 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 66 | int map_parse_str(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 67 | { |
| 68 | /* The loose of the "const" is balanced by the SMP_T_CSTR type */ |
| 69 | smp->data.str.str = (char *)text; |
| 70 | smp->data.str.len = strlen(text); |
| 71 | smp->data.str.size = smp->data.str.len + 1; |
| 72 | smp->type = SMP_T_CSTR; |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | /* Parse an integer and convert it to a sample. The output type is SINT if the |
| 77 | * number is negative, or UINT if it is positive or null. The function returns |
| 78 | * zero (error) if the number is too large. |
| 79 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 80 | int map_parse_int(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 81 | { |
| 82 | long long int value; |
| 83 | char *error; |
| 84 | |
| 85 | /* parse interger and convert it. Return the value in 64 format. */ |
| 86 | value = strtoll(text, &error, 10); |
| 87 | if (*error != '\0') |
| 88 | return 0; |
| 89 | |
| 90 | /* check sign iand limits */ |
| 91 | if (value < 0) { |
| 92 | if (value < INT_MIN) |
| 93 | return 0; |
| 94 | smp->type = SMP_T_SINT; |
| 95 | smp->data.sint = value; |
| 96 | } |
| 97 | else { |
| 98 | if (value > UINT_MAX) |
| 99 | return 0; |
| 100 | smp->type = SMP_T_UINT; |
| 101 | smp->data.uint = value; |
| 102 | } |
| 103 | |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | /* This function creates and initializes a new map_reference entry. This |
| 108 | * function only fails in case of a memory allocation issue, in which case |
| 109 | * it returns NULL. <reference> here is a unique identifier for the map's |
| 110 | * contents, typically the name of the file used to build the map. |
| 111 | */ |
| 112 | static struct map_reference *map_create_reference(const char *reference) |
| 113 | { |
| 114 | struct map_reference *ref; |
| 115 | |
| 116 | /* create new entry */ |
| 117 | ref = calloc(1, sizeof(*ref)); |
| 118 | if (!ref) |
| 119 | return NULL; |
| 120 | |
| 121 | ref->reference = strdup(reference); |
| 122 | if (!ref->reference) |
| 123 | return NULL; |
| 124 | |
| 125 | LIST_INIT(&ref->entries); |
| 126 | LIST_INIT(&ref->maps); |
| 127 | LIST_ADDQ(&maps, &ref->list); |
| 128 | |
| 129 | return ref; |
| 130 | } |
| 131 | |
| 132 | /* This function just create new entry */ |
| 133 | static struct map_entry *map_create_entry(int line, char *key, char *value) |
| 134 | { |
| 135 | struct map_entry *ent; |
| 136 | |
| 137 | ent = calloc(1, sizeof(*ent)); |
| 138 | if (!ent) |
| 139 | return NULL; |
| 140 | |
| 141 | ent->line = line; |
| 142 | |
| 143 | ent->key = strdup(key); |
| 144 | if (!ent->key) { |
| 145 | free(ent); |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | ent->value = strdup(value); |
| 150 | if (!ent->value) { |
| 151 | free(ent->key); |
| 152 | free(ent); |
| 153 | return NULL; |
| 154 | } |
| 155 | |
| 156 | return ent; |
| 157 | } |
| 158 | |
| 159 | /* This crete and initialize map descriptor. |
| 160 | * Return NULL if out of memory error |
| 161 | */ |
| 162 | static struct map_descriptor *map_create_descriptor(struct map_reference *ref, |
| 163 | struct sample_conv *conv) |
| 164 | { |
| 165 | struct map_descriptor *desc; |
| 166 | |
| 167 | desc = calloc(1, sizeof(*desc)); |
| 168 | if (!desc) |
| 169 | return NULL; |
| 170 | |
| 171 | desc->conv = conv; |
Thierry FOURNIER | a82d202 | 2013-12-05 11:59:55 +0100 | [diff] [blame] | 172 | desc->ref = ref; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 173 | |
| 174 | LIST_ADDQ(&ref->maps, &desc->list); |
| 175 | |
| 176 | return desc; |
| 177 | } |
| 178 | |
| 179 | /* This function just add entry into the list of pattern. |
| 180 | * It can return false only in memory problem case |
| 181 | */ |
| 182 | static int map_add_entry(struct map_reference *map, int line, char *key, char *value) |
| 183 | { |
| 184 | struct map_entry *ent; |
| 185 | |
| 186 | ent = map_create_entry(line, key, value); |
| 187 | if (!ent) |
| 188 | return 0; |
| 189 | LIST_ADDQ(&map->entries, &ent->list); |
| 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | /* Reads patterns from a file. If <err_msg> is non-NULL, an error message will |
| 194 | * be returned there on errors and the caller will have to free it. |
| 195 | * |
| 196 | * The file contains one key + value per line. Lines which start with '#' are |
| 197 | * ignored, just like empty lines. Leading tabs/spaces are stripped. The key is |
| 198 | * then the first "word" (series of non-space/tabs characters), and the value is |
| 199 | * what follows this series of space/tab till the end of the line excluding |
| 200 | * trailing spaces/tabs. |
| 201 | * |
| 202 | * Example : |
| 203 | * |
| 204 | * # this is a comment and is ignored |
| 205 | * 62.212.114.60 1wt.eu \n |
| 206 | * <-><-----------><---><----><----> |
| 207 | * | | | | `--- trailing spaces ignored |
| 208 | * | | | `-------- value |
| 209 | * | | `--------------- middle spaces ignored |
| 210 | * | `------------------------ key |
| 211 | * `-------------------------------- leading spaces ignored |
| 212 | * |
| 213 | * Return non-zero in case of succes, otherwise 0. |
| 214 | */ |
| 215 | static int map_read_entries_from_file(const char *filename, |
| 216 | struct map_reference *ref, |
| 217 | char **err) |
| 218 | { |
| 219 | FILE *file; |
| 220 | char *c; |
| 221 | int ret = 0; |
| 222 | int line = 0; |
| 223 | char *key_beg; |
| 224 | char *key_end; |
| 225 | char *value_beg; |
| 226 | char *value_end; |
| 227 | |
| 228 | file = fopen(filename, "r"); |
| 229 | if (!file) { |
| 230 | memprintf(err, "failed to open pattern file <%s>", filename); |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | /* now parse all patterns. The file may contain only one pattern |
| 235 | * followed by one value per line. The start spaces, separator spaces |
| 236 | * and and spaces are stripped. Each can contain comment started by '#' |
| 237 | */ |
| 238 | while (fgets(trash.str, trash.size, file) != NULL) { |
| 239 | line++; |
| 240 | c = trash.str; |
| 241 | |
| 242 | /* ignore lines beginning with a dash */ |
| 243 | if (*c == '#') |
| 244 | continue; |
| 245 | |
| 246 | /* strip leading spaces and tabs */ |
| 247 | while (*c == ' ' || *c == '\t') |
| 248 | c++; |
| 249 | |
| 250 | /* empty lines are ignored too */ |
Thierry FOURNIER | 338a031 | 2014-02-26 18:30:13 +0100 | [diff] [blame] | 251 | if (*c == '\0' || *c == '\r' || *c == '\n') |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 252 | continue; |
| 253 | |
| 254 | /* look for the end of the key */ |
| 255 | key_beg = c; |
| 256 | while (*c && *c != ' ' && *c != '\t' && *c != '\n' && *c != '\r') |
| 257 | c++; |
| 258 | |
| 259 | key_end = c; |
| 260 | |
| 261 | /* strip middle spaces and tabs */ |
| 262 | while (*c == ' ' || *c == '\t') |
| 263 | c++; |
| 264 | |
| 265 | /* look for the end of the value, it is the end of the line */ |
| 266 | value_beg = c; |
| 267 | while (*c && *c != '\n' && *c != '\r') |
| 268 | c++; |
| 269 | value_end = c; |
| 270 | |
| 271 | /* trim possibly trailing spaces and tabs */ |
| 272 | while (value_end > value_beg && (value_end[-1] == ' ' || value_end[-1] == '\t')) |
| 273 | value_end--; |
| 274 | |
| 275 | /* set final \0 and check entries */ |
| 276 | *key_end = '\0'; |
| 277 | *value_end = '\0'; |
| 278 | |
| 279 | /* insert values */ |
| 280 | if (!map_add_entry(ref, line, key_beg, value_beg)) { |
| 281 | memprintf(err, "out of memory"); |
| 282 | goto out_close; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /* succes */ |
| 287 | ret = 1; |
| 288 | |
| 289 | out_close: |
| 290 | fclose(file); |
| 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | /* This function read the string entries of <ent>, parse it with |
| 295 | * the <desc> methods, and strore the result into <desc> dummy ACL. |
| 296 | * return 1 in succes case, else return 0 and <err> is filled. |
| 297 | * |
| 298 | * The acm parser use <pattern> for creating new pattern (list |
| 299 | * of values case) or using the same pattern (tree index case). |
| 300 | * |
| 301 | * <patflags> must be PAT_F_*. |
| 302 | */ |
| 303 | static int map_parse_and_index(struct map_descriptor *desc, |
| 304 | struct pattern **pattern, |
| 305 | struct map_entry *ent, |
| 306 | int patflags, |
| 307 | char **err) |
| 308 | { |
| 309 | struct sample_storage *smp; |
| 310 | |
| 311 | /* use new smp for storing value */ |
| 312 | smp = calloc(1, sizeof(*smp)); |
| 313 | if (!smp) |
| 314 | return 0; |
| 315 | |
| 316 | /* first read and convert value */ |
| 317 | if (!desc->parse(ent->value, smp)) { |
| 318 | memprintf(err, "parse value failed at line %d of file <%s>", |
| 319 | ent->line, desc->ref->reference); |
| 320 | return 0; |
| 321 | } |
| 322 | |
Thierry FOURNIER | 7148ce6 | 2013-12-06 19:06:43 +0100 | [diff] [blame] | 323 | /* register key */ |
Thierry FOURNIER | 972028f | 2014-01-23 17:53:31 +0100 | [diff] [blame^] | 324 | if (!pattern_register(desc->pat, ent->key, smp, pattern, patflags, err)) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 325 | return 0; |
| 326 | |
| 327 | return 1; |
| 328 | } |
| 329 | |
| 330 | /* This function load the map file according with data type declared into |
| 331 | * the "struct sample_conv". |
| 332 | * |
| 333 | * This function choose the indexation type (ebtree or list) according with |
| 334 | * the type of match needed. |
| 335 | */ |
| 336 | static int sample_load_map(struct arg *arg, struct sample_conv *conv, char **err) |
| 337 | { |
| 338 | struct map_reference *ref; |
| 339 | struct map_descriptor *desc; |
| 340 | struct pattern *pattern; |
| 341 | struct map_entry *ent; |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 342 | struct pattern_expr *pat = NULL; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 343 | |
| 344 | /* look for existing map reference. The reference is the |
| 345 | * file encountered in the first argument. arg[0] with string |
| 346 | * type is guaranteed by the parser. |
| 347 | */ |
| 348 | ref = map_get_reference(arg[0].data.str.str); |
| 349 | |
| 350 | /* The reference doesn't exist */ |
| 351 | if (!ref) { |
| 352 | |
| 353 | /* create new reference entry */ |
| 354 | ref = map_create_reference(arg[0].data.str.str); |
| 355 | if (!ref) { |
| 356 | memprintf(err, "out of memory"); |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | /* load the file */ |
| 361 | if (!map_read_entries_from_file(arg[0].data.str.str, ref, err)) |
| 362 | return 0; |
| 363 | } |
| 364 | |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 365 | /* look for identical existing map. Two maps are identical if |
| 366 | * their in_type and out_type are the same. If is not found, pat |
| 367 | * is NULL. |
| 368 | */ |
| 369 | else { |
| 370 | list_for_each_entry(desc, &ref->maps, list) |
| 371 | if (desc->conv->in_type == conv->in_type && |
Thierry FOURNIER | 736459e | 2013-12-11 11:20:24 +0100 | [diff] [blame] | 372 | desc->conv->out_type == conv->out_type && |
| 373 | desc->conv->private == conv->private) |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 374 | break; |
| 375 | if (&desc->list != &ref->maps) |
| 376 | pat = desc->pat; |
| 377 | } |
| 378 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 379 | /* create new map descriptor */ |
| 380 | desc = map_create_descriptor(ref, conv); |
| 381 | if (!desc) { |
| 382 | memprintf(err, "out of memory"); |
| 383 | return 0; |
| 384 | } |
| 385 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 386 | /* check the output parse method */ |
| 387 | switch (desc->conv->out_type) { |
| 388 | case SMP_T_STR: desc->parse = map_parse_str; break; |
| 389 | case SMP_T_UINT: desc->parse = map_parse_int; break; |
| 390 | case SMP_T_IPV4: desc->parse = map_parse_ip; break; |
| 391 | case SMP_T_IPV6: desc->parse = map_parse_ip6; break; |
| 392 | default: |
| 393 | memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.", |
| 394 | conv->out_type); |
| 395 | return 0; |
| 396 | } |
| 397 | |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 398 | /* If identical pattern is not found, initialize his own pattern */ |
| 399 | if (!pat) { |
| 400 | |
| 401 | desc->pat = calloc(1, sizeof(*desc->pat)); |
| 402 | if (!desc->pat) { |
| 403 | memprintf(err, "out of memory"); |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | pattern_init_expr(desc->pat); |
| 408 | |
| 409 | /* This is original pattern, must free */ |
| 410 | desc->do_free = 1; |
| 411 | |
| 412 | /* set the match method */ |
| 413 | desc->pat->match = pat_match_fcts[conv->private]; |
Thierry FOURNIER | 736459e | 2013-12-11 11:20:24 +0100 | [diff] [blame] | 414 | desc->pat->parse = pat_parse_fcts[conv->private]; |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 415 | |
| 416 | /* parse each line of the file */ |
| 417 | pattern = NULL; |
| 418 | list_for_each_entry(ent, &ref->entries, list) |
| 419 | if (!map_parse_and_index(desc, &pattern, ent, 0, err)) |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | /* identical pattern found. Use reference to this pattern, and mark |
| 424 | * the map_descriptor pattern as non freeable |
| 425 | */ |
| 426 | else { |
| 427 | desc->pat = pat; |
| 428 | desc->do_free = 0; |
| 429 | } |
| 430 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 431 | /* The second argument is the default value */ |
| 432 | if (arg[1].type == ARGT_STR) { |
| 433 | desc->default_value = strdup(arg[1].data.str.str); |
| 434 | if (!desc->default_value) { |
| 435 | memprintf(err, "out of memory"); |
| 436 | return 0; |
| 437 | } |
| 438 | desc->def = calloc(1, sizeof(*desc->def)); |
| 439 | if (!desc->def) { |
| 440 | memprintf(err, "out of memory"); |
| 441 | return 0; |
| 442 | } |
| 443 | if (!desc->parse(desc->default_value, desc->def)) { |
| 444 | memprintf(err, "Cannot parse default value"); |
| 445 | return 0; |
| 446 | } |
| 447 | } |
| 448 | else |
| 449 | desc->def = NULL; |
| 450 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 451 | /* replace the first argument by this definition */ |
| 452 | arg[0].type = ARGT_MAP; |
| 453 | arg[0].data.map = desc; |
| 454 | |
| 455 | return 1; |
| 456 | } |
| 457 | |
| 458 | static int sample_conv_map(const struct arg *arg_p, struct sample *smp) |
| 459 | { |
| 460 | struct map_descriptor *desc; |
| 461 | struct sample_storage *sample; |
| 462 | enum pat_match_res ret; |
| 463 | |
| 464 | /* get config */ |
| 465 | desc = arg_p[0].data.map; |
| 466 | |
| 467 | /* Execute the match function. */ |
Thierry FOURNIER | 7609064 | 2013-12-10 15:03:38 +0100 | [diff] [blame] | 468 | ret = pattern_exec_match(desc->pat, smp, &sample, NULL, NULL); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 469 | if (ret != PAT_MATCH) { |
| 470 | if (!desc->def) |
| 471 | return 0; |
| 472 | sample = desc->def; |
| 473 | } |
| 474 | |
| 475 | /* copy new data */ |
| 476 | smp->type = sample->type; |
| 477 | memcpy(&smp->data, &sample->data, sizeof(smp->data)); |
| 478 | return 1; |
| 479 | } |
| 480 | |
| 481 | /* Note: must not be declared <const> as its list will be overwritten |
| 482 | * |
| 483 | * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function |
| 484 | * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the |
| 485 | * file can be parsed. |
| 486 | * |
| 487 | * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function |
| 488 | * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file. |
| 489 | * |
| 490 | * The map_* keywords only emit strings. |
| 491 | * |
| 492 | * The output type is only used during the configuration parsing. It is used for detecting |
| 493 | * compatibility problems. |
| 494 | * |
| 495 | * The arguments are: <file>[,<default value>] |
| 496 | */ |
| 497 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
| 498 | { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_STR }, |
| 499 | { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_STR }, |
| 500 | { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_BEG }, |
| 501 | { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_SUB }, |
| 502 | { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_DIR }, |
| 503 | { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_DOM }, |
| 504 | { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_END }, |
| 505 | { "map_reg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_REG }, |
| 506 | { "map_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_UINT, SMP_T_STR, PAT_MATCH_INT }, |
| 507 | { "map_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_STR, PAT_MATCH_IP }, |
| 508 | |
| 509 | { "map_str_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_STR }, |
| 510 | { "map_beg_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_BEG }, |
| 511 | { "map_sub_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_SUB }, |
| 512 | { "map_dir_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_DIR }, |
| 513 | { "map_dom_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_DOM }, |
| 514 | { "map_end_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_END }, |
| 515 | { "map_reg_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_REG }, |
| 516 | { "map_int_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_UINT, SMP_T_UINT, PAT_MATCH_INT }, |
| 517 | { "map_ip_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_UINT, PAT_MATCH_IP }, |
| 518 | |
| 519 | { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_STR }, |
| 520 | { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_BEG }, |
| 521 | { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_SUB }, |
| 522 | { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_DIR }, |
| 523 | { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_DOM }, |
| 524 | { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_END }, |
| 525 | { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_REG }, |
| 526 | { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_UINT, SMP_T_IPV4, PAT_MATCH_INT }, |
| 527 | { "map_ip_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_IPV4, PAT_MATCH_IP }, |
| 528 | |
| 529 | { /* END */ }, |
| 530 | }}; |
| 531 | |
| 532 | __attribute__((constructor)) |
| 533 | static void __map_init(void) |
| 534 | { |
| 535 | /* register format conversion keywords */ |
| 536 | sample_register_convs(&sample_conv_kws); |
| 537 | } |