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