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