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