blob: cfbb7d853fce466c0b1dc751aa671136069b277e [file] [log] [blame]
Emeric Brun3bd697e2010-01-04 15:23:48 +01001/*
2 * Stick tables management functions.
3 *
4 * Copyright 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
Willy Tarreau08d5f982010-06-06 13:34:54 +02005 * Copyright (C) 2010 Willy Tarreau <w@1wt.eu>
Emeric Brun3bd697e2010-01-04 15:23:48 +01006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14#include <string.h>
Willy Tarreauf13ebdf2016-11-22 18:00:53 +010015#include <errno.h>
Emeric Brun3bd697e2010-01-04 15:23:48 +010016
Willy Tarreaub2551052020-06-09 09:07:15 +020017#include <import/ebmbtree.h>
18#include <import/ebsttree.h>
19#include <import/ebistree.h>
20
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020021#include <haproxy/api.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020022#include <haproxy/arg.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020023#include <haproxy/cfgparse.h>
Willy Tarreau83487a82020-06-04 20:19:54 +020024#include <haproxy/cli.h>
Thayne McCombs92149f92020-11-20 01:28:26 -070025#include <haproxy/dict.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020026#include <haproxy/errors.h>
Willy Tarreauf268ee82020-06-04 17:05:57 +020027#include <haproxy/global.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020028#include <haproxy/http_rules.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020029#include <haproxy/list.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020030#include <haproxy/log.h>
Willy Tarreau6131d6a2020-06-02 16:48:09 +020031#include <haproxy/net_helper.h>
Willy Tarreau3c2a7c22020-06-04 18:38:21 +020032#include <haproxy/peers.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/pool.h>
34#include <haproxy/proto_tcp.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020035#include <haproxy/proxy.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020036#include <haproxy/sample.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020037#include <haproxy/stats-t.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020038#include <haproxy/stick_table.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020039#include <haproxy/stream.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020040#include <haproxy/stream_interface.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020041#include <haproxy/task.h>
Willy Tarreau8b550af2020-06-04 17:42:48 +020042#include <haproxy/tcp_rules.h>
Willy Tarreau92b4f132020-06-01 11:05:15 +020043#include <haproxy/time.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020044#include <haproxy/tools.h>
Emeric Brun3bd697e2010-01-04 15:23:48 +010045
Emeric Brun3bd697e2010-01-04 15:23:48 +010046
Willy Tarreau12785782012-04-27 21:37:17 +020047/* structure used to return a table key built from a sample */
Emeric Brun819fc6f2017-06-13 19:37:32 +020048static THREAD_LOCAL struct stktable_key static_table_key;
Willy Tarreau478331d2020-08-28 11:31:31 +020049static int (*smp_fetch_src)(const struct arg *, struct sample *, const char *, void *);
Willy Tarreauf0b38bf2010-06-06 13:22:23 +020050
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010051struct stktable *stktables_list;
52struct eb_root stktable_by_name = EB_ROOT;
53
Olivier Houchard52dabbc2018-11-14 17:54:36 +010054#define round_ptr_size(i) (((i) + (sizeof(void *) - 1)) &~ (sizeof(void *) - 1))
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010055
56/* This function inserts stktable <t> into the tree of known stick-table.
57 * The stick-table ID is used as the storing key so it must already have
58 * been initialized.
59 */
60void stktable_store_name(struct stktable *t)
61{
62 t->name.key = t->id;
63 ebis_insert(&stktable_by_name, &t->name);
64}
65
66struct stktable *stktable_find_by_name(const char *name)
67{
68 struct ebpt_node *node;
69 struct stktable *t;
70
71 node = ebis_lookup(&stktable_by_name, name);
72 if (node) {
73 t = container_of(node, struct stktable, name);
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010074 if (strcmp(t->id, name) == 0)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010075 return t;
76 }
77
78 return NULL;
79}
80
Emeric Brun3bd697e2010-01-04 15:23:48 +010081/*
Willy Tarreauaea940e2010-06-06 11:56:36 +020082 * Free an allocated sticky session <ts>, and decrease sticky sessions counter
83 * in table <t>.
Emeric Brun3bd697e2010-01-04 15:23:48 +010084 */
Emeric Brun819fc6f2017-06-13 19:37:32 +020085void __stksess_free(struct stktable *t, struct stksess *ts)
Emeric Brun3bd697e2010-01-04 15:23:48 +010086{
87 t->current--;
Olivier Houchard52dabbc2018-11-14 17:54:36 +010088 pool_free(t->pool, (void *)ts - round_ptr_size(t->data_size));
Emeric Brun3bd697e2010-01-04 15:23:48 +010089}
90
91/*
Emeric Brun819fc6f2017-06-13 19:37:32 +020092 * Free an allocated sticky session <ts>, and decrease sticky sessions counter
93 * in table <t>.
94 * This function locks the table
95 */
96void stksess_free(struct stktable *t, struct stksess *ts)
97{
Thayne McCombs92149f92020-11-20 01:28:26 -070098 void *data;
99 data = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_KEY);
100 if (data) {
101 dict_entry_unref(&server_key_dict, stktable_data_cast(data, server_key));
102 stktable_data_cast(data, server_key) = NULL;
103 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100104 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200105 __stksess_free(t, ts);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100106 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200107}
108
109/*
Willy Tarreauf6efda12010-08-03 20:34:06 +0200110 * Kill an stksess (only if its ref_cnt is zero).
111 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200112int __stksess_kill(struct stktable *t, struct stksess *ts)
Willy Tarreauf6efda12010-08-03 20:34:06 +0200113{
114 if (ts->ref_cnt)
Emeric Brun819fc6f2017-06-13 19:37:32 +0200115 return 0;
Willy Tarreauf6efda12010-08-03 20:34:06 +0200116
117 eb32_delete(&ts->exp);
Emeric Brun85e77c72010-09-23 18:16:52 +0200118 eb32_delete(&ts->upd);
Willy Tarreauf6efda12010-08-03 20:34:06 +0200119 ebmb_delete(&ts->key);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200120 __stksess_free(t, ts);
121 return 1;
Willy Tarreauf6efda12010-08-03 20:34:06 +0200122}
123
124/*
Emeric Brun819fc6f2017-06-13 19:37:32 +0200125 * Decrease the refcount if decrefcnt is not 0.
126 * and try to kill the stksess
127 * This function locks the table
128 */
129int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt)
130{
131 int ret;
132
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100133 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200134 if (decrefcnt)
135 ts->ref_cnt--;
136 ret = __stksess_kill(t, ts);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100137 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200138
139 return ret;
140}
141
142/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200143 * Initialize or update the key in the sticky session <ts> present in table <t>
144 * from the value present in <key>.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100145 */
Willy Tarreau393379c2010-06-06 12:11:37 +0200146void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100147{
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200148 if (t->type != SMP_T_STR)
Willy Tarreau86257dc2010-06-06 12:57:10 +0200149 memcpy(ts->key.key, key->key, t->key_size);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100150 else {
Willy Tarreau86257dc2010-06-06 12:57:10 +0200151 memcpy(ts->key.key, key->key, MIN(t->key_size - 1, key->key_len));
152 ts->key.key[MIN(t->key_size - 1, key->key_len)] = 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100153 }
154}
155
156
157/*
Willy Tarreau393379c2010-06-06 12:11:37 +0200158 * Init sticky session <ts> of table <t>. The data parts are cleared and <ts>
159 * is returned.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100160 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200161static struct stksess *__stksess_init(struct stktable *t, struct stksess * ts)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100162{
Willy Tarreau393379c2010-06-06 12:11:37 +0200163 memset((void *)ts - t->data_size, 0, t->data_size);
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200164 ts->ref_cnt = 0;
Willy Tarreau86257dc2010-06-06 12:57:10 +0200165 ts->key.node.leaf_p = NULL;
166 ts->exp.node.leaf_p = NULL;
Emeric Brun85e77c72010-09-23 18:16:52 +0200167 ts->upd.node.leaf_p = NULL;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200168 ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100169 HA_RWLOCK_INIT(&ts->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100170 return ts;
171}
172
173/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200174 * Trash oldest <to_batch> sticky sessions from table <t>
Willy Tarreaudfe79252020-11-03 17:47:41 +0100175 * Returns number of trashed sticky sessions. It may actually trash less
176 * than expected if finding these requires too long a search time (e.g.
177 * most of them have ts->ref_cnt>0).
Emeric Brun3bd697e2010-01-04 15:23:48 +0100178 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200179int __stktable_trash_oldest(struct stktable *t, int to_batch)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100180{
181 struct stksess *ts;
182 struct eb32_node *eb;
Willy Tarreaudfe79252020-11-03 17:47:41 +0100183 int max_search = to_batch * 2; // no more than 50% misses
Emeric Brun3bd697e2010-01-04 15:23:48 +0100184 int batched = 0;
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200185 int looped = 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100186
187 eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK);
188
189 while (batched < to_batch) {
190
191 if (unlikely(!eb)) {
192 /* we might have reached the end of the tree, typically because
193 * <now_ms> is in the first half and we're first scanning the last
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200194 * half. Let's loop back to the beginning of the tree now if we
195 * have not yet visited it.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100196 */
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200197 if (looped)
198 break;
199 looped = 1;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100200 eb = eb32_first(&t->exps);
201 if (likely(!eb))
202 break;
203 }
204
Willy Tarreaudfe79252020-11-03 17:47:41 +0100205 if (--max_search < 0)
206 break;
207
Emeric Brun3bd697e2010-01-04 15:23:48 +0100208 /* timer looks expired, detach it from the queue */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200209 ts = eb32_entry(eb, struct stksess, exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100210 eb = eb32_next(eb);
211
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200212 /* don't delete an entry which is currently referenced */
213 if (ts->ref_cnt)
214 continue;
215
Willy Tarreau86257dc2010-06-06 12:57:10 +0200216 eb32_delete(&ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100217
Willy Tarreau86257dc2010-06-06 12:57:10 +0200218 if (ts->expire != ts->exp.key) {
Emeric Brun3bd697e2010-01-04 15:23:48 +0100219 if (!tick_isset(ts->expire))
220 continue;
221
Willy Tarreau86257dc2010-06-06 12:57:10 +0200222 ts->exp.key = ts->expire;
223 eb32_insert(&t->exps, &ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100224
Aleksey Ponomaryovb38ad122023-02-07 19:27:06 +0100225 /* the update might have jumped beyond the next element,
226 * possibly causing a wrapping. We need to check whether
227 * the next element should be used instead. If the next
228 * element doesn't exist it means we're on the right
229 * side and have to check the first one then. If it
230 * exists and is closer, we must use it, otherwise we
231 * use the current one.
232 */
233 if (!eb)
234 eb = eb32_first(&t->exps);
235
236 if (!eb || tick_is_lt(ts->exp.key, eb->key))
Willy Tarreau86257dc2010-06-06 12:57:10 +0200237 eb = &ts->exp;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100238
239 continue;
240 }
Emeric Brun3bd697e2010-01-04 15:23:48 +0100241
Willy Tarreauaea940e2010-06-06 11:56:36 +0200242 /* session expired, trash it */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200243 ebmb_delete(&ts->key);
Emeric Brun85e77c72010-09-23 18:16:52 +0200244 eb32_delete(&ts->upd);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200245 __stksess_free(t, ts);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100246 batched++;
247 }
248
249 return batched;
250}
251
252/*
Emeric Brun819fc6f2017-06-13 19:37:32 +0200253 * Trash oldest <to_batch> sticky sessions from table <t>
254 * Returns number of trashed sticky sessions.
255 * This function locks the table
256 */
257int stktable_trash_oldest(struct stktable *t, int to_batch)
258{
259 int ret;
260
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100261 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200262 ret = __stktable_trash_oldest(t, to_batch);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100263 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200264
265 return ret;
266}
267/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200268 * Allocate and initialise a new sticky session.
269 * The new sticky session is returned or NULL in case of lack of memory.
270 * Sticky sessions should only be allocated this way, and must be freed using
Willy Tarreaua7b46b52013-04-11 16:55:37 +0200271 * stksess_free(). Table <t>'s sticky session counter is increased. If <key>
272 * is not NULL, it is assigned to the new session.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100273 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200274struct stksess *__stksess_new(struct stktable *t, struct stktable_key *key)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100275{
276 struct stksess *ts;
277
278 if (unlikely(t->current == t->size)) {
279 if ( t->nopurge )
280 return NULL;
281
Emeric Brun819fc6f2017-06-13 19:37:32 +0200282 if (!__stktable_trash_oldest(t, (t->size >> 8) + 1))
Emeric Brun3bd697e2010-01-04 15:23:48 +0100283 return NULL;
284 }
285
Willy Tarreaubafbe012017-11-24 17:34:44 +0100286 ts = pool_alloc(t->pool);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100287 if (ts) {
288 t->current++;
Olivier Houchard52dabbc2018-11-14 17:54:36 +0100289 ts = (void *)ts + round_ptr_size(t->data_size);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200290 __stksess_init(t, ts);
Willy Tarreaua7b46b52013-04-11 16:55:37 +0200291 if (key)
292 stksess_setkey(t, ts, key);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100293 }
294
295 return ts;
296}
Emeric Brun819fc6f2017-06-13 19:37:32 +0200297/*
298 * Allocate and initialise a new sticky session.
299 * The new sticky session is returned or NULL in case of lack of memory.
300 * Sticky sessions should only be allocated this way, and must be freed using
301 * stksess_free(). Table <t>'s sticky session counter is increased. If <key>
302 * is not NULL, it is assigned to the new session.
303 * This function locks the table
304 */
305struct stksess *stksess_new(struct stktable *t, struct stktable_key *key)
306{
307 struct stksess *ts;
308
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100309 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200310 ts = __stksess_new(t, key);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100311 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200312
313 return ts;
314}
Emeric Brun3bd697e2010-01-04 15:23:48 +0100315
316/*
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200317 * Looks in table <t> for a sticky session matching key <key>.
Willy Tarreauaea940e2010-06-06 11:56:36 +0200318 * Returns pointer on requested sticky session or NULL if none was found.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100319 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200320struct stksess *__stktable_lookup_key(struct stktable *t, struct stktable_key *key)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100321{
322 struct ebmb_node *eb;
323
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200324 if (t->type == SMP_T_STR)
Emeric Brun485479d2010-09-23 18:02:19 +0200325 eb = ebst_lookup_len(&t->keys, key->key, key->key_len+1 < t->key_size ? key->key_len : t->key_size-1);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100326 else
327 eb = ebmb_lookup(&t->keys, key->key, t->key_size);
328
329 if (unlikely(!eb)) {
330 /* no session found */
331 return NULL;
332 }
333
Willy Tarreau86257dc2010-06-06 12:57:10 +0200334 return ebmb_entry(eb, struct stksess, key);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100335}
336
Emeric Brun819fc6f2017-06-13 19:37:32 +0200337/*
338 * Looks in table <t> for a sticky session matching key <key>.
339 * Returns pointer on requested sticky session or NULL if none was found.
340 * The refcount of the found entry is increased and this function
341 * is protected using the table lock
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200342 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200343struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key)
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200344{
345 struct stksess *ts;
346
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100347 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200348 ts = __stktable_lookup_key(t, key);
349 if (ts)
350 ts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100351 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200352
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200353 return ts;
354}
355
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200356/*
357 * Looks in table <t> for a sticky session with same key as <ts>.
358 * Returns pointer on requested sticky session or NULL if none was found.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100359 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200360struct stksess *__stktable_lookup(struct stktable *t, struct stksess *ts)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100361{
Emeric Brun3bd697e2010-01-04 15:23:48 +0100362 struct ebmb_node *eb;
363
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200364 if (t->type == SMP_T_STR)
Willy Tarreau86257dc2010-06-06 12:57:10 +0200365 eb = ebst_lookup(&(t->keys), (char *)ts->key.key);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100366 else
Willy Tarreau86257dc2010-06-06 12:57:10 +0200367 eb = ebmb_lookup(&(t->keys), ts->key.key, t->key_size);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100368
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200369 if (unlikely(!eb))
370 return NULL;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100371
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200372 return ebmb_entry(eb, struct stksess, key);
373}
Emeric Brun3bd697e2010-01-04 15:23:48 +0100374
Emeric Brun819fc6f2017-06-13 19:37:32 +0200375/*
376 * Looks in table <t> for a sticky session with same key as <ts>.
377 * Returns pointer on requested sticky session or NULL if none was found.
378 * The refcount of the found entry is increased and this function
379 * is protected using the table lock
380 */
381struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts)
382{
383 struct stksess *lts;
384
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100385 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200386 lts = __stktable_lookup(t, ts);
387 if (lts)
388 lts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100389 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200390
391 return lts;
392}
393
Willy Tarreaucb183642010-06-06 17:58:34 +0200394/* Update the expiration timer for <ts> but do not touch its expiration node.
395 * The table's expiration timer is updated if set.
Emeric Brun819fc6f2017-06-13 19:37:32 +0200396 * The node will be also inserted into the update tree if needed, at a position
397 * depending if the update is a local or coming from a remote node
Willy Tarreaucb183642010-06-06 17:58:34 +0200398 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200399void __stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local, int expire)
Willy Tarreaucb183642010-06-06 17:58:34 +0200400{
Emeric Brun85e77c72010-09-23 18:16:52 +0200401 struct eb32_node * eb;
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200402 ts->expire = expire;
Willy Tarreaucb183642010-06-06 17:58:34 +0200403 if (t->expire) {
404 t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next);
405 task_queue(t->exp_task);
406 }
Emeric Brun85e77c72010-09-23 18:16:52 +0200407
Emeric Brun819fc6f2017-06-13 19:37:32 +0200408 /* If sync is enabled */
409 if (t->sync_task) {
410 if (local) {
411 /* If this entry is not in the tree
412 or not scheduled for at least one peer */
413 if (!ts->upd.node.leaf_p
414 || (int)(t->commitupdate - ts->upd.key) >= 0
415 || (int)(ts->upd.key - t->localupdate) >= 0) {
416 ts->upd.key = ++t->update;
417 t->localupdate = t->update;
418 eb32_delete(&ts->upd);
419 eb = eb32_insert(&t->updates, &ts->upd);
420 if (eb != &ts->upd) {
421 eb32_delete(eb);
422 eb32_insert(&t->updates, &ts->upd);
423 }
Emeric Brunaaf58602015-06-15 17:23:30 +0200424 }
Emeric Brun819fc6f2017-06-13 19:37:32 +0200425 task_wakeup(t->sync_task, TASK_WOKEN_MSG);
Emeric Brun85e77c72010-09-23 18:16:52 +0200426 }
Emeric Brun819fc6f2017-06-13 19:37:32 +0200427 else {
428 /* If this entry is not in the tree */
429 if (!ts->upd.node.leaf_p) {
430 ts->upd.key= (++t->update)+(2147483648U);
431 eb = eb32_insert(&t->updates, &ts->upd);
432 if (eb != &ts->upd) {
433 eb32_delete(eb);
434 eb32_insert(&t->updates, &ts->upd);
435 }
436 }
437 }
Emeric Brun85e77c72010-09-23 18:16:52 +0200438 }
Willy Tarreaucb183642010-06-06 17:58:34 +0200439}
440
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200441/* Update the expiration timer for <ts> but do not touch its expiration node.
Emeric Brun819fc6f2017-06-13 19:37:32 +0200442 * The table's expiration timer is updated using the date of expiration coming from
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200443 * <t> stick-table configuration.
Emeric Brun819fc6f2017-06-13 19:37:32 +0200444 * The node will be also inserted into the update tree if needed, at a position
445 * considering the update is coming from a remote node
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200446 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200447void stktable_touch_remote(struct stktable *t, struct stksess *ts, int decrefcnt)
448{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100449 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200450 __stktable_touch_with_exp(t, ts, 0, ts->expire);
451 if (decrefcnt)
452 ts->ref_cnt--;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100453 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200454}
455
456/* Update the expiration timer for <ts> but do not touch its expiration node.
457 * The table's expiration timer is updated using the date of expiration coming from
458 * <t> stick-table configuration.
459 * The node will be also inserted into the update tree if needed, at a position
460 * considering the update was made locally
461 */
462void stktable_touch_local(struct stktable *t, struct stksess *ts, int decrefcnt)
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200463{
464 int expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
465
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100466 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200467 __stktable_touch_with_exp(t, ts, 1, expire);
468 if (decrefcnt)
469 ts->ref_cnt--;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100470 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200471}
Willy Tarreau43e90352018-06-27 06:25:57 +0200472/* Just decrease the ref_cnt of the current session. Does nothing if <ts> is NULL */
473static void stktable_release(struct stktable *t, struct stksess *ts)
Emeric Brun819fc6f2017-06-13 19:37:32 +0200474{
Willy Tarreau43e90352018-06-27 06:25:57 +0200475 if (!ts)
476 return;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100477 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200478 ts->ref_cnt--;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100479 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200480}
481
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200482/* Insert new sticky session <ts> in the table. It is assumed that it does not
483 * yet exist (the caller must check this). The table's timeout is updated if it
484 * is set. <ts> is returned.
485 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200486void __stktable_store(struct stktable *t, struct stksess *ts)
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200487{
Emeric Brun3bd697e2010-01-04 15:23:48 +0100488
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200489 ebmb_insert(&t->keys, &ts->key, t->key_size);
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200490 ts->exp.key = ts->expire;
491 eb32_insert(&t->exps, &ts->exp);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200492 if (t->expire) {
493 t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next);
494 task_queue(t->exp_task);
495 }
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200496}
497
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200498/* Returns a valid or initialized stksess for the specified stktable_key in the
499 * specified table, or NULL if the key was NULL, or if no entry was found nor
500 * could be created. The entry's expiration is updated.
501 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200502struct stksess *__stktable_get_entry(struct stktable *table, struct stktable_key *key)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200503{
504 struct stksess *ts;
505
506 if (!key)
507 return NULL;
508
Emeric Brun819fc6f2017-06-13 19:37:32 +0200509 ts = __stktable_lookup_key(table, key);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200510 if (ts == NULL) {
511 /* entry does not exist, initialize a new one */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200512 ts = __stksess_new(table, key);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200513 if (!ts)
514 return NULL;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200515 __stktable_store(table, ts);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200516 }
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200517 return ts;
518}
Emeric Brun819fc6f2017-06-13 19:37:32 +0200519/* Returns a valid or initialized stksess for the specified stktable_key in the
520 * specified table, or NULL if the key was NULL, or if no entry was found nor
521 * could be created. The entry's expiration is updated.
522 * This function locks the table, and the refcount of the entry is increased.
523 */
524struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key)
525{
526 struct stksess *ts;
527
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100528 HA_SPIN_LOCK(STK_TABLE_LOCK, &table->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200529 ts = __stktable_get_entry(table, key);
530 if (ts)
531 ts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100532 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &table->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200533
534 return ts;
535}
536
537/* Lookup for an entry with the same key and store the submitted
538 * stksess if not found.
539 */
540struct stksess *__stktable_set_entry(struct stktable *table, struct stksess *nts)
541{
542 struct stksess *ts;
543
544 ts = __stktable_lookup(table, nts);
545 if (ts == NULL) {
546 ts = nts;
547 __stktable_store(table, ts);
548 }
549 return ts;
550}
551
552/* Lookup for an entry with the same key and store the submitted
553 * stksess if not found.
554 * This function locks the table, and the refcount of the entry is increased.
555 */
556struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts)
557{
558 struct stksess *ts;
559
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100560 HA_SPIN_LOCK(STK_TABLE_LOCK, &table->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200561 ts = __stktable_set_entry(table, nts);
562 ts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100563 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &table->lock);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200564
Emeric Brun819fc6f2017-06-13 19:37:32 +0200565 return ts;
566}
Emeric Brun3bd697e2010-01-04 15:23:48 +0100567/*
Willy Tarreaud2636522022-11-14 18:02:44 +0100568 * Task processing function to trash expired sticky sessions. A pointer to the
569 * task itself is returned since it never dies.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100570 */
Willy Tarreaud2636522022-11-14 18:02:44 +0100571struct task *process_table_expire(struct task *task, void *context, unsigned int state)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100572{
Willy Tarreaud2636522022-11-14 18:02:44 +0100573 struct stktable *t = context;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100574 struct stksess *ts;
575 struct eb32_node *eb;
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200576 int looped = 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100577
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100578 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100579 eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK);
580
581 while (1) {
582 if (unlikely(!eb)) {
583 /* we might have reached the end of the tree, typically because
584 * <now_ms> is in the first half and we're first scanning the last
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200585 * half. Let's loop back to the beginning of the tree now if we
586 * have not yet visited it.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100587 */
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200588 if (looped)
589 break;
590 looped = 1;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100591 eb = eb32_first(&t->exps);
592 if (likely(!eb))
593 break;
594 }
595
596 if (likely(tick_is_lt(now_ms, eb->key))) {
597 /* timer not expired yet, revisit it later */
598 t->exp_next = eb->key;
Willy Tarreau4d5f13c2017-11-05 11:04:47 +0100599 goto out_unlock;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100600 }
601
602 /* timer looks expired, detach it from the queue */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200603 ts = eb32_entry(eb, struct stksess, exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100604 eb = eb32_next(eb);
605
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200606 /* don't delete an entry which is currently referenced */
607 if (ts->ref_cnt)
608 continue;
609
Willy Tarreau86257dc2010-06-06 12:57:10 +0200610 eb32_delete(&ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100611
612 if (!tick_is_expired(ts->expire, now_ms)) {
613 if (!tick_isset(ts->expire))
614 continue;
615
Willy Tarreau86257dc2010-06-06 12:57:10 +0200616 ts->exp.key = ts->expire;
617 eb32_insert(&t->exps, &ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100618
Aleksey Ponomaryovb38ad122023-02-07 19:27:06 +0100619 /* the update might have jumped beyond the next element,
620 * possibly causing a wrapping. We need to check whether
621 * the next element should be used instead. If the next
622 * element doesn't exist it means we're on the right
623 * side and have to check the first one then. If it
624 * exists and is closer, we must use it, otherwise we
625 * use the current one.
626 */
627 if (!eb)
628 eb = eb32_first(&t->exps);
629
630 if (!eb || tick_is_lt(ts->exp.key, eb->key))
Willy Tarreau86257dc2010-06-06 12:57:10 +0200631 eb = &ts->exp;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100632 continue;
633 }
634
635 /* session expired, trash it */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200636 ebmb_delete(&ts->key);
Emeric Brun85e77c72010-09-23 18:16:52 +0200637 eb32_delete(&ts->upd);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200638 __stksess_free(t, ts);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100639 }
640
641 /* We have found no task to expire in any tree */
642 t->exp_next = TICK_ETERNITY;
Willy Tarreau4d5f13c2017-11-05 11:04:47 +0100643out_unlock:
Willy Tarreaud2636522022-11-14 18:02:44 +0100644 task->expire = t->exp_next;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100645 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100646 return task;
647}
648
Willy Tarreauaea940e2010-06-06 11:56:36 +0200649/* Perform minimal stick table intializations, report 0 in case of error, 1 if OK. */
Emeric Brun3bd697e2010-01-04 15:23:48 +0100650int stktable_init(struct stktable *t)
651{
Remi Tricot-Le Bretonbe5b1bb2021-05-12 17:39:04 +0200652 int peers_retval = 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100653 if (t->size) {
Emeric Brun819fc6f2017-06-13 19:37:32 +0200654 t->keys = EB_ROOT_UNIQUE;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100655 memset(&t->exps, 0, sizeof(t->exps));
Emeric Brun1c6235d2015-12-16 15:28:12 +0100656 t->updates = EB_ROOT_UNIQUE;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100657 HA_SPIN_INIT(&t->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100658
Olivier Houchard52dabbc2018-11-14 17:54:36 +0100659 t->pool = create_pool("sticktables", sizeof(struct stksess) + round_ptr_size(t->data_size) + t->key_size, MEM_F_SHARED);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100660
661 t->exp_next = TICK_ETERNITY;
662 if ( t->expire ) {
Emeric Brunc60def82017-09-27 14:59:38 +0200663 t->exp_task = task_new(MAX_THREADS_MASK);
Willy Tarreau848522f2018-10-15 11:12:15 +0200664 if (!t->exp_task)
665 return 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100666 t->exp_task->process = process_table_expire;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100667 t->exp_task->context = (void *)t;
668 }
Willy Tarreauc3914d42020-09-24 08:39:22 +0200669 if (t->peers.p && t->peers.p->peers_fe && !t->peers.p->peers_fe->disabled) {
Remi Tricot-Le Bretonbe5b1bb2021-05-12 17:39:04 +0200670 peers_retval = peers_register_table(t->peers.p, t);
Emeric Brun32da3c42010-09-23 18:39:19 +0200671 }
672
Remi Tricot-Le Bretonbe5b1bb2021-05-12 17:39:04 +0200673 return (t->pool != NULL) && !peers_retval;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100674 }
675 return 1;
676}
677
678/*
679 * Configuration keywords of known table types
680 */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200681struct stktable_type stktable_types[SMP_TYPES] = {
682 [SMP_T_SINT] = { "integer", 0, 4 },
683 [SMP_T_IPV4] = { "ip", 0, 4 },
684 [SMP_T_IPV6] = { "ipv6", 0, 16 },
685 [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 },
686 [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 }
687};
Emeric Brun3bd697e2010-01-04 15:23:48 +0100688
689/*
690 * Parse table type configuration.
691 * Returns 0 on successful parsing, else 1.
692 * <myidx> is set at next configuration <args> index.
693 */
William Lallemand42b46252023-04-13 14:33:52 +0200694int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size, const char *file, int linenum)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100695{
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200696 for (*type = 0; *type < SMP_TYPES; (*type)++) {
697 if (!stktable_types[*type].kw)
698 continue;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100699 if (strcmp(args[*myidx], stktable_types[*type].kw) != 0)
700 continue;
701
702 *key_size = stktable_types[*type].default_size;
703 (*myidx)++;
704
Willy Tarreauaea940e2010-06-06 11:56:36 +0200705 if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) {
Emeric Brun3bd697e2010-01-04 15:23:48 +0100706 if (strcmp("len", args[*myidx]) == 0) {
William Lallemand42b46252023-04-13 14:33:52 +0200707 char *stop;
708
Emeric Brun3bd697e2010-01-04 15:23:48 +0100709 (*myidx)++;
William Lallemand42b46252023-04-13 14:33:52 +0200710 *key_size = strtol(args[*myidx], &stop, 10);
711 if (*stop != '\0' || !*key_size) {
712 ha_alert("parsing [%s:%d] : 'len' expects a positive integer argument.\n", file, linenum);
713 return 1;
714 }
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200715 if (*type == SMP_T_STR) {
Emeric Brun485479d2010-09-23 18:02:19 +0200716 /* null terminated string needs +1 for '\0'. */
717 (*key_size)++;
718 }
Emeric Brun3bd697e2010-01-04 15:23:48 +0100719 (*myidx)++;
720 }
721 }
722 return 0;
723 }
William Lallemand42b46252023-04-13 14:33:52 +0200724 ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n", file, linenum, args[0], args[*myidx]);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100725 return 1;
726}
727
Willy Tarreau3b63ca22021-05-08 14:10:42 +0200728/* reserve some space for data type <type>, and associate argument at <sa> if
729 * not NULL. Returns PE_NONE (0) if OK or an error code among :
730 * - PE_ENUM_OOR if <type> does not exist
731 * - PE_EXIST if <type> is already registered
732 * - PE_ARG_NOT_USE if <sa> was provided but not expected
733 * - PE_ARG_MISSING if <sa> was expected but not provided
734 */
735int stktable_alloc_data_type(struct stktable *t, int type, const char *sa)
736{
737 if (type >= STKTABLE_DATA_TYPES)
738 return PE_ENUM_OOR;
739
740 if (t->data_ofs[type])
741 /* already allocated */
742 return PE_EXIST;
743
744 switch (stktable_data_types[type].arg_type) {
745 case ARG_T_NONE:
746 if (sa)
747 return PE_ARG_NOT_USED;
748 break;
749 case ARG_T_INT:
750 if (!sa)
751 return PE_ARG_MISSING;
752 t->data_arg[type].i = atoi(sa);
753 break;
754 case ARG_T_DELAY:
755 if (!sa)
756 return PE_ARG_MISSING;
757 sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS);
758 if (sa)
759 return PE_ARG_INVC; /* invalid char */
760 break;
761 }
762
763 t->data_size += stktable_type_size(stktable_data_types[type].std_type);
764 t->data_ofs[type] = -t->data_size;
765 return PE_NONE;
766}
767
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100768/*
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100769 * Parse a line with <linenum> as number in <file> configuration file to configure
770 * the stick-table with <t> as address and <id> as ID.
771 * <peers> provides the "peers" section pointer only if this function is called
772 * from a "peers" section.
773 * <nid> is the stick-table name which is sent over the network. It must be equal
774 * to <id> if this stick-table is parsed from a proxy section, and prefixed by <peers>
775 * "peers" section name followed by a '/' character if parsed from a "peers" section.
Ilya Shipitsind4259502020-04-08 01:07:56 +0500776 * This is the responsibility of the caller to check this.
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100777 * Return an error status with ERR_* flags set if required, 0 if no error was encountered.
778 */
779int parse_stick_table(const char *file, int linenum, char **args,
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100780 struct stktable *t, char *id, char *nid, struct peers *peers)
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100781{
782 int err_code = 0;
783 int idx = 1;
784 unsigned int val;
785
786 if (!id || !*id) {
787 ha_alert("parsing [%s:%d] : %s: ID not provided.\n", file, linenum, args[0]);
788 err_code |= ERR_ALERT | ERR_ABORT;
789 goto out;
790 }
791
792 /* Store the "peers" section if this function is called from a "peers" section. */
793 if (peers) {
794 t->peers.p = peers;
795 idx++;
796 }
797
798 t->id = id;
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100799 t->nid = nid;
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100800 t->type = (unsigned int)-1;
801 t->conf.file = file;
802 t->conf.line = linenum;
803
804 while (*args[idx]) {
805 const char *err;
806
807 if (strcmp(args[idx], "size") == 0) {
808 idx++;
809 if (!*(args[idx])) {
810 ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n",
811 file, linenum, args[0], args[idx-1]);
812 err_code |= ERR_ALERT | ERR_FATAL;
813 goto out;
814 }
815 if ((err = parse_size_err(args[idx], &t->size))) {
816 ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n",
817 file, linenum, args[0], *err, args[idx-1]);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821 idx++;
822 }
823 /* This argument does not exit in "peers" section. */
824 else if (!peers && strcmp(args[idx], "peers") == 0) {
825 idx++;
826 if (!*(args[idx])) {
827 ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n",
828 file, linenum, args[0], args[idx-1]);
829 err_code |= ERR_ALERT | ERR_FATAL;
830 goto out;
831 }
832 t->peers.name = strdup(args[idx++]);
833 }
834 else if (strcmp(args[idx], "expire") == 0) {
835 idx++;
836 if (!*(args[idx])) {
837 ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n",
838 file, linenum, args[0], args[idx-1]);
839 err_code |= ERR_ALERT | ERR_FATAL;
840 goto out;
841 }
842 err = parse_time_err(args[idx], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200843 if (err == PARSE_TIME_OVER) {
844 ha_alert("parsing [%s:%d]: %s: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
845 file, linenum, args[0], args[idx], args[idx-1]);
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100846 err_code |= ERR_ALERT | ERR_FATAL;
847 goto out;
848 }
Willy Tarreau9faebe32019-06-07 19:00:37 +0200849 else if (err == PARSE_TIME_UNDER) {
850 ha_alert("parsing [%s:%d]: %s: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
851 file, linenum, args[0], args[idx], args[idx-1]);
852 err_code |= ERR_ALERT | ERR_FATAL;
853 goto out;
854 }
855 else if (err) {
856 ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n",
857 file, linenum, args[0], *err, args[idx-1]);
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100858 err_code |= ERR_ALERT | ERR_FATAL;
859 goto out;
860 }
861 t->expire = val;
862 idx++;
863 }
864 else if (strcmp(args[idx], "nopurge") == 0) {
865 t->nopurge = 1;
866 idx++;
867 }
868 else if (strcmp(args[idx], "type") == 0) {
869 idx++;
William Lallemand42b46252023-04-13 14:33:52 +0200870 if (stktable_parse_type(args, &idx, &t->type, &t->key_size, file, linenum) != 0) {
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100871 err_code |= ERR_ALERT | ERR_FATAL;
872 goto out;
873 }
874 /* idx already points to next arg */
875 }
876 else if (strcmp(args[idx], "store") == 0) {
877 int type, err;
878 char *cw, *nw, *sa;
879
880 idx++;
881 nw = args[idx];
882 while (*nw) {
883 /* the "store" keyword supports a comma-separated list */
884 cw = nw;
885 sa = NULL; /* store arg */
886 while (*nw && *nw != ',') {
887 if (*nw == '(') {
888 *nw = 0;
889 sa = ++nw;
890 while (*nw != ')') {
891 if (!*nw) {
892 ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n",
893 file, linenum, args[0], cw);
894 err_code |= ERR_ALERT | ERR_FATAL;
895 goto out;
896 }
897 nw++;
898 }
899 *nw = '\0';
900 }
901 nw++;
902 }
903 if (*nw)
904 *nw++ = '\0';
905 type = stktable_get_data_type(cw);
906 if (type < 0) {
907 ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n",
908 file, linenum, args[0], cw);
909 err_code |= ERR_ALERT | ERR_FATAL;
910 goto out;
911 }
912
913 err = stktable_alloc_data_type(t, type, sa);
914 switch (err) {
915 case PE_NONE: break;
916 case PE_EXIST:
917 ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n",
918 file, linenum, args[0], cw);
919 err_code |= ERR_WARN;
920 break;
921
922 case PE_ARG_MISSING:
923 ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n",
924 file, linenum, args[0], cw);
925 err_code |= ERR_ALERT | ERR_FATAL;
926 goto out;
927
928 case PE_ARG_NOT_USED:
929 ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n",
930 file, linenum, args[0], cw);
931 err_code |= ERR_ALERT | ERR_FATAL;
932 goto out;
933
934 default:
935 ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n",
936 file, linenum, args[0], cw);
937 err_code |= ERR_ALERT | ERR_FATAL;
938 goto out;
939 }
940 }
941 idx++;
942 }
Thayne McCombs92149f92020-11-20 01:28:26 -0700943 else if (strcmp(args[idx], "srvkey") == 0) {
944 char *keytype;
945 idx++;
946 keytype = args[idx];
947 if (strcmp(keytype, "name") == 0) {
948 t->server_key_type = STKTABLE_SRV_NAME;
949 }
950 else if (strcmp(keytype, "addr") == 0) {
951 t->server_key_type = STKTABLE_SRV_ADDR;
952 }
953 else {
954 ha_alert("parsing [%s:%d] : %s : unknown server key type '%s'.\n",
955 file, linenum, args[0], keytype);
956 err_code |= ERR_ALERT | ERR_FATAL;
957 goto out;
958
959 }
960 idx++;
961 }
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100962 else {
963 ha_alert("parsing [%s:%d] : %s: unknown argument '%s'.\n",
964 file, linenum, args[0], args[idx]);
965 err_code |= ERR_ALERT | ERR_FATAL;
966 goto out;
967 }
968 }
969
970 if (!t->size) {
971 ha_alert("parsing [%s:%d] : %s: missing size.\n",
972 file, linenum, args[0]);
973 err_code |= ERR_ALERT | ERR_FATAL;
974 goto out;
975 }
976
977 if (t->type == (unsigned int)-1) {
978 ha_alert("parsing [%s:%d] : %s: missing type.\n",
979 file, linenum, args[0]);
980 err_code |= ERR_ALERT | ERR_FATAL;
981 goto out;
982 }
983
984 out:
985 return err_code;
986}
987
Willy Tarreau8fed9032014-07-03 17:02:46 +0200988/* Prepares a stktable_key from a sample <smp> to search into table <t>.
Willy Tarreauf0c730a2016-05-25 17:07:56 +0200989 * Note that the sample *is* modified and that the returned key may point
990 * to it, so the sample must not be modified afterwards before the lookup.
Willy Tarreau8fed9032014-07-03 17:02:46 +0200991 * Returns NULL if the sample could not be converted (eg: no matching type),
992 * otherwise a pointer to the static stktable_key filled with what is needed
993 * for the lookup.
Willy Tarreauf0b38bf2010-06-06 13:22:23 +0200994 */
Willy Tarreau8fed9032014-07-03 17:02:46 +0200995struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
Willy Tarreauf0b38bf2010-06-06 13:22:23 +0200996{
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200997 /* Convert sample. */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200998 if (!sample_convert(smp, t->type))
Willy Tarreau7fc1c6e2012-04-26 11:03:17 +0200999 return NULL;
1000
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001001 /* Fill static_table_key. */
1002 switch (t->type) {
Emeric Brun485479d2010-09-23 18:02:19 +02001003
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +02001004 case SMP_T_IPV4:
Christopher Fauletca20d022017-08-29 15:30:31 +02001005 static_table_key.key = &smp->data.u.ipv4;
1006 static_table_key.key_len = 4;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001007 break;
Emeric Brun485479d2010-09-23 18:02:19 +02001008
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +02001009 case SMP_T_IPV6:
Christopher Fauletca20d022017-08-29 15:30:31 +02001010 static_table_key.key = &smp->data.u.ipv6;
1011 static_table_key.key_len = 16;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001012 break;
Emeric Brun485479d2010-09-23 18:02:19 +02001013
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +02001014 case SMP_T_SINT:
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001015 /* The stick table require a 32bit unsigned int, "sint" is a
1016 * signed 64 it, so we can convert it inplace.
1017 */
Willy Tarreau28c63c12019-10-23 06:21:05 +02001018 smp->data.u.sint = (unsigned int)smp->data.u.sint;
Christopher Fauletca20d022017-08-29 15:30:31 +02001019 static_table_key.key = &smp->data.u.sint;
1020 static_table_key.key_len = 4;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001021 break;
1022
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +02001023 case SMP_T_STR:
Willy Tarreauce6955e2016-08-09 11:59:12 +02001024 if (!smp_make_safe(smp))
1025 return NULL;
Willy Tarreau843b7cb2018-07-13 10:54:26 +02001026 static_table_key.key = smp->data.u.str.area;
1027 static_table_key.key_len = smp->data.u.str.data;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001028 break;
Emeric Brun485479d2010-09-23 18:02:19 +02001029
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +02001030 case SMP_T_BIN:
Willy Tarreau843b7cb2018-07-13 10:54:26 +02001031 if (smp->data.u.str.data < t->key_size) {
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001032 /* This type needs padding with 0. */
Willy Tarreauf65c6c02016-08-09 12:08:41 +02001033 if (!smp_make_rw(smp))
1034 return NULL;
1035
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001036 if (smp->data.u.str.size < t->key_size)
1037 if (!smp_dup(smp))
1038 return NULL;
1039 if (smp->data.u.str.size < t->key_size)
1040 return NULL;
Willy Tarreau843b7cb2018-07-13 10:54:26 +02001041 memset(smp->data.u.str.area + smp->data.u.str.data, 0,
1042 t->key_size - smp->data.u.str.data);
1043 smp->data.u.str.data = t->key_size;
Emeric Brun485479d2010-09-23 18:02:19 +02001044 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +02001045 static_table_key.key = smp->data.u.str.area;
1046 static_table_key.key_len = smp->data.u.str.data;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001047 break;
Emeric Brun485479d2010-09-23 18:02:19 +02001048
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001049 default: /* impossible case. */
1050 return NULL;
Emeric Brun485479d2010-09-23 18:02:19 +02001051 }
1052
Christopher Fauletca20d022017-08-29 15:30:31 +02001053 return &static_table_key;
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001054}
1055
1056/*
Willy Tarreau8fed9032014-07-03 17:02:46 +02001057 * Process a fetch + format conversion as defined by the sample expression <expr>
1058 * on request or response considering the <opt> parameter. Returns either NULL if
1059 * no key could be extracted, or a pointer to the converted result stored in
1060 * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset
1061 * and its flags will be initialized so that the caller gets a copy of the input
Willy Tarreau6bcb0a82014-07-30 08:56:35 +02001062 * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present
1063 * without SMP_OPT_FINAL). The output will be usable like this :
1064 *
1065 * return MAY_CHANGE FINAL Meaning for the sample
1066 * NULL 0 * Not present and will never be (eg: header)
1067 * NULL 1 0 Not present or unstable, could change (eg: req_len)
1068 * NULL 1 1 Not present, will not change anymore
1069 * smp 0 * Present and will not change (eg: header)
1070 * smp 1 0 not possible
1071 * smp 1 1 Present, last known value (eg: request length)
Willy Tarreau8fed9032014-07-03 17:02:46 +02001072 */
Willy Tarreau192252e2015-04-04 01:47:55 +02001073struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *sess, struct stream *strm,
Willy Tarreau8fed9032014-07-03 17:02:46 +02001074 unsigned int opt, struct sample_expr *expr, struct sample *smp)
1075{
1076 if (smp)
1077 memset(smp, 0, sizeof(*smp));
1078
Willy Tarreau192252e2015-04-04 01:47:55 +02001079 smp = sample_process(px, sess, strm, opt, expr, smp);
Willy Tarreau8fed9032014-07-03 17:02:46 +02001080 if (!smp)
1081 return NULL;
1082
1083 if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL))
1084 return NULL; /* we can only use stable samples */
1085
1086 return smp_to_stkey(smp, t);
1087}
1088
1089/*
Willy Tarreau12785782012-04-27 21:37:17 +02001090 * Returns 1 if sample expression <expr> result can be converted to table key of
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001091 * type <table_type>, otherwise zero. Used in configuration check.
1092 */
Willy Tarreau12785782012-04-27 21:37:17 +02001093int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type)
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001094{
Thierry FOURNIERf73eb8f2013-11-27 15:30:55 +01001095 int out_type;
1096
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +02001097 if (table_type >= SMP_TYPES || !stktable_types[table_type].kw)
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001098 return 0;
1099
Thierry FOURNIERf73eb8f2013-11-27 15:30:55 +01001100 out_type = smp_expr_output_type(expr);
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001101
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001102 /* Convert sample. */
1103 if (!sample_casts[out_type][table_type])
Thierry FOURNIERf73eb8f2013-11-27 15:30:55 +01001104 return 0;
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001105
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001106 return 1;
1107}
Emeric Brun3bd697e2010-01-04 15:23:48 +01001108
Willy Tarreauedee1d62014-07-15 16:44:27 +02001109/* Extra data types processing : after the last one, some room may remain
1110 * before STKTABLE_DATA_TYPES that may be used to register extra data types
1111 * at run time.
1112 */
Willy Tarreau08d5f982010-06-06 13:34:54 +02001113struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = {
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02001114 [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT },
Thierry FOURNIER3cf11112015-07-28 08:57:05 +02001115 [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT },
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02001116 [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT },
Willy Tarreauba2ffd12013-05-29 15:54:14 +02001117 [STKTABLE_DT_GPC0_RATE] = { .name = "gpc0_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02001118 [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT },
1119 [STKTABLE_DT_CONN_RATE] = { .name = "conn_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1120 [STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .std_type = STD_T_UINT },
1121 [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT },
1122 [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1123 [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT },
1124 [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1125 [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT },
1126 [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1127 [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL },
1128 [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1129 [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL },
1130 [STKTABLE_DT_BYTES_OUT_RATE]= { .name = "bytes_out_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001131 [STKTABLE_DT_GPC1] = { .name = "gpc1", .std_type = STD_T_UINT },
1132 [STKTABLE_DT_GPC1_RATE] = { .name = "gpc1_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
Thayne McCombs92149f92020-11-20 01:28:26 -07001133 [STKTABLE_DT_SERVER_KEY] = { .name = "server_key", .std_type = STD_T_DICT },
Willy Tarreau826f3ab2021-02-10 12:07:15 +01001134 [STKTABLE_DT_HTTP_FAIL_CNT] = { .name = "http_fail_cnt", .std_type = STD_T_UINT },
1135 [STKTABLE_DT_HTTP_FAIL_RATE]= { .name = "http_fail_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
Willy Tarreau08d5f982010-06-06 13:34:54 +02001136};
1137
Willy Tarreauedee1d62014-07-15 16:44:27 +02001138/* Registers stick-table extra data type with index <idx>, name <name>, type
1139 * <std_type> and arg type <arg_type>. If the index is negative, the next free
1140 * index is automatically allocated. The allocated index is returned, or -1 if
1141 * no free index was found or <name> was already registered. The <name> is used
1142 * directly as a pointer, so if it's not stable, the caller must allocate it.
1143 */
1144int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type)
1145{
1146 if (idx < 0) {
1147 for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) {
1148 if (!stktable_data_types[idx].name)
1149 break;
1150
1151 if (strcmp(stktable_data_types[idx].name, name) == 0)
1152 return -1;
1153 }
1154 }
1155
1156 if (idx >= STKTABLE_DATA_TYPES)
1157 return -1;
1158
1159 if (stktable_data_types[idx].name != NULL)
1160 return -1;
1161
1162 stktable_data_types[idx].name = name;
1163 stktable_data_types[idx].std_type = std_type;
1164 stktable_data_types[idx].arg_type = arg_type;
1165 return idx;
1166}
1167
Willy Tarreau08d5f982010-06-06 13:34:54 +02001168/*
1169 * Returns the data type number for the stktable_data_type whose name is <name>,
1170 * or <0 if not found.
1171 */
1172int stktable_get_data_type(char *name)
1173{
1174 int type;
1175
1176 for (type = 0; type < STKTABLE_DATA_TYPES; type++) {
Willy Tarreauedee1d62014-07-15 16:44:27 +02001177 if (!stktable_data_types[type].name)
1178 continue;
Willy Tarreau08d5f982010-06-06 13:34:54 +02001179 if (strcmp(name, stktable_data_types[type].name) == 0)
1180 return type;
1181 }
Thayne McCombs92149f92020-11-20 01:28:26 -07001182 /* For backwards compatibility */
1183 if (strcmp(name, "server_name") == 0)
1184 return STKTABLE_DT_SERVER_KEY;
Willy Tarreau08d5f982010-06-06 13:34:54 +02001185 return -1;
1186}
1187
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001188/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1189 * it up into this table. Returns true if found, false otherwise. The input
1190 * type is STR so that input samples are converted to string (since all types
1191 * can be converted to strings), then the function casts the string again into
1192 * the table's type. This is a double conversion, but in the future we might
1193 * support automatic input types to perform the cast on the fly.
1194 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001195static int sample_conv_in_table(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001196{
1197 struct stktable *t;
1198 struct stktable_key *key;
1199 struct stksess *ts;
1200
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001201 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001202
1203 key = smp_to_stkey(smp, t);
1204 if (!key)
1205 return 0;
1206
1207 ts = stktable_lookup_key(t, key);
1208
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001209 smp->data.type = SMP_T_BOOL;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001210 smp->data.u.sint = !!ts;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001211 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau43e90352018-06-27 06:25:57 +02001212 stktable_release(t, ts);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001213 return 1;
1214}
1215
1216/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1217 * it up into this table. Returns the data rate received from clients in bytes/s
1218 * if the key is present in the table, otherwise zero, so that comparisons can
1219 * be easily performed. If the inspected parameter is not stored in the table,
1220 * <not found> is returned.
1221 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001222static int sample_conv_table_bytes_in_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001223{
1224 struct stktable *t;
1225 struct stktable_key *key;
1226 struct stksess *ts;
1227 void *ptr;
1228
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001229 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001230
1231 key = smp_to_stkey(smp, t);
1232 if (!key)
1233 return 0;
1234
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001235 ts = stktable_lookup_key(t, key);
1236
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001237 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001238 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001239 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001240
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001241 if (!ts) /* key not present */
1242 return 1;
1243
1244 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001245 if (ptr)
1246 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
1247 t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001248
Daniel Corbett3e60b112018-05-27 09:47:12 -04001249 stktable_release(t, ts);
1250 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001251}
1252
1253/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1254 * it up into this table. Returns the cumulated number of connections for the key
1255 * if the key is present in the table, otherwise zero, so that comparisons can
1256 * be easily performed. If the inspected parameter is not stored in the table,
1257 * <not found> is returned.
1258 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001259static int sample_conv_table_conn_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001260{
1261 struct stktable *t;
1262 struct stktable_key *key;
1263 struct stksess *ts;
1264 void *ptr;
1265
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001266 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001267
1268 key = smp_to_stkey(smp, t);
1269 if (!key)
1270 return 0;
1271
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001272 ts = stktable_lookup_key(t, key);
1273
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001274 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001275 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001276 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001277
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001278 if (!ts) /* key not present */
1279 return 1;
1280
1281 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001282 if (ptr)
1283 smp->data.u.sint = stktable_data_cast(ptr, conn_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001284
Daniel Corbett3e60b112018-05-27 09:47:12 -04001285 stktable_release(t, ts);
1286 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001287}
1288
1289/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1290 * it up into this table. Returns the number of concurrent connections for the
1291 * key if the key is present in the table, otherwise zero, so that comparisons
1292 * can be easily performed. If the inspected parameter is not stored in the
1293 * table, <not found> is returned.
1294 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001295static int sample_conv_table_conn_cur(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001296{
1297 struct stktable *t;
1298 struct stktable_key *key;
1299 struct stksess *ts;
1300 void *ptr;
1301
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001302 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001303
1304 key = smp_to_stkey(smp, t);
1305 if (!key)
1306 return 0;
1307
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001308 ts = stktable_lookup_key(t, key);
1309
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001310 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001311 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001312 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001313
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001314 if (!ts) /* key not present */
1315 return 1;
1316
1317 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001318 if (ptr)
1319 smp->data.u.sint = stktable_data_cast(ptr, conn_cur);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001320
Daniel Corbett3e60b112018-05-27 09:47:12 -04001321 stktable_release(t, ts);
1322 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001323}
1324
1325/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1326 * it up into this table. Returns the rate of incoming connections from the key
1327 * if the key is present in the table, otherwise zero, so that comparisons can
1328 * be easily performed. If the inspected parameter is not stored in the table,
1329 * <not found> is returned.
1330 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001331static int sample_conv_table_conn_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001332{
1333 struct stktable *t;
1334 struct stktable_key *key;
1335 struct stksess *ts;
1336 void *ptr;
1337
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001338 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001339
1340 key = smp_to_stkey(smp, t);
1341 if (!key)
1342 return 0;
1343
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001344 ts = stktable_lookup_key(t, key);
1345
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001346 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001347 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001348 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001349
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001350 if (!ts) /* key not present */
1351 return 1;
1352
1353 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001354 if (ptr)
1355 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
1356 t->data_arg[STKTABLE_DT_CONN_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001357
Daniel Corbett3e60b112018-05-27 09:47:12 -04001358 stktable_release(t, ts);
1359 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001360}
1361
1362/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1363 * it up into this table. Returns the data rate sent to clients in bytes/s
1364 * if the key is present in the table, otherwise zero, so that comparisons can
1365 * be easily performed. If the inspected parameter is not stored in the table,
1366 * <not found> is returned.
1367 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001368static int sample_conv_table_bytes_out_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001369{
1370 struct stktable *t;
1371 struct stktable_key *key;
1372 struct stksess *ts;
1373 void *ptr;
1374
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001375 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001376
1377 key = smp_to_stkey(smp, t);
1378 if (!key)
1379 return 0;
1380
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001381 ts = stktable_lookup_key(t, key);
1382
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001383 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001384 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001385 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001386
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001387 if (!ts) /* key not present */
1388 return 1;
1389
1390 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001391 if (ptr)
1392 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
1393 t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001394
Daniel Corbett3e60b112018-05-27 09:47:12 -04001395 stktable_release(t, ts);
1396 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001397}
1398
1399/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001400 * it up into this table. Returns the value of the GPT0 tag for the key
1401 * if the key is present in the table, otherwise false, so that comparisons can
1402 * be easily performed. If the inspected parameter is not stored in the table,
1403 * <not found> is returned.
1404 */
1405static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private)
1406{
1407 struct stktable *t;
1408 struct stktable_key *key;
1409 struct stksess *ts;
1410 void *ptr;
1411
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001412 t = arg_p[0].data.t;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001413
1414 key = smp_to_stkey(smp, t);
1415 if (!key)
1416 return 0;
1417
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001418 ts = stktable_lookup_key(t, key);
1419
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001420 smp->flags = SMP_F_VOL_TEST;
1421 smp->data.type = SMP_T_SINT;
1422 smp->data.u.sint = 0;
1423
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001424 if (!ts) /* key not present */
1425 return 1;
1426
1427 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001428 if (ptr)
1429 smp->data.u.sint = stktable_data_cast(ptr, gpt0);
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001430
Daniel Corbett3e60b112018-05-27 09:47:12 -04001431 stktable_release(t, ts);
1432 return !!ptr;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001433}
1434
1435/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001436 * it up into this table. Returns the value of the GPC0 counter for the key
1437 * if the key is present in the table, otherwise zero, so that comparisons can
1438 * be easily performed. If the inspected parameter is not stored in the table,
1439 * <not found> is returned.
1440 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001441static int sample_conv_table_gpc0(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001442{
1443 struct stktable *t;
1444 struct stktable_key *key;
1445 struct stksess *ts;
1446 void *ptr;
1447
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001448 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001449
1450 key = smp_to_stkey(smp, t);
1451 if (!key)
1452 return 0;
1453
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001454 ts = stktable_lookup_key(t, key);
1455
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001456 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001457 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001458 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001459
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001460 if (!ts) /* key not present */
1461 return 1;
1462
1463 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001464 if (ptr)
1465 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001466
Daniel Corbett3e60b112018-05-27 09:47:12 -04001467 stktable_release(t, ts);
1468 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001469}
1470
1471/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1472 * it up into this table. Returns the event rate of the GPC0 counter for the key
1473 * if the key is present in the table, otherwise zero, so that comparisons can
1474 * be easily performed. If the inspected parameter is not stored in the table,
1475 * <not found> is returned.
1476 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001477static int sample_conv_table_gpc0_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001478{
1479 struct stktable *t;
1480 struct stktable_key *key;
1481 struct stksess *ts;
1482 void *ptr;
1483
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001484 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001485
1486 key = smp_to_stkey(smp, t);
1487 if (!key)
1488 return 0;
1489
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001490 ts = stktable_lookup_key(t, key);
1491
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001492 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001493 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001494 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001495
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001496 if (!ts) /* key not present */
1497 return 1;
1498
1499 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001500 if (ptr)
1501 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate),
1502 t->data_arg[STKTABLE_DT_GPC0_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001503
Daniel Corbett3e60b112018-05-27 09:47:12 -04001504 stktable_release(t, ts);
1505 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001506}
1507
1508/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001509 * it up into this table. Returns the value of the GPC1 counter for the key
1510 * if the key is present in the table, otherwise zero, so that comparisons can
1511 * be easily performed. If the inspected parameter is not stored in the table,
1512 * <not found> is returned.
1513 */
1514static int sample_conv_table_gpc1(const struct arg *arg_p, struct sample *smp, void *private)
1515{
1516 struct stktable *t;
1517 struct stktable_key *key;
1518 struct stksess *ts;
1519 void *ptr;
1520
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001521 t = arg_p[0].data.t;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001522
1523 key = smp_to_stkey(smp, t);
1524 if (!key)
1525 return 0;
1526
1527 ts = stktable_lookup_key(t, key);
1528
1529 smp->flags = SMP_F_VOL_TEST;
1530 smp->data.type = SMP_T_SINT;
1531 smp->data.u.sint = 0;
1532
1533 if (!ts) /* key not present */
1534 return 1;
1535
1536 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001537 if (ptr)
1538 smp->data.u.sint = stktable_data_cast(ptr, gpc1);
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001539
Daniel Corbett3e60b112018-05-27 09:47:12 -04001540 stktable_release(t, ts);
1541 return !!ptr;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001542}
1543
1544/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1545 * it up into this table. Returns the event rate of the GPC1 counter for the key
1546 * if the key is present in the table, otherwise zero, so that comparisons can
1547 * be easily performed. If the inspected parameter is not stored in the table,
1548 * <not found> is returned.
1549 */
1550static int sample_conv_table_gpc1_rate(const struct arg *arg_p, struct sample *smp, void *private)
1551{
1552 struct stktable *t;
1553 struct stktable_key *key;
1554 struct stksess *ts;
1555 void *ptr;
1556
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001557 t = arg_p[0].data.t;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001558
1559 key = smp_to_stkey(smp, t);
1560 if (!key)
1561 return 0;
1562
1563 ts = stktable_lookup_key(t, key);
1564
1565 smp->flags = SMP_F_VOL_TEST;
1566 smp->data.type = SMP_T_SINT;
1567 smp->data.u.sint = 0;
1568
1569 if (!ts) /* key not present */
1570 return 1;
1571
1572 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001573 if (ptr)
1574 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc1_rate),
1575 t->data_arg[STKTABLE_DT_GPC1_RATE].u);
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001576
Daniel Corbett3e60b112018-05-27 09:47:12 -04001577 stktable_release(t, ts);
1578 return !!ptr;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001579}
1580
1581/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001582 * it up into this table. Returns the cumulated number of HTTP request errors
1583 * for the key if the key is present in the table, otherwise zero, so that
1584 * comparisons can be easily performed. If the inspected parameter is not stored
1585 * in the table, <not found> is returned.
1586 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001587static int sample_conv_table_http_err_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001588{
1589 struct stktable *t;
1590 struct stktable_key *key;
1591 struct stksess *ts;
1592 void *ptr;
1593
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001594 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001595
1596 key = smp_to_stkey(smp, t);
1597 if (!key)
1598 return 0;
1599
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001600 ts = stktable_lookup_key(t, key);
1601
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001602 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001603 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001604 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001605
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001606 if (!ts) /* key not present */
1607 return 1;
1608
1609 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001610 if (ptr)
1611 smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001612
Daniel Corbett3e60b112018-05-27 09:47:12 -04001613 stktable_release(t, ts);
1614 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001615}
1616
1617/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1618 * it up into this table. Returns the HTTP request error rate the key
1619 * if the key is present in the table, otherwise zero, so that comparisons can
1620 * be easily performed. If the inspected parameter is not stored in the table,
1621 * <not found> is returned.
1622 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001623static int sample_conv_table_http_err_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001624{
1625 struct stktable *t;
1626 struct stktable_key *key;
1627 struct stksess *ts;
1628 void *ptr;
1629
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001630 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001631
1632 key = smp_to_stkey(smp, t);
1633 if (!key)
1634 return 0;
1635
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001636 ts = stktable_lookup_key(t, key);
1637
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001638 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001639 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001640 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001641
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001642 if (!ts) /* key not present */
1643 return 1;
1644
1645 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001646 if (ptr)
1647 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
1648 t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001649
Daniel Corbett3e60b112018-05-27 09:47:12 -04001650 stktable_release(t, ts);
1651 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001652}
1653
1654/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Willy Tarreau826f3ab2021-02-10 12:07:15 +01001655 * it up into this table. Returns the cumulated number of HTTP response failures
1656 * for the key if the key is present in the table, otherwise zero, so that
1657 * comparisons can be easily performed. If the inspected parameter is not stored
1658 * in the table, <not found> is returned.
1659 */
1660static int sample_conv_table_http_fail_cnt(const struct arg *arg_p, struct sample *smp, void *private)
1661{
1662 struct stktable *t;
1663 struct stktable_key *key;
1664 struct stksess *ts;
1665 void *ptr;
1666
1667 t = arg_p[0].data.t;
1668
1669 key = smp_to_stkey(smp, t);
1670 if (!key)
1671 return 0;
1672
1673 ts = stktable_lookup_key(t, key);
1674
1675 smp->flags = SMP_F_VOL_TEST;
1676 smp->data.type = SMP_T_SINT;
1677 smp->data.u.sint = 0;
1678
1679 if (!ts) /* key not present */
1680 return 1;
1681
1682 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_CNT);
1683 if (ptr)
1684 smp->data.u.sint = stktable_data_cast(ptr, http_fail_cnt);
1685
1686 stktable_release(t, ts);
1687 return !!ptr;
1688}
1689
1690/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1691 * it up into this table. Returns the HTTP response failure rate for the key
1692 * if the key is present in the table, otherwise zero, so that comparisons can
1693 * be easily performed. If the inspected parameter is not stored in the table,
1694 * <not found> is returned.
1695 */
1696static int sample_conv_table_http_fail_rate(const struct arg *arg_p, struct sample *smp, void *private)
1697{
1698 struct stktable *t;
1699 struct stktable_key *key;
1700 struct stksess *ts;
1701 void *ptr;
1702
1703 t = arg_p[0].data.t;
1704
1705 key = smp_to_stkey(smp, t);
1706 if (!key)
1707 return 0;
1708
1709 ts = stktable_lookup_key(t, key);
1710
1711 smp->flags = SMP_F_VOL_TEST;
1712 smp->data.type = SMP_T_SINT;
1713 smp->data.u.sint = 0;
1714
1715 if (!ts) /* key not present */
1716 return 1;
1717
1718 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_RATE);
1719 if (ptr)
1720 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_fail_rate),
1721 t->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u);
1722
1723 stktable_release(t, ts);
1724 return !!ptr;
1725}
1726
1727/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001728 * it up into this table. Returns the cumulated number of HTTP request for the
1729 * key if the key is present in the table, otherwise zero, so that comparisons
1730 * can be easily performed. If the inspected parameter is not stored in the
1731 * table, <not found> is returned.
1732 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001733static int sample_conv_table_http_req_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001734{
1735 struct stktable *t;
1736 struct stktable_key *key;
1737 struct stksess *ts;
1738 void *ptr;
1739
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001740 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001741
1742 key = smp_to_stkey(smp, t);
1743 if (!key)
1744 return 0;
1745
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001746 ts = stktable_lookup_key(t, key);
1747
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001748 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001749 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001750 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001751
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001752 if (!ts) /* key not present */
1753 return 1;
1754
1755 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001756 if (ptr)
1757 smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001758
Daniel Corbett3e60b112018-05-27 09:47:12 -04001759 stktable_release(t, ts);
1760 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001761}
1762
1763/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1764 * it up into this table. Returns the HTTP request rate the key if the key is
1765 * present in the table, otherwise zero, so that comparisons can be easily
1766 * performed. If the inspected parameter is not stored in the table, <not found>
1767 * is returned.
1768 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001769static int sample_conv_table_http_req_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001770{
1771 struct stktable *t;
1772 struct stktable_key *key;
1773 struct stksess *ts;
1774 void *ptr;
1775
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001776 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001777
1778 key = smp_to_stkey(smp, t);
1779 if (!key)
1780 return 0;
1781
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001782 ts = stktable_lookup_key(t, key);
1783
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001784 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001785 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001786 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001787
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001788 if (!ts) /* key not present */
1789 return 1;
1790
1791 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001792 if (ptr)
1793 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
1794 t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001795
Daniel Corbett3e60b112018-05-27 09:47:12 -04001796 stktable_release(t, ts);
1797 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001798}
1799
1800/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1801 * it up into this table. Returns the volume of datareceived from clients in kbytes
1802 * if the key is present in the table, otherwise zero, so that comparisons can
1803 * be easily performed. If the inspected parameter is not stored in the table,
1804 * <not found> is returned.
1805 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001806static int sample_conv_table_kbytes_in(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001807{
1808 struct stktable *t;
1809 struct stktable_key *key;
1810 struct stksess *ts;
1811 void *ptr;
1812
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001813 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001814
1815 key = smp_to_stkey(smp, t);
1816 if (!key)
1817 return 0;
1818
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001819 ts = stktable_lookup_key(t, key);
1820
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001821 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001822 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001823 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001824
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001825 if (!ts) /* key not present */
1826 return 1;
1827
1828 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001829 if (ptr)
1830 smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001831
Daniel Corbett3e60b112018-05-27 09:47:12 -04001832 stktable_release(t, ts);
1833 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001834}
1835
1836/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1837 * it up into this table. Returns the volume of data sent to clients in kbytes
1838 * if the key is present in the table, otherwise zero, so that comparisons can
1839 * be easily performed. If the inspected parameter is not stored in the table,
1840 * <not found> is returned.
1841 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001842static int sample_conv_table_kbytes_out(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001843{
1844 struct stktable *t;
1845 struct stktable_key *key;
1846 struct stksess *ts;
1847 void *ptr;
1848
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001849 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001850
1851 key = smp_to_stkey(smp, t);
1852 if (!key)
1853 return 0;
1854
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001855 ts = stktable_lookup_key(t, key);
1856
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001857 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001858 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001859 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001860
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001861 if (!ts) /* key not present */
1862 return 1;
1863
1864 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001865 if (ptr)
1866 smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001867
Daniel Corbett3e60b112018-05-27 09:47:12 -04001868 stktable_release(t, ts);
1869 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001870}
1871
1872/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1873 * it up into this table. Returns the server ID associated with the key if the
1874 * key is present in the table, otherwise zero, so that comparisons can be
1875 * easily performed. If the inspected parameter is not stored in the table,
1876 * <not found> is returned.
1877 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001878static int sample_conv_table_server_id(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001879{
1880 struct stktable *t;
1881 struct stktable_key *key;
1882 struct stksess *ts;
1883 void *ptr;
1884
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001885 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001886
1887 key = smp_to_stkey(smp, t);
1888 if (!key)
1889 return 0;
1890
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001891 ts = stktable_lookup_key(t, key);
1892
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001893 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001894 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001895 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001896
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001897 if (!ts) /* key not present */
1898 return 1;
1899
1900 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001901 if (ptr)
1902 smp->data.u.sint = stktable_data_cast(ptr, server_id);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001903
Daniel Corbett3e60b112018-05-27 09:47:12 -04001904 stktable_release(t, ts);
1905 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001906}
1907
1908/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1909 * it up into this table. Returns the cumulated number of sessions for the
1910 * key if the key is present in the table, otherwise zero, so that comparisons
1911 * can be easily performed. If the inspected parameter is not stored in the
1912 * table, <not found> is returned.
1913 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001914static int sample_conv_table_sess_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001915{
1916 struct stktable *t;
1917 struct stktable_key *key;
1918 struct stksess *ts;
1919 void *ptr;
1920
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001921 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001922
1923 key = smp_to_stkey(smp, t);
1924 if (!key)
1925 return 0;
1926
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001927 ts = stktable_lookup_key(t, key);
1928
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001929 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001930 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001931 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001932
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001933 if (!ts) /* key not present */
1934 return 1;
1935
1936 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001937 if (ptr)
1938 smp->data.u.sint = stktable_data_cast(ptr, sess_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001939
Daniel Corbett3e60b112018-05-27 09:47:12 -04001940 stktable_release(t, ts);
1941 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001942}
1943
1944/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1945 * it up into this table. Returns the session rate the key if the key is
1946 * present in the table, otherwise zero, so that comparisons can be easily
1947 * performed. If the inspected parameter is not stored in the table, <not found>
1948 * is returned.
1949 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001950static int sample_conv_table_sess_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001951{
1952 struct stktable *t;
1953 struct stktable_key *key;
1954 struct stksess *ts;
1955 void *ptr;
1956
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001957 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001958
1959 key = smp_to_stkey(smp, t);
1960 if (!key)
1961 return 0;
1962
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001963 ts = stktable_lookup_key(t, key);
1964
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001965 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001966 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001967 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001968
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001969 if (!ts) /* key not present */
1970 return 1;
1971
1972 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001973 if (ptr)
1974 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
1975 t->data_arg[STKTABLE_DT_SESS_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001976
Daniel Corbett3e60b112018-05-27 09:47:12 -04001977 stktable_release(t, ts);
1978 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001979}
1980
1981/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1982 * it up into this table. Returns the amount of concurrent connections tracking
1983 * the same key if the key is present in the table, otherwise zero, so that
1984 * comparisons can be easily performed. If the inspected parameter is not
1985 * stored in the table, <not found> is returned.
1986 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001987static int sample_conv_table_trackers(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001988{
1989 struct stktable *t;
1990 struct stktable_key *key;
1991 struct stksess *ts;
1992
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001993 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001994
1995 key = smp_to_stkey(smp, t);
1996 if (!key)
1997 return 0;
1998
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001999 ts = stktable_lookup_key(t, key);
2000
Willy Tarreaud9f316a2014-07-10 14:03:38 +02002001 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002002 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002003 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02002004
Tim Duesterhus65189c12018-06-26 15:57:29 +02002005 if (!ts)
2006 return 1;
2007
2008 smp->data.u.sint = ts->ref_cnt;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02002009
Daniel Corbett3e60b112018-05-27 09:47:12 -04002010 stktable_release(t, ts);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02002011 return 1;
2012}
2013
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002014/* Always returns 1. */
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002015static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px,
Willy Tarreau658b85b2015-09-27 10:00:49 +02002016 struct session *sess, struct stream *s, int flags)
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002017{
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002018 struct stksess *ts;
2019 struct stkctr *stkctr;
2020
2021 /* Extract the stksess, return OK if no stksess available. */
2022 if (s)
2023 stkctr = &s->stkctr[rule->arg.gpc.sc];
2024 else
2025 stkctr = &sess->stkctr[rule->arg.gpc.sc];
Willy Tarreau79c1e912016-01-25 14:54:45 +01002026
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002027 ts = stkctr_entry(stkctr);
Willy Tarreau79c1e912016-01-25 14:54:45 +01002028 if (ts) {
2029 void *ptr1, *ptr2;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002030
Willy Tarreau79c1e912016-01-25 14:54:45 +01002031 /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */
2032 ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002033 ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0);
2034 if (ptr1 || ptr2) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002035 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002036
2037 if (ptr1)
2038 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate),
Willy Tarreau79c1e912016-01-25 14:54:45 +01002039 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1);
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002040
Emeric Brun819fc6f2017-06-13 19:37:32 +02002041 if (ptr2)
2042 stktable_data_cast(ptr2, gpc0)++;
Willy Tarreau79c1e912016-01-25 14:54:45 +01002043
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002044 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002045
2046 /* If data was modified, we need to touch to re-schedule sync */
2047 stktable_touch_local(stkctr->table, ts, 0);
2048 }
Willy Tarreau79c1e912016-01-25 14:54:45 +01002049 }
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002050 return ACT_RET_CONT;
2051}
2052
2053/* This function is a common parser for using variables. It understands
2054 * the formats:
2055 *
2056 * sc-inc-gpc0(<stick-table ID>)
2057 *
2058 * It returns 0 if fails and <err> is filled with an error message. Otherwise,
2059 * it returns 1 and the variable <expr> is filled with the pointer to the
2060 * expression to execute.
2061 */
2062static enum act_parse_ret parse_inc_gpc0(const char **args, int *arg, struct proxy *px,
2063 struct act_rule *rule, char **err)
2064{
2065 const char *cmd_name = args[*arg-1];
2066 char *error;
2067
2068 cmd_name += strlen("sc-inc-gpc0");
2069 if (*cmd_name == '\0') {
2070 /* default stick table id. */
2071 rule->arg.gpc.sc = 0;
2072 } else {
2073 /* parse the stick table id. */
2074 if (*cmd_name != '(') {
2075 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
2076 return ACT_RET_PRS_ERR;
2077 }
2078 cmd_name++; /* jump the '(' */
2079 rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */
2080 if (*error != ')') {
2081 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
2082 return ACT_RET_PRS_ERR;
2083 }
2084
Christopher Faulet28436e22019-12-18 10:25:46 +01002085 if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) {
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002086 memprintf(err, "invalid stick table track ID. The max allowed ID is %d",
Christopher Faulet28436e22019-12-18 10:25:46 +01002087 MAX_SESS_STKCTR-1);
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002088 return ACT_RET_PRS_ERR;
2089 }
2090 }
Thierry FOURNIER42148732015-09-02 17:17:33 +02002091 rule->action = ACT_CUSTOM;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02002092 rule->action_ptr = action_inc_gpc0;
2093 return ACT_RET_PRS_OK;
2094}
2095
2096/* Always returns 1. */
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002097static enum act_return action_inc_gpc1(struct act_rule *rule, struct proxy *px,
2098 struct session *sess, struct stream *s, int flags)
2099{
2100 struct stksess *ts;
2101 struct stkctr *stkctr;
2102
2103 /* Extract the stksess, return OK if no stksess available. */
2104 if (s)
2105 stkctr = &s->stkctr[rule->arg.gpc.sc];
2106 else
2107 stkctr = &sess->stkctr[rule->arg.gpc.sc];
2108
2109 ts = stkctr_entry(stkctr);
2110 if (ts) {
2111 void *ptr1, *ptr2;
2112
2113 /* First, update gpc1_rate if it's tracked. Second, update its gpc1 if tracked. */
2114 ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1_RATE);
2115 ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1);
2116 if (ptr1 || ptr2) {
2117 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
2118
2119 if (ptr1)
2120 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc1_rate),
2121 stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u, 1);
2122
2123 if (ptr2)
2124 stktable_data_cast(ptr2, gpc1)++;
2125
2126 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
2127
2128 /* If data was modified, we need to touch to re-schedule sync */
2129 stktable_touch_local(stkctr->table, ts, 0);
2130 }
2131 }
2132 return ACT_RET_CONT;
2133}
2134
2135/* This function is a common parser for using variables. It understands
2136 * the formats:
2137 *
2138 * sc-inc-gpc1(<stick-table ID>)
2139 *
2140 * It returns 0 if fails and <err> is filled with an error message. Otherwise,
2141 * it returns 1 and the variable <expr> is filled with the pointer to the
2142 * expression to execute.
2143 */
2144static enum act_parse_ret parse_inc_gpc1(const char **args, int *arg, struct proxy *px,
2145 struct act_rule *rule, char **err)
2146{
2147 const char *cmd_name = args[*arg-1];
2148 char *error;
2149
2150 cmd_name += strlen("sc-inc-gpc1");
2151 if (*cmd_name == '\0') {
2152 /* default stick table id. */
2153 rule->arg.gpc.sc = 0;
2154 } else {
2155 /* parse the stick table id. */
2156 if (*cmd_name != '(') {
2157 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
2158 return ACT_RET_PRS_ERR;
2159 }
2160 cmd_name++; /* jump the '(' */
2161 rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */
2162 if (*error != ')') {
2163 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
2164 return ACT_RET_PRS_ERR;
2165 }
2166
Christopher Faulet28436e22019-12-18 10:25:46 +01002167 if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) {
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002168 memprintf(err, "invalid stick table track ID. The max allowed ID is %d",
Christopher Faulet28436e22019-12-18 10:25:46 +01002169 MAX_SESS_STKCTR-1);
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002170 return ACT_RET_PRS_ERR;
2171 }
2172 }
2173 rule->action = ACT_CUSTOM;
2174 rule->action_ptr = action_inc_gpc1;
2175 return ACT_RET_PRS_OK;
2176}
2177
2178/* Always returns 1. */
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002179static enum act_return action_set_gpt0(struct act_rule *rule, struct proxy *px,
Willy Tarreau658b85b2015-09-27 10:00:49 +02002180 struct session *sess, struct stream *s, int flags)
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002181{
2182 void *ptr;
2183 struct stksess *ts;
2184 struct stkctr *stkctr;
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002185 unsigned int value = 0;
2186 struct sample *smp;
2187 int smp_opt_dir;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002188
2189 /* Extract the stksess, return OK if no stksess available. */
2190 if (s)
2191 stkctr = &s->stkctr[rule->arg.gpt.sc];
2192 else
2193 stkctr = &sess->stkctr[rule->arg.gpt.sc];
Willy Tarreau79c1e912016-01-25 14:54:45 +01002194
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002195 ts = stkctr_entry(stkctr);
2196 if (!ts)
2197 return ACT_RET_CONT;
2198
2199 /* Store the sample in the required sc, and ignore errors. */
2200 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0);
Willy Tarreau79c1e912016-01-25 14:54:45 +01002201 if (ptr) {
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002202 if (!rule->arg.gpt.expr)
2203 value = (unsigned int)(rule->arg.gpt.value);
2204 else {
2205 switch (rule->from) {
Aurelien DARRAGONa3d46bd2023-08-09 17:23:32 +02002206 case ACT_F_TCP_REQ_CON: smp_opt_dir = SMP_OPT_DIR_REQ; break;
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002207 case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break;
2208 case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break;
2209 case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break;
2210 case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break;
2211 case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break;
2212 default:
2213 send_log(px, LOG_ERR, "stick table: internal error while setting gpt0.");
2214 if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
2215 ha_alert("stick table: internal error while executing setting gpt0.\n");
2216 return ACT_RET_CONT;
2217 }
2218
2219 /* Fetch and cast the expression. */
2220 smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT);
2221 if (!smp) {
2222 send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt0.");
2223 if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
2224 ha_alert("stick table: invalid expression or data type while setting gpt0.\n");
2225 return ACT_RET_CONT;
2226 }
2227 value = (unsigned int)(smp->data.u.sint);
2228 }
2229
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002230 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002231
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002232 stktable_data_cast(ptr, gpt0) = value;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002233
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002234 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002235
2236 stktable_touch_local(stkctr->table, ts, 0);
Willy Tarreau79c1e912016-01-25 14:54:45 +01002237 }
2238
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002239 return ACT_RET_CONT;
2240}
2241
2242/* This function is a common parser for using variables. It understands
2243 * the format:
2244 *
2245 * set-gpt0(<stick-table ID>) <expression>
2246 *
2247 * It returns 0 if fails and <err> is filled with an error message. Otherwise,
2248 * it returns 1 and the variable <expr> is filled with the pointer to the
2249 * expression to execute.
2250 */
2251static enum act_parse_ret parse_set_gpt0(const char **args, int *arg, struct proxy *px,
2252 struct act_rule *rule, char **err)
2253
2254
2255{
2256 const char *cmd_name = args[*arg-1];
2257 char *error;
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002258 int smp_val;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002259
2260 cmd_name += strlen("sc-set-gpt0");
2261 if (*cmd_name == '\0') {
2262 /* default stick table id. */
2263 rule->arg.gpt.sc = 0;
2264 } else {
2265 /* parse the stick table id. */
2266 if (*cmd_name != '(') {
2267 memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]);
2268 return ACT_RET_PRS_ERR;
2269 }
2270 cmd_name++; /* jump the '(' */
2271 rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */
2272 if (*error != ')') {
2273 memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]);
2274 return ACT_RET_PRS_ERR;
2275 }
2276
Christopher Faulet28436e22019-12-18 10:25:46 +01002277 if (rule->arg.gpt.sc >= MAX_SESS_STKCTR) {
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002278 memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d",
Christopher Faulet28436e22019-12-18 10:25:46 +01002279 args[*arg-1], MAX_SESS_STKCTR-1);
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002280 return ACT_RET_PRS_ERR;
2281 }
2282 }
2283
Willy Tarreauf1e1c912021-08-24 14:57:28 +02002284 /* value may be either an integer or an expression */
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002285 rule->arg.gpt.expr = NULL;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002286 rule->arg.gpt.value = strtol(args[*arg], &error, 10);
Willy Tarreauf1e1c912021-08-24 14:57:28 +02002287 if (*error == '\0') {
2288 /* valid integer, skip it */
2289 (*arg)++;
2290 } else {
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002291 rule->arg.gpt.expr = sample_parse_expr((char **)args, arg, px->conf.args.file,
Willy Tarreaue3b57bf2020-02-14 16:50:14 +01002292 px->conf.args.line, err, &px->conf.args, NULL);
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002293 if (!rule->arg.gpt.expr)
2294 return ACT_RET_PRS_ERR;
2295
2296 switch (rule->from) {
Aurelien DARRAGONa3d46bd2023-08-09 17:23:32 +02002297 case ACT_F_TCP_REQ_CON: smp_val = SMP_VAL_FE_CON_ACC; break;
Cédric Dufour0d7712d2019-11-06 18:38:53 +01002298 case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break;
2299 case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break;
2300 case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break;
2301 case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break;
2302 case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break;
2303 default:
2304 memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from);
2305 return ACT_RET_PRS_ERR;
2306 }
2307 if (!(rule->arg.gpt.expr->fetch->val & smp_val)) {
2308 memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1],
2309 sample_src_names(rule->arg.gpt.expr->fetch->use));
2310 free(rule->arg.gpt.expr);
2311 return ACT_RET_PRS_ERR;
2312 }
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002313 }
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002314
Thierry FOURNIER42148732015-09-02 17:17:33 +02002315 rule->action = ACT_CUSTOM;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002316 rule->action_ptr = action_set_gpt0;
2317
2318 return ACT_RET_PRS_OK;
2319}
2320
Willy Tarreau7d562212016-11-25 16:10:05 +01002321/* set temp integer to the number of used entries in the table pointed to by expr.
2322 * Accepts exactly 1 argument of type table.
2323 */
2324static int
2325smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2326{
2327 smp->flags = SMP_F_VOL_TEST;
2328 smp->data.type = SMP_T_SINT;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002329 smp->data.u.sint = args->data.t->current;
Willy Tarreau7d562212016-11-25 16:10:05 +01002330 return 1;
2331}
2332
2333/* set temp integer to the number of free entries in the table pointed to by expr.
2334 * Accepts exactly 1 argument of type table.
2335 */
2336static int
2337smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private)
2338{
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002339 struct stktable *t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002340
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002341 t = args->data.t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002342 smp->flags = SMP_F_VOL_TEST;
2343 smp->data.type = SMP_T_SINT;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002344 smp->data.u.sint = t->size - t->current;
Willy Tarreau7d562212016-11-25 16:10:05 +01002345 return 1;
2346}
2347
2348/* Returns a pointer to a stkctr depending on the fetch keyword name.
2349 * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively.
2350 * sc[0-9]_* will return a pointer to the respective field in the
2351 * stream <l4>. sc_* requires an UINT argument specifying the stick
2352 * counter number. src_* will fill a locally allocated structure with
2353 * the table and entry corresponding to what is specified with src_*.
2354 * NULL may be returned if the designated stkctr is not tracked. For
2355 * the sc_* and sc[0-9]_* forms, an optional table argument may be
2356 * passed. When present, the currently tracked key is then looked up
2357 * in the specified table instead of the current table. The purpose is
Ilya Shipitsin47d17182020-06-21 21:42:57 +05002358 * to be able to convert multiple values per key (eg: have gpc0 from
Willy Tarreau7d562212016-11-25 16:10:05 +01002359 * multiple tables). <strm> is allowed to be NULL, in which case only
2360 * the session will be consulted.
2361 */
2362struct stkctr *
Emeric Brun819fc6f2017-06-13 19:37:32 +02002363smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw, struct stkctr *stkctr)
Willy Tarreau7d562212016-11-25 16:10:05 +01002364{
Willy Tarreau7d562212016-11-25 16:10:05 +01002365 struct stkctr *stkptr;
2366 struct stksess *stksess;
2367 unsigned int num = kw[2] - '0';
2368 int arg = 0;
2369
2370 if (num == '_' - '0') {
2371 /* sc_* variant, args[0] = ctr# (mandatory) */
2372 num = args[arg++].data.sint;
Willy Tarreau7d562212016-11-25 16:10:05 +01002373 }
2374 else if (num > 9) { /* src_* variant, args[0] = table */
2375 struct stktable_key *key;
2376 struct connection *conn = objt_conn(sess->origin);
2377 struct sample smp;
2378
2379 if (!conn)
2380 return NULL;
2381
Joseph Herlant5662fa42018-11-15 13:43:28 -08002382 /* Fetch source address in a sample. */
Willy Tarreau7d562212016-11-25 16:10:05 +01002383 smp.px = NULL;
2384 smp.sess = sess;
2385 smp.strm = strm;
Amaury Denoyellec460c702021-05-12 10:17:47 +02002386 if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, "src", NULL))
Willy Tarreau7d562212016-11-25 16:10:05 +01002387 return NULL;
2388
2389 /* Converts into key. */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002390 key = smp_to_stkey(&smp, args->data.t);
Willy Tarreau7d562212016-11-25 16:10:05 +01002391 if (!key)
2392 return NULL;
2393
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002394 stkctr->table = args->data.t;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002395 stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key));
2396 return stkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002397 }
2398
2399 /* Here, <num> contains the counter number from 0 to 9 for
2400 * the sc[0-9]_ form, or even higher using sc_(num) if needed.
2401 * args[arg] is the first optional argument. We first lookup the
2402 * ctr form the stream, then from the session if it was not there.
Christopher Fauleta9fa88a2019-10-21 10:53:34 +02002403 * But we must be sure the counter does not exceed MAX_SESS_STKCTR.
Willy Tarreau7d562212016-11-25 16:10:05 +01002404 */
Christopher Fauleta9fa88a2019-10-21 10:53:34 +02002405 if (num >= MAX_SESS_STKCTR)
2406 return NULL;
Willy Tarreau7d562212016-11-25 16:10:05 +01002407
2408 if (strm)
2409 stkptr = &strm->stkctr[num];
2410 if (!strm || !stkctr_entry(stkptr)) {
2411 stkptr = &sess->stkctr[num];
2412 if (!stkctr_entry(stkptr))
2413 return NULL;
2414 }
2415
2416 stksess = stkctr_entry(stkptr);
2417 if (!stksess)
2418 return NULL;
2419
2420 if (unlikely(args[arg].type == ARGT_TAB)) {
2421 /* an alternate table was specified, let's look up the same key there */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002422 stkctr->table = args[arg].data.t;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002423 stkctr_set_entry(stkctr, stktable_lookup(stkctr->table, stksess));
2424 return stkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002425 }
2426 return stkptr;
2427}
2428
2429/* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create
2430 * the entry if it doesn't exist yet. This is needed for a few fetch
2431 * functions which need to create an entry, such as src_inc_gpc* and
2432 * src_clr_gpc*.
2433 */
2434struct stkctr *
Emeric Brun819fc6f2017-06-13 19:37:32 +02002435smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw, struct stkctr *stkctr)
Willy Tarreau7d562212016-11-25 16:10:05 +01002436{
Willy Tarreau7d562212016-11-25 16:10:05 +01002437 struct stktable_key *key;
2438 struct connection *conn = objt_conn(sess->origin);
2439 struct sample smp;
2440
2441 if (strncmp(kw, "src_", 4) != 0)
2442 return NULL;
2443
2444 if (!conn)
2445 return NULL;
2446
Joseph Herlant5662fa42018-11-15 13:43:28 -08002447 /* Fetch source address in a sample. */
Willy Tarreau7d562212016-11-25 16:10:05 +01002448 smp.px = NULL;
2449 smp.sess = sess;
2450 smp.strm = strm;
Amaury Denoyellec460c702021-05-12 10:17:47 +02002451 if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, "src", NULL))
Willy Tarreau7d562212016-11-25 16:10:05 +01002452 return NULL;
2453
2454 /* Converts into key. */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002455 key = smp_to_stkey(&smp, args->data.t);
Willy Tarreau7d562212016-11-25 16:10:05 +01002456 if (!key)
2457 return NULL;
2458
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002459 stkctr->table = args->data.t;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002460 stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key));
2461 return stkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002462}
2463
2464/* set return a boolean indicating if the requested stream counter is
2465 * currently being tracked or not.
2466 * Supports being called as "sc[0-9]_tracked" only.
2467 */
2468static int
2469smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private)
2470{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002471 struct stkctr tmpstkctr;
2472 struct stkctr *stkctr;
2473
Willy Tarreau7d562212016-11-25 16:10:05 +01002474 smp->flags = SMP_F_VOL_TEST;
2475 smp->data.type = SMP_T_BOOL;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002476 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2477 smp->data.u.sint = !!stkctr;
2478
2479 /* release the ref count */
Dirkjan Bussinkff57f1b2018-09-14 14:31:22 +02002480 if (stkctr == &tmpstkctr)
Emeric Brun819fc6f2017-06-13 19:37:32 +02002481 stktable_release(stkctr->table, stkctr_entry(stkctr));
2482
Willy Tarreau7d562212016-11-25 16:10:05 +01002483 return 1;
2484}
2485
2486/* set <smp> to the General Purpose Flag 0 value from the stream's tracked
2487 * frontend counters or from the src.
2488 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value
2489 * zero is returned if the key is new.
2490 */
2491static int
2492smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2493{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002494 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002495 struct stkctr *stkctr;
2496
Emeric Brun819fc6f2017-06-13 19:37:32 +02002497 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002498 if (!stkctr)
2499 return 0;
2500
2501 smp->flags = SMP_F_VOL_TEST;
2502 smp->data.type = SMP_T_SINT;
2503 smp->data.u.sint = 0;
2504
Emeric Brun819fc6f2017-06-13 19:37:32 +02002505 if (stkctr_entry(stkctr)) {
2506 void *ptr;
2507
2508 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0);
2509 if (!ptr) {
2510 if (stkctr == &tmpstkctr)
2511 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002512 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002513 }
2514
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002515 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002516
Willy Tarreau7d562212016-11-25 16:10:05 +01002517 smp->data.u.sint = stktable_data_cast(ptr, gpt0);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002518
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002519 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002520
2521 if (stkctr == &tmpstkctr)
2522 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002523 }
2524 return 1;
2525}
2526
2527/* set <smp> to the General Purpose Counter 0 value from the stream's tracked
2528 * frontend counters or from the src.
2529 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value
2530 * zero is returned if the key is new.
2531 */
2532static int
2533smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2534{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002535 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002536 struct stkctr *stkctr;
2537
Emeric Brun819fc6f2017-06-13 19:37:32 +02002538 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002539 if (!stkctr)
2540 return 0;
2541
2542 smp->flags = SMP_F_VOL_TEST;
2543 smp->data.type = SMP_T_SINT;
2544 smp->data.u.sint = 0;
2545
2546 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002547 void *ptr;
2548
2549 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
2550 if (!ptr) {
2551 if (stkctr == &tmpstkctr)
2552 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002553 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002554 }
2555
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002556 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002557
Willy Tarreau7d562212016-11-25 16:10:05 +01002558 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002559
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002560 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002561
2562 if (stkctr == &tmpstkctr)
2563 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002564 }
2565 return 1;
2566}
2567
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002568/* set <smp> to the General Purpose Counter 1 value from the stream's tracked
2569 * frontend counters or from the src.
2570 * Supports being called as "sc[0-9]_get_gpc1" or "src_get_gpc1" only. Value
2571 * zero is returned if the key is new.
2572 */
2573static int
2574smp_fetch_sc_get_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private)
2575{
2576 struct stkctr tmpstkctr;
2577 struct stkctr *stkctr;
2578
2579 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2580 if (!stkctr)
2581 return 0;
2582
2583 smp->flags = SMP_F_VOL_TEST;
2584 smp->data.type = SMP_T_SINT;
2585 smp->data.u.sint = 0;
2586
2587 if (stkctr_entry(stkctr) != NULL) {
2588 void *ptr;
2589
2590 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1);
2591 if (!ptr) {
2592 if (stkctr == &tmpstkctr)
2593 stktable_release(stkctr->table, stkctr_entry(stkctr));
2594 return 0; /* parameter not stored */
2595 }
2596
2597 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2598
2599 smp->data.u.sint = stktable_data_cast(ptr, gpc1);
2600
2601 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2602
2603 if (stkctr == &tmpstkctr)
2604 stktable_release(stkctr->table, stkctr_entry(stkctr));
2605 }
2606 return 1;
2607}
2608
Willy Tarreau7d562212016-11-25 16:10:05 +01002609/* set <smp> to the General Purpose Counter 0's event rate from the stream's
2610 * tracked frontend counters or from the src.
2611 * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only.
2612 * Value zero is returned if the key is new.
2613 */
2614static int
2615smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2616{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002617 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002618 struct stkctr *stkctr;
2619
Emeric Brun819fc6f2017-06-13 19:37:32 +02002620 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002621 if (!stkctr)
2622 return 0;
2623
2624 smp->flags = SMP_F_VOL_TEST;
2625 smp->data.type = SMP_T_SINT;
2626 smp->data.u.sint = 0;
2627 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002628 void *ptr;
2629
2630 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
2631 if (!ptr) {
2632 if (stkctr == &tmpstkctr)
2633 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002634 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002635 }
2636
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002637 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002638
Willy Tarreau7d562212016-11-25 16:10:05 +01002639 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate),
2640 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002641
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002642 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002643
2644 if (stkctr == &tmpstkctr)
2645 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002646 }
2647 return 1;
2648}
2649
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002650/* set <smp> to the General Purpose Counter 1's event rate from the stream's
2651 * tracked frontend counters or from the src.
2652 * Supports being called as "sc[0-9]_gpc1_rate" or "src_gpc1_rate" only.
2653 * Value zero is returned if the key is new.
2654 */
2655static int
2656smp_fetch_sc_gpc1_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2657{
2658 struct stkctr tmpstkctr;
2659 struct stkctr *stkctr;
2660
2661 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2662 if (!stkctr)
2663 return 0;
2664
2665 smp->flags = SMP_F_VOL_TEST;
2666 smp->data.type = SMP_T_SINT;
2667 smp->data.u.sint = 0;
2668 if (stkctr_entry(stkctr) != NULL) {
2669 void *ptr;
2670
2671 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE);
2672 if (!ptr) {
2673 if (stkctr == &tmpstkctr)
2674 stktable_release(stkctr->table, stkctr_entry(stkctr));
2675 return 0; /* parameter not stored */
2676 }
2677
2678 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2679
2680 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc1_rate),
2681 stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u);
2682
2683 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2684
2685 if (stkctr == &tmpstkctr)
2686 stktable_release(stkctr->table, stkctr_entry(stkctr));
2687 }
2688 return 1;
2689}
2690
Willy Tarreau7d562212016-11-25 16:10:05 +01002691/* Increment the General Purpose Counter 0 value from the stream's tracked
2692 * frontend counters and return it into temp integer.
2693 * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only.
2694 */
2695static int
2696smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2697{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002698 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002699 struct stkctr *stkctr;
2700
Emeric Brun819fc6f2017-06-13 19:37:32 +02002701 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002702 if (!stkctr)
2703 return 0;
2704
2705 smp->flags = SMP_F_VOL_TEST;
2706 smp->data.type = SMP_T_SINT;
2707 smp->data.u.sint = 0;
2708
Emeric Brun819fc6f2017-06-13 19:37:32 +02002709 if (!stkctr_entry(stkctr))
2710 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002711
2712 if (stkctr && stkctr_entry(stkctr)) {
2713 void *ptr1,*ptr2;
2714
Emeric Brun819fc6f2017-06-13 19:37:32 +02002715
Willy Tarreau7d562212016-11-25 16:10:05 +01002716 /* First, update gpc0_rate if it's tracked. Second, update its
2717 * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr.
2718 */
2719 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
Willy Tarreau7d562212016-11-25 16:10:05 +01002720 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002721 if (ptr1 || ptr2) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002722 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Willy Tarreau7d562212016-11-25 16:10:05 +01002723
Emeric Brun819fc6f2017-06-13 19:37:32 +02002724 if (ptr1) {
2725 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate),
2726 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1);
2727 smp->data.u.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr;
2728 }
2729
2730 if (ptr2)
2731 smp->data.u.sint = ++stktable_data_cast(ptr2, gpc0);
2732
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002733 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002734
2735 /* If data was modified, we need to touch to re-schedule sync */
2736 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
2737 }
2738 else if (stkctr == &tmpstkctr)
2739 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002740 }
2741 return 1;
2742}
2743
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002744/* Increment the General Purpose Counter 1 value from the stream's tracked
2745 * frontend counters and return it into temp integer.
2746 * Supports being called as "sc[0-9]_inc_gpc1" or "src_inc_gpc1" only.
2747 */
2748static int
2749smp_fetch_sc_inc_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private)
2750{
2751 struct stkctr tmpstkctr;
2752 struct stkctr *stkctr;
2753
2754 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2755 if (!stkctr)
2756 return 0;
2757
2758 smp->flags = SMP_F_VOL_TEST;
2759 smp->data.type = SMP_T_SINT;
2760 smp->data.u.sint = 0;
2761
2762 if (!stkctr_entry(stkctr))
2763 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2764
2765 if (stkctr && stkctr_entry(stkctr)) {
2766 void *ptr1,*ptr2;
2767
2768
2769 /* First, update gpc1_rate if it's tracked. Second, update its
2770 * gpc1 if tracked. Returns gpc1's value otherwise the curr_ctr.
2771 */
2772 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE);
2773 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1);
2774 if (ptr1 || ptr2) {
2775 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2776
2777 if (ptr1) {
2778 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc1_rate),
2779 stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u, 1);
2780 smp->data.u.sint = (&stktable_data_cast(ptr1, gpc1_rate))->curr_ctr;
2781 }
2782
2783 if (ptr2)
2784 smp->data.u.sint = ++stktable_data_cast(ptr2, gpc1);
2785
2786 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2787
2788 /* If data was modified, we need to touch to re-schedule sync */
2789 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
2790 }
2791 else if (stkctr == &tmpstkctr)
2792 stktable_release(stkctr->table, stkctr_entry(stkctr));
2793 }
2794 return 1;
2795}
2796
Willy Tarreau7d562212016-11-25 16:10:05 +01002797/* Clear the General Purpose Counter 0 value from the stream's tracked
2798 * frontend counters and return its previous value into temp integer.
2799 * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only.
2800 */
2801static int
2802smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2803{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002804 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002805 struct stkctr *stkctr;
2806
Emeric Brun819fc6f2017-06-13 19:37:32 +02002807 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002808 if (!stkctr)
2809 return 0;
2810
2811 smp->flags = SMP_F_VOL_TEST;
2812 smp->data.type = SMP_T_SINT;
2813 smp->data.u.sint = 0;
2814
Emeric Brun819fc6f2017-06-13 19:37:32 +02002815 if (!stkctr_entry(stkctr))
2816 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002817
Emeric Brun819fc6f2017-06-13 19:37:32 +02002818 if (stkctr && stkctr_entry(stkctr)) {
2819 void *ptr;
2820
2821 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
2822 if (!ptr) {
2823 if (stkctr == &tmpstkctr)
2824 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002825 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002826 }
2827
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002828 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002829
Willy Tarreau7d562212016-11-25 16:10:05 +01002830 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
2831 stktable_data_cast(ptr, gpc0) = 0;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002832
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002833 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002834
Willy Tarreau7d562212016-11-25 16:10:05 +01002835 /* If data was modified, we need to touch to re-schedule sync */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002836 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
Willy Tarreau7d562212016-11-25 16:10:05 +01002837 }
2838 return 1;
2839}
2840
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002841/* Clear the General Purpose Counter 1 value from the stream's tracked
2842 * frontend counters and return its previous value into temp integer.
2843 * Supports being called as "sc[0-9]_clr_gpc1" or "src_clr_gpc1" only.
2844 */
2845static int
2846smp_fetch_sc_clr_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private)
2847{
2848 struct stkctr tmpstkctr;
2849 struct stkctr *stkctr;
2850
2851 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2852 if (!stkctr)
2853 return 0;
2854
2855 smp->flags = SMP_F_VOL_TEST;
2856 smp->data.type = SMP_T_SINT;
2857 smp->data.u.sint = 0;
2858
2859 if (!stkctr_entry(stkctr))
2860 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2861
2862 if (stkctr && stkctr_entry(stkctr)) {
2863 void *ptr;
2864
2865 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1);
2866 if (!ptr) {
2867 if (stkctr == &tmpstkctr)
2868 stktable_release(stkctr->table, stkctr_entry(stkctr));
2869 return 0; /* parameter not stored */
2870 }
2871
2872 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2873
2874 smp->data.u.sint = stktable_data_cast(ptr, gpc1);
2875 stktable_data_cast(ptr, gpc1) = 0;
2876
2877 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2878
2879 /* If data was modified, we need to touch to re-schedule sync */
2880 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
2881 }
2882 return 1;
2883}
2884
Willy Tarreau7d562212016-11-25 16:10:05 +01002885/* set <smp> to the cumulated number of connections from the stream's tracked
2886 * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or
2887 * "src_conn_cnt" only.
2888 */
2889static int
2890smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2891{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002892 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002893 struct stkctr *stkctr;
2894
Emeric Brun819fc6f2017-06-13 19:37:32 +02002895 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002896 if (!stkctr)
2897 return 0;
2898
2899 smp->flags = SMP_F_VOL_TEST;
2900 smp->data.type = SMP_T_SINT;
2901 smp->data.u.sint = 0;
2902 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002903 void *ptr;
2904
2905 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT);
2906 if (!ptr) {
2907 if (stkctr == &tmpstkctr)
2908 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002909 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002910 }
2911
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002912 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002913
Willy Tarreau7d562212016-11-25 16:10:05 +01002914 smp->data.u.sint = stktable_data_cast(ptr, conn_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002915
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002916 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002917
2918 if (stkctr == &tmpstkctr)
2919 stktable_release(stkctr->table, stkctr_entry(stkctr));
2920
2921
Willy Tarreau7d562212016-11-25 16:10:05 +01002922 }
2923 return 1;
2924}
2925
2926/* set <smp> to the connection rate from the stream's tracked frontend
2927 * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate"
2928 * only.
2929 */
2930static int
2931smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2932{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002933 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002934 struct stkctr *stkctr;
2935
Emeric Brun819fc6f2017-06-13 19:37:32 +02002936 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002937 if (!stkctr)
2938 return 0;
2939
2940 smp->flags = SMP_F_VOL_TEST;
2941 smp->data.type = SMP_T_SINT;
2942 smp->data.u.sint = 0;
2943 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002944 void *ptr;
2945
2946 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE);
2947 if (!ptr) {
2948 if (stkctr == &tmpstkctr)
2949 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002950 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002951 }
2952
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002953 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002954
Willy Tarreau7d562212016-11-25 16:10:05 +01002955 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
2956 stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002957
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002958 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002959
2960 if (stkctr == &tmpstkctr)
2961 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002962 }
2963 return 1;
2964}
2965
2966/* set temp integer to the number of connections from the stream's source address
2967 * in the table pointed to by expr, after updating it.
2968 * Accepts exactly 1 argument of type table.
2969 */
2970static int
2971smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2972{
2973 struct connection *conn = objt_conn(smp->sess->origin);
2974 struct stksess *ts;
2975 struct stktable_key *key;
2976 void *ptr;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002977 struct stktable *t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002978
2979 if (!conn)
2980 return 0;
2981
Joseph Herlant5662fa42018-11-15 13:43:28 -08002982 /* Fetch source address in a sample. */
Amaury Denoyellec460c702021-05-12 10:17:47 +02002983 if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, smp, "src", NULL))
Willy Tarreau7d562212016-11-25 16:10:05 +01002984 return 0;
2985
2986 /* Converts into key. */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002987 key = smp_to_stkey(smp, args->data.t);
Willy Tarreau7d562212016-11-25 16:10:05 +01002988 if (!key)
2989 return 0;
2990
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002991 t = args->data.t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002992
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002993 if ((ts = stktable_get_entry(t, key)) == NULL)
Willy Tarreau7d562212016-11-25 16:10:05 +01002994 /* entry does not exist and could not be created */
2995 return 0;
2996
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002997 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002998 if (!ptr) {
Willy Tarreau7d562212016-11-25 16:10:05 +01002999 return 0; /* parameter not stored in this table */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003000 }
Willy Tarreau7d562212016-11-25 16:10:05 +01003001
3002 smp->data.type = SMP_T_SINT;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003003
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003004 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003005
Willy Tarreau7d562212016-11-25 16:10:05 +01003006 smp->data.u.sint = ++stktable_data_cast(ptr, conn_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003007
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003008 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003009
Willy Tarreau7d562212016-11-25 16:10:05 +01003010 smp->flags = SMP_F_VOL_TEST;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003011
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003012 stktable_touch_local(t, ts, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003013
3014 /* Touch was previously performed by stktable_update_key */
Willy Tarreau7d562212016-11-25 16:10:05 +01003015 return 1;
3016}
3017
3018/* set <smp> to the number of concurrent connections from the stream's tracked
3019 * frontend counters. Supports being called as "sc[0-9]_conn_cur" or
3020 * "src_conn_cur" only.
3021 */
3022static int
3023smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private)
3024{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003025 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003026 struct stkctr *stkctr;
3027
Emeric Brun819fc6f2017-06-13 19:37:32 +02003028 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003029 if (!stkctr)
3030 return 0;
3031
3032 smp->flags = SMP_F_VOL_TEST;
3033 smp->data.type = SMP_T_SINT;
3034 smp->data.u.sint = 0;
3035 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003036 void *ptr;
3037
3038 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR);
3039 if (!ptr) {
3040 if (stkctr == &tmpstkctr)
3041 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003042 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003043 }
3044
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003045 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003046
Willy Tarreau7d562212016-11-25 16:10:05 +01003047 smp->data.u.sint = stktable_data_cast(ptr, conn_cur);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003048
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003049 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003050
3051 if (stkctr == &tmpstkctr)
3052 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003053 }
3054 return 1;
3055}
3056
3057/* set <smp> to the cumulated number of streams from the stream's tracked
3058 * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or
3059 * "src_sess_cnt" only.
3060 */
3061static int
3062smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
3063{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003064 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003065 struct stkctr *stkctr;
3066
Emeric Brun819fc6f2017-06-13 19:37:32 +02003067 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003068 if (!stkctr)
3069 return 0;
3070
3071 smp->flags = SMP_F_VOL_TEST;
3072 smp->data.type = SMP_T_SINT;
3073 smp->data.u.sint = 0;
3074 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003075 void *ptr;
3076
3077 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT);
3078 if (!ptr) {
3079 if (stkctr == &tmpstkctr)
3080 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003081 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003082 }
3083
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003084 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003085
Willy Tarreau7d562212016-11-25 16:10:05 +01003086 smp->data.u.sint = stktable_data_cast(ptr, sess_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003087
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003088 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003089
3090 if (stkctr == &tmpstkctr)
3091 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003092 }
3093 return 1;
3094}
3095
3096/* set <smp> to the stream rate from the stream's tracked frontend counters.
3097 * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only.
3098 */
3099static int
3100smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3101{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003102 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003103 struct stkctr *stkctr;
3104
Emeric Brun819fc6f2017-06-13 19:37:32 +02003105 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003106 if (!stkctr)
3107 return 0;
3108
3109 smp->flags = SMP_F_VOL_TEST;
3110 smp->data.type = SMP_T_SINT;
3111 smp->data.u.sint = 0;
3112 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003113 void *ptr;
3114
3115 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE);
3116 if (!ptr) {
3117 if (stkctr == &tmpstkctr)
3118 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003119 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003120 }
3121
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003122 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003123
Willy Tarreau7d562212016-11-25 16:10:05 +01003124 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
3125 stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003126
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003127 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003128
3129 if (stkctr == &tmpstkctr)
3130 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003131 }
3132 return 1;
3133}
3134
3135/* set <smp> to the cumulated number of HTTP requests from the stream's tracked
3136 * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or
3137 * "src_http_req_cnt" only.
3138 */
3139static int
3140smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
3141{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003142 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003143 struct stkctr *stkctr;
3144
Emeric Brun819fc6f2017-06-13 19:37:32 +02003145 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003146 if (!stkctr)
3147 return 0;
3148
3149 smp->flags = SMP_F_VOL_TEST;
3150 smp->data.type = SMP_T_SINT;
3151 smp->data.u.sint = 0;
3152 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003153 void *ptr;
3154
3155 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT);
3156 if (!ptr) {
3157 if (stkctr == &tmpstkctr)
3158 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003159 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003160 }
3161
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003162 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003163
Willy Tarreau7d562212016-11-25 16:10:05 +01003164 smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003165
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003166 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003167
3168 if (stkctr == &tmpstkctr)
3169 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003170 }
3171 return 1;
3172}
3173
3174/* set <smp> to the HTTP request rate from the stream's tracked frontend
3175 * counters. Supports being called as "sc[0-9]_http_req_rate" or
3176 * "src_http_req_rate" only.
3177 */
3178static int
3179smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3180{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003181 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003182 struct stkctr *stkctr;
3183
Emeric Brun819fc6f2017-06-13 19:37:32 +02003184 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003185 if (!stkctr)
3186 return 0;
3187
3188 smp->flags = SMP_F_VOL_TEST;
3189 smp->data.type = SMP_T_SINT;
3190 smp->data.u.sint = 0;
3191 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003192 void *ptr;
3193
3194 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE);
3195 if (!ptr) {
3196 if (stkctr == &tmpstkctr)
3197 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003198 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003199 }
3200
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003201 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003202
Willy Tarreau7d562212016-11-25 16:10:05 +01003203 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
3204 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003205
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003206 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003207
3208 if (stkctr == &tmpstkctr)
3209 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003210 }
3211 return 1;
3212}
3213
3214/* set <smp> to the cumulated number of HTTP requests errors from the stream's
3215 * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or
3216 * "src_http_err_cnt" only.
3217 */
3218static int
3219smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
3220{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003221 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003222 struct stkctr *stkctr;
3223
Emeric Brun819fc6f2017-06-13 19:37:32 +02003224 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003225 if (!stkctr)
3226 return 0;
3227
3228 smp->flags = SMP_F_VOL_TEST;
3229 smp->data.type = SMP_T_SINT;
3230 smp->data.u.sint = 0;
3231 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003232 void *ptr;
3233
3234 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT);
3235 if (!ptr) {
3236 if (stkctr == &tmpstkctr)
3237 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003238 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003239 }
3240
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003241 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003242
Willy Tarreau7d562212016-11-25 16:10:05 +01003243 smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003244
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003245 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003246
3247 if (stkctr == &tmpstkctr)
3248 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003249 }
3250 return 1;
3251}
3252
3253/* set <smp> to the HTTP request error rate from the stream's tracked frontend
3254 * counters. Supports being called as "sc[0-9]_http_err_rate" or
3255 * "src_http_err_rate" only.
3256 */
3257static int
3258smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3259{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003260 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003261 struct stkctr *stkctr;
3262
Emeric Brun819fc6f2017-06-13 19:37:32 +02003263 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003264 if (!stkctr)
3265 return 0;
3266
3267 smp->flags = SMP_F_VOL_TEST;
3268 smp->data.type = SMP_T_SINT;
3269 smp->data.u.sint = 0;
3270 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003271 void *ptr;
3272
3273 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE);
3274 if (!ptr) {
3275 if (stkctr == &tmpstkctr)
3276 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003277 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003278 }
3279
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003280 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003281
Willy Tarreau7d562212016-11-25 16:10:05 +01003282 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
3283 stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003284
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003285 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003286
3287 if (stkctr == &tmpstkctr)
3288 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003289 }
3290 return 1;
3291}
3292
Willy Tarreau826f3ab2021-02-10 12:07:15 +01003293/* set <smp> to the cumulated number of HTTP response failures from the stream's
3294 * tracked frontend counters. Supports being called as "sc[0-9]_http_fail_cnt" or
3295 * "src_http_fail_cnt" only.
3296 */
3297static int
3298smp_fetch_sc_http_fail_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
3299{
3300 struct stkctr tmpstkctr;
3301 struct stkctr *stkctr;
3302
3303 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
3304 if (!stkctr)
3305 return 0;
3306
3307 smp->flags = SMP_F_VOL_TEST;
3308 smp->data.type = SMP_T_SINT;
3309 smp->data.u.sint = 0;
3310 if (stkctr_entry(stkctr) != NULL) {
3311 void *ptr;
3312
3313 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_CNT);
3314 if (!ptr) {
3315 if (stkctr == &tmpstkctr)
3316 stktable_release(stkctr->table, stkctr_entry(stkctr));
3317 return 0; /* parameter not stored */
3318 }
3319
3320 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
3321
3322 smp->data.u.sint = stktable_data_cast(ptr, http_fail_cnt);
3323
3324 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
3325
3326 if (stkctr == &tmpstkctr)
3327 stktable_release(stkctr->table, stkctr_entry(stkctr));
3328 }
3329 return 1;
3330}
3331
3332/* set <smp> to the HTTP response failure rate from the stream's tracked frontend
3333 * counters. Supports being called as "sc[0-9]_http_fail_rate" or
3334 * "src_http_fail_rate" only.
3335 */
3336static int
3337smp_fetch_sc_http_fail_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3338{
3339 struct stkctr tmpstkctr;
3340 struct stkctr *stkctr;
3341
3342 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
3343 if (!stkctr)
3344 return 0;
3345
3346 smp->flags = SMP_F_VOL_TEST;
3347 smp->data.type = SMP_T_SINT;
3348 smp->data.u.sint = 0;
3349 if (stkctr_entry(stkctr) != NULL) {
3350 void *ptr;
3351
3352 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_RATE);
3353 if (!ptr) {
3354 if (stkctr == &tmpstkctr)
3355 stktable_release(stkctr->table, stkctr_entry(stkctr));
3356 return 0; /* parameter not stored */
3357 }
3358
3359 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
3360
3361 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_fail_rate),
3362 stkctr->table->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u);
3363
3364 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
3365
3366 if (stkctr == &tmpstkctr)
3367 stktable_release(stkctr->table, stkctr_entry(stkctr));
3368 }
3369 return 1;
3370}
3371
Willy Tarreau7d562212016-11-25 16:10:05 +01003372/* set <smp> to the number of kbytes received from clients, as found in the
3373 * stream's tracked frontend counters. Supports being called as
3374 * "sc[0-9]_kbytes_in" or "src_kbytes_in" only.
3375 */
3376static int
3377smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private)
3378{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003379 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003380 struct stkctr *stkctr;
3381
Emeric Brun819fc6f2017-06-13 19:37:32 +02003382 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003383 if (!stkctr)
3384 return 0;
3385
3386 smp->flags = SMP_F_VOL_TEST;
3387 smp->data.type = SMP_T_SINT;
3388 smp->data.u.sint = 0;
3389 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003390 void *ptr;
3391
3392 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT);
3393 if (!ptr) {
3394 if (stkctr == &tmpstkctr)
3395 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003396 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003397 }
3398
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003399 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003400
Willy Tarreau7d562212016-11-25 16:10:05 +01003401 smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003402
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003403 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003404
3405 if (stkctr == &tmpstkctr)
3406 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003407 }
3408 return 1;
3409}
3410
3411/* set <smp> to the data rate received from clients in bytes/s, as found
3412 * in the stream's tracked frontend counters. Supports being called as
3413 * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only.
3414 */
3415static int
3416smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3417{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003418 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003419 struct stkctr *stkctr;
3420
Emeric Brun819fc6f2017-06-13 19:37:32 +02003421 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003422 if (!stkctr)
3423 return 0;
3424
3425 smp->flags = SMP_F_VOL_TEST;
3426 smp->data.type = SMP_T_SINT;
3427 smp->data.u.sint = 0;
3428 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003429 void *ptr;
3430
3431 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE);
3432 if (!ptr) {
3433 if (stkctr == &tmpstkctr)
3434 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003435 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003436 }
3437
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003438 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003439
Willy Tarreau7d562212016-11-25 16:10:05 +01003440 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
3441 stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003442
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003443 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003444
3445 if (stkctr == &tmpstkctr)
3446 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003447 }
3448 return 1;
3449}
3450
3451/* set <smp> to the number of kbytes sent to clients, as found in the
3452 * stream's tracked frontend counters. Supports being called as
3453 * "sc[0-9]_kbytes_out" or "src_kbytes_out" only.
3454 */
3455static int
3456smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private)
3457{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003458 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003459 struct stkctr *stkctr;
3460
Emeric Brun819fc6f2017-06-13 19:37:32 +02003461 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003462 if (!stkctr)
3463 return 0;
3464
3465 smp->flags = SMP_F_VOL_TEST;
3466 smp->data.type = SMP_T_SINT;
3467 smp->data.u.sint = 0;
3468 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003469 void *ptr;
3470
3471 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT);
3472 if (!ptr) {
3473 if (stkctr == &tmpstkctr)
3474 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003475 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003476 }
3477
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003478 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003479
Willy Tarreau7d562212016-11-25 16:10:05 +01003480 smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003481
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003482 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003483
3484 if (stkctr == &tmpstkctr)
3485 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003486 }
3487 return 1;
3488}
3489
3490/* set <smp> to the data rate sent to clients in bytes/s, as found in the
3491 * stream's tracked frontend counters. Supports being called as
3492 * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only.
3493 */
3494static int
3495smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3496{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003497 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003498 struct stkctr *stkctr;
3499
Emeric Brun819fc6f2017-06-13 19:37:32 +02003500 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003501 if (!stkctr)
3502 return 0;
3503
3504 smp->flags = SMP_F_VOL_TEST;
3505 smp->data.type = SMP_T_SINT;
3506 smp->data.u.sint = 0;
3507 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003508 void *ptr;
3509
3510 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE);
3511 if (!ptr) {
3512 if (stkctr == &tmpstkctr)
3513 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003514 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003515 }
3516
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003517 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003518
Willy Tarreau7d562212016-11-25 16:10:05 +01003519 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
3520 stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003521
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003522 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003523
3524 if (stkctr == &tmpstkctr)
3525 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003526 }
3527 return 1;
3528}
3529
3530/* set <smp> to the number of active trackers on the SC entry in the stream's
3531 * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only.
3532 */
3533static int
3534smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private)
3535{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003536 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003537 struct stkctr *stkctr;
3538
Emeric Brun819fc6f2017-06-13 19:37:32 +02003539 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003540 if (!stkctr)
3541 return 0;
3542
3543 smp->flags = SMP_F_VOL_TEST;
3544 smp->data.type = SMP_T_SINT;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003545 if (stkctr == &tmpstkctr) {
3546 smp->data.u.sint = stkctr_entry(stkctr) ? (stkctr_entry(stkctr)->ref_cnt-1) : 0;
3547 stktable_release(stkctr->table, stkctr_entry(stkctr));
3548 }
3549 else {
3550 smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0;
3551 }
3552
Willy Tarreau7d562212016-11-25 16:10:05 +01003553 return 1;
3554}
3555
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003556
3557/* The functions below are used to manipulate table contents from the CLI.
3558 * There are 3 main actions, "clear", "set" and "show". The code is shared
3559 * between all actions, and the action is encoded in the void *private in
3560 * the appctx as well as in the keyword registration, among one of the
3561 * following values.
3562 */
3563
3564enum {
3565 STK_CLI_ACT_CLR,
3566 STK_CLI_ACT_SET,
3567 STK_CLI_ACT_SHOW,
3568};
3569
3570/* Dump the status of a table to a stream interface's
3571 * read buffer. It returns 0 if the output buffer is full
3572 * and needs to be called again, otherwise non-zero.
3573 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003574static int table_dump_head_to_buffer(struct buffer *msg,
3575 struct stream_interface *si,
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003576 struct stktable *t, struct stktable *target)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003577{
3578 struct stream *s = si_strm(si);
3579
3580 chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003581 t->id, stktable_types[t->type].kw, t->size, t->current);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003582
3583 /* any other information should be dumped here */
3584
William Lallemand07a62f72017-05-24 00:57:40 +02003585 if (target && (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) < ACCESS_LVL_OPER)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003586 chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n");
3587
Willy Tarreau06d80a92017-10-19 14:32:15 +02003588 if (ci_putchk(si_ic(si), msg) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003589 si_rx_room_blk(si);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003590 return 0;
3591 }
3592
3593 return 1;
3594}
3595
3596/* Dump a table entry to a stream interface's
3597 * read buffer. It returns 0 if the output buffer is full
3598 * and needs to be called again, otherwise non-zero.
3599 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003600static int table_dump_entry_to_buffer(struct buffer *msg,
3601 struct stream_interface *si,
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003602 struct stktable *t, struct stksess *entry)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003603{
3604 int dt;
3605
3606 chunk_appendf(msg, "%p:", entry);
3607
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003608 if (t->type == SMP_T_IPV4) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003609 char addr[INET_ADDRSTRLEN];
3610 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
3611 chunk_appendf(msg, " key=%s", addr);
3612 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003613 else if (t->type == SMP_T_IPV6) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003614 char addr[INET6_ADDRSTRLEN];
3615 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
3616 chunk_appendf(msg, " key=%s", addr);
3617 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003618 else if (t->type == SMP_T_SINT) {
Willy Tarreau6cde5d82020-02-25 09:41:22 +01003619 chunk_appendf(msg, " key=%u", read_u32(entry->key.key));
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003620 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003621 else if (t->type == SMP_T_STR) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003622 chunk_appendf(msg, " key=");
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003623 dump_text(msg, (const char *)entry->key.key, t->key_size);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003624 }
3625 else {
3626 chunk_appendf(msg, " key=");
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003627 dump_binary(msg, (const char *)entry->key.key, t->key_size);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003628 }
3629
3630 chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
3631
3632 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
3633 void *ptr;
3634
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003635 if (t->data_ofs[dt] == 0)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003636 continue;
3637 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
Emeric Brunc24b4142021-06-30 16:24:04 +02003638 chunk_appendf(msg, " %s(%u)=", stktable_data_types[dt].name, t->data_arg[dt].u);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003639 else
3640 chunk_appendf(msg, " %s=", stktable_data_types[dt].name);
3641
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003642 ptr = stktable_data_ptr(t, entry, dt);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003643 switch (stktable_data_types[dt].std_type) {
3644 case STD_T_SINT:
3645 chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
3646 break;
3647 case STD_T_UINT:
3648 chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
3649 break;
3650 case STD_T_ULL:
Emeric Brunc24b4142021-06-30 16:24:04 +02003651 chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull));
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003652 break;
3653 case STD_T_FRQP:
Emeric Brunc24b4142021-06-30 16:24:04 +02003654 chunk_appendf(msg, "%u",
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003655 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003656 t->data_arg[dt].u));
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003657 break;
Frédéric Lécaille16b4f542019-05-23 12:15:04 +02003658 case STD_T_DICT: {
3659 struct dict_entry *de;
3660 de = stktable_data_cast(ptr, std_t_dict);
3661 chunk_appendf(msg, "%s", de ? (char *)de->value.key : "-");
3662 break;
3663 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003664 }
3665 }
3666 chunk_appendf(msg, "\n");
3667
Willy Tarreau06d80a92017-10-19 14:32:15 +02003668 if (ci_putchk(si_ic(si), msg) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003669 si_rx_room_blk(si);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003670 return 0;
3671 }
3672
3673 return 1;
3674}
3675
3676
3677/* Processes a single table entry matching a specific key passed in argument.
3678 * returns 0 if wants to be called again, 1 if has ended processing.
3679 */
3680static int table_process_entry_per_key(struct appctx *appctx, char **args)
3681{
3682 struct stream_interface *si = appctx->owner;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003683 struct stktable *t = appctx->ctx.table.target;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003684 struct stksess *ts;
3685 uint32_t uint32_key;
3686 unsigned char ip6_key[sizeof(struct in6_addr)];
3687 long long value;
3688 int data_type;
3689 int cur_arg;
3690 void *ptr;
Willy Tarreaufa1258f2021-04-10 23:00:53 +02003691 struct freq_ctr *frqp;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003692
Willy Tarreau9d008692019-08-09 11:21:01 +02003693 if (!*args[4])
3694 return cli_err(appctx, "Key value expected\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003695
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003696 switch (t->type) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003697 case SMP_T_IPV4:
3698 uint32_key = htonl(inetaddr_host(args[4]));
Christopher Fauletca20d022017-08-29 15:30:31 +02003699 static_table_key.key = &uint32_key;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003700 break;
3701 case SMP_T_IPV6:
Christopher Faulet1e850b52021-11-15 09:17:25 +01003702 if (inet_pton(AF_INET6, args[4], ip6_key) <= 0)
3703 return cli_err(appctx, "Invalid key\n");
Christopher Fauletca20d022017-08-29 15:30:31 +02003704 static_table_key.key = &ip6_key;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003705 break;
3706 case SMP_T_SINT:
3707 {
3708 char *endptr;
3709 unsigned long val;
3710 errno = 0;
3711 val = strtoul(args[4], &endptr, 10);
3712 if ((errno == ERANGE && val == ULONG_MAX) ||
3713 (errno != 0 && val == 0) || endptr == args[4] ||
Willy Tarreau9d008692019-08-09 11:21:01 +02003714 val > 0xffffffff)
3715 return cli_err(appctx, "Invalid key\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003716 uint32_key = (uint32_t) val;
Christopher Fauletca20d022017-08-29 15:30:31 +02003717 static_table_key.key = &uint32_key;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003718 break;
3719 }
3720 break;
3721 case SMP_T_STR:
Christopher Fauletca20d022017-08-29 15:30:31 +02003722 static_table_key.key = args[4];
3723 static_table_key.key_len = strlen(args[4]);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003724 break;
3725 default:
Willy Tarreaua24bc782016-12-14 15:50:35 +01003726 switch (appctx->ctx.table.action) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003727 case STK_CLI_ACT_SHOW:
Willy Tarreau9d008692019-08-09 11:21:01 +02003728 return cli_err(appctx, "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003729 case STK_CLI_ACT_CLR:
Willy Tarreau9d008692019-08-09 11:21:01 +02003730 return cli_err(appctx, "Removing keys from tables of type other than ip, ipv6, string and integer is not supported\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003731 case STK_CLI_ACT_SET:
Willy Tarreau9d008692019-08-09 11:21:01 +02003732 return cli_err(appctx, "Inserting keys into tables of type other than ip, ipv6, string and integer is not supported\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003733 default:
Willy Tarreau9d008692019-08-09 11:21:01 +02003734 return cli_err(appctx, "Unknown action\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003735 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003736 }
3737
3738 /* check permissions */
3739 if (!cli_has_level(appctx, ACCESS_LVL_OPER))
3740 return 1;
3741
Willy Tarreaua24bc782016-12-14 15:50:35 +01003742 switch (appctx->ctx.table.action) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003743 case STK_CLI_ACT_SHOW:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003744 ts = stktable_lookup_key(t, &static_table_key);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003745 if (!ts)
3746 return 1;
3747 chunk_reset(&trash);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003748 if (!table_dump_head_to_buffer(&trash, si, t, t)) {
3749 stktable_release(t, ts);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003750 return 0;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003751 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003752 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003753 if (!table_dump_entry_to_buffer(&trash, si, t, ts)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003754 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003755 stktable_release(t, ts);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003756 return 0;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003757 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003758 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003759 stktable_release(t, ts);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003760 break;
3761
3762 case STK_CLI_ACT_CLR:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003763 ts = stktable_lookup_key(t, &static_table_key);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003764 if (!ts)
3765 return 1;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003766
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003767 if (!stksess_kill(t, ts, 1)) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003768 /* don't delete an entry which is currently referenced */
Willy Tarreau9d008692019-08-09 11:21:01 +02003769 return cli_err(appctx, "Entry currently in use, cannot remove\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003770 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003771 break;
3772
3773 case STK_CLI_ACT_SET:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003774 ts = stktable_get_entry(t, &static_table_key);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003775 if (!ts) {
3776 /* don't delete an entry which is currently referenced */
Willy Tarreau9d008692019-08-09 11:21:01 +02003777 return cli_err(appctx, "Unable to allocate a new entry\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003778 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003779 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003780 for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) {
3781 if (strncmp(args[cur_arg], "data.", 5) != 0) {
Willy Tarreau9d008692019-08-09 11:21:01 +02003782 cli_err(appctx, "\"data.<type>\" followed by a value expected\n");
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003783 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003784 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003785 return 1;
3786 }
3787
3788 data_type = stktable_get_data_type(args[cur_arg] + 5);
3789 if (data_type < 0) {
Willy Tarreau9d008692019-08-09 11:21:01 +02003790 cli_err(appctx, "Unknown data type\n");
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003791 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003792 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003793 return 1;
3794 }
3795
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003796 if (!t->data_ofs[data_type]) {
Willy Tarreau9d008692019-08-09 11:21:01 +02003797 cli_err(appctx, "Data type not stored in this table\n");
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003798 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003799 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003800 return 1;
3801 }
3802
3803 if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) {
Willy Tarreau9d008692019-08-09 11:21:01 +02003804 cli_err(appctx, "Require a valid integer value to store\n");
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003805 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003806 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003807 return 1;
3808 }
3809
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003810 ptr = stktable_data_ptr(t, ts, data_type);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003811
3812 switch (stktable_data_types[data_type].std_type) {
3813 case STD_T_SINT:
3814 stktable_data_cast(ptr, std_t_sint) = value;
3815 break;
3816 case STD_T_UINT:
3817 stktable_data_cast(ptr, std_t_uint) = value;
3818 break;
3819 case STD_T_ULL:
3820 stktable_data_cast(ptr, std_t_ull) = value;
3821 break;
3822 case STD_T_FRQP:
3823 /* We set both the current and previous values. That way
3824 * the reported frequency is stable during all the period
3825 * then slowly fades out. This allows external tools to
3826 * push measures without having to update them too often.
3827 */
3828 frqp = &stktable_data_cast(ptr, std_t_frqp);
Willy Tarreaufa1258f2021-04-10 23:00:53 +02003829 /* First bit is reserved for the freq_ctr lock
Emeric Brunf2fc1fd2017-11-02 17:32:43 +01003830 Note: here we're still protected by the stksess lock
Willy Tarreaufa1258f2021-04-10 23:00:53 +02003831 so we don't need to update the update the freq_ctr
Emeric Brunf2fc1fd2017-11-02 17:32:43 +01003832 using its internal lock */
3833 frqp->curr_tick = now_ms & ~0x1;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003834 frqp->prev_ctr = 0;
3835 frqp->curr_ctr = value;
3836 break;
3837 }
3838 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003839 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003840 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003841 break;
3842
3843 default:
Willy Tarreau9d008692019-08-09 11:21:01 +02003844 return cli_err(appctx, "Unknown action\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003845 }
3846 return 1;
3847}
3848
3849/* Prepares the appctx fields with the data-based filters from the command line.
3850 * Returns 0 if the dump can proceed, 1 if has ended processing.
3851 */
3852static int table_prepare_data_request(struct appctx *appctx, char **args)
3853{
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01003854 int i;
Adis Nezirovicd0142e72020-01-22 16:50:27 +01003855 char *err = NULL;
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01003856
Willy Tarreau9d008692019-08-09 11:21:01 +02003857 if (appctx->ctx.table.action != STK_CLI_ACT_SHOW && appctx->ctx.table.action != STK_CLI_ACT_CLR)
3858 return cli_err(appctx, "content-based lookup is only supported with the \"show\" and \"clear\" actions\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003859
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01003860 for (i = 0; i < STKTABLE_FILTER_LEN; i++) {
3861 if (i > 0 && !*args[3+3*i]) // number of filter entries can be less than STKTABLE_FILTER_LEN
3862 break;
3863 /* condition on stored data value */
3864 appctx->ctx.table.data_type[i] = stktable_get_data_type(args[3+3*i] + 5);
3865 if (appctx->ctx.table.data_type[i] < 0)
Adis Nezirovicd0142e72020-01-22 16:50:27 +01003866 return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Unknown data type\n", i + 1));
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003867
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01003868 if (!((struct stktable *)appctx->ctx.table.target)->data_ofs[appctx->ctx.table.data_type[i]])
Adis Nezirovicd0142e72020-01-22 16:50:27 +01003869 return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Data type not stored in this table\n", i + 1));
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003870
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01003871 appctx->ctx.table.data_op[i] = get_std_op(args[4+3*i]);
Willy Tarreau2b64a352020-01-22 17:09:47 +01003872 if (appctx->ctx.table.data_op[i] < 0)
Adis Nezirovicd0142e72020-01-22 16:50:27 +01003873 return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n", i + 1));
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003874
Adis Nezirovic56dd3542020-01-22 16:16:48 +01003875 if (!*args[5+3*i] || strl2llrc(args[5+3*i], strlen(args[5+3*i]), &appctx->ctx.table.value[i]) != 0)
Adis Nezirovicd0142e72020-01-22 16:50:27 +01003876 return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require a valid integer value to compare against\n", i + 1));
3877 }
3878
3879 if (*args[3+3*i]) {
3880 return cli_dynerr(appctx, memprintf(&err, "Detected extra data in filter, %ith word of input, after '%s'\n", 3+3*i + 1, args[2+3*i]));
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01003881 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003882
3883 /* OK we're done, all the fields are set */
3884 return 0;
3885}
3886
3887/* returns 0 if wants to be called, 1 if has ended processing */
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003888static int cli_parse_table_req(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003889{
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01003890 int i;
3891
3892 for (i = 0; i < STKTABLE_FILTER_LEN; i++)
3893 appctx->ctx.table.data_type[i] = -1;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003894 appctx->ctx.table.target = NULL;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003895 appctx->ctx.table.entry = NULL;
Willy Tarreaua24bc782016-12-14 15:50:35 +01003896 appctx->ctx.table.action = (long)private; // keyword argument, one of STK_CLI_ACT_*
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003897
3898 if (*args[2]) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003899 appctx->ctx.table.target = stktable_find_by_name(args[2]);
Willy Tarreau9d008692019-08-09 11:21:01 +02003900 if (!appctx->ctx.table.target)
3901 return cli_err(appctx, "No such table\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003902 }
3903 else {
Willy Tarreaua24bc782016-12-14 15:50:35 +01003904 if (appctx->ctx.table.action != STK_CLI_ACT_SHOW)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003905 goto err_args;
3906 return 0;
3907 }
3908
3909 if (strcmp(args[3], "key") == 0)
3910 return table_process_entry_per_key(appctx, args);
3911 else if (strncmp(args[3], "data.", 5) == 0)
3912 return table_prepare_data_request(appctx, args);
3913 else if (*args[3])
3914 goto err_args;
3915
3916 return 0;
3917
3918err_args:
Willy Tarreaua24bc782016-12-14 15:50:35 +01003919 switch (appctx->ctx.table.action) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003920 case STK_CLI_ACT_SHOW:
Willy Tarreau9d008692019-08-09 11:21:01 +02003921 return cli_err(appctx, "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003922 case STK_CLI_ACT_CLR:
Willy Tarreau9d008692019-08-09 11:21:01 +02003923 return cli_err(appctx, "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003924 case STK_CLI_ACT_SET:
Willy Tarreau9d008692019-08-09 11:21:01 +02003925 return cli_err(appctx, "Required arguments: <table> key <key> [data.<store_data_type> <value>]*\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003926 default:
Willy Tarreau9d008692019-08-09 11:21:01 +02003927 return cli_err(appctx, "Unknown action\n");
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003928 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003929}
3930
3931/* This function is used to deal with table operations (dump or clear depending
3932 * on the action stored in appctx->private). It returns 0 if the output buffer is
3933 * full and it needs to be called again, otherwise non-zero.
3934 */
3935static int cli_io_handler_table(struct appctx *appctx)
3936{
3937 struct stream_interface *si = appctx->owner;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003938 struct stream *s = si_strm(si);
3939 struct ebmb_node *eb;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003940 int skip_entry;
Willy Tarreaua24bc782016-12-14 15:50:35 +01003941 int show = appctx->ctx.table.action == STK_CLI_ACT_SHOW;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003942
3943 /*
3944 * We have 3 possible states in appctx->st2 :
3945 * - STAT_ST_INIT : the first call
3946 * - STAT_ST_INFO : the proxy pointer points to the next table to
3947 * dump, the entry pointer is NULL ;
3948 * - STAT_ST_LIST : the proxy pointer points to the current table
3949 * and the entry pointer points to the next entry to be dumped,
3950 * and the refcount on the next entry is held ;
3951 * - STAT_ST_END : nothing left to dump, the buffer may contain some
3952 * data though.
3953 */
3954
3955 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
3956 /* in case of abort, remove any refcount we might have set on an entry */
3957 if (appctx->st2 == STAT_ST_LIST) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003958 stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003959 }
3960 return 1;
3961 }
3962
3963 chunk_reset(&trash);
3964
3965 while (appctx->st2 != STAT_ST_FIN) {
3966 switch (appctx->st2) {
3967 case STAT_ST_INIT:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003968 appctx->ctx.table.t = appctx->ctx.table.target;
3969 if (!appctx->ctx.table.t)
3970 appctx->ctx.table.t = stktables_list;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003971
3972 appctx->ctx.table.entry = NULL;
3973 appctx->st2 = STAT_ST_INFO;
3974 break;
3975
3976 case STAT_ST_INFO:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003977 if (!appctx->ctx.table.t ||
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003978 (appctx->ctx.table.target &&
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003979 appctx->ctx.table.t != appctx->ctx.table.target)) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003980 appctx->st2 = STAT_ST_END;
3981 break;
3982 }
3983
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003984 if (appctx->ctx.table.t->size) {
3985 if (show && !table_dump_head_to_buffer(&trash, si, appctx->ctx.table.t, appctx->ctx.table.target))
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003986 return 0;
3987
3988 if (appctx->ctx.table.target &&
William Lallemand07a62f72017-05-24 00:57:40 +02003989 (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003990 /* dump entries only if table explicitly requested */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003991 HA_SPIN_LOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
3992 eb = ebmb_first(&appctx->ctx.table.t->keys);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003993 if (eb) {
3994 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
3995 appctx->ctx.table.entry->ref_cnt++;
3996 appctx->st2 = STAT_ST_LIST;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003997 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003998 break;
3999 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004000 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004001 }
4002 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004003 appctx->ctx.table.t = appctx->ctx.table.t->next;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004004 break;
4005
4006 case STAT_ST_LIST:
4007 skip_entry = 0;
4008
Christopher Faulet2a944ee2017-11-07 10:42:54 +01004009 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02004010
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01004011 if (appctx->ctx.table.data_type[0] >= 0) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004012 /* we're filtering on some data contents */
4013 void *ptr;
Willy Tarreau2b64a352020-01-22 17:09:47 +01004014 int dt, i;
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01004015 signed char op;
4016 long long data, value;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004017
Emeric Brun819fc6f2017-06-13 19:37:32 +02004018
Willy Tarreau2b64a352020-01-22 17:09:47 +01004019 for (i = 0; i < STKTABLE_FILTER_LEN; i++) {
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01004020 if (appctx->ctx.table.data_type[i] == -1)
4021 break;
4022 dt = appctx->ctx.table.data_type[i];
4023 ptr = stktable_data_ptr(appctx->ctx.table.t,
4024 appctx->ctx.table.entry,
4025 dt);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004026
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01004027 data = 0;
4028 switch (stktable_data_types[dt].std_type) {
4029 case STD_T_SINT:
4030 data = stktable_data_cast(ptr, std_t_sint);
4031 break;
4032 case STD_T_UINT:
4033 data = stktable_data_cast(ptr, std_t_uint);
4034 break;
4035 case STD_T_ULL:
4036 data = stktable_data_cast(ptr, std_t_ull);
4037 break;
4038 case STD_T_FRQP:
4039 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
4040 appctx->ctx.table.t->data_arg[dt].u);
4041 break;
4042 }
4043
4044 op = appctx->ctx.table.data_op[i];
4045 value = appctx->ctx.table.value[i];
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004046
Adis Nezirovic1a693fc2020-01-16 15:19:29 +01004047 /* skip the entry if the data does not match the test and the value */
4048 if ((data < value &&
4049 (op == STD_OP_EQ || op == STD_OP_GT || op == STD_OP_GE)) ||
4050 (data == value &&
4051 (op == STD_OP_NE || op == STD_OP_GT || op == STD_OP_LT)) ||
4052 (data > value &&
4053 (op == STD_OP_EQ || op == STD_OP_LT || op == STD_OP_LE))) {
4054 skip_entry = 1;
4055 break;
4056 }
4057 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004058 }
4059
4060 if (show && !skip_entry &&
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004061 !table_dump_entry_to_buffer(&trash, si, appctx->ctx.table.t, appctx->ctx.table.entry)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01004062 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02004063 return 0;
4064 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004065
Christopher Faulet2a944ee2017-11-07 10:42:54 +01004066 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02004067
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004068 HA_SPIN_LOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004069 appctx->ctx.table.entry->ref_cnt--;
4070
4071 eb = ebmb_next(&appctx->ctx.table.entry->key);
4072 if (eb) {
4073 struct stksess *old = appctx->ctx.table.entry;
4074 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
4075 if (show)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004076 __stksess_kill_if_expired(appctx->ctx.table.t, old);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004077 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004078 __stksess_kill(appctx->ctx.table.t, old);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004079 appctx->ctx.table.entry->ref_cnt++;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004080 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004081 break;
4082 }
4083
4084
4085 if (show)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004086 __stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004087 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004088 __stksess_kill(appctx->ctx.table.t, appctx->ctx.table.entry);
Emeric Brun819fc6f2017-06-13 19:37:32 +02004089
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004090 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004091
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004092 appctx->ctx.table.t = appctx->ctx.table.t->next;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004093 appctx->st2 = STAT_ST_INFO;
4094 break;
4095
4096 case STAT_ST_END:
4097 appctx->st2 = STAT_ST_FIN;
4098 break;
4099 }
4100 }
4101 return 1;
4102}
4103
4104static void cli_release_show_table(struct appctx *appctx)
4105{
4106 if (appctx->st2 == STAT_ST_LIST) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01004107 stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004108 }
4109}
4110
Willy Tarreau478331d2020-08-28 11:31:31 +02004111static void stkt_late_init(void)
4112{
4113 struct sample_fetch *f;
4114
4115 f = find_sample_fetch("src", strlen("src"));
4116 if (f)
4117 smp_fetch_src = f->process;
4118}
4119
4120INITCALL0(STG_INIT, stkt_late_init);
4121
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004122/* register cli keywords */
4123static struct cli_kw_list cli_kws = {{ },{
Willy Tarreaub205bfd2021-05-07 11:38:37 +02004124 { { "clear", "table", NULL }, "clear table <table> [<filter>]* : remove an entry from a table (filter: data/key)", cli_parse_table_req, cli_io_handler_table, cli_release_show_table, (void *)STK_CLI_ACT_CLR },
4125 { { "set", "table", NULL }, "set table <table> key <k> [data.* <v>]* : update or create a table entry's data", cli_parse_table_req, cli_io_handler_table, NULL, (void *)STK_CLI_ACT_SET },
4126 { { "show", "table", NULL }, "show table <table> [<filter>]* : report table usage stats or dump this table's contents (filter: data/key)", cli_parse_table_req, cli_io_handler_table, cli_release_show_table, (void *)STK_CLI_ACT_SHOW },
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004127 {{},}
4128}};
4129
Willy Tarreau0108d902018-11-25 19:14:37 +01004130INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01004131
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004132static struct action_kw_list tcp_conn_kws = { { }, {
Amaury Denoyellee4a617c2021-05-06 15:33:09 +02004133 { "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
4134 { "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
4135 { "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004136 { /* END */ }
4137}};
4138
Willy Tarreau0108d902018-11-25 19:14:37 +01004139INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws);
4140
Willy Tarreau620408f2016-10-21 16:37:51 +02004141static struct action_kw_list tcp_sess_kws = { { }, {
Amaury Denoyellee4a617c2021-05-06 15:33:09 +02004142 { "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
4143 { "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
4144 { "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
Willy Tarreau620408f2016-10-21 16:37:51 +02004145 { /* END */ }
4146}};
4147
Willy Tarreau0108d902018-11-25 19:14:37 +01004148INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws);
4149
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004150static struct action_kw_list tcp_req_kws = { { }, {
Amaury Denoyellee4a617c2021-05-06 15:33:09 +02004151 { "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
4152 { "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
4153 { "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004154 { /* END */ }
4155}};
4156
Willy Tarreau0108d902018-11-25 19:14:37 +01004157INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_kws);
4158
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004159static struct action_kw_list tcp_res_kws = { { }, {
Amaury Denoyellee4a617c2021-05-06 15:33:09 +02004160 { "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
4161 { "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
4162 { "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004163 { /* END */ }
4164}};
4165
Willy Tarreau0108d902018-11-25 19:14:37 +01004166INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws);
4167
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004168static struct action_kw_list http_req_kws = { { }, {
Amaury Denoyellee4a617c2021-05-06 15:33:09 +02004169 { "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
4170 { "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
4171 { "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004172 { /* END */ }
4173}};
4174
Willy Tarreau0108d902018-11-25 19:14:37 +01004175INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws);
4176
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004177static struct action_kw_list http_res_kws = { { }, {
Amaury Denoyellee4a617c2021-05-06 15:33:09 +02004178 { "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
4179 { "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
4180 { "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004181 { /* END */ }
4182}};
4183
Willy Tarreau0108d902018-11-25 19:14:37 +01004184INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws);
4185
Willy Tarreau7d562212016-11-25 16:10:05 +01004186/* Note: must not be declared <const> as its list will be overwritten.
4187 * Please take care of keeping this list alphabetically sorted.
4188 */
4189static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
4190 { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4191 { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4192 { "sc_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004193 { "sc_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN },
Willy Tarreau7d562212016-11-25 16:10:05 +01004194 { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4195 { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4196 { "sc_conn_rate", smp_fetch_sc_conn_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER401c64b2017-01-05 11:44:09 +01004197 { "sc_get_gpt0", smp_fetch_sc_get_gpt0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004198 { "sc_get_gpc0", smp_fetch_sc_get_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004199 { "sc_get_gpc1", smp_fetch_sc_get_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN },
Willy Tarreau7d562212016-11-25 16:10:05 +01004200 { "sc_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004201 { "sc_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004202 { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4203 { "sc_http_err_rate", smp_fetch_sc_http_err_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau826f3ab2021-02-10 12:07:15 +01004204 { "sc_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4205 { "sc_http_fail_rate", smp_fetch_sc_http_fail_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004206 { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4207 { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4208 { "sc_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004209 { "sc_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004210 { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4211 { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4212 { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4213 { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4214 { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
4215 { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4216 { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4217 { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4218 { "sc0_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004219 { "sc0_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004220 { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4221 { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4222 { "sc0_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER401c64b2017-01-05 11:44:09 +01004223 { "sc0_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004224 { "sc0_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004225 { "sc0_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004226 { "sc0_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004227 { "sc0_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004228 { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4229 { "sc0_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau826f3ab2021-02-10 12:07:15 +01004230 { "sc0_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4231 { "sc0_http_fail_rate", smp_fetch_sc_http_fail_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004232 { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4233 { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4234 { "sc0_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004235 { "sc0_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004236 { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4237 { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4238 { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4239 { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4240 { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
4241 { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4242 { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4243 { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4244 { "sc1_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004245 { "sc1_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004246 { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4247 { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4248 { "sc1_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER401c64b2017-01-05 11:44:09 +01004249 { "sc1_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004250 { "sc1_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004251 { "sc1_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004252 { "sc1_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004253 { "sc1_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004254 { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4255 { "sc1_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau826f3ab2021-02-10 12:07:15 +01004256 { "sc1_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4257 { "sc1_http_fail_rate", smp_fetch_sc_http_fail_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004258 { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4259 { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4260 { "sc1_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004261 { "sc1_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004262 { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4263 { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4264 { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4265 { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4266 { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
4267 { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4268 { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4269 { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4270 { "sc2_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004271 { "sc2_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004272 { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4273 { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4274 { "sc2_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER401c64b2017-01-05 11:44:09 +01004275 { "sc2_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004276 { "sc2_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004277 { "sc2_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004278 { "sc2_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004279 { "sc2_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004280 { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4281 { "sc2_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau826f3ab2021-02-10 12:07:15 +01004282 { "sc2_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4283 { "sc2_http_fail_rate", smp_fetch_sc_http_fail_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004284 { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4285 { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4286 { "sc2_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004287 { "sc2_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004288 { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4289 { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4290 { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4291 { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4292 { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
4293 { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4294 { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4295 { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4296 { "src_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004297 { "src_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004298 { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4299 { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4300 { "src_conn_rate", smp_fetch_sc_conn_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Thierry FOURNIER401c64b2017-01-05 11:44:09 +01004301 { "src_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004302 { "src_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004303 { "src_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004304 { "src_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004305 { "src_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004306 { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4307 { "src_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Willy Tarreau826f3ab2021-02-10 12:07:15 +01004308 { "src_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4309 { "src_http_fail_rate", smp_fetch_sc_http_fail_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004310 { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4311 { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4312 { "src_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004313 { "src_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Willy Tarreau7d562212016-11-25 16:10:05 +01004314 { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4315 { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4316 { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4317 { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4318 { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4319 { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4320 { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4321 { /* END */ },
4322}};
4323
Willy Tarreau0108d902018-11-25 19:14:37 +01004324INITCALL1(STG_REGISTER, sample_register_fetches, &smp_fetch_keywords);
Willy Tarreau7d562212016-11-25 16:10:05 +01004325
Willy Tarreaud9f316a2014-07-10 14:03:38 +02004326/* Note: must not be declared <const> as its list will be overwritten */
4327static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Willy Tarreau2d17db52016-05-25 17:16:38 +02004328 { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL },
4329 { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4330 { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4331 { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4332 { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4333 { "table_conn_rate", sample_conv_table_conn_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4334 { "table_gpt0", sample_conv_table_gpt0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4335 { "table_gpc0", sample_conv_table_gpc0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004336 { "table_gpc1", sample_conv_table_gpc1, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Willy Tarreau2d17db52016-05-25 17:16:38 +02004337 { "table_gpc0_rate", sample_conv_table_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01004338 { "table_gpc1_rate", sample_conv_table_gpc1_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Willy Tarreau2d17db52016-05-25 17:16:38 +02004339 { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4340 { "table_http_err_rate", sample_conv_table_http_err_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Willy Tarreau826f3ab2021-02-10 12:07:15 +01004341 { "table_http_fail_cnt", sample_conv_table_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4342 { "table_http_fail_rate", sample_conv_table_http_fail_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Willy Tarreau2d17db52016-05-25 17:16:38 +02004343 { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4344 { "table_http_req_rate", sample_conv_table_http_req_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4345 { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4346 { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4347 { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4348 { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4349 { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4350 { "table_trackers", sample_conv_table_trackers, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Willy Tarreaud9f316a2014-07-10 14:03:38 +02004351 { /* END */ },
4352}};
4353
Willy Tarreau0108d902018-11-25 19:14:37 +01004354INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws);