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