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 | |
Aurelien DARRAGON | 6ce5cd0 | 2023-11-16 16:17:12 +0100 | [diff] [blame] | 775 | /* Performs stick table cleanup: it's meant to be called after the table |
| 776 | * has been initialized ith stktable_init(), else it will lead to undefined |
| 777 | * behavior. |
| 778 | * |
| 779 | * However it does not free the table pointer itself |
| 780 | */ |
| 781 | void stktable_deinit(struct stktable *t) |
| 782 | { |
| 783 | if (!t) |
| 784 | return; |
Aurelien DARRAGON | febaa3e | 2023-11-16 16:18:14 +0100 | [diff] [blame] | 785 | task_destroy(t->exp_task); |
Aurelien DARRAGON | 6ce5cd0 | 2023-11-16 16:17:12 +0100 | [diff] [blame] | 786 | pool_destroy(t->pool); |
| 787 | } |
| 788 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 789 | /* |
| 790 | * Configuration keywords of known table types |
| 791 | */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 792 | struct stktable_type stktable_types[SMP_TYPES] = { |
| 793 | [SMP_T_SINT] = { "integer", 0, 4 }, |
| 794 | [SMP_T_IPV4] = { "ip", 0, 4 }, |
| 795 | [SMP_T_IPV6] = { "ipv6", 0, 16 }, |
| 796 | [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 }, |
| 797 | [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 } |
| 798 | }; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 799 | |
| 800 | /* |
| 801 | * Parse table type configuration. |
| 802 | * Returns 0 on successful parsing, else 1. |
| 803 | * <myidx> is set at next configuration <args> index. |
| 804 | */ |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 805 | 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] | 806 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 807 | for (*type = 0; *type < SMP_TYPES; (*type)++) { |
| 808 | if (!stktable_types[*type].kw) |
| 809 | continue; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 810 | if (strcmp(args[*myidx], stktable_types[*type].kw) != 0) |
| 811 | continue; |
| 812 | |
| 813 | *key_size = stktable_types[*type].default_size; |
| 814 | (*myidx)++; |
| 815 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 816 | if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 817 | if (strcmp("len", args[*myidx]) == 0) { |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 818 | char *stop; |
| 819 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 820 | (*myidx)++; |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 821 | *key_size = strtol(args[*myidx], &stop, 10); |
| 822 | if (*stop != '\0' || !*key_size) { |
| 823 | ha_alert("parsing [%s:%d] : 'len' expects a positive integer argument.\n", file, linenum); |
| 824 | return 1; |
| 825 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 826 | if (*type == SMP_T_STR) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 827 | /* null terminated string needs +1 for '\0'. */ |
| 828 | (*key_size)++; |
| 829 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 830 | (*myidx)++; |
| 831 | } |
| 832 | } |
| 833 | return 0; |
| 834 | } |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 835 | 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] | 836 | return 1; |
| 837 | } |
| 838 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 839 | /* reserve some space for data type <type>, there is 2 optionnals |
| 840 | * argument at <sa> and <sa2> to configure this data type and |
| 841 | * they can be NULL if unused for a given type. |
| 842 | * Returns PE_NONE (0) if OK or an error code among : |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 843 | * - PE_ENUM_OOR if <type> does not exist |
| 844 | * - PE_EXIST if <type> is already registered |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 845 | * - PE_ARG_NOT_USE if <sa>/<sa2> was provided but not expected |
| 846 | * - PE_ARG_MISSING if <sa>/<sa2> was expected but not provided |
| 847 | * - 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] | 848 | */ |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 849 | int stktable_alloc_data_type(struct stktable *t, int type, const char *sa, const char *sa2) |
| 850 | |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 851 | { |
| 852 | if (type >= STKTABLE_DATA_TYPES) |
| 853 | return PE_ENUM_OOR; |
| 854 | |
| 855 | if (t->data_ofs[type]) |
| 856 | /* already allocated */ |
| 857 | return PE_EXIST; |
| 858 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 859 | t->data_nbelem[type] = 1; |
| 860 | if (stktable_data_types[type].is_array) { |
| 861 | /* arrays take their element count on first argument */ |
| 862 | if (!sa) |
| 863 | return PE_ARG_MISSING; |
| 864 | t->data_nbelem[type] = atoi(sa); |
| 865 | if (!t->data_nbelem[type] || (t->data_nbelem[type] > STKTABLE_MAX_DT_ARRAY_SIZE)) |
| 866 | return PE_ARG_VALUE_OOR; |
| 867 | sa = sa2; |
| 868 | } |
| 869 | |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 870 | switch (stktable_data_types[type].arg_type) { |
| 871 | case ARG_T_NONE: |
| 872 | if (sa) |
| 873 | return PE_ARG_NOT_USED; |
| 874 | break; |
| 875 | case ARG_T_INT: |
| 876 | if (!sa) |
| 877 | return PE_ARG_MISSING; |
| 878 | t->data_arg[type].i = atoi(sa); |
| 879 | break; |
| 880 | case ARG_T_DELAY: |
| 881 | if (!sa) |
| 882 | return PE_ARG_MISSING; |
| 883 | sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS); |
| 884 | if (sa) |
| 885 | return PE_ARG_INVC; /* invalid char */ |
| 886 | break; |
| 887 | } |
| 888 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 889 | 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] | 890 | t->data_ofs[type] = -t->data_size; |
| 891 | return PE_NONE; |
| 892 | } |
| 893 | |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 894 | /* |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 895 | * Parse a line with <linenum> as number in <file> configuration file to configure |
| 896 | * the stick-table with <t> as address and <id> as ID. |
| 897 | * <peers> provides the "peers" section pointer only if this function is called |
| 898 | * from a "peers" section. |
| 899 | * <nid> is the stick-table name which is sent over the network. It must be equal |
| 900 | * to <id> if this stick-table is parsed from a proxy section, and prefixed by <peers> |
| 901 | * "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] | 902 | * 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] | 903 | * Return an error status with ERR_* flags set if required, 0 if no error was encountered. |
| 904 | */ |
| 905 | 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] | 906 | 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] | 907 | { |
| 908 | int err_code = 0; |
| 909 | int idx = 1; |
| 910 | unsigned int val; |
| 911 | |
| 912 | if (!id || !*id) { |
| 913 | ha_alert("parsing [%s:%d] : %s: ID not provided.\n", file, linenum, args[0]); |
| 914 | err_code |= ERR_ALERT | ERR_ABORT; |
| 915 | goto out; |
| 916 | } |
| 917 | |
| 918 | /* Store the "peers" section if this function is called from a "peers" section. */ |
| 919 | if (peers) { |
| 920 | t->peers.p = peers; |
| 921 | idx++; |
| 922 | } |
| 923 | |
| 924 | t->id = id; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 925 | t->idlen = strlen(id); |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 926 | t->nid = nid; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 927 | t->type = (unsigned int)-1; |
| 928 | t->conf.file = file; |
| 929 | t->conf.line = linenum; |
| 930 | |
| 931 | while (*args[idx]) { |
| 932 | const char *err; |
| 933 | |
| 934 | if (strcmp(args[idx], "size") == 0) { |
| 935 | idx++; |
| 936 | if (!*(args[idx])) { |
| 937 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 938 | file, linenum, args[0], args[idx-1]); |
| 939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 940 | goto out; |
| 941 | } |
| 942 | if ((err = parse_size_err(args[idx], &t->size))) { |
| 943 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 944 | file, linenum, args[0], *err, args[idx-1]); |
| 945 | err_code |= ERR_ALERT | ERR_FATAL; |
| 946 | goto out; |
| 947 | } |
| 948 | idx++; |
| 949 | } |
| 950 | /* This argument does not exit in "peers" section. */ |
| 951 | else if (!peers && strcmp(args[idx], "peers") == 0) { |
| 952 | idx++; |
| 953 | if (!*(args[idx])) { |
| 954 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 955 | file, linenum, args[0], args[idx-1]); |
| 956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 957 | goto out; |
| 958 | } |
Aurelien DARRAGON | 0509b1e | 2023-11-02 09:18:55 +0100 | [diff] [blame] | 959 | ha_free(&t->peers.name); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 960 | t->peers.name = strdup(args[idx++]); |
| 961 | } |
| 962 | else if (strcmp(args[idx], "expire") == 0) { |
| 963 | idx++; |
| 964 | if (!*(args[idx])) { |
| 965 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 966 | file, linenum, args[0], args[idx-1]); |
| 967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 968 | goto out; |
| 969 | } |
| 970 | err = parse_time_err(args[idx], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 971 | if (err == PARSE_TIME_OVER) { |
| 972 | ha_alert("parsing [%s:%d]: %s: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 973 | file, linenum, args[0], args[idx], args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 975 | goto out; |
| 976 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 977 | else if (err == PARSE_TIME_UNDER) { |
| 978 | ha_alert("parsing [%s:%d]: %s: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 979 | file, linenum, args[0], args[idx], args[idx-1]); |
| 980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 981 | goto out; |
| 982 | } |
| 983 | else if (err) { |
| 984 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 985 | file, linenum, args[0], *err, args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 987 | goto out; |
| 988 | } |
| 989 | t->expire = val; |
| 990 | idx++; |
| 991 | } |
| 992 | else if (strcmp(args[idx], "nopurge") == 0) { |
| 993 | t->nopurge = 1; |
| 994 | idx++; |
| 995 | } |
| 996 | else if (strcmp(args[idx], "type") == 0) { |
| 997 | idx++; |
William Lallemand | 3f21097 | 2023-04-13 14:33:52 +0200 | [diff] [blame] | 998 | 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] | 999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | /* idx already points to next arg */ |
| 1003 | } |
| 1004 | else if (strcmp(args[idx], "store") == 0) { |
| 1005 | int type, err; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1006 | char *cw, *nw, *sa, *sa2; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1007 | |
| 1008 | idx++; |
| 1009 | nw = args[idx]; |
| 1010 | while (*nw) { |
| 1011 | /* the "store" keyword supports a comma-separated list */ |
| 1012 | cw = nw; |
| 1013 | sa = NULL; /* store arg */ |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1014 | sa2 = NULL; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1015 | while (*nw && *nw != ',') { |
| 1016 | if (*nw == '(') { |
| 1017 | *nw = 0; |
| 1018 | sa = ++nw; |
| 1019 | while (*nw != ')') { |
| 1020 | if (!*nw) { |
| 1021 | ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 1022 | file, linenum, args[0], cw); |
| 1023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1024 | goto out; |
| 1025 | } |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1026 | if (*nw == ',') { |
| 1027 | *nw = '\0'; |
| 1028 | sa2 = nw + 1; |
| 1029 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1030 | nw++; |
| 1031 | } |
| 1032 | *nw = '\0'; |
| 1033 | } |
| 1034 | nw++; |
| 1035 | } |
| 1036 | if (*nw) |
| 1037 | *nw++ = '\0'; |
| 1038 | type = stktable_get_data_type(cw); |
| 1039 | if (type < 0) { |
| 1040 | ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 1041 | file, linenum, args[0], cw); |
| 1042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1043 | goto out; |
| 1044 | } |
| 1045 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1046 | err = stktable_alloc_data_type(t, type, sa, sa2); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1047 | switch (err) { |
| 1048 | case PE_NONE: break; |
| 1049 | case PE_EXIST: |
| 1050 | ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 1051 | file, linenum, args[0], cw); |
| 1052 | err_code |= ERR_WARN; |
| 1053 | break; |
| 1054 | |
| 1055 | case PE_ARG_MISSING: |
| 1056 | ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 1057 | file, linenum, args[0], cw); |
| 1058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1059 | goto out; |
| 1060 | |
| 1061 | case PE_ARG_NOT_USED: |
| 1062 | ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 1063 | file, linenum, args[0], cw); |
| 1064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1065 | goto out; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1066 | case PE_ARG_VALUE_OOR: |
| 1067 | ha_alert("parsing [%s:%d] : %s: array size is out of allowed range (1-%d) for store option '%s'.\n", |
| 1068 | file, linenum, args[0], STKTABLE_MAX_DT_ARRAY_SIZE, cw); |
| 1069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1070 | goto out; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1071 | |
| 1072 | default: |
| 1073 | ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 1074 | file, linenum, args[0], cw); |
| 1075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1076 | goto out; |
| 1077 | } |
| 1078 | } |
| 1079 | idx++; |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 1080 | if (t->data_ofs[STKTABLE_DT_GPT] && t->data_ofs[STKTABLE_DT_GPT0]) { |
| 1081 | ha_alert("parsing [%s:%d] : %s: simultaneous usage of 'gpt' and 'gpt0' in a same table is not permitted as 'gpt' overrides 'gpt0'.\n", |
| 1082 | file, linenum, args[0]); |
| 1083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1084 | goto out; |
| 1085 | } |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1086 | else if (t->data_ofs[STKTABLE_DT_GPC] && (t->data_ofs[STKTABLE_DT_GPC0] || t->data_ofs[STKTABLE_DT_GPC1])) { |
| 1087 | 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", |
| 1088 | file, linenum, args[0]); |
| 1089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1090 | goto out; |
| 1091 | } |
| 1092 | else if (t->data_ofs[STKTABLE_DT_GPC_RATE] && (t->data_ofs[STKTABLE_DT_GPC0_RATE] || t->data_ofs[STKTABLE_DT_GPC1_RATE])) { |
| 1093 | 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", |
| 1094 | file, linenum, args[0]); |
| 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1096 | goto out; |
| 1097 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1098 | } |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 1099 | else if (strcmp(args[idx], "srvkey") == 0) { |
| 1100 | char *keytype; |
| 1101 | idx++; |
| 1102 | keytype = args[idx]; |
| 1103 | if (strcmp(keytype, "name") == 0) { |
| 1104 | t->server_key_type = STKTABLE_SRV_NAME; |
| 1105 | } |
| 1106 | else if (strcmp(keytype, "addr") == 0) { |
| 1107 | t->server_key_type = STKTABLE_SRV_ADDR; |
| 1108 | } |
| 1109 | else { |
| 1110 | ha_alert("parsing [%s:%d] : %s : unknown server key type '%s'.\n", |
| 1111 | file, linenum, args[0], keytype); |
| 1112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1113 | goto out; |
| 1114 | |
| 1115 | } |
| 1116 | idx++; |
| 1117 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1118 | else { |
| 1119 | ha_alert("parsing [%s:%d] : %s: unknown argument '%s'.\n", |
| 1120 | file, linenum, args[0], args[idx]); |
| 1121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1122 | goto out; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | if (!t->size) { |
| 1127 | ha_alert("parsing [%s:%d] : %s: missing size.\n", |
| 1128 | file, linenum, args[0]); |
| 1129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1130 | goto out; |
| 1131 | } |
| 1132 | |
| 1133 | if (t->type == (unsigned int)-1) { |
| 1134 | ha_alert("parsing [%s:%d] : %s: missing type.\n", |
| 1135 | file, linenum, args[0]); |
| 1136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1137 | goto out; |
| 1138 | } |
| 1139 | |
| 1140 | out: |
| 1141 | return err_code; |
| 1142 | } |
| 1143 | |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1144 | /* 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] | 1145 | * Note that the sample *is* modified and that the returned key may point |
| 1146 | * 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] | 1147 | * Returns NULL if the sample could not be converted (eg: no matching type), |
| 1148 | * otherwise a pointer to the static stktable_key filled with what is needed |
| 1149 | * for the lookup. |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1150 | */ |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1151 | struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1152 | { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1153 | /* Convert sample. */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1154 | if (!sample_convert(smp, t->type)) |
Willy Tarreau | 7fc1c6e | 2012-04-26 11:03:17 +0200 | [diff] [blame] | 1155 | return NULL; |
| 1156 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1157 | /* Fill static_table_key. */ |
| 1158 | switch (t->type) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1159 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1160 | case SMP_T_IPV4: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1161 | static_table_key.key = &smp->data.u.ipv4; |
| 1162 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1163 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1164 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1165 | case SMP_T_IPV6: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1166 | static_table_key.key = &smp->data.u.ipv6; |
| 1167 | static_table_key.key_len = 16; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1168 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1169 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1170 | case SMP_T_SINT: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1171 | /* The stick table require a 32bit unsigned int, "sint" is a |
| 1172 | * signed 64 it, so we can convert it inplace. |
| 1173 | */ |
Willy Tarreau | 28c63c1 | 2019-10-23 06:21:05 +0200 | [diff] [blame] | 1174 | smp->data.u.sint = (unsigned int)smp->data.u.sint; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1175 | static_table_key.key = &smp->data.u.sint; |
| 1176 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1177 | break; |
| 1178 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1179 | case SMP_T_STR: |
Willy Tarreau | ce6955e | 2016-08-09 11:59:12 +0200 | [diff] [blame] | 1180 | if (!smp_make_safe(smp)) |
| 1181 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1182 | static_table_key.key = smp->data.u.str.area; |
| 1183 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1184 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1185 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1186 | case SMP_T_BIN: |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1187 | if (smp->data.u.str.data < t->key_size) { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1188 | /* This type needs padding with 0. */ |
Willy Tarreau | f65c6c0 | 2016-08-09 12:08:41 +0200 | [diff] [blame] | 1189 | if (!smp_make_rw(smp)) |
| 1190 | return NULL; |
| 1191 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1192 | if (smp->data.u.str.size < t->key_size) |
| 1193 | if (!smp_dup(smp)) |
| 1194 | return NULL; |
| 1195 | if (smp->data.u.str.size < t->key_size) |
| 1196 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1197 | memset(smp->data.u.str.area + smp->data.u.str.data, 0, |
| 1198 | t->key_size - smp->data.u.str.data); |
| 1199 | smp->data.u.str.data = t->key_size; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1200 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1201 | static_table_key.key = smp->data.u.str.area; |
| 1202 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1203 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1204 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1205 | default: /* impossible case. */ |
| 1206 | return NULL; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1207 | } |
| 1208 | |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1209 | return &static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | /* |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1213 | * Process a fetch + format conversion as defined by the sample expression <expr> |
| 1214 | * on request or response considering the <opt> parameter. Returns either NULL if |
| 1215 | * no key could be extracted, or a pointer to the converted result stored in |
| 1216 | * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset |
| 1217 | * 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] | 1218 | * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present |
| 1219 | * without SMP_OPT_FINAL). The output will be usable like this : |
| 1220 | * |
| 1221 | * return MAY_CHANGE FINAL Meaning for the sample |
| 1222 | * NULL 0 * Not present and will never be (eg: header) |
| 1223 | * NULL 1 0 Not present or unstable, could change (eg: req_len) |
| 1224 | * NULL 1 1 Not present, will not change anymore |
| 1225 | * smp 0 * Present and will not change (eg: header) |
| 1226 | * smp 1 0 not possible |
| 1227 | * smp 1 1 Present, last known value (eg: request length) |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1228 | */ |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1229 | 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] | 1230 | unsigned int opt, struct sample_expr *expr, struct sample *smp) |
| 1231 | { |
| 1232 | if (smp) |
| 1233 | memset(smp, 0, sizeof(*smp)); |
| 1234 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1235 | smp = sample_process(px, sess, strm, opt, expr, smp); |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1236 | if (!smp) |
| 1237 | return NULL; |
| 1238 | |
| 1239 | if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
| 1240 | return NULL; /* we can only use stable samples */ |
| 1241 | |
| 1242 | return smp_to_stkey(smp, t); |
| 1243 | } |
| 1244 | |
| 1245 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1246 | * 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] | 1247 | * type <table_type>, otherwise zero. Used in configuration check. |
| 1248 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1249 | int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1250 | { |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1251 | int out_type; |
| 1252 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1253 | if (table_type >= SMP_TYPES || !stktable_types[table_type].kw) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1254 | return 0; |
| 1255 | |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1256 | out_type = smp_expr_output_type(expr); |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1257 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1258 | /* Convert sample. */ |
| 1259 | if (!sample_casts[out_type][table_type]) |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1260 | return 0; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1261 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1262 | return 1; |
| 1263 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 1264 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1265 | /* Extra data types processing : after the last one, some room may remain |
| 1266 | * before STKTABLE_DATA_TYPES that may be used to register extra data types |
| 1267 | * at run time. |
| 1268 | */ |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1269 | struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = { |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1270 | [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT }, |
Thierry FOURNIER | 3cf1111 | 2015-07-28 08:57:05 +0200 | [diff] [blame] | 1271 | [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1272 | [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT }, |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 1273 | [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] | 1274 | [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT }, |
| 1275 | [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] | 1276 | [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] | 1277 | [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT }, |
| 1278 | [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1279 | [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT }, |
| 1280 | [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1281 | [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT }, |
| 1282 | [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1283 | [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL }, |
| 1284 | [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1285 | [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL }, |
| 1286 | [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] | 1287 | [STKTABLE_DT_GPC1] = { .name = "gpc1", .std_type = STD_T_UINT }, |
| 1288 | [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] | 1289 | [STKTABLE_DT_SERVER_KEY] = { .name = "server_key", .std_type = STD_T_DICT }, |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 1290 | [STKTABLE_DT_HTTP_FAIL_CNT] = { .name = "http_fail_cnt", .std_type = STD_T_UINT }, |
| 1291 | [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] | 1292 | [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] | 1293 | [STKTABLE_DT_GPC] = { .name = "gpc", .std_type = STD_T_UINT, .is_array = 1 }, |
| 1294 | [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] | 1295 | }; |
| 1296 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1297 | /* Registers stick-table extra data type with index <idx>, name <name>, type |
| 1298 | * <std_type> and arg type <arg_type>. If the index is negative, the next free |
| 1299 | * index is automatically allocated. The allocated index is returned, or -1 if |
| 1300 | * no free index was found or <name> was already registered. The <name> is used |
| 1301 | * directly as a pointer, so if it's not stable, the caller must allocate it. |
| 1302 | */ |
| 1303 | int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type) |
| 1304 | { |
| 1305 | if (idx < 0) { |
| 1306 | for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) { |
| 1307 | if (!stktable_data_types[idx].name) |
| 1308 | break; |
| 1309 | |
| 1310 | if (strcmp(stktable_data_types[idx].name, name) == 0) |
| 1311 | return -1; |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | if (idx >= STKTABLE_DATA_TYPES) |
| 1316 | return -1; |
| 1317 | |
| 1318 | if (stktable_data_types[idx].name != NULL) |
| 1319 | return -1; |
| 1320 | |
| 1321 | stktable_data_types[idx].name = name; |
| 1322 | stktable_data_types[idx].std_type = std_type; |
| 1323 | stktable_data_types[idx].arg_type = arg_type; |
| 1324 | return idx; |
| 1325 | } |
| 1326 | |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1327 | /* |
| 1328 | * Returns the data type number for the stktable_data_type whose name is <name>, |
| 1329 | * or <0 if not found. |
| 1330 | */ |
| 1331 | int stktable_get_data_type(char *name) |
| 1332 | { |
| 1333 | int type; |
| 1334 | |
| 1335 | for (type = 0; type < STKTABLE_DATA_TYPES; type++) { |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1336 | if (!stktable_data_types[type].name) |
| 1337 | continue; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1338 | if (strcmp(name, stktable_data_types[type].name) == 0) |
| 1339 | return type; |
| 1340 | } |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 1341 | /* For backwards compatibility */ |
| 1342 | if (strcmp(name, "server_name") == 0) |
| 1343 | return STKTABLE_DT_SERVER_KEY; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1344 | return -1; |
| 1345 | } |
| 1346 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1347 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1348 | * it up into this table. Returns true if found, false otherwise. The input |
| 1349 | * type is STR so that input samples are converted to string (since all types |
| 1350 | * can be converted to strings), then the function casts the string again into |
| 1351 | * the table's type. This is a double conversion, but in the future we might |
| 1352 | * support automatic input types to perform the cast on the fly. |
| 1353 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1354 | 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] | 1355 | { |
| 1356 | struct stktable *t; |
| 1357 | struct stktable_key *key; |
| 1358 | struct stksess *ts; |
| 1359 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1360 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1361 | |
| 1362 | key = smp_to_stkey(smp, t); |
| 1363 | if (!key) |
| 1364 | return 0; |
| 1365 | |
| 1366 | ts = stktable_lookup_key(t, key); |
| 1367 | |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1368 | smp->data.type = SMP_T_BOOL; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1369 | smp->data.u.sint = !!ts; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1370 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 1371 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1372 | return 1; |
| 1373 | } |
| 1374 | |
| 1375 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1376 | * it up into this table. Returns the data rate received from clients in bytes/s |
| 1377 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1378 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1379 | * <not found> is returned. |
| 1380 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1381 | 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] | 1382 | { |
| 1383 | struct stktable *t; |
| 1384 | struct stktable_key *key; |
| 1385 | struct stksess *ts; |
| 1386 | void *ptr; |
| 1387 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1388 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1389 | |
| 1390 | key = smp_to_stkey(smp, t); |
| 1391 | if (!key) |
| 1392 | return 0; |
| 1393 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1394 | ts = stktable_lookup_key(t, key); |
| 1395 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1396 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1397 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1398 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1399 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1400 | if (!ts) /* key not present */ |
| 1401 | return 1; |
| 1402 | |
| 1403 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1404 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1405 | 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] | 1406 | t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1407 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1408 | stktable_release(t, ts); |
| 1409 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1413 | * it up into this table. Returns the cumulated number of connections for the key |
| 1414 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1415 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1416 | * <not found> is returned. |
| 1417 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1418 | 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] | 1419 | { |
| 1420 | struct stktable *t; |
| 1421 | struct stktable_key *key; |
| 1422 | struct stksess *ts; |
| 1423 | void *ptr; |
| 1424 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1425 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1426 | |
| 1427 | key = smp_to_stkey(smp, t); |
| 1428 | if (!key) |
| 1429 | return 0; |
| 1430 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1431 | ts = stktable_lookup_key(t, key); |
| 1432 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1433 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1434 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1435 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1436 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1437 | if (!ts) /* key not present */ |
| 1438 | return 1; |
| 1439 | |
| 1440 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1441 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1442 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1443 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1444 | stktable_release(t, ts); |
| 1445 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1449 | * it up into this table. Returns the number of concurrent connections for the |
| 1450 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1451 | * can be easily performed. If the inspected parameter is not stored in the |
| 1452 | * table, <not found> is returned. |
| 1453 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1454 | 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] | 1455 | { |
| 1456 | struct stktable *t; |
| 1457 | struct stktable_key *key; |
| 1458 | struct stksess *ts; |
| 1459 | void *ptr; |
| 1460 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1461 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1462 | |
| 1463 | key = smp_to_stkey(smp, t); |
| 1464 | if (!key) |
| 1465 | return 0; |
| 1466 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1467 | ts = stktable_lookup_key(t, key); |
| 1468 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1469 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1470 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1471 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1472 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1473 | if (!ts) /* key not present */ |
| 1474 | return 1; |
| 1475 | |
| 1476 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1477 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1478 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1479 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1480 | stktable_release(t, ts); |
| 1481 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1485 | * it up into this table. Returns the rate of incoming connections from the key |
| 1486 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1487 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1488 | * <not found> is returned. |
| 1489 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1490 | 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] | 1491 | { |
| 1492 | struct stktable *t; |
| 1493 | struct stktable_key *key; |
| 1494 | struct stksess *ts; |
| 1495 | void *ptr; |
| 1496 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1497 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1498 | |
| 1499 | key = smp_to_stkey(smp, t); |
| 1500 | if (!key) |
| 1501 | return 0; |
| 1502 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1503 | ts = stktable_lookup_key(t, key); |
| 1504 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1505 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1506 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1507 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1508 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1509 | if (!ts) /* key not present */ |
| 1510 | return 1; |
| 1511 | |
| 1512 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1513 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1514 | 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] | 1515 | t->data_arg[STKTABLE_DT_CONN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1516 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1517 | stktable_release(t, ts); |
| 1518 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /* 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] | 1522 | * it up into this table. Returns the expiration delay for the key if the key is |
| 1523 | * present in the table, otherwise the default value provided as second argument |
| 1524 | * if any, if not (no default value), <not found> is returned. |
| 1525 | */ |
| 1526 | static int sample_conv_table_expire(const struct arg *arg_p, struct sample *smp, void *private) |
| 1527 | { |
| 1528 | struct stktable *t; |
| 1529 | struct stktable_key *key; |
| 1530 | struct stksess *ts; |
| 1531 | |
| 1532 | t = arg_p[0].data.t; |
| 1533 | |
| 1534 | key = smp_to_stkey(smp, t); |
| 1535 | if (!key) |
| 1536 | return 0; |
| 1537 | |
| 1538 | ts = stktable_lookup_key(t, key); |
| 1539 | |
| 1540 | smp->flags = SMP_F_VOL_TEST; |
| 1541 | smp->data.type = SMP_T_SINT; |
| 1542 | smp->data.u.sint = 0; |
| 1543 | |
| 1544 | if (!ts) { /* key not present */ |
| 1545 | if (arg_p[1].type == ARGT_STOP) |
| 1546 | return 0; |
| 1547 | |
| 1548 | /* default value */ |
| 1549 | smp->data.u.sint = arg_p[1].data.sint; |
| 1550 | return 1; |
| 1551 | } |
| 1552 | |
| 1553 | smp->data.u.sint = tick_remain(now_ms, ts->expire); |
| 1554 | |
| 1555 | stktable_release(t, ts); |
| 1556 | return 1; |
| 1557 | } |
| 1558 | |
| 1559 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1560 | * it up into this table. Returns the time the key remains unused if the key is |
| 1561 | * present in the table, otherwise the default value provided as second argument |
| 1562 | * if any, if not (no default value), <not found> is returned. |
| 1563 | */ |
| 1564 | static int sample_conv_table_idle(const struct arg *arg_p, struct sample *smp, void *private) |
| 1565 | { |
| 1566 | struct stktable *t; |
| 1567 | struct stktable_key *key; |
| 1568 | struct stksess *ts; |
| 1569 | |
| 1570 | t = arg_p[0].data.t; |
| 1571 | |
| 1572 | key = smp_to_stkey(smp, t); |
| 1573 | if (!key) |
| 1574 | return 0; |
| 1575 | |
| 1576 | ts = stktable_lookup_key(t, key); |
| 1577 | |
| 1578 | smp->flags = SMP_F_VOL_TEST; |
| 1579 | smp->data.type = SMP_T_SINT; |
| 1580 | smp->data.u.sint = 0; |
| 1581 | |
| 1582 | if (!ts) { /* key not present */ |
| 1583 | if (arg_p[1].type == ARGT_STOP) |
| 1584 | return 0; |
| 1585 | |
| 1586 | /* default value */ |
| 1587 | smp->data.u.sint = arg_p[1].data.sint; |
| 1588 | return 1; |
| 1589 | } |
| 1590 | |
| 1591 | smp->data.u.sint = tick_remain(tick_remain(now_ms, ts->expire), t->expire); |
| 1592 | |
| 1593 | stktable_release(t, ts); |
| 1594 | return 1; |
| 1595 | } |
| 1596 | |
| 1597 | /* 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] | 1598 | * it up into this table. Returns the data rate sent to clients in bytes/s |
| 1599 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1600 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1601 | * <not found> is returned. |
| 1602 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1603 | 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] | 1604 | { |
| 1605 | struct stktable *t; |
| 1606 | struct stktable_key *key; |
| 1607 | struct stksess *ts; |
| 1608 | void *ptr; |
| 1609 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1610 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1611 | |
| 1612 | key = smp_to_stkey(smp, t); |
| 1613 | if (!key) |
| 1614 | return 0; |
| 1615 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1616 | ts = stktable_lookup_key(t, key); |
| 1617 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1618 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1619 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1620 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1621 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1622 | if (!ts) /* key not present */ |
| 1623 | return 1; |
| 1624 | |
| 1625 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1626 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1627 | 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] | 1628 | t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1629 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1630 | stktable_release(t, ts); |
| 1631 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1632 | } |
| 1633 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 1634 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1635 | * it up into this table. Returns the value of the GPT[arg_p(0)] tag for the key |
| 1636 | * if the key is present in the table, otherwise false, so that comparisons can |
| 1637 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1638 | * <not found> is returned. |
| 1639 | */ |
| 1640 | static int sample_conv_table_gpt(const struct arg *arg_p, struct sample *smp, void *private) |
| 1641 | { |
| 1642 | struct stktable *t; |
| 1643 | struct stktable_key *key; |
| 1644 | struct stksess *ts; |
| 1645 | void *ptr; |
| 1646 | unsigned int idx; |
| 1647 | |
| 1648 | idx = arg_p[0].data.sint; |
| 1649 | |
| 1650 | t = arg_p[1].data.t; |
| 1651 | |
| 1652 | key = smp_to_stkey(smp, t); |
| 1653 | if (!key) |
| 1654 | return 0; |
| 1655 | |
| 1656 | ts = stktable_lookup_key(t, key); |
| 1657 | |
| 1658 | smp->flags = SMP_F_VOL_TEST; |
| 1659 | smp->data.type = SMP_T_SINT; |
| 1660 | smp->data.u.sint = 0; |
| 1661 | |
| 1662 | if (!ts) /* key not present */ |
| 1663 | return 1; |
| 1664 | |
| 1665 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPT, idx); |
| 1666 | if (ptr) |
| 1667 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 1668 | |
| 1669 | stktable_release(t, ts); |
| 1670 | return !!ptr; |
| 1671 | } |
| 1672 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1673 | /* 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] | 1674 | * it up into this table. Returns the value of the GPT0 tag for the key |
| 1675 | * if the key is present in the table, otherwise false, so that comparisons can |
| 1676 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1677 | * <not found> is returned. |
| 1678 | */ |
| 1679 | static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private) |
| 1680 | { |
| 1681 | struct stktable *t; |
| 1682 | struct stktable_key *key; |
| 1683 | struct stksess *ts; |
| 1684 | void *ptr; |
| 1685 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1686 | t = arg_p[0].data.t; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1687 | |
| 1688 | key = smp_to_stkey(smp, t); |
| 1689 | if (!key) |
| 1690 | return 0; |
| 1691 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1692 | ts = stktable_lookup_key(t, key); |
| 1693 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1694 | smp->flags = SMP_F_VOL_TEST; |
| 1695 | smp->data.type = SMP_T_SINT; |
| 1696 | smp->data.u.sint = 0; |
| 1697 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1698 | if (!ts) /* key not present */ |
| 1699 | return 1; |
| 1700 | |
| 1701 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 1702 | if (!ptr) |
| 1703 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPT, 0); |
| 1704 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1705 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1706 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1707 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1708 | stktable_release(t, ts); |
| 1709 | return !!ptr; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1710 | } |
| 1711 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 1712 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1713 | * it up into this table. Returns the value of the GPC[arg_p(0)] counter for the key |
| 1714 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1715 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1716 | * <not found> is returned. |
| 1717 | */ |
| 1718 | static int sample_conv_table_gpc(const struct arg *arg_p, struct sample *smp, void *private) |
| 1719 | { |
| 1720 | struct stktable *t; |
| 1721 | struct stktable_key *key; |
| 1722 | struct stksess *ts; |
| 1723 | void *ptr; |
| 1724 | unsigned int idx; |
| 1725 | |
| 1726 | idx = arg_p[0].data.sint; |
| 1727 | |
| 1728 | t = arg_p[1].data.t; |
| 1729 | |
| 1730 | key = smp_to_stkey(smp, t); |
| 1731 | if (!key) |
| 1732 | return 0; |
| 1733 | |
| 1734 | ts = stktable_lookup_key(t, key); |
| 1735 | |
| 1736 | smp->flags = SMP_F_VOL_TEST; |
| 1737 | smp->data.type = SMP_T_SINT; |
| 1738 | smp->data.u.sint = 0; |
| 1739 | |
| 1740 | if (!ts) /* key not present */ |
| 1741 | return 1; |
| 1742 | |
| 1743 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, idx); |
| 1744 | if (ptr) |
| 1745 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 1746 | |
| 1747 | stktable_release(t, ts); |
| 1748 | return !!ptr; |
| 1749 | } |
| 1750 | |
| 1751 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1752 | * it up into this table. Returns the event rate of the GPC[arg_p(0)] counter |
| 1753 | * for the key if the key is present in the table, otherwise zero, so that |
| 1754 | * comparisons can be easily performed. If the inspected parameter is not |
| 1755 | * stored in the table, <not found> is returned. |
| 1756 | */ |
| 1757 | static int sample_conv_table_gpc_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 1758 | { |
| 1759 | struct stktable *t; |
| 1760 | struct stktable_key *key; |
| 1761 | struct stksess *ts; |
| 1762 | void *ptr; |
| 1763 | unsigned int idx; |
| 1764 | |
| 1765 | idx = arg_p[0].data.sint; |
| 1766 | |
| 1767 | t = arg_p[1].data.t; |
| 1768 | |
| 1769 | key = smp_to_stkey(smp, t); |
| 1770 | if (!key) |
| 1771 | return 0; |
| 1772 | |
| 1773 | ts = stktable_lookup_key(t, key); |
| 1774 | |
| 1775 | smp->flags = SMP_F_VOL_TEST; |
| 1776 | smp->data.type = SMP_T_SINT; |
| 1777 | smp->data.u.sint = 0; |
| 1778 | |
| 1779 | if (!ts) /* key not present */ |
| 1780 | return 1; |
| 1781 | |
| 1782 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, idx); |
| 1783 | if (ptr) |
| 1784 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1785 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1786 | |
| 1787 | stktable_release(t, ts); |
| 1788 | return !!ptr; |
| 1789 | } |
| 1790 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1791 | /* 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] | 1792 | * it up into this table. Returns the value of the GPC0 counter for the key |
| 1793 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1794 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1795 | * <not found> is returned. |
| 1796 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1797 | 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] | 1798 | { |
| 1799 | struct stktable *t; |
| 1800 | struct stktable_key *key; |
| 1801 | struct stksess *ts; |
| 1802 | void *ptr; |
| 1803 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1804 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1805 | |
| 1806 | key = smp_to_stkey(smp, t); |
| 1807 | if (!key) |
| 1808 | return 0; |
| 1809 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1810 | ts = stktable_lookup_key(t, key); |
| 1811 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1812 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1813 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1814 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1815 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1816 | if (!ts) /* key not present */ |
| 1817 | return 1; |
| 1818 | |
| 1819 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1820 | if (!ptr) { |
| 1821 | /* fallback on the gpc array */ |
| 1822 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, 0); |
| 1823 | } |
| 1824 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1825 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1826 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1827 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1828 | stktable_release(t, ts); |
| 1829 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1833 | * it up into this table. Returns the event rate of the GPC0 counter for the key |
| 1834 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1835 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1836 | * <not found> is returned. |
| 1837 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1838 | 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] | 1839 | { |
| 1840 | struct stktable *t; |
| 1841 | struct stktable_key *key; |
| 1842 | struct stksess *ts; |
| 1843 | void *ptr; |
| 1844 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1845 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1846 | |
| 1847 | key = smp_to_stkey(smp, t); |
| 1848 | if (!key) |
| 1849 | return 0; |
| 1850 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1851 | ts = stktable_lookup_key(t, key); |
| 1852 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1853 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1854 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1855 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1856 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1857 | if (!ts) /* key not present */ |
| 1858 | return 1; |
| 1859 | |
| 1860 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1861 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1862 | 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] | 1863 | t->data_arg[STKTABLE_DT_GPC0_RATE].u); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1864 | else { |
| 1865 | /* fallback on the gpc array */ |
| 1866 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, 0); |
| 1867 | if (ptr) |
| 1868 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1869 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1870 | } |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1871 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1872 | stktable_release(t, ts); |
| 1873 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | /* 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] | 1877 | * it up into this table. Returns the value of the GPC1 counter for the key |
| 1878 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1879 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1880 | * <not found> is returned. |
| 1881 | */ |
| 1882 | static int sample_conv_table_gpc1(const struct arg *arg_p, struct sample *smp, void *private) |
| 1883 | { |
| 1884 | struct stktable *t; |
| 1885 | struct stktable_key *key; |
| 1886 | struct stksess *ts; |
| 1887 | void *ptr; |
| 1888 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1889 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1890 | |
| 1891 | key = smp_to_stkey(smp, t); |
| 1892 | if (!key) |
| 1893 | return 0; |
| 1894 | |
| 1895 | ts = stktable_lookup_key(t, key); |
| 1896 | |
| 1897 | smp->flags = SMP_F_VOL_TEST; |
| 1898 | smp->data.type = SMP_T_SINT; |
| 1899 | smp->data.u.sint = 0; |
| 1900 | |
| 1901 | if (!ts) /* key not present */ |
| 1902 | return 1; |
| 1903 | |
| 1904 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1905 | if (!ptr) { |
| 1906 | /* fallback on the gpc array */ |
| 1907 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, 1); |
| 1908 | } |
| 1909 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1910 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1911 | 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] | 1912 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1913 | stktable_release(t, ts); |
| 1914 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1918 | * it up into this table. Returns the event rate of the GPC1 counter for the key |
| 1919 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1920 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1921 | * <not found> is returned. |
| 1922 | */ |
| 1923 | static int sample_conv_table_gpc1_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 1924 | { |
| 1925 | struct stktable *t; |
| 1926 | struct stktable_key *key; |
| 1927 | struct stksess *ts; |
| 1928 | void *ptr; |
| 1929 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1930 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1931 | |
| 1932 | key = smp_to_stkey(smp, t); |
| 1933 | if (!key) |
| 1934 | return 0; |
| 1935 | |
| 1936 | ts = stktable_lookup_key(t, key); |
| 1937 | |
| 1938 | smp->flags = SMP_F_VOL_TEST; |
| 1939 | smp->data.type = SMP_T_SINT; |
| 1940 | smp->data.u.sint = 0; |
| 1941 | |
| 1942 | if (!ts) /* key not present */ |
| 1943 | return 1; |
| 1944 | |
| 1945 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1946 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1947 | 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] | 1948 | t->data_arg[STKTABLE_DT_GPC1_RATE].u); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1949 | else { |
| 1950 | /* fallback on the gpc array */ |
| 1951 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, 1); |
| 1952 | if (ptr) |
| 1953 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1954 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1955 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1956 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1957 | stktable_release(t, ts); |
| 1958 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | /* 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] | 1962 | * it up into this table. Returns the cumulated number of HTTP request errors |
| 1963 | * for the key if the key is present in the table, otherwise zero, so that |
| 1964 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 1965 | * in the table, <not found> is returned. |
| 1966 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1967 | 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] | 1968 | { |
| 1969 | struct stktable *t; |
| 1970 | struct stktable_key *key; |
| 1971 | struct stksess *ts; |
| 1972 | void *ptr; |
| 1973 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1974 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1975 | |
| 1976 | key = smp_to_stkey(smp, t); |
| 1977 | if (!key) |
| 1978 | return 0; |
| 1979 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1980 | ts = stktable_lookup_key(t, key); |
| 1981 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1982 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1983 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1984 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1985 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1986 | if (!ts) /* key not present */ |
| 1987 | return 1; |
| 1988 | |
| 1989 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1990 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1991 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1992 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1993 | stktable_release(t, ts); |
| 1994 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1998 | * it up into this table. Returns the HTTP request error rate the key |
| 1999 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2000 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2001 | * <not found> is returned. |
| 2002 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2003 | 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] | 2004 | { |
| 2005 | struct stktable *t; |
| 2006 | struct stktable_key *key; |
| 2007 | struct stksess *ts; |
| 2008 | void *ptr; |
| 2009 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2010 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2011 | |
| 2012 | key = smp_to_stkey(smp, t); |
| 2013 | if (!key) |
| 2014 | return 0; |
| 2015 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2016 | ts = stktable_lookup_key(t, key); |
| 2017 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2018 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2019 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2020 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2021 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2022 | if (!ts) /* key not present */ |
| 2023 | return 1; |
| 2024 | |
| 2025 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2026 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2027 | 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] | 2028 | t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2029 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2030 | stktable_release(t, ts); |
| 2031 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | /* 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] | 2035 | * it up into this table. Returns the cumulated number of HTTP response failures |
| 2036 | * for the key if the key is present in the table, otherwise zero, so that |
| 2037 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 2038 | * in the table, <not found> is returned. |
| 2039 | */ |
| 2040 | static int sample_conv_table_http_fail_cnt(const struct arg *arg_p, struct sample *smp, void *private) |
| 2041 | { |
| 2042 | struct stktable *t; |
| 2043 | struct stktable_key *key; |
| 2044 | struct stksess *ts; |
| 2045 | void *ptr; |
| 2046 | |
| 2047 | t = arg_p[0].data.t; |
| 2048 | |
| 2049 | key = smp_to_stkey(smp, t); |
| 2050 | if (!key) |
| 2051 | return 0; |
| 2052 | |
| 2053 | ts = stktable_lookup_key(t, key); |
| 2054 | |
| 2055 | smp->flags = SMP_F_VOL_TEST; |
| 2056 | smp->data.type = SMP_T_SINT; |
| 2057 | smp->data.u.sint = 0; |
| 2058 | |
| 2059 | if (!ts) /* key not present */ |
| 2060 | return 1; |
| 2061 | |
| 2062 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_CNT); |
| 2063 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2064 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2065 | |
| 2066 | stktable_release(t, ts); |
| 2067 | return !!ptr; |
| 2068 | } |
| 2069 | |
| 2070 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2071 | * it up into this table. Returns the HTTP response failure rate for the key |
| 2072 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2073 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2074 | * <not found> is returned. |
| 2075 | */ |
| 2076 | static int sample_conv_table_http_fail_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 2077 | { |
| 2078 | struct stktable *t; |
| 2079 | struct stktable_key *key; |
| 2080 | struct stksess *ts; |
| 2081 | void *ptr; |
| 2082 | |
| 2083 | t = arg_p[0].data.t; |
| 2084 | |
| 2085 | key = smp_to_stkey(smp, t); |
| 2086 | if (!key) |
| 2087 | return 0; |
| 2088 | |
| 2089 | ts = stktable_lookup_key(t, key); |
| 2090 | |
| 2091 | smp->flags = SMP_F_VOL_TEST; |
| 2092 | smp->data.type = SMP_T_SINT; |
| 2093 | smp->data.u.sint = 0; |
| 2094 | |
| 2095 | if (!ts) /* key not present */ |
| 2096 | return 1; |
| 2097 | |
| 2098 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_RATE); |
| 2099 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2100 | 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] | 2101 | t->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u); |
| 2102 | |
| 2103 | stktable_release(t, ts); |
| 2104 | return !!ptr; |
| 2105 | } |
| 2106 | |
| 2107 | /* 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] | 2108 | * it up into this table. Returns the cumulated number of HTTP request for the |
| 2109 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 2110 | * can be easily performed. If the inspected parameter is not stored in the |
| 2111 | * table, <not found> is returned. |
| 2112 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2113 | 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] | 2114 | { |
| 2115 | struct stktable *t; |
| 2116 | struct stktable_key *key; |
| 2117 | struct stksess *ts; |
| 2118 | void *ptr; |
| 2119 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2120 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2121 | |
| 2122 | key = smp_to_stkey(smp, t); |
| 2123 | if (!key) |
| 2124 | return 0; |
| 2125 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2126 | ts = stktable_lookup_key(t, key); |
| 2127 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2128 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2129 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2130 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2131 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2132 | if (!ts) /* key not present */ |
| 2133 | return 1; |
| 2134 | |
| 2135 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2136 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2137 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2138 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2139 | stktable_release(t, ts); |
| 2140 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2144 | * it up into this table. Returns the HTTP request rate the key if the key is |
| 2145 | * present in the table, otherwise zero, so that comparisons can be easily |
| 2146 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 2147 | * is returned. |
| 2148 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2149 | 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] | 2150 | { |
| 2151 | struct stktable *t; |
| 2152 | struct stktable_key *key; |
| 2153 | struct stksess *ts; |
| 2154 | void *ptr; |
| 2155 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2156 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2157 | |
| 2158 | key = smp_to_stkey(smp, t); |
| 2159 | if (!key) |
| 2160 | return 0; |
| 2161 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2162 | ts = stktable_lookup_key(t, key); |
| 2163 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2164 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2165 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2166 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2167 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2168 | if (!ts) /* key not present */ |
| 2169 | return 1; |
| 2170 | |
| 2171 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2172 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2173 | 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] | 2174 | t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2175 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2176 | stktable_release(t, ts); |
| 2177 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2181 | * it up into this table. Returns the volume of datareceived from clients in kbytes |
| 2182 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2183 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2184 | * <not found> is returned. |
| 2185 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2186 | 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] | 2187 | { |
| 2188 | struct stktable *t; |
| 2189 | struct stktable_key *key; |
| 2190 | struct stksess *ts; |
| 2191 | void *ptr; |
| 2192 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2193 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2194 | |
| 2195 | key = smp_to_stkey(smp, t); |
| 2196 | if (!key) |
| 2197 | return 0; |
| 2198 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2199 | ts = stktable_lookup_key(t, key); |
| 2200 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2201 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2202 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2203 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2204 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2205 | if (!ts) /* key not present */ |
| 2206 | return 1; |
| 2207 | |
| 2208 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2209 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2210 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2211 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2212 | stktable_release(t, ts); |
| 2213 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2217 | * it up into this table. Returns the volume of data sent to clients in kbytes |
| 2218 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2219 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2220 | * <not found> is returned. |
| 2221 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2222 | 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] | 2223 | { |
| 2224 | struct stktable *t; |
| 2225 | struct stktable_key *key; |
| 2226 | struct stksess *ts; |
| 2227 | void *ptr; |
| 2228 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2229 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2230 | |
| 2231 | key = smp_to_stkey(smp, t); |
| 2232 | if (!key) |
| 2233 | return 0; |
| 2234 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2235 | ts = stktable_lookup_key(t, key); |
| 2236 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2237 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2238 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2239 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2240 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2241 | if (!ts) /* key not present */ |
| 2242 | return 1; |
| 2243 | |
| 2244 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2245 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2246 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2247 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2248 | stktable_release(t, ts); |
| 2249 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2253 | * it up into this table. Returns the server ID associated with the key if the |
| 2254 | * key is present in the table, otherwise zero, so that comparisons can be |
| 2255 | * easily performed. If the inspected parameter is not stored in the table, |
| 2256 | * <not found> is returned. |
| 2257 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2258 | 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] | 2259 | { |
| 2260 | struct stktable *t; |
| 2261 | struct stktable_key *key; |
| 2262 | struct stksess *ts; |
| 2263 | void *ptr; |
| 2264 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2265 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2266 | |
| 2267 | key = smp_to_stkey(smp, t); |
| 2268 | if (!key) |
| 2269 | return 0; |
| 2270 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2271 | ts = stktable_lookup_key(t, key); |
| 2272 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2273 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2274 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2275 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2276 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2277 | if (!ts) /* key not present */ |
| 2278 | return 1; |
| 2279 | |
| 2280 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2281 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2282 | smp->data.u.sint = stktable_data_cast(ptr, std_t_sint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2283 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2284 | stktable_release(t, ts); |
| 2285 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2289 | * it up into this table. Returns the cumulated number of sessions for the |
| 2290 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 2291 | * can be easily performed. If the inspected parameter is not stored in the |
| 2292 | * table, <not found> is returned. |
| 2293 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2294 | 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] | 2295 | { |
| 2296 | struct stktable *t; |
| 2297 | struct stktable_key *key; |
| 2298 | struct stksess *ts; |
| 2299 | void *ptr; |
| 2300 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2301 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2302 | |
| 2303 | key = smp_to_stkey(smp, t); |
| 2304 | if (!key) |
| 2305 | return 0; |
| 2306 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2307 | ts = stktable_lookup_key(t, key); |
| 2308 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2309 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2310 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2311 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2312 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2313 | if (!ts) /* key not present */ |
| 2314 | return 1; |
| 2315 | |
| 2316 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2317 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2318 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2319 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2320 | stktable_release(t, ts); |
| 2321 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2325 | * it up into this table. Returns the session rate the key if the key is |
| 2326 | * present in the table, otherwise zero, so that comparisons can be easily |
| 2327 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 2328 | * is returned. |
| 2329 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2330 | 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] | 2331 | { |
| 2332 | struct stktable *t; |
| 2333 | struct stktable_key *key; |
| 2334 | struct stksess *ts; |
| 2335 | void *ptr; |
| 2336 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2337 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2338 | |
| 2339 | key = smp_to_stkey(smp, t); |
| 2340 | if (!key) |
| 2341 | return 0; |
| 2342 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2343 | ts = stktable_lookup_key(t, key); |
| 2344 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2345 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2346 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2347 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2348 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2349 | if (!ts) /* key not present */ |
| 2350 | return 1; |
| 2351 | |
| 2352 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2353 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2354 | 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] | 2355 | t->data_arg[STKTABLE_DT_SESS_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2356 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2357 | stktable_release(t, ts); |
| 2358 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2362 | * it up into this table. Returns the amount of concurrent connections tracking |
| 2363 | * the same key if the key is present in the table, otherwise zero, so that |
| 2364 | * comparisons can be easily performed. If the inspected parameter is not |
| 2365 | * stored in the table, <not found> is returned. |
| 2366 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2367 | 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] | 2368 | { |
| 2369 | struct stktable *t; |
| 2370 | struct stktable_key *key; |
| 2371 | struct stksess *ts; |
| 2372 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2373 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2374 | |
| 2375 | key = smp_to_stkey(smp, t); |
| 2376 | if (!key) |
| 2377 | return 0; |
| 2378 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2379 | ts = stktable_lookup_key(t, key); |
| 2380 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2381 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2382 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2383 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2384 | |
Tim Duesterhus | 65189c1 | 2018-06-26 15:57:29 +0200 | [diff] [blame] | 2385 | if (!ts) |
| 2386 | return 1; |
| 2387 | |
| 2388 | smp->data.u.sint = ts->ref_cnt; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2389 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2390 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2391 | return 1; |
| 2392 | } |
| 2393 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2394 | /* This function increments the gpc counter at index 'rule->arg.gpc.idx' of the |
| 2395 | * array on the tracksc counter of index 'rule->arg.gpc.sc' stored into the |
| 2396 | * <stream> or directly in the session <sess> if <stream> is set to NULL |
| 2397 | * |
| 2398 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2399 | */ |
| 2400 | static enum act_return action_inc_gpc(struct act_rule *rule, struct proxy *px, |
| 2401 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2402 | { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2403 | struct stksess *ts; |
| 2404 | struct stkctr *stkctr; |
| 2405 | |
| 2406 | /* Extract the stksess, return OK if no stksess available. */ |
| 2407 | if (s) |
| 2408 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2409 | else |
| 2410 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2411 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2412 | ts = stkctr_entry(stkctr); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2413 | if (ts) { |
| 2414 | void *ptr1, *ptr2; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2415 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2416 | /* First, update gpc_rate if it's tracked. Second, update its gpc if tracked. */ |
| 2417 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, rule->arg.gpc.idx); |
| 2418 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, rule->arg.gpc.idx); |
| 2419 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2420 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2421 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2422 | |
| 2423 | if (ptr1) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2424 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2425 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, 1); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2426 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2427 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2428 | stktable_data_cast(ptr2, std_t_uint)++; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2429 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2430 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2431 | |
| 2432 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2433 | stktable_touch_local(stkctr->table, ts, 0); |
| 2434 | } |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2435 | } |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2436 | return ACT_RET_CONT; |
| 2437 | } |
| 2438 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2439 | /* Same as action_inc_gpc() but for gpc0 only */ |
| 2440 | static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px, |
| 2441 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2442 | { |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2443 | struct stksess *ts; |
| 2444 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 2445 | unsigned int period = 0; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2446 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2447 | /* Extract the stksess, return OK if no stksess available. */ |
| 2448 | if (s) |
| 2449 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2450 | else |
| 2451 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2452 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2453 | ts = stkctr_entry(stkctr); |
| 2454 | if (ts) { |
| 2455 | void *ptr1, *ptr2; |
| 2456 | |
| 2457 | /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */ |
| 2458 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2459 | if (ptr1) { |
| 2460 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 2461 | } |
| 2462 | else { |
| 2463 | /* fallback on the gpc array */ |
| 2464 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, 0); |
| 2465 | if (ptr1) |
| 2466 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 2467 | } |
| 2468 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2469 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2470 | if (!ptr2) { |
| 2471 | /* fallback on the gpc array */ |
| 2472 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, 0); |
| 2473 | } |
| 2474 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2475 | if (ptr1 || ptr2) { |
| 2476 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2477 | |
| 2478 | if (ptr1) |
| 2479 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2480 | period, 1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2481 | |
| 2482 | if (ptr2) |
| 2483 | stktable_data_cast(ptr2, std_t_uint)++; |
| 2484 | |
| 2485 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2486 | |
| 2487 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2488 | stktable_touch_local(stkctr->table, ts, 0); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2489 | } |
| 2490 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2491 | return ACT_RET_CONT; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2492 | } |
| 2493 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2494 | /* Same as action_inc_gpc() but for gpc1 only */ |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2495 | static enum act_return action_inc_gpc1(struct act_rule *rule, struct proxy *px, |
| 2496 | struct session *sess, struct stream *s, int flags) |
| 2497 | { |
| 2498 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2499 | struct stkctr *stkctr = NULL; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 2500 | unsigned int period = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2501 | |
| 2502 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2503 | if (s && s->stkctr) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2504 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2505 | else if (sess->stkctr) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2506 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2507 | else |
| 2508 | return ACT_RET_CONT; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2509 | |
| 2510 | ts = stkctr_entry(stkctr); |
| 2511 | if (ts) { |
| 2512 | void *ptr1, *ptr2; |
| 2513 | |
| 2514 | /* First, update gpc1_rate if it's tracked. Second, update its gpc1 if tracked. */ |
| 2515 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2516 | if (ptr1) { |
| 2517 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 2518 | } |
| 2519 | else { |
| 2520 | /* fallback on the gpc array */ |
| 2521 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, 1); |
| 2522 | if (ptr1) |
| 2523 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 2524 | } |
| 2525 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2526 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2527 | if (!ptr2) { |
| 2528 | /* fallback on the gpc array */ |
| 2529 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, 1); |
| 2530 | } |
| 2531 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2532 | if (ptr1 || ptr2) { |
| 2533 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2534 | |
| 2535 | if (ptr1) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2536 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2537 | period, 1); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2538 | |
| 2539 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2540 | stktable_data_cast(ptr2, std_t_uint)++; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2541 | |
| 2542 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2543 | |
| 2544 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2545 | stktable_touch_local(stkctr->table, ts, 0); |
| 2546 | } |
| 2547 | } |
| 2548 | return ACT_RET_CONT; |
| 2549 | } |
| 2550 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2551 | /* This function is a common parser for actions incrementing the GPC |
| 2552 | * (General Purpose Counters). It understands the formats: |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2553 | * |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2554 | * sc-inc-gpc(<gpc IDX>,<track ID>) |
| 2555 | * sc-inc-gpc0([<track ID>]) |
| 2556 | * sc-inc-gpc1([<track ID>]) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2557 | * |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2558 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error |
| 2559 | * message. Otherwise it returns ACT_RET_PRS_OK. |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2560 | */ |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2561 | static enum act_parse_ret parse_inc_gpc(const char **args, int *arg, struct proxy *px, |
| 2562 | struct act_rule *rule, char **err) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2563 | { |
| 2564 | const char *cmd_name = args[*arg-1]; |
| 2565 | char *error; |
| 2566 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2567 | if (!global.tune.nb_stk_ctr) { |
| 2568 | memprintf(err, "Cannot use '%s', stick-counters are disabled via tune.stick-counters", args[*arg-1]); |
| 2569 | return ACT_RET_PRS_ERR; |
| 2570 | } |
| 2571 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2572 | cmd_name += strlen("sc-inc-gpc"); |
| 2573 | if (*cmd_name == '(') { |
| 2574 | cmd_name++; /* skip the '(' */ |
| 2575 | rule->arg.gpc.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2576 | if (*error != ',') { |
| 2577 | 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] | 2578 | return ACT_RET_PRS_ERR; |
| 2579 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2580 | else { |
| 2581 | cmd_name = error + 1; /* skip the ',' */ |
| 2582 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2583 | if (*error != ')') { |
| 2584 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-inc-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2585 | return ACT_RET_PRS_ERR; |
| 2586 | } |
| 2587 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2588 | if (rule->arg.gpc.sc >= global.tune.nb_stk_ctr) { |
| 2589 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d (tune.stick-counters)", |
| 2590 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2591 | return ACT_RET_PRS_ERR; |
| 2592 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2593 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2594 | rule->action_ptr = action_inc_gpc; |
| 2595 | } |
| 2596 | else if (*cmd_name == '0' ||*cmd_name == '1') { |
| 2597 | char c = *cmd_name; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2598 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2599 | cmd_name++; |
| 2600 | if (*cmd_name == '\0') { |
| 2601 | /* default stick table id. */ |
| 2602 | rule->arg.gpc.sc = 0; |
| 2603 | } else { |
| 2604 | /* parse the stick table id. */ |
| 2605 | if (*cmd_name != '(') { |
| 2606 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 2607 | return ACT_RET_PRS_ERR; |
| 2608 | } |
| 2609 | cmd_name++; /* jump the '(' */ |
| 2610 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2611 | if (*error != ')') { |
| 2612 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 2613 | return ACT_RET_PRS_ERR; |
| 2614 | } |
| 2615 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2616 | if (rule->arg.gpc.sc >= global.tune.nb_stk_ctr) { |
| 2617 | memprintf(err, "invalid stick table track ID. The max allowed ID is %d (tune.stick-counters)", |
| 2618 | global.tune.nb_stk_ctr-1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2619 | return ACT_RET_PRS_ERR; |
| 2620 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2621 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2622 | if (c == '1') |
| 2623 | rule->action_ptr = action_inc_gpc1; |
| 2624 | else |
| 2625 | rule->action_ptr = action_inc_gpc0; |
| 2626 | } |
| 2627 | else { |
| 2628 | /* default stick table id. */ |
Willy Tarreau | 2039151 | 2023-01-02 17:35:50 +0100 | [diff] [blame] | 2629 | 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] | 2630 | return ACT_RET_PRS_ERR; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2631 | } |
| 2632 | rule->action = ACT_CUSTOM; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2633 | return ACT_RET_PRS_OK; |
| 2634 | } |
| 2635 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2636 | /* This function sets the gpt at index 'rule->arg.gpt.idx' of the array on the |
| 2637 | * tracksc counter of index 'rule->arg.gpt.sc' stored into the <stream> or |
| 2638 | * directly in the session <sess> if <stream> is set to NULL. This gpt is |
| 2639 | * set to the value computed by the expression 'rule->arg.gpt.expr' or if |
| 2640 | * 'rule->arg.gpt.expr' is null directly to the value of 'rule->arg.gpt.value'. |
| 2641 | * |
| 2642 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2643 | */ |
| 2644 | static enum act_return action_set_gpt(struct act_rule *rule, struct proxy *px, |
| 2645 | struct session *sess, struct stream *s, int flags) |
| 2646 | { |
| 2647 | void *ptr; |
| 2648 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2649 | struct stkctr *stkctr = NULL; |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2650 | unsigned int value = 0; |
| 2651 | struct sample *smp; |
| 2652 | int smp_opt_dir; |
| 2653 | |
| 2654 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2655 | if (s && s->stkctr) |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2656 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2657 | else if (sess->stkctr) |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2658 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2659 | else |
| 2660 | return ACT_RET_CONT; |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2661 | |
| 2662 | ts = stkctr_entry(stkctr); |
| 2663 | if (!ts) |
| 2664 | return ACT_RET_CONT; |
| 2665 | |
| 2666 | /* Store the sample in the required sc, and ignore errors. */ |
| 2667 | ptr = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPT, rule->arg.gpt.idx); |
| 2668 | if (ptr) { |
| 2669 | |
| 2670 | if (!rule->arg.gpt.expr) |
| 2671 | value = (unsigned int)(rule->arg.gpt.value); |
| 2672 | else { |
| 2673 | switch (rule->from) { |
Aurelien DARRAGON | e18fe56 | 2023-08-09 17:23:32 +0200 | [diff] [blame] | 2674 | 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] | 2675 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2676 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2677 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2678 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2679 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2680 | default: |
| 2681 | send_log(px, LOG_ERR, "stick table: internal error while setting gpt%u.", rule->arg.gpt.idx); |
| 2682 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2683 | ha_alert("stick table: internal error while executing setting gpt%u.\n", rule->arg.gpt.idx); |
| 2684 | return ACT_RET_CONT; |
| 2685 | } |
| 2686 | |
| 2687 | /* Fetch and cast the expression. */ |
| 2688 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT); |
| 2689 | if (!smp) { |
| 2690 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt%u.", rule->arg.gpt.idx); |
| 2691 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2692 | ha_alert("stick table: invalid expression or data type while setting gpt%u.\n", rule->arg.gpt.idx); |
| 2693 | return ACT_RET_CONT; |
| 2694 | } |
| 2695 | value = (unsigned int)(smp->data.u.sint); |
| 2696 | } |
| 2697 | |
| 2698 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2699 | |
| 2700 | stktable_data_cast(ptr, std_t_uint) = value; |
| 2701 | |
| 2702 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2703 | |
| 2704 | stktable_touch_local(stkctr->table, ts, 0); |
| 2705 | } |
| 2706 | |
| 2707 | return ACT_RET_CONT; |
| 2708 | } |
| 2709 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2710 | /* Always returns 1. */ |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2711 | 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] | 2712 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2713 | { |
| 2714 | void *ptr; |
| 2715 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2716 | struct stkctr *stkctr = NULL; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2717 | unsigned int value = 0; |
| 2718 | struct sample *smp; |
| 2719 | int smp_opt_dir; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2720 | |
| 2721 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2722 | if (s && s->stkctr) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2723 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2724 | else if (sess->stkctr) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2725 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2726 | else |
| 2727 | return ACT_RET_CONT; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2728 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2729 | ts = stkctr_entry(stkctr); |
| 2730 | if (!ts) |
| 2731 | return ACT_RET_CONT; |
| 2732 | |
| 2733 | /* Store the sample in the required sc, and ignore errors. */ |
| 2734 | ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 2735 | if (!ptr) |
| 2736 | ptr = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPT, 0); |
| 2737 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2738 | if (ptr) { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2739 | if (!rule->arg.gpt.expr) |
| 2740 | value = (unsigned int)(rule->arg.gpt.value); |
| 2741 | else { |
| 2742 | switch (rule->from) { |
Aurelien DARRAGON | e18fe56 | 2023-08-09 17:23:32 +0200 | [diff] [blame] | 2743 | 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] | 2744 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2745 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2746 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2747 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2748 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2749 | default: |
| 2750 | send_log(px, LOG_ERR, "stick table: internal error while setting gpt0."); |
| 2751 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2752 | ha_alert("stick table: internal error while executing setting gpt0.\n"); |
| 2753 | return ACT_RET_CONT; |
| 2754 | } |
| 2755 | |
| 2756 | /* Fetch and cast the expression. */ |
| 2757 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT); |
| 2758 | if (!smp) { |
| 2759 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt0."); |
| 2760 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2761 | ha_alert("stick table: invalid expression or data type while setting gpt0.\n"); |
| 2762 | return ACT_RET_CONT; |
| 2763 | } |
| 2764 | value = (unsigned int)(smp->data.u.sint); |
| 2765 | } |
| 2766 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2767 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2768 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2769 | stktable_data_cast(ptr, std_t_uint) = value; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2770 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2771 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2772 | |
| 2773 | stktable_touch_local(stkctr->table, ts, 0); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2774 | } |
| 2775 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2776 | return ACT_RET_CONT; |
| 2777 | } |
| 2778 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2779 | /* This function is a parser for the "sc-set-gpt" and "sc-set-gpt0" actions. |
| 2780 | * It understands the formats: |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2781 | * |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2782 | * sc-set-gpt(<gpt IDX>,<track ID>) <expression> |
| 2783 | * sc-set-gpt0(<track ID>) <expression> |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2784 | * |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2785 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error message. |
| 2786 | * Otherwise, it returns ACT_RET_PRS_OK and the variable 'rule->arg.gpt.expr' |
| 2787 | * is filled with the pointer to the expression to execute or NULL if the arg |
| 2788 | * is directly an integer stored into 'rule->arg.gpt.value'. |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2789 | */ |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2790 | 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] | 2791 | struct act_rule *rule, char **err) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2792 | { |
| 2793 | const char *cmd_name = args[*arg-1]; |
| 2794 | char *error; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2795 | int smp_val; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2796 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2797 | if (!global.tune.nb_stk_ctr) { |
| 2798 | memprintf(err, "Cannot use '%s', stick-counters are disabled via tune.stick-counters", args[*arg-1]); |
| 2799 | return ACT_RET_PRS_ERR; |
| 2800 | } |
| 2801 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2802 | cmd_name += strlen("sc-set-gpt"); |
| 2803 | if (*cmd_name == '(') { |
| 2804 | cmd_name++; /* skip the '(' */ |
| 2805 | rule->arg.gpt.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2806 | if (*error != ',') { |
| 2807 | 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] | 2808 | return ACT_RET_PRS_ERR; |
| 2809 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2810 | else { |
| 2811 | cmd_name = error + 1; /* skip the ',' */ |
| 2812 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2813 | if (*error != ')') { |
| 2814 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt(<GPT ID>,<Track ID>)", args[*arg-1]); |
| 2815 | return ACT_RET_PRS_ERR; |
| 2816 | } |
| 2817 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2818 | if (rule->arg.gpt.sc >= global.tune.nb_stk_ctr) { |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2819 | 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] | 2820 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2821 | return ACT_RET_PRS_ERR; |
| 2822 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2823 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2824 | rule->action_ptr = action_set_gpt; |
| 2825 | } |
| 2826 | else if (*cmd_name == '0') { |
| 2827 | cmd_name++; |
| 2828 | if (*cmd_name == '\0') { |
| 2829 | /* default stick table id. */ |
| 2830 | rule->arg.gpt.sc = 0; |
| 2831 | } else { |
| 2832 | /* parse the stick table id. */ |
| 2833 | if (*cmd_name != '(') { |
| 2834 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2835 | return ACT_RET_PRS_ERR; |
| 2836 | } |
| 2837 | cmd_name++; /* jump the '(' */ |
| 2838 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2839 | if (*error != ')') { |
| 2840 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2841 | return ACT_RET_PRS_ERR; |
| 2842 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2843 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2844 | if (rule->arg.gpt.sc >= global.tune.nb_stk_ctr) { |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2845 | 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] | 2846 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2847 | return ACT_RET_PRS_ERR; |
| 2848 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2849 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2850 | rule->action_ptr = action_set_gpt0; |
| 2851 | } |
| 2852 | else { |
| 2853 | /* default stick table id. */ |
| 2854 | memprintf(err, "invalid gpt ID '%s'. Expects sc-set-gpt(<GPT ID>,<Track ID>)", args[*arg-1]); |
| 2855 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2856 | } |
| 2857 | |
Willy Tarreau | ece4c4a | 2021-08-24 14:57:28 +0200 | [diff] [blame] | 2858 | /* value may be either an integer or an expression */ |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2859 | rule->arg.gpt.expr = NULL; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2860 | rule->arg.gpt.value = strtol(args[*arg], &error, 10); |
Willy Tarreau | ece4c4a | 2021-08-24 14:57:28 +0200 | [diff] [blame] | 2861 | if (*error == '\0') { |
| 2862 | /* valid integer, skip it */ |
| 2863 | (*arg)++; |
| 2864 | } else { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2865 | 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] | 2866 | px->conf.args.line, err, &px->conf.args, NULL); |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2867 | if (!rule->arg.gpt.expr) |
| 2868 | return ACT_RET_PRS_ERR; |
| 2869 | |
| 2870 | switch (rule->from) { |
Aurelien DARRAGON | e18fe56 | 2023-08-09 17:23:32 +0200 | [diff] [blame] | 2871 | 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] | 2872 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 2873 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 2874 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 2875 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 2876 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 2877 | default: |
| 2878 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 2879 | return ACT_RET_PRS_ERR; |
| 2880 | } |
| 2881 | if (!(rule->arg.gpt.expr->fetch->val & smp_val)) { |
| 2882 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 2883 | sample_src_names(rule->arg.gpt.expr->fetch->use)); |
| 2884 | free(rule->arg.gpt.expr); |
| 2885 | return ACT_RET_PRS_ERR; |
| 2886 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2887 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2888 | |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 2889 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2890 | |
| 2891 | return ACT_RET_PRS_OK; |
| 2892 | } |
| 2893 | |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 2894 | /* This function updates the gpc at index 'rule->arg.gpc.idx' of the array on |
| 2895 | * the tracksc counter of index 'rule->arg.gpc.sc' stored into the <stream> or |
| 2896 | * directly in the session <sess> if <stream> is set to NULL. This gpc is |
| 2897 | * set to the value computed by the expression 'rule->arg.gpc.expr' or if |
| 2898 | * 'rule->arg.gpc.expr' is null directly to the value of 'rule->arg.gpc.value'. |
| 2899 | * |
| 2900 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2901 | */ |
| 2902 | static enum act_return action_add_gpc(struct act_rule *rule, struct proxy *px, |
| 2903 | struct session *sess, struct stream *s, int flags) |
| 2904 | { |
| 2905 | void *ptr1, *ptr2; |
| 2906 | struct stksess *ts; |
| 2907 | struct stkctr *stkctr; |
| 2908 | unsigned int value = 0; |
| 2909 | struct sample *smp; |
| 2910 | int smp_opt_dir; |
| 2911 | |
| 2912 | /* Extract the stksess, return OK if no stksess available. */ |
| 2913 | if (s) |
| 2914 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2915 | else |
| 2916 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
| 2917 | |
| 2918 | ts = stkctr_entry(stkctr); |
| 2919 | if (!ts) |
| 2920 | return ACT_RET_CONT; |
| 2921 | |
| 2922 | /* First, update gpc_rate if it's tracked. Second, update its gpc if tracked. */ |
| 2923 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, rule->arg.gpc.idx); |
| 2924 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, rule->arg.gpc.idx); |
| 2925 | |
| 2926 | if (ptr1 || ptr2) { |
| 2927 | if (!rule->arg.gpc.expr) |
| 2928 | value = (unsigned int)(rule->arg.gpc.value); |
| 2929 | else { |
| 2930 | switch (rule->from) { |
Aurelien DARRAGON | b425f75 | 2023-08-09 17:39:29 +0200 | [diff] [blame] | 2931 | case ACT_F_TCP_REQ_CON: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 2932 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2933 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2934 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2935 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2936 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2937 | default: |
| 2938 | send_log(px, LOG_ERR, "stick table: internal error while setting gpc%u.", rule->arg.gpc.idx); |
| 2939 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2940 | ha_alert("stick table: internal error while executing setting gpc%u.\n", rule->arg.gpc.idx); |
| 2941 | return ACT_RET_CONT; |
| 2942 | } |
| 2943 | |
| 2944 | /* Fetch and cast the expression. */ |
| 2945 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpc.expr, SMP_T_SINT); |
| 2946 | if (!smp) { |
| 2947 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpc%u.", rule->arg.gpc.idx); |
| 2948 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2949 | ha_alert("stick table: invalid expression or data type while setting gpc%u.\n", rule->arg.gpc.idx); |
| 2950 | return ACT_RET_CONT; |
| 2951 | } |
| 2952 | value = (unsigned int)(smp->data.u.sint); |
| 2953 | } |
| 2954 | |
| 2955 | if (value) { |
| 2956 | /* only update the value if non-null increment */ |
| 2957 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2958 | |
| 2959 | if (ptr1) |
| 2960 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 2961 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, value); |
| 2962 | |
| 2963 | if (ptr2) |
| 2964 | stktable_data_cast(ptr2, std_t_uint) += value; |
| 2965 | |
| 2966 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2967 | } |
| 2968 | /* always touch the table so that it doesn't expire */ |
| 2969 | stktable_touch_local(stkctr->table, ts, 0); |
| 2970 | } |
| 2971 | |
| 2972 | return ACT_RET_CONT; |
| 2973 | } |
| 2974 | |
| 2975 | /* This function is a parser for the "sc-add-gpc" action. It understands the |
| 2976 | * format: |
| 2977 | * |
| 2978 | * sc-add-gpc(<gpc IDX>,<track ID>) <expression> |
| 2979 | * |
| 2980 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error message. |
| 2981 | * Otherwise, it returns ACT_RET_PRS_OK and the variable 'rule->arg.gpc.expr' |
| 2982 | * is filled with the pointer to the expression to execute or NULL if the arg |
| 2983 | * is directly an integer stored into 'rule->arg.gpt.value'. |
| 2984 | */ |
| 2985 | static enum act_parse_ret parse_add_gpc(const char **args, int *arg, struct proxy *px, |
| 2986 | struct act_rule *rule, char **err) |
| 2987 | { |
| 2988 | const char *cmd_name = args[*arg-1]; |
| 2989 | char *error; |
| 2990 | int smp_val; |
| 2991 | |
| 2992 | cmd_name += strlen("sc-add-gpc"); |
| 2993 | if (*cmd_name != '(') { |
| 2994 | memprintf(err, "Missing or invalid arguments for '%s'. Expects sc-add-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2995 | return ACT_RET_PRS_ERR; |
| 2996 | } |
| 2997 | cmd_name++; /* skip the '(' */ |
| 2998 | rule->arg.gpc.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2999 | if (*error != ',') { |
| 3000 | memprintf(err, "Missing gpc ID. Expects %s(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 3001 | return ACT_RET_PRS_ERR; |
| 3002 | } |
| 3003 | else { |
| 3004 | cmd_name = error + 1; /* skip the ',' */ |
| 3005 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 3006 | if (*error != ')') { |
| 3007 | memprintf(err, "invalid stick table track ID '%s'. Expects %s(<GPC ID>,<Track ID>)", cmd_name, args[*arg-1]); |
| 3008 | return ACT_RET_PRS_ERR; |
| 3009 | } |
| 3010 | |
| 3011 | if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) { |
| 3012 | memprintf(err, "invalid stick table track ID '%s' for '%s'. The max allowed ID is %d", |
| 3013 | cmd_name, args[*arg-1], MAX_SESS_STKCTR-1); |
| 3014 | return ACT_RET_PRS_ERR; |
| 3015 | } |
| 3016 | } |
| 3017 | rule->action_ptr = action_add_gpc; |
| 3018 | |
| 3019 | /* value may be either an integer or an expression */ |
| 3020 | rule->arg.gpc.expr = NULL; |
| 3021 | rule->arg.gpc.value = strtol(args[*arg], &error, 10); |
| 3022 | if (*error == '\0') { |
| 3023 | /* valid integer, skip it */ |
| 3024 | (*arg)++; |
| 3025 | } else { |
| 3026 | rule->arg.gpc.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, |
| 3027 | px->conf.args.line, err, &px->conf.args, NULL); |
| 3028 | if (!rule->arg.gpc.expr) |
| 3029 | return ACT_RET_PRS_ERR; |
| 3030 | |
| 3031 | switch (rule->from) { |
Aurelien DARRAGON | b425f75 | 2023-08-09 17:39:29 +0200 | [diff] [blame] | 3032 | case ACT_F_TCP_REQ_CON: smp_val = SMP_VAL_FE_CON_ACC; break; |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 3033 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 3034 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 3035 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 3036 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 3037 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 3038 | default: |
| 3039 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 3040 | return ACT_RET_PRS_ERR; |
| 3041 | } |
| 3042 | |
| 3043 | if (!(rule->arg.gpc.expr->fetch->val & smp_val)) { |
| 3044 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 3045 | sample_src_names(rule->arg.gpc.expr->fetch->use)); |
| 3046 | free(rule->arg.gpc.expr); |
| 3047 | return ACT_RET_PRS_ERR; |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | rule->action = ACT_CUSTOM; |
| 3052 | |
| 3053 | return ACT_RET_PRS_OK; |
| 3054 | } |
| 3055 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3056 | /* set temp integer to the number of used entries in the table pointed to by expr. |
| 3057 | * Accepts exactly 1 argument of type table. |
| 3058 | */ |
| 3059 | static int |
| 3060 | smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3061 | { |
| 3062 | smp->flags = SMP_F_VOL_TEST; |
| 3063 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3064 | smp->data.u.sint = args->data.t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3065 | return 1; |
| 3066 | } |
| 3067 | |
| 3068 | /* set temp integer to the number of free entries in the table pointed to by expr. |
| 3069 | * Accepts exactly 1 argument of type table. |
| 3070 | */ |
| 3071 | static int |
| 3072 | smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3073 | { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3074 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3075 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3076 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3077 | smp->flags = SMP_F_VOL_TEST; |
| 3078 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3079 | smp->data.u.sint = t->size - t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3080 | return 1; |
| 3081 | } |
| 3082 | |
| 3083 | /* Returns a pointer to a stkctr depending on the fetch keyword name. |
| 3084 | * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively. |
| 3085 | * sc[0-9]_* will return a pointer to the respective field in the |
| 3086 | * stream <l4>. sc_* requires an UINT argument specifying the stick |
| 3087 | * counter number. src_* will fill a locally allocated structure with |
| 3088 | * the table and entry corresponding to what is specified with src_*. |
| 3089 | * NULL may be returned if the designated stkctr is not tracked. For |
| 3090 | * the sc_* and sc[0-9]_* forms, an optional table argument may be |
| 3091 | * passed. When present, the currently tracked key is then looked up |
| 3092 | * in the specified table instead of the current table. The purpose is |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 3093 | * 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] | 3094 | * multiple tables). <strm> is allowed to be NULL, in which case only |
| 3095 | * the session will be consulted. |
| 3096 | */ |
| 3097 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3098 | 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] | 3099 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3100 | struct stkctr *stkptr; |
| 3101 | struct stksess *stksess; |
| 3102 | unsigned int num = kw[2] - '0'; |
| 3103 | int arg = 0; |
| 3104 | |
| 3105 | if (num == '_' - '0') { |
| 3106 | /* sc_* variant, args[0] = ctr# (mandatory) */ |
| 3107 | num = args[arg++].data.sint; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3108 | } |
| 3109 | else if (num > 9) { /* src_* variant, args[0] = table */ |
| 3110 | struct stktable_key *key; |
| 3111 | struct connection *conn = objt_conn(sess->origin); |
| 3112 | struct sample smp; |
| 3113 | |
| 3114 | if (!conn) |
| 3115 | return NULL; |
| 3116 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3117 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3118 | smp.px = NULL; |
| 3119 | smp.sess = sess; |
| 3120 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3121 | 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] | 3122 | return NULL; |
| 3123 | |
| 3124 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3125 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3126 | if (!key) |
| 3127 | return NULL; |
| 3128 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3129 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3130 | stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key)); |
| 3131 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | /* Here, <num> contains the counter number from 0 to 9 for |
| 3135 | * the sc[0-9]_ form, or even higher using sc_(num) if needed. |
| 3136 | * args[arg] is the first optional argument. We first lookup the |
| 3137 | * 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] | 3138 | * 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] | 3139 | */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3140 | if (num >= global.tune.nb_stk_ctr) |
Christopher Faulet | a9fa88a | 2019-10-21 10:53:34 +0200 | [diff] [blame] | 3141 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3142 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3143 | stkptr = NULL; |
| 3144 | if (strm && strm->stkctr) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3145 | stkptr = &strm->stkctr[num]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3146 | if (!strm || !stkptr || !stkctr_entry(stkptr)) { |
| 3147 | if (sess->stkctr) |
| 3148 | stkptr = &sess->stkctr[num]; |
| 3149 | else |
| 3150 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3151 | if (!stkctr_entry(stkptr)) |
| 3152 | return NULL; |
| 3153 | } |
| 3154 | |
| 3155 | stksess = stkctr_entry(stkptr); |
| 3156 | if (!stksess) |
| 3157 | return NULL; |
| 3158 | |
| 3159 | if (unlikely(args[arg].type == ARGT_TAB)) { |
| 3160 | /* 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] | 3161 | stkctr->table = args[arg].data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3162 | stkctr_set_entry(stkctr, stktable_lookup(stkctr->table, stksess)); |
| 3163 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3164 | } |
| 3165 | return stkptr; |
| 3166 | } |
| 3167 | |
| 3168 | /* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create |
| 3169 | * the entry if it doesn't exist yet. This is needed for a few fetch |
| 3170 | * functions which need to create an entry, such as src_inc_gpc* and |
| 3171 | * src_clr_gpc*. |
| 3172 | */ |
| 3173 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3174 | 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] | 3175 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3176 | struct stktable_key *key; |
| 3177 | struct connection *conn = objt_conn(sess->origin); |
| 3178 | struct sample smp; |
| 3179 | |
| 3180 | if (strncmp(kw, "src_", 4) != 0) |
| 3181 | return NULL; |
| 3182 | |
| 3183 | if (!conn) |
| 3184 | return NULL; |
| 3185 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3186 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3187 | smp.px = NULL; |
| 3188 | smp.sess = sess; |
| 3189 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3190 | 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] | 3191 | return NULL; |
| 3192 | |
| 3193 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3194 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3195 | if (!key) |
| 3196 | return NULL; |
| 3197 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3198 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3199 | stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key)); |
| 3200 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | /* set return a boolean indicating if the requested stream counter is |
| 3204 | * currently being tracked or not. |
| 3205 | * Supports being called as "sc[0-9]_tracked" only. |
| 3206 | */ |
| 3207 | static int |
| 3208 | smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3209 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3210 | struct stkctr tmpstkctr; |
| 3211 | struct stkctr *stkctr; |
| 3212 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3213 | smp->flags = SMP_F_VOL_TEST; |
| 3214 | smp->data.type = SMP_T_BOOL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3215 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3216 | smp->data.u.sint = !!stkctr; |
| 3217 | |
| 3218 | /* release the ref count */ |
Dirkjan Bussink | ff57f1b | 2018-09-14 14:31:22 +0200 | [diff] [blame] | 3219 | if (stkctr == &tmpstkctr) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3220 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3221 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 3222 | return 1; |
| 3223 | } |
| 3224 | |
| 3225 | /* set <smp> to the General Purpose Tag of index set as first arg |
| 3226 | * to value from the stream's tracked frontend counters or from the src. |
| 3227 | * Supports being called as "sc_get_gpt(<gpt-idx>,<sc-idx>[,<table>])" or |
| 3228 | * "src_get_gpt(<gpt-idx>[,<table>])" only. Value zero is returned if |
| 3229 | * the key is new or gpt is not stored. |
| 3230 | */ |
| 3231 | static int |
| 3232 | smp_fetch_sc_get_gpt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3233 | { |
| 3234 | struct stkctr tmpstkctr; |
| 3235 | struct stkctr *stkctr; |
| 3236 | unsigned int idx; |
| 3237 | |
| 3238 | idx = args[0].data.sint; |
| 3239 | |
| 3240 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3241 | if (!stkctr) |
| 3242 | return 0; |
| 3243 | |
| 3244 | smp->flags = SMP_F_VOL_TEST; |
| 3245 | smp->data.type = SMP_T_SINT; |
| 3246 | smp->data.u.sint = 0; |
| 3247 | |
| 3248 | if (stkctr_entry(stkctr)) { |
| 3249 | void *ptr; |
| 3250 | |
| 3251 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, idx); |
| 3252 | if (!ptr) { |
| 3253 | if (stkctr == &tmpstkctr) |
| 3254 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3255 | return 0; /* parameter not stored */ |
| 3256 | } |
| 3257 | |
| 3258 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3259 | |
| 3260 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3261 | |
| 3262 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3263 | |
| 3264 | if (stkctr == &tmpstkctr) |
| 3265 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3266 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3267 | return 1; |
| 3268 | } |
| 3269 | |
| 3270 | /* set <smp> to the General Purpose Flag 0 value from the stream's tracked |
| 3271 | * frontend counters or from the src. |
| 3272 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value |
| 3273 | * zero is returned if the key is new. |
| 3274 | */ |
| 3275 | static int |
| 3276 | smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3277 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3278 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3279 | struct stkctr *stkctr; |
| 3280 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3281 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3282 | if (!stkctr) |
| 3283 | return 0; |
| 3284 | |
| 3285 | smp->flags = SMP_F_VOL_TEST; |
| 3286 | smp->data.type = SMP_T_SINT; |
| 3287 | smp->data.u.sint = 0; |
| 3288 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3289 | if (stkctr_entry(stkctr)) { |
| 3290 | void *ptr; |
| 3291 | |
| 3292 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 3293 | if (!ptr) |
| 3294 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, 0); |
| 3295 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3296 | if (!ptr) { |
| 3297 | if (stkctr == &tmpstkctr) |
| 3298 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3299 | return 0; /* parameter not stored */ |
| 3300 | } |
| 3301 | |
| 3302 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3303 | |
| 3304 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3305 | |
| 3306 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3307 | |
| 3308 | if (stkctr == &tmpstkctr) |
| 3309 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3310 | } |
| 3311 | return 1; |
| 3312 | } |
| 3313 | |
| 3314 | /* set <smp> to the GPC[args(0)]'s value from the stream's tracked |
| 3315 | * frontend counters or from the src. |
| 3316 | * Supports being called as "sc_get_gpc(<gpc-idx>,<sc-idx>[,<table>])" or |
| 3317 | * "src_get_gpc(<gpc-idx>[,<table>])" only. Value |
| 3318 | * Value zero is returned if the key is new or gpc is not stored. |
| 3319 | */ |
| 3320 | static int |
| 3321 | smp_fetch_sc_get_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3322 | { |
| 3323 | struct stkctr tmpstkctr; |
| 3324 | struct stkctr *stkctr; |
| 3325 | unsigned int idx; |
| 3326 | |
| 3327 | idx = args[0].data.sint; |
| 3328 | |
| 3329 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3330 | if (!stkctr) |
| 3331 | return 0; |
| 3332 | |
| 3333 | smp->flags = SMP_F_VOL_TEST; |
| 3334 | smp->data.type = SMP_T_SINT; |
| 3335 | smp->data.u.sint = 0; |
| 3336 | |
| 3337 | if (stkctr_entry(stkctr) != NULL) { |
| 3338 | void *ptr; |
| 3339 | |
| 3340 | 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] | 3341 | if (!ptr) { |
| 3342 | if (stkctr == &tmpstkctr) |
| 3343 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3344 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3345 | } |
| 3346 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3347 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3348 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3349 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3350 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3351 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3352 | |
| 3353 | if (stkctr == &tmpstkctr) |
| 3354 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3355 | } |
| 3356 | return 1; |
| 3357 | } |
| 3358 | |
| 3359 | /* set <smp> to the General Purpose Counter 0 value from the stream's tracked |
| 3360 | * frontend counters or from the src. |
| 3361 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value |
| 3362 | * zero is returned if the key is new. |
| 3363 | */ |
| 3364 | static int |
| 3365 | smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3366 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3367 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3368 | struct stkctr *stkctr; |
| 3369 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3370 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3371 | if (!stkctr) |
| 3372 | return 0; |
| 3373 | |
| 3374 | smp->flags = SMP_F_VOL_TEST; |
| 3375 | smp->data.type = SMP_T_SINT; |
| 3376 | smp->data.u.sint = 0; |
| 3377 | |
| 3378 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3379 | void *ptr; |
| 3380 | |
| 3381 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3382 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3383 | /* fallback on the gpc array */ |
| 3384 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3385 | } |
| 3386 | |
| 3387 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3388 | if (stkctr == &tmpstkctr) |
| 3389 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3390 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3391 | } |
| 3392 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3393 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3394 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3395 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3396 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3397 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3398 | |
| 3399 | if (stkctr == &tmpstkctr) |
| 3400 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3401 | } |
| 3402 | return 1; |
| 3403 | } |
| 3404 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3405 | /* set <smp> to the General Purpose Counter 1 value from the stream's tracked |
| 3406 | * frontend counters or from the src. |
| 3407 | * Supports being called as "sc[0-9]_get_gpc1" or "src_get_gpc1" only. Value |
| 3408 | * zero is returned if the key is new. |
| 3409 | */ |
| 3410 | static int |
| 3411 | smp_fetch_sc_get_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3412 | { |
| 3413 | struct stkctr tmpstkctr; |
| 3414 | struct stkctr *stkctr; |
| 3415 | |
| 3416 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3417 | if (!stkctr) |
| 3418 | return 0; |
| 3419 | |
| 3420 | smp->flags = SMP_F_VOL_TEST; |
| 3421 | smp->data.type = SMP_T_SINT; |
| 3422 | smp->data.u.sint = 0; |
| 3423 | |
| 3424 | if (stkctr_entry(stkctr) != NULL) { |
| 3425 | void *ptr; |
| 3426 | |
| 3427 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3428 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3429 | /* fallback on the gpc array */ |
| 3430 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3431 | } |
| 3432 | |
| 3433 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3434 | if (stkctr == &tmpstkctr) |
| 3435 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3436 | return 0; /* parameter not stored */ |
| 3437 | } |
| 3438 | |
| 3439 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3440 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3441 | 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] | 3442 | |
| 3443 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3444 | |
| 3445 | if (stkctr == &tmpstkctr) |
| 3446 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3447 | } |
| 3448 | return 1; |
| 3449 | } |
| 3450 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3451 | /* set <smp> to the GPC[args(0)]'s event rate from the stream's |
| 3452 | * tracked frontend counters or from the src. |
| 3453 | * Supports being called as "sc_gpc_rate(<gpc-idx>,<sc-idx>[,<table])" |
| 3454 | * or "src_gpc_rate(<gpc-idx>[,<table>])" only. |
| 3455 | * Value zero is returned if the key is new or gpc_rate is not stored. |
| 3456 | */ |
| 3457 | static int |
| 3458 | smp_fetch_sc_gpc_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3459 | { |
| 3460 | struct stkctr tmpstkctr; |
| 3461 | struct stkctr *stkctr; |
| 3462 | unsigned int idx; |
| 3463 | |
| 3464 | idx = args[0].data.sint; |
| 3465 | |
| 3466 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3467 | if (!stkctr) |
| 3468 | return 0; |
| 3469 | |
| 3470 | smp->flags = SMP_F_VOL_TEST; |
| 3471 | smp->data.type = SMP_T_SINT; |
| 3472 | smp->data.u.sint = 0; |
| 3473 | if (stkctr_entry(stkctr) != NULL) { |
| 3474 | void *ptr; |
| 3475 | |
| 3476 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3477 | if (!ptr) { |
| 3478 | if (stkctr == &tmpstkctr) |
| 3479 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3480 | return 0; /* parameter not stored */ |
| 3481 | } |
| 3482 | |
| 3483 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3484 | |
| 3485 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 3486 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 3487 | |
| 3488 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3489 | |
| 3490 | if (stkctr == &tmpstkctr) |
| 3491 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3492 | } |
| 3493 | return 1; |
| 3494 | } |
| 3495 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3496 | /* set <smp> to the General Purpose Counter 0's event rate from the stream's |
| 3497 | * tracked frontend counters or from the src. |
| 3498 | * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only. |
| 3499 | * Value zero is returned if the key is new. |
| 3500 | */ |
| 3501 | static int |
| 3502 | smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3503 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3504 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3505 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3506 | unsigned int period; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3507 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3508 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3509 | if (!stkctr) |
| 3510 | return 0; |
| 3511 | |
| 3512 | smp->flags = SMP_F_VOL_TEST; |
| 3513 | smp->data.type = SMP_T_SINT; |
| 3514 | smp->data.u.sint = 0; |
| 3515 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3516 | void *ptr; |
| 3517 | |
| 3518 | 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] | 3519 | if (ptr) { |
| 3520 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3521 | } |
| 3522 | else { |
| 3523 | /* fallback on the gpc array */ |
| 3524 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3525 | if (ptr) |
| 3526 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3527 | } |
| 3528 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3529 | if (!ptr) { |
| 3530 | if (stkctr == &tmpstkctr) |
| 3531 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3532 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3533 | } |
| 3534 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3535 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3536 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3537 | 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] | 3538 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3539 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3540 | |
| 3541 | if (stkctr == &tmpstkctr) |
| 3542 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3543 | } |
| 3544 | return 1; |
| 3545 | } |
| 3546 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3547 | /* set <smp> to the General Purpose Counter 1's event rate from the stream's |
| 3548 | * tracked frontend counters or from the src. |
| 3549 | * Supports being called as "sc[0-9]_gpc1_rate" or "src_gpc1_rate" only. |
| 3550 | * Value zero is returned if the key is new. |
| 3551 | */ |
| 3552 | static int |
| 3553 | smp_fetch_sc_gpc1_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3554 | { |
| 3555 | struct stkctr tmpstkctr; |
| 3556 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3557 | unsigned int period; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3558 | |
| 3559 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3560 | if (!stkctr) |
| 3561 | return 0; |
| 3562 | |
| 3563 | smp->flags = SMP_F_VOL_TEST; |
| 3564 | smp->data.type = SMP_T_SINT; |
| 3565 | smp->data.u.sint = 0; |
| 3566 | if (stkctr_entry(stkctr) != NULL) { |
| 3567 | void *ptr; |
| 3568 | |
| 3569 | 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] | 3570 | if (ptr) { |
| 3571 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3572 | } |
| 3573 | else { |
| 3574 | /* fallback on the gpc array */ |
| 3575 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3576 | if (ptr) |
| 3577 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3578 | } |
| 3579 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3580 | if (!ptr) { |
| 3581 | if (stkctr == &tmpstkctr) |
| 3582 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3583 | return 0; /* parameter not stored */ |
| 3584 | } |
| 3585 | |
| 3586 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3587 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3588 | 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] | 3589 | |
| 3590 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3591 | |
| 3592 | if (stkctr == &tmpstkctr) |
| 3593 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3594 | } |
| 3595 | return 1; |
| 3596 | } |
| 3597 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3598 | /* Increment the GPC[args(0)] value from the stream's tracked |
| 3599 | * frontend counters and return it into temp integer. |
| 3600 | * Supports being called as "sc_inc_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3601 | * or "src_inc_gpc(<gpc-idx>[,<table>])" only. |
| 3602 | */ |
| 3603 | static int |
| 3604 | smp_fetch_sc_inc_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3605 | { |
| 3606 | struct stkctr tmpstkctr; |
| 3607 | struct stkctr *stkctr; |
| 3608 | unsigned int idx; |
| 3609 | |
| 3610 | idx = args[0].data.sint; |
| 3611 | |
| 3612 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3613 | if (!stkctr) |
| 3614 | return 0; |
| 3615 | |
| 3616 | smp->flags = SMP_F_VOL_TEST; |
| 3617 | smp->data.type = SMP_T_SINT; |
| 3618 | smp->data.u.sint = 0; |
| 3619 | |
| 3620 | if (!stkctr_entry(stkctr)) |
| 3621 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3622 | |
| 3623 | if (stkctr && stkctr_entry(stkctr)) { |
| 3624 | void *ptr1,*ptr2; |
| 3625 | |
| 3626 | |
| 3627 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3628 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3629 | */ |
| 3630 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3631 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3632 | if (ptr1 || ptr2) { |
| 3633 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3634 | |
| 3635 | if (ptr1) { |
| 3636 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 3637 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, 1); |
| 3638 | smp->data.u.sint = (&stktable_data_cast(ptr1, std_t_frqp))->curr_ctr; |
| 3639 | } |
| 3640 | |
| 3641 | if (ptr2) |
| 3642 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
| 3643 | |
| 3644 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3645 | |
| 3646 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3647 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3648 | } |
| 3649 | else if (stkctr == &tmpstkctr) |
| 3650 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3651 | } |
| 3652 | return 1; |
| 3653 | } |
| 3654 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3655 | /* Increment the General Purpose Counter 0 value from the stream's tracked |
| 3656 | * frontend counters and return it into temp integer. |
| 3657 | * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. |
| 3658 | */ |
| 3659 | static int |
| 3660 | smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3661 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3662 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3663 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3664 | unsigned int period = 0; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3665 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3666 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3667 | if (!stkctr) |
| 3668 | return 0; |
| 3669 | |
| 3670 | smp->flags = SMP_F_VOL_TEST; |
| 3671 | smp->data.type = SMP_T_SINT; |
| 3672 | smp->data.u.sint = 0; |
| 3673 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3674 | if (!stkctr_entry(stkctr)) |
| 3675 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3676 | |
| 3677 | if (stkctr && stkctr_entry(stkctr)) { |
| 3678 | void *ptr1,*ptr2; |
| 3679 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3680 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3681 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3682 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3683 | */ |
| 3684 | 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] | 3685 | if (ptr1) { |
| 3686 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3687 | } |
| 3688 | else { |
| 3689 | /* fallback on the gpc array */ |
| 3690 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3691 | if (ptr1) |
| 3692 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3693 | } |
| 3694 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3695 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3696 | if (!ptr2) { |
| 3697 | /* fallback on the gpc array */ |
| 3698 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3699 | } |
| 3700 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3701 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3702 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3703 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3704 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3705 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3706 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3707 | 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] | 3708 | } |
| 3709 | |
| 3710 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3711 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3712 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3713 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3714 | |
| 3715 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3716 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3717 | } |
| 3718 | else if (stkctr == &tmpstkctr) |
| 3719 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3720 | } |
| 3721 | return 1; |
| 3722 | } |
| 3723 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3724 | /* Increment the General Purpose Counter 1 value from the stream's tracked |
| 3725 | * frontend counters and return it into temp integer. |
| 3726 | * Supports being called as "sc[0-9]_inc_gpc1" or "src_inc_gpc1" only. |
| 3727 | */ |
| 3728 | static int |
| 3729 | smp_fetch_sc_inc_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3730 | { |
| 3731 | struct stkctr tmpstkctr; |
| 3732 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3733 | unsigned int period = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3734 | |
| 3735 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3736 | if (!stkctr) |
| 3737 | return 0; |
| 3738 | |
| 3739 | smp->flags = SMP_F_VOL_TEST; |
| 3740 | smp->data.type = SMP_T_SINT; |
| 3741 | smp->data.u.sint = 0; |
| 3742 | |
| 3743 | if (!stkctr_entry(stkctr)) |
| 3744 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3745 | |
| 3746 | if (stkctr && stkctr_entry(stkctr)) { |
| 3747 | void *ptr1,*ptr2; |
| 3748 | |
| 3749 | |
| 3750 | /* First, update gpc1_rate if it's tracked. Second, update its |
| 3751 | * gpc1 if tracked. Returns gpc1's value otherwise the curr_ctr. |
| 3752 | */ |
| 3753 | 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] | 3754 | if (ptr1) { |
| 3755 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3756 | } |
| 3757 | else { |
| 3758 | /* fallback on the gpc array */ |
| 3759 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3760 | if (ptr1) |
| 3761 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3762 | } |
| 3763 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3764 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3765 | if (!ptr2) { |
| 3766 | /* fallback on the gpc array */ |
| 3767 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3768 | } |
| 3769 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3770 | if (ptr1 || ptr2) { |
| 3771 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3772 | |
| 3773 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3774 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3775 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3776 | 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] | 3777 | } |
| 3778 | |
| 3779 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3780 | 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] | 3781 | |
| 3782 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3783 | |
| 3784 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3785 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3786 | } |
| 3787 | else if (stkctr == &tmpstkctr) |
| 3788 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3789 | } |
| 3790 | return 1; |
| 3791 | } |
| 3792 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3793 | /* Clear the GPC[args(0)] value from the stream's tracked |
| 3794 | * frontend counters and return its previous value into temp integer. |
| 3795 | * Supports being called as "sc_clr_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3796 | * or "src_clr_gpc(<gpc-idx>[,<table>])" only. |
| 3797 | */ |
| 3798 | static int |
| 3799 | smp_fetch_sc_clr_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3800 | { |
| 3801 | struct stkctr tmpstkctr; |
| 3802 | struct stkctr *stkctr; |
| 3803 | unsigned int idx; |
| 3804 | |
| 3805 | idx = args[0].data.sint; |
| 3806 | |
| 3807 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3808 | if (!stkctr) |
| 3809 | return 0; |
| 3810 | |
| 3811 | smp->flags = SMP_F_VOL_TEST; |
| 3812 | smp->data.type = SMP_T_SINT; |
| 3813 | smp->data.u.sint = 0; |
| 3814 | |
| 3815 | if (!stkctr_entry(stkctr)) |
| 3816 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3817 | |
| 3818 | if (stkctr && stkctr_entry(stkctr)) { |
| 3819 | void *ptr; |
| 3820 | |
| 3821 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3822 | if (!ptr) { |
| 3823 | if (stkctr == &tmpstkctr) |
| 3824 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3825 | return 0; /* parameter not stored */ |
| 3826 | } |
| 3827 | |
| 3828 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3829 | |
| 3830 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3831 | stktable_data_cast(ptr, std_t_uint) = 0; |
| 3832 | |
| 3833 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3834 | |
| 3835 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3836 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3837 | } |
| 3838 | return 1; |
| 3839 | } |
| 3840 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3841 | /* Clear the General Purpose Counter 0 value from the stream's tracked |
| 3842 | * frontend counters and return its previous value into temp integer. |
| 3843 | * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only. |
| 3844 | */ |
| 3845 | static int |
| 3846 | smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3847 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3848 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3849 | struct stkctr *stkctr; |
| 3850 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3851 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3852 | if (!stkctr) |
| 3853 | return 0; |
| 3854 | |
| 3855 | smp->flags = SMP_F_VOL_TEST; |
| 3856 | smp->data.type = SMP_T_SINT; |
| 3857 | smp->data.u.sint = 0; |
| 3858 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3859 | if (!stkctr_entry(stkctr)) |
| 3860 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3861 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3862 | if (stkctr && stkctr_entry(stkctr)) { |
| 3863 | void *ptr; |
| 3864 | |
| 3865 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3866 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3867 | /* fallback on the gpc array */ |
| 3868 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3869 | } |
| 3870 | |
| 3871 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3872 | if (stkctr == &tmpstkctr) |
| 3873 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3874 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3875 | } |
| 3876 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3877 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3878 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3879 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3880 | stktable_data_cast(ptr, std_t_uint) = 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3881 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3882 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3883 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3884 | /* If data was modified, we need to touch to re-schedule sync */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3885 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3886 | } |
| 3887 | return 1; |
| 3888 | } |
| 3889 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3890 | /* Clear the General Purpose Counter 1 value from the stream's tracked |
| 3891 | * frontend counters and return its previous value into temp integer. |
| 3892 | * Supports being called as "sc[0-9]_clr_gpc1" or "src_clr_gpc1" only. |
| 3893 | */ |
| 3894 | static int |
| 3895 | smp_fetch_sc_clr_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3896 | { |
| 3897 | struct stkctr tmpstkctr; |
| 3898 | struct stkctr *stkctr; |
| 3899 | |
| 3900 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3901 | if (!stkctr) |
| 3902 | return 0; |
| 3903 | |
| 3904 | smp->flags = SMP_F_VOL_TEST; |
| 3905 | smp->data.type = SMP_T_SINT; |
| 3906 | smp->data.u.sint = 0; |
| 3907 | |
| 3908 | if (!stkctr_entry(stkctr)) |
| 3909 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3910 | |
| 3911 | if (stkctr && stkctr_entry(stkctr)) { |
| 3912 | void *ptr; |
| 3913 | |
| 3914 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3915 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3916 | /* fallback on the gpc array */ |
| 3917 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3918 | } |
| 3919 | |
| 3920 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3921 | if (stkctr == &tmpstkctr) |
| 3922 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3923 | return 0; /* parameter not stored */ |
| 3924 | } |
| 3925 | |
| 3926 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3927 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3928 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3929 | stktable_data_cast(ptr, std_t_uint) = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3930 | |
| 3931 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3932 | |
| 3933 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3934 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3935 | } |
| 3936 | return 1; |
| 3937 | } |
| 3938 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3939 | /* set <smp> to the cumulated number of connections from the stream's tracked |
| 3940 | * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or |
| 3941 | * "src_conn_cnt" only. |
| 3942 | */ |
| 3943 | static int |
| 3944 | smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3945 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3946 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3947 | struct stkctr *stkctr; |
| 3948 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3949 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3950 | if (!stkctr) |
| 3951 | return 0; |
| 3952 | |
| 3953 | smp->flags = SMP_F_VOL_TEST; |
| 3954 | smp->data.type = SMP_T_SINT; |
| 3955 | smp->data.u.sint = 0; |
| 3956 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3957 | void *ptr; |
| 3958 | |
| 3959 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); |
| 3960 | if (!ptr) { |
| 3961 | if (stkctr == &tmpstkctr) |
| 3962 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3963 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3964 | } |
| 3965 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3966 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3967 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3968 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3969 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3970 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3971 | |
| 3972 | if (stkctr == &tmpstkctr) |
| 3973 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3974 | |
| 3975 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3976 | } |
| 3977 | return 1; |
| 3978 | } |
| 3979 | |
| 3980 | /* set <smp> to the connection rate from the stream's tracked frontend |
| 3981 | * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate" |
| 3982 | * only. |
| 3983 | */ |
| 3984 | static int |
| 3985 | smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3986 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3987 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3988 | struct stkctr *stkctr; |
| 3989 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3990 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3991 | if (!stkctr) |
| 3992 | return 0; |
| 3993 | |
| 3994 | smp->flags = SMP_F_VOL_TEST; |
| 3995 | smp->data.type = SMP_T_SINT; |
| 3996 | smp->data.u.sint = 0; |
| 3997 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3998 | void *ptr; |
| 3999 | |
| 4000 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); |
| 4001 | if (!ptr) { |
| 4002 | if (stkctr == &tmpstkctr) |
| 4003 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4004 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4005 | } |
| 4006 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4007 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4008 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4009 | 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] | 4010 | stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4011 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4012 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4013 | |
| 4014 | if (stkctr == &tmpstkctr) |
| 4015 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4016 | } |
| 4017 | return 1; |
| 4018 | } |
| 4019 | |
| 4020 | /* set temp integer to the number of connections from the stream's source address |
| 4021 | * in the table pointed to by expr, after updating it. |
| 4022 | * Accepts exactly 1 argument of type table. |
| 4023 | */ |
| 4024 | static int |
| 4025 | smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4026 | { |
| 4027 | struct connection *conn = objt_conn(smp->sess->origin); |
| 4028 | struct stksess *ts; |
| 4029 | struct stktable_key *key; |
| 4030 | void *ptr; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4031 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4032 | |
| 4033 | if (!conn) |
| 4034 | return 0; |
| 4035 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 4036 | /* Fetch source address in a sample. */ |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 4037 | 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] | 4038 | return 0; |
| 4039 | |
| 4040 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4041 | key = smp_to_stkey(smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4042 | if (!key) |
| 4043 | return 0; |
| 4044 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4045 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4046 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4047 | if ((ts = stktable_get_entry(t, key)) == NULL) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4048 | /* entry does not exist and could not be created */ |
| 4049 | return 0; |
| 4050 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4051 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4052 | if (!ptr) { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4053 | return 0; /* parameter not stored in this table */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4054 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4055 | |
| 4056 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4057 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4058 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4059 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4060 | smp->data.u.sint = ++stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4061 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4062 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4063 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4064 | smp->flags = SMP_F_VOL_TEST; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4065 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4066 | stktable_touch_local(t, ts, 1); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4067 | |
| 4068 | /* Touch was previously performed by stktable_update_key */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4069 | return 1; |
| 4070 | } |
| 4071 | |
| 4072 | /* set <smp> to the number of concurrent connections from the stream's tracked |
| 4073 | * frontend counters. Supports being called as "sc[0-9]_conn_cur" or |
| 4074 | * "src_conn_cur" only. |
| 4075 | */ |
| 4076 | static int |
| 4077 | smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4078 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4079 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4080 | struct stkctr *stkctr; |
| 4081 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4082 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4083 | if (!stkctr) |
| 4084 | return 0; |
| 4085 | |
| 4086 | smp->flags = SMP_F_VOL_TEST; |
| 4087 | smp->data.type = SMP_T_SINT; |
| 4088 | smp->data.u.sint = 0; |
| 4089 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4090 | void *ptr; |
| 4091 | |
| 4092 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); |
| 4093 | if (!ptr) { |
| 4094 | if (stkctr == &tmpstkctr) |
| 4095 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4096 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4097 | } |
| 4098 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4099 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4100 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4101 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4102 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4103 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4104 | |
| 4105 | if (stkctr == &tmpstkctr) |
| 4106 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4107 | } |
| 4108 | return 1; |
| 4109 | } |
| 4110 | |
| 4111 | /* set <smp> to the cumulated number of streams from the stream's tracked |
| 4112 | * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or |
| 4113 | * "src_sess_cnt" only. |
| 4114 | */ |
| 4115 | static int |
| 4116 | smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4117 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4118 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4119 | struct stkctr *stkctr; |
| 4120 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4121 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4122 | if (!stkctr) |
| 4123 | return 0; |
| 4124 | |
| 4125 | smp->flags = SMP_F_VOL_TEST; |
| 4126 | smp->data.type = SMP_T_SINT; |
| 4127 | smp->data.u.sint = 0; |
| 4128 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4129 | void *ptr; |
| 4130 | |
| 4131 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); |
| 4132 | if (!ptr) { |
| 4133 | if (stkctr == &tmpstkctr) |
| 4134 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4135 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4136 | } |
| 4137 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4138 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4139 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4140 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4141 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4142 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4143 | |
| 4144 | if (stkctr == &tmpstkctr) |
| 4145 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4146 | } |
| 4147 | return 1; |
| 4148 | } |
| 4149 | |
| 4150 | /* set <smp> to the stream rate from the stream's tracked frontend counters. |
| 4151 | * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only. |
| 4152 | */ |
| 4153 | static int |
| 4154 | smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4155 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4156 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4157 | struct stkctr *stkctr; |
| 4158 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4159 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4160 | if (!stkctr) |
| 4161 | return 0; |
| 4162 | |
| 4163 | smp->flags = SMP_F_VOL_TEST; |
| 4164 | smp->data.type = SMP_T_SINT; |
| 4165 | smp->data.u.sint = 0; |
| 4166 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4167 | void *ptr; |
| 4168 | |
| 4169 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); |
| 4170 | if (!ptr) { |
| 4171 | if (stkctr == &tmpstkctr) |
| 4172 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4173 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4174 | } |
| 4175 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4176 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4177 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4178 | 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] | 4179 | stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4180 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4181 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4182 | |
| 4183 | if (stkctr == &tmpstkctr) |
| 4184 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4185 | } |
| 4186 | return 1; |
| 4187 | } |
| 4188 | |
| 4189 | /* set <smp> to the cumulated number of HTTP requests from the stream's tracked |
| 4190 | * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or |
| 4191 | * "src_http_req_cnt" only. |
| 4192 | */ |
| 4193 | static int |
| 4194 | smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4195 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4196 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4197 | struct stkctr *stkctr; |
| 4198 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4199 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4200 | if (!stkctr) |
| 4201 | return 0; |
| 4202 | |
| 4203 | smp->flags = SMP_F_VOL_TEST; |
| 4204 | smp->data.type = SMP_T_SINT; |
| 4205 | smp->data.u.sint = 0; |
| 4206 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4207 | void *ptr; |
| 4208 | |
| 4209 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
| 4210 | if (!ptr) { |
| 4211 | if (stkctr == &tmpstkctr) |
| 4212 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4213 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4214 | } |
| 4215 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4216 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4217 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4218 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4219 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4220 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4221 | |
| 4222 | if (stkctr == &tmpstkctr) |
| 4223 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4224 | } |
| 4225 | return 1; |
| 4226 | } |
| 4227 | |
| 4228 | /* set <smp> to the HTTP request rate from the stream's tracked frontend |
| 4229 | * counters. Supports being called as "sc[0-9]_http_req_rate" or |
| 4230 | * "src_http_req_rate" only. |
| 4231 | */ |
| 4232 | static int |
| 4233 | smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4234 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4235 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4236 | struct stkctr *stkctr; |
| 4237 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4238 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4239 | if (!stkctr) |
| 4240 | return 0; |
| 4241 | |
| 4242 | smp->flags = SMP_F_VOL_TEST; |
| 4243 | smp->data.type = SMP_T_SINT; |
| 4244 | smp->data.u.sint = 0; |
| 4245 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4246 | void *ptr; |
| 4247 | |
| 4248 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
| 4249 | if (!ptr) { |
| 4250 | if (stkctr == &tmpstkctr) |
| 4251 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4252 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4253 | } |
| 4254 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4255 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4256 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4257 | 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] | 4258 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4259 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4260 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4261 | |
| 4262 | if (stkctr == &tmpstkctr) |
| 4263 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4264 | } |
| 4265 | return 1; |
| 4266 | } |
| 4267 | |
| 4268 | /* set <smp> to the cumulated number of HTTP requests errors from the stream's |
| 4269 | * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or |
| 4270 | * "src_http_err_cnt" only. |
| 4271 | */ |
| 4272 | static int |
| 4273 | smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4274 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4275 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4276 | struct stkctr *stkctr; |
| 4277 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4278 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4279 | if (!stkctr) |
| 4280 | return 0; |
| 4281 | |
| 4282 | smp->flags = SMP_F_VOL_TEST; |
| 4283 | smp->data.type = SMP_T_SINT; |
| 4284 | smp->data.u.sint = 0; |
| 4285 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4286 | void *ptr; |
| 4287 | |
| 4288 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
| 4289 | if (!ptr) { |
| 4290 | if (stkctr == &tmpstkctr) |
| 4291 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4292 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4293 | } |
| 4294 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4295 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4296 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4297 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4298 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4299 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4300 | |
| 4301 | if (stkctr == &tmpstkctr) |
| 4302 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4303 | } |
| 4304 | return 1; |
| 4305 | } |
| 4306 | |
| 4307 | /* set <smp> to the HTTP request error rate from the stream's tracked frontend |
| 4308 | * counters. Supports being called as "sc[0-9]_http_err_rate" or |
| 4309 | * "src_http_err_rate" only. |
| 4310 | */ |
| 4311 | static int |
| 4312 | smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4313 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4314 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4315 | struct stkctr *stkctr; |
| 4316 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4317 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4318 | if (!stkctr) |
| 4319 | return 0; |
| 4320 | |
| 4321 | smp->flags = SMP_F_VOL_TEST; |
| 4322 | smp->data.type = SMP_T_SINT; |
| 4323 | smp->data.u.sint = 0; |
| 4324 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4325 | void *ptr; |
| 4326 | |
| 4327 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
| 4328 | if (!ptr) { |
| 4329 | if (stkctr == &tmpstkctr) |
| 4330 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4331 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4332 | } |
| 4333 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4334 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4335 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4336 | 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] | 4337 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4338 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4339 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4340 | |
| 4341 | if (stkctr == &tmpstkctr) |
| 4342 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4343 | } |
| 4344 | return 1; |
| 4345 | } |
| 4346 | |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4347 | /* set <smp> to the cumulated number of HTTP response failures from the stream's |
| 4348 | * tracked frontend counters. Supports being called as "sc[0-9]_http_fail_cnt" or |
| 4349 | * "src_http_fail_cnt" only. |
| 4350 | */ |
| 4351 | static int |
| 4352 | smp_fetch_sc_http_fail_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4353 | { |
| 4354 | struct stkctr tmpstkctr; |
| 4355 | struct stkctr *stkctr; |
| 4356 | |
| 4357 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4358 | if (!stkctr) |
| 4359 | return 0; |
| 4360 | |
| 4361 | smp->flags = SMP_F_VOL_TEST; |
| 4362 | smp->data.type = SMP_T_SINT; |
| 4363 | smp->data.u.sint = 0; |
| 4364 | if (stkctr_entry(stkctr) != NULL) { |
| 4365 | void *ptr; |
| 4366 | |
| 4367 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_CNT); |
| 4368 | if (!ptr) { |
| 4369 | if (stkctr == &tmpstkctr) |
| 4370 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4371 | return 0; /* parameter not stored */ |
| 4372 | } |
| 4373 | |
| 4374 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4375 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4376 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4377 | |
| 4378 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4379 | |
| 4380 | if (stkctr == &tmpstkctr) |
| 4381 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4382 | } |
| 4383 | return 1; |
| 4384 | } |
| 4385 | |
| 4386 | /* set <smp> to the HTTP response failure rate from the stream's tracked frontend |
| 4387 | * counters. Supports being called as "sc[0-9]_http_fail_rate" or |
| 4388 | * "src_http_fail_rate" only. |
| 4389 | */ |
| 4390 | static int |
| 4391 | smp_fetch_sc_http_fail_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4392 | { |
| 4393 | struct stkctr tmpstkctr; |
| 4394 | struct stkctr *stkctr; |
| 4395 | |
| 4396 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4397 | if (!stkctr) |
| 4398 | return 0; |
| 4399 | |
| 4400 | smp->flags = SMP_F_VOL_TEST; |
| 4401 | smp->data.type = SMP_T_SINT; |
| 4402 | smp->data.u.sint = 0; |
| 4403 | if (stkctr_entry(stkctr) != NULL) { |
| 4404 | void *ptr; |
| 4405 | |
| 4406 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_RATE); |
| 4407 | if (!ptr) { |
| 4408 | if (stkctr == &tmpstkctr) |
| 4409 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4410 | return 0; /* parameter not stored */ |
| 4411 | } |
| 4412 | |
| 4413 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4414 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4415 | 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] | 4416 | stkctr->table->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u); |
| 4417 | |
| 4418 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4419 | |
| 4420 | if (stkctr == &tmpstkctr) |
| 4421 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4422 | } |
| 4423 | return 1; |
| 4424 | } |
| 4425 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4426 | /* set <smp> to the number of kbytes received from clients, as found in the |
| 4427 | * stream's tracked frontend counters. Supports being called as |
| 4428 | * "sc[0-9]_kbytes_in" or "src_kbytes_in" only. |
| 4429 | */ |
| 4430 | static int |
| 4431 | smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4432 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4433 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4434 | struct stkctr *stkctr; |
| 4435 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4436 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4437 | if (!stkctr) |
| 4438 | return 0; |
| 4439 | |
| 4440 | smp->flags = SMP_F_VOL_TEST; |
| 4441 | smp->data.type = SMP_T_SINT; |
| 4442 | smp->data.u.sint = 0; |
| 4443 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4444 | void *ptr; |
| 4445 | |
| 4446 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
| 4447 | if (!ptr) { |
| 4448 | if (stkctr == &tmpstkctr) |
| 4449 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4450 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4451 | } |
| 4452 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4453 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4454 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4455 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4456 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4457 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4458 | |
| 4459 | if (stkctr == &tmpstkctr) |
| 4460 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4461 | } |
| 4462 | return 1; |
| 4463 | } |
| 4464 | |
| 4465 | /* set <smp> to the data rate received from clients in bytes/s, as found |
| 4466 | * in the stream's tracked frontend counters. Supports being called as |
| 4467 | * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only. |
| 4468 | */ |
| 4469 | static int |
| 4470 | smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4471 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4472 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4473 | struct stkctr *stkctr; |
| 4474 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4475 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4476 | if (!stkctr) |
| 4477 | return 0; |
| 4478 | |
| 4479 | smp->flags = SMP_F_VOL_TEST; |
| 4480 | smp->data.type = SMP_T_SINT; |
| 4481 | smp->data.u.sint = 0; |
| 4482 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4483 | void *ptr; |
| 4484 | |
| 4485 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
| 4486 | if (!ptr) { |
| 4487 | if (stkctr == &tmpstkctr) |
| 4488 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4489 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4490 | } |
| 4491 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4492 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4493 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4494 | 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] | 4495 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4496 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4497 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4498 | |
| 4499 | if (stkctr == &tmpstkctr) |
| 4500 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4501 | } |
| 4502 | return 1; |
| 4503 | } |
| 4504 | |
| 4505 | /* set <smp> to the number of kbytes sent to clients, as found in the |
| 4506 | * stream's tracked frontend counters. Supports being called as |
| 4507 | * "sc[0-9]_kbytes_out" or "src_kbytes_out" only. |
| 4508 | */ |
| 4509 | static int |
| 4510 | smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4511 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4512 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4513 | struct stkctr *stkctr; |
| 4514 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4515 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4516 | if (!stkctr) |
| 4517 | return 0; |
| 4518 | |
| 4519 | smp->flags = SMP_F_VOL_TEST; |
| 4520 | smp->data.type = SMP_T_SINT; |
| 4521 | smp->data.u.sint = 0; |
| 4522 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4523 | void *ptr; |
| 4524 | |
| 4525 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
| 4526 | if (!ptr) { |
| 4527 | if (stkctr == &tmpstkctr) |
| 4528 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4529 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4530 | } |
| 4531 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4532 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4533 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4534 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4535 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4536 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4537 | |
| 4538 | if (stkctr == &tmpstkctr) |
| 4539 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4540 | } |
| 4541 | return 1; |
| 4542 | } |
| 4543 | |
| 4544 | /* set <smp> to the data rate sent to clients in bytes/s, as found in the |
| 4545 | * stream's tracked frontend counters. Supports being called as |
| 4546 | * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. |
| 4547 | */ |
| 4548 | static int |
| 4549 | smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4550 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4551 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4552 | struct stkctr *stkctr; |
| 4553 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4554 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4555 | if (!stkctr) |
| 4556 | return 0; |
| 4557 | |
| 4558 | smp->flags = SMP_F_VOL_TEST; |
| 4559 | smp->data.type = SMP_T_SINT; |
| 4560 | smp->data.u.sint = 0; |
| 4561 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4562 | void *ptr; |
| 4563 | |
| 4564 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
| 4565 | if (!ptr) { |
| 4566 | if (stkctr == &tmpstkctr) |
| 4567 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4568 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4569 | } |
| 4570 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4571 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4572 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4573 | 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] | 4574 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4575 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4576 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4577 | |
| 4578 | if (stkctr == &tmpstkctr) |
| 4579 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4580 | } |
| 4581 | return 1; |
| 4582 | } |
| 4583 | |
| 4584 | /* set <smp> to the number of active trackers on the SC entry in the stream's |
| 4585 | * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only. |
| 4586 | */ |
| 4587 | static int |
| 4588 | smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4589 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4590 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4591 | struct stkctr *stkctr; |
| 4592 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4593 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4594 | if (!stkctr) |
| 4595 | return 0; |
| 4596 | |
| 4597 | smp->flags = SMP_F_VOL_TEST; |
| 4598 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4599 | if (stkctr == &tmpstkctr) { |
| 4600 | smp->data.u.sint = stkctr_entry(stkctr) ? (stkctr_entry(stkctr)->ref_cnt-1) : 0; |
| 4601 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4602 | } |
| 4603 | else { |
| 4604 | smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0; |
| 4605 | } |
| 4606 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4607 | return 1; |
| 4608 | } |
| 4609 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4610 | |
| 4611 | /* The functions below are used to manipulate table contents from the CLI. |
| 4612 | * There are 3 main actions, "clear", "set" and "show". The code is shared |
| 4613 | * between all actions, and the action is encoded in the void *private in |
| 4614 | * the appctx as well as in the keyword registration, among one of the |
| 4615 | * following values. |
| 4616 | */ |
| 4617 | |
| 4618 | enum { |
| 4619 | STK_CLI_ACT_CLR, |
| 4620 | STK_CLI_ACT_SET, |
| 4621 | STK_CLI_ACT_SHOW, |
| 4622 | }; |
| 4623 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4624 | /* Dump the status of a table to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4625 | * read buffer. It returns 0 if the output buffer is full |
| 4626 | * and needs to be called again, otherwise non-zero. |
| 4627 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4628 | static int table_dump_head_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4629 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4630 | struct stktable *t, struct stktable *target) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4631 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 4632 | struct stream *s = __sc_strm(appctx_sc(appctx)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4633 | |
| 4634 | 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] | 4635 | t->id, stktable_types[t->type].kw, t->size, t->current); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4636 | |
| 4637 | /* any other information should be dumped here */ |
| 4638 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 4639 | 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] | 4640 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
| 4641 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4642 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4643 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4644 | |
| 4645 | return 1; |
| 4646 | } |
| 4647 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4648 | /* Dump a table entry to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4649 | * read buffer. It returns 0 if the output buffer is full |
| 4650 | * and needs to be called again, otherwise non-zero. |
| 4651 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4652 | static int table_dump_entry_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4653 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4654 | struct stktable *t, struct stksess *entry) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4655 | { |
| 4656 | int dt; |
| 4657 | |
| 4658 | chunk_appendf(msg, "%p:", entry); |
| 4659 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4660 | if (t->type == SMP_T_IPV4) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4661 | char addr[INET_ADDRSTRLEN]; |
| 4662 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4663 | chunk_appendf(msg, " key=%s", addr); |
| 4664 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4665 | else if (t->type == SMP_T_IPV6) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4666 | char addr[INET6_ADDRSTRLEN]; |
| 4667 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4668 | chunk_appendf(msg, " key=%s", addr); |
| 4669 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4670 | else if (t->type == SMP_T_SINT) { |
Willy Tarreau | 6cde5d8 | 2020-02-25 09:41:22 +0100 | [diff] [blame] | 4671 | chunk_appendf(msg, " key=%u", read_u32(entry->key.key)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4672 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4673 | else if (t->type == SMP_T_STR) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4674 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4675 | dump_text(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4676 | } |
| 4677 | else { |
| 4678 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4679 | dump_binary(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4680 | } |
| 4681 | |
Willy Tarreau | 16b282f | 2022-11-29 11:55:18 +0100 | [diff] [blame] | 4682 | 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] | 4683 | |
| 4684 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 4685 | void *ptr; |
| 4686 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4687 | if (t->data_ofs[dt] == 0) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4688 | continue; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 4689 | if (stktable_data_types[dt].is_array) { |
| 4690 | char tmp[16] = {}; |
| 4691 | const char *name_pfx = stktable_data_types[dt].name; |
| 4692 | const char *name_sfx = NULL; |
| 4693 | unsigned int idx = 0; |
| 4694 | int i = 0; |
| 4695 | |
| 4696 | /* split name to show index before first _ of the name |
| 4697 | * for example: 'gpc3_rate' if array name is 'gpc_rate'. |
| 4698 | */ |
| 4699 | for (i = 0 ; i < (sizeof(tmp) - 1); i++) { |
| 4700 | if (!name_pfx[i]) |
| 4701 | break; |
| 4702 | if (name_pfx[i] == '_') { |
| 4703 | name_pfx = &tmp[0]; |
| 4704 | name_sfx = &stktable_data_types[dt].name[i]; |
| 4705 | break; |
| 4706 | } |
| 4707 | tmp[i] = name_pfx[i]; |
| 4708 | } |
| 4709 | |
| 4710 | ptr = stktable_data_ptr_idx(t, entry, dt, idx); |
| 4711 | while (ptr) { |
| 4712 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
| 4713 | chunk_appendf(msg, " %s%u%s(%u)=", name_pfx, idx, name_sfx ? name_sfx : "", t->data_arg[dt].u); |
| 4714 | else |
| 4715 | chunk_appendf(msg, " %s%u%s=", name_pfx, idx, name_sfx ? name_sfx : ""); |
| 4716 | switch (stktable_data_types[dt].std_type) { |
| 4717 | case STD_T_SINT: |
| 4718 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4719 | break; |
| 4720 | case STD_T_UINT: |
| 4721 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4722 | break; |
| 4723 | case STD_T_ULL: |
| 4724 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
| 4725 | break; |
| 4726 | case STD_T_FRQP: |
| 4727 | chunk_appendf(msg, "%u", |
| 4728 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 4729 | t->data_arg[dt].u)); |
| 4730 | break; |
| 4731 | } |
| 4732 | ptr = stktable_data_ptr_idx(t, entry, dt, ++idx); |
| 4733 | } |
| 4734 | continue; |
| 4735 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4736 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4737 | 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] | 4738 | else |
| 4739 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
| 4740 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4741 | ptr = stktable_data_ptr(t, entry, dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4742 | switch (stktable_data_types[dt].std_type) { |
| 4743 | case STD_T_SINT: |
| 4744 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4745 | break; |
| 4746 | case STD_T_UINT: |
| 4747 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4748 | break; |
| 4749 | case STD_T_ULL: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4750 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4751 | break; |
| 4752 | case STD_T_FRQP: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4753 | chunk_appendf(msg, "%u", |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4754 | 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] | 4755 | t->data_arg[dt].u)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4756 | break; |
Frédéric Lécaille | 16b4f54 | 2019-05-23 12:15:04 +0200 | [diff] [blame] | 4757 | case STD_T_DICT: { |
| 4758 | struct dict_entry *de; |
| 4759 | de = stktable_data_cast(ptr, std_t_dict); |
| 4760 | chunk_appendf(msg, "%s", de ? (char *)de->value.key : "-"); |
| 4761 | break; |
| 4762 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | chunk_appendf(msg, "\n"); |
| 4766 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4767 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4768 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4769 | |
| 4770 | return 1; |
| 4771 | } |
| 4772 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4773 | /* appctx context used by the "show table" command */ |
| 4774 | struct show_table_ctx { |
| 4775 | void *target; /* table we want to dump, or NULL for all */ |
| 4776 | struct stktable *t; /* table being currently dumped (first if NULL) */ |
| 4777 | struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ |
| 4778 | long long value[STKTABLE_FILTER_LEN]; /* value to compare against */ |
| 4779 | signed char data_type[STKTABLE_FILTER_LEN]; /* type of data to compare, or -1 if none */ |
| 4780 | 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] | 4781 | enum { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4782 | STATE_NEXT = 0, /* px points to next table, entry=NULL */ |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 4783 | STATE_DUMP, /* px points to curr table, entry is valid, refcount held */ |
| 4784 | STATE_DONE, /* done dumping */ |
| 4785 | } state; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4786 | char action; /* action on the table : one of STK_CLI_ACT_* */ |
| 4787 | }; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4788 | |
| 4789 | /* Processes a single table entry matching a specific key passed in argument. |
| 4790 | * returns 0 if wants to be called again, 1 if has ended processing. |
| 4791 | */ |
| 4792 | static int table_process_entry_per_key(struct appctx *appctx, char **args) |
| 4793 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4794 | struct show_table_ctx *ctx = appctx->svcctx; |
| 4795 | struct stktable *t = ctx->target; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4796 | struct stksess *ts; |
| 4797 | uint32_t uint32_key; |
| 4798 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
| 4799 | long long value; |
| 4800 | int data_type; |
| 4801 | int cur_arg; |
| 4802 | void *ptr; |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4803 | struct freq_ctr *frqp; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4804 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4805 | if (!*args[4]) |
| 4806 | return cli_err(appctx, "Key value expected\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4807 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4808 | switch (t->type) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4809 | case SMP_T_IPV4: |
Aurelien DARRAGON | deb4e5e | 2023-08-28 13:57:19 +0200 | [diff] [blame] | 4810 | if (inet_pton(AF_INET, args[4], &uint32_key) <= 0) |
| 4811 | return cli_err(appctx, "Invalid key\n"); |
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 | case SMP_T_IPV6: |
Christopher Faulet | b7c962b | 2021-11-15 09:17:25 +0100 | [diff] [blame] | 4815 | if (inet_pton(AF_INET6, args[4], ip6_key) <= 0) |
| 4816 | return cli_err(appctx, "Invalid key\n"); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4817 | static_table_key.key = &ip6_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4818 | break; |
| 4819 | case SMP_T_SINT: |
| 4820 | { |
| 4821 | char *endptr; |
| 4822 | unsigned long val; |
| 4823 | errno = 0; |
| 4824 | val = strtoul(args[4], &endptr, 10); |
| 4825 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 4826 | (errno != 0 && val == 0) || endptr == args[4] || |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4827 | val > 0xffffffff) |
| 4828 | return cli_err(appctx, "Invalid key\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4829 | uint32_key = (uint32_t) val; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4830 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4831 | break; |
| 4832 | } |
| 4833 | break; |
| 4834 | case SMP_T_STR: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4835 | static_table_key.key = args[4]; |
| 4836 | static_table_key.key_len = strlen(args[4]); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4837 | break; |
| 4838 | default: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4839 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4840 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4841 | 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] | 4842 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4843 | 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] | 4844 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4845 | 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] | 4846 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4847 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4848 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | /* check permissions */ |
| 4852 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 4853 | return 1; |
| 4854 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4855 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4856 | case STK_CLI_ACT_SHOW: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4857 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4858 | if (!ts) |
| 4859 | return 1; |
| 4860 | chunk_reset(&trash); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4861 | 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] | 4862 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4863 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4864 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4865 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4866 | if (!table_dump_entry_to_buffer(&trash, appctx, t, ts)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4867 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4868 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4869 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4870 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4871 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4872 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4873 | break; |
| 4874 | |
| 4875 | case STK_CLI_ACT_CLR: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4876 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4877 | if (!ts) |
| 4878 | return 1; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4879 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4880 | if (!stksess_kill(t, ts, 1)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4881 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4882 | return cli_err(appctx, "Entry currently in use, cannot remove\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4883 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4884 | break; |
| 4885 | |
| 4886 | case STK_CLI_ACT_SET: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4887 | ts = stktable_get_entry(t, &static_table_key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4888 | if (!ts) { |
| 4889 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4890 | return cli_err(appctx, "Unable to allocate a new entry\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4891 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4892 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4893 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 4894 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4895 | cli_err(appctx, "\"data.<type>\" followed by a value expected\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4896 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4897 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4898 | return 1; |
| 4899 | } |
| 4900 | |
| 4901 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 4902 | if (data_type < 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4903 | cli_err(appctx, "Unknown data type\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4904 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4905 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4906 | return 1; |
| 4907 | } |
| 4908 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4909 | if (!t->data_ofs[data_type]) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4910 | cli_err(appctx, "Data type not stored in this table\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4911 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4912 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4913 | return 1; |
| 4914 | } |
| 4915 | |
| 4916 | 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] | 4917 | cli_err(appctx, "Require a valid integer value to store\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4918 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4919 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4920 | return 1; |
| 4921 | } |
| 4922 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4923 | ptr = stktable_data_ptr(t, ts, data_type); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4924 | |
| 4925 | switch (stktable_data_types[data_type].std_type) { |
| 4926 | case STD_T_SINT: |
| 4927 | stktable_data_cast(ptr, std_t_sint) = value; |
| 4928 | break; |
| 4929 | case STD_T_UINT: |
| 4930 | stktable_data_cast(ptr, std_t_uint) = value; |
| 4931 | break; |
| 4932 | case STD_T_ULL: |
| 4933 | stktable_data_cast(ptr, std_t_ull) = value; |
| 4934 | break; |
| 4935 | case STD_T_FRQP: |
| 4936 | /* We set both the current and previous values. That way |
| 4937 | * the reported frequency is stable during all the period |
| 4938 | * then slowly fades out. This allows external tools to |
| 4939 | * push measures without having to update them too often. |
| 4940 | */ |
| 4941 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4942 | /* First bit is reserved for the freq_ctr lock |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4943 | Note: here we're still protected by the stksess lock |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4944 | so we don't need to update the update the freq_ctr |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4945 | using its internal lock */ |
| 4946 | frqp->curr_tick = now_ms & ~0x1; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4947 | frqp->prev_ctr = 0; |
| 4948 | frqp->curr_ctr = value; |
| 4949 | break; |
| 4950 | } |
| 4951 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4952 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4953 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4954 | break; |
| 4955 | |
| 4956 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4957 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4958 | } |
| 4959 | return 1; |
| 4960 | } |
| 4961 | |
| 4962 | /* Prepares the appctx fields with the data-based filters from the command line. |
| 4963 | * Returns 0 if the dump can proceed, 1 if has ended processing. |
| 4964 | */ |
| 4965 | static int table_prepare_data_request(struct appctx *appctx, char **args) |
| 4966 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4967 | struct show_table_ctx *ctx = appctx->svcctx; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4968 | int i; |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4969 | char *err = NULL; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4970 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4971 | 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] | 4972 | 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] | 4973 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4974 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
| 4975 | if (i > 0 && !*args[3+3*i]) // number of filter entries can be less than STKTABLE_FILTER_LEN |
| 4976 | break; |
| 4977 | /* condition on stored data value */ |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4978 | ctx->data_type[i] = stktable_get_data_type(args[3+3*i] + 5); |
| 4979 | if (ctx->data_type[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4980 | 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] | 4981 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4982 | if (!((struct stktable *)ctx->target)->data_ofs[ctx->data_type[i]]) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4983 | 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] | 4984 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4985 | ctx->data_op[i] = get_std_op(args[4+3*i]); |
| 4986 | if (ctx->data_op[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4987 | 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] | 4988 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4989 | 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] | 4990 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require a valid integer value to compare against\n", i + 1)); |
| 4991 | } |
| 4992 | |
| 4993 | if (*args[3+3*i]) { |
| 4994 | 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] | 4995 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4996 | |
| 4997 | /* OK we're done, all the fields are set */ |
| 4998 | return 0; |
| 4999 | } |
| 5000 | |
| 5001 | /* 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] | 5002 | 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] | 5003 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5004 | struct show_table_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5005 | int i; |
| 5006 | |
| 5007 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5008 | ctx->data_type[i] = -1; |
| 5009 | ctx->target = NULL; |
| 5010 | ctx->entry = NULL; |
| 5011 | ctx->action = (long)private; // keyword argument, one of STK_CLI_ACT_* |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5012 | |
| 5013 | if (*args[2]) { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5014 | ctx->t = ctx->target = stktable_find_by_name(args[2]); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5015 | if (!ctx->target) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5016 | return cli_err(appctx, "No such table\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5017 | } |
| 5018 | else { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5019 | ctx->t = stktables_list; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5020 | if (ctx->action != STK_CLI_ACT_SHOW) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5021 | goto err_args; |
| 5022 | return 0; |
| 5023 | } |
| 5024 | |
| 5025 | if (strcmp(args[3], "key") == 0) |
| 5026 | return table_process_entry_per_key(appctx, args); |
| 5027 | else if (strncmp(args[3], "data.", 5) == 0) |
| 5028 | return table_prepare_data_request(appctx, args); |
| 5029 | else if (*args[3]) |
| 5030 | goto err_args; |
| 5031 | |
| 5032 | return 0; |
| 5033 | |
| 5034 | err_args: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5035 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5036 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5037 | 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] | 5038 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5039 | 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] | 5040 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5041 | 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] | 5042 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5043 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5044 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | /* This function is used to deal with table operations (dump or clear depending |
| 5048 | * on the action stored in appctx->private). It returns 0 if the output buffer is |
| 5049 | * full and it needs to be called again, otherwise non-zero. |
| 5050 | */ |
| 5051 | static int cli_io_handler_table(struct appctx *appctx) |
| 5052 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5053 | struct show_table_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5054 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 475e463 | 2022-05-27 10:26:46 +0200 | [diff] [blame] | 5055 | struct stream *s = __sc_strm(sc); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5056 | struct ebmb_node *eb; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5057 | int skip_entry; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5058 | int show = ctx->action == STK_CLI_ACT_SHOW; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5059 | |
| 5060 | /* |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5061 | * We have 3 possible states in ctx->state : |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5062 | * - STATE_NEXT : the proxy pointer points to the next table to |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5063 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5064 | * - STATE_DUMP : the proxy pointer points to the current table |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5065 | * and the entry pointer points to the next entry to be dumped, |
| 5066 | * and the refcount on the next entry is held ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5067 | * - STATE_DONE : nothing left to dump, the buffer may contain some |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5068 | * data though. |
| 5069 | */ |
Christopher Faulet | 87633c3 | 2023-04-03 18:32:50 +0200 | [diff] [blame] | 5070 | /* FIXME: Don't watch the other side !*/ |
Christopher Faulet | 208c712 | 2023-04-13 16:16:15 +0200 | [diff] [blame] | 5071 | if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5072 | /* 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] | 5073 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5074 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5075 | } |
| 5076 | return 1; |
| 5077 | } |
| 5078 | |
| 5079 | chunk_reset(&trash); |
| 5080 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5081 | while (ctx->state != STATE_DONE) { |
| 5082 | switch (ctx->state) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5083 | case STATE_NEXT: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5084 | if (!ctx->t || |
| 5085 | (ctx->target && |
| 5086 | ctx->t != ctx->target)) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5087 | ctx->state = STATE_DONE; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5088 | break; |
| 5089 | } |
| 5090 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5091 | if (ctx->t->size) { |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5092 | 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] | 5093 | return 0; |
| 5094 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5095 | if (ctx->target && |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 5096 | (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5097 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5098 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5099 | eb = ebmb_first(&ctx->t->keys); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5100 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5101 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
| 5102 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5103 | ctx->state = STATE_DUMP; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5104 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5105 | break; |
| 5106 | } |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5107 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5108 | } |
| 5109 | } |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5110 | ctx->t = ctx->t->next; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5111 | break; |
| 5112 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5113 | case STATE_DUMP: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5114 | skip_entry = 0; |
| 5115 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5116 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5117 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5118 | if (ctx->data_type[0] >= 0) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5119 | /* we're filtering on some data contents */ |
| 5120 | void *ptr; |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5121 | int dt, i; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5122 | signed char op; |
| 5123 | long long data, value; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5124 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5125 | |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5126 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5127 | if (ctx->data_type[i] == -1) |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5128 | break; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5129 | dt = ctx->data_type[i]; |
| 5130 | ptr = stktable_data_ptr(ctx->t, |
| 5131 | ctx->entry, |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5132 | dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5133 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5134 | data = 0; |
| 5135 | switch (stktable_data_types[dt].std_type) { |
| 5136 | case STD_T_SINT: |
| 5137 | data = stktable_data_cast(ptr, std_t_sint); |
| 5138 | break; |
| 5139 | case STD_T_UINT: |
| 5140 | data = stktable_data_cast(ptr, std_t_uint); |
| 5141 | break; |
| 5142 | case STD_T_ULL: |
| 5143 | data = stktable_data_cast(ptr, std_t_ull); |
| 5144 | break; |
| 5145 | case STD_T_FRQP: |
| 5146 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5147 | ctx->t->data_arg[dt].u); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5148 | break; |
| 5149 | } |
| 5150 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5151 | op = ctx->data_op[i]; |
| 5152 | value = ctx->value[i]; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5153 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5154 | /* skip the entry if the data does not match the test and the value */ |
| 5155 | if ((data < value && |
| 5156 | (op == STD_OP_EQ || op == STD_OP_GT || op == STD_OP_GE)) || |
| 5157 | (data == value && |
| 5158 | (op == STD_OP_NE || op == STD_OP_GT || op == STD_OP_LT)) || |
| 5159 | (data > value && |
| 5160 | (op == STD_OP_EQ || op == STD_OP_LT || op == STD_OP_LE))) { |
| 5161 | skip_entry = 1; |
| 5162 | break; |
| 5163 | } |
| 5164 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | if (show && !skip_entry && |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5168 | !table_dump_entry_to_buffer(&trash, appctx, ctx->t, ctx->entry)) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5169 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5170 | return 0; |
| 5171 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5172 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5173 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5174 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5175 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5176 | ctx->entry->ref_cnt--; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5177 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5178 | eb = ebmb_next(&ctx->entry->key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5179 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5180 | struct stksess *old = ctx->entry; |
| 5181 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5182 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5183 | __stksess_kill_if_expired(ctx->t, old); |
| 5184 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5185 | __stksess_kill(ctx->t, old); |
| 5186 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5187 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5188 | break; |
| 5189 | } |
| 5190 | |
| 5191 | |
| 5192 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5193 | __stksess_kill_if_expired(ctx->t, ctx->entry); |
| 5194 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5195 | __stksess_kill(ctx->t, ctx->entry); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5196 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5197 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5198 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5199 | ctx->t = ctx->t->next; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5200 | ctx->state = STATE_NEXT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5201 | break; |
| 5202 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5203 | default: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5204 | break; |
| 5205 | } |
| 5206 | } |
| 5207 | return 1; |
| 5208 | } |
| 5209 | |
| 5210 | static void cli_release_show_table(struct appctx *appctx) |
| 5211 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5212 | struct show_table_ctx *ctx = appctx->svcctx; |
| 5213 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5214 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5215 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5216 | } |
| 5217 | } |
| 5218 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5219 | static int stk_parse_stick_counters(char **args, int section_type, struct proxy *curpx, |
| 5220 | const struct proxy *defpx, const char *file, int line, |
| 5221 | char **err) |
| 5222 | { |
| 5223 | char *error; |
| 5224 | int counters; |
| 5225 | |
| 5226 | counters = strtol(args[1], &error, 10); |
| 5227 | if (*error != 0) { |
| 5228 | memprintf(err, "%s: '%s' is an invalid number", args[0], args[1]); |
| 5229 | return -1; |
| 5230 | } |
| 5231 | |
| 5232 | if (counters < 0) { |
| 5233 | memprintf(err, "%s: the number of stick-counters may not be negative (was %d)", args[0], counters); |
| 5234 | return -1; |
| 5235 | } |
| 5236 | |
| 5237 | global.tune.nb_stk_ctr = counters; |
| 5238 | return 0; |
| 5239 | } |
| 5240 | |
| 5241 | /* This function creates the stk_ctr pools after the configuration parsing. It |
| 5242 | * returns 0 on success otherwise ERR_*. If nb_stk_ctr is 0, the pool remains |
| 5243 | * NULL. |
| 5244 | */ |
| 5245 | static int stkt_create_stk_ctr_pool(void) |
| 5246 | { |
| 5247 | if (!global.tune.nb_stk_ctr) |
| 5248 | return 0; |
| 5249 | |
| 5250 | pool_head_stk_ctr = create_pool("stk_ctr", sizeof(*((struct session*)0)->stkctr) * global.tune.nb_stk_ctr, MEM_F_SHARED); |
| 5251 | if (!pool_head_stk_ctr) { |
| 5252 | ha_alert("out of memory while creating the stick-counters pool.\n"); |
| 5253 | return ERR_ABORT; |
| 5254 | } |
| 5255 | return 0; |
| 5256 | } |
| 5257 | |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5258 | static void stkt_late_init(void) |
| 5259 | { |
| 5260 | struct sample_fetch *f; |
| 5261 | |
| 5262 | f = find_sample_fetch("src", strlen("src")); |
| 5263 | if (f) |
| 5264 | smp_fetch_src = f->process; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5265 | hap_register_post_check(stkt_create_stk_ctr_pool); |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | INITCALL0(STG_INIT, stkt_late_init); |
| 5269 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5270 | /* register cli keywords */ |
| 5271 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5272 | { { "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 }, |
| 5273 | { { "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 }, |
| 5274 | { { "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] | 5275 | {{},} |
| 5276 | }}; |
| 5277 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5278 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5279 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5280 | static struct action_kw_list tcp_conn_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5281 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5282 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5283 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5284 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5285 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5286 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5287 | { /* END */ } |
| 5288 | }}; |
| 5289 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5290 | INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws); |
| 5291 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5292 | static struct action_kw_list tcp_sess_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5293 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5294 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5295 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5296 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5297 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5298 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5299 | { /* END */ } |
| 5300 | }}; |
| 5301 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5302 | INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws); |
| 5303 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5304 | static struct action_kw_list tcp_req_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5305 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5306 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5307 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5308 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5309 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5310 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5311 | { /* END */ } |
| 5312 | }}; |
| 5313 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5314 | INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_kws); |
| 5315 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5316 | static struct action_kw_list tcp_res_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5317 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5318 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5319 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5320 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5321 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5322 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5323 | { /* END */ } |
| 5324 | }}; |
| 5325 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5326 | INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws); |
| 5327 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5328 | static struct action_kw_list http_req_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5329 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5330 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5331 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5332 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5333 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5334 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5335 | { /* END */ } |
| 5336 | }}; |
| 5337 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5338 | INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws); |
| 5339 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5340 | static struct action_kw_list http_res_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5341 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5342 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5343 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5344 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5345 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5346 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5347 | { /* END */ } |
| 5348 | }}; |
| 5349 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5350 | INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws); |
| 5351 | |
Christopher Faulet | a924804 | 2023-01-05 11:17:38 +0100 | [diff] [blame] | 5352 | static struct action_kw_list http_after_res_kws = { { }, { |
Aurelien DARRAGON | e2907c7 | 2023-03-17 11:28:58 +0100 | [diff] [blame] | 5353 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Christopher Faulet | a924804 | 2023-01-05 11:17:38 +0100 | [diff] [blame] | 5354 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5355 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5356 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5357 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5358 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5359 | { /* END */ } |
| 5360 | }}; |
| 5361 | |
| 5362 | INITCALL1(STG_REGISTER, http_after_res_keywords_register, &http_after_res_kws); |
| 5363 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5364 | /* Note: must not be declared <const> as its list will be overwritten. |
| 5365 | * Please take care of keeping this list alphabetically sorted. |
| 5366 | */ |
| 5367 | static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 5368 | { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5369 | { "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] | 5370 | { "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] | 5371 | { "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] | 5372 | { "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] | 5373 | { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5374 | { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5375 | { "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] | 5376 | { "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] | 5377 | { "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] | 5378 | { "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] | 5379 | { "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] | 5380 | { "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] | 5381 | { "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] | 5382 | { "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] | 5383 | { "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] | 5384 | { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5385 | { "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] | 5386 | { "sc_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5387 | { "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] | 5388 | { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5389 | { "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] | 5390 | { "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] | 5391 | { "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] | 5392 | { "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] | 5393 | { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5394 | { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5395 | { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5396 | { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5397 | { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5398 | { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5399 | { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5400 | { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5401 | { "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] | 5402 | { "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] | 5403 | { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5404 | { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5405 | { "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] | 5406 | { "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] | 5407 | { "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] | 5408 | { "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] | 5409 | { "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] | 5410 | { "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] | 5411 | { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5412 | { "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] | 5413 | { "sc0_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5414 | { "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] | 5415 | { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5416 | { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5417 | { "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] | 5418 | { "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] | 5419 | { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5420 | { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5421 | { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5422 | { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5423 | { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5424 | { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5425 | { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5426 | { "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] | 5427 | { "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] | 5428 | { "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] | 5429 | { "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] | 5430 | { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5431 | { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5432 | { "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] | 5433 | { "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] | 5434 | { "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] | 5435 | { "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] | 5436 | { "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] | 5437 | { "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] | 5438 | { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5439 | { "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] | 5440 | { "sc1_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5441 | { "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] | 5442 | { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5443 | { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5444 | { "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] | 5445 | { "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] | 5446 | { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5447 | { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5448 | { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5449 | { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5450 | { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5451 | { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5452 | { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5453 | { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5454 | { "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] | 5455 | { "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] | 5456 | { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5457 | { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5458 | { "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] | 5459 | { "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] | 5460 | { "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] | 5461 | { "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] | 5462 | { "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] | 5463 | { "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] | 5464 | { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5465 | { "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] | 5466 | { "sc2_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5467 | { "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] | 5468 | { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5469 | { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5470 | { "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] | 5471 | { "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] | 5472 | { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5473 | { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5474 | { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5475 | { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5476 | { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5477 | { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5478 | { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5479 | { "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] | 5480 | { "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] | 5481 | { "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] | 5482 | { "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] | 5483 | { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5484 | { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5485 | { "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] | 5486 | { "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] | 5487 | { "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] | 5488 | { "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] | 5489 | { "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] | 5490 | { "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] | 5491 | { "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] | 5492 | { "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] | 5493 | { "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] | 5494 | { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5495 | { "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] | 5496 | { "src_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5497 | { "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] | 5498 | { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5499 | { "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] | 5500 | { "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] | 5501 | { "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] | 5502 | { "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] | 5503 | { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5504 | { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5505 | { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5506 | { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5507 | { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5508 | { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5509 | { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5510 | { /* END */ }, |
| 5511 | }}; |
| 5512 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5513 | INITCALL1(STG_REGISTER, sample_register_fetches, &smp_fetch_keywords); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5514 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 5515 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 5516 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5517 | { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL }, |
| 5518 | { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5519 | { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5520 | { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5521 | { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5522 | { "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] | 5523 | { "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] | 5524 | { "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] | 5525 | { "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] | 5526 | { "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] | 5527 | { "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] | 5528 | { "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] | 5529 | { "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] | 5530 | { "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] | 5531 | { "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] | 5532 | { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5533 | { "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] | 5534 | { "table_http_fail_cnt", sample_conv_table_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5535 | { "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] | 5536 | { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5537 | { "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] | 5538 | { "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] | 5539 | { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5540 | { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5541 | { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5542 | { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5543 | { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5544 | { "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] | 5545 | { /* END */ }, |
| 5546 | }}; |
| 5547 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5548 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5549 | |
| 5550 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 5551 | { CFG_GLOBAL, "tune.stick-counters", stk_parse_stick_counters }, |
| 5552 | { /* END */ } |
| 5553 | }}; |
| 5554 | |
| 5555 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |