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> |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 32 | #include <proto/proto_http.h> |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 33 | #include <proto/proto_tcp.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 34 | #include <proto/proxy.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 35 | #include <proto/sample.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 36 | #include <proto/stream.h> |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 37 | #include <proto/stream_interface.h> |
Willy Tarreau | 68129b9 | 2010-06-06 16:06:52 +0200 | [diff] [blame] | 38 | #include <proto/stick_table.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 39 | #include <proto/task.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 40 | #include <proto/peers.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 41 | #include <proto/tcp_rules.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 42 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 43 | /* structure used to return a table key built from a sample */ |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 44 | struct stktable_key *static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 45 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 46 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 47 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
| 48 | * in table <t>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 49 | */ |
| 50 | void stksess_free(struct stktable *t, struct stksess *ts) |
| 51 | { |
| 52 | t->current--; |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 53 | pool_free2(t->pool, (void *)ts - t->data_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /* |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 57 | * Kill an stksess (only if its ref_cnt is zero). |
| 58 | */ |
| 59 | void stksess_kill(struct stktable *t, struct stksess *ts) |
| 60 | { |
| 61 | if (ts->ref_cnt) |
| 62 | return; |
| 63 | |
| 64 | eb32_delete(&ts->exp); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 65 | eb32_delete(&ts->upd); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 66 | ebmb_delete(&ts->key); |
| 67 | stksess_free(t, ts); |
| 68 | } |
| 69 | |
| 70 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 71 | * Initialize or update the key in the sticky session <ts> present in table <t> |
| 72 | * from the value present in <key>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 73 | */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 74 | 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] | 75 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 76 | if (t->type != SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 77 | memcpy(ts->key.key, key->key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 78 | else { |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 79 | memcpy(ts->key.key, key->key, MIN(t->key_size - 1, key->key_len)); |
| 80 | ts->key.key[MIN(t->key_size - 1, key->key_len)] = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /* |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 86 | * Init sticky session <ts> of table <t>. The data parts are cleared and <ts> |
| 87 | * is returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 88 | */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 89 | static struct stksess *stksess_init(struct stktable *t, struct stksess * ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 90 | { |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 91 | memset((void *)ts - t->data_size, 0, t->data_size); |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 92 | ts->ref_cnt = 0; |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 93 | ts->key.node.leaf_p = NULL; |
| 94 | ts->exp.node.leaf_p = NULL; |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 95 | ts->upd.node.leaf_p = NULL; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 96 | return ts; |
| 97 | } |
| 98 | |
| 99 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 100 | * Trash oldest <to_batch> sticky sessions from table <t> |
| 101 | * Returns number of trashed sticky sessions. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 102 | */ |
Willy Tarreau | 3a925c1 | 2013-09-04 17:54:01 +0200 | [diff] [blame] | 103 | int stktable_trash_oldest(struct stktable *t, int to_batch) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 104 | { |
| 105 | struct stksess *ts; |
| 106 | struct eb32_node *eb; |
| 107 | int batched = 0; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 108 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 109 | |
| 110 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 111 | |
| 112 | while (batched < to_batch) { |
| 113 | |
| 114 | if (unlikely(!eb)) { |
| 115 | /* we might have reached the end of the tree, typically because |
| 116 | * <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] | 117 | * half. Let's loop back to the beginning of the tree now if we |
| 118 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 119 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 120 | if (looped) |
| 121 | break; |
| 122 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 123 | eb = eb32_first(&t->exps); |
| 124 | if (likely(!eb)) |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 129 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 130 | eb = eb32_next(eb); |
| 131 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 132 | /* don't delete an entry which is currently referenced */ |
| 133 | if (ts->ref_cnt) |
| 134 | continue; |
| 135 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 136 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 137 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 138 | if (ts->expire != ts->exp.key) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 139 | if (!tick_isset(ts->expire)) |
| 140 | continue; |
| 141 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 142 | ts->exp.key = ts->expire; |
| 143 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 144 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 145 | if (!eb || eb->key > ts->exp.key) |
| 146 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 147 | |
| 148 | continue; |
| 149 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 150 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 151 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 152 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 153 | eb32_delete(&ts->upd); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 154 | stksess_free(t, ts); |
| 155 | batched++; |
| 156 | } |
| 157 | |
| 158 | return batched; |
| 159 | } |
| 160 | |
| 161 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 162 | * Allocate and initialise a new sticky session. |
| 163 | * The new sticky session is returned or NULL in case of lack of memory. |
| 164 | * 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] | 165 | * stksess_free(). Table <t>'s sticky session counter is increased. If <key> |
| 166 | * is not NULL, it is assigned to the new session. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 167 | */ |
| 168 | struct stksess *stksess_new(struct stktable *t, struct stktable_key *key) |
| 169 | { |
| 170 | struct stksess *ts; |
| 171 | |
| 172 | if (unlikely(t->current == t->size)) { |
| 173 | if ( t->nopurge ) |
| 174 | return NULL; |
| 175 | |
Emeric Brun | fbce6d0 | 2010-09-23 18:10:00 +0200 | [diff] [blame] | 176 | if (!stktable_trash_oldest(t, (t->size >> 8) + 1)) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 177 | return NULL; |
| 178 | } |
| 179 | |
Vincent Bernat | ef8f4fe | 2016-11-17 15:42:40 +0100 | [diff] [blame] | 180 | ts = pool_alloc2(t->pool); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 181 | if (ts) { |
| 182 | t->current++; |
Willy Tarreau | 5179146 | 2016-11-18 18:21:39 +0100 | [diff] [blame] | 183 | ts = (void *)ts + t->data_size; |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 184 | stksess_init(t, ts); |
Willy Tarreau | a7b46b5 | 2013-04-11 16:55:37 +0200 | [diff] [blame] | 185 | if (key) |
| 186 | stksess_setkey(t, ts, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | return ts; |
| 190 | } |
| 191 | |
| 192 | /* |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 193 | * Looks in table <t> for a sticky session matching key <key>. |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 194 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 195 | */ |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 196 | struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 197 | { |
| 198 | struct ebmb_node *eb; |
| 199 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 200 | if (t->type == SMP_T_STR) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 201 | 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] | 202 | else |
| 203 | eb = ebmb_lookup(&t->keys, key->key, t->key_size); |
| 204 | |
| 205 | if (unlikely(!eb)) { |
| 206 | /* no session found */ |
| 207 | return NULL; |
| 208 | } |
| 209 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 210 | return ebmb_entry(eb, struct stksess, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 211 | } |
| 212 | |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 213 | /* Lookup and touch <key> in <table>, or create the entry if it does not exist. |
| 214 | * This is mainly used for situations where we want to refresh a key's usage so |
| 215 | * that it does not expire, and we want to have it created if it was not there. |
| 216 | * The stksess is returned, or NULL if it could not be created. |
| 217 | */ |
| 218 | struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key) |
| 219 | { |
| 220 | struct stksess *ts; |
| 221 | |
| 222 | ts = stktable_lookup_key(table, key); |
| 223 | if (likely(ts)) |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 224 | return stktable_touch(table, ts, 1); |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 225 | |
| 226 | /* entry does not exist, initialize a new one */ |
| 227 | ts = stksess_new(table, key); |
| 228 | if (likely(ts)) |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 229 | stktable_store(table, ts, 1); |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 230 | return ts; |
| 231 | } |
| 232 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 233 | /* |
| 234 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 235 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 236 | */ |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 237 | struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 238 | { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 239 | struct ebmb_node *eb; |
| 240 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 241 | if (t->type == SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 242 | eb = ebst_lookup(&(t->keys), (char *)ts->key.key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 243 | else |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 244 | eb = ebmb_lookup(&(t->keys), ts->key.key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 245 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 246 | if (unlikely(!eb)) |
| 247 | return NULL; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 248 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 249 | return ebmb_entry(eb, struct stksess, key); |
| 250 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 251 | |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 252 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 253 | * The table's expiration timer is updated if set. |
| 254 | */ |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 255 | struct stksess *stktable_touch_with_exp(struct stktable *t, struct stksess *ts, |
| 256 | int local, int expire) |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 257 | { |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 258 | struct eb32_node * eb; |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 259 | ts->expire = expire; |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 260 | if (t->expire) { |
| 261 | t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next); |
| 262 | task_queue(t->exp_task); |
| 263 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 264 | |
Emeric Brun | aaf5860 | 2015-06-15 17:23:30 +0200 | [diff] [blame] | 265 | /* If sync is enabled and update is local */ |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 266 | if (t->sync_task && local) { |
Emeric Brun | c703a9d | 2015-09-22 15:05:06 +0200 | [diff] [blame] | 267 | /* If this entry is not in the tree |
| 268 | or not scheduled for at least one peer */ |
| 269 | if (!ts->upd.node.leaf_p |
| 270 | || (int)(t->commitupdate - ts->upd.key) >= 0 |
| 271 | || (int)(ts->upd.key - t->localupdate) >= 0) { |
Emeric Brun | aaf5860 | 2015-06-15 17:23:30 +0200 | [diff] [blame] | 272 | ts->upd.key = ++t->update; |
| 273 | t->localupdate = t->update; |
| 274 | eb32_delete(&ts->upd); |
| 275 | eb = eb32_insert(&t->updates, &ts->upd); |
| 276 | if (eb != &ts->upd) { |
| 277 | eb32_delete(eb); |
| 278 | eb32_insert(&t->updates, &ts->upd); |
| 279 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 280 | } |
| 281 | task_wakeup(t->sync_task, TASK_WOKEN_MSG); |
| 282 | } |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 283 | return ts; |
| 284 | } |
| 285 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 286 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 287 | * The table's expiration timer is updated if set. The date of expiration coming from |
| 288 | * <t> stick-table configuration. |
| 289 | */ |
| 290 | struct stksess *stktable_touch(struct stktable *t, struct stksess *ts, int local) |
| 291 | { |
| 292 | int expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
| 293 | |
| 294 | return stktable_touch_with_exp(t, ts, local, expire); |
| 295 | } |
| 296 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 297 | /* Insert new sticky session <ts> in the table. It is assumed that it does not |
| 298 | * yet exist (the caller must check this). The table's timeout is updated if it |
| 299 | * is set. <ts> is returned. |
| 300 | */ |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 301 | struct stksess *stktable_store(struct stktable *t, struct stksess *ts, int local) |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 302 | { |
| 303 | ebmb_insert(&t->keys, &ts->key, t->key_size); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 304 | stktable_touch(t, ts, local); |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 305 | ts->exp.key = ts->expire; |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 306 | eb32_insert(&t->exps, &ts->exp); |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 307 | return ts; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 308 | } |
| 309 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 310 | /* Same function as stktable_store(), but with <expire> as supplementary argument |
| 311 | * to set the date of expiration of <ts> new sticky session thanks to |
| 312 | * stktable_touch_with_exp(). |
| 313 | */ |
| 314 | struct stksess *stktable_store_with_exp(struct stktable *t, struct stksess *ts, |
| 315 | int local, int expire) |
| 316 | { |
| 317 | ebmb_insert(&t->keys, &ts->key, t->key_size); |
| 318 | stktable_touch_with_exp(t, ts, local, expire); |
| 319 | ts->exp.key = ts->expire; |
| 320 | eb32_insert(&t->exps, &ts->exp); |
| 321 | return ts; |
| 322 | } |
| 323 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 324 | /* Returns a valid or initialized stksess for the specified stktable_key in the |
| 325 | * specified table, or NULL if the key was NULL, or if no entry was found nor |
| 326 | * could be created. The entry's expiration is updated. |
| 327 | */ |
| 328 | struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key) |
| 329 | { |
| 330 | struct stksess *ts; |
| 331 | |
| 332 | if (!key) |
| 333 | return NULL; |
| 334 | |
| 335 | ts = stktable_lookup_key(table, key); |
| 336 | if (ts == NULL) { |
| 337 | /* entry does not exist, initialize a new one */ |
| 338 | ts = stksess_new(table, key); |
| 339 | if (!ts) |
| 340 | return NULL; |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 341 | stktable_store(table, ts, 1); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 342 | } |
| 343 | else |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 344 | stktable_touch(table, ts, 1); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 345 | return ts; |
| 346 | } |
| 347 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 348 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 349 | * Trash expired sticky sessions from table <t>. The next expiration date is |
| 350 | * returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 351 | */ |
| 352 | static int stktable_trash_expired(struct stktable *t) |
| 353 | { |
| 354 | struct stksess *ts; |
| 355 | struct eb32_node *eb; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 356 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 357 | |
| 358 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 359 | |
| 360 | while (1) { |
| 361 | if (unlikely(!eb)) { |
| 362 | /* we might have reached the end of the tree, typically because |
| 363 | * <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] | 364 | * half. Let's loop back to the beginning of the tree now if we |
| 365 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 366 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 367 | if (looped) |
| 368 | break; |
| 369 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 370 | eb = eb32_first(&t->exps); |
| 371 | if (likely(!eb)) |
| 372 | break; |
| 373 | } |
| 374 | |
| 375 | if (likely(tick_is_lt(now_ms, eb->key))) { |
| 376 | /* timer not expired yet, revisit it later */ |
| 377 | t->exp_next = eb->key; |
| 378 | return t->exp_next; |
| 379 | } |
| 380 | |
| 381 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 382 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 383 | eb = eb32_next(eb); |
| 384 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 385 | /* don't delete an entry which is currently referenced */ |
| 386 | if (ts->ref_cnt) |
| 387 | continue; |
| 388 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 389 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 390 | |
| 391 | if (!tick_is_expired(ts->expire, now_ms)) { |
| 392 | if (!tick_isset(ts->expire)) |
| 393 | continue; |
| 394 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 395 | ts->exp.key = ts->expire; |
| 396 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 397 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 398 | if (!eb || eb->key > ts->exp.key) |
| 399 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 400 | continue; |
| 401 | } |
| 402 | |
| 403 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 404 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 405 | eb32_delete(&ts->upd); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 406 | stksess_free(t, ts); |
| 407 | } |
| 408 | |
| 409 | /* We have found no task to expire in any tree */ |
| 410 | t->exp_next = TICK_ETERNITY; |
| 411 | return t->exp_next; |
| 412 | } |
| 413 | |
| 414 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 415 | * Task processing function to trash expired sticky sessions. A pointer to the |
| 416 | * task itself is returned since it never dies. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 417 | */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 418 | static struct task *process_table_expire(struct task *task) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 419 | { |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 420 | struct stktable *t = task->context; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 421 | |
| 422 | task->expire = stktable_trash_expired(t); |
| 423 | return task; |
| 424 | } |
| 425 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 426 | /* 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] | 427 | int stktable_init(struct stktable *t) |
| 428 | { |
| 429 | if (t->size) { |
| 430 | memset(&t->keys, 0, sizeof(t->keys)); |
| 431 | memset(&t->exps, 0, sizeof(t->exps)); |
Emeric Brun | 1c6235d | 2015-12-16 15:28:12 +0100 | [diff] [blame] | 432 | t->updates = EB_ROOT_UNIQUE; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 433 | |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 434 | 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] | 435 | |
| 436 | t->exp_next = TICK_ETERNITY; |
| 437 | if ( t->expire ) { |
| 438 | t->exp_task = task_new(); |
| 439 | t->exp_task->process = process_table_expire; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 440 | t->exp_task->context = (void *)t; |
| 441 | } |
Willy Tarreau | c8b6791 | 2015-05-01 18:29:57 +0200 | [diff] [blame] | 442 | 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] | 443 | peers_register_table(t->peers.p, t); |
| 444 | } |
| 445 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 446 | return t->pool != NULL; |
| 447 | } |
| 448 | return 1; |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * Configuration keywords of known table types |
| 453 | */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 454 | struct stktable_type stktable_types[SMP_TYPES] = { |
| 455 | [SMP_T_SINT] = { "integer", 0, 4 }, |
| 456 | [SMP_T_IPV4] = { "ip", 0, 4 }, |
| 457 | [SMP_T_IPV6] = { "ipv6", 0, 16 }, |
| 458 | [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 }, |
| 459 | [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 } |
| 460 | }; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 461 | |
| 462 | /* |
| 463 | * Parse table type configuration. |
| 464 | * Returns 0 on successful parsing, else 1. |
| 465 | * <myidx> is set at next configuration <args> index. |
| 466 | */ |
| 467 | int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size) |
| 468 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 469 | for (*type = 0; *type < SMP_TYPES; (*type)++) { |
| 470 | if (!stktable_types[*type].kw) |
| 471 | continue; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 472 | if (strcmp(args[*myidx], stktable_types[*type].kw) != 0) |
| 473 | continue; |
| 474 | |
| 475 | *key_size = stktable_types[*type].default_size; |
| 476 | (*myidx)++; |
| 477 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 478 | if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 479 | if (strcmp("len", args[*myidx]) == 0) { |
| 480 | (*myidx)++; |
| 481 | *key_size = atol(args[*myidx]); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 482 | if (!*key_size) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 483 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 484 | if (*type == SMP_T_STR) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 485 | /* null terminated string needs +1 for '\0'. */ |
| 486 | (*key_size)++; |
| 487 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 488 | (*myidx)++; |
| 489 | } |
| 490 | } |
| 491 | return 0; |
| 492 | } |
| 493 | return 1; |
| 494 | } |
| 495 | |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 496 | /* 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] | 497 | * Note that the sample *is* modified and that the returned key may point |
| 498 | * 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] | 499 | * Returns NULL if the sample could not be converted (eg: no matching type), |
| 500 | * otherwise a pointer to the static stktable_key filled with what is needed |
| 501 | * for the lookup. |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 502 | */ |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 503 | struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 504 | { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 505 | /* Convert sample. */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 506 | if (!sample_convert(smp, t->type)) |
Willy Tarreau | 7fc1c6e | 2012-04-26 11:03:17 +0200 | [diff] [blame] | 507 | return NULL; |
| 508 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 509 | /* Fill static_table_key. */ |
| 510 | switch (t->type) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 511 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 512 | case SMP_T_IPV4: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 513 | static_table_key->key = &smp->data.u.ipv4; |
| 514 | static_table_key->key_len = 4; |
| 515 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 516 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 517 | case SMP_T_IPV6: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 518 | static_table_key->key = &smp->data.u.ipv6; |
| 519 | static_table_key->key_len = 16; |
| 520 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 521 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 522 | case SMP_T_SINT: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 523 | /* The stick table require a 32bit unsigned int, "sint" is a |
| 524 | * signed 64 it, so we can convert it inplace. |
| 525 | */ |
| 526 | *(unsigned int *)&smp->data.u.sint = (unsigned int)smp->data.u.sint; |
| 527 | static_table_key->key = &smp->data.u.sint; |
| 528 | static_table_key->key_len = 4; |
| 529 | break; |
| 530 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 531 | case SMP_T_STR: |
Willy Tarreau | ce6955e | 2016-08-09 11:59:12 +0200 | [diff] [blame] | 532 | if (!smp_make_safe(smp)) |
| 533 | return NULL; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 534 | static_table_key->key = smp->data.u.str.str; |
| 535 | static_table_key->key_len = smp->data.u.str.len; |
| 536 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 537 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 538 | case SMP_T_BIN: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 539 | if (smp->data.u.str.len < t->key_size) { |
| 540 | /* This type needs padding with 0. */ |
Willy Tarreau | f65c6c0 | 2016-08-09 12:08:41 +0200 | [diff] [blame] | 541 | if (!smp_make_rw(smp)) |
| 542 | return NULL; |
| 543 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 544 | if (smp->data.u.str.size < t->key_size) |
| 545 | if (!smp_dup(smp)) |
| 546 | return NULL; |
| 547 | if (smp->data.u.str.size < t->key_size) |
| 548 | return NULL; |
| 549 | memset(smp->data.u.str.str + smp->data.u.str.len, 0, |
| 550 | t->key_size - smp->data.u.str.len); |
| 551 | smp->data.u.str.len = t->key_size; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 552 | } |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 553 | static_table_key->key = smp->data.u.str.str; |
| 554 | static_table_key->key_len = smp->data.u.str.len; |
| 555 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 556 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 557 | default: /* impossible case. */ |
| 558 | return NULL; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 559 | } |
| 560 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 561 | return static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /* |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 565 | * Process a fetch + format conversion as defined by the sample expression <expr> |
| 566 | * on request or response considering the <opt> parameter. Returns either NULL if |
| 567 | * no key could be extracted, or a pointer to the converted result stored in |
| 568 | * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset |
| 569 | * 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] | 570 | * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present |
| 571 | * without SMP_OPT_FINAL). The output will be usable like this : |
| 572 | * |
| 573 | * return MAY_CHANGE FINAL Meaning for the sample |
| 574 | * NULL 0 * Not present and will never be (eg: header) |
| 575 | * NULL 1 0 Not present or unstable, could change (eg: req_len) |
| 576 | * NULL 1 1 Not present, will not change anymore |
| 577 | * smp 0 * Present and will not change (eg: header) |
| 578 | * smp 1 0 not possible |
| 579 | * smp 1 1 Present, last known value (eg: request length) |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 580 | */ |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 581 | 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] | 582 | unsigned int opt, struct sample_expr *expr, struct sample *smp) |
| 583 | { |
| 584 | if (smp) |
| 585 | memset(smp, 0, sizeof(*smp)); |
| 586 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 587 | smp = sample_process(px, sess, strm, opt, expr, smp); |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 588 | if (!smp) |
| 589 | return NULL; |
| 590 | |
| 591 | if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
| 592 | return NULL; /* we can only use stable samples */ |
| 593 | |
| 594 | return smp_to_stkey(smp, t); |
| 595 | } |
| 596 | |
| 597 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 598 | * 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] | 599 | * type <table_type>, otherwise zero. Used in configuration check. |
| 600 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 601 | int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 602 | { |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 603 | int out_type; |
| 604 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 605 | if (table_type >= SMP_TYPES || !stktable_types[table_type].kw) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 606 | return 0; |
| 607 | |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 608 | out_type = smp_expr_output_type(expr); |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 609 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 610 | /* Convert sample. */ |
| 611 | if (!sample_casts[out_type][table_type]) |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 612 | return 0; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 613 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 614 | return 1; |
| 615 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 616 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 617 | /* Extra data types processing : after the last one, some room may remain |
| 618 | * before STKTABLE_DATA_TYPES that may be used to register extra data types |
| 619 | * at run time. |
| 620 | */ |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 621 | struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = { |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 622 | [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT }, |
Thierry FOURNIER | 3cf1111 | 2015-07-28 08:57:05 +0200 | [diff] [blame] | 623 | [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 624 | [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT }, |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 625 | [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] | 626 | [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT }, |
| 627 | [STKTABLE_DT_CONN_RATE] = { .name = "conn_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 628 | [STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .std_type = STD_T_UINT }, |
| 629 | [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT }, |
| 630 | [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 631 | [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT }, |
| 632 | [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 633 | [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT }, |
| 634 | [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 635 | [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL }, |
| 636 | [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 637 | [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL }, |
| 638 | [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] | 639 | }; |
| 640 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 641 | /* Registers stick-table extra data type with index <idx>, name <name>, type |
| 642 | * <std_type> and arg type <arg_type>. If the index is negative, the next free |
| 643 | * index is automatically allocated. The allocated index is returned, or -1 if |
| 644 | * no free index was found or <name> was already registered. The <name> is used |
| 645 | * directly as a pointer, so if it's not stable, the caller must allocate it. |
| 646 | */ |
| 647 | int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type) |
| 648 | { |
| 649 | if (idx < 0) { |
| 650 | for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) { |
| 651 | if (!stktable_data_types[idx].name) |
| 652 | break; |
| 653 | |
| 654 | if (strcmp(stktable_data_types[idx].name, name) == 0) |
| 655 | return -1; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | if (idx >= STKTABLE_DATA_TYPES) |
| 660 | return -1; |
| 661 | |
| 662 | if (stktable_data_types[idx].name != NULL) |
| 663 | return -1; |
| 664 | |
| 665 | stktable_data_types[idx].name = name; |
| 666 | stktable_data_types[idx].std_type = std_type; |
| 667 | stktable_data_types[idx].arg_type = arg_type; |
| 668 | return idx; |
| 669 | } |
| 670 | |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 671 | /* |
| 672 | * Returns the data type number for the stktable_data_type whose name is <name>, |
| 673 | * or <0 if not found. |
| 674 | */ |
| 675 | int stktable_get_data_type(char *name) |
| 676 | { |
| 677 | int type; |
| 678 | |
| 679 | for (type = 0; type < STKTABLE_DATA_TYPES; type++) { |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 680 | if (!stktable_data_types[type].name) |
| 681 | continue; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 682 | if (strcmp(name, stktable_data_types[type].name) == 0) |
| 683 | return type; |
| 684 | } |
| 685 | return -1; |
| 686 | } |
| 687 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 688 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 689 | * it up into this table. Returns true if found, false otherwise. The input |
| 690 | * type is STR so that input samples are converted to string (since all types |
| 691 | * can be converted to strings), then the function casts the string again into |
| 692 | * the table's type. This is a double conversion, but in the future we might |
| 693 | * support automatic input types to perform the cast on the fly. |
| 694 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 695 | 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] | 696 | { |
| 697 | struct stktable *t; |
| 698 | struct stktable_key *key; |
| 699 | struct stksess *ts; |
| 700 | |
| 701 | t = &arg_p[0].data.prx->table; |
| 702 | |
| 703 | key = smp_to_stkey(smp, t); |
| 704 | if (!key) |
| 705 | return 0; |
| 706 | |
| 707 | ts = stktable_lookup_key(t, key); |
| 708 | |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 709 | smp->data.type = SMP_T_BOOL; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 710 | smp->data.u.sint = !!ts; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 711 | smp->flags = SMP_F_VOL_TEST; |
| 712 | return 1; |
| 713 | } |
| 714 | |
| 715 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 716 | * it up into this table. Returns the data rate received from clients in bytes/s |
| 717 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 718 | * be easily performed. If the inspected parameter is not stored in the table, |
| 719 | * <not found> is returned. |
| 720 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 721 | 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] | 722 | { |
| 723 | struct stktable *t; |
| 724 | struct stktable_key *key; |
| 725 | struct stksess *ts; |
| 726 | void *ptr; |
| 727 | |
| 728 | t = &arg_p[0].data.prx->table; |
| 729 | |
| 730 | key = smp_to_stkey(smp, t); |
| 731 | if (!key) |
| 732 | return 0; |
| 733 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 734 | ts = stktable_lookup_key(t, key); |
| 735 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 736 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 737 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 738 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 739 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 740 | if (!ts) /* key not present */ |
| 741 | return 1; |
| 742 | |
| 743 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE); |
| 744 | if (!ptr) |
| 745 | return 0; /* parameter not stored */ |
| 746 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 747 | 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] | 748 | t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
| 749 | return 1; |
| 750 | } |
| 751 | |
| 752 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 753 | * it up into this table. Returns the cumulated number of connections for the key |
| 754 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 755 | * be easily performed. If the inspected parameter is not stored in the table, |
| 756 | * <not found> is returned. |
| 757 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 758 | 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] | 759 | { |
| 760 | struct stktable *t; |
| 761 | struct stktable_key *key; |
| 762 | struct stksess *ts; |
| 763 | void *ptr; |
| 764 | |
| 765 | t = &arg_p[0].data.prx->table; |
| 766 | |
| 767 | key = smp_to_stkey(smp, t); |
| 768 | if (!key) |
| 769 | return 0; |
| 770 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 771 | ts = stktable_lookup_key(t, key); |
| 772 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 773 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 774 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 775 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 776 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 777 | if (!ts) /* key not present */ |
| 778 | return 1; |
| 779 | |
| 780 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
| 781 | if (!ptr) |
| 782 | return 0; /* parameter not stored */ |
| 783 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 784 | smp->data.u.sint = stktable_data_cast(ptr, conn_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 785 | return 1; |
| 786 | } |
| 787 | |
| 788 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 789 | * it up into this table. Returns the number of concurrent connections for the |
| 790 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 791 | * can be easily performed. If the inspected parameter is not stored in the |
| 792 | * table, <not found> is returned. |
| 793 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 794 | 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] | 795 | { |
| 796 | struct stktable *t; |
| 797 | struct stktable_key *key; |
| 798 | struct stksess *ts; |
| 799 | void *ptr; |
| 800 | |
| 801 | t = &arg_p[0].data.prx->table; |
| 802 | |
| 803 | key = smp_to_stkey(smp, t); |
| 804 | if (!key) |
| 805 | return 0; |
| 806 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 807 | ts = stktable_lookup_key(t, key); |
| 808 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 809 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 810 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 811 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 812 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 813 | if (!ts) /* key not present */ |
| 814 | return 1; |
| 815 | |
| 816 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
| 817 | if (!ptr) |
| 818 | return 0; /* parameter not stored */ |
| 819 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 820 | smp->data.u.sint = stktable_data_cast(ptr, conn_cur); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 821 | return 1; |
| 822 | } |
| 823 | |
| 824 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 825 | * it up into this table. Returns the rate of incoming connections from the key |
| 826 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 827 | * be easily performed. If the inspected parameter is not stored in the table, |
| 828 | * <not found> is returned. |
| 829 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 830 | 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] | 831 | { |
| 832 | struct stktable *t; |
| 833 | struct stktable_key *key; |
| 834 | struct stksess *ts; |
| 835 | void *ptr; |
| 836 | |
| 837 | t = &arg_p[0].data.prx->table; |
| 838 | |
| 839 | key = smp_to_stkey(smp, t); |
| 840 | if (!key) |
| 841 | return 0; |
| 842 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 843 | ts = stktable_lookup_key(t, key); |
| 844 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 845 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 846 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 847 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 848 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 849 | if (!ts) /* key not present */ |
| 850 | return 1; |
| 851 | |
| 852 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
| 853 | if (!ptr) |
| 854 | return 0; /* parameter not stored */ |
| 855 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 856 | 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] | 857 | t->data_arg[STKTABLE_DT_CONN_RATE].u); |
| 858 | return 1; |
| 859 | } |
| 860 | |
| 861 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 862 | * it up into this table. Returns the data rate sent to clients in bytes/s |
| 863 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 864 | * be easily performed. If the inspected parameter is not stored in the table, |
| 865 | * <not found> is returned. |
| 866 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 867 | 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] | 868 | { |
| 869 | struct stktable *t; |
| 870 | struct stktable_key *key; |
| 871 | struct stksess *ts; |
| 872 | void *ptr; |
| 873 | |
| 874 | t = &arg_p[0].data.prx->table; |
| 875 | |
| 876 | key = smp_to_stkey(smp, t); |
| 877 | if (!key) |
| 878 | return 0; |
| 879 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 880 | ts = stktable_lookup_key(t, key); |
| 881 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 882 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 883 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 884 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 885 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 886 | if (!ts) /* key not present */ |
| 887 | return 1; |
| 888 | |
| 889 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE); |
| 890 | if (!ptr) |
| 891 | return 0; /* parameter not stored */ |
| 892 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 893 | 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] | 894 | t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
| 895 | return 1; |
| 896 | } |
| 897 | |
| 898 | /* 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] | 899 | * it up into this table. Returns the value of the GPT0 tag for the key |
| 900 | * if the key is present in the table, otherwise false, so that comparisons can |
| 901 | * be easily performed. If the inspected parameter is not stored in the table, |
| 902 | * <not found> is returned. |
| 903 | */ |
| 904 | static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private) |
| 905 | { |
| 906 | struct stktable *t; |
| 907 | struct stktable_key *key; |
| 908 | struct stksess *ts; |
| 909 | void *ptr; |
| 910 | |
| 911 | t = &arg_p[0].data.prx->table; |
| 912 | |
| 913 | key = smp_to_stkey(smp, t); |
| 914 | if (!key) |
| 915 | return 0; |
| 916 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 917 | ts = stktable_lookup_key(t, key); |
| 918 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 919 | smp->flags = SMP_F_VOL_TEST; |
| 920 | smp->data.type = SMP_T_SINT; |
| 921 | smp->data.u.sint = 0; |
| 922 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 923 | if (!ts) /* key not present */ |
| 924 | return 1; |
| 925 | |
| 926 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0); |
| 927 | if (!ptr) |
| 928 | return 0; /* parameter not stored */ |
| 929 | |
| 930 | smp->data.u.sint = stktable_data_cast(ptr, gpt0); |
| 931 | return 1; |
| 932 | } |
| 933 | |
| 934 | /* 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] | 935 | * it up into this table. Returns the value of the GPC0 counter for the key |
| 936 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 937 | * be easily performed. If the inspected parameter is not stored in the table, |
| 938 | * <not found> is returned. |
| 939 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 940 | 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] | 941 | { |
| 942 | struct stktable *t; |
| 943 | struct stktable_key *key; |
| 944 | struct stksess *ts; |
| 945 | void *ptr; |
| 946 | |
| 947 | t = &arg_p[0].data.prx->table; |
| 948 | |
| 949 | key = smp_to_stkey(smp, t); |
| 950 | if (!key) |
| 951 | return 0; |
| 952 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 953 | ts = stktable_lookup_key(t, key); |
| 954 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 955 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 956 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 957 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 958 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 959 | if (!ts) /* key not present */ |
| 960 | return 1; |
| 961 | |
| 962 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0); |
| 963 | if (!ptr) |
| 964 | return 0; /* parameter not stored */ |
| 965 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 966 | smp->data.u.sint = stktable_data_cast(ptr, gpc0); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 967 | return 1; |
| 968 | } |
| 969 | |
| 970 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 971 | * it up into this table. Returns the event rate of the GPC0 counter for the key |
| 972 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 973 | * be easily performed. If the inspected parameter is not stored in the table, |
| 974 | * <not found> is returned. |
| 975 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 976 | 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] | 977 | { |
| 978 | struct stktable *t; |
| 979 | struct stktable_key *key; |
| 980 | struct stksess *ts; |
| 981 | void *ptr; |
| 982 | |
| 983 | t = &arg_p[0].data.prx->table; |
| 984 | |
| 985 | key = smp_to_stkey(smp, t); |
| 986 | if (!key) |
| 987 | return 0; |
| 988 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 989 | ts = stktable_lookup_key(t, key); |
| 990 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 991 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 992 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 993 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 994 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 995 | if (!ts) /* key not present */ |
| 996 | return 1; |
| 997 | |
| 998 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE); |
| 999 | if (!ptr) |
| 1000 | return 0; /* parameter not stored */ |
| 1001 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1002 | 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] | 1003 | t->data_arg[STKTABLE_DT_GPC0_RATE].u); |
| 1004 | return 1; |
| 1005 | } |
| 1006 | |
| 1007 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1008 | * it up into this table. Returns the cumulated number of HTTP request errors |
| 1009 | * for the key if the key is present in the table, otherwise zero, so that |
| 1010 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 1011 | * in the table, <not found> is returned. |
| 1012 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1013 | 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] | 1014 | { |
| 1015 | struct stktable *t; |
| 1016 | struct stktable_key *key; |
| 1017 | struct stksess *ts; |
| 1018 | void *ptr; |
| 1019 | |
| 1020 | t = &arg_p[0].data.prx->table; |
| 1021 | |
| 1022 | key = smp_to_stkey(smp, t); |
| 1023 | if (!key) |
| 1024 | return 0; |
| 1025 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1026 | ts = stktable_lookup_key(t, key); |
| 1027 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1028 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1029 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1030 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1031 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1032 | if (!ts) /* key not present */ |
| 1033 | return 1; |
| 1034 | |
| 1035 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT); |
| 1036 | if (!ptr) |
| 1037 | return 0; /* parameter not stored */ |
| 1038 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1039 | smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1040 | return 1; |
| 1041 | } |
| 1042 | |
| 1043 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1044 | * it up into this table. Returns the HTTP request error rate the key |
| 1045 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1046 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1047 | * <not found> is returned. |
| 1048 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1049 | 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] | 1050 | { |
| 1051 | struct stktable *t; |
| 1052 | struct stktable_key *key; |
| 1053 | struct stksess *ts; |
| 1054 | void *ptr; |
| 1055 | |
| 1056 | t = &arg_p[0].data.prx->table; |
| 1057 | |
| 1058 | key = smp_to_stkey(smp, t); |
| 1059 | if (!key) |
| 1060 | return 0; |
| 1061 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1062 | ts = stktable_lookup_key(t, key); |
| 1063 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1064 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1065 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1066 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1067 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1068 | if (!ts) /* key not present */ |
| 1069 | return 1; |
| 1070 | |
| 1071 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE); |
| 1072 | if (!ptr) |
| 1073 | return 0; /* parameter not stored */ |
| 1074 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1075 | 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] | 1076 | t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
| 1077 | return 1; |
| 1078 | } |
| 1079 | |
| 1080 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1081 | * it up into this table. Returns the cumulated number of HTTP request for the |
| 1082 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1083 | * can be easily performed. If the inspected parameter is not stored in the |
| 1084 | * table, <not found> is returned. |
| 1085 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1086 | 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] | 1087 | { |
| 1088 | struct stktable *t; |
| 1089 | struct stktable_key *key; |
| 1090 | struct stksess *ts; |
| 1091 | void *ptr; |
| 1092 | |
| 1093 | t = &arg_p[0].data.prx->table; |
| 1094 | |
| 1095 | key = smp_to_stkey(smp, t); |
| 1096 | if (!key) |
| 1097 | return 0; |
| 1098 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1099 | ts = stktable_lookup_key(t, key); |
| 1100 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1101 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1102 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1103 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1104 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1105 | if (!ts) /* key not present */ |
| 1106 | return 1; |
| 1107 | |
| 1108 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT); |
| 1109 | if (!ptr) |
| 1110 | return 0; /* parameter not stored */ |
| 1111 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1112 | smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1113 | return 1; |
| 1114 | } |
| 1115 | |
| 1116 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1117 | * it up into this table. Returns the HTTP request rate the key if the key is |
| 1118 | * present in the table, otherwise zero, so that comparisons can be easily |
| 1119 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 1120 | * is returned. |
| 1121 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1122 | 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] | 1123 | { |
| 1124 | struct stktable *t; |
| 1125 | struct stktable_key *key; |
| 1126 | struct stksess *ts; |
| 1127 | void *ptr; |
| 1128 | |
| 1129 | t = &arg_p[0].data.prx->table; |
| 1130 | |
| 1131 | key = smp_to_stkey(smp, t); |
| 1132 | if (!key) |
| 1133 | return 0; |
| 1134 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1135 | ts = stktable_lookup_key(t, key); |
| 1136 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1137 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1138 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1139 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1140 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1141 | if (!ts) /* key not present */ |
| 1142 | return 1; |
| 1143 | |
| 1144 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE); |
| 1145 | if (!ptr) |
| 1146 | return 0; /* parameter not stored */ |
| 1147 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1148 | 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] | 1149 | t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
| 1150 | return 1; |
| 1151 | } |
| 1152 | |
| 1153 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1154 | * it up into this table. Returns the volume of datareceived from clients in kbytes |
| 1155 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1156 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1157 | * <not found> is returned. |
| 1158 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1159 | 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] | 1160 | { |
| 1161 | struct stktable *t; |
| 1162 | struct stktable_key *key; |
| 1163 | struct stksess *ts; |
| 1164 | void *ptr; |
| 1165 | |
| 1166 | t = &arg_p[0].data.prx->table; |
| 1167 | |
| 1168 | key = smp_to_stkey(smp, t); |
| 1169 | if (!key) |
| 1170 | return 0; |
| 1171 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1172 | ts = stktable_lookup_key(t, key); |
| 1173 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1174 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1175 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1176 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1177 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1178 | if (!ts) /* key not present */ |
| 1179 | return 1; |
| 1180 | |
| 1181 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT); |
| 1182 | if (!ptr) |
| 1183 | return 0; /* parameter not stored */ |
| 1184 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1185 | smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1186 | return 1; |
| 1187 | } |
| 1188 | |
| 1189 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1190 | * it up into this table. Returns the volume of data sent to clients in kbytes |
| 1191 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1192 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1193 | * <not found> is returned. |
| 1194 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1195 | 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] | 1196 | { |
| 1197 | struct stktable *t; |
| 1198 | struct stktable_key *key; |
| 1199 | struct stksess *ts; |
| 1200 | void *ptr; |
| 1201 | |
| 1202 | t = &arg_p[0].data.prx->table; |
| 1203 | |
| 1204 | key = smp_to_stkey(smp, t); |
| 1205 | if (!key) |
| 1206 | return 0; |
| 1207 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1208 | ts = stktable_lookup_key(t, key); |
| 1209 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1210 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1211 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1212 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1213 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1214 | if (!ts) /* key not present */ |
| 1215 | return 1; |
| 1216 | |
| 1217 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT); |
| 1218 | if (!ptr) |
| 1219 | return 0; /* parameter not stored */ |
| 1220 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1221 | smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1222 | return 1; |
| 1223 | } |
| 1224 | |
| 1225 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1226 | * it up into this table. Returns the server ID associated with the key if the |
| 1227 | * key is present in the table, otherwise zero, so that comparisons can be |
| 1228 | * easily performed. If the inspected parameter is not stored in the table, |
| 1229 | * <not found> is returned. |
| 1230 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1231 | 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] | 1232 | { |
| 1233 | struct stktable *t; |
| 1234 | struct stktable_key *key; |
| 1235 | struct stksess *ts; |
| 1236 | void *ptr; |
| 1237 | |
| 1238 | t = &arg_p[0].data.prx->table; |
| 1239 | |
| 1240 | key = smp_to_stkey(smp, t); |
| 1241 | if (!key) |
| 1242 | return 0; |
| 1243 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1244 | ts = stktable_lookup_key(t, key); |
| 1245 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1246 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1247 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1248 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1249 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1250 | if (!ts) /* key not present */ |
| 1251 | return 1; |
| 1252 | |
| 1253 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID); |
| 1254 | if (!ptr) |
| 1255 | return 0; /* parameter not stored */ |
| 1256 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1257 | smp->data.u.sint = stktable_data_cast(ptr, server_id); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1258 | return 1; |
| 1259 | } |
| 1260 | |
| 1261 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1262 | * it up into this table. Returns the cumulated number of sessions for the |
| 1263 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1264 | * can be easily performed. If the inspected parameter is not stored in the |
| 1265 | * table, <not found> is returned. |
| 1266 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1267 | 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] | 1268 | { |
| 1269 | struct stktable *t; |
| 1270 | struct stktable_key *key; |
| 1271 | struct stksess *ts; |
| 1272 | void *ptr; |
| 1273 | |
| 1274 | t = &arg_p[0].data.prx->table; |
| 1275 | |
| 1276 | key = smp_to_stkey(smp, t); |
| 1277 | if (!key) |
| 1278 | return 0; |
| 1279 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1280 | ts = stktable_lookup_key(t, key); |
| 1281 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1282 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1283 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1284 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1285 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1286 | if (!ts) /* key not present */ |
| 1287 | return 1; |
| 1288 | |
| 1289 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT); |
| 1290 | if (!ptr) |
| 1291 | return 0; /* parameter not stored */ |
| 1292 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1293 | smp->data.u.sint = stktable_data_cast(ptr, sess_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1294 | return 1; |
| 1295 | } |
| 1296 | |
| 1297 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1298 | * it up into this table. Returns the session rate the key if the key is |
| 1299 | * present in the table, otherwise zero, so that comparisons can be easily |
| 1300 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 1301 | * is returned. |
| 1302 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1303 | 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] | 1304 | { |
| 1305 | struct stktable *t; |
| 1306 | struct stktable_key *key; |
| 1307 | struct stksess *ts; |
| 1308 | void *ptr; |
| 1309 | |
| 1310 | t = &arg_p[0].data.prx->table; |
| 1311 | |
| 1312 | key = smp_to_stkey(smp, t); |
| 1313 | if (!key) |
| 1314 | return 0; |
| 1315 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1316 | ts = stktable_lookup_key(t, key); |
| 1317 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1318 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1319 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1320 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1321 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1322 | if (!ts) /* key not present */ |
| 1323 | return 1; |
| 1324 | |
| 1325 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE); |
| 1326 | if (!ptr) |
| 1327 | return 0; /* parameter not stored */ |
| 1328 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1329 | 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] | 1330 | t->data_arg[STKTABLE_DT_SESS_RATE].u); |
| 1331 | return 1; |
| 1332 | } |
| 1333 | |
| 1334 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1335 | * it up into this table. Returns the amount of concurrent connections tracking |
| 1336 | * the same key if the key is present in the table, otherwise zero, so that |
| 1337 | * comparisons can be easily performed. If the inspected parameter is not |
| 1338 | * stored in the table, <not found> is returned. |
| 1339 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1340 | 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] | 1341 | { |
| 1342 | struct stktable *t; |
| 1343 | struct stktable_key *key; |
| 1344 | struct stksess *ts; |
| 1345 | |
| 1346 | t = &arg_p[0].data.prx->table; |
| 1347 | |
| 1348 | key = smp_to_stkey(smp, t); |
| 1349 | if (!key) |
| 1350 | return 0; |
| 1351 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1352 | ts = stktable_lookup_key(t, key); |
| 1353 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1354 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1355 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1356 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1357 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1358 | if (ts) |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1359 | smp->data.u.sint = ts->ref_cnt; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1360 | |
| 1361 | return 1; |
| 1362 | } |
| 1363 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1364 | /* Always returns 1. */ |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1365 | 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] | 1366 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1367 | { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1368 | struct stksess *ts; |
| 1369 | struct stkctr *stkctr; |
| 1370 | |
| 1371 | /* Extract the stksess, return OK if no stksess available. */ |
| 1372 | if (s) |
| 1373 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 1374 | else |
| 1375 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1376 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1377 | ts = stkctr_entry(stkctr); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1378 | if (ts) { |
| 1379 | void *ptr1, *ptr2; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1380 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1381 | /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */ |
| 1382 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE); |
| 1383 | if (ptr1) |
| 1384 | update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate), |
| 1385 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1386 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1387 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0); |
| 1388 | if (ptr2) |
| 1389 | stktable_data_cast(ptr2, gpc0)++; |
| 1390 | |
| 1391 | /* If data was modified, we need to touch to re-schedule sync */ |
| 1392 | if (ptr1 || ptr2) |
| 1393 | stktable_touch(stkctr->table, ts, 1); |
| 1394 | } |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1395 | return ACT_RET_CONT; |
| 1396 | } |
| 1397 | |
| 1398 | /* This function is a common parser for using variables. It understands |
| 1399 | * the formats: |
| 1400 | * |
| 1401 | * sc-inc-gpc0(<stick-table ID>) |
| 1402 | * |
| 1403 | * It returns 0 if fails and <err> is filled with an error message. Otherwise, |
| 1404 | * it returns 1 and the variable <expr> is filled with the pointer to the |
| 1405 | * expression to execute. |
| 1406 | */ |
| 1407 | static enum act_parse_ret parse_inc_gpc0(const char **args, int *arg, struct proxy *px, |
| 1408 | struct act_rule *rule, char **err) |
| 1409 | { |
| 1410 | const char *cmd_name = args[*arg-1]; |
| 1411 | char *error; |
| 1412 | |
| 1413 | cmd_name += strlen("sc-inc-gpc0"); |
| 1414 | if (*cmd_name == '\0') { |
| 1415 | /* default stick table id. */ |
| 1416 | rule->arg.gpc.sc = 0; |
| 1417 | } else { |
| 1418 | /* parse the stick table id. */ |
| 1419 | if (*cmd_name != '(') { |
| 1420 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1421 | return ACT_RET_PRS_ERR; |
| 1422 | } |
| 1423 | cmd_name++; /* jump the '(' */ |
| 1424 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 1425 | if (*error != ')') { |
| 1426 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1427 | return ACT_RET_PRS_ERR; |
| 1428 | } |
| 1429 | |
| 1430 | if (rule->arg.gpc.sc >= ACT_ACTION_TRK_SCMAX) { |
| 1431 | memprintf(err, "invalid stick table track ID. The max allowed ID is %d", |
| 1432 | ACT_ACTION_TRK_SCMAX-1); |
| 1433 | return ACT_RET_PRS_ERR; |
| 1434 | } |
| 1435 | } |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 1436 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1437 | rule->action_ptr = action_inc_gpc0; |
| 1438 | return ACT_RET_PRS_OK; |
| 1439 | } |
| 1440 | |
| 1441 | /* Always returns 1. */ |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1442 | 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] | 1443 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1444 | { |
| 1445 | void *ptr; |
| 1446 | struct stksess *ts; |
| 1447 | struct stkctr *stkctr; |
| 1448 | |
| 1449 | /* Extract the stksess, return OK if no stksess available. */ |
| 1450 | if (s) |
| 1451 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
| 1452 | else |
| 1453 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1454 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1455 | ts = stkctr_entry(stkctr); |
| 1456 | if (!ts) |
| 1457 | return ACT_RET_CONT; |
| 1458 | |
| 1459 | /* Store the sample in the required sc, and ignore errors. */ |
| 1460 | ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1461 | if (ptr) { |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1462 | stktable_data_cast(ptr, gpt0) = rule->arg.gpt.value; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1463 | stktable_touch(stkctr->table, ts, 1); |
| 1464 | } |
| 1465 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1466 | return ACT_RET_CONT; |
| 1467 | } |
| 1468 | |
| 1469 | /* This function is a common parser for using variables. It understands |
| 1470 | * the format: |
| 1471 | * |
| 1472 | * set-gpt0(<stick-table ID>) <expression> |
| 1473 | * |
| 1474 | * It returns 0 if fails and <err> is filled with an error message. Otherwise, |
| 1475 | * it returns 1 and the variable <expr> is filled with the pointer to the |
| 1476 | * expression to execute. |
| 1477 | */ |
| 1478 | static enum act_parse_ret parse_set_gpt0(const char **args, int *arg, struct proxy *px, |
| 1479 | struct act_rule *rule, char **err) |
| 1480 | |
| 1481 | |
| 1482 | { |
| 1483 | const char *cmd_name = args[*arg-1]; |
| 1484 | char *error; |
| 1485 | |
| 1486 | cmd_name += strlen("sc-set-gpt0"); |
| 1487 | if (*cmd_name == '\0') { |
| 1488 | /* default stick table id. */ |
| 1489 | rule->arg.gpt.sc = 0; |
| 1490 | } else { |
| 1491 | /* parse the stick table id. */ |
| 1492 | if (*cmd_name != '(') { |
| 1493 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 1494 | return ACT_RET_PRS_ERR; |
| 1495 | } |
| 1496 | cmd_name++; /* jump the '(' */ |
| 1497 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 1498 | if (*error != ')') { |
| 1499 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 1500 | return ACT_RET_PRS_ERR; |
| 1501 | } |
| 1502 | |
| 1503 | if (rule->arg.gpt.sc >= ACT_ACTION_TRK_SCMAX) { |
| 1504 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d", |
| 1505 | args[*arg-1], ACT_ACTION_TRK_SCMAX-1); |
| 1506 | return ACT_RET_PRS_ERR; |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | rule->arg.gpt.value = strtol(args[*arg], &error, 10); |
| 1511 | if (*error != '\0') { |
| 1512 | memprintf(err, "invalid integer value '%s'", args[*arg]); |
| 1513 | return ACT_RET_PRS_ERR; |
| 1514 | } |
| 1515 | (*arg)++; |
| 1516 | |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 1517 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1518 | rule->action_ptr = action_set_gpt0; |
| 1519 | |
| 1520 | return ACT_RET_PRS_OK; |
| 1521 | } |
| 1522 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 1523 | /* set temp integer to the number of used entries in the table pointed to by expr. |
| 1524 | * Accepts exactly 1 argument of type table. |
| 1525 | */ |
| 1526 | static int |
| 1527 | smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1528 | { |
| 1529 | smp->flags = SMP_F_VOL_TEST; |
| 1530 | smp->data.type = SMP_T_SINT; |
| 1531 | smp->data.u.sint = args->data.prx->table.current; |
| 1532 | return 1; |
| 1533 | } |
| 1534 | |
| 1535 | /* set temp integer to the number of free entries in the table pointed to by expr. |
| 1536 | * Accepts exactly 1 argument of type table. |
| 1537 | */ |
| 1538 | static int |
| 1539 | smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1540 | { |
| 1541 | struct proxy *px; |
| 1542 | |
| 1543 | px = args->data.prx; |
| 1544 | smp->flags = SMP_F_VOL_TEST; |
| 1545 | smp->data.type = SMP_T_SINT; |
| 1546 | smp->data.u.sint = px->table.size - px->table.current; |
| 1547 | return 1; |
| 1548 | } |
| 1549 | |
| 1550 | /* Returns a pointer to a stkctr depending on the fetch keyword name. |
| 1551 | * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively. |
| 1552 | * sc[0-9]_* will return a pointer to the respective field in the |
| 1553 | * stream <l4>. sc_* requires an UINT argument specifying the stick |
| 1554 | * counter number. src_* will fill a locally allocated structure with |
| 1555 | * the table and entry corresponding to what is specified with src_*. |
| 1556 | * NULL may be returned if the designated stkctr is not tracked. For |
| 1557 | * the sc_* and sc[0-9]_* forms, an optional table argument may be |
| 1558 | * passed. When present, the currently tracked key is then looked up |
| 1559 | * in the specified table instead of the current table. The purpose is |
| 1560 | * to be able to convery multiple values per key (eg: have gpc0 from |
| 1561 | * multiple tables). <strm> is allowed to be NULL, in which case only |
| 1562 | * the session will be consulted. |
| 1563 | */ |
| 1564 | struct stkctr * |
| 1565 | smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw) |
| 1566 | { |
| 1567 | static struct stkctr stkctr; |
| 1568 | struct stkctr *stkptr; |
| 1569 | struct stksess *stksess; |
| 1570 | unsigned int num = kw[2] - '0'; |
| 1571 | int arg = 0; |
| 1572 | |
| 1573 | if (num == '_' - '0') { |
| 1574 | /* sc_* variant, args[0] = ctr# (mandatory) */ |
| 1575 | num = args[arg++].data.sint; |
| 1576 | if (num >= MAX_SESS_STKCTR) |
| 1577 | return NULL; |
| 1578 | } |
| 1579 | else if (num > 9) { /* src_* variant, args[0] = table */ |
| 1580 | struct stktable_key *key; |
| 1581 | struct connection *conn = objt_conn(sess->origin); |
| 1582 | struct sample smp; |
| 1583 | |
| 1584 | if (!conn) |
| 1585 | return NULL; |
| 1586 | |
| 1587 | /* Fetch source adress in a sample. */ |
| 1588 | smp.px = NULL; |
| 1589 | smp.sess = sess; |
| 1590 | smp.strm = strm; |
| 1591 | if (!smp_fetch_src(NULL, &smp, NULL, NULL)) |
| 1592 | return NULL; |
| 1593 | |
| 1594 | /* Converts into key. */ |
| 1595 | key = smp_to_stkey(&smp, &args->data.prx->table); |
| 1596 | if (!key) |
| 1597 | return NULL; |
| 1598 | |
| 1599 | stkctr.table = &args->data.prx->table; |
| 1600 | stkctr_set_entry(&stkctr, stktable_lookup_key(stkctr.table, key)); |
| 1601 | return &stkctr; |
| 1602 | } |
| 1603 | |
| 1604 | /* Here, <num> contains the counter number from 0 to 9 for |
| 1605 | * the sc[0-9]_ form, or even higher using sc_(num) if needed. |
| 1606 | * args[arg] is the first optional argument. We first lookup the |
| 1607 | * ctr form the stream, then from the session if it was not there. |
| 1608 | */ |
| 1609 | |
| 1610 | if (strm) |
| 1611 | stkptr = &strm->stkctr[num]; |
| 1612 | if (!strm || !stkctr_entry(stkptr)) { |
| 1613 | stkptr = &sess->stkctr[num]; |
| 1614 | if (!stkctr_entry(stkptr)) |
| 1615 | return NULL; |
| 1616 | } |
| 1617 | |
| 1618 | stksess = stkctr_entry(stkptr); |
| 1619 | if (!stksess) |
| 1620 | return NULL; |
| 1621 | |
| 1622 | if (unlikely(args[arg].type == ARGT_TAB)) { |
| 1623 | /* an alternate table was specified, let's look up the same key there */ |
| 1624 | stkctr.table = &args[arg].data.prx->table; |
| 1625 | stkctr_set_entry(&stkctr, stktable_lookup(stkctr.table, stksess)); |
| 1626 | return &stkctr; |
| 1627 | } |
| 1628 | return stkptr; |
| 1629 | } |
| 1630 | |
| 1631 | /* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create |
| 1632 | * the entry if it doesn't exist yet. This is needed for a few fetch |
| 1633 | * functions which need to create an entry, such as src_inc_gpc* and |
| 1634 | * src_clr_gpc*. |
| 1635 | */ |
| 1636 | struct stkctr * |
| 1637 | smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw) |
| 1638 | { |
| 1639 | static struct stkctr stkctr; |
| 1640 | struct stktable_key *key; |
| 1641 | struct connection *conn = objt_conn(sess->origin); |
| 1642 | struct sample smp; |
| 1643 | |
| 1644 | if (strncmp(kw, "src_", 4) != 0) |
| 1645 | return NULL; |
| 1646 | |
| 1647 | if (!conn) |
| 1648 | return NULL; |
| 1649 | |
| 1650 | /* Fetch source adress in a sample. */ |
| 1651 | smp.px = NULL; |
| 1652 | smp.sess = sess; |
| 1653 | smp.strm = strm; |
| 1654 | if (!smp_fetch_src(NULL, &smp, NULL, NULL)) |
| 1655 | return NULL; |
| 1656 | |
| 1657 | /* Converts into key. */ |
| 1658 | key = smp_to_stkey(&smp, &args->data.prx->table); |
| 1659 | if (!key) |
| 1660 | return NULL; |
| 1661 | |
| 1662 | stkctr.table = &args->data.prx->table; |
| 1663 | stkctr_set_entry(&stkctr, stktable_update_key(stkctr.table, key)); |
| 1664 | return &stkctr; |
| 1665 | } |
| 1666 | |
| 1667 | /* set return a boolean indicating if the requested stream counter is |
| 1668 | * currently being tracked or not. |
| 1669 | * Supports being called as "sc[0-9]_tracked" only. |
| 1670 | */ |
| 1671 | static int |
| 1672 | smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1673 | { |
| 1674 | smp->flags = SMP_F_VOL_TEST; |
| 1675 | smp->data.type = SMP_T_BOOL; |
| 1676 | smp->data.u.sint = !!smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1677 | return 1; |
| 1678 | } |
| 1679 | |
| 1680 | /* set <smp> to the General Purpose Flag 0 value from the stream's tracked |
| 1681 | * frontend counters or from the src. |
| 1682 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value |
| 1683 | * zero is returned if the key is new. |
| 1684 | */ |
| 1685 | static int |
| 1686 | smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1687 | { |
| 1688 | struct stkctr *stkctr; |
| 1689 | |
| 1690 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1691 | if (!stkctr) |
| 1692 | return 0; |
| 1693 | |
| 1694 | smp->flags = SMP_F_VOL_TEST; |
| 1695 | smp->data.type = SMP_T_SINT; |
| 1696 | smp->data.u.sint = 0; |
| 1697 | |
| 1698 | if (stkctr_entry(stkctr) != NULL) { |
| 1699 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0); |
| 1700 | if (!ptr) |
| 1701 | return 0; /* parameter not stored */ |
| 1702 | smp->data.u.sint = stktable_data_cast(ptr, gpt0); |
| 1703 | } |
| 1704 | return 1; |
| 1705 | } |
| 1706 | |
| 1707 | /* set <smp> to the General Purpose Counter 0 value from the stream's tracked |
| 1708 | * frontend counters or from the src. |
| 1709 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value |
| 1710 | * zero is returned if the key is new. |
| 1711 | */ |
| 1712 | static int |
| 1713 | smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1714 | { |
| 1715 | struct stkctr *stkctr; |
| 1716 | |
| 1717 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1718 | if (!stkctr) |
| 1719 | return 0; |
| 1720 | |
| 1721 | smp->flags = SMP_F_VOL_TEST; |
| 1722 | smp->data.type = SMP_T_SINT; |
| 1723 | smp->data.u.sint = 0; |
| 1724 | |
| 1725 | if (stkctr_entry(stkctr) != NULL) { |
| 1726 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 1727 | if (!ptr) |
| 1728 | return 0; /* parameter not stored */ |
| 1729 | smp->data.u.sint = stktable_data_cast(ptr, gpc0); |
| 1730 | } |
| 1731 | return 1; |
| 1732 | } |
| 1733 | |
| 1734 | /* set <smp> to the General Purpose Counter 0's event rate from the stream's |
| 1735 | * tracked frontend counters or from the src. |
| 1736 | * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only. |
| 1737 | * Value zero is returned if the key is new. |
| 1738 | */ |
| 1739 | static int |
| 1740 | smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1741 | { |
| 1742 | struct stkctr *stkctr; |
| 1743 | |
| 1744 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1745 | if (!stkctr) |
| 1746 | return 0; |
| 1747 | |
| 1748 | smp->flags = SMP_F_VOL_TEST; |
| 1749 | smp->data.type = SMP_T_SINT; |
| 1750 | smp->data.u.sint = 0; |
| 1751 | if (stkctr_entry(stkctr) != NULL) { |
| 1752 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
| 1753 | if (!ptr) |
| 1754 | return 0; /* parameter not stored */ |
| 1755 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), |
| 1756 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u); |
| 1757 | } |
| 1758 | return 1; |
| 1759 | } |
| 1760 | |
| 1761 | /* Increment the General Purpose Counter 0 value from the stream's tracked |
| 1762 | * frontend counters and return it into temp integer. |
| 1763 | * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. |
| 1764 | */ |
| 1765 | static int |
| 1766 | smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1767 | { |
| 1768 | struct stkctr *stkctr; |
| 1769 | |
| 1770 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1771 | if (!stkctr) |
| 1772 | return 0; |
| 1773 | |
| 1774 | smp->flags = SMP_F_VOL_TEST; |
| 1775 | smp->data.type = SMP_T_SINT; |
| 1776 | smp->data.u.sint = 0; |
| 1777 | |
| 1778 | if (stkctr_entry(stkctr) == NULL) |
| 1779 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw); |
| 1780 | |
| 1781 | if (stkctr && stkctr_entry(stkctr)) { |
| 1782 | void *ptr1,*ptr2; |
| 1783 | |
| 1784 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 1785 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 1786 | */ |
| 1787 | ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
| 1788 | if (ptr1) { |
| 1789 | update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate), |
| 1790 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); |
| 1791 | smp->data.u.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr; |
| 1792 | } |
| 1793 | |
| 1794 | ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 1795 | if (ptr2) |
| 1796 | smp->data.u.sint = ++stktable_data_cast(ptr2, gpc0); |
| 1797 | |
| 1798 | /* If data was modified, we need to touch to re-schedule sync */ |
| 1799 | if (ptr1 || ptr2) |
| 1800 | stktable_touch(stkctr->table, stkctr_entry(stkctr), 1); |
| 1801 | } |
| 1802 | return 1; |
| 1803 | } |
| 1804 | |
| 1805 | /* Clear the General Purpose Counter 0 value from the stream's tracked |
| 1806 | * frontend counters and return its previous value into temp integer. |
| 1807 | * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only. |
| 1808 | */ |
| 1809 | static int |
| 1810 | smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1811 | { |
| 1812 | struct stkctr *stkctr; |
| 1813 | |
| 1814 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1815 | if (!stkctr) |
| 1816 | return 0; |
| 1817 | |
| 1818 | smp->flags = SMP_F_VOL_TEST; |
| 1819 | smp->data.type = SMP_T_SINT; |
| 1820 | smp->data.u.sint = 0; |
| 1821 | |
| 1822 | if (stkctr_entry(stkctr) == NULL) |
| 1823 | stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw); |
| 1824 | |
| 1825 | if (stkctr_entry(stkctr) != NULL) { |
| 1826 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
| 1827 | if (!ptr) |
| 1828 | return 0; /* parameter not stored */ |
| 1829 | smp->data.u.sint = stktable_data_cast(ptr, gpc0); |
| 1830 | stktable_data_cast(ptr, gpc0) = 0; |
| 1831 | /* If data was modified, we need to touch to re-schedule sync */ |
| 1832 | stktable_touch(stkctr->table, stkctr_entry(stkctr), 1); |
| 1833 | } |
| 1834 | return 1; |
| 1835 | } |
| 1836 | |
| 1837 | /* set <smp> to the cumulated number of connections from the stream's tracked |
| 1838 | * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or |
| 1839 | * "src_conn_cnt" only. |
| 1840 | */ |
| 1841 | static int |
| 1842 | smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1843 | { |
| 1844 | struct stkctr *stkctr; |
| 1845 | |
| 1846 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1847 | if (!stkctr) |
| 1848 | return 0; |
| 1849 | |
| 1850 | smp->flags = SMP_F_VOL_TEST; |
| 1851 | smp->data.type = SMP_T_SINT; |
| 1852 | smp->data.u.sint = 0; |
| 1853 | if (stkctr_entry(stkctr) != NULL) { |
| 1854 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); |
| 1855 | if (!ptr) |
| 1856 | return 0; /* parameter not stored */ |
| 1857 | smp->data.u.sint = stktable_data_cast(ptr, conn_cnt); |
| 1858 | } |
| 1859 | return 1; |
| 1860 | } |
| 1861 | |
| 1862 | /* set <smp> to the connection rate from the stream's tracked frontend |
| 1863 | * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate" |
| 1864 | * only. |
| 1865 | */ |
| 1866 | static int |
| 1867 | smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1868 | { |
| 1869 | struct stkctr *stkctr; |
| 1870 | |
| 1871 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1872 | if (!stkctr) |
| 1873 | return 0; |
| 1874 | |
| 1875 | smp->flags = SMP_F_VOL_TEST; |
| 1876 | smp->data.type = SMP_T_SINT; |
| 1877 | smp->data.u.sint = 0; |
| 1878 | if (stkctr_entry(stkctr) != NULL) { |
| 1879 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); |
| 1880 | if (!ptr) |
| 1881 | return 0; /* parameter not stored */ |
| 1882 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), |
| 1883 | stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); |
| 1884 | } |
| 1885 | return 1; |
| 1886 | } |
| 1887 | |
| 1888 | /* set temp integer to the number of connections from the stream's source address |
| 1889 | * in the table pointed to by expr, after updating it. |
| 1890 | * Accepts exactly 1 argument of type table. |
| 1891 | */ |
| 1892 | static int |
| 1893 | smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1894 | { |
| 1895 | struct connection *conn = objt_conn(smp->sess->origin); |
| 1896 | struct stksess *ts; |
| 1897 | struct stktable_key *key; |
| 1898 | void *ptr; |
| 1899 | struct proxy *px; |
| 1900 | |
| 1901 | if (!conn) |
| 1902 | return 0; |
| 1903 | |
| 1904 | /* Fetch source adress in a sample. */ |
| 1905 | if (!smp_fetch_src(NULL, smp, NULL, NULL)) |
| 1906 | return 0; |
| 1907 | |
| 1908 | /* Converts into key. */ |
| 1909 | key = smp_to_stkey(smp, &args->data.prx->table); |
| 1910 | if (!key) |
| 1911 | return 0; |
| 1912 | |
| 1913 | px = args->data.prx; |
| 1914 | |
| 1915 | if ((ts = stktable_update_key(&px->table, key)) == NULL) |
| 1916 | /* entry does not exist and could not be created */ |
| 1917 | return 0; |
| 1918 | |
| 1919 | ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT); |
| 1920 | if (!ptr) |
| 1921 | return 0; /* parameter not stored in this table */ |
| 1922 | |
| 1923 | smp->data.type = SMP_T_SINT; |
| 1924 | smp->data.u.sint = ++stktable_data_cast(ptr, conn_cnt); |
| 1925 | /* Touch was previously performed by stktable_update_key */ |
| 1926 | smp->flags = SMP_F_VOL_TEST; |
| 1927 | return 1; |
| 1928 | } |
| 1929 | |
| 1930 | /* set <smp> to the number of concurrent connections from the stream's tracked |
| 1931 | * frontend counters. Supports being called as "sc[0-9]_conn_cur" or |
| 1932 | * "src_conn_cur" only. |
| 1933 | */ |
| 1934 | static int |
| 1935 | smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1936 | { |
| 1937 | struct stkctr *stkctr; |
| 1938 | |
| 1939 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1940 | if (!stkctr) |
| 1941 | return 0; |
| 1942 | |
| 1943 | smp->flags = SMP_F_VOL_TEST; |
| 1944 | smp->data.type = SMP_T_SINT; |
| 1945 | smp->data.u.sint = 0; |
| 1946 | if (stkctr_entry(stkctr) != NULL) { |
| 1947 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); |
| 1948 | if (!ptr) |
| 1949 | return 0; /* parameter not stored */ |
| 1950 | smp->data.u.sint = stktable_data_cast(ptr, conn_cur); |
| 1951 | } |
| 1952 | return 1; |
| 1953 | } |
| 1954 | |
| 1955 | /* set <smp> to the cumulated number of streams from the stream's tracked |
| 1956 | * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or |
| 1957 | * "src_sess_cnt" only. |
| 1958 | */ |
| 1959 | static int |
| 1960 | smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1961 | { |
| 1962 | struct stkctr *stkctr; |
| 1963 | |
| 1964 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1965 | if (!stkctr) |
| 1966 | return 0; |
| 1967 | |
| 1968 | smp->flags = SMP_F_VOL_TEST; |
| 1969 | smp->data.type = SMP_T_SINT; |
| 1970 | smp->data.u.sint = 0; |
| 1971 | if (stkctr_entry(stkctr) != NULL) { |
| 1972 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); |
| 1973 | if (!ptr) |
| 1974 | return 0; /* parameter not stored */ |
| 1975 | smp->data.u.sint = stktable_data_cast(ptr, sess_cnt); |
| 1976 | } |
| 1977 | return 1; |
| 1978 | } |
| 1979 | |
| 1980 | /* set <smp> to the stream rate from the stream's tracked frontend counters. |
| 1981 | * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only. |
| 1982 | */ |
| 1983 | static int |
| 1984 | smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1985 | { |
| 1986 | struct stkctr *stkctr; |
| 1987 | |
| 1988 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 1989 | if (!stkctr) |
| 1990 | return 0; |
| 1991 | |
| 1992 | smp->flags = SMP_F_VOL_TEST; |
| 1993 | smp->data.type = SMP_T_SINT; |
| 1994 | smp->data.u.sint = 0; |
| 1995 | if (stkctr_entry(stkctr) != NULL) { |
| 1996 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); |
| 1997 | if (!ptr) |
| 1998 | return 0; /* parameter not stored */ |
| 1999 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), |
| 2000 | stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); |
| 2001 | } |
| 2002 | return 1; |
| 2003 | } |
| 2004 | |
| 2005 | /* set <smp> to the cumulated number of HTTP requests from the stream's tracked |
| 2006 | * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or |
| 2007 | * "src_http_req_cnt" only. |
| 2008 | */ |
| 2009 | static int |
| 2010 | smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2011 | { |
| 2012 | struct stkctr *stkctr; |
| 2013 | |
| 2014 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2015 | if (!stkctr) |
| 2016 | return 0; |
| 2017 | |
| 2018 | smp->flags = SMP_F_VOL_TEST; |
| 2019 | smp->data.type = SMP_T_SINT; |
| 2020 | smp->data.u.sint = 0; |
| 2021 | if (stkctr_entry(stkctr) != NULL) { |
| 2022 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
| 2023 | if (!ptr) |
| 2024 | return 0; /* parameter not stored */ |
| 2025 | smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt); |
| 2026 | } |
| 2027 | return 1; |
| 2028 | } |
| 2029 | |
| 2030 | /* set <smp> to the HTTP request rate from the stream's tracked frontend |
| 2031 | * counters. Supports being called as "sc[0-9]_http_req_rate" or |
| 2032 | * "src_http_req_rate" only. |
| 2033 | */ |
| 2034 | static int |
| 2035 | smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2036 | { |
| 2037 | struct stkctr *stkctr; |
| 2038 | |
| 2039 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2040 | if (!stkctr) |
| 2041 | return 0; |
| 2042 | |
| 2043 | smp->flags = SMP_F_VOL_TEST; |
| 2044 | smp->data.type = SMP_T_SINT; |
| 2045 | smp->data.u.sint = 0; |
| 2046 | if (stkctr_entry(stkctr) != NULL) { |
| 2047 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
| 2048 | if (!ptr) |
| 2049 | return 0; /* parameter not stored */ |
| 2050 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
| 2051 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
| 2052 | } |
| 2053 | return 1; |
| 2054 | } |
| 2055 | |
| 2056 | /* set <smp> to the cumulated number of HTTP requests errors from the stream's |
| 2057 | * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or |
| 2058 | * "src_http_err_cnt" only. |
| 2059 | */ |
| 2060 | static int |
| 2061 | smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2062 | { |
| 2063 | struct stkctr *stkctr; |
| 2064 | |
| 2065 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2066 | if (!stkctr) |
| 2067 | return 0; |
| 2068 | |
| 2069 | smp->flags = SMP_F_VOL_TEST; |
| 2070 | smp->data.type = SMP_T_SINT; |
| 2071 | smp->data.u.sint = 0; |
| 2072 | if (stkctr_entry(stkctr) != NULL) { |
| 2073 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
| 2074 | if (!ptr) |
| 2075 | return 0; /* parameter not stored */ |
| 2076 | smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt); |
| 2077 | } |
| 2078 | return 1; |
| 2079 | } |
| 2080 | |
| 2081 | /* set <smp> to the HTTP request error rate from the stream's tracked frontend |
| 2082 | * counters. Supports being called as "sc[0-9]_http_err_rate" or |
| 2083 | * "src_http_err_rate" only. |
| 2084 | */ |
| 2085 | static int |
| 2086 | smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2087 | { |
| 2088 | struct stkctr *stkctr; |
| 2089 | |
| 2090 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2091 | if (!stkctr) |
| 2092 | return 0; |
| 2093 | |
| 2094 | smp->flags = SMP_F_VOL_TEST; |
| 2095 | smp->data.type = SMP_T_SINT; |
| 2096 | smp->data.u.sint = 0; |
| 2097 | if (stkctr_entry(stkctr) != NULL) { |
| 2098 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
| 2099 | if (!ptr) |
| 2100 | return 0; /* parameter not stored */ |
| 2101 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), |
| 2102 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
| 2103 | } |
| 2104 | return 1; |
| 2105 | } |
| 2106 | |
| 2107 | /* set <smp> to the number of kbytes received from clients, as found in the |
| 2108 | * stream's tracked frontend counters. Supports being called as |
| 2109 | * "sc[0-9]_kbytes_in" or "src_kbytes_in" only. |
| 2110 | */ |
| 2111 | static int |
| 2112 | smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2113 | { |
| 2114 | struct stkctr *stkctr; |
| 2115 | |
| 2116 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2117 | if (!stkctr) |
| 2118 | return 0; |
| 2119 | |
| 2120 | smp->flags = SMP_F_VOL_TEST; |
| 2121 | smp->data.type = SMP_T_SINT; |
| 2122 | smp->data.u.sint = 0; |
| 2123 | if (stkctr_entry(stkctr) != NULL) { |
| 2124 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
| 2125 | if (!ptr) |
| 2126 | return 0; /* parameter not stored */ |
| 2127 | smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; |
| 2128 | } |
| 2129 | return 1; |
| 2130 | } |
| 2131 | |
| 2132 | /* set <smp> to the data rate received from clients in bytes/s, as found |
| 2133 | * in the stream's tracked frontend counters. Supports being called as |
| 2134 | * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only. |
| 2135 | */ |
| 2136 | static int |
| 2137 | smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2138 | { |
| 2139 | struct stkctr *stkctr; |
| 2140 | |
| 2141 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2142 | if (!stkctr) |
| 2143 | return 0; |
| 2144 | |
| 2145 | smp->flags = SMP_F_VOL_TEST; |
| 2146 | smp->data.type = SMP_T_SINT; |
| 2147 | smp->data.u.sint = 0; |
| 2148 | if (stkctr_entry(stkctr) != NULL) { |
| 2149 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
| 2150 | if (!ptr) |
| 2151 | return 0; /* parameter not stored */ |
| 2152 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
| 2153 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
| 2154 | } |
| 2155 | return 1; |
| 2156 | } |
| 2157 | |
| 2158 | /* set <smp> to the number of kbytes sent to clients, as found in the |
| 2159 | * stream's tracked frontend counters. Supports being called as |
| 2160 | * "sc[0-9]_kbytes_out" or "src_kbytes_out" only. |
| 2161 | */ |
| 2162 | static int |
| 2163 | smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2164 | { |
| 2165 | struct stkctr *stkctr; |
| 2166 | |
| 2167 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2168 | if (!stkctr) |
| 2169 | return 0; |
| 2170 | |
| 2171 | smp->flags = SMP_F_VOL_TEST; |
| 2172 | smp->data.type = SMP_T_SINT; |
| 2173 | smp->data.u.sint = 0; |
| 2174 | if (stkctr_entry(stkctr) != NULL) { |
| 2175 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
| 2176 | if (!ptr) |
| 2177 | return 0; /* parameter not stored */ |
| 2178 | smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; |
| 2179 | } |
| 2180 | return 1; |
| 2181 | } |
| 2182 | |
| 2183 | /* set <smp> to the data rate sent to clients in bytes/s, as found in the |
| 2184 | * stream's tracked frontend counters. Supports being called as |
| 2185 | * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. |
| 2186 | */ |
| 2187 | static int |
| 2188 | smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2189 | { |
| 2190 | struct stkctr *stkctr; |
| 2191 | |
| 2192 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2193 | if (!stkctr) |
| 2194 | return 0; |
| 2195 | |
| 2196 | smp->flags = SMP_F_VOL_TEST; |
| 2197 | smp->data.type = SMP_T_SINT; |
| 2198 | smp->data.u.sint = 0; |
| 2199 | if (stkctr_entry(stkctr) != NULL) { |
| 2200 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
| 2201 | if (!ptr) |
| 2202 | return 0; /* parameter not stored */ |
| 2203 | smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
| 2204 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
| 2205 | } |
| 2206 | return 1; |
| 2207 | } |
| 2208 | |
| 2209 | /* set <smp> to the number of active trackers on the SC entry in the stream's |
| 2210 | * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only. |
| 2211 | */ |
| 2212 | static int |
| 2213 | smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 2214 | { |
| 2215 | struct stkctr *stkctr; |
| 2216 | |
| 2217 | stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); |
| 2218 | if (!stkctr) |
| 2219 | return 0; |
| 2220 | |
| 2221 | smp->flags = SMP_F_VOL_TEST; |
| 2222 | smp->data.type = SMP_T_SINT; |
| 2223 | smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0; |
| 2224 | return 1; |
| 2225 | } |
| 2226 | |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2227 | |
| 2228 | /* The functions below are used to manipulate table contents from the CLI. |
| 2229 | * There are 3 main actions, "clear", "set" and "show". The code is shared |
| 2230 | * between all actions, and the action is encoded in the void *private in |
| 2231 | * the appctx as well as in the keyword registration, among one of the |
| 2232 | * following values. |
| 2233 | */ |
| 2234 | |
| 2235 | enum { |
| 2236 | STK_CLI_ACT_CLR, |
| 2237 | STK_CLI_ACT_SET, |
| 2238 | STK_CLI_ACT_SHOW, |
| 2239 | }; |
| 2240 | |
| 2241 | /* Dump the status of a table to a stream interface's |
| 2242 | * read buffer. It returns 0 if the output buffer is full |
| 2243 | * and needs to be called again, otherwise non-zero. |
| 2244 | */ |
| 2245 | static int table_dump_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 2246 | struct proxy *proxy, struct proxy *target) |
| 2247 | { |
| 2248 | struct stream *s = si_strm(si); |
| 2249 | |
| 2250 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
| 2251 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 2252 | |
| 2253 | /* any other information should be dumped here */ |
| 2254 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 2255 | 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] | 2256 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
| 2257 | |
| 2258 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 2259 | si_applet_cant_put(si); |
| 2260 | return 0; |
| 2261 | } |
| 2262 | |
| 2263 | return 1; |
| 2264 | } |
| 2265 | |
| 2266 | /* Dump a table entry to a stream interface's |
| 2267 | * read buffer. It returns 0 if the output buffer is full |
| 2268 | * and needs to be called again, otherwise non-zero. |
| 2269 | */ |
| 2270 | static int table_dump_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 2271 | struct proxy *proxy, struct stksess *entry) |
| 2272 | { |
| 2273 | int dt; |
| 2274 | |
| 2275 | chunk_appendf(msg, "%p:", entry); |
| 2276 | |
| 2277 | if (proxy->table.type == SMP_T_IPV4) { |
| 2278 | char addr[INET_ADDRSTRLEN]; |
| 2279 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 2280 | chunk_appendf(msg, " key=%s", addr); |
| 2281 | } |
| 2282 | else if (proxy->table.type == SMP_T_IPV6) { |
| 2283 | char addr[INET6_ADDRSTRLEN]; |
| 2284 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
| 2285 | chunk_appendf(msg, " key=%s", addr); |
| 2286 | } |
| 2287 | else if (proxy->table.type == SMP_T_SINT) { |
| 2288 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
| 2289 | } |
| 2290 | else if (proxy->table.type == SMP_T_STR) { |
| 2291 | chunk_appendf(msg, " key="); |
| 2292 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 2293 | } |
| 2294 | else { |
| 2295 | chunk_appendf(msg, " key="); |
| 2296 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 2297 | } |
| 2298 | |
| 2299 | chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire)); |
| 2300 | |
| 2301 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 2302 | void *ptr; |
| 2303 | |
| 2304 | if (proxy->table.data_ofs[dt] == 0) |
| 2305 | continue; |
| 2306 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
| 2307 | chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u); |
| 2308 | else |
| 2309 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
| 2310 | |
| 2311 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 2312 | switch (stktable_data_types[dt].std_type) { |
| 2313 | case STD_T_SINT: |
| 2314 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
| 2315 | break; |
| 2316 | case STD_T_UINT: |
| 2317 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
| 2318 | break; |
| 2319 | case STD_T_ULL: |
| 2320 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
| 2321 | break; |
| 2322 | case STD_T_FRQP: |
| 2323 | chunk_appendf(msg, "%d", |
| 2324 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 2325 | proxy->table.data_arg[dt].u)); |
| 2326 | break; |
| 2327 | } |
| 2328 | } |
| 2329 | chunk_appendf(msg, "\n"); |
| 2330 | |
| 2331 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 2332 | si_applet_cant_put(si); |
| 2333 | return 0; |
| 2334 | } |
| 2335 | |
| 2336 | return 1; |
| 2337 | } |
| 2338 | |
| 2339 | |
| 2340 | /* Processes a single table entry matching a specific key passed in argument. |
| 2341 | * returns 0 if wants to be called again, 1 if has ended processing. |
| 2342 | */ |
| 2343 | static int table_process_entry_per_key(struct appctx *appctx, char **args) |
| 2344 | { |
| 2345 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2346 | struct proxy *px = appctx->ctx.table.target; |
| 2347 | struct stksess *ts; |
| 2348 | uint32_t uint32_key; |
| 2349 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
| 2350 | long long value; |
| 2351 | int data_type; |
| 2352 | int cur_arg; |
| 2353 | void *ptr; |
| 2354 | struct freq_ctr_period *frqp; |
| 2355 | |
| 2356 | if (!*args[4]) { |
| 2357 | appctx->ctx.cli.msg = "Key value expected\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2358 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2359 | return 1; |
| 2360 | } |
| 2361 | |
| 2362 | switch (px->table.type) { |
| 2363 | case SMP_T_IPV4: |
| 2364 | uint32_key = htonl(inetaddr_host(args[4])); |
| 2365 | static_table_key->key = &uint32_key; |
| 2366 | break; |
| 2367 | case SMP_T_IPV6: |
| 2368 | inet_pton(AF_INET6, args[4], ip6_key); |
| 2369 | static_table_key->key = &ip6_key; |
| 2370 | break; |
| 2371 | case SMP_T_SINT: |
| 2372 | { |
| 2373 | char *endptr; |
| 2374 | unsigned long val; |
| 2375 | errno = 0; |
| 2376 | val = strtoul(args[4], &endptr, 10); |
| 2377 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 2378 | (errno != 0 && val == 0) || endptr == args[4] || |
| 2379 | val > 0xffffffff) { |
| 2380 | appctx->ctx.cli.msg = "Invalid key\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2381 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2382 | return 1; |
| 2383 | } |
| 2384 | uint32_key = (uint32_t) val; |
| 2385 | static_table_key->key = &uint32_key; |
| 2386 | break; |
| 2387 | } |
| 2388 | break; |
| 2389 | case SMP_T_STR: |
| 2390 | static_table_key->key = args[4]; |
| 2391 | static_table_key->key_len = strlen(args[4]); |
| 2392 | break; |
| 2393 | default: |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 2394 | switch (appctx->ctx.table.action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2395 | case STK_CLI_ACT_SHOW: |
| 2396 | appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 2397 | break; |
| 2398 | case STK_CLI_ACT_CLR: |
| 2399 | appctx->ctx.cli.msg = "Removing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 2400 | break; |
| 2401 | case STK_CLI_ACT_SET: |
| 2402 | appctx->ctx.cli.msg = "Inserting keys into tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 2403 | break; |
| 2404 | default: |
| 2405 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 2406 | break; |
| 2407 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2408 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2409 | return 1; |
| 2410 | } |
| 2411 | |
| 2412 | /* check permissions */ |
| 2413 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 2414 | return 1; |
| 2415 | |
| 2416 | ts = stktable_lookup_key(&px->table, static_table_key); |
| 2417 | |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 2418 | switch (appctx->ctx.table.action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2419 | case STK_CLI_ACT_SHOW: |
| 2420 | if (!ts) |
| 2421 | return 1; |
| 2422 | chunk_reset(&trash); |
| 2423 | if (!table_dump_head_to_buffer(&trash, si, px, px)) |
| 2424 | return 0; |
| 2425 | if (!table_dump_entry_to_buffer(&trash, si, px, ts)) |
| 2426 | return 0; |
| 2427 | break; |
| 2428 | |
| 2429 | case STK_CLI_ACT_CLR: |
| 2430 | if (!ts) |
| 2431 | return 1; |
| 2432 | if (ts->ref_cnt) { |
| 2433 | /* don't delete an entry which is currently referenced */ |
| 2434 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2435 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2436 | return 1; |
| 2437 | } |
| 2438 | stksess_kill(&px->table, ts); |
| 2439 | break; |
| 2440 | |
| 2441 | case STK_CLI_ACT_SET: |
| 2442 | if (ts) |
| 2443 | stktable_touch(&px->table, ts, 1); |
| 2444 | else { |
| 2445 | ts = stksess_new(&px->table, static_table_key); |
| 2446 | if (!ts) { |
| 2447 | /* don't delete an entry which is currently referenced */ |
| 2448 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2449 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2450 | return 1; |
| 2451 | } |
| 2452 | stktable_store(&px->table, ts, 1); |
| 2453 | } |
| 2454 | |
| 2455 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 2456 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
| 2457 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2458 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2459 | return 1; |
| 2460 | } |
| 2461 | |
| 2462 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 2463 | if (data_type < 0) { |
| 2464 | appctx->ctx.cli.msg = "Unknown data type\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2465 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2466 | return 1; |
| 2467 | } |
| 2468 | |
| 2469 | if (!px->table.data_ofs[data_type]) { |
| 2470 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2471 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2472 | return 1; |
| 2473 | } |
| 2474 | |
| 2475 | if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) { |
| 2476 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2477 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2478 | return 1; |
| 2479 | } |
| 2480 | |
| 2481 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 2482 | |
| 2483 | switch (stktable_data_types[data_type].std_type) { |
| 2484 | case STD_T_SINT: |
| 2485 | stktable_data_cast(ptr, std_t_sint) = value; |
| 2486 | break; |
| 2487 | case STD_T_UINT: |
| 2488 | stktable_data_cast(ptr, std_t_uint) = value; |
| 2489 | break; |
| 2490 | case STD_T_ULL: |
| 2491 | stktable_data_cast(ptr, std_t_ull) = value; |
| 2492 | break; |
| 2493 | case STD_T_FRQP: |
| 2494 | /* We set both the current and previous values. That way |
| 2495 | * the reported frequency is stable during all the period |
| 2496 | * then slowly fades out. This allows external tools to |
| 2497 | * push measures without having to update them too often. |
| 2498 | */ |
| 2499 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 2500 | frqp->curr_tick = now_ms; |
| 2501 | frqp->prev_ctr = 0; |
| 2502 | frqp->curr_ctr = value; |
| 2503 | break; |
| 2504 | } |
| 2505 | } |
| 2506 | break; |
| 2507 | |
| 2508 | default: |
| 2509 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2510 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2511 | break; |
| 2512 | } |
| 2513 | return 1; |
| 2514 | } |
| 2515 | |
| 2516 | /* Prepares the appctx fields with the data-based filters from the command line. |
| 2517 | * Returns 0 if the dump can proceed, 1 if has ended processing. |
| 2518 | */ |
| 2519 | static int table_prepare_data_request(struct appctx *appctx, char **args) |
| 2520 | { |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 2521 | if (appctx->ctx.table.action != STK_CLI_ACT_SHOW && appctx->ctx.table.action != STK_CLI_ACT_CLR) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2522 | 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] | 2523 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2524 | return 1; |
| 2525 | } |
| 2526 | |
| 2527 | /* condition on stored data value */ |
| 2528 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 2529 | if (appctx->ctx.table.data_type < 0) { |
| 2530 | appctx->ctx.cli.msg = "Unknown data type\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2531 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2532 | return 1; |
| 2533 | } |
| 2534 | |
| 2535 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 2536 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2537 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2538 | return 1; |
| 2539 | } |
| 2540 | |
| 2541 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 2542 | if (appctx->ctx.table.data_op < 0) { |
| 2543 | 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] | 2544 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2545 | return 1; |
| 2546 | } |
| 2547 | |
| 2548 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 2549 | 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] | 2550 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2551 | return 1; |
| 2552 | } |
| 2553 | |
| 2554 | /* OK we're done, all the fields are set */ |
| 2555 | return 0; |
| 2556 | } |
| 2557 | |
| 2558 | /* returns 0 if wants to be called, 1 if has ended processing */ |
| 2559 | static int cli_parse_table_req(char **args, struct appctx *appctx, void *private) |
| 2560 | { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2561 | appctx->ctx.table.data_type = -1; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2562 | appctx->ctx.table.target = NULL; |
| 2563 | appctx->ctx.table.proxy = NULL; |
| 2564 | appctx->ctx.table.entry = NULL; |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 2565 | 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] | 2566 | |
| 2567 | if (*args[2]) { |
| 2568 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
| 2569 | if (!appctx->ctx.table.target) { |
| 2570 | appctx->ctx.cli.msg = "No such table\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2571 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2572 | return 1; |
| 2573 | } |
| 2574 | } |
| 2575 | else { |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 2576 | if (appctx->ctx.table.action != STK_CLI_ACT_SHOW) |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2577 | goto err_args; |
| 2578 | return 0; |
| 2579 | } |
| 2580 | |
| 2581 | if (strcmp(args[3], "key") == 0) |
| 2582 | return table_process_entry_per_key(appctx, args); |
| 2583 | else if (strncmp(args[3], "data.", 5) == 0) |
| 2584 | return table_prepare_data_request(appctx, args); |
| 2585 | else if (*args[3]) |
| 2586 | goto err_args; |
| 2587 | |
| 2588 | return 0; |
| 2589 | |
| 2590 | err_args: |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 2591 | switch (appctx->ctx.table.action) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2592 | case STK_CLI_ACT_SHOW: |
| 2593 | appctx->ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n"; |
| 2594 | break; |
| 2595 | case STK_CLI_ACT_CLR: |
| 2596 | appctx->ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n"; |
| 2597 | break; |
| 2598 | case STK_CLI_ACT_SET: |
| 2599 | appctx->ctx.cli.msg = "Required arguments: <table> key <key> [data.<store_data_type> <value>]*\n"; |
| 2600 | break; |
| 2601 | default: |
| 2602 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 2603 | break; |
| 2604 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 2605 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2606 | return 1; |
| 2607 | } |
| 2608 | |
| 2609 | /* This function is used to deal with table operations (dump or clear depending |
| 2610 | * on the action stored in appctx->private). It returns 0 if the output buffer is |
| 2611 | * full and it needs to be called again, otherwise non-zero. |
| 2612 | */ |
| 2613 | static int cli_io_handler_table(struct appctx *appctx) |
| 2614 | { |
| 2615 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2616 | struct stream *s = si_strm(si); |
| 2617 | struct ebmb_node *eb; |
| 2618 | int dt; |
| 2619 | int skip_entry; |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 2620 | int show = appctx->ctx.table.action == STK_CLI_ACT_SHOW; |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2621 | |
| 2622 | /* |
| 2623 | * We have 3 possible states in appctx->st2 : |
| 2624 | * - STAT_ST_INIT : the first call |
| 2625 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
| 2626 | * dump, the entry pointer is NULL ; |
| 2627 | * - STAT_ST_LIST : the proxy pointer points to the current table |
| 2628 | * and the entry pointer points to the next entry to be dumped, |
| 2629 | * and the refcount on the next entry is held ; |
| 2630 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
| 2631 | * data though. |
| 2632 | */ |
| 2633 | |
| 2634 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
| 2635 | /* in case of abort, remove any refcount we might have set on an entry */ |
| 2636 | if (appctx->st2 == STAT_ST_LIST) { |
| 2637 | appctx->ctx.table.entry->ref_cnt--; |
| 2638 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 2639 | } |
| 2640 | return 1; |
| 2641 | } |
| 2642 | |
| 2643 | chunk_reset(&trash); |
| 2644 | |
| 2645 | while (appctx->st2 != STAT_ST_FIN) { |
| 2646 | switch (appctx->st2) { |
| 2647 | case STAT_ST_INIT: |
| 2648 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 2649 | if (!appctx->ctx.table.proxy) |
| 2650 | appctx->ctx.table.proxy = proxy; |
| 2651 | |
| 2652 | appctx->ctx.table.entry = NULL; |
| 2653 | appctx->st2 = STAT_ST_INFO; |
| 2654 | break; |
| 2655 | |
| 2656 | case STAT_ST_INFO: |
| 2657 | if (!appctx->ctx.table.proxy || |
| 2658 | (appctx->ctx.table.target && |
| 2659 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 2660 | appctx->st2 = STAT_ST_END; |
| 2661 | break; |
| 2662 | } |
| 2663 | |
| 2664 | if (appctx->ctx.table.proxy->table.size) { |
| 2665 | if (show && !table_dump_head_to_buffer(&trash, si, appctx->ctx.table.proxy, appctx->ctx.table.target)) |
| 2666 | return 0; |
| 2667 | |
| 2668 | if (appctx->ctx.table.target && |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 2669 | (strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) { |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2670 | /* dump entries only if table explicitly requested */ |
| 2671 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
| 2672 | if (eb) { |
| 2673 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 2674 | appctx->ctx.table.entry->ref_cnt++; |
| 2675 | appctx->st2 = STAT_ST_LIST; |
| 2676 | break; |
| 2677 | } |
| 2678 | } |
| 2679 | } |
| 2680 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 2681 | break; |
| 2682 | |
| 2683 | case STAT_ST_LIST: |
| 2684 | skip_entry = 0; |
| 2685 | |
| 2686 | if (appctx->ctx.table.data_type >= 0) { |
| 2687 | /* we're filtering on some data contents */ |
| 2688 | void *ptr; |
| 2689 | long long data; |
| 2690 | |
| 2691 | dt = appctx->ctx.table.data_type; |
| 2692 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 2693 | appctx->ctx.table.entry, |
| 2694 | dt); |
| 2695 | |
| 2696 | data = 0; |
| 2697 | switch (stktable_data_types[dt].std_type) { |
| 2698 | case STD_T_SINT: |
| 2699 | data = stktable_data_cast(ptr, std_t_sint); |
| 2700 | break; |
| 2701 | case STD_T_UINT: |
| 2702 | data = stktable_data_cast(ptr, std_t_uint); |
| 2703 | break; |
| 2704 | case STD_T_ULL: |
| 2705 | data = stktable_data_cast(ptr, std_t_ull); |
| 2706 | break; |
| 2707 | case STD_T_FRQP: |
| 2708 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 2709 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
| 2710 | break; |
| 2711 | } |
| 2712 | |
| 2713 | /* skip the entry if the data does not match the test and the value */ |
| 2714 | if ((data < appctx->ctx.table.value && |
| 2715 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 2716 | appctx->ctx.table.data_op == STD_OP_GT || |
| 2717 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 2718 | (data == appctx->ctx.table.value && |
| 2719 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 2720 | appctx->ctx.table.data_op == STD_OP_GT || |
| 2721 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 2722 | (data > appctx->ctx.table.value && |
| 2723 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 2724 | appctx->ctx.table.data_op == STD_OP_LT || |
| 2725 | appctx->ctx.table.data_op == STD_OP_LE))) |
| 2726 | skip_entry = 1; |
| 2727 | } |
| 2728 | |
| 2729 | if (show && !skip_entry && |
| 2730 | !table_dump_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, appctx->ctx.table.entry)) |
| 2731 | return 0; |
| 2732 | |
| 2733 | appctx->ctx.table.entry->ref_cnt--; |
| 2734 | |
| 2735 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
| 2736 | if (eb) { |
| 2737 | struct stksess *old = appctx->ctx.table.entry; |
| 2738 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 2739 | if (show) |
| 2740 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 2741 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 2742 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 2743 | appctx->ctx.table.entry->ref_cnt++; |
| 2744 | break; |
| 2745 | } |
| 2746 | |
| 2747 | |
| 2748 | if (show) |
| 2749 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 2750 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 2751 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 2752 | |
| 2753 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 2754 | appctx->st2 = STAT_ST_INFO; |
| 2755 | break; |
| 2756 | |
| 2757 | case STAT_ST_END: |
| 2758 | appctx->st2 = STAT_ST_FIN; |
| 2759 | break; |
| 2760 | } |
| 2761 | } |
| 2762 | return 1; |
| 2763 | } |
| 2764 | |
| 2765 | static void cli_release_show_table(struct appctx *appctx) |
| 2766 | { |
| 2767 | if (appctx->st2 == STAT_ST_LIST) { |
| 2768 | appctx->ctx.table.entry->ref_cnt--; |
| 2769 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | /* register cli keywords */ |
| 2774 | static struct cli_kw_list cli_kws = {{ },{ |
| 2775 | { { "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 }, |
| 2776 | { { "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 }, |
| 2777 | { { "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 }, |
| 2778 | {{},} |
| 2779 | }}; |
| 2780 | |
| 2781 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2782 | static struct action_kw_list tcp_conn_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2783 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2784 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 2785 | { /* END */ } |
| 2786 | }}; |
| 2787 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 2788 | static struct action_kw_list tcp_sess_kws = { { }, { |
| 2789 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
| 2790 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 2791 | { /* END */ } |
| 2792 | }}; |
| 2793 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2794 | static struct action_kw_list tcp_req_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2795 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2796 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 2797 | { /* END */ } |
| 2798 | }}; |
| 2799 | |
| 2800 | static struct action_kw_list tcp_res_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2801 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2802 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 2803 | { /* END */ } |
| 2804 | }}; |
| 2805 | |
| 2806 | static struct action_kw_list http_req_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2807 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2808 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 2809 | { /* END */ } |
| 2810 | }}; |
| 2811 | |
| 2812 | static struct action_kw_list http_res_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 2813 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2814 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 2815 | { /* END */ } |
| 2816 | }}; |
| 2817 | |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2818 | ///* Note: must not be declared <const> as its list will be overwritten. |
| 2819 | // * Please take care of keeping this list alphabetically sorted. |
| 2820 | // */ |
| 2821 | //static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 2822 | // { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2823 | // { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2824 | // { /* END */ }, |
| 2825 | //}}; |
| 2826 | /* Note: must not be declared <const> as its list will be overwritten. |
| 2827 | * Please take care of keeping this list alphabetically sorted. |
| 2828 | */ |
| 2829 | static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
| 2830 | { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2831 | { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2832 | { "sc_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2833 | { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2834 | { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2835 | { "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] | 2836 | { "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] | 2837 | { "sc_get_gpc0", smp_fetch_sc_get_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2838 | { "sc_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2839 | { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2840 | { "sc_http_err_rate", smp_fetch_sc_http_err_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2841 | { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2842 | { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2843 | { "sc_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2844 | { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2845 | { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2846 | { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2847 | { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2848 | { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 2849 | { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2850 | { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2851 | { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2852 | { "sc0_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2853 | { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2854 | { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2855 | { "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] | 2856 | { "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] | 2857 | { "sc0_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2858 | { "sc0_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2859 | { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2860 | { "sc0_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2861 | { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2862 | { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2863 | { "sc0_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2864 | { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2865 | { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2866 | { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2867 | { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2868 | { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 2869 | { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2870 | { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2871 | { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2872 | { "sc1_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2873 | { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2874 | { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2875 | { "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] | 2876 | { "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] | 2877 | { "sc1_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2878 | { "sc1_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2879 | { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2880 | { "sc1_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2881 | { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2882 | { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2883 | { "sc1_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2884 | { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2885 | { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2886 | { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2887 | { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2888 | { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 2889 | { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2890 | { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2891 | { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2892 | { "sc2_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2893 | { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2894 | { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2895 | { "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] | 2896 | { "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] | 2897 | { "sc2_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2898 | { "sc2_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2899 | { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2900 | { "sc2_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2901 | { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2902 | { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2903 | { "sc2_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2904 | { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2905 | { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2906 | { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2907 | { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2908 | { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 2909 | { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2910 | { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2911 | { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2912 | { "src_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2913 | { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2914 | { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2915 | { "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] | 2916 | { "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] | 2917 | { "src_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2918 | { "src_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2919 | { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2920 | { "src_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2921 | { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2922 | { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2923 | { "src_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2924 | { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2925 | { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2926 | { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2927 | { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2928 | { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, |
| 2929 | { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2930 | { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 2931 | { /* END */ }, |
| 2932 | }}; |
| 2933 | |
| 2934 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2935 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 2936 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 2937 | { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL }, |
| 2938 | { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2939 | { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2940 | { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2941 | { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2942 | { "table_conn_rate", sample_conv_table_conn_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2943 | { "table_gpt0", sample_conv_table_gpt0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2944 | { "table_gpc0", sample_conv_table_gpc0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2945 | { "table_gpc0_rate", sample_conv_table_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2946 | { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2947 | { "table_http_err_rate", sample_conv_table_http_err_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2948 | { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2949 | { "table_http_req_rate", sample_conv_table_http_req_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2950 | { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2951 | { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2952 | { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2953 | { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2954 | { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 2955 | { "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] | 2956 | { /* END */ }, |
| 2957 | }}; |
| 2958 | |
| 2959 | __attribute__((constructor)) |
| 2960 | static void __stick_table_init(void) |
| 2961 | { |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2962 | /* register som action keywords. */ |
| 2963 | tcp_req_conn_keywords_register(&tcp_conn_kws); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 2964 | tcp_req_sess_keywords_register(&tcp_sess_kws); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 2965 | tcp_req_cont_keywords_register(&tcp_req_kws); |
| 2966 | tcp_res_cont_keywords_register(&tcp_res_kws); |
| 2967 | http_req_keywords_register(&http_req_kws); |
| 2968 | http_res_keywords_register(&http_res_kws); |
| 2969 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2970 | /* register sample fetch and format conversion keywords */ |
Willy Tarreau | 7d56221 | 2016-11-25 16:10:05 +0100 | [diff] [blame] | 2971 | sample_register_fetches(&smp_fetch_keywords); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2972 | sample_register_convs(&sample_conv_kws); |
Willy Tarreau | f13ebdf | 2016-11-22 18:00:53 +0100 | [diff] [blame] | 2973 | cli_register_kw(&cli_kws); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 2974 | } |