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