Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Stick tables management functions. |
| 3 | * |
| 4 | * Copyright 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 5 | * Copyright (C) 2010 Willy Tarreau <w@1wt.eu> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <string.h> |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 15 | #include <errno.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 16 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 17 | #include <import/ebmbtree.h> |
| 18 | #include <import/ebsttree.h> |
| 19 | #include <import/ebistree.h> |
| 20 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 21 | #include <haproxy/api.h> |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 22 | #include <haproxy/applet.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 23 | #include <haproxy/arg.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 24 | #include <haproxy/cfgparse.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 25 | #include <haproxy/cli.h> |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 26 | #include <haproxy/dict.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 27 | #include <haproxy/errors.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 28 | #include <haproxy/global.h> |
Willy Tarreau | c761f84 | 2020-06-04 11:40:28 +0200 | [diff] [blame] | 29 | #include <haproxy/http_rules.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 30 | #include <haproxy/list.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 31 | #include <haproxy/log.h> |
Willy Tarreau | 6131d6a | 2020-06-02 16:48:09 +0200 | [diff] [blame] | 32 | #include <haproxy/net_helper.h> |
Willy Tarreau | 3c2a7c2 | 2020-06-04 18:38:21 +0200 | [diff] [blame] | 33 | #include <haproxy/peers.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 34 | #include <haproxy/pool.h> |
| 35 | #include <haproxy/proto_tcp.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 36 | #include <haproxy/proxy.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 37 | #include <haproxy/sample.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 38 | #include <haproxy/sc_strm.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 39 | #include <haproxy/stats-t.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 40 | #include <haproxy/stconn.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 41 | #include <haproxy/stick_table.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 42 | #include <haproxy/stream.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 43 | #include <haproxy/task.h> |
Willy Tarreau | 8b550af | 2020-06-04 17:42:48 +0200 | [diff] [blame] | 44 | #include <haproxy/tcp_rules.h> |
Willy Tarreau | 9310f48 | 2021-10-06 16:18:40 +0200 | [diff] [blame] | 45 | #include <haproxy/ticks.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 46 | #include <haproxy/tools.h> |
Willy Tarreau | a472858 | 2022-11-24 07:35:17 +0100 | [diff] [blame] | 47 | #include <haproxy/xxhash.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 48 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 49 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 50 | /* structure used to return a table key built from a sample */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 51 | static THREAD_LOCAL struct stktable_key static_table_key; |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 52 | static int (*smp_fetch_src)(const struct arg *, struct sample *, const char *, void *); |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 53 | struct pool_head *pool_head_stk_ctr __read_mostly = NULL; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 54 | struct stktable *stktables_list; |
| 55 | struct eb_root stktable_by_name = EB_ROOT; |
| 56 | |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 57 | #define round_ptr_size(i) (((i) + (sizeof(void *) - 1)) &~ (sizeof(void *) - 1)) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 58 | |
| 59 | /* This function inserts stktable <t> into the tree of known stick-table. |
| 60 | * The stick-table ID is used as the storing key so it must already have |
| 61 | * been initialized. |
| 62 | */ |
| 63 | void stktable_store_name(struct stktable *t) |
| 64 | { |
| 65 | t->name.key = t->id; |
| 66 | ebis_insert(&stktable_by_name, &t->name); |
| 67 | } |
| 68 | |
| 69 | struct stktable *stktable_find_by_name(const char *name) |
| 70 | { |
| 71 | struct ebpt_node *node; |
| 72 | struct stktable *t; |
| 73 | |
| 74 | node = ebis_lookup(&stktable_by_name, name); |
| 75 | if (node) { |
| 76 | t = container_of(node, struct stktable, name); |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 77 | if (strcmp(t->id, name) == 0) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 78 | return t; |
| 79 | } |
| 80 | |
| 81 | return NULL; |
| 82 | } |
| 83 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 84 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 85 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 86 | * in table <t>. It's safe to call it under or out of a lock. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 87 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 88 | void __stksess_free(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 89 | { |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 90 | HA_ATOMIC_DEC(&t->current); |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 91 | pool_free(t->pool, (void *)ts - round_ptr_size(t->data_size)); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 95 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
| 96 | * in table <t>. |
| 97 | * This function locks the table |
| 98 | */ |
| 99 | void stksess_free(struct stktable *t, struct stksess *ts) |
| 100 | { |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 101 | void *data; |
| 102 | data = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_KEY); |
| 103 | if (data) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 104 | dict_entry_unref(&server_key_dict, stktable_data_cast(data, std_t_dict)); |
| 105 | stktable_data_cast(data, std_t_dict) = NULL; |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 106 | } |
Willy Tarreau | 8d3c333 | 2022-10-11 18:50:22 +0000 | [diff] [blame] | 107 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 108 | __stksess_free(t, ts); |
Willy Tarreau | 8d3c333 | 2022-10-11 18:50:22 +0000 | [diff] [blame] | 109 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 113 | * Kill an stksess (only if its ref_cnt is zero). |
| 114 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 115 | int __stksess_kill(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 116 | { |
| 117 | if (ts->ref_cnt) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 118 | return 0; |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 119 | |
| 120 | eb32_delete(&ts->exp); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 121 | eb32_delete(&ts->upd); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 122 | ebmb_delete(&ts->key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 123 | __stksess_free(t, ts); |
| 124 | return 1; |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 128 | * Decrease the refcount if decrefcnt is not 0. |
| 129 | * and try to kill the stksess |
| 130 | * This function locks the table |
| 131 | */ |
| 132 | int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt) |
| 133 | { |
| 134 | int ret; |
| 135 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 136 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 137 | if (decrefcnt) |
| 138 | ts->ref_cnt--; |
| 139 | ret = __stksess_kill(t, ts); |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 140 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 146 | * Initialize or update the key in the sticky session <ts> present in table <t> |
| 147 | * from the value present in <key>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 148 | */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 149 | void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 150 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 151 | if (t->type != SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 152 | memcpy(ts->key.key, key->key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 153 | else { |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 154 | memcpy(ts->key.key, key->key, MIN(t->key_size - 1, key->key_len)); |
| 155 | ts->key.key[MIN(t->key_size - 1, key->key_len)] = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 159 | /* return a shard number for key <key> of len <len> present in table <t>. This |
| 160 | * takes into account the presence or absence of a peers section with shards |
| 161 | * and the number of shards, the table's hash_seed, and of course the key. The |
| 162 | * caller must pass a valid <key> and <len>. The shard number to be used by the |
| 163 | * entry is returned (from 1 to nb_shards, otherwise 0 for none). |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 164 | */ |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 165 | int stktable_get_key_shard(struct stktable *t, const void *key, size_t len) |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 166 | { |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 167 | /* no peers section or no shards in the peers section */ |
| 168 | if (!t->peers.p || !t->peers.p->nb_shards) |
| 169 | return 0; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 170 | |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 171 | return XXH64(key, len, t->hash_seed) % t->peers.p->nb_shards + 1; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 172 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 173 | |
| 174 | /* |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 175 | * Set the shard for <key> key of <ts> sticky session attached to <t> stick table. |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 176 | * Use zero for stick-table without peers synchronisation. |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 177 | */ |
| 178 | static void stksess_setkey_shard(struct stktable *t, struct stksess *ts, |
| 179 | struct stktable_key *key) |
| 180 | { |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 181 | size_t keylen; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 182 | |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 183 | if (t->type == SMP_T_STR) |
| 184 | keylen = key->key_len; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 185 | else |
Willy Tarreau | d5cae6a | 2022-11-29 17:36:44 +0100 | [diff] [blame] | 186 | keylen = t->key_size; |
| 187 | |
| 188 | ts->shard = stktable_get_key_shard(t, key->key, keylen); |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 192 | * Init sticky session <ts> of table <t>. The data parts are cleared and <ts> |
| 193 | * is returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 194 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 195 | static struct stksess *__stksess_init(struct stktable *t, struct stksess * ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 196 | { |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 197 | memset((void *)ts - t->data_size, 0, t->data_size); |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 198 | ts->ref_cnt = 0; |
Willy Tarreau | e548a7a | 2022-11-29 16:08:35 +0100 | [diff] [blame] | 199 | ts->shard = 0; |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 200 | ts->key.node.leaf_p = NULL; |
| 201 | ts->exp.node.leaf_p = NULL; |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 202 | ts->upd.node.leaf_p = NULL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 203 | ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 204 | HA_RWLOCK_INIT(&ts->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 205 | return ts; |
| 206 | } |
| 207 | |
| 208 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 209 | * Trash oldest <to_batch> sticky sessions from table <t> |
Willy Tarreau | dfe7925 | 2020-11-03 17:47:41 +0100 | [diff] [blame] | 210 | * Returns number of trashed sticky sessions. It may actually trash less |
| 211 | * than expected if finding these requires too long a search time (e.g. |
| 212 | * most of them have ts->ref_cnt>0). |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 213 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 214 | int __stktable_trash_oldest(struct stktable *t, int to_batch) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 215 | { |
| 216 | struct stksess *ts; |
| 217 | struct eb32_node *eb; |
Willy Tarreau | dfe7925 | 2020-11-03 17:47:41 +0100 | [diff] [blame] | 218 | int max_search = to_batch * 2; // no more than 50% misses |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 219 | int batched = 0; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 220 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 221 | |
| 222 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 223 | |
| 224 | while (batched < to_batch) { |
| 225 | |
| 226 | if (unlikely(!eb)) { |
| 227 | /* we might have reached the end of the tree, typically because |
| 228 | * <now_ms> is in the first half and we're first scanning the last |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 229 | * half. Let's loop back to the beginning of the tree now if we |
| 230 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 231 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 232 | if (looped) |
| 233 | break; |
| 234 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 235 | eb = eb32_first(&t->exps); |
| 236 | if (likely(!eb)) |
| 237 | break; |
| 238 | } |
| 239 | |
Willy Tarreau | dfe7925 | 2020-11-03 17:47:41 +0100 | [diff] [blame] | 240 | if (--max_search < 0) |
| 241 | break; |
| 242 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 243 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 244 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 245 | eb = eb32_next(eb); |
| 246 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 247 | /* don't delete an entry which is currently referenced */ |
| 248 | if (ts->ref_cnt) |
| 249 | continue; |
| 250 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 251 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 252 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 253 | if (ts->expire != ts->exp.key) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 254 | if (!tick_isset(ts->expire)) |
| 255 | continue; |
| 256 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 257 | ts->exp.key = ts->expire; |
| 258 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 259 | |
Aleksey Ponomaryov | 5938021 | 2023-02-07 19:27:06 +0100 | [diff] [blame] | 260 | /* the update might have jumped beyond the next element, |
| 261 | * possibly causing a wrapping. We need to check whether |
| 262 | * the next element should be used instead. If the next |
| 263 | * element doesn't exist it means we're on the right |
| 264 | * side and have to check the first one then. If it |
| 265 | * exists and is closer, we must use it, otherwise we |
| 266 | * use the current one. |
| 267 | */ |
| 268 | if (!eb) |
| 269 | eb = eb32_first(&t->exps); |
| 270 | |
| 271 | if (!eb || tick_is_lt(ts->exp.key, eb->key)) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 272 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 273 | |
| 274 | continue; |
| 275 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 276 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 277 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 278 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 279 | eb32_delete(&ts->upd); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 280 | __stksess_free(t, ts); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 281 | batched++; |
| 282 | } |
| 283 | |
| 284 | return batched; |
| 285 | } |
| 286 | |
| 287 | /* |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 288 | * Trash oldest <to_batch> sticky sessions from table <t> |
| 289 | * Returns number of trashed sticky sessions. |
| 290 | * This function locks the table |
| 291 | */ |
| 292 | int stktable_trash_oldest(struct stktable *t, int to_batch) |
| 293 | { |
| 294 | int ret; |
| 295 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 296 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 297 | ret = __stktable_trash_oldest(t, to_batch); |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 298 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 299 | |
| 300 | return ret; |
| 301 | } |
| 302 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 303 | * Allocate and initialise a new sticky session. |
| 304 | * The new sticky session is returned or NULL in case of lack of memory. |
| 305 | * Sticky sessions should only be allocated this way, and must be freed using |
Willy Tarreau | a7b46b5 | 2013-04-11 16:55:37 +0200 | [diff] [blame] | 306 | * stksess_free(). Table <t>'s sticky session counter is increased. If <key> |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 307 | * is not NULL, it is assigned to the new session. It must be called unlocked |
| 308 | * as it may rely on a lock to trash older entries. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 309 | */ |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 310 | struct stksess *stksess_new(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 311 | { |
| 312 | struct stksess *ts; |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 313 | unsigned int current; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 314 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 315 | current = HA_ATOMIC_FETCH_ADD(&t->current, 1); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 316 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 317 | if (unlikely(current >= t->size)) { |
| 318 | /* the table was already full, we may have to purge entries */ |
| 319 | if (t->nopurge || !stktable_trash_oldest(t, (t->size >> 8) + 1)) { |
| 320 | HA_ATOMIC_DEC(&t->current); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 321 | return NULL; |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 322 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 323 | } |
| 324 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 325 | ts = pool_alloc(t->pool); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 326 | if (ts) { |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 327 | ts = (void *)ts + round_ptr_size(t->data_size); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 328 | __stksess_init(t, ts); |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 329 | if (key) { |
Willy Tarreau | a7b46b5 | 2013-04-11 16:55:37 +0200 | [diff] [blame] | 330 | stksess_setkey(t, ts, key); |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 331 | stksess_setkey_shard(t, ts, key); |
| 332 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | return ts; |
| 336 | } |
| 337 | |
| 338 | /* |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 339 | * Looks in table <t> for a sticky session matching key <key>. |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 340 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 341 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 342 | struct stksess *__stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 343 | { |
| 344 | struct ebmb_node *eb; |
| 345 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 346 | if (t->type == SMP_T_STR) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 347 | eb = ebst_lookup_len(&t->keys, key->key, key->key_len+1 < t->key_size ? key->key_len : t->key_size-1); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 348 | else |
| 349 | eb = ebmb_lookup(&t->keys, key->key, t->key_size); |
| 350 | |
| 351 | if (unlikely(!eb)) { |
| 352 | /* no session found */ |
| 353 | return NULL; |
| 354 | } |
| 355 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 356 | return ebmb_entry(eb, struct stksess, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 359 | /* |
| 360 | * Looks in table <t> for a sticky session matching key <key>. |
| 361 | * Returns pointer on requested sticky session or NULL if none was found. |
| 362 | * The refcount of the found entry is increased and this function |
| 363 | * is protected using the table lock |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 364 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 365 | struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 366 | { |
| 367 | struct stksess *ts; |
| 368 | |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 369 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 370 | ts = __stktable_lookup_key(t, key); |
| 371 | if (ts) |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 372 | HA_ATOMIC_INC(&ts->ref_cnt); |
| 373 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 374 | |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 375 | return ts; |
| 376 | } |
| 377 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 378 | /* |
| 379 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 380 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 381 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 382 | struct stksess *__stktable_lookup(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 383 | { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 384 | struct ebmb_node *eb; |
| 385 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 386 | if (t->type == SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 387 | eb = ebst_lookup(&(t->keys), (char *)ts->key.key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 388 | else |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 389 | eb = ebmb_lookup(&(t->keys), ts->key.key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 390 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 391 | if (unlikely(!eb)) |
| 392 | return NULL; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 393 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 394 | return ebmb_entry(eb, struct stksess, key); |
| 395 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 396 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 397 | /* |
| 398 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 399 | * Returns pointer on requested sticky session or NULL if none was found. |
| 400 | * The refcount of the found entry is increased and this function |
| 401 | * is protected using the table lock |
| 402 | */ |
| 403 | struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts) |
| 404 | { |
| 405 | struct stksess *lts; |
| 406 | |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 407 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 408 | lts = __stktable_lookup(t, ts); |
| 409 | if (lts) |
Willy Tarreau | a7d6a13 | 2022-10-11 15:42:54 +0200 | [diff] [blame] | 410 | HA_ATOMIC_INC(<s->ref_cnt); |
| 411 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 412 | |
| 413 | return lts; |
| 414 | } |
| 415 | |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 416 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 417 | * The table's expiration timer is updated if set. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 418 | * The node will be also inserted into the update tree if needed, at a position |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 419 | * depending if the update is a local or coming from a remote node. |
| 420 | * If <decrefcnt> is set, the ts entry's ref_cnt will be decremented. The table's |
| 421 | * write lock may be taken. |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 422 | */ |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 423 | void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local, int expire, int decrefcnt) |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 424 | { |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 425 | struct eb32_node * eb; |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 426 | int locked = 0; |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 427 | |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 428 | if (expire != HA_ATOMIC_LOAD(&ts->expire)) { |
| 429 | /* we'll need to set the expiration and to wake up the expiration timer .*/ |
| 430 | HA_ATOMIC_STORE(&ts->expire, expire); |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 431 | stktable_requeue_exp(t, ts); |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 432 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 433 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 434 | /* If sync is enabled */ |
| 435 | if (t->sync_task) { |
| 436 | if (local) { |
| 437 | /* If this entry is not in the tree |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 438 | * or not scheduled for at least one peer. |
| 439 | */ |
| 440 | if (!locked++) |
| 441 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
| 442 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 443 | if (!ts->upd.node.leaf_p |
| 444 | || (int)(t->commitupdate - ts->upd.key) >= 0 |
| 445 | || (int)(ts->upd.key - t->localupdate) >= 0) { |
| 446 | ts->upd.key = ++t->update; |
| 447 | t->localupdate = t->update; |
| 448 | eb32_delete(&ts->upd); |
| 449 | eb = eb32_insert(&t->updates, &ts->upd); |
| 450 | if (eb != &ts->upd) { |
| 451 | eb32_delete(eb); |
| 452 | eb32_insert(&t->updates, &ts->upd); |
| 453 | } |
Emeric Brun | aaf5860 | 2015-06-15 17:23:30 +0200 | [diff] [blame] | 454 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 455 | task_wakeup(t->sync_task, TASK_WOKEN_MSG); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 456 | } |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 457 | else { |
| 458 | /* If this entry is not in the tree */ |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 459 | if (!locked++) |
| 460 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
| 461 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 462 | if (!ts->upd.node.leaf_p) { |
| 463 | ts->upd.key= (++t->update)+(2147483648U); |
| 464 | eb = eb32_insert(&t->updates, &ts->upd); |
| 465 | if (eb != &ts->upd) { |
| 466 | eb32_delete(eb); |
| 467 | eb32_insert(&t->updates, &ts->upd); |
| 468 | } |
| 469 | } |
| 470 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 471 | } |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 472 | |
Willy Tarreau | a7536ef | 2022-10-11 18:31:04 +0000 | [diff] [blame] | 473 | if (decrefcnt) { |
| 474 | if (locked) |
| 475 | ts->ref_cnt--; |
| 476 | else { |
| 477 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
| 478 | HA_ATOMIC_DEC(&ts->ref_cnt); |
| 479 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | if (locked) |
| 484 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 487 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 488 | * The table's expiration timer is updated using the date of expiration coming from |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 489 | * <t> stick-table configuration. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 490 | * The node will be also inserted into the update tree if needed, at a position |
| 491 | * considering the update is coming from a remote node |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 492 | */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 493 | void stktable_touch_remote(struct stktable *t, struct stksess *ts, int decrefcnt) |
| 494 | { |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 495 | stktable_touch_with_exp(t, ts, 0, ts->expire, decrefcnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 499 | * The table's expiration timer is updated using the date of expiration coming from |
| 500 | * <t> stick-table configuration. |
| 501 | * The node will be also inserted into the update tree if needed, at a position |
| 502 | * considering the update was made locally |
| 503 | */ |
| 504 | void stktable_touch_local(struct stktable *t, struct stksess *ts, int decrefcnt) |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 505 | { |
| 506 | int expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
| 507 | |
Willy Tarreau | 9f5cb43 | 2022-10-11 18:17:58 +0000 | [diff] [blame] | 508 | stktable_touch_with_exp(t, ts, 1, expire, decrefcnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 509 | } |
Willy Tarreau | 4be073b | 2022-10-11 18:10:27 +0000 | [diff] [blame] | 510 | /* Just decrease the ref_cnt of the current session. Does nothing if <ts> is NULL. |
| 511 | * Note that we still need to take the read lock because a number of other places |
| 512 | * (including in Lua and peers) update the ref_cnt non-atomically under the write |
| 513 | * lock. |
| 514 | */ |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 515 | static void stktable_release(struct stktable *t, struct stksess *ts) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 516 | { |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 517 | if (!ts) |
| 518 | return; |
Willy Tarreau | 4be073b | 2022-10-11 18:10:27 +0000 | [diff] [blame] | 519 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); |
| 520 | HA_ATOMIC_DEC(&ts->ref_cnt); |
| 521 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 524 | /* Insert new sticky session <ts> in the table. It is assumed that it does not |
| 525 | * yet exist (the caller must check this). The table's timeout is updated if it |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 526 | * is set. <ts> is returned if properly inserted, otherwise the one already |
| 527 | * present if any. |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 528 | */ |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 529 | struct stksess *__stktable_store(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 530 | { |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 531 | struct ebmb_node *eb; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 532 | |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 533 | eb = ebmb_insert(&t->keys, &ts->key, t->key_size); |
| 534 | if (likely(eb == &ts->key)) { |
| 535 | ts->exp.key = ts->expire; |
| 536 | eb32_insert(&t->exps, &ts->exp); |
| 537 | } |
Willy Tarreau | d2d3fd9 | 2022-10-11 15:09:46 +0200 | [diff] [blame] | 538 | return ebmb_entry(eb, struct stksess, key); // most commonly this is <ts> |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 541 | /* requeues the table's expiration task to take the recently added <ts> into |
| 542 | * account. This is performed atomically and doesn't require any lock. |
| 543 | */ |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 544 | void stktable_requeue_exp(struct stktable *t, const struct stksess *ts) |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 545 | { |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 546 | int old_exp, new_exp; |
| 547 | int expire = ts->expire; |
| 548 | |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 549 | if (!t->expire) |
| 550 | return; |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 551 | |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 552 | /* set the task's expire to the newest expiration date. */ |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 553 | old_exp = HA_ATOMIC_LOAD(&t->exp_task->expire); |
Willy Tarreau | 3238f79 | 2022-11-14 17:54:07 +0100 | [diff] [blame] | 554 | new_exp = tick_first(expire, old_exp); |
| 555 | |
| 556 | /* let's not go further if we're already up to date */ |
| 557 | if (new_exp == old_exp) |
| 558 | return; |
| 559 | |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 560 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
| 561 | |
Willy Tarreau | 3238f79 | 2022-11-14 17:54:07 +0100 | [diff] [blame] | 562 | while (new_exp != old_exp && |
| 563 | !HA_ATOMIC_CAS(&t->exp_task->expire, &old_exp, new_exp)) { |
| 564 | __ha_cpu_relax(); |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 565 | new_exp = tick_first(expire, old_exp); |
Willy Tarreau | 3238f79 | 2022-11-14 17:54:07 +0100 | [diff] [blame] | 566 | } |
Willy Tarreau | dbae89e | 2022-10-12 10:00:50 +0000 | [diff] [blame] | 567 | |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 568 | task_queue(t->exp_task); |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 569 | |
| 570 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Willy Tarreau | eb23e3e | 2022-10-12 09:56:08 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 573 | /* Returns a valid or initialized stksess for the specified stktable_key in the |
| 574 | * specified table, or NULL if the key was NULL, or if no entry was found nor |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 575 | * could be created. The entry's expiration is updated. This function locks the |
| 576 | * table, and the refcount of the entry is increased. |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 577 | */ |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 578 | struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 579 | { |
Willy Tarreau | 175aa06 | 2022-10-11 15:13:46 +0200 | [diff] [blame] | 580 | struct stksess *ts, *ts2; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 581 | |
| 582 | if (!key) |
| 583 | return NULL; |
| 584 | |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 585 | ts = stktable_lookup_key(table, key); |
| 586 | if (ts) |
| 587 | return ts; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 588 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 589 | /* No such entry exists, let's try to create a new one. this doesn't |
| 590 | * require locking yet. |
| 591 | */ |
| 592 | |
| 593 | ts = stksess_new(table, key); |
| 594 | if (!ts) |
| 595 | return NULL; |
| 596 | |
| 597 | /* Now we're certain to have a ts. We need to store it. For this we'll |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 598 | * need an exclusive access. We don't need an atomic upgrade, this is |
| 599 | * rare and an unlock+lock sequence will do the job fine. Given that |
| 600 | * this will not be atomic, the missing entry might appear in the mean |
| 601 | * tome so we have to be careful that the one we try to insert is the |
| 602 | * one we find. |
| 603 | */ |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 604 | |
Willy Tarreau | 996f1a5 | 2022-10-11 16:19:35 +0200 | [diff] [blame] | 605 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &table->lock); |
Willy Tarreau | 47f2297 | 2022-10-11 15:22:42 +0200 | [diff] [blame] | 606 | |
| 607 | ts2 = __stktable_store(table, ts); |
| 608 | if (unlikely(ts2 != ts)) { |
| 609 | /* another entry was added in the mean time, let's |
| 610 | * switch to it. |
| 611 | */ |
| 612 | __stksess_free(table, ts); |
| 613 | ts = ts2; |
| 614 | } |
| 615 | |
| 616 | HA_ATOMIC_INC(&ts->ref_cnt); |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 617 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &table->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 618 | |
Willy Tarreau | cbdb528 | 2022-10-12 10:04:01 +0000 | [diff] [blame] | 619 | stktable_requeue_exp(table, ts); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 620 | return ts; |
| 621 | } |
| 622 | |
| 623 | /* Lookup for an entry with the same key and store the submitted |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 624 | * stksess if not found. This function locks the table either shared or |
| 625 | * exclusively, and the refcount of the entry is increased. |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 626 | */ |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 627 | struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 628 | { |
| 629 | struct stksess *ts; |
| 630 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 631 | HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &table->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 632 | ts = __stktable_lookup(table, nts); |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 633 | if (ts) { |
| 634 | HA_ATOMIC_INC(&ts->ref_cnt); |
| 635 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &table->lock); |
| 636 | return ts; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 637 | } |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 638 | ts = nts; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 639 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 640 | /* let's increment it before switching to exclusive */ |
| 641 | HA_ATOMIC_INC(&ts->ref_cnt); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 642 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 643 | if (HA_RWLOCK_TRYRDTOSK(STK_TABLE_LOCK, &table->lock) != 0) { |
| 644 | /* upgrade to seek lock failed, let's drop and take */ |
| 645 | HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &table->lock); |
| 646 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &table->lock); |
| 647 | } |
| 648 | else |
| 649 | HA_RWLOCK_SKTOWR(STK_TABLE_LOCK, &table->lock); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 650 | |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 651 | /* now we're write-locked */ |
| 652 | |
| 653 | __stktable_store(table, ts); |
| 654 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &table->lock); |
Willy Tarreau | cbdb528 | 2022-10-12 10:04:01 +0000 | [diff] [blame] | 655 | |
| 656 | stktable_requeue_exp(table, ts); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 657 | return ts; |
| 658 | } |
Willy Tarreau | e628852 | 2022-10-12 09:13:14 +0000 | [diff] [blame] | 659 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 660 | /* |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 661 | * Task processing function to trash expired sticky sessions. A pointer to the |
| 662 | * task itself is returned since it never dies. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 663 | */ |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 664 | struct task *process_table_expire(struct task *task, void *context, unsigned int state) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 665 | { |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 666 | struct stktable *t = context; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 667 | struct stksess *ts; |
| 668 | struct eb32_node *eb; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 669 | int looped = 0; |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 670 | int exp_next; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 671 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 672 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 673 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 674 | |
| 675 | while (1) { |
| 676 | if (unlikely(!eb)) { |
| 677 | /* we might have reached the end of the tree, typically because |
| 678 | * <now_ms> is in the first half and we're first scanning the last |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 679 | * half. Let's loop back to the beginning of the tree now if we |
| 680 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 681 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 682 | if (looped) |
| 683 | break; |
| 684 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 685 | eb = eb32_first(&t->exps); |
| 686 | if (likely(!eb)) |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | if (likely(tick_is_lt(now_ms, eb->key))) { |
| 691 | /* timer not expired yet, revisit it later */ |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 692 | exp_next = eb->key; |
Willy Tarreau | 4d5f13c | 2017-11-05 11:04:47 +0100 | [diff] [blame] | 693 | goto out_unlock; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 697 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 698 | eb = eb32_next(eb); |
| 699 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 700 | /* don't delete an entry which is currently referenced */ |
| 701 | if (ts->ref_cnt) |
| 702 | continue; |
| 703 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 704 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 705 | |
| 706 | if (!tick_is_expired(ts->expire, now_ms)) { |
| 707 | if (!tick_isset(ts->expire)) |
| 708 | continue; |
| 709 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 710 | ts->exp.key = ts->expire; |
| 711 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 712 | |
Aleksey Ponomaryov | 5938021 | 2023-02-07 19:27:06 +0100 | [diff] [blame] | 713 | /* the update might have jumped beyond the next element, |
| 714 | * possibly causing a wrapping. We need to check whether |
| 715 | * the next element should be used instead. If the next |
| 716 | * element doesn't exist it means we're on the right |
| 717 | * side and have to check the first one then. If it |
| 718 | * exists and is closer, we must use it, otherwise we |
| 719 | * use the current one. |
| 720 | */ |
| 721 | if (!eb) |
| 722 | eb = eb32_first(&t->exps); |
| 723 | |
| 724 | if (!eb || tick_is_lt(ts->exp.key, eb->key)) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 725 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 726 | continue; |
| 727 | } |
| 728 | |
| 729 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 730 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 731 | eb32_delete(&ts->upd); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 732 | __stksess_free(t, ts); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /* We have found no task to expire in any tree */ |
Willy Tarreau | 6342714 | 2022-11-14 17:33:02 +0100 | [diff] [blame] | 736 | exp_next = TICK_ETERNITY; |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 737 | |
Willy Tarreau | 4d5f13c | 2017-11-05 11:04:47 +0100 | [diff] [blame] | 738 | out_unlock: |
Willy Tarreau | fbb934d | 2022-11-14 18:02:44 +0100 | [diff] [blame] | 739 | task->expire = exp_next; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 740 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 741 | return task; |
| 742 | } |
| 743 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 744 | /* Perform minimal stick table intializations, report 0 in case of error, 1 if OK. */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 745 | int stktable_init(struct stktable *t) |
| 746 | { |
Remi Tricot-Le Breton | 208ff01 | 2021-05-12 17:39:04 +0200 | [diff] [blame] | 747 | int peers_retval = 0; |
Willy Tarreau | 56460ee | 2022-11-28 18:53:06 +0100 | [diff] [blame] | 748 | |
| 749 | t->hash_seed = XXH64(t->id, t->idlen, 0); |
| 750 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 751 | if (t->size) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 752 | t->keys = EB_ROOT_UNIQUE; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 753 | memset(&t->exps, 0, sizeof(t->exps)); |
Emeric Brun | 1c6235d | 2015-12-16 15:28:12 +0100 | [diff] [blame] | 754 | t->updates = EB_ROOT_UNIQUE; |
Amaury Denoyelle | 3e06488 | 2022-10-12 16:47:59 +0200 | [diff] [blame] | 755 | HA_RWLOCK_INIT(&t->lock); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 756 | |
Olivier Houchard | 52dabbc | 2018-11-14 17:54:36 +0100 | [diff] [blame] | 757 | t->pool = create_pool("sticktables", sizeof(struct stksess) + round_ptr_size(t->data_size) + t->key_size, MEM_F_SHARED); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 758 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 759 | if ( t->expire ) { |
Willy Tarreau | beeabf5 | 2021-10-01 18:23:30 +0200 | [diff] [blame] | 760 | t->exp_task = task_new_anywhere(); |
Willy Tarreau | 848522f | 2018-10-15 11:12:15 +0200 | [diff] [blame] | 761 | if (!t->exp_task) |
| 762 | return 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 763 | t->exp_task->process = process_table_expire; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 764 | t->exp_task->context = (void *)t; |
| 765 | } |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 766 | if (t->peers.p && t->peers.p->peers_fe && !(t->peers.p->peers_fe->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) { |
Remi Tricot-Le Breton | 208ff01 | 2021-05-12 17:39:04 +0200 | [diff] [blame] | 767 | peers_retval = peers_register_table(t->peers.p, t); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 768 | } |
| 769 | |
Remi Tricot-Le Breton | 208ff01 | 2021-05-12 17:39:04 +0200 | [diff] [blame] | 770 | return (t->pool != NULL) && !peers_retval; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 771 | } |
| 772 | return 1; |
| 773 | } |
| 774 | |
| 775 | /* |
| 776 | * Configuration keywords of known table types |
| 777 | */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 778 | struct stktable_type stktable_types[SMP_TYPES] = { |
| 779 | [SMP_T_SINT] = { "integer", 0, 4 }, |
| 780 | [SMP_T_IPV4] = { "ip", 0, 4 }, |
| 781 | [SMP_T_IPV6] = { "ipv6", 0, 16 }, |
| 782 | [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 }, |
| 783 | [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 } |
| 784 | }; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * Parse table type configuration. |
| 788 | * Returns 0 on successful parsing, else 1. |
| 789 | * <myidx> is set at next configuration <args> index. |
| 790 | */ |
| 791 | int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size) |
| 792 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 793 | for (*type = 0; *type < SMP_TYPES; (*type)++) { |
| 794 | if (!stktable_types[*type].kw) |
| 795 | continue; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 796 | if (strcmp(args[*myidx], stktable_types[*type].kw) != 0) |
| 797 | continue; |
| 798 | |
| 799 | *key_size = stktable_types[*type].default_size; |
| 800 | (*myidx)++; |
| 801 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 802 | if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 803 | if (strcmp("len", args[*myidx]) == 0) { |
| 804 | (*myidx)++; |
| 805 | *key_size = atol(args[*myidx]); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 806 | if (!*key_size) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 807 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 808 | if (*type == SMP_T_STR) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 809 | /* null terminated string needs +1 for '\0'. */ |
| 810 | (*key_size)++; |
| 811 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 812 | (*myidx)++; |
| 813 | } |
| 814 | } |
| 815 | return 0; |
| 816 | } |
| 817 | return 1; |
| 818 | } |
| 819 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 820 | /* reserve some space for data type <type>, there is 2 optionnals |
| 821 | * argument at <sa> and <sa2> to configure this data type and |
| 822 | * they can be NULL if unused for a given type. |
| 823 | * Returns PE_NONE (0) if OK or an error code among : |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 824 | * - PE_ENUM_OOR if <type> does not exist |
| 825 | * - PE_EXIST if <type> is already registered |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 826 | * - PE_ARG_NOT_USE if <sa>/<sa2> was provided but not expected |
| 827 | * - PE_ARG_MISSING if <sa>/<sa2> was expected but not provided |
| 828 | * - 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] | 829 | */ |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 830 | int stktable_alloc_data_type(struct stktable *t, int type, const char *sa, const char *sa2) |
| 831 | |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 832 | { |
| 833 | if (type >= STKTABLE_DATA_TYPES) |
| 834 | return PE_ENUM_OOR; |
| 835 | |
| 836 | if (t->data_ofs[type]) |
| 837 | /* already allocated */ |
| 838 | return PE_EXIST; |
| 839 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 840 | t->data_nbelem[type] = 1; |
| 841 | if (stktable_data_types[type].is_array) { |
| 842 | /* arrays take their element count on first argument */ |
| 843 | if (!sa) |
| 844 | return PE_ARG_MISSING; |
| 845 | t->data_nbelem[type] = atoi(sa); |
| 846 | if (!t->data_nbelem[type] || (t->data_nbelem[type] > STKTABLE_MAX_DT_ARRAY_SIZE)) |
| 847 | return PE_ARG_VALUE_OOR; |
| 848 | sa = sa2; |
| 849 | } |
| 850 | |
Willy Tarreau | 3b63ca2 | 2021-05-08 14:10:42 +0200 | [diff] [blame] | 851 | switch (stktable_data_types[type].arg_type) { |
| 852 | case ARG_T_NONE: |
| 853 | if (sa) |
| 854 | return PE_ARG_NOT_USED; |
| 855 | break; |
| 856 | case ARG_T_INT: |
| 857 | if (!sa) |
| 858 | return PE_ARG_MISSING; |
| 859 | t->data_arg[type].i = atoi(sa); |
| 860 | break; |
| 861 | case ARG_T_DELAY: |
| 862 | if (!sa) |
| 863 | return PE_ARG_MISSING; |
| 864 | sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS); |
| 865 | if (sa) |
| 866 | return PE_ARG_INVC; /* invalid char */ |
| 867 | break; |
| 868 | } |
| 869 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 870 | 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] | 871 | t->data_ofs[type] = -t->data_size; |
| 872 | return PE_NONE; |
| 873 | } |
| 874 | |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 875 | /* |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 876 | * Parse a line with <linenum> as number in <file> configuration file to configure |
| 877 | * the stick-table with <t> as address and <id> as ID. |
| 878 | * <peers> provides the "peers" section pointer only if this function is called |
| 879 | * from a "peers" section. |
| 880 | * <nid> is the stick-table name which is sent over the network. It must be equal |
| 881 | * to <id> if this stick-table is parsed from a proxy section, and prefixed by <peers> |
| 882 | * "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] | 883 | * 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] | 884 | * Return an error status with ERR_* flags set if required, 0 if no error was encountered. |
| 885 | */ |
| 886 | 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] | 887 | 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] | 888 | { |
| 889 | int err_code = 0; |
| 890 | int idx = 1; |
| 891 | unsigned int val; |
| 892 | |
| 893 | if (!id || !*id) { |
| 894 | ha_alert("parsing [%s:%d] : %s: ID not provided.\n", file, linenum, args[0]); |
| 895 | err_code |= ERR_ALERT | ERR_ABORT; |
| 896 | goto out; |
| 897 | } |
| 898 | |
| 899 | /* Store the "peers" section if this function is called from a "peers" section. */ |
| 900 | if (peers) { |
| 901 | t->peers.p = peers; |
| 902 | idx++; |
| 903 | } |
| 904 | |
| 905 | t->id = id; |
Frédéric Lécaille | 36d1565 | 2022-10-17 14:58:19 +0200 | [diff] [blame] | 906 | t->idlen = strlen(id); |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 907 | t->nid = nid; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 908 | t->type = (unsigned int)-1; |
| 909 | t->conf.file = file; |
| 910 | t->conf.line = linenum; |
| 911 | |
| 912 | while (*args[idx]) { |
| 913 | const char *err; |
| 914 | |
| 915 | if (strcmp(args[idx], "size") == 0) { |
| 916 | idx++; |
| 917 | if (!*(args[idx])) { |
| 918 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 919 | file, linenum, args[0], args[idx-1]); |
| 920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 921 | goto out; |
| 922 | } |
| 923 | if ((err = parse_size_err(args[idx], &t->size))) { |
| 924 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 925 | file, linenum, args[0], *err, args[idx-1]); |
| 926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 927 | goto out; |
| 928 | } |
| 929 | idx++; |
| 930 | } |
| 931 | /* This argument does not exit in "peers" section. */ |
| 932 | else if (!peers && strcmp(args[idx], "peers") == 0) { |
| 933 | idx++; |
| 934 | if (!*(args[idx])) { |
| 935 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 936 | file, linenum, args[0], args[idx-1]); |
| 937 | err_code |= ERR_ALERT | ERR_FATAL; |
| 938 | goto out; |
| 939 | } |
| 940 | t->peers.name = strdup(args[idx++]); |
| 941 | } |
| 942 | else if (strcmp(args[idx], "expire") == 0) { |
| 943 | idx++; |
| 944 | if (!*(args[idx])) { |
| 945 | ha_alert("parsing [%s:%d] : %s: missing argument after '%s'.\n", |
| 946 | file, linenum, args[0], args[idx-1]); |
| 947 | err_code |= ERR_ALERT | ERR_FATAL; |
| 948 | goto out; |
| 949 | } |
| 950 | err = parse_time_err(args[idx], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 951 | if (err == PARSE_TIME_OVER) { |
| 952 | ha_alert("parsing [%s:%d]: %s: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 953 | file, linenum, args[0], args[idx], args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 955 | goto out; |
| 956 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 957 | else if (err == PARSE_TIME_UNDER) { |
| 958 | ha_alert("parsing [%s:%d]: %s: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 959 | file, linenum, args[0], args[idx], args[idx-1]); |
| 960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 961 | goto out; |
| 962 | } |
| 963 | else if (err) { |
| 964 | ha_alert("parsing [%s:%d] : %s: unexpected character '%c' in argument of '%s'.\n", |
| 965 | file, linenum, args[0], *err, args[idx-1]); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 967 | goto out; |
| 968 | } |
| 969 | t->expire = val; |
| 970 | idx++; |
| 971 | } |
| 972 | else if (strcmp(args[idx], "nopurge") == 0) { |
| 973 | t->nopurge = 1; |
| 974 | idx++; |
| 975 | } |
| 976 | else if (strcmp(args[idx], "type") == 0) { |
| 977 | idx++; |
| 978 | if (stktable_parse_type(args, &idx, &t->type, &t->key_size) != 0) { |
| 979 | ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n", |
| 980 | file, linenum, args[0], args[idx]); |
| 981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 982 | goto out; |
| 983 | } |
| 984 | /* idx already points to next arg */ |
| 985 | } |
| 986 | else if (strcmp(args[idx], "store") == 0) { |
| 987 | int type, err; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 988 | char *cw, *nw, *sa, *sa2; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 989 | |
| 990 | idx++; |
| 991 | nw = args[idx]; |
| 992 | while (*nw) { |
| 993 | /* the "store" keyword supports a comma-separated list */ |
| 994 | cw = nw; |
| 995 | sa = NULL; /* store arg */ |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 996 | sa2 = NULL; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 997 | while (*nw && *nw != ',') { |
| 998 | if (*nw == '(') { |
| 999 | *nw = 0; |
| 1000 | sa = ++nw; |
| 1001 | while (*nw != ')') { |
| 1002 | if (!*nw) { |
| 1003 | ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 1004 | file, linenum, args[0], cw); |
| 1005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1006 | goto out; |
| 1007 | } |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1008 | if (*nw == ',') { |
| 1009 | *nw = '\0'; |
| 1010 | sa2 = nw + 1; |
| 1011 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1012 | nw++; |
| 1013 | } |
| 1014 | *nw = '\0'; |
| 1015 | } |
| 1016 | nw++; |
| 1017 | } |
| 1018 | if (*nw) |
| 1019 | *nw++ = '\0'; |
| 1020 | type = stktable_get_data_type(cw); |
| 1021 | if (type < 0) { |
| 1022 | ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 1023 | file, linenum, args[0], cw); |
| 1024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1025 | goto out; |
| 1026 | } |
| 1027 | |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1028 | err = stktable_alloc_data_type(t, type, sa, sa2); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1029 | switch (err) { |
| 1030 | case PE_NONE: break; |
| 1031 | case PE_EXIST: |
| 1032 | ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 1033 | file, linenum, args[0], cw); |
| 1034 | err_code |= ERR_WARN; |
| 1035 | break; |
| 1036 | |
| 1037 | case PE_ARG_MISSING: |
| 1038 | ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 1039 | file, linenum, args[0], cw); |
| 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1041 | goto out; |
| 1042 | |
| 1043 | case PE_ARG_NOT_USED: |
| 1044 | ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 1045 | file, linenum, args[0], cw); |
| 1046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1047 | goto out; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 1048 | case PE_ARG_VALUE_OOR: |
| 1049 | ha_alert("parsing [%s:%d] : %s: array size is out of allowed range (1-%d) for store option '%s'.\n", |
| 1050 | file, linenum, args[0], STKTABLE_MAX_DT_ARRAY_SIZE, cw); |
| 1051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1052 | goto out; |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1053 | |
| 1054 | default: |
| 1055 | ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 1056 | file, linenum, args[0], cw); |
| 1057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | } |
| 1061 | idx++; |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 1062 | if (t->data_ofs[STKTABLE_DT_GPT] && t->data_ofs[STKTABLE_DT_GPT0]) { |
| 1063 | ha_alert("parsing [%s:%d] : %s: simultaneous usage of 'gpt' and 'gpt0' in a same table is not permitted as 'gpt' overrides 'gpt0'.\n", |
| 1064 | file, linenum, args[0]); |
| 1065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1066 | goto out; |
| 1067 | } |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1068 | else if (t->data_ofs[STKTABLE_DT_GPC] && (t->data_ofs[STKTABLE_DT_GPC0] || t->data_ofs[STKTABLE_DT_GPC1])) { |
| 1069 | 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", |
| 1070 | file, linenum, args[0]); |
| 1071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | else if (t->data_ofs[STKTABLE_DT_GPC_RATE] && (t->data_ofs[STKTABLE_DT_GPC0_RATE] || t->data_ofs[STKTABLE_DT_GPC1_RATE])) { |
| 1075 | 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", |
| 1076 | file, linenum, args[0]); |
| 1077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1078 | goto out; |
| 1079 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1080 | } |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 1081 | else if (strcmp(args[idx], "srvkey") == 0) { |
| 1082 | char *keytype; |
| 1083 | idx++; |
| 1084 | keytype = args[idx]; |
| 1085 | if (strcmp(keytype, "name") == 0) { |
| 1086 | t->server_key_type = STKTABLE_SRV_NAME; |
| 1087 | } |
| 1088 | else if (strcmp(keytype, "addr") == 0) { |
| 1089 | t->server_key_type = STKTABLE_SRV_ADDR; |
| 1090 | } |
| 1091 | else { |
| 1092 | ha_alert("parsing [%s:%d] : %s : unknown server key type '%s'.\n", |
| 1093 | file, linenum, args[0], keytype); |
| 1094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1095 | goto out; |
| 1096 | |
| 1097 | } |
| 1098 | idx++; |
| 1099 | } |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1100 | else { |
| 1101 | ha_alert("parsing [%s:%d] : %s: unknown argument '%s'.\n", |
| 1102 | file, linenum, args[0], args[idx]); |
| 1103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1104 | goto out; |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | if (!t->size) { |
| 1109 | ha_alert("parsing [%s:%d] : %s: missing size.\n", |
| 1110 | file, linenum, args[0]); |
| 1111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1112 | goto out; |
| 1113 | } |
| 1114 | |
| 1115 | if (t->type == (unsigned int)-1) { |
| 1116 | ha_alert("parsing [%s:%d] : %s: missing type.\n", |
| 1117 | file, linenum, args[0]); |
| 1118 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1119 | goto out; |
| 1120 | } |
| 1121 | |
| 1122 | out: |
| 1123 | return err_code; |
| 1124 | } |
| 1125 | |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1126 | /* 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] | 1127 | * Note that the sample *is* modified and that the returned key may point |
| 1128 | * 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] | 1129 | * Returns NULL if the sample could not be converted (eg: no matching type), |
| 1130 | * otherwise a pointer to the static stktable_key filled with what is needed |
| 1131 | * for the lookup. |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1132 | */ |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1133 | struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1134 | { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1135 | /* Convert sample. */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1136 | if (!sample_convert(smp, t->type)) |
Willy Tarreau | 7fc1c6e | 2012-04-26 11:03:17 +0200 | [diff] [blame] | 1137 | return NULL; |
| 1138 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1139 | /* Fill static_table_key. */ |
| 1140 | switch (t->type) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1141 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1142 | case SMP_T_IPV4: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1143 | static_table_key.key = &smp->data.u.ipv4; |
| 1144 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1145 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1146 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1147 | case SMP_T_IPV6: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1148 | static_table_key.key = &smp->data.u.ipv6; |
| 1149 | static_table_key.key_len = 16; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1150 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1151 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1152 | case SMP_T_SINT: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1153 | /* The stick table require a 32bit unsigned int, "sint" is a |
| 1154 | * signed 64 it, so we can convert it inplace. |
| 1155 | */ |
Willy Tarreau | 28c63c1 | 2019-10-23 06:21:05 +0200 | [diff] [blame] | 1156 | smp->data.u.sint = (unsigned int)smp->data.u.sint; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1157 | static_table_key.key = &smp->data.u.sint; |
| 1158 | static_table_key.key_len = 4; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1159 | break; |
| 1160 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1161 | case SMP_T_STR: |
Willy Tarreau | ce6955e | 2016-08-09 11:59:12 +0200 | [diff] [blame] | 1162 | if (!smp_make_safe(smp)) |
| 1163 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1164 | static_table_key.key = smp->data.u.str.area; |
| 1165 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1166 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1167 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1168 | case SMP_T_BIN: |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1169 | if (smp->data.u.str.data < t->key_size) { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1170 | /* This type needs padding with 0. */ |
Willy Tarreau | f65c6c0 | 2016-08-09 12:08:41 +0200 | [diff] [blame] | 1171 | if (!smp_make_rw(smp)) |
| 1172 | return NULL; |
| 1173 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1174 | if (smp->data.u.str.size < t->key_size) |
| 1175 | if (!smp_dup(smp)) |
| 1176 | return NULL; |
| 1177 | if (smp->data.u.str.size < t->key_size) |
| 1178 | return NULL; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1179 | memset(smp->data.u.str.area + smp->data.u.str.data, 0, |
| 1180 | t->key_size - smp->data.u.str.data); |
| 1181 | smp->data.u.str.data = t->key_size; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1182 | } |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1183 | static_table_key.key = smp->data.u.str.area; |
| 1184 | static_table_key.key_len = smp->data.u.str.data; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1185 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1186 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1187 | default: /* impossible case. */ |
| 1188 | return NULL; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1189 | } |
| 1190 | |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 1191 | return &static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /* |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1195 | * Process a fetch + format conversion as defined by the sample expression <expr> |
| 1196 | * on request or response considering the <opt> parameter. Returns either NULL if |
| 1197 | * no key could be extracted, or a pointer to the converted result stored in |
| 1198 | * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset |
| 1199 | * 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] | 1200 | * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present |
| 1201 | * without SMP_OPT_FINAL). The output will be usable like this : |
| 1202 | * |
| 1203 | * return MAY_CHANGE FINAL Meaning for the sample |
| 1204 | * NULL 0 * Not present and will never be (eg: header) |
| 1205 | * NULL 1 0 Not present or unstable, could change (eg: req_len) |
| 1206 | * NULL 1 1 Not present, will not change anymore |
| 1207 | * smp 0 * Present and will not change (eg: header) |
| 1208 | * smp 1 0 not possible |
| 1209 | * smp 1 1 Present, last known value (eg: request length) |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1210 | */ |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1211 | 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] | 1212 | unsigned int opt, struct sample_expr *expr, struct sample *smp) |
| 1213 | { |
| 1214 | if (smp) |
| 1215 | memset(smp, 0, sizeof(*smp)); |
| 1216 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1217 | smp = sample_process(px, sess, strm, opt, expr, smp); |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 1218 | if (!smp) |
| 1219 | return NULL; |
| 1220 | |
| 1221 | if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
| 1222 | return NULL; /* we can only use stable samples */ |
| 1223 | |
| 1224 | return smp_to_stkey(smp, t); |
| 1225 | } |
| 1226 | |
| 1227 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1228 | * 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] | 1229 | * type <table_type>, otherwise zero. Used in configuration check. |
| 1230 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1231 | int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1232 | { |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1233 | int out_type; |
| 1234 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1235 | if (table_type >= SMP_TYPES || !stktable_types[table_type].kw) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1236 | return 0; |
| 1237 | |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1238 | out_type = smp_expr_output_type(expr); |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1239 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 1240 | /* Convert sample. */ |
| 1241 | if (!sample_casts[out_type][table_type]) |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 1242 | return 0; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1243 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1244 | return 1; |
| 1245 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 1246 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1247 | /* Extra data types processing : after the last one, some room may remain |
| 1248 | * before STKTABLE_DATA_TYPES that may be used to register extra data types |
| 1249 | * at run time. |
| 1250 | */ |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1251 | struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = { |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1252 | [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT }, |
Thierry FOURNIER | 3cf1111 | 2015-07-28 08:57:05 +0200 | [diff] [blame] | 1253 | [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 1254 | [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT }, |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 1255 | [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] | 1256 | [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT }, |
| 1257 | [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] | 1258 | [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] | 1259 | [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT }, |
| 1260 | [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1261 | [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT }, |
| 1262 | [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1263 | [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT }, |
| 1264 | [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1265 | [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL }, |
| 1266 | [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 1267 | [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL }, |
| 1268 | [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] | 1269 | [STKTABLE_DT_GPC1] = { .name = "gpc1", .std_type = STD_T_UINT }, |
| 1270 | [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] | 1271 | [STKTABLE_DT_SERVER_KEY] = { .name = "server_key", .std_type = STD_T_DICT }, |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 1272 | [STKTABLE_DT_HTTP_FAIL_CNT] = { .name = "http_fail_cnt", .std_type = STD_T_UINT }, |
| 1273 | [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] | 1274 | [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] | 1275 | [STKTABLE_DT_GPC] = { .name = "gpc", .std_type = STD_T_UINT, .is_array = 1 }, |
| 1276 | [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] | 1277 | }; |
| 1278 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1279 | /* Registers stick-table extra data type with index <idx>, name <name>, type |
| 1280 | * <std_type> and arg type <arg_type>. If the index is negative, the next free |
| 1281 | * index is automatically allocated. The allocated index is returned, or -1 if |
| 1282 | * no free index was found or <name> was already registered. The <name> is used |
| 1283 | * directly as a pointer, so if it's not stable, the caller must allocate it. |
| 1284 | */ |
| 1285 | int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type) |
| 1286 | { |
| 1287 | if (idx < 0) { |
| 1288 | for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) { |
| 1289 | if (!stktable_data_types[idx].name) |
| 1290 | break; |
| 1291 | |
| 1292 | if (strcmp(stktable_data_types[idx].name, name) == 0) |
| 1293 | return -1; |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | if (idx >= STKTABLE_DATA_TYPES) |
| 1298 | return -1; |
| 1299 | |
| 1300 | if (stktable_data_types[idx].name != NULL) |
| 1301 | return -1; |
| 1302 | |
| 1303 | stktable_data_types[idx].name = name; |
| 1304 | stktable_data_types[idx].std_type = std_type; |
| 1305 | stktable_data_types[idx].arg_type = arg_type; |
| 1306 | return idx; |
| 1307 | } |
| 1308 | |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1309 | /* |
| 1310 | * Returns the data type number for the stktable_data_type whose name is <name>, |
| 1311 | * or <0 if not found. |
| 1312 | */ |
| 1313 | int stktable_get_data_type(char *name) |
| 1314 | { |
| 1315 | int type; |
| 1316 | |
| 1317 | for (type = 0; type < STKTABLE_DATA_TYPES; type++) { |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 1318 | if (!stktable_data_types[type].name) |
| 1319 | continue; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1320 | if (strcmp(name, stktable_data_types[type].name) == 0) |
| 1321 | return type; |
| 1322 | } |
Thayne McCombs | 92149f9 | 2020-11-20 01:28:26 -0700 | [diff] [blame] | 1323 | /* For backwards compatibility */ |
| 1324 | if (strcmp(name, "server_name") == 0) |
| 1325 | return STKTABLE_DT_SERVER_KEY; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 1326 | return -1; |
| 1327 | } |
| 1328 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1329 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1330 | * it up into this table. Returns true if found, false otherwise. The input |
| 1331 | * type is STR so that input samples are converted to string (since all types |
| 1332 | * can be converted to strings), then the function casts the string again into |
| 1333 | * the table's type. This is a double conversion, but in the future we might |
| 1334 | * support automatic input types to perform the cast on the fly. |
| 1335 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1336 | 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] | 1337 | { |
| 1338 | struct stktable *t; |
| 1339 | struct stktable_key *key; |
| 1340 | struct stksess *ts; |
| 1341 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1342 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1343 | |
| 1344 | key = smp_to_stkey(smp, t); |
| 1345 | if (!key) |
| 1346 | return 0; |
| 1347 | |
| 1348 | ts = stktable_lookup_key(t, key); |
| 1349 | |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1350 | smp->data.type = SMP_T_BOOL; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1351 | smp->data.u.sint = !!ts; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1352 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 43e9035 | 2018-06-27 06:25:57 +0200 | [diff] [blame] | 1353 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1354 | return 1; |
| 1355 | } |
| 1356 | |
| 1357 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1358 | * it up into this table. Returns the data rate received from clients in bytes/s |
| 1359 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1360 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1361 | * <not found> is returned. |
| 1362 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1363 | 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] | 1364 | { |
| 1365 | struct stktable *t; |
| 1366 | struct stktable_key *key; |
| 1367 | struct stksess *ts; |
| 1368 | void *ptr; |
| 1369 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1370 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1371 | |
| 1372 | key = smp_to_stkey(smp, t); |
| 1373 | if (!key) |
| 1374 | return 0; |
| 1375 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1376 | ts = stktable_lookup_key(t, key); |
| 1377 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1378 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1379 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1380 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1381 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1382 | if (!ts) /* key not present */ |
| 1383 | return 1; |
| 1384 | |
| 1385 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1386 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1387 | 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] | 1388 | t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1389 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1390 | stktable_release(t, ts); |
| 1391 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1395 | * it up into this table. Returns the cumulated number of connections for the key |
| 1396 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1397 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1398 | * <not found> is returned. |
| 1399 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1400 | 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] | 1401 | { |
| 1402 | struct stktable *t; |
| 1403 | struct stktable_key *key; |
| 1404 | struct stksess *ts; |
| 1405 | void *ptr; |
| 1406 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1407 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1408 | |
| 1409 | key = smp_to_stkey(smp, t); |
| 1410 | if (!key) |
| 1411 | return 0; |
| 1412 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1413 | ts = stktable_lookup_key(t, key); |
| 1414 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1415 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1416 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1417 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1418 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1419 | if (!ts) /* key not present */ |
| 1420 | return 1; |
| 1421 | |
| 1422 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1423 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1424 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1425 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1426 | stktable_release(t, ts); |
| 1427 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1431 | * it up into this table. Returns the number of concurrent connections for the |
| 1432 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1433 | * can be easily performed. If the inspected parameter is not stored in the |
| 1434 | * table, <not found> is returned. |
| 1435 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1436 | 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] | 1437 | { |
| 1438 | struct stktable *t; |
| 1439 | struct stktable_key *key; |
| 1440 | struct stksess *ts; |
| 1441 | void *ptr; |
| 1442 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1443 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1444 | |
| 1445 | key = smp_to_stkey(smp, t); |
| 1446 | if (!key) |
| 1447 | return 0; |
| 1448 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1449 | ts = stktable_lookup_key(t, key); |
| 1450 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1451 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1452 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1453 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1454 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1455 | if (!ts) /* key not present */ |
| 1456 | return 1; |
| 1457 | |
| 1458 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1459 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1460 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1461 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1462 | stktable_release(t, ts); |
| 1463 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1467 | * it up into this table. Returns the rate of incoming connections from the key |
| 1468 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1469 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1470 | * <not found> is returned. |
| 1471 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1472 | 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] | 1473 | { |
| 1474 | struct stktable *t; |
| 1475 | struct stktable_key *key; |
| 1476 | struct stksess *ts; |
| 1477 | void *ptr; |
| 1478 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1479 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1480 | |
| 1481 | key = smp_to_stkey(smp, t); |
| 1482 | if (!key) |
| 1483 | return 0; |
| 1484 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1485 | ts = stktable_lookup_key(t, key); |
| 1486 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1487 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1488 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1489 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1490 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1491 | if (!ts) /* key not present */ |
| 1492 | return 1; |
| 1493 | |
| 1494 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1495 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1496 | 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] | 1497 | t->data_arg[STKTABLE_DT_CONN_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1498 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1499 | stktable_release(t, ts); |
| 1500 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /* 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] | 1504 | * it up into this table. Returns the expiration delay for the key if the key is |
| 1505 | * present in the table, otherwise the default value provided as second argument |
| 1506 | * if any, if not (no default value), <not found> is returned. |
| 1507 | */ |
| 1508 | static int sample_conv_table_expire(const struct arg *arg_p, struct sample *smp, void *private) |
| 1509 | { |
| 1510 | struct stktable *t; |
| 1511 | struct stktable_key *key; |
| 1512 | struct stksess *ts; |
| 1513 | |
| 1514 | t = arg_p[0].data.t; |
| 1515 | |
| 1516 | key = smp_to_stkey(smp, t); |
| 1517 | if (!key) |
| 1518 | return 0; |
| 1519 | |
| 1520 | ts = stktable_lookup_key(t, key); |
| 1521 | |
| 1522 | smp->flags = SMP_F_VOL_TEST; |
| 1523 | smp->data.type = SMP_T_SINT; |
| 1524 | smp->data.u.sint = 0; |
| 1525 | |
| 1526 | if (!ts) { /* key not present */ |
| 1527 | if (arg_p[1].type == ARGT_STOP) |
| 1528 | return 0; |
| 1529 | |
| 1530 | /* default value */ |
| 1531 | smp->data.u.sint = arg_p[1].data.sint; |
| 1532 | return 1; |
| 1533 | } |
| 1534 | |
| 1535 | smp->data.u.sint = tick_remain(now_ms, ts->expire); |
| 1536 | |
| 1537 | stktable_release(t, ts); |
| 1538 | return 1; |
| 1539 | } |
| 1540 | |
| 1541 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1542 | * it up into this table. Returns the time the key remains unused if the key is |
| 1543 | * present in the table, otherwise the default value provided as second argument |
| 1544 | * if any, if not (no default value), <not found> is returned. |
| 1545 | */ |
| 1546 | static int sample_conv_table_idle(const struct arg *arg_p, struct sample *smp, void *private) |
| 1547 | { |
| 1548 | struct stktable *t; |
| 1549 | struct stktable_key *key; |
| 1550 | struct stksess *ts; |
| 1551 | |
| 1552 | t = arg_p[0].data.t; |
| 1553 | |
| 1554 | key = smp_to_stkey(smp, t); |
| 1555 | if (!key) |
| 1556 | return 0; |
| 1557 | |
| 1558 | ts = stktable_lookup_key(t, key); |
| 1559 | |
| 1560 | smp->flags = SMP_F_VOL_TEST; |
| 1561 | smp->data.type = SMP_T_SINT; |
| 1562 | smp->data.u.sint = 0; |
| 1563 | |
| 1564 | if (!ts) { /* key not present */ |
| 1565 | if (arg_p[1].type == ARGT_STOP) |
| 1566 | return 0; |
| 1567 | |
| 1568 | /* default value */ |
| 1569 | smp->data.u.sint = arg_p[1].data.sint; |
| 1570 | return 1; |
| 1571 | } |
| 1572 | |
| 1573 | smp->data.u.sint = tick_remain(tick_remain(now_ms, ts->expire), t->expire); |
| 1574 | |
| 1575 | stktable_release(t, ts); |
| 1576 | return 1; |
| 1577 | } |
| 1578 | |
| 1579 | /* 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] | 1580 | * it up into this table. Returns the data rate sent to clients in bytes/s |
| 1581 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1582 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1583 | * <not found> is returned. |
| 1584 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1585 | 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] | 1586 | { |
| 1587 | struct stktable *t; |
| 1588 | struct stktable_key *key; |
| 1589 | struct stksess *ts; |
| 1590 | void *ptr; |
| 1591 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1592 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1593 | |
| 1594 | key = smp_to_stkey(smp, t); |
| 1595 | if (!key) |
| 1596 | return 0; |
| 1597 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1598 | ts = stktable_lookup_key(t, key); |
| 1599 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1600 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1601 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1602 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1603 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1604 | if (!ts) /* key not present */ |
| 1605 | return 1; |
| 1606 | |
| 1607 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1608 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1609 | 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] | 1610 | t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1611 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1612 | stktable_release(t, ts); |
| 1613 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1614 | } |
| 1615 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 1616 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1617 | * it up into this table. Returns the value of the GPT[arg_p(0)] tag for the key |
| 1618 | * if the key is present in the table, otherwise false, so that comparisons can |
| 1619 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1620 | * <not found> is returned. |
| 1621 | */ |
| 1622 | static int sample_conv_table_gpt(const struct arg *arg_p, struct sample *smp, void *private) |
| 1623 | { |
| 1624 | struct stktable *t; |
| 1625 | struct stktable_key *key; |
| 1626 | struct stksess *ts; |
| 1627 | void *ptr; |
| 1628 | unsigned int idx; |
| 1629 | |
| 1630 | idx = arg_p[0].data.sint; |
| 1631 | |
| 1632 | t = arg_p[1].data.t; |
| 1633 | |
| 1634 | key = smp_to_stkey(smp, t); |
| 1635 | if (!key) |
| 1636 | return 0; |
| 1637 | |
| 1638 | ts = stktable_lookup_key(t, key); |
| 1639 | |
| 1640 | smp->flags = SMP_F_VOL_TEST; |
| 1641 | smp->data.type = SMP_T_SINT; |
| 1642 | smp->data.u.sint = 0; |
| 1643 | |
| 1644 | if (!ts) /* key not present */ |
| 1645 | return 1; |
| 1646 | |
| 1647 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPT, idx); |
| 1648 | if (ptr) |
| 1649 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 1650 | |
| 1651 | stktable_release(t, ts); |
| 1652 | return !!ptr; |
| 1653 | } |
| 1654 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1655 | /* 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] | 1656 | * it up into this table. Returns the value of the GPT0 tag for the key |
| 1657 | * if the key is present in the table, otherwise false, so that comparisons can |
| 1658 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1659 | * <not found> is returned. |
| 1660 | */ |
| 1661 | static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private) |
| 1662 | { |
| 1663 | struct stktable *t; |
| 1664 | struct stktable_key *key; |
| 1665 | struct stksess *ts; |
| 1666 | void *ptr; |
| 1667 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1668 | t = arg_p[0].data.t; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1669 | |
| 1670 | key = smp_to_stkey(smp, t); |
| 1671 | if (!key) |
| 1672 | return 0; |
| 1673 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1674 | ts = stktable_lookup_key(t, key); |
| 1675 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1676 | smp->flags = SMP_F_VOL_TEST; |
| 1677 | smp->data.type = SMP_T_SINT; |
| 1678 | smp->data.u.sint = 0; |
| 1679 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1680 | if (!ts) /* key not present */ |
| 1681 | return 1; |
| 1682 | |
| 1683 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 1684 | if (!ptr) |
| 1685 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPT, 0); |
| 1686 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1687 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1688 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1689 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1690 | stktable_release(t, ts); |
| 1691 | return !!ptr; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1692 | } |
| 1693 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 1694 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1695 | * it up into this table. Returns the value of the GPC[arg_p(0)] counter for the key |
| 1696 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1697 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1698 | * <not found> is returned. |
| 1699 | */ |
| 1700 | static int sample_conv_table_gpc(const struct arg *arg_p, struct sample *smp, void *private) |
| 1701 | { |
| 1702 | struct stktable *t; |
| 1703 | struct stktable_key *key; |
| 1704 | struct stksess *ts; |
| 1705 | void *ptr; |
| 1706 | unsigned int idx; |
| 1707 | |
| 1708 | idx = arg_p[0].data.sint; |
| 1709 | |
| 1710 | t = arg_p[1].data.t; |
| 1711 | |
| 1712 | key = smp_to_stkey(smp, t); |
| 1713 | if (!key) |
| 1714 | return 0; |
| 1715 | |
| 1716 | ts = stktable_lookup_key(t, key); |
| 1717 | |
| 1718 | smp->flags = SMP_F_VOL_TEST; |
| 1719 | smp->data.type = SMP_T_SINT; |
| 1720 | smp->data.u.sint = 0; |
| 1721 | |
| 1722 | if (!ts) /* key not present */ |
| 1723 | return 1; |
| 1724 | |
| 1725 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, idx); |
| 1726 | if (ptr) |
| 1727 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 1728 | |
| 1729 | stktable_release(t, ts); |
| 1730 | return !!ptr; |
| 1731 | } |
| 1732 | |
| 1733 | /* Casts sample <smp> to the type of the table specified in arg_p(1), and looks |
| 1734 | * it up into this table. Returns the event rate of the GPC[arg_p(0)] counter |
| 1735 | * for the key if the key is present in the table, otherwise zero, so that |
| 1736 | * comparisons can be easily performed. If the inspected parameter is not |
| 1737 | * stored in the table, <not found> is returned. |
| 1738 | */ |
| 1739 | static int sample_conv_table_gpc_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 1740 | { |
| 1741 | struct stktable *t; |
| 1742 | struct stktable_key *key; |
| 1743 | struct stksess *ts; |
| 1744 | void *ptr; |
| 1745 | unsigned int idx; |
| 1746 | |
| 1747 | idx = arg_p[0].data.sint; |
| 1748 | |
| 1749 | t = arg_p[1].data.t; |
| 1750 | |
| 1751 | key = smp_to_stkey(smp, t); |
| 1752 | if (!key) |
| 1753 | return 0; |
| 1754 | |
| 1755 | ts = stktable_lookup_key(t, key); |
| 1756 | |
| 1757 | smp->flags = SMP_F_VOL_TEST; |
| 1758 | smp->data.type = SMP_T_SINT; |
| 1759 | smp->data.u.sint = 0; |
| 1760 | |
| 1761 | if (!ts) /* key not present */ |
| 1762 | return 1; |
| 1763 | |
| 1764 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, idx); |
| 1765 | if (ptr) |
| 1766 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1767 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1768 | |
| 1769 | stktable_release(t, ts); |
| 1770 | return !!ptr; |
| 1771 | } |
| 1772 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1773 | /* 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] | 1774 | * it up into this table. Returns the value of the GPC0 counter for the key |
| 1775 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1776 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1777 | * <not found> is returned. |
| 1778 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1779 | 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] | 1780 | { |
| 1781 | struct stktable *t; |
| 1782 | struct stktable_key *key; |
| 1783 | struct stksess *ts; |
| 1784 | void *ptr; |
| 1785 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1786 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1787 | |
| 1788 | key = smp_to_stkey(smp, t); |
| 1789 | if (!key) |
| 1790 | return 0; |
| 1791 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1792 | ts = stktable_lookup_key(t, key); |
| 1793 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1794 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1795 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1796 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1797 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1798 | if (!ts) /* key not present */ |
| 1799 | return 1; |
| 1800 | |
| 1801 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1802 | if (!ptr) { |
| 1803 | /* fallback on the gpc array */ |
| 1804 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, 0); |
| 1805 | } |
| 1806 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1807 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1808 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1809 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1810 | stktable_release(t, ts); |
| 1811 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1815 | * it up into this table. Returns the event rate of the GPC0 counter for the key |
| 1816 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1817 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1818 | * <not found> is returned. |
| 1819 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1820 | 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] | 1821 | { |
| 1822 | struct stktable *t; |
| 1823 | struct stktable_key *key; |
| 1824 | struct stksess *ts; |
| 1825 | void *ptr; |
| 1826 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1827 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1828 | |
| 1829 | key = smp_to_stkey(smp, t); |
| 1830 | if (!key) |
| 1831 | return 0; |
| 1832 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1833 | ts = stktable_lookup_key(t, key); |
| 1834 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1835 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1836 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1837 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1838 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1839 | if (!ts) /* key not present */ |
| 1840 | return 1; |
| 1841 | |
| 1842 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1843 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1844 | 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] | 1845 | t->data_arg[STKTABLE_DT_GPC0_RATE].u); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1846 | else { |
| 1847 | /* fallback on the gpc array */ |
| 1848 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, 0); |
| 1849 | if (ptr) |
| 1850 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1851 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1852 | } |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1853 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1854 | stktable_release(t, ts); |
| 1855 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | /* 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] | 1859 | * it up into this table. Returns the value of the GPC1 counter for the key |
| 1860 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1861 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1862 | * <not found> is returned. |
| 1863 | */ |
| 1864 | static int sample_conv_table_gpc1(const struct arg *arg_p, struct sample *smp, void *private) |
| 1865 | { |
| 1866 | struct stktable *t; |
| 1867 | struct stktable_key *key; |
| 1868 | struct stksess *ts; |
| 1869 | void *ptr; |
| 1870 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1871 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1872 | |
| 1873 | key = smp_to_stkey(smp, t); |
| 1874 | if (!key) |
| 1875 | return 0; |
| 1876 | |
| 1877 | ts = stktable_lookup_key(t, key); |
| 1878 | |
| 1879 | smp->flags = SMP_F_VOL_TEST; |
| 1880 | smp->data.type = SMP_T_SINT; |
| 1881 | smp->data.u.sint = 0; |
| 1882 | |
| 1883 | if (!ts) /* key not present */ |
| 1884 | return 1; |
| 1885 | |
| 1886 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1887 | if (!ptr) { |
| 1888 | /* fallback on the gpc array */ |
| 1889 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC, 1); |
| 1890 | } |
| 1891 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1892 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1893 | 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] | 1894 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1895 | stktable_release(t, ts); |
| 1896 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1900 | * it up into this table. Returns the event rate of the GPC1 counter for the key |
| 1901 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1902 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1903 | * <not found> is returned. |
| 1904 | */ |
| 1905 | static int sample_conv_table_gpc1_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 1906 | { |
| 1907 | struct stktable *t; |
| 1908 | struct stktable_key *key; |
| 1909 | struct stksess *ts; |
| 1910 | void *ptr; |
| 1911 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1912 | t = arg_p[0].data.t; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1913 | |
| 1914 | key = smp_to_stkey(smp, t); |
| 1915 | if (!key) |
| 1916 | return 0; |
| 1917 | |
| 1918 | ts = stktable_lookup_key(t, key); |
| 1919 | |
| 1920 | smp->flags = SMP_F_VOL_TEST; |
| 1921 | smp->data.type = SMP_T_SINT; |
| 1922 | smp->data.u.sint = 0; |
| 1923 | |
| 1924 | if (!ts) /* key not present */ |
| 1925 | return 1; |
| 1926 | |
| 1927 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC1_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1928 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1929 | 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] | 1930 | t->data_arg[STKTABLE_DT_GPC1_RATE].u); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 1931 | else { |
| 1932 | /* fallback on the gpc array */ |
| 1933 | ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPC_RATE, 1); |
| 1934 | if (ptr) |
| 1935 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 1936 | t->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 1937 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1938 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1939 | stktable_release(t, ts); |
| 1940 | return !!ptr; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | /* 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] | 1944 | * it up into this table. Returns the cumulated number of HTTP request errors |
| 1945 | * for the key if the key is present in the table, otherwise zero, so that |
| 1946 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 1947 | * in the table, <not found> is returned. |
| 1948 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1949 | 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] | 1950 | { |
| 1951 | struct stktable *t; |
| 1952 | struct stktable_key *key; |
| 1953 | struct stksess *ts; |
| 1954 | void *ptr; |
| 1955 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1956 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1957 | |
| 1958 | key = smp_to_stkey(smp, t); |
| 1959 | if (!key) |
| 1960 | return 0; |
| 1961 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1962 | ts = stktable_lookup_key(t, key); |
| 1963 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1964 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1965 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1966 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1967 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1968 | if (!ts) /* key not present */ |
| 1969 | return 1; |
| 1970 | |
| 1971 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1972 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 1973 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1974 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 1975 | stktable_release(t, ts); |
| 1976 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1980 | * it up into this table. Returns the HTTP request error rate the key |
| 1981 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1982 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1983 | * <not found> is returned. |
| 1984 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1985 | 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] | 1986 | { |
| 1987 | struct stktable *t; |
| 1988 | struct stktable_key *key; |
| 1989 | struct stksess *ts; |
| 1990 | void *ptr; |
| 1991 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1992 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1993 | |
| 1994 | key = smp_to_stkey(smp, t); |
| 1995 | if (!key) |
| 1996 | return 0; |
| 1997 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1998 | ts = stktable_lookup_key(t, key); |
| 1999 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2000 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2001 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2002 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2003 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2004 | if (!ts) /* key not present */ |
| 2005 | return 1; |
| 2006 | |
| 2007 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2008 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2009 | 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] | 2010 | t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2011 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2012 | stktable_release(t, ts); |
| 2013 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | /* 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] | 2017 | * it up into this table. Returns the cumulated number of HTTP response failures |
| 2018 | * for the key if the key is present in the table, otherwise zero, so that |
| 2019 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 2020 | * in the table, <not found> is returned. |
| 2021 | */ |
| 2022 | static int sample_conv_table_http_fail_cnt(const struct arg *arg_p, struct sample *smp, void *private) |
| 2023 | { |
| 2024 | struct stktable *t; |
| 2025 | struct stktable_key *key; |
| 2026 | struct stksess *ts; |
| 2027 | void *ptr; |
| 2028 | |
| 2029 | t = arg_p[0].data.t; |
| 2030 | |
| 2031 | key = smp_to_stkey(smp, t); |
| 2032 | if (!key) |
| 2033 | return 0; |
| 2034 | |
| 2035 | ts = stktable_lookup_key(t, key); |
| 2036 | |
| 2037 | smp->flags = SMP_F_VOL_TEST; |
| 2038 | smp->data.type = SMP_T_SINT; |
| 2039 | smp->data.u.sint = 0; |
| 2040 | |
| 2041 | if (!ts) /* key not present */ |
| 2042 | return 1; |
| 2043 | |
| 2044 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_CNT); |
| 2045 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2046 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 2047 | |
| 2048 | stktable_release(t, ts); |
| 2049 | return !!ptr; |
| 2050 | } |
| 2051 | |
| 2052 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2053 | * it up into this table. Returns the HTTP response failure rate for the key |
| 2054 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2055 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2056 | * <not found> is returned. |
| 2057 | */ |
| 2058 | static int sample_conv_table_http_fail_rate(const struct arg *arg_p, struct sample *smp, void *private) |
| 2059 | { |
| 2060 | struct stktable *t; |
| 2061 | struct stktable_key *key; |
| 2062 | struct stksess *ts; |
| 2063 | void *ptr; |
| 2064 | |
| 2065 | t = arg_p[0].data.t; |
| 2066 | |
| 2067 | key = smp_to_stkey(smp, t); |
| 2068 | if (!key) |
| 2069 | return 0; |
| 2070 | |
| 2071 | ts = stktable_lookup_key(t, key); |
| 2072 | |
| 2073 | smp->flags = SMP_F_VOL_TEST; |
| 2074 | smp->data.type = SMP_T_SINT; |
| 2075 | smp->data.u.sint = 0; |
| 2076 | |
| 2077 | if (!ts) /* key not present */ |
| 2078 | return 1; |
| 2079 | |
| 2080 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_FAIL_RATE); |
| 2081 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2082 | 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] | 2083 | t->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u); |
| 2084 | |
| 2085 | stktable_release(t, ts); |
| 2086 | return !!ptr; |
| 2087 | } |
| 2088 | |
| 2089 | /* 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] | 2090 | * it up into this table. Returns the cumulated number of HTTP request for the |
| 2091 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 2092 | * can be easily performed. If the inspected parameter is not stored in the |
| 2093 | * table, <not found> is returned. |
| 2094 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2095 | 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] | 2096 | { |
| 2097 | struct stktable *t; |
| 2098 | struct stktable_key *key; |
| 2099 | struct stksess *ts; |
| 2100 | void *ptr; |
| 2101 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2102 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2103 | |
| 2104 | key = smp_to_stkey(smp, t); |
| 2105 | if (!key) |
| 2106 | return 0; |
| 2107 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2108 | ts = stktable_lookup_key(t, key); |
| 2109 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2110 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2111 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2112 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2113 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2114 | if (!ts) /* key not present */ |
| 2115 | return 1; |
| 2116 | |
| 2117 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2118 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2119 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2120 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2121 | stktable_release(t, ts); |
| 2122 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2126 | * it up into this table. Returns the HTTP request rate the key if the key is |
| 2127 | * present in the table, otherwise zero, so that comparisons can be easily |
| 2128 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 2129 | * is returned. |
| 2130 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2131 | 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] | 2132 | { |
| 2133 | struct stktable *t; |
| 2134 | struct stktable_key *key; |
| 2135 | struct stksess *ts; |
| 2136 | void *ptr; |
| 2137 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2138 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2139 | |
| 2140 | key = smp_to_stkey(smp, t); |
| 2141 | if (!key) |
| 2142 | return 0; |
| 2143 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2144 | ts = stktable_lookup_key(t, key); |
| 2145 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2146 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2147 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2148 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2149 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2150 | if (!ts) /* key not present */ |
| 2151 | return 1; |
| 2152 | |
| 2153 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2154 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2155 | 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] | 2156 | t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2157 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2158 | stktable_release(t, ts); |
| 2159 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2163 | * it up into this table. Returns the volume of datareceived from clients in kbytes |
| 2164 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2165 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2166 | * <not found> is returned. |
| 2167 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2168 | 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] | 2169 | { |
| 2170 | struct stktable *t; |
| 2171 | struct stktable_key *key; |
| 2172 | struct stksess *ts; |
| 2173 | void *ptr; |
| 2174 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2175 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2176 | |
| 2177 | key = smp_to_stkey(smp, t); |
| 2178 | if (!key) |
| 2179 | return 0; |
| 2180 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2181 | ts = stktable_lookup_key(t, key); |
| 2182 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2183 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2184 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2185 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2186 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2187 | if (!ts) /* key not present */ |
| 2188 | return 1; |
| 2189 | |
| 2190 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2191 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2192 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2193 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2194 | stktable_release(t, ts); |
| 2195 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2199 | * it up into this table. Returns the volume of data sent to clients in kbytes |
| 2200 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 2201 | * be easily performed. If the inspected parameter is not stored in the table, |
| 2202 | * <not found> is returned. |
| 2203 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2204 | 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] | 2205 | { |
| 2206 | struct stktable *t; |
| 2207 | struct stktable_key *key; |
| 2208 | struct stksess *ts; |
| 2209 | void *ptr; |
| 2210 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2211 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2212 | |
| 2213 | key = smp_to_stkey(smp, t); |
| 2214 | if (!key) |
| 2215 | return 0; |
| 2216 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2217 | ts = stktable_lookup_key(t, key); |
| 2218 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2219 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2220 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2221 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2222 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2223 | if (!ts) /* key not present */ |
| 2224 | return 1; |
| 2225 | |
| 2226 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2227 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2228 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2229 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2230 | stktable_release(t, ts); |
| 2231 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2235 | * it up into this table. Returns the server ID associated with the key if the |
| 2236 | * key is present in the table, otherwise zero, so that comparisons can be |
| 2237 | * easily performed. If the inspected parameter is not stored in the table, |
| 2238 | * <not found> is returned. |
| 2239 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2240 | 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] | 2241 | { |
| 2242 | struct stktable *t; |
| 2243 | struct stktable_key *key; |
| 2244 | struct stksess *ts; |
| 2245 | void *ptr; |
| 2246 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2247 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2248 | |
| 2249 | key = smp_to_stkey(smp, t); |
| 2250 | if (!key) |
| 2251 | return 0; |
| 2252 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2253 | ts = stktable_lookup_key(t, key); |
| 2254 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2255 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2256 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2257 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2258 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2259 | if (!ts) /* key not present */ |
| 2260 | return 1; |
| 2261 | |
| 2262 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2263 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2264 | smp->data.u.sint = stktable_data_cast(ptr, std_t_sint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2265 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2266 | stktable_release(t, ts); |
| 2267 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2271 | * it up into this table. Returns the cumulated number of sessions for the |
| 2272 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 2273 | * can be easily performed. If the inspected parameter is not stored in the |
| 2274 | * table, <not found> is returned. |
| 2275 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2276 | 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] | 2277 | { |
| 2278 | struct stktable *t; |
| 2279 | struct stktable_key *key; |
| 2280 | struct stksess *ts; |
| 2281 | void *ptr; |
| 2282 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2283 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2284 | |
| 2285 | key = smp_to_stkey(smp, t); |
| 2286 | if (!key) |
| 2287 | return 0; |
| 2288 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2289 | ts = stktable_lookup_key(t, key); |
| 2290 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2291 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2292 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2293 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2294 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2295 | if (!ts) /* key not present */ |
| 2296 | return 1; |
| 2297 | |
| 2298 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2299 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2300 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2301 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2302 | stktable_release(t, ts); |
| 2303 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2307 | * it up into this table. Returns the session rate the key if the key is |
| 2308 | * present in the table, otherwise zero, so that comparisons can be easily |
| 2309 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 2310 | * is returned. |
| 2311 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2312 | 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] | 2313 | { |
| 2314 | struct stktable *t; |
| 2315 | struct stktable_key *key; |
| 2316 | struct stksess *ts; |
| 2317 | void *ptr; |
| 2318 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2319 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2320 | |
| 2321 | key = smp_to_stkey(smp, t); |
| 2322 | if (!key) |
| 2323 | return 0; |
| 2324 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2325 | ts = stktable_lookup_key(t, key); |
| 2326 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2327 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2328 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2329 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2330 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2331 | if (!ts) /* key not present */ |
| 2332 | return 1; |
| 2333 | |
| 2334 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE); |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2335 | if (ptr) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2336 | 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] | 2337 | t->data_arg[STKTABLE_DT_SESS_RATE].u); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2338 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2339 | stktable_release(t, ts); |
| 2340 | return !!ptr; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 2344 | * it up into this table. Returns the amount of concurrent connections tracking |
| 2345 | * the same key if the key is present in the table, otherwise zero, so that |
| 2346 | * comparisons can be easily performed. If the inspected parameter is not |
| 2347 | * stored in the table, <not found> is returned. |
| 2348 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 2349 | 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] | 2350 | { |
| 2351 | struct stktable *t; |
| 2352 | struct stktable_key *key; |
| 2353 | struct stksess *ts; |
| 2354 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 2355 | t = arg_p[0].data.t; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2356 | |
| 2357 | key = smp_to_stkey(smp, t); |
| 2358 | if (!key) |
| 2359 | return 0; |
| 2360 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 2361 | ts = stktable_lookup_key(t, key); |
| 2362 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2363 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 2364 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 2365 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2366 | |
Tim Duesterhus | 65189c1 | 2018-06-26 15:57:29 +0200 | [diff] [blame] | 2367 | if (!ts) |
| 2368 | return 1; |
| 2369 | |
| 2370 | smp->data.u.sint = ts->ref_cnt; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2371 | |
Daniel Corbett | 3e60b11 | 2018-05-27 09:47:12 -0400 | [diff] [blame] | 2372 | stktable_release(t, ts); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2373 | return 1; |
| 2374 | } |
| 2375 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2376 | /* This function increments the gpc counter at index 'rule->arg.gpc.idx' of the |
| 2377 | * array on the tracksc counter of index 'rule->arg.gpc.sc' stored into the |
| 2378 | * <stream> or directly in the session <sess> if <stream> is set to NULL |
| 2379 | * |
| 2380 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2381 | */ |
| 2382 | static enum act_return action_inc_gpc(struct act_rule *rule, struct proxy *px, |
| 2383 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2384 | { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2385 | struct stksess *ts; |
| 2386 | struct stkctr *stkctr; |
| 2387 | |
| 2388 | /* Extract the stksess, return OK if no stksess available. */ |
| 2389 | if (s) |
| 2390 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2391 | else |
| 2392 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2393 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2394 | ts = stkctr_entry(stkctr); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2395 | if (ts) { |
| 2396 | void *ptr1, *ptr2; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2397 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2398 | /* First, update gpc_rate if it's tracked. Second, update its gpc if tracked. */ |
| 2399 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, rule->arg.gpc.idx); |
| 2400 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, rule->arg.gpc.idx); |
| 2401 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2402 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2403 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2404 | |
| 2405 | if (ptr1) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2406 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2407 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, 1); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2408 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2409 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2410 | stktable_data_cast(ptr2, std_t_uint)++; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2411 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2412 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2413 | |
| 2414 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2415 | stktable_touch_local(stkctr->table, ts, 0); |
| 2416 | } |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2417 | } |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2418 | return ACT_RET_CONT; |
| 2419 | } |
| 2420 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2421 | /* Same as action_inc_gpc() but for gpc0 only */ |
| 2422 | static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px, |
| 2423 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2424 | { |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2425 | struct stksess *ts; |
| 2426 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 2427 | unsigned int period = 0; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2428 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2429 | /* Extract the stksess, return OK if no stksess available. */ |
| 2430 | if (s) |
| 2431 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2432 | else |
| 2433 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2434 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2435 | ts = stkctr_entry(stkctr); |
| 2436 | if (ts) { |
| 2437 | void *ptr1, *ptr2; |
| 2438 | |
| 2439 | /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */ |
| 2440 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2441 | if (ptr1) { |
| 2442 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 2443 | } |
| 2444 | else { |
| 2445 | /* fallback on the gpc array */ |
| 2446 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, 0); |
| 2447 | if (ptr1) |
| 2448 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 2449 | } |
| 2450 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2451 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2452 | if (!ptr2) { |
| 2453 | /* fallback on the gpc array */ |
| 2454 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, 0); |
| 2455 | } |
| 2456 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2457 | if (ptr1 || ptr2) { |
| 2458 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2459 | |
| 2460 | if (ptr1) |
| 2461 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2462 | period, 1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2463 | |
| 2464 | if (ptr2) |
| 2465 | stktable_data_cast(ptr2, std_t_uint)++; |
| 2466 | |
| 2467 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2468 | |
| 2469 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2470 | stktable_touch_local(stkctr->table, ts, 0); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2471 | } |
| 2472 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2473 | return ACT_RET_CONT; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2474 | } |
| 2475 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2476 | /* Same as action_inc_gpc() but for gpc1 only */ |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2477 | static enum act_return action_inc_gpc1(struct act_rule *rule, struct proxy *px, |
| 2478 | struct session *sess, struct stream *s, int flags) |
| 2479 | { |
| 2480 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2481 | struct stkctr *stkctr = NULL; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 2482 | unsigned int period = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2483 | |
| 2484 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2485 | if (s && s->stkctr) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2486 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2487 | else if (sess->stkctr) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2488 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2489 | else |
| 2490 | return ACT_RET_CONT; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2491 | |
| 2492 | ts = stkctr_entry(stkctr); |
| 2493 | if (ts) { |
| 2494 | void *ptr1, *ptr2; |
| 2495 | |
| 2496 | /* First, update gpc1_rate if it's tracked. Second, update its gpc1 if tracked. */ |
| 2497 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1_RATE); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2498 | if (ptr1) { |
| 2499 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 2500 | } |
| 2501 | else { |
| 2502 | /* fallback on the gpc array */ |
| 2503 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, 1); |
| 2504 | if (ptr1) |
| 2505 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 2506 | } |
| 2507 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2508 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2509 | if (!ptr2) { |
| 2510 | /* fallback on the gpc array */ |
| 2511 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, 1); |
| 2512 | } |
| 2513 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2514 | if (ptr1 || ptr2) { |
| 2515 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2516 | |
| 2517 | if (ptr1) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2518 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 2519 | period, 1); |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2520 | |
| 2521 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2522 | stktable_data_cast(ptr2, std_t_uint)++; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2523 | |
| 2524 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2525 | |
| 2526 | /* If data was modified, we need to touch to re-schedule sync */ |
| 2527 | stktable_touch_local(stkctr->table, ts, 0); |
| 2528 | } |
| 2529 | } |
| 2530 | return ACT_RET_CONT; |
| 2531 | } |
| 2532 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2533 | /* This function is a common parser for actions incrementing the GPC |
| 2534 | * (General Purpose Counters). It understands the formats: |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2535 | * |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2536 | * sc-inc-gpc(<gpc IDX>,<track ID>) |
| 2537 | * sc-inc-gpc0([<track ID>]) |
| 2538 | * sc-inc-gpc1([<track ID>]) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2539 | * |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2540 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error |
| 2541 | * message. Otherwise it returns ACT_RET_PRS_OK. |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2542 | */ |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2543 | static enum act_parse_ret parse_inc_gpc(const char **args, int *arg, struct proxy *px, |
| 2544 | struct act_rule *rule, char **err) |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2545 | { |
| 2546 | const char *cmd_name = args[*arg-1]; |
| 2547 | char *error; |
| 2548 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2549 | if (!global.tune.nb_stk_ctr) { |
| 2550 | memprintf(err, "Cannot use '%s', stick-counters are disabled via tune.stick-counters", args[*arg-1]); |
| 2551 | return ACT_RET_PRS_ERR; |
| 2552 | } |
| 2553 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2554 | cmd_name += strlen("sc-inc-gpc"); |
| 2555 | if (*cmd_name == '(') { |
| 2556 | cmd_name++; /* skip the '(' */ |
| 2557 | rule->arg.gpc.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2558 | if (*error != ',') { |
| 2559 | 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] | 2560 | return ACT_RET_PRS_ERR; |
| 2561 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2562 | else { |
| 2563 | cmd_name = error + 1; /* skip the ',' */ |
| 2564 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2565 | if (*error != ')') { |
| 2566 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-inc-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2567 | return ACT_RET_PRS_ERR; |
| 2568 | } |
| 2569 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2570 | if (rule->arg.gpc.sc >= global.tune.nb_stk_ctr) { |
| 2571 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d (tune.stick-counters)", |
| 2572 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2573 | return ACT_RET_PRS_ERR; |
| 2574 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2575 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2576 | rule->action_ptr = action_inc_gpc; |
| 2577 | } |
| 2578 | else if (*cmd_name == '0' ||*cmd_name == '1') { |
| 2579 | char c = *cmd_name; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2580 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2581 | cmd_name++; |
| 2582 | if (*cmd_name == '\0') { |
| 2583 | /* default stick table id. */ |
| 2584 | rule->arg.gpc.sc = 0; |
| 2585 | } else { |
| 2586 | /* parse the stick table id. */ |
| 2587 | if (*cmd_name != '(') { |
| 2588 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 2589 | return ACT_RET_PRS_ERR; |
| 2590 | } |
| 2591 | cmd_name++; /* jump the '(' */ |
| 2592 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2593 | if (*error != ')') { |
| 2594 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 2595 | return ACT_RET_PRS_ERR; |
| 2596 | } |
| 2597 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2598 | if (rule->arg.gpc.sc >= global.tune.nb_stk_ctr) { |
| 2599 | memprintf(err, "invalid stick table track ID. The max allowed ID is %d (tune.stick-counters)", |
| 2600 | global.tune.nb_stk_ctr-1); |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2601 | return ACT_RET_PRS_ERR; |
| 2602 | } |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2603 | } |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 2604 | if (c == '1') |
| 2605 | rule->action_ptr = action_inc_gpc1; |
| 2606 | else |
| 2607 | rule->action_ptr = action_inc_gpc0; |
| 2608 | } |
| 2609 | else { |
| 2610 | /* default stick table id. */ |
Willy Tarreau | 2039151 | 2023-01-02 17:35:50 +0100 | [diff] [blame] | 2611 | 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] | 2612 | return ACT_RET_PRS_ERR; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2613 | } |
| 2614 | rule->action = ACT_CUSTOM; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2615 | return ACT_RET_PRS_OK; |
| 2616 | } |
| 2617 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2618 | /* This function sets the gpt at index 'rule->arg.gpt.idx' of the array on the |
| 2619 | * tracksc counter of index 'rule->arg.gpt.sc' stored into the <stream> or |
| 2620 | * directly in the session <sess> if <stream> is set to NULL. This gpt is |
| 2621 | * set to the value computed by the expression 'rule->arg.gpt.expr' or if |
| 2622 | * 'rule->arg.gpt.expr' is null directly to the value of 'rule->arg.gpt.value'. |
| 2623 | * |
| 2624 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2625 | */ |
| 2626 | static enum act_return action_set_gpt(struct act_rule *rule, struct proxy *px, |
| 2627 | struct session *sess, struct stream *s, int flags) |
| 2628 | { |
| 2629 | void *ptr; |
| 2630 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2631 | struct stkctr *stkctr = NULL; |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2632 | unsigned int value = 0; |
| 2633 | struct sample *smp; |
| 2634 | int smp_opt_dir; |
| 2635 | |
| 2636 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2637 | if (s && s->stkctr) |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2638 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2639 | else if (sess->stkctr) |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2640 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2641 | else |
| 2642 | return ACT_RET_CONT; |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2643 | |
| 2644 | ts = stkctr_entry(stkctr); |
| 2645 | if (!ts) |
| 2646 | return ACT_RET_CONT; |
| 2647 | |
| 2648 | /* Store the sample in the required sc, and ignore errors. */ |
| 2649 | ptr = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPT, rule->arg.gpt.idx); |
| 2650 | if (ptr) { |
| 2651 | |
| 2652 | if (!rule->arg.gpt.expr) |
| 2653 | value = (unsigned int)(rule->arg.gpt.value); |
| 2654 | else { |
| 2655 | switch (rule->from) { |
| 2656 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2657 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2658 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2659 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2660 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2661 | default: |
| 2662 | send_log(px, LOG_ERR, "stick table: internal error while setting gpt%u.", rule->arg.gpt.idx); |
| 2663 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2664 | ha_alert("stick table: internal error while executing setting gpt%u.\n", rule->arg.gpt.idx); |
| 2665 | return ACT_RET_CONT; |
| 2666 | } |
| 2667 | |
| 2668 | /* Fetch and cast the expression. */ |
| 2669 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT); |
| 2670 | if (!smp) { |
| 2671 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt%u.", rule->arg.gpt.idx); |
| 2672 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2673 | ha_alert("stick table: invalid expression or data type while setting gpt%u.\n", rule->arg.gpt.idx); |
| 2674 | return ACT_RET_CONT; |
| 2675 | } |
| 2676 | value = (unsigned int)(smp->data.u.sint); |
| 2677 | } |
| 2678 | |
| 2679 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2680 | |
| 2681 | stktable_data_cast(ptr, std_t_uint) = value; |
| 2682 | |
| 2683 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2684 | |
| 2685 | stktable_touch_local(stkctr->table, ts, 0); |
| 2686 | } |
| 2687 | |
| 2688 | return ACT_RET_CONT; |
| 2689 | } |
| 2690 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 2691 | /* Always returns 1. */ |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2692 | 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] | 2693 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2694 | { |
| 2695 | void *ptr; |
| 2696 | struct stksess *ts; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2697 | struct stkctr *stkctr = NULL; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2698 | unsigned int value = 0; |
| 2699 | struct sample *smp; |
| 2700 | int smp_opt_dir; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2701 | |
| 2702 | /* Extract the stksess, return OK if no stksess available. */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2703 | if (s && s->stkctr) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2704 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2705 | else if (sess->stkctr) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2706 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2707 | else |
| 2708 | return ACT_RET_CONT; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2709 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2710 | ts = stkctr_entry(stkctr); |
| 2711 | if (!ts) |
| 2712 | return ACT_RET_CONT; |
| 2713 | |
| 2714 | /* Store the sample in the required sc, and ignore errors. */ |
| 2715 | ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 2716 | if (!ptr) |
| 2717 | ptr = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPT, 0); |
| 2718 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2719 | if (ptr) { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2720 | if (!rule->arg.gpt.expr) |
| 2721 | value = (unsigned int)(rule->arg.gpt.value); |
| 2722 | else { |
| 2723 | switch (rule->from) { |
| 2724 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2725 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2726 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2727 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2728 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2729 | default: |
| 2730 | send_log(px, LOG_ERR, "stick table: internal error while setting gpt0."); |
| 2731 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2732 | ha_alert("stick table: internal error while executing setting gpt0.\n"); |
| 2733 | return ACT_RET_CONT; |
| 2734 | } |
| 2735 | |
| 2736 | /* Fetch and cast the expression. */ |
| 2737 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpt.expr, SMP_T_SINT); |
| 2738 | if (!smp) { |
| 2739 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpt0."); |
| 2740 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2741 | ha_alert("stick table: invalid expression or data type while setting gpt0.\n"); |
| 2742 | return ACT_RET_CONT; |
| 2743 | } |
| 2744 | value = (unsigned int)(smp->data.u.sint); |
| 2745 | } |
| 2746 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2747 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2748 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 2749 | stktable_data_cast(ptr, std_t_uint) = value; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2750 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2751 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 2752 | |
| 2753 | stktable_touch_local(stkctr->table, ts, 0); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 2754 | } |
| 2755 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2756 | return ACT_RET_CONT; |
| 2757 | } |
| 2758 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2759 | /* This function is a parser for the "sc-set-gpt" and "sc-set-gpt0" actions. |
| 2760 | * It understands the formats: |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2761 | * |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2762 | * sc-set-gpt(<gpt IDX>,<track ID>) <expression> |
| 2763 | * sc-set-gpt0(<track ID>) <expression> |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2764 | * |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2765 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error message. |
| 2766 | * Otherwise, it returns ACT_RET_PRS_OK and the variable 'rule->arg.gpt.expr' |
| 2767 | * is filled with the pointer to the expression to execute or NULL if the arg |
| 2768 | * is directly an integer stored into 'rule->arg.gpt.value'. |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2769 | */ |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2770 | 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] | 2771 | struct act_rule *rule, char **err) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2772 | { |
| 2773 | const char *cmd_name = args[*arg-1]; |
| 2774 | char *error; |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2775 | int smp_val; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2776 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2777 | if (!global.tune.nb_stk_ctr) { |
| 2778 | memprintf(err, "Cannot use '%s', stick-counters are disabled via tune.stick-counters", args[*arg-1]); |
| 2779 | return ACT_RET_PRS_ERR; |
| 2780 | } |
| 2781 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2782 | cmd_name += strlen("sc-set-gpt"); |
| 2783 | if (*cmd_name == '(') { |
| 2784 | cmd_name++; /* skip the '(' */ |
| 2785 | rule->arg.gpt.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2786 | if (*error != ',') { |
| 2787 | 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] | 2788 | return ACT_RET_PRS_ERR; |
| 2789 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2790 | else { |
| 2791 | cmd_name = error + 1; /* skip the ',' */ |
| 2792 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2793 | if (*error != ')') { |
| 2794 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt(<GPT ID>,<Track ID>)", args[*arg-1]); |
| 2795 | return ACT_RET_PRS_ERR; |
| 2796 | } |
| 2797 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2798 | if (rule->arg.gpt.sc >= global.tune.nb_stk_ctr) { |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2799 | 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] | 2800 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2801 | return ACT_RET_PRS_ERR; |
| 2802 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2803 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2804 | rule->action_ptr = action_set_gpt; |
| 2805 | } |
| 2806 | else if (*cmd_name == '0') { |
| 2807 | cmd_name++; |
| 2808 | if (*cmd_name == '\0') { |
| 2809 | /* default stick table id. */ |
| 2810 | rule->arg.gpt.sc = 0; |
| 2811 | } else { |
| 2812 | /* parse the stick table id. */ |
| 2813 | if (*cmd_name != '(') { |
| 2814 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2815 | return ACT_RET_PRS_ERR; |
| 2816 | } |
| 2817 | cmd_name++; /* jump the '(' */ |
| 2818 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2819 | if (*error != ')') { |
| 2820 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 2821 | return ACT_RET_PRS_ERR; |
| 2822 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2823 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 2824 | if (rule->arg.gpt.sc >= global.tune.nb_stk_ctr) { |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2825 | 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] | 2826 | args[*arg-1], global.tune.nb_stk_ctr-1); |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2827 | return ACT_RET_PRS_ERR; |
| 2828 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2829 | } |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 2830 | rule->action_ptr = action_set_gpt0; |
| 2831 | } |
| 2832 | else { |
| 2833 | /* default stick table id. */ |
| 2834 | memprintf(err, "invalid gpt ID '%s'. Expects sc-set-gpt(<GPT ID>,<Track ID>)", args[*arg-1]); |
| 2835 | return ACT_RET_PRS_ERR; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2836 | } |
| 2837 | |
Willy Tarreau | ece4c4a | 2021-08-24 14:57:28 +0200 | [diff] [blame] | 2838 | /* value may be either an integer or an expression */ |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2839 | rule->arg.gpt.expr = NULL; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2840 | rule->arg.gpt.value = strtol(args[*arg], &error, 10); |
Willy Tarreau | ece4c4a | 2021-08-24 14:57:28 +0200 | [diff] [blame] | 2841 | if (*error == '\0') { |
| 2842 | /* valid integer, skip it */ |
| 2843 | (*arg)++; |
| 2844 | } else { |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2845 | 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] | 2846 | px->conf.args.line, err, &px->conf.args, NULL); |
Cédric Dufour | 0d7712d | 2019-11-06 18:38:53 +0100 | [diff] [blame] | 2847 | if (!rule->arg.gpt.expr) |
| 2848 | return ACT_RET_PRS_ERR; |
| 2849 | |
| 2850 | switch (rule->from) { |
| 2851 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 2852 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 2853 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 2854 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 2855 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 2856 | default: |
| 2857 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 2858 | return ACT_RET_PRS_ERR; |
| 2859 | } |
| 2860 | if (!(rule->arg.gpt.expr->fetch->val & smp_val)) { |
| 2861 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 2862 | sample_src_names(rule->arg.gpt.expr->fetch->use)); |
| 2863 | free(rule->arg.gpt.expr); |
| 2864 | return ACT_RET_PRS_ERR; |
| 2865 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2866 | } |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2867 | |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 2868 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2869 | |
| 2870 | return ACT_RET_PRS_OK; |
| 2871 | } |
| 2872 | |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 2873 | /* This function updates the gpc at index 'rule->arg.gpc.idx' of the array on |
| 2874 | * the tracksc counter of index 'rule->arg.gpc.sc' stored into the <stream> or |
| 2875 | * directly in the session <sess> if <stream> is set to NULL. This gpc is |
| 2876 | * set to the value computed by the expression 'rule->arg.gpc.expr' or if |
| 2877 | * 'rule->arg.gpc.expr' is null directly to the value of 'rule->arg.gpc.value'. |
| 2878 | * |
| 2879 | * This function always returns ACT_RET_CONT and parameter flags is unused. |
| 2880 | */ |
| 2881 | static enum act_return action_add_gpc(struct act_rule *rule, struct proxy *px, |
| 2882 | struct session *sess, struct stream *s, int flags) |
| 2883 | { |
| 2884 | void *ptr1, *ptr2; |
| 2885 | struct stksess *ts; |
| 2886 | struct stkctr *stkctr; |
| 2887 | unsigned int value = 0; |
| 2888 | struct sample *smp; |
| 2889 | int smp_opt_dir; |
| 2890 | |
| 2891 | /* Extract the stksess, return OK if no stksess available. */ |
| 2892 | if (s) |
| 2893 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 2894 | else |
| 2895 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
| 2896 | |
| 2897 | ts = stkctr_entry(stkctr); |
| 2898 | if (!ts) |
| 2899 | return ACT_RET_CONT; |
| 2900 | |
| 2901 | /* First, update gpc_rate if it's tracked. Second, update its gpc if tracked. */ |
| 2902 | ptr1 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC_RATE, rule->arg.gpc.idx); |
| 2903 | ptr2 = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPC, rule->arg.gpc.idx); |
| 2904 | |
| 2905 | if (ptr1 || ptr2) { |
| 2906 | if (!rule->arg.gpc.expr) |
| 2907 | value = (unsigned int)(rule->arg.gpc.value); |
| 2908 | else { |
| 2909 | switch (rule->from) { |
| 2910 | case ACT_F_TCP_REQ_SES: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2911 | case ACT_F_TCP_REQ_CNT: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2912 | case ACT_F_TCP_RES_CNT: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2913 | case ACT_F_HTTP_REQ: smp_opt_dir = SMP_OPT_DIR_REQ; break; |
| 2914 | case ACT_F_HTTP_RES: smp_opt_dir = SMP_OPT_DIR_RES; break; |
| 2915 | default: |
| 2916 | send_log(px, LOG_ERR, "stick table: internal error while setting gpc%u.", rule->arg.gpc.idx); |
| 2917 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2918 | ha_alert("stick table: internal error while executing setting gpc%u.\n", rule->arg.gpc.idx); |
| 2919 | return ACT_RET_CONT; |
| 2920 | } |
| 2921 | |
| 2922 | /* Fetch and cast the expression. */ |
| 2923 | smp = sample_fetch_as_type(px, sess, s, smp_opt_dir|SMP_OPT_FINAL, rule->arg.gpc.expr, SMP_T_SINT); |
| 2924 | if (!smp) { |
| 2925 | send_log(px, LOG_WARNING, "stick table: invalid expression or data type while setting gpc%u.", rule->arg.gpc.idx); |
| 2926 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) |
| 2927 | ha_alert("stick table: invalid expression or data type while setting gpc%u.\n", rule->arg.gpc.idx); |
| 2928 | return ACT_RET_CONT; |
| 2929 | } |
| 2930 | value = (unsigned int)(smp->data.u.sint); |
| 2931 | } |
| 2932 | |
| 2933 | if (value) { |
| 2934 | /* only update the value if non-null increment */ |
| 2935 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
| 2936 | |
| 2937 | if (ptr1) |
| 2938 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 2939 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, value); |
| 2940 | |
| 2941 | if (ptr2) |
| 2942 | stktable_data_cast(ptr2, std_t_uint) += value; |
| 2943 | |
| 2944 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
| 2945 | } |
| 2946 | /* always touch the table so that it doesn't expire */ |
| 2947 | stktable_touch_local(stkctr->table, ts, 0); |
| 2948 | } |
| 2949 | |
| 2950 | return ACT_RET_CONT; |
| 2951 | } |
| 2952 | |
| 2953 | /* This function is a parser for the "sc-add-gpc" action. It understands the |
| 2954 | * format: |
| 2955 | * |
| 2956 | * sc-add-gpc(<gpc IDX>,<track ID>) <expression> |
| 2957 | * |
| 2958 | * It returns ACT_RET_PRS_ERR if fails and <err> is filled with an error message. |
| 2959 | * Otherwise, it returns ACT_RET_PRS_OK and the variable 'rule->arg.gpc.expr' |
| 2960 | * is filled with the pointer to the expression to execute or NULL if the arg |
| 2961 | * is directly an integer stored into 'rule->arg.gpt.value'. |
| 2962 | */ |
| 2963 | static enum act_parse_ret parse_add_gpc(const char **args, int *arg, struct proxy *px, |
| 2964 | struct act_rule *rule, char **err) |
| 2965 | { |
| 2966 | const char *cmd_name = args[*arg-1]; |
| 2967 | char *error; |
| 2968 | int smp_val; |
| 2969 | |
| 2970 | cmd_name += strlen("sc-add-gpc"); |
| 2971 | if (*cmd_name != '(') { |
| 2972 | memprintf(err, "Missing or invalid arguments for '%s'. Expects sc-add-gpc(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2973 | return ACT_RET_PRS_ERR; |
| 2974 | } |
| 2975 | cmd_name++; /* skip the '(' */ |
| 2976 | rule->arg.gpc.idx = strtoul(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2977 | if (*error != ',') { |
| 2978 | memprintf(err, "Missing gpc ID. Expects %s(<GPC ID>,<Track ID>)", args[*arg-1]); |
| 2979 | return ACT_RET_PRS_ERR; |
| 2980 | } |
| 2981 | else { |
| 2982 | cmd_name = error + 1; /* skip the ',' */ |
| 2983 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 2984 | if (*error != ')') { |
| 2985 | memprintf(err, "invalid stick table track ID '%s'. Expects %s(<GPC ID>,<Track ID>)", cmd_name, args[*arg-1]); |
| 2986 | return ACT_RET_PRS_ERR; |
| 2987 | } |
| 2988 | |
| 2989 | if (rule->arg.gpc.sc >= MAX_SESS_STKCTR) { |
| 2990 | memprintf(err, "invalid stick table track ID '%s' for '%s'. The max allowed ID is %d", |
| 2991 | cmd_name, args[*arg-1], MAX_SESS_STKCTR-1); |
| 2992 | return ACT_RET_PRS_ERR; |
| 2993 | } |
| 2994 | } |
| 2995 | rule->action_ptr = action_add_gpc; |
| 2996 | |
| 2997 | /* value may be either an integer or an expression */ |
| 2998 | rule->arg.gpc.expr = NULL; |
| 2999 | rule->arg.gpc.value = strtol(args[*arg], &error, 10); |
| 3000 | if (*error == '\0') { |
| 3001 | /* valid integer, skip it */ |
| 3002 | (*arg)++; |
| 3003 | } else { |
| 3004 | rule->arg.gpc.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, |
| 3005 | px->conf.args.line, err, &px->conf.args, NULL); |
| 3006 | if (!rule->arg.gpc.expr) |
| 3007 | return ACT_RET_PRS_ERR; |
| 3008 | |
| 3009 | switch (rule->from) { |
| 3010 | case ACT_F_TCP_REQ_SES: smp_val = SMP_VAL_FE_SES_ACC; break; |
| 3011 | case ACT_F_TCP_REQ_CNT: smp_val = SMP_VAL_FE_REQ_CNT; break; |
| 3012 | case ACT_F_TCP_RES_CNT: smp_val = SMP_VAL_BE_RES_CNT; break; |
| 3013 | case ACT_F_HTTP_REQ: smp_val = SMP_VAL_FE_HRQ_HDR; break; |
| 3014 | case ACT_F_HTTP_RES: smp_val = SMP_VAL_BE_HRS_HDR; break; |
| 3015 | default: |
| 3016 | memprintf(err, "internal error, unexpected rule->from=%d, please report this bug!", rule->from); |
| 3017 | return ACT_RET_PRS_ERR; |
| 3018 | } |
| 3019 | |
| 3020 | if (!(rule->arg.gpc.expr->fetch->val & smp_val)) { |
| 3021 | memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", args[*arg-1], |
| 3022 | sample_src_names(rule->arg.gpc.expr->fetch->use)); |
| 3023 | free(rule->arg.gpc.expr); |
| 3024 | return ACT_RET_PRS_ERR; |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | rule->action = ACT_CUSTOM; |
| 3029 | |
| 3030 | return ACT_RET_PRS_OK; |
| 3031 | } |
| 3032 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3033 | /* set temp integer to the number of used entries in the table pointed to by expr. |
| 3034 | * Accepts exactly 1 argument of type table. |
| 3035 | */ |
| 3036 | static int |
| 3037 | smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3038 | { |
| 3039 | smp->flags = SMP_F_VOL_TEST; |
| 3040 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3041 | smp->data.u.sint = args->data.t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3042 | return 1; |
| 3043 | } |
| 3044 | |
| 3045 | /* set temp integer to the number of free entries in the table pointed to by expr. |
| 3046 | * Accepts exactly 1 argument of type table. |
| 3047 | */ |
| 3048 | static int |
| 3049 | smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3050 | { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3051 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3052 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3053 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3054 | smp->flags = SMP_F_VOL_TEST; |
| 3055 | smp->data.type = SMP_T_SINT; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3056 | smp->data.u.sint = t->size - t->current; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3057 | return 1; |
| 3058 | } |
| 3059 | |
| 3060 | /* Returns a pointer to a stkctr depending on the fetch keyword name. |
| 3061 | * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively. |
| 3062 | * sc[0-9]_* will return a pointer to the respective field in the |
| 3063 | * stream <l4>. sc_* requires an UINT argument specifying the stick |
| 3064 | * counter number. src_* will fill a locally allocated structure with |
| 3065 | * the table and entry corresponding to what is specified with src_*. |
| 3066 | * NULL may be returned if the designated stkctr is not tracked. For |
| 3067 | * the sc_* and sc[0-9]_* forms, an optional table argument may be |
| 3068 | * passed. When present, the currently tracked key is then looked up |
| 3069 | * in the specified table instead of the current table. The purpose is |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 3070 | * 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] | 3071 | * multiple tables). <strm> is allowed to be NULL, in which case only |
| 3072 | * the session will be consulted. |
| 3073 | */ |
| 3074 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3075 | 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] | 3076 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3077 | struct stkctr *stkptr; |
| 3078 | struct stksess *stksess; |
| 3079 | unsigned int num = kw[2] - '0'; |
| 3080 | int arg = 0; |
| 3081 | |
| 3082 | if (num == '_' - '0') { |
| 3083 | /* sc_* variant, args[0] = ctr# (mandatory) */ |
| 3084 | num = args[arg++].data.sint; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3085 | } |
| 3086 | else if (num > 9) { /* src_* variant, args[0] = table */ |
| 3087 | struct stktable_key *key; |
| 3088 | struct connection *conn = objt_conn(sess->origin); |
| 3089 | struct sample smp; |
| 3090 | |
| 3091 | if (!conn) |
| 3092 | return NULL; |
| 3093 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3094 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3095 | smp.px = NULL; |
| 3096 | smp.sess = sess; |
| 3097 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3098 | 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] | 3099 | return NULL; |
| 3100 | |
| 3101 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3102 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3103 | if (!key) |
| 3104 | return NULL; |
| 3105 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3106 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3107 | stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key)); |
| 3108 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | /* Here, <num> contains the counter number from 0 to 9 for |
| 3112 | * the sc[0-9]_ form, or even higher using sc_(num) if needed. |
| 3113 | * args[arg] is the first optional argument. We first lookup the |
| 3114 | * 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] | 3115 | * 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] | 3116 | */ |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3117 | if (num >= global.tune.nb_stk_ctr) |
Christopher Faulet | a9fa88a | 2019-10-21 10:53:34 +0200 | [diff] [blame] | 3118 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3119 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3120 | stkptr = NULL; |
| 3121 | if (strm && strm->stkctr) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3122 | stkptr = &strm->stkctr[num]; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 3123 | if (!strm || !stkptr || !stkctr_entry(stkptr)) { |
| 3124 | if (sess->stkctr) |
| 3125 | stkptr = &sess->stkctr[num]; |
| 3126 | else |
| 3127 | return NULL; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3128 | if (!stkctr_entry(stkptr)) |
| 3129 | return NULL; |
| 3130 | } |
| 3131 | |
| 3132 | stksess = stkctr_entry(stkptr); |
| 3133 | if (!stksess) |
| 3134 | return NULL; |
| 3135 | |
| 3136 | if (unlikely(args[arg].type == ARGT_TAB)) { |
| 3137 | /* 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] | 3138 | stkctr->table = args[arg].data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3139 | stkctr_set_entry(stkctr, stktable_lookup(stkctr->table, stksess)); |
| 3140 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3141 | } |
| 3142 | return stkptr; |
| 3143 | } |
| 3144 | |
| 3145 | /* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create |
| 3146 | * the entry if it doesn't exist yet. This is needed for a few fetch |
| 3147 | * functions which need to create an entry, such as src_inc_gpc* and |
| 3148 | * src_clr_gpc*. |
| 3149 | */ |
| 3150 | struct stkctr * |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3151 | 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] | 3152 | { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3153 | struct stktable_key *key; |
| 3154 | struct connection *conn = objt_conn(sess->origin); |
| 3155 | struct sample smp; |
| 3156 | |
| 3157 | if (strncmp(kw, "src_", 4) != 0) |
| 3158 | return NULL; |
| 3159 | |
| 3160 | if (!conn) |
| 3161 | return NULL; |
| 3162 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 3163 | /* Fetch source address in a sample. */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3164 | smp.px = NULL; |
| 3165 | smp.sess = sess; |
| 3166 | smp.strm = strm; |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 3167 | 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] | 3168 | return NULL; |
| 3169 | |
| 3170 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3171 | key = smp_to_stkey(&smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3172 | if (!key) |
| 3173 | return NULL; |
| 3174 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 3175 | stkctr->table = args->data.t; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3176 | stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key)); |
| 3177 | return stkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | /* set return a boolean indicating if the requested stream counter is |
| 3181 | * currently being tracked or not. |
| 3182 | * Supports being called as "sc[0-9]_tracked" only. |
| 3183 | */ |
| 3184 | static int |
| 3185 | smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3186 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3187 | struct stkctr tmpstkctr; |
| 3188 | struct stkctr *stkctr; |
| 3189 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3190 | smp->flags = SMP_F_VOL_TEST; |
| 3191 | smp->data.type = SMP_T_BOOL; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3192 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3193 | smp->data.u.sint = !!stkctr; |
| 3194 | |
| 3195 | /* release the ref count */ |
Dirkjan Bussink | ff57f1b | 2018-09-14 14:31:22 +0200 | [diff] [blame] | 3196 | if (stkctr == &tmpstkctr) |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3197 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3198 | |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 3199 | return 1; |
| 3200 | } |
| 3201 | |
| 3202 | /* set <smp> to the General Purpose Tag of index set as first arg |
| 3203 | * to value from the stream's tracked frontend counters or from the src. |
| 3204 | * Supports being called as "sc_get_gpt(<gpt-idx>,<sc-idx>[,<table>])" or |
| 3205 | * "src_get_gpt(<gpt-idx>[,<table>])" only. Value zero is returned if |
| 3206 | * the key is new or gpt is not stored. |
| 3207 | */ |
| 3208 | static int |
| 3209 | smp_fetch_sc_get_gpt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3210 | { |
| 3211 | struct stkctr tmpstkctr; |
| 3212 | struct stkctr *stkctr; |
| 3213 | unsigned int idx; |
| 3214 | |
| 3215 | idx = args[0].data.sint; |
| 3216 | |
| 3217 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3218 | if (!stkctr) |
| 3219 | return 0; |
| 3220 | |
| 3221 | smp->flags = SMP_F_VOL_TEST; |
| 3222 | smp->data.type = SMP_T_SINT; |
| 3223 | smp->data.u.sint = 0; |
| 3224 | |
| 3225 | if (stkctr_entry(stkctr)) { |
| 3226 | void *ptr; |
| 3227 | |
| 3228 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, idx); |
| 3229 | if (!ptr) { |
| 3230 | if (stkctr == &tmpstkctr) |
| 3231 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3232 | return 0; /* parameter not stored */ |
| 3233 | } |
| 3234 | |
| 3235 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3236 | |
| 3237 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3238 | |
| 3239 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3240 | |
| 3241 | if (stkctr == &tmpstkctr) |
| 3242 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3243 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3244 | return 1; |
| 3245 | } |
| 3246 | |
| 3247 | /* set <smp> to the General Purpose Flag 0 value from the stream's tracked |
| 3248 | * frontend counters or from the src. |
| 3249 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value |
| 3250 | * zero is returned if the key is new. |
| 3251 | */ |
| 3252 | static int |
| 3253 | smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3254 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3255 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3256 | struct stkctr *stkctr; |
| 3257 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3258 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3259 | if (!stkctr) |
| 3260 | return 0; |
| 3261 | |
| 3262 | smp->flags = SMP_F_VOL_TEST; |
| 3263 | smp->data.type = SMP_T_SINT; |
| 3264 | smp->data.u.sint = 0; |
| 3265 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3266 | if (stkctr_entry(stkctr)) { |
| 3267 | void *ptr; |
| 3268 | |
| 3269 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0); |
Emeric Brun | f7ab0bf | 2021-06-30 18:58:22 +0200 | [diff] [blame] | 3270 | if (!ptr) |
| 3271 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, 0); |
| 3272 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3273 | if (!ptr) { |
| 3274 | if (stkctr == &tmpstkctr) |
| 3275 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3276 | return 0; /* parameter not stored */ |
| 3277 | } |
| 3278 | |
| 3279 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3280 | |
| 3281 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3282 | |
| 3283 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3284 | |
| 3285 | if (stkctr == &tmpstkctr) |
| 3286 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3287 | } |
| 3288 | return 1; |
| 3289 | } |
| 3290 | |
| 3291 | /* set <smp> to the GPC[args(0)]'s value from the stream's tracked |
| 3292 | * frontend counters or from the src. |
| 3293 | * Supports being called as "sc_get_gpc(<gpc-idx>,<sc-idx>[,<table>])" or |
| 3294 | * "src_get_gpc(<gpc-idx>[,<table>])" only. Value |
| 3295 | * Value zero is returned if the key is new or gpc is not stored. |
| 3296 | */ |
| 3297 | static int |
| 3298 | smp_fetch_sc_get_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3299 | { |
| 3300 | struct stkctr tmpstkctr; |
| 3301 | struct stkctr *stkctr; |
| 3302 | unsigned int idx; |
| 3303 | |
| 3304 | idx = args[0].data.sint; |
| 3305 | |
| 3306 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3307 | if (!stkctr) |
| 3308 | return 0; |
| 3309 | |
| 3310 | smp->flags = SMP_F_VOL_TEST; |
| 3311 | smp->data.type = SMP_T_SINT; |
| 3312 | smp->data.u.sint = 0; |
| 3313 | |
| 3314 | if (stkctr_entry(stkctr) != NULL) { |
| 3315 | void *ptr; |
| 3316 | |
| 3317 | 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] | 3318 | if (!ptr) { |
| 3319 | if (stkctr == &tmpstkctr) |
| 3320 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3321 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3322 | } |
| 3323 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3324 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3325 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3326 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3327 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3328 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3329 | |
| 3330 | if (stkctr == &tmpstkctr) |
| 3331 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3332 | } |
| 3333 | return 1; |
| 3334 | } |
| 3335 | |
| 3336 | /* set <smp> to the General Purpose Counter 0 value from the stream's tracked |
| 3337 | * frontend counters or from the src. |
| 3338 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value |
| 3339 | * zero is returned if the key is new. |
| 3340 | */ |
| 3341 | static int |
| 3342 | smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3343 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3344 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3345 | struct stkctr *stkctr; |
| 3346 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3347 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3348 | if (!stkctr) |
| 3349 | return 0; |
| 3350 | |
| 3351 | smp->flags = SMP_F_VOL_TEST; |
| 3352 | smp->data.type = SMP_T_SINT; |
| 3353 | smp->data.u.sint = 0; |
| 3354 | |
| 3355 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3356 | void *ptr; |
| 3357 | |
| 3358 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3359 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3360 | /* fallback on the gpc array */ |
| 3361 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3362 | } |
| 3363 | |
| 3364 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3365 | if (stkctr == &tmpstkctr) |
| 3366 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3367 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3368 | } |
| 3369 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3370 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3371 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3372 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3373 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3374 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3375 | |
| 3376 | if (stkctr == &tmpstkctr) |
| 3377 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3378 | } |
| 3379 | return 1; |
| 3380 | } |
| 3381 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3382 | /* set <smp> to the General Purpose Counter 1 value from the stream's tracked |
| 3383 | * frontend counters or from the src. |
| 3384 | * Supports being called as "sc[0-9]_get_gpc1" or "src_get_gpc1" only. Value |
| 3385 | * zero is returned if the key is new. |
| 3386 | */ |
| 3387 | static int |
| 3388 | smp_fetch_sc_get_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3389 | { |
| 3390 | struct stkctr tmpstkctr; |
| 3391 | struct stkctr *stkctr; |
| 3392 | |
| 3393 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3394 | if (!stkctr) |
| 3395 | return 0; |
| 3396 | |
| 3397 | smp->flags = SMP_F_VOL_TEST; |
| 3398 | smp->data.type = SMP_T_SINT; |
| 3399 | smp->data.u.sint = 0; |
| 3400 | |
| 3401 | if (stkctr_entry(stkctr) != NULL) { |
| 3402 | void *ptr; |
| 3403 | |
| 3404 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3405 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3406 | /* fallback on the gpc array */ |
| 3407 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3408 | } |
| 3409 | |
| 3410 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3411 | if (stkctr == &tmpstkctr) |
| 3412 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3413 | return 0; /* parameter not stored */ |
| 3414 | } |
| 3415 | |
| 3416 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3417 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3418 | 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] | 3419 | |
| 3420 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3421 | |
| 3422 | if (stkctr == &tmpstkctr) |
| 3423 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3424 | } |
| 3425 | return 1; |
| 3426 | } |
| 3427 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3428 | /* set <smp> to the GPC[args(0)]'s event rate from the stream's |
| 3429 | * tracked frontend counters or from the src. |
| 3430 | * Supports being called as "sc_gpc_rate(<gpc-idx>,<sc-idx>[,<table])" |
| 3431 | * or "src_gpc_rate(<gpc-idx>[,<table>])" only. |
| 3432 | * Value zero is returned if the key is new or gpc_rate is not stored. |
| 3433 | */ |
| 3434 | static int |
| 3435 | smp_fetch_sc_gpc_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3436 | { |
| 3437 | struct stkctr tmpstkctr; |
| 3438 | struct stkctr *stkctr; |
| 3439 | unsigned int idx; |
| 3440 | |
| 3441 | idx = args[0].data.sint; |
| 3442 | |
| 3443 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3444 | if (!stkctr) |
| 3445 | return 0; |
| 3446 | |
| 3447 | smp->flags = SMP_F_VOL_TEST; |
| 3448 | smp->data.type = SMP_T_SINT; |
| 3449 | smp->data.u.sint = 0; |
| 3450 | if (stkctr_entry(stkctr) != NULL) { |
| 3451 | void *ptr; |
| 3452 | |
| 3453 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3454 | if (!ptr) { |
| 3455 | if (stkctr == &tmpstkctr) |
| 3456 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3457 | return 0; /* parameter not stored */ |
| 3458 | } |
| 3459 | |
| 3460 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3461 | |
| 3462 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 3463 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u); |
| 3464 | |
| 3465 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3466 | |
| 3467 | if (stkctr == &tmpstkctr) |
| 3468 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3469 | } |
| 3470 | return 1; |
| 3471 | } |
| 3472 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3473 | /* set <smp> to the General Purpose Counter 0's event rate from the stream's |
| 3474 | * tracked frontend counters or from the src. |
| 3475 | * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only. |
| 3476 | * Value zero is returned if the key is new. |
| 3477 | */ |
| 3478 | static int |
| 3479 | smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3480 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3481 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3482 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3483 | unsigned int period; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3484 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3485 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3486 | if (!stkctr) |
| 3487 | return 0; |
| 3488 | |
| 3489 | smp->flags = SMP_F_VOL_TEST; |
| 3490 | smp->data.type = SMP_T_SINT; |
| 3491 | smp->data.u.sint = 0; |
| 3492 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3493 | void *ptr; |
| 3494 | |
| 3495 | 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] | 3496 | if (ptr) { |
| 3497 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3498 | } |
| 3499 | else { |
| 3500 | /* fallback on the gpc array */ |
| 3501 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3502 | if (ptr) |
| 3503 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3504 | } |
| 3505 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3506 | if (!ptr) { |
| 3507 | if (stkctr == &tmpstkctr) |
| 3508 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3509 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3510 | } |
| 3511 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3512 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3513 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3514 | 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] | 3515 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3516 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3517 | |
| 3518 | if (stkctr == &tmpstkctr) |
| 3519 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3520 | } |
| 3521 | return 1; |
| 3522 | } |
| 3523 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3524 | /* set <smp> to the General Purpose Counter 1's event rate from the stream's |
| 3525 | * tracked frontend counters or from the src. |
| 3526 | * Supports being called as "sc[0-9]_gpc1_rate" or "src_gpc1_rate" only. |
| 3527 | * Value zero is returned if the key is new. |
| 3528 | */ |
| 3529 | static int |
| 3530 | smp_fetch_sc_gpc1_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3531 | { |
| 3532 | struct stkctr tmpstkctr; |
| 3533 | struct stkctr *stkctr; |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3534 | unsigned int period; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3535 | |
| 3536 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3537 | if (!stkctr) |
| 3538 | return 0; |
| 3539 | |
| 3540 | smp->flags = SMP_F_VOL_TEST; |
| 3541 | smp->data.type = SMP_T_SINT; |
| 3542 | smp->data.u.sint = 0; |
| 3543 | if (stkctr_entry(stkctr) != NULL) { |
| 3544 | void *ptr; |
| 3545 | |
| 3546 | 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] | 3547 | if (ptr) { |
| 3548 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3549 | } |
| 3550 | else { |
| 3551 | /* fallback on the gpc array */ |
| 3552 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3553 | if (ptr) |
| 3554 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3555 | } |
| 3556 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3557 | if (!ptr) { |
| 3558 | if (stkctr == &tmpstkctr) |
| 3559 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3560 | return 0; /* parameter not stored */ |
| 3561 | } |
| 3562 | |
| 3563 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3564 | |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3565 | 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] | 3566 | |
| 3567 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3568 | |
| 3569 | if (stkctr == &tmpstkctr) |
| 3570 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3571 | } |
| 3572 | return 1; |
| 3573 | } |
| 3574 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3575 | /* Increment the GPC[args(0)] value from the stream's tracked |
| 3576 | * frontend counters and return it into temp integer. |
| 3577 | * Supports being called as "sc_inc_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3578 | * or "src_inc_gpc(<gpc-idx>[,<table>])" only. |
| 3579 | */ |
| 3580 | static int |
| 3581 | smp_fetch_sc_inc_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3582 | { |
| 3583 | struct stkctr tmpstkctr; |
| 3584 | struct stkctr *stkctr; |
| 3585 | unsigned int idx; |
| 3586 | |
| 3587 | idx = args[0].data.sint; |
| 3588 | |
| 3589 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3590 | if (!stkctr) |
| 3591 | return 0; |
| 3592 | |
| 3593 | smp->flags = SMP_F_VOL_TEST; |
| 3594 | smp->data.type = SMP_T_SINT; |
| 3595 | smp->data.u.sint = 0; |
| 3596 | |
| 3597 | if (!stkctr_entry(stkctr)) |
| 3598 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3599 | |
| 3600 | if (stkctr && stkctr_entry(stkctr)) { |
| 3601 | void *ptr1,*ptr2; |
| 3602 | |
| 3603 | |
| 3604 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3605 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3606 | */ |
| 3607 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, idx); |
| 3608 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3609 | if (ptr1 || ptr2) { |
| 3610 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3611 | |
| 3612 | if (ptr1) { |
| 3613 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
| 3614 | stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u, 1); |
| 3615 | smp->data.u.sint = (&stktable_data_cast(ptr1, std_t_frqp))->curr_ctr; |
| 3616 | } |
| 3617 | |
| 3618 | if (ptr2) |
| 3619 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
| 3620 | |
| 3621 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3622 | |
| 3623 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3624 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3625 | } |
| 3626 | else if (stkctr == &tmpstkctr) |
| 3627 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3628 | } |
| 3629 | return 1; |
| 3630 | } |
| 3631 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3632 | /* Increment the General Purpose Counter 0 value from the stream's tracked |
| 3633 | * frontend counters and return it into temp integer. |
| 3634 | * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. |
| 3635 | */ |
| 3636 | static int |
| 3637 | smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3638 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3639 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3640 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3641 | unsigned int period = 0; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3642 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3643 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3644 | if (!stkctr) |
| 3645 | return 0; |
| 3646 | |
| 3647 | smp->flags = SMP_F_VOL_TEST; |
| 3648 | smp->data.type = SMP_T_SINT; |
| 3649 | smp->data.u.sint = 0; |
| 3650 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3651 | if (!stkctr_entry(stkctr)) |
| 3652 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3653 | |
| 3654 | if (stkctr && stkctr_entry(stkctr)) { |
| 3655 | void *ptr1,*ptr2; |
| 3656 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3657 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3658 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 3659 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 3660 | */ |
| 3661 | 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] | 3662 | if (ptr1) { |
| 3663 | period = stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u; |
| 3664 | } |
| 3665 | else { |
| 3666 | /* fallback on the gpc array */ |
| 3667 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 0); |
| 3668 | if (ptr1) |
| 3669 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3670 | } |
| 3671 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3672 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3673 | if (!ptr2) { |
| 3674 | /* fallback on the gpc array */ |
| 3675 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3676 | } |
| 3677 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3678 | if (ptr1 || ptr2) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3679 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3680 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3681 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3682 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3683 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3684 | 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] | 3685 | } |
| 3686 | |
| 3687 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3688 | smp->data.u.sint = ++stktable_data_cast(ptr2, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3689 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3690 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3691 | |
| 3692 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3693 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3694 | } |
| 3695 | else if (stkctr == &tmpstkctr) |
| 3696 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3697 | } |
| 3698 | return 1; |
| 3699 | } |
| 3700 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3701 | /* Increment the General Purpose Counter 1 value from the stream's tracked |
| 3702 | * frontend counters and return it into temp integer. |
| 3703 | * Supports being called as "sc[0-9]_inc_gpc1" or "src_inc_gpc1" only. |
| 3704 | */ |
| 3705 | static int |
| 3706 | smp_fetch_sc_inc_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3707 | { |
| 3708 | struct stkctr tmpstkctr; |
| 3709 | struct stkctr *stkctr; |
Willy Tarreau | 5b654ad | 2021-07-06 18:51:12 +0200 | [diff] [blame] | 3710 | unsigned int period = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3711 | |
| 3712 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3713 | if (!stkctr) |
| 3714 | return 0; |
| 3715 | |
| 3716 | smp->flags = SMP_F_VOL_TEST; |
| 3717 | smp->data.type = SMP_T_SINT; |
| 3718 | smp->data.u.sint = 0; |
| 3719 | |
| 3720 | if (!stkctr_entry(stkctr)) |
| 3721 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3722 | |
| 3723 | if (stkctr && stkctr_entry(stkctr)) { |
| 3724 | void *ptr1,*ptr2; |
| 3725 | |
| 3726 | |
| 3727 | /* First, update gpc1_rate if it's tracked. Second, update its |
| 3728 | * gpc1 if tracked. Returns gpc1's value otherwise the curr_ctr. |
| 3729 | */ |
| 3730 | 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] | 3731 | if (ptr1) { |
| 3732 | period = stkctr->table->data_arg[STKTABLE_DT_GPC1_RATE].u; |
| 3733 | } |
| 3734 | else { |
| 3735 | /* fallback on the gpc array */ |
| 3736 | ptr1 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC_RATE, 1); |
| 3737 | if (ptr1) |
| 3738 | period = stkctr->table->data_arg[STKTABLE_DT_GPC_RATE].u; |
| 3739 | } |
| 3740 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3741 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3742 | if (!ptr2) { |
| 3743 | /* fallback on the gpc array */ |
| 3744 | ptr2 = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3745 | } |
| 3746 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3747 | if (ptr1 || ptr2) { |
| 3748 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3749 | |
| 3750 | if (ptr1) { |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3751 | update_freq_ctr_period(&stktable_data_cast(ptr1, std_t_frqp), |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3752 | period, 1); |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3753 | 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] | 3754 | } |
| 3755 | |
| 3756 | if (ptr2) |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3757 | 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] | 3758 | |
| 3759 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3760 | |
| 3761 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3762 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3763 | } |
| 3764 | else if (stkctr == &tmpstkctr) |
| 3765 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3766 | } |
| 3767 | return 1; |
| 3768 | } |
| 3769 | |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 3770 | /* Clear the GPC[args(0)] value from the stream's tracked |
| 3771 | * frontend counters and return its previous value into temp integer. |
| 3772 | * Supports being called as "sc_clr_gpc(<gpc-idx>,<sc-idx>[,<table>])" |
| 3773 | * or "src_clr_gpc(<gpc-idx>[,<table>])" only. |
| 3774 | */ |
| 3775 | static int |
| 3776 | smp_fetch_sc_clr_gpc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3777 | { |
| 3778 | struct stkctr tmpstkctr; |
| 3779 | struct stkctr *stkctr; |
| 3780 | unsigned int idx; |
| 3781 | |
| 3782 | idx = args[0].data.sint; |
| 3783 | |
| 3784 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args + 1, kw, &tmpstkctr); |
| 3785 | if (!stkctr) |
| 3786 | return 0; |
| 3787 | |
| 3788 | smp->flags = SMP_F_VOL_TEST; |
| 3789 | smp->data.type = SMP_T_SINT; |
| 3790 | smp->data.u.sint = 0; |
| 3791 | |
| 3792 | if (!stkctr_entry(stkctr)) |
| 3793 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3794 | |
| 3795 | if (stkctr && stkctr_entry(stkctr)) { |
| 3796 | void *ptr; |
| 3797 | |
| 3798 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, idx); |
| 3799 | if (!ptr) { |
| 3800 | if (stkctr == &tmpstkctr) |
| 3801 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3802 | return 0; /* parameter not stored */ |
| 3803 | } |
| 3804 | |
| 3805 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3806 | |
| 3807 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3808 | stktable_data_cast(ptr, std_t_uint) = 0; |
| 3809 | |
| 3810 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3811 | |
| 3812 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3813 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3814 | } |
| 3815 | return 1; |
| 3816 | } |
| 3817 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3818 | /* Clear the General Purpose Counter 0 value from the stream's tracked |
| 3819 | * frontend counters and return its previous value into temp integer. |
| 3820 | * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only. |
| 3821 | */ |
| 3822 | static int |
| 3823 | smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3824 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3825 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3826 | struct stkctr *stkctr; |
| 3827 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3828 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3829 | if (!stkctr) |
| 3830 | return 0; |
| 3831 | |
| 3832 | smp->flags = SMP_F_VOL_TEST; |
| 3833 | smp->data.type = SMP_T_SINT; |
| 3834 | smp->data.u.sint = 0; |
| 3835 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3836 | if (!stkctr_entry(stkctr)) |
| 3837 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3838 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3839 | if (stkctr && stkctr_entry(stkctr)) { |
| 3840 | void *ptr; |
| 3841 | |
| 3842 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 3843 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3844 | /* fallback on the gpc array */ |
| 3845 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 0); |
| 3846 | } |
| 3847 | |
| 3848 | if (!ptr) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3849 | if (stkctr == &tmpstkctr) |
| 3850 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3851 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3852 | } |
| 3853 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3854 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3855 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3856 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3857 | stktable_data_cast(ptr, std_t_uint) = 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3858 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3859 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3860 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3861 | /* If data was modified, we need to touch to re-schedule sync */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3862 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3863 | } |
| 3864 | return 1; |
| 3865 | } |
| 3866 | |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3867 | /* Clear the General Purpose Counter 1 value from the stream's tracked |
| 3868 | * frontend counters and return its previous value into temp integer. |
| 3869 | * Supports being called as "sc[0-9]_clr_gpc1" or "src_clr_gpc1" only. |
| 3870 | */ |
| 3871 | static int |
| 3872 | smp_fetch_sc_clr_gpc1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3873 | { |
| 3874 | struct stkctr tmpstkctr; |
| 3875 | struct stkctr *stkctr; |
| 3876 | |
| 3877 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3878 | if (!stkctr) |
| 3879 | return 0; |
| 3880 | |
| 3881 | smp->flags = SMP_F_VOL_TEST; |
| 3882 | smp->data.type = SMP_T_SINT; |
| 3883 | smp->data.u.sint = 0; |
| 3884 | |
| 3885 | if (!stkctr_entry(stkctr)) |
| 3886 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 3887 | |
| 3888 | if (stkctr && stkctr_entry(stkctr)) { |
| 3889 | void *ptr; |
| 3890 | |
| 3891 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC1); |
| 3892 | if (!ptr) { |
Emeric Brun | 726783d | 2021-06-30 19:06:43 +0200 | [diff] [blame] | 3893 | /* fallback on the gpc array */ |
| 3894 | ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC, 1); |
| 3895 | } |
| 3896 | |
| 3897 | if (!ptr) { |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3898 | if (stkctr == &tmpstkctr) |
| 3899 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3900 | return 0; /* parameter not stored */ |
| 3901 | } |
| 3902 | |
| 3903 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3904 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3905 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
| 3906 | stktable_data_cast(ptr, std_t_uint) = 0; |
Frédéric Lécaille | 6778b27 | 2018-01-29 15:22:53 +0100 | [diff] [blame] | 3907 | |
| 3908 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 3909 | |
| 3910 | /* If data was modified, we need to touch to re-schedule sync */ |
| 3911 | stktable_touch_local(stkctr->table, stkctr_entry(stkctr), (stkctr == &tmpstkctr) ? 1 : 0); |
| 3912 | } |
| 3913 | return 1; |
| 3914 | } |
| 3915 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3916 | /* set <smp> to the cumulated number of connections from the stream's tracked |
| 3917 | * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or |
| 3918 | * "src_conn_cnt" only. |
| 3919 | */ |
| 3920 | static int |
| 3921 | smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3922 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3923 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3924 | struct stkctr *stkctr; |
| 3925 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3926 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3927 | if (!stkctr) |
| 3928 | return 0; |
| 3929 | |
| 3930 | smp->flags = SMP_F_VOL_TEST; |
| 3931 | smp->data.type = SMP_T_SINT; |
| 3932 | smp->data.u.sint = 0; |
| 3933 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3934 | void *ptr; |
| 3935 | |
| 3936 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); |
| 3937 | if (!ptr) { |
| 3938 | if (stkctr == &tmpstkctr) |
| 3939 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3940 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3941 | } |
| 3942 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3943 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3944 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3945 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3946 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3947 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3948 | |
| 3949 | if (stkctr == &tmpstkctr) |
| 3950 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 3951 | |
| 3952 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3953 | } |
| 3954 | return 1; |
| 3955 | } |
| 3956 | |
| 3957 | /* set <smp> to the connection rate from the stream's tracked frontend |
| 3958 | * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate" |
| 3959 | * only. |
| 3960 | */ |
| 3961 | static int |
| 3962 | smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 3963 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3964 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3965 | struct stkctr *stkctr; |
| 3966 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3967 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3968 | if (!stkctr) |
| 3969 | return 0; |
| 3970 | |
| 3971 | smp->flags = SMP_F_VOL_TEST; |
| 3972 | smp->data.type = SMP_T_SINT; |
| 3973 | smp->data.u.sint = 0; |
| 3974 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3975 | void *ptr; |
| 3976 | |
| 3977 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); |
| 3978 | if (!ptr) { |
| 3979 | if (stkctr == &tmpstkctr) |
| 3980 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3981 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3982 | } |
| 3983 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3984 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3985 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 3986 | 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] | 3987 | stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3988 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3989 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 3990 | |
| 3991 | if (stkctr == &tmpstkctr) |
| 3992 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 3993 | } |
| 3994 | return 1; |
| 3995 | } |
| 3996 | |
| 3997 | /* set temp integer to the number of connections from the stream's source address |
| 3998 | * in the table pointed to by expr, after updating it. |
| 3999 | * Accepts exactly 1 argument of type table. |
| 4000 | */ |
| 4001 | static int |
| 4002 | smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4003 | { |
| 4004 | struct connection *conn = objt_conn(smp->sess->origin); |
| 4005 | struct stksess *ts; |
| 4006 | struct stktable_key *key; |
| 4007 | void *ptr; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4008 | struct stktable *t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4009 | |
| 4010 | if (!conn) |
| 4011 | return 0; |
| 4012 | |
Joseph Herlant | 5662fa4 | 2018-11-15 13:43:28 -0800 | [diff] [blame] | 4013 | /* Fetch source address in a sample. */ |
Amaury Denoyelle | c460c70 | 2021-05-12 10:17:47 +0200 | [diff] [blame] | 4014 | 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] | 4015 | return 0; |
| 4016 | |
| 4017 | /* Converts into key. */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4018 | key = smp_to_stkey(smp, args->data.t); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4019 | if (!key) |
| 4020 | return 0; |
| 4021 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4022 | t = args->data.t; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4023 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4024 | if ((ts = stktable_get_entry(t, key)) == NULL) |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4025 | /* entry does not exist and could not be created */ |
| 4026 | return 0; |
| 4027 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4028 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4029 | if (!ptr) { |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4030 | return 0; /* parameter not stored in this table */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4031 | } |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4032 | |
| 4033 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4034 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4035 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4036 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4037 | smp->data.u.sint = ++stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4038 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4039 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4040 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4041 | smp->flags = SMP_F_VOL_TEST; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4042 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4043 | stktable_touch_local(t, ts, 1); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4044 | |
| 4045 | /* Touch was previously performed by stktable_update_key */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4046 | return 1; |
| 4047 | } |
| 4048 | |
| 4049 | /* set <smp> to the number of concurrent connections from the stream's tracked |
| 4050 | * frontend counters. Supports being called as "sc[0-9]_conn_cur" or |
| 4051 | * "src_conn_cur" only. |
| 4052 | */ |
| 4053 | static int |
| 4054 | smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4055 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4056 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4057 | struct stkctr *stkctr; |
| 4058 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4059 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4060 | if (!stkctr) |
| 4061 | return 0; |
| 4062 | |
| 4063 | smp->flags = SMP_F_VOL_TEST; |
| 4064 | smp->data.type = SMP_T_SINT; |
| 4065 | smp->data.u.sint = 0; |
| 4066 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4067 | void *ptr; |
| 4068 | |
| 4069 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); |
| 4070 | if (!ptr) { |
| 4071 | if (stkctr == &tmpstkctr) |
| 4072 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4073 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4074 | } |
| 4075 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4076 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4077 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4078 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4079 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4080 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4081 | |
| 4082 | if (stkctr == &tmpstkctr) |
| 4083 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4084 | } |
| 4085 | return 1; |
| 4086 | } |
| 4087 | |
| 4088 | /* set <smp> to the cumulated number of streams from the stream's tracked |
| 4089 | * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or |
| 4090 | * "src_sess_cnt" only. |
| 4091 | */ |
| 4092 | static int |
| 4093 | smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4094 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4095 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4096 | struct stkctr *stkctr; |
| 4097 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4098 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4099 | if (!stkctr) |
| 4100 | return 0; |
| 4101 | |
| 4102 | smp->flags = SMP_F_VOL_TEST; |
| 4103 | smp->data.type = SMP_T_SINT; |
| 4104 | smp->data.u.sint = 0; |
| 4105 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4106 | void *ptr; |
| 4107 | |
| 4108 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); |
| 4109 | if (!ptr) { |
| 4110 | if (stkctr == &tmpstkctr) |
| 4111 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4112 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4113 | } |
| 4114 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4115 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4116 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4117 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4118 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4119 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4120 | |
| 4121 | if (stkctr == &tmpstkctr) |
| 4122 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4123 | } |
| 4124 | return 1; |
| 4125 | } |
| 4126 | |
| 4127 | /* set <smp> to the stream rate from the stream's tracked frontend counters. |
| 4128 | * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only. |
| 4129 | */ |
| 4130 | static int |
| 4131 | smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4132 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4133 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4134 | struct stkctr *stkctr; |
| 4135 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4136 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4137 | if (!stkctr) |
| 4138 | return 0; |
| 4139 | |
| 4140 | smp->flags = SMP_F_VOL_TEST; |
| 4141 | smp->data.type = SMP_T_SINT; |
| 4142 | smp->data.u.sint = 0; |
| 4143 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4144 | void *ptr; |
| 4145 | |
| 4146 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); |
| 4147 | if (!ptr) { |
| 4148 | if (stkctr == &tmpstkctr) |
| 4149 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4150 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4151 | } |
| 4152 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4153 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4154 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4155 | 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] | 4156 | stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4157 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4158 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4159 | |
| 4160 | if (stkctr == &tmpstkctr) |
| 4161 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4162 | } |
| 4163 | return 1; |
| 4164 | } |
| 4165 | |
| 4166 | /* set <smp> to the cumulated number of HTTP requests from the stream's tracked |
| 4167 | * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or |
| 4168 | * "src_http_req_cnt" only. |
| 4169 | */ |
| 4170 | static int |
| 4171 | smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4172 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4173 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4174 | struct stkctr *stkctr; |
| 4175 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4176 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4177 | if (!stkctr) |
| 4178 | return 0; |
| 4179 | |
| 4180 | smp->flags = SMP_F_VOL_TEST; |
| 4181 | smp->data.type = SMP_T_SINT; |
| 4182 | smp->data.u.sint = 0; |
| 4183 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4184 | void *ptr; |
| 4185 | |
| 4186 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
| 4187 | if (!ptr) { |
| 4188 | if (stkctr == &tmpstkctr) |
| 4189 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4190 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4191 | } |
| 4192 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4193 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4194 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4195 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4196 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4197 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4198 | |
| 4199 | if (stkctr == &tmpstkctr) |
| 4200 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4201 | } |
| 4202 | return 1; |
| 4203 | } |
| 4204 | |
| 4205 | /* set <smp> to the HTTP request rate from the stream's tracked frontend |
| 4206 | * counters. Supports being called as "sc[0-9]_http_req_rate" or |
| 4207 | * "src_http_req_rate" only. |
| 4208 | */ |
| 4209 | static int |
| 4210 | smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4211 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4212 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4213 | struct stkctr *stkctr; |
| 4214 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4215 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4216 | if (!stkctr) |
| 4217 | return 0; |
| 4218 | |
| 4219 | smp->flags = SMP_F_VOL_TEST; |
| 4220 | smp->data.type = SMP_T_SINT; |
| 4221 | smp->data.u.sint = 0; |
| 4222 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4223 | void *ptr; |
| 4224 | |
| 4225 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
| 4226 | if (!ptr) { |
| 4227 | if (stkctr == &tmpstkctr) |
| 4228 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4229 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4230 | } |
| 4231 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4232 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4233 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4234 | 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] | 4235 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4236 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4237 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4238 | |
| 4239 | if (stkctr == &tmpstkctr) |
| 4240 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4241 | } |
| 4242 | return 1; |
| 4243 | } |
| 4244 | |
| 4245 | /* set <smp> to the cumulated number of HTTP requests errors from the stream's |
| 4246 | * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or |
| 4247 | * "src_http_err_cnt" only. |
| 4248 | */ |
| 4249 | static int |
| 4250 | smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4251 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4252 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4253 | struct stkctr *stkctr; |
| 4254 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4255 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4256 | if (!stkctr) |
| 4257 | return 0; |
| 4258 | |
| 4259 | smp->flags = SMP_F_VOL_TEST; |
| 4260 | smp->data.type = SMP_T_SINT; |
| 4261 | smp->data.u.sint = 0; |
| 4262 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4263 | void *ptr; |
| 4264 | |
| 4265 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
| 4266 | if (!ptr) { |
| 4267 | if (stkctr == &tmpstkctr) |
| 4268 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4269 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4270 | } |
| 4271 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4272 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4273 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4274 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4275 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4276 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4277 | |
| 4278 | if (stkctr == &tmpstkctr) |
| 4279 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4280 | } |
| 4281 | return 1; |
| 4282 | } |
| 4283 | |
| 4284 | /* set <smp> to the HTTP request error rate from the stream's tracked frontend |
| 4285 | * counters. Supports being called as "sc[0-9]_http_err_rate" or |
| 4286 | * "src_http_err_rate" only. |
| 4287 | */ |
| 4288 | static int |
| 4289 | smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4290 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4291 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4292 | struct stkctr *stkctr; |
| 4293 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4294 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4295 | if (!stkctr) |
| 4296 | return 0; |
| 4297 | |
| 4298 | smp->flags = SMP_F_VOL_TEST; |
| 4299 | smp->data.type = SMP_T_SINT; |
| 4300 | smp->data.u.sint = 0; |
| 4301 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4302 | void *ptr; |
| 4303 | |
| 4304 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
| 4305 | if (!ptr) { |
| 4306 | if (stkctr == &tmpstkctr) |
| 4307 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4308 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4309 | } |
| 4310 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4311 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4312 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4313 | 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] | 4314 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4315 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4316 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4317 | |
| 4318 | if (stkctr == &tmpstkctr) |
| 4319 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4320 | } |
| 4321 | return 1; |
| 4322 | } |
| 4323 | |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4324 | /* set <smp> to the cumulated number of HTTP response failures from the stream's |
| 4325 | * tracked frontend counters. Supports being called as "sc[0-9]_http_fail_cnt" or |
| 4326 | * "src_http_fail_cnt" only. |
| 4327 | */ |
| 4328 | static int |
| 4329 | smp_fetch_sc_http_fail_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4330 | { |
| 4331 | struct stkctr tmpstkctr; |
| 4332 | struct stkctr *stkctr; |
| 4333 | |
| 4334 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4335 | if (!stkctr) |
| 4336 | return 0; |
| 4337 | |
| 4338 | smp->flags = SMP_F_VOL_TEST; |
| 4339 | smp->data.type = SMP_T_SINT; |
| 4340 | smp->data.u.sint = 0; |
| 4341 | if (stkctr_entry(stkctr) != NULL) { |
| 4342 | void *ptr; |
| 4343 | |
| 4344 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_CNT); |
| 4345 | if (!ptr) { |
| 4346 | if (stkctr == &tmpstkctr) |
| 4347 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4348 | return 0; /* parameter not stored */ |
| 4349 | } |
| 4350 | |
| 4351 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4352 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4353 | smp->data.u.sint = stktable_data_cast(ptr, std_t_uint); |
Willy Tarreau | 826f3ab | 2021-02-10 12:07:15 +0100 | [diff] [blame] | 4354 | |
| 4355 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4356 | |
| 4357 | if (stkctr == &tmpstkctr) |
| 4358 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4359 | } |
| 4360 | return 1; |
| 4361 | } |
| 4362 | |
| 4363 | /* set <smp> to the HTTP response failure rate from the stream's tracked frontend |
| 4364 | * counters. Supports being called as "sc[0-9]_http_fail_rate" or |
| 4365 | * "src_http_fail_rate" only. |
| 4366 | */ |
| 4367 | static int |
| 4368 | smp_fetch_sc_http_fail_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4369 | { |
| 4370 | struct stkctr tmpstkctr; |
| 4371 | struct stkctr *stkctr; |
| 4372 | |
| 4373 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
| 4374 | if (!stkctr) |
| 4375 | return 0; |
| 4376 | |
| 4377 | smp->flags = SMP_F_VOL_TEST; |
| 4378 | smp->data.type = SMP_T_SINT; |
| 4379 | smp->data.u.sint = 0; |
| 4380 | if (stkctr_entry(stkctr) != NULL) { |
| 4381 | void *ptr; |
| 4382 | |
| 4383 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_FAIL_RATE); |
| 4384 | if (!ptr) { |
| 4385 | if (stkctr == &tmpstkctr) |
| 4386 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4387 | return 0; /* parameter not stored */ |
| 4388 | } |
| 4389 | |
| 4390 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4391 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4392 | 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] | 4393 | stkctr->table->data_arg[STKTABLE_DT_HTTP_FAIL_RATE].u); |
| 4394 | |
| 4395 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
| 4396 | |
| 4397 | if (stkctr == &tmpstkctr) |
| 4398 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4399 | } |
| 4400 | return 1; |
| 4401 | } |
| 4402 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4403 | /* set <smp> to the number of kbytes received from clients, as found in the |
| 4404 | * stream's tracked frontend counters. Supports being called as |
| 4405 | * "sc[0-9]_kbytes_in" or "src_kbytes_in" only. |
| 4406 | */ |
| 4407 | static int |
| 4408 | smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4409 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4410 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4411 | struct stkctr *stkctr; |
| 4412 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4413 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4414 | if (!stkctr) |
| 4415 | return 0; |
| 4416 | |
| 4417 | smp->flags = SMP_F_VOL_TEST; |
| 4418 | smp->data.type = SMP_T_SINT; |
| 4419 | smp->data.u.sint = 0; |
| 4420 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4421 | void *ptr; |
| 4422 | |
| 4423 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
| 4424 | if (!ptr) { |
| 4425 | if (stkctr == &tmpstkctr) |
| 4426 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4427 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4428 | } |
| 4429 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4430 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4431 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4432 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4433 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4434 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4435 | |
| 4436 | if (stkctr == &tmpstkctr) |
| 4437 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4438 | } |
| 4439 | return 1; |
| 4440 | } |
| 4441 | |
| 4442 | /* set <smp> to the data rate received from clients in bytes/s, as found |
| 4443 | * in the stream's tracked frontend counters. Supports being called as |
| 4444 | * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only. |
| 4445 | */ |
| 4446 | static int |
| 4447 | smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4448 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4449 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4450 | struct stkctr *stkctr; |
| 4451 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4452 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4453 | if (!stkctr) |
| 4454 | return 0; |
| 4455 | |
| 4456 | smp->flags = SMP_F_VOL_TEST; |
| 4457 | smp->data.type = SMP_T_SINT; |
| 4458 | smp->data.u.sint = 0; |
| 4459 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4460 | void *ptr; |
| 4461 | |
| 4462 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
| 4463 | if (!ptr) { |
| 4464 | if (stkctr == &tmpstkctr) |
| 4465 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4466 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4467 | } |
| 4468 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4469 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4470 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4471 | 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] | 4472 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4473 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4474 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4475 | |
| 4476 | if (stkctr == &tmpstkctr) |
| 4477 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4478 | } |
| 4479 | return 1; |
| 4480 | } |
| 4481 | |
| 4482 | /* set <smp> to the number of kbytes sent to clients, as found in the |
| 4483 | * stream's tracked frontend counters. Supports being called as |
| 4484 | * "sc[0-9]_kbytes_out" or "src_kbytes_out" only. |
| 4485 | */ |
| 4486 | static int |
| 4487 | smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4488 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4489 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4490 | struct stkctr *stkctr; |
| 4491 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4492 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4493 | if (!stkctr) |
| 4494 | return 0; |
| 4495 | |
| 4496 | smp->flags = SMP_F_VOL_TEST; |
| 4497 | smp->data.type = SMP_T_SINT; |
| 4498 | smp->data.u.sint = 0; |
| 4499 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4500 | void *ptr; |
| 4501 | |
| 4502 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
| 4503 | if (!ptr) { |
| 4504 | if (stkctr == &tmpstkctr) |
| 4505 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4506 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4507 | } |
| 4508 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4509 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4510 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4511 | smp->data.u.sint = stktable_data_cast(ptr, std_t_ull) >> 10; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4512 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4513 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4514 | |
| 4515 | if (stkctr == &tmpstkctr) |
| 4516 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4517 | } |
| 4518 | return 1; |
| 4519 | } |
| 4520 | |
| 4521 | /* set <smp> to the data rate sent to clients in bytes/s, as found in the |
| 4522 | * stream's tracked frontend counters. Supports being called as |
| 4523 | * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. |
| 4524 | */ |
| 4525 | static int |
| 4526 | smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4527 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4528 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4529 | struct stkctr *stkctr; |
| 4530 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4531 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4532 | if (!stkctr) |
| 4533 | return 0; |
| 4534 | |
| 4535 | smp->flags = SMP_F_VOL_TEST; |
| 4536 | smp->data.type = SMP_T_SINT; |
| 4537 | smp->data.u.sint = 0; |
| 4538 | if (stkctr_entry(stkctr) != NULL) { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4539 | void *ptr; |
| 4540 | |
| 4541 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
| 4542 | if (!ptr) { |
| 4543 | if (stkctr == &tmpstkctr) |
| 4544 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4545 | return 0; /* parameter not stored */ |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4546 | } |
| 4547 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4548 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4549 | |
Emeric Brun | 0e3457b | 2021-06-30 17:18:28 +0200 | [diff] [blame] | 4550 | 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] | 4551 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4552 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4553 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &stkctr_entry(stkctr)->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4554 | |
| 4555 | if (stkctr == &tmpstkctr) |
| 4556 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4557 | } |
| 4558 | return 1; |
| 4559 | } |
| 4560 | |
| 4561 | /* set <smp> to the number of active trackers on the SC entry in the stream's |
| 4562 | * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only. |
| 4563 | */ |
| 4564 | static int |
| 4565 | smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 4566 | { |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4567 | struct stkctr tmpstkctr; |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4568 | struct stkctr *stkctr; |
| 4569 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4570 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4571 | if (!stkctr) |
| 4572 | return 0; |
| 4573 | |
| 4574 | smp->flags = SMP_F_VOL_TEST; |
| 4575 | smp->data.type = SMP_T_SINT; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4576 | if (stkctr == &tmpstkctr) { |
| 4577 | smp->data.u.sint = stkctr_entry(stkctr) ? (stkctr_entry(stkctr)->ref_cnt-1) : 0; |
| 4578 | stktable_release(stkctr->table, stkctr_entry(stkctr)); |
| 4579 | } |
| 4580 | else { |
| 4581 | smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0; |
| 4582 | } |
| 4583 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 4584 | return 1; |
| 4585 | } |
| 4586 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4587 | |
| 4588 | /* The functions below are used to manipulate table contents from the CLI. |
| 4589 | * There are 3 main actions, "clear", "set" and "show". The code is shared |
| 4590 | * between all actions, and the action is encoded in the void *private in |
| 4591 | * the appctx as well as in the keyword registration, among one of the |
| 4592 | * following values. |
| 4593 | */ |
| 4594 | |
| 4595 | enum { |
| 4596 | STK_CLI_ACT_CLR, |
| 4597 | STK_CLI_ACT_SET, |
| 4598 | STK_CLI_ACT_SHOW, |
| 4599 | }; |
| 4600 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4601 | /* Dump the status of a table to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4602 | * read buffer. It returns 0 if the output buffer is full |
| 4603 | * and needs to be called again, otherwise non-zero. |
| 4604 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4605 | static int table_dump_head_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4606 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4607 | struct stktable *t, struct stktable *target) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4608 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 4609 | struct stream *s = __sc_strm(appctx_sc(appctx)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4610 | |
| 4611 | 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] | 4612 | t->id, stktable_types[t->type].kw, t->size, t->current); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4613 | |
| 4614 | /* any other information should be dumped here */ |
| 4615 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 4616 | 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] | 4617 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
| 4618 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4619 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4620 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4621 | |
| 4622 | return 1; |
| 4623 | } |
| 4624 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4625 | /* Dump a table entry to a stream connector's |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4626 | * read buffer. It returns 0 if the output buffer is full |
| 4627 | * and needs to be called again, otherwise non-zero. |
| 4628 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4629 | static int table_dump_entry_to_buffer(struct buffer *msg, |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4630 | struct appctx *appctx, |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4631 | struct stktable *t, struct stksess *entry) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4632 | { |
| 4633 | int dt; |
| 4634 | |
| 4635 | chunk_appendf(msg, "%p:", entry); |
| 4636 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4637 | if (t->type == SMP_T_IPV4) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4638 | char addr[INET_ADDRSTRLEN]; |
| 4639 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4640 | chunk_appendf(msg, " key=%s", addr); |
| 4641 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4642 | else if (t->type == SMP_T_IPV6) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4643 | char addr[INET6_ADDRSTRLEN]; |
| 4644 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 4645 | chunk_appendf(msg, " key=%s", addr); |
| 4646 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4647 | else if (t->type == SMP_T_SINT) { |
Willy Tarreau | 6cde5d8 | 2020-02-25 09:41:22 +0100 | [diff] [blame] | 4648 | chunk_appendf(msg, " key=%u", read_u32(entry->key.key)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4649 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4650 | else if (t->type == SMP_T_STR) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4651 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4652 | dump_text(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4653 | } |
| 4654 | else { |
| 4655 | chunk_appendf(msg, " key="); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4656 | dump_binary(msg, (const char *)entry->key.key, t->key_size); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4657 | } |
| 4658 | |
Willy Tarreau | 16b282f | 2022-11-29 11:55:18 +0100 | [diff] [blame] | 4659 | 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] | 4660 | |
| 4661 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 4662 | void *ptr; |
| 4663 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4664 | if (t->data_ofs[dt] == 0) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4665 | continue; |
Emeric Brun | c64a2a3 | 2021-06-30 18:01:02 +0200 | [diff] [blame] | 4666 | if (stktable_data_types[dt].is_array) { |
| 4667 | char tmp[16] = {}; |
| 4668 | const char *name_pfx = stktable_data_types[dt].name; |
| 4669 | const char *name_sfx = NULL; |
| 4670 | unsigned int idx = 0; |
| 4671 | int i = 0; |
| 4672 | |
| 4673 | /* split name to show index before first _ of the name |
| 4674 | * for example: 'gpc3_rate' if array name is 'gpc_rate'. |
| 4675 | */ |
| 4676 | for (i = 0 ; i < (sizeof(tmp) - 1); i++) { |
| 4677 | if (!name_pfx[i]) |
| 4678 | break; |
| 4679 | if (name_pfx[i] == '_') { |
| 4680 | name_pfx = &tmp[0]; |
| 4681 | name_sfx = &stktable_data_types[dt].name[i]; |
| 4682 | break; |
| 4683 | } |
| 4684 | tmp[i] = name_pfx[i]; |
| 4685 | } |
| 4686 | |
| 4687 | ptr = stktable_data_ptr_idx(t, entry, dt, idx); |
| 4688 | while (ptr) { |
| 4689 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
| 4690 | chunk_appendf(msg, " %s%u%s(%u)=", name_pfx, idx, name_sfx ? name_sfx : "", t->data_arg[dt].u); |
| 4691 | else |
| 4692 | chunk_appendf(msg, " %s%u%s=", name_pfx, idx, name_sfx ? name_sfx : ""); |
| 4693 | switch (stktable_data_types[dt].std_type) { |
| 4694 | case STD_T_SINT: |
| 4695 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4696 | break; |
| 4697 | case STD_T_UINT: |
| 4698 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4699 | break; |
| 4700 | case STD_T_ULL: |
| 4701 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
| 4702 | break; |
| 4703 | case STD_T_FRQP: |
| 4704 | chunk_appendf(msg, "%u", |
| 4705 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 4706 | t->data_arg[dt].u)); |
| 4707 | break; |
| 4708 | } |
| 4709 | ptr = stktable_data_ptr_idx(t, entry, dt, ++idx); |
| 4710 | } |
| 4711 | continue; |
| 4712 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4713 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4714 | 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] | 4715 | else |
| 4716 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
| 4717 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4718 | ptr = stktable_data_ptr(t, entry, dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4719 | switch (stktable_data_types[dt].std_type) { |
| 4720 | case STD_T_SINT: |
| 4721 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 4722 | break; |
| 4723 | case STD_T_UINT: |
| 4724 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 4725 | break; |
| 4726 | case STD_T_ULL: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4727 | chunk_appendf(msg, "%llu", stktable_data_cast(ptr, std_t_ull)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4728 | break; |
| 4729 | case STD_T_FRQP: |
Emeric Brun | 01928ae | 2021-06-30 16:24:04 +0200 | [diff] [blame] | 4730 | chunk_appendf(msg, "%u", |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4731 | 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] | 4732 | t->data_arg[dt].u)); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4733 | break; |
Frédéric Lécaille | 16b4f54 | 2019-05-23 12:15:04 +0200 | [diff] [blame] | 4734 | case STD_T_DICT: { |
| 4735 | struct dict_entry *de; |
| 4736 | de = stktable_data_cast(ptr, std_t_dict); |
| 4737 | chunk_appendf(msg, "%s", de ? (char *)de->value.key : "-"); |
| 4738 | break; |
| 4739 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4740 | } |
| 4741 | } |
| 4742 | chunk_appendf(msg, "\n"); |
| 4743 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4744 | if (applet_putchk(appctx, msg) == -1) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4745 | return 0; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4746 | |
| 4747 | return 1; |
| 4748 | } |
| 4749 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4750 | /* appctx context used by the "show table" command */ |
| 4751 | struct show_table_ctx { |
| 4752 | void *target; /* table we want to dump, or NULL for all */ |
| 4753 | struct stktable *t; /* table being currently dumped (first if NULL) */ |
| 4754 | struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ |
| 4755 | long long value[STKTABLE_FILTER_LEN]; /* value to compare against */ |
| 4756 | signed char data_type[STKTABLE_FILTER_LEN]; /* type of data to compare, or -1 if none */ |
| 4757 | 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] | 4758 | enum { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4759 | STATE_NEXT = 0, /* px points to next table, entry=NULL */ |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 4760 | STATE_DUMP, /* px points to curr table, entry is valid, refcount held */ |
| 4761 | STATE_DONE, /* done dumping */ |
| 4762 | } state; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4763 | char action; /* action on the table : one of STK_CLI_ACT_* */ |
| 4764 | }; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4765 | |
| 4766 | /* Processes a single table entry matching a specific key passed in argument. |
| 4767 | * returns 0 if wants to be called again, 1 if has ended processing. |
| 4768 | */ |
| 4769 | static int table_process_entry_per_key(struct appctx *appctx, char **args) |
| 4770 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4771 | struct show_table_ctx *ctx = appctx->svcctx; |
| 4772 | struct stktable *t = ctx->target; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4773 | struct stksess *ts; |
| 4774 | uint32_t uint32_key; |
| 4775 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
| 4776 | long long value; |
| 4777 | int data_type; |
| 4778 | int cur_arg; |
| 4779 | void *ptr; |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4780 | struct freq_ctr *frqp; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4781 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4782 | if (!*args[4]) |
| 4783 | return cli_err(appctx, "Key value expected\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4784 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4785 | switch (t->type) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4786 | case SMP_T_IPV4: |
| 4787 | uint32_key = htonl(inetaddr_host(args[4])); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4788 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4789 | break; |
| 4790 | case SMP_T_IPV6: |
Christopher Faulet | b7c962b | 2021-11-15 09:17:25 +0100 | [diff] [blame] | 4791 | if (inet_pton(AF_INET6, args[4], ip6_key) <= 0) |
| 4792 | return cli_err(appctx, "Invalid key\n"); |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4793 | static_table_key.key = &ip6_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4794 | break; |
| 4795 | case SMP_T_SINT: |
| 4796 | { |
| 4797 | char *endptr; |
| 4798 | unsigned long val; |
| 4799 | errno = 0; |
| 4800 | val = strtoul(args[4], &endptr, 10); |
| 4801 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 4802 | (errno != 0 && val == 0) || endptr == args[4] || |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4803 | val > 0xffffffff) |
| 4804 | return cli_err(appctx, "Invalid key\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4805 | uint32_key = (uint32_t) val; |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4806 | static_table_key.key = &uint32_key; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4807 | break; |
| 4808 | } |
| 4809 | break; |
| 4810 | case SMP_T_STR: |
Christopher Faulet | ca20d02 | 2017-08-29 15:30:31 +0200 | [diff] [blame] | 4811 | static_table_key.key = args[4]; |
| 4812 | static_table_key.key_len = strlen(args[4]); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4813 | break; |
| 4814 | default: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4815 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4816 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4817 | 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] | 4818 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4819 | 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] | 4820 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4821 | 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] | 4822 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4823 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4824 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | /* check permissions */ |
| 4828 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 4829 | return 1; |
| 4830 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4831 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4832 | case STK_CLI_ACT_SHOW: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4833 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4834 | if (!ts) |
| 4835 | return 1; |
| 4836 | chunk_reset(&trash); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4837 | 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] | 4838 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4839 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4840 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4841 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4842 | if (!table_dump_entry_to_buffer(&trash, appctx, t, ts)) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4843 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4844 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4845 | return 0; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4846 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4847 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4848 | stktable_release(t, ts); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4849 | break; |
| 4850 | |
| 4851 | case STK_CLI_ACT_CLR: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4852 | ts = stktable_lookup_key(t, &static_table_key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4853 | if (!ts) |
| 4854 | return 1; |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4855 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4856 | if (!stksess_kill(t, ts, 1)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4857 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4858 | return cli_err(appctx, "Entry currently in use, cannot remove\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4859 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4860 | break; |
| 4861 | |
| 4862 | case STK_CLI_ACT_SET: |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4863 | ts = stktable_get_entry(t, &static_table_key); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 4864 | if (!ts) { |
| 4865 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4866 | return cli_err(appctx, "Unable to allocate a new entry\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4867 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4868 | HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4869 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 4870 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4871 | cli_err(appctx, "\"data.<type>\" followed by a value expected\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4872 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4873 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4874 | return 1; |
| 4875 | } |
| 4876 | |
| 4877 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 4878 | if (data_type < 0) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4879 | cli_err(appctx, "Unknown data type\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4880 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4881 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4882 | return 1; |
| 4883 | } |
| 4884 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4885 | if (!t->data_ofs[data_type]) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4886 | cli_err(appctx, "Data type not stored in this table\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4887 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4888 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4889 | return 1; |
| 4890 | } |
| 4891 | |
| 4892 | 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] | 4893 | cli_err(appctx, "Require a valid integer value to store\n"); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4894 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4895 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4896 | return 1; |
| 4897 | } |
| 4898 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4899 | ptr = stktable_data_ptr(t, ts, data_type); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4900 | |
| 4901 | switch (stktable_data_types[data_type].std_type) { |
| 4902 | case STD_T_SINT: |
| 4903 | stktable_data_cast(ptr, std_t_sint) = value; |
| 4904 | break; |
| 4905 | case STD_T_UINT: |
| 4906 | stktable_data_cast(ptr, std_t_uint) = value; |
| 4907 | break; |
| 4908 | case STD_T_ULL: |
| 4909 | stktable_data_cast(ptr, std_t_ull) = value; |
| 4910 | break; |
| 4911 | case STD_T_FRQP: |
| 4912 | /* We set both the current and previous values. That way |
| 4913 | * the reported frequency is stable during all the period |
| 4914 | * then slowly fades out. This allows external tools to |
| 4915 | * push measures without having to update them too often. |
| 4916 | */ |
| 4917 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4918 | /* First bit is reserved for the freq_ctr lock |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4919 | Note: here we're still protected by the stksess lock |
Willy Tarreau | fa1258f | 2021-04-10 23:00:53 +0200 | [diff] [blame] | 4920 | so we don't need to update the update the freq_ctr |
Emeric Brun | f2fc1fd | 2017-11-02 17:32:43 +0100 | [diff] [blame] | 4921 | using its internal lock */ |
| 4922 | frqp->curr_tick = now_ms & ~0x1; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4923 | frqp->prev_ctr = 0; |
| 4924 | frqp->curr_ctr = value; |
| 4925 | break; |
| 4926 | } |
| 4927 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4928 | HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 4929 | stktable_touch_local(t, ts, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4930 | break; |
| 4931 | |
| 4932 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4933 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4934 | } |
| 4935 | return 1; |
| 4936 | } |
| 4937 | |
| 4938 | /* Prepares the appctx fields with the data-based filters from the command line. |
| 4939 | * Returns 0 if the dump can proceed, 1 if has ended processing. |
| 4940 | */ |
| 4941 | static int table_prepare_data_request(struct appctx *appctx, char **args) |
| 4942 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4943 | struct show_table_ctx *ctx = appctx->svcctx; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4944 | int i; |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4945 | char *err = NULL; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4946 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4947 | 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] | 4948 | 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] | 4949 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4950 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
| 4951 | if (i > 0 && !*args[3+3*i]) // number of filter entries can be less than STKTABLE_FILTER_LEN |
| 4952 | break; |
| 4953 | /* condition on stored data value */ |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4954 | ctx->data_type[i] = stktable_get_data_type(args[3+3*i] + 5); |
| 4955 | if (ctx->data_type[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4956 | 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] | 4957 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4958 | if (!((struct stktable *)ctx->target)->data_ofs[ctx->data_type[i]]) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4959 | 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] | 4960 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4961 | ctx->data_op[i] = get_std_op(args[4+3*i]); |
| 4962 | if (ctx->data_op[i] < 0) |
Adis Nezirovic | d0142e7 | 2020-01-22 16:50:27 +0100 | [diff] [blame] | 4963 | 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] | 4964 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4965 | 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] | 4966 | return cli_dynerr(appctx, memprintf(&err, "Filter entry #%i: Require a valid integer value to compare against\n", i + 1)); |
| 4967 | } |
| 4968 | |
| 4969 | if (*args[3+3*i]) { |
| 4970 | 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] | 4971 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4972 | |
| 4973 | /* OK we're done, all the fields are set */ |
| 4974 | return 0; |
| 4975 | } |
| 4976 | |
| 4977 | /* 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] | 4978 | 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] | 4979 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4980 | struct show_table_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 4981 | int i; |
| 4982 | |
| 4983 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4984 | ctx->data_type[i] = -1; |
| 4985 | ctx->target = NULL; |
| 4986 | ctx->entry = NULL; |
| 4987 | ctx->action = (long)private; // keyword argument, one of STK_CLI_ACT_* |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4988 | |
| 4989 | if (*args[2]) { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4990 | ctx->t = ctx->target = stktable_find_by_name(args[2]); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4991 | if (!ctx->target) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4992 | return cli_err(appctx, "No such table\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4993 | } |
| 4994 | else { |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 4995 | ctx->t = stktables_list; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 4996 | if (ctx->action != STK_CLI_ACT_SHOW) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 4997 | goto err_args; |
| 4998 | return 0; |
| 4999 | } |
| 5000 | |
| 5001 | if (strcmp(args[3], "key") == 0) |
| 5002 | return table_process_entry_per_key(appctx, args); |
| 5003 | else if (strncmp(args[3], "data.", 5) == 0) |
| 5004 | return table_prepare_data_request(appctx, args); |
| 5005 | else if (*args[3]) |
| 5006 | goto err_args; |
| 5007 | |
| 5008 | return 0; |
| 5009 | |
| 5010 | err_args: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5011 | switch (ctx->action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5012 | case STK_CLI_ACT_SHOW: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5013 | 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] | 5014 | case STK_CLI_ACT_CLR: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5015 | 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] | 5016 | case STK_CLI_ACT_SET: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5017 | 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] | 5018 | default: |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5019 | return cli_err(appctx, "Unknown action\n"); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5020 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | /* This function is used to deal with table operations (dump or clear depending |
| 5024 | * on the action stored in appctx->private). It returns 0 if the output buffer is |
| 5025 | * full and it needs to be called again, otherwise non-zero. |
| 5026 | */ |
| 5027 | static int cli_io_handler_table(struct appctx *appctx) |
| 5028 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5029 | struct show_table_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5030 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 475e463 | 2022-05-27 10:26:46 +0200 | [diff] [blame] | 5031 | struct stream *s = __sc_strm(sc); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5032 | struct ebmb_node *eb; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5033 | int skip_entry; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5034 | int show = ctx->action == STK_CLI_ACT_SHOW; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5035 | |
| 5036 | /* |
Willy Tarreau | 0f154ed | 2022-05-03 12:02:36 +0200 | [diff] [blame] | 5037 | * We have 3 possible states in ctx->state : |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5038 | * - STATE_NEXT : the proxy pointer points to the next table to |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5039 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5040 | * - STATE_DUMP : the proxy pointer points to the current table |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5041 | * and the entry pointer points to the next entry to be dumped, |
| 5042 | * and the refcount on the next entry is held ; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5043 | * - STATE_DONE : nothing left to dump, the buffer may contain some |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5044 | * data though. |
| 5045 | */ |
| 5046 | |
Christopher Faulet | da89e9b | 2023-01-04 14:11:10 +0100 | [diff] [blame] | 5047 | if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5048 | /* 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] | 5049 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5050 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5051 | } |
| 5052 | return 1; |
| 5053 | } |
| 5054 | |
| 5055 | chunk_reset(&trash); |
| 5056 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5057 | while (ctx->state != STATE_DONE) { |
| 5058 | switch (ctx->state) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5059 | case STATE_NEXT: |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5060 | if (!ctx->t || |
| 5061 | (ctx->target && |
| 5062 | ctx->t != ctx->target)) { |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5063 | ctx->state = STATE_DONE; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5064 | break; |
| 5065 | } |
| 5066 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5067 | if (ctx->t->size) { |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5068 | 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] | 5069 | return 0; |
| 5070 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5071 | if (ctx->target && |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 5072 | (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5073 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5074 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5075 | eb = ebmb_first(&ctx->t->keys); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5076 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5077 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
| 5078 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5079 | ctx->state = STATE_DUMP; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5080 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5081 | break; |
| 5082 | } |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5083 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5084 | } |
| 5085 | } |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5086 | ctx->t = ctx->t->next; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5087 | break; |
| 5088 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5089 | case STATE_DUMP: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5090 | skip_entry = 0; |
| 5091 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5092 | HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5093 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5094 | if (ctx->data_type[0] >= 0) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5095 | /* we're filtering on some data contents */ |
| 5096 | void *ptr; |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5097 | int dt, i; |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5098 | signed char op; |
| 5099 | long long data, value; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5100 | |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5101 | |
Willy Tarreau | 2b64a35 | 2020-01-22 17:09:47 +0100 | [diff] [blame] | 5102 | for (i = 0; i < STKTABLE_FILTER_LEN; i++) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5103 | if (ctx->data_type[i] == -1) |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5104 | break; |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5105 | dt = ctx->data_type[i]; |
| 5106 | ptr = stktable_data_ptr(ctx->t, |
| 5107 | ctx->entry, |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5108 | dt); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5109 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5110 | data = 0; |
| 5111 | switch (stktable_data_types[dt].std_type) { |
| 5112 | case STD_T_SINT: |
| 5113 | data = stktable_data_cast(ptr, std_t_sint); |
| 5114 | break; |
| 5115 | case STD_T_UINT: |
| 5116 | data = stktable_data_cast(ptr, std_t_uint); |
| 5117 | break; |
| 5118 | case STD_T_ULL: |
| 5119 | data = stktable_data_cast(ptr, std_t_ull); |
| 5120 | break; |
| 5121 | case STD_T_FRQP: |
| 5122 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5123 | ctx->t->data_arg[dt].u); |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5124 | break; |
| 5125 | } |
| 5126 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5127 | op = ctx->data_op[i]; |
| 5128 | value = ctx->value[i]; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5129 | |
Adis Nezirovic | 1a693fc | 2020-01-16 15:19:29 +0100 | [diff] [blame] | 5130 | /* skip the entry if the data does not match the test and the value */ |
| 5131 | if ((data < value && |
| 5132 | (op == STD_OP_EQ || op == STD_OP_GT || op == STD_OP_GE)) || |
| 5133 | (data == value && |
| 5134 | (op == STD_OP_NE || op == STD_OP_GT || op == STD_OP_LT)) || |
| 5135 | (data > value && |
| 5136 | (op == STD_OP_EQ || op == STD_OP_LT || op == STD_OP_LE))) { |
| 5137 | skip_entry = 1; |
| 5138 | break; |
| 5139 | } |
| 5140 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | if (show && !skip_entry && |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5144 | !table_dump_entry_to_buffer(&trash, appctx, ctx->t, ctx->entry)) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5145 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5146 | return 0; |
| 5147 | } |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5148 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5149 | HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ctx->entry->lock); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5150 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5151 | HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5152 | ctx->entry->ref_cnt--; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5153 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5154 | eb = ebmb_next(&ctx->entry->key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5155 | if (eb) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5156 | struct stksess *old = ctx->entry; |
| 5157 | ctx->entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5158 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5159 | __stksess_kill_if_expired(ctx->t, old); |
| 5160 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5161 | __stksess_kill(ctx->t, old); |
| 5162 | ctx->entry->ref_cnt++; |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5163 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5164 | break; |
| 5165 | } |
| 5166 | |
| 5167 | |
| 5168 | if (show) |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5169 | __stksess_kill_if_expired(ctx->t, ctx->entry); |
| 5170 | else if (!skip_entry && !ctx->entry->ref_cnt) |
| 5171 | __stksess_kill(ctx->t, ctx->entry); |
Emeric Brun | 819fc6f | 2017-06-13 19:37:32 +0200 | [diff] [blame] | 5172 | |
Willy Tarreau | 7664222 | 2022-10-11 12:02:50 +0200 | [diff] [blame] | 5173 | HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &ctx->t->lock); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5174 | |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5175 | ctx->t = ctx->t->next; |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5176 | ctx->state = STATE_NEXT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5177 | break; |
| 5178 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5179 | default: |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5180 | break; |
| 5181 | } |
| 5182 | } |
| 5183 | return 1; |
| 5184 | } |
| 5185 | |
| 5186 | static void cli_release_show_table(struct appctx *appctx) |
| 5187 | { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5188 | struct show_table_ctx *ctx = appctx->svcctx; |
| 5189 | |
Willy Tarreau | 7849d4c | 2022-05-03 11:45:02 +0200 | [diff] [blame] | 5190 | if (ctx->state == STATE_DUMP) { |
Willy Tarreau | 3c69e08 | 2022-05-03 11:35:07 +0200 | [diff] [blame] | 5191 | stksess_kill_if_expired(ctx->t, ctx->entry, 1); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5192 | } |
| 5193 | } |
| 5194 | |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5195 | static int stk_parse_stick_counters(char **args, int section_type, struct proxy *curpx, |
| 5196 | const struct proxy *defpx, const char *file, int line, |
| 5197 | char **err) |
| 5198 | { |
| 5199 | char *error; |
| 5200 | int counters; |
| 5201 | |
| 5202 | counters = strtol(args[1], &error, 10); |
| 5203 | if (*error != 0) { |
| 5204 | memprintf(err, "%s: '%s' is an invalid number", args[0], args[1]); |
| 5205 | return -1; |
| 5206 | } |
| 5207 | |
| 5208 | if (counters < 0) { |
| 5209 | memprintf(err, "%s: the number of stick-counters may not be negative (was %d)", args[0], counters); |
| 5210 | return -1; |
| 5211 | } |
| 5212 | |
| 5213 | global.tune.nb_stk_ctr = counters; |
| 5214 | return 0; |
| 5215 | } |
| 5216 | |
| 5217 | /* This function creates the stk_ctr pools after the configuration parsing. It |
| 5218 | * returns 0 on success otherwise ERR_*. If nb_stk_ctr is 0, the pool remains |
| 5219 | * NULL. |
| 5220 | */ |
| 5221 | static int stkt_create_stk_ctr_pool(void) |
| 5222 | { |
| 5223 | if (!global.tune.nb_stk_ctr) |
| 5224 | return 0; |
| 5225 | |
| 5226 | pool_head_stk_ctr = create_pool("stk_ctr", sizeof(*((struct session*)0)->stkctr) * global.tune.nb_stk_ctr, MEM_F_SHARED); |
| 5227 | if (!pool_head_stk_ctr) { |
| 5228 | ha_alert("out of memory while creating the stick-counters pool.\n"); |
| 5229 | return ERR_ABORT; |
| 5230 | } |
| 5231 | return 0; |
| 5232 | } |
| 5233 | |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5234 | static void stkt_late_init(void) |
| 5235 | { |
| 5236 | struct sample_fetch *f; |
| 5237 | |
| 5238 | f = find_sample_fetch("src", strlen("src")); |
| 5239 | if (f) |
| 5240 | smp_fetch_src = f->process; |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5241 | hap_register_post_check(stkt_create_stk_ctr_pool); |
Willy Tarreau | 478331d | 2020-08-28 11:31:31 +0200 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | INITCALL0(STG_INIT, stkt_late_init); |
| 5245 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5246 | /* register cli keywords */ |
| 5247 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5248 | { { "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 }, |
| 5249 | { { "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 }, |
| 5250 | { { "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] | 5251 | {{},} |
| 5252 | }}; |
| 5253 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5254 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 5255 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5256 | static struct action_kw_list tcp_conn_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5257 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5258 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5259 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5260 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5261 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5262 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5263 | { /* END */ } |
| 5264 | }}; |
| 5265 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5266 | INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws); |
| 5267 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5268 | static struct action_kw_list tcp_sess_kws = { { }, { |
Willy Tarreau | 5a72d03 | 2023-01-02 18:15:20 +0100 | [diff] [blame] | 5269 | { "sc-add-gpc", parse_add_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 4d7ada8 | 2021-06-30 19:04:16 +0200 | [diff] [blame] | 5270 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5271 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5272 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
Emeric Brun | 877b0b5 | 2021-06-30 18:57:49 +0200 | [diff] [blame] | 5273 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5274 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 5275 | { /* END */ } |
| 5276 | }}; |
| 5277 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5278 | INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws); |
| 5279 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5280 | static struct action_kw_list tcp_req_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_cont_keywords_register, &tcp_req_kws); |
| 5291 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5292 | static struct action_kw_list tcp_res_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 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5299 | { /* END */ } |
| 5300 | }}; |
| 5301 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5302 | INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws); |
| 5303 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5304 | static struct action_kw_list http_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, http_req_keywords_register, &http_req_kws); |
| 5315 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 5316 | static struct action_kw_list http_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, http_res_keywords_register, &http_res_kws); |
| 5327 | |
Christopher Faulet | a924804 | 2023-01-05 11:17:38 +0100 | [diff] [blame] | 5328 | static struct action_kw_list http_after_res_kws = { { }, { |
| 5329 | { "sc-inc-gpc", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5330 | { "sc-inc-gpc0", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5331 | { "sc-inc-gpc1", parse_inc_gpc, KWF_MATCH_PREFIX }, |
| 5332 | { "sc-set-gpt", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5333 | { "sc-set-gpt0", parse_set_gpt, KWF_MATCH_PREFIX }, |
| 5334 | { /* END */ } |
| 5335 | }}; |
| 5336 | |
| 5337 | INITCALL1(STG_REGISTER, http_after_res_keywords_register, &http_after_res_kws); |
| 5338 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5339 | /* Note: must not be declared <const> as its list will be overwritten. |
| 5340 | * Please take care of keeping this list alphabetically sorted. |
| 5341 | */ |
| 5342 | static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 5343 | { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5344 | { "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] | 5345 | { "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] | 5346 | { "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] | 5347 | { "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] | 5348 | { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5349 | { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5350 | { "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] | 5351 | { "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] | 5352 | { "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] | 5353 | { "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] | 5354 | { "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] | 5355 | { "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] | 5356 | { "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] | 5357 | { "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] | 5358 | { "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] | 5359 | { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5360 | { "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] | 5361 | { "sc_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5362 | { "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] | 5363 | { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5364 | { "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] | 5365 | { "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] | 5366 | { "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] | 5367 | { "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] | 5368 | { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5369 | { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5370 | { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5371 | { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5372 | { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5373 | { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5374 | { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5375 | { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5376 | { "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] | 5377 | { "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] | 5378 | { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5379 | { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5380 | { "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] | 5381 | { "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] | 5382 | { "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] | 5383 | { "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] | 5384 | { "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] | 5385 | { "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] | 5386 | { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5387 | { "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] | 5388 | { "sc0_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5389 | { "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] | 5390 | { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5391 | { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5392 | { "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] | 5393 | { "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] | 5394 | { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5395 | { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5396 | { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5397 | { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5398 | { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5399 | { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5400 | { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5401 | { "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] | 5402 | { "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] | 5403 | { "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] | 5404 | { "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] | 5405 | { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5406 | { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5407 | { "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] | 5408 | { "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] | 5409 | { "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] | 5410 | { "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] | 5411 | { "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] | 5412 | { "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] | 5413 | { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5414 | { "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] | 5415 | { "sc1_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5416 | { "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] | 5417 | { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5418 | { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5419 | { "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] | 5420 | { "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] | 5421 | { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5422 | { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5423 | { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5424 | { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5425 | { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5426 | { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5427 | { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5428 | { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5429 | { "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] | 5430 | { "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] | 5431 | { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5432 | { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5433 | { "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] | 5434 | { "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] | 5435 | { "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] | 5436 | { "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] | 5437 | { "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] | 5438 | { "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] | 5439 | { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5440 | { "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] | 5441 | { "sc2_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5442 | { "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] | 5443 | { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5444 | { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5445 | { "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] | 5446 | { "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] | 5447 | { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5448 | { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5449 | { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5450 | { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5451 | { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 5452 | { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5453 | { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5454 | { "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] | 5455 | { "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] | 5456 | { "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] | 5457 | { "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] | 5458 | { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5459 | { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5460 | { "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] | 5461 | { "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] | 5462 | { "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] | 5463 | { "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] | 5464 | { "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] | 5465 | { "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] | 5466 | { "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] | 5467 | { "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] | 5468 | { "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] | 5469 | { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5470 | { "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] | 5471 | { "src_http_fail_cnt", smp_fetch_sc_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5472 | { "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] | 5473 | { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5474 | { "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] | 5475 | { "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] | 5476 | { "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] | 5477 | { "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] | 5478 | { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5479 | { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5480 | { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5481 | { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5482 | { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 5483 | { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5484 | { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 5485 | { /* END */ }, |
| 5486 | }}; |
| 5487 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5488 | INITCALL1(STG_REGISTER, sample_register_fetches, &smp_fetch_keywords); |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 5489 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 5490 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 5491 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 5492 | { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL }, |
| 5493 | { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5494 | { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5495 | { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5496 | { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5497 | { "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] | 5498 | { "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] | 5499 | { "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] | 5500 | { "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] | 5501 | { "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] | 5502 | { "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] | 5503 | { "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] | 5504 | { "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] | 5505 | { "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] | 5506 | { "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] | 5507 | { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5508 | { "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] | 5509 | { "table_http_fail_cnt", sample_conv_table_http_fail_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5510 | { "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] | 5511 | { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5512 | { "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] | 5513 | { "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] | 5514 | { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5515 | { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5516 | { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5517 | { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5518 | { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 5519 | { "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] | 5520 | { /* END */ }, |
| 5521 | }}; |
| 5522 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5523 | INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws); |
Willy Tarreau | 6c01171 | 2023-01-06 16:09:58 +0100 | [diff] [blame] | 5524 | |
| 5525 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 5526 | { CFG_GLOBAL, "tune.stick-counters", stk_parse_stick_counters }, |
| 5527 | { /* END */ } |
| 5528 | }}; |
| 5529 | |
| 5530 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |