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 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 25 | #include <sys/socket.h> |
| 26 | #include <netinet/in.h> |
Willy Tarreau | ecfb8e8 | 2012-04-20 12:29:52 +0200 | [diff] [blame] | 27 | #include <types/arg.h> |
| 28 | #include <types/buffers.h> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 29 | |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 30 | /* input and output sample types */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 31 | enum { |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 32 | SMP_T_BOOL = 0, /* boolean */ |
| 33 | SMP_T_UINT, /* unsigned 32bits integer type */ |
| 34 | SMP_T_SINT, /* signed 32bits integer type */ |
| 35 | SMP_T_IPV4, /* ipv4 type */ |
| 36 | SMP_T_IPV6, /* ipv6 type */ |
| 37 | SMP_T_STR, /* char string type */ |
| 38 | SMP_T_BIN, /* buffer type */ |
| 39 | SMP_T_CSTR, /* constant char string type, data need dup before conversion */ |
| 40 | SMP_T_CBIN, /* constant buffer type, data need dup before conversion */ |
| 41 | SMP_TYPES /* number of types, must always be last */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 44 | /* Flags used to describe fetched samples. MAY_CHANGE indicates that the result |
| 45 | * of the fetch might still evolve, for instance because of more data expected, |
| 46 | * even if the fetch has failed. VOL_* indicates how long a result may be cached. |
| 47 | */ |
| 48 | enum { |
| 49 | SMP_F_NOT_LAST = 1 << 0, /* other occurrences might exist for this sample */ |
| 50 | SMP_F_MAY_CHANGE = 1 << 1, /* sample is unstable and might change (eg: request length) */ |
| 51 | SMP_F_VOL_TEST = 1 << 2, /* result must not survive longer than the test (eg: time) */ |
| 52 | SMP_F_VOL_1ST = 1 << 3, /* result sensitive to changes in first line (eg: URI) */ |
| 53 | SMP_F_VOL_HDR = 1 << 4, /* result sensitive to changes in headers */ |
| 54 | SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */ |
| 55 | SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */ |
| 56 | SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */ |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 57 | }; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 58 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 59 | /* pattern fetch direction */ |
| 60 | #define PATTERN_FETCH_REQ 1 |
| 61 | #define PATTERN_FETCH_RTR 2 |
| 62 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 63 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 64 | /* pattern result data */ |
| 65 | union pattern_data { |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 66 | unsigned int uint; /* used for unsigned 32bits integers and booleans */ |
| 67 | int sint; /* used for signed 32bits integers */ |
| 68 | struct in_addr ipv4; /* used for ipv4 addresses */ |
| 69 | struct in6_addr ipv6; /* used for ipv6 addresses */ |
| 70 | struct chunk str; /* used for char strings or buffers */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 73 | /* a sample context might be used by any sample fetch function in order to |
| 74 | * store information needed across multiple calls (eg: restart point for a |
| 75 | * next occurrence). By definition it may store up to 8 pointers, or any |
| 76 | * scalar (double, int, long long). |
| 77 | */ |
| 78 | union smp_ctx { |
| 79 | void *p; /* any pointer */ |
| 80 | int i; /* any integer */ |
| 81 | long long ll; /* any long long or smaller */ |
| 82 | double d; /* any float or double */ |
| 83 | void *a[8]; /* any array of up to 8 pointers */ |
| 84 | }; |
| 85 | |
| 86 | /* a sample is a typed data extracted from a stream. It has a type, contents, |
| 87 | * validity constraints, a context for use in iterative calls. |
| 88 | */ |
| 89 | struct sample { |
| 90 | unsigned int flags; /* SMP_F_* */ |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 91 | int type; /* SMP_T_* */ |
Willy Tarreau | 16c31b0 | 2012-04-23 14:24:58 +0200 | [diff] [blame] | 92 | union pattern_data data; |
| 93 | union smp_ctx ctx; |
| 94 | }; |
| 95 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 96 | /* pattern conversion */ |
| 97 | struct pattern_conv { |
| 98 | const char *kw; /* configuration keyword */ |
Willy Tarreau | ecfb8e8 | 2012-04-20 12:29:52 +0200 | [diff] [blame] | 99 | int (*process)(const struct arg *arg_p, |
Willy Tarreau | f995410 | 2012-04-20 14:03:29 +0200 | [diff] [blame] | 100 | union pattern_data *data); /* process function */ |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 101 | unsigned int arg_mask; /* arguments (ARG*()) */ |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 102 | int (*val_args)(struct arg *arg_p, |
| 103 | char **err_msg); /* argument validation function */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 104 | unsigned int in_type; /* input needed pattern type */ |
| 105 | unsigned int out_type; /* output pattern type */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | /* pattern conversion expression */ |
| 109 | struct pattern_conv_expr { |
| 110 | struct list list; /* member of a pattern expression */ |
| 111 | struct pattern_conv *conv; /* pattern conversion */ |
Willy Tarreau | ecfb8e8 | 2012-04-20 12:29:52 +0200 | [diff] [blame] | 112 | struct arg *arg_p; /* pointer on args */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /* pattern fetch */ |
| 116 | struct pattern_fetch { |
| 117 | const char *kw; /* configuration keyword */ |
| 118 | int (*process)(struct proxy *px, |
| 119 | struct session *l4, |
| 120 | void *l7, |
Willy Tarreau | ecfb8e8 | 2012-04-20 12:29:52 +0200 | [diff] [blame] | 121 | int dir, const struct arg *arg_p, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 122 | union pattern_data *data); /* fetch processing function */ |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 123 | unsigned int arg_mask; /* arguments (ARG*()) */ |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 124 | int (*val_args)(struct arg *arg_p, |
| 125 | char **err_msg); /* argument validation function */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 126 | unsigned long out_type; /* output pattern type */ |
| 127 | int dir; /* usable directions */ |
| 128 | }; |
| 129 | |
| 130 | /* pattern expression */ |
| 131 | struct pattern_expr { |
| 132 | struct list list; /* member of list of pattern, currently not used */ |
| 133 | struct pattern_fetch *fetch; /* pattern fetch */ |
Willy Tarreau | ecfb8e8 | 2012-04-20 12:29:52 +0200 | [diff] [blame] | 134 | struct arg *arg_p; /* pointer on args */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 135 | struct list conv_exprs; /* list of conversion expression to apply */ |
| 136 | }; |
| 137 | |
| 138 | /* pattern fetch keywords list */ |
| 139 | struct pattern_fetch_kw_list { |
| 140 | struct list list; /* head of pattern fetch keyword list */ |
| 141 | struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */ |
| 142 | }; |
| 143 | |
| 144 | /* pattern conversion keywords list */ |
| 145 | struct pattern_conv_kw_list { |
| 146 | struct list list; /* head of pattern conversion keyword list */ |
| 147 | struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */ |
| 148 | }; |
| 149 | |
| 150 | #endif /* _TYPES_PATTERN_H */ |