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