blob: 1263ca4c4b897cb23a9ea97bd10ec6bb3617345c [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
17#include <common/config.h>
Frédéric Lécailled456aa42019-03-08 14:47:00 +010018#include <common/cfgparse.h>
Willy Tarreau0108d902018-11-25 19:14:37 +010019#include <common/initcall.h>
Emeric Brun3bd697e2010-01-04 15:23:48 +010020#include <common/memory.h>
21#include <common/mini-clist.h>
22#include <common/standard.h>
23#include <common/time.h>
24
25#include <ebmbtree.h>
26#include <ebsttree.h>
27
Willy Tarreauf13ebdf2016-11-22 18:00:53 +010028#include <types/cli.h>
Willy Tarreau39713102016-11-25 15:49:32 +010029#include <types/global.h>
Willy Tarreauf13ebdf2016-11-22 18:00:53 +010030#include <types/stats.h>
31
Willy Tarreaud9f316a2014-07-10 14:03:38 +020032#include <proto/arg.h>
Willy Tarreauf13ebdf2016-11-22 18:00:53 +010033#include <proto/cli.h>
Willy Tarreau61c112a2018-10-02 16:43:32 +020034#include <proto/http_rules.h>
Andjelko Iharosc3680ec2017-07-20 16:49:14 +020035#include <proto/log.h>
Thierry FOURNIER236657b2015-08-19 08:25:14 +020036#include <proto/proto_http.h>
Willy Tarreau7d562212016-11-25 16:10:05 +010037#include <proto/proto_tcp.h>
Emeric Brun3bd697e2010-01-04 15:23:48 +010038#include <proto/proxy.h>
Willy Tarreaucd3b0942012-04-27 21:52:18 +020039#include <proto/sample.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020040#include <proto/stream.h>
Willy Tarreauf13ebdf2016-11-22 18:00:53 +010041#include <proto/stream_interface.h>
Willy Tarreau68129b92010-06-06 16:06:52 +020042#include <proto/stick_table.h>
Emeric Brun3bd697e2010-01-04 15:23:48 +010043#include <proto/task.h>
Emeric Brun32da3c42010-09-23 18:39:19 +020044#include <proto/peers.h>
Willy Tarreau39713102016-11-25 15:49:32 +010045#include <proto/tcp_rules.h>
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 Tarreauf0b38bf2010-06-06 13:22:23 +020049
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010050struct stktable *stktables_list;
51struct eb_root stktable_by_name = EB_ROOT;
52
Olivier Houchard52dabbc2018-11-14 17:54:36 +010053#define round_ptr_size(i) (((i) + (sizeof(void *) - 1)) &~ (sizeof(void *) - 1))
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010054
55/* This function inserts stktable <t> into the tree of known stick-table.
56 * The stick-table ID is used as the storing key so it must already have
57 * been initialized.
58 */
59void stktable_store_name(struct stktable *t)
60{
61 t->name.key = t->id;
62 ebis_insert(&stktable_by_name, &t->name);
63}
64
65struct stktable *stktable_find_by_name(const char *name)
66{
67 struct ebpt_node *node;
68 struct stktable *t;
69
70 node = ebis_lookup(&stktable_by_name, name);
71 if (node) {
72 t = container_of(node, struct stktable, name);
73 if (!strcmp(t->id, name))
74 return t;
75 }
76
77 return NULL;
78}
79
Emeric Brun3bd697e2010-01-04 15:23:48 +010080/*
Willy Tarreauaea940e2010-06-06 11:56:36 +020081 * Free an allocated sticky session <ts>, and decrease sticky sessions counter
82 * in table <t>.
Emeric Brun3bd697e2010-01-04 15:23:48 +010083 */
Emeric Brun819fc6f2017-06-13 19:37:32 +020084void __stksess_free(struct stktable *t, struct stksess *ts)
Emeric Brun3bd697e2010-01-04 15:23:48 +010085{
86 t->current--;
Olivier Houchard52dabbc2018-11-14 17:54:36 +010087 pool_free(t->pool, (void *)ts - round_ptr_size(t->data_size));
Emeric Brun3bd697e2010-01-04 15:23:48 +010088}
89
90/*
Emeric Brun819fc6f2017-06-13 19:37:32 +020091 * Free an allocated sticky session <ts>, and decrease sticky sessions counter
92 * in table <t>.
93 * This function locks the table
94 */
95void stksess_free(struct stktable *t, struct stksess *ts)
96{
Christopher Faulet2a944ee2017-11-07 10:42:54 +010097 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +020098 __stksess_free(t, ts);
Christopher Faulet2a944ee2017-11-07 10:42:54 +010099 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200100}
101
102/*
Willy Tarreauf6efda12010-08-03 20:34:06 +0200103 * Kill an stksess (only if its ref_cnt is zero).
104 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200105int __stksess_kill(struct stktable *t, struct stksess *ts)
Willy Tarreauf6efda12010-08-03 20:34:06 +0200106{
107 if (ts->ref_cnt)
Emeric Brun819fc6f2017-06-13 19:37:32 +0200108 return 0;
Willy Tarreauf6efda12010-08-03 20:34:06 +0200109
110 eb32_delete(&ts->exp);
Emeric Brun85e77c72010-09-23 18:16:52 +0200111 eb32_delete(&ts->upd);
Willy Tarreauf6efda12010-08-03 20:34:06 +0200112 ebmb_delete(&ts->key);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200113 __stksess_free(t, ts);
114 return 1;
Willy Tarreauf6efda12010-08-03 20:34:06 +0200115}
116
117/*
Emeric Brun819fc6f2017-06-13 19:37:32 +0200118 * Decrease the refcount if decrefcnt is not 0.
119 * and try to kill the stksess
120 * This function locks the table
121 */
122int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt)
123{
124 int ret;
125
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100126 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200127 if (decrefcnt)
128 ts->ref_cnt--;
129 ret = __stksess_kill(t, ts);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100130 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200131
132 return ret;
133}
134
135/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200136 * Initialize or update the key in the sticky session <ts> present in table <t>
137 * from the value present in <key>.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100138 */
Willy Tarreau393379c2010-06-06 12:11:37 +0200139void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100140{
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200141 if (t->type != SMP_T_STR)
Willy Tarreau86257dc2010-06-06 12:57:10 +0200142 memcpy(ts->key.key, key->key, t->key_size);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100143 else {
Willy Tarreau86257dc2010-06-06 12:57:10 +0200144 memcpy(ts->key.key, key->key, MIN(t->key_size - 1, key->key_len));
145 ts->key.key[MIN(t->key_size - 1, key->key_len)] = 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100146 }
147}
148
149
150/*
Willy Tarreau393379c2010-06-06 12:11:37 +0200151 * Init sticky session <ts> of table <t>. The data parts are cleared and <ts>
152 * is returned.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100153 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200154static struct stksess *__stksess_init(struct stktable *t, struct stksess * ts)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100155{
Willy Tarreau393379c2010-06-06 12:11:37 +0200156 memset((void *)ts - t->data_size, 0, t->data_size);
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200157 ts->ref_cnt = 0;
Willy Tarreau86257dc2010-06-06 12:57:10 +0200158 ts->key.node.leaf_p = NULL;
159 ts->exp.node.leaf_p = NULL;
Emeric Brun85e77c72010-09-23 18:16:52 +0200160 ts->upd.node.leaf_p = NULL;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200161 ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100162 HA_RWLOCK_INIT(&ts->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100163 return ts;
164}
165
166/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200167 * Trash oldest <to_batch> sticky sessions from table <t>
168 * Returns number of trashed sticky sessions.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100169 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200170int __stktable_trash_oldest(struct stktable *t, int to_batch)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100171{
172 struct stksess *ts;
173 struct eb32_node *eb;
174 int batched = 0;
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200175 int looped = 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100176
177 eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK);
178
179 while (batched < to_batch) {
180
181 if (unlikely(!eb)) {
182 /* we might have reached the end of the tree, typically because
183 * <now_ms> is in the first half and we're first scanning the last
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200184 * half. Let's loop back to the beginning of the tree now if we
185 * have not yet visited it.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100186 */
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200187 if (looped)
188 break;
189 looped = 1;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100190 eb = eb32_first(&t->exps);
191 if (likely(!eb))
192 break;
193 }
194
195 /* timer looks expired, detach it from the queue */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200196 ts = eb32_entry(eb, struct stksess, exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100197 eb = eb32_next(eb);
198
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200199 /* don't delete an entry which is currently referenced */
200 if (ts->ref_cnt)
201 continue;
202
Willy Tarreau86257dc2010-06-06 12:57:10 +0200203 eb32_delete(&ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100204
Willy Tarreau86257dc2010-06-06 12:57:10 +0200205 if (ts->expire != ts->exp.key) {
Emeric Brun3bd697e2010-01-04 15:23:48 +0100206 if (!tick_isset(ts->expire))
207 continue;
208
Willy Tarreau86257dc2010-06-06 12:57:10 +0200209 ts->exp.key = ts->expire;
210 eb32_insert(&t->exps, &ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100211
Willy Tarreau86257dc2010-06-06 12:57:10 +0200212 if (!eb || eb->key > ts->exp.key)
213 eb = &ts->exp;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100214
215 continue;
216 }
Emeric Brun3bd697e2010-01-04 15:23:48 +0100217
Willy Tarreauaea940e2010-06-06 11:56:36 +0200218 /* session expired, trash it */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200219 ebmb_delete(&ts->key);
Emeric Brun85e77c72010-09-23 18:16:52 +0200220 eb32_delete(&ts->upd);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200221 __stksess_free(t, ts);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100222 batched++;
223 }
224
225 return batched;
226}
227
228/*
Emeric Brun819fc6f2017-06-13 19:37:32 +0200229 * Trash oldest <to_batch> sticky sessions from table <t>
230 * Returns number of trashed sticky sessions.
231 * This function locks the table
232 */
233int stktable_trash_oldest(struct stktable *t, int to_batch)
234{
235 int ret;
236
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100237 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200238 ret = __stktable_trash_oldest(t, to_batch);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100239 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200240
241 return ret;
242}
243/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200244 * Allocate and initialise a new sticky session.
245 * The new sticky session is returned or NULL in case of lack of memory.
246 * Sticky sessions should only be allocated this way, and must be freed using
Willy Tarreaua7b46b52013-04-11 16:55:37 +0200247 * stksess_free(). Table <t>'s sticky session counter is increased. If <key>
248 * is not NULL, it is assigned to the new session.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100249 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200250struct stksess *__stksess_new(struct stktable *t, struct stktable_key *key)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100251{
252 struct stksess *ts;
253
254 if (unlikely(t->current == t->size)) {
255 if ( t->nopurge )
256 return NULL;
257
Emeric Brun819fc6f2017-06-13 19:37:32 +0200258 if (!__stktable_trash_oldest(t, (t->size >> 8) + 1))
Emeric Brun3bd697e2010-01-04 15:23:48 +0100259 return NULL;
260 }
261
Willy Tarreaubafbe012017-11-24 17:34:44 +0100262 ts = pool_alloc(t->pool);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100263 if (ts) {
264 t->current++;
Olivier Houchard52dabbc2018-11-14 17:54:36 +0100265 ts = (void *)ts + round_ptr_size(t->data_size);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200266 __stksess_init(t, ts);
Willy Tarreaua7b46b52013-04-11 16:55:37 +0200267 if (key)
268 stksess_setkey(t, ts, key);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100269 }
270
271 return ts;
272}
Emeric Brun819fc6f2017-06-13 19:37:32 +0200273/*
274 * Allocate and initialise a new sticky session.
275 * The new sticky session is returned or NULL in case of lack of memory.
276 * Sticky sessions should only be allocated this way, and must be freed using
277 * stksess_free(). Table <t>'s sticky session counter is increased. If <key>
278 * is not NULL, it is assigned to the new session.
279 * This function locks the table
280 */
281struct stksess *stksess_new(struct stktable *t, struct stktable_key *key)
282{
283 struct stksess *ts;
284
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100285 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200286 ts = __stksess_new(t, key);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100287 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200288
289 return ts;
290}
Emeric Brun3bd697e2010-01-04 15:23:48 +0100291
292/*
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200293 * Looks in table <t> for a sticky session matching key <key>.
Willy Tarreauaea940e2010-06-06 11:56:36 +0200294 * Returns pointer on requested sticky session or NULL if none was found.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100295 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200296struct stksess *__stktable_lookup_key(struct stktable *t, struct stktable_key *key)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100297{
298 struct ebmb_node *eb;
299
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200300 if (t->type == SMP_T_STR)
Emeric Brun485479d2010-09-23 18:02:19 +0200301 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 +0100302 else
303 eb = ebmb_lookup(&t->keys, key->key, t->key_size);
304
305 if (unlikely(!eb)) {
306 /* no session found */
307 return NULL;
308 }
309
Willy Tarreau86257dc2010-06-06 12:57:10 +0200310 return ebmb_entry(eb, struct stksess, key);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100311}
312
Emeric Brun819fc6f2017-06-13 19:37:32 +0200313/*
314 * Looks in table <t> for a sticky session matching key <key>.
315 * Returns pointer on requested sticky session or NULL if none was found.
316 * The refcount of the found entry is increased and this function
317 * is protected using the table lock
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200318 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200319struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key)
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200320{
321 struct stksess *ts;
322
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100323 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200324 ts = __stktable_lookup_key(t, key);
325 if (ts)
326 ts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100327 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200328
Willy Tarreau1f7e9252010-06-20 12:27:21 +0200329 return ts;
330}
331
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200332/*
333 * Looks in table <t> for a sticky session with same key as <ts>.
334 * Returns pointer on requested sticky session or NULL if none was found.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100335 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200336struct stksess *__stktable_lookup(struct stktable *t, struct stksess *ts)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100337{
Emeric Brun3bd697e2010-01-04 15:23:48 +0100338 struct ebmb_node *eb;
339
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200340 if (t->type == SMP_T_STR)
Willy Tarreau86257dc2010-06-06 12:57:10 +0200341 eb = ebst_lookup(&(t->keys), (char *)ts->key.key);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100342 else
Willy Tarreau86257dc2010-06-06 12:57:10 +0200343 eb = ebmb_lookup(&(t->keys), ts->key.key, t->key_size);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100344
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200345 if (unlikely(!eb))
346 return NULL;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100347
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200348 return ebmb_entry(eb, struct stksess, key);
349}
Emeric Brun3bd697e2010-01-04 15:23:48 +0100350
Emeric Brun819fc6f2017-06-13 19:37:32 +0200351/*
352 * Looks in table <t> for a sticky session with same key as <ts>.
353 * Returns pointer on requested sticky session or NULL if none was found.
354 * The refcount of the found entry is increased and this function
355 * is protected using the table lock
356 */
357struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts)
358{
359 struct stksess *lts;
360
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100361 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200362 lts = __stktable_lookup(t, ts);
363 if (lts)
364 lts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100365 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200366
367 return lts;
368}
369
Willy Tarreaucb183642010-06-06 17:58:34 +0200370/* Update the expiration timer for <ts> but do not touch its expiration node.
371 * The table's expiration timer is updated if set.
Emeric Brun819fc6f2017-06-13 19:37:32 +0200372 * The node will be also inserted into the update tree if needed, at a position
373 * depending if the update is a local or coming from a remote node
Willy Tarreaucb183642010-06-06 17:58:34 +0200374 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200375void __stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local, int expire)
Willy Tarreaucb183642010-06-06 17:58:34 +0200376{
Emeric Brun85e77c72010-09-23 18:16:52 +0200377 struct eb32_node * eb;
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200378 ts->expire = expire;
Willy Tarreaucb183642010-06-06 17:58:34 +0200379 if (t->expire) {
380 t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next);
381 task_queue(t->exp_task);
382 }
Emeric Brun85e77c72010-09-23 18:16:52 +0200383
Emeric Brun819fc6f2017-06-13 19:37:32 +0200384 /* If sync is enabled */
385 if (t->sync_task) {
386 if (local) {
387 /* If this entry is not in the tree
388 or not scheduled for at least one peer */
389 if (!ts->upd.node.leaf_p
390 || (int)(t->commitupdate - ts->upd.key) >= 0
391 || (int)(ts->upd.key - t->localupdate) >= 0) {
392 ts->upd.key = ++t->update;
393 t->localupdate = t->update;
394 eb32_delete(&ts->upd);
395 eb = eb32_insert(&t->updates, &ts->upd);
396 if (eb != &ts->upd) {
397 eb32_delete(eb);
398 eb32_insert(&t->updates, &ts->upd);
399 }
Emeric Brunaaf58602015-06-15 17:23:30 +0200400 }
Emeric Brun819fc6f2017-06-13 19:37:32 +0200401 task_wakeup(t->sync_task, TASK_WOKEN_MSG);
Emeric Brun85e77c72010-09-23 18:16:52 +0200402 }
Emeric Brun819fc6f2017-06-13 19:37:32 +0200403 else {
404 /* If this entry is not in the tree */
405 if (!ts->upd.node.leaf_p) {
406 ts->upd.key= (++t->update)+(2147483648U);
407 eb = eb32_insert(&t->updates, &ts->upd);
408 if (eb != &ts->upd) {
409 eb32_delete(eb);
410 eb32_insert(&t->updates, &ts->upd);
411 }
412 }
413 }
Emeric Brun85e77c72010-09-23 18:16:52 +0200414 }
Willy Tarreaucb183642010-06-06 17:58:34 +0200415}
416
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200417/* Update the expiration timer for <ts> but do not touch its expiration node.
Emeric Brun819fc6f2017-06-13 19:37:32 +0200418 * The table's expiration timer is updated using the date of expiration coming from
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200419 * <t> stick-table configuration.
Emeric Brun819fc6f2017-06-13 19:37:32 +0200420 * The node will be also inserted into the update tree if needed, at a position
421 * considering the update is coming from a remote node
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200422 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200423void stktable_touch_remote(struct stktable *t, struct stksess *ts, int decrefcnt)
424{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100425 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200426 __stktable_touch_with_exp(t, ts, 0, ts->expire);
427 if (decrefcnt)
428 ts->ref_cnt--;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100429 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200430}
431
432/* Update the expiration timer for <ts> but do not touch its expiration node.
433 * The table's expiration timer is updated using the date of expiration coming from
434 * <t> stick-table configuration.
435 * The node will be also inserted into the update tree if needed, at a position
436 * considering the update was made locally
437 */
438void stktable_touch_local(struct stktable *t, struct stksess *ts, int decrefcnt)
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200439{
440 int expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
441
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100442 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200443 __stktable_touch_with_exp(t, ts, 1, expire);
444 if (decrefcnt)
445 ts->ref_cnt--;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100446 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200447}
Willy Tarreau43e90352018-06-27 06:25:57 +0200448/* Just decrease the ref_cnt of the current session. Does nothing if <ts> is NULL */
449static void stktable_release(struct stktable *t, struct stksess *ts)
Emeric Brun819fc6f2017-06-13 19:37:32 +0200450{
Willy Tarreau43e90352018-06-27 06:25:57 +0200451 if (!ts)
452 return;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100453 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200454 ts->ref_cnt--;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100455 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200456}
457
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200458/* Insert new sticky session <ts> in the table. It is assumed that it does not
459 * yet exist (the caller must check this). The table's timeout is updated if it
460 * is set. <ts> is returned.
461 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200462void __stktable_store(struct stktable *t, struct stksess *ts)
Willy Tarreauf16d2b82010-06-06 15:38:59 +0200463{
Emeric Brun3bd697e2010-01-04 15:23:48 +0100464
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200465 ebmb_insert(&t->keys, &ts->key, t->key_size);
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200466 ts->exp.key = ts->expire;
467 eb32_insert(&t->exps, &ts->exp);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200468 if (t->expire) {
469 t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next);
470 task_queue(t->exp_task);
471 }
Frédéric Lécaille523cc9e2016-10-12 17:30:30 +0200472}
473
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200474/* Returns a valid or initialized stksess for the specified stktable_key in the
475 * specified table, or NULL if the key was NULL, or if no entry was found nor
476 * could be created. The entry's expiration is updated.
477 */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200478struct stksess *__stktable_get_entry(struct stktable *table, struct stktable_key *key)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200479{
480 struct stksess *ts;
481
482 if (!key)
483 return NULL;
484
Emeric Brun819fc6f2017-06-13 19:37:32 +0200485 ts = __stktable_lookup_key(table, key);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200486 if (ts == NULL) {
487 /* entry does not exist, initialize a new one */
Emeric Brun819fc6f2017-06-13 19:37:32 +0200488 ts = __stksess_new(table, key);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200489 if (!ts)
490 return NULL;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200491 __stktable_store(table, ts);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200492 }
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200493 return ts;
494}
Emeric Brun819fc6f2017-06-13 19:37:32 +0200495/* Returns a valid or initialized stksess for the specified stktable_key in the
496 * specified table, or NULL if the key was NULL, or if no entry was found nor
497 * could be created. The entry's expiration is updated.
498 * This function locks the table, and the refcount of the entry is increased.
499 */
500struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key)
501{
502 struct stksess *ts;
503
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100504 HA_SPIN_LOCK(STK_TABLE_LOCK, &table->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200505 ts = __stktable_get_entry(table, key);
506 if (ts)
507 ts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100508 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &table->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200509
510 return ts;
511}
512
513/* Lookup for an entry with the same key and store the submitted
514 * stksess if not found.
515 */
516struct stksess *__stktable_set_entry(struct stktable *table, struct stksess *nts)
517{
518 struct stksess *ts;
519
520 ts = __stktable_lookup(table, nts);
521 if (ts == NULL) {
522 ts = nts;
523 __stktable_store(table, ts);
524 }
525 return ts;
526}
527
528/* Lookup for an entry with the same key and store the submitted
529 * stksess if not found.
530 * This function locks the table, and the refcount of the entry is increased.
531 */
532struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts)
533{
534 struct stksess *ts;
535
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100536 HA_SPIN_LOCK(STK_TABLE_LOCK, &table->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200537 ts = __stktable_set_entry(table, nts);
538 ts->ref_cnt++;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100539 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &table->lock);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200540
Emeric Brun819fc6f2017-06-13 19:37:32 +0200541 return ts;
542}
Emeric Brun3bd697e2010-01-04 15:23:48 +0100543/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200544 * Trash expired sticky sessions from table <t>. The next expiration date is
545 * returned.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100546 */
547static int stktable_trash_expired(struct stktable *t)
548{
549 struct stksess *ts;
550 struct eb32_node *eb;
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200551 int looped = 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100552
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100553 HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100554 eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK);
555
556 while (1) {
557 if (unlikely(!eb)) {
558 /* we might have reached the end of the tree, typically because
559 * <now_ms> is in the first half and we're first scanning the last
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200560 * half. Let's loop back to the beginning of the tree now if we
561 * have not yet visited it.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100562 */
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200563 if (looped)
564 break;
565 looped = 1;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100566 eb = eb32_first(&t->exps);
567 if (likely(!eb))
568 break;
569 }
570
571 if (likely(tick_is_lt(now_ms, eb->key))) {
572 /* timer not expired yet, revisit it later */
573 t->exp_next = eb->key;
Willy Tarreau4d5f13c2017-11-05 11:04:47 +0100574 goto out_unlock;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100575 }
576
577 /* timer looks expired, detach it from the queue */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200578 ts = eb32_entry(eb, struct stksess, exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100579 eb = eb32_next(eb);
580
Willy Tarreaue7f3d7a2010-06-14 14:53:07 +0200581 /* don't delete an entry which is currently referenced */
582 if (ts->ref_cnt)
583 continue;
584
Willy Tarreau86257dc2010-06-06 12:57:10 +0200585 eb32_delete(&ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100586
587 if (!tick_is_expired(ts->expire, now_ms)) {
588 if (!tick_isset(ts->expire))
589 continue;
590
Willy Tarreau86257dc2010-06-06 12:57:10 +0200591 ts->exp.key = ts->expire;
592 eb32_insert(&t->exps, &ts->exp);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100593
Willy Tarreau86257dc2010-06-06 12:57:10 +0200594 if (!eb || eb->key > ts->exp.key)
595 eb = &ts->exp;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100596 continue;
597 }
598
599 /* session expired, trash it */
Willy Tarreau86257dc2010-06-06 12:57:10 +0200600 ebmb_delete(&ts->key);
Emeric Brun85e77c72010-09-23 18:16:52 +0200601 eb32_delete(&ts->upd);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200602 __stksess_free(t, ts);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100603 }
604
605 /* We have found no task to expire in any tree */
606 t->exp_next = TICK_ETERNITY;
Willy Tarreau4d5f13c2017-11-05 11:04:47 +0100607out_unlock:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100608 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100609 return t->exp_next;
610}
611
612/*
Willy Tarreauaea940e2010-06-06 11:56:36 +0200613 * Task processing function to trash expired sticky sessions. A pointer to the
614 * task itself is returned since it never dies.
Emeric Brun3bd697e2010-01-04 15:23:48 +0100615 */
Olivier Houchard9f6af332018-05-25 14:04:04 +0200616static struct task *process_table_expire(struct task *task, void *context, unsigned short state)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100617{
Olivier Houchard9f6af332018-05-25 14:04:04 +0200618 struct stktable *t = context;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100619
620 task->expire = stktable_trash_expired(t);
621 return task;
622}
623
Willy Tarreauaea940e2010-06-06 11:56:36 +0200624/* Perform minimal stick table intializations, report 0 in case of error, 1 if OK. */
Emeric Brun3bd697e2010-01-04 15:23:48 +0100625int stktable_init(struct stktable *t)
626{
627 if (t->size) {
Emeric Brun819fc6f2017-06-13 19:37:32 +0200628 t->keys = EB_ROOT_UNIQUE;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100629 memset(&t->exps, 0, sizeof(t->exps));
Emeric Brun1c6235d2015-12-16 15:28:12 +0100630 t->updates = EB_ROOT_UNIQUE;
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100631 HA_SPIN_INIT(&t->lock);
Emeric Brun3bd697e2010-01-04 15:23:48 +0100632
Olivier Houchard52dabbc2018-11-14 17:54:36 +0100633 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 +0100634
635 t->exp_next = TICK_ETERNITY;
636 if ( t->expire ) {
Emeric Brunc60def82017-09-27 14:59:38 +0200637 t->exp_task = task_new(MAX_THREADS_MASK);
Willy Tarreau848522f2018-10-15 11:12:15 +0200638 if (!t->exp_task)
639 return 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100640 t->exp_task->process = process_table_expire;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100641 t->exp_task->context = (void *)t;
642 }
Willy Tarreauc8b67912015-05-01 18:29:57 +0200643 if (t->peers.p && t->peers.p->peers_fe && t->peers.p->peers_fe->state != PR_STSTOPPED) {
Emeric Brun32da3c42010-09-23 18:39:19 +0200644 peers_register_table(t->peers.p, t);
645 }
646
Emeric Brun3bd697e2010-01-04 15:23:48 +0100647 return t->pool != NULL;
648 }
649 return 1;
650}
651
652/*
653 * Configuration keywords of known table types
654 */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200655struct stktable_type stktable_types[SMP_TYPES] = {
656 [SMP_T_SINT] = { "integer", 0, 4 },
657 [SMP_T_IPV4] = { "ip", 0, 4 },
658 [SMP_T_IPV6] = { "ipv6", 0, 16 },
659 [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 },
660 [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 }
661};
Emeric Brun3bd697e2010-01-04 15:23:48 +0100662
663/*
664 * Parse table type configuration.
665 * Returns 0 on successful parsing, else 1.
666 * <myidx> is set at next configuration <args> index.
667 */
668int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size)
669{
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200670 for (*type = 0; *type < SMP_TYPES; (*type)++) {
671 if (!stktable_types[*type].kw)
672 continue;
Emeric Brun3bd697e2010-01-04 15:23:48 +0100673 if (strcmp(args[*myidx], stktable_types[*type].kw) != 0)
674 continue;
675
676 *key_size = stktable_types[*type].default_size;
677 (*myidx)++;
678
Willy Tarreauaea940e2010-06-06 11:56:36 +0200679 if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) {
Emeric Brun3bd697e2010-01-04 15:23:48 +0100680 if (strcmp("len", args[*myidx]) == 0) {
681 (*myidx)++;
682 *key_size = atol(args[*myidx]);
Emeric Brun485479d2010-09-23 18:02:19 +0200683 if (!*key_size)
Emeric Brun3bd697e2010-01-04 15:23:48 +0100684 break;
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200685 if (*type == SMP_T_STR) {
Emeric Brun485479d2010-09-23 18:02:19 +0200686 /* null terminated string needs +1 for '\0'. */
687 (*key_size)++;
688 }
Emeric Brun3bd697e2010-01-04 15:23:48 +0100689 (*myidx)++;
690 }
691 }
692 return 0;
693 }
694 return 1;
695}
696
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100697/*
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100698 * Parse a line with <linenum> as number in <file> configuration file to configure
699 * the stick-table with <t> as address and <id> as ID.
700 * <peers> provides the "peers" section pointer only if this function is called
701 * from a "peers" section.
702 * <nid> is the stick-table name which is sent over the network. It must be equal
703 * to <id> if this stick-table is parsed from a proxy section, and prefixed by <peers>
704 * "peers" section name followed by a '/' character if parsed from a "peers" section.
705 * This is the responsability of the caller to check this.
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100706 * Return an error status with ERR_* flags set if required, 0 if no error was encountered.
707 */
708int parse_stick_table(const char *file, int linenum, char **args,
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100709 struct stktable *t, char *id, char *nid, struct peers *peers)
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100710{
711 int err_code = 0;
712 int idx = 1;
713 unsigned int val;
714
715 if (!id || !*id) {
716 ha_alert("parsing [%s:%d] : %s: ID not provided.\n", file, linenum, args[0]);
717 err_code |= ERR_ALERT | ERR_ABORT;
718 goto out;
719 }
720
721 /* Store the "peers" section if this function is called from a "peers" section. */
722 if (peers) {
723 t->peers.p = peers;
724 idx++;
725 }
726
727 t->id = id;
Frédéric Lécaillec02766a2019-03-20 15:06:55 +0100728 t->nid = nid;
Frédéric Lécailled456aa42019-03-08 14:47:00 +0100729 t->type = (unsigned int)-1;
730 t->conf.file = file;
731 t->conf.line = linenum;
732
733 while (*args[idx]) {
734 const char *err;
735
736 if (strcmp(args[idx], "size") == 0) {
737 idx++;
738 if (!*(args[idx])) {
739 ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n",
740 file, linenum, args[0], args[idx-1]);
741 err_code |= ERR_ALERT | ERR_FATAL;
742 goto out;
743 }
744 if ((err = parse_size_err(args[idx], &t->size))) {
745 ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n",
746 file, linenum, args[0], *err, args[idx-1]);
747 err_code |= ERR_ALERT | ERR_FATAL;
748 goto out;
749 }
750 idx++;
751 }
752 /* This argument does not exit in "peers" section. */
753 else if (!peers && strcmp(args[idx], "peers") == 0) {
754 idx++;
755 if (!*(args[idx])) {
756 ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n",
757 file, linenum, args[0], args[idx-1]);
758 err_code |= ERR_ALERT | ERR_FATAL;
759 goto out;
760 }
761 t->peers.name = strdup(args[idx++]);
762 }
763 else if (strcmp(args[idx], "expire") == 0) {
764 idx++;
765 if (!*(args[idx])) {
766 ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n",
767 file, linenum, args[0], args[idx-1]);
768 err_code |= ERR_ALERT | ERR_FATAL;
769 goto out;
770 }
771 err = parse_time_err(args[idx], &val, TIME_UNIT_MS);
772 if (err) {
773 ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n",
774 file, linenum, args[0], *err, args[idx-1]);
775 err_code |= ERR_ALERT | ERR_FATAL;
776 goto out;
777 }
778 if (val > INT_MAX) {
779 ha_alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n",
780 file, linenum, val);
781 err_code |= ERR_ALERT | ERR_FATAL;
782 goto out;
783 }
784 t->expire = val;
785 idx++;
786 }
787 else if (strcmp(args[idx], "nopurge") == 0) {
788 t->nopurge = 1;
789 idx++;
790 }
791 else if (strcmp(args[idx], "type") == 0) {
792 idx++;
793 if (stktable_parse_type(args, &idx, &t->type, &t->key_size) != 0) {
794 ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n",
795 file, linenum, args[0], args[idx]);
796 err_code |= ERR_ALERT | ERR_FATAL;
797 goto out;
798 }
799 /* idx already points to next arg */
800 }
801 else if (strcmp(args[idx], "store") == 0) {
802 int type, err;
803 char *cw, *nw, *sa;
804
805 idx++;
806 nw = args[idx];
807 while (*nw) {
808 /* the "store" keyword supports a comma-separated list */
809 cw = nw;
810 sa = NULL; /* store arg */
811 while (*nw && *nw != ',') {
812 if (*nw == '(') {
813 *nw = 0;
814 sa = ++nw;
815 while (*nw != ')') {
816 if (!*nw) {
817 ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n",
818 file, linenum, args[0], cw);
819 err_code |= ERR_ALERT | ERR_FATAL;
820 goto out;
821 }
822 nw++;
823 }
824 *nw = '\0';
825 }
826 nw++;
827 }
828 if (*nw)
829 *nw++ = '\0';
830 type = stktable_get_data_type(cw);
831 if (type < 0) {
832 ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n",
833 file, linenum, args[0], cw);
834 err_code |= ERR_ALERT | ERR_FATAL;
835 goto out;
836 }
837
838 err = stktable_alloc_data_type(t, type, sa);
839 switch (err) {
840 case PE_NONE: break;
841 case PE_EXIST:
842 ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n",
843 file, linenum, args[0], cw);
844 err_code |= ERR_WARN;
845 break;
846
847 case PE_ARG_MISSING:
848 ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n",
849 file, linenum, args[0], cw);
850 err_code |= ERR_ALERT | ERR_FATAL;
851 goto out;
852
853 case PE_ARG_NOT_USED:
854 ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n",
855 file, linenum, args[0], cw);
856 err_code |= ERR_ALERT | ERR_FATAL;
857 goto out;
858
859 default:
860 ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n",
861 file, linenum, args[0], cw);
862 err_code |= ERR_ALERT | ERR_FATAL;
863 goto out;
864 }
865 }
866 idx++;
867 }
868 else {
869 ha_alert("parsing [%s:%d] : %s: unknown argument '%s'.\n",
870 file, linenum, args[0], args[idx]);
871 err_code |= ERR_ALERT | ERR_FATAL;
872 goto out;
873 }
874 }
875
876 if (!t->size) {
877 ha_alert("parsing [%s:%d] : %s: missing size.\n",
878 file, linenum, args[0]);
879 err_code |= ERR_ALERT | ERR_FATAL;
880 goto out;
881 }
882
883 if (t->type == (unsigned int)-1) {
884 ha_alert("parsing [%s:%d] : %s: missing type.\n",
885 file, linenum, args[0]);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto out;
888 }
889
890 out:
891 return err_code;
892}
893
Willy Tarreau8fed9032014-07-03 17:02:46 +0200894/* Prepares a stktable_key from a sample <smp> to search into table <t>.
Willy Tarreauf0c730a2016-05-25 17:07:56 +0200895 * Note that the sample *is* modified and that the returned key may point
896 * to it, so the sample must not be modified afterwards before the lookup.
Willy Tarreau8fed9032014-07-03 17:02:46 +0200897 * Returns NULL if the sample could not be converted (eg: no matching type),
898 * otherwise a pointer to the static stktable_key filled with what is needed
899 * for the lookup.
Willy Tarreauf0b38bf2010-06-06 13:22:23 +0200900 */
Willy Tarreau8fed9032014-07-03 17:02:46 +0200901struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
Willy Tarreauf0b38bf2010-06-06 13:22:23 +0200902{
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200903 /* Convert sample. */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200904 if (!sample_convert(smp, t->type))
Willy Tarreau7fc1c6e2012-04-26 11:03:17 +0200905 return NULL;
906
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200907 /* Fill static_table_key. */
908 switch (t->type) {
Emeric Brun485479d2010-09-23 18:02:19 +0200909
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200910 case SMP_T_IPV4:
Christopher Fauletca20d022017-08-29 15:30:31 +0200911 static_table_key.key = &smp->data.u.ipv4;
912 static_table_key.key_len = 4;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200913 break;
Emeric Brun485479d2010-09-23 18:02:19 +0200914
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200915 case SMP_T_IPV6:
Christopher Fauletca20d022017-08-29 15:30:31 +0200916 static_table_key.key = &smp->data.u.ipv6;
917 static_table_key.key_len = 16;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200918 break;
Emeric Brun485479d2010-09-23 18:02:19 +0200919
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200920 case SMP_T_SINT:
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200921 /* The stick table require a 32bit unsigned int, "sint" is a
922 * signed 64 it, so we can convert it inplace.
923 */
924 *(unsigned int *)&smp->data.u.sint = (unsigned int)smp->data.u.sint;
Christopher Fauletca20d022017-08-29 15:30:31 +0200925 static_table_key.key = &smp->data.u.sint;
926 static_table_key.key_len = 4;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200927 break;
928
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200929 case SMP_T_STR:
Willy Tarreauce6955e2016-08-09 11:59:12 +0200930 if (!smp_make_safe(smp))
931 return NULL;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200932 static_table_key.key = smp->data.u.str.area;
933 static_table_key.key_len = smp->data.u.str.data;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200934 break;
Emeric Brun485479d2010-09-23 18:02:19 +0200935
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200936 case SMP_T_BIN:
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200937 if (smp->data.u.str.data < t->key_size) {
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200938 /* This type needs padding with 0. */
Willy Tarreauf65c6c02016-08-09 12:08:41 +0200939 if (!smp_make_rw(smp))
940 return NULL;
941
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200942 if (smp->data.u.str.size < t->key_size)
943 if (!smp_dup(smp))
944 return NULL;
945 if (smp->data.u.str.size < t->key_size)
946 return NULL;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200947 memset(smp->data.u.str.area + smp->data.u.str.data, 0,
948 t->key_size - smp->data.u.str.data);
949 smp->data.u.str.data = t->key_size;
Emeric Brun485479d2010-09-23 18:02:19 +0200950 }
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200951 static_table_key.key = smp->data.u.str.area;
952 static_table_key.key_len = smp->data.u.str.data;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200953 break;
Emeric Brun485479d2010-09-23 18:02:19 +0200954
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +0200955 default: /* impossible case. */
956 return NULL;
Emeric Brun485479d2010-09-23 18:02:19 +0200957 }
958
Christopher Fauletca20d022017-08-29 15:30:31 +0200959 return &static_table_key;
Willy Tarreauf0b38bf2010-06-06 13:22:23 +0200960}
961
962/*
Willy Tarreau8fed9032014-07-03 17:02:46 +0200963 * Process a fetch + format conversion as defined by the sample expression <expr>
964 * on request or response considering the <opt> parameter. Returns either NULL if
965 * no key could be extracted, or a pointer to the converted result stored in
966 * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset
967 * and its flags will be initialized so that the caller gets a copy of the input
Willy Tarreau6bcb0a82014-07-30 08:56:35 +0200968 * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present
969 * without SMP_OPT_FINAL). The output will be usable like this :
970 *
971 * return MAY_CHANGE FINAL Meaning for the sample
972 * NULL 0 * Not present and will never be (eg: header)
973 * NULL 1 0 Not present or unstable, could change (eg: req_len)
974 * NULL 1 1 Not present, will not change anymore
975 * smp 0 * Present and will not change (eg: header)
976 * smp 1 0 not possible
977 * smp 1 1 Present, last known value (eg: request length)
Willy Tarreau8fed9032014-07-03 17:02:46 +0200978 */
Willy Tarreau192252e2015-04-04 01:47:55 +0200979struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *sess, struct stream *strm,
Willy Tarreau8fed9032014-07-03 17:02:46 +0200980 unsigned int opt, struct sample_expr *expr, struct sample *smp)
981{
982 if (smp)
983 memset(smp, 0, sizeof(*smp));
984
Willy Tarreau192252e2015-04-04 01:47:55 +0200985 smp = sample_process(px, sess, strm, opt, expr, smp);
Willy Tarreau8fed9032014-07-03 17:02:46 +0200986 if (!smp)
987 return NULL;
988
989 if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL))
990 return NULL; /* we can only use stable samples */
991
992 return smp_to_stkey(smp, t);
993}
994
995/*
Willy Tarreau12785782012-04-27 21:37:17 +0200996 * Returns 1 if sample expression <expr> result can be converted to table key of
Willy Tarreauf0b38bf2010-06-06 13:22:23 +0200997 * type <table_type>, otherwise zero. Used in configuration check.
998 */
Willy Tarreau12785782012-04-27 21:37:17 +0200999int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type)
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001000{
Thierry FOURNIERf73eb8f2013-11-27 15:30:55 +01001001 int out_type;
1002
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +02001003 if (table_type >= SMP_TYPES || !stktable_types[table_type].kw)
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001004 return 0;
1005
Thierry FOURNIERf73eb8f2013-11-27 15:30:55 +01001006 out_type = smp_expr_output_type(expr);
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001007
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +02001008 /* Convert sample. */
1009 if (!sample_casts[out_type][table_type])
Thierry FOURNIERf73eb8f2013-11-27 15:30:55 +01001010 return 0;
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001011
Willy Tarreauf0b38bf2010-06-06 13:22:23 +02001012 return 1;
1013}
Emeric Brun3bd697e2010-01-04 15:23:48 +01001014
Willy Tarreauedee1d62014-07-15 16:44:27 +02001015/* Extra data types processing : after the last one, some room may remain
1016 * before STKTABLE_DATA_TYPES that may be used to register extra data types
1017 * at run time.
1018 */
Willy Tarreau08d5f982010-06-06 13:34:54 +02001019struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = {
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02001020 [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT },
Thierry FOURNIER3cf11112015-07-28 08:57:05 +02001021 [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT },
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02001022 [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT },
Willy Tarreauba2ffd12013-05-29 15:54:14 +02001023 [STKTABLE_DT_GPC0_RATE] = { .name = "gpc0_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02001024 [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT },
1025 [STKTABLE_DT_CONN_RATE] = { .name = "conn_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1026 [STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .std_type = STD_T_UINT },
1027 [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT },
1028 [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1029 [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT },
1030 [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1031 [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT },
1032 [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1033 [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL },
1034 [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
1035 [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL },
1036 [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 +01001037 [STKTABLE_DT_GPC1] = { .name = "gpc1", .std_type = STD_T_UINT },
1038 [STKTABLE_DT_GPC1_RATE] = { .name = "gpc1_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY },
Willy Tarreau08d5f982010-06-06 13:34:54 +02001039};
1040
Willy Tarreauedee1d62014-07-15 16:44:27 +02001041/* Registers stick-table extra data type with index <idx>, name <name>, type
1042 * <std_type> and arg type <arg_type>. If the index is negative, the next free
1043 * index is automatically allocated. The allocated index is returned, or -1 if
1044 * no free index was found or <name> was already registered. The <name> is used
1045 * directly as a pointer, so if it's not stable, the caller must allocate it.
1046 */
1047int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type)
1048{
1049 if (idx < 0) {
1050 for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) {
1051 if (!stktable_data_types[idx].name)
1052 break;
1053
1054 if (strcmp(stktable_data_types[idx].name, name) == 0)
1055 return -1;
1056 }
1057 }
1058
1059 if (idx >= STKTABLE_DATA_TYPES)
1060 return -1;
1061
1062 if (stktable_data_types[idx].name != NULL)
1063 return -1;
1064
1065 stktable_data_types[idx].name = name;
1066 stktable_data_types[idx].std_type = std_type;
1067 stktable_data_types[idx].arg_type = arg_type;
1068 return idx;
1069}
1070
Willy Tarreau08d5f982010-06-06 13:34:54 +02001071/*
1072 * Returns the data type number for the stktable_data_type whose name is <name>,
1073 * or <0 if not found.
1074 */
1075int stktable_get_data_type(char *name)
1076{
1077 int type;
1078
1079 for (type = 0; type < STKTABLE_DATA_TYPES; type++) {
Willy Tarreauedee1d62014-07-15 16:44:27 +02001080 if (!stktable_data_types[type].name)
1081 continue;
Willy Tarreau08d5f982010-06-06 13:34:54 +02001082 if (strcmp(name, stktable_data_types[type].name) == 0)
1083 return type;
1084 }
1085 return -1;
1086}
1087
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001088/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1089 * it up into this table. Returns true if found, false otherwise. The input
1090 * type is STR so that input samples are converted to string (since all types
1091 * can be converted to strings), then the function casts the string again into
1092 * the table's type. This is a double conversion, but in the future we might
1093 * support automatic input types to perform the cast on the fly.
1094 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001095static int sample_conv_in_table(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001096{
1097 struct stktable *t;
1098 struct stktable_key *key;
1099 struct stksess *ts;
1100
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001101 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001102
1103 key = smp_to_stkey(smp, t);
1104 if (!key)
1105 return 0;
1106
1107 ts = stktable_lookup_key(t, key);
1108
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001109 smp->data.type = SMP_T_BOOL;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001110 smp->data.u.sint = !!ts;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001111 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau43e90352018-06-27 06:25:57 +02001112 stktable_release(t, ts);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001113 return 1;
1114}
1115
1116/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1117 * it up into this table. Returns the data rate received from clients in bytes/s
1118 * if the key is present in the table, otherwise zero, so that comparisons can
1119 * be easily performed. If the inspected parameter is not stored in the table,
1120 * <not found> is returned.
1121 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001122static int sample_conv_table_bytes_in_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001123{
1124 struct stktable *t;
1125 struct stktable_key *key;
1126 struct stksess *ts;
1127 void *ptr;
1128
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001129 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001130
1131 key = smp_to_stkey(smp, t);
1132 if (!key)
1133 return 0;
1134
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001135 ts = stktable_lookup_key(t, key);
1136
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001137 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001138 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001139 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001140
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001141 if (!ts) /* key not present */
1142 return 1;
1143
1144 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001145 if (ptr)
1146 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
1147 t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001148
Daniel Corbett3e60b112018-05-27 09:47:12 -04001149 stktable_release(t, ts);
1150 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001151}
1152
1153/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1154 * it up into this table. Returns the cumulated number of connections for the key
1155 * if the key is present in the table, otherwise zero, so that comparisons can
1156 * be easily performed. If the inspected parameter is not stored in the table,
1157 * <not found> is returned.
1158 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001159static int sample_conv_table_conn_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001160{
1161 struct stktable *t;
1162 struct stktable_key *key;
1163 struct stksess *ts;
1164 void *ptr;
1165
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001166 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001167
1168 key = smp_to_stkey(smp, t);
1169 if (!key)
1170 return 0;
1171
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001172 ts = stktable_lookup_key(t, key);
1173
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001174 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001175 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001176 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001177
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001178 if (!ts) /* key not present */
1179 return 1;
1180
1181 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001182 if (ptr)
1183 smp->data.u.sint = stktable_data_cast(ptr, conn_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001184
Daniel Corbett3e60b112018-05-27 09:47:12 -04001185 stktable_release(t, ts);
1186 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001187}
1188
1189/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1190 * it up into this table. Returns the number of concurrent connections for the
1191 * key if the key is present in the table, otherwise zero, so that comparisons
1192 * can be easily performed. If the inspected parameter is not stored in the
1193 * table, <not found> is returned.
1194 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001195static int sample_conv_table_conn_cur(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 void *ptr;
1201
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001202 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001203
1204 key = smp_to_stkey(smp, t);
1205 if (!key)
1206 return 0;
1207
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001208 ts = stktable_lookup_key(t, key);
1209
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001210 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001211 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001212 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001213
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001214 if (!ts) /* key not present */
1215 return 1;
1216
1217 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001218 if (ptr)
1219 smp->data.u.sint = stktable_data_cast(ptr, conn_cur);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001220
Daniel Corbett3e60b112018-05-27 09:47:12 -04001221 stktable_release(t, ts);
1222 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001223}
1224
1225/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1226 * it up into this table. Returns the rate of incoming connections from the key
1227 * if the key is present in the table, otherwise zero, so that comparisons can
1228 * be easily performed. If the inspected parameter is not stored in the table,
1229 * <not found> is returned.
1230 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001231static int sample_conv_table_conn_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001232{
1233 struct stktable *t;
1234 struct stktable_key *key;
1235 struct stksess *ts;
1236 void *ptr;
1237
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001238 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001239
1240 key = smp_to_stkey(smp, t);
1241 if (!key)
1242 return 0;
1243
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001244 ts = stktable_lookup_key(t, key);
1245
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001246 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001247 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001248 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001249
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001250 if (!ts) /* key not present */
1251 return 1;
1252
1253 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001254 if (ptr)
1255 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
1256 t->data_arg[STKTABLE_DT_CONN_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001257
Daniel Corbett3e60b112018-05-27 09:47:12 -04001258 stktable_release(t, ts);
1259 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001260}
1261
1262/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1263 * it up into this table. Returns the data rate sent to clients in bytes/s
1264 * if the key is present in the table, otherwise zero, so that comparisons can
1265 * be easily performed. If the inspected parameter is not stored in the table,
1266 * <not found> is returned.
1267 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001268static int sample_conv_table_bytes_out_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001269{
1270 struct stktable *t;
1271 struct stktable_key *key;
1272 struct stksess *ts;
1273 void *ptr;
1274
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001275 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001276
1277 key = smp_to_stkey(smp, t);
1278 if (!key)
1279 return 0;
1280
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001281 ts = stktable_lookup_key(t, key);
1282
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001283 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001284 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001285 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001286
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001287 if (!ts) /* key not present */
1288 return 1;
1289
1290 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001291 if (ptr)
1292 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
1293 t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001294
Daniel Corbett3e60b112018-05-27 09:47:12 -04001295 stktable_release(t, ts);
1296 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001297}
1298
1299/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001300 * it up into this table. Returns the value of the GPT0 tag for the key
1301 * if the key is present in the table, otherwise false, so that comparisons can
1302 * be easily performed. If the inspected parameter is not stored in the table,
1303 * <not found> is returned.
1304 */
1305static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private)
1306{
1307 struct stktable *t;
1308 struct stktable_key *key;
1309 struct stksess *ts;
1310 void *ptr;
1311
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001312 t = arg_p[0].data.t;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001313
1314 key = smp_to_stkey(smp, t);
1315 if (!key)
1316 return 0;
1317
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001318 ts = stktable_lookup_key(t, key);
1319
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001320 smp->flags = SMP_F_VOL_TEST;
1321 smp->data.type = SMP_T_SINT;
1322 smp->data.u.sint = 0;
1323
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001324 if (!ts) /* key not present */
1325 return 1;
1326
1327 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001328 if (ptr)
1329 smp->data.u.sint = stktable_data_cast(ptr, gpt0);
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001330
Daniel Corbett3e60b112018-05-27 09:47:12 -04001331 stktable_release(t, ts);
1332 return !!ptr;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001333}
1334
1335/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001336 * it up into this table. Returns the value of the GPC0 counter for the key
1337 * if the key is present in the table, otherwise zero, so that comparisons can
1338 * be easily performed. If the inspected parameter is not stored in the table,
1339 * <not found> is returned.
1340 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001341static int sample_conv_table_gpc0(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001342{
1343 struct stktable *t;
1344 struct stktable_key *key;
1345 struct stksess *ts;
1346 void *ptr;
1347
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001348 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001349
1350 key = smp_to_stkey(smp, t);
1351 if (!key)
1352 return 0;
1353
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001354 ts = stktable_lookup_key(t, key);
1355
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001356 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001357 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001358 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001359
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001360 if (!ts) /* key not present */
1361 return 1;
1362
1363 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001364 if (ptr)
1365 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001366
Daniel Corbett3e60b112018-05-27 09:47:12 -04001367 stktable_release(t, ts);
1368 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001369}
1370
1371/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1372 * it up into this table. Returns the event rate of the GPC0 counter for the key
1373 * if the key is present in the table, otherwise zero, so that comparisons can
1374 * be easily performed. If the inspected parameter is not stored in the table,
1375 * <not found> is returned.
1376 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001377static int sample_conv_table_gpc0_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001378{
1379 struct stktable *t;
1380 struct stktable_key *key;
1381 struct stksess *ts;
1382 void *ptr;
1383
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001384 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001385
1386 key = smp_to_stkey(smp, t);
1387 if (!key)
1388 return 0;
1389
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001390 ts = stktable_lookup_key(t, key);
1391
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001392 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001393 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001394 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001395
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001396 if (!ts) /* key not present */
1397 return 1;
1398
1399 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001400 if (ptr)
1401 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate),
1402 t->data_arg[STKTABLE_DT_GPC0_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001403
Daniel Corbett3e60b112018-05-27 09:47:12 -04001404 stktable_release(t, ts);
1405 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001406}
1407
1408/* 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 +01001409 * it up into this table. Returns the value of the GPC1 counter for the key
1410 * if the key is present in the table, otherwise zero, so that comparisons can
1411 * be easily performed. If the inspected parameter is not stored in the table,
1412 * <not found> is returned.
1413 */
1414static int sample_conv_table_gpc1(const struct arg *arg_p, struct sample *smp, void *private)
1415{
1416 struct stktable *t;
1417 struct stktable_key *key;
1418 struct stksess *ts;
1419 void *ptr;
1420
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001421 t = arg_p[0].data.t;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001422
1423 key = smp_to_stkey(smp, t);
1424 if (!key)
1425 return 0;
1426
1427 ts = stktable_lookup_key(t, key);
1428
1429 smp->flags = SMP_F_VOL_TEST;
1430 smp->data.type = SMP_T_SINT;
1431 smp->data.u.sint = 0;
1432
1433 if (!ts) /* key not present */
1434 return 1;
1435
1436 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001437 if (ptr)
1438 smp->data.u.sint = stktable_data_cast(ptr, gpc1);
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001439
Daniel Corbett3e60b112018-05-27 09:47:12 -04001440 stktable_release(t, ts);
1441 return !!ptr;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001442}
1443
1444/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1445 * it up into this table. Returns the event rate of the GPC1 counter for the key
1446 * if the key is present in the table, otherwise zero, so that comparisons can
1447 * be easily performed. If the inspected parameter is not stored in the table,
1448 * <not found> is returned.
1449 */
1450static int sample_conv_table_gpc1_rate(const struct arg *arg_p, struct sample *smp, void *private)
1451{
1452 struct stktable *t;
1453 struct stktable_key *key;
1454 struct stksess *ts;
1455 void *ptr;
1456
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001457 t = arg_p[0].data.t;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001458
1459 key = smp_to_stkey(smp, t);
1460 if (!key)
1461 return 0;
1462
1463 ts = stktable_lookup_key(t, key);
1464
1465 smp->flags = SMP_F_VOL_TEST;
1466 smp->data.type = SMP_T_SINT;
1467 smp->data.u.sint = 0;
1468
1469 if (!ts) /* key not present */
1470 return 1;
1471
1472 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001473 if (ptr)
1474 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc1_rate),
1475 t->data_arg[STKTABLE_DT_GPC1_RATE].u);
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001476
Daniel Corbett3e60b112018-05-27 09:47:12 -04001477 stktable_release(t, ts);
1478 return !!ptr;
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001479}
1480
1481/* Casts sample <smp> to the type of the table specified in arg(0), and looks
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001482 * it up into this table. Returns the cumulated number of HTTP request errors
1483 * for the key if the key is present in the table, otherwise zero, so that
1484 * comparisons can be easily performed. If the inspected parameter is not stored
1485 * in the table, <not found> is returned.
1486 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001487static int sample_conv_table_http_err_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001488{
1489 struct stktable *t;
1490 struct stktable_key *key;
1491 struct stksess *ts;
1492 void *ptr;
1493
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001494 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001495
1496 key = smp_to_stkey(smp, t);
1497 if (!key)
1498 return 0;
1499
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001500 ts = stktable_lookup_key(t, key);
1501
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001502 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001503 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001504 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001505
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001506 if (!ts) /* key not present */
1507 return 1;
1508
1509 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001510 if (ptr)
1511 smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001512
Daniel Corbett3e60b112018-05-27 09:47:12 -04001513 stktable_release(t, ts);
1514 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001515}
1516
1517/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1518 * it up into this table. Returns the HTTP request error rate the key
1519 * if the key is present in the table, otherwise zero, so that comparisons can
1520 * be easily performed. If the inspected parameter is not stored in the table,
1521 * <not found> is returned.
1522 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001523static int sample_conv_table_http_err_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001524{
1525 struct stktable *t;
1526 struct stktable_key *key;
1527 struct stksess *ts;
1528 void *ptr;
1529
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001530 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001531
1532 key = smp_to_stkey(smp, t);
1533 if (!key)
1534 return 0;
1535
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001536 ts = stktable_lookup_key(t, key);
1537
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001538 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001539 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001540 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001541
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001542 if (!ts) /* key not present */
1543 return 1;
1544
1545 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001546 if (ptr)
1547 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
1548 t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001549
Daniel Corbett3e60b112018-05-27 09:47:12 -04001550 stktable_release(t, ts);
1551 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001552}
1553
1554/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1555 * it up into this table. Returns the cumulated number of HTTP request for the
1556 * key if the key is present in the table, otherwise zero, so that comparisons
1557 * can be easily performed. If the inspected parameter is not stored in the
1558 * table, <not found> is returned.
1559 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001560static int sample_conv_table_http_req_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001561{
1562 struct stktable *t;
1563 struct stktable_key *key;
1564 struct stksess *ts;
1565 void *ptr;
1566
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001567 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001568
1569 key = smp_to_stkey(smp, t);
1570 if (!key)
1571 return 0;
1572
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001573 ts = stktable_lookup_key(t, key);
1574
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001575 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001576 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001577 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001578
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001579 if (!ts) /* key not present */
1580 return 1;
1581
1582 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001583 if (ptr)
1584 smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001585
Daniel Corbett3e60b112018-05-27 09:47:12 -04001586 stktable_release(t, ts);
1587 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001588}
1589
1590/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1591 * it up into this table. Returns the HTTP request rate the key if the key is
1592 * present in the table, otherwise zero, so that comparisons can be easily
1593 * performed. If the inspected parameter is not stored in the table, <not found>
1594 * is returned.
1595 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001596static int sample_conv_table_http_req_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001597{
1598 struct stktable *t;
1599 struct stktable_key *key;
1600 struct stksess *ts;
1601 void *ptr;
1602
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001603 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001604
1605 key = smp_to_stkey(smp, t);
1606 if (!key)
1607 return 0;
1608
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001609 ts = stktable_lookup_key(t, key);
1610
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001611 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001612 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001613 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001614
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001615 if (!ts) /* key not present */
1616 return 1;
1617
1618 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001619 if (ptr)
1620 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
1621 t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001622
Daniel Corbett3e60b112018-05-27 09:47:12 -04001623 stktable_release(t, ts);
1624 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001625}
1626
1627/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1628 * it up into this table. Returns the volume of datareceived from clients in kbytes
1629 * if the key is present in the table, otherwise zero, so that comparisons can
1630 * be easily performed. If the inspected parameter is not stored in the table,
1631 * <not found> is returned.
1632 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001633static int sample_conv_table_kbytes_in(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001634{
1635 struct stktable *t;
1636 struct stktable_key *key;
1637 struct stksess *ts;
1638 void *ptr;
1639
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001640 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001641
1642 key = smp_to_stkey(smp, t);
1643 if (!key)
1644 return 0;
1645
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001646 ts = stktable_lookup_key(t, key);
1647
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001648 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001649 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001650 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001651
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001652 if (!ts) /* key not present */
1653 return 1;
1654
1655 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001656 if (ptr)
1657 smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001658
Daniel Corbett3e60b112018-05-27 09:47:12 -04001659 stktable_release(t, ts);
1660 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001661}
1662
1663/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1664 * it up into this table. Returns the volume of data sent to clients in kbytes
1665 * if the key is present in the table, otherwise zero, so that comparisons can
1666 * be easily performed. If the inspected parameter is not stored in the table,
1667 * <not found> is returned.
1668 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001669static int sample_conv_table_kbytes_out(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001670{
1671 struct stktable *t;
1672 struct stktable_key *key;
1673 struct stksess *ts;
1674 void *ptr;
1675
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001676 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001677
1678 key = smp_to_stkey(smp, t);
1679 if (!key)
1680 return 0;
1681
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001682 ts = stktable_lookup_key(t, key);
1683
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001684 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001685 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001686 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001687
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001688 if (!ts) /* key not present */
1689 return 1;
1690
1691 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001692 if (ptr)
1693 smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001694
Daniel Corbett3e60b112018-05-27 09:47:12 -04001695 stktable_release(t, ts);
1696 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001697}
1698
1699/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1700 * it up into this table. Returns the server ID associated with the key if the
1701 * key is present in the table, otherwise zero, so that comparisons can be
1702 * easily performed. If the inspected parameter is not stored in the table,
1703 * <not found> is returned.
1704 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001705static int sample_conv_table_server_id(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001706{
1707 struct stktable *t;
1708 struct stktable_key *key;
1709 struct stksess *ts;
1710 void *ptr;
1711
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001712 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001713
1714 key = smp_to_stkey(smp, t);
1715 if (!key)
1716 return 0;
1717
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001718 ts = stktable_lookup_key(t, key);
1719
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001720 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001721 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001722 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001723
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001724 if (!ts) /* key not present */
1725 return 1;
1726
1727 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001728 if (ptr)
1729 smp->data.u.sint = stktable_data_cast(ptr, server_id);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001730
Daniel Corbett3e60b112018-05-27 09:47:12 -04001731 stktable_release(t, ts);
1732 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001733}
1734
1735/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1736 * it up into this table. Returns the cumulated number of sessions for the
1737 * key if the key is present in the table, otherwise zero, so that comparisons
1738 * can be easily performed. If the inspected parameter is not stored in the
1739 * table, <not found> is returned.
1740 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001741static int sample_conv_table_sess_cnt(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001742{
1743 struct stktable *t;
1744 struct stktable_key *key;
1745 struct stksess *ts;
1746 void *ptr;
1747
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001748 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001749
1750 key = smp_to_stkey(smp, t);
1751 if (!key)
1752 return 0;
1753
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001754 ts = stktable_lookup_key(t, key);
1755
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001756 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001757 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001758 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001759
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001760 if (!ts) /* key not present */
1761 return 1;
1762
1763 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001764 if (ptr)
1765 smp->data.u.sint = stktable_data_cast(ptr, sess_cnt);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001766
Daniel Corbett3e60b112018-05-27 09:47:12 -04001767 stktable_release(t, ts);
1768 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001769}
1770
1771/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1772 * it up into this table. Returns the session rate the key if the key is
1773 * present in the table, otherwise zero, so that comparisons can be easily
1774 * performed. If the inspected parameter is not stored in the table, <not found>
1775 * is returned.
1776 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001777static int sample_conv_table_sess_rate(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001778{
1779 struct stktable *t;
1780 struct stktable_key *key;
1781 struct stksess *ts;
1782 void *ptr;
1783
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001784 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001785
1786 key = smp_to_stkey(smp, t);
1787 if (!key)
1788 return 0;
1789
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001790 ts = stktable_lookup_key(t, key);
1791
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001792 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001793 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001794 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001795
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001796 if (!ts) /* key not present */
1797 return 1;
1798
1799 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE);
Daniel Corbett3e60b112018-05-27 09:47:12 -04001800 if (ptr)
1801 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
1802 t->data_arg[STKTABLE_DT_SESS_RATE].u);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001803
Daniel Corbett3e60b112018-05-27 09:47:12 -04001804 stktable_release(t, ts);
1805 return !!ptr;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001806}
1807
1808/* Casts sample <smp> to the type of the table specified in arg(0), and looks
1809 * it up into this table. Returns the amount of concurrent connections tracking
1810 * the same key if the key is present in the table, otherwise zero, so that
1811 * comparisons can be easily performed. If the inspected parameter is not
1812 * stored in the table, <not found> is returned.
1813 */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001814static int sample_conv_table_trackers(const struct arg *arg_p, struct sample *smp, void *private)
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001815{
1816 struct stktable *t;
1817 struct stktable_key *key;
1818 struct stksess *ts;
1819
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01001820 t = arg_p[0].data.t;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001821
1822 key = smp_to_stkey(smp, t);
1823 if (!key)
1824 return 0;
1825
Willy Tarreauf0c730a2016-05-25 17:07:56 +02001826 ts = stktable_lookup_key(t, key);
1827
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001828 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001829 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001830 smp->data.u.sint = 0;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001831
Tim Duesterhus65189c12018-06-26 15:57:29 +02001832 if (!ts)
1833 return 1;
1834
1835 smp->data.u.sint = ts->ref_cnt;
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001836
Daniel Corbett3e60b112018-05-27 09:47:12 -04001837 stktable_release(t, ts);
Willy Tarreaud9f316a2014-07-10 14:03:38 +02001838 return 1;
1839}
1840
Thierry FOURNIER236657b2015-08-19 08:25:14 +02001841/* Always returns 1. */
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001842static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px,
Willy Tarreau658b85b2015-09-27 10:00:49 +02001843 struct session *sess, struct stream *s, int flags)
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001844{
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001845 struct stksess *ts;
1846 struct stkctr *stkctr;
1847
1848 /* Extract the stksess, return OK if no stksess available. */
1849 if (s)
1850 stkctr = &s->stkctr[rule->arg.gpc.sc];
1851 else
1852 stkctr = &sess->stkctr[rule->arg.gpc.sc];
Willy Tarreau79c1e912016-01-25 14:54:45 +01001853
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001854 ts = stkctr_entry(stkctr);
Willy Tarreau79c1e912016-01-25 14:54:45 +01001855 if (ts) {
1856 void *ptr1, *ptr2;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001857
Willy Tarreau79c1e912016-01-25 14:54:45 +01001858 /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */
1859 ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE);
Emeric Brun819fc6f2017-06-13 19:37:32 +02001860 ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0);
1861 if (ptr1 || ptr2) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001862 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02001863
1864 if (ptr1)
1865 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate),
Willy Tarreau79c1e912016-01-25 14:54:45 +01001866 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1);
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001867
Emeric Brun819fc6f2017-06-13 19:37:32 +02001868 if (ptr2)
1869 stktable_data_cast(ptr2, gpc0)++;
Willy Tarreau79c1e912016-01-25 14:54:45 +01001870
Christopher Faulet2a944ee2017-11-07 10:42:54 +01001871 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02001872
1873 /* If data was modified, we need to touch to re-schedule sync */
1874 stktable_touch_local(stkctr->table, ts, 0);
1875 }
Willy Tarreau79c1e912016-01-25 14:54:45 +01001876 }
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001877 return ACT_RET_CONT;
1878}
1879
1880/* This function is a common parser for using variables. It understands
1881 * the formats:
1882 *
1883 * sc-inc-gpc0(<stick-table ID>)
1884 *
1885 * It returns 0 if fails and <err> is filled with an error message. Otherwise,
1886 * it returns 1 and the variable <expr> is filled with the pointer to the
1887 * expression to execute.
1888 */
1889static enum act_parse_ret parse_inc_gpc0(const char **args, int *arg, struct proxy *px,
1890 struct act_rule *rule, char **err)
1891{
1892 const char *cmd_name = args[*arg-1];
1893 char *error;
1894
1895 cmd_name += strlen("sc-inc-gpc0");
1896 if (*cmd_name == '\0') {
1897 /* default stick table id. */
1898 rule->arg.gpc.sc = 0;
1899 } else {
1900 /* parse the stick table id. */
1901 if (*cmd_name != '(') {
1902 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
1903 return ACT_RET_PRS_ERR;
1904 }
1905 cmd_name++; /* jump the '(' */
1906 rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */
1907 if (*error != ')') {
1908 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
1909 return ACT_RET_PRS_ERR;
1910 }
1911
1912 if (rule->arg.gpc.sc >= ACT_ACTION_TRK_SCMAX) {
1913 memprintf(err, "invalid stick table track ID. The max allowed ID is %d",
1914 ACT_ACTION_TRK_SCMAX-1);
1915 return ACT_RET_PRS_ERR;
1916 }
1917 }
Thierry FOURNIER42148732015-09-02 17:17:33 +02001918 rule->action = ACT_CUSTOM;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02001919 rule->action_ptr = action_inc_gpc0;
1920 return ACT_RET_PRS_OK;
1921}
1922
1923/* Always returns 1. */
Frédéric Lécaille6778b272018-01-29 15:22:53 +01001924static enum act_return action_inc_gpc1(struct act_rule *rule, struct proxy *px,
1925 struct session *sess, struct stream *s, int flags)
1926{
1927 struct stksess *ts;
1928 struct stkctr *stkctr;
1929
1930 /* Extract the stksess, return OK if no stksess available. */
1931 if (s)
1932 stkctr = &s->stkctr[rule->arg.gpc.sc];
1933 else
1934 stkctr = &sess->stkctr[rule->arg.gpc.sc];
1935
1936 ts = stkctr_entry(stkctr);
1937 if (ts) {
1938 void *ptr1, *ptr2;
1939
1940 /* First, update gpc1_rate if it's tracked. Second, update its gpc1 if tracked. */
1941 ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1_RATE);
1942 ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1);
1943 if (ptr1 || ptr2) {
1944 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
1945
1946 if (ptr1)
1947 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc1_rate),
1948 stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u, 1);
1949
1950 if (ptr2)
1951 stktable_data_cast(ptr2, gpc1)++;
1952
1953 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
1954
1955 /* If data was modified, we need to touch to re-schedule sync */
1956 stktable_touch_local(stkctr->table, ts, 0);
1957 }
1958 }
1959 return ACT_RET_CONT;
1960}
1961
1962/* This function is a common parser for using variables. It understands
1963 * the formats:
1964 *
1965 * sc-inc-gpc1(<stick-table ID>)
1966 *
1967 * It returns 0 if fails and <err> is filled with an error message. Otherwise,
1968 * it returns 1 and the variable <expr> is filled with the pointer to the
1969 * expression to execute.
1970 */
1971static enum act_parse_ret parse_inc_gpc1(const char **args, int *arg, struct proxy *px,
1972 struct act_rule *rule, char **err)
1973{
1974 const char *cmd_name = args[*arg-1];
1975 char *error;
1976
1977 cmd_name += strlen("sc-inc-gpc1");
1978 if (*cmd_name == '\0') {
1979 /* default stick table id. */
1980 rule->arg.gpc.sc = 0;
1981 } else {
1982 /* parse the stick table id. */
1983 if (*cmd_name != '(') {
1984 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
1985 return ACT_RET_PRS_ERR;
1986 }
1987 cmd_name++; /* jump the '(' */
1988 rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */
1989 if (*error != ')') {
1990 memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]);
1991 return ACT_RET_PRS_ERR;
1992 }
1993
1994 if (rule->arg.gpc.sc >= ACT_ACTION_TRK_SCMAX) {
1995 memprintf(err, "invalid stick table track ID. The max allowed ID is %d",
1996 ACT_ACTION_TRK_SCMAX-1);
1997 return ACT_RET_PRS_ERR;
1998 }
1999 }
2000 rule->action = ACT_CUSTOM;
2001 rule->action_ptr = action_inc_gpc1;
2002 return ACT_RET_PRS_OK;
2003}
2004
2005/* Always returns 1. */
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002006static enum act_return action_set_gpt0(struct act_rule *rule, struct proxy *px,
Willy Tarreau658b85b2015-09-27 10:00:49 +02002007 struct session *sess, struct stream *s, int flags)
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002008{
2009 void *ptr;
2010 struct stksess *ts;
2011 struct stkctr *stkctr;
2012
2013 /* Extract the stksess, return OK if no stksess available. */
2014 if (s)
2015 stkctr = &s->stkctr[rule->arg.gpt.sc];
2016 else
2017 stkctr = &sess->stkctr[rule->arg.gpt.sc];
Willy Tarreau79c1e912016-01-25 14:54:45 +01002018
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002019 ts = stkctr_entry(stkctr);
2020 if (!ts)
2021 return ACT_RET_CONT;
2022
2023 /* Store the sample in the required sc, and ignore errors. */
2024 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0);
Willy Tarreau79c1e912016-01-25 14:54:45 +01002025 if (ptr) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002026 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002027
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002028 stktable_data_cast(ptr, gpt0) = rule->arg.gpt.value;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002029
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002030 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002031
2032 stktable_touch_local(stkctr->table, ts, 0);
Willy Tarreau79c1e912016-01-25 14:54:45 +01002033 }
2034
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002035 return ACT_RET_CONT;
2036}
2037
2038/* This function is a common parser for using variables. It understands
2039 * the format:
2040 *
2041 * set-gpt0(<stick-table ID>) <expression>
2042 *
2043 * It returns 0 if fails and <err> is filled with an error message. Otherwise,
2044 * it returns 1 and the variable <expr> is filled with the pointer to the
2045 * expression to execute.
2046 */
2047static enum act_parse_ret parse_set_gpt0(const char **args, int *arg, struct proxy *px,
2048 struct act_rule *rule, char **err)
2049
2050
2051{
2052 const char *cmd_name = args[*arg-1];
2053 char *error;
2054
2055 cmd_name += strlen("sc-set-gpt0");
2056 if (*cmd_name == '\0') {
2057 /* default stick table id. */
2058 rule->arg.gpt.sc = 0;
2059 } else {
2060 /* parse the stick table id. */
2061 if (*cmd_name != '(') {
2062 memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]);
2063 return ACT_RET_PRS_ERR;
2064 }
2065 cmd_name++; /* jump the '(' */
2066 rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */
2067 if (*error != ')') {
2068 memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]);
2069 return ACT_RET_PRS_ERR;
2070 }
2071
2072 if (rule->arg.gpt.sc >= ACT_ACTION_TRK_SCMAX) {
2073 memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d",
2074 args[*arg-1], ACT_ACTION_TRK_SCMAX-1);
2075 return ACT_RET_PRS_ERR;
2076 }
2077 }
2078
2079 rule->arg.gpt.value = strtol(args[*arg], &error, 10);
2080 if (*error != '\0') {
2081 memprintf(err, "invalid integer value '%s'", args[*arg]);
2082 return ACT_RET_PRS_ERR;
2083 }
2084 (*arg)++;
2085
Thierry FOURNIER42148732015-09-02 17:17:33 +02002086 rule->action = ACT_CUSTOM;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002087 rule->action_ptr = action_set_gpt0;
2088
2089 return ACT_RET_PRS_OK;
2090}
2091
Willy Tarreau7d562212016-11-25 16:10:05 +01002092/* set temp integer to the number of used entries in the table pointed to by expr.
2093 * Accepts exactly 1 argument of type table.
2094 */
2095static int
2096smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2097{
2098 smp->flags = SMP_F_VOL_TEST;
2099 smp->data.type = SMP_T_SINT;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002100 smp->data.u.sint = args->data.t->current;
Willy Tarreau7d562212016-11-25 16:10:05 +01002101 return 1;
2102}
2103
2104/* set temp integer to the number of free entries in the table pointed to by expr.
2105 * Accepts exactly 1 argument of type table.
2106 */
2107static int
2108smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private)
2109{
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002110 struct stktable *t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002111
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002112 t = args->data.t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002113 smp->flags = SMP_F_VOL_TEST;
2114 smp->data.type = SMP_T_SINT;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002115 smp->data.u.sint = t->size - t->current;
Willy Tarreau7d562212016-11-25 16:10:05 +01002116 return 1;
2117}
2118
2119/* Returns a pointer to a stkctr depending on the fetch keyword name.
2120 * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively.
2121 * sc[0-9]_* will return a pointer to the respective field in the
2122 * stream <l4>. sc_* requires an UINT argument specifying the stick
2123 * counter number. src_* will fill a locally allocated structure with
2124 * the table and entry corresponding to what is specified with src_*.
2125 * NULL may be returned if the designated stkctr is not tracked. For
2126 * the sc_* and sc[0-9]_* forms, an optional table argument may be
2127 * passed. When present, the currently tracked key is then looked up
2128 * in the specified table instead of the current table. The purpose is
2129 * to be able to convery multiple values per key (eg: have gpc0 from
2130 * multiple tables). <strm> is allowed to be NULL, in which case only
2131 * the session will be consulted.
2132 */
2133struct stkctr *
Emeric Brun819fc6f2017-06-13 19:37:32 +02002134smp_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 +01002135{
Willy Tarreau7d562212016-11-25 16:10:05 +01002136 struct stkctr *stkptr;
2137 struct stksess *stksess;
2138 unsigned int num = kw[2] - '0';
2139 int arg = 0;
2140
2141 if (num == '_' - '0') {
2142 /* sc_* variant, args[0] = ctr# (mandatory) */
2143 num = args[arg++].data.sint;
2144 if (num >= MAX_SESS_STKCTR)
2145 return NULL;
2146 }
2147 else if (num > 9) { /* src_* variant, args[0] = table */
2148 struct stktable_key *key;
2149 struct connection *conn = objt_conn(sess->origin);
2150 struct sample smp;
2151
2152 if (!conn)
2153 return NULL;
2154
Joseph Herlant5662fa42018-11-15 13:43:28 -08002155 /* Fetch source address in a sample. */
Willy Tarreau7d562212016-11-25 16:10:05 +01002156 smp.px = NULL;
2157 smp.sess = sess;
2158 smp.strm = strm;
2159 if (!smp_fetch_src(NULL, &smp, NULL, NULL))
2160 return NULL;
2161
2162 /* Converts into key. */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002163 key = smp_to_stkey(&smp, args->data.t);
Willy Tarreau7d562212016-11-25 16:10:05 +01002164 if (!key)
2165 return NULL;
2166
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002167 stkctr->table = args->data.t;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002168 stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key));
2169 return stkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002170 }
2171
2172 /* Here, <num> contains the counter number from 0 to 9 for
2173 * the sc[0-9]_ form, or even higher using sc_(num) if needed.
2174 * args[arg] is the first optional argument. We first lookup the
2175 * ctr form the stream, then from the session if it was not there.
2176 */
2177
2178 if (strm)
2179 stkptr = &strm->stkctr[num];
2180 if (!strm || !stkctr_entry(stkptr)) {
2181 stkptr = &sess->stkctr[num];
2182 if (!stkctr_entry(stkptr))
2183 return NULL;
2184 }
2185
2186 stksess = stkctr_entry(stkptr);
2187 if (!stksess)
2188 return NULL;
2189
2190 if (unlikely(args[arg].type == ARGT_TAB)) {
2191 /* an alternate table was specified, let's look up the same key there */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002192 stkctr->table = args[arg].data.t;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002193 stkctr_set_entry(stkctr, stktable_lookup(stkctr->table, stksess));
2194 return stkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002195 }
2196 return stkptr;
2197}
2198
2199/* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create
2200 * the entry if it doesn't exist yet. This is needed for a few fetch
2201 * functions which need to create an entry, such as src_inc_gpc* and
2202 * src_clr_gpc*.
2203 */
2204struct stkctr *
Emeric Brun819fc6f2017-06-13 19:37:32 +02002205smp_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 +01002206{
Willy Tarreau7d562212016-11-25 16:10:05 +01002207 struct stktable_key *key;
2208 struct connection *conn = objt_conn(sess->origin);
2209 struct sample smp;
2210
2211 if (strncmp(kw, "src_", 4) != 0)
2212 return NULL;
2213
2214 if (!conn)
2215 return NULL;
2216
Joseph Herlant5662fa42018-11-15 13:43:28 -08002217 /* Fetch source address in a sample. */
Willy Tarreau7d562212016-11-25 16:10:05 +01002218 smp.px = NULL;
2219 smp.sess = sess;
2220 smp.strm = strm;
2221 if (!smp_fetch_src(NULL, &smp, NULL, NULL))
2222 return NULL;
2223
2224 /* Converts into key. */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002225 key = smp_to_stkey(&smp, args->data.t);
Willy Tarreau7d562212016-11-25 16:10:05 +01002226 if (!key)
2227 return NULL;
2228
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002229 stkctr->table = args->data.t;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002230 stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key));
2231 return stkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002232}
2233
2234/* set return a boolean indicating if the requested stream counter is
2235 * currently being tracked or not.
2236 * Supports being called as "sc[0-9]_tracked" only.
2237 */
2238static int
2239smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private)
2240{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002241 struct stkctr tmpstkctr;
2242 struct stkctr *stkctr;
2243
Willy Tarreau7d562212016-11-25 16:10:05 +01002244 smp->flags = SMP_F_VOL_TEST;
2245 smp->data.type = SMP_T_BOOL;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002246 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2247 smp->data.u.sint = !!stkctr;
2248
2249 /* release the ref count */
Dirkjan Bussinkff57f1b2018-09-14 14:31:22 +02002250 if (stkctr == &tmpstkctr)
Emeric Brun819fc6f2017-06-13 19:37:32 +02002251 stktable_release(stkctr->table, stkctr_entry(stkctr));
2252
Willy Tarreau7d562212016-11-25 16:10:05 +01002253 return 1;
2254}
2255
2256/* set <smp> to the General Purpose Flag 0 value from the stream's tracked
2257 * frontend counters or from the src.
2258 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value
2259 * zero is returned if the key is new.
2260 */
2261static int
2262smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2263{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002264 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002265 struct stkctr *stkctr;
2266
Emeric Brun819fc6f2017-06-13 19:37:32 +02002267 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002268 if (!stkctr)
2269 return 0;
2270
2271 smp->flags = SMP_F_VOL_TEST;
2272 smp->data.type = SMP_T_SINT;
2273 smp->data.u.sint = 0;
2274
Emeric Brun819fc6f2017-06-13 19:37:32 +02002275 if (stkctr_entry(stkctr)) {
2276 void *ptr;
2277
2278 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0);
2279 if (!ptr) {
2280 if (stkctr == &tmpstkctr)
2281 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002282 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002283 }
2284
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002285 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002286
Willy Tarreau7d562212016-11-25 16:10:05 +01002287 smp->data.u.sint = stktable_data_cast(ptr, gpt0);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002288
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002289 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002290
2291 if (stkctr == &tmpstkctr)
2292 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002293 }
2294 return 1;
2295}
2296
2297/* set <smp> to the General Purpose Counter 0 value from the stream's tracked
2298 * frontend counters or from the src.
2299 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value
2300 * zero is returned if the key is new.
2301 */
2302static int
2303smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2304{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002305 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002306 struct stkctr *stkctr;
2307
Emeric Brun819fc6f2017-06-13 19:37:32 +02002308 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002309 if (!stkctr)
2310 return 0;
2311
2312 smp->flags = SMP_F_VOL_TEST;
2313 smp->data.type = SMP_T_SINT;
2314 smp->data.u.sint = 0;
2315
2316 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002317 void *ptr;
2318
2319 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
2320 if (!ptr) {
2321 if (stkctr == &tmpstkctr)
2322 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002323 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002324 }
2325
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002326 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002327
Willy Tarreau7d562212016-11-25 16:10:05 +01002328 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002329
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002330 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002331
2332 if (stkctr == &tmpstkctr)
2333 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002334 }
2335 return 1;
2336}
2337
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002338/* set <smp> to the General Purpose Counter 1 value from the stream's tracked
2339 * frontend counters or from the src.
2340 * Supports being called as "sc[0-9]_get_gpc1" or "src_get_gpc1" only. Value
2341 * zero is returned if the key is new.
2342 */
2343static int
2344smp_fetch_sc_get_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private)
2345{
2346 struct stkctr tmpstkctr;
2347 struct stkctr *stkctr;
2348
2349 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2350 if (!stkctr)
2351 return 0;
2352
2353 smp->flags = SMP_F_VOL_TEST;
2354 smp->data.type = SMP_T_SINT;
2355 smp->data.u.sint = 0;
2356
2357 if (stkctr_entry(stkctr) != NULL) {
2358 void *ptr;
2359
2360 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1);
2361 if (!ptr) {
2362 if (stkctr == &tmpstkctr)
2363 stktable_release(stkctr->table, stkctr_entry(stkctr));
2364 return 0; /* parameter not stored */
2365 }
2366
2367 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2368
2369 smp->data.u.sint = stktable_data_cast(ptr, gpc1);
2370
2371 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2372
2373 if (stkctr == &tmpstkctr)
2374 stktable_release(stkctr->table, stkctr_entry(stkctr));
2375 }
2376 return 1;
2377}
2378
Willy Tarreau7d562212016-11-25 16:10:05 +01002379/* set <smp> to the General Purpose Counter 0's event rate from the stream's
2380 * tracked frontend counters or from the src.
2381 * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only.
2382 * Value zero is returned if the key is new.
2383 */
2384static int
2385smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2386{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002387 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002388 struct stkctr *stkctr;
2389
Emeric Brun819fc6f2017-06-13 19:37:32 +02002390 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002391 if (!stkctr)
2392 return 0;
2393
2394 smp->flags = SMP_F_VOL_TEST;
2395 smp->data.type = SMP_T_SINT;
2396 smp->data.u.sint = 0;
2397 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002398 void *ptr;
2399
2400 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
2401 if (!ptr) {
2402 if (stkctr == &tmpstkctr)
2403 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002404 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002405 }
2406
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002407 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002408
Willy Tarreau7d562212016-11-25 16:10:05 +01002409 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate),
2410 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002411
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002412 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002413
2414 if (stkctr == &tmpstkctr)
2415 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002416 }
2417 return 1;
2418}
2419
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002420/* set <smp> to the General Purpose Counter 1's event rate from the stream's
2421 * tracked frontend counters or from the src.
2422 * Supports being called as "sc[0-9]_gpc1_rate" or "src_gpc1_rate" only.
2423 * Value zero is returned if the key is new.
2424 */
2425static int
2426smp_fetch_sc_gpc1_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2427{
2428 struct stkctr tmpstkctr;
2429 struct stkctr *stkctr;
2430
2431 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2432 if (!stkctr)
2433 return 0;
2434
2435 smp->flags = SMP_F_VOL_TEST;
2436 smp->data.type = SMP_T_SINT;
2437 smp->data.u.sint = 0;
2438 if (stkctr_entry(stkctr) != NULL) {
2439 void *ptr;
2440
2441 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE);
2442 if (!ptr) {
2443 if (stkctr == &tmpstkctr)
2444 stktable_release(stkctr->table, stkctr_entry(stkctr));
2445 return 0; /* parameter not stored */
2446 }
2447
2448 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2449
2450 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc1_rate),
2451 stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u);
2452
2453 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2454
2455 if (stkctr == &tmpstkctr)
2456 stktable_release(stkctr->table, stkctr_entry(stkctr));
2457 }
2458 return 1;
2459}
2460
Willy Tarreau7d562212016-11-25 16:10:05 +01002461/* Increment the General Purpose Counter 0 value from the stream's tracked
2462 * frontend counters and return it into temp integer.
2463 * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only.
2464 */
2465static int
2466smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2467{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002468 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002469 struct stkctr *stkctr;
2470
Emeric Brun819fc6f2017-06-13 19:37:32 +02002471 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002472 if (!stkctr)
2473 return 0;
2474
2475 smp->flags = SMP_F_VOL_TEST;
2476 smp->data.type = SMP_T_SINT;
2477 smp->data.u.sint = 0;
2478
Emeric Brun819fc6f2017-06-13 19:37:32 +02002479 if (!stkctr_entry(stkctr))
2480 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002481
2482 if (stkctr && stkctr_entry(stkctr)) {
2483 void *ptr1,*ptr2;
2484
Emeric Brun819fc6f2017-06-13 19:37:32 +02002485
Willy Tarreau7d562212016-11-25 16:10:05 +01002486 /* First, update gpc0_rate if it's tracked. Second, update its
2487 * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr.
2488 */
2489 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
Willy Tarreau7d562212016-11-25 16:10:05 +01002490 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002491 if (ptr1 || ptr2) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002492 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Willy Tarreau7d562212016-11-25 16:10:05 +01002493
Emeric Brun819fc6f2017-06-13 19:37:32 +02002494 if (ptr1) {
2495 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate),
2496 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1);
2497 smp->data.u.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr;
2498 }
2499
2500 if (ptr2)
2501 smp->data.u.sint = ++stktable_data_cast(ptr2, gpc0);
2502
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002503 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002504
2505 /* If data was modified, we need to touch to re-schedule sync */
2506 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
2507 }
2508 else if (stkctr == &tmpstkctr)
2509 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002510 }
2511 return 1;
2512}
2513
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002514/* Increment the General Purpose Counter 1 value from the stream's tracked
2515 * frontend counters and return it into temp integer.
2516 * Supports being called as "sc[0-9]_inc_gpc1" or "src_inc_gpc1" only.
2517 */
2518static int
2519smp_fetch_sc_inc_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private)
2520{
2521 struct stkctr tmpstkctr;
2522 struct stkctr *stkctr;
2523
2524 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2525 if (!stkctr)
2526 return 0;
2527
2528 smp->flags = SMP_F_VOL_TEST;
2529 smp->data.type = SMP_T_SINT;
2530 smp->data.u.sint = 0;
2531
2532 if (!stkctr_entry(stkctr))
2533 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2534
2535 if (stkctr && stkctr_entry(stkctr)) {
2536 void *ptr1,*ptr2;
2537
2538
2539 /* First, update gpc1_rate if it's tracked. Second, update its
2540 * gpc1 if tracked. Returns gpc1's value otherwise the curr_ctr.
2541 */
2542 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE);
2543 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1);
2544 if (ptr1 || ptr2) {
2545 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2546
2547 if (ptr1) {
2548 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc1_rate),
2549 stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u, 1);
2550 smp->data.u.sint = (&stktable_data_cast(ptr1, gpc1_rate))->curr_ctr;
2551 }
2552
2553 if (ptr2)
2554 smp->data.u.sint = ++stktable_data_cast(ptr2, gpc1);
2555
2556 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2557
2558 /* If data was modified, we need to touch to re-schedule sync */
2559 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
2560 }
2561 else if (stkctr == &tmpstkctr)
2562 stktable_release(stkctr->table, stkctr_entry(stkctr));
2563 }
2564 return 1;
2565}
2566
Willy Tarreau7d562212016-11-25 16:10:05 +01002567/* Clear the General Purpose Counter 0 value from the stream's tracked
2568 * frontend counters and return its previous value into temp integer.
2569 * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only.
2570 */
2571static int
2572smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2573{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002574 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002575 struct stkctr *stkctr;
2576
Emeric Brun819fc6f2017-06-13 19:37:32 +02002577 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002578 if (!stkctr)
2579 return 0;
2580
2581 smp->flags = SMP_F_VOL_TEST;
2582 smp->data.type = SMP_T_SINT;
2583 smp->data.u.sint = 0;
2584
Emeric Brun819fc6f2017-06-13 19:37:32 +02002585 if (!stkctr_entry(stkctr))
2586 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002587
Emeric Brun819fc6f2017-06-13 19:37:32 +02002588 if (stkctr && stkctr_entry(stkctr)) {
2589 void *ptr;
2590
2591 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
2592 if (!ptr) {
2593 if (stkctr == &tmpstkctr)
2594 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002595 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002596 }
2597
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002598 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002599
Willy Tarreau7d562212016-11-25 16:10:05 +01002600 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
2601 stktable_data_cast(ptr, gpc0) = 0;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002602
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002603 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002604
Willy Tarreau7d562212016-11-25 16:10:05 +01002605 /* If data was modified, we need to touch to re-schedule sync */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002606 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
Willy Tarreau7d562212016-11-25 16:10:05 +01002607 }
2608 return 1;
2609}
2610
Frédéric Lécaille6778b272018-01-29 15:22:53 +01002611/* Clear the General Purpose Counter 1 value from the stream's tracked
2612 * frontend counters and return its previous value into temp integer.
2613 * Supports being called as "sc[0-9]_clr_gpc1" or "src_clr_gpc1" only.
2614 */
2615static int
2616smp_fetch_sc_clr_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private)
2617{
2618 struct stkctr tmpstkctr;
2619 struct stkctr *stkctr;
2620
2621 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2622 if (!stkctr)
2623 return 0;
2624
2625 smp->flags = SMP_F_VOL_TEST;
2626 smp->data.type = SMP_T_SINT;
2627 smp->data.u.sint = 0;
2628
2629 if (!stkctr_entry(stkctr))
2630 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
2631
2632 if (stkctr && stkctr_entry(stkctr)) {
2633 void *ptr;
2634
2635 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1);
2636 if (!ptr) {
2637 if (stkctr == &tmpstkctr)
2638 stktable_release(stkctr->table, stkctr_entry(stkctr));
2639 return 0; /* parameter not stored */
2640 }
2641
2642 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2643
2644 smp->data.u.sint = stktable_data_cast(ptr, gpc1);
2645 stktable_data_cast(ptr, gpc1) = 0;
2646
2647 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
2648
2649 /* If data was modified, we need to touch to re-schedule sync */
2650 stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0);
2651 }
2652 return 1;
2653}
2654
Willy Tarreau7d562212016-11-25 16:10:05 +01002655/* set <smp> to the cumulated number of connections from the stream's tracked
2656 * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or
2657 * "src_conn_cnt" only.
2658 */
2659static int
2660smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2661{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002662 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002663 struct stkctr *stkctr;
2664
Emeric Brun819fc6f2017-06-13 19:37:32 +02002665 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002666 if (!stkctr)
2667 return 0;
2668
2669 smp->flags = SMP_F_VOL_TEST;
2670 smp->data.type = SMP_T_SINT;
2671 smp->data.u.sint = 0;
2672 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002673 void *ptr;
2674
2675 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT);
2676 if (!ptr) {
2677 if (stkctr == &tmpstkctr)
2678 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002679 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002680 }
2681
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002682 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002683
Willy Tarreau7d562212016-11-25 16:10:05 +01002684 smp->data.u.sint = stktable_data_cast(ptr, conn_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002685
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002686 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002687
2688 if (stkctr == &tmpstkctr)
2689 stktable_release(stkctr->table, stkctr_entry(stkctr));
2690
2691
Willy Tarreau7d562212016-11-25 16:10:05 +01002692 }
2693 return 1;
2694}
2695
2696/* set <smp> to the connection rate from the stream's tracked frontend
2697 * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate"
2698 * only.
2699 */
2700static int
2701smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2702{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002703 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002704 struct stkctr *stkctr;
2705
Emeric Brun819fc6f2017-06-13 19:37:32 +02002706 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002707 if (!stkctr)
2708 return 0;
2709
2710 smp->flags = SMP_F_VOL_TEST;
2711 smp->data.type = SMP_T_SINT;
2712 smp->data.u.sint = 0;
2713 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002714 void *ptr;
2715
2716 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE);
2717 if (!ptr) {
2718 if (stkctr == &tmpstkctr)
2719 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002720 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002721 }
2722
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002723 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002724
Willy Tarreau7d562212016-11-25 16:10:05 +01002725 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
2726 stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002727
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002728 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002729
2730 if (stkctr == &tmpstkctr)
2731 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002732 }
2733 return 1;
2734}
2735
2736/* set temp integer to the number of connections from the stream's source address
2737 * in the table pointed to by expr, after updating it.
2738 * Accepts exactly 1 argument of type table.
2739 */
2740static int
2741smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2742{
2743 struct connection *conn = objt_conn(smp->sess->origin);
2744 struct stksess *ts;
2745 struct stktable_key *key;
2746 void *ptr;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002747 struct stktable *t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002748
2749 if (!conn)
2750 return 0;
2751
Joseph Herlant5662fa42018-11-15 13:43:28 -08002752 /* Fetch source address in a sample. */
Willy Tarreau7d562212016-11-25 16:10:05 +01002753 if (!smp_fetch_src(NULL, smp, NULL, NULL))
2754 return 0;
2755
2756 /* Converts into key. */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002757 key = smp_to_stkey(smp, args->data.t);
Willy Tarreau7d562212016-11-25 16:10:05 +01002758 if (!key)
2759 return 0;
2760
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002761 t = args->data.t;
Willy Tarreau7d562212016-11-25 16:10:05 +01002762
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002763 if ((ts = stktable_get_entry(t, key)) == NULL)
Willy Tarreau7d562212016-11-25 16:10:05 +01002764 /* entry does not exist and could not be created */
2765 return 0;
2766
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002767 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002768 if (!ptr) {
Willy Tarreau7d562212016-11-25 16:10:05 +01002769 return 0; /* parameter not stored in this table */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002770 }
Willy Tarreau7d562212016-11-25 16:10:05 +01002771
2772 smp->data.type = SMP_T_SINT;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002773
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002774 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002775
Willy Tarreau7d562212016-11-25 16:10:05 +01002776 smp->data.u.sint = ++stktable_data_cast(ptr, conn_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002777
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002778 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002779
Willy Tarreau7d562212016-11-25 16:10:05 +01002780 smp->flags = SMP_F_VOL_TEST;
Emeric Brun819fc6f2017-06-13 19:37:32 +02002781
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01002782 stktable_touch_local(t, ts, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002783
2784 /* Touch was previously performed by stktable_update_key */
Willy Tarreau7d562212016-11-25 16:10:05 +01002785 return 1;
2786}
2787
2788/* set <smp> to the number of concurrent connections from the stream's tracked
2789 * frontend counters. Supports being called as "sc[0-9]_conn_cur" or
2790 * "src_conn_cur" only.
2791 */
2792static int
2793smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private)
2794{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002795 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002796 struct stkctr *stkctr;
2797
Emeric Brun819fc6f2017-06-13 19:37:32 +02002798 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002799 if (!stkctr)
2800 return 0;
2801
2802 smp->flags = SMP_F_VOL_TEST;
2803 smp->data.type = SMP_T_SINT;
2804 smp->data.u.sint = 0;
2805 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002806 void *ptr;
2807
2808 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR);
2809 if (!ptr) {
2810 if (stkctr == &tmpstkctr)
2811 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002812 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002813 }
2814
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002815 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002816
Willy Tarreau7d562212016-11-25 16:10:05 +01002817 smp->data.u.sint = stktable_data_cast(ptr, conn_cur);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002818
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002819 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002820
2821 if (stkctr == &tmpstkctr)
2822 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002823 }
2824 return 1;
2825}
2826
2827/* set <smp> to the cumulated number of streams from the stream's tracked
2828 * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or
2829 * "src_sess_cnt" only.
2830 */
2831static int
2832smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2833{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002834 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002835 struct stkctr *stkctr;
2836
Emeric Brun819fc6f2017-06-13 19:37:32 +02002837 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002838 if (!stkctr)
2839 return 0;
2840
2841 smp->flags = SMP_F_VOL_TEST;
2842 smp->data.type = SMP_T_SINT;
2843 smp->data.u.sint = 0;
2844 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002845 void *ptr;
2846
2847 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT);
2848 if (!ptr) {
2849 if (stkctr == &tmpstkctr)
2850 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002851 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002852 }
2853
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002854 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002855
Willy Tarreau7d562212016-11-25 16:10:05 +01002856 smp->data.u.sint = stktable_data_cast(ptr, sess_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002857
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002858 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002859
2860 if (stkctr == &tmpstkctr)
2861 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002862 }
2863 return 1;
2864}
2865
2866/* set <smp> to the stream rate from the stream's tracked frontend counters.
2867 * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only.
2868 */
2869static int
2870smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2871{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002872 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002873 struct stkctr *stkctr;
2874
Emeric Brun819fc6f2017-06-13 19:37:32 +02002875 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002876 if (!stkctr)
2877 return 0;
2878
2879 smp->flags = SMP_F_VOL_TEST;
2880 smp->data.type = SMP_T_SINT;
2881 smp->data.u.sint = 0;
2882 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002883 void *ptr;
2884
2885 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE);
2886 if (!ptr) {
2887 if (stkctr == &tmpstkctr)
2888 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002889 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002890 }
2891
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002892 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002893
Willy Tarreau7d562212016-11-25 16:10:05 +01002894 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
2895 stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002896
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002897 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002898
2899 if (stkctr == &tmpstkctr)
2900 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002901 }
2902 return 1;
2903}
2904
2905/* set <smp> to the cumulated number of HTTP requests from the stream's tracked
2906 * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or
2907 * "src_http_req_cnt" only.
2908 */
2909static int
2910smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2911{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002912 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002913 struct stkctr *stkctr;
2914
Emeric Brun819fc6f2017-06-13 19:37:32 +02002915 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002916 if (!stkctr)
2917 return 0;
2918
2919 smp->flags = SMP_F_VOL_TEST;
2920 smp->data.type = SMP_T_SINT;
2921 smp->data.u.sint = 0;
2922 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002923 void *ptr;
2924
2925 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT);
2926 if (!ptr) {
2927 if (stkctr == &tmpstkctr)
2928 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002929 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002930 }
2931
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002932 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002933
Willy Tarreau7d562212016-11-25 16:10:05 +01002934 smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002935
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002936 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002937
2938 if (stkctr == &tmpstkctr)
2939 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002940 }
2941 return 1;
2942}
2943
2944/* set <smp> to the HTTP request rate from the stream's tracked frontend
2945 * counters. Supports being called as "sc[0-9]_http_req_rate" or
2946 * "src_http_req_rate" only.
2947 */
2948static int
2949smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
2950{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002951 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002952 struct stkctr *stkctr;
2953
Emeric Brun819fc6f2017-06-13 19:37:32 +02002954 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002955 if (!stkctr)
2956 return 0;
2957
2958 smp->flags = SMP_F_VOL_TEST;
2959 smp->data.type = SMP_T_SINT;
2960 smp->data.u.sint = 0;
2961 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02002962 void *ptr;
2963
2964 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE);
2965 if (!ptr) {
2966 if (stkctr == &tmpstkctr)
2967 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002968 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02002969 }
2970
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002971 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002972
Willy Tarreau7d562212016-11-25 16:10:05 +01002973 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
2974 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002975
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002976 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02002977
2978 if (stkctr == &tmpstkctr)
2979 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01002980 }
2981 return 1;
2982}
2983
2984/* set <smp> to the cumulated number of HTTP requests errors from the stream's
2985 * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or
2986 * "src_http_err_cnt" only.
2987 */
2988static int
2989smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
2990{
Emeric Brun819fc6f2017-06-13 19:37:32 +02002991 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01002992 struct stkctr *stkctr;
2993
Emeric Brun819fc6f2017-06-13 19:37:32 +02002994 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01002995 if (!stkctr)
2996 return 0;
2997
2998 smp->flags = SMP_F_VOL_TEST;
2999 smp->data.type = SMP_T_SINT;
3000 smp->data.u.sint = 0;
3001 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003002 void *ptr;
3003
3004 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT);
3005 if (!ptr) {
3006 if (stkctr == &tmpstkctr)
3007 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003008 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003009 }
3010
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003011 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003012
Willy Tarreau7d562212016-11-25 16:10:05 +01003013 smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003014
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003015 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003016
3017 if (stkctr == &tmpstkctr)
3018 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003019 }
3020 return 1;
3021}
3022
3023/* set <smp> to the HTTP request error rate from the stream's tracked frontend
3024 * counters. Supports being called as "sc[0-9]_http_err_rate" or
3025 * "src_http_err_rate" only.
3026 */
3027static int
3028smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3029{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003030 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003031 struct stkctr *stkctr;
3032
Emeric Brun819fc6f2017-06-13 19:37:32 +02003033 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003034 if (!stkctr)
3035 return 0;
3036
3037 smp->flags = SMP_F_VOL_TEST;
3038 smp->data.type = SMP_T_SINT;
3039 smp->data.u.sint = 0;
3040 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003041 void *ptr;
3042
3043 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE);
3044 if (!ptr) {
3045 if (stkctr == &tmpstkctr)
3046 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003047 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003048 }
3049
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003050 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003051
Willy Tarreau7d562212016-11-25 16:10:05 +01003052 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
3053 stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003054
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003055 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003056
3057 if (stkctr == &tmpstkctr)
3058 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003059 }
3060 return 1;
3061}
3062
3063/* set <smp> to the number of kbytes received from clients, as found in the
3064 * stream's tracked frontend counters. Supports being called as
3065 * "sc[0-9]_kbytes_in" or "src_kbytes_in" only.
3066 */
3067static int
3068smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private)
3069{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003070 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003071 struct stkctr *stkctr;
3072
Emeric Brun819fc6f2017-06-13 19:37:32 +02003073 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003074 if (!stkctr)
3075 return 0;
3076
3077 smp->flags = SMP_F_VOL_TEST;
3078 smp->data.type = SMP_T_SINT;
3079 smp->data.u.sint = 0;
3080 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003081 void *ptr;
3082
3083 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT);
3084 if (!ptr) {
3085 if (stkctr == &tmpstkctr)
3086 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003087 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003088 }
3089
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003090 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003091
Willy Tarreau7d562212016-11-25 16:10:05 +01003092 smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003093
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003094 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003095
3096 if (stkctr == &tmpstkctr)
3097 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003098 }
3099 return 1;
3100}
3101
3102/* set <smp> to the data rate received from clients in bytes/s, as found
3103 * in the stream's tracked frontend counters. Supports being called as
3104 * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only.
3105 */
3106static int
3107smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3108{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003109 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003110 struct stkctr *stkctr;
3111
Emeric Brun819fc6f2017-06-13 19:37:32 +02003112 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003113 if (!stkctr)
3114 return 0;
3115
3116 smp->flags = SMP_F_VOL_TEST;
3117 smp->data.type = SMP_T_SINT;
3118 smp->data.u.sint = 0;
3119 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003120 void *ptr;
3121
3122 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE);
3123 if (!ptr) {
3124 if (stkctr == &tmpstkctr)
3125 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003126 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003127 }
3128
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003129 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003130
Willy Tarreau7d562212016-11-25 16:10:05 +01003131 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
3132 stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003133
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003134 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003135
3136 if (stkctr == &tmpstkctr)
3137 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003138 }
3139 return 1;
3140}
3141
3142/* set <smp> to the number of kbytes sent to clients, as found in the
3143 * stream's tracked frontend counters. Supports being called as
3144 * "sc[0-9]_kbytes_out" or "src_kbytes_out" only.
3145 */
3146static int
3147smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private)
3148{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003149 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003150 struct stkctr *stkctr;
3151
Emeric Brun819fc6f2017-06-13 19:37:32 +02003152 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003153 if (!stkctr)
3154 return 0;
3155
3156 smp->flags = SMP_F_VOL_TEST;
3157 smp->data.type = SMP_T_SINT;
3158 smp->data.u.sint = 0;
3159 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003160 void *ptr;
3161
3162 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT);
3163 if (!ptr) {
3164 if (stkctr == &tmpstkctr)
3165 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003166 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003167 }
3168
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003169 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003170
Willy Tarreau7d562212016-11-25 16:10:05 +01003171 smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003172
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003173 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003174
3175 if (stkctr == &tmpstkctr)
3176 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003177 }
3178 return 1;
3179}
3180
3181/* set <smp> to the data rate sent to clients in bytes/s, as found in the
3182 * stream's tracked frontend counters. Supports being called as
3183 * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only.
3184 */
3185static int
3186smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
3187{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003188 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003189 struct stkctr *stkctr;
3190
Emeric Brun819fc6f2017-06-13 19:37:32 +02003191 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003192 if (!stkctr)
3193 return 0;
3194
3195 smp->flags = SMP_F_VOL_TEST;
3196 smp->data.type = SMP_T_SINT;
3197 smp->data.u.sint = 0;
3198 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun819fc6f2017-06-13 19:37:32 +02003199 void *ptr;
3200
3201 ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE);
3202 if (!ptr) {
3203 if (stkctr == &tmpstkctr)
3204 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003205 return 0; /* parameter not stored */
Emeric Brun819fc6f2017-06-13 19:37:32 +02003206 }
3207
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003208 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003209
Willy Tarreau7d562212016-11-25 16:10:05 +01003210 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
3211 stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003212
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003213 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003214
3215 if (stkctr == &tmpstkctr)
3216 stktable_release(stkctr->table, stkctr_entry(stkctr));
Willy Tarreau7d562212016-11-25 16:10:05 +01003217 }
3218 return 1;
3219}
3220
3221/* set <smp> to the number of active trackers on the SC entry in the stream's
3222 * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only.
3223 */
3224static int
3225smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private)
3226{
Emeric Brun819fc6f2017-06-13 19:37:32 +02003227 struct stkctr tmpstkctr;
Willy Tarreau7d562212016-11-25 16:10:05 +01003228 struct stkctr *stkctr;
3229
Emeric Brun819fc6f2017-06-13 19:37:32 +02003230 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
Willy Tarreau7d562212016-11-25 16:10:05 +01003231 if (!stkctr)
3232 return 0;
3233
3234 smp->flags = SMP_F_VOL_TEST;
3235 smp->data.type = SMP_T_SINT;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003236 if (stkctr == &tmpstkctr) {
3237 smp->data.u.sint = stkctr_entry(stkctr) ? (stkctr_entry(stkctr)->ref_cnt-1) : 0;
3238 stktable_release(stkctr->table, stkctr_entry(stkctr));
3239 }
3240 else {
3241 smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0;
3242 }
3243
Willy Tarreau7d562212016-11-25 16:10:05 +01003244 return 1;
3245}
3246
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003247
3248/* The functions below are used to manipulate table contents from the CLI.
3249 * There are 3 main actions, "clear", "set" and "show". The code is shared
3250 * between all actions, and the action is encoded in the void *private in
3251 * the appctx as well as in the keyword registration, among one of the
3252 * following values.
3253 */
3254
3255enum {
3256 STK_CLI_ACT_CLR,
3257 STK_CLI_ACT_SET,
3258 STK_CLI_ACT_SHOW,
3259};
3260
3261/* Dump the status of a table to a stream interface's
3262 * read buffer. It returns 0 if the output buffer is full
3263 * and needs to be called again, otherwise non-zero.
3264 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003265static int table_dump_head_to_buffer(struct buffer *msg,
3266 struct stream_interface *si,
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003267 struct stktable *t, struct stktable *target)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003268{
3269 struct stream *s = si_strm(si);
3270
3271 chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003272 t->id, stktable_types[t->type].kw, t->size, t->current);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003273
3274 /* any other information should be dumped here */
3275
William Lallemand07a62f72017-05-24 00:57:40 +02003276 if (target && (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) < ACCESS_LVL_OPER)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003277 chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n");
3278
Willy Tarreau06d80a92017-10-19 14:32:15 +02003279 if (ci_putchk(si_ic(si), msg) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003280 si_rx_room_blk(si);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003281 return 0;
3282 }
3283
3284 return 1;
3285}
3286
3287/* Dump a table entry to a stream interface's
3288 * read buffer. It returns 0 if the output buffer is full
3289 * and needs to be called again, otherwise non-zero.
3290 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003291static int table_dump_entry_to_buffer(struct buffer *msg,
3292 struct stream_interface *si,
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003293 struct stktable *t, struct stksess *entry)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003294{
3295 int dt;
3296
3297 chunk_appendf(msg, "%p:", entry);
3298
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003299 if (t->type == SMP_T_IPV4) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003300 char addr[INET_ADDRSTRLEN];
3301 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
3302 chunk_appendf(msg, " key=%s", addr);
3303 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003304 else if (t->type == SMP_T_IPV6) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003305 char addr[INET6_ADDRSTRLEN];
3306 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
3307 chunk_appendf(msg, " key=%s", addr);
3308 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003309 else if (t->type == SMP_T_SINT) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003310 chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key);
3311 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003312 else if (t->type == SMP_T_STR) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003313 chunk_appendf(msg, " key=");
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003314 dump_text(msg, (const char *)entry->key.key, t->key_size);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003315 }
3316 else {
3317 chunk_appendf(msg, " key=");
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003318 dump_binary(msg, (const char *)entry->key.key, t->key_size);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003319 }
3320
3321 chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
3322
3323 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
3324 void *ptr;
3325
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003326 if (t->data_ofs[dt] == 0)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003327 continue;
3328 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003329 chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, t->data_arg[dt].u);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003330 else
3331 chunk_appendf(msg, " %s=", stktable_data_types[dt].name);
3332
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003333 ptr = stktable_data_ptr(t, entry, dt);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003334 switch (stktable_data_types[dt].std_type) {
3335 case STD_T_SINT:
3336 chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
3337 break;
3338 case STD_T_UINT:
3339 chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
3340 break;
3341 case STD_T_ULL:
3342 chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull));
3343 break;
3344 case STD_T_FRQP:
3345 chunk_appendf(msg, "%d",
3346 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003347 t->data_arg[dt].u));
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003348 break;
3349 }
3350 }
3351 chunk_appendf(msg, "\n");
3352
Willy Tarreau06d80a92017-10-19 14:32:15 +02003353 if (ci_putchk(si_ic(si), msg) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003354 si_rx_room_blk(si);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003355 return 0;
3356 }
3357
3358 return 1;
3359}
3360
3361
3362/* Processes a single table entry matching a specific key passed in argument.
3363 * returns 0 if wants to be called again, 1 if has ended processing.
3364 */
3365static int table_process_entry_per_key(struct appctx *appctx, char **args)
3366{
3367 struct stream_interface *si = appctx->owner;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003368 struct stktable *t = appctx->ctx.table.target;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003369 struct stksess *ts;
3370 uint32_t uint32_key;
3371 unsigned char ip6_key[sizeof(struct in6_addr)];
3372 long long value;
3373 int data_type;
3374 int cur_arg;
3375 void *ptr;
3376 struct freq_ctr_period *frqp;
3377
3378 if (!*args[4]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003379 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003380 appctx->ctx.cli.msg = "Key value expected\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003381 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003382 return 1;
3383 }
3384
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003385 switch (t->type) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003386 case SMP_T_IPV4:
3387 uint32_key = htonl(inetaddr_host(args[4]));
Christopher Fauletca20d022017-08-29 15:30:31 +02003388 static_table_key.key = &uint32_key;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003389 break;
3390 case SMP_T_IPV6:
3391 inet_pton(AF_INET6, args[4], ip6_key);
Christopher Fauletca20d022017-08-29 15:30:31 +02003392 static_table_key.key = &ip6_key;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003393 break;
3394 case SMP_T_SINT:
3395 {
3396 char *endptr;
3397 unsigned long val;
3398 errno = 0;
3399 val = strtoul(args[4], &endptr, 10);
3400 if ((errno == ERANGE && val == ULONG_MAX) ||
3401 (errno != 0 && val == 0) || endptr == args[4] ||
3402 val > 0xffffffff) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003403 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003404 appctx->ctx.cli.msg = "Invalid key\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003405 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003406 return 1;
3407 }
3408 uint32_key = (uint32_t) val;
Christopher Fauletca20d022017-08-29 15:30:31 +02003409 static_table_key.key = &uint32_key;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003410 break;
3411 }
3412 break;
3413 case SMP_T_STR:
Christopher Fauletca20d022017-08-29 15:30:31 +02003414 static_table_key.key = args[4];
3415 static_table_key.key_len = strlen(args[4]);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003416 break;
3417 default:
Willy Tarreaua24bc782016-12-14 15:50:35 +01003418 switch (appctx->ctx.table.action) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003419 case STK_CLI_ACT_SHOW:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003420 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003421 appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
3422 break;
3423 case STK_CLI_ACT_CLR:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003424 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003425 appctx->ctx.cli.msg = "Removing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
3426 break;
3427 case STK_CLI_ACT_SET:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003428 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003429 appctx->ctx.cli.msg = "Inserting keys into tables of type other than ip, ipv6, string and integer is not supported\n";
3430 break;
3431 default:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003432 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003433 appctx->ctx.cli.msg = "Unknown action\n";
3434 break;
3435 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003436 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003437 return 1;
3438 }
3439
3440 /* check permissions */
3441 if (!cli_has_level(appctx, ACCESS_LVL_OPER))
3442 return 1;
3443
Willy Tarreaua24bc782016-12-14 15:50:35 +01003444 switch (appctx->ctx.table.action) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003445 case STK_CLI_ACT_SHOW:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003446 ts = stktable_lookup_key(t, &static_table_key);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003447 if (!ts)
3448 return 1;
3449 chunk_reset(&trash);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003450 if (!table_dump_head_to_buffer(&trash, si, t, t)) {
3451 stktable_release(t, ts);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003452 return 0;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003453 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003454 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003455 if (!table_dump_entry_to_buffer(&trash, si, t, ts)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003456 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003457 stktable_release(t, ts);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003458 return 0;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003459 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003460 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003461 stktable_release(t, ts);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003462 break;
3463
3464 case STK_CLI_ACT_CLR:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003465 ts = stktable_lookup_key(t, &static_table_key);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003466 if (!ts)
3467 return 1;
Emeric Brun819fc6f2017-06-13 19:37:32 +02003468
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003469 if (!stksess_kill(t, ts, 1)) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003470 /* don't delete an entry which is currently referenced */
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003471 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003472 appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003473 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003474 return 1;
3475 }
Emeric Brun819fc6f2017-06-13 19:37:32 +02003476
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003477 break;
3478
3479 case STK_CLI_ACT_SET:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003480 ts = stktable_get_entry(t, &static_table_key);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003481 if (!ts) {
3482 /* don't delete an entry which is currently referenced */
3483 appctx->ctx.cli.severity = LOG_ERR;
3484 appctx->ctx.cli.msg = "Unable to allocate a new entry\n";
3485 appctx->st0 = CLI_ST_PRINT;
3486 return 1;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003487 }
3488
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003489 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003490 for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) {
3491 if (strncmp(args[cur_arg], "data.", 5) != 0) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003492 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003493 appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003494 appctx->st0 = CLI_ST_PRINT;
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003495 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003496 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003497 return 1;
3498 }
3499
3500 data_type = stktable_get_data_type(args[cur_arg] + 5);
3501 if (data_type < 0) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003502 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003503 appctx->ctx.cli.msg = "Unknown data type\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003504 appctx->st0 = CLI_ST_PRINT;
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003505 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003506 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003507 return 1;
3508 }
3509
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003510 if (!t->data_ofs[data_type]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003511 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003512 appctx->ctx.cli.msg = "Data type not stored in this table\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003513 appctx->st0 = CLI_ST_PRINT;
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003514 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003515 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003516 return 1;
3517 }
3518
3519 if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003520 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003521 appctx->ctx.cli.msg = "Require a valid integer value to store\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003522 appctx->st0 = CLI_ST_PRINT;
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003523 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003524 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003525 return 1;
3526 }
3527
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003528 ptr = stktable_data_ptr(t, ts, data_type);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003529
3530 switch (stktable_data_types[data_type].std_type) {
3531 case STD_T_SINT:
3532 stktable_data_cast(ptr, std_t_sint) = value;
3533 break;
3534 case STD_T_UINT:
3535 stktable_data_cast(ptr, std_t_uint) = value;
3536 break;
3537 case STD_T_ULL:
3538 stktable_data_cast(ptr, std_t_ull) = value;
3539 break;
3540 case STD_T_FRQP:
3541 /* We set both the current and previous values. That way
3542 * the reported frequency is stable during all the period
3543 * then slowly fades out. This allows external tools to
3544 * push measures without having to update them too often.
3545 */
3546 frqp = &stktable_data_cast(ptr, std_t_frqp);
Emeric Brunf2fc1fd2017-11-02 17:32:43 +01003547 /* First bit is reserved for the freq_ctr_period lock
3548 Note: here we're still protected by the stksess lock
3549 so we don't need to update the update the freq_ctr_period
3550 using its internal lock */
3551 frqp->curr_tick = now_ms & ~0x1;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003552 frqp->prev_ctr = 0;
3553 frqp->curr_ctr = value;
3554 break;
3555 }
3556 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003557 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003558 stktable_touch_local(t, ts, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003559 break;
3560
3561 default:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003562 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003563 appctx->ctx.cli.msg = "Unknown action\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003564 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003565 break;
3566 }
3567 return 1;
3568}
3569
3570/* Prepares the appctx fields with the data-based filters from the command line.
3571 * Returns 0 if the dump can proceed, 1 if has ended processing.
3572 */
3573static int table_prepare_data_request(struct appctx *appctx, char **args)
3574{
Willy Tarreaua24bc782016-12-14 15:50:35 +01003575 if (appctx->ctx.table.action != STK_CLI_ACT_SHOW && appctx->ctx.table.action != STK_CLI_ACT_CLR) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003576 appctx->ctx.cli.severity = LOG_ERR;
Aurélien Nephtali6e8a41d2018-03-15 21:48:50 +01003577 appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003578 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003579 return 1;
3580 }
3581
3582 /* condition on stored data value */
3583 appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5);
3584 if (appctx->ctx.table.data_type < 0) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003585 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003586 appctx->ctx.cli.msg = "Unknown data type\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003587 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003588 return 1;
3589 }
3590
Dragan Dosen7d61a332019-05-07 14:16:18 +02003591 if (!((struct proxy *)appctx->ctx.table.target)->table ||
3592 !((struct proxy *)appctx->ctx.table.target)->table->data_ofs[appctx->ctx.table.data_type]) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003593 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003594 appctx->ctx.cli.msg = "Data type not stored in this table\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003595 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003596 return 1;
3597 }
3598
3599 appctx->ctx.table.data_op = get_std_op(args[4]);
3600 if (appctx->ctx.table.data_op < 0) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003601 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003602 appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003603 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003604 return 1;
3605 }
3606
3607 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003608 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003609 appctx->ctx.cli.msg = "Require a valid integer value to compare against\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003610 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003611 return 1;
3612 }
3613
3614 /* OK we're done, all the fields are set */
3615 return 0;
3616}
3617
3618/* returns 0 if wants to be called, 1 if has ended processing */
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003619static int cli_parse_table_req(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003620{
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003621 appctx->ctx.table.data_type = -1;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003622 appctx->ctx.table.target = NULL;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003623 appctx->ctx.table.entry = NULL;
Willy Tarreaua24bc782016-12-14 15:50:35 +01003624 appctx->ctx.table.action = (long)private; // keyword argument, one of STK_CLI_ACT_*
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003625
3626 if (*args[2]) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003627 appctx->ctx.table.target = stktable_find_by_name(args[2]);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003628 if (!appctx->ctx.table.target) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003629 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003630 appctx->ctx.cli.msg = "No such table\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003631 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003632 return 1;
3633 }
3634 }
3635 else {
Willy Tarreaua24bc782016-12-14 15:50:35 +01003636 if (appctx->ctx.table.action != STK_CLI_ACT_SHOW)
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003637 goto err_args;
3638 return 0;
3639 }
3640
3641 if (strcmp(args[3], "key") == 0)
3642 return table_process_entry_per_key(appctx, args);
3643 else if (strncmp(args[3], "data.", 5) == 0)
3644 return table_prepare_data_request(appctx, args);
3645 else if (*args[3])
3646 goto err_args;
3647
3648 return 0;
3649
3650err_args:
Willy Tarreaua24bc782016-12-14 15:50:35 +01003651 switch (appctx->ctx.table.action) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003652 case STK_CLI_ACT_SHOW:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003653 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003654 appctx->ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
3655 break;
3656 case STK_CLI_ACT_CLR:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003657 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003658 appctx->ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n";
3659 break;
3660 case STK_CLI_ACT_SET:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003661 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003662 appctx->ctx.cli.msg = "Required arguments: <table> key <key> [data.<store_data_type> <value>]*\n";
3663 break;
3664 default:
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003665 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003666 appctx->ctx.cli.msg = "Unknown action\n";
3667 break;
3668 }
Willy Tarreau3b6e5472016-11-24 15:53:53 +01003669 appctx->st0 = CLI_ST_PRINT;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003670 return 1;
3671}
3672
3673/* This function is used to deal with table operations (dump or clear depending
3674 * on the action stored in appctx->private). It returns 0 if the output buffer is
3675 * full and it needs to be called again, otherwise non-zero.
3676 */
3677static int cli_io_handler_table(struct appctx *appctx)
3678{
3679 struct stream_interface *si = appctx->owner;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003680 struct stream *s = si_strm(si);
3681 struct ebmb_node *eb;
3682 int dt;
3683 int skip_entry;
Willy Tarreaua24bc782016-12-14 15:50:35 +01003684 int show = appctx->ctx.table.action == STK_CLI_ACT_SHOW;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003685
3686 /*
3687 * We have 3 possible states in appctx->st2 :
3688 * - STAT_ST_INIT : the first call
3689 * - STAT_ST_INFO : the proxy pointer points to the next table to
3690 * dump, the entry pointer is NULL ;
3691 * - STAT_ST_LIST : the proxy pointer points to the current table
3692 * and the entry pointer points to the next entry to be dumped,
3693 * and the refcount on the next entry is held ;
3694 * - STAT_ST_END : nothing left to dump, the buffer may contain some
3695 * data though.
3696 */
3697
3698 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
3699 /* in case of abort, remove any refcount we might have set on an entry */
3700 if (appctx->st2 == STAT_ST_LIST) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003701 stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003702 }
3703 return 1;
3704 }
3705
3706 chunk_reset(&trash);
3707
3708 while (appctx->st2 != STAT_ST_FIN) {
3709 switch (appctx->st2) {
3710 case STAT_ST_INIT:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003711 appctx->ctx.table.t = appctx->ctx.table.target;
3712 if (!appctx->ctx.table.t)
3713 appctx->ctx.table.t = stktables_list;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003714
3715 appctx->ctx.table.entry = NULL;
3716 appctx->st2 = STAT_ST_INFO;
3717 break;
3718
3719 case STAT_ST_INFO:
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003720 if (!appctx->ctx.table.t ||
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003721 (appctx->ctx.table.target &&
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003722 appctx->ctx.table.t != appctx->ctx.table.target)) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003723 appctx->st2 = STAT_ST_END;
3724 break;
3725 }
3726
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003727 if (appctx->ctx.table.t->size) {
3728 if (show && !table_dump_head_to_buffer(&trash, si, appctx->ctx.table.t, appctx->ctx.table.target))
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003729 return 0;
3730
3731 if (appctx->ctx.table.target &&
William Lallemand07a62f72017-05-24 00:57:40 +02003732 (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) {
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003733 /* dump entries only if table explicitly requested */
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003734 HA_SPIN_LOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
3735 eb = ebmb_first(&appctx->ctx.table.t->keys);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003736 if (eb) {
3737 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
3738 appctx->ctx.table.entry->ref_cnt++;
3739 appctx->st2 = STAT_ST_LIST;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003740 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003741 break;
3742 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003743 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003744 }
3745 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003746 appctx->ctx.table.t = appctx->ctx.table.t->next;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003747 break;
3748
3749 case STAT_ST_LIST:
3750 skip_entry = 0;
3751
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003752 HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003753
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003754 if (appctx->ctx.table.data_type >= 0) {
3755 /* we're filtering on some data contents */
3756 void *ptr;
3757 long long data;
3758
Emeric Brun819fc6f2017-06-13 19:37:32 +02003759
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003760 dt = appctx->ctx.table.data_type;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003761 ptr = stktable_data_ptr(appctx->ctx.table.t,
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003762 appctx->ctx.table.entry,
3763 dt);
3764
3765 data = 0;
3766 switch (stktable_data_types[dt].std_type) {
3767 case STD_T_SINT:
3768 data = stktable_data_cast(ptr, std_t_sint);
3769 break;
3770 case STD_T_UINT:
3771 data = stktable_data_cast(ptr, std_t_uint);
3772 break;
3773 case STD_T_ULL:
3774 data = stktable_data_cast(ptr, std_t_ull);
3775 break;
3776 case STD_T_FRQP:
3777 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003778 appctx->ctx.table.t->data_arg[dt].u);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003779 break;
3780 }
3781
3782 /* skip the entry if the data does not match the test and the value */
3783 if ((data < appctx->ctx.table.value &&
3784 (appctx->ctx.table.data_op == STD_OP_EQ ||
3785 appctx->ctx.table.data_op == STD_OP_GT ||
3786 appctx->ctx.table.data_op == STD_OP_GE)) ||
3787 (data == appctx->ctx.table.value &&
3788 (appctx->ctx.table.data_op == STD_OP_NE ||
3789 appctx->ctx.table.data_op == STD_OP_GT ||
3790 appctx->ctx.table.data_op == STD_OP_LT)) ||
3791 (data > appctx->ctx.table.value &&
3792 (appctx->ctx.table.data_op == STD_OP_EQ ||
3793 appctx->ctx.table.data_op == STD_OP_LT ||
3794 appctx->ctx.table.data_op == STD_OP_LE)))
3795 skip_entry = 1;
3796 }
3797
3798 if (show && !skip_entry &&
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003799 !table_dump_entry_to_buffer(&trash, si, appctx->ctx.table.t, appctx->ctx.table.entry)) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003800 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003801 return 0;
3802 }
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003803
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003804 HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003805
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003806 HA_SPIN_LOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003807 appctx->ctx.table.entry->ref_cnt--;
3808
3809 eb = ebmb_next(&appctx->ctx.table.entry->key);
3810 if (eb) {
3811 struct stksess *old = appctx->ctx.table.entry;
3812 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
3813 if (show)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003814 __stksess_kill_if_expired(appctx->ctx.table.t, old);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003815 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003816 __stksess_kill(appctx->ctx.table.t, old);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003817 appctx->ctx.table.entry->ref_cnt++;
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003818 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003819 break;
3820 }
3821
3822
3823 if (show)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003824 __stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003825 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003826 __stksess_kill(appctx->ctx.table.t, appctx->ctx.table.entry);
Emeric Brun819fc6f2017-06-13 19:37:32 +02003827
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003828 HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003829
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003830 appctx->ctx.table.t = appctx->ctx.table.t->next;
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003831 appctx->st2 = STAT_ST_INFO;
3832 break;
3833
3834 case STAT_ST_END:
3835 appctx->st2 = STAT_ST_FIN;
3836 break;
3837 }
3838 }
3839 return 1;
3840}
3841
3842static void cli_release_show_table(struct appctx *appctx)
3843{
3844 if (appctx->st2 == STAT_ST_LIST) {
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +01003845 stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry, 1);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003846 }
3847}
3848
3849/* register cli keywords */
3850static struct cli_kw_list cli_kws = {{ },{
3851 { { "clear", "table", NULL }, "clear table : remove an entry from a table", cli_parse_table_req, cli_io_handler_table, cli_release_show_table, (void *)STK_CLI_ACT_CLR },
3852 { { "set", "table", NULL }, "set table [id] : update or create a table entry's data", cli_parse_table_req, cli_io_handler_table, NULL, (void *)STK_CLI_ACT_SET },
3853 { { "show", "table", NULL }, "show table [id]: report table usage stats or dump this table's contents", cli_parse_table_req, cli_io_handler_table, cli_release_show_table, (void *)STK_CLI_ACT_SHOW },
3854 {{},}
3855}};
3856
Willy Tarreau0108d902018-11-25 19:14:37 +01003857INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
Willy Tarreauf13ebdf2016-11-22 18:00:53 +01003858
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003859static struct action_kw_list tcp_conn_kws = { { }, {
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003860 { "sc-inc-gpc0", parse_inc_gpc0, 1 },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01003861 { "sc-inc-gpc1", parse_inc_gpc1, 1 },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003862 { "sc-set-gpt0", parse_set_gpt0, 1 },
3863 { /* END */ }
3864}};
3865
Willy Tarreau0108d902018-11-25 19:14:37 +01003866INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws);
3867
Willy Tarreau620408f2016-10-21 16:37:51 +02003868static struct action_kw_list tcp_sess_kws = { { }, {
3869 { "sc-inc-gpc0", parse_inc_gpc0, 1 },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01003870 { "sc-inc-gpc1", parse_inc_gpc1, 1 },
Willy Tarreau620408f2016-10-21 16:37:51 +02003871 { "sc-set-gpt0", parse_set_gpt0, 1 },
3872 { /* END */ }
3873}};
3874
Willy Tarreau0108d902018-11-25 19:14:37 +01003875INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws);
3876
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003877static struct action_kw_list tcp_req_kws = { { }, {
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003878 { "sc-inc-gpc0", parse_inc_gpc0, 1 },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01003879 { "sc-inc-gpc1", parse_inc_gpc1, 1 },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003880 { "sc-set-gpt0", parse_set_gpt0, 1 },
3881 { /* END */ }
3882}};
3883
Willy Tarreau0108d902018-11-25 19:14:37 +01003884INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_kws);
3885
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003886static struct action_kw_list tcp_res_kws = { { }, {
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003887 { "sc-inc-gpc0", parse_inc_gpc0, 1 },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01003888 { "sc-inc-gpc1", parse_inc_gpc1, 1 },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003889 { "sc-set-gpt0", parse_set_gpt0, 1 },
3890 { /* END */ }
3891}};
3892
Willy Tarreau0108d902018-11-25 19:14:37 +01003893INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws);
3894
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003895static struct action_kw_list http_req_kws = { { }, {
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003896 { "sc-inc-gpc0", parse_inc_gpc0, 1 },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01003897 { "sc-inc-gpc1", parse_inc_gpc1, 1 },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003898 { "sc-set-gpt0", parse_set_gpt0, 1 },
3899 { /* END */ }
3900}};
3901
Willy Tarreau0108d902018-11-25 19:14:37 +01003902INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws);
3903
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003904static struct action_kw_list http_res_kws = { { }, {
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003905 { "sc-inc-gpc0", parse_inc_gpc0, 1 },
Frédéric Lécaille6778b272018-01-29 15:22:53 +01003906 { "sc-inc-gpc1", parse_inc_gpc1, 1 },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003907 { "sc-set-gpt0", parse_set_gpt0, 1 },
3908 { /* END */ }
3909}};
3910
Willy Tarreau0108d902018-11-25 19:14:37 +01003911INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws);
3912
Willy Tarreau7d562212016-11-25 16:10:05 +01003913///* Note: must not be declared <const> as its list will be overwritten.
3914// * Please take care of keeping this list alphabetically sorted.
3915// */
3916//static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
3917// { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3918// { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3919// { /* END */ },
3920//}};
3921/* Note: must not be declared <const> as its list will be overwritten.
3922 * Please take care of keeping this list alphabetically sorted.
3923 */
3924static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
3925 { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3926 { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3927 { "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 +01003928 { "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 +01003929 { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3930 { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3931 { "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 +01003932 { "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 +01003933 { "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 +01003934 { "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 +01003935 { "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 +01003936 { "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 +01003937 { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3938 { "sc_http_err_rate", smp_fetch_sc_http_err_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3939 { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3940 { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3941 { "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 +01003942 { "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 +01003943 { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3944 { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3945 { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3946 { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3947 { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
3948 { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3949 { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3950 { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3951 { "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 +01003952 { "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 +01003953 { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3954 { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3955 { "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 +01003956 { "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 +01003957 { "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 +01003958 { "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 +01003959 { "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 +01003960 { "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 +01003961 { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3962 { "sc0_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3963 { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3964 { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3965 { "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 +01003966 { "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 +01003967 { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3968 { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3969 { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3970 { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3971 { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
3972 { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3973 { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3974 { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3975 { "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 +01003976 { "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 +01003977 { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3978 { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3979 { "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 +01003980 { "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 +01003981 { "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 +01003982 { "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 +01003983 { "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 +01003984 { "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 +01003985 { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3986 { "sc1_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3987 { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3988 { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3989 { "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 +01003990 { "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 +01003991 { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3992 { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3993 { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3994 { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3995 { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
3996 { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3997 { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3998 { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3999 { "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 +01004000 { "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 +01004001 { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4002 { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4003 { "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 +01004004 { "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 +01004005 { "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 +01004006 { "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 +01004007 { "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 +01004008 { "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 +01004009 { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4010 { "sc2_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4011 { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4012 { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4013 { "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 +01004014 { "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 +01004015 { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4016 { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4017 { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4018 { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4019 { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
4020 { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4021 { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4022 { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4023 { "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 +01004024 { "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 +01004025 { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4026 { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4027 { "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 +01004028 { "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 +01004029 { "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 +01004030 { "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 +01004031 { "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 +01004032 { "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 +01004033 { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4034 { "src_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4035 { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4036 { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4037 { "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 +01004038 { "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 +01004039 { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4040 { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4041 { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4042 { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4043 { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
4044 { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4045 { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
4046 { /* END */ },
4047}};
4048
Willy Tarreau0108d902018-11-25 19:14:37 +01004049INITCALL1(STG_REGISTER, sample_register_fetches, &smp_fetch_keywords);
Willy Tarreau7d562212016-11-25 16:10:05 +01004050
Willy Tarreaud9f316a2014-07-10 14:03:38 +02004051/* Note: must not be declared <const> as its list will be overwritten */
4052static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Willy Tarreau2d17db52016-05-25 17:16:38 +02004053 { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL },
4054 { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4055 { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4056 { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4057 { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4058 { "table_conn_rate", sample_conv_table_conn_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4059 { "table_gpt0", sample_conv_table_gpt0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4060 { "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 +01004061 { "table_gpc1", sample_conv_table_gpc1, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Willy Tarreau2d17db52016-05-25 17:16:38 +02004062 { "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 +01004063 { "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 +02004064 { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4065 { "table_http_err_rate", sample_conv_table_http_err_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4066 { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4067 { "table_http_req_rate", sample_conv_table_http_req_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4068 { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4069 { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4070 { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4071 { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4072 { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
4073 { "table_trackers", sample_conv_table_trackers, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT },
Willy Tarreaud9f316a2014-07-10 14:03:38 +02004074 { /* END */ },
4075}};
4076
Willy Tarreau0108d902018-11-25 19:14:37 +01004077INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws);