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