Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 1 | #include <ctype.h> |
| 2 | |
| 3 | #include <common/cfgparse.h> |
Willy Tarreau | 35b51c6 | 2018-09-10 15:38:55 +0200 | [diff] [blame] | 4 | #include <common/http.h> |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5 | #include <common/initcall.h> |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 6 | #include <common/mini-clist.h> |
| 7 | |
| 8 | #include <types/vars.h> |
| 9 | |
| 10 | #include <proto/arg.h> |
Willy Tarreau | 61c112a | 2018-10-02 16:43:32 +0200 | [diff] [blame] | 11 | #include <proto/http_rules.h> |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 12 | #include <proto/proto_http.h> |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 13 | #include <proto/sample.h> |
| 14 | #include <proto/stream.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 15 | #include <proto/tcp_rules.h> |
Willy Tarreau | ebcd484 | 2015-06-19 11:59:02 +0200 | [diff] [blame] | 16 | #include <proto/vars.h> |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 17 | |
| 18 | /* This contains a pool of struct vars */ |
Willy Tarreau | 8ceae72 | 2018-11-26 11:58:30 +0100 | [diff] [blame] | 19 | DECLARE_STATIC_POOL(var_pool, "vars", sizeof(struct var)); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 20 | |
| 21 | /* This array contain all the names of all the HAProxy vars. |
| 22 | * This permits to identify two variables name with |
| 23 | * only one pointer. It permits to not using strdup() for |
| 24 | * each variable name used during the runtime. |
| 25 | */ |
| 26 | static char **var_names = NULL; |
| 27 | static int var_names_nb = 0; |
| 28 | |
| 29 | /* This array of int contains the system limits per context. */ |
| 30 | static unsigned int var_global_limit = 0; |
| 31 | static unsigned int var_global_size = 0; |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 32 | static unsigned int var_proc_limit = 0; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 33 | static unsigned int var_sess_limit = 0; |
| 34 | static unsigned int var_txn_limit = 0; |
| 35 | static unsigned int var_reqres_limit = 0; |
| 36 | |
Willy Tarreau | 86abe44 | 2018-11-25 20:12:18 +0100 | [diff] [blame] | 37 | __decl_rwlock(var_names_rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 39 | /* returns the struct vars pointer for a session, stream and scope, or NULL if |
| 40 | * it does not exist. |
| 41 | */ |
| 42 | static inline struct vars *get_vars(struct session *sess, struct stream *strm, enum vars_scope scope) |
| 43 | { |
| 44 | switch (scope) { |
| 45 | case SCOPE_PROC: |
| 46 | return &global.vars; |
| 47 | case SCOPE_SESS: |
| 48 | return &sess->vars; |
| 49 | case SCOPE_TXN: |
| 50 | return strm ? &strm->vars_txn : NULL; |
| 51 | case SCOPE_REQ: |
| 52 | case SCOPE_RES: |
| 53 | default: |
| 54 | return strm ? &strm->vars_reqres : NULL; |
| 55 | } |
| 56 | } |
| 57 | |
Willy Tarreau | 7233098 | 2015-06-19 11:21:56 +0200 | [diff] [blame] | 58 | /* This function adds or remove memory size from the accounting. The inner |
| 59 | * pointers may be null when setting the outer ones only. |
| 60 | */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 61 | static void var_accounting_diff(struct vars *vars, struct session *sess, struct stream *strm, int size) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 62 | { |
| 63 | switch (vars->scope) { |
| 64 | case SCOPE_REQ: |
| 65 | case SCOPE_RES: |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 66 | if (strm) |
| 67 | _HA_ATOMIC_ADD(&strm->vars_reqres.size, size); |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 68 | /* fall through */ |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 69 | case SCOPE_TXN: |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 70 | if (strm) |
| 71 | _HA_ATOMIC_ADD(&strm->vars_txn.size, size); |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 72 | /* fall through */ |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 73 | case SCOPE_SESS: |
Olivier Houchard | 25ad13f | 2019-03-08 18:55:38 +0100 | [diff] [blame] | 74 | _HA_ATOMIC_ADD(&sess->vars.size, size); |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 75 | /* fall through */ |
| 76 | case SCOPE_PROC: |
Olivier Houchard | 25ad13f | 2019-03-08 18:55:38 +0100 | [diff] [blame] | 77 | _HA_ATOMIC_ADD(&global.vars.size, size); |
| 78 | _HA_ATOMIC_ADD(&var_global_size, size); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | /* This function returns 1 if the <size> is available in the var |
Joseph Herlant | 0767689 | 2018-11-15 09:19:50 -0800 | [diff] [blame] | 83 | * pool <vars>, otherwise returns 0. If the space is available, |
Willy Tarreau | 7233098 | 2015-06-19 11:21:56 +0200 | [diff] [blame] | 84 | * the size is reserved. The inner pointers may be null when setting |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 85 | * the outer ones only. The accounting uses either <sess> or <strm> |
| 86 | * depending on the scope. <strm> may be NULL when no stream is known |
| 87 | * and only the session exists (eg: tcp-request connection). |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 88 | */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 89 | static int var_accounting_add(struct vars *vars, struct session *sess, struct stream *strm, int size) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 90 | { |
| 91 | switch (vars->scope) { |
| 92 | case SCOPE_REQ: |
| 93 | case SCOPE_RES: |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 94 | if (var_reqres_limit && strm && strm->vars_reqres.size + size > var_reqres_limit) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 95 | return 0; |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 96 | /* fall through */ |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 97 | case SCOPE_TXN: |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 98 | if (var_txn_limit && strm && strm->vars_txn.size + size > var_txn_limit) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 99 | return 0; |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 100 | /* fall through */ |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 101 | case SCOPE_SESS: |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 102 | if (var_sess_limit && sess->vars.size + size > var_sess_limit) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 103 | return 0; |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 104 | /* fall through */ |
| 105 | case SCOPE_PROC: |
| 106 | if (var_proc_limit && global.vars.size + size > var_proc_limit) |
| 107 | return 0; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 108 | if (var_global_limit && var_global_size + size > var_global_limit) |
| 109 | return 0; |
| 110 | } |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 111 | var_accounting_diff(vars, sess, strm, size); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 112 | return 1; |
| 113 | } |
| 114 | |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 115 | /* This fnuction remove a variable from the list and free memory it used */ |
| 116 | unsigned int var_clear(struct var *var) |
| 117 | { |
| 118 | unsigned int size = 0; |
| 119 | |
| 120 | if (var->data.type == SMP_T_STR || var->data.type == SMP_T_BIN) { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 121 | free(var->data.u.str.area); |
| 122 | size += var->data.u.str.data; |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 123 | } |
Christopher Faulet | d02210c | 2017-07-24 16:24:39 +0200 | [diff] [blame] | 124 | else if (var->data.type == SMP_T_METH && var->data.u.meth.meth == HTTP_METH_OTHER) { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 125 | free(var->data.u.meth.str.area); |
| 126 | size += var->data.u.meth.str.data; |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 127 | } |
| 128 | LIST_DEL(&var->l); |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 129 | pool_free(var_pool, var); |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 130 | size += sizeof(struct var); |
| 131 | return size; |
| 132 | } |
| 133 | |
Joseph Herlant | 0767689 | 2018-11-15 09:19:50 -0800 | [diff] [blame] | 134 | /* This function free all the memory used by all the variables |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 135 | * in the list. |
| 136 | */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 137 | void vars_prune(struct vars *vars, struct session *sess, struct stream *strm) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 138 | { |
| 139 | struct var *var, *tmp; |
Willy Tarreau | 7233098 | 2015-06-19 11:21:56 +0200 | [diff] [blame] | 140 | unsigned int size = 0; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 141 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 142 | HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 143 | list_for_each_entry_safe(var, tmp, &vars->head, l) { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 144 | size += var_clear(var); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 145 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 146 | HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock); |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 147 | var_accounting_diff(vars, sess, strm, -size); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 148 | } |
| 149 | |
Willy Tarreau | ebcd484 | 2015-06-19 11:59:02 +0200 | [diff] [blame] | 150 | /* This function frees all the memory used by all the session variables in the |
| 151 | * list starting at <vars>. |
| 152 | */ |
| 153 | void vars_prune_per_sess(struct vars *vars) |
| 154 | { |
| 155 | struct var *var, *tmp; |
| 156 | unsigned int size = 0; |
| 157 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 158 | HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock); |
Willy Tarreau | ebcd484 | 2015-06-19 11:59:02 +0200 | [diff] [blame] | 159 | list_for_each_entry_safe(var, tmp, &vars->head, l) { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 160 | size += var_clear(var); |
Willy Tarreau | ebcd484 | 2015-06-19 11:59:02 +0200 | [diff] [blame] | 161 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 162 | HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 163 | |
Olivier Houchard | 25ad13f | 2019-03-08 18:55:38 +0100 | [diff] [blame] | 164 | _HA_ATOMIC_SUB(&vars->size, size); |
| 165 | _HA_ATOMIC_SUB(&global.vars.size, size); |
| 166 | _HA_ATOMIC_SUB(&var_global_size, size); |
Willy Tarreau | ebcd484 | 2015-06-19 11:59:02 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 169 | /* This function init a list of variabes. */ |
| 170 | void vars_init(struct vars *vars, enum vars_scope scope) |
| 171 | { |
| 172 | LIST_INIT(&vars->head); |
| 173 | vars->scope = scope; |
| 174 | vars->size = 0; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 175 | HA_RWLOCK_INIT(&vars->rwlock); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* This function declares a new variable name. It returns a pointer |
| 179 | * on the string identifying the name. This function assures that |
| 180 | * the same name exists only once. |
| 181 | * |
| 182 | * This function check if the variable name is acceptable. |
| 183 | * |
| 184 | * The function returns NULL if an error occurs, and <err> is filled. |
| 185 | * In this case, the HAProxy must be stopped because the structs are |
| 186 | * left inconsistent. Otherwise, it returns the pointer on the global |
| 187 | * name. |
| 188 | */ |
Christopher Faulet | 09c9df2 | 2016-10-31 11:05:37 +0100 | [diff] [blame] | 189 | static char *register_name(const char *name, int len, enum vars_scope *scope, |
| 190 | int alloc, char **err) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 191 | { |
| 192 | int i; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 193 | char **var_names2; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 194 | const char *tmp; |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 195 | char *res = NULL; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 196 | |
| 197 | /* Check length. */ |
| 198 | if (len == 0) { |
| 199 | memprintf(err, "Empty variable name cannot be accepted"); |
Christopher Faulet | eb3e276 | 2017-12-08 09:17:39 +0100 | [diff] [blame] | 200 | return res; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /* Check scope. */ |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 204 | if (len > 5 && strncmp(name, "proc.", 5) == 0) { |
| 205 | name += 5; |
| 206 | len -= 5; |
| 207 | *scope = SCOPE_PROC; |
| 208 | } |
| 209 | else if (len > 5 && strncmp(name, "sess.", 5) == 0) { |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 210 | name += 5; |
| 211 | len -= 5; |
| 212 | *scope = SCOPE_SESS; |
| 213 | } |
| 214 | else if (len > 4 && strncmp(name, "txn.", 4) == 0) { |
| 215 | name += 4; |
| 216 | len -= 4; |
| 217 | *scope = SCOPE_TXN; |
| 218 | } |
| 219 | else if (len > 4 && strncmp(name, "req.", 4) == 0) { |
| 220 | name += 4; |
| 221 | len -= 4; |
| 222 | *scope = SCOPE_REQ; |
| 223 | } |
| 224 | else if (len > 4 && strncmp(name, "res.", 4) == 0) { |
| 225 | name += 4; |
| 226 | len -= 4; |
| 227 | *scope = SCOPE_RES; |
| 228 | } |
| 229 | else { |
| 230 | memprintf(err, "invalid variable name '%s'. A variable name must be start by its scope. " |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 231 | "The scope can be 'proc', 'sess', 'txn', 'req' or 'res'", name); |
Christopher Faulet | eb3e276 | 2017-12-08 09:17:39 +0100 | [diff] [blame] | 232 | return res; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 235 | if (alloc) |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 236 | HA_RWLOCK_WRLOCK(VARS_LOCK, &var_names_rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 237 | else |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 238 | HA_RWLOCK_RDLOCK(VARS_LOCK, &var_names_rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 239 | |
| 240 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 241 | /* Look for existing variable name. */ |
| 242 | for (i = 0; i < var_names_nb; i++) |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 243 | if (strncmp(var_names[i], name, len) == 0 && var_names[i][len] == '\0') { |
| 244 | res = var_names[i]; |
| 245 | goto end; |
| 246 | } |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 247 | |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 248 | if (!alloc) { |
| 249 | res = NULL; |
| 250 | goto end; |
| 251 | } |
Christopher Faulet | 09c9df2 | 2016-10-31 11:05:37 +0100 | [diff] [blame] | 252 | |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 253 | /* Store variable name. If realloc fails, var_names remains valid */ |
| 254 | var_names2 = realloc(var_names, (var_names_nb + 1) * sizeof(*var_names)); |
| 255 | if (!var_names2) { |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 256 | memprintf(err, "out of memory error"); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 257 | res = NULL; |
| 258 | goto end; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 259 | } |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 260 | var_names_nb++; |
| 261 | var_names = var_names2; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 262 | var_names[var_names_nb - 1] = malloc(len + 1); |
| 263 | if (!var_names[var_names_nb - 1]) { |
| 264 | memprintf(err, "out of memory error"); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 265 | res = NULL; |
| 266 | goto end; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 267 | } |
| 268 | memcpy(var_names[var_names_nb - 1], name, len); |
| 269 | var_names[var_names_nb - 1][len] = '\0'; |
| 270 | |
| 271 | /* Check variable name syntax. */ |
| 272 | tmp = var_names[var_names_nb - 1]; |
| 273 | while (*tmp) { |
Christopher Faulet | b71557a | 2016-10-31 10:49:03 +0100 | [diff] [blame] | 274 | if (!isalnum((int)(unsigned char)*tmp) && *tmp != '_' && *tmp != '.') { |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 275 | memprintf(err, "invalid syntax at char '%s'", tmp); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 276 | res = NULL; |
| 277 | goto end; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 278 | } |
| 279 | tmp++; |
| 280 | } |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 281 | res = var_names[var_names_nb - 1]; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 282 | |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 283 | end: |
| 284 | if (alloc) |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 285 | HA_RWLOCK_WRUNLOCK(VARS_LOCK, &var_names_rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 286 | else |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 287 | HA_RWLOCK_RDUNLOCK(VARS_LOCK, &var_names_rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 288 | |
| 289 | return res; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* This function returns an existing variable or returns NULL. */ |
| 293 | static inline struct var *var_get(struct vars *vars, const char *name) |
| 294 | { |
| 295 | struct var *var; |
| 296 | |
| 297 | list_for_each_entry(var, &vars->head, l) |
| 298 | if (var->name == name) |
| 299 | return var; |
| 300 | return NULL; |
| 301 | } |
| 302 | |
| 303 | /* Returns 0 if fails, else returns 1. */ |
| 304 | static int smp_fetch_var(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 305 | { |
| 306 | const struct var_desc *var_desc = &args[0].data.var; |
| 307 | struct var *var; |
| 308 | struct vars *vars; |
| 309 | |
| 310 | /* Check the availibity of the variable. */ |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 311 | vars = get_vars(smp->sess, smp->strm, var_desc->scope); |
| 312 | if (!vars || vars->scope != var_desc->scope) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 313 | return 0; |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 314 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 315 | HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 316 | var = var_get(vars, var_desc->name); |
| 317 | |
| 318 | /* check for the variable avalaibility */ |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 319 | if (!var) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 320 | HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 321 | return 0; |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 322 | } |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 323 | |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 324 | /* Duplicate the sample data because it could modified by another |
| 325 | * thread */ |
Thierry FOURNIER | 5cc18d4 | 2015-08-19 09:02:36 +0200 | [diff] [blame] | 326 | smp->data = var->data; |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 327 | smp_dup(smp); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 328 | smp->flags |= SMP_F_CONST; |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 329 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 330 | HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 331 | return 1; |
| 332 | } |
| 333 | |
| 334 | /* This function search in the <head> a variable with the same |
| 335 | * pointer value that the <name>. If the variable doesn't exists, |
| 336 | * create it. The function stores a copy of smp> if the variable. |
| 337 | * It returns 0 if fails, else returns 1. |
| 338 | */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 339 | static int sample_store(struct vars *vars, const char *name, struct sample *smp) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 340 | { |
| 341 | struct var *var; |
| 342 | |
| 343 | /* Look for existing variable name. */ |
| 344 | var = var_get(vars, name); |
| 345 | |
| 346 | if (var) { |
| 347 | /* free its used memory. */ |
| 348 | if (var->data.type == SMP_T_STR || |
| 349 | var->data.type == SMP_T_BIN) { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 350 | free(var->data.u.str.area); |
| 351 | var_accounting_diff(vars, smp->sess, smp->strm, |
| 352 | -var->data.u.str.data); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 353 | } |
Christopher Faulet | d02210c | 2017-07-24 16:24:39 +0200 | [diff] [blame] | 354 | else if (var->data.type == SMP_T_METH && var->data.u.meth.meth == HTTP_METH_OTHER) { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 355 | free(var->data.u.meth.str.area); |
| 356 | var_accounting_diff(vars, smp->sess, smp->strm, |
| 357 | -var->data.u.meth.str.data); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 358 | } |
| 359 | } else { |
| 360 | |
Joseph Herlant | 0767689 | 2018-11-15 09:19:50 -0800 | [diff] [blame] | 361 | /* Check memory available. */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 362 | if (!var_accounting_add(vars, smp->sess, smp->strm, sizeof(struct var))) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 363 | return 0; |
| 364 | |
| 365 | /* Create new entry. */ |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 366 | var = pool_alloc(var_pool); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 367 | if (!var) |
| 368 | return 0; |
| 369 | LIST_ADDQ(&vars->head, &var->l); |
| 370 | var->name = name; |
| 371 | } |
| 372 | |
| 373 | /* Set type. */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 374 | var->data.type = smp->data.type; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 375 | |
| 376 | /* Copy data. If the data needs memory, the function can fail. */ |
| 377 | switch (var->data.type) { |
| 378 | case SMP_T_BOOL: |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 379 | case SMP_T_SINT: |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 380 | var->data.u.sint = smp->data.u.sint; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 381 | break; |
| 382 | case SMP_T_IPV4: |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 383 | var->data.u.ipv4 = smp->data.u.ipv4; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 384 | break; |
| 385 | case SMP_T_IPV6: |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 386 | var->data.u.ipv6 = smp->data.u.ipv6; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 387 | break; |
| 388 | case SMP_T_STR: |
| 389 | case SMP_T_BIN: |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 390 | if (!var_accounting_add(vars, smp->sess, smp->strm, smp->data.u.str.data)) { |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 391 | var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ |
| 392 | return 0; |
| 393 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 394 | var->data.u.str.area = malloc(smp->data.u.str.data); |
| 395 | if (!var->data.u.str.area) { |
| 396 | var_accounting_diff(vars, smp->sess, smp->strm, |
| 397 | -smp->data.u.str.data); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 398 | var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ |
| 399 | return 0; |
| 400 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 401 | var->data.u.str.data = smp->data.u.str.data; |
| 402 | memcpy(var->data.u.str.area, smp->data.u.str.area, |
| 403 | var->data.u.str.data); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 404 | break; |
| 405 | case SMP_T_METH: |
Christopher Faulet | d02210c | 2017-07-24 16:24:39 +0200 | [diff] [blame] | 406 | var->data.u.meth.meth = smp->data.u.meth.meth; |
| 407 | if (smp->data.u.meth.meth != HTTP_METH_OTHER) |
| 408 | break; |
| 409 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 410 | if (!var_accounting_add(vars, smp->sess, smp->strm, smp->data.u.meth.str.data)) { |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 411 | var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ |
| 412 | return 0; |
| 413 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 414 | var->data.u.meth.str.area = malloc(smp->data.u.meth.str.data); |
| 415 | if (!var->data.u.meth.str.area) { |
| 416 | var_accounting_diff(vars, smp->sess, smp->strm, |
| 417 | -smp->data.u.meth.str.data); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 418 | var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ |
| 419 | return 0; |
| 420 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 421 | var->data.u.meth.str.data = smp->data.u.meth.str.data; |
| 422 | var->data.u.meth.str.size = smp->data.u.meth.str.data; |
| 423 | memcpy(var->data.u.meth.str.area, smp->data.u.meth.str.area, |
| 424 | var->data.u.meth.str.data); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 425 | break; |
| 426 | } |
| 427 | return 1; |
| 428 | } |
| 429 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 430 | /* Returns 0 if fails, else returns 1. Note that stream may be null for SCOPE_SESS. */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 431 | static inline int sample_store_stream(const char *name, enum vars_scope scope, struct sample *smp) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 432 | { |
| 433 | struct vars *vars; |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 434 | int ret; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 435 | |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 436 | vars = get_vars(smp->sess, smp->strm, scope); |
| 437 | if (!vars || vars->scope != scope) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 438 | return 0; |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 439 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 440 | HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 441 | ret = sample_store(vars, name, smp); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 442 | HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock); |
Christopher Faulet | e95f2c3 | 2017-07-24 16:30:34 +0200 | [diff] [blame] | 443 | return ret; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 446 | /* Returns 0 if fails, else returns 1. Note that stream may be null for SCOPE_SESS. */ |
| 447 | static inline int sample_clear_stream(const char *name, enum vars_scope scope, struct sample *smp) |
| 448 | { |
| 449 | struct vars *vars; |
| 450 | struct var *var; |
| 451 | unsigned int size = 0; |
| 452 | |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 453 | vars = get_vars(smp->sess, smp->strm, scope); |
| 454 | if (!vars || vars->scope != scope) |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 455 | return 0; |
| 456 | |
| 457 | /* Look for existing variable name. */ |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 458 | HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock); |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 459 | var = var_get(vars, name); |
| 460 | if (var) { |
| 461 | size = var_clear(var); |
| 462 | var_accounting_diff(vars, smp->sess, smp->strm, -size); |
| 463 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 464 | HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock); |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 465 | return 1; |
| 466 | } |
| 467 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 468 | /* Returns 0 if fails, else returns 1. */ |
| 469 | static int smp_conv_store(const struct arg *args, struct sample *smp, void *private) |
| 470 | { |
Christopher Faulet | 0099a8c | 2016-11-09 16:15:32 +0100 | [diff] [blame] | 471 | return sample_store_stream(args[0].data.var.name, args[0].data.var.scope, smp); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 472 | } |
| 473 | |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 474 | /* Returns 0 if fails, else returns 1. */ |
| 475 | static int smp_conv_clear(const struct arg *args, struct sample *smp, void *private) |
| 476 | { |
| 477 | return sample_clear_stream(args[0].data.var.name, args[0].data.var.scope, smp); |
| 478 | } |
| 479 | |
Joseph Herlant | 0767689 | 2018-11-15 09:19:50 -0800 | [diff] [blame] | 480 | /* This functions check an argument entry and fill it with a variable |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 481 | * type. The argumen must be a string. If the variable lookup fails, |
Joseph Herlant | 0767689 | 2018-11-15 09:19:50 -0800 | [diff] [blame] | 482 | * the function returns 0 and fill <err>, otherwise it returns 1. |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 483 | */ |
| 484 | int vars_check_arg(struct arg *arg, char **err) |
| 485 | { |
| 486 | char *name; |
| 487 | enum vars_scope scope; |
| 488 | |
| 489 | /* Check arg type. */ |
| 490 | if (arg->type != ARGT_STR) { |
| 491 | memprintf(err, "unexpected argument type"); |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | /* Register new variable name. */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 496 | name = register_name(arg->data.str.area, arg->data.str.data, &scope, |
| 497 | 1, |
| 498 | err); |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 499 | if (!name) |
| 500 | return 0; |
| 501 | |
Tim Duesterhus | a6cc7e8 | 2019-05-13 10:53:29 +0200 | [diff] [blame] | 502 | /* properly destroy the chunk */ |
| 503 | chunk_destroy(&arg->data.str); |
| 504 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 505 | /* Use the global variable name pointer. */ |
| 506 | arg->type = ARGT_VAR; |
| 507 | arg->data.var.name = name; |
| 508 | arg->data.var.scope = scope; |
| 509 | return 1; |
| 510 | } |
| 511 | |
Christopher Faulet | 09c9df2 | 2016-10-31 11:05:37 +0100 | [diff] [blame] | 512 | /* This function store a sample in a variable if it was already defined. |
| 513 | * In error case, it fails silently. |
| 514 | */ |
| 515 | void vars_set_by_name_ifexist(const char *name, size_t len, struct sample *smp) |
| 516 | { |
| 517 | enum vars_scope scope; |
| 518 | |
| 519 | /* Resolve name and scope. */ |
| 520 | name = register_name(name, len, &scope, 0, NULL); |
| 521 | if (!name) |
| 522 | return; |
| 523 | |
| 524 | sample_store_stream(name, scope, smp); |
| 525 | } |
| 526 | |
| 527 | |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 528 | /* This function store a sample in a variable. |
| 529 | * In error case, it fails silently. |
| 530 | */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 531 | void vars_set_by_name(const char *name, size_t len, struct sample *smp) |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 532 | { |
| 533 | enum vars_scope scope; |
| 534 | |
| 535 | /* Resolve name and scope. */ |
Christopher Faulet | 09c9df2 | 2016-10-31 11:05:37 +0100 | [diff] [blame] | 536 | name = register_name(name, len, &scope, 1, NULL); |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 537 | if (!name) |
| 538 | return; |
| 539 | |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 540 | sample_store_stream(name, scope, smp); |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 543 | /* This function unset a variable if it was already defined. |
| 544 | * In error case, it fails silently. |
| 545 | */ |
| 546 | void vars_unset_by_name_ifexist(const char *name, size_t len, struct sample *smp) |
| 547 | { |
| 548 | enum vars_scope scope; |
| 549 | |
| 550 | /* Resolve name and scope. */ |
| 551 | name = register_name(name, len, &scope, 0, NULL); |
| 552 | if (!name) |
| 553 | return; |
| 554 | |
| 555 | sample_clear_stream(name, scope, smp); |
| 556 | } |
| 557 | |
| 558 | |
| 559 | /* This function unset a variable. |
| 560 | * In error case, it fails silently. |
| 561 | */ |
| 562 | void vars_unset_by_name(const char *name, size_t len, struct sample *smp) |
| 563 | { |
| 564 | enum vars_scope scope; |
| 565 | |
| 566 | /* Resolve name and scope. */ |
| 567 | name = register_name(name, len, &scope, 1, NULL); |
| 568 | if (!name) |
| 569 | return; |
| 570 | |
| 571 | sample_clear_stream(name, scope, smp); |
| 572 | } |
| 573 | |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 574 | /* This function fills a sample with the variable content. |
| 575 | * |
| 576 | * Keep in mind that a sample content is duplicated by using smp_dup() |
| 577 | * and it therefore uses a pre-allocated trash chunk as returned by |
| 578 | * get_trash_chunk(). |
| 579 | * |
| 580 | * Returns 1 if the sample is filled, otherwise it returns 0. |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 581 | */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 582 | int vars_get_by_name(const char *name, size_t len, struct sample *smp) |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 583 | { |
| 584 | struct vars *vars; |
| 585 | struct var *var; |
| 586 | enum vars_scope scope; |
| 587 | |
| 588 | /* Resolve name and scope. */ |
Christopher Faulet | 09c9df2 | 2016-10-31 11:05:37 +0100 | [diff] [blame] | 589 | name = register_name(name, len, &scope, 1, NULL); |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 590 | if (!name) |
| 591 | return 0; |
| 592 | |
| 593 | /* Select "vars" pool according with the scope. */ |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 594 | vars = get_vars(smp->sess, smp->strm, scope); |
| 595 | if (!vars || vars->scope != scope) |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 596 | return 0; |
| 597 | |
| 598 | /* Get the variable entry. */ |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 599 | HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 600 | var = var_get(vars, name); |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 601 | if (!var) { |
| 602 | HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 603 | return 0; |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 604 | } |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 605 | |
| 606 | /* Copy sample. */ |
Thierry FOURNIER | 5cc18d4 | 2015-08-19 09:02:36 +0200 | [diff] [blame] | 607 | smp->data = var->data; |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 608 | smp_dup(smp); |
| 609 | |
| 610 | HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | c365d99 | 2015-06-09 12:27:17 +0200 | [diff] [blame] | 611 | return 1; |
| 612 | } |
| 613 | |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 614 | /* This function fills a sample with the content of the variable described |
| 615 | * by <var_desc>. |
| 616 | * |
| 617 | * Keep in mind that a sample content is duplicated by using smp_dup() |
| 618 | * and it therefore uses a pre-allocated trash chunk as returned by |
| 619 | * get_trash_chunk(). |
| 620 | * |
| 621 | * Returns 1 if the sample is filled, otherwise it returns 0. |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 622 | */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 623 | int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp) |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 624 | { |
| 625 | struct vars *vars; |
| 626 | struct var *var; |
| 627 | |
| 628 | /* Select "vars" pool according with the scope. */ |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 629 | vars = get_vars(smp->sess, smp->strm, var_desc->scope); |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 630 | |
Joseph Herlant | 0767689 | 2018-11-15 09:19:50 -0800 | [diff] [blame] | 631 | /* Check if the scope is available a this point of processing. */ |
Willy Tarreau | f37b140 | 2019-06-04 16:27:36 +0200 | [diff] [blame] | 632 | if (!vars || vars->scope != var_desc->scope) |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 633 | return 0; |
| 634 | |
| 635 | /* Get the variable entry. */ |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 636 | HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 637 | var = var_get(vars, var_desc->name); |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 638 | if (!var) { |
| 639 | HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 640 | return 0; |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 641 | } |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 642 | |
| 643 | /* Copy sample. */ |
Thierry FOURNIER | 5cc18d4 | 2015-08-19 09:02:36 +0200 | [diff] [blame] | 644 | smp->data = var->data; |
Dragan Dosen | e980ca9 | 2021-02-22 17:20:01 +0100 | [diff] [blame] | 645 | smp_dup(smp); |
| 646 | |
| 647 | HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock); |
Thierry FOURNIER | fd77e05 | 2015-07-07 21:20:42 +0200 | [diff] [blame] | 648 | return 1; |
| 649 | } |
| 650 | |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 651 | /* Always returns ACT_RET_CONT even if an error occurs. */ |
| 652 | static enum act_return action_store(struct act_rule *rule, struct proxy *px, |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 653 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 654 | { |
| 655 | struct sample smp; |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 656 | int dir; |
| 657 | |
| 658 | switch (rule->from) { |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 659 | case ACT_F_TCP_REQ_SES: dir = SMP_OPT_DIR_REQ; break; |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 660 | case ACT_F_TCP_REQ_CNT: dir = SMP_OPT_DIR_REQ; break; |
| 661 | case ACT_F_TCP_RES_CNT: dir = SMP_OPT_DIR_RES; break; |
| 662 | case ACT_F_HTTP_REQ: dir = SMP_OPT_DIR_REQ; break; |
| 663 | case ACT_F_HTTP_RES: dir = SMP_OPT_DIR_RES; break; |
| 664 | default: |
| 665 | send_log(px, LOG_ERR, "Vars: internal error while execute action store."); |
| 666 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 667 | ha_alert("Vars: internal error while execute action store.\n"); |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 668 | return ACT_RET_CONT; |
| 669 | } |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 670 | |
| 671 | /* Process the expression. */ |
| 672 | memset(&smp, 0, sizeof(smp)); |
Willy Tarreau | 108a8fd | 2016-10-21 17:13:24 +0200 | [diff] [blame] | 673 | if (!sample_process(px, sess, s, dir|SMP_OPT_FINAL, |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 674 | rule->arg.vars.expr, &smp)) |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 675 | return ACT_RET_CONT; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 676 | |
| 677 | /* Store the sample, and ignore errors. */ |
Willy Tarreau | 6204cd9 | 2016-03-10 16:33:04 +0100 | [diff] [blame] | 678 | sample_store_stream(rule->arg.vars.name, rule->arg.vars.scope, &smp); |
Thierry FOURNIER | 24ff6c6 | 2015-08-06 08:52:53 +0200 | [diff] [blame] | 679 | return ACT_RET_CONT; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 682 | /* Always returns ACT_RET_CONT even if an error occurs. */ |
| 683 | static enum act_return action_clear(struct act_rule *rule, struct proxy *px, |
| 684 | struct session *sess, struct stream *s, int flags) |
| 685 | { |
| 686 | struct sample smp; |
| 687 | |
| 688 | memset(&smp, 0, sizeof(smp)); |
| 689 | smp_set_owner(&smp, px, sess, s, SMP_OPT_FINAL); |
| 690 | |
| 691 | /* Clear the variable using the sample context, and ignore errors. */ |
| 692 | sample_clear_stream(rule->arg.vars.name, rule->arg.vars.scope, &smp); |
| 693 | return ACT_RET_CONT; |
| 694 | } |
| 695 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 696 | /* This two function checks the variable name and replace the |
| 697 | * configuration string name by the global string name. its |
| 698 | * the same string, but the global pointer can be easy to |
| 699 | * compare. |
| 700 | * |
| 701 | * The first function checks a sample-fetch and the second |
| 702 | * checks a converter. |
| 703 | */ |
| 704 | static int smp_check_var(struct arg *args, char **err) |
| 705 | { |
| 706 | return vars_check_arg(&args[0], err); |
| 707 | } |
| 708 | |
| 709 | static int conv_check_var(struct arg *args, struct sample_conv *conv, |
| 710 | const char *file, int line, char **err_msg) |
| 711 | { |
| 712 | return vars_check_arg(&args[0], err_msg); |
| 713 | } |
| 714 | |
| 715 | /* This function is a common parser for using variables. It understands |
| 716 | * the format: |
| 717 | * |
| 718 | * set-var(<variable-name>) <expression> |
Willy Tarreau | 4b7531f | 2019-06-04 16:43:29 +0200 | [diff] [blame] | 719 | * unset-var(<variable-name>) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 720 | * |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 721 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error |
| 722 | * message. Otherwise, it returns ACT_RET_PRS_OK and the variable <expr> |
| 723 | * is filled with the pointer to the expression to execute. |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 724 | */ |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 725 | static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy *px, |
| 726 | struct act_rule *rule, char **err) |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 727 | { |
| 728 | const char *var_name = args[*arg-1]; |
| 729 | int var_len; |
Thierry FOURNIER | 48a9cd1 | 2015-07-28 19:00:28 +0200 | [diff] [blame] | 730 | const char *kw_name; |
Willy Tarreau | e365815 | 2016-11-24 21:23:28 +0100 | [diff] [blame] | 731 | int flags, set_var = 0; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 732 | |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 733 | if (!strncmp(var_name, "set-var", 7)) { |
| 734 | var_name += 7; |
| 735 | set_var = 1; |
| 736 | } |
| 737 | if (!strncmp(var_name, "unset-var", 9)) { |
| 738 | var_name += 9; |
| 739 | set_var = 0; |
| 740 | } |
| 741 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 742 | if (*var_name != '(') { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 743 | memprintf(err, "invalid variable '%s'. Expects 'set-var(<var-name>)' or 'unset-var(<var-name>)'", |
| 744 | args[*arg-1]); |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 745 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 746 | } |
| 747 | var_name++; /* jump the '(' */ |
| 748 | var_len = strlen(var_name); |
| 749 | var_len--; /* remove the ')' */ |
| 750 | if (var_name[var_len] != ')') { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 751 | memprintf(err, "invalid variable '%s'. Expects 'set-var(<var-name>)' or 'unset-var(<var-name>)'", |
| 752 | args[*arg-1]); |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 753 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 754 | } |
| 755 | |
Christopher Faulet | 09c9df2 | 2016-10-31 11:05:37 +0100 | [diff] [blame] | 756 | rule->arg.vars.name = register_name(var_name, var_len, &rule->arg.vars.scope, 1, err); |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 757 | if (!rule->arg.vars.name) |
| 758 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 759 | |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 760 | /* There is no fetch method when variable is unset. Just set the right |
| 761 | * action and return. */ |
| 762 | if (!set_var) { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 763 | rule->action = ACT_CUSTOM; |
| 764 | rule->action_ptr = action_clear; |
| 765 | return ACT_RET_PRS_OK; |
| 766 | } |
| 767 | |
Thierry FOURNIER | 48a9cd1 | 2015-07-28 19:00:28 +0200 | [diff] [blame] | 768 | kw_name = args[*arg-1]; |
| 769 | |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 770 | rule->arg.vars.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, |
| 771 | px->conf.args.line, err, &px->conf.args); |
| 772 | if (!rule->arg.vars.expr) |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 773 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 774 | |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 775 | switch (rule->from) { |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 776 | case ACT_F_TCP_REQ_SES: flags = SMP_VAL_FE_SES_ACC; break; |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 777 | case ACT_F_TCP_REQ_CNT: flags = SMP_VAL_FE_REQ_CNT; break; |
| 778 | case ACT_F_TCP_RES_CNT: flags = SMP_VAL_BE_RES_CNT; break; |
| 779 | case ACT_F_HTTP_REQ: flags = SMP_VAL_FE_HRQ_HDR; break; |
| 780 | case ACT_F_HTTP_RES: flags = SMP_VAL_BE_HRS_HDR; break; |
| 781 | default: |
| 782 | memprintf(err, |
| 783 | "internal error, unexpected rule->from=%d, please report this bug!", |
| 784 | rule->from); |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 785 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 786 | } |
| 787 | if (!(rule->arg.vars.expr->fetch->val & flags)) { |
| 788 | memprintf(err, |
| 789 | "fetch method '%s' extracts information from '%s', none of which is available here", |
| 790 | kw_name, sample_src_names(rule->arg.vars.expr->fetch->use)); |
| 791 | free(rule->arg.vars.expr); |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 792 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 793 | } |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 794 | |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 795 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | 4dc15d1 | 2015-08-06 18:25:56 +0200 | [diff] [blame] | 796 | rule->action_ptr = action_store; |
Thierry FOURNIER | afa8049 | 2015-08-19 09:04:15 +0200 | [diff] [blame] | 797 | return ACT_RET_PRS_OK; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | static int vars_max_size(char **args, int section_type, struct proxy *curpx, |
| 801 | struct proxy *defpx, const char *file, int line, |
| 802 | char **err, unsigned int *limit) |
| 803 | { |
| 804 | char *error; |
| 805 | |
| 806 | *limit = strtol(args[1], &error, 10); |
| 807 | if (*error != 0) { |
| 808 | memprintf(err, "%s: '%s' is an invalid size", args[0], args[1]); |
| 809 | return -1; |
| 810 | } |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | static int vars_max_size_global(char **args, int section_type, struct proxy *curpx, |
| 815 | struct proxy *defpx, const char *file, int line, |
| 816 | char **err) |
| 817 | { |
| 818 | return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_global_limit); |
| 819 | } |
| 820 | |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 821 | static int vars_max_size_proc(char **args, int section_type, struct proxy *curpx, |
| 822 | struct proxy *defpx, const char *file, int line, |
| 823 | char **err) |
| 824 | { |
| 825 | return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_proc_limit); |
| 826 | } |
| 827 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 828 | static int vars_max_size_sess(char **args, int section_type, struct proxy *curpx, |
| 829 | struct proxy *defpx, const char *file, int line, |
| 830 | char **err) |
| 831 | { |
| 832 | return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_sess_limit); |
| 833 | } |
| 834 | |
| 835 | static int vars_max_size_txn(char **args, int section_type, struct proxy *curpx, |
| 836 | struct proxy *defpx, const char *file, int line, |
| 837 | char **err) |
| 838 | { |
| 839 | return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_txn_limit); |
| 840 | } |
| 841 | |
| 842 | static int vars_max_size_reqres(char **args, int section_type, struct proxy *curpx, |
| 843 | struct proxy *defpx, const char *file, int line, |
| 844 | char **err) |
| 845 | { |
| 846 | return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_reqres_limit); |
| 847 | } |
| 848 | |
| 849 | static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { |
| 850 | |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 851 | { "var", smp_fetch_var, ARG1(1,STR), smp_check_var, SMP_T_STR, SMP_USE_L4CLI }, |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 852 | { /* END */ }, |
| 853 | }}; |
| 854 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 855 | INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords); |
| 856 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 857 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 858 | { "set-var", smp_conv_store, ARG1(1,STR), conv_check_var, SMP_T_ANY, SMP_T_ANY }, |
| 859 | { "unset-var", smp_conv_clear, ARG1(1,STR), conv_check_var, SMP_T_ANY, SMP_T_ANY }, |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 860 | { /* END */ }, |
| 861 | }}; |
| 862 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 863 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |
| 864 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 865 | static struct action_kw_list tcp_req_sess_kws = { { }, { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 866 | { "set-var", parse_store, 1 }, |
| 867 | { "unset-var", parse_store, 1 }, |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 868 | { /* END */ } |
| 869 | }}; |
| 870 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 871 | INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_req_sess_kws); |
| 872 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 873 | static struct action_kw_list tcp_req_cont_kws = { { }, { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 874 | { "set-var", parse_store, 1 }, |
| 875 | { "unset-var", parse_store, 1 }, |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 876 | { /* END */ } |
| 877 | }}; |
| 878 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 879 | INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_cont_kws); |
| 880 | |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 881 | static struct action_kw_list tcp_res_kws = { { }, { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 882 | { "set-var", parse_store, 1 }, |
| 883 | { "unset-var", parse_store, 1 }, |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 884 | { /* END */ } |
| 885 | }}; |
| 886 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 887 | INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws); |
| 888 | |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 889 | static struct action_kw_list http_req_kws = { { }, { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 890 | { "set-var", parse_store, 1 }, |
| 891 | { "unset-var", parse_store, 1 }, |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 892 | { /* END */ } |
| 893 | }}; |
| 894 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 895 | INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws); |
| 896 | |
Thierry FOURNIER | 36481b8 | 2015-08-19 09:01:53 +0200 | [diff] [blame] | 897 | static struct action_kw_list http_res_kws = { { }, { |
Christopher Faulet | 85d79c9 | 2016-11-09 16:54:56 +0100 | [diff] [blame] | 898 | { "set-var", parse_store, 1 }, |
| 899 | { "unset-var", parse_store, 1 }, |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 900 | { /* END */ } |
| 901 | }}; |
| 902 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 903 | INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws); |
| 904 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 905 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 906 | { CFG_GLOBAL, "tune.vars.global-max-size", vars_max_size_global }, |
Christopher Faulet | ff2613e | 2016-11-09 11:36:17 +0100 | [diff] [blame] | 907 | { CFG_GLOBAL, "tune.vars.proc-max-size", vars_max_size_proc }, |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 908 | { CFG_GLOBAL, "tune.vars.sess-max-size", vars_max_size_sess }, |
| 909 | { CFG_GLOBAL, "tune.vars.txn-max-size", vars_max_size_txn }, |
| 910 | { CFG_GLOBAL, "tune.vars.reqres-max-size", vars_max_size_reqres }, |
| 911 | { /* END */ } |
| 912 | }}; |
| 913 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 914 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |