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