Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Stick tables management functions. |
| 3 | * |
| 4 | * Copyright 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 5 | * Copyright (C) 2010 Willy Tarreau <w@1wt.eu> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 6 | * |
| 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 Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 15 | #include <errno.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 16 | |
| 17 | #include <common/config.h> |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 18 | #include <common/cfgparse.h> |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 19 | #include <common/initcall.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 20 | #include <common/memory.h> |
| 21 | #include <common/mini-clist.h> |
Willy Tarreau | 6cde5d8 | 2020-02-25 09:41:22 +0100 | [diff] [blame] | 22 | #include <common/net_helper.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 23 | #include <common/standard.h> |
| 24 | #include <common/time.h> |
| 25 | |
| 26 | #include <ebmbtree.h> |
| 27 | #include <ebsttree.h> |
| 28 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 29 | #include <types/cli.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 30 | #include <types/global.h> |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 31 | #include <types/stats.h> |
| 32 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 33 | #include <proto/arg.h> |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 34 | #include <proto/cli.h> |
Willy Tarreau | 61c112a | 2018-10-02 16:43:32 +0200 | [diff] [blame] | 35 | #include <proto/http_rules.h> |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 36 | #include <proto/log.h> |
Christopher Faulet | fc9cfe4 | 2019-07-16 14:54:53 +0200 | [diff] [blame] | 37 | #include <proto/http_ana.h> |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 38 | #include <proto/proto_tcp.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 39 | #include <proto/proxy.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 40 | #include <proto/sample.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 41 | #include <proto/stream.h> |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 42 | #include <proto/stream_interface.h> |
Willy Tarreau | 68129b9 | 2010-06-06 16:06:52 +0200 | [diff] [blame] | 43 | #include <proto/stick_table.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 44 | #include <proto/task.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 45 | #include <proto/peers.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 46 | #include <proto/tcp_rules.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 47 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 48 | /* structure used to return a table key built from a sample */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 49 | static THREAD_LOCAL struct stktable_key static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 50 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 51 | struct stktable *stktables_list; |
| 52 | struct eb_root stktable_by_name = EB_ROOT; |
| 53 | |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 54 | #define round_ptr_size(i) (((i) + (sizeof(void *) - 1)) &~ (sizeof(void *) - 1)) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 55 | |
| 56 | /* This function inserts stktable <t> into the tree of known stick-table. |
| 57 | * The stick-table ID is used as the storing key so it must already have |
| 58 | * been initialized. |
| 59 | */ |
| 60 | void stktable_store_name(struct stktable *t) |
| 61 | { |
| 62 | t->name.key = t->id; |
| 63 | ebis_insert(&stktable_by_name, &t->name); |
| 64 | } |
| 65 | |
| 66 | struct stktable *stktable_find_by_name(const char *name) |
| 67 | { |
| 68 | struct ebpt_node *node; |
| 69 | struct stktable *t; |
| 70 | |
| 71 | node = ebis_lookup(&stktable_by_name, name); |
| 72 | if (node) { |
| 73 | t = container_of(node, struct stktable, name); |
| 74 | if (!strcmp(t->id, name)) |
| 75 | return t; |
| 76 | } |
| 77 | |
| 78 | return NULL; |
| 79 | } |
| 80 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 81 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 82 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
| 83 | * in table <t>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 84 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 85 | void __stksess_free(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 86 | { |
| 87 | t->current--; |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 88 | pool_free(t->pool, (void *)ts - round_ptr_size(t->data_size)); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 92 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
| 93 | * in table <t>. |
| 94 | * This function locks the table |
| 95 | */ |
| 96 | void stksess_free(struct stktable *t, struct stksess *ts) |
| 97 | { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 98 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 99 | __stksess_free(t, ts); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 100 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 104 | * Kill an stksess (only if its ref_cnt is zero). |
| 105 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 106 | int __stksess_kill(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 107 | { |
| 108 | if (ts->ref_cnt) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 109 | return 0; |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 110 | |
| 111 | eb32_delete(&ts->exp); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 112 | eb32_delete(&ts->upd); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 113 | ebmb_delete(&ts->key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 114 | __stksess_free(t, ts); |
| 115 | return 1; |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 119 | * Decrease the refcount if decrefcnt is not 0. |
| 120 | * and try to kill the stksess |
| 121 | * This function locks the table |
| 122 | */ |
| 123 | int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt) |
| 124 | { |
| 125 | int ret; |
| 126 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 127 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 128 | if (decrefcnt) |
| 129 | ts->ref_cnt--; |
| 130 | ret = __stksess_kill(t, ts); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 131 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 132 | |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 137 | * Initialize or update the key in the sticky session <ts> present in table <t> |
| 138 | * from the value present in <key>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 139 | */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 140 | void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 141 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 142 | if (t->type != SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 143 | memcpy(ts->key.key, key->key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 144 | else { |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 145 | memcpy(ts->key.key, key->key, MIN(t->key_size - 1, key->key_len)); |
| 146 | ts->key.key[MIN(t->key_size - 1, key->key_len)] = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | |
| 151 | /* |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 152 | * Init sticky session <ts> of table <t>. The data parts are cleared and <ts> |
| 153 | * is returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 154 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 155 | static struct stksess *__stksess_init(struct stktable *t, struct stksess * ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 156 | { |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 157 | memset((void *)ts - t->data_size, 0, t->data_size); |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 158 | ts->ref_cnt = 0; |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 159 | ts->key.node.leaf_p = NULL; |
| 160 | ts->exp.node.leaf_p = NULL; |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 161 | ts->upd.node.leaf_p = NULL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 162 | ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 163 | HA_RWLOCK_INIT(&ts->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 164 | return ts; |
| 165 | } |
| 166 | |
| 167 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 168 | * Trash oldest <to_batch> sticky sessions from table <t> |
| 169 | * Returns number of trashed sticky sessions. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 170 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 171 | int __stktable_trash_oldest(struct stktable *t, int to_batch) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 172 | { |
| 173 | struct stksess *ts; |
| 174 | struct eb32_node *eb; |
| 175 | int batched = 0; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 176 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 177 | |
| 178 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 179 | |
| 180 | while (batched < to_batch) { |
| 181 | |
| 182 | if (unlikely(!eb)) { |
| 183 | /* we might have reached the end of the tree, typically because |
| 184 | * <now_ms> is in the first half and we're first scanning the last |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 185 | * half. Let's loop back to the beginning of the tree now if we |
| 186 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 187 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 188 | if (looped) |
| 189 | break; |
| 190 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 191 | eb = eb32_first(&t->exps); |
| 192 | if (likely(!eb)) |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 197 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 198 | eb = eb32_next(eb); |
| 199 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 200 | /* don't delete an entry which is currently referenced */ |
| 201 | if (ts->ref_cnt) |
| 202 | continue; |
| 203 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 204 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 205 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 206 | if (ts->expire != ts->exp.key) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 207 | if (!tick_isset(ts->expire)) |
| 208 | continue; |
| 209 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 210 | ts->exp.key = ts->expire; |
| 211 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 212 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 213 | if (!eb || eb->key > ts->exp.key) |
| 214 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 215 | |
| 216 | continue; |
| 217 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 218 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 219 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 220 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 221 | eb32_delete(&ts->upd); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 222 | __stksess_free(t, ts); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 223 | batched++; |
| 224 | } |
| 225 | |
| 226 | return batched; |
| 227 | } |
| 228 | |
| 229 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 230 | * Trash oldest <to_batch> sticky sessions from table <t> |
| 231 | * Returns number of trashed sticky sessions. |
| 232 | * This function locks the table |
| 233 | */ |
| 234 | int stktable_trash_oldest(struct stktable *t, int to_batch) |
| 235 | { |
| 236 | int ret; |
| 237 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 238 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 239 | ret = __stktable_trash_oldest(t, to_batch); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 240 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 241 | |
| 242 | return ret; |
| 243 | } |
| 244 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 245 | * Allocate and initialise a new sticky session. |
| 246 | * The new sticky session is returned or NULL in case of lack of memory. |
| 247 | * Sticky sessions should only be allocated this way, and must be freed using |
Willy Tarreau | a7b46b5 | 2013-04-11 16:55:37 +0200 | [diff] [blame] | 248 | * stksess_free(). Table <t>'s sticky session counter is increased. If <key> |
| 249 | * is not NULL, it is assigned to the new session. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 250 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 251 | struct stksess *__stksess_new(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 252 | { |
| 253 | struct stksess *ts; |
| 254 | |
| 255 | if (unlikely(t->current == t->size)) { |
| 256 | if ( t->nopurge ) |
| 257 | return NULL; |
| 258 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 259 | if (!__stktable_trash_oldest(t, (t->size >> 8) + 1)) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 260 | return NULL; |
| 261 | } |
| 262 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 263 | ts = pool_alloc(t->pool); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 264 | if (ts) { |
| 265 | t->current++; |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 266 | ts = (void *)ts + round_ptr_size(t->data_size); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 267 | __stksess_init(t, ts); |
Willy Tarreau | a7b46b5 | 2013-04-11 16:55:37 +0200 | [diff] [blame] | 268 | if (key) |
| 269 | stksess_setkey(t, ts, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | return ts; |
| 273 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 274 | /* |
| 275 | * Allocate and initialise a new sticky session. |
| 276 | * The new sticky session is returned or NULL in case of lack of memory. |
| 277 | * Sticky sessions should only be allocated this way, and must be freed using |
| 278 | * stksess_free(). Table <t>'s sticky session counter is increased. If <key> |
| 279 | * is not NULL, it is assigned to the new session. |
| 280 | * This function locks the table |
| 281 | */ |
| 282 | struct stksess *stksess_new(struct stktable *t, struct stktable_key *key) |
| 283 | { |
| 284 | struct stksess *ts; |
| 285 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 286 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 287 | ts = __stksess_new(t, key); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 288 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 289 | |
| 290 | return ts; |
| 291 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 292 | |
| 293 | /* |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 294 | * Looks in table <t> for a sticky session matching key <key>. |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 295 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 296 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 297 | struct stksess *__stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 298 | { |
| 299 | struct ebmb_node *eb; |
| 300 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 301 | if (t->type == SMP_T_STR) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 302 | eb = ebst_lookup_len(&t->keys, key->key, key->key_len+1 < t->key_size ? key->key_len : t->key_size-1); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 303 | else |
| 304 | eb = ebmb_lookup(&t->keys, key->key, t->key_size); |
| 305 | |
| 306 | if (unlikely(!eb)) { |
| 307 | /* no session found */ |
| 308 | return NULL; |
| 309 | } |
| 310 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 311 | return ebmb_entry(eb, struct stksess, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 314 | /* |
| 315 | * Looks in table <t> for a sticky session matching key <key>. |
| 316 | * Returns pointer on requested sticky session or NULL if none was found. |
| 317 | * The refcount of the found entry is increased and this function |
| 318 | * is protected using the table lock |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 319 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 320 | struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 321 | { |
| 322 | struct stksess *ts; |
| 323 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 324 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 325 | ts = __stktable_lookup_key(t, key); |
| 326 | if (ts) |
| 327 | ts->ref_cnt++; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 328 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 329 | |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 330 | return ts; |
| 331 | } |
| 332 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 333 | /* |
| 334 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 335 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 336 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 337 | struct stksess *__stktable_lookup(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 338 | { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 339 | struct ebmb_node *eb; |
| 340 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 341 | if (t->type == SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 342 | eb = ebst_lookup(&(t->keys), (char *)ts->key.key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 343 | else |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 344 | eb = ebmb_lookup(&(t->keys), ts->key.key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 345 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 346 | if (unlikely(!eb)) |
| 347 | return NULL; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 348 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 349 | return ebmb_entry(eb, struct stksess, key); |
| 350 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 351 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 352 | /* |
| 353 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 354 | * Returns pointer on requested sticky session or NULL if none was found. |
| 355 | * The refcount of the found entry is increased and this function |
| 356 | * is protected using the table lock |
| 357 | */ |
| 358 | struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts) |
| 359 | { |
| 360 | struct stksess *lts; |
| 361 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 362 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 363 | lts = __stktable_lookup(t, ts); |
| 364 | if (lts) |
| 365 | lts->ref_cnt++; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 366 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 367 | |
| 368 | return lts; |
| 369 | } |
| 370 | |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 371 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 372 | * The table's expiration timer is updated if set. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 373 | * The node will be also inserted into the update tree if needed, at a position |
| 374 | * depending if the update is a local or coming from a remote node |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 375 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 376 | void __stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local, int expire) |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 377 | { |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 378 | struct eb32_node * eb; |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 379 | ts->expire = expire; |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 380 | if (t->expire) { |
| 381 | t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next); |
| 382 | task_queue(t->exp_task); |
| 383 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 384 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 385 | /* If sync is enabled */ |
| 386 | if (t->sync_task) { |
| 387 | if (local) { |
| 388 | /* If this entry is not in the tree |
| 389 | or not scheduled for at least one peer */ |
| 390 | if (!ts->upd.node.leaf_p |
| 391 | || (int)(t->commitupdate - ts->upd.key) >= 0 |
| 392 | || (int)(ts->upd.key - t->localupdate) >= 0) { |
| 393 | ts->upd.key = ++t->update; |
| 394 | t->localupdate = t->update; |
| 395 | eb32_delete(&ts->upd); |
| 396 | eb = eb32_insert(&t->updates, &ts->upd); |
| 397 | if (eb != &ts->upd) { |
| 398 | eb32_delete(eb); |
| 399 | eb32_insert(&t->updates, &ts->upd); |
| 400 | } |
Emeric Brun | aaf5860 | 2015-06-15 17:23:30 +0200 | [diff] [blame] | 401 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 402 | task_wakeup(t->sync_task, TASK_WOKEN_MSG); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 403 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 404 | else { |
| 405 | /* If this entry is not in the tree */ |
| 406 | if (!ts->upd.node.leaf_p) { |
| 407 | ts->upd.key= (++t->update)+(2147483648U); |
| 408 | eb = eb32_insert(&t->updates, &ts->upd); |
| 409 | if (eb != &ts->upd) { |
| 410 | eb32_delete(eb); |
| 411 | eb32_insert(&t->updates, &ts->upd); |
| 412 | } |
| 413 | } |
| 414 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 415 | } |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 416 | } |
| 417 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 418 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 419 | * The table's expiration timer is updated using the date of expiration coming from |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 420 | * <t> stick-table configuration. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 421 | * The node will be also inserted into the update tree if needed, at a position |
| 422 | * considering the update is coming from a remote node |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 423 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 424 | void stktable_touch_remote(struct stktable *t, struct stksess *ts, int decrefcnt) |
| 425 | { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 426 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 427 | __stktable_touch_with_exp(t, ts, 0, ts->expire); |
| 428 | if (decrefcnt) |
| 429 | ts->ref_cnt--; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 430 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 434 | * The table's expiration timer is updated using the date of expiration coming from |
| 435 | * <t> stick-table configuration. |
| 436 | * The node will be also inserted into the update tree if needed, at a position |
| 437 | * considering the update was made locally |
| 438 | */ |
| 439 | void stktable_touch_local(struct stktable *t, struct stksess *ts, int decrefcnt) |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 440 | { |
| 441 | int expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
| 442 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 443 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 444 | __stktable_touch_with_exp(t, ts, 1, expire); |
| 445 | if (decrefcnt) |
| 446 | ts->ref_cnt--; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 447 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 448 | } |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 449 | /* Just decrease the ref_cnt of the current session. Does nothing if <ts> is NULL */ |
| 450 | static void stktable_release(struct stktable *t, struct stksess *ts) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 451 | { |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 452 | if (!ts) |
| 453 | return; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 454 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 455 | ts->ref_cnt--; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 456 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 457 | } |
| 458 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 459 | /* Insert new sticky session <ts> in the table. It is assumed that it does not |
| 460 | * yet exist (the caller must check this). The table's timeout is updated if it |
| 461 | * is set. <ts> is returned. |
| 462 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 463 | void __stktable_store(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 464 | { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 465 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 466 | ebmb_insert(&t->keys, &ts->key, t->key_size); |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 467 | ts->exp.key = ts->expire; |
| 468 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 469 | if (t->expire) { |
| 470 | t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next); |
| 471 | task_queue(t->exp_task); |
| 472 | } |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 475 | /* Returns a valid or initialized stksess for the specified stktable_key in the |
| 476 | * specified table, or NULL if the key was NULL, or if no entry was found nor |
| 477 | * could be created. The entry's expiration is updated. |
| 478 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 479 | struct stksess *__stktable_get_entry(struct stktable *table, struct stktable_key *key) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 480 | { |
| 481 | struct stksess *ts; |
| 482 | |
| 483 | if (!key) |
| 484 | return NULL; |
| 485 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 486 | ts = __stktable_lookup_key(table, key); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 487 | if (ts == NULL) { |
| 488 | /* entry does not exist, initialize a new one */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 489 | ts = __stksess_new(table, key); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 490 | if (!ts) |
| 491 | return NULL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 492 | __stktable_store(table, ts); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 493 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 494 | return ts; |
| 495 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 496 | /* Returns a valid or initialized stksess for the specified stktable_key in the |
| 497 | * specified table, or NULL if the key was NULL, or if no entry was found nor |
| 498 | * could be created. The entry's expiration is updated. |
| 499 | * This function locks the table, and the refcount of the entry is increased. |
| 500 | */ |
| 501 | struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key) |
| 502 | { |
| 503 | struct stksess *ts; |
| 504 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 505 | HA_SPIN_LOCK(STK_TABLE_LOCK, &table->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 506 | ts = __stktable_get_entry(table, key); |
| 507 | if (ts) |
| 508 | ts->ref_cnt++; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 509 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &table->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 510 | |
| 511 | return ts; |
| 512 | } |
| 513 | |
| 514 | /* Lookup for an entry with the same key and store the submitted |
| 515 | * stksess if not found. |
| 516 | */ |
| 517 | struct stksess *__stktable_set_entry(struct stktable *table, struct stksess *nts) |
| 518 | { |
| 519 | struct stksess *ts; |
| 520 | |
| 521 | ts = __stktable_lookup(table, nts); |
| 522 | if (ts == NULL) { |
| 523 | ts = nts; |
| 524 | __stktable_store(table, ts); |
| 525 | } |
| 526 | return ts; |
| 527 | } |
| 528 | |
| 529 | /* Lookup for an entry with the same key and store the submitted |
| 530 | * stksess if not found. |
| 531 | * This function locks the table, and the refcount of the entry is increased. |
| 532 | */ |
| 533 | struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts) |
| 534 | { |
| 535 | struct stksess *ts; |
| 536 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 537 | HA_SPIN_LOCK(STK_TABLE_LOCK, &table->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 538 | ts = __stktable_set_entry(table, nts); |
| 539 | ts->ref_cnt++; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 540 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &table->lock); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 541 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 542 | return ts; |
| 543 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 544 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 545 | * Trash expired sticky sessions from table <t>. The next expiration date is |
| 546 | * returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 547 | */ |
| 548 | static int stktable_trash_expired(struct stktable *t) |
| 549 | { |
| 550 | struct stksess *ts; |
| 551 | struct eb32_node *eb; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 552 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 553 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 554 | HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 555 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 556 | |
| 557 | while (1) { |
| 558 | if (unlikely(!eb)) { |
| 559 | /* we might have reached the end of the tree, typically because |
| 560 | * <now_ms> is in the first half and we're first scanning the last |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 561 | * half. Let's loop back to the beginning of the tree now if we |
| 562 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 563 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 564 | if (looped) |
| 565 | break; |
| 566 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 567 | eb = eb32_first(&t->exps); |
| 568 | if (likely(!eb)) |
| 569 | break; |
| 570 | } |
| 571 | |
| 572 | if (likely(tick_is_lt(now_ms, eb->key))) { |
| 573 | /* timer not expired yet, revisit it later */ |
| 574 | t->exp_next = eb->key; |
Willy Tarreau | 4d5f13c | 2017-11-05 11:04:47 +0100 | [diff] [blame] | 575 | goto out_unlock; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 579 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 580 | eb = eb32_next(eb); |
| 581 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 582 | /* don't delete an entry which is currently referenced */ |
| 583 | if (ts->ref_cnt) |
| 584 | continue; |
| 585 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 586 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 587 | |
| 588 | if (!tick_is_expired(ts->expire, now_ms)) { |
| 589 | if (!tick_isset(ts->expire)) |
| 590 | continue; |
| 591 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 592 | ts->exp.key = ts->expire; |
| 593 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 594 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 595 | if (!eb || eb->key > ts->exp.key) |
| 596 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 597 | continue; |
| 598 | } |
| 599 | |
| 600 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 601 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 602 | eb32_delete(&ts->upd); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 603 | __stksess_free(t, ts); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /* We have found no task to expire in any tree */ |
| 607 | t->exp_next = TICK_ETERNITY; |
Willy Tarreau | 4d5f13c | 2017-11-05 11:04:47 +0100 | [diff] [blame] | 608 | out_unlock: |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 609 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 610 | return t->exp_next; |
| 611 | } |
| 612 | |
| 613 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 614 | * Task processing function to trash expired sticky sessions. A pointer to the |
| 615 | * task itself is returned since it never dies. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 616 | */ |
Olivier Houchard | 9f6af33 | 2018-05-25 14:04:04 +0200 | [diff] [blame] | 617 | static struct task *process_table_expire(struct task *task, void *context, unsigned short state) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 618 | { |
Olivier Houchard | 9f6af33 | 2018-05-25 14:04:04 +0200 | [diff] [blame] | 619 | struct stktable *t = context; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 620 | |
| 621 | task->expire = stktable_trash_expired(t); |
| 622 | return task; |
| 623 | } |
| 624 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 625 | /* Perform minimal stick table intializations, report 0 in case of error, 1 if OK. */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 626 | int stktable_init(struct stktable *t) |
| 627 | { |
| 628 | if (t->size) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 629 | t->keys = EB_ROOT_UNIQUE; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 630 | memset(&t->exps, 0, sizeof(t->exps)); |
Emeric Brun | 1c6235d | 2015-12-16 15:28:12 +0100 | [diff] [blame] | 631 | t->updates = EB_ROOT_UNIQUE; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 632 | HA_SPIN_INIT(&t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 633 | |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 634 | t->pool = create_pool("sticktables", sizeof(struct stksess) + round_ptr_size(t->data_size) + t->key_size, MEM_F_SHARED); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 635 | |
| 636 | t->exp_next = TICK_ETERNITY; |
| 637 | if ( t->expire ) { |
Emeric Brun | c60def8 | 2017-09-27 14:59:38 +0200 | [diff] [blame] | 638 | t->exp_task = task_new(MAX_THREADS_MASK); |
Willy Tarreau | 848522f | 2018-10-15 11:12:15 +0200 | [diff] [blame] | 639 | if (!t->exp_task) |
| 640 | return 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 641 | t->exp_task->process = process_table_expire; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 642 | t->exp_task->context = (void *)t; |
| 643 | } |
Willy Tarreau | c8b6791 | 2015-05-01 18:29:57 +0200 | [diff] [blame] | 644 | if (t->peers.p && t->peers.p->peers_fe && t->peers.p->peers_fe->state != PR_STSTOPPED) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 645 | peers_register_table(t->peers.p, t); |
| 646 | } |
| 647 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 648 | return t->pool != NULL; |
| 649 | } |
| 650 | return 1; |
| 651 | } |
| 652 | |
| 653 | /* |
| 654 | * Configuration keywords of known table types |
| 655 | */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 656 | struct stktable_type stktable_types[SMP_TYPES] = { |
| 657 | [SMP_T_SINT] = { "integer", 0, 4 }, |
| 658 | [SMP_T_IPV4] = { "ip", 0, 4 }, |
| 659 | [SMP_T_IPV6] = { "ipv6", 0, 16 }, |
| 660 | [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 }, |
| 661 | [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 } |
| 662 | }; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 663 | |
| 664 | /* |
| 665 | * Parse table type configuration. |
| 666 | * Returns 0 on successful parsing, else 1. |
| 667 | * <myidx> is set at next configuration <args> index. |
| 668 | */ |
| 669 | int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size) |
| 670 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 671 | for (*type = 0; *type < SMP_TYPES; (*type)++) { |
| 672 | if (!stktable_types[*type].kw) |
| 673 | continue; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 674 | if (strcmp(args[*myidx], stktable_types[*type].kw) != 0) |
| 675 | continue; |
| 676 | |
| 677 | *key_size = stktable_types[*type].default_size; |
| 678 | (*myidx)++; |
| 679 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 680 | if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 681 | if (strcmp("len", args[*myidx]) == 0) { |
| 682 | (*myidx)++; |
| 683 | *key_size = atol(args[*myidx]); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 684 | if (!*key_size) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 685 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 686 | if (*type == SMP_T_STR) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 687 | /* null terminated string needs +1 for '\0'. */ |
| 688 | (*key_size)++; |
| 689 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 690 | (*myidx)++; |
| 691 | } |
| 692 | } |
| 693 | return 0; |
| 694 | } |
| 695 | return 1; |
| 696 | } |
| 697 | |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 698 | /* |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 699 | * Parse a line with <linenum> as number in <file> configuration file to configure |
| 700 | * the stick-table with <t> as address and <id> as ID. |
| 701 | * <peers> provides the "peers" section pointer only if this function is called |
| 702 | * from a "peers" section. |
| 703 | * <nid> is the stick-table name which is sent over the network. It must be equal |
| 704 | * to <id> if this stick-table is parsed from a proxy section, and prefixed by <peers> |
| 705 | * "peers" section name followed by a '/' character if parsed from a "peers" section. |
| 706 | * This is the responsability of the caller to check this. |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 707 | * Return an error status with ERR_* flags set if required, 0 if no error was encountered. |
| 708 | */ |
| 709 | int parse_stick_table(const char *file, int linenum, char **args, |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 710 | struct stktable *t, char *id, char *nid, struct peers *peers) |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 711 | { |
| 712 | int err_code = 0; |
| 713 | int idx = 1; |
| 714 | unsigned int val; |
| 715 | |
| 716 | if (!id || !*id) { |
| 717 | ha_alert("parsing [%s:%d] : %s: ID not provided.\n", file, linenum, args[0]); |
| 718 | err_code |= ERR_ALERT | ERR_ABORT; |
| 719 | goto out; |
| 720 | } |
| 721 | |
| 722 | /* Store the "peers" section if this function is called from a "peers" section. */ |
| 723 | if (peers) { |
| 724 | t->peers.p = peers; |
| 725 | idx++; |
| 726 | } |
| 727 | |
| 728 | t->id = id; |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 729 | t->nid = nid; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 730 | t->type = (unsigned int)-1; |
| 731 | t->conf.file = file; |
| 732 | t->conf.line = linenum; |
| 733 | |
| 734 | while (*args[idx]) { |
| 735 | const char *err; |
| 736 | |
| 737 | if (strcmp(args[idx], "size") == 0) { |
| 738 | idx++; |
| 739 | if (!*(args[idx])) { |
| 740 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 741 | file, linenum, args[0], args[idx-1]); |
| 742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 743 | goto out; |
| 744 | } |
| 745 | if ((err = parse_size_err(args[idx], &t->size))) { |
| 746 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 747 | file, linenum, args[0], *err, args[idx-1]); |
| 748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 749 | goto out; |
| 750 | } |
| 751 | idx++; |
| 752 | } |
| 753 | /* This argument does not exit in "peers" section. */ |
| 754 | else if (!peers && strcmp(args[idx], "peers") == 0) { |
| 755 | idx++; |
| 756 | if (!*(args[idx])) { |
| 757 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 758 | file, linenum, args[0], args[idx-1]); |
| 759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 760 | goto out; |
| 761 | } |
| 762 | t->peers.name = strdup(args[idx++]); |
| 763 | } |
| 764 | else if (strcmp(args[idx], "expire") == 0) { |
| 765 | idx++; |
| 766 | if (!*(args[idx])) { |
| 767 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 768 | file, linenum, args[0], args[idx-1]); |
| 769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 770 | goto out; |
| 771 | } |
| 772 | err = parse_time_err(args[idx], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 773 | if (err == PARSE_TIME_OVER) { |
| 774 | ha_alert("parsing [%s:%d]: %s: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 775 | file, linenum, args[0], args[idx], args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 777 | goto out; |
| 778 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 779 | else if (err == PARSE_TIME_UNDER) { |
| 780 | ha_alert("parsing [%s:%d]: %s: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 781 | file, linenum, args[0], args[idx], args[idx-1]); |
| 782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 783 | goto out; |
| 784 | } |
| 785 | else if (err) { |
| 786 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 787 | file, linenum, args[0], *err, args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 789 | goto out; |
| 790 | } |
| 791 | t->expire = val; |
| 792 | idx++; |
| 793 | } |
| 794 | else if (strcmp(args[idx], "nopurge") == 0) { |
| 795 | t->nopurge = 1; |
| 796 | idx++; |
| 797 | } |
| 798 | else if (strcmp(args[idx], "type") == 0) { |
| 799 | idx++; |
| 800 | if (stktable_parse_type(args, &idx, &t->type, &t->key_size) != 0) { |
| 801 | ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n", |
| 802 | file, linenum, args[0], args[idx]); |
| 803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 804 | goto out; |
| 805 | } |
| 806 | /* idx already points to next arg */ |
| 807 | } |
| 808 | else if (strcmp(args[idx], "store") == 0) { |
| 809 | int type, err; |
| 810 | char *cw, *nw, *sa; |
| 811 | |
| 812 | idx++; |
| 813 | nw = args[idx]; |
| 814 | while (*nw) { |
| 815 | /* the "store" keyword supports a comma-separated list */ |
| 816 | cw = nw; |
| 817 | sa = NULL; /* store arg */ |
| 818 | while (*nw && *nw != ',') { |
| 819 | if (*nw == '(') { |
| 820 | *nw = 0; |
| 821 | sa = ++nw; |
| 822 | while (*nw != ')') { |
| 823 | if (!*nw) { |
| 824 | ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 825 | file, linenum, args[0], cw); |
| 826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 827 | goto out; |
| 828 | } |
| 829 | nw++; |
| 830 | } |
| 831 | *nw = '\0'; |
| 832 | } |
| 833 | nw++; |
| 834 | } |
| 835 | if (*nw) |
| 836 | *nw++ = '\0'; |
| 837 | type = stktable_get_data_type(cw); |
| 838 | if (type < 0) { |
| 839 | ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 840 | file, linenum, args[0], cw); |
| 841 | err_code |= ERR_ALERT | ERR_FATAL; |
| 842 | goto out; |
| 843 | } |
| 844 | |
| 845 | err = stktable_alloc_data_type(t, type, sa); |
| 846 | switch (err) { |
| 847 | case PE_NONE: break; |
| 848 | case PE_EXIST: |
| 849 | ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 850 | file, linenum, args[0], cw); |
| 851 | err_code |= ERR_WARN; |
| 852 | break; |
| 853 | |
| 854 | case PE_ARG_MISSING: |
| 855 | ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 856 | file, linenum, args[0], cw); |
| 857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 858 | goto out; |
| 859 | |
| 860 | case PE_ARG_NOT_USED: |
| 861 | ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 862 | file, linenum, args[0], cw); |
| 863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 864 | goto out; |
| 865 | |
| 866 | default: |
| 867 | ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 868 | file, linenum, args[0], cw); |
| 869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 870 | goto out; |
| 871 | } |
| 872 | } |
| 873 | idx++; |
| 874 | } |
| 875 | else { |
| 876 | ha_alert("parsing [%s:%d] : %s: unknown argument '%s'.\n", |
| 877 | file, linenum, args[0], args[idx]); |
| 878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 879 | goto out; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | if (!t->size) { |
| 884 | ha_alert("parsing [%s:%d] : %s: missing size.\n", |
| 885 | file, linenum, args[0]); |
| 886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 887 | goto out; |
| 888 | } |
| 889 | |
| 890 | if (t->type == (unsigned int)-1) { |
| 891 | ha_alert("parsing [%s:%d] : %s: missing type.\n", |
| 892 | file, linenum, args[0]); |
| 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto out; |
| 895 | } |
| 896 | |
| 897 | out: |
| 898 | return err_code; |
| 899 | } |
| 900 | |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 901 | /* Prepares a stktable_key from a sample <smp> to search into table <t>. |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 902 | * Note that the sample *is* modified and that the returned key may point |
| 903 | * to it, so the sample must not be modified afterwards before the lookup. |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 904 | * Returns NULL if the sample could not be converted (eg: no matching type), |
| 905 | * otherwise a pointer to the static stktable_key filled with what is needed |
| 906 | * for the lookup. |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 907 | */ |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 908 | struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 909 | { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 910 | /* Convert sample. */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 911 | if (!sample_convert(smp, t->type)) |
Willy Tarreau | 7fc1c6e | 2012-04-26 11:03:17 +0200 | [diff] [blame] | 912 | return NULL; |
| 913 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 914 | /* Fill static_table_key. */ |
| 915 | switch (t->type) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 916 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 917 | case SMP_T_IPV4: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 918 | static_table_key.key = &smp->data.u.ipv4; |
| 919 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 920 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 921 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 922 | case SMP_T_IPV6: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 923 | static_table_key.key = &smp->data.u.ipv6; |
| 924 | static_table_key.key_len = 16; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 925 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 926 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 927 | case SMP_T_SINT: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 928 | /* The stick table require a 32bit unsigned int, "sint" is a |
| 929 | * signed 64 it, so we can convert it inplace. |
| 930 | */ |
Willy Tarreau | 28c63c1 | 2019-10-23 06:21:05 +0200 | [diff] [blame] | 931 | smp->data.u.sint = (unsigned int)smp->data.u.sint; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 932 | static_table_key.key = &smp->data.u.sint; |
| 933 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 934 | break; |
| 935 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 936 | case SMP_T_STR: |
Willy Tarreau | ce6955e | 2016-08-09 11:59:12 +0200 | [diff] [blame] | 937 | if (!smp_make_safe(smp)) |
| 938 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 939 | static_table_key.key = smp->data.u.str.area; |
| 940 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 941 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 942 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 943 | case SMP_T_BIN: |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 944 | if (smp->data.u.str.data < t->key_size) { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 945 | /* This type needs padding with 0. */ |
Willy Tarreau | f65c6c0 | 2016-08-09 12:08:41 +0200 | [diff] [blame] | 946 | if (!smp_make_rw(smp)) |
| 947 | return NULL; |
| 948 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 949 | if (smp->data.u.str.size < t->key_size) |
| 950 | if (!smp_dup(smp)) |
| 951 | return NULL; |
| 952 | if (smp->data.u.str.size < t->key_size) |
| 953 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 954 | memset(smp->data.u.str.area + smp->data.u.str.data, 0, |
| 955 | t->key_size - smp->data.u.str.data); |
| 956 | smp->data.u.str.data = t->key_size; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 957 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 958 | static_table_key.key = smp->data.u.str.area; |
| 959 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 960 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 961 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 962 | default: /* impossible case. */ |
| 963 | return NULL; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 964 | } |
| 965 | |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 966 | return &static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /* |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 970 | * Process a fetch + format conversion as defined by the sample expression <expr> |
| 971 | * on request or response considering the <opt> parameter. Returns either NULL if |
| 972 | * no key could be extracted, or a pointer to the converted result stored in |
| 973 | * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset |
| 974 | * and its flags will be initialized so that the caller gets a copy of the input |
Willy Tarreau | 6bcb0a8 | 2014-07-30 08:56:35 +0200 | [diff] [blame] | 975 | * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present |
| 976 | * without SMP_OPT_FINAL). The output will be usable like this : |
| 977 | * |
| 978 | * return MAY_CHANGE FINAL Meaning for the sample |
| 979 | * NULL 0 * Not present and will never be (eg: header) |
| 980 | * NULL 1 0 Not present or unstable, could change (eg: req_len) |
| 981 | * NULL 1 1 Not present, will not change anymore |
| 982 | * smp 0 * Present and will not change (eg: header) |
| 983 | * smp 1 0 not possible |
| 984 | * smp 1 1 Present, last known value (eg: request length) |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 985 | */ |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 986 | struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *sess, struct stream *strm, |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 987 | unsigned int opt, struct sample_expr *expr, struct sample *smp) |
| 988 | { |
| 989 | if (smp) |
| 990 | memset(smp, 0, sizeof(*smp)); |
| 991 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 992 | smp = sample_process(px, sess, strm, opt, expr, smp); |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 993 | if (!smp) |
| 994 | return NULL; |
| 995 | |
| 996 | if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
| 997 | return NULL; /* we can only use stable samples */ |
| 998 | |
| 999 | return smp_to_stkey(smp, t); |
| 1000 | } |
| 1001 | |
| 1002 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1003 | * Returns 1 if sample expression <expr> result can be converted to table key of |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1004 | * type <table_type>, otherwise zero. Used in configuration check. |
| 1005 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1006 | int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1007 | { |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1008 | int out_type; |
| 1009 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1010 | if (table_type >= SMP_TYPES || !stktable_types[table_type].kw) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1011 | return 0; |
| 1012 | |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1013 | out_type = smp_expr_output_type(expr); |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1014 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1015 | /* Convert sample. */ |
| 1016 | if (!sample_casts[out_type][table_type]) |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1017 | return 0; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1018 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1019 | return 1; |
| 1020 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 1021 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1022 | /* Extra data types processing : after the last one, some room may remain |
| 1023 | * before STKTABLE_DATA_TYPES that may be used to register extra data types |
| 1024 | * at run time. |
| 1025 | */ |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1026 | struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = { |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1027 | [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT }, |
Thierry FOURNIER | 3cf1111 | 2015-07-28 08:57:05 +0200 | [diff] [blame] | 1028 | [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1029 | [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT }, |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 1030 | [STKTABLE_DT_GPC0_RATE] = { .name = "gpc0_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1031 | [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT }, |
| 1032 | [STKTABLE_DT_CONN_RATE] = { .name = "conn_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1033 | [STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .std_type = STD_T_UINT }, |
| 1034 | [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT }, |
| 1035 | [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1036 | [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT }, |
| 1037 | [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1038 | [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT }, |
| 1039 | [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1040 | [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL }, |
| 1041 | [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1042 | [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL }, |
| 1043 | [STKTABLE_DT_BYTES_OUT_RATE]= { .name = "bytes_out_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1044 | [STKTABLE_DT_GPC1] = { .name = "gpc1", .std_type = STD_T_UINT }, |
| 1045 | [STKTABLE_DT_GPC1_RATE] = { .name = "gpc1_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
Frédéric Lécaille | 5ad57ea | 2019-05-17 10:08:29 +0200 | [diff] [blame] | 1046 | [STKTABLE_DT_SERVER_NAME] = { .name = "server_name", .std_type = STD_T_DICT }, |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1047 | }; |
| 1048 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1049 | /* Registers stick-table extra data type with index <idx>, name <name>, type |
| 1050 | * <std_type> and arg type <arg_type>. If the index is negative, the next free |
| 1051 | * index is automatically allocated. The allocated index is returned, or -1 if |
| 1052 | * no free index was found or <name> was already registered. The <name> is used |
| 1053 | * directly as a pointer, so if it's not stable, the caller must allocate it. |
| 1054 | */ |
| 1055 | int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type) |
| 1056 | { |
| 1057 | if (idx < 0) { |
| 1058 | for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) { |
| 1059 | if (!stktable_data_types[idx].name) |
| 1060 | break; |
| 1061 | |
| 1062 | if (strcmp(stktable_data_types[idx].name, name) == 0) |
| 1063 | return -1; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | if (idx >= STKTABLE_DATA_TYPES) |
| 1068 | return -1; |
| 1069 | |
| 1070 | if (stktable_data_types[idx].name != NULL) |
| 1071 | return -1; |
| 1072 | |
| 1073 | stktable_data_types[idx].name = name; |
| 1074 | stktable_data_types[idx].std_type = std_type; |
| 1075 | stktable_data_types[idx].arg_type = arg_type; |
| 1076 | return idx; |
| 1077 | } |
| 1078 | |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1079 | /* |
| 1080 | * Returns the data type number for the stktable_data_type whose name is <name>, |
| 1081 | * or <0 if not found. |
| 1082 | */ |
| 1083 | int stktable_get_data_type(char *name) |
| 1084 | { |
| 1085 | int type; |
| 1086 | |
| 1087 | for (type = 0; type < STKTABLE_DATA_TYPES; type++) { |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1088 | if (!stktable_data_types[type].name) |
| 1089 | continue; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1090 | if (strcmp(name, stktable_data_types[type].name) == 0) |
| 1091 | return type; |
| 1092 | } |
| 1093 | return -1; |
| 1094 | } |
| 1095 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1096 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1097 | * it up into this table. Returns true if found, false otherwise. The input |
| 1098 | * type is STR so that input samples are converted to string (since all types |
| 1099 | * can be converted to strings), then the function casts the string again into |
| 1100 | * the table's type. This is a double conversion, but in the future we might |
| 1101 | * support automatic input types to perform the cast on the fly. |
| 1102 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1103 | static int sample_conv_in_table(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1104 | { |
| 1105 | struct stktable *t; |
| 1106 | struct stktable_key *key; |
| 1107 | struct stksess *ts; |
| 1108 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1109 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1110 | |
| 1111 | key = smp_to_stkey(smp, t); |
| 1112 | if (!key) |
| 1113 | return 0; |
| 1114 | |
| 1115 | ts = stktable_lookup_key(t, key); |
| 1116 | |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1117 | smp->data.type = SMP_T_BOOL; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1118 | smp->data.u.sint = !!ts; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1119 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 1120 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1121 | return 1; |
| 1122 | } |
| 1123 | |
| 1124 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1125 | * it up into this table. Returns the data rate received from clients in bytes/s |
| 1126 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1127 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1128 | * <not found> is returned. |
| 1129 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1130 | static int sample_conv_table_bytes_in_rate(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1131 | { |
| 1132 | struct stktable *t; |
| 1133 | struct stktable_key *key; |
| 1134 | struct stksess *ts; |
| 1135 | void *ptr; |
| 1136 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1137 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1138 | |
| 1139 | key = smp_to_stkey(smp, t); |
| 1140 | if (!key) |
| 1141 | return 0; |
| 1142 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1143 | ts = stktable_lookup_key(t, key); |
| 1144 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1145 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1146 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1147 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1148 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1149 | if (!ts) /* key not present */ |
| 1150 | return 1; |
| 1151 | |
| 1152 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1153 | if (ptr) |
| 1154 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
| 1155 | t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1156 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1157 | stktable_release(t, ts); |
| 1158 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1162 | * it up into this table. Returns the cumulated number of connections for the key |
| 1163 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1164 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1165 | * <not found> is returned. |
| 1166 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1167 | static int sample_conv_table_conn_cnt(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1168 | { |
| 1169 | struct stktable *t; |
| 1170 | struct stktable_key *key; |
| 1171 | struct stksess *ts; |
| 1172 | void *ptr; |
| 1173 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1174 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1175 | |
| 1176 | key = smp_to_stkey(smp, t); |
| 1177 | if (!key) |
| 1178 | return 0; |
| 1179 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1180 | ts = stktable_lookup_key(t, key); |
| 1181 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1182 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1183 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1184 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1185 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1186 | if (!ts) /* key not present */ |
| 1187 | return 1; |
| 1188 | |
| 1189 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1190 | if (ptr) |
| 1191 | smp->data.u.sint = stktable_data_cast(ptr, conn_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1192 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1193 | stktable_release(t, ts); |
| 1194 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1198 | * it up into this table. Returns the number of concurrent connections for the |
| 1199 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1200 | * can be easily performed. If the inspected parameter is not stored in the |
| 1201 | * table, <not found> is returned. |
| 1202 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1203 | static int sample_conv_table_conn_cur(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1204 | { |
| 1205 | struct stktable *t; |
| 1206 | struct stktable_key *key; |
| 1207 | struct stksess *ts; |
| 1208 | void *ptr; |
| 1209 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1210 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1211 | |
| 1212 | key = smp_to_stkey(smp, t); |
| 1213 | if (!key) |
| 1214 | return 0; |
| 1215 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1216 | ts = stktable_lookup_key(t, key); |
| 1217 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1218 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1219 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1220 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1221 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1222 | if (!ts) /* key not present */ |
| 1223 | return 1; |
| 1224 | |
| 1225 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1226 | if (ptr) |
| 1227 | smp->data.u.sint = stktable_data_cast(ptr, conn_cur); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1228 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1229 | stktable_release(t, ts); |
| 1230 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1234 | * it up into this table. Returns the rate of incoming connections from the key |
| 1235 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1236 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1237 | * <not found> is returned. |
| 1238 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1239 | static int sample_conv_table_conn_rate(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1240 | { |
| 1241 | struct stktable *t; |
| 1242 | struct stktable_key *key; |
| 1243 | struct stksess *ts; |
| 1244 | void *ptr; |
| 1245 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1246 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1247 | |
| 1248 | key = smp_to_stkey(smp, t); |
| 1249 | if (!key) |
| 1250 | return 0; |
| 1251 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1252 | ts = stktable_lookup_key(t, key); |
| 1253 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1254 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1255 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1256 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1257 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1258 | if (!ts) /* key not present */ |
| 1259 | return 1; |
| 1260 | |
| 1261 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1262 | if (ptr) |
| 1263 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), |
| 1264 | t->data_arg[STKTABLE_DT_CONN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1265 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1266 | stktable_release(t, ts); |
| 1267 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1271 | * it up into this table. Returns the data rate sent to clients in bytes/s |
| 1272 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1273 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1274 | * <not found> is returned. |
| 1275 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1276 | static int sample_conv_table_bytes_out_rate(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1277 | { |
| 1278 | struct stktable *t; |
| 1279 | struct stktable_key *key; |
| 1280 | struct stksess *ts; |
| 1281 | void *ptr; |
| 1282 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1283 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1284 | |
| 1285 | key = smp_to_stkey(smp, t); |
| 1286 | if (!key) |
| 1287 | return 0; |
| 1288 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1289 | ts = stktable_lookup_key(t, key); |
| 1290 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1291 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1292 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1293 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1294 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1295 | if (!ts) /* key not present */ |
| 1296 | return 1; |
| 1297 | |
| 1298 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1299 | if (ptr) |
| 1300 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
| 1301 | t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1302 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1303 | stktable_release(t, ts); |
| 1304 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1308 | * it up into this table. Returns the value of the GPT0 tag for the key |
| 1309 | * if the key is present in the table, otherwise false, so that comparisons can |
| 1310 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1311 | * <not found> is returned. |
| 1312 | */ |
| 1313 | static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private) |
| 1314 | { |
| 1315 | struct stktable *t; |
| 1316 | struct stktable_key *key; |
| 1317 | struct stksess *ts; |
| 1318 | void *ptr; |
| 1319 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1320 | t = arg_p[0].data.t; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1321 | |
| 1322 | key = smp_to_stkey(smp, t); |
| 1323 | if (!key) |
| 1324 | return 0; |
| 1325 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1326 | ts = stktable_lookup_key(t, key); |
| 1327 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1328 | smp->flags = SMP_F_VOL_TEST; |
| 1329 | smp->data.type = SMP_T_SINT; |
| 1330 | smp->data.u.sint = 0; |
| 1331 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1332 | if (!ts) /* key not present */ |
| 1333 | return 1; |
| 1334 | |
| 1335 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1336 | if (ptr) |
| 1337 | smp->data.u.sint = stktable_data_cast(ptr, gpt0); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1338 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1339 | stktable_release(t, ts); |
| 1340 | return !!ptr; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1344 | * it up into this table. Returns the value of the GPC0 counter for the key |
| 1345 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1346 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1347 | * <not found> is returned. |
| 1348 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1349 | static int sample_conv_table_gpc0(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1350 | { |
| 1351 | struct stktable *t; |
| 1352 | struct stktable_key *key; |
| 1353 | struct stksess *ts; |
| 1354 | void *ptr; |
| 1355 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1356 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1357 | |
| 1358 | key = smp_to_stkey(smp, t); |
| 1359 | if (!key) |
| 1360 | return 0; |
| 1361 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1362 | ts = stktable_lookup_key(t, key); |
| 1363 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1364 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1365 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1366 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1367 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1368 | if (!ts) /* key not present */ |
| 1369 | return 1; |
| 1370 | |
| 1371 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1372 | if (ptr) |
| 1373 | smp->data.u.sint = stktable_data_cast(ptr, gpc0); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1374 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1375 | stktable_release(t, ts); |
| 1376 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1380 | * it up into this table. Returns the event rate of the GPC0 counter for the key |
| 1381 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1382 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1383 | * <not found> is returned. |
| 1384 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1385 | static int sample_conv_table_gpc0_rate(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1386 | { |
| 1387 | struct stktable *t; |
| 1388 | struct stktable_key *key; |
| 1389 | struct stksess *ts; |
| 1390 | void *ptr; |
| 1391 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1392 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1393 | |
| 1394 | key = smp_to_stkey(smp, t); |
| 1395 | if (!key) |
| 1396 | return 0; |
| 1397 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1398 | ts = stktable_lookup_key(t, key); |
| 1399 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1400 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1401 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1402 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1403 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1404 | if (!ts) /* key not present */ |
| 1405 | return 1; |
| 1406 | |
| 1407 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1408 | if (ptr) |
| 1409 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), |
| 1410 | t->data_arg[STKTABLE_DT_GPC0_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1411 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1412 | stktable_release(t, ts); |
| 1413 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1417 | * it up into this table. Returns the value of the GPC1 counter for the key |
| 1418 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1419 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1420 | * <not found> is returned. |
| 1421 | */ |
| 1422 | static int sample_conv_table_gpc1(const struct arg *arg_p, struct sample *smp, void *private) |
| 1423 | { |
| 1424 | struct stktable *t; |
| 1425 | struct stktable_key *key; |
| 1426 | struct stksess *ts; |
| 1427 | void *ptr; |
| 1428 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1429 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1430 | |
| 1431 | key = smp_to_stkey(smp, t); |
| 1432 | if (!key) |
| 1433 | return 0; |
| 1434 | |
| 1435 | ts = stktable_lookup_key(t, key); |
| 1436 | |
| 1437 | smp->flags = SMP_F_VOL_TEST; |
| 1438 | smp->data.type = SMP_T_SINT; |
| 1439 | smp->data.u.sint = 0; |
| 1440 | |
| 1441 | if (!ts) /* key not present */ |
| 1442 | return 1; |
| 1443 | |
| 1444 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1445 | if (ptr) |
| 1446 | smp->data.u.sint = stktable_data_cast(ptr, gpc1); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1447 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1448 | stktable_release(t, ts); |
| 1449 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1453 | * it up into this table. Returns the event rate of the GPC1 counter for the key |
| 1454 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1455 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1456 | * <not found> is returned. |
| 1457 | */ |
| 1458 | static int sample_conv_table_gpc1_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 1459 | { |
| 1460 | struct stktable *t; |
| 1461 | struct stktable_key *key; |
| 1462 | struct stksess *ts; |
| 1463 | void *ptr; |
| 1464 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1465 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1466 | |
| 1467 | key = smp_to_stkey(smp, t); |
| 1468 | if (!key) |
| 1469 | return 0; |
| 1470 | |
| 1471 | ts = stktable_lookup_key(t, key); |
| 1472 | |
| 1473 | smp->flags = SMP_F_VOL_TEST; |
| 1474 | smp->data.type = SMP_T_SINT; |
| 1475 | smp->data.u.sint = 0; |
| 1476 | |
| 1477 | if (!ts) /* key not present */ |
| 1478 | return 1; |
| 1479 | |
| 1480 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1481 | if (ptr) |
| 1482 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc1_rate), |
| 1483 | t->data_arg[STKTABLE_DT_GPC1_RATE].u); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1484 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1485 | stktable_release(t, ts); |
| 1486 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1490 | * it up into this table. Returns the cumulated number of HTTP request errors |
| 1491 | * for the key if the key is present in the table, otherwise zero, so that |
| 1492 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 1493 | * in the table, <not found> is returned. |
| 1494 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1495 | static int sample_conv_table_http_err_cnt(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1496 | { |
| 1497 | struct stktable *t; |
| 1498 | struct stktable_key *key; |
| 1499 | struct stksess *ts; |
| 1500 | void *ptr; |
| 1501 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1502 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1503 | |
| 1504 | key = smp_to_stkey(smp, t); |
| 1505 | if (!key) |
| 1506 | return 0; |
| 1507 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1508 | ts = stktable_lookup_key(t, key); |
| 1509 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1510 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1511 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1512 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1513 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1514 | if (!ts) /* key not present */ |
| 1515 | return 1; |
| 1516 | |
| 1517 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1518 | if (ptr) |
| 1519 | smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1520 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1521 | stktable_release(t, ts); |
| 1522 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1526 | * it up into this table. Returns the HTTP request error rate the key |
| 1527 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1528 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1529 | * <not found> is returned. |
| 1530 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1531 | static int sample_conv_table_http_err_rate(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1532 | { |
| 1533 | struct stktable *t; |
| 1534 | struct stktable_key *key; |
| 1535 | struct stksess *ts; |
| 1536 | void *ptr; |
| 1537 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1538 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1539 | |
| 1540 | key = smp_to_stkey(smp, t); |
| 1541 | if (!key) |
| 1542 | return 0; |
| 1543 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1544 | ts = stktable_lookup_key(t, key); |
| 1545 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1546 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1547 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1548 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1549 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1550 | if (!ts) /* key not present */ |
| 1551 | return 1; |
| 1552 | |
| 1553 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1554 | if (ptr) |
| 1555 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), |
| 1556 | t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1557 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1558 | stktable_release(t, ts); |
| 1559 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1563 | * it up into this table. Returns the cumulated number of HTTP request for the |
| 1564 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1565 | * can be easily performed. If the inspected parameter is not stored in the |
| 1566 | * table, <not found> is returned. |
| 1567 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1568 | static int sample_conv_table_http_req_cnt(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1569 | { |
| 1570 | struct stktable *t; |
| 1571 | struct stktable_key *key; |
| 1572 | struct stksess *ts; |
| 1573 | void *ptr; |
| 1574 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1575 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1576 | |
| 1577 | key = smp_to_stkey(smp, t); |
| 1578 | if (!key) |
| 1579 | return 0; |
| 1580 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1581 | ts = stktable_lookup_key(t, key); |
| 1582 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1583 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1584 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1585 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1586 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1587 | if (!ts) /* key not present */ |
| 1588 | return 1; |
| 1589 | |
| 1590 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1591 | if (ptr) |
| 1592 | smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1593 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1594 | stktable_release(t, ts); |
| 1595 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1599 | * it up into this table. Returns the HTTP request rate the key if the key is |
| 1600 | * present in the table, otherwise zero, so that comparisons can be easily |
| 1601 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 1602 | * is returned. |
| 1603 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1604 | static int sample_conv_table_http_req_rate(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1605 | { |
| 1606 | struct stktable *t; |
| 1607 | struct stktable_key *key; |
| 1608 | struct stksess *ts; |
| 1609 | void *ptr; |
| 1610 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1611 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1612 | |
| 1613 | key = smp_to_stkey(smp, t); |
| 1614 | if (!key) |
| 1615 | return 0; |
| 1616 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1617 | ts = stktable_lookup_key(t, key); |
| 1618 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1619 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1620 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1621 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1622 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1623 | if (!ts) /* key not present */ |
| 1624 | return 1; |
| 1625 | |
| 1626 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1627 | if (ptr) |
| 1628 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
| 1629 | t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1630 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1631 | stktable_release(t, ts); |
| 1632 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1636 | * it up into this table. Returns the volume of datareceived from clients in kbytes |
| 1637 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1638 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1639 | * <not found> is returned. |
| 1640 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1641 | static int sample_conv_table_kbytes_in(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1642 | { |
| 1643 | struct stktable *t; |
| 1644 | struct stktable_key *key; |
| 1645 | struct stksess *ts; |
| 1646 | void *ptr; |
| 1647 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1648 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1649 | |
| 1650 | key = smp_to_stkey(smp, t); |
| 1651 | if (!key) |
| 1652 | return 0; |
| 1653 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1654 | ts = stktable_lookup_key(t, key); |
| 1655 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1656 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1657 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1658 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1659 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1660 | if (!ts) /* key not present */ |
| 1661 | return 1; |
| 1662 | |
| 1663 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1664 | if (ptr) |
| 1665 | smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1666 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1667 | stktable_release(t, ts); |
| 1668 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1672 | * it up into this table. Returns the volume of data sent to clients in kbytes |
| 1673 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1674 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1675 | * <not found> is returned. |
| 1676 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1677 | static int sample_conv_table_kbytes_out(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1678 | { |
| 1679 | struct stktable *t; |
| 1680 | struct stktable_key *key; |
| 1681 | struct stksess *ts; |
| 1682 | void *ptr; |
| 1683 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1684 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1685 | |
| 1686 | key = smp_to_stkey(smp, t); |
| 1687 | if (!key) |
| 1688 | return 0; |
| 1689 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1690 | ts = stktable_lookup_key(t, key); |
| 1691 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1692 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1693 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1694 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1695 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1696 | if (!ts) /* key not present */ |
| 1697 | return 1; |
| 1698 | |
| 1699 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1700 | if (ptr) |
| 1701 | smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1702 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1703 | stktable_release(t, ts); |
| 1704 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1708 | * it up into this table. Returns the server ID associated with the key if the |
| 1709 | * key is present in the table, otherwise zero, so that comparisons can be |
| 1710 | * easily performed. If the inspected parameter is not stored in the table, |
| 1711 | * <not found> is returned. |
| 1712 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1713 | static int sample_conv_table_server_id(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1714 | { |
| 1715 | struct stktable *t; |
| 1716 | struct stktable_key *key; |
| 1717 | struct stksess *ts; |
| 1718 | void *ptr; |
| 1719 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1720 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1721 | |
| 1722 | key = smp_to_stkey(smp, t); |
| 1723 | if (!key) |
| 1724 | return 0; |
| 1725 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1726 | ts = stktable_lookup_key(t, key); |
| 1727 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1728 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1729 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1730 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1731 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1732 | if (!ts) /* key not present */ |
| 1733 | return 1; |
| 1734 | |
| 1735 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1736 | if (ptr) |
| 1737 | smp->data.u.sint = stktable_data_cast(ptr, server_id); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1738 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1739 | stktable_release(t, ts); |
| 1740 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1744 | * it up into this table. Returns the cumulated number of sessions for the |
| 1745 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1746 | * can be easily performed. If the inspected parameter is not stored in the |
| 1747 | * table, <not found> is returned. |
| 1748 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1749 | static int sample_conv_table_sess_cnt(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1750 | { |
| 1751 | struct stktable *t; |
| 1752 | struct stktable_key *key; |
| 1753 | struct stksess *ts; |
| 1754 | void *ptr; |
| 1755 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1756 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1757 | |
| 1758 | key = smp_to_stkey(smp, t); |
| 1759 | if (!key) |
| 1760 | return 0; |
| 1761 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1762 | ts = stktable_lookup_key(t, key); |
| 1763 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1764 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1765 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1766 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1767 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1768 | if (!ts) /* key not present */ |
| 1769 | return 1; |
| 1770 | |
| 1771 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1772 | if (ptr) |
| 1773 | smp->data.u.sint = stktable_data_cast(ptr, sess_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1774 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1775 | stktable_release(t, ts); |
| 1776 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1780 | * it up into this table. Returns the session rate the key if the key is |
| 1781 | * present in the table, otherwise zero, so that comparisons can be easily |
| 1782 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 1783 | * is returned. |
| 1784 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1785 | static int sample_conv_table_sess_rate(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1786 | { |
| 1787 | struct stktable *t; |
| 1788 | struct stktable_key *key; |
| 1789 | struct stksess *ts; |
| 1790 | void *ptr; |
| 1791 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1792 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1793 | |
| 1794 | key = smp_to_stkey(smp, t); |
| 1795 | if (!key) |
| 1796 | return 0; |
| 1797 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1798 | ts = stktable_lookup_key(t, key); |
| 1799 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1800 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1801 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1802 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1803 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1804 | if (!ts) /* key not present */ |
| 1805 | return 1; |
| 1806 | |
| 1807 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1808 | if (ptr) |
| 1809 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), |
| 1810 | t->data_arg[STKTABLE_DT_SESS_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1811 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1812 | stktable_release(t, ts); |
| 1813 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1817 | * it up into this table. Returns the amount of concurrent connections tracking |
| 1818 | * the same key if the key is present in the table, otherwise zero, so that |
| 1819 | * comparisons can be easily performed. If the inspected parameter is not |
| 1820 | * stored in the table, <not found> is returned. |
| 1821 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1822 | static int sample_conv_table_trackers(const struct arg *arg_p, struct sample *smp, void *private) |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1823 | { |
| 1824 | struct stktable *t; |
| 1825 | struct stktable_key *key; |
| 1826 | struct stksess *ts; |
| 1827 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1828 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1829 | |
| 1830 | key = smp_to_stkey(smp, t); |
| 1831 | if (!key) |
| 1832 | return 0; |
| 1833 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1834 | ts = stktable_lookup_key(t, key); |
| 1835 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1836 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1837 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1838 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1839 | |
Tim Duesterhus | 65189c1 | 2018-06-26 15:57:29 +0200 | [diff] [blame] | 1840 | if (!ts) |
| 1841 | return 1; |
| 1842 | |
| 1843 | smp->data.u.sint = ts->ref_cnt; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1844 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1845 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1846 | return 1; |
| 1847 | } |
| 1848 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1849 | /* Always returns 1. */ |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1850 | static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px, |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 1851 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1852 | { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1853 | struct stksess *ts; |
| 1854 | struct stkctr *stkctr; |
| 1855 | |
| 1856 | /* Extract the stksess, return OK if no stksess available. */ |
| 1857 | if (s) |
| 1858 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 1859 | else |
| 1860 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1861 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1862 | ts = stkctr_entry(stkctr); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1863 | if (ts) { |
| 1864 | void *ptr1, *ptr2; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1865 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1866 | /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */ |
| 1867 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 1868 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0); |
| 1869 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1870 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 1871 | |
| 1872 | if (ptr1) |
| 1873 | update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate), |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1874 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1875 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 1876 | if (ptr2) |
| 1877 | stktable_data_cast(ptr2, gpc0)++; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1878 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 1879 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 1880 | |
| 1881 | /* If data was modified, we need to touch to re-schedule sync */ |
| 1882 | stktable_touch_local(stkctr->table, ts, 0); |
| 1883 | } |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1884 | } |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1885 | return ACT_RET_CONT; |
| 1886 | } |
| 1887 | |
| 1888 | /* This function is a common parser for using variables. It understands |
| 1889 | * the formats: |
| 1890 | * |
| 1891 | * sc-inc-gpc0(<stick-table ID>) |
| 1892 | * |
| 1893 | * It returns 0 if fails and <err> is filled with an error message. Otherwise, |
| 1894 | * it returns 1 and the variable <expr> is filled with the pointer to the |
| 1895 | * expression to execute. |
| 1896 | */ |
| 1897 | static enum act_parse_ret parse_inc_gpc0(const char **args, int *arg, struct proxy *px, |
| 1898 | struct act_rule *rule, char **err) |
| 1899 | { |
| 1900 | const char *cmd_name = args[*arg-1]; |
| 1901 | char *error; |
| 1902 | |
| 1903 | cmd_name += strlen("sc-inc-gpc0"); |
| 1904 | if (*cmd_name == '\0') { |
| 1905 | /* default stick table id. */ |
| 1906 | rule->arg.gpc.sc = 0; |
| 1907 | } else { |
| 1908 | /* parse the stick table id. */ |
| 1909 | if (*cmd_name != '(') { |
| 1910 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1911 | return ACT_RET_PRS_ERR; |
| 1912 | } |
| 1913 | cmd_name++; /* jump the '(' */ |
| 1914 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 1915 | if (*error != ')') { |
| 1916 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1917 | return ACT_RET_PRS_ERR; |
| 1918 | } |
| 1919 | |
Christopher Faulet | 28436e2 | 2019-12-18 10:25:46 +0100 | [diff] [blame] | 1920 | if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1921 | memprintf(err, "invalid stick table track ID. The max allowed ID is %d", |
Christopher Faulet | 28436e2 | 2019-12-18 10:25:46 +0100 | [diff] [blame] | 1922 | MAX_SESS_STKCTR-1); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1923 | return ACT_RET_PRS_ERR; |
| 1924 | } |
| 1925 | } |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 1926 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1927 | rule->action_ptr = action_inc_gpc0; |
| 1928 | return ACT_RET_PRS_OK; |
| 1929 | } |
| 1930 | |
| 1931 | /* Always returns 1. */ |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1932 | static enum act_return action_inc_gpc1(struct act_rule *rule, struct proxy *px, |
| 1933 | struct session *sess, struct stream *s, int flags) |
| 1934 | { |
| 1935 | struct stksess *ts; |
| 1936 | struct stkctr *stkctr; |
| 1937 | |
| 1938 | /* Extract the stksess, return OK if no stksess available. */ |
| 1939 | if (s) |
| 1940 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 1941 | else |
| 1942 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
| 1943 | |
| 1944 | ts = stkctr_entry(stkctr); |
| 1945 | if (ts) { |
| 1946 | void *ptr1, *ptr2; |
| 1947 | |
| 1948 | /* First, update gpc1_rate if it's tracked. Second, update its gpc1 if tracked. */ |
| 1949 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1_RATE); |
| 1950 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1); |
| 1951 | if (ptr1 || ptr2) { |
| 1952 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 1953 | |
| 1954 | if (ptr1) |
| 1955 | update_freq_ctr_period(&stktable_data_cast(ptr1, gpc1_rate), |
| 1956 | stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u, 1); |
| 1957 | |
| 1958 | if (ptr2) |
| 1959 | stktable_data_cast(ptr2, gpc1)++; |
| 1960 | |
| 1961 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 1962 | |
| 1963 | /* If data was modified, we need to touch to re-schedule sync */ |
| 1964 | stktable_touch_local(stkctr->table, ts, 0); |
| 1965 | } |
| 1966 | } |
| 1967 | return ACT_RET_CONT; |
| 1968 | } |
| 1969 | |
| 1970 | /* This function is a common parser for using variables. It understands |
| 1971 | * the formats: |
| 1972 | * |
| 1973 | * sc-inc-gpc1(<stick-table ID>) |
| 1974 | * |
| 1975 | * It returns 0 if fails and <err> is filled with an error message. Otherwise, |
| 1976 | * it returns 1 and the variable <expr> is filled with the pointer to the |
| 1977 | * expression to execute. |
| 1978 | */ |
| 1979 | static enum act_parse_ret parse_inc_gpc1(const char **args, int *arg, struct proxy *px, |
| 1980 | struct act_rule *rule, char **err) |
| 1981 | { |
| 1982 | const char *cmd_name = args[*arg-1]; |
| 1983 | char *error; |
| 1984 | |
| 1985 | cmd_name += strlen("sc-inc-gpc1"); |
| 1986 | if (*cmd_name == '\0') { |
| 1987 | /* default stick table id. */ |
| 1988 | rule->arg.gpc.sc = 0; |
| 1989 | } else { |
| 1990 | /* parse the stick table id. */ |
| 1991 | if (*cmd_name != '(') { |
| 1992 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1993 | return ACT_RET_PRS_ERR; |
| 1994 | } |
| 1995 | cmd_name++; /* jump the '(' */ |
| 1996 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 1997 | if (*error != ')') { |
| 1998 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1999 | return ACT_RET_PRS_ERR; |
| 2000 | } |
| 2001 | |
Christopher Faulet | 28436e2 | 2019-12-18 10:25:46 +0100 | [diff] [blame] | 2002 | if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2003 | memprintf(err, "invalid stick table track ID. The max allowed ID is %d", |
Christopher Faulet | 28436e2 | 2019-12-18 10:25:46 +0100 | [diff] [blame] | 2004 | MAX_SESS_STKCTR-1); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2005 | return ACT_RET_PRS_ERR; |
| 2006 | } |
| 2007 | } |
| 2008 | rule->action = ACT_CUSTOM; |
| 2009 | rule->action_ptr = action_inc_gpc1; |
| 2010 | return ACT_RET_PRS_OK; |
| 2011 | } |
| 2012 | |
| 2013 | /* Always returns 1. */ |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2014 | static enum act_return action_set_gpt0(struct act_rule *rule, struct proxy *px, |
Willy Tarreau | 658b85b | 2015-09-27 10:00:49 +0200 | [diff] [blame] | 2015 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2016 | { |
| 2017 | void *ptr; |
| 2018 | struct stksess *ts; |
| 2019 | struct stkctr *stkctr; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2020 | unsigned int value = 0; |
| 2021 | struct sample *smp; |
| 2022 | int smp_opt_dir; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2023 | |
| 2024 | /* Extract the stksess, return OK if no stksess available. */ |
| 2025 | if (s) |
| 2026 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
| 2027 | else |
| 2028 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2029 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2030 | ts = stkctr_entry(stkctr); |
| 2031 | if (!ts) |
| 2032 | return ACT_RET_CONT; |
| 2033 | |
| 2034 | /* Store the sample in the required sc, and ignore errors. */ |
| 2035 | ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2036 | if (ptr) { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2037 | if (!rule->arg.gpt.expr) |
| 2038 | value = (unsigned int)(rule->arg.gpt.value); |
| 2039 | else { |
| 2040 | switch (rule->from) { |
| 2041 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2042 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2043 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2044 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2045 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2046 | default: |
| 2047 | send_log(px, LOG_ERR, "stick table: internal error while setting gpt0."); |
| 2048 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2049 | ha_alert("stick table: internal error while executing setting gpt0.\n"); |
| 2050 | return ACT_RET_CONT; |
| 2051 | } |
| 2052 | |
| 2053 | /* Fetch and cast the expression. */ |
| 2054 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT); |
| 2055 | if (!smp) { |
| 2056 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt0."); |
| 2057 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2058 | ha_alert("stick table: invalid expression or data type while setting gpt0.\n"); |
| 2059 | return ACT_RET_CONT; |
| 2060 | } |
| 2061 | value = (unsigned int)(smp->data.u.sint); |
| 2062 | } |
| 2063 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2064 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2065 | |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2066 | stktable_data_cast(ptr, gpt0) = value; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2067 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2068 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2069 | |
| 2070 | stktable_touch_local(stkctr->table, ts, 0); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2071 | } |
| 2072 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2073 | return ACT_RET_CONT; |
| 2074 | } |
| 2075 | |
| 2076 | /* This function is a common parser for using variables. It understands |
| 2077 | * the format: |
| 2078 | * |
| 2079 | * set-gpt0(<stick-table ID>) <expression> |
| 2080 | * |
| 2081 | * It returns 0 if fails and <err> is filled with an error message. Otherwise, |
| 2082 | * it returns 1 and the variable <expr> is filled with the pointer to the |
| 2083 | * expression to execute. |
| 2084 | */ |
| 2085 | static enum act_parse_ret parse_set_gpt0(const char **args, int *arg, struct proxy *px, |
| 2086 | struct act_rule *rule, char **err) |
| 2087 | |
| 2088 | |
| 2089 | { |
| 2090 | const char *cmd_name = args[*arg-1]; |
| 2091 | char *error; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2092 | int smp_val; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2093 | |
| 2094 | cmd_name += strlen("sc-set-gpt0"); |
| 2095 | if (*cmd_name == '\0') { |
| 2096 | /* default stick table id. */ |
| 2097 | rule->arg.gpt.sc = 0; |
| 2098 | } else { |
| 2099 | /* parse the stick table id. */ |
| 2100 | if (*cmd_name != '(') { |
| 2101 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2102 | return ACT_RET_PRS_ERR; |
| 2103 | } |
| 2104 | cmd_name++; /* jump the '(' */ |
| 2105 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2106 | if (*error != ')') { |
| 2107 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2108 | return ACT_RET_PRS_ERR; |
| 2109 | } |
| 2110 | |
Christopher Faulet | 28436e2 | 2019-12-18 10:25:46 +0100 | [diff] [blame] | 2111 | if (rule->arg.gpt.sc >= MAX_SESS_STKCTR) { |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2112 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d", |
Christopher Faulet | 28436e2 | 2019-12-18 10:25:46 +0100 | [diff] [blame] | 2113 | args[*arg-1], MAX_SESS_STKCTR-1); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2114 | return ACT_RET_PRS_ERR; |
| 2115 | } |
| 2116 | } |
| 2117 | |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2118 | rule->arg.gpt.expr = NULL; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2119 | rule->arg.gpt.value = strtol(args[*arg], &error, 10); |
| 2120 | if (*error != '\0') { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2121 | rule->arg.gpt.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 2122 | px->conf.args.line, err, &px->conf.args, NULL); |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2123 | if (!rule->arg.gpt.expr) |
| 2124 | return ACT_RET_PRS_ERR; |
| 2125 | |
| 2126 | switch (rule->from) { |
| 2127 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 2128 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 2129 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 2130 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 2131 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 2132 | default: |
| 2133 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 2134 | return ACT_RET_PRS_ERR; |
| 2135 | } |
| 2136 | if (!(rule->arg.gpt.expr->fetch->val & smp_val)) { |
| 2137 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 2138 | sample_src_names(rule->arg.gpt.expr->fetch->use)); |
| 2139 | free(rule->arg.gpt.expr); |
| 2140 | return ACT_RET_PRS_ERR; |
| 2141 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2142 | } |
| 2143 | (*arg)++; |
| 2144 | |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 2145 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2146 | rule->action_ptr = action_set_gpt0; |
| 2147 | |
| 2148 | return ACT_RET_PRS_OK; |
| 2149 | } |
| 2150 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2151 | /* set temp integer to the number of used entries in the table pointed to by expr. |
| 2152 | * Accepts exactly 1 argument of type table. |
| 2153 | */ |
| 2154 | static int |
| 2155 | smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2156 | { |
| 2157 | smp->flags = SMP_F_VOL_TEST; |
| 2158 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2159 | smp->data.u.sint = args->data.t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2160 | return 1; |
| 2161 | } |
| 2162 | |
| 2163 | /* set temp integer to the number of free entries in the table pointed to by expr. |
| 2164 | * Accepts exactly 1 argument of type table. |
| 2165 | */ |
| 2166 | static int |
| 2167 | smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2168 | { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2169 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2170 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2171 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2172 | smp->flags = SMP_F_VOL_TEST; |
| 2173 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2174 | smp->data.u.sint = t->size - t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2175 | return 1; |
| 2176 | } |
| 2177 | |
| 2178 | /* Returns a pointer to a stkctr depending on the fetch keyword name. |
| 2179 | * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively. |
| 2180 | * sc[0-9]_* will return a pointer to the respective field in the |
| 2181 | * stream <l4>. sc_* requires an UINT argument specifying the stick |
| 2182 | * counter number. src_* will fill a locally allocated structure with |
| 2183 | * the table and entry corresponding to what is specified with src_*. |
| 2184 | * NULL may be returned if the designated stkctr is not tracked. For |
| 2185 | * the sc_* and sc[0-9]_* forms, an optional table argument may be |
| 2186 | * passed. When present, the currently tracked key is then looked up |
| 2187 | * in the specified table instead of the current table. The purpose is |
| 2188 | * to be able to convery multiple values per key (eg: have gpc0 from |
| 2189 | * multiple tables). <strm> is allowed to be NULL, in which case only |
| 2190 | * the session will be consulted. |
| 2191 | */ |
| 2192 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2193 | smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw, struct stkctr *stkctr) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2194 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2195 | struct stkctr *stkptr; |
| 2196 | struct stksess *stksess; |
| 2197 | unsigned int num = kw[2] - '0'; |
| 2198 | int arg = 0; |
| 2199 | |
| 2200 | if (num == '_' - '0') { |
| 2201 | /* sc_* variant, args[0] = ctr# (mandatory) */ |
| 2202 | num = args[arg++].data.sint; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2203 | } |
| 2204 | else if (num > 9) { /* src_* variant, args[0] = table */ |
| 2205 | struct stktable_key *key; |
| 2206 | struct connection *conn = objt_conn(sess->origin); |
| 2207 | struct sample smp; |
| 2208 | |
| 2209 | if (!conn) |
| 2210 | return NULL; |
| 2211 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 2212 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2213 | smp.px = NULL; |
| 2214 | smp.sess = sess; |
| 2215 | smp.strm = strm; |
| 2216 | if (!smp_fetch_src(NULL, &smp, NULL, NULL)) |
| 2217 | return NULL; |
| 2218 | |
| 2219 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2220 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2221 | if (!key) |
| 2222 | return NULL; |
| 2223 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2224 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2225 | stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key)); |
| 2226 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | /* Here, <num> contains the counter number from 0 to 9 for |
| 2230 | * the sc[0-9]_ form, or even higher using sc_(num) if needed. |
| 2231 | * args[arg] is the first optional argument. We first lookup the |
| 2232 | * ctr form the stream, then from the session if it was not there. |
Christopher Faulet | a9fa88a | 2019-10-21 10:53:34 +0200 | [diff] [blame] | 2233 | * But we must be sure the counter does not exceed MAX_SESS_STKCTR. |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2234 | */ |
Christopher Faulet | a9fa88a | 2019-10-21 10:53:34 +0200 | [diff] [blame] | 2235 | if (num >= MAX_SESS_STKCTR) |
| 2236 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2237 | |
| 2238 | if (strm) |
| 2239 | stkptr = &strm->stkctr[num]; |
| 2240 | if (!strm || !stkctr_entry(stkptr)) { |
| 2241 | stkptr = &sess->stkctr[num]; |
| 2242 | if (!stkctr_entry(stkptr)) |
| 2243 | return NULL; |
| 2244 | } |
| 2245 | |
| 2246 | stksess = stkctr_entry(stkptr); |
| 2247 | if (!stksess) |
| 2248 | return NULL; |
| 2249 | |
| 2250 | if (unlikely(args[arg].type == ARGT_TAB)) { |
| 2251 | /* an alternate table was specified, let's look up the same key there */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2252 | stkctr->table = args[arg].data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2253 | stkctr_set_entry(stkctr, stktable_lookup(stkctr->table, stksess)); |
| 2254 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2255 | } |
| 2256 | return stkptr; |
| 2257 | } |
| 2258 | |
| 2259 | /* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create |
| 2260 | * the entry if it doesn't exist yet. This is needed for a few fetch |
| 2261 | * functions which need to create an entry, such as src_inc_gpc* and |
| 2262 | * src_clr_gpc*. |
| 2263 | */ |
| 2264 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2265 | smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw, struct stkctr *stkctr) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2266 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2267 | struct stktable_key *key; |
| 2268 | struct connection *conn = objt_conn(sess->origin); |
| 2269 | struct sample smp; |
| 2270 | |
| 2271 | if (strncmp(kw, "src_", 4) != 0) |
| 2272 | return NULL; |
| 2273 | |
| 2274 | if (!conn) |
| 2275 | return NULL; |
| 2276 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 2277 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2278 | smp.px = NULL; |
| 2279 | smp.sess = sess; |
| 2280 | smp.strm = strm; |
| 2281 | if (!smp_fetch_src(NULL, &smp, NULL, NULL)) |
| 2282 | return NULL; |
| 2283 | |
| 2284 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2285 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2286 | if (!key) |
| 2287 | return NULL; |
| 2288 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2289 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2290 | stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key)); |
| 2291 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /* set return a boolean indicating if the requested stream counter is |
| 2295 | * currently being tracked or not. |
| 2296 | * Supports being called as "sc[0-9]_tracked" only. |
| 2297 | */ |
| 2298 | static int |
| 2299 | smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2300 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2301 | struct stkctr tmpstkctr; |
| 2302 | struct stkctr *stkctr; |
| 2303 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2304 | smp->flags = SMP_F_VOL_TEST; |
| 2305 | smp->data.type = SMP_T_BOOL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2306 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 2307 | smp->data.u.sint = !!stkctr; |
| 2308 | |
| 2309 | /* release the ref count */ |
Dirkjan Bussink | ff57f1b | 2018-09-14 14:31:22 +0200 | [diff] [blame] | 2310 | if (stkctr == &tmpstkctr) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2311 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2312 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2313 | return 1; |
| 2314 | } |
| 2315 | |
| 2316 | /* set <smp> to the General Purpose Flag 0 value from the stream's tracked |
| 2317 | * frontend counters or from the src. |
| 2318 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value |
| 2319 | * zero is returned if the key is new. |
| 2320 | */ |
| 2321 | static int |
| 2322 | smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2323 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2324 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2325 | struct stkctr *stkctr; |
| 2326 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2327 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2328 | if (!stkctr) |
| 2329 | return 0; |
| 2330 | |
| 2331 | smp->flags = SMP_F_VOL_TEST; |
| 2332 | smp->data.type = SMP_T_SINT; |
| 2333 | smp->data.u.sint = 0; |
| 2334 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2335 | if (stkctr_entry(stkctr)) { |
| 2336 | void *ptr; |
| 2337 | |
| 2338 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0); |
| 2339 | if (!ptr) { |
| 2340 | if (stkctr == &tmpstkctr) |
| 2341 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2342 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2343 | } |
| 2344 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2345 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2346 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2347 | smp->data.u.sint = stktable_data_cast(ptr, gpt0); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2348 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2349 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2350 | |
| 2351 | if (stkctr == &tmpstkctr) |
| 2352 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2353 | } |
| 2354 | return 1; |
| 2355 | } |
| 2356 | |
| 2357 | /* set <smp> to the General Purpose Counter 0 value from the stream's tracked |
| 2358 | * frontend counters or from the src. |
| 2359 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value |
| 2360 | * zero is returned if the key is new. |
| 2361 | */ |
| 2362 | static int |
| 2363 | smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2364 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2365 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2366 | struct stkctr *stkctr; |
| 2367 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2368 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2369 | if (!stkctr) |
| 2370 | return 0; |
| 2371 | |
| 2372 | smp->flags = SMP_F_VOL_TEST; |
| 2373 | smp->data.type = SMP_T_SINT; |
| 2374 | smp->data.u.sint = 0; |
| 2375 | |
| 2376 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2377 | void *ptr; |
| 2378 | |
| 2379 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 2380 | if (!ptr) { |
| 2381 | if (stkctr == &tmpstkctr) |
| 2382 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2383 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2384 | } |
| 2385 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2386 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2387 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2388 | smp->data.u.sint = stktable_data_cast(ptr, gpc0); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2389 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2390 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2391 | |
| 2392 | if (stkctr == &tmpstkctr) |
| 2393 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2394 | } |
| 2395 | return 1; |
| 2396 | } |
| 2397 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2398 | /* set <smp> to the General Purpose Counter 1 value from the stream's tracked |
| 2399 | * frontend counters or from the src. |
| 2400 | * Supports being called as "sc[0-9]_get_gpc1" or "src_get_gpc1" only. Value |
| 2401 | * zero is returned if the key is new. |
| 2402 | */ |
| 2403 | static int |
| 2404 | smp_fetch_sc_get_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2405 | { |
| 2406 | struct stkctr tmpstkctr; |
| 2407 | struct stkctr *stkctr; |
| 2408 | |
| 2409 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 2410 | if (!stkctr) |
| 2411 | return 0; |
| 2412 | |
| 2413 | smp->flags = SMP_F_VOL_TEST; |
| 2414 | smp->data.type = SMP_T_SINT; |
| 2415 | smp->data.u.sint = 0; |
| 2416 | |
| 2417 | if (stkctr_entry(stkctr) != NULL) { |
| 2418 | void *ptr; |
| 2419 | |
| 2420 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 2421 | if (!ptr) { |
| 2422 | if (stkctr == &tmpstkctr) |
| 2423 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2424 | return 0; /* parameter not stored */ |
| 2425 | } |
| 2426 | |
| 2427 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2428 | |
| 2429 | smp->data.u.sint = stktable_data_cast(ptr, gpc1); |
| 2430 | |
| 2431 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2432 | |
| 2433 | if (stkctr == &tmpstkctr) |
| 2434 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2435 | } |
| 2436 | return 1; |
| 2437 | } |
| 2438 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2439 | /* set <smp> to the General Purpose Counter 0's event rate from the stream's |
| 2440 | * tracked frontend counters or from the src. |
| 2441 | * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only. |
| 2442 | * Value zero is returned if the key is new. |
| 2443 | */ |
| 2444 | static int |
| 2445 | smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2446 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2447 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2448 | struct stkctr *stkctr; |
| 2449 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2450 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2451 | if (!stkctr) |
| 2452 | return 0; |
| 2453 | |
| 2454 | smp->flags = SMP_F_VOL_TEST; |
| 2455 | smp->data.type = SMP_T_SINT; |
| 2456 | smp->data.u.sint = 0; |
| 2457 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2458 | void *ptr; |
| 2459 | |
| 2460 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
| 2461 | if (!ptr) { |
| 2462 | if (stkctr == &tmpstkctr) |
| 2463 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2464 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2465 | } |
| 2466 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2467 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2468 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2469 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), |
| 2470 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2471 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2472 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2473 | |
| 2474 | if (stkctr == &tmpstkctr) |
| 2475 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2476 | } |
| 2477 | return 1; |
| 2478 | } |
| 2479 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2480 | /* set <smp> to the General Purpose Counter 1's event rate from the stream's |
| 2481 | * tracked frontend counters or from the src. |
| 2482 | * Supports being called as "sc[0-9]_gpc1_rate" or "src_gpc1_rate" only. |
| 2483 | * Value zero is returned if the key is new. |
| 2484 | */ |
| 2485 | static int |
| 2486 | smp_fetch_sc_gpc1_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2487 | { |
| 2488 | struct stkctr tmpstkctr; |
| 2489 | struct stkctr *stkctr; |
| 2490 | |
| 2491 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 2492 | if (!stkctr) |
| 2493 | return 0; |
| 2494 | |
| 2495 | smp->flags = SMP_F_VOL_TEST; |
| 2496 | smp->data.type = SMP_T_SINT; |
| 2497 | smp->data.u.sint = 0; |
| 2498 | if (stkctr_entry(stkctr) != NULL) { |
| 2499 | void *ptr; |
| 2500 | |
| 2501 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE); |
| 2502 | if (!ptr) { |
| 2503 | if (stkctr == &tmpstkctr) |
| 2504 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2505 | return 0; /* parameter not stored */ |
| 2506 | } |
| 2507 | |
| 2508 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2509 | |
| 2510 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc1_rate), |
| 2511 | stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u); |
| 2512 | |
| 2513 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2514 | |
| 2515 | if (stkctr == &tmpstkctr) |
| 2516 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2517 | } |
| 2518 | return 1; |
| 2519 | } |
| 2520 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2521 | /* Increment the General Purpose Counter 0 value from the stream's tracked |
| 2522 | * frontend counters and return it into temp integer. |
| 2523 | * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. |
| 2524 | */ |
| 2525 | static int |
| 2526 | smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2527 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2528 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2529 | struct stkctr *stkctr; |
| 2530 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2531 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2532 | if (!stkctr) |
| 2533 | return 0; |
| 2534 | |
| 2535 | smp->flags = SMP_F_VOL_TEST; |
| 2536 | smp->data.type = SMP_T_SINT; |
| 2537 | smp->data.u.sint = 0; |
| 2538 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2539 | if (!stkctr_entry(stkctr)) |
| 2540 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2541 | |
| 2542 | if (stkctr && stkctr_entry(stkctr)) { |
| 2543 | void *ptr1,*ptr2; |
| 2544 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2545 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2546 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 2547 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 2548 | */ |
| 2549 | ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2550 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2551 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2552 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2553 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2554 | if (ptr1) { |
| 2555 | update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate), |
| 2556 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); |
| 2557 | smp->data.u.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr; |
| 2558 | } |
| 2559 | |
| 2560 | if (ptr2) |
| 2561 | smp->data.u.sint = ++stktable_data_cast(ptr2, gpc0); |
| 2562 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2563 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2564 | |
| 2565 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2566 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 2567 | } |
| 2568 | else if (stkctr == &tmpstkctr) |
| 2569 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2570 | } |
| 2571 | return 1; |
| 2572 | } |
| 2573 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2574 | /* Increment the General Purpose Counter 1 value from the stream's tracked |
| 2575 | * frontend counters and return it into temp integer. |
| 2576 | * Supports being called as "sc[0-9]_inc_gpc1" or "src_inc_gpc1" only. |
| 2577 | */ |
| 2578 | static int |
| 2579 | smp_fetch_sc_inc_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2580 | { |
| 2581 | struct stkctr tmpstkctr; |
| 2582 | struct stkctr *stkctr; |
| 2583 | |
| 2584 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 2585 | if (!stkctr) |
| 2586 | return 0; |
| 2587 | |
| 2588 | smp->flags = SMP_F_VOL_TEST; |
| 2589 | smp->data.type = SMP_T_SINT; |
| 2590 | smp->data.u.sint = 0; |
| 2591 | |
| 2592 | if (!stkctr_entry(stkctr)) |
| 2593 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 2594 | |
| 2595 | if (stkctr && stkctr_entry(stkctr)) { |
| 2596 | void *ptr1,*ptr2; |
| 2597 | |
| 2598 | |
| 2599 | /* First, update gpc1_rate if it's tracked. Second, update its |
| 2600 | * gpc1 if tracked. Returns gpc1's value otherwise the curr_ctr. |
| 2601 | */ |
| 2602 | ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE); |
| 2603 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 2604 | if (ptr1 || ptr2) { |
| 2605 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2606 | |
| 2607 | if (ptr1) { |
| 2608 | update_freq_ctr_period(&stktable_data_cast(ptr1, gpc1_rate), |
| 2609 | stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u, 1); |
| 2610 | smp->data.u.sint = (&stktable_data_cast(ptr1, gpc1_rate))->curr_ctr; |
| 2611 | } |
| 2612 | |
| 2613 | if (ptr2) |
| 2614 | smp->data.u.sint = ++stktable_data_cast(ptr2, gpc1); |
| 2615 | |
| 2616 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2617 | |
| 2618 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2619 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 2620 | } |
| 2621 | else if (stkctr == &tmpstkctr) |
| 2622 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2623 | } |
| 2624 | return 1; |
| 2625 | } |
| 2626 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2627 | /* Clear the General Purpose Counter 0 value from the stream's tracked |
| 2628 | * frontend counters and return its previous value into temp integer. |
| 2629 | * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only. |
| 2630 | */ |
| 2631 | static int |
| 2632 | smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2633 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2634 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2635 | struct stkctr *stkctr; |
| 2636 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2637 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2638 | if (!stkctr) |
| 2639 | return 0; |
| 2640 | |
| 2641 | smp->flags = SMP_F_VOL_TEST; |
| 2642 | smp->data.type = SMP_T_SINT; |
| 2643 | smp->data.u.sint = 0; |
| 2644 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2645 | if (!stkctr_entry(stkctr)) |
| 2646 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2647 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2648 | if (stkctr && stkctr_entry(stkctr)) { |
| 2649 | void *ptr; |
| 2650 | |
| 2651 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 2652 | if (!ptr) { |
| 2653 | if (stkctr == &tmpstkctr) |
| 2654 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2655 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2656 | } |
| 2657 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2658 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2659 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2660 | smp->data.u.sint = stktable_data_cast(ptr, gpc0); |
| 2661 | stktable_data_cast(ptr, gpc0) = 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2662 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2663 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2664 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2665 | /* If data was modified, we need to touch to re-schedule sync */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2666 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2667 | } |
| 2668 | return 1; |
| 2669 | } |
| 2670 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2671 | /* Clear the General Purpose Counter 1 value from the stream's tracked |
| 2672 | * frontend counters and return its previous value into temp integer. |
| 2673 | * Supports being called as "sc[0-9]_clr_gpc1" or "src_clr_gpc1" only. |
| 2674 | */ |
| 2675 | static int |
| 2676 | smp_fetch_sc_clr_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2677 | { |
| 2678 | struct stkctr tmpstkctr; |
| 2679 | struct stkctr *stkctr; |
| 2680 | |
| 2681 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 2682 | if (!stkctr) |
| 2683 | return 0; |
| 2684 | |
| 2685 | smp->flags = SMP_F_VOL_TEST; |
| 2686 | smp->data.type = SMP_T_SINT; |
| 2687 | smp->data.u.sint = 0; |
| 2688 | |
| 2689 | if (!stkctr_entry(stkctr)) |
| 2690 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 2691 | |
| 2692 | if (stkctr && stkctr_entry(stkctr)) { |
| 2693 | void *ptr; |
| 2694 | |
| 2695 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 2696 | if (!ptr) { |
| 2697 | if (stkctr == &tmpstkctr) |
| 2698 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2699 | return 0; /* parameter not stored */ |
| 2700 | } |
| 2701 | |
| 2702 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2703 | |
| 2704 | smp->data.u.sint = stktable_data_cast(ptr, gpc1); |
| 2705 | stktable_data_cast(ptr, gpc1) = 0; |
| 2706 | |
| 2707 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 2708 | |
| 2709 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2710 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 2711 | } |
| 2712 | return 1; |
| 2713 | } |
| 2714 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2715 | /* set <smp> to the cumulated number of connections from the stream's tracked |
| 2716 | * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or |
| 2717 | * "src_conn_cnt" only. |
| 2718 | */ |
| 2719 | static int |
| 2720 | smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2721 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2722 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2723 | struct stkctr *stkctr; |
| 2724 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2725 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2726 | if (!stkctr) |
| 2727 | return 0; |
| 2728 | |
| 2729 | smp->flags = SMP_F_VOL_TEST; |
| 2730 | smp->data.type = SMP_T_SINT; |
| 2731 | smp->data.u.sint = 0; |
| 2732 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2733 | void *ptr; |
| 2734 | |
| 2735 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); |
| 2736 | if (!ptr) { |
| 2737 | if (stkctr == &tmpstkctr) |
| 2738 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2739 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2740 | } |
| 2741 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2742 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2743 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2744 | smp->data.u.sint = stktable_data_cast(ptr, conn_cnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2745 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2746 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2747 | |
| 2748 | if (stkctr == &tmpstkctr) |
| 2749 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 2750 | |
| 2751 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2752 | } |
| 2753 | return 1; |
| 2754 | } |
| 2755 | |
| 2756 | /* set <smp> to the connection rate from the stream's tracked frontend |
| 2757 | * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate" |
| 2758 | * only. |
| 2759 | */ |
| 2760 | static int |
| 2761 | smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2762 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2763 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2764 | struct stkctr *stkctr; |
| 2765 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2766 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2767 | if (!stkctr) |
| 2768 | return 0; |
| 2769 | |
| 2770 | smp->flags = SMP_F_VOL_TEST; |
| 2771 | smp->data.type = SMP_T_SINT; |
| 2772 | smp->data.u.sint = 0; |
| 2773 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2774 | void *ptr; |
| 2775 | |
| 2776 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); |
| 2777 | if (!ptr) { |
| 2778 | if (stkctr == &tmpstkctr) |
| 2779 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2780 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2781 | } |
| 2782 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2783 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2784 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2785 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), |
| 2786 | stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2787 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2788 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2789 | |
| 2790 | if (stkctr == &tmpstkctr) |
| 2791 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2792 | } |
| 2793 | return 1; |
| 2794 | } |
| 2795 | |
| 2796 | /* set temp integer to the number of connections from the stream's source address |
| 2797 | * in the table pointed to by expr, after updating it. |
| 2798 | * Accepts exactly 1 argument of type table. |
| 2799 | */ |
| 2800 | static int |
| 2801 | smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2802 | { |
| 2803 | struct connection *conn = objt_conn(smp->sess->origin); |
| 2804 | struct stksess *ts; |
| 2805 | struct stktable_key *key; |
| 2806 | void *ptr; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2807 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2808 | |
| 2809 | if (!conn) |
| 2810 | return 0; |
| 2811 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 2812 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2813 | if (!smp_fetch_src(NULL, smp, NULL, NULL)) |
| 2814 | return 0; |
| 2815 | |
| 2816 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2817 | key = smp_to_stkey(smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2818 | if (!key) |
| 2819 | return 0; |
| 2820 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2821 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2822 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2823 | if ((ts = stktable_get_entry(t, key)) == NULL) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2824 | /* entry does not exist and could not be created */ |
| 2825 | return 0; |
| 2826 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2827 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2828 | if (!ptr) { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2829 | return 0; /* parameter not stored in this table */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2830 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2831 | |
| 2832 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2833 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2834 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2835 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2836 | smp->data.u.sint = ++stktable_data_cast(ptr, conn_cnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2837 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2838 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2839 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2840 | smp->flags = SMP_F_VOL_TEST; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2841 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2842 | stktable_touch_local(t, ts, 1); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2843 | |
| 2844 | /* Touch was previously performed by stktable_update_key */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2845 | return 1; |
| 2846 | } |
| 2847 | |
| 2848 | /* set <smp> to the number of concurrent connections from the stream's tracked |
| 2849 | * frontend counters. Supports being called as "sc[0-9]_conn_cur" or |
| 2850 | * "src_conn_cur" only. |
| 2851 | */ |
| 2852 | static int |
| 2853 | smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2854 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2855 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2856 | struct stkctr *stkctr; |
| 2857 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2858 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2859 | if (!stkctr) |
| 2860 | return 0; |
| 2861 | |
| 2862 | smp->flags = SMP_F_VOL_TEST; |
| 2863 | smp->data.type = SMP_T_SINT; |
| 2864 | smp->data.u.sint = 0; |
| 2865 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2866 | void *ptr; |
| 2867 | |
| 2868 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); |
| 2869 | if (!ptr) { |
| 2870 | if (stkctr == &tmpstkctr) |
| 2871 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2872 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2873 | } |
| 2874 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2875 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2876 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2877 | smp->data.u.sint = stktable_data_cast(ptr, conn_cur); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2878 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2879 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2880 | |
| 2881 | if (stkctr == &tmpstkctr) |
| 2882 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2883 | } |
| 2884 | return 1; |
| 2885 | } |
| 2886 | |
| 2887 | /* set <smp> to the cumulated number of streams from the stream's tracked |
| 2888 | * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or |
| 2889 | * "src_sess_cnt" only. |
| 2890 | */ |
| 2891 | static int |
| 2892 | smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2893 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2894 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2895 | struct stkctr *stkctr; |
| 2896 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2897 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2898 | if (!stkctr) |
| 2899 | return 0; |
| 2900 | |
| 2901 | smp->flags = SMP_F_VOL_TEST; |
| 2902 | smp->data.type = SMP_T_SINT; |
| 2903 | smp->data.u.sint = 0; |
| 2904 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2905 | void *ptr; |
| 2906 | |
| 2907 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); |
| 2908 | if (!ptr) { |
| 2909 | if (stkctr == &tmpstkctr) |
| 2910 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2911 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2912 | } |
| 2913 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2914 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2915 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2916 | smp->data.u.sint = stktable_data_cast(ptr, sess_cnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2917 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2918 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2919 | |
| 2920 | if (stkctr == &tmpstkctr) |
| 2921 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2922 | } |
| 2923 | return 1; |
| 2924 | } |
| 2925 | |
| 2926 | /* set <smp> to the stream rate from the stream's tracked frontend counters. |
| 2927 | * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only. |
| 2928 | */ |
| 2929 | static int |
| 2930 | smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2931 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2932 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2933 | struct stkctr *stkctr; |
| 2934 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2935 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2936 | if (!stkctr) |
| 2937 | return 0; |
| 2938 | |
| 2939 | smp->flags = SMP_F_VOL_TEST; |
| 2940 | smp->data.type = SMP_T_SINT; |
| 2941 | smp->data.u.sint = 0; |
| 2942 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2943 | void *ptr; |
| 2944 | |
| 2945 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); |
| 2946 | if (!ptr) { |
| 2947 | if (stkctr == &tmpstkctr) |
| 2948 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2949 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2950 | } |
| 2951 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2952 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2953 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2954 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), |
| 2955 | stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2956 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2957 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2958 | |
| 2959 | if (stkctr == &tmpstkctr) |
| 2960 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2961 | } |
| 2962 | return 1; |
| 2963 | } |
| 2964 | |
| 2965 | /* set <smp> to the cumulated number of HTTP requests from the stream's tracked |
| 2966 | * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or |
| 2967 | * "src_http_req_cnt" only. |
| 2968 | */ |
| 2969 | static int |
| 2970 | smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2971 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2972 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2973 | struct stkctr *stkctr; |
| 2974 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2975 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2976 | if (!stkctr) |
| 2977 | return 0; |
| 2978 | |
| 2979 | smp->flags = SMP_F_VOL_TEST; |
| 2980 | smp->data.type = SMP_T_SINT; |
| 2981 | smp->data.u.sint = 0; |
| 2982 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2983 | void *ptr; |
| 2984 | |
| 2985 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
| 2986 | if (!ptr) { |
| 2987 | if (stkctr == &tmpstkctr) |
| 2988 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2989 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2990 | } |
| 2991 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2992 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2993 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2994 | smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2995 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2996 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2997 | |
| 2998 | if (stkctr == &tmpstkctr) |
| 2999 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3000 | } |
| 3001 | return 1; |
| 3002 | } |
| 3003 | |
| 3004 | /* set <smp> to the HTTP request rate from the stream's tracked frontend |
| 3005 | * counters. Supports being called as "sc[0-9]_http_req_rate" or |
| 3006 | * "src_http_req_rate" only. |
| 3007 | */ |
| 3008 | static int |
| 3009 | smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3010 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3011 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3012 | struct stkctr *stkctr; |
| 3013 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3014 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3015 | if (!stkctr) |
| 3016 | return 0; |
| 3017 | |
| 3018 | smp->flags = SMP_F_VOL_TEST; |
| 3019 | smp->data.type = SMP_T_SINT; |
| 3020 | smp->data.u.sint = 0; |
| 3021 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3022 | void *ptr; |
| 3023 | |
| 3024 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
| 3025 | if (!ptr) { |
| 3026 | if (stkctr == &tmpstkctr) |
| 3027 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3028 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3029 | } |
| 3030 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3031 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3032 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3033 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
| 3034 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3035 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3036 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3037 | |
| 3038 | if (stkctr == &tmpstkctr) |
| 3039 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3040 | } |
| 3041 | return 1; |
| 3042 | } |
| 3043 | |
| 3044 | /* set <smp> to the cumulated number of HTTP requests errors from the stream's |
| 3045 | * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or |
| 3046 | * "src_http_err_cnt" only. |
| 3047 | */ |
| 3048 | static int |
| 3049 | smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3050 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3051 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3052 | struct stkctr *stkctr; |
| 3053 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3054 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3055 | if (!stkctr) |
| 3056 | return 0; |
| 3057 | |
| 3058 | smp->flags = SMP_F_VOL_TEST; |
| 3059 | smp->data.type = SMP_T_SINT; |
| 3060 | smp->data.u.sint = 0; |
| 3061 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3062 | void *ptr; |
| 3063 | |
| 3064 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
| 3065 | if (!ptr) { |
| 3066 | if (stkctr == &tmpstkctr) |
| 3067 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3068 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3069 | } |
| 3070 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3071 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3072 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3073 | smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3074 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3075 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3076 | |
| 3077 | if (stkctr == &tmpstkctr) |
| 3078 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3079 | } |
| 3080 | return 1; |
| 3081 | } |
| 3082 | |
| 3083 | /* set <smp> to the HTTP request error rate from the stream's tracked frontend |
| 3084 | * counters. Supports being called as "sc[0-9]_http_err_rate" or |
| 3085 | * "src_http_err_rate" only. |
| 3086 | */ |
| 3087 | static int |
| 3088 | smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3089 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3090 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3091 | struct stkctr *stkctr; |
| 3092 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3093 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3094 | if (!stkctr) |
| 3095 | return 0; |
| 3096 | |
| 3097 | smp->flags = SMP_F_VOL_TEST; |
| 3098 | smp->data.type = SMP_T_SINT; |
| 3099 | smp->data.u.sint = 0; |
| 3100 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3101 | void *ptr; |
| 3102 | |
| 3103 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
| 3104 | if (!ptr) { |
| 3105 | if (stkctr == &tmpstkctr) |
| 3106 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3107 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3108 | } |
| 3109 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3110 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3111 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3112 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), |
| 3113 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3114 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3115 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3116 | |
| 3117 | if (stkctr == &tmpstkctr) |
| 3118 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3119 | } |
| 3120 | return 1; |
| 3121 | } |
| 3122 | |
| 3123 | /* set <smp> to the number of kbytes received from clients, as found in the |
| 3124 | * stream's tracked frontend counters. Supports being called as |
| 3125 | * "sc[0-9]_kbytes_in" or "src_kbytes_in" only. |
| 3126 | */ |
| 3127 | static int |
| 3128 | smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3129 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3130 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3131 | struct stkctr *stkctr; |
| 3132 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3133 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3134 | if (!stkctr) |
| 3135 | return 0; |
| 3136 | |
| 3137 | smp->flags = SMP_F_VOL_TEST; |
| 3138 | smp->data.type = SMP_T_SINT; |
| 3139 | smp->data.u.sint = 0; |
| 3140 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3141 | void *ptr; |
| 3142 | |
| 3143 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
| 3144 | if (!ptr) { |
| 3145 | if (stkctr == &tmpstkctr) |
| 3146 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3147 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3148 | } |
| 3149 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3150 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3151 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3152 | smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3153 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3154 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3155 | |
| 3156 | if (stkctr == &tmpstkctr) |
| 3157 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3158 | } |
| 3159 | return 1; |
| 3160 | } |
| 3161 | |
| 3162 | /* set <smp> to the data rate received from clients in bytes/s, as found |
| 3163 | * in the stream's tracked frontend counters. Supports being called as |
| 3164 | * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only. |
| 3165 | */ |
| 3166 | static int |
| 3167 | smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3168 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3169 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3170 | struct stkctr *stkctr; |
| 3171 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3172 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3173 | if (!stkctr) |
| 3174 | return 0; |
| 3175 | |
| 3176 | smp->flags = SMP_F_VOL_TEST; |
| 3177 | smp->data.type = SMP_T_SINT; |
| 3178 | smp->data.u.sint = 0; |
| 3179 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3180 | void *ptr; |
| 3181 | |
| 3182 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
| 3183 | if (!ptr) { |
| 3184 | if (stkctr == &tmpstkctr) |
| 3185 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3186 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3187 | } |
| 3188 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3189 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3190 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3191 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
| 3192 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3193 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3194 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3195 | |
| 3196 | if (stkctr == &tmpstkctr) |
| 3197 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3198 | } |
| 3199 | return 1; |
| 3200 | } |
| 3201 | |
| 3202 | /* set <smp> to the number of kbytes sent to clients, as found in the |
| 3203 | * stream's tracked frontend counters. Supports being called as |
| 3204 | * "sc[0-9]_kbytes_out" or "src_kbytes_out" only. |
| 3205 | */ |
| 3206 | static int |
| 3207 | smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3208 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3209 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3210 | struct stkctr *stkctr; |
| 3211 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3212 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3213 | if (!stkctr) |
| 3214 | return 0; |
| 3215 | |
| 3216 | smp->flags = SMP_F_VOL_TEST; |
| 3217 | smp->data.type = SMP_T_SINT; |
| 3218 | smp->data.u.sint = 0; |
| 3219 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3220 | void *ptr; |
| 3221 | |
| 3222 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
| 3223 | if (!ptr) { |
| 3224 | if (stkctr == &tmpstkctr) |
| 3225 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3226 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3227 | } |
| 3228 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3229 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3230 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3231 | smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3232 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3233 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3234 | |
| 3235 | if (stkctr == &tmpstkctr) |
| 3236 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3237 | } |
| 3238 | return 1; |
| 3239 | } |
| 3240 | |
| 3241 | /* set <smp> to the data rate sent to clients in bytes/s, as found in the |
| 3242 | * stream's tracked frontend counters. Supports being called as |
| 3243 | * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. |
| 3244 | */ |
| 3245 | static int |
| 3246 | smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3247 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3248 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3249 | struct stkctr *stkctr; |
| 3250 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3251 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3252 | if (!stkctr) |
| 3253 | return 0; |
| 3254 | |
| 3255 | smp->flags = SMP_F_VOL_TEST; |
| 3256 | smp->data.type = SMP_T_SINT; |
| 3257 | smp->data.u.sint = 0; |
| 3258 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3259 | void *ptr; |
| 3260 | |
| 3261 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
| 3262 | if (!ptr) { |
| 3263 | if (stkctr == &tmpstkctr) |
| 3264 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3265 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3266 | } |
| 3267 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3268 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3269 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3270 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
| 3271 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3272 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3273 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3274 | |
| 3275 | if (stkctr == &tmpstkctr) |
| 3276 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3277 | } |
| 3278 | return 1; |
| 3279 | } |
| 3280 | |
| 3281 | /* set <smp> to the number of active trackers on the SC entry in the stream's |
| 3282 | * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only. |
| 3283 | */ |
| 3284 | static int |
| 3285 | smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3286 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3287 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3288 | struct stkctr *stkctr; |
| 3289 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3290 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3291 | if (!stkctr) |
| 3292 | return 0; |
| 3293 | |
| 3294 | smp->flags = SMP_F_VOL_TEST; |
| 3295 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3296 | if (stkctr == &tmpstkctr) { |
| 3297 | smp->data.u.sint = stkctr_entry(stkctr) ? (stkctr_entry(stkctr)->ref_cnt-1) : 0; |
| 3298 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3299 | } |
| 3300 | else { |
| 3301 | smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0; |
| 3302 | } |
| 3303 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3304 | return 1; |
| 3305 | } |
| 3306 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3307 | |
| 3308 | /* The functions below are used to manipulate table contents from the CLI. |
| 3309 | * There are 3 main actions, "clear", "set" and "show". The code is shared |
| 3310 | * between all actions, and the action is encoded in the void *private in |
| 3311 | * the appctx as well as in the keyword registration, among one of the |
| 3312 | * following values. |
| 3313 | */ |
| 3314 | |
| 3315 | enum { |
| 3316 | STK_CLI_ACT_CLR, |
| 3317 | STK_CLI_ACT_SET, |
| 3318 | STK_CLI_ACT_SHOW, |
| 3319 | }; |
| 3320 | |
| 3321 | /* Dump the status of a table to a stream interface's |
| 3322 | * read buffer. It returns 0 if the output buffer is full |
| 3323 | * and needs to be called again, otherwise non-zero. |
| 3324 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3325 | static int table_dump_head_to_buffer(struct buffer *msg, |
| 3326 | struct stream_interface *si, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3327 | struct stktable *t, struct stktable *target) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3328 | { |
| 3329 | struct stream *s = si_strm(si); |
| 3330 | |
| 3331 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3332 | t->id, stktable_types[t->type].kw, t->size, t->current); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3333 | |
| 3334 | /* any other information should be dumped here */ |
| 3335 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 3336 | if (target && (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) < ACCESS_LVL_OPER) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3337 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
| 3338 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3339 | if (ci_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3340 | si_rx_room_blk(si); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3341 | return 0; |
| 3342 | } |
| 3343 | |
| 3344 | return 1; |
| 3345 | } |
| 3346 | |
| 3347 | /* Dump a table entry to a stream interface's |
| 3348 | * read buffer. It returns 0 if the output buffer is full |
| 3349 | * and needs to be called again, otherwise non-zero. |
| 3350 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3351 | static int table_dump_entry_to_buffer(struct buffer *msg, |
| 3352 | struct stream_interface *si, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3353 | struct stktable *t, struct stksess *entry) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3354 | { |
| 3355 | int dt; |
| 3356 | |
| 3357 | chunk_appendf(msg, "%p:", entry); |
| 3358 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3359 | if (t->type == SMP_T_IPV4) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3360 | char addr[INET_ADDRSTRLEN]; |
| 3361 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 3362 | chunk_appendf(msg, " key=%s", addr); |
| 3363 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3364 | else if (t->type == SMP_T_IPV6) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3365 | char addr[INET6_ADDRSTRLEN]; |
| 3366 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 3367 | chunk_appendf(msg, " key=%s", addr); |
| 3368 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3369 | else if (t->type == SMP_T_SINT) { |
Willy Tarreau | 6cde5d8 | 2020-02-25 09:41:22 +0100 | [diff] [blame] | 3370 | chunk_appendf(msg, " key=%u", read_u32(entry->key.key)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3371 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3372 | else if (t->type == SMP_T_STR) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3373 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3374 | dump_text(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3375 | } |
| 3376 | else { |
| 3377 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3378 | dump_binary(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire)); |
| 3382 | |
| 3383 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 3384 | void *ptr; |
| 3385 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3386 | if (t->data_ofs[dt] == 0) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3387 | continue; |
| 3388 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3389 | chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, t->data_arg[dt].u); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3390 | else |
| 3391 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
| 3392 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3393 | ptr = stktable_data_ptr(t, entry, dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3394 | switch (stktable_data_types[dt].std_type) { |
| 3395 | case STD_T_SINT: |
| 3396 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 3397 | break; |
| 3398 | case STD_T_UINT: |
| 3399 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 3400 | break; |
| 3401 | case STD_T_ULL: |
| 3402 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
| 3403 | break; |
| 3404 | case STD_T_FRQP: |
| 3405 | chunk_appendf(msg, "%d", |
| 3406 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3407 | t->data_arg[dt].u)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3408 | break; |
Frédéric Lécaille | 16b4f54 | 2019-05-23 12:15:04 +0200 | [diff] [blame] | 3409 | case STD_T_DICT: { |
| 3410 | struct dict_entry *de; |
| 3411 | de = stktable_data_cast(ptr, std_t_dict); |
| 3412 | chunk_appendf(msg, "%s", de ? (char *)de->value.key : "-"); |
| 3413 | break; |
| 3414 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3415 | } |
| 3416 | } |
| 3417 | chunk_appendf(msg, "\n"); |
| 3418 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3419 | if (ci_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3420 | si_rx_room_blk(si); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3421 | return 0; |
| 3422 | } |
| 3423 | |
| 3424 | return 1; |
| 3425 | } |
| 3426 | |
| 3427 | |
| 3428 | /* Processes a single table entry matching a specific key passed in argument. |
| 3429 | * returns 0 if wants to be called again, 1 if has ended processing. |
| 3430 | */ |
| 3431 | static int table_process_entry_per_key(struct appctx *appctx, char **args) |
| 3432 | { |
| 3433 | struct stream_interface *si = appctx->owner; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3434 | struct stktable *t = appctx->ctx.table.target; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3435 | struct stksess *ts; |
| 3436 | uint32_t uint32_key; |
| 3437 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
| 3438 | long long value; |
| 3439 | int data_type; |
| 3440 | int cur_arg; |
| 3441 | void *ptr; |
| 3442 | struct freq_ctr_period *frqp; |
| 3443 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3444 | if (!*args[4]) |
| 3445 | return cli_err(appctx, "Key value expected\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3446 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3447 | switch (t->type) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3448 | case SMP_T_IPV4: |
| 3449 | uint32_key = htonl(inetaddr_host(args[4])); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 3450 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3451 | break; |
| 3452 | case SMP_T_IPV6: |
| 3453 | inet_pton(AF_INET6, args[4], ip6_key); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 3454 | static_table_key.key = &ip6_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3455 | break; |
| 3456 | case SMP_T_SINT: |
| 3457 | { |
| 3458 | char *endptr; |
| 3459 | unsigned long val; |
| 3460 | errno = 0; |
| 3461 | val = strtoul(args[4], &endptr, 10); |
| 3462 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 3463 | (errno != 0 && val == 0) || endptr == args[4] || |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3464 | val > 0xffffffff) |
| 3465 | return cli_err(appctx, "Invalid key\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3466 | uint32_key = (uint32_t) val; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 3467 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3468 | break; |
| 3469 | } |
| 3470 | break; |
| 3471 | case SMP_T_STR: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 3472 | static_table_key.key = args[4]; |
| 3473 | static_table_key.key_len = strlen(args[4]); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3474 | break; |
| 3475 | default: |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 3476 | switch (appctx->ctx.table.action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3477 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3478 | return cli_err(appctx, "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3479 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3480 | return cli_err(appctx, "Removing keys from tables of type other than ip, ipv6, string and integer is not supported\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3481 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3482 | return cli_err(appctx, "Inserting keys into tables of type other than ip, ipv6, string and integer is not supported\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3483 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3484 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3485 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | /* check permissions */ |
| 3489 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 3490 | return 1; |
| 3491 | |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 3492 | switch (appctx->ctx.table.action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3493 | case STK_CLI_ACT_SHOW: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3494 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3495 | if (!ts) |
| 3496 | return 1; |
| 3497 | chunk_reset(&trash); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3498 | if (!table_dump_head_to_buffer(&trash, si, t, t)) { |
| 3499 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3500 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3501 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3502 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3503 | if (!table_dump_entry_to_buffer(&trash, si, t, ts)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3504 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3505 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3506 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3507 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3508 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3509 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3510 | break; |
| 3511 | |
| 3512 | case STK_CLI_ACT_CLR: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3513 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3514 | if (!ts) |
| 3515 | return 1; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3516 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3517 | if (!stksess_kill(t, ts, 1)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3518 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3519 | return cli_err(appctx, "Entry currently in use, cannot remove\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3520 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3521 | break; |
| 3522 | |
| 3523 | case STK_CLI_ACT_SET: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3524 | ts = stktable_get_entry(t, &static_table_key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3525 | if (!ts) { |
| 3526 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3527 | return cli_err(appctx, "Unable to allocate a new entry\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3528 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3529 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3530 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 3531 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3532 | cli_err(appctx, "\"data.<type>\" followed by a value expected\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3533 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3534 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3535 | return 1; |
| 3536 | } |
| 3537 | |
| 3538 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 3539 | if (data_type < 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3540 | cli_err(appctx, "Unknown data type\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3541 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3542 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3543 | return 1; |
| 3544 | } |
| 3545 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3546 | if (!t->data_ofs[data_type]) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3547 | cli_err(appctx, "Data type not stored in this table\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3548 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3549 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3550 | return 1; |
| 3551 | } |
| 3552 | |
| 3553 | if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3554 | cli_err(appctx, "Require a valid integer value to store\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3555 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3556 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3557 | return 1; |
| 3558 | } |
| 3559 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3560 | ptr = stktable_data_ptr(t, ts, data_type); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3561 | |
| 3562 | switch (stktable_data_types[data_type].std_type) { |
| 3563 | case STD_T_SINT: |
| 3564 | stktable_data_cast(ptr, std_t_sint) = value; |
| 3565 | break; |
| 3566 | case STD_T_UINT: |
| 3567 | stktable_data_cast(ptr, std_t_uint) = value; |
| 3568 | break; |
| 3569 | case STD_T_ULL: |
| 3570 | stktable_data_cast(ptr, std_t_ull) = value; |
| 3571 | break; |
| 3572 | case STD_T_FRQP: |
| 3573 | /* We set both the current and previous values. That way |
| 3574 | * the reported frequency is stable during all the period |
| 3575 | * then slowly fades out. This allows external tools to |
| 3576 | * push measures without having to update them too often. |
| 3577 | */ |
| 3578 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 3579 | /* First bit is reserved for the freq_ctr_period lock |
| 3580 | Note: here we're still protected by the stksess lock |
| 3581 | so we don't need to update the update the freq_ctr_period |
| 3582 | using its internal lock */ |
| 3583 | frqp->curr_tick = now_ms & ~0x1; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3584 | frqp->prev_ctr = 0; |
| 3585 | frqp->curr_ctr = value; |
| 3586 | break; |
| 3587 | } |
| 3588 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3589 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3590 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3591 | break; |
| 3592 | |
| 3593 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3594 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3595 | } |
| 3596 | return 1; |
| 3597 | } |
| 3598 | |
| 3599 | /* Prepares the appctx fields with the data-based filters from the command line. |
| 3600 | * Returns 0 if the dump can proceed, 1 if has ended processing. |
| 3601 | */ |
| 3602 | static int table_prepare_data_request(struct appctx *appctx, char **args) |
| 3603 | { |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3604 | int i; |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 3605 | char *err = NULL; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3606 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3607 | if (appctx->ctx.table.action != STK_CLI_ACT_SHOW && appctx->ctx.table.action != STK_CLI_ACT_CLR) |
| 3608 | return cli_err(appctx, "content-based lookup is only supported with the \"show\" and \"clear\" actions\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3609 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3610 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
| 3611 | if (i > 0 && !*args[3+3*i]) // number of filter entries can be less than STKTABLE_FILTER_LEN |
| 3612 | break; |
| 3613 | /* condition on stored data value */ |
| 3614 | appctx->ctx.table.data_type[i] = stktable_get_data_type(args[3+3*i] + 5); |
| 3615 | if (appctx->ctx.table.data_type[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 3616 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Unknown data type\n", i + 1)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3617 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3618 | if (!((struct stktable *)appctx->ctx.table.target)->data_ofs[appctx->ctx.table.data_type[i]]) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 3619 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Data type not stored in this table\n", i + 1)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3620 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3621 | appctx->ctx.table.data_op[i] = get_std_op(args[4+3*i]); |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 3622 | if (appctx->ctx.table.data_op[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 3623 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n", i + 1)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3624 | |
Adis Nezirovic | 56dd354 | 2020-01-22 16:16:48 +0100 | [diff] [blame] | 3625 | if (!*args[5+3*i] || strl2llrc(args[5+3*i], strlen(args[5+3*i]), &appctx->ctx.table.value[i]) != 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 3626 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require a valid integer value to compare against\n", i + 1)); |
| 3627 | } |
| 3628 | |
| 3629 | if (*args[3+3*i]) { |
| 3630 | return cli_dynerr(appctx, memprintf(&err, "Detected extra data in filter, %ith word of input, after '%s'\n", 3+3*i + 1, args[2+3*i])); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3631 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3632 | |
| 3633 | /* OK we're done, all the fields are set */ |
| 3634 | return 0; |
| 3635 | } |
| 3636 | |
| 3637 | /* returns 0 if wants to be called, 1 if has ended processing */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 3638 | static int cli_parse_table_req(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3639 | { |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3640 | int i; |
| 3641 | |
| 3642 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) |
| 3643 | appctx->ctx.table.data_type[i] = -1; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3644 | appctx->ctx.table.target = NULL; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3645 | appctx->ctx.table.entry = NULL; |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 3646 | appctx->ctx.table.action = (long)private; // keyword argument, one of STK_CLI_ACT_* |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3647 | |
| 3648 | if (*args[2]) { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3649 | appctx->ctx.table.target = stktable_find_by_name(args[2]); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3650 | if (!appctx->ctx.table.target) |
| 3651 | return cli_err(appctx, "No such table\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3652 | } |
| 3653 | else { |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 3654 | if (appctx->ctx.table.action != STK_CLI_ACT_SHOW) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3655 | goto err_args; |
| 3656 | return 0; |
| 3657 | } |
| 3658 | |
| 3659 | if (strcmp(args[3], "key") == 0) |
| 3660 | return table_process_entry_per_key(appctx, args); |
| 3661 | else if (strncmp(args[3], "data.", 5) == 0) |
| 3662 | return table_prepare_data_request(appctx, args); |
| 3663 | else if (*args[3]) |
| 3664 | goto err_args; |
| 3665 | |
| 3666 | return 0; |
| 3667 | |
| 3668 | err_args: |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 3669 | switch (appctx->ctx.table.action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3670 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3671 | return cli_err(appctx, "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3672 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3673 | return cli_err(appctx, "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3674 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3675 | return cli_err(appctx, "Required arguments: <table> key <key> [data.<store_data_type> <value>]*\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3676 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 3677 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3678 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | /* This function is used to deal with table operations (dump or clear depending |
| 3682 | * on the action stored in appctx->private). It returns 0 if the output buffer is |
| 3683 | * full and it needs to be called again, otherwise non-zero. |
| 3684 | */ |
| 3685 | static int cli_io_handler_table(struct appctx *appctx) |
| 3686 | { |
| 3687 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3688 | struct stream *s = si_strm(si); |
| 3689 | struct ebmb_node *eb; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3690 | int skip_entry; |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 3691 | int show = appctx->ctx.table.action == STK_CLI_ACT_SHOW; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3692 | |
| 3693 | /* |
| 3694 | * We have 3 possible states in appctx->st2 : |
| 3695 | * - STAT_ST_INIT : the first call |
| 3696 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
| 3697 | * dump, the entry pointer is NULL ; |
| 3698 | * - STAT_ST_LIST : the proxy pointer points to the current table |
| 3699 | * and the entry pointer points to the next entry to be dumped, |
| 3700 | * and the refcount on the next entry is held ; |
| 3701 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
| 3702 | * data though. |
| 3703 | */ |
| 3704 | |
| 3705 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
| 3706 | /* in case of abort, remove any refcount we might have set on an entry */ |
| 3707 | if (appctx->st2 == STAT_ST_LIST) { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3708 | stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3709 | } |
| 3710 | return 1; |
| 3711 | } |
| 3712 | |
| 3713 | chunk_reset(&trash); |
| 3714 | |
| 3715 | while (appctx->st2 != STAT_ST_FIN) { |
| 3716 | switch (appctx->st2) { |
| 3717 | case STAT_ST_INIT: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3718 | appctx->ctx.table.t = appctx->ctx.table.target; |
| 3719 | if (!appctx->ctx.table.t) |
| 3720 | appctx->ctx.table.t = stktables_list; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3721 | |
| 3722 | appctx->ctx.table.entry = NULL; |
| 3723 | appctx->st2 = STAT_ST_INFO; |
| 3724 | break; |
| 3725 | |
| 3726 | case STAT_ST_INFO: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3727 | if (!appctx->ctx.table.t || |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3728 | (appctx->ctx.table.target && |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3729 | appctx->ctx.table.t != appctx->ctx.table.target)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3730 | appctx->st2 = STAT_ST_END; |
| 3731 | break; |
| 3732 | } |
| 3733 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3734 | if (appctx->ctx.table.t->size) { |
| 3735 | if (show && !table_dump_head_to_buffer(&trash, si, appctx->ctx.table.t, appctx->ctx.table.target)) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3736 | return 0; |
| 3737 | |
| 3738 | if (appctx->ctx.table.target && |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 3739 | (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3740 | /* dump entries only if table explicitly requested */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3741 | HA_SPIN_LOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock); |
| 3742 | eb = ebmb_first(&appctx->ctx.table.t->keys); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3743 | if (eb) { |
| 3744 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 3745 | appctx->ctx.table.entry->ref_cnt++; |
| 3746 | appctx->st2 = STAT_ST_LIST; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3747 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3748 | break; |
| 3749 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3750 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3751 | } |
| 3752 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3753 | appctx->ctx.table.t = appctx->ctx.table.t->next; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3754 | break; |
| 3755 | |
| 3756 | case STAT_ST_LIST: |
| 3757 | skip_entry = 0; |
| 3758 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3759 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3760 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3761 | if (appctx->ctx.table.data_type[0] >= 0) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3762 | /* we're filtering on some data contents */ |
| 3763 | void *ptr; |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 3764 | int dt, i; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3765 | signed char op; |
| 3766 | long long data, value; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3767 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3768 | |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 3769 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3770 | if (appctx->ctx.table.data_type[i] == -1) |
| 3771 | break; |
| 3772 | dt = appctx->ctx.table.data_type[i]; |
| 3773 | ptr = stktable_data_ptr(appctx->ctx.table.t, |
| 3774 | appctx->ctx.table.entry, |
| 3775 | dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3776 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3777 | data = 0; |
| 3778 | switch (stktable_data_types[dt].std_type) { |
| 3779 | case STD_T_SINT: |
| 3780 | data = stktable_data_cast(ptr, std_t_sint); |
| 3781 | break; |
| 3782 | case STD_T_UINT: |
| 3783 | data = stktable_data_cast(ptr, std_t_uint); |
| 3784 | break; |
| 3785 | case STD_T_ULL: |
| 3786 | data = stktable_data_cast(ptr, std_t_ull); |
| 3787 | break; |
| 3788 | case STD_T_FRQP: |
| 3789 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 3790 | appctx->ctx.table.t->data_arg[dt].u); |
| 3791 | break; |
| 3792 | } |
| 3793 | |
| 3794 | op = appctx->ctx.table.data_op[i]; |
| 3795 | value = appctx->ctx.table.value[i]; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3796 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 3797 | /* skip the entry if the data does not match the test and the value */ |
| 3798 | if ((data < value && |
| 3799 | (op == STD_OP_EQ || op == STD_OP_GT || op == STD_OP_GE)) || |
| 3800 | (data == value && |
| 3801 | (op == STD_OP_NE || op == STD_OP_GT || op == STD_OP_LT)) || |
| 3802 | (data > value && |
| 3803 | (op == STD_OP_EQ || op == STD_OP_LT || op == STD_OP_LE))) { |
| 3804 | skip_entry = 1; |
| 3805 | break; |
| 3806 | } |
| 3807 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | if (show && !skip_entry && |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3811 | !table_dump_entry_to_buffer(&trash, si, appctx->ctx.table.t, appctx->ctx.table.entry)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3812 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3813 | return 0; |
| 3814 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3815 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3816 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &appctx->ctx.table.entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3817 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3818 | HA_SPIN_LOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3819 | appctx->ctx.table.entry->ref_cnt--; |
| 3820 | |
| 3821 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
| 3822 | if (eb) { |
| 3823 | struct stksess *old = appctx->ctx.table.entry; |
| 3824 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 3825 | if (show) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3826 | __stksess_kill_if_expired(appctx->ctx.table.t, old); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3827 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3828 | __stksess_kill(appctx->ctx.table.t, old); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3829 | appctx->ctx.table.entry->ref_cnt++; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3830 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3831 | break; |
| 3832 | } |
| 3833 | |
| 3834 | |
| 3835 | if (show) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3836 | __stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3837 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3838 | __stksess_kill(appctx->ctx.table.t, appctx->ctx.table.entry); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3839 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3840 | HA_SPIN_UNLOCK(STK_TABLE_LOCK, &appctx->ctx.table.t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3841 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3842 | appctx->ctx.table.t = appctx->ctx.table.t->next; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3843 | appctx->st2 = STAT_ST_INFO; |
| 3844 | break; |
| 3845 | |
| 3846 | case STAT_ST_END: |
| 3847 | appctx->st2 = STAT_ST_FIN; |
| 3848 | break; |
| 3849 | } |
| 3850 | } |
| 3851 | return 1; |
| 3852 | } |
| 3853 | |
| 3854 | static void cli_release_show_table(struct appctx *appctx) |
| 3855 | { |
| 3856 | if (appctx->st2 == STAT_ST_LIST) { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3857 | stksess_kill_if_expired(appctx->ctx.table.t, appctx->ctx.table.entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | /* register cli keywords */ |
| 3862 | static struct cli_kw_list cli_kws = {{ },{ |
| 3863 | { { "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 }, |
| 3864 | { { "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 }, |
| 3865 | { { "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 }, |
| 3866 | {{},} |
| 3867 | }}; |
| 3868 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3869 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 3870 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3871 | static struct action_kw_list tcp_conn_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3872 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3873 | { "sc-inc-gpc1", parse_inc_gpc1, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3874 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 3875 | { /* END */ } |
| 3876 | }}; |
| 3877 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3878 | INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws); |
| 3879 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 3880 | static struct action_kw_list tcp_sess_kws = { { }, { |
| 3881 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3882 | { "sc-inc-gpc1", parse_inc_gpc1, 1 }, |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 3883 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 3884 | { /* END */ } |
| 3885 | }}; |
| 3886 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3887 | INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws); |
| 3888 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3889 | static struct action_kw_list tcp_req_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3890 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3891 | { "sc-inc-gpc1", parse_inc_gpc1, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3892 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 3893 | { /* END */ } |
| 3894 | }}; |
| 3895 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3896 | INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_kws); |
| 3897 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3898 | static struct action_kw_list tcp_res_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3899 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3900 | { "sc-inc-gpc1", parse_inc_gpc1, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3901 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 3902 | { /* END */ } |
| 3903 | }}; |
| 3904 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3905 | INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws); |
| 3906 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3907 | static struct action_kw_list http_req_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3908 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3909 | { "sc-inc-gpc1", parse_inc_gpc1, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3910 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 3911 | { /* END */ } |
| 3912 | }}; |
| 3913 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3914 | INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws); |
| 3915 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3916 | static struct action_kw_list http_res_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 3917 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3918 | { "sc-inc-gpc1", parse_inc_gpc1, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 3919 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 3920 | { /* END */ } |
| 3921 | }}; |
| 3922 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 3923 | INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws); |
| 3924 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3925 | ///* Note: must not be declared <const> as its list will be overwritten. |
| 3926 | // * Please take care of keeping this list alphabetically sorted. |
| 3927 | // */ |
| 3928 | //static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 3929 | // { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3930 | // { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3931 | // { /* END */ }, |
| 3932 | //}}; |
| 3933 | /* Note: must not be declared <const> as its list will be overwritten. |
| 3934 | * Please take care of keeping this list alphabetically sorted. |
| 3935 | */ |
| 3936 | static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 3937 | { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3938 | { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3939 | { "sc_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3940 | { "sc_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3941 | { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3942 | { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3943 | { "sc_conn_rate", smp_fetch_sc_conn_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Thierry FOURNIER | 401c64b | 2017-01-05 11:44:09 +0100 | [diff] [blame] | 3944 | { "sc_get_gpt0", smp_fetch_sc_get_gpt0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3945 | { "sc_get_gpc0", smp_fetch_sc_get_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3946 | { "sc_get_gpc1", smp_fetch_sc_get_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3947 | { "sc_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3948 | { "sc_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3949 | { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3950 | { "sc_http_err_rate", smp_fetch_sc_http_err_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3951 | { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3952 | { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3953 | { "sc_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3954 | { "sc_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3955 | { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 3956 | { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 3957 | { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3958 | { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3959 | { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 3960 | { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3961 | { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3962 | { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3963 | { "sc0_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3964 | { "sc0_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3965 | { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3966 | { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3967 | { "sc0_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Thierry FOURNIER | 401c64b | 2017-01-05 11:44:09 +0100 | [diff] [blame] | 3968 | { "sc0_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3969 | { "sc0_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3970 | { "sc0_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3971 | { "sc0_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3972 | { "sc0_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3973 | { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3974 | { "sc0_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3975 | { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3976 | { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3977 | { "sc0_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3978 | { "sc0_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3979 | { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 3980 | { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 3981 | { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3982 | { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3983 | { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 3984 | { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3985 | { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3986 | { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3987 | { "sc1_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3988 | { "sc1_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3989 | { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3990 | { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3991 | { "sc1_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Thierry FOURNIER | 401c64b | 2017-01-05 11:44:09 +0100 | [diff] [blame] | 3992 | { "sc1_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3993 | { "sc1_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3994 | { "sc1_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3995 | { "sc1_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3996 | { "sc1_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3997 | { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3998 | { "sc1_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 3999 | { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4000 | { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4001 | { "sc1_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4002 | { "sc1_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4003 | { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4004 | { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4005 | { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4006 | { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4007 | { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 4008 | { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4009 | { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4010 | { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4011 | { "sc2_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4012 | { "sc2_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4013 | { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4014 | { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4015 | { "sc2_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Thierry FOURNIER | 401c64b | 2017-01-05 11:44:09 +0100 | [diff] [blame] | 4016 | { "sc2_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4017 | { "sc2_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4018 | { "sc2_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4019 | { "sc2_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4020 | { "sc2_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4021 | { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4022 | { "sc2_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4023 | { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4024 | { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4025 | { "sc2_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4026 | { "sc2_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4027 | { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4028 | { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4029 | { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4030 | { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4031 | { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 4032 | { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4033 | { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4034 | { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4035 | { "src_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4036 | { "src_clr_gpc1", smp_fetch_sc_clr_gpc1, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4037 | { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4038 | { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4039 | { "src_conn_rate", smp_fetch_sc_conn_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Thierry FOURNIER | 401c64b | 2017-01-05 11:44:09 +0100 | [diff] [blame] | 4040 | { "src_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4041 | { "src_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4042 | { "src_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4043 | { "src_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4044 | { "src_gpc1_rate", smp_fetch_sc_gpc1_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4045 | { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4046 | { "src_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4047 | { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4048 | { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4049 | { "src_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4050 | { "src_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4051 | { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4052 | { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4053 | { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4054 | { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4055 | { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 4056 | { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4057 | { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 4058 | { /* END */ }, |
| 4059 | }}; |
| 4060 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 4061 | INITCALL1(STG_REGISTER, sample_register_fetches, &smp_fetch_keywords); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4062 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 4063 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 4064 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 4065 | { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL }, |
| 4066 | { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4067 | { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4068 | { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4069 | { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4070 | { "table_conn_rate", sample_conv_table_conn_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4071 | { "table_gpt0", sample_conv_table_gpt0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4072 | { "table_gpc0", sample_conv_table_gpc0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4073 | { "table_gpc1", sample_conv_table_gpc1, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 4074 | { "table_gpc0_rate", sample_conv_table_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 4075 | { "table_gpc1_rate", sample_conv_table_gpc1_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 4076 | { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4077 | { "table_http_err_rate", sample_conv_table_http_err_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4078 | { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4079 | { "table_http_req_rate", sample_conv_table_http_req_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4080 | { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4081 | { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4082 | { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4083 | { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4084 | { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 4085 | { "table_trackers", sample_conv_table_trackers, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 4086 | { /* END */ }, |
| 4087 | }}; |
| 4088 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 4089 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |