blob: 49ff672756b1eb5706be2811908f50251301f30f [file] [log] [blame]
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02001#include <ctype.h>
2
3#include <common/cfgparse.h>
Willy Tarreau35b51c62018-09-10 15:38:55 +02004#include <common/http.h>
Willy Tarreau0108d902018-11-25 19:14:37 +01005#include <common/initcall.h>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02006#include <common/mini-clist.h>
7
8#include <types/vars.h>
9
10#include <proto/arg.h>
Willy Tarreau61c112a2018-10-02 16:43:32 +020011#include <proto/http_rules.h>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020012#include <proto/proto_http.h>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020013#include <proto/sample.h>
14#include <proto/stream.h>
Willy Tarreau39713102016-11-25 15:49:32 +010015#include <proto/tcp_rules.h>
Willy Tarreauebcd4842015-06-19 11:59:02 +020016#include <proto/vars.h>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020017
18/* This contains a pool of struct vars */
Willy Tarreau8ceae722018-11-26 11:58:30 +010019DECLARE_STATIC_POOL(var_pool, "vars", sizeof(struct var));
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020020
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 */
26static char **var_names = NULL;
27static int var_names_nb = 0;
28
29/* This array of int contains the system limits per context. */
30static unsigned int var_global_limit = 0;
31static unsigned int var_global_size = 0;
Christopher Fauletff2613e2016-11-09 11:36:17 +010032static unsigned int var_proc_limit = 0;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020033static unsigned int var_sess_limit = 0;
34static unsigned int var_txn_limit = 0;
35static unsigned int var_reqres_limit = 0;
36
Willy Tarreau86abe442018-11-25 20:12:18 +010037__decl_rwlock(var_names_rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +020038
Willy Tarreauf37b1402019-06-04 16:27:36 +020039/* returns the struct vars pointer for a session, stream and scope, or NULL if
40 * it does not exist.
41 */
42static 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 Tarreau72330982015-06-19 11:21:56 +020058/* 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 Tarreau6204cd92016-03-10 16:33:04 +010061static void var_accounting_diff(struct vars *vars, struct session *sess, struct stream *strm, int size)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020062{
63 switch (vars->scope) {
64 case SCOPE_REQ:
65 case SCOPE_RES:
Willy Tarreauf37b1402019-06-04 16:27:36 +020066 if (strm)
67 _HA_ATOMIC_ADD(&strm->vars_reqres.size, size);
Willy Tarreau6204cd92016-03-10 16:33:04 +010068 /* fall through */
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020069 case SCOPE_TXN:
Willy Tarreauf37b1402019-06-04 16:27:36 +020070 if (strm)
71 _HA_ATOMIC_ADD(&strm->vars_txn.size, size);
Willy Tarreau6204cd92016-03-10 16:33:04 +010072 /* fall through */
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020073 case SCOPE_SESS:
Olivier Houchard25ad13f2019-03-08 18:55:38 +010074 _HA_ATOMIC_ADD(&sess->vars.size, size);
Christopher Fauletff2613e2016-11-09 11:36:17 +010075 /* fall through */
76 case SCOPE_PROC:
Olivier Houchard25ad13f2019-03-08 18:55:38 +010077 _HA_ATOMIC_ADD(&global.vars.size, size);
78 _HA_ATOMIC_ADD(&var_global_size, size);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020079 }
80}
81
82/* This function returns 1 if the <size> is available in the var
Joseph Herlant07676892018-11-15 09:19:50 -080083 * pool <vars>, otherwise returns 0. If the space is available,
Willy Tarreau72330982015-06-19 11:21:56 +020084 * the size is reserved. The inner pointers may be null when setting
Willy Tarreau6204cd92016-03-10 16:33:04 +010085 * 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 FOURNIER4834bc72015-06-06 19:29:07 +020088 */
Willy Tarreau6204cd92016-03-10 16:33:04 +010089static int var_accounting_add(struct vars *vars, struct session *sess, struct stream *strm, int size)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020090{
91 switch (vars->scope) {
92 case SCOPE_REQ:
93 case SCOPE_RES:
Willy Tarreauf37b1402019-06-04 16:27:36 +020094 if (var_reqres_limit && strm && strm->vars_reqres.size + size > var_reqres_limit)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020095 return 0;
Willy Tarreau6204cd92016-03-10 16:33:04 +010096 /* fall through */
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020097 case SCOPE_TXN:
Willy Tarreauf37b1402019-06-04 16:27:36 +020098 if (var_txn_limit && strm && strm->vars_txn.size + size > var_txn_limit)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020099 return 0;
Willy Tarreau6204cd92016-03-10 16:33:04 +0100100 /* fall through */
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200101 case SCOPE_SESS:
Willy Tarreau6204cd92016-03-10 16:33:04 +0100102 if (var_sess_limit && sess->vars.size + size > var_sess_limit)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200103 return 0;
Christopher Fauletff2613e2016-11-09 11:36:17 +0100104 /* fall through */
105 case SCOPE_PROC:
106 if (var_proc_limit && global.vars.size + size > var_proc_limit)
107 return 0;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200108 if (var_global_limit && var_global_size + size > var_global_limit)
109 return 0;
110 }
Willy Tarreau6204cd92016-03-10 16:33:04 +0100111 var_accounting_diff(vars, sess, strm, size);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200112 return 1;
113}
114
Christopher Faulet85d79c92016-11-09 16:54:56 +0100115/* This fnuction remove a variable from the list and free memory it used */
116unsigned 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 Tarreau843b7cb2018-07-13 10:54:26 +0200121 free(var->data.u.str.area);
122 size += var->data.u.str.data;
Christopher Faulet85d79c92016-11-09 16:54:56 +0100123 }
Christopher Fauletd02210c2017-07-24 16:24:39 +0200124 else if (var->data.type == SMP_T_METH && var->data.u.meth.meth == HTTP_METH_OTHER) {
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200125 free(var->data.u.meth.str.area);
126 size += var->data.u.meth.str.data;
Christopher Faulet85d79c92016-11-09 16:54:56 +0100127 }
128 LIST_DEL(&var->l);
Willy Tarreaubafbe012017-11-24 17:34:44 +0100129 pool_free(var_pool, var);
Christopher Faulet85d79c92016-11-09 16:54:56 +0100130 size += sizeof(struct var);
131 return size;
132}
133
Joseph Herlant07676892018-11-15 09:19:50 -0800134/* This function free all the memory used by all the variables
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200135 * in the list.
136 */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100137void vars_prune(struct vars *vars, struct session *sess, struct stream *strm)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200138{
139 struct var *var, *tmp;
Willy Tarreau72330982015-06-19 11:21:56 +0200140 unsigned int size = 0;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200141
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100142 HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200143 list_for_each_entry_safe(var, tmp, &vars->head, l) {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100144 size += var_clear(var);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200145 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100146 HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
Willy Tarreau6204cd92016-03-10 16:33:04 +0100147 var_accounting_diff(vars, sess, strm, -size);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200148}
149
Willy Tarreauebcd4842015-06-19 11:59:02 +0200150/* This function frees all the memory used by all the session variables in the
151 * list starting at <vars>.
152 */
153void vars_prune_per_sess(struct vars *vars)
154{
155 struct var *var, *tmp;
156 unsigned int size = 0;
157
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100158 HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
Willy Tarreauebcd4842015-06-19 11:59:02 +0200159 list_for_each_entry_safe(var, tmp, &vars->head, l) {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100160 size += var_clear(var);
Willy Tarreauebcd4842015-06-19 11:59:02 +0200161 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100162 HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200163
Olivier Houchard25ad13f2019-03-08 18:55:38 +0100164 _HA_ATOMIC_SUB(&vars->size, size);
165 _HA_ATOMIC_SUB(&global.vars.size, size);
166 _HA_ATOMIC_SUB(&var_global_size, size);
Willy Tarreauebcd4842015-06-19 11:59:02 +0200167}
168
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200169/* This function init a list of variabes. */
170void vars_init(struct vars *vars, enum vars_scope scope)
171{
172 LIST_INIT(&vars->head);
173 vars->scope = scope;
174 vars->size = 0;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100175 HA_RWLOCK_INIT(&vars->rwlock);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200176}
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 Faulet09c9df22016-10-31 11:05:37 +0100189static char *register_name(const char *name, int len, enum vars_scope *scope,
190 int alloc, char **err)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200191{
192 int i;
Hubert Verstraete831962e2016-06-28 22:44:26 +0200193 char **var_names2;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200194 const char *tmp;
Christopher Faulete95f2c32017-07-24 16:30:34 +0200195 char *res = NULL;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200196
197 /* Check length. */
198 if (len == 0) {
199 memprintf(err, "Empty variable name cannot be accepted");
Christopher Fauleteb3e2762017-12-08 09:17:39 +0100200 return res;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200201 }
202
203 /* Check scope. */
Christopher Fauletff2613e2016-11-09 11:36:17 +0100204 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 FOURNIER4834bc72015-06-06 19:29:07 +0200210 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 Fauletff2613e2016-11-09 11:36:17 +0100231 "The scope can be 'proc', 'sess', 'txn', 'req' or 'res'", name);
Christopher Fauleteb3e2762017-12-08 09:17:39 +0100232 return res;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200233 }
234
Christopher Faulete95f2c32017-07-24 16:30:34 +0200235 if (alloc)
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100236 HA_RWLOCK_WRLOCK(VARS_LOCK, &var_names_rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200237 else
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100238 HA_RWLOCK_RDLOCK(VARS_LOCK, &var_names_rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200239
240
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200241 /* Look for existing variable name. */
242 for (i = 0; i < var_names_nb; i++)
Christopher Faulete95f2c32017-07-24 16:30:34 +0200243 if (strncmp(var_names[i], name, len) == 0 && var_names[i][len] == '\0') {
244 res = var_names[i];
245 goto end;
246 }
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200247
Christopher Faulete95f2c32017-07-24 16:30:34 +0200248 if (!alloc) {
249 res = NULL;
250 goto end;
251 }
Christopher Faulet09c9df22016-10-31 11:05:37 +0100252
Hubert Verstraete831962e2016-06-28 22:44:26 +0200253 /* 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 FOURNIER4834bc72015-06-06 19:29:07 +0200256 memprintf(err, "out of memory error");
Christopher Faulete95f2c32017-07-24 16:30:34 +0200257 res = NULL;
258 goto end;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200259 }
Hubert Verstraete831962e2016-06-28 22:44:26 +0200260 var_names_nb++;
261 var_names = var_names2;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200262 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 Faulete95f2c32017-07-24 16:30:34 +0200265 res = NULL;
266 goto end;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200267 }
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 Fauletb71557a2016-10-31 10:49:03 +0100274 if (!isalnum((int)(unsigned char)*tmp) && *tmp != '_' && *tmp != '.') {
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200275 memprintf(err, "invalid syntax at char '%s'", tmp);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200276 res = NULL;
277 goto end;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200278 }
279 tmp++;
280 }
Christopher Faulete95f2c32017-07-24 16:30:34 +0200281 res = var_names[var_names_nb - 1];
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200282
Christopher Faulete95f2c32017-07-24 16:30:34 +0200283 end:
284 if (alloc)
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100285 HA_RWLOCK_WRUNLOCK(VARS_LOCK, &var_names_rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200286 else
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100287 HA_RWLOCK_RDUNLOCK(VARS_LOCK, &var_names_rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200288
289 return res;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200290}
291
292/* This function returns an existing variable or returns NULL. */
293static 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. */
304static 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 Tarreauf37b1402019-06-04 16:27:36 +0200311 vars = get_vars(smp->sess, smp->strm, var_desc->scope);
312 if (!vars || vars->scope != var_desc->scope)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200313 return 0;
Christopher Faulete95f2c32017-07-24 16:30:34 +0200314
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100315 HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200316 var = var_get(vars, var_desc->name);
317
318 /* check for the variable avalaibility */
Christopher Faulete95f2c32017-07-24 16:30:34 +0200319 if (!var) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100320 HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200321 return 0;
Christopher Faulete95f2c32017-07-24 16:30:34 +0200322 }
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200323
Christopher Faulete95f2c32017-07-24 16:30:34 +0200324 /* Duplicate the sample data because it could modified by another
325 * thread */
Thierry FOURNIER5cc18d42015-08-19 09:02:36 +0200326 smp->data = var->data;
Christopher Faulete95f2c32017-07-24 16:30:34 +0200327 smp_dup(smp);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200328 smp->flags |= SMP_F_CONST;
Christopher Faulete95f2c32017-07-24 16:30:34 +0200329
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100330 HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200331 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 Tarreau6204cd92016-03-10 16:33:04 +0100339static int sample_store(struct vars *vars, const char *name, struct sample *smp)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200340{
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 Tarreau843b7cb2018-07-13 10:54:26 +0200350 free(var->data.u.str.area);
351 var_accounting_diff(vars, smp->sess, smp->strm,
352 -var->data.u.str.data);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200353 }
Christopher Fauletd02210c2017-07-24 16:24:39 +0200354 else if (var->data.type == SMP_T_METH && var->data.u.meth.meth == HTTP_METH_OTHER) {
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200355 free(var->data.u.meth.str.area);
356 var_accounting_diff(vars, smp->sess, smp->strm,
357 -var->data.u.meth.str.data);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200358 }
359 } else {
360
Joseph Herlant07676892018-11-15 09:19:50 -0800361 /* Check memory available. */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100362 if (!var_accounting_add(vars, smp->sess, smp->strm, sizeof(struct var)))
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200363 return 0;
364
365 /* Create new entry. */
Willy Tarreaubafbe012017-11-24 17:34:44 +0100366 var = pool_alloc(var_pool);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200367 if (!var)
368 return 0;
369 LIST_ADDQ(&vars->head, &var->l);
370 var->name = name;
371 }
372
373 /* Set type. */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200374 var->data.type = smp->data.type;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200375
376 /* Copy data. If the data needs memory, the function can fail. */
377 switch (var->data.type) {
378 case SMP_T_BOOL:
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200379 case SMP_T_SINT:
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200380 var->data.u.sint = smp->data.u.sint;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200381 break;
382 case SMP_T_IPV4:
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200383 var->data.u.ipv4 = smp->data.u.ipv4;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200384 break;
385 case SMP_T_IPV6:
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200386 var->data.u.ipv6 = smp->data.u.ipv6;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200387 break;
388 case SMP_T_STR:
389 case SMP_T_BIN:
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200390 if (!var_accounting_add(vars, smp->sess, smp->strm, smp->data.u.str.data)) {
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200391 var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */
392 return 0;
393 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200394 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 FOURNIER4834bc72015-06-06 19:29:07 +0200398 var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */
399 return 0;
400 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200401 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 FOURNIER4834bc72015-06-06 19:29:07 +0200404 break;
405 case SMP_T_METH:
Christopher Fauletd02210c2017-07-24 16:24:39 +0200406 var->data.u.meth.meth = smp->data.u.meth.meth;
407 if (smp->data.u.meth.meth != HTTP_METH_OTHER)
408 break;
409
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200410 if (!var_accounting_add(vars, smp->sess, smp->strm, smp->data.u.meth.str.data)) {
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200411 var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */
412 return 0;
413 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200414 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 FOURNIER4834bc72015-06-06 19:29:07 +0200418 var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */
419 return 0;
420 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200421 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 FOURNIER4834bc72015-06-06 19:29:07 +0200425 break;
426 }
427 return 1;
428}
429
Willy Tarreau620408f2016-10-21 16:37:51 +0200430/* Returns 0 if fails, else returns 1. Note that stream may be null for SCOPE_SESS. */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100431static inline int sample_store_stream(const char *name, enum vars_scope scope, struct sample *smp)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200432{
433 struct vars *vars;
Christopher Faulete95f2c32017-07-24 16:30:34 +0200434 int ret;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200435
Willy Tarreauf37b1402019-06-04 16:27:36 +0200436 vars = get_vars(smp->sess, smp->strm, scope);
437 if (!vars || vars->scope != scope)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200438 return 0;
Christopher Faulete95f2c32017-07-24 16:30:34 +0200439
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100440 HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200441 ret = sample_store(vars, name, smp);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100442 HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
Christopher Faulete95f2c32017-07-24 16:30:34 +0200443 return ret;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200444}
445
Christopher Faulet85d79c92016-11-09 16:54:56 +0100446/* Returns 0 if fails, else returns 1. Note that stream may be null for SCOPE_SESS. */
447static 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 Tarreauf37b1402019-06-04 16:27:36 +0200453 vars = get_vars(smp->sess, smp->strm, scope);
454 if (!vars || vars->scope != scope)
Christopher Faulet85d79c92016-11-09 16:54:56 +0100455 return 0;
456
457 /* Look for existing variable name. */
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100458 HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
Christopher Faulet85d79c92016-11-09 16:54:56 +0100459 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 Faulet2a944ee2017-11-07 10:42:54 +0100464 HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
Christopher Faulet85d79c92016-11-09 16:54:56 +0100465 return 1;
466}
467
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200468/* Returns 0 if fails, else returns 1. */
469static int smp_conv_store(const struct arg *args, struct sample *smp, void *private)
470{
Christopher Faulet0099a8c2016-11-09 16:15:32 +0100471 return sample_store_stream(args[0].data.var.name, args[0].data.var.scope, smp);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200472}
473
Christopher Faulet85d79c92016-11-09 16:54:56 +0100474/* Returns 0 if fails, else returns 1. */
475static 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 Herlant07676892018-11-15 09:19:50 -0800480/* This functions check an argument entry and fill it with a variable
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200481 * type. The argumen must be a string. If the variable lookup fails,
Joseph Herlant07676892018-11-15 09:19:50 -0800482 * the function returns 0 and fill <err>, otherwise it returns 1.
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200483 */
484int 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 Tarreau843b7cb2018-07-13 10:54:26 +0200496 name = register_name(arg->data.str.area, arg->data.str.data, &scope,
497 1,
498 err);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200499 if (!name)
500 return 0;
501
Tim Duesterhusa6cc7e82019-05-13 10:53:29 +0200502 /* properly destroy the chunk */
503 chunk_destroy(&arg->data.str);
504
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200505 /* 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 Faulet09c9df22016-10-31 11:05:37 +0100512/* This function store a sample in a variable if it was already defined.
513 * In error case, it fails silently.
514 */
515void 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 FOURNIERc365d992015-06-09 12:27:17 +0200528/* This function store a sample in a variable.
529 * In error case, it fails silently.
530 */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100531void vars_set_by_name(const char *name, size_t len, struct sample *smp)
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200532{
533 enum vars_scope scope;
534
535 /* Resolve name and scope. */
Christopher Faulet09c9df22016-10-31 11:05:37 +0100536 name = register_name(name, len, &scope, 1, NULL);
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200537 if (!name)
538 return;
539
Willy Tarreau6204cd92016-03-10 16:33:04 +0100540 sample_store_stream(name, scope, smp);
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200541}
542
Christopher Faulet85d79c92016-11-09 16:54:56 +0100543/* This function unset a variable if it was already defined.
544 * In error case, it fails silently.
545 */
546void 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 */
562void 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
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200574/* this function fills a sample with the
575 * variable content. Returns 1 if the sample
576 * is filled, otherwise it returns 0.
577 */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100578int vars_get_by_name(const char *name, size_t len, struct sample *smp)
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200579{
580 struct vars *vars;
581 struct var *var;
582 enum vars_scope scope;
583
584 /* Resolve name and scope. */
Christopher Faulet09c9df22016-10-31 11:05:37 +0100585 name = register_name(name, len, &scope, 1, NULL);
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200586 if (!name)
587 return 0;
588
589 /* Select "vars" pool according with the scope. */
Willy Tarreauf37b1402019-06-04 16:27:36 +0200590 vars = get_vars(smp->sess, smp->strm, scope);
591 if (!vars || vars->scope != scope)
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200592 return 0;
593
594 /* Get the variable entry. */
595 var = var_get(vars, name);
596 if (!var)
597 return 0;
598
599 /* Copy sample. */
Thierry FOURNIER5cc18d42015-08-19 09:02:36 +0200600 smp->data = var->data;
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200601 smp->flags = SMP_F_CONST;
Thierry FOURNIERc365d992015-06-09 12:27:17 +0200602 return 1;
603}
604
Thierry FOURNIERfd77e052015-07-07 21:20:42 +0200605/* this function fills a sample with the
Joseph Herlant07676892018-11-15 09:19:50 -0800606 * content of the variable described by <var_desc>. Returns 1
Thierry FOURNIERfd77e052015-07-07 21:20:42 +0200607 * if the sample is filled, otherwise it returns 0.
608 */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100609int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp)
Thierry FOURNIERfd77e052015-07-07 21:20:42 +0200610{
611 struct vars *vars;
612 struct var *var;
613
614 /* Select "vars" pool according with the scope. */
Willy Tarreauf37b1402019-06-04 16:27:36 +0200615 vars = get_vars(smp->sess, smp->strm, var_desc->scope);
Thierry FOURNIERfd77e052015-07-07 21:20:42 +0200616
Joseph Herlant07676892018-11-15 09:19:50 -0800617 /* Check if the scope is available a this point of processing. */
Willy Tarreauf37b1402019-06-04 16:27:36 +0200618 if (!vars || vars->scope != var_desc->scope)
Thierry FOURNIERfd77e052015-07-07 21:20:42 +0200619 return 0;
620
621 /* Get the variable entry. */
622 var = var_get(vars, var_desc->name);
623 if (!var)
624 return 0;
625
626 /* Copy sample. */
Thierry FOURNIER5cc18d42015-08-19 09:02:36 +0200627 smp->data = var->data;
Thierry FOURNIERfd77e052015-07-07 21:20:42 +0200628 smp->flags = SMP_F_CONST;
Thierry FOURNIERfd77e052015-07-07 21:20:42 +0200629 return 1;
630}
631
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200632/* Always returns ACT_RET_CONT even if an error occurs. */
633static enum act_return action_store(struct act_rule *rule, struct proxy *px,
Willy Tarreau658b85b2015-09-27 10:00:49 +0200634 struct session *sess, struct stream *s, int flags)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200635{
636 struct sample smp;
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200637 int dir;
638
639 switch (rule->from) {
Willy Tarreau620408f2016-10-21 16:37:51 +0200640 case ACT_F_TCP_REQ_SES: dir = SMP_OPT_DIR_REQ; break;
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200641 case ACT_F_TCP_REQ_CNT: dir = SMP_OPT_DIR_REQ; break;
642 case ACT_F_TCP_RES_CNT: dir = SMP_OPT_DIR_RES; break;
643 case ACT_F_HTTP_REQ: dir = SMP_OPT_DIR_REQ; break;
644 case ACT_F_HTTP_RES: dir = SMP_OPT_DIR_RES; break;
645 default:
646 send_log(px, LOG_ERR, "Vars: internal error while execute action store.");
647 if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
Christopher Faulet767a84b2017-11-24 16:50:31 +0100648 ha_alert("Vars: internal error while execute action store.\n");
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200649 return ACT_RET_CONT;
650 }
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200651
652 /* Process the expression. */
653 memset(&smp, 0, sizeof(smp));
Willy Tarreau108a8fd2016-10-21 17:13:24 +0200654 if (!sample_process(px, sess, s, dir|SMP_OPT_FINAL,
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200655 rule->arg.vars.expr, &smp))
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +0200656 return ACT_RET_CONT;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200657
658 /* Store the sample, and ignore errors. */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100659 sample_store_stream(rule->arg.vars.name, rule->arg.vars.scope, &smp);
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +0200660 return ACT_RET_CONT;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200661}
662
Christopher Faulet85d79c92016-11-09 16:54:56 +0100663/* Always returns ACT_RET_CONT even if an error occurs. */
664static enum act_return action_clear(struct act_rule *rule, struct proxy *px,
665 struct session *sess, struct stream *s, int flags)
666{
667 struct sample smp;
668
669 memset(&smp, 0, sizeof(smp));
670 smp_set_owner(&smp, px, sess, s, SMP_OPT_FINAL);
671
672 /* Clear the variable using the sample context, and ignore errors. */
673 sample_clear_stream(rule->arg.vars.name, rule->arg.vars.scope, &smp);
674 return ACT_RET_CONT;
675}
676
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200677/* This two function checks the variable name and replace the
678 * configuration string name by the global string name. its
679 * the same string, but the global pointer can be easy to
680 * compare.
681 *
682 * The first function checks a sample-fetch and the second
683 * checks a converter.
684 */
685static int smp_check_var(struct arg *args, char **err)
686{
687 return vars_check_arg(&args[0], err);
688}
689
690static int conv_check_var(struct arg *args, struct sample_conv *conv,
691 const char *file, int line, char **err_msg)
692{
693 return vars_check_arg(&args[0], err_msg);
694}
695
696/* This function is a common parser for using variables. It understands
697 * the format:
698 *
699 * set-var(<variable-name>) <expression>
Willy Tarreau4b7531f2019-06-04 16:43:29 +0200700 * unset-var(<variable-name>)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200701 *
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200702 * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error
703 * message. Otherwise, it returns ACT_RET_PRS_OK and the variable <expr>
704 * is filled with the pointer to the expression to execute.
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200705 */
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200706static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy *px,
707 struct act_rule *rule, char **err)
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200708{
709 const char *var_name = args[*arg-1];
710 int var_len;
Thierry FOURNIER48a9cd12015-07-28 19:00:28 +0200711 const char *kw_name;
Willy Tarreaue3658152016-11-24 21:23:28 +0100712 int flags, set_var = 0;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200713
Christopher Faulet85d79c92016-11-09 16:54:56 +0100714 if (!strncmp(var_name, "set-var", 7)) {
715 var_name += 7;
716 set_var = 1;
717 }
718 if (!strncmp(var_name, "unset-var", 9)) {
719 var_name += 9;
720 set_var = 0;
721 }
722
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200723 if (*var_name != '(') {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100724 memprintf(err, "invalid variable '%s'. Expects 'set-var(<var-name>)' or 'unset-var(<var-name>)'",
725 args[*arg-1]);
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200726 return ACT_RET_PRS_ERR;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200727 }
728 var_name++; /* jump the '(' */
729 var_len = strlen(var_name);
730 var_len--; /* remove the ')' */
731 if (var_name[var_len] != ')') {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100732 memprintf(err, "invalid variable '%s'. Expects 'set-var(<var-name>)' or 'unset-var(<var-name>)'",
733 args[*arg-1]);
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200734 return ACT_RET_PRS_ERR;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200735 }
736
Christopher Faulet09c9df22016-10-31 11:05:37 +0100737 rule->arg.vars.name = register_name(var_name, var_len, &rule->arg.vars.scope, 1, err);
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200738 if (!rule->arg.vars.name)
739 return ACT_RET_PRS_ERR;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200740
Christopher Faulet85d79c92016-11-09 16:54:56 +0100741 /* There is no fetch method when variable is unset. Just set the right
742 * action and return. */
743 if (!set_var) {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100744 rule->action = ACT_CUSTOM;
745 rule->action_ptr = action_clear;
746 return ACT_RET_PRS_OK;
747 }
748
Thierry FOURNIER48a9cd12015-07-28 19:00:28 +0200749 kw_name = args[*arg-1];
750
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200751 rule->arg.vars.expr = sample_parse_expr((char **)args, arg, px->conf.args.file,
752 px->conf.args.line, err, &px->conf.args);
753 if (!rule->arg.vars.expr)
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200754 return ACT_RET_PRS_ERR;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200755
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200756 switch (rule->from) {
Willy Tarreau620408f2016-10-21 16:37:51 +0200757 case ACT_F_TCP_REQ_SES: flags = SMP_VAL_FE_SES_ACC; break;
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200758 case ACT_F_TCP_REQ_CNT: flags = SMP_VAL_FE_REQ_CNT; break;
759 case ACT_F_TCP_RES_CNT: flags = SMP_VAL_BE_RES_CNT; break;
760 case ACT_F_HTTP_REQ: flags = SMP_VAL_FE_HRQ_HDR; break;
761 case ACT_F_HTTP_RES: flags = SMP_VAL_BE_HRS_HDR; break;
762 default:
763 memprintf(err,
764 "internal error, unexpected rule->from=%d, please report this bug!",
765 rule->from);
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200766 return ACT_RET_PRS_ERR;
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200767 }
768 if (!(rule->arg.vars.expr->fetch->val & flags)) {
769 memprintf(err,
770 "fetch method '%s' extracts information from '%s', none of which is available here",
771 kw_name, sample_src_names(rule->arg.vars.expr->fetch->use));
772 free(rule->arg.vars.expr);
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200773 return ACT_RET_PRS_ERR;
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200774 }
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200775
Thierry FOURNIER42148732015-09-02 17:17:33 +0200776 rule->action = ACT_CUSTOM;
Thierry FOURNIER4dc15d12015-08-06 18:25:56 +0200777 rule->action_ptr = action_store;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200778 return ACT_RET_PRS_OK;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200779}
780
781static int vars_max_size(char **args, int section_type, struct proxy *curpx,
782 struct proxy *defpx, const char *file, int line,
783 char **err, unsigned int *limit)
784{
785 char *error;
786
787 *limit = strtol(args[1], &error, 10);
788 if (*error != 0) {
789 memprintf(err, "%s: '%s' is an invalid size", args[0], args[1]);
790 return -1;
791 }
792 return 0;
793}
794
795static int vars_max_size_global(char **args, int section_type, struct proxy *curpx,
796 struct proxy *defpx, const char *file, int line,
797 char **err)
798{
799 return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_global_limit);
800}
801
Christopher Fauletff2613e2016-11-09 11:36:17 +0100802static int vars_max_size_proc(char **args, int section_type, struct proxy *curpx,
803 struct proxy *defpx, const char *file, int line,
804 char **err)
805{
806 return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_proc_limit);
807}
808
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200809static int vars_max_size_sess(char **args, int section_type, struct proxy *curpx,
810 struct proxy *defpx, const char *file, int line,
811 char **err)
812{
813 return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_sess_limit);
814}
815
816static int vars_max_size_txn(char **args, int section_type, struct proxy *curpx,
817 struct proxy *defpx, const char *file, int line,
818 char **err)
819{
820 return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_txn_limit);
821}
822
823static int vars_max_size_reqres(char **args, int section_type, struct proxy *curpx,
824 struct proxy *defpx, const char *file, int line,
825 char **err)
826{
827 return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_reqres_limit);
828}
829
830static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
831
Christopher Fauletff2613e2016-11-09 11:36:17 +0100832 { "var", smp_fetch_var, ARG1(1,STR), smp_check_var, SMP_T_STR, SMP_USE_L4CLI },
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200833 { /* END */ },
834}};
835
Willy Tarreau0108d902018-11-25 19:14:37 +0100836INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords);
837
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200838static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100839 { "set-var", smp_conv_store, ARG1(1,STR), conv_check_var, SMP_T_ANY, SMP_T_ANY },
840 { "unset-var", smp_conv_clear, ARG1(1,STR), conv_check_var, SMP_T_ANY, SMP_T_ANY },
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200841 { /* END */ },
842}};
843
Willy Tarreau0108d902018-11-25 19:14:37 +0100844INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws);
845
Willy Tarreau620408f2016-10-21 16:37:51 +0200846static struct action_kw_list tcp_req_sess_kws = { { }, {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100847 { "set-var", parse_store, 1 },
848 { "unset-var", parse_store, 1 },
Willy Tarreau620408f2016-10-21 16:37:51 +0200849 { /* END */ }
850}};
851
Willy Tarreau0108d902018-11-25 19:14:37 +0100852INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_req_sess_kws);
853
Willy Tarreau620408f2016-10-21 16:37:51 +0200854static struct action_kw_list tcp_req_cont_kws = { { }, {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100855 { "set-var", parse_store, 1 },
856 { "unset-var", parse_store, 1 },
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200857 { /* END */ }
858}};
859
Willy Tarreau0108d902018-11-25 19:14:37 +0100860INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_cont_kws);
861
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200862static struct action_kw_list tcp_res_kws = { { }, {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100863 { "set-var", parse_store, 1 },
864 { "unset-var", parse_store, 1 },
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200865 { /* END */ }
866}};
867
Willy Tarreau0108d902018-11-25 19:14:37 +0100868INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws);
869
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200870static struct action_kw_list http_req_kws = { { }, {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100871 { "set-var", parse_store, 1 },
872 { "unset-var", parse_store, 1 },
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200873 { /* END */ }
874}};
875
Willy Tarreau0108d902018-11-25 19:14:37 +0100876INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws);
877
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200878static struct action_kw_list http_res_kws = { { }, {
Christopher Faulet85d79c92016-11-09 16:54:56 +0100879 { "set-var", parse_store, 1 },
880 { "unset-var", parse_store, 1 },
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200881 { /* END */ }
882}};
883
Willy Tarreau0108d902018-11-25 19:14:37 +0100884INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws);
885
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200886static struct cfg_kw_list cfg_kws = {{ },{
887 { CFG_GLOBAL, "tune.vars.global-max-size", vars_max_size_global },
Christopher Fauletff2613e2016-11-09 11:36:17 +0100888 { CFG_GLOBAL, "tune.vars.proc-max-size", vars_max_size_proc },
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200889 { CFG_GLOBAL, "tune.vars.sess-max-size", vars_max_size_sess },
890 { CFG_GLOBAL, "tune.vars.txn-max-size", vars_max_size_txn },
891 { CFG_GLOBAL, "tune.vars.reqres-max-size", vars_max_size_reqres },
892 { /* END */ }
893}};
894
Willy Tarreau0108d902018-11-25 19:14:37 +0100895INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);