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) { |
| 2916 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2917 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2918 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2919 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2920 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2921 | default: |
| 2922 | send_log(px, LOG_ERR, "stick table: internal error while setting gpc%u.", rule->arg.gpc.idx); |
| 2923 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2924 | ha_alert("stick table: internal error while executing setting gpc%u.\n", rule->arg.gpc.idx); |
| 2925 | return ACT_RET_CONT; |
| 2926 | } |
| 2927 | |
| 2928 | /* Fetch and cast the expression. */ |
| 2929 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpc.expr, SMP_T_SINT); |
| 2930 | if (!smp) { |
| 2931 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpc%u.", rule->arg.gpc.idx); |
| 2932 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2933 | ha_alert("stick table: invalid expression or data type while setting gpc%u.\n", rule->arg.gpc.idx); |
| 2934 | return ACT_RET_CONT; |
| 2935 | } |
| 2936 | value = (unsigned int)(smp->data.u.sint); |
| 2937 | } |
| 2938 | |
| 2939 | if (value) { |
| 2940 | /* only update the value if non-null increment */ |
| 2941 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2942 | |
| 2943 | if (ptr1) |
| 2944 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 2945 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, value); |
| 2946 | |
| 2947 | if (ptr2) |
| 2948 | stktable_data_cast(ptr2, std_t_uint) += value; |
| 2949 | |
| 2950 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2951 | } |
| 2952 | /* always touch the table so that it doesn't expire */ |
| 2953 | stktable_touch_local(stkctr->table, ts, 0); |
| 2954 | } |
| 2955 | |
| 2956 | return ACT_RET_CONT; |
| 2957 | } |
| 2958 | |
| 2959 | /* This function is a parser for the "sc-add-gpc" action. It understands the |
| 2960 | * format: |
| 2961 | * |
| 2962 | * sc-add-gpc(<gpc IDX>,<track ID>) <expression> |
| 2963 | * |
| 2964 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error message. |
| 2965 | * Otherwise, it returns ACT_RET_PRS_OK and the variable 'rule->arg.gpc.expr' |
| 2966 | * is filled with the pointer to the expression to execute or NULL if the arg |
| 2967 | * is directly an integer stored into 'rule->arg.gpt.value'. |
| 2968 | */ |
| 2969 | static enum act_parse_ret parse_add_gpc(const char **args, int *arg, struct proxy *px, |
| 2970 | struct act_rule *rule, char **err) |
| 2971 | { |
| 2972 | const char *cmd_name = args[*arg-1]; |
| 2973 | char *error; |
| 2974 | int smp_val; |
| 2975 | |
| 2976 | cmd_name += strlen("sc-add-gpc"); |
| 2977 | if (*cmd_name != '(') { |
| 2978 | memprintf(err, "Missing or invalid arguments for '%s'. Expects sc-add-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2979 | return ACT_RET_PRS_ERR; |
| 2980 | } |
| 2981 | cmd_name++; /* skip the '(' */ |
| 2982 | rule->arg.gpc.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2983 | if (*error != ',') { |
| 2984 | memprintf(err, "Missing gpc ID. Expects %s(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2985 | return ACT_RET_PRS_ERR; |
| 2986 | } |
| 2987 | else { |
| 2988 | cmd_name = error + 1; /* skip the ',' */ |
| 2989 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2990 | if (*error != ')') { |
| 2991 | memprintf(err, "invalid stick table track ID '%s'. Expects %s(<GPC ID>,<Track ID>)", cmd_name, args[*arg-1]); |
| 2992 | return ACT_RET_PRS_ERR; |
| 2993 | } |
| 2994 | |
| 2995 | if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) { |
| 2996 | memprintf(err, "invalid stick table track ID '%s' for '%s'. The max allowed ID is %d", |
| 2997 | cmd_name, args[*arg-1], MAX_SESS_STKCTR-1); |
| 2998 | return ACT_RET_PRS_ERR; |
| 2999 | } |
| 3000 | } |
| 3001 | rule->action_ptr = action_add_gpc; |
| 3002 | |
| 3003 | /* value may be either an integer or an expression */ |
| 3004 | rule->arg.gpc.expr = NULL; |
| 3005 | rule->arg.gpc.value = strtol(args[*arg], &error, 10); |
| 3006 | if (*error == '\0') { |
| 3007 | /* valid integer, skip it */ |
| 3008 | (*arg)++; |
| 3009 | } else { |
| 3010 | rule->arg.gpc.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, |
| 3011 | px->conf.args.line, err, &px->conf.args, NULL); |
| 3012 | if (!rule->arg.gpc.expr) |
| 3013 | return ACT_RET_PRS_ERR; |
| 3014 | |
| 3015 | switch (rule->from) { |
| 3016 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 3017 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 3018 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 3019 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 3020 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 3021 | default: |
| 3022 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 3023 | return ACT_RET_PRS_ERR; |
| 3024 | } |
| 3025 | |
| 3026 | if (!(rule->arg.gpc.expr->fetch->val & smp_val)) { |
| 3027 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 3028 | sample_src_names(rule->arg.gpc.expr->fetch->use)); |
| 3029 | free(rule->arg.gpc.expr); |
| 3030 | return ACT_RET_PRS_ERR; |
| 3031 | } |
| 3032 | } |
| 3033 | |
| 3034 | rule->action = ACT_CUSTOM; |
| 3035 | |
| 3036 | return ACT_RET_PRS_OK; |
| 3037 | } |
| 3038 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3039 | /* set temp integer to the number of used entries in the table pointed to by expr. |
| 3040 | * Accepts exactly 1 argument of type table. |
| 3041 | */ |
| 3042 | static int |
| 3043 | smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3044 | { |
| 3045 | smp->flags = SMP_F_VOL_TEST; |
| 3046 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3047 | smp->data.u.sint = args->data.t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3048 | return 1; |
| 3049 | } |
| 3050 | |
| 3051 | /* set temp integer to the number of free entries in the table pointed to by expr. |
| 3052 | * Accepts exactly 1 argument of type table. |
| 3053 | */ |
| 3054 | static int |
| 3055 | smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3056 | { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3057 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3058 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3059 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3060 | smp->flags = SMP_F_VOL_TEST; |
| 3061 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3062 | smp->data.u.sint = t->size - t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3063 | return 1; |
| 3064 | } |
| 3065 | |
| 3066 | /* Returns a pointer to a stkctr depending on the fetch keyword name. |
| 3067 | * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively. |
| 3068 | * sc[0-9]_* will return a pointer to the respective field in the |
| 3069 | * stream <l4>. sc_* requires an UINT argument specifying the stick |
| 3070 | * counter number. src_* will fill a locally allocated structure with |
| 3071 | * the table and entry corresponding to what is specified with src_*. |
| 3072 | * NULL may be returned if the designated stkctr is not tracked. For |
| 3073 | * the sc_* and sc[0-9]_* forms, an optional table argument may be |
| 3074 | * passed. When present, the currently tracked key is then looked up |
| 3075 | * in the specified table instead of the current table. The purpose is |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 3076 | * 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] | 3077 | * multiple tables). <strm> is allowed to be NULL, in which case only |
| 3078 | * the session will be consulted. |
| 3079 | */ |
| 3080 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3081 | 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] | 3082 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3083 | struct stkctr *stkptr; |
| 3084 | struct stksess *stksess; |
| 3085 | unsigned int num = kw[2] - '0'; |
| 3086 | int arg = 0; |
| 3087 | |
| 3088 | if (num == '_' - '0') { |
| 3089 | /* sc_* variant, args[0] = ctr# (mandatory) */ |
| 3090 | num = args[arg++].data.sint; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3091 | } |
| 3092 | else if (num > 9) { /* src_* variant, args[0] = table */ |
| 3093 | struct stktable_key *key; |
| 3094 | struct connection *conn = objt_conn(sess->origin); |
| 3095 | struct sample smp; |
| 3096 | |
| 3097 | if (!conn) |
| 3098 | return NULL; |
| 3099 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3100 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3101 | smp.px = NULL; |
| 3102 | smp.sess = sess; |
| 3103 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3104 | 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] | 3105 | return NULL; |
| 3106 | |
| 3107 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3108 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3109 | if (!key) |
| 3110 | return NULL; |
| 3111 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3112 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3113 | stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key)); |
| 3114 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | /* Here, <num> contains the counter number from 0 to 9 for |
| 3118 | * the sc[0-9]_ form, or even higher using sc_(num) if needed. |
| 3119 | * args[arg] is the first optional argument. We first lookup the |
| 3120 | * 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] | 3121 | * 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] | 3122 | */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3123 | if (num >= global.tune.nb_stk_ctr) |
Christopher Faulet | a9fa88a | 2019-10-21 10:53:34 +0200 | [diff] [blame] | 3124 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3125 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3126 | stkptr = NULL; |
| 3127 | if (strm && strm->stkctr) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3128 | stkptr = &strm->stkctr[num]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3129 | if (!strm || !stkptr || !stkctr_entry(stkptr)) { |
| 3130 | if (sess->stkctr) |
| 3131 | stkptr = &sess->stkctr[num]; |
| 3132 | else |
| 3133 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3134 | if (!stkctr_entry(stkptr)) |
| 3135 | return NULL; |
| 3136 | } |
| 3137 | |
| 3138 | stksess = stkctr_entry(stkptr); |
| 3139 | if (!stksess) |
| 3140 | return NULL; |
| 3141 | |
| 3142 | if (unlikely(args[arg].type == ARGT_TAB)) { |
| 3143 | /* 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] | 3144 | stkctr->table = args[arg].data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3145 | stkctr_set_entry(stkctr, stktable_lookup(stkctr->table, stksess)); |
| 3146 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3147 | } |
| 3148 | return stkptr; |
| 3149 | } |
| 3150 | |
| 3151 | /* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create |
| 3152 | * the entry if it doesn't exist yet. This is needed for a few fetch |
| 3153 | * functions which need to create an entry, such as src_inc_gpc* and |
| 3154 | * src_clr_gpc*. |
| 3155 | */ |
| 3156 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3157 | 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] | 3158 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3159 | struct stktable_key *key; |
| 3160 | struct connection *conn = objt_conn(sess->origin); |
| 3161 | struct sample smp; |
| 3162 | |
| 3163 | if (strncmp(kw, "src_", 4) != 0) |
| 3164 | return NULL; |
| 3165 | |
| 3166 | if (!conn) |
| 3167 | return NULL; |
| 3168 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3169 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3170 | smp.px = NULL; |
| 3171 | smp.sess = sess; |
| 3172 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3173 | 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] | 3174 | return NULL; |
| 3175 | |
| 3176 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3177 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3178 | if (!key) |
| 3179 | return NULL; |
| 3180 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3181 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3182 | stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key)); |
| 3183 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | /* set return a boolean indicating if the requested stream counter is |
| 3187 | * currently being tracked or not. |
| 3188 | * Supports being called as "sc[0-9]_tracked" only. |
| 3189 | */ |
| 3190 | static int |
| 3191 | smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3192 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3193 | struct stkctr tmpstkctr; |
| 3194 | struct stkctr *stkctr; |
| 3195 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3196 | smp->flags = SMP_F_VOL_TEST; |
| 3197 | smp->data.type = SMP_T_BOOL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3198 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3199 | smp->data.u.sint = !!stkctr; |
| 3200 | |
| 3201 | /* release the ref count */ |
Dirkjan Bussink | ff57f1b | 2018-09-14 14:31:22 +0200 | [diff] [blame] | 3202 | if (stkctr == &tmpstkctr) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3203 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3204 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 3205 | return 1; |
| 3206 | } |
| 3207 | |
| 3208 | /* set <smp> to the General Purpose Tag of index set as first arg |
| 3209 | * to value from the stream's tracked frontend counters or from the src. |
| 3210 | * Supports being called as "sc_get_gpt(<gpt-idx>,<sc-idx>[,<table>])" or |
| 3211 | * "src_get_gpt(<gpt-idx>[,<table>])" only. Value zero is returned if |
| 3212 | * the key is new or gpt is not stored. |
| 3213 | */ |
| 3214 | static int |
| 3215 | smp_fetch_sc_get_gpt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3216 | { |
| 3217 | struct stkctr tmpstkctr; |
| 3218 | struct stkctr *stkctr; |
| 3219 | unsigned int idx; |
| 3220 | |
| 3221 | idx = args[0].data.sint; |
| 3222 | |
| 3223 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3224 | if (!stkctr) |
| 3225 | return 0; |
| 3226 | |
| 3227 | smp->flags = SMP_F_VOL_TEST; |
| 3228 | smp->data.type = SMP_T_SINT; |
| 3229 | smp->data.u.sint = 0; |
| 3230 | |
| 3231 | if (stkctr_entry(stkctr)) { |
| 3232 | void *ptr; |
| 3233 | |
| 3234 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, idx); |
| 3235 | if (!ptr) { |
| 3236 | if (stkctr == &tmpstkctr) |
| 3237 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3238 | return 0; /* parameter not stored */ |
| 3239 | } |
| 3240 | |
| 3241 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3242 | |
| 3243 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3244 | |
| 3245 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3246 | |
| 3247 | if (stkctr == &tmpstkctr) |
| 3248 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3249 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3250 | return 1; |
| 3251 | } |
| 3252 | |
| 3253 | /* set <smp> to the General Purpose Flag 0 value from the stream's tracked |
| 3254 | * frontend counters or from the src. |
| 3255 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value |
| 3256 | * zero is returned if the key is new. |
| 3257 | */ |
| 3258 | static int |
| 3259 | smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3260 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3261 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3262 | struct stkctr *stkctr; |
| 3263 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3264 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3265 | if (!stkctr) |
| 3266 | return 0; |
| 3267 | |
| 3268 | smp->flags = SMP_F_VOL_TEST; |
| 3269 | smp->data.type = SMP_T_SINT; |
| 3270 | smp->data.u.sint = 0; |
| 3271 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3272 | if (stkctr_entry(stkctr)) { |
| 3273 | void *ptr; |
| 3274 | |
| 3275 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 3276 | if (!ptr) |
| 3277 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, 0); |
| 3278 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3279 | if (!ptr) { |
| 3280 | if (stkctr == &tmpstkctr) |
| 3281 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3282 | return 0; /* parameter not stored */ |
| 3283 | } |
| 3284 | |
| 3285 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3286 | |
| 3287 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3288 | |
| 3289 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3290 | |
| 3291 | if (stkctr == &tmpstkctr) |
| 3292 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3293 | } |
| 3294 | return 1; |
| 3295 | } |
| 3296 | |
| 3297 | /* set <smp> to the GPC[args(0)]'s value from the stream's tracked |
| 3298 | * frontend counters or from the src. |
| 3299 | * Supports being called as "sc_get_gpc(<gpc-idx>,<sc-idx>[,<table>])" or |
| 3300 | * "src_get_gpc(<gpc-idx>[,<table>])" only. Value |
| 3301 | * Value zero is returned if the key is new or gpc is not stored. |
| 3302 | */ |
| 3303 | static int |
| 3304 | smp_fetch_sc_get_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3305 | { |
| 3306 | struct stkctr tmpstkctr; |
| 3307 | struct stkctr *stkctr; |
| 3308 | unsigned int idx; |
| 3309 | |
| 3310 | idx = args[0].data.sint; |
| 3311 | |
| 3312 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3313 | if (!stkctr) |
| 3314 | return 0; |
| 3315 | |
| 3316 | smp->flags = SMP_F_VOL_TEST; |
| 3317 | smp->data.type = SMP_T_SINT; |
| 3318 | smp->data.u.sint = 0; |
| 3319 | |
| 3320 | if (stkctr_entry(stkctr) != NULL) { |
| 3321 | void *ptr; |
| 3322 | |
| 3323 | 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] | 3324 | if (!ptr) { |
| 3325 | if (stkctr == &tmpstkctr) |
| 3326 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3327 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3328 | } |
| 3329 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3330 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3331 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3332 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3333 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3334 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3335 | |
| 3336 | if (stkctr == &tmpstkctr) |
| 3337 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3338 | } |
| 3339 | return 1; |
| 3340 | } |
| 3341 | |
| 3342 | /* set <smp> to the General Purpose Counter 0 value from the stream's tracked |
| 3343 | * frontend counters or from the src. |
| 3344 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value |
| 3345 | * zero is returned if the key is new. |
| 3346 | */ |
| 3347 | static int |
| 3348 | smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3349 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3350 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3351 | struct stkctr *stkctr; |
| 3352 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3353 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3354 | if (!stkctr) |
| 3355 | return 0; |
| 3356 | |
| 3357 | smp->flags = SMP_F_VOL_TEST; |
| 3358 | smp->data.type = SMP_T_SINT; |
| 3359 | smp->data.u.sint = 0; |
| 3360 | |
| 3361 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3362 | void *ptr; |
| 3363 | |
| 3364 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3365 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3366 | /* fallback on the gpc array */ |
| 3367 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3368 | } |
| 3369 | |
| 3370 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3371 | if (stkctr == &tmpstkctr) |
| 3372 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3373 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3374 | } |
| 3375 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3376 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3377 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3378 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3379 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3380 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3381 | |
| 3382 | if (stkctr == &tmpstkctr) |
| 3383 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3384 | } |
| 3385 | return 1; |
| 3386 | } |
| 3387 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3388 | /* set <smp> to the General Purpose Counter 1 value from the stream's tracked |
| 3389 | * frontend counters or from the src. |
| 3390 | * Supports being called as "sc[0-9]_get_gpc1" or "src_get_gpc1" only. Value |
| 3391 | * zero is returned if the key is new. |
| 3392 | */ |
| 3393 | static int |
| 3394 | smp_fetch_sc_get_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3395 | { |
| 3396 | struct stkctr tmpstkctr; |
| 3397 | struct stkctr *stkctr; |
| 3398 | |
| 3399 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3400 | if (!stkctr) |
| 3401 | return 0; |
| 3402 | |
| 3403 | smp->flags = SMP_F_VOL_TEST; |
| 3404 | smp->data.type = SMP_T_SINT; |
| 3405 | smp->data.u.sint = 0; |
| 3406 | |
| 3407 | if (stkctr_entry(stkctr) != NULL) { |
| 3408 | void *ptr; |
| 3409 | |
| 3410 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3411 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3412 | /* fallback on the gpc array */ |
| 3413 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3414 | } |
| 3415 | |
| 3416 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3417 | if (stkctr == &tmpstkctr) |
| 3418 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3419 | return 0; /* parameter not stored */ |
| 3420 | } |
| 3421 | |
| 3422 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3423 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3424 | 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] | 3425 | |
| 3426 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3427 | |
| 3428 | if (stkctr == &tmpstkctr) |
| 3429 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3430 | } |
| 3431 | return 1; |
| 3432 | } |
| 3433 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3434 | /* set <smp> to the GPC[args(0)]'s event rate from the stream's |
| 3435 | * tracked frontend counters or from the src. |
| 3436 | * Supports being called as "sc_gpc_rate(<gpc-idx>,<sc-idx>[,<table])" |
| 3437 | * or "src_gpc_rate(<gpc-idx>[,<table>])" only. |
| 3438 | * Value zero is returned if the key is new or gpc_rate is not stored. |
| 3439 | */ |
| 3440 | static int |
| 3441 | smp_fetch_sc_gpc_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3442 | { |
| 3443 | struct stkctr tmpstkctr; |
| 3444 | struct stkctr *stkctr; |
| 3445 | unsigned int idx; |
| 3446 | |
| 3447 | idx = args[0].data.sint; |
| 3448 | |
| 3449 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3450 | if (!stkctr) |
| 3451 | return 0; |
| 3452 | |
| 3453 | smp->flags = SMP_F_VOL_TEST; |
| 3454 | smp->data.type = SMP_T_SINT; |
| 3455 | smp->data.u.sint = 0; |
| 3456 | if (stkctr_entry(stkctr) != NULL) { |
| 3457 | void *ptr; |
| 3458 | |
| 3459 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3460 | if (!ptr) { |
| 3461 | if (stkctr == &tmpstkctr) |
| 3462 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3463 | return 0; /* parameter not stored */ |
| 3464 | } |
| 3465 | |
| 3466 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3467 | |
| 3468 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 3469 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 3470 | |
| 3471 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3472 | |
| 3473 | if (stkctr == &tmpstkctr) |
| 3474 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3475 | } |
| 3476 | return 1; |
| 3477 | } |
| 3478 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3479 | /* set <smp> to the General Purpose Counter 0's event rate from the stream's |
| 3480 | * tracked frontend counters or from the src. |
| 3481 | * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only. |
| 3482 | * Value zero is returned if the key is new. |
| 3483 | */ |
| 3484 | static int |
| 3485 | smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3486 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3487 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3488 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3489 | unsigned int period; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3490 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3491 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3492 | if (!stkctr) |
| 3493 | return 0; |
| 3494 | |
| 3495 | smp->flags = SMP_F_VOL_TEST; |
| 3496 | smp->data.type = SMP_T_SINT; |
| 3497 | smp->data.u.sint = 0; |
| 3498 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3499 | void *ptr; |
| 3500 | |
| 3501 | 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] | 3502 | if (ptr) { |
| 3503 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3504 | } |
| 3505 | else { |
| 3506 | /* fallback on the gpc array */ |
| 3507 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3508 | if (ptr) |
| 3509 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3510 | } |
| 3511 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3512 | if (!ptr) { |
| 3513 | if (stkctr == &tmpstkctr) |
| 3514 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3515 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3516 | } |
| 3517 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3518 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3519 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3520 | 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] | 3521 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3522 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3523 | |
| 3524 | if (stkctr == &tmpstkctr) |
| 3525 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3526 | } |
| 3527 | return 1; |
| 3528 | } |
| 3529 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3530 | /* set <smp> to the General Purpose Counter 1's event rate from the stream's |
| 3531 | * tracked frontend counters or from the src. |
| 3532 | * Supports being called as "sc[0-9]_gpc1_rate" or "src_gpc1_rate" only. |
| 3533 | * Value zero is returned if the key is new. |
| 3534 | */ |
| 3535 | static int |
| 3536 | smp_fetch_sc_gpc1_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3537 | { |
| 3538 | struct stkctr tmpstkctr; |
| 3539 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3540 | unsigned int period; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3541 | |
| 3542 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3543 | if (!stkctr) |
| 3544 | return 0; |
| 3545 | |
| 3546 | smp->flags = SMP_F_VOL_TEST; |
| 3547 | smp->data.type = SMP_T_SINT; |
| 3548 | smp->data.u.sint = 0; |
| 3549 | if (stkctr_entry(stkctr) != NULL) { |
| 3550 | void *ptr; |
| 3551 | |
| 3552 | 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] | 3553 | if (ptr) { |
| 3554 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3555 | } |
| 3556 | else { |
| 3557 | /* fallback on the gpc array */ |
| 3558 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3559 | if (ptr) |
| 3560 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3561 | } |
| 3562 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3563 | if (!ptr) { |
| 3564 | if (stkctr == &tmpstkctr) |
| 3565 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3566 | return 0; /* parameter not stored */ |
| 3567 | } |
| 3568 | |
| 3569 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3570 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3571 | 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] | 3572 | |
| 3573 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3574 | |
| 3575 | if (stkctr == &tmpstkctr) |
| 3576 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3577 | } |
| 3578 | return 1; |
| 3579 | } |
| 3580 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3581 | /* Increment the GPC[args(0)] value from the stream's tracked |
| 3582 | * frontend counters and return it into temp integer. |
| 3583 | * Supports being called as "sc_inc_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3584 | * or "src_inc_gpc(<gpc-idx>[,<table>])" only. |
| 3585 | */ |
| 3586 | static int |
| 3587 | smp_fetch_sc_inc_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3588 | { |
| 3589 | struct stkctr tmpstkctr; |
| 3590 | struct stkctr *stkctr; |
| 3591 | unsigned int idx; |
| 3592 | |
| 3593 | idx = args[0].data.sint; |
| 3594 | |
| 3595 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3596 | if (!stkctr) |
| 3597 | return 0; |
| 3598 | |
| 3599 | smp->flags = SMP_F_VOL_TEST; |
| 3600 | smp->data.type = SMP_T_SINT; |
| 3601 | smp->data.u.sint = 0; |
| 3602 | |
| 3603 | if (!stkctr_entry(stkctr)) |
| 3604 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3605 | |
| 3606 | if (stkctr && stkctr_entry(stkctr)) { |
| 3607 | void *ptr1,*ptr2; |
| 3608 | |
| 3609 | |
| 3610 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3611 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3612 | */ |
| 3613 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3614 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3615 | if (ptr1 || ptr2) { |
| 3616 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3617 | |
| 3618 | if (ptr1) { |
| 3619 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 3620 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, 1); |
| 3621 | smp->data.u.sint = (&stktable_data_cast(ptr1, std_t_frqp))->curr_ctr; |
| 3622 | } |
| 3623 | |
| 3624 | if (ptr2) |
| 3625 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
| 3626 | |
| 3627 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3628 | |
| 3629 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3630 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3631 | } |
| 3632 | else if (stkctr == &tmpstkctr) |
| 3633 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3634 | } |
| 3635 | return 1; |
| 3636 | } |
| 3637 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3638 | /* Increment the General Purpose Counter 0 value from the stream's tracked |
| 3639 | * frontend counters and return it into temp integer. |
| 3640 | * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. |
| 3641 | */ |
| 3642 | static int |
| 3643 | smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3644 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3645 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3646 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3647 | unsigned int period = 0; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3648 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3649 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3650 | if (!stkctr) |
| 3651 | return 0; |
| 3652 | |
| 3653 | smp->flags = SMP_F_VOL_TEST; |
| 3654 | smp->data.type = SMP_T_SINT; |
| 3655 | smp->data.u.sint = 0; |
| 3656 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3657 | if (!stkctr_entry(stkctr)) |
| 3658 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3659 | |
| 3660 | if (stkctr && stkctr_entry(stkctr)) { |
| 3661 | void *ptr1,*ptr2; |
| 3662 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3663 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3664 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3665 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3666 | */ |
| 3667 | 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] | 3668 | if (ptr1) { |
| 3669 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3670 | } |
| 3671 | else { |
| 3672 | /* fallback on the gpc array */ |
| 3673 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3674 | if (ptr1) |
| 3675 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3676 | } |
| 3677 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3678 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3679 | if (!ptr2) { |
| 3680 | /* fallback on the gpc array */ |
| 3681 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3682 | } |
| 3683 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3684 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3685 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3686 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3687 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3688 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3689 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3690 | 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] | 3691 | } |
| 3692 | |
| 3693 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3694 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3695 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3696 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3697 | |
| 3698 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3699 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3700 | } |
| 3701 | else if (stkctr == &tmpstkctr) |
| 3702 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3703 | } |
| 3704 | return 1; |
| 3705 | } |
| 3706 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3707 | /* Increment the General Purpose Counter 1 value from the stream's tracked |
| 3708 | * frontend counters and return it into temp integer. |
| 3709 | * Supports being called as "sc[0-9]_inc_gpc1" or "src_inc_gpc1" only. |
| 3710 | */ |
| 3711 | static int |
| 3712 | smp_fetch_sc_inc_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3713 | { |
| 3714 | struct stkctr tmpstkctr; |
| 3715 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3716 | unsigned int period = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3717 | |
| 3718 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3719 | if (!stkctr) |
| 3720 | return 0; |
| 3721 | |
| 3722 | smp->flags = SMP_F_VOL_TEST; |
| 3723 | smp->data.type = SMP_T_SINT; |
| 3724 | smp->data.u.sint = 0; |
| 3725 | |
| 3726 | if (!stkctr_entry(stkctr)) |
| 3727 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3728 | |
| 3729 | if (stkctr && stkctr_entry(stkctr)) { |
| 3730 | void *ptr1,*ptr2; |
| 3731 | |
| 3732 | |
| 3733 | /* First, update gpc1_rate if it's tracked. Second, update its |
| 3734 | * gpc1 if tracked. Returns gpc1's value otherwise the curr_ctr. |
| 3735 | */ |
| 3736 | 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] | 3737 | if (ptr1) { |
| 3738 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3739 | } |
| 3740 | else { |
| 3741 | /* fallback on the gpc array */ |
| 3742 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3743 | if (ptr1) |
| 3744 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3745 | } |
| 3746 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3747 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3748 | if (!ptr2) { |
| 3749 | /* fallback on the gpc array */ |
| 3750 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3751 | } |
| 3752 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3753 | if (ptr1 || ptr2) { |
| 3754 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3755 | |
| 3756 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3757 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3758 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3759 | 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] | 3760 | } |
| 3761 | |
| 3762 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3763 | 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] | 3764 | |
| 3765 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3766 | |
| 3767 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3768 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3769 | } |
| 3770 | else if (stkctr == &tmpstkctr) |
| 3771 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3772 | } |
| 3773 | return 1; |
| 3774 | } |
| 3775 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3776 | /* Clear the GPC[args(0)] value from the stream's tracked |
| 3777 | * frontend counters and return its previous value into temp integer. |
| 3778 | * Supports being called as "sc_clr_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3779 | * or "src_clr_gpc(<gpc-idx>[,<table>])" only. |
| 3780 | */ |
| 3781 | static int |
| 3782 | smp_fetch_sc_clr_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3783 | { |
| 3784 | struct stkctr tmpstkctr; |
| 3785 | struct stkctr *stkctr; |
| 3786 | unsigned int idx; |
| 3787 | |
| 3788 | idx = args[0].data.sint; |
| 3789 | |
| 3790 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3791 | if (!stkctr) |
| 3792 | return 0; |
| 3793 | |
| 3794 | smp->flags = SMP_F_VOL_TEST; |
| 3795 | smp->data.type = SMP_T_SINT; |
| 3796 | smp->data.u.sint = 0; |
| 3797 | |
| 3798 | if (!stkctr_entry(stkctr)) |
| 3799 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3800 | |
| 3801 | if (stkctr && stkctr_entry(stkctr)) { |
| 3802 | void *ptr; |
| 3803 | |
| 3804 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3805 | if (!ptr) { |
| 3806 | if (stkctr == &tmpstkctr) |
| 3807 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3808 | return 0; /* parameter not stored */ |
| 3809 | } |
| 3810 | |
| 3811 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3812 | |
| 3813 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3814 | stktable_data_cast(ptr, std_t_uint) = 0; |
| 3815 | |
| 3816 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3817 | |
| 3818 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3819 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3820 | } |
| 3821 | return 1; |
| 3822 | } |
| 3823 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3824 | /* Clear the General Purpose Counter 0 value from the stream's tracked |
| 3825 | * frontend counters and return its previous value into temp integer. |
| 3826 | * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only. |
| 3827 | */ |
| 3828 | static int |
| 3829 | smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3830 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3831 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3832 | struct stkctr *stkctr; |
| 3833 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3834 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3835 | if (!stkctr) |
| 3836 | return 0; |
| 3837 | |
| 3838 | smp->flags = SMP_F_VOL_TEST; |
| 3839 | smp->data.type = SMP_T_SINT; |
| 3840 | smp->data.u.sint = 0; |
| 3841 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3842 | if (!stkctr_entry(stkctr)) |
| 3843 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3844 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3845 | if (stkctr && stkctr_entry(stkctr)) { |
| 3846 | void *ptr; |
| 3847 | |
| 3848 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3849 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3850 | /* fallback on the gpc array */ |
| 3851 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3852 | } |
| 3853 | |
| 3854 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3855 | if (stkctr == &tmpstkctr) |
| 3856 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3857 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3858 | } |
| 3859 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3860 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3861 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3862 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3863 | stktable_data_cast(ptr, std_t_uint) = 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3864 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3865 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3866 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3867 | /* If data was modified, we need to touch to re-schedule sync */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3868 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3869 | } |
| 3870 | return 1; |
| 3871 | } |
| 3872 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3873 | /* Clear the General Purpose Counter 1 value from the stream's tracked |
| 3874 | * frontend counters and return its previous value into temp integer. |
| 3875 | * Supports being called as "sc[0-9]_clr_gpc1" or "src_clr_gpc1" only. |
| 3876 | */ |
| 3877 | static int |
| 3878 | smp_fetch_sc_clr_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3879 | { |
| 3880 | struct stkctr tmpstkctr; |
| 3881 | struct stkctr *stkctr; |
| 3882 | |
| 3883 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3884 | if (!stkctr) |
| 3885 | return 0; |
| 3886 | |
| 3887 | smp->flags = SMP_F_VOL_TEST; |
| 3888 | smp->data.type = SMP_T_SINT; |
| 3889 | smp->data.u.sint = 0; |
| 3890 | |
| 3891 | if (!stkctr_entry(stkctr)) |
| 3892 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3893 | |
| 3894 | if (stkctr && stkctr_entry(stkctr)) { |
| 3895 | void *ptr; |
| 3896 | |
| 3897 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3898 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3899 | /* fallback on the gpc array */ |
| 3900 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3901 | } |
| 3902 | |
| 3903 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3904 | if (stkctr == &tmpstkctr) |
| 3905 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3906 | return 0; /* parameter not stored */ |
| 3907 | } |
| 3908 | |
| 3909 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3910 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3911 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3912 | stktable_data_cast(ptr, std_t_uint) = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3913 | |
| 3914 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3915 | |
| 3916 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3917 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3918 | } |
| 3919 | return 1; |
| 3920 | } |
| 3921 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3922 | /* set <smp> to the cumulated number of connections from the stream's tracked |
| 3923 | * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or |
| 3924 | * "src_conn_cnt" only. |
| 3925 | */ |
| 3926 | static int |
| 3927 | smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3928 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3929 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3930 | struct stkctr *stkctr; |
| 3931 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3932 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3933 | if (!stkctr) |
| 3934 | return 0; |
| 3935 | |
| 3936 | smp->flags = SMP_F_VOL_TEST; |
| 3937 | smp->data.type = SMP_T_SINT; |
| 3938 | smp->data.u.sint = 0; |
| 3939 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3940 | void *ptr; |
| 3941 | |
| 3942 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); |
| 3943 | if (!ptr) { |
| 3944 | if (stkctr == &tmpstkctr) |
| 3945 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3946 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3947 | } |
| 3948 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3949 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3950 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3951 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3952 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3953 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3954 | |
| 3955 | if (stkctr == &tmpstkctr) |
| 3956 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3957 | |
| 3958 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3959 | } |
| 3960 | return 1; |
| 3961 | } |
| 3962 | |
| 3963 | /* set <smp> to the connection rate from the stream's tracked frontend |
| 3964 | * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate" |
| 3965 | * only. |
| 3966 | */ |
| 3967 | static int |
| 3968 | smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3969 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3970 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3971 | struct stkctr *stkctr; |
| 3972 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3973 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3974 | if (!stkctr) |
| 3975 | return 0; |
| 3976 | |
| 3977 | smp->flags = SMP_F_VOL_TEST; |
| 3978 | smp->data.type = SMP_T_SINT; |
| 3979 | smp->data.u.sint = 0; |
| 3980 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3981 | void *ptr; |
| 3982 | |
| 3983 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); |
| 3984 | if (!ptr) { |
| 3985 | if (stkctr == &tmpstkctr) |
| 3986 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3987 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3988 | } |
| 3989 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3990 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3991 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3992 | 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] | 3993 | stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3994 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3995 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3996 | |
| 3997 | if (stkctr == &tmpstkctr) |
| 3998 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3999 | } |
| 4000 | return 1; |
| 4001 | } |
| 4002 | |
| 4003 | /* set temp integer to the number of connections from the stream's source address |
| 4004 | * in the table pointed to by expr, after updating it. |
| 4005 | * Accepts exactly 1 argument of type table. |
| 4006 | */ |
| 4007 | static int |
| 4008 | smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4009 | { |
| 4010 | struct connection *conn = objt_conn(smp->sess->origin); |
| 4011 | struct stksess *ts; |
| 4012 | struct stktable_key *key; |
| 4013 | void *ptr; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4014 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4015 | |
| 4016 | if (!conn) |
| 4017 | return 0; |
| 4018 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 4019 | /* Fetch source address in a sample. */ |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 4020 | 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] | 4021 | return 0; |
| 4022 | |
| 4023 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4024 | key = smp_to_stkey(smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4025 | if (!key) |
| 4026 | return 0; |
| 4027 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4028 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4029 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4030 | if ((ts = stktable_get_entry(t, key)) == NULL) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4031 | /* entry does not exist and could not be created */ |
| 4032 | return 0; |
| 4033 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4034 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4035 | if (!ptr) { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4036 | return 0; /* parameter not stored in this table */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4037 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4038 | |
| 4039 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4040 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4041 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4042 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4043 | smp->data.u.sint = ++stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4044 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4045 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4046 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4047 | smp->flags = SMP_F_VOL_TEST; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4048 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4049 | stktable_touch_local(t, ts, 1); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4050 | |
| 4051 | /* Touch was previously performed by stktable_update_key */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4052 | return 1; |
| 4053 | } |
| 4054 | |
| 4055 | /* set <smp> to the number of concurrent connections from the stream's tracked |
| 4056 | * frontend counters. Supports being called as "sc[0-9]_conn_cur" or |
| 4057 | * "src_conn_cur" only. |
| 4058 | */ |
| 4059 | static int |
| 4060 | smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4061 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4062 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4063 | struct stkctr *stkctr; |
| 4064 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4065 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4066 | if (!stkctr) |
| 4067 | return 0; |
| 4068 | |
| 4069 | smp->flags = SMP_F_VOL_TEST; |
| 4070 | smp->data.type = SMP_T_SINT; |
| 4071 | smp->data.u.sint = 0; |
| 4072 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4073 | void *ptr; |
| 4074 | |
| 4075 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); |
| 4076 | if (!ptr) { |
| 4077 | if (stkctr == &tmpstkctr) |
| 4078 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4079 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4080 | } |
| 4081 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4082 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4083 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4084 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4085 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4086 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4087 | |
| 4088 | if (stkctr == &tmpstkctr) |
| 4089 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4090 | } |
| 4091 | return 1; |
| 4092 | } |
| 4093 | |
| 4094 | /* set <smp> to the cumulated number of streams from the stream's tracked |
| 4095 | * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or |
| 4096 | * "src_sess_cnt" only. |
| 4097 | */ |
| 4098 | static int |
| 4099 | smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4100 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4101 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4102 | struct stkctr *stkctr; |
| 4103 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4104 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4105 | if (!stkctr) |
| 4106 | return 0; |
| 4107 | |
| 4108 | smp->flags = SMP_F_VOL_TEST; |
| 4109 | smp->data.type = SMP_T_SINT; |
| 4110 | smp->data.u.sint = 0; |
| 4111 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4112 | void *ptr; |
| 4113 | |
| 4114 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); |
| 4115 | if (!ptr) { |
| 4116 | if (stkctr == &tmpstkctr) |
| 4117 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4118 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4119 | } |
| 4120 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4121 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4122 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4123 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4124 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4125 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4126 | |
| 4127 | if (stkctr == &tmpstkctr) |
| 4128 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4129 | } |
| 4130 | return 1; |
| 4131 | } |
| 4132 | |
| 4133 | /* set <smp> to the stream rate from the stream's tracked frontend counters. |
| 4134 | * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only. |
| 4135 | */ |
| 4136 | static int |
| 4137 | smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4138 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4139 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4140 | struct stkctr *stkctr; |
| 4141 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4142 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4143 | if (!stkctr) |
| 4144 | return 0; |
| 4145 | |
| 4146 | smp->flags = SMP_F_VOL_TEST; |
| 4147 | smp->data.type = SMP_T_SINT; |
| 4148 | smp->data.u.sint = 0; |
| 4149 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4150 | void *ptr; |
| 4151 | |
| 4152 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); |
| 4153 | if (!ptr) { |
| 4154 | if (stkctr == &tmpstkctr) |
| 4155 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4156 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4157 | } |
| 4158 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4159 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4160 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4161 | 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] | 4162 | stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4163 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4164 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4165 | |
| 4166 | if (stkctr == &tmpstkctr) |
| 4167 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4168 | } |
| 4169 | return 1; |
| 4170 | } |
| 4171 | |
| 4172 | /* set <smp> to the cumulated number of HTTP requests from the stream's tracked |
| 4173 | * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or |
| 4174 | * "src_http_req_cnt" only. |
| 4175 | */ |
| 4176 | static int |
| 4177 | smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4178 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4179 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4180 | struct stkctr *stkctr; |
| 4181 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4182 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4183 | if (!stkctr) |
| 4184 | return 0; |
| 4185 | |
| 4186 | smp->flags = SMP_F_VOL_TEST; |
| 4187 | smp->data.type = SMP_T_SINT; |
| 4188 | smp->data.u.sint = 0; |
| 4189 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4190 | void *ptr; |
| 4191 | |
| 4192 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
| 4193 | if (!ptr) { |
| 4194 | if (stkctr == &tmpstkctr) |
| 4195 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4196 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4197 | } |
| 4198 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4199 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4200 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4201 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4202 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4203 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4204 | |
| 4205 | if (stkctr == &tmpstkctr) |
| 4206 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4207 | } |
| 4208 | return 1; |
| 4209 | } |
| 4210 | |
| 4211 | /* set <smp> to the HTTP request rate from the stream's tracked frontend |
| 4212 | * counters. Supports being called as "sc[0-9]_http_req_rate" or |
| 4213 | * "src_http_req_rate" only. |
| 4214 | */ |
| 4215 | static int |
| 4216 | smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4217 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4218 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4219 | struct stkctr *stkctr; |
| 4220 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4221 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4222 | if (!stkctr) |
| 4223 | return 0; |
| 4224 | |
| 4225 | smp->flags = SMP_F_VOL_TEST; |
| 4226 | smp->data.type = SMP_T_SINT; |
| 4227 | smp->data.u.sint = 0; |
| 4228 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4229 | void *ptr; |
| 4230 | |
| 4231 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
| 4232 | if (!ptr) { |
| 4233 | if (stkctr == &tmpstkctr) |
| 4234 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4235 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4236 | } |
| 4237 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4238 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4239 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4240 | 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] | 4241 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4242 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4243 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4244 | |
| 4245 | if (stkctr == &tmpstkctr) |
| 4246 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4247 | } |
| 4248 | return 1; |
| 4249 | } |
| 4250 | |
| 4251 | /* set <smp> to the cumulated number of HTTP requests errors from the stream's |
| 4252 | * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or |
| 4253 | * "src_http_err_cnt" only. |
| 4254 | */ |
| 4255 | static int |
| 4256 | smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4257 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4258 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4259 | struct stkctr *stkctr; |
| 4260 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4261 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4262 | if (!stkctr) |
| 4263 | return 0; |
| 4264 | |
| 4265 | smp->flags = SMP_F_VOL_TEST; |
| 4266 | smp->data.type = SMP_T_SINT; |
| 4267 | smp->data.u.sint = 0; |
| 4268 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4269 | void *ptr; |
| 4270 | |
| 4271 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
| 4272 | if (!ptr) { |
| 4273 | if (stkctr == &tmpstkctr) |
| 4274 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4275 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4276 | } |
| 4277 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4278 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4279 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4280 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4281 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4282 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4283 | |
| 4284 | if (stkctr == &tmpstkctr) |
| 4285 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4286 | } |
| 4287 | return 1; |
| 4288 | } |
| 4289 | |
| 4290 | /* set <smp> to the HTTP request error rate from the stream's tracked frontend |
| 4291 | * counters. Supports being called as "sc[0-9]_http_err_rate" or |
| 4292 | * "src_http_err_rate" only. |
| 4293 | */ |
| 4294 | static int |
| 4295 | smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4296 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4297 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4298 | struct stkctr *stkctr; |
| 4299 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4300 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4301 | if (!stkctr) |
| 4302 | return 0; |
| 4303 | |
| 4304 | smp->flags = SMP_F_VOL_TEST; |
| 4305 | smp->data.type = SMP_T_SINT; |
| 4306 | smp->data.u.sint = 0; |
| 4307 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4308 | void *ptr; |
| 4309 | |
| 4310 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
| 4311 | if (!ptr) { |
| 4312 | if (stkctr == &tmpstkctr) |
| 4313 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4314 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4315 | } |
| 4316 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4317 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4318 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4319 | 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] | 4320 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4321 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4322 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4323 | |
| 4324 | if (stkctr == &tmpstkctr) |
| 4325 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4326 | } |
| 4327 | return 1; |
| 4328 | } |
| 4329 | |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4330 | /* set <smp> to the cumulated number of HTTP response failures from the stream's |
| 4331 | * tracked frontend counters. Supports being called as "sc[0-9]_http_fail_cnt" or |
| 4332 | * "src_http_fail_cnt" only. |
| 4333 | */ |
| 4334 | static int |
| 4335 | smp_fetch_sc_http_fail_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4336 | { |
| 4337 | struct stkctr tmpstkctr; |
| 4338 | struct stkctr *stkctr; |
| 4339 | |
| 4340 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4341 | if (!stkctr) |
| 4342 | return 0; |
| 4343 | |
| 4344 | smp->flags = SMP_F_VOL_TEST; |
| 4345 | smp->data.type = SMP_T_SINT; |
| 4346 | smp->data.u.sint = 0; |
| 4347 | if (stkctr_entry(stkctr) != NULL) { |
| 4348 | void *ptr; |
| 4349 | |
| 4350 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_CNT); |
| 4351 | if (!ptr) { |
| 4352 | if (stkctr == &tmpstkctr) |
| 4353 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4354 | return 0; /* parameter not stored */ |
| 4355 | } |
| 4356 | |
| 4357 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4358 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4359 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4360 | |
| 4361 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4362 | |
| 4363 | if (stkctr == &tmpstkctr) |
| 4364 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4365 | } |
| 4366 | return 1; |
| 4367 | } |
| 4368 | |
| 4369 | /* set <smp> to the HTTP response failure rate from the stream's tracked frontend |
| 4370 | * counters. Supports being called as "sc[0-9]_http_fail_rate" or |
| 4371 | * "src_http_fail_rate" only. |
| 4372 | */ |
| 4373 | static int |
| 4374 | smp_fetch_sc_http_fail_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4375 | { |
| 4376 | struct stkctr tmpstkctr; |
| 4377 | struct stkctr *stkctr; |
| 4378 | |
| 4379 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4380 | if (!stkctr) |
| 4381 | return 0; |
| 4382 | |
| 4383 | smp->flags = SMP_F_VOL_TEST; |
| 4384 | smp->data.type = SMP_T_SINT; |
| 4385 | smp->data.u.sint = 0; |
| 4386 | if (stkctr_entry(stkctr) != NULL) { |
| 4387 | void *ptr; |
| 4388 | |
| 4389 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_RATE); |
| 4390 | if (!ptr) { |
| 4391 | if (stkctr == &tmpstkctr) |
| 4392 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4393 | return 0; /* parameter not stored */ |
| 4394 | } |
| 4395 | |
| 4396 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4397 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4398 | 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] | 4399 | stkctr->table->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u); |
| 4400 | |
| 4401 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4402 | |
| 4403 | if (stkctr == &tmpstkctr) |
| 4404 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4405 | } |
| 4406 | return 1; |
| 4407 | } |
| 4408 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4409 | /* set <smp> to the number of kbytes received from clients, as found in the |
| 4410 | * stream's tracked frontend counters. Supports being called as |
| 4411 | * "sc[0-9]_kbytes_in" or "src_kbytes_in" only. |
| 4412 | */ |
| 4413 | static int |
| 4414 | smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4415 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4416 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4417 | struct stkctr *stkctr; |
| 4418 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4419 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4420 | if (!stkctr) |
| 4421 | return 0; |
| 4422 | |
| 4423 | smp->flags = SMP_F_VOL_TEST; |
| 4424 | smp->data.type = SMP_T_SINT; |
| 4425 | smp->data.u.sint = 0; |
| 4426 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4427 | void *ptr; |
| 4428 | |
| 4429 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
| 4430 | if (!ptr) { |
| 4431 | if (stkctr == &tmpstkctr) |
| 4432 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4433 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4434 | } |
| 4435 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4436 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4437 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4438 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4439 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4440 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4441 | |
| 4442 | if (stkctr == &tmpstkctr) |
| 4443 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4444 | } |
| 4445 | return 1; |
| 4446 | } |
| 4447 | |
| 4448 | /* set <smp> to the data rate received from clients in bytes/s, as found |
| 4449 | * in the stream's tracked frontend counters. Supports being called as |
| 4450 | * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only. |
| 4451 | */ |
| 4452 | static int |
| 4453 | smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4454 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4455 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4456 | struct stkctr *stkctr; |
| 4457 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4458 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4459 | if (!stkctr) |
| 4460 | return 0; |
| 4461 | |
| 4462 | smp->flags = SMP_F_VOL_TEST; |
| 4463 | smp->data.type = SMP_T_SINT; |
| 4464 | smp->data.u.sint = 0; |
| 4465 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4466 | void *ptr; |
| 4467 | |
| 4468 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
| 4469 | if (!ptr) { |
| 4470 | if (stkctr == &tmpstkctr) |
| 4471 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4472 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4473 | } |
| 4474 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4475 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4476 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4477 | 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] | 4478 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4479 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4480 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4481 | |
| 4482 | if (stkctr == &tmpstkctr) |
| 4483 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4484 | } |
| 4485 | return 1; |
| 4486 | } |
| 4487 | |
| 4488 | /* set <smp> to the number of kbytes sent to clients, as found in the |
| 4489 | * stream's tracked frontend counters. Supports being called as |
| 4490 | * "sc[0-9]_kbytes_out" or "src_kbytes_out" only. |
| 4491 | */ |
| 4492 | static int |
| 4493 | smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4494 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4495 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4496 | struct stkctr *stkctr; |
| 4497 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4498 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4499 | if (!stkctr) |
| 4500 | return 0; |
| 4501 | |
| 4502 | smp->flags = SMP_F_VOL_TEST; |
| 4503 | smp->data.type = SMP_T_SINT; |
| 4504 | smp->data.u.sint = 0; |
| 4505 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4506 | void *ptr; |
| 4507 | |
| 4508 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
| 4509 | if (!ptr) { |
| 4510 | if (stkctr == &tmpstkctr) |
| 4511 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4512 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4513 | } |
| 4514 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4515 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4516 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4517 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4518 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4519 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4520 | |
| 4521 | if (stkctr == &tmpstkctr) |
| 4522 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4523 | } |
| 4524 | return 1; |
| 4525 | } |
| 4526 | |
| 4527 | /* set <smp> to the data rate sent to clients in bytes/s, as found in the |
| 4528 | * stream's tracked frontend counters. Supports being called as |
| 4529 | * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. |
| 4530 | */ |
| 4531 | static int |
| 4532 | smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4533 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4534 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4535 | struct stkctr *stkctr; |
| 4536 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4537 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4538 | if (!stkctr) |
| 4539 | return 0; |
| 4540 | |
| 4541 | smp->flags = SMP_F_VOL_TEST; |
| 4542 | smp->data.type = SMP_T_SINT; |
| 4543 | smp->data.u.sint = 0; |
| 4544 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4545 | void *ptr; |
| 4546 | |
| 4547 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
| 4548 | if (!ptr) { |
| 4549 | if (stkctr == &tmpstkctr) |
| 4550 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4551 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4552 | } |
| 4553 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4554 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4555 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4556 | 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] | 4557 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4558 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4559 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4560 | |
| 4561 | if (stkctr == &tmpstkctr) |
| 4562 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4563 | } |
| 4564 | return 1; |
| 4565 | } |
| 4566 | |
| 4567 | /* set <smp> to the number of active trackers on the SC entry in the stream's |
| 4568 | * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only. |
| 4569 | */ |
| 4570 | static int |
| 4571 | smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4572 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4573 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4574 | struct stkctr *stkctr; |
| 4575 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4576 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4577 | if (!stkctr) |
| 4578 | return 0; |
| 4579 | |
| 4580 | smp->flags = SMP_F_VOL_TEST; |
| 4581 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4582 | if (stkctr == &tmpstkctr) { |
| 4583 | smp->data.u.sint = stkctr_entry(stkctr) ? (stkctr_entry(stkctr)->ref_cnt-1) : 0; |
| 4584 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4585 | } |
| 4586 | else { |
| 4587 | smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0; |
| 4588 | } |
| 4589 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4590 | return 1; |
| 4591 | } |
| 4592 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4593 | |
| 4594 | /* The functions below are used to manipulate table contents from the CLI. |
| 4595 | * There are 3 main actions, "clear", "set" and "show". The code is shared |
| 4596 | * between all actions, and the action is encoded in the void *private in |
| 4597 | * the appctx as well as in the keyword registration, among one of the |
| 4598 | * following values. |
| 4599 | */ |
| 4600 | |
| 4601 | enum { |
| 4602 | STK_CLI_ACT_CLR, |
| 4603 | STK_CLI_ACT_SET, |
| 4604 | STK_CLI_ACT_SHOW, |
| 4605 | }; |
| 4606 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4607 | /* Dump the status of a table to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4608 | * read buffer. It returns 0 if the output buffer is full |
| 4609 | * and needs to be called again, otherwise non-zero. |
| 4610 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4611 | static int table_dump_head_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4612 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4613 | struct stktable *t, struct stktable *target) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4614 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 4615 | struct stream *s = __sc_strm(appctx_sc(appctx)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4616 | |
| 4617 | 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] | 4618 | t->id, stktable_types[t->type].kw, t->size, t->current); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4619 | |
| 4620 | /* any other information should be dumped here */ |
| 4621 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 4622 | 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] | 4623 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
| 4624 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4625 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4626 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4627 | |
| 4628 | return 1; |
| 4629 | } |
| 4630 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4631 | /* Dump a table entry to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4632 | * read buffer. It returns 0 if the output buffer is full |
| 4633 | * and needs to be called again, otherwise non-zero. |
| 4634 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4635 | static int table_dump_entry_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4636 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4637 | struct stktable *t, struct stksess *entry) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4638 | { |
| 4639 | int dt; |
| 4640 | |
| 4641 | chunk_appendf(msg, "%p:", entry); |
| 4642 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4643 | if (t->type == SMP_T_IPV4) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4644 | char addr[INET_ADDRSTRLEN]; |
| 4645 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4646 | chunk_appendf(msg, " key=%s", addr); |
| 4647 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4648 | else if (t->type == SMP_T_IPV6) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4649 | char addr[INET6_ADDRSTRLEN]; |
| 4650 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4651 | chunk_appendf(msg, " key=%s", addr); |
| 4652 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4653 | else if (t->type == SMP_T_SINT) { |
Willy Tarreau | 6cde5d8 | 2020-02-25 09:41:22 +0100 | [diff] [blame] | 4654 | chunk_appendf(msg, " key=%u", read_u32(entry->key.key)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4655 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4656 | else if (t->type == SMP_T_STR) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4657 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4658 | dump_text(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4659 | } |
| 4660 | else { |
| 4661 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4662 | dump_binary(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4663 | } |
| 4664 | |
Willy Tarreau | 16b282f | 2022-11-29 11:55:18 +0100 | [diff] [blame] | 4665 | 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] | 4666 | |
| 4667 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 4668 | void *ptr; |
| 4669 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4670 | if (t->data_ofs[dt] == 0) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4671 | continue; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 4672 | if (stktable_data_types[dt].is_array) { |
| 4673 | char tmp[16] = {}; |
| 4674 | const char *name_pfx = stktable_data_types[dt].name; |
| 4675 | const char *name_sfx = NULL; |
| 4676 | unsigned int idx = 0; |
| 4677 | int i = 0; |
| 4678 | |
| 4679 | /* split name to show index before first _ of the name |
| 4680 | * for example: 'gpc3_rate' if array name is 'gpc_rate'. |
| 4681 | */ |
| 4682 | for (i = 0 ; i < (sizeof(tmp) - 1); i++) { |
| 4683 | if (!name_pfx[i]) |
| 4684 | break; |
| 4685 | if (name_pfx[i] == '_') { |
| 4686 | name_pfx = &tmp[0]; |
| 4687 | name_sfx = &stktable_data_types[dt].name[i]; |
| 4688 | break; |
| 4689 | } |
| 4690 | tmp[i] = name_pfx[i]; |
| 4691 | } |
| 4692 | |
| 4693 | ptr = stktable_data_ptr_idx(t, entry, dt, idx); |
| 4694 | while (ptr) { |
| 4695 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
| 4696 | chunk_appendf(msg, " %s%u%s(%u)=", name_pfx, idx, name_sfx ? name_sfx : "", t->data_arg[dt].u); |
| 4697 | else |
| 4698 | chunk_appendf(msg, " %s%u%s=", name_pfx, idx, name_sfx ? name_sfx : ""); |
| 4699 | switch (stktable_data_types[dt].std_type) { |
| 4700 | case STD_T_SINT: |
| 4701 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4702 | break; |
| 4703 | case STD_T_UINT: |
| 4704 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4705 | break; |
| 4706 | case STD_T_ULL: |
| 4707 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
| 4708 | break; |
| 4709 | case STD_T_FRQP: |
| 4710 | chunk_appendf(msg, "%u", |
| 4711 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 4712 | t->data_arg[dt].u)); |
| 4713 | break; |
| 4714 | } |
| 4715 | ptr = stktable_data_ptr_idx(t, entry, dt, ++idx); |
| 4716 | } |
| 4717 | continue; |
| 4718 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4719 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4720 | 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] | 4721 | else |
| 4722 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
| 4723 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4724 | ptr = stktable_data_ptr(t, entry, dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4725 | switch (stktable_data_types[dt].std_type) { |
| 4726 | case STD_T_SINT: |
| 4727 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4728 | break; |
| 4729 | case STD_T_UINT: |
| 4730 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4731 | break; |
| 4732 | case STD_T_ULL: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4733 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4734 | break; |
| 4735 | case STD_T_FRQP: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4736 | chunk_appendf(msg, "%u", |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4737 | 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] | 4738 | t->data_arg[dt].u)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4739 | break; |
Frédéric Lécaille | 16b4f54 | 2019-05-23 12:15:04 +0200 | [diff] [blame] | 4740 | case STD_T_DICT: { |
| 4741 | struct dict_entry *de; |
| 4742 | de = stktable_data_cast(ptr, std_t_dict); |
| 4743 | chunk_appendf(msg, "%s", de ? (char *)de->value.key : "-"); |
| 4744 | break; |
| 4745 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4746 | } |
| 4747 | } |
| 4748 | chunk_appendf(msg, "\n"); |
| 4749 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4750 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4751 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4752 | |
| 4753 | return 1; |
| 4754 | } |
| 4755 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4756 | /* appctx context used by the "show table" command */ |
| 4757 | struct show_table_ctx { |
| 4758 | void *target; /* table we want to dump, or NULL for all */ |
| 4759 | struct stktable *t; /* table being currently dumped (first if NULL) */ |
| 4760 | struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ |
| 4761 | long long value[STKTABLE_FILTER_LEN]; /* value to compare against */ |
| 4762 | signed char data_type[STKTABLE_FILTER_LEN]; /* type of data to compare, or -1 if none */ |
| 4763 | 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] | 4764 | enum { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4765 | STATE_NEXT = 0, /* px points to next table, entry=NULL */ |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 4766 | STATE_DUMP, /* px points to curr table, entry is valid, refcount held */ |
| 4767 | STATE_DONE, /* done dumping */ |
| 4768 | } state; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4769 | char action; /* action on the table : one of STK_CLI_ACT_* */ |
| 4770 | }; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4771 | |
| 4772 | /* Processes a single table entry matching a specific key passed in argument. |
| 4773 | * returns 0 if wants to be called again, 1 if has ended processing. |
| 4774 | */ |
| 4775 | static int table_process_entry_per_key(struct appctx *appctx, char **args) |
| 4776 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4777 | struct show_table_ctx *ctx = appctx->svcctx; |
| 4778 | struct stktable *t = ctx->target; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4779 | struct stksess *ts; |
| 4780 | uint32_t uint32_key; |
| 4781 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
| 4782 | long long value; |
| 4783 | int data_type; |
| 4784 | int cur_arg; |
| 4785 | void *ptr; |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4786 | struct freq_ctr *frqp; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4787 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4788 | if (!*args[4]) |
| 4789 | return cli_err(appctx, "Key value expected\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4790 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4791 | switch (t->type) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4792 | case SMP_T_IPV4: |
| 4793 | uint32_key = htonl(inetaddr_host(args[4])); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4794 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4795 | break; |
| 4796 | case SMP_T_IPV6: |
Christopher Faulet | b7c962b | 2021-11-15 09:17:25 +0100 | [diff] [blame] | 4797 | if (inet_pton(AF_INET6, args[4], ip6_key) <= 0) |
| 4798 | return cli_err(appctx, "Invalid key\n"); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4799 | static_table_key.key = &ip6_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4800 | break; |
| 4801 | case SMP_T_SINT: |
| 4802 | { |
| 4803 | char *endptr; |
| 4804 | unsigned long val; |
| 4805 | errno = 0; |
| 4806 | val = strtoul(args[4], &endptr, 10); |
| 4807 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 4808 | (errno != 0 && val == 0) || endptr == args[4] || |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4809 | val > 0xffffffff) |
| 4810 | return cli_err(appctx, "Invalid key\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4811 | uint32_key = (uint32_t) val; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4812 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4813 | break; |
| 4814 | } |
| 4815 | break; |
| 4816 | case SMP_T_STR: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4817 | static_table_key.key = args[4]; |
| 4818 | static_table_key.key_len = strlen(args[4]); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4819 | break; |
| 4820 | default: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4821 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4822 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4823 | 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] | 4824 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4825 | 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] | 4826 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4827 | 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] | 4828 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4829 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4830 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | /* check permissions */ |
| 4834 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 4835 | return 1; |
| 4836 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4837 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4838 | case STK_CLI_ACT_SHOW: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4839 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4840 | if (!ts) |
| 4841 | return 1; |
| 4842 | chunk_reset(&trash); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4843 | 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] | 4844 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4845 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4846 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4847 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4848 | if (!table_dump_entry_to_buffer(&trash, appctx, t, ts)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4849 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4850 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4851 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4852 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4853 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4854 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4855 | break; |
| 4856 | |
| 4857 | case STK_CLI_ACT_CLR: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4858 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4859 | if (!ts) |
| 4860 | return 1; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4861 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4862 | if (!stksess_kill(t, ts, 1)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4863 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4864 | return cli_err(appctx, "Entry currently in use, cannot remove\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4865 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4866 | break; |
| 4867 | |
| 4868 | case STK_CLI_ACT_SET: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4869 | ts = stktable_get_entry(t, &static_table_key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4870 | if (!ts) { |
| 4871 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4872 | return cli_err(appctx, "Unable to allocate a new entry\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4873 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4874 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4875 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 4876 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4877 | cli_err(appctx, "\"data.<type>\" followed by a value expected\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4878 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4879 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4880 | return 1; |
| 4881 | } |
| 4882 | |
| 4883 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 4884 | if (data_type < 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4885 | cli_err(appctx, "Unknown data type\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4886 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4887 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4888 | return 1; |
| 4889 | } |
| 4890 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4891 | if (!t->data_ofs[data_type]) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4892 | cli_err(appctx, "Data type not stored in this table\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4893 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4894 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4895 | return 1; |
| 4896 | } |
| 4897 | |
| 4898 | 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] | 4899 | cli_err(appctx, "Require a valid integer value to store\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4900 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4901 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4902 | return 1; |
| 4903 | } |
| 4904 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4905 | ptr = stktable_data_ptr(t, ts, data_type); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4906 | |
| 4907 | switch (stktable_data_types[data_type].std_type) { |
| 4908 | case STD_T_SINT: |
| 4909 | stktable_data_cast(ptr, std_t_sint) = value; |
| 4910 | break; |
| 4911 | case STD_T_UINT: |
| 4912 | stktable_data_cast(ptr, std_t_uint) = value; |
| 4913 | break; |
| 4914 | case STD_T_ULL: |
| 4915 | stktable_data_cast(ptr, std_t_ull) = value; |
| 4916 | break; |
| 4917 | case STD_T_FRQP: |
| 4918 | /* We set both the current and previous values. That way |
| 4919 | * the reported frequency is stable during all the period |
| 4920 | * then slowly fades out. This allows external tools to |
| 4921 | * push measures without having to update them too often. |
| 4922 | */ |
| 4923 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4924 | /* First bit is reserved for the freq_ctr lock |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4925 | Note: here we're still protected by the stksess lock |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4926 | so we don't need to update the update the freq_ctr |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4927 | using its internal lock */ |
| 4928 | frqp->curr_tick = now_ms & ~0x1; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4929 | frqp->prev_ctr = 0; |
| 4930 | frqp->curr_ctr = value; |
| 4931 | break; |
| 4932 | } |
| 4933 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4934 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4935 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4936 | break; |
| 4937 | |
| 4938 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4939 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4940 | } |
| 4941 | return 1; |
| 4942 | } |
| 4943 | |
| 4944 | /* Prepares the appctx fields with the data-based filters from the command line. |
| 4945 | * Returns 0 if the dump can proceed, 1 if has ended processing. |
| 4946 | */ |
| 4947 | static int table_prepare_data_request(struct appctx *appctx, char **args) |
| 4948 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4949 | struct show_table_ctx *ctx = appctx->svcctx; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4950 | int i; |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4951 | char *err = NULL; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4952 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4953 | 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] | 4954 | 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] | 4955 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4956 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
| 4957 | if (i > 0 && !*args[3+3*i]) // number of filter entries can be less than STKTABLE_FILTER_LEN |
| 4958 | break; |
| 4959 | /* condition on stored data value */ |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4960 | ctx->data_type[i] = stktable_get_data_type(args[3+3*i] + 5); |
| 4961 | if (ctx->data_type[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4962 | 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] | 4963 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4964 | if (!((struct stktable *)ctx->target)->data_ofs[ctx->data_type[i]]) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4965 | 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] | 4966 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4967 | ctx->data_op[i] = get_std_op(args[4+3*i]); |
| 4968 | if (ctx->data_op[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4969 | 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] | 4970 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4971 | 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] | 4972 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require a valid integer value to compare against\n", i + 1)); |
| 4973 | } |
| 4974 | |
| 4975 | if (*args[3+3*i]) { |
| 4976 | 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] | 4977 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4978 | |
| 4979 | /* OK we're done, all the fields are set */ |
| 4980 | return 0; |
| 4981 | } |
| 4982 | |
| 4983 | /* 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] | 4984 | 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] | 4985 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4986 | struct show_table_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4987 | int i; |
| 4988 | |
| 4989 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4990 | ctx->data_type[i] = -1; |
| 4991 | ctx->target = NULL; |
| 4992 | ctx->entry = NULL; |
| 4993 | ctx->action = (long)private; // keyword argument, one of STK_CLI_ACT_* |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4994 | |
| 4995 | if (*args[2]) { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4996 | ctx->t = ctx->target = stktable_find_by_name(args[2]); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4997 | if (!ctx->target) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4998 | return cli_err(appctx, "No such table\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4999 | } |
| 5000 | else { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5001 | ctx->t = stktables_list; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5002 | if (ctx->action != STK_CLI_ACT_SHOW) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5003 | goto err_args; |
| 5004 | return 0; |
| 5005 | } |
| 5006 | |
| 5007 | if (strcmp(args[3], "key") == 0) |
| 5008 | return table_process_entry_per_key(appctx, args); |
| 5009 | else if (strncmp(args[3], "data.", 5) == 0) |
| 5010 | return table_prepare_data_request(appctx, args); |
| 5011 | else if (*args[3]) |
| 5012 | goto err_args; |
| 5013 | |
| 5014 | return 0; |
| 5015 | |
| 5016 | err_args: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5017 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5018 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5019 | 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] | 5020 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5021 | 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] | 5022 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5023 | 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] | 5024 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5025 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5026 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | /* This function is used to deal with table operations (dump or clear depending |
| 5030 | * on the action stored in appctx->private). It returns 0 if the output buffer is |
| 5031 | * full and it needs to be called again, otherwise non-zero. |
| 5032 | */ |
| 5033 | static int cli_io_handler_table(struct appctx *appctx) |
| 5034 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5035 | struct show_table_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5036 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 475e463 | 2022-05-27 10:26:46 +0200 | [diff] [blame] | 5037 | struct stream *s = __sc_strm(sc); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5038 | struct ebmb_node *eb; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5039 | int skip_entry; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5040 | int show = ctx->action == STK_CLI_ACT_SHOW; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5041 | |
| 5042 | /* |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5043 | * We have 3 possible states in ctx->state : |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5044 | * - STATE_NEXT : the proxy pointer points to the next table to |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5045 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5046 | * - STATE_DUMP : the proxy pointer points to the current table |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5047 | * and the entry pointer points to the next entry to be dumped, |
| 5048 | * and the refcount on the next entry is held ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5049 | * - STATE_DONE : nothing left to dump, the buffer may contain some |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5050 | * data though. |
| 5051 | */ |
Christopher Faulet | 87633c3 | 2023-04-03 18:32:50 +0200 | [diff] [blame] | 5052 | /* FIXME: Don't watch the other side !*/ |
Christopher Faulet | 208c712 | 2023-04-13 16:16:15 +0200 | [diff] [blame] | 5053 | if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5054 | /* 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] | 5055 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5056 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5057 | } |
| 5058 | return 1; |
| 5059 | } |
| 5060 | |
| 5061 | chunk_reset(&trash); |
| 5062 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5063 | while (ctx->state != STATE_DONE) { |
| 5064 | switch (ctx->state) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5065 | case STATE_NEXT: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5066 | if (!ctx->t || |
| 5067 | (ctx->target && |
| 5068 | ctx->t != ctx->target)) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5069 | ctx->state = STATE_DONE; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5070 | break; |
| 5071 | } |
| 5072 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5073 | if (ctx->t->size) { |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5074 | 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] | 5075 | return 0; |
| 5076 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5077 | if (ctx->target && |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 5078 | (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5079 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5080 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5081 | eb = ebmb_first(&ctx->t->keys); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5082 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5083 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
| 5084 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5085 | ctx->state = STATE_DUMP; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5086 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5087 | break; |
| 5088 | } |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5089 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5090 | } |
| 5091 | } |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5092 | ctx->t = ctx->t->next; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5093 | break; |
| 5094 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5095 | case STATE_DUMP: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5096 | skip_entry = 0; |
| 5097 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5098 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5099 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5100 | if (ctx->data_type[0] >= 0) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5101 | /* we're filtering on some data contents */ |
| 5102 | void *ptr; |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5103 | int dt, i; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5104 | signed char op; |
| 5105 | long long data, value; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5106 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5107 | |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5108 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5109 | if (ctx->data_type[i] == -1) |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5110 | break; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5111 | dt = ctx->data_type[i]; |
| 5112 | ptr = stktable_data_ptr(ctx->t, |
| 5113 | ctx->entry, |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5114 | dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5115 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5116 | data = 0; |
| 5117 | switch (stktable_data_types[dt].std_type) { |
| 5118 | case STD_T_SINT: |
| 5119 | data = stktable_data_cast(ptr, std_t_sint); |
| 5120 | break; |
| 5121 | case STD_T_UINT: |
| 5122 | data = stktable_data_cast(ptr, std_t_uint); |
| 5123 | break; |
| 5124 | case STD_T_ULL: |
| 5125 | data = stktable_data_cast(ptr, std_t_ull); |
| 5126 | break; |
| 5127 | case STD_T_FRQP: |
| 5128 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5129 | ctx->t->data_arg[dt].u); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5130 | break; |
| 5131 | } |
| 5132 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5133 | op = ctx->data_op[i]; |
| 5134 | value = ctx->value[i]; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5135 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5136 | /* skip the entry if the data does not match the test and the value */ |
| 5137 | if ((data < value && |
| 5138 | (op == STD_OP_EQ || op == STD_OP_GT || op == STD_OP_GE)) || |
| 5139 | (data == value && |
| 5140 | (op == STD_OP_NE || op == STD_OP_GT || op == STD_OP_LT)) || |
| 5141 | (data > value && |
| 5142 | (op == STD_OP_EQ || op == STD_OP_LT || op == STD_OP_LE))) { |
| 5143 | skip_entry = 1; |
| 5144 | break; |
| 5145 | } |
| 5146 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | if (show && !skip_entry && |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5150 | !table_dump_entry_to_buffer(&trash, appctx, ctx->t, ctx->entry)) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5151 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5152 | return 0; |
| 5153 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5154 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5155 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5156 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5157 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5158 | ctx->entry->ref_cnt--; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5159 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5160 | eb = ebmb_next(&ctx->entry->key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5161 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5162 | struct stksess *old = ctx->entry; |
| 5163 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5164 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5165 | __stksess_kill_if_expired(ctx->t, old); |
| 5166 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5167 | __stksess_kill(ctx->t, old); |
| 5168 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5169 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5170 | break; |
| 5171 | } |
| 5172 | |
| 5173 | |
| 5174 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5175 | __stksess_kill_if_expired(ctx->t, ctx->entry); |
| 5176 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5177 | __stksess_kill(ctx->t, ctx->entry); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5178 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5179 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5180 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5181 | ctx->t = ctx->t->next; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5182 | ctx->state = STATE_NEXT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5183 | break; |
| 5184 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5185 | default: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5186 | break; |
| 5187 | } |
| 5188 | } |
| 5189 | return 1; |
| 5190 | } |
| 5191 | |
| 5192 | static void cli_release_show_table(struct appctx *appctx) |
| 5193 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5194 | struct show_table_ctx *ctx = appctx->svcctx; |
| 5195 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5196 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5197 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5198 | } |
| 5199 | } |
| 5200 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5201 | static int stk_parse_stick_counters(char **args, int section_type, struct proxy *curpx, |
| 5202 | const struct proxy *defpx, const char *file, int line, |
| 5203 | char **err) |
| 5204 | { |
| 5205 | char *error; |
| 5206 | int counters; |
| 5207 | |
| 5208 | counters = strtol(args[1], &error, 10); |
| 5209 | if (*error != 0) { |
| 5210 | memprintf(err, "%s: '%s' is an invalid number", args[0], args[1]); |
| 5211 | return -1; |
| 5212 | } |
| 5213 | |
| 5214 | if (counters < 0) { |
| 5215 | memprintf(err, "%s: the number of stick-counters may not be negative (was %d)", args[0], counters); |
| 5216 | return -1; |
| 5217 | } |
| 5218 | |
| 5219 | global.tune.nb_stk_ctr = counters; |
| 5220 | return 0; |
| 5221 | } |
| 5222 | |
| 5223 | /* This function creates the stk_ctr pools after the configuration parsing. It |
| 5224 | * returns 0 on success otherwise ERR_*. If nb_stk_ctr is 0, the pool remains |
| 5225 | * NULL. |
| 5226 | */ |
| 5227 | static int stkt_create_stk_ctr_pool(void) |
| 5228 | { |
| 5229 | if (!global.tune.nb_stk_ctr) |
| 5230 | return 0; |
| 5231 | |
| 5232 | pool_head_stk_ctr = create_pool("stk_ctr", sizeof(*((struct session*)0)->stkctr) * global.tune.nb_stk_ctr, MEM_F_SHARED); |
| 5233 | if (!pool_head_stk_ctr) { |
| 5234 | ha_alert("out of memory while creating the stick-counters pool.\n"); |
| 5235 | return ERR_ABORT; |
| 5236 | } |
| 5237 | return 0; |
| 5238 | } |
| 5239 | |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5240 | static void stkt_late_init(void) |
| 5241 | { |
| 5242 | struct sample_fetch *f; |
| 5243 | |
| 5244 | f = find_sample_fetch("src", strlen("src")); |
| 5245 | if (f) |
| 5246 | smp_fetch_src = f->process; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5247 | hap_register_post_check(stkt_create_stk_ctr_pool); |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | INITCALL0(STG_INIT, stkt_late_init); |
| 5251 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5252 | /* register cli keywords */ |
| 5253 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5254 | { { "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 }, |
| 5255 | { { "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 }, |
| 5256 | { { "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] | 5257 | {{},} |
| 5258 | }}; |
| 5259 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5260 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5261 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5262 | static struct action_kw_list tcp_conn_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5263 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5264 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5265 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5266 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5267 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5268 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5269 | { /* END */ } |
| 5270 | }}; |
| 5271 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5272 | INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws); |
| 5273 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5274 | static struct action_kw_list tcp_sess_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5275 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5276 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5277 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5278 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5279 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5280 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5281 | { /* END */ } |
| 5282 | }}; |
| 5283 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5284 | INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws); |
| 5285 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5286 | static struct action_kw_list tcp_req_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5287 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5288 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5289 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5290 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5291 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5292 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5293 | { /* END */ } |
| 5294 | }}; |
| 5295 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5296 | INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_kws); |
| 5297 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5298 | static struct action_kw_list tcp_res_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5299 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5300 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5301 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5302 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5303 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5304 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5305 | { /* END */ } |
| 5306 | }}; |
| 5307 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5308 | INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws); |
| 5309 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5310 | static struct action_kw_list http_req_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5311 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5312 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5313 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5314 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5315 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5316 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5317 | { /* END */ } |
| 5318 | }}; |
| 5319 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5320 | INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws); |
| 5321 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5322 | static struct action_kw_list http_res_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5323 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5324 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5325 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5326 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5327 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5328 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5329 | { /* END */ } |
| 5330 | }}; |
| 5331 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5332 | INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws); |
| 5333 | |
Christopher Faulet | a924804 | 2023-01-05 11:17:38 +0100 | [diff] [blame] | 5334 | static struct action_kw_list http_after_res_kws = { { }, { |
Aurelien DARRAGON | e2907c7 | 2023-03-17 11:28:58 +0100 | [diff] [blame] | 5335 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Christopher Faulet | a924804 | 2023-01-05 11:17:38 +0100 | [diff] [blame] | 5336 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5337 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5338 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5339 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5340 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5341 | { /* END */ } |
| 5342 | }}; |
| 5343 | |
| 5344 | INITCALL1(STG_REGISTER, http_after_res_keywords_register, &http_after_res_kws); |
| 5345 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5346 | /* Note: must not be declared <const> as its list will be overwritten. |
| 5347 | * Please take care of keeping this list alphabetically sorted. |
| 5348 | */ |
| 5349 | static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 5350 | { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5351 | { "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] | 5352 | { "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] | 5353 | { "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] | 5354 | { "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] | 5355 | { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5356 | { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5357 | { "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] | 5358 | { "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] | 5359 | { "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] | 5360 | { "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] | 5361 | { "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] | 5362 | { "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] | 5363 | { "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] | 5364 | { "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] | 5365 | { "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] | 5366 | { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5367 | { "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] | 5368 | { "sc_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5369 | { "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] | 5370 | { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5371 | { "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] | 5372 | { "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] | 5373 | { "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] | 5374 | { "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] | 5375 | { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5376 | { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5377 | { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5378 | { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5379 | { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5380 | { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5381 | { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5382 | { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5383 | { "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] | 5384 | { "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] | 5385 | { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5386 | { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5387 | { "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] | 5388 | { "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] | 5389 | { "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] | 5390 | { "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] | 5391 | { "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] | 5392 | { "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] | 5393 | { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5394 | { "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] | 5395 | { "sc0_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5396 | { "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] | 5397 | { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5398 | { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5399 | { "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] | 5400 | { "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] | 5401 | { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5402 | { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5403 | { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5404 | { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5405 | { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5406 | { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5407 | { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5408 | { "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] | 5409 | { "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] | 5410 | { "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] | 5411 | { "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] | 5412 | { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5413 | { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5414 | { "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] | 5415 | { "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] | 5416 | { "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] | 5417 | { "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] | 5418 | { "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] | 5419 | { "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] | 5420 | { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5421 | { "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] | 5422 | { "sc1_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5423 | { "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] | 5424 | { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5425 | { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5426 | { "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] | 5427 | { "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] | 5428 | { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5429 | { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5430 | { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5431 | { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5432 | { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5433 | { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5434 | { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5435 | { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5436 | { "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] | 5437 | { "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] | 5438 | { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5439 | { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5440 | { "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] | 5441 | { "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] | 5442 | { "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] | 5443 | { "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] | 5444 | { "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] | 5445 | { "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] | 5446 | { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5447 | { "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] | 5448 | { "sc2_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5449 | { "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] | 5450 | { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5451 | { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5452 | { "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] | 5453 | { "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] | 5454 | { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5455 | { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5456 | { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5457 | { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5458 | { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5459 | { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5460 | { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5461 | { "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] | 5462 | { "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] | 5463 | { "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] | 5464 | { "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] | 5465 | { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5466 | { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5467 | { "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] | 5468 | { "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] | 5469 | { "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] | 5470 | { "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] | 5471 | { "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] | 5472 | { "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] | 5473 | { "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] | 5474 | { "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] | 5475 | { "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] | 5476 | { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5477 | { "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] | 5478 | { "src_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5479 | { "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] | 5480 | { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5481 | { "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] | 5482 | { "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] | 5483 | { "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] | 5484 | { "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] | 5485 | { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5486 | { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5487 | { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5488 | { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5489 | { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5490 | { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5491 | { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5492 | { /* END */ }, |
| 5493 | }}; |
| 5494 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5495 | INITCALL1(STG_REGISTER, sample_register_fetches, &smp_fetch_keywords); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5496 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 5497 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 5498 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5499 | { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL }, |
| 5500 | { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5501 | { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5502 | { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5503 | { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5504 | { "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] | 5505 | { "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] | 5506 | { "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] | 5507 | { "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] | 5508 | { "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] | 5509 | { "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] | 5510 | { "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] | 5511 | { "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] | 5512 | { "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] | 5513 | { "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] | 5514 | { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5515 | { "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] | 5516 | { "table_http_fail_cnt", sample_conv_table_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5517 | { "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] | 5518 | { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5519 | { "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] | 5520 | { "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] | 5521 | { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5522 | { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5523 | { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5524 | { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5525 | { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5526 | { "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] | 5527 | { /* END */ }, |
| 5528 | }}; |
| 5529 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5530 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5531 | |
| 5532 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 5533 | { CFG_GLOBAL, "tune.stick-counters", stk_parse_stick_counters }, |
| 5534 | { /* END */ } |
| 5535 | }}; |
| 5536 | |
| 5537 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |