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