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 | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 22 | #include <haproxy/applet.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 23 | #include <haproxy/arg.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 24 | #include <haproxy/cfgparse.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 25 | #include <haproxy/cli.h> |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 26 | #include <haproxy/dict.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 27 | #include <haproxy/errors.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 28 | #include <haproxy/global.h> |
Willy Tarreau | c761f84 | 2020-06-04 11:40:28 +0200 | [diff] [blame] | 29 | #include <haproxy/http_rules.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 30 | #include <haproxy/list.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 31 | #include <haproxy/log.h> |
Willy Tarreau | 6131d6a | 2020-06-02 16:48:09 +0200 | [diff] [blame] | 32 | #include <haproxy/net_helper.h> |
Willy Tarreau | 3c2a7c2 | 2020-06-04 18:38:21 +0200 | [diff] [blame] | 33 | #include <haproxy/peers.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 34 | #include <haproxy/pool.h> |
| 35 | #include <haproxy/proto_tcp.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 36 | #include <haproxy/proxy.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 37 | #include <haproxy/sample.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 38 | #include <haproxy/sc_strm.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 39 | #include <haproxy/stats-t.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 40 | #include <haproxy/stconn.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 41 | #include <haproxy/stick_table.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 42 | #include <haproxy/stream.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 43 | #include <haproxy/task.h> |
Willy Tarreau | 8b550af | 2020-06-04 17:42:48 +0200 | [diff] [blame] | 44 | #include <haproxy/tcp_rules.h> |
Willy Tarreau | 9310f48 | 2021-10-06 16:18:40 +0200 | [diff] [blame] | 45 | #include <haproxy/ticks.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 46 | #include <haproxy/tools.h> |
Willy Tarreau | a472858 | 2022-11-24 07:35:17 +0100 | [diff] [blame] | 47 | #include <haproxy/xxhash.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 48 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 49 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 50 | /* structure used to return a table key built from a sample */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 51 | static THREAD_LOCAL struct stktable_key static_table_key; |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 52 | static int (*smp_fetch_src)(const struct arg *, struct sample *, const char *, void *); |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 53 | struct pool_head *pool_head_stk_ctr __read_mostly = NULL; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 54 | struct stktable *stktables_list; |
| 55 | struct eb_root stktable_by_name = EB_ROOT; |
| 56 | |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 57 | #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] | 58 | |
| 59 | /* This function inserts stktable <t> into the tree of known stick-table. |
| 60 | * The stick-table ID is used as the storing key so it must already have |
| 61 | * been initialized. |
| 62 | */ |
| 63 | void stktable_store_name(struct stktable *t) |
| 64 | { |
| 65 | t->name.key = t->id; |
| 66 | ebis_insert(&stktable_by_name, &t->name); |
| 67 | } |
| 68 | |
| 69 | struct stktable *stktable_find_by_name(const char *name) |
| 70 | { |
| 71 | struct ebpt_node *node; |
| 72 | struct stktable *t; |
| 73 | |
| 74 | node = ebis_lookup(&stktable_by_name, name); |
| 75 | if (node) { |
| 76 | t = container_of(node, struct stktable, name); |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 77 | if (strcmp(t->id, name) == 0) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 78 | return t; |
| 79 | } |
| 80 | |
| 81 | return NULL; |
| 82 | } |
| 83 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 84 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 85 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 86 | * in table <t>. It's safe to call it under or out of a lock. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 87 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 88 | void __stksess_free(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 89 | { |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 90 | HA_ATOMIC_DEC(&t->current); |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 91 | pool_free(t->pool, (void *)ts - round_ptr_size(t->data_size)); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 95 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
| 96 | * in table <t>. |
| 97 | * This function locks the table |
| 98 | */ |
| 99 | void stksess_free(struct stktable *t, struct stksess *ts) |
| 100 | { |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 101 | void *data; |
| 102 | data = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_KEY); |
| 103 | if (data) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 104 | dict_entry_unref(&server_key_dict, stktable_data_cast(data, std_t_dict)); |
| 105 | stktable_data_cast(data, std_t_dict) = NULL; |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 106 | } |
Willy Tarreau | 8d3c333 | 2022-10-11 18:50:22 +0000 | [diff] [blame] | 107 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 108 | __stksess_free(t, ts); |
Willy Tarreau | 8d3c333 | 2022-10-11 18:50:22 +0000 | [diff] [blame] | 109 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 113 | * Kill an stksess (only if its ref_cnt is zero). |
| 114 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 115 | int __stksess_kill(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 116 | { |
| 117 | if (ts->ref_cnt) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 118 | return 0; |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 119 | |
| 120 | eb32_delete(&ts->exp); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 121 | eb32_delete(&ts->upd); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 122 | ebmb_delete(&ts->key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 123 | __stksess_free(t, ts); |
| 124 | return 1; |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 128 | * Decrease the refcount if decrefcnt is not 0. |
| 129 | * and try to kill the stksess |
| 130 | * This function locks the table |
| 131 | */ |
| 132 | int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt) |
| 133 | { |
| 134 | int ret; |
| 135 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 136 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 137 | if (decrefcnt) |
| 138 | ts->ref_cnt--; |
| 139 | ret = __stksess_kill(t, ts); |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 140 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 146 | * Initialize or update the key in the sticky session <ts> present in table <t> |
| 147 | * from the value present in <key>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 148 | */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 149 | 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] | 150 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 151 | if (t->type != SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 152 | memcpy(ts->key.key, key->key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 153 | else { |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 154 | memcpy(ts->key.key, key->key, MIN(t->key_size - 1, key->key_len)); |
| 155 | ts->key.key[MIN(t->key_size - 1, key->key_len)] = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 159 | /* return a shard number for key <key> of len <len> present in table <t>. This |
| 160 | * takes into account the presence or absence of a peers section with shards |
| 161 | * and the number of shards, the table's hash_seed, and of course the key. The |
| 162 | * caller must pass a valid <key> and <len>. The shard number to be used by the |
| 163 | * entry is returned (from 1 to nb_shards, otherwise 0 for none). |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 164 | */ |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 165 | int stktable_get_key_shard(struct stktable *t, const void *key, size_t len) |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 166 | { |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 167 | /* no peers section or no shards in the peers section */ |
| 168 | if (!t->peers.p || !t->peers.p->nb_shards) |
| 169 | return 0; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 170 | |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 171 | return XXH64(key, len, t->hash_seed) % t->peers.p->nb_shards + 1; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 172 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 173 | |
| 174 | /* |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 175 | * Set the shard for <key> key of <ts> sticky session attached to <t> stick table. |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 176 | * Use zero for stick-table without peers synchronisation. |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 177 | */ |
| 178 | static void stksess_setkey_shard(struct stktable *t, struct stksess *ts, |
| 179 | struct stktable_key *key) |
| 180 | { |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 181 | size_t keylen; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 182 | |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 183 | if (t->type == SMP_T_STR) |
| 184 | keylen = key->key_len; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 185 | else |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 186 | keylen = t->key_size; |
| 187 | |
| 188 | ts->shard = stktable_get_key_shard(t, key->key, keylen); |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 192 | * Init sticky session <ts> of table <t>. The data parts are cleared and <ts> |
| 193 | * is returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 194 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 195 | static struct stksess *__stksess_init(struct stktable *t, struct stksess * ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 196 | { |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 197 | memset((void *)ts - t->data_size, 0, t->data_size); |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 198 | ts->ref_cnt = 0; |
Willy Tarreau | e548a7a | 2022-11-29 16:08:35 +0100 | [diff] [blame] | 199 | ts->shard = 0; |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 200 | ts->key.node.leaf_p = NULL; |
| 201 | ts->exp.node.leaf_p = NULL; |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 202 | ts->upd.node.leaf_p = NULL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 203 | ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 204 | HA_RWLOCK_INIT(&ts->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 205 | return ts; |
| 206 | } |
| 207 | |
| 208 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 209 | * Trash oldest <to_batch> sticky sessions from table <t> |
Willy Tarreau | dfe7925 | 2020-11-03 17:47:41 +0100 | [diff] [blame] | 210 | * Returns number of trashed sticky sessions. It may actually trash less |
| 211 | * than expected if finding these requires too long a search time (e.g. |
| 212 | * most of them have ts->ref_cnt>0). |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 213 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 214 | int __stktable_trash_oldest(struct stktable *t, int to_batch) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 215 | { |
| 216 | struct stksess *ts; |
| 217 | struct eb32_node *eb; |
Willy Tarreau | dfe7925 | 2020-11-03 17:47:41 +0100 | [diff] [blame] | 218 | int max_search = to_batch * 2; // no more than 50% misses |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 219 | int batched = 0; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 220 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 221 | |
| 222 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 223 | |
| 224 | while (batched < to_batch) { |
| 225 | |
| 226 | if (unlikely(!eb)) { |
| 227 | /* we might have reached the end of the tree, typically because |
| 228 | * <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] | 229 | * half. Let's loop back to the beginning of the tree now if we |
| 230 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 231 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 232 | if (looped) |
| 233 | break; |
| 234 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 235 | eb = eb32_first(&t->exps); |
| 236 | if (likely(!eb)) |
| 237 | break; |
| 238 | } |
| 239 | |
Willy Tarreau | dfe7925 | 2020-11-03 17:47:41 +0100 | [diff] [blame] | 240 | if (--max_search < 0) |
| 241 | break; |
| 242 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 243 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 244 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 245 | eb = eb32_next(eb); |
| 246 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 247 | /* don't delete an entry which is currently referenced */ |
| 248 | if (ts->ref_cnt) |
| 249 | continue; |
| 250 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 251 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 252 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 253 | if (ts->expire != ts->exp.key) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 254 | if (!tick_isset(ts->expire)) |
| 255 | continue; |
| 256 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 257 | ts->exp.key = ts->expire; |
| 258 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 259 | |
Aleksey Ponomaryov | 5938021 | 2023-02-07 19:27:06 +0100 | [diff] [blame] | 260 | /* the update might have jumped beyond the next element, |
| 261 | * possibly causing a wrapping. We need to check whether |
| 262 | * the next element should be used instead. If the next |
| 263 | * element doesn't exist it means we're on the right |
| 264 | * side and have to check the first one then. If it |
| 265 | * exists and is closer, we must use it, otherwise we |
| 266 | * use the current one. |
| 267 | */ |
| 268 | if (!eb) |
| 269 | eb = eb32_first(&t->exps); |
| 270 | |
| 271 | if (!eb || tick_is_lt(ts->exp.key, eb->key)) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 272 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 273 | |
| 274 | continue; |
| 275 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 276 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 277 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 278 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 279 | eb32_delete(&ts->upd); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 280 | __stksess_free(t, ts); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 281 | batched++; |
| 282 | } |
| 283 | |
| 284 | return batched; |
| 285 | } |
| 286 | |
| 287 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 288 | * Trash oldest <to_batch> sticky sessions from table <t> |
| 289 | * Returns number of trashed sticky sessions. |
| 290 | * This function locks the table |
| 291 | */ |
| 292 | int stktable_trash_oldest(struct stktable *t, int to_batch) |
| 293 | { |
| 294 | int ret; |
| 295 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 296 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 297 | ret = __stktable_trash_oldest(t, to_batch); |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 298 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 299 | |
| 300 | return ret; |
| 301 | } |
| 302 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 303 | * Allocate and initialise a new sticky session. |
| 304 | * The new sticky session is returned or NULL in case of lack of memory. |
| 305 | * 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] | 306 | * stksess_free(). Table <t>'s sticky session counter is increased. If <key> |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 307 | * is not NULL, it is assigned to the new session. It must be called unlocked |
| 308 | * as it may rely on a lock to trash older entries. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 309 | */ |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 310 | struct stksess *stksess_new(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 311 | { |
| 312 | struct stksess *ts; |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 313 | unsigned int current; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 314 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 315 | current = HA_ATOMIC_FETCH_ADD(&t->current, 1); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 316 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 317 | if (unlikely(current >= t->size)) { |
| 318 | /* the table was already full, we may have to purge entries */ |
| 319 | if (t->nopurge || !stktable_trash_oldest(t, (t->size >> 8) + 1)) { |
| 320 | HA_ATOMIC_DEC(&t->current); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 321 | return NULL; |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 322 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 323 | } |
| 324 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 325 | ts = pool_alloc(t->pool); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 326 | if (ts) { |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 327 | ts = (void *)ts + round_ptr_size(t->data_size); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 328 | __stksess_init(t, ts); |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 329 | if (key) { |
Willy Tarreau | a7b46b5 | 2013-04-11 16:55:37 +0200 | [diff] [blame] | 330 | stksess_setkey(t, ts, key); |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 331 | stksess_setkey_shard(t, ts, key); |
| 332 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | return ts; |
| 336 | } |
| 337 | |
| 338 | /* |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 339 | * Looks in table <t> for a sticky session matching key <key>. |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 340 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 341 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 342 | struct stksess *__stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 343 | { |
| 344 | struct ebmb_node *eb; |
| 345 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 346 | if (t->type == SMP_T_STR) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 347 | 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] | 348 | else |
| 349 | eb = ebmb_lookup(&t->keys, key->key, t->key_size); |
| 350 | |
| 351 | if (unlikely(!eb)) { |
| 352 | /* no session found */ |
| 353 | return NULL; |
| 354 | } |
| 355 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 356 | return ebmb_entry(eb, struct stksess, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 359 | /* |
| 360 | * Looks in table <t> for a sticky session matching key <key>. |
| 361 | * Returns pointer on requested sticky session or NULL if none was found. |
| 362 | * The refcount of the found entry is increased and this function |
| 363 | * is protected using the table lock |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 364 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 365 | struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 366 | { |
| 367 | struct stksess *ts; |
| 368 | |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 369 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 370 | ts = __stktable_lookup_key(t, key); |
| 371 | if (ts) |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 372 | HA_ATOMIC_INC(&ts->ref_cnt); |
| 373 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 374 | |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 375 | return ts; |
| 376 | } |
| 377 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 378 | /* |
| 379 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 380 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 381 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 382 | struct stksess *__stktable_lookup(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 383 | { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 384 | struct ebmb_node *eb; |
| 385 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 386 | if (t->type == SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 387 | eb = ebst_lookup(&(t->keys), (char *)ts->key.key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 388 | else |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 389 | eb = ebmb_lookup(&(t->keys), ts->key.key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 390 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 391 | if (unlikely(!eb)) |
| 392 | return NULL; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 393 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 394 | return ebmb_entry(eb, struct stksess, key); |
| 395 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 396 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 397 | /* |
| 398 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 399 | * Returns pointer on requested sticky session or NULL if none was found. |
| 400 | * The refcount of the found entry is increased and this function |
| 401 | * is protected using the table lock |
| 402 | */ |
| 403 | struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts) |
| 404 | { |
| 405 | struct stksess *lts; |
| 406 | |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 407 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 408 | lts = __stktable_lookup(t, ts); |
| 409 | if (lts) |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 410 | HA_ATOMIC_INC(<s->ref_cnt); |
| 411 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 412 | |
| 413 | return lts; |
| 414 | } |
| 415 | |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 416 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 417 | * The table's expiration timer is updated if set. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 418 | * The node will be also inserted into the update tree if needed, at a position |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 419 | * depending if the update is a local or coming from a remote node. |
| 420 | * If <decrefcnt> is set, the ts entry's ref_cnt will be decremented. The table's |
| 421 | * write lock may be taken. |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 422 | */ |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 423 | void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local, int expire, int decrefcnt) |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 424 | { |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 425 | struct eb32_node * eb; |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 426 | int locked = 0; |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 427 | |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 428 | if (expire != HA_ATOMIC_LOAD(&ts->expire)) { |
| 429 | /* we'll need to set the expiration and to wake up the expiration timer .*/ |
| 430 | HA_ATOMIC_STORE(&ts->expire, expire); |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 431 | stktable_requeue_exp(t, ts); |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 432 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 433 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 434 | /* If sync is enabled */ |
| 435 | if (t->sync_task) { |
| 436 | if (local) { |
| 437 | /* If this entry is not in the tree |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 438 | * or not scheduled for at least one peer. |
| 439 | */ |
| 440 | if (!locked++) |
| 441 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
| 442 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 443 | if (!ts->upd.node.leaf_p |
| 444 | || (int)(t->commitupdate - ts->upd.key) >= 0 |
| 445 | || (int)(ts->upd.key - t->localupdate) >= 0) { |
| 446 | ts->upd.key = ++t->update; |
| 447 | t->localupdate = t->update; |
| 448 | eb32_delete(&ts->upd); |
| 449 | eb = eb32_insert(&t->updates, &ts->upd); |
| 450 | if (eb != &ts->upd) { |
| 451 | eb32_delete(eb); |
| 452 | eb32_insert(&t->updates, &ts->upd); |
| 453 | } |
Emeric Brun | aaf5860 | 2015-06-15 17:23:30 +0200 | [diff] [blame] | 454 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 455 | task_wakeup(t->sync_task, TASK_WOKEN_MSG); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 456 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 457 | else { |
| 458 | /* If this entry is not in the tree */ |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 459 | if (!locked++) |
| 460 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
| 461 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 462 | if (!ts->upd.node.leaf_p) { |
| 463 | ts->upd.key= (++t->update)+(2147483648U); |
| 464 | eb = eb32_insert(&t->updates, &ts->upd); |
| 465 | if (eb != &ts->upd) { |
| 466 | eb32_delete(eb); |
| 467 | eb32_insert(&t->updates, &ts->upd); |
| 468 | } |
| 469 | } |
| 470 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 471 | } |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 472 | |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 473 | if (decrefcnt) { |
| 474 | if (locked) |
| 475 | ts->ref_cnt--; |
| 476 | else { |
| 477 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
| 478 | HA_ATOMIC_DEC(&ts->ref_cnt); |
| 479 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | if (locked) |
| 484 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 487 | /* 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] | 488 | * 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] | 489 | * <t> stick-table configuration. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 490 | * The node will be also inserted into the update tree if needed, at a position |
| 491 | * considering the update is coming from a remote node |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 492 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 493 | void stktable_touch_remote(struct stktable *t, struct stksess *ts, int decrefcnt) |
| 494 | { |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 495 | stktable_touch_with_exp(t, ts, 0, ts->expire, decrefcnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 499 | * The table's expiration timer is updated using the date of expiration coming from |
| 500 | * <t> stick-table configuration. |
| 501 | * The node will be also inserted into the update tree if needed, at a position |
| 502 | * considering the update was made locally |
| 503 | */ |
| 504 | 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] | 505 | { |
| 506 | int expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
| 507 | |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 508 | stktable_touch_with_exp(t, ts, 1, expire, decrefcnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 509 | } |
Willy Tarreau | 4be073b | 2022-10-11 18:10:27 +0000 | [diff] [blame] | 510 | /* Just decrease the ref_cnt of the current session. Does nothing if <ts> is NULL. |
| 511 | * Note that we still need to take the read lock because a number of other places |
| 512 | * (including in Lua and peers) update the ref_cnt non-atomically under the write |
| 513 | * lock. |
| 514 | */ |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 515 | static void stktable_release(struct stktable *t, struct stksess *ts) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 516 | { |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 517 | if (!ts) |
| 518 | return; |
Willy Tarreau | 4be073b | 2022-10-11 18:10:27 +0000 | [diff] [blame] | 519 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
| 520 | HA_ATOMIC_DEC(&ts->ref_cnt); |
| 521 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 524 | /* Insert new sticky session <ts> in the table. It is assumed that it does not |
| 525 | * yet exist (the caller must check this). The table's timeout is updated if it |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 526 | * is set. <ts> is returned if properly inserted, otherwise the one already |
| 527 | * present if any. |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 528 | */ |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 529 | struct stksess *__stktable_store(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 530 | { |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 531 | struct ebmb_node *eb; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 532 | |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 533 | eb = ebmb_insert(&t->keys, &ts->key, t->key_size); |
| 534 | if (likely(eb == &ts->key)) { |
| 535 | ts->exp.key = ts->expire; |
| 536 | eb32_insert(&t->exps, &ts->exp); |
| 537 | } |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 538 | return ebmb_entry(eb, struct stksess, key); // most commonly this is <ts> |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 541 | /* requeues the table's expiration task to take the recently added <ts> into |
| 542 | * account. This is performed atomically and doesn't require any lock. |
| 543 | */ |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 544 | void stktable_requeue_exp(struct stktable *t, const struct stksess *ts) |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 545 | { |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 546 | int old_exp, new_exp; |
| 547 | int expire = ts->expire; |
| 548 | |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 549 | if (!t->expire) |
| 550 | return; |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 551 | |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 552 | /* set the task's expire to the newest expiration date. */ |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 553 | old_exp = HA_ATOMIC_LOAD(&t->exp_task->expire); |
Willy Tarreau | 3238f79 | 2022-11-14 17:54:07 +0100 | [diff] [blame] | 554 | new_exp = tick_first(expire, old_exp); |
| 555 | |
| 556 | /* let's not go further if we're already up to date */ |
| 557 | if (new_exp == old_exp) |
| 558 | return; |
| 559 | |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 560 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
| 561 | |
Willy Tarreau | 3238f79 | 2022-11-14 17:54:07 +0100 | [diff] [blame] | 562 | while (new_exp != old_exp && |
| 563 | !HA_ATOMIC_CAS(&t->exp_task->expire, &old_exp, new_exp)) { |
| 564 | __ha_cpu_relax(); |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 565 | new_exp = tick_first(expire, old_exp); |
Willy Tarreau | 3238f79 | 2022-11-14 17:54:07 +0100 | [diff] [blame] | 566 | } |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 567 | |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 568 | task_queue(t->exp_task); |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 569 | |
| 570 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 573 | /* Returns a valid or initialized stksess for the specified stktable_key in the |
| 574 | * specified table, or NULL if the key was NULL, or if no entry was found nor |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 575 | * could be created. The entry's expiration is updated. This function locks the |
| 576 | * table, and the refcount of the entry is increased. |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 577 | */ |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 578 | struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 579 | { |
Willy Tarreau | 175aa06 | 2022-10-11 15:13:46 +0200 | [diff] [blame] | 580 | struct stksess *ts, *ts2; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 581 | |
| 582 | if (!key) |
| 583 | return NULL; |
| 584 | |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 585 | ts = stktable_lookup_key(table, key); |
| 586 | if (ts) |
| 587 | return ts; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 588 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 589 | /* No such entry exists, let's try to create a new one. this doesn't |
| 590 | * require locking yet. |
| 591 | */ |
| 592 | |
| 593 | ts = stksess_new(table, key); |
| 594 | if (!ts) |
| 595 | return NULL; |
| 596 | |
| 597 | /* Now we're certain to have a ts. We need to store it. For this we'll |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 598 | * need an exclusive access. We don't need an atomic upgrade, this is |
| 599 | * rare and an unlock+lock sequence will do the job fine. Given that |
| 600 | * this will not be atomic, the missing entry might appear in the mean |
| 601 | * tome so we have to be careful that the one we try to insert is the |
| 602 | * one we find. |
| 603 | */ |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 604 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 605 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &table->lock); |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 606 | |
| 607 | ts2 = __stktable_store(table, ts); |
| 608 | if (unlikely(ts2 != ts)) { |
| 609 | /* another entry was added in the mean time, let's |
| 610 | * switch to it. |
| 611 | */ |
| 612 | __stksess_free(table, ts); |
| 613 | ts = ts2; |
| 614 | } |
| 615 | |
| 616 | HA_ATOMIC_INC(&ts->ref_cnt); |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 617 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &table->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 618 | |
Willy Tarreau | cbdb528 | 2022-10-12 10:04:01 +0000 | [diff] [blame] | 619 | stktable_requeue_exp(table, ts); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 620 | return ts; |
| 621 | } |
| 622 | |
| 623 | /* Lookup for an entry with the same key and store the submitted |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 624 | * stksess if not found. This function locks the table either shared or |
| 625 | * exclusively, and the refcount of the entry is increased. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 626 | */ |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 627 | struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 628 | { |
| 629 | struct stksess *ts; |
| 630 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 631 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &table->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 632 | ts = __stktable_lookup(table, nts); |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 633 | if (ts) { |
| 634 | HA_ATOMIC_INC(&ts->ref_cnt); |
| 635 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &table->lock); |
| 636 | return ts; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 637 | } |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 638 | ts = nts; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 639 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 640 | /* let's increment it before switching to exclusive */ |
| 641 | HA_ATOMIC_INC(&ts->ref_cnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 642 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 643 | if (HA_RWLOCK_TRYRDTOSK(STK_TABLE_LOCK, &table->lock) != 0) { |
| 644 | /* upgrade to seek lock failed, let's drop and take */ |
| 645 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &table->lock); |
| 646 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &table->lock); |
| 647 | } |
| 648 | else |
| 649 | HA_RWLOCK_SKTOWR(STK_TABLE_LOCK, &table->lock); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 650 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 651 | /* now we're write-locked */ |
| 652 | |
| 653 | __stktable_store(table, ts); |
| 654 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &table->lock); |
Willy Tarreau | cbdb528 | 2022-10-12 10:04:01 +0000 | [diff] [blame] | 655 | |
| 656 | stktable_requeue_exp(table, ts); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 657 | return ts; |
| 658 | } |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 659 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 660 | /* |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 661 | * Task processing function to trash expired sticky sessions. A pointer to the |
| 662 | * task itself is returned since it never dies. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 663 | */ |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 664 | 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] | 665 | { |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 666 | struct stktable *t = context; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 667 | struct stksess *ts; |
| 668 | struct eb32_node *eb; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 669 | int looped = 0; |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 670 | int exp_next; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 671 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 672 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 673 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 674 | |
| 675 | while (1) { |
| 676 | if (unlikely(!eb)) { |
| 677 | /* we might have reached the end of the tree, typically because |
| 678 | * <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] | 679 | * half. Let's loop back to the beginning of the tree now if we |
| 680 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 681 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 682 | if (looped) |
| 683 | break; |
| 684 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 685 | eb = eb32_first(&t->exps); |
| 686 | if (likely(!eb)) |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | if (likely(tick_is_lt(now_ms, eb->key))) { |
| 691 | /* timer not expired yet, revisit it later */ |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 692 | exp_next = eb->key; |
Willy Tarreau | 4d5f13c | 2017-11-05 11:04:47 +0100 | [diff] [blame] | 693 | goto out_unlock; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 697 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 698 | eb = eb32_next(eb); |
| 699 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 700 | /* don't delete an entry which is currently referenced */ |
| 701 | if (ts->ref_cnt) |
| 702 | continue; |
| 703 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 704 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 705 | |
| 706 | if (!tick_is_expired(ts->expire, now_ms)) { |
| 707 | if (!tick_isset(ts->expire)) |
| 708 | continue; |
| 709 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 710 | ts->exp.key = ts->expire; |
| 711 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 712 | |
Aleksey Ponomaryov | 5938021 | 2023-02-07 19:27:06 +0100 | [diff] [blame] | 713 | /* the update might have jumped beyond the next element, |
| 714 | * possibly causing a wrapping. We need to check whether |
| 715 | * the next element should be used instead. If the next |
| 716 | * element doesn't exist it means we're on the right |
| 717 | * side and have to check the first one then. If it |
| 718 | * exists and is closer, we must use it, otherwise we |
| 719 | * use the current one. |
| 720 | */ |
| 721 | if (!eb) |
| 722 | eb = eb32_first(&t->exps); |
| 723 | |
| 724 | if (!eb || tick_is_lt(ts->exp.key, eb->key)) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 725 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 726 | continue; |
| 727 | } |
| 728 | |
| 729 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 730 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 731 | eb32_delete(&ts->upd); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 732 | __stksess_free(t, ts); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /* We have found no task to expire in any tree */ |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 736 | exp_next = TICK_ETERNITY; |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 737 | |
Willy Tarreau | 4d5f13c | 2017-11-05 11:04:47 +0100 | [diff] [blame] | 738 | out_unlock: |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 739 | task->expire = exp_next; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 740 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 741 | return task; |
| 742 | } |
| 743 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 744 | /* 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] | 745 | int stktable_init(struct stktable *t) |
| 746 | { |
Remi Tricot-Le Breton | 208ff01 | 2021-05-12 17:39:04 +0200 | [diff] [blame] | 747 | int peers_retval = 0; |
Willy Tarreau | 56460ee | 2022-11-28 18:53:06 +0100 | [diff] [blame] | 748 | |
| 749 | t->hash_seed = XXH64(t->id, t->idlen, 0); |
| 750 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 751 | if (t->size) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 752 | t->keys = EB_ROOT_UNIQUE; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 753 | memset(&t->exps, 0, sizeof(t->exps)); |
Emeric Brun | 1c6235d | 2015-12-16 15:28:12 +0100 | [diff] [blame] | 754 | t->updates = EB_ROOT_UNIQUE; |
Amaury Denoyelle | 3e06488 | 2022-10-12 16:47:59 +0200 | [diff] [blame] | 755 | HA_RWLOCK_INIT(&t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 756 | |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 757 | 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] | 758 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 759 | if ( t->expire ) { |
Willy Tarreau | beeabf5 | 2021-10-01 18:23:30 +0200 | [diff] [blame] | 760 | t->exp_task = task_new_anywhere(); |
Willy Tarreau | 848522f | 2018-10-15 11:12:15 +0200 | [diff] [blame] | 761 | if (!t->exp_task) |
| 762 | return 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 763 | t->exp_task->process = process_table_expire; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 764 | t->exp_task->context = (void *)t; |
| 765 | } |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 766 | if (t->peers.p && t->peers.p->peers_fe && !(t->peers.p->peers_fe->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) { |
Remi Tricot-Le Breton | 208ff01 | 2021-05-12 17:39:04 +0200 | [diff] [blame] | 767 | peers_retval = peers_register_table(t->peers.p, t); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 768 | } |
| 769 | |
Remi Tricot-Le Breton | 208ff01 | 2021-05-12 17:39:04 +0200 | [diff] [blame] | 770 | return (t->pool != NULL) && !peers_retval; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 771 | } |
| 772 | return 1; |
| 773 | } |
| 774 | |
| 775 | /* |
| 776 | * Configuration keywords of known table types |
| 777 | */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 778 | struct stktable_type stktable_types[SMP_TYPES] = { |
| 779 | [SMP_T_SINT] = { "integer", 0, 4 }, |
| 780 | [SMP_T_IPV4] = { "ip", 0, 4 }, |
| 781 | [SMP_T_IPV6] = { "ipv6", 0, 16 }, |
| 782 | [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 }, |
| 783 | [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 } |
| 784 | }; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * Parse table type configuration. |
| 788 | * Returns 0 on successful parsing, else 1. |
| 789 | * <myidx> is set at next configuration <args> index. |
| 790 | */ |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 791 | 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] | 792 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 793 | for (*type = 0; *type < SMP_TYPES; (*type)++) { |
| 794 | if (!stktable_types[*type].kw) |
| 795 | continue; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 796 | if (strcmp(args[*myidx], stktable_types[*type].kw) != 0) |
| 797 | continue; |
| 798 | |
| 799 | *key_size = stktable_types[*type].default_size; |
| 800 | (*myidx)++; |
| 801 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 802 | if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 803 | if (strcmp("len", args[*myidx]) == 0) { |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 804 | char *stop; |
| 805 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 806 | (*myidx)++; |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 807 | *key_size = strtol(args[*myidx], &stop, 10); |
| 808 | if (*stop != '\0' || !*key_size) { |
| 809 | ha_alert("parsing [%s:%d] : 'len' expects a positive integer argument.\n", file, linenum); |
| 810 | return 1; |
| 811 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 812 | if (*type == SMP_T_STR) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 813 | /* null terminated string needs +1 for '\0'. */ |
| 814 | (*key_size)++; |
| 815 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 816 | (*myidx)++; |
| 817 | } |
| 818 | } |
| 819 | return 0; |
| 820 | } |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 821 | 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] | 822 | return 1; |
| 823 | } |
| 824 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 825 | /* reserve some space for data type <type>, there is 2 optionnals |
| 826 | * argument at <sa> and <sa2> to configure this data type and |
| 827 | * they can be NULL if unused for a given type. |
| 828 | * Returns PE_NONE (0) if OK or an error code among : |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 829 | * - PE_ENUM_OOR if <type> does not exist |
| 830 | * - PE_EXIST if <type> is already registered |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 831 | * - PE_ARG_NOT_USE if <sa>/<sa2> was provided but not expected |
| 832 | * - PE_ARG_MISSING if <sa>/<sa2> was expected but not provided |
| 833 | * - PE_ARG_VALUE_OOR if type is an array and <sa> it out of array size range. |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 834 | */ |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 835 | int stktable_alloc_data_type(struct stktable *t, int type, const char *sa, const char *sa2) |
| 836 | |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 837 | { |
| 838 | if (type >= STKTABLE_DATA_TYPES) |
| 839 | return PE_ENUM_OOR; |
| 840 | |
| 841 | if (t->data_ofs[type]) |
| 842 | /* already allocated */ |
| 843 | return PE_EXIST; |
| 844 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 845 | t->data_nbelem[type] = 1; |
| 846 | if (stktable_data_types[type].is_array) { |
| 847 | /* arrays take their element count on first argument */ |
| 848 | if (!sa) |
| 849 | return PE_ARG_MISSING; |
| 850 | t->data_nbelem[type] = atoi(sa); |
| 851 | if (!t->data_nbelem[type] || (t->data_nbelem[type] > STKTABLE_MAX_DT_ARRAY_SIZE)) |
| 852 | return PE_ARG_VALUE_OOR; |
| 853 | sa = sa2; |
| 854 | } |
| 855 | |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 856 | switch (stktable_data_types[type].arg_type) { |
| 857 | case ARG_T_NONE: |
| 858 | if (sa) |
| 859 | return PE_ARG_NOT_USED; |
| 860 | break; |
| 861 | case ARG_T_INT: |
| 862 | if (!sa) |
| 863 | return PE_ARG_MISSING; |
| 864 | t->data_arg[type].i = atoi(sa); |
| 865 | break; |
| 866 | case ARG_T_DELAY: |
| 867 | if (!sa) |
| 868 | return PE_ARG_MISSING; |
| 869 | sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS); |
| 870 | if (sa) |
| 871 | return PE_ARG_INVC; /* invalid char */ |
| 872 | break; |
| 873 | } |
| 874 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 875 | t->data_size += t->data_nbelem[type] * stktable_type_size(stktable_data_types[type].std_type); |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 876 | t->data_ofs[type] = -t->data_size; |
| 877 | return PE_NONE; |
| 878 | } |
| 879 | |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 880 | /* |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 881 | * Parse a line with <linenum> as number in <file> configuration file to configure |
| 882 | * the stick-table with <t> as address and <id> as ID. |
| 883 | * <peers> provides the "peers" section pointer only if this function is called |
| 884 | * from a "peers" section. |
| 885 | * <nid> is the stick-table name which is sent over the network. It must be equal |
| 886 | * to <id> if this stick-table is parsed from a proxy section, and prefixed by <peers> |
| 887 | * "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] | 888 | * 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] | 889 | * Return an error status with ERR_* flags set if required, 0 if no error was encountered. |
| 890 | */ |
| 891 | 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] | 892 | 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] | 893 | { |
| 894 | int err_code = 0; |
| 895 | int idx = 1; |
| 896 | unsigned int val; |
| 897 | |
| 898 | if (!id || !*id) { |
| 899 | ha_alert("parsing [%s:%d] : %s: ID not provided.\n", file, linenum, args[0]); |
| 900 | err_code |= ERR_ALERT | ERR_ABORT; |
| 901 | goto out; |
| 902 | } |
| 903 | |
| 904 | /* Store the "peers" section if this function is called from a "peers" section. */ |
| 905 | if (peers) { |
| 906 | t->peers.p = peers; |
| 907 | idx++; |
| 908 | } |
| 909 | |
| 910 | t->id = id; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 911 | t->idlen = strlen(id); |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 912 | t->nid = nid; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 913 | t->type = (unsigned int)-1; |
| 914 | t->conf.file = file; |
| 915 | t->conf.line = linenum; |
| 916 | |
| 917 | while (*args[idx]) { |
| 918 | const char *err; |
| 919 | |
| 920 | if (strcmp(args[idx], "size") == 0) { |
| 921 | idx++; |
| 922 | if (!*(args[idx])) { |
| 923 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 924 | file, linenum, args[0], args[idx-1]); |
| 925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 926 | goto out; |
| 927 | } |
| 928 | if ((err = parse_size_err(args[idx], &t->size))) { |
| 929 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 930 | file, linenum, args[0], *err, args[idx-1]); |
| 931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 932 | goto out; |
| 933 | } |
| 934 | idx++; |
| 935 | } |
| 936 | /* This argument does not exit in "peers" section. */ |
| 937 | else if (!peers && strcmp(args[idx], "peers") == 0) { |
| 938 | idx++; |
| 939 | if (!*(args[idx])) { |
| 940 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 941 | file, linenum, args[0], args[idx-1]); |
| 942 | err_code |= ERR_ALERT | ERR_FATAL; |
| 943 | goto out; |
| 944 | } |
| 945 | t->peers.name = strdup(args[idx++]); |
| 946 | } |
| 947 | else if (strcmp(args[idx], "expire") == 0) { |
| 948 | idx++; |
| 949 | if (!*(args[idx])) { |
| 950 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 951 | file, linenum, args[0], args[idx-1]); |
| 952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 953 | goto out; |
| 954 | } |
| 955 | err = parse_time_err(args[idx], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 956 | if (err == PARSE_TIME_OVER) { |
| 957 | ha_alert("parsing [%s:%d]: %s: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 958 | file, linenum, args[0], args[idx], args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 959 | err_code |= ERR_ALERT | ERR_FATAL; |
| 960 | goto out; |
| 961 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 962 | else if (err == PARSE_TIME_UNDER) { |
| 963 | ha_alert("parsing [%s:%d]: %s: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 964 | file, linenum, args[0], args[idx], args[idx-1]); |
| 965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 966 | goto out; |
| 967 | } |
| 968 | else if (err) { |
| 969 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 970 | file, linenum, args[0], *err, args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 972 | goto out; |
| 973 | } |
| 974 | t->expire = val; |
| 975 | idx++; |
| 976 | } |
| 977 | else if (strcmp(args[idx], "nopurge") == 0) { |
| 978 | t->nopurge = 1; |
| 979 | idx++; |
| 980 | } |
| 981 | else if (strcmp(args[idx], "type") == 0) { |
| 982 | idx++; |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 983 | 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] | 984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 985 | goto out; |
| 986 | } |
| 987 | /* idx already points to next arg */ |
| 988 | } |
| 989 | else if (strcmp(args[idx], "store") == 0) { |
| 990 | int type, err; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 991 | char *cw, *nw, *sa, *sa2; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 992 | |
| 993 | idx++; |
| 994 | nw = args[idx]; |
| 995 | while (*nw) { |
| 996 | /* the "store" keyword supports a comma-separated list */ |
| 997 | cw = nw; |
| 998 | sa = NULL; /* store arg */ |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 999 | sa2 = NULL; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1000 | while (*nw && *nw != ',') { |
| 1001 | if (*nw == '(') { |
| 1002 | *nw = 0; |
| 1003 | sa = ++nw; |
| 1004 | while (*nw != ')') { |
| 1005 | if (!*nw) { |
| 1006 | ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 1007 | file, linenum, args[0], cw); |
| 1008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1009 | goto out; |
| 1010 | } |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1011 | if (*nw == ',') { |
| 1012 | *nw = '\0'; |
| 1013 | sa2 = nw + 1; |
| 1014 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1015 | nw++; |
| 1016 | } |
| 1017 | *nw = '\0'; |
| 1018 | } |
| 1019 | nw++; |
| 1020 | } |
| 1021 | if (*nw) |
| 1022 | *nw++ = '\0'; |
| 1023 | type = stktable_get_data_type(cw); |
| 1024 | if (type < 0) { |
| 1025 | ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 1026 | file, linenum, args[0], cw); |
| 1027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1028 | goto out; |
| 1029 | } |
| 1030 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1031 | err = stktable_alloc_data_type(t, type, sa, sa2); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1032 | switch (err) { |
| 1033 | case PE_NONE: break; |
| 1034 | case PE_EXIST: |
| 1035 | ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 1036 | file, linenum, args[0], cw); |
| 1037 | err_code |= ERR_WARN; |
| 1038 | break; |
| 1039 | |
| 1040 | case PE_ARG_MISSING: |
| 1041 | ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 1042 | file, linenum, args[0], cw); |
| 1043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1044 | goto out; |
| 1045 | |
| 1046 | case PE_ARG_NOT_USED: |
| 1047 | ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 1048 | file, linenum, args[0], cw); |
| 1049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1050 | goto out; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1051 | case PE_ARG_VALUE_OOR: |
| 1052 | ha_alert("parsing [%s:%d] : %s: array size is out of allowed range (1-%d) for store option '%s'.\n", |
| 1053 | file, linenum, args[0], STKTABLE_MAX_DT_ARRAY_SIZE, cw); |
| 1054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1055 | goto out; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1056 | |
| 1057 | default: |
| 1058 | ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 1059 | file, linenum, args[0], cw); |
| 1060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1061 | goto out; |
| 1062 | } |
| 1063 | } |
| 1064 | idx++; |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 1065 | if (t->data_ofs[STKTABLE_DT_GPT] && t->data_ofs[STKTABLE_DT_GPT0]) { |
| 1066 | ha_alert("parsing [%s:%d] : %s: simultaneous usage of 'gpt' and 'gpt0' in a same table is not permitted as 'gpt' overrides 'gpt0'.\n", |
| 1067 | file, linenum, args[0]); |
| 1068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1069 | goto out; |
| 1070 | } |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1071 | else if (t->data_ofs[STKTABLE_DT_GPC] && (t->data_ofs[STKTABLE_DT_GPC0] || t->data_ofs[STKTABLE_DT_GPC1])) { |
| 1072 | ha_alert("parsing [%s:%d] : %s: simultaneous usage of 'gpc' and 'gpc[0/1]' in a same table is not permitted as 'gpc' overrides 'gpc[0/1]'.\n", |
| 1073 | file, linenum, args[0]); |
| 1074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1075 | goto out; |
| 1076 | } |
| 1077 | else if (t->data_ofs[STKTABLE_DT_GPC_RATE] && (t->data_ofs[STKTABLE_DT_GPC0_RATE] || t->data_ofs[STKTABLE_DT_GPC1_RATE])) { |
| 1078 | ha_alert("parsing [%s:%d] : %s: simultaneous usage of 'gpc_rate' and 'gpc[0/1]_rate' in a same table is not permitted as 'gpc_rate' overrides 'gpc[0/1]_rate'.\n", |
| 1079 | file, linenum, args[0]); |
| 1080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1081 | goto out; |
| 1082 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1083 | } |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 1084 | else if (strcmp(args[idx], "srvkey") == 0) { |
| 1085 | char *keytype; |
| 1086 | idx++; |
| 1087 | keytype = args[idx]; |
| 1088 | if (strcmp(keytype, "name") == 0) { |
| 1089 | t->server_key_type = STKTABLE_SRV_NAME; |
| 1090 | } |
| 1091 | else if (strcmp(keytype, "addr") == 0) { |
| 1092 | t->server_key_type = STKTABLE_SRV_ADDR; |
| 1093 | } |
| 1094 | else { |
| 1095 | ha_alert("parsing [%s:%d] : %s : unknown server key type '%s'.\n", |
| 1096 | file, linenum, args[0], keytype); |
| 1097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1098 | goto out; |
| 1099 | |
| 1100 | } |
| 1101 | idx++; |
| 1102 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1103 | else { |
| 1104 | ha_alert("parsing [%s:%d] : %s: unknown argument '%s'.\n", |
| 1105 | file, linenum, args[0], args[idx]); |
| 1106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1107 | goto out; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | if (!t->size) { |
| 1112 | ha_alert("parsing [%s:%d] : %s: missing size.\n", |
| 1113 | file, linenum, args[0]); |
| 1114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1115 | goto out; |
| 1116 | } |
| 1117 | |
| 1118 | if (t->type == (unsigned int)-1) { |
| 1119 | ha_alert("parsing [%s:%d] : %s: missing type.\n", |
| 1120 | file, linenum, args[0]); |
| 1121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1122 | goto out; |
| 1123 | } |
| 1124 | |
| 1125 | out: |
| 1126 | return err_code; |
| 1127 | } |
| 1128 | |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1129 | /* 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] | 1130 | * Note that the sample *is* modified and that the returned key may point |
| 1131 | * 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] | 1132 | * Returns NULL if the sample could not be converted (eg: no matching type), |
| 1133 | * otherwise a pointer to the static stktable_key filled with what is needed |
| 1134 | * for the lookup. |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1135 | */ |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1136 | struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1137 | { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1138 | /* Convert sample. */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1139 | if (!sample_convert(smp, t->type)) |
Willy Tarreau | 7fc1c6e | 2012-04-26 11:03:17 +0200 | [diff] [blame] | 1140 | return NULL; |
| 1141 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1142 | /* Fill static_table_key. */ |
| 1143 | switch (t->type) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1144 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1145 | case SMP_T_IPV4: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1146 | static_table_key.key = &smp->data.u.ipv4; |
| 1147 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1148 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1149 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1150 | case SMP_T_IPV6: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1151 | static_table_key.key = &smp->data.u.ipv6; |
| 1152 | static_table_key.key_len = 16; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1153 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1154 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1155 | case SMP_T_SINT: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1156 | /* The stick table require a 32bit unsigned int, "sint" is a |
| 1157 | * signed 64 it, so we can convert it inplace. |
| 1158 | */ |
Willy Tarreau | 28c63c1 | 2019-10-23 06:21:05 +0200 | [diff] [blame] | 1159 | smp->data.u.sint = (unsigned int)smp->data.u.sint; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1160 | static_table_key.key = &smp->data.u.sint; |
| 1161 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1162 | break; |
| 1163 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1164 | case SMP_T_STR: |
Willy Tarreau | ce6955e | 2016-08-09 11:59:12 +0200 | [diff] [blame] | 1165 | if (!smp_make_safe(smp)) |
| 1166 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1167 | static_table_key.key = smp->data.u.str.area; |
| 1168 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1169 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1170 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1171 | case SMP_T_BIN: |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1172 | if (smp->data.u.str.data < t->key_size) { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1173 | /* This type needs padding with 0. */ |
Willy Tarreau | f65c6c0 | 2016-08-09 12:08:41 +0200 | [diff] [blame] | 1174 | if (!smp_make_rw(smp)) |
| 1175 | return NULL; |
| 1176 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1177 | if (smp->data.u.str.size < t->key_size) |
| 1178 | if (!smp_dup(smp)) |
| 1179 | return NULL; |
| 1180 | if (smp->data.u.str.size < t->key_size) |
| 1181 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1182 | memset(smp->data.u.str.area + smp->data.u.str.data, 0, |
| 1183 | t->key_size - smp->data.u.str.data); |
| 1184 | smp->data.u.str.data = t->key_size; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1185 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1186 | static_table_key.key = smp->data.u.str.area; |
| 1187 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1188 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1189 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1190 | default: /* impossible case. */ |
| 1191 | return NULL; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1194 | return &static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | /* |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1198 | * Process a fetch + format conversion as defined by the sample expression <expr> |
| 1199 | * on request or response considering the <opt> parameter. Returns either NULL if |
| 1200 | * no key could be extracted, or a pointer to the converted result stored in |
| 1201 | * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset |
| 1202 | * 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] | 1203 | * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present |
| 1204 | * without SMP_OPT_FINAL). The output will be usable like this : |
| 1205 | * |
| 1206 | * return MAY_CHANGE FINAL Meaning for the sample |
| 1207 | * NULL 0 * Not present and will never be (eg: header) |
| 1208 | * NULL 1 0 Not present or unstable, could change (eg: req_len) |
| 1209 | * NULL 1 1 Not present, will not change anymore |
| 1210 | * smp 0 * Present and will not change (eg: header) |
| 1211 | * smp 1 0 not possible |
| 1212 | * smp 1 1 Present, last known value (eg: request length) |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1213 | */ |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1214 | 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] | 1215 | unsigned int opt, struct sample_expr *expr, struct sample *smp) |
| 1216 | { |
| 1217 | if (smp) |
| 1218 | memset(smp, 0, sizeof(*smp)); |
| 1219 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1220 | smp = sample_process(px, sess, strm, opt, expr, smp); |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1221 | if (!smp) |
| 1222 | return NULL; |
| 1223 | |
| 1224 | if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
| 1225 | return NULL; /* we can only use stable samples */ |
| 1226 | |
| 1227 | return smp_to_stkey(smp, t); |
| 1228 | } |
| 1229 | |
| 1230 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1231 | * 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] | 1232 | * type <table_type>, otherwise zero. Used in configuration check. |
| 1233 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1234 | int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1235 | { |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1236 | int out_type; |
| 1237 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1238 | if (table_type >= SMP_TYPES || !stktable_types[table_type].kw) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1239 | return 0; |
| 1240 | |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1241 | out_type = smp_expr_output_type(expr); |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1242 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1243 | /* Convert sample. */ |
| 1244 | if (!sample_casts[out_type][table_type]) |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1245 | return 0; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1246 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1247 | return 1; |
| 1248 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 1249 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1250 | /* Extra data types processing : after the last one, some room may remain |
| 1251 | * before STKTABLE_DATA_TYPES that may be used to register extra data types |
| 1252 | * at run time. |
| 1253 | */ |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1254 | struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = { |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1255 | [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT }, |
Thierry FOURNIER | 3cf1111 | 2015-07-28 08:57:05 +0200 | [diff] [blame] | 1256 | [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1257 | [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT }, |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 1258 | [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] | 1259 | [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT }, |
| 1260 | [STKTABLE_DT_CONN_RATE] = { .name = "conn_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
Willy Tarreau | db2ab82 | 2021-10-08 17:53:12 +0200 | [diff] [blame] | 1261 | [STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .std_type = STD_T_UINT, .is_local = 1 }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1262 | [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT }, |
| 1263 | [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1264 | [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT }, |
| 1265 | [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1266 | [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT }, |
| 1267 | [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1268 | [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL }, |
| 1269 | [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1270 | [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL }, |
| 1271 | [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] | 1272 | [STKTABLE_DT_GPC1] = { .name = "gpc1", .std_type = STD_T_UINT }, |
| 1273 | [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] | 1274 | [STKTABLE_DT_SERVER_KEY] = { .name = "server_key", .std_type = STD_T_DICT }, |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 1275 | [STKTABLE_DT_HTTP_FAIL_CNT] = { .name = "http_fail_cnt", .std_type = STD_T_UINT }, |
| 1276 | [STKTABLE_DT_HTTP_FAIL_RATE]= { .name = "http_fail_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 1277 | [STKTABLE_DT_GPT] = { .name = "gpt", .std_type = STD_T_UINT, .is_array = 1 }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 1278 | [STKTABLE_DT_GPC] = { .name = "gpc", .std_type = STD_T_UINT, .is_array = 1 }, |
| 1279 | [STKTABLE_DT_GPC_RATE] = { .name = "gpc_rate", .std_type = STD_T_FRQP, .is_array = 1, .arg_type = ARG_T_DELAY }, |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1280 | }; |
| 1281 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1282 | /* Registers stick-table extra data type with index <idx>, name <name>, type |
| 1283 | * <std_type> and arg type <arg_type>. If the index is negative, the next free |
| 1284 | * index is automatically allocated. The allocated index is returned, or -1 if |
| 1285 | * no free index was found or <name> was already registered. The <name> is used |
| 1286 | * directly as a pointer, so if it's not stable, the caller must allocate it. |
| 1287 | */ |
| 1288 | int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type) |
| 1289 | { |
| 1290 | if (idx < 0) { |
| 1291 | for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) { |
| 1292 | if (!stktable_data_types[idx].name) |
| 1293 | break; |
| 1294 | |
| 1295 | if (strcmp(stktable_data_types[idx].name, name) == 0) |
| 1296 | return -1; |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | if (idx >= STKTABLE_DATA_TYPES) |
| 1301 | return -1; |
| 1302 | |
| 1303 | if (stktable_data_types[idx].name != NULL) |
| 1304 | return -1; |
| 1305 | |
| 1306 | stktable_data_types[idx].name = name; |
| 1307 | stktable_data_types[idx].std_type = std_type; |
| 1308 | stktable_data_types[idx].arg_type = arg_type; |
| 1309 | return idx; |
| 1310 | } |
| 1311 | |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1312 | /* |
| 1313 | * Returns the data type number for the stktable_data_type whose name is <name>, |
| 1314 | * or <0 if not found. |
| 1315 | */ |
| 1316 | int stktable_get_data_type(char *name) |
| 1317 | { |
| 1318 | int type; |
| 1319 | |
| 1320 | for (type = 0; type < STKTABLE_DATA_TYPES; type++) { |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1321 | if (!stktable_data_types[type].name) |
| 1322 | continue; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1323 | if (strcmp(name, stktable_data_types[type].name) == 0) |
| 1324 | return type; |
| 1325 | } |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 1326 | /* For backwards compatibility */ |
| 1327 | if (strcmp(name, "server_name") == 0) |
| 1328 | return STKTABLE_DT_SERVER_KEY; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1329 | return -1; |
| 1330 | } |
| 1331 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1332 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1333 | * it up into this table. Returns true if found, false otherwise. The input |
| 1334 | * type is STR so that input samples are converted to string (since all types |
| 1335 | * can be converted to strings), then the function casts the string again into |
| 1336 | * the table's type. This is a double conversion, but in the future we might |
| 1337 | * support automatic input types to perform the cast on the fly. |
| 1338 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1339 | 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] | 1340 | { |
| 1341 | struct stktable *t; |
| 1342 | struct stktable_key *key; |
| 1343 | struct stksess *ts; |
| 1344 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1345 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1346 | |
| 1347 | key = smp_to_stkey(smp, t); |
| 1348 | if (!key) |
| 1349 | return 0; |
| 1350 | |
| 1351 | ts = stktable_lookup_key(t, key); |
| 1352 | |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1353 | smp->data.type = SMP_T_BOOL; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1354 | smp->data.u.sint = !!ts; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1355 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 1356 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1357 | return 1; |
| 1358 | } |
| 1359 | |
| 1360 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1361 | * it up into this table. Returns the data rate received from clients in bytes/s |
| 1362 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1363 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1364 | * <not found> is returned. |
| 1365 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1366 | 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] | 1367 | { |
| 1368 | struct stktable *t; |
| 1369 | struct stktable_key *key; |
| 1370 | struct stksess *ts; |
| 1371 | void *ptr; |
| 1372 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1373 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1374 | |
| 1375 | key = smp_to_stkey(smp, t); |
| 1376 | if (!key) |
| 1377 | return 0; |
| 1378 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1379 | ts = stktable_lookup_key(t, key); |
| 1380 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1381 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1382 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1383 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1384 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1385 | if (!ts) /* key not present */ |
| 1386 | return 1; |
| 1387 | |
| 1388 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1389 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1390 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1391 | t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1392 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1393 | stktable_release(t, ts); |
| 1394 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1398 | * it up into this table. Returns the cumulated number of connections for the key |
| 1399 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1400 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1401 | * <not found> is returned. |
| 1402 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1403 | 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] | 1404 | { |
| 1405 | struct stktable *t; |
| 1406 | struct stktable_key *key; |
| 1407 | struct stksess *ts; |
| 1408 | void *ptr; |
| 1409 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1410 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1411 | |
| 1412 | key = smp_to_stkey(smp, t); |
| 1413 | if (!key) |
| 1414 | return 0; |
| 1415 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1416 | ts = stktable_lookup_key(t, key); |
| 1417 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1418 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1419 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1420 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1421 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1422 | if (!ts) /* key not present */ |
| 1423 | return 1; |
| 1424 | |
| 1425 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1426 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1427 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1428 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1429 | stktable_release(t, ts); |
| 1430 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1434 | * it up into this table. Returns the number of concurrent connections for the |
| 1435 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1436 | * can be easily performed. If the inspected parameter is not stored in the |
| 1437 | * table, <not found> is returned. |
| 1438 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1439 | 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] | 1440 | { |
| 1441 | struct stktable *t; |
| 1442 | struct stktable_key *key; |
| 1443 | struct stksess *ts; |
| 1444 | void *ptr; |
| 1445 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1446 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1447 | |
| 1448 | key = smp_to_stkey(smp, t); |
| 1449 | if (!key) |
| 1450 | return 0; |
| 1451 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1452 | ts = stktable_lookup_key(t, key); |
| 1453 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1454 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1455 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1456 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1457 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1458 | if (!ts) /* key not present */ |
| 1459 | return 1; |
| 1460 | |
| 1461 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1462 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1463 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1464 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1465 | stktable_release(t, ts); |
| 1466 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1470 | * it up into this table. Returns the rate of incoming connections from the key |
| 1471 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1472 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1473 | * <not found> is returned. |
| 1474 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1475 | 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] | 1476 | { |
| 1477 | struct stktable *t; |
| 1478 | struct stktable_key *key; |
| 1479 | struct stksess *ts; |
| 1480 | void *ptr; |
| 1481 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1482 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1483 | |
| 1484 | key = smp_to_stkey(smp, t); |
| 1485 | if (!key) |
| 1486 | return 0; |
| 1487 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1488 | ts = stktable_lookup_key(t, key); |
| 1489 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1490 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1491 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1492 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1493 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1494 | if (!ts) /* key not present */ |
| 1495 | return 1; |
| 1496 | |
| 1497 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1498 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1499 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1500 | t->data_arg[STKTABLE_DT_CONN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1501 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1502 | stktable_release(t, ts); |
| 1503 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
Frédéric Lécaille | bbeec37 | 2022-08-16 18:11:25 +0200 | [diff] [blame] | 1507 | * it up into this table. Returns the expiration delay for the key if the key is |
| 1508 | * present in the table, otherwise the default value provided as second argument |
| 1509 | * if any, if not (no default value), <not found> is returned. |
| 1510 | */ |
| 1511 | static int sample_conv_table_expire(const struct arg *arg_p, struct sample *smp, void *private) |
| 1512 | { |
| 1513 | struct stktable *t; |
| 1514 | struct stktable_key *key; |
| 1515 | struct stksess *ts; |
| 1516 | |
| 1517 | t = arg_p[0].data.t; |
| 1518 | |
| 1519 | key = smp_to_stkey(smp, t); |
| 1520 | if (!key) |
| 1521 | return 0; |
| 1522 | |
| 1523 | ts = stktable_lookup_key(t, key); |
| 1524 | |
| 1525 | smp->flags = SMP_F_VOL_TEST; |
| 1526 | smp->data.type = SMP_T_SINT; |
| 1527 | smp->data.u.sint = 0; |
| 1528 | |
| 1529 | if (!ts) { /* key not present */ |
| 1530 | if (arg_p[1].type == ARGT_STOP) |
| 1531 | return 0; |
| 1532 | |
| 1533 | /* default value */ |
| 1534 | smp->data.u.sint = arg_p[1].data.sint; |
| 1535 | return 1; |
| 1536 | } |
| 1537 | |
| 1538 | smp->data.u.sint = tick_remain(now_ms, ts->expire); |
| 1539 | |
| 1540 | stktable_release(t, ts); |
| 1541 | return 1; |
| 1542 | } |
| 1543 | |
| 1544 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1545 | * it up into this table. Returns the time the key remains unused if the key is |
| 1546 | * present in the table, otherwise the default value provided as second argument |
| 1547 | * if any, if not (no default value), <not found> is returned. |
| 1548 | */ |
| 1549 | static int sample_conv_table_idle(const struct arg *arg_p, struct sample *smp, void *private) |
| 1550 | { |
| 1551 | struct stktable *t; |
| 1552 | struct stktable_key *key; |
| 1553 | struct stksess *ts; |
| 1554 | |
| 1555 | t = arg_p[0].data.t; |
| 1556 | |
| 1557 | key = smp_to_stkey(smp, t); |
| 1558 | if (!key) |
| 1559 | return 0; |
| 1560 | |
| 1561 | ts = stktable_lookup_key(t, key); |
| 1562 | |
| 1563 | smp->flags = SMP_F_VOL_TEST; |
| 1564 | smp->data.type = SMP_T_SINT; |
| 1565 | smp->data.u.sint = 0; |
| 1566 | |
| 1567 | if (!ts) { /* key not present */ |
| 1568 | if (arg_p[1].type == ARGT_STOP) |
| 1569 | return 0; |
| 1570 | |
| 1571 | /* default value */ |
| 1572 | smp->data.u.sint = arg_p[1].data.sint; |
| 1573 | return 1; |
| 1574 | } |
| 1575 | |
| 1576 | smp->data.u.sint = tick_remain(tick_remain(now_ms, ts->expire), t->expire); |
| 1577 | |
| 1578 | stktable_release(t, ts); |
| 1579 | return 1; |
| 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 data rate sent to clients in bytes/s |
| 1584 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1585 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1586 | * <not found> is returned. |
| 1587 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1588 | 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] | 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_BYTES_OUT_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1611 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1612 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1613 | t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1614 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1615 | stktable_release(t, ts); |
| 1616 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1617 | } |
| 1618 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 1619 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1620 | * it up into this table. Returns the value of the GPT[arg_p(0)] tag for the key |
| 1621 | * if the key is present in the table, otherwise false, so that comparisons can |
| 1622 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1623 | * <not found> is returned. |
| 1624 | */ |
| 1625 | static int sample_conv_table_gpt(const struct arg *arg_p, struct sample *smp, void *private) |
| 1626 | { |
| 1627 | struct stktable *t; |
| 1628 | struct stktable_key *key; |
| 1629 | struct stksess *ts; |
| 1630 | void *ptr; |
| 1631 | unsigned int idx; |
| 1632 | |
| 1633 | idx = arg_p[0].data.sint; |
| 1634 | |
| 1635 | t = arg_p[1].data.t; |
| 1636 | |
| 1637 | key = smp_to_stkey(smp, t); |
| 1638 | if (!key) |
| 1639 | return 0; |
| 1640 | |
| 1641 | ts = stktable_lookup_key(t, key); |
| 1642 | |
| 1643 | smp->flags = SMP_F_VOL_TEST; |
| 1644 | smp->data.type = SMP_T_SINT; |
| 1645 | smp->data.u.sint = 0; |
| 1646 | |
| 1647 | if (!ts) /* key not present */ |
| 1648 | return 1; |
| 1649 | |
| 1650 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPT, idx); |
| 1651 | if (ptr) |
| 1652 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 1653 | |
| 1654 | stktable_release(t, ts); |
| 1655 | return !!ptr; |
| 1656 | } |
| 1657 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1658 | /* 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] | 1659 | * it up into this table. Returns the value of the GPT0 tag for the key |
| 1660 | * if the key is present in the table, otherwise false, so that comparisons can |
| 1661 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1662 | * <not found> is returned. |
| 1663 | */ |
| 1664 | static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private) |
| 1665 | { |
| 1666 | struct stktable *t; |
| 1667 | struct stktable_key *key; |
| 1668 | struct stksess *ts; |
| 1669 | void *ptr; |
| 1670 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1671 | t = arg_p[0].data.t; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1672 | |
| 1673 | key = smp_to_stkey(smp, t); |
| 1674 | if (!key) |
| 1675 | return 0; |
| 1676 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1677 | ts = stktable_lookup_key(t, key); |
| 1678 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1679 | smp->flags = SMP_F_VOL_TEST; |
| 1680 | smp->data.type = SMP_T_SINT; |
| 1681 | smp->data.u.sint = 0; |
| 1682 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1683 | if (!ts) /* key not present */ |
| 1684 | return 1; |
| 1685 | |
| 1686 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 1687 | if (!ptr) |
| 1688 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPT, 0); |
| 1689 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1690 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1691 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1692 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1693 | stktable_release(t, ts); |
| 1694 | return !!ptr; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1695 | } |
| 1696 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 1697 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1698 | * it up into this table. Returns the value of the GPC[arg_p(0)] counter for the key |
| 1699 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1700 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1701 | * <not found> is returned. |
| 1702 | */ |
| 1703 | static int sample_conv_table_gpc(const struct arg *arg_p, struct sample *smp, void *private) |
| 1704 | { |
| 1705 | struct stktable *t; |
| 1706 | struct stktable_key *key; |
| 1707 | struct stksess *ts; |
| 1708 | void *ptr; |
| 1709 | unsigned int idx; |
| 1710 | |
| 1711 | idx = arg_p[0].data.sint; |
| 1712 | |
| 1713 | t = arg_p[1].data.t; |
| 1714 | |
| 1715 | key = smp_to_stkey(smp, t); |
| 1716 | if (!key) |
| 1717 | return 0; |
| 1718 | |
| 1719 | ts = stktable_lookup_key(t, key); |
| 1720 | |
| 1721 | smp->flags = SMP_F_VOL_TEST; |
| 1722 | smp->data.type = SMP_T_SINT; |
| 1723 | smp->data.u.sint = 0; |
| 1724 | |
| 1725 | if (!ts) /* key not present */ |
| 1726 | return 1; |
| 1727 | |
| 1728 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, idx); |
| 1729 | if (ptr) |
| 1730 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 1731 | |
| 1732 | stktable_release(t, ts); |
| 1733 | return !!ptr; |
| 1734 | } |
| 1735 | |
| 1736 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1737 | * it up into this table. Returns the event rate of the GPC[arg_p(0)] counter |
| 1738 | * for the key if the key is present in the table, otherwise zero, so that |
| 1739 | * comparisons can be easily performed. If the inspected parameter is not |
| 1740 | * stored in the table, <not found> is returned. |
| 1741 | */ |
| 1742 | static int sample_conv_table_gpc_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 1743 | { |
| 1744 | struct stktable *t; |
| 1745 | struct stktable_key *key; |
| 1746 | struct stksess *ts; |
| 1747 | void *ptr; |
| 1748 | unsigned int idx; |
| 1749 | |
| 1750 | idx = arg_p[0].data.sint; |
| 1751 | |
| 1752 | t = arg_p[1].data.t; |
| 1753 | |
| 1754 | key = smp_to_stkey(smp, t); |
| 1755 | if (!key) |
| 1756 | return 0; |
| 1757 | |
| 1758 | ts = stktable_lookup_key(t, key); |
| 1759 | |
| 1760 | smp->flags = SMP_F_VOL_TEST; |
| 1761 | smp->data.type = SMP_T_SINT; |
| 1762 | smp->data.u.sint = 0; |
| 1763 | |
| 1764 | if (!ts) /* key not present */ |
| 1765 | return 1; |
| 1766 | |
| 1767 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, idx); |
| 1768 | if (ptr) |
| 1769 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1770 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1771 | |
| 1772 | stktable_release(t, ts); |
| 1773 | return !!ptr; |
| 1774 | } |
| 1775 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1776 | /* 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] | 1777 | * it up into this table. Returns the value of the GPC0 counter for the key |
| 1778 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1779 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1780 | * <not found> is returned. |
| 1781 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1782 | 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] | 1783 | { |
| 1784 | struct stktable *t; |
| 1785 | struct stktable_key *key; |
| 1786 | struct stksess *ts; |
| 1787 | void *ptr; |
| 1788 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1789 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1790 | |
| 1791 | key = smp_to_stkey(smp, t); |
| 1792 | if (!key) |
| 1793 | return 0; |
| 1794 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1795 | ts = stktable_lookup_key(t, key); |
| 1796 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1797 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1798 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1799 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1800 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1801 | if (!ts) /* key not present */ |
| 1802 | return 1; |
| 1803 | |
| 1804 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1805 | if (!ptr) { |
| 1806 | /* fallback on the gpc array */ |
| 1807 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, 0); |
| 1808 | } |
| 1809 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1810 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1811 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1812 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1813 | stktable_release(t, ts); |
| 1814 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1818 | * it up into this table. Returns the event rate of the GPC0 counter for the key |
| 1819 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1820 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1821 | * <not found> is returned. |
| 1822 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1823 | 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] | 1824 | { |
| 1825 | struct stktable *t; |
| 1826 | struct stktable_key *key; |
| 1827 | struct stksess *ts; |
| 1828 | void *ptr; |
| 1829 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1830 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1831 | |
| 1832 | key = smp_to_stkey(smp, t); |
| 1833 | if (!key) |
| 1834 | return 0; |
| 1835 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1836 | ts = stktable_lookup_key(t, key); |
| 1837 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1838 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1839 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1840 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1841 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1842 | if (!ts) /* key not present */ |
| 1843 | return 1; |
| 1844 | |
| 1845 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1846 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1847 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1848 | t->data_arg[STKTABLE_DT_GPC0_RATE].u); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1849 | else { |
| 1850 | /* fallback on the gpc array */ |
| 1851 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, 0); |
| 1852 | if (ptr) |
| 1853 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1854 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1855 | } |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1856 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1857 | stktable_release(t, ts); |
| 1858 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | /* 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] | 1862 | * it up into this table. Returns the value of the GPC1 counter for the key |
| 1863 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1864 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1865 | * <not found> is returned. |
| 1866 | */ |
| 1867 | static int sample_conv_table_gpc1(const struct arg *arg_p, struct sample *smp, void *private) |
| 1868 | { |
| 1869 | struct stktable *t; |
| 1870 | struct stktable_key *key; |
| 1871 | struct stksess *ts; |
| 1872 | void *ptr; |
| 1873 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1874 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1875 | |
| 1876 | key = smp_to_stkey(smp, t); |
| 1877 | if (!key) |
| 1878 | return 0; |
| 1879 | |
| 1880 | ts = stktable_lookup_key(t, key); |
| 1881 | |
| 1882 | smp->flags = SMP_F_VOL_TEST; |
| 1883 | smp->data.type = SMP_T_SINT; |
| 1884 | smp->data.u.sint = 0; |
| 1885 | |
| 1886 | if (!ts) /* key not present */ |
| 1887 | return 1; |
| 1888 | |
| 1889 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1890 | if (!ptr) { |
| 1891 | /* fallback on the gpc array */ |
| 1892 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, 1); |
| 1893 | } |
| 1894 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1895 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1896 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1897 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1898 | stktable_release(t, ts); |
| 1899 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1903 | * it up into this table. Returns the event rate of the GPC1 counter for the key |
| 1904 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1905 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1906 | * <not found> is returned. |
| 1907 | */ |
| 1908 | static int sample_conv_table_gpc1_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 1909 | { |
| 1910 | struct stktable *t; |
| 1911 | struct stktable_key *key; |
| 1912 | struct stksess *ts; |
| 1913 | void *ptr; |
| 1914 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1915 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1916 | |
| 1917 | key = smp_to_stkey(smp, t); |
| 1918 | if (!key) |
| 1919 | return 0; |
| 1920 | |
| 1921 | ts = stktable_lookup_key(t, key); |
| 1922 | |
| 1923 | smp->flags = SMP_F_VOL_TEST; |
| 1924 | smp->data.type = SMP_T_SINT; |
| 1925 | smp->data.u.sint = 0; |
| 1926 | |
| 1927 | if (!ts) /* key not present */ |
| 1928 | return 1; |
| 1929 | |
| 1930 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1931 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1932 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1933 | t->data_arg[STKTABLE_DT_GPC1_RATE].u); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1934 | else { |
| 1935 | /* fallback on the gpc array */ |
| 1936 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, 1); |
| 1937 | if (ptr) |
| 1938 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1939 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1940 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1941 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1942 | stktable_release(t, ts); |
| 1943 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | /* 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] | 1947 | * it up into this table. Returns the cumulated number of HTTP request errors |
| 1948 | * for the key if the key is present in the table, otherwise zero, so that |
| 1949 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 1950 | * in the table, <not found> is returned. |
| 1951 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1952 | 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] | 1953 | { |
| 1954 | struct stktable *t; |
| 1955 | struct stktable_key *key; |
| 1956 | struct stksess *ts; |
| 1957 | void *ptr; |
| 1958 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1959 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1960 | |
| 1961 | key = smp_to_stkey(smp, t); |
| 1962 | if (!key) |
| 1963 | return 0; |
| 1964 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1965 | ts = stktable_lookup_key(t, key); |
| 1966 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1967 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1968 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1969 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1970 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1971 | if (!ts) /* key not present */ |
| 1972 | return 1; |
| 1973 | |
| 1974 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1975 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1976 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
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 HTTP request error rate the key |
| 1984 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1985 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1986 | * <not found> is returned. |
| 1987 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1988 | 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] | 1989 | { |
| 1990 | struct stktable *t; |
| 1991 | struct stktable_key *key; |
| 1992 | struct stksess *ts; |
| 1993 | void *ptr; |
| 1994 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1995 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1996 | |
| 1997 | key = smp_to_stkey(smp, t); |
| 1998 | if (!key) |
| 1999 | return 0; |
| 2000 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2001 | ts = stktable_lookup_key(t, key); |
| 2002 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2003 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2004 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2005 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2006 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2007 | if (!ts) /* key not present */ |
| 2008 | return 1; |
| 2009 | |
| 2010 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2011 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2012 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2013 | t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2014 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2015 | stktable_release(t, ts); |
| 2016 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | /* 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] | 2020 | * it up into this table. Returns the cumulated number of HTTP response failures |
| 2021 | * for the key if the key is present in the table, otherwise zero, so that |
| 2022 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 2023 | * in the table, <not found> is returned. |
| 2024 | */ |
| 2025 | static int sample_conv_table_http_fail_cnt(const struct arg *arg_p, struct sample *smp, void *private) |
| 2026 | { |
| 2027 | struct stktable *t; |
| 2028 | struct stktable_key *key; |
| 2029 | struct stksess *ts; |
| 2030 | void *ptr; |
| 2031 | |
| 2032 | t = arg_p[0].data.t; |
| 2033 | |
| 2034 | key = smp_to_stkey(smp, t); |
| 2035 | if (!key) |
| 2036 | return 0; |
| 2037 | |
| 2038 | ts = stktable_lookup_key(t, key); |
| 2039 | |
| 2040 | smp->flags = SMP_F_VOL_TEST; |
| 2041 | smp->data.type = SMP_T_SINT; |
| 2042 | smp->data.u.sint = 0; |
| 2043 | |
| 2044 | if (!ts) /* key not present */ |
| 2045 | return 1; |
| 2046 | |
| 2047 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_CNT); |
| 2048 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2049 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2050 | |
| 2051 | stktable_release(t, ts); |
| 2052 | return !!ptr; |
| 2053 | } |
| 2054 | |
| 2055 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2056 | * it up into this table. Returns the HTTP response failure rate for the key |
| 2057 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2058 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2059 | * <not found> is returned. |
| 2060 | */ |
| 2061 | static int sample_conv_table_http_fail_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 2062 | { |
| 2063 | struct stktable *t; |
| 2064 | struct stktable_key *key; |
| 2065 | struct stksess *ts; |
| 2066 | void *ptr; |
| 2067 | |
| 2068 | t = arg_p[0].data.t; |
| 2069 | |
| 2070 | key = smp_to_stkey(smp, t); |
| 2071 | if (!key) |
| 2072 | return 0; |
| 2073 | |
| 2074 | ts = stktable_lookup_key(t, key); |
| 2075 | |
| 2076 | smp->flags = SMP_F_VOL_TEST; |
| 2077 | smp->data.type = SMP_T_SINT; |
| 2078 | smp->data.u.sint = 0; |
| 2079 | |
| 2080 | if (!ts) /* key not present */ |
| 2081 | return 1; |
| 2082 | |
| 2083 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_RATE); |
| 2084 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2085 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2086 | t->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u); |
| 2087 | |
| 2088 | stktable_release(t, ts); |
| 2089 | return !!ptr; |
| 2090 | } |
| 2091 | |
| 2092 | /* 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] | 2093 | * it up into this table. Returns the cumulated number of HTTP request for the |
| 2094 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 2095 | * can be easily performed. If the inspected parameter is not stored in the |
| 2096 | * table, <not found> is returned. |
| 2097 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2098 | 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] | 2099 | { |
| 2100 | struct stktable *t; |
| 2101 | struct stktable_key *key; |
| 2102 | struct stksess *ts; |
| 2103 | void *ptr; |
| 2104 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2105 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2106 | |
| 2107 | key = smp_to_stkey(smp, t); |
| 2108 | if (!key) |
| 2109 | return 0; |
| 2110 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2111 | ts = stktable_lookup_key(t, key); |
| 2112 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2113 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2114 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2115 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2116 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2117 | if (!ts) /* key not present */ |
| 2118 | return 1; |
| 2119 | |
| 2120 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2121 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2122 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2123 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2124 | stktable_release(t, ts); |
| 2125 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2129 | * it up into this table. Returns the HTTP request rate the key if the key is |
| 2130 | * present in the table, otherwise zero, so that comparisons can be easily |
| 2131 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 2132 | * is returned. |
| 2133 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2134 | 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] | 2135 | { |
| 2136 | struct stktable *t; |
| 2137 | struct stktable_key *key; |
| 2138 | struct stksess *ts; |
| 2139 | void *ptr; |
| 2140 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2141 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2142 | |
| 2143 | key = smp_to_stkey(smp, t); |
| 2144 | if (!key) |
| 2145 | return 0; |
| 2146 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2147 | ts = stktable_lookup_key(t, key); |
| 2148 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2149 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2150 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2151 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2152 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2153 | if (!ts) /* key not present */ |
| 2154 | return 1; |
| 2155 | |
| 2156 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2157 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2158 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2159 | t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2160 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2161 | stktable_release(t, ts); |
| 2162 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2166 | * it up into this table. Returns the volume of datareceived from clients in kbytes |
| 2167 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2168 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2169 | * <not found> is returned. |
| 2170 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2171 | 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] | 2172 | { |
| 2173 | struct stktable *t; |
| 2174 | struct stktable_key *key; |
| 2175 | struct stksess *ts; |
| 2176 | void *ptr; |
| 2177 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2178 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2179 | |
| 2180 | key = smp_to_stkey(smp, t); |
| 2181 | if (!key) |
| 2182 | return 0; |
| 2183 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2184 | ts = stktable_lookup_key(t, key); |
| 2185 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2186 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2187 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2188 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2189 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2190 | if (!ts) /* key not present */ |
| 2191 | return 1; |
| 2192 | |
| 2193 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2194 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2195 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2196 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2197 | stktable_release(t, ts); |
| 2198 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2202 | * it up into this table. Returns the volume of data sent to clients in kbytes |
| 2203 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2204 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2205 | * <not found> is returned. |
| 2206 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2207 | 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] | 2208 | { |
| 2209 | struct stktable *t; |
| 2210 | struct stktable_key *key; |
| 2211 | struct stksess *ts; |
| 2212 | void *ptr; |
| 2213 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2214 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2215 | |
| 2216 | key = smp_to_stkey(smp, t); |
| 2217 | if (!key) |
| 2218 | return 0; |
| 2219 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2220 | ts = stktable_lookup_key(t, key); |
| 2221 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2222 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2223 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2224 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2225 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2226 | if (!ts) /* key not present */ |
| 2227 | return 1; |
| 2228 | |
| 2229 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2230 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2231 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2232 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2233 | stktable_release(t, ts); |
| 2234 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2238 | * it up into this table. Returns the server ID associated with the key if the |
| 2239 | * key is present in the table, otherwise zero, so that comparisons can be |
| 2240 | * easily performed. If the inspected parameter is not stored in the table, |
| 2241 | * <not found> is returned. |
| 2242 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2243 | 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] | 2244 | { |
| 2245 | struct stktable *t; |
| 2246 | struct stktable_key *key; |
| 2247 | struct stksess *ts; |
| 2248 | void *ptr; |
| 2249 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2250 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2251 | |
| 2252 | key = smp_to_stkey(smp, t); |
| 2253 | if (!key) |
| 2254 | return 0; |
| 2255 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2256 | ts = stktable_lookup_key(t, key); |
| 2257 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2258 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2259 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2260 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2261 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2262 | if (!ts) /* key not present */ |
| 2263 | return 1; |
| 2264 | |
| 2265 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2266 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2267 | smp->data.u.sint = stktable_data_cast(ptr, std_t_sint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2268 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2269 | stktable_release(t, ts); |
| 2270 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2274 | * it up into this table. Returns the cumulated number of sessions for the |
| 2275 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 2276 | * can be easily performed. If the inspected parameter is not stored in the |
| 2277 | * table, <not found> is returned. |
| 2278 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2279 | 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] | 2280 | { |
| 2281 | struct stktable *t; |
| 2282 | struct stktable_key *key; |
| 2283 | struct stksess *ts; |
| 2284 | void *ptr; |
| 2285 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2286 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2287 | |
| 2288 | key = smp_to_stkey(smp, t); |
| 2289 | if (!key) |
| 2290 | return 0; |
| 2291 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2292 | ts = stktable_lookup_key(t, key); |
| 2293 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2294 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2295 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2296 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2297 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2298 | if (!ts) /* key not present */ |
| 2299 | return 1; |
| 2300 | |
| 2301 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2302 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2303 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2304 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2305 | stktable_release(t, ts); |
| 2306 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2310 | * it up into this table. Returns the session rate the key if the key is |
| 2311 | * present in the table, otherwise zero, so that comparisons can be easily |
| 2312 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 2313 | * is returned. |
| 2314 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2315 | 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] | 2316 | { |
| 2317 | struct stktable *t; |
| 2318 | struct stktable_key *key; |
| 2319 | struct stksess *ts; |
| 2320 | void *ptr; |
| 2321 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2322 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2323 | |
| 2324 | key = smp_to_stkey(smp, t); |
| 2325 | if (!key) |
| 2326 | return 0; |
| 2327 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2328 | ts = stktable_lookup_key(t, key); |
| 2329 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2330 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2331 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2332 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2333 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2334 | if (!ts) /* key not present */ |
| 2335 | return 1; |
| 2336 | |
| 2337 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2338 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2339 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2340 | t->data_arg[STKTABLE_DT_SESS_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2341 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2342 | stktable_release(t, ts); |
| 2343 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2347 | * it up into this table. Returns the amount of concurrent connections tracking |
| 2348 | * the same key if the key is present in the table, otherwise zero, so that |
| 2349 | * comparisons can be easily performed. If the inspected parameter is not |
| 2350 | * stored in the table, <not found> is returned. |
| 2351 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2352 | 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] | 2353 | { |
| 2354 | struct stktable *t; |
| 2355 | struct stktable_key *key; |
| 2356 | struct stksess *ts; |
| 2357 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2358 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2359 | |
| 2360 | key = smp_to_stkey(smp, t); |
| 2361 | if (!key) |
| 2362 | return 0; |
| 2363 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2364 | ts = stktable_lookup_key(t, key); |
| 2365 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2366 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2367 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2368 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2369 | |
Tim Duesterhus | 65189c1 | 2018-06-26 15:57:29 +0200 | [diff] [blame] | 2370 | if (!ts) |
| 2371 | return 1; |
| 2372 | |
| 2373 | smp->data.u.sint = ts->ref_cnt; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2374 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2375 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2376 | return 1; |
| 2377 | } |
| 2378 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2379 | /* This function increments the gpc counter at index 'rule->arg.gpc.idx' of the |
| 2380 | * array on the tracksc counter of index 'rule->arg.gpc.sc' stored into the |
| 2381 | * <stream> or directly in the session <sess> if <stream> is set to NULL |
| 2382 | * |
| 2383 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2384 | */ |
| 2385 | static enum act_return action_inc_gpc(struct act_rule *rule, struct proxy *px, |
| 2386 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2387 | { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2388 | struct stksess *ts; |
| 2389 | struct stkctr *stkctr; |
| 2390 | |
| 2391 | /* Extract the stksess, return OK if no stksess available. */ |
| 2392 | if (s) |
| 2393 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2394 | else |
| 2395 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2396 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2397 | ts = stkctr_entry(stkctr); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2398 | if (ts) { |
| 2399 | void *ptr1, *ptr2; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2400 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2401 | /* First, update gpc_rate if it's tracked. Second, update its gpc if tracked. */ |
| 2402 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, rule->arg.gpc.idx); |
| 2403 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, rule->arg.gpc.idx); |
| 2404 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2405 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2406 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2407 | |
| 2408 | if (ptr1) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2409 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2410 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, 1); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2411 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2412 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2413 | stktable_data_cast(ptr2, std_t_uint)++; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2414 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2415 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2416 | |
| 2417 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2418 | stktable_touch_local(stkctr->table, ts, 0); |
| 2419 | } |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2420 | } |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2421 | return ACT_RET_CONT; |
| 2422 | } |
| 2423 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2424 | /* Same as action_inc_gpc() but for gpc0 only */ |
| 2425 | static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px, |
| 2426 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2427 | { |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2428 | struct stksess *ts; |
| 2429 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 2430 | unsigned int period = 0; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2431 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2432 | /* Extract the stksess, return OK if no stksess available. */ |
| 2433 | if (s) |
| 2434 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2435 | else |
| 2436 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2437 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2438 | ts = stkctr_entry(stkctr); |
| 2439 | if (ts) { |
| 2440 | void *ptr1, *ptr2; |
| 2441 | |
| 2442 | /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */ |
| 2443 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2444 | if (ptr1) { |
| 2445 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 2446 | } |
| 2447 | else { |
| 2448 | /* fallback on the gpc array */ |
| 2449 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, 0); |
| 2450 | if (ptr1) |
| 2451 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 2452 | } |
| 2453 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2454 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2455 | if (!ptr2) { |
| 2456 | /* fallback on the gpc array */ |
| 2457 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, 0); |
| 2458 | } |
| 2459 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2460 | if (ptr1 || ptr2) { |
| 2461 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2462 | |
| 2463 | if (ptr1) |
| 2464 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2465 | period, 1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2466 | |
| 2467 | if (ptr2) |
| 2468 | stktable_data_cast(ptr2, std_t_uint)++; |
| 2469 | |
| 2470 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2471 | |
| 2472 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2473 | stktable_touch_local(stkctr->table, ts, 0); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2474 | } |
| 2475 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2476 | return ACT_RET_CONT; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2477 | } |
| 2478 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2479 | /* Same as action_inc_gpc() but for gpc1 only */ |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2480 | static enum act_return action_inc_gpc1(struct act_rule *rule, struct proxy *px, |
| 2481 | struct session *sess, struct stream *s, int flags) |
| 2482 | { |
| 2483 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2484 | struct stkctr *stkctr = NULL; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 2485 | unsigned int period = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2486 | |
| 2487 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2488 | if (s && s->stkctr) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2489 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2490 | else if (sess->stkctr) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2491 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2492 | else |
| 2493 | return ACT_RET_CONT; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2494 | |
| 2495 | ts = stkctr_entry(stkctr); |
| 2496 | if (ts) { |
| 2497 | void *ptr1, *ptr2; |
| 2498 | |
| 2499 | /* First, update gpc1_rate if it's tracked. Second, update its gpc1 if tracked. */ |
| 2500 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2501 | if (ptr1) { |
| 2502 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 2503 | } |
| 2504 | else { |
| 2505 | /* fallback on the gpc array */ |
| 2506 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, 1); |
| 2507 | if (ptr1) |
| 2508 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 2509 | } |
| 2510 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2511 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2512 | if (!ptr2) { |
| 2513 | /* fallback on the gpc array */ |
| 2514 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, 1); |
| 2515 | } |
| 2516 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2517 | if (ptr1 || ptr2) { |
| 2518 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2519 | |
| 2520 | if (ptr1) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2521 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2522 | period, 1); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2523 | |
| 2524 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2525 | stktable_data_cast(ptr2, std_t_uint)++; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2526 | |
| 2527 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2528 | |
| 2529 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2530 | stktable_touch_local(stkctr->table, ts, 0); |
| 2531 | } |
| 2532 | } |
| 2533 | return ACT_RET_CONT; |
| 2534 | } |
| 2535 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2536 | /* This function is a common parser for actions incrementing the GPC |
| 2537 | * (General Purpose Counters). It understands the formats: |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2538 | * |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2539 | * sc-inc-gpc(<gpc IDX>,<track ID>) |
| 2540 | * sc-inc-gpc0([<track ID>]) |
| 2541 | * sc-inc-gpc1([<track ID>]) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2542 | * |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2543 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error |
| 2544 | * message. Otherwise it returns ACT_RET_PRS_OK. |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2545 | */ |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2546 | static enum act_parse_ret parse_inc_gpc(const char **args, int *arg, struct proxy *px, |
| 2547 | struct act_rule *rule, char **err) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2548 | { |
| 2549 | const char *cmd_name = args[*arg-1]; |
| 2550 | char *error; |
| 2551 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2552 | if (!global.tune.nb_stk_ctr) { |
| 2553 | memprintf(err, "Cannot use '%s', stick-counters are disabled via tune.stick-counters", args[*arg-1]); |
| 2554 | return ACT_RET_PRS_ERR; |
| 2555 | } |
| 2556 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2557 | cmd_name += strlen("sc-inc-gpc"); |
| 2558 | if (*cmd_name == '(') { |
| 2559 | cmd_name++; /* skip the '(' */ |
| 2560 | rule->arg.gpc.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2561 | if (*error != ',') { |
| 2562 | memprintf(err, "Missing gpc ID '%s'. Expects sc-inc-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2563 | return ACT_RET_PRS_ERR; |
| 2564 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2565 | else { |
| 2566 | cmd_name = error + 1; /* skip the ',' */ |
| 2567 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2568 | if (*error != ')') { |
| 2569 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-inc-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2570 | return ACT_RET_PRS_ERR; |
| 2571 | } |
| 2572 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2573 | if (rule->arg.gpc.sc >= global.tune.nb_stk_ctr) { |
| 2574 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d (tune.stick-counters)", |
| 2575 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2576 | return ACT_RET_PRS_ERR; |
| 2577 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2578 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2579 | rule->action_ptr = action_inc_gpc; |
| 2580 | } |
| 2581 | else if (*cmd_name == '0' ||*cmd_name == '1') { |
| 2582 | char c = *cmd_name; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2583 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2584 | cmd_name++; |
| 2585 | if (*cmd_name == '\0') { |
| 2586 | /* default stick table id. */ |
| 2587 | rule->arg.gpc.sc = 0; |
| 2588 | } else { |
| 2589 | /* parse the stick table id. */ |
| 2590 | if (*cmd_name != '(') { |
| 2591 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 2592 | return ACT_RET_PRS_ERR; |
| 2593 | } |
| 2594 | cmd_name++; /* jump the '(' */ |
| 2595 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2596 | if (*error != ')') { |
| 2597 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 2598 | return ACT_RET_PRS_ERR; |
| 2599 | } |
| 2600 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2601 | if (rule->arg.gpc.sc >= global.tune.nb_stk_ctr) { |
| 2602 | memprintf(err, "invalid stick table track ID. The max allowed ID is %d (tune.stick-counters)", |
| 2603 | global.tune.nb_stk_ctr-1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2604 | return ACT_RET_PRS_ERR; |
| 2605 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2606 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2607 | if (c == '1') |
| 2608 | rule->action_ptr = action_inc_gpc1; |
| 2609 | else |
| 2610 | rule->action_ptr = action_inc_gpc0; |
| 2611 | } |
| 2612 | else { |
| 2613 | /* default stick table id. */ |
Willy Tarreau | 2039151 | 2023-01-02 17:35:50 +0100 | [diff] [blame] | 2614 | memprintf(err, "invalid gpc ID '%s'. Expects sc-inc-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2615 | return ACT_RET_PRS_ERR; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2616 | } |
| 2617 | rule->action = ACT_CUSTOM; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2618 | return ACT_RET_PRS_OK; |
| 2619 | } |
| 2620 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2621 | /* This function sets the gpt at index 'rule->arg.gpt.idx' of the array on the |
| 2622 | * tracksc counter of index 'rule->arg.gpt.sc' stored into the <stream> or |
| 2623 | * directly in the session <sess> if <stream> is set to NULL. This gpt is |
| 2624 | * set to the value computed by the expression 'rule->arg.gpt.expr' or if |
| 2625 | * 'rule->arg.gpt.expr' is null directly to the value of 'rule->arg.gpt.value'. |
| 2626 | * |
| 2627 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2628 | */ |
| 2629 | static enum act_return action_set_gpt(struct act_rule *rule, struct proxy *px, |
| 2630 | struct session *sess, struct stream *s, int flags) |
| 2631 | { |
| 2632 | void *ptr; |
| 2633 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2634 | struct stkctr *stkctr = NULL; |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2635 | unsigned int value = 0; |
| 2636 | struct sample *smp; |
| 2637 | int smp_opt_dir; |
| 2638 | |
| 2639 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2640 | if (s && s->stkctr) |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2641 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2642 | else if (sess->stkctr) |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2643 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2644 | else |
| 2645 | return ACT_RET_CONT; |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2646 | |
| 2647 | ts = stkctr_entry(stkctr); |
| 2648 | if (!ts) |
| 2649 | return ACT_RET_CONT; |
| 2650 | |
| 2651 | /* Store the sample in the required sc, and ignore errors. */ |
| 2652 | ptr = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPT, rule->arg.gpt.idx); |
| 2653 | if (ptr) { |
| 2654 | |
| 2655 | if (!rule->arg.gpt.expr) |
| 2656 | value = (unsigned int)(rule->arg.gpt.value); |
| 2657 | else { |
| 2658 | switch (rule->from) { |
Aurelien DARRAGON | e18fe56 | 2023-08-09 17:23:32 +0200 | [diff] [blame] | 2659 | case ACT_F_TCP_REQ_CON: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2660 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2661 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2662 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2663 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2664 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2665 | default: |
| 2666 | send_log(px, LOG_ERR, "stick table: internal error while setting gpt%u.", rule->arg.gpt.idx); |
| 2667 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2668 | ha_alert("stick table: internal error while executing setting gpt%u.\n", rule->arg.gpt.idx); |
| 2669 | return ACT_RET_CONT; |
| 2670 | } |
| 2671 | |
| 2672 | /* Fetch and cast the expression. */ |
| 2673 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT); |
| 2674 | if (!smp) { |
| 2675 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt%u.", rule->arg.gpt.idx); |
| 2676 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2677 | ha_alert("stick table: invalid expression or data type while setting gpt%u.\n", rule->arg.gpt.idx); |
| 2678 | return ACT_RET_CONT; |
| 2679 | } |
| 2680 | value = (unsigned int)(smp->data.u.sint); |
| 2681 | } |
| 2682 | |
| 2683 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2684 | |
| 2685 | stktable_data_cast(ptr, std_t_uint) = value; |
| 2686 | |
| 2687 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2688 | |
| 2689 | stktable_touch_local(stkctr->table, ts, 0); |
| 2690 | } |
| 2691 | |
| 2692 | return ACT_RET_CONT; |
| 2693 | } |
| 2694 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2695 | /* Always returns 1. */ |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2696 | 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] | 2697 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2698 | { |
| 2699 | void *ptr; |
| 2700 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2701 | struct stkctr *stkctr = NULL; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2702 | unsigned int value = 0; |
| 2703 | struct sample *smp; |
| 2704 | int smp_opt_dir; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2705 | |
| 2706 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2707 | if (s && s->stkctr) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2708 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2709 | else if (sess->stkctr) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2710 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2711 | else |
| 2712 | return ACT_RET_CONT; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2713 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2714 | ts = stkctr_entry(stkctr); |
| 2715 | if (!ts) |
| 2716 | return ACT_RET_CONT; |
| 2717 | |
| 2718 | /* Store the sample in the required sc, and ignore errors. */ |
| 2719 | ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 2720 | if (!ptr) |
| 2721 | ptr = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPT, 0); |
| 2722 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2723 | if (ptr) { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2724 | if (!rule->arg.gpt.expr) |
| 2725 | value = (unsigned int)(rule->arg.gpt.value); |
| 2726 | else { |
| 2727 | switch (rule->from) { |
Aurelien DARRAGON | e18fe56 | 2023-08-09 17:23:32 +0200 | [diff] [blame] | 2728 | 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] | 2729 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2730 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2731 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2732 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2733 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2734 | default: |
| 2735 | send_log(px, LOG_ERR, "stick table: internal error while setting gpt0."); |
| 2736 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2737 | ha_alert("stick table: internal error while executing setting gpt0.\n"); |
| 2738 | return ACT_RET_CONT; |
| 2739 | } |
| 2740 | |
| 2741 | /* Fetch and cast the expression. */ |
| 2742 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT); |
| 2743 | if (!smp) { |
| 2744 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt0."); |
| 2745 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2746 | ha_alert("stick table: invalid expression or data type while setting gpt0.\n"); |
| 2747 | return ACT_RET_CONT; |
| 2748 | } |
| 2749 | value = (unsigned int)(smp->data.u.sint); |
| 2750 | } |
| 2751 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2752 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2753 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2754 | stktable_data_cast(ptr, std_t_uint) = value; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2755 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2756 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2757 | |
| 2758 | stktable_touch_local(stkctr->table, ts, 0); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2759 | } |
| 2760 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2761 | return ACT_RET_CONT; |
| 2762 | } |
| 2763 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2764 | /* This function is a parser for the "sc-set-gpt" and "sc-set-gpt0" actions. |
| 2765 | * It understands the formats: |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2766 | * |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2767 | * sc-set-gpt(<gpt IDX>,<track ID>) <expression> |
| 2768 | * sc-set-gpt0(<track ID>) <expression> |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2769 | * |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2770 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error message. |
| 2771 | * Otherwise, it returns ACT_RET_PRS_OK and the variable 'rule->arg.gpt.expr' |
| 2772 | * is filled with the pointer to the expression to execute or NULL if the arg |
| 2773 | * is directly an integer stored into 'rule->arg.gpt.value'. |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2774 | */ |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2775 | static enum act_parse_ret parse_set_gpt(const char **args, int *arg, struct proxy *px, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2776 | struct act_rule *rule, char **err) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2777 | { |
| 2778 | const char *cmd_name = args[*arg-1]; |
| 2779 | char *error; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2780 | int smp_val; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2781 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2782 | if (!global.tune.nb_stk_ctr) { |
| 2783 | memprintf(err, "Cannot use '%s', stick-counters are disabled via tune.stick-counters", args[*arg-1]); |
| 2784 | return ACT_RET_PRS_ERR; |
| 2785 | } |
| 2786 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2787 | cmd_name += strlen("sc-set-gpt"); |
| 2788 | if (*cmd_name == '(') { |
| 2789 | cmd_name++; /* skip the '(' */ |
| 2790 | rule->arg.gpt.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2791 | if (*error != ',') { |
| 2792 | memprintf(err, "Missing gpt ID '%s'. Expects sc-set-gpt(<GPT ID>,<Track ID>)", args[*arg-1]); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2793 | return ACT_RET_PRS_ERR; |
| 2794 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2795 | else { |
| 2796 | cmd_name = error + 1; /* skip the ',' */ |
| 2797 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2798 | if (*error != ')') { |
| 2799 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt(<GPT ID>,<Track ID>)", args[*arg-1]); |
| 2800 | return ACT_RET_PRS_ERR; |
| 2801 | } |
| 2802 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2803 | if (rule->arg.gpt.sc >= global.tune.nb_stk_ctr) { |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2804 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d", |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2805 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2806 | return ACT_RET_PRS_ERR; |
| 2807 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2808 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2809 | rule->action_ptr = action_set_gpt; |
| 2810 | } |
| 2811 | else if (*cmd_name == '0') { |
| 2812 | cmd_name++; |
| 2813 | if (*cmd_name == '\0') { |
| 2814 | /* default stick table id. */ |
| 2815 | rule->arg.gpt.sc = 0; |
| 2816 | } else { |
| 2817 | /* parse the stick table id. */ |
| 2818 | if (*cmd_name != '(') { |
| 2819 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2820 | return ACT_RET_PRS_ERR; |
| 2821 | } |
| 2822 | cmd_name++; /* jump the '(' */ |
| 2823 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2824 | if (*error != ')') { |
| 2825 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2826 | return ACT_RET_PRS_ERR; |
| 2827 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2828 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2829 | if (rule->arg.gpt.sc >= global.tune.nb_stk_ctr) { |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2830 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d", |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2831 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2832 | return ACT_RET_PRS_ERR; |
| 2833 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2834 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2835 | rule->action_ptr = action_set_gpt0; |
| 2836 | } |
| 2837 | else { |
| 2838 | /* default stick table id. */ |
| 2839 | memprintf(err, "invalid gpt ID '%s'. Expects sc-set-gpt(<GPT ID>,<Track ID>)", args[*arg-1]); |
| 2840 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2841 | } |
| 2842 | |
Willy Tarreau | ece4c4a | 2021-08-24 14:57:28 +0200 | [diff] [blame] | 2843 | /* value may be either an integer or an expression */ |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2844 | rule->arg.gpt.expr = NULL; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2845 | rule->arg.gpt.value = strtol(args[*arg], &error, 10); |
Willy Tarreau | ece4c4a | 2021-08-24 14:57:28 +0200 | [diff] [blame] | 2846 | if (*error == '\0') { |
| 2847 | /* valid integer, skip it */ |
| 2848 | (*arg)++; |
| 2849 | } else { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2850 | 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] | 2851 | px->conf.args.line, err, &px->conf.args, NULL); |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2852 | if (!rule->arg.gpt.expr) |
| 2853 | return ACT_RET_PRS_ERR; |
| 2854 | |
| 2855 | switch (rule->from) { |
Aurelien DARRAGON | e18fe56 | 2023-08-09 17:23:32 +0200 | [diff] [blame] | 2856 | 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] | 2857 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 2858 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 2859 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 2860 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 2861 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 2862 | default: |
| 2863 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 2864 | return ACT_RET_PRS_ERR; |
| 2865 | } |
| 2866 | if (!(rule->arg.gpt.expr->fetch->val & smp_val)) { |
| 2867 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 2868 | sample_src_names(rule->arg.gpt.expr->fetch->use)); |
| 2869 | free(rule->arg.gpt.expr); |
| 2870 | return ACT_RET_PRS_ERR; |
| 2871 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2872 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2873 | |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 2874 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2875 | |
| 2876 | return ACT_RET_PRS_OK; |
| 2877 | } |
| 2878 | |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 2879 | /* This function updates the gpc at index 'rule->arg.gpc.idx' of the array on |
| 2880 | * the tracksc counter of index 'rule->arg.gpc.sc' stored into the <stream> or |
| 2881 | * directly in the session <sess> if <stream> is set to NULL. This gpc is |
| 2882 | * set to the value computed by the expression 'rule->arg.gpc.expr' or if |
| 2883 | * 'rule->arg.gpc.expr' is null directly to the value of 'rule->arg.gpc.value'. |
| 2884 | * |
| 2885 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2886 | */ |
| 2887 | static enum act_return action_add_gpc(struct act_rule *rule, struct proxy *px, |
| 2888 | struct session *sess, struct stream *s, int flags) |
| 2889 | { |
| 2890 | void *ptr1, *ptr2; |
| 2891 | struct stksess *ts; |
| 2892 | struct stkctr *stkctr; |
| 2893 | unsigned int value = 0; |
| 2894 | struct sample *smp; |
| 2895 | int smp_opt_dir; |
| 2896 | |
| 2897 | /* Extract the stksess, return OK if no stksess available. */ |
| 2898 | if (s) |
| 2899 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2900 | else |
| 2901 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
| 2902 | |
| 2903 | ts = stkctr_entry(stkctr); |
| 2904 | if (!ts) |
| 2905 | return ACT_RET_CONT; |
| 2906 | |
| 2907 | /* First, update gpc_rate if it's tracked. Second, update its gpc if tracked. */ |
| 2908 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, rule->arg.gpc.idx); |
| 2909 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, rule->arg.gpc.idx); |
| 2910 | |
| 2911 | if (ptr1 || ptr2) { |
| 2912 | if (!rule->arg.gpc.expr) |
| 2913 | value = (unsigned int)(rule->arg.gpc.value); |
| 2914 | else { |
| 2915 | switch (rule->from) { |
Aurelien DARRAGON | b425f75 | 2023-08-09 17:39:29 +0200 | [diff] [blame] | 2916 | case ACT_F_TCP_REQ_CON: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 2917 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2918 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2919 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2920 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2921 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2922 | default: |
| 2923 | send_log(px, LOG_ERR, "stick table: internal error while setting gpc%u.", rule->arg.gpc.idx); |
| 2924 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2925 | ha_alert("stick table: internal error while executing setting gpc%u.\n", rule->arg.gpc.idx); |
| 2926 | return ACT_RET_CONT; |
| 2927 | } |
| 2928 | |
| 2929 | /* Fetch and cast the expression. */ |
| 2930 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpc.expr, SMP_T_SINT); |
| 2931 | if (!smp) { |
| 2932 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpc%u.", rule->arg.gpc.idx); |
| 2933 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2934 | ha_alert("stick table: invalid expression or data type while setting gpc%u.\n", rule->arg.gpc.idx); |
| 2935 | return ACT_RET_CONT; |
| 2936 | } |
| 2937 | value = (unsigned int)(smp->data.u.sint); |
| 2938 | } |
| 2939 | |
| 2940 | if (value) { |
| 2941 | /* only update the value if non-null increment */ |
| 2942 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2943 | |
| 2944 | if (ptr1) |
| 2945 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 2946 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, value); |
| 2947 | |
| 2948 | if (ptr2) |
| 2949 | stktable_data_cast(ptr2, std_t_uint) += value; |
| 2950 | |
| 2951 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2952 | } |
| 2953 | /* always touch the table so that it doesn't expire */ |
| 2954 | stktable_touch_local(stkctr->table, ts, 0); |
| 2955 | } |
| 2956 | |
| 2957 | return ACT_RET_CONT; |
| 2958 | } |
| 2959 | |
| 2960 | /* This function is a parser for the "sc-add-gpc" action. It understands the |
| 2961 | * format: |
| 2962 | * |
| 2963 | * sc-add-gpc(<gpc IDX>,<track ID>) <expression> |
| 2964 | * |
| 2965 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error message. |
| 2966 | * Otherwise, it returns ACT_RET_PRS_OK and the variable 'rule->arg.gpc.expr' |
| 2967 | * is filled with the pointer to the expression to execute or NULL if the arg |
| 2968 | * is directly an integer stored into 'rule->arg.gpt.value'. |
| 2969 | */ |
| 2970 | static enum act_parse_ret parse_add_gpc(const char **args, int *arg, struct proxy *px, |
| 2971 | struct act_rule *rule, char **err) |
| 2972 | { |
| 2973 | const char *cmd_name = args[*arg-1]; |
| 2974 | char *error; |
| 2975 | int smp_val; |
| 2976 | |
| 2977 | cmd_name += strlen("sc-add-gpc"); |
| 2978 | if (*cmd_name != '(') { |
| 2979 | memprintf(err, "Missing or invalid arguments for '%s'. Expects sc-add-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2980 | return ACT_RET_PRS_ERR; |
| 2981 | } |
| 2982 | cmd_name++; /* skip the '(' */ |
| 2983 | rule->arg.gpc.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2984 | if (*error != ',') { |
| 2985 | memprintf(err, "Missing gpc ID. Expects %s(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2986 | return ACT_RET_PRS_ERR; |
| 2987 | } |
| 2988 | else { |
| 2989 | cmd_name = error + 1; /* skip the ',' */ |
| 2990 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2991 | if (*error != ')') { |
| 2992 | memprintf(err, "invalid stick table track ID '%s'. Expects %s(<GPC ID>,<Track ID>)", cmd_name, args[*arg-1]); |
| 2993 | return ACT_RET_PRS_ERR; |
| 2994 | } |
| 2995 | |
| 2996 | if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) { |
| 2997 | memprintf(err, "invalid stick table track ID '%s' for '%s'. The max allowed ID is %d", |
| 2998 | cmd_name, args[*arg-1], MAX_SESS_STKCTR-1); |
| 2999 | return ACT_RET_PRS_ERR; |
| 3000 | } |
| 3001 | } |
| 3002 | rule->action_ptr = action_add_gpc; |
| 3003 | |
| 3004 | /* value may be either an integer or an expression */ |
| 3005 | rule->arg.gpc.expr = NULL; |
| 3006 | rule->arg.gpc.value = strtol(args[*arg], &error, 10); |
| 3007 | if (*error == '\0') { |
| 3008 | /* valid integer, skip it */ |
| 3009 | (*arg)++; |
| 3010 | } else { |
| 3011 | rule->arg.gpc.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, |
| 3012 | px->conf.args.line, err, &px->conf.args, NULL); |
| 3013 | if (!rule->arg.gpc.expr) |
| 3014 | return ACT_RET_PRS_ERR; |
| 3015 | |
| 3016 | switch (rule->from) { |
Aurelien DARRAGON | b425f75 | 2023-08-09 17:39:29 +0200 | [diff] [blame] | 3017 | case ACT_F_TCP_REQ_CON: smp_val = SMP_VAL_FE_CON_ACC; break; |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 3018 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 3019 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 3020 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 3021 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 3022 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 3023 | default: |
| 3024 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 3025 | return ACT_RET_PRS_ERR; |
| 3026 | } |
| 3027 | |
| 3028 | if (!(rule->arg.gpc.expr->fetch->val & smp_val)) { |
| 3029 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 3030 | sample_src_names(rule->arg.gpc.expr->fetch->use)); |
| 3031 | free(rule->arg.gpc.expr); |
| 3032 | return ACT_RET_PRS_ERR; |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | rule->action = ACT_CUSTOM; |
| 3037 | |
| 3038 | return ACT_RET_PRS_OK; |
| 3039 | } |
| 3040 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3041 | /* set temp integer to the number of used entries in the table pointed to by expr. |
| 3042 | * Accepts exactly 1 argument of type table. |
| 3043 | */ |
| 3044 | static int |
| 3045 | smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3046 | { |
| 3047 | smp->flags = SMP_F_VOL_TEST; |
| 3048 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3049 | smp->data.u.sint = args->data.t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3050 | return 1; |
| 3051 | } |
| 3052 | |
| 3053 | /* set temp integer to the number of free entries in the table pointed to by expr. |
| 3054 | * Accepts exactly 1 argument of type table. |
| 3055 | */ |
| 3056 | static int |
| 3057 | smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3058 | { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3059 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3060 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3061 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3062 | smp->flags = SMP_F_VOL_TEST; |
| 3063 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3064 | smp->data.u.sint = t->size - t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3065 | return 1; |
| 3066 | } |
| 3067 | |
| 3068 | /* Returns a pointer to a stkctr depending on the fetch keyword name. |
| 3069 | * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively. |
| 3070 | * sc[0-9]_* will return a pointer to the respective field in the |
| 3071 | * stream <l4>. sc_* requires an UINT argument specifying the stick |
| 3072 | * counter number. src_* will fill a locally allocated structure with |
| 3073 | * the table and entry corresponding to what is specified with src_*. |
| 3074 | * NULL may be returned if the designated stkctr is not tracked. For |
| 3075 | * the sc_* and sc[0-9]_* forms, an optional table argument may be |
| 3076 | * passed. When present, the currently tracked key is then looked up |
| 3077 | * in the specified table instead of the current table. The purpose is |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 3078 | * 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] | 3079 | * multiple tables). <strm> is allowed to be NULL, in which case only |
| 3080 | * the session will be consulted. |
| 3081 | */ |
| 3082 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3083 | 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] | 3084 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3085 | struct stkctr *stkptr; |
| 3086 | struct stksess *stksess; |
| 3087 | unsigned int num = kw[2] - '0'; |
| 3088 | int arg = 0; |
| 3089 | |
| 3090 | if (num == '_' - '0') { |
| 3091 | /* sc_* variant, args[0] = ctr# (mandatory) */ |
| 3092 | num = args[arg++].data.sint; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3093 | } |
| 3094 | else if (num > 9) { /* src_* variant, args[0] = table */ |
| 3095 | struct stktable_key *key; |
| 3096 | struct connection *conn = objt_conn(sess->origin); |
| 3097 | struct sample smp; |
| 3098 | |
| 3099 | if (!conn) |
| 3100 | return NULL; |
| 3101 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3102 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3103 | smp.px = NULL; |
| 3104 | smp.sess = sess; |
| 3105 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3106 | 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] | 3107 | return NULL; |
| 3108 | |
| 3109 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3110 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3111 | if (!key) |
| 3112 | return NULL; |
| 3113 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3114 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3115 | stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key)); |
| 3116 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | /* Here, <num> contains the counter number from 0 to 9 for |
| 3120 | * the sc[0-9]_ form, or even higher using sc_(num) if needed. |
| 3121 | * args[arg] is the first optional argument. We first lookup the |
| 3122 | * ctr form the stream, then from the session if it was not there. |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3123 | * But we must be sure the counter does not exceed global.tune.nb_stk_ctr. |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3124 | */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3125 | if (num >= global.tune.nb_stk_ctr) |
Christopher Faulet | a9fa88a | 2019-10-21 10:53:34 +0200 | [diff] [blame] | 3126 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3127 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3128 | stkptr = NULL; |
| 3129 | if (strm && strm->stkctr) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3130 | stkptr = &strm->stkctr[num]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3131 | if (!strm || !stkptr || !stkctr_entry(stkptr)) { |
| 3132 | if (sess->stkctr) |
| 3133 | stkptr = &sess->stkctr[num]; |
| 3134 | else |
| 3135 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3136 | if (!stkctr_entry(stkptr)) |
| 3137 | return NULL; |
| 3138 | } |
| 3139 | |
| 3140 | stksess = stkctr_entry(stkptr); |
| 3141 | if (!stksess) |
| 3142 | return NULL; |
| 3143 | |
| 3144 | if (unlikely(args[arg].type == ARGT_TAB)) { |
| 3145 | /* 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] | 3146 | stkctr->table = args[arg].data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3147 | stkctr_set_entry(stkctr, stktable_lookup(stkctr->table, stksess)); |
| 3148 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3149 | } |
| 3150 | return stkptr; |
| 3151 | } |
| 3152 | |
| 3153 | /* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create |
| 3154 | * the entry if it doesn't exist yet. This is needed for a few fetch |
| 3155 | * functions which need to create an entry, such as src_inc_gpc* and |
| 3156 | * src_clr_gpc*. |
| 3157 | */ |
| 3158 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3159 | 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] | 3160 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3161 | struct stktable_key *key; |
| 3162 | struct connection *conn = objt_conn(sess->origin); |
| 3163 | struct sample smp; |
| 3164 | |
| 3165 | if (strncmp(kw, "src_", 4) != 0) |
| 3166 | return NULL; |
| 3167 | |
| 3168 | if (!conn) |
| 3169 | return NULL; |
| 3170 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3171 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3172 | smp.px = NULL; |
| 3173 | smp.sess = sess; |
| 3174 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3175 | 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] | 3176 | return NULL; |
| 3177 | |
| 3178 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3179 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3180 | if (!key) |
| 3181 | return NULL; |
| 3182 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3183 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3184 | stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key)); |
| 3185 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | /* set return a boolean indicating if the requested stream counter is |
| 3189 | * currently being tracked or not. |
| 3190 | * Supports being called as "sc[0-9]_tracked" only. |
| 3191 | */ |
| 3192 | static int |
| 3193 | smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3194 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3195 | struct stkctr tmpstkctr; |
| 3196 | struct stkctr *stkctr; |
| 3197 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3198 | smp->flags = SMP_F_VOL_TEST; |
| 3199 | smp->data.type = SMP_T_BOOL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3200 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3201 | smp->data.u.sint = !!stkctr; |
| 3202 | |
| 3203 | /* release the ref count */ |
Dirkjan Bussink | ff57f1b | 2018-09-14 14:31:22 +0200 | [diff] [blame] | 3204 | if (stkctr == &tmpstkctr) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3205 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3206 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 3207 | return 1; |
| 3208 | } |
| 3209 | |
| 3210 | /* set <smp> to the General Purpose Tag of index set as first arg |
| 3211 | * to value from the stream's tracked frontend counters or from the src. |
| 3212 | * Supports being called as "sc_get_gpt(<gpt-idx>,<sc-idx>[,<table>])" or |
| 3213 | * "src_get_gpt(<gpt-idx>[,<table>])" only. Value zero is returned if |
| 3214 | * the key is new or gpt is not stored. |
| 3215 | */ |
| 3216 | static int |
| 3217 | smp_fetch_sc_get_gpt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3218 | { |
| 3219 | struct stkctr tmpstkctr; |
| 3220 | struct stkctr *stkctr; |
| 3221 | unsigned int idx; |
| 3222 | |
| 3223 | idx = args[0].data.sint; |
| 3224 | |
| 3225 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 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 | |
| 3233 | if (stkctr_entry(stkctr)) { |
| 3234 | void *ptr; |
| 3235 | |
| 3236 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, idx); |
| 3237 | if (!ptr) { |
| 3238 | if (stkctr == &tmpstkctr) |
| 3239 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3240 | return 0; /* parameter not stored */ |
| 3241 | } |
| 3242 | |
| 3243 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3244 | |
| 3245 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3246 | |
| 3247 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3248 | |
| 3249 | if (stkctr == &tmpstkctr) |
| 3250 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3251 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3252 | return 1; |
| 3253 | } |
| 3254 | |
| 3255 | /* set <smp> to the General Purpose Flag 0 value from the stream's tracked |
| 3256 | * frontend counters or from the src. |
| 3257 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value |
| 3258 | * zero is returned if the key is new. |
| 3259 | */ |
| 3260 | static int |
| 3261 | smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3262 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3263 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3264 | struct stkctr *stkctr; |
| 3265 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3266 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3267 | if (!stkctr) |
| 3268 | return 0; |
| 3269 | |
| 3270 | smp->flags = SMP_F_VOL_TEST; |
| 3271 | smp->data.type = SMP_T_SINT; |
| 3272 | smp->data.u.sint = 0; |
| 3273 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3274 | if (stkctr_entry(stkctr)) { |
| 3275 | void *ptr; |
| 3276 | |
| 3277 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 3278 | if (!ptr) |
| 3279 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, 0); |
| 3280 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3281 | if (!ptr) { |
| 3282 | if (stkctr == &tmpstkctr) |
| 3283 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3284 | return 0; /* parameter not stored */ |
| 3285 | } |
| 3286 | |
| 3287 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3288 | |
| 3289 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3290 | |
| 3291 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3292 | |
| 3293 | if (stkctr == &tmpstkctr) |
| 3294 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3295 | } |
| 3296 | return 1; |
| 3297 | } |
| 3298 | |
| 3299 | /* set <smp> to the GPC[args(0)]'s value from the stream's tracked |
| 3300 | * frontend counters or from the src. |
| 3301 | * Supports being called as "sc_get_gpc(<gpc-idx>,<sc-idx>[,<table>])" or |
| 3302 | * "src_get_gpc(<gpc-idx>[,<table>])" only. Value |
| 3303 | * Value zero is returned if the key is new or gpc is not stored. |
| 3304 | */ |
| 3305 | static int |
| 3306 | smp_fetch_sc_get_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3307 | { |
| 3308 | struct stkctr tmpstkctr; |
| 3309 | struct stkctr *stkctr; |
| 3310 | unsigned int idx; |
| 3311 | |
| 3312 | idx = args[0].data.sint; |
| 3313 | |
| 3314 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3315 | if (!stkctr) |
| 3316 | return 0; |
| 3317 | |
| 3318 | smp->flags = SMP_F_VOL_TEST; |
| 3319 | smp->data.type = SMP_T_SINT; |
| 3320 | smp->data.u.sint = 0; |
| 3321 | |
| 3322 | if (stkctr_entry(stkctr) != NULL) { |
| 3323 | void *ptr; |
| 3324 | |
| 3325 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3326 | if (!ptr) { |
| 3327 | if (stkctr == &tmpstkctr) |
| 3328 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3329 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3330 | } |
| 3331 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3332 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3333 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3334 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3335 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3336 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3337 | |
| 3338 | if (stkctr == &tmpstkctr) |
| 3339 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3340 | } |
| 3341 | return 1; |
| 3342 | } |
| 3343 | |
| 3344 | /* set <smp> to the General Purpose Counter 0 value from the stream's tracked |
| 3345 | * frontend counters or from the src. |
| 3346 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value |
| 3347 | * zero is returned if the key is new. |
| 3348 | */ |
| 3349 | static int |
| 3350 | smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3351 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3352 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3353 | struct stkctr *stkctr; |
| 3354 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3355 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3356 | if (!stkctr) |
| 3357 | return 0; |
| 3358 | |
| 3359 | smp->flags = SMP_F_VOL_TEST; |
| 3360 | smp->data.type = SMP_T_SINT; |
| 3361 | smp->data.u.sint = 0; |
| 3362 | |
| 3363 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3364 | void *ptr; |
| 3365 | |
| 3366 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3367 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3368 | /* fallback on the gpc array */ |
| 3369 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3370 | } |
| 3371 | |
| 3372 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3373 | if (stkctr == &tmpstkctr) |
| 3374 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3375 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3376 | } |
| 3377 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3378 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3379 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3380 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3381 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3382 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3383 | |
| 3384 | if (stkctr == &tmpstkctr) |
| 3385 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3386 | } |
| 3387 | return 1; |
| 3388 | } |
| 3389 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3390 | /* set <smp> to the General Purpose Counter 1 value from the stream's tracked |
| 3391 | * frontend counters or from the src. |
| 3392 | * Supports being called as "sc[0-9]_get_gpc1" or "src_get_gpc1" only. Value |
| 3393 | * zero is returned if the key is new. |
| 3394 | */ |
| 3395 | static int |
| 3396 | smp_fetch_sc_get_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3397 | { |
| 3398 | struct stkctr tmpstkctr; |
| 3399 | struct stkctr *stkctr; |
| 3400 | |
| 3401 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3402 | if (!stkctr) |
| 3403 | return 0; |
| 3404 | |
| 3405 | smp->flags = SMP_F_VOL_TEST; |
| 3406 | smp->data.type = SMP_T_SINT; |
| 3407 | smp->data.u.sint = 0; |
| 3408 | |
| 3409 | if (stkctr_entry(stkctr) != NULL) { |
| 3410 | void *ptr; |
| 3411 | |
| 3412 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3413 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3414 | /* fallback on the gpc array */ |
| 3415 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3416 | } |
| 3417 | |
| 3418 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3419 | if (stkctr == &tmpstkctr) |
| 3420 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3421 | return 0; /* parameter not stored */ |
| 3422 | } |
| 3423 | |
| 3424 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3425 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3426 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3427 | |
| 3428 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3429 | |
| 3430 | if (stkctr == &tmpstkctr) |
| 3431 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3432 | } |
| 3433 | return 1; |
| 3434 | } |
| 3435 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3436 | /* set <smp> to the GPC[args(0)]'s event rate from the stream's |
| 3437 | * tracked frontend counters or from the src. |
| 3438 | * Supports being called as "sc_gpc_rate(<gpc-idx>,<sc-idx>[,<table])" |
| 3439 | * or "src_gpc_rate(<gpc-idx>[,<table>])" only. |
| 3440 | * Value zero is returned if the key is new or gpc_rate is not stored. |
| 3441 | */ |
| 3442 | static int |
| 3443 | smp_fetch_sc_gpc_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3444 | { |
| 3445 | struct stkctr tmpstkctr; |
| 3446 | struct stkctr *stkctr; |
| 3447 | unsigned int idx; |
| 3448 | |
| 3449 | idx = args[0].data.sint; |
| 3450 | |
| 3451 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3452 | if (!stkctr) |
| 3453 | return 0; |
| 3454 | |
| 3455 | smp->flags = SMP_F_VOL_TEST; |
| 3456 | smp->data.type = SMP_T_SINT; |
| 3457 | smp->data.u.sint = 0; |
| 3458 | if (stkctr_entry(stkctr) != NULL) { |
| 3459 | void *ptr; |
| 3460 | |
| 3461 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3462 | if (!ptr) { |
| 3463 | if (stkctr == &tmpstkctr) |
| 3464 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3465 | return 0; /* parameter not stored */ |
| 3466 | } |
| 3467 | |
| 3468 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3469 | |
| 3470 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 3471 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 3472 | |
| 3473 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3474 | |
| 3475 | if (stkctr == &tmpstkctr) |
| 3476 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3477 | } |
| 3478 | return 1; |
| 3479 | } |
| 3480 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3481 | /* set <smp> to the General Purpose Counter 0's event rate from the stream's |
| 3482 | * tracked frontend counters or from the src. |
| 3483 | * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only. |
| 3484 | * Value zero is returned if the key is new. |
| 3485 | */ |
| 3486 | static int |
| 3487 | smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3488 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3489 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3490 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3491 | unsigned int period; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3492 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3493 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3494 | if (!stkctr) |
| 3495 | return 0; |
| 3496 | |
| 3497 | smp->flags = SMP_F_VOL_TEST; |
| 3498 | smp->data.type = SMP_T_SINT; |
| 3499 | smp->data.u.sint = 0; |
| 3500 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3501 | void *ptr; |
| 3502 | |
| 3503 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3504 | if (ptr) { |
| 3505 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3506 | } |
| 3507 | else { |
| 3508 | /* fallback on the gpc array */ |
| 3509 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3510 | if (ptr) |
| 3511 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3512 | } |
| 3513 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3514 | if (!ptr) { |
| 3515 | if (stkctr == &tmpstkctr) |
| 3516 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3517 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3518 | } |
| 3519 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3520 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3521 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3522 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), period); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3523 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3524 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3525 | |
| 3526 | if (stkctr == &tmpstkctr) |
| 3527 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3528 | } |
| 3529 | return 1; |
| 3530 | } |
| 3531 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3532 | /* set <smp> to the General Purpose Counter 1's event rate from the stream's |
| 3533 | * tracked frontend counters or from the src. |
| 3534 | * Supports being called as "sc[0-9]_gpc1_rate" or "src_gpc1_rate" only. |
| 3535 | * Value zero is returned if the key is new. |
| 3536 | */ |
| 3537 | static int |
| 3538 | smp_fetch_sc_gpc1_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3539 | { |
| 3540 | struct stkctr tmpstkctr; |
| 3541 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3542 | unsigned int period; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3543 | |
| 3544 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3545 | if (!stkctr) |
| 3546 | return 0; |
| 3547 | |
| 3548 | smp->flags = SMP_F_VOL_TEST; |
| 3549 | smp->data.type = SMP_T_SINT; |
| 3550 | smp->data.u.sint = 0; |
| 3551 | if (stkctr_entry(stkctr) != NULL) { |
| 3552 | void *ptr; |
| 3553 | |
| 3554 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3555 | if (ptr) { |
| 3556 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3557 | } |
| 3558 | else { |
| 3559 | /* fallback on the gpc array */ |
| 3560 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3561 | if (ptr) |
| 3562 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3563 | } |
| 3564 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3565 | if (!ptr) { |
| 3566 | if (stkctr == &tmpstkctr) |
| 3567 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3568 | return 0; /* parameter not stored */ |
| 3569 | } |
| 3570 | |
| 3571 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3572 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3573 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), period); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3574 | |
| 3575 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3576 | |
| 3577 | if (stkctr == &tmpstkctr) |
| 3578 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3579 | } |
| 3580 | return 1; |
| 3581 | } |
| 3582 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3583 | /* Increment the GPC[args(0)] value from the stream's tracked |
| 3584 | * frontend counters and return it into temp integer. |
| 3585 | * Supports being called as "sc_inc_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3586 | * or "src_inc_gpc(<gpc-idx>[,<table>])" only. |
| 3587 | */ |
| 3588 | static int |
| 3589 | smp_fetch_sc_inc_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3590 | { |
| 3591 | struct stkctr tmpstkctr; |
| 3592 | struct stkctr *stkctr; |
| 3593 | unsigned int idx; |
| 3594 | |
| 3595 | idx = args[0].data.sint; |
| 3596 | |
| 3597 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3598 | if (!stkctr) |
| 3599 | return 0; |
| 3600 | |
| 3601 | smp->flags = SMP_F_VOL_TEST; |
| 3602 | smp->data.type = SMP_T_SINT; |
| 3603 | smp->data.u.sint = 0; |
| 3604 | |
| 3605 | if (!stkctr_entry(stkctr)) |
| 3606 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3607 | |
| 3608 | if (stkctr && stkctr_entry(stkctr)) { |
| 3609 | void *ptr1,*ptr2; |
| 3610 | |
| 3611 | |
| 3612 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3613 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3614 | */ |
| 3615 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3616 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3617 | if (ptr1 || ptr2) { |
| 3618 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3619 | |
| 3620 | if (ptr1) { |
| 3621 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 3622 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, 1); |
| 3623 | smp->data.u.sint = (&stktable_data_cast(ptr1, std_t_frqp))->curr_ctr; |
| 3624 | } |
| 3625 | |
| 3626 | if (ptr2) |
| 3627 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
| 3628 | |
| 3629 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3630 | |
| 3631 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3632 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3633 | } |
| 3634 | else if (stkctr == &tmpstkctr) |
| 3635 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3636 | } |
| 3637 | return 1; |
| 3638 | } |
| 3639 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3640 | /* Increment the General Purpose Counter 0 value from the stream's tracked |
| 3641 | * frontend counters and return it into temp integer. |
| 3642 | * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. |
| 3643 | */ |
| 3644 | static int |
| 3645 | smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3646 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3647 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3648 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3649 | unsigned int period = 0; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3650 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3651 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3652 | if (!stkctr) |
| 3653 | return 0; |
| 3654 | |
| 3655 | smp->flags = SMP_F_VOL_TEST; |
| 3656 | smp->data.type = SMP_T_SINT; |
| 3657 | smp->data.u.sint = 0; |
| 3658 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3659 | if (!stkctr_entry(stkctr)) |
| 3660 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3661 | |
| 3662 | if (stkctr && stkctr_entry(stkctr)) { |
| 3663 | void *ptr1,*ptr2; |
| 3664 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3665 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3666 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3667 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3668 | */ |
| 3669 | ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3670 | if (ptr1) { |
| 3671 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3672 | } |
| 3673 | else { |
| 3674 | /* fallback on the gpc array */ |
| 3675 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3676 | if (ptr1) |
| 3677 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3678 | } |
| 3679 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3680 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3681 | if (!ptr2) { |
| 3682 | /* fallback on the gpc array */ |
| 3683 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3684 | } |
| 3685 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3686 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3687 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3688 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3689 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3690 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3691 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3692 | smp->data.u.sint = (&stktable_data_cast(ptr1, std_t_frqp))->curr_ctr; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3696 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3697 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3698 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3699 | |
| 3700 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3701 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3702 | } |
| 3703 | else if (stkctr == &tmpstkctr) |
| 3704 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3705 | } |
| 3706 | return 1; |
| 3707 | } |
| 3708 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3709 | /* Increment the General Purpose Counter 1 value from the stream's tracked |
| 3710 | * frontend counters and return it into temp integer. |
| 3711 | * Supports being called as "sc[0-9]_inc_gpc1" or "src_inc_gpc1" only. |
| 3712 | */ |
| 3713 | static int |
| 3714 | smp_fetch_sc_inc_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3715 | { |
| 3716 | struct stkctr tmpstkctr; |
| 3717 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3718 | unsigned int period = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3719 | |
| 3720 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3721 | if (!stkctr) |
| 3722 | return 0; |
| 3723 | |
| 3724 | smp->flags = SMP_F_VOL_TEST; |
| 3725 | smp->data.type = SMP_T_SINT; |
| 3726 | smp->data.u.sint = 0; |
| 3727 | |
| 3728 | if (!stkctr_entry(stkctr)) |
| 3729 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3730 | |
| 3731 | if (stkctr && stkctr_entry(stkctr)) { |
| 3732 | void *ptr1,*ptr2; |
| 3733 | |
| 3734 | |
| 3735 | /* First, update gpc1_rate if it's tracked. Second, update its |
| 3736 | * gpc1 if tracked. Returns gpc1's value otherwise the curr_ctr. |
| 3737 | */ |
| 3738 | ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3739 | if (ptr1) { |
| 3740 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3741 | } |
| 3742 | else { |
| 3743 | /* fallback on the gpc array */ |
| 3744 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3745 | if (ptr1) |
| 3746 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3747 | } |
| 3748 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3749 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3750 | if (!ptr2) { |
| 3751 | /* fallback on the gpc array */ |
| 3752 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3753 | } |
| 3754 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3755 | if (ptr1 || ptr2) { |
| 3756 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3757 | |
| 3758 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3759 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3760 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3761 | smp->data.u.sint = (&stktable_data_cast(ptr1, std_t_frqp))->curr_ctr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3765 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3766 | |
| 3767 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3768 | |
| 3769 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3770 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3771 | } |
| 3772 | else if (stkctr == &tmpstkctr) |
| 3773 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3774 | } |
| 3775 | return 1; |
| 3776 | } |
| 3777 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3778 | /* Clear the GPC[args(0)] value from the stream's tracked |
| 3779 | * frontend counters and return its previous value into temp integer. |
| 3780 | * Supports being called as "sc_clr_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3781 | * or "src_clr_gpc(<gpc-idx>[,<table>])" only. |
| 3782 | */ |
| 3783 | static int |
| 3784 | smp_fetch_sc_clr_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3785 | { |
| 3786 | struct stkctr tmpstkctr; |
| 3787 | struct stkctr *stkctr; |
| 3788 | unsigned int idx; |
| 3789 | |
| 3790 | idx = args[0].data.sint; |
| 3791 | |
| 3792 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3793 | if (!stkctr) |
| 3794 | return 0; |
| 3795 | |
| 3796 | smp->flags = SMP_F_VOL_TEST; |
| 3797 | smp->data.type = SMP_T_SINT; |
| 3798 | smp->data.u.sint = 0; |
| 3799 | |
| 3800 | if (!stkctr_entry(stkctr)) |
| 3801 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3802 | |
| 3803 | if (stkctr && stkctr_entry(stkctr)) { |
| 3804 | void *ptr; |
| 3805 | |
| 3806 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3807 | if (!ptr) { |
| 3808 | if (stkctr == &tmpstkctr) |
| 3809 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3810 | return 0; /* parameter not stored */ |
| 3811 | } |
| 3812 | |
| 3813 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3814 | |
| 3815 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3816 | stktable_data_cast(ptr, std_t_uint) = 0; |
| 3817 | |
| 3818 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3819 | |
| 3820 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3821 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3822 | } |
| 3823 | return 1; |
| 3824 | } |
| 3825 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3826 | /* Clear the General Purpose Counter 0 value from the stream's tracked |
| 3827 | * frontend counters and return its previous value into temp integer. |
| 3828 | * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only. |
| 3829 | */ |
| 3830 | static int |
| 3831 | smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3832 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3833 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3834 | struct stkctr *stkctr; |
| 3835 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3836 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3837 | if (!stkctr) |
| 3838 | return 0; |
| 3839 | |
| 3840 | smp->flags = SMP_F_VOL_TEST; |
| 3841 | smp->data.type = SMP_T_SINT; |
| 3842 | smp->data.u.sint = 0; |
| 3843 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3844 | if (!stkctr_entry(stkctr)) |
| 3845 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3846 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3847 | if (stkctr && stkctr_entry(stkctr)) { |
| 3848 | void *ptr; |
| 3849 | |
| 3850 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3851 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3852 | /* fallback on the gpc array */ |
| 3853 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3854 | } |
| 3855 | |
| 3856 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3857 | if (stkctr == &tmpstkctr) |
| 3858 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3859 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3860 | } |
| 3861 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3862 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3863 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3864 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3865 | stktable_data_cast(ptr, std_t_uint) = 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3866 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3867 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3868 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3869 | /* If data was modified, we need to touch to re-schedule sync */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3870 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3871 | } |
| 3872 | return 1; |
| 3873 | } |
| 3874 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3875 | /* Clear the General Purpose Counter 1 value from the stream's tracked |
| 3876 | * frontend counters and return its previous value into temp integer. |
| 3877 | * Supports being called as "sc[0-9]_clr_gpc1" or "src_clr_gpc1" only. |
| 3878 | */ |
| 3879 | static int |
| 3880 | smp_fetch_sc_clr_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3881 | { |
| 3882 | struct stkctr tmpstkctr; |
| 3883 | struct stkctr *stkctr; |
| 3884 | |
| 3885 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3886 | if (!stkctr) |
| 3887 | return 0; |
| 3888 | |
| 3889 | smp->flags = SMP_F_VOL_TEST; |
| 3890 | smp->data.type = SMP_T_SINT; |
| 3891 | smp->data.u.sint = 0; |
| 3892 | |
| 3893 | if (!stkctr_entry(stkctr)) |
| 3894 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3895 | |
| 3896 | if (stkctr && stkctr_entry(stkctr)) { |
| 3897 | void *ptr; |
| 3898 | |
| 3899 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3900 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3901 | /* fallback on the gpc array */ |
| 3902 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3903 | } |
| 3904 | |
| 3905 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3906 | if (stkctr == &tmpstkctr) |
| 3907 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3908 | return 0; /* parameter not stored */ |
| 3909 | } |
| 3910 | |
| 3911 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3912 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3913 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3914 | stktable_data_cast(ptr, std_t_uint) = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3915 | |
| 3916 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3917 | |
| 3918 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3919 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3920 | } |
| 3921 | return 1; |
| 3922 | } |
| 3923 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3924 | /* set <smp> to the cumulated number of connections from the stream's tracked |
| 3925 | * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or |
| 3926 | * "src_conn_cnt" only. |
| 3927 | */ |
| 3928 | static int |
| 3929 | smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3930 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3931 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3932 | struct stkctr *stkctr; |
| 3933 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3934 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3935 | if (!stkctr) |
| 3936 | return 0; |
| 3937 | |
| 3938 | smp->flags = SMP_F_VOL_TEST; |
| 3939 | smp->data.type = SMP_T_SINT; |
| 3940 | smp->data.u.sint = 0; |
| 3941 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3942 | void *ptr; |
| 3943 | |
| 3944 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); |
| 3945 | if (!ptr) { |
| 3946 | if (stkctr == &tmpstkctr) |
| 3947 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3948 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3949 | } |
| 3950 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3951 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3952 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3953 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3954 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3955 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3956 | |
| 3957 | if (stkctr == &tmpstkctr) |
| 3958 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3959 | |
| 3960 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3961 | } |
| 3962 | return 1; |
| 3963 | } |
| 3964 | |
| 3965 | /* set <smp> to the connection rate from the stream's tracked frontend |
| 3966 | * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate" |
| 3967 | * only. |
| 3968 | */ |
| 3969 | static int |
| 3970 | smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3971 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3972 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3973 | struct stkctr *stkctr; |
| 3974 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3975 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3976 | if (!stkctr) |
| 3977 | return 0; |
| 3978 | |
| 3979 | smp->flags = SMP_F_VOL_TEST; |
| 3980 | smp->data.type = SMP_T_SINT; |
| 3981 | smp->data.u.sint = 0; |
| 3982 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3983 | void *ptr; |
| 3984 | |
| 3985 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); |
| 3986 | if (!ptr) { |
| 3987 | if (stkctr == &tmpstkctr) |
| 3988 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3989 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3990 | } |
| 3991 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3992 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3993 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3994 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3995 | stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3996 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3997 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3998 | |
| 3999 | if (stkctr == &tmpstkctr) |
| 4000 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4001 | } |
| 4002 | return 1; |
| 4003 | } |
| 4004 | |
| 4005 | /* set temp integer to the number of connections from the stream's source address |
| 4006 | * in the table pointed to by expr, after updating it. |
| 4007 | * Accepts exactly 1 argument of type table. |
| 4008 | */ |
| 4009 | static int |
| 4010 | smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4011 | { |
| 4012 | struct connection *conn = objt_conn(smp->sess->origin); |
| 4013 | struct stksess *ts; |
| 4014 | struct stktable_key *key; |
| 4015 | void *ptr; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4016 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4017 | |
| 4018 | if (!conn) |
| 4019 | return 0; |
| 4020 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 4021 | /* Fetch source address in a sample. */ |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 4022 | 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] | 4023 | return 0; |
| 4024 | |
| 4025 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4026 | key = smp_to_stkey(smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4027 | if (!key) |
| 4028 | return 0; |
| 4029 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4030 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4031 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4032 | if ((ts = stktable_get_entry(t, key)) == NULL) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4033 | /* entry does not exist and could not be created */ |
| 4034 | return 0; |
| 4035 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4036 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4037 | if (!ptr) { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4038 | return 0; /* parameter not stored in this table */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4039 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4040 | |
| 4041 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4042 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4043 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4044 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4045 | smp->data.u.sint = ++stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4046 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4047 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4048 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4049 | smp->flags = SMP_F_VOL_TEST; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4050 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4051 | stktable_touch_local(t, ts, 1); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4052 | |
| 4053 | /* Touch was previously performed by stktable_update_key */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4054 | return 1; |
| 4055 | } |
| 4056 | |
| 4057 | /* set <smp> to the number of concurrent connections from the stream's tracked |
| 4058 | * frontend counters. Supports being called as "sc[0-9]_conn_cur" or |
| 4059 | * "src_conn_cur" only. |
| 4060 | */ |
| 4061 | static int |
| 4062 | smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4063 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4064 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4065 | struct stkctr *stkctr; |
| 4066 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4067 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4068 | if (!stkctr) |
| 4069 | return 0; |
| 4070 | |
| 4071 | smp->flags = SMP_F_VOL_TEST; |
| 4072 | smp->data.type = SMP_T_SINT; |
| 4073 | smp->data.u.sint = 0; |
| 4074 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4075 | void *ptr; |
| 4076 | |
| 4077 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); |
| 4078 | if (!ptr) { |
| 4079 | if (stkctr == &tmpstkctr) |
| 4080 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4081 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4082 | } |
| 4083 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4084 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4085 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4086 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4087 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4088 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4089 | |
| 4090 | if (stkctr == &tmpstkctr) |
| 4091 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4092 | } |
| 4093 | return 1; |
| 4094 | } |
| 4095 | |
| 4096 | /* set <smp> to the cumulated number of streams from the stream's tracked |
| 4097 | * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or |
| 4098 | * "src_sess_cnt" only. |
| 4099 | */ |
| 4100 | static int |
| 4101 | smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4102 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4103 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4104 | struct stkctr *stkctr; |
| 4105 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4106 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4107 | if (!stkctr) |
| 4108 | return 0; |
| 4109 | |
| 4110 | smp->flags = SMP_F_VOL_TEST; |
| 4111 | smp->data.type = SMP_T_SINT; |
| 4112 | smp->data.u.sint = 0; |
| 4113 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4114 | void *ptr; |
| 4115 | |
| 4116 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); |
| 4117 | if (!ptr) { |
| 4118 | if (stkctr == &tmpstkctr) |
| 4119 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4120 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4121 | } |
| 4122 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4123 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4124 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4125 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4126 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4127 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4128 | |
| 4129 | if (stkctr == &tmpstkctr) |
| 4130 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4131 | } |
| 4132 | return 1; |
| 4133 | } |
| 4134 | |
| 4135 | /* set <smp> to the stream rate from the stream's tracked frontend counters. |
| 4136 | * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only. |
| 4137 | */ |
| 4138 | static int |
| 4139 | smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4140 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4141 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4142 | struct stkctr *stkctr; |
| 4143 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4144 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4145 | if (!stkctr) |
| 4146 | return 0; |
| 4147 | |
| 4148 | smp->flags = SMP_F_VOL_TEST; |
| 4149 | smp->data.type = SMP_T_SINT; |
| 4150 | smp->data.u.sint = 0; |
| 4151 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4152 | void *ptr; |
| 4153 | |
| 4154 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); |
| 4155 | if (!ptr) { |
| 4156 | if (stkctr == &tmpstkctr) |
| 4157 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4158 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4159 | } |
| 4160 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4161 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4162 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4163 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4164 | stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4165 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4166 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4167 | |
| 4168 | if (stkctr == &tmpstkctr) |
| 4169 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4170 | } |
| 4171 | return 1; |
| 4172 | } |
| 4173 | |
| 4174 | /* set <smp> to the cumulated number of HTTP requests from the stream's tracked |
| 4175 | * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or |
| 4176 | * "src_http_req_cnt" only. |
| 4177 | */ |
| 4178 | static int |
| 4179 | smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4180 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4181 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4182 | struct stkctr *stkctr; |
| 4183 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4184 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4185 | if (!stkctr) |
| 4186 | return 0; |
| 4187 | |
| 4188 | smp->flags = SMP_F_VOL_TEST; |
| 4189 | smp->data.type = SMP_T_SINT; |
| 4190 | smp->data.u.sint = 0; |
| 4191 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4192 | void *ptr; |
| 4193 | |
| 4194 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
| 4195 | if (!ptr) { |
| 4196 | if (stkctr == &tmpstkctr) |
| 4197 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4198 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4199 | } |
| 4200 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4201 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4202 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4203 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4204 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4205 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4206 | |
| 4207 | if (stkctr == &tmpstkctr) |
| 4208 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4209 | } |
| 4210 | return 1; |
| 4211 | } |
| 4212 | |
| 4213 | /* set <smp> to the HTTP request rate from the stream's tracked frontend |
| 4214 | * counters. Supports being called as "sc[0-9]_http_req_rate" or |
| 4215 | * "src_http_req_rate" only. |
| 4216 | */ |
| 4217 | static int |
| 4218 | smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4219 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4220 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4221 | struct stkctr *stkctr; |
| 4222 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4223 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4224 | if (!stkctr) |
| 4225 | return 0; |
| 4226 | |
| 4227 | smp->flags = SMP_F_VOL_TEST; |
| 4228 | smp->data.type = SMP_T_SINT; |
| 4229 | smp->data.u.sint = 0; |
| 4230 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4231 | void *ptr; |
| 4232 | |
| 4233 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
| 4234 | if (!ptr) { |
| 4235 | if (stkctr == &tmpstkctr) |
| 4236 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4237 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4238 | } |
| 4239 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4240 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4241 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4242 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4243 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4244 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4245 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4246 | |
| 4247 | if (stkctr == &tmpstkctr) |
| 4248 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4249 | } |
| 4250 | return 1; |
| 4251 | } |
| 4252 | |
| 4253 | /* set <smp> to the cumulated number of HTTP requests errors from the stream's |
| 4254 | * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or |
| 4255 | * "src_http_err_cnt" only. |
| 4256 | */ |
| 4257 | static int |
| 4258 | smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4259 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4260 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4261 | struct stkctr *stkctr; |
| 4262 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4263 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4264 | if (!stkctr) |
| 4265 | return 0; |
| 4266 | |
| 4267 | smp->flags = SMP_F_VOL_TEST; |
| 4268 | smp->data.type = SMP_T_SINT; |
| 4269 | smp->data.u.sint = 0; |
| 4270 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4271 | void *ptr; |
| 4272 | |
| 4273 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
| 4274 | if (!ptr) { |
| 4275 | if (stkctr == &tmpstkctr) |
| 4276 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4277 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4278 | } |
| 4279 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4280 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4281 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4282 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4283 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4284 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4285 | |
| 4286 | if (stkctr == &tmpstkctr) |
| 4287 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4288 | } |
| 4289 | return 1; |
| 4290 | } |
| 4291 | |
| 4292 | /* set <smp> to the HTTP request error rate from the stream's tracked frontend |
| 4293 | * counters. Supports being called as "sc[0-9]_http_err_rate" or |
| 4294 | * "src_http_err_rate" only. |
| 4295 | */ |
| 4296 | static int |
| 4297 | smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4298 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4299 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4300 | struct stkctr *stkctr; |
| 4301 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4302 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4303 | if (!stkctr) |
| 4304 | return 0; |
| 4305 | |
| 4306 | smp->flags = SMP_F_VOL_TEST; |
| 4307 | smp->data.type = SMP_T_SINT; |
| 4308 | smp->data.u.sint = 0; |
| 4309 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4310 | void *ptr; |
| 4311 | |
| 4312 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
| 4313 | if (!ptr) { |
| 4314 | if (stkctr == &tmpstkctr) |
| 4315 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4316 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4317 | } |
| 4318 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4319 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4320 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4321 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4322 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4323 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4324 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4325 | |
| 4326 | if (stkctr == &tmpstkctr) |
| 4327 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4328 | } |
| 4329 | return 1; |
| 4330 | } |
| 4331 | |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4332 | /* set <smp> to the cumulated number of HTTP response failures from the stream's |
| 4333 | * tracked frontend counters. Supports being called as "sc[0-9]_http_fail_cnt" or |
| 4334 | * "src_http_fail_cnt" only. |
| 4335 | */ |
| 4336 | static int |
| 4337 | smp_fetch_sc_http_fail_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4338 | { |
| 4339 | struct stkctr tmpstkctr; |
| 4340 | struct stkctr *stkctr; |
| 4341 | |
| 4342 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4343 | if (!stkctr) |
| 4344 | return 0; |
| 4345 | |
| 4346 | smp->flags = SMP_F_VOL_TEST; |
| 4347 | smp->data.type = SMP_T_SINT; |
| 4348 | smp->data.u.sint = 0; |
| 4349 | if (stkctr_entry(stkctr) != NULL) { |
| 4350 | void *ptr; |
| 4351 | |
| 4352 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_CNT); |
| 4353 | if (!ptr) { |
| 4354 | if (stkctr == &tmpstkctr) |
| 4355 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4356 | return 0; /* parameter not stored */ |
| 4357 | } |
| 4358 | |
| 4359 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4360 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4361 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4362 | |
| 4363 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4364 | |
| 4365 | if (stkctr == &tmpstkctr) |
| 4366 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4367 | } |
| 4368 | return 1; |
| 4369 | } |
| 4370 | |
| 4371 | /* set <smp> to the HTTP response failure rate from the stream's tracked frontend |
| 4372 | * counters. Supports being called as "sc[0-9]_http_fail_rate" or |
| 4373 | * "src_http_fail_rate" only. |
| 4374 | */ |
| 4375 | static int |
| 4376 | smp_fetch_sc_http_fail_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4377 | { |
| 4378 | struct stkctr tmpstkctr; |
| 4379 | struct stkctr *stkctr; |
| 4380 | |
| 4381 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4382 | if (!stkctr) |
| 4383 | return 0; |
| 4384 | |
| 4385 | smp->flags = SMP_F_VOL_TEST; |
| 4386 | smp->data.type = SMP_T_SINT; |
| 4387 | smp->data.u.sint = 0; |
| 4388 | if (stkctr_entry(stkctr) != NULL) { |
| 4389 | void *ptr; |
| 4390 | |
| 4391 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_RATE); |
| 4392 | if (!ptr) { |
| 4393 | if (stkctr == &tmpstkctr) |
| 4394 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4395 | return 0; /* parameter not stored */ |
| 4396 | } |
| 4397 | |
| 4398 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4399 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4400 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4401 | stkctr->table->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u); |
| 4402 | |
| 4403 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4404 | |
| 4405 | if (stkctr == &tmpstkctr) |
| 4406 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4407 | } |
| 4408 | return 1; |
| 4409 | } |
| 4410 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4411 | /* set <smp> to the number of kbytes received from clients, as found in the |
| 4412 | * stream's tracked frontend counters. Supports being called as |
| 4413 | * "sc[0-9]_kbytes_in" or "src_kbytes_in" only. |
| 4414 | */ |
| 4415 | static int |
| 4416 | smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4417 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4418 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4419 | struct stkctr *stkctr; |
| 4420 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4421 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4422 | if (!stkctr) |
| 4423 | return 0; |
| 4424 | |
| 4425 | smp->flags = SMP_F_VOL_TEST; |
| 4426 | smp->data.type = SMP_T_SINT; |
| 4427 | smp->data.u.sint = 0; |
| 4428 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4429 | void *ptr; |
| 4430 | |
| 4431 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
| 4432 | if (!ptr) { |
| 4433 | if (stkctr == &tmpstkctr) |
| 4434 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4435 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4436 | } |
| 4437 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4438 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4439 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4440 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4441 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4442 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4443 | |
| 4444 | if (stkctr == &tmpstkctr) |
| 4445 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4446 | } |
| 4447 | return 1; |
| 4448 | } |
| 4449 | |
| 4450 | /* set <smp> to the data rate received from clients in bytes/s, as found |
| 4451 | * in the stream's tracked frontend counters. Supports being called as |
| 4452 | * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only. |
| 4453 | */ |
| 4454 | static int |
| 4455 | smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4456 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4457 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4458 | struct stkctr *stkctr; |
| 4459 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4460 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4461 | if (!stkctr) |
| 4462 | return 0; |
| 4463 | |
| 4464 | smp->flags = SMP_F_VOL_TEST; |
| 4465 | smp->data.type = SMP_T_SINT; |
| 4466 | smp->data.u.sint = 0; |
| 4467 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4468 | void *ptr; |
| 4469 | |
| 4470 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
| 4471 | if (!ptr) { |
| 4472 | if (stkctr == &tmpstkctr) |
| 4473 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4474 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4475 | } |
| 4476 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4477 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4478 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4479 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4480 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4481 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4482 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4483 | |
| 4484 | if (stkctr == &tmpstkctr) |
| 4485 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4486 | } |
| 4487 | return 1; |
| 4488 | } |
| 4489 | |
| 4490 | /* set <smp> to the number of kbytes sent to clients, as found in the |
| 4491 | * stream's tracked frontend counters. Supports being called as |
| 4492 | * "sc[0-9]_kbytes_out" or "src_kbytes_out" only. |
| 4493 | */ |
| 4494 | static int |
| 4495 | smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4496 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4497 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4498 | struct stkctr *stkctr; |
| 4499 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4500 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4501 | if (!stkctr) |
| 4502 | return 0; |
| 4503 | |
| 4504 | smp->flags = SMP_F_VOL_TEST; |
| 4505 | smp->data.type = SMP_T_SINT; |
| 4506 | smp->data.u.sint = 0; |
| 4507 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4508 | void *ptr; |
| 4509 | |
| 4510 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
| 4511 | if (!ptr) { |
| 4512 | if (stkctr == &tmpstkctr) |
| 4513 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4514 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4515 | } |
| 4516 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4517 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4518 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4519 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4520 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4521 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4522 | |
| 4523 | if (stkctr == &tmpstkctr) |
| 4524 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4525 | } |
| 4526 | return 1; |
| 4527 | } |
| 4528 | |
| 4529 | /* set <smp> to the data rate sent to clients in bytes/s, as found in the |
| 4530 | * stream's tracked frontend counters. Supports being called as |
| 4531 | * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. |
| 4532 | */ |
| 4533 | static int |
| 4534 | smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4535 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4536 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4537 | struct stkctr *stkctr; |
| 4538 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4539 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4540 | if (!stkctr) |
| 4541 | return 0; |
| 4542 | |
| 4543 | smp->flags = SMP_F_VOL_TEST; |
| 4544 | smp->data.type = SMP_T_SINT; |
| 4545 | smp->data.u.sint = 0; |
| 4546 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4547 | void *ptr; |
| 4548 | |
| 4549 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
| 4550 | if (!ptr) { |
| 4551 | if (stkctr == &tmpstkctr) |
| 4552 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4553 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4554 | } |
| 4555 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4556 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4557 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4558 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4559 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4560 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4561 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4562 | |
| 4563 | if (stkctr == &tmpstkctr) |
| 4564 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4565 | } |
| 4566 | return 1; |
| 4567 | } |
| 4568 | |
| 4569 | /* set <smp> to the number of active trackers on the SC entry in the stream's |
| 4570 | * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only. |
| 4571 | */ |
| 4572 | static int |
| 4573 | smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4574 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4575 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4576 | struct stkctr *stkctr; |
| 4577 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4578 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4579 | if (!stkctr) |
| 4580 | return 0; |
| 4581 | |
| 4582 | smp->flags = SMP_F_VOL_TEST; |
| 4583 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4584 | if (stkctr == &tmpstkctr) { |
| 4585 | smp->data.u.sint = stkctr_entry(stkctr) ? (stkctr_entry(stkctr)->ref_cnt-1) : 0; |
| 4586 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4587 | } |
| 4588 | else { |
| 4589 | smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0; |
| 4590 | } |
| 4591 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4592 | return 1; |
| 4593 | } |
| 4594 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4595 | |
| 4596 | /* The functions below are used to manipulate table contents from the CLI. |
| 4597 | * There are 3 main actions, "clear", "set" and "show". The code is shared |
| 4598 | * between all actions, and the action is encoded in the void *private in |
| 4599 | * the appctx as well as in the keyword registration, among one of the |
| 4600 | * following values. |
| 4601 | */ |
| 4602 | |
| 4603 | enum { |
| 4604 | STK_CLI_ACT_CLR, |
| 4605 | STK_CLI_ACT_SET, |
| 4606 | STK_CLI_ACT_SHOW, |
| 4607 | }; |
| 4608 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4609 | /* Dump the status of a table to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4610 | * read buffer. It returns 0 if the output buffer is full |
| 4611 | * and needs to be called again, otherwise non-zero. |
| 4612 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4613 | static int table_dump_head_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4614 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4615 | struct stktable *t, struct stktable *target) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4616 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 4617 | struct stream *s = __sc_strm(appctx_sc(appctx)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4618 | |
| 4619 | 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] | 4620 | t->id, stktable_types[t->type].kw, t->size, t->current); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4621 | |
| 4622 | /* any other information should be dumped here */ |
| 4623 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 4624 | 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] | 4625 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
| 4626 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4627 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4628 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4629 | |
| 4630 | return 1; |
| 4631 | } |
| 4632 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4633 | /* Dump a table entry to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4634 | * read buffer. It returns 0 if the output buffer is full |
| 4635 | * and needs to be called again, otherwise non-zero. |
| 4636 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4637 | static int table_dump_entry_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4638 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4639 | struct stktable *t, struct stksess *entry) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4640 | { |
| 4641 | int dt; |
| 4642 | |
| 4643 | chunk_appendf(msg, "%p:", entry); |
| 4644 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4645 | if (t->type == SMP_T_IPV4) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4646 | char addr[INET_ADDRSTRLEN]; |
| 4647 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4648 | chunk_appendf(msg, " key=%s", addr); |
| 4649 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4650 | else if (t->type == SMP_T_IPV6) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4651 | char addr[INET6_ADDRSTRLEN]; |
| 4652 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4653 | chunk_appendf(msg, " key=%s", addr); |
| 4654 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4655 | else if (t->type == SMP_T_SINT) { |
Willy Tarreau | 6cde5d8 | 2020-02-25 09:41:22 +0100 | [diff] [blame] | 4656 | chunk_appendf(msg, " key=%u", read_u32(entry->key.key)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4657 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4658 | else if (t->type == SMP_T_STR) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4659 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4660 | dump_text(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4661 | } |
| 4662 | else { |
| 4663 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4664 | dump_binary(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4665 | } |
| 4666 | |
Willy Tarreau | 16b282f | 2022-11-29 11:55:18 +0100 | [diff] [blame] | 4667 | chunk_appendf(msg, " use=%d exp=%d shard=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire), entry->shard); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4668 | |
| 4669 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 4670 | void *ptr; |
| 4671 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4672 | if (t->data_ofs[dt] == 0) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4673 | continue; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 4674 | if (stktable_data_types[dt].is_array) { |
| 4675 | char tmp[16] = {}; |
| 4676 | const char *name_pfx = stktable_data_types[dt].name; |
| 4677 | const char *name_sfx = NULL; |
| 4678 | unsigned int idx = 0; |
| 4679 | int i = 0; |
| 4680 | |
| 4681 | /* split name to show index before first _ of the name |
| 4682 | * for example: 'gpc3_rate' if array name is 'gpc_rate'. |
| 4683 | */ |
| 4684 | for (i = 0 ; i < (sizeof(tmp) - 1); i++) { |
| 4685 | if (!name_pfx[i]) |
| 4686 | break; |
| 4687 | if (name_pfx[i] == '_') { |
| 4688 | name_pfx = &tmp[0]; |
| 4689 | name_sfx = &stktable_data_types[dt].name[i]; |
| 4690 | break; |
| 4691 | } |
| 4692 | tmp[i] = name_pfx[i]; |
| 4693 | } |
| 4694 | |
| 4695 | ptr = stktable_data_ptr_idx(t, entry, dt, idx); |
| 4696 | while (ptr) { |
| 4697 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
| 4698 | chunk_appendf(msg, " %s%u%s(%u)=", name_pfx, idx, name_sfx ? name_sfx : "", t->data_arg[dt].u); |
| 4699 | else |
| 4700 | chunk_appendf(msg, " %s%u%s=", name_pfx, idx, name_sfx ? name_sfx : ""); |
| 4701 | switch (stktable_data_types[dt].std_type) { |
| 4702 | case STD_T_SINT: |
| 4703 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4704 | break; |
| 4705 | case STD_T_UINT: |
| 4706 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4707 | break; |
| 4708 | case STD_T_ULL: |
| 4709 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
| 4710 | break; |
| 4711 | case STD_T_FRQP: |
| 4712 | chunk_appendf(msg, "%u", |
| 4713 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 4714 | t->data_arg[dt].u)); |
| 4715 | break; |
| 4716 | } |
| 4717 | ptr = stktable_data_ptr_idx(t, entry, dt, ++idx); |
| 4718 | } |
| 4719 | continue; |
| 4720 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4721 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4722 | 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] | 4723 | else |
| 4724 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
| 4725 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4726 | ptr = stktable_data_ptr(t, entry, dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4727 | switch (stktable_data_types[dt].std_type) { |
| 4728 | case STD_T_SINT: |
| 4729 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4730 | break; |
| 4731 | case STD_T_UINT: |
| 4732 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4733 | break; |
| 4734 | case STD_T_ULL: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4735 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4736 | break; |
| 4737 | case STD_T_FRQP: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4738 | chunk_appendf(msg, "%u", |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4739 | 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] | 4740 | t->data_arg[dt].u)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4741 | break; |
Frédéric Lécaille | 16b4f54 | 2019-05-23 12:15:04 +0200 | [diff] [blame] | 4742 | case STD_T_DICT: { |
| 4743 | struct dict_entry *de; |
| 4744 | de = stktable_data_cast(ptr, std_t_dict); |
| 4745 | chunk_appendf(msg, "%s", de ? (char *)de->value.key : "-"); |
| 4746 | break; |
| 4747 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4748 | } |
| 4749 | } |
| 4750 | chunk_appendf(msg, "\n"); |
| 4751 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4752 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4753 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4754 | |
| 4755 | return 1; |
| 4756 | } |
| 4757 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4758 | /* appctx context used by the "show table" command */ |
| 4759 | struct show_table_ctx { |
| 4760 | void *target; /* table we want to dump, or NULL for all */ |
| 4761 | struct stktable *t; /* table being currently dumped (first if NULL) */ |
| 4762 | struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ |
| 4763 | long long value[STKTABLE_FILTER_LEN]; /* value to compare against */ |
| 4764 | signed char data_type[STKTABLE_FILTER_LEN]; /* type of data to compare, or -1 if none */ |
| 4765 | signed char data_op[STKTABLE_FILTER_LEN]; /* operator (STD_OP_*) when data_type set */ |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 4766 | enum { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4767 | STATE_NEXT = 0, /* px points to next table, entry=NULL */ |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 4768 | STATE_DUMP, /* px points to curr table, entry is valid, refcount held */ |
| 4769 | STATE_DONE, /* done dumping */ |
| 4770 | } state; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4771 | char action; /* action on the table : one of STK_CLI_ACT_* */ |
| 4772 | }; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4773 | |
| 4774 | /* Processes a single table entry matching a specific key passed in argument. |
| 4775 | * returns 0 if wants to be called again, 1 if has ended processing. |
| 4776 | */ |
| 4777 | static int table_process_entry_per_key(struct appctx *appctx, char **args) |
| 4778 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4779 | struct show_table_ctx *ctx = appctx->svcctx; |
| 4780 | struct stktable *t = ctx->target; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4781 | struct stksess *ts; |
| 4782 | uint32_t uint32_key; |
| 4783 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
| 4784 | long long value; |
| 4785 | int data_type; |
| 4786 | int cur_arg; |
| 4787 | void *ptr; |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4788 | struct freq_ctr *frqp; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4789 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4790 | if (!*args[4]) |
| 4791 | return cli_err(appctx, "Key value expected\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4792 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4793 | switch (t->type) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4794 | case SMP_T_IPV4: |
| 4795 | uint32_key = htonl(inetaddr_host(args[4])); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4796 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4797 | break; |
| 4798 | case SMP_T_IPV6: |
Christopher Faulet | b7c962b | 2021-11-15 09:17:25 +0100 | [diff] [blame] | 4799 | if (inet_pton(AF_INET6, args[4], ip6_key) <= 0) |
| 4800 | return cli_err(appctx, "Invalid key\n"); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4801 | static_table_key.key = &ip6_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4802 | break; |
| 4803 | case SMP_T_SINT: |
| 4804 | { |
| 4805 | char *endptr; |
| 4806 | unsigned long val; |
| 4807 | errno = 0; |
| 4808 | val = strtoul(args[4], &endptr, 10); |
| 4809 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 4810 | (errno != 0 && val == 0) || endptr == args[4] || |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4811 | val > 0xffffffff) |
| 4812 | return cli_err(appctx, "Invalid key\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4813 | uint32_key = (uint32_t) val; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4814 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4815 | break; |
| 4816 | } |
| 4817 | break; |
| 4818 | case SMP_T_STR: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4819 | static_table_key.key = args[4]; |
| 4820 | static_table_key.key_len = strlen(args[4]); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4821 | break; |
| 4822 | default: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4823 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4824 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4825 | 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] | 4826 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4827 | 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] | 4828 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4829 | 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] | 4830 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4831 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4832 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | /* check permissions */ |
| 4836 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 4837 | return 1; |
| 4838 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4839 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4840 | case STK_CLI_ACT_SHOW: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4841 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4842 | if (!ts) |
| 4843 | return 1; |
| 4844 | chunk_reset(&trash); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4845 | if (!table_dump_head_to_buffer(&trash, appctx, t, t)) { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4846 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4847 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4848 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4849 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4850 | if (!table_dump_entry_to_buffer(&trash, appctx, t, ts)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4851 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4852 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4853 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4854 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4855 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4856 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4857 | break; |
| 4858 | |
| 4859 | case STK_CLI_ACT_CLR: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4860 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4861 | if (!ts) |
| 4862 | return 1; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4863 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4864 | if (!stksess_kill(t, ts, 1)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4865 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4866 | return cli_err(appctx, "Entry currently in use, cannot remove\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4867 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4868 | break; |
| 4869 | |
| 4870 | case STK_CLI_ACT_SET: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4871 | ts = stktable_get_entry(t, &static_table_key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4872 | if (!ts) { |
| 4873 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4874 | return cli_err(appctx, "Unable to allocate a new entry\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4875 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4876 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4877 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 4878 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4879 | cli_err(appctx, "\"data.<type>\" followed by a value expected\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4880 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4881 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4882 | return 1; |
| 4883 | } |
| 4884 | |
| 4885 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 4886 | if (data_type < 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4887 | cli_err(appctx, "Unknown data type\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4888 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4889 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4890 | return 1; |
| 4891 | } |
| 4892 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4893 | if (!t->data_ofs[data_type]) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4894 | cli_err(appctx, "Data type not stored in this table\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4895 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4896 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4897 | return 1; |
| 4898 | } |
| 4899 | |
| 4900 | 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] | 4901 | cli_err(appctx, "Require a valid integer value to store\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4902 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4903 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4904 | return 1; |
| 4905 | } |
| 4906 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4907 | ptr = stktable_data_ptr(t, ts, data_type); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4908 | |
| 4909 | switch (stktable_data_types[data_type].std_type) { |
| 4910 | case STD_T_SINT: |
| 4911 | stktable_data_cast(ptr, std_t_sint) = value; |
| 4912 | break; |
| 4913 | case STD_T_UINT: |
| 4914 | stktable_data_cast(ptr, std_t_uint) = value; |
| 4915 | break; |
| 4916 | case STD_T_ULL: |
| 4917 | stktable_data_cast(ptr, std_t_ull) = value; |
| 4918 | break; |
| 4919 | case STD_T_FRQP: |
| 4920 | /* We set both the current and previous values. That way |
| 4921 | * the reported frequency is stable during all the period |
| 4922 | * then slowly fades out. This allows external tools to |
| 4923 | * push measures without having to update them too often. |
| 4924 | */ |
| 4925 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4926 | /* First bit is reserved for the freq_ctr lock |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4927 | Note: here we're still protected by the stksess lock |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4928 | so we don't need to update the update the freq_ctr |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4929 | using its internal lock */ |
| 4930 | frqp->curr_tick = now_ms & ~0x1; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4931 | frqp->prev_ctr = 0; |
| 4932 | frqp->curr_ctr = value; |
| 4933 | break; |
| 4934 | } |
| 4935 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4936 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4937 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4938 | break; |
| 4939 | |
| 4940 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4941 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4942 | } |
| 4943 | return 1; |
| 4944 | } |
| 4945 | |
| 4946 | /* Prepares the appctx fields with the data-based filters from the command line. |
| 4947 | * Returns 0 if the dump can proceed, 1 if has ended processing. |
| 4948 | */ |
| 4949 | static int table_prepare_data_request(struct appctx *appctx, char **args) |
| 4950 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4951 | struct show_table_ctx *ctx = appctx->svcctx; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4952 | int i; |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4953 | char *err = NULL; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4954 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4955 | if (ctx->action != STK_CLI_ACT_SHOW && ctx->action != STK_CLI_ACT_CLR) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4956 | 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] | 4957 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4958 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
| 4959 | if (i > 0 && !*args[3+3*i]) // number of filter entries can be less than STKTABLE_FILTER_LEN |
| 4960 | break; |
| 4961 | /* condition on stored data value */ |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4962 | ctx->data_type[i] = stktable_get_data_type(args[3+3*i] + 5); |
| 4963 | if (ctx->data_type[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4964 | 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] | 4965 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4966 | if (!((struct stktable *)ctx->target)->data_ofs[ctx->data_type[i]]) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4967 | 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] | 4968 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4969 | ctx->data_op[i] = get_std_op(args[4+3*i]); |
| 4970 | if (ctx->data_op[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4971 | 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] | 4972 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4973 | if (!*args[5+3*i] || strl2llrc(args[5+3*i], strlen(args[5+3*i]), &ctx->value[i]) != 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4974 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require a valid integer value to compare against\n", i + 1)); |
| 4975 | } |
| 4976 | |
| 4977 | if (*args[3+3*i]) { |
| 4978 | 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] | 4979 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4980 | |
| 4981 | /* OK we're done, all the fields are set */ |
| 4982 | return 0; |
| 4983 | } |
| 4984 | |
| 4985 | /* 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] | 4986 | 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] | 4987 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4988 | struct show_table_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4989 | int i; |
| 4990 | |
| 4991 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4992 | ctx->data_type[i] = -1; |
| 4993 | ctx->target = NULL; |
| 4994 | ctx->entry = NULL; |
| 4995 | ctx->action = (long)private; // keyword argument, one of STK_CLI_ACT_* |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4996 | |
| 4997 | if (*args[2]) { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4998 | ctx->t = ctx->target = stktable_find_by_name(args[2]); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4999 | if (!ctx->target) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5000 | return cli_err(appctx, "No such table\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5001 | } |
| 5002 | else { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5003 | ctx->t = stktables_list; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5004 | if (ctx->action != STK_CLI_ACT_SHOW) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5005 | goto err_args; |
| 5006 | return 0; |
| 5007 | } |
| 5008 | |
| 5009 | if (strcmp(args[3], "key") == 0) |
| 5010 | return table_process_entry_per_key(appctx, args); |
| 5011 | else if (strncmp(args[3], "data.", 5) == 0) |
| 5012 | return table_prepare_data_request(appctx, args); |
| 5013 | else if (*args[3]) |
| 5014 | goto err_args; |
| 5015 | |
| 5016 | return 0; |
| 5017 | |
| 5018 | err_args: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5019 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5020 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5021 | 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] | 5022 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5023 | 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] | 5024 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5025 | 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] | 5026 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5027 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5028 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | /* This function is used to deal with table operations (dump or clear depending |
| 5032 | * on the action stored in appctx->private). It returns 0 if the output buffer is |
| 5033 | * full and it needs to be called again, otherwise non-zero. |
| 5034 | */ |
| 5035 | static int cli_io_handler_table(struct appctx *appctx) |
| 5036 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5037 | struct show_table_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5038 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 475e463 | 2022-05-27 10:26:46 +0200 | [diff] [blame] | 5039 | struct stream *s = __sc_strm(sc); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5040 | struct ebmb_node *eb; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5041 | int skip_entry; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5042 | int show = ctx->action == STK_CLI_ACT_SHOW; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5043 | |
| 5044 | /* |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5045 | * We have 3 possible states in ctx->state : |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5046 | * - STATE_NEXT : the proxy pointer points to the next table to |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5047 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5048 | * - STATE_DUMP : the proxy pointer points to the current table |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5049 | * and the entry pointer points to the next entry to be dumped, |
| 5050 | * and the refcount on the next entry is held ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5051 | * - STATE_DONE : nothing left to dump, the buffer may contain some |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5052 | * data though. |
| 5053 | */ |
Christopher Faulet | 87633c3 | 2023-04-03 18:32:50 +0200 | [diff] [blame] | 5054 | /* FIXME: Don't watch the other side !*/ |
Christopher Faulet | 208c712 | 2023-04-13 16:16:15 +0200 | [diff] [blame] | 5055 | if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5056 | /* in case of abort, remove any refcount we might have set on an entry */ |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5057 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5058 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5059 | } |
| 5060 | return 1; |
| 5061 | } |
| 5062 | |
| 5063 | chunk_reset(&trash); |
| 5064 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5065 | while (ctx->state != STATE_DONE) { |
| 5066 | switch (ctx->state) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5067 | case STATE_NEXT: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5068 | if (!ctx->t || |
| 5069 | (ctx->target && |
| 5070 | ctx->t != ctx->target)) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5071 | ctx->state = STATE_DONE; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5072 | break; |
| 5073 | } |
| 5074 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5075 | if (ctx->t->size) { |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5076 | if (show && !table_dump_head_to_buffer(&trash, appctx, ctx->t, ctx->target)) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5077 | return 0; |
| 5078 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5079 | if (ctx->target && |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 5080 | (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5081 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5082 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5083 | eb = ebmb_first(&ctx->t->keys); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5084 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5085 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
| 5086 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5087 | ctx->state = STATE_DUMP; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5088 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5089 | break; |
| 5090 | } |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5091 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5092 | } |
| 5093 | } |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5094 | ctx->t = ctx->t->next; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5095 | break; |
| 5096 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5097 | case STATE_DUMP: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5098 | skip_entry = 0; |
| 5099 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5100 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5101 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5102 | if (ctx->data_type[0] >= 0) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5103 | /* we're filtering on some data contents */ |
| 5104 | void *ptr; |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5105 | int dt, i; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5106 | signed char op; |
| 5107 | long long data, value; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5108 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5109 | |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5110 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5111 | if (ctx->data_type[i] == -1) |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5112 | break; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5113 | dt = ctx->data_type[i]; |
| 5114 | ptr = stktable_data_ptr(ctx->t, |
| 5115 | ctx->entry, |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5116 | dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5117 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5118 | data = 0; |
| 5119 | switch (stktable_data_types[dt].std_type) { |
| 5120 | case STD_T_SINT: |
| 5121 | data = stktable_data_cast(ptr, std_t_sint); |
| 5122 | break; |
| 5123 | case STD_T_UINT: |
| 5124 | data = stktable_data_cast(ptr, std_t_uint); |
| 5125 | break; |
| 5126 | case STD_T_ULL: |
| 5127 | data = stktable_data_cast(ptr, std_t_ull); |
| 5128 | break; |
| 5129 | case STD_T_FRQP: |
| 5130 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5131 | ctx->t->data_arg[dt].u); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5132 | break; |
| 5133 | } |
| 5134 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5135 | op = ctx->data_op[i]; |
| 5136 | value = ctx->value[i]; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5137 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5138 | /* skip the entry if the data does not match the test and the value */ |
| 5139 | if ((data < value && |
| 5140 | (op == STD_OP_EQ || op == STD_OP_GT || op == STD_OP_GE)) || |
| 5141 | (data == value && |
| 5142 | (op == STD_OP_NE || op == STD_OP_GT || op == STD_OP_LT)) || |
| 5143 | (data > value && |
| 5144 | (op == STD_OP_EQ || op == STD_OP_LT || op == STD_OP_LE))) { |
| 5145 | skip_entry = 1; |
| 5146 | break; |
| 5147 | } |
| 5148 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | if (show && !skip_entry && |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5152 | !table_dump_entry_to_buffer(&trash, appctx, ctx->t, ctx->entry)) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5153 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5154 | return 0; |
| 5155 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5156 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5157 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5158 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5159 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5160 | ctx->entry->ref_cnt--; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5161 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5162 | eb = ebmb_next(&ctx->entry->key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5163 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5164 | struct stksess *old = ctx->entry; |
| 5165 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5166 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5167 | __stksess_kill_if_expired(ctx->t, old); |
| 5168 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5169 | __stksess_kill(ctx->t, old); |
| 5170 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5171 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5172 | break; |
| 5173 | } |
| 5174 | |
| 5175 | |
| 5176 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5177 | __stksess_kill_if_expired(ctx->t, ctx->entry); |
| 5178 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5179 | __stksess_kill(ctx->t, ctx->entry); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5180 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5181 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5182 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5183 | ctx->t = ctx->t->next; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5184 | ctx->state = STATE_NEXT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5185 | break; |
| 5186 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5187 | default: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5188 | break; |
| 5189 | } |
| 5190 | } |
| 5191 | return 1; |
| 5192 | } |
| 5193 | |
| 5194 | static void cli_release_show_table(struct appctx *appctx) |
| 5195 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5196 | struct show_table_ctx *ctx = appctx->svcctx; |
| 5197 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5198 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5199 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5200 | } |
| 5201 | } |
| 5202 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5203 | static int stk_parse_stick_counters(char **args, int section_type, struct proxy *curpx, |
| 5204 | const struct proxy *defpx, const char *file, int line, |
| 5205 | char **err) |
| 5206 | { |
| 5207 | char *error; |
| 5208 | int counters; |
| 5209 | |
| 5210 | counters = strtol(args[1], &error, 10); |
| 5211 | if (*error != 0) { |
| 5212 | memprintf(err, "%s: '%s' is an invalid number", args[0], args[1]); |
| 5213 | return -1; |
| 5214 | } |
| 5215 | |
| 5216 | if (counters < 0) { |
| 5217 | memprintf(err, "%s: the number of stick-counters may not be negative (was %d)", args[0], counters); |
| 5218 | return -1; |
| 5219 | } |
| 5220 | |
| 5221 | global.tune.nb_stk_ctr = counters; |
| 5222 | return 0; |
| 5223 | } |
| 5224 | |
| 5225 | /* This function creates the stk_ctr pools after the configuration parsing. It |
| 5226 | * returns 0 on success otherwise ERR_*. If nb_stk_ctr is 0, the pool remains |
| 5227 | * NULL. |
| 5228 | */ |
| 5229 | static int stkt_create_stk_ctr_pool(void) |
| 5230 | { |
| 5231 | if (!global.tune.nb_stk_ctr) |
| 5232 | return 0; |
| 5233 | |
| 5234 | pool_head_stk_ctr = create_pool("stk_ctr", sizeof(*((struct session*)0)->stkctr) * global.tune.nb_stk_ctr, MEM_F_SHARED); |
| 5235 | if (!pool_head_stk_ctr) { |
| 5236 | ha_alert("out of memory while creating the stick-counters pool.\n"); |
| 5237 | return ERR_ABORT; |
| 5238 | } |
| 5239 | return 0; |
| 5240 | } |
| 5241 | |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5242 | static void stkt_late_init(void) |
| 5243 | { |
| 5244 | struct sample_fetch *f; |
| 5245 | |
| 5246 | f = find_sample_fetch("src", strlen("src")); |
| 5247 | if (f) |
| 5248 | smp_fetch_src = f->process; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5249 | hap_register_post_check(stkt_create_stk_ctr_pool); |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | INITCALL0(STG_INIT, stkt_late_init); |
| 5253 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5254 | /* register cli keywords */ |
| 5255 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5256 | { { "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 }, |
| 5257 | { { "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 }, |
| 5258 | { { "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] | 5259 | {{},} |
| 5260 | }}; |
| 5261 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5262 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5263 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5264 | static struct action_kw_list tcp_conn_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5265 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5266 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5267 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5268 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5269 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5270 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5271 | { /* END */ } |
| 5272 | }}; |
| 5273 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5274 | INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws); |
| 5275 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5276 | static struct action_kw_list tcp_sess_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5277 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5278 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5279 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5280 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5281 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5282 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5283 | { /* END */ } |
| 5284 | }}; |
| 5285 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5286 | INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws); |
| 5287 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5288 | static struct action_kw_list tcp_req_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5289 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5290 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5291 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5292 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5293 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5294 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5295 | { /* END */ } |
| 5296 | }}; |
| 5297 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5298 | INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_kws); |
| 5299 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5300 | static struct action_kw_list tcp_res_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5301 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5302 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5303 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5304 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5305 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5306 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5307 | { /* END */ } |
| 5308 | }}; |
| 5309 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5310 | INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws); |
| 5311 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5312 | static struct action_kw_list http_req_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5313 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5314 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5315 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5316 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5317 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5318 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5319 | { /* END */ } |
| 5320 | }}; |
| 5321 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5322 | INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws); |
| 5323 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5324 | static struct action_kw_list http_res_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5325 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5326 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5327 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5328 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5329 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5330 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5331 | { /* END */ } |
| 5332 | }}; |
| 5333 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5334 | INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws); |
| 5335 | |
Christopher Faulet | a924804 | 2023-01-05 11:17:38 +0100 | [diff] [blame] | 5336 | static struct action_kw_list http_after_res_kws = { { }, { |
Aurelien DARRAGON | e2907c7 | 2023-03-17 11:28:58 +0100 | [diff] [blame] | 5337 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Christopher Faulet | a924804 | 2023-01-05 11:17:38 +0100 | [diff] [blame] | 5338 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5339 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5340 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5341 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5342 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5343 | { /* END */ } |
| 5344 | }}; |
| 5345 | |
| 5346 | INITCALL1(STG_REGISTER, http_after_res_keywords_register, &http_after_res_kws); |
| 5347 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5348 | /* Note: must not be declared <const> as its list will be overwritten. |
| 5349 | * Please take care of keeping this list alphabetically sorted. |
| 5350 | */ |
| 5351 | static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 5352 | { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5353 | { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5354 | { "sc_clr_gpc", smp_fetch_sc_clr_gpc, ARG3(2,SINT,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5355 | { "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] | 5356 | { "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] | 5357 | { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5358 | { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5359 | { "sc_conn_rate", smp_fetch_sc_conn_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5360 | { "sc_get_gpt", smp_fetch_sc_get_gpt, ARG3(2,SINT,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Thierry FOURNIER | 401c64b | 2017-01-05 11:44:09 +0100 | [diff] [blame] | 5361 | { "sc_get_gpt0", smp_fetch_sc_get_gpt0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5362 | { "sc_get_gpc", smp_fetch_sc_get_gpc, ARG3(2,SINT,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5363 | { "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] | 5364 | { "sc_get_gpc1", smp_fetch_sc_get_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5365 | { "sc_gpc_rate", smp_fetch_sc_gpc_rate, ARG3(2,SINT,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5366 | { "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] | 5367 | { "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] | 5368 | { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5369 | { "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] | 5370 | { "sc_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5371 | { "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] | 5372 | { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5373 | { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5374 | { "sc_inc_gpc", smp_fetch_sc_inc_gpc, ARG3(2,SINT,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5375 | { "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] | 5376 | { "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] | 5377 | { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5378 | { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5379 | { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5380 | { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5381 | { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5382 | { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5383 | { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5384 | { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5385 | { "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] | 5386 | { "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] | 5387 | { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5388 | { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5389 | { "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] | 5390 | { "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] | 5391 | { "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] | 5392 | { "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] | 5393 | { "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] | 5394 | { "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] | 5395 | { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5396 | { "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] | 5397 | { "sc0_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5398 | { "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] | 5399 | { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5400 | { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5401 | { "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] | 5402 | { "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] | 5403 | { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5404 | { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5405 | { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5406 | { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5407 | { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5408 | { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5409 | { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5410 | { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5411 | { "sc1_clr_gpc", smp_fetch_sc_clr_gpc, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5412 | { "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] | 5413 | { "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] | 5414 | { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5415 | { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5416 | { "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] | 5417 | { "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] | 5418 | { "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] | 5419 | { "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] | 5420 | { "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] | 5421 | { "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] | 5422 | { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5423 | { "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] | 5424 | { "sc1_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5425 | { "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] | 5426 | { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5427 | { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5428 | { "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] | 5429 | { "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] | 5430 | { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5431 | { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5432 | { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5433 | { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5434 | { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5435 | { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5436 | { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5437 | { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5438 | { "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] | 5439 | { "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] | 5440 | { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5441 | { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5442 | { "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] | 5443 | { "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] | 5444 | { "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] | 5445 | { "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] | 5446 | { "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] | 5447 | { "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] | 5448 | { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5449 | { "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] | 5450 | { "sc2_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5451 | { "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] | 5452 | { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5453 | { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5454 | { "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] | 5455 | { "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] | 5456 | { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5457 | { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5458 | { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5459 | { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5460 | { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5461 | { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5462 | { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5463 | { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5464 | { "src_clr_gpc", smp_fetch_sc_clr_gpc, ARG2(2,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5465 | { "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] | 5466 | { "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] | 5467 | { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5468 | { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5469 | { "src_conn_rate", smp_fetch_sc_conn_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5470 | { "src_get_gpt" , smp_fetch_sc_get_gpt, ARG2(2,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Thierry FOURNIER | 401c64b | 2017-01-05 11:44:09 +0100 | [diff] [blame] | 5471 | { "src_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5472 | { "src_get_gpc", smp_fetch_sc_get_gpc, ARG2(2,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5473 | { "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] | 5474 | { "src_get_gpc1", smp_fetch_sc_get_gpc1, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5475 | { "src_gpc_rate", smp_fetch_sc_gpc_rate, ARG2(2,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5476 | { "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] | 5477 | { "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] | 5478 | { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5479 | { "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] | 5480 | { "src_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5481 | { "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] | 5482 | { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5483 | { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5484 | { "src_inc_gpc", smp_fetch_sc_inc_gpc, ARG2(2,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5485 | { "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] | 5486 | { "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] | 5487 | { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5488 | { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5489 | { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5490 | { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5491 | { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5492 | { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5493 | { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5494 | { /* END */ }, |
| 5495 | }}; |
| 5496 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5497 | INITCALL1(STG_REGISTER, sample_register_fetches, &smp_fetch_keywords); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5498 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 5499 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 5500 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5501 | { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL }, |
| 5502 | { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5503 | { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5504 | { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5505 | { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5506 | { "table_conn_rate", sample_conv_table_conn_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Frédéric Lécaille | bbeec37 | 2022-08-16 18:11:25 +0200 | [diff] [blame] | 5507 | { "table_expire", sample_conv_table_expire, ARG2(1,TAB,SINT), NULL, SMP_T_ANY, SMP_T_SINT }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5508 | { "table_gpt", sample_conv_table_gpt, ARG2(2,SINT,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5509 | { "table_gpt0", sample_conv_table_gpt0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5510 | { "table_gpc", sample_conv_table_gpc, ARG2(2,SINT,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5511 | { "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] | 5512 | { "table_gpc1", sample_conv_table_gpc1, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5513 | { "table_gpc_rate", sample_conv_table_gpc_rate, ARG2(2,SINT,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5514 | { "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] | 5515 | { "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] | 5516 | { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5517 | { "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] | 5518 | { "table_http_fail_cnt", sample_conv_table_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5519 | { "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] | 5520 | { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5521 | { "table_http_req_rate", sample_conv_table_http_req_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
Frédéric Lécaille | bbeec37 | 2022-08-16 18:11:25 +0200 | [diff] [blame] | 5522 | { "table_idle", sample_conv_table_idle, ARG2(1,TAB,SINT), NULL, SMP_T_ANY, SMP_T_SINT }, |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5523 | { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5524 | { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5525 | { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5526 | { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5527 | { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5528 | { "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] | 5529 | { /* END */ }, |
| 5530 | }}; |
| 5531 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5532 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5533 | |
| 5534 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 5535 | { CFG_GLOBAL, "tune.stick-counters", stk_parse_stick_counters }, |
| 5536 | { /* END */ } |
| 5537 | }}; |
| 5538 | |
| 5539 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |