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