Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * include/types/pattern.h |
| 3 | * Macros, variables and structures for patterns management. |
| 4 | * |
| 5 | * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _TYPES_PATTERN_H |
| 23 | #define _TYPES_PATTERN_H |
| 24 | |
| 25 | #include <types/buffers.h> |
| 26 | #include <sys/socket.h> |
| 27 | #include <netinet/in.h> |
| 28 | |
| 29 | /* pattern in and out types */ |
| 30 | enum { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 31 | PATTERN_TYPE_IP = 0, /* ipv4 type */ |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 32 | PATTERN_TYPE_IPV6, /* ipv6 type */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 33 | PATTERN_TYPE_INTEGER, /* unsigned 32bits integer type */ |
| 34 | PATTERN_TYPE_STRING, /* char string type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 35 | PATTERN_TYPE_DATA, /* buffer type */ |
| 36 | PATTERN_TYPE_CONSTSTRING, /* constant char string type, data need dup before conversion */ |
| 37 | PATTERN_TYPE_CONSTDATA, /* constant buffer type, data need dup before conversion */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 38 | PATTERN_TYPES /* number of types, must always be last */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 41 | |
| 42 | /* pattern arg types */ |
| 43 | enum { |
| 44 | PATTERN_ARG_TYPE_IP = 0, /* ipv4 type */ |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 45 | PATTERN_ARG_TYPE_IPV6, /* ipv6 type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 46 | PATTERN_ARG_TYPE_INTEGER, /* unsigned 32bits integer type */ |
| 47 | PATTERN_ARG_TYPE_SINTEGER, /* signed 32bits integer type */ |
| 48 | PATTERN_ARG_TYPE_STRING /* string type */ |
| 49 | }; |
| 50 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 51 | /* pattern fetch direction */ |
| 52 | #define PATTERN_FETCH_REQ 1 |
| 53 | #define PATTERN_FETCH_RTR 2 |
| 54 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 55 | |
| 56 | union pattern_arg_data { |
| 57 | struct in_addr ip; /* used for ipv4 type */ |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 58 | struct in6_addr ipv6; /* used for ipv6 type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 59 | uint32_t integer; /* used for unsigned 32bits integer type */ |
Willy Tarreau | b695a6e | 2010-11-14 14:24:27 +0100 | [diff] [blame] | 60 | int sinteger; /* used for signed 32bits integer type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 61 | struct chunk str; |
| 62 | }; |
| 63 | |
| 64 | struct pattern_arg { |
| 65 | int type; /* type of arg */ |
| 66 | union pattern_arg_data data; /* data */ |
| 67 | }; |
| 68 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 69 | /* pattern result data */ |
| 70 | union pattern_data { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 71 | struct in_addr ip; /* used for ipv4 type */ |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 72 | struct in6_addr ipv6; /* used for ipv6 type */ |
Willy Tarreau | b666bc7 | 2011-12-16 16:44:06 +0100 | [diff] [blame] | 73 | int integer; /* used for unsigned 32bits integer type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 74 | struct chunk str; /* used for char string type or buffers*/ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* pattern result */ |
| 78 | struct pattern { |
| 79 | int type; /* current type of data */ |
| 80 | union pattern_data data; /* data */ |
| 81 | }; |
| 82 | |
| 83 | /* pattern conversion */ |
| 84 | struct pattern_conv { |
| 85 | const char *kw; /* configuration keyword */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 86 | int (*process)(const struct pattern_arg *arg_p, |
Willy Tarreau | 1a51b63 | 2010-01-26 17:17:56 +0100 | [diff] [blame] | 87 | int arg_i, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 88 | union pattern_data *data); /* process function */ |
Willy Tarreau | 9e92d32 | 2010-01-26 17:58:06 +0100 | [diff] [blame] | 89 | int (*parse_args)(const char *arg_str, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 90 | struct pattern_arg **arg_p, |
Willy Tarreau | 9e92d32 | 2010-01-26 17:58:06 +0100 | [diff] [blame] | 91 | int *arg_i); /* argument parser. Can be NULL. */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 92 | unsigned int in_type; /* input needed pattern type */ |
| 93 | unsigned int out_type; /* output pattern type */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | /* pattern conversion expression */ |
| 97 | struct pattern_conv_expr { |
| 98 | struct list list; /* member of a pattern expression */ |
| 99 | struct pattern_conv *conv; /* pattern conversion */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 100 | struct pattern_arg *arg_p; /* pointer on args */ |
| 101 | int arg_i; /* number of args */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /* pattern fetch */ |
| 105 | struct pattern_fetch { |
| 106 | const char *kw; /* configuration keyword */ |
| 107 | int (*process)(struct proxy *px, |
| 108 | struct session *l4, |
| 109 | void *l7, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 110 | int dir, const struct pattern_arg *arg_p, |
| 111 | int arg_i, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 112 | union pattern_data *data); /* fetch processing function */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 113 | int (*parse_args)(const char *arg_str, |
| 114 | struct pattern_arg **arg_p, |
| 115 | int *arg_i); /* argument parser. Can be NULL. */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 116 | unsigned long out_type; /* output pattern type */ |
| 117 | int dir; /* usable directions */ |
| 118 | }; |
| 119 | |
| 120 | /* pattern expression */ |
| 121 | struct pattern_expr { |
| 122 | struct list list; /* member of list of pattern, currently not used */ |
| 123 | struct pattern_fetch *fetch; /* pattern fetch */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 124 | struct pattern_arg *arg_p; /* pointer on args */ |
| 125 | int arg_i; /* number of args */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 126 | struct list conv_exprs; /* list of conversion expression to apply */ |
| 127 | }; |
| 128 | |
| 129 | /* pattern fetch keywords list */ |
| 130 | struct pattern_fetch_kw_list { |
| 131 | struct list list; /* head of pattern fetch keyword list */ |
| 132 | struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */ |
| 133 | }; |
| 134 | |
| 135 | /* pattern conversion keywords list */ |
| 136 | struct pattern_conv_kw_list { |
| 137 | struct list list; /* head of pattern conversion keyword list */ |
| 138 | struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */ |
| 139 | }; |
| 140 | |
| 141 | #endif /* _TYPES_PATTERN_H */ |