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