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