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