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> |
| 15 | |
| 16 | #include <common/config.h> |
| 17 | #include <common/memory.h> |
| 18 | #include <common/mini-clist.h> |
| 19 | #include <common/standard.h> |
| 20 | #include <common/time.h> |
| 21 | |
| 22 | #include <ebmbtree.h> |
| 23 | #include <ebsttree.h> |
| 24 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 25 | #include <proto/arg.h> |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 26 | #include <proto/proto_http.h> |
| 27 | #include <proto/proto_tcp.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 28 | #include <proto/proxy.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 29 | #include <proto/sample.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 30 | #include <proto/stream.h> |
Willy Tarreau | 68129b9 | 2010-06-06 16:06:52 +0200 | [diff] [blame] | 31 | #include <proto/stick_table.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 32 | #include <proto/task.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 33 | #include <proto/peers.h> |
| 34 | #include <types/global.h> |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 35 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 36 | /* structure used to return a table key built from a sample */ |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 37 | struct stktable_key *static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 38 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 39 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 40 | * Free an allocated sticky session <ts>, and decrease sticky sessions counter |
| 41 | * in table <t>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 42 | */ |
| 43 | void stksess_free(struct stktable *t, struct stksess *ts) |
| 44 | { |
| 45 | t->current--; |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 46 | pool_free2(t->pool, (void *)ts - t->data_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 50 | * Kill an stksess (only if its ref_cnt is zero). |
| 51 | */ |
| 52 | void stksess_kill(struct stktable *t, struct stksess *ts) |
| 53 | { |
| 54 | if (ts->ref_cnt) |
| 55 | return; |
| 56 | |
| 57 | eb32_delete(&ts->exp); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 58 | eb32_delete(&ts->upd); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 59 | ebmb_delete(&ts->key); |
| 60 | stksess_free(t, ts); |
| 61 | } |
| 62 | |
| 63 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 64 | * Initialize or update the key in the sticky session <ts> present in table <t> |
| 65 | * from the value present in <key>. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 66 | */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 67 | 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] | 68 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 69 | if (t->type != SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 70 | memcpy(ts->key.key, key->key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 71 | else { |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 72 | memcpy(ts->key.key, key->key, MIN(t->key_size - 1, key->key_len)); |
| 73 | ts->key.key[MIN(t->key_size - 1, key->key_len)] = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /* |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 79 | * Init sticky session <ts> of table <t>. The data parts are cleared and <ts> |
| 80 | * is returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 81 | */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 82 | static struct stksess *stksess_init(struct stktable *t, struct stksess * ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 83 | { |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 84 | memset((void *)ts - t->data_size, 0, t->data_size); |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 85 | ts->ref_cnt = 0; |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 86 | ts->key.node.leaf_p = NULL; |
| 87 | ts->exp.node.leaf_p = NULL; |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 88 | ts->upd.node.leaf_p = NULL; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 89 | return ts; |
| 90 | } |
| 91 | |
| 92 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 93 | * Trash oldest <to_batch> sticky sessions from table <t> |
| 94 | * Returns number of trashed sticky sessions. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 95 | */ |
Willy Tarreau | 3a925c1 | 2013-09-04 17:54:01 +0200 | [diff] [blame] | 96 | int stktable_trash_oldest(struct stktable *t, int to_batch) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 97 | { |
| 98 | struct stksess *ts; |
| 99 | struct eb32_node *eb; |
| 100 | int batched = 0; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 101 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 102 | |
| 103 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 104 | |
| 105 | while (batched < to_batch) { |
| 106 | |
| 107 | if (unlikely(!eb)) { |
| 108 | /* we might have reached the end of the tree, typically because |
| 109 | * <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] | 110 | * half. Let's loop back to the beginning of the tree now if we |
| 111 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 112 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 113 | if (looped) |
| 114 | break; |
| 115 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 116 | eb = eb32_first(&t->exps); |
| 117 | if (likely(!eb)) |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 122 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 123 | eb = eb32_next(eb); |
| 124 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 125 | /* don't delete an entry which is currently referenced */ |
| 126 | if (ts->ref_cnt) |
| 127 | continue; |
| 128 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 129 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 130 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 131 | if (ts->expire != ts->exp.key) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 132 | if (!tick_isset(ts->expire)) |
| 133 | continue; |
| 134 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 135 | ts->exp.key = ts->expire; |
| 136 | eb32_insert(&t->exps, &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 (!eb || eb->key > ts->exp.key) |
| 139 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 140 | |
| 141 | continue; |
| 142 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 143 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 144 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 145 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 146 | eb32_delete(&ts->upd); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 147 | stksess_free(t, ts); |
| 148 | batched++; |
| 149 | } |
| 150 | |
| 151 | return batched; |
| 152 | } |
| 153 | |
| 154 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 155 | * Allocate and initialise a new sticky session. |
| 156 | * The new sticky session is returned or NULL in case of lack of memory. |
| 157 | * 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] | 158 | * stksess_free(). Table <t>'s sticky session counter is increased. If <key> |
| 159 | * is not NULL, it is assigned to the new session. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 160 | */ |
| 161 | struct stksess *stksess_new(struct stktable *t, struct stktable_key *key) |
| 162 | { |
| 163 | struct stksess *ts; |
| 164 | |
| 165 | if (unlikely(t->current == t->size)) { |
| 166 | if ( t->nopurge ) |
| 167 | return NULL; |
| 168 | |
Emeric Brun | fbce6d0 | 2010-09-23 18:10:00 +0200 | [diff] [blame] | 169 | if (!stktable_trash_oldest(t, (t->size >> 8) + 1)) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 170 | return NULL; |
| 171 | } |
| 172 | |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 173 | ts = pool_alloc2(t->pool) + t->data_size; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 174 | if (ts) { |
| 175 | t->current++; |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 176 | stksess_init(t, ts); |
Willy Tarreau | a7b46b5 | 2013-04-11 16:55:37 +0200 | [diff] [blame] | 177 | if (key) |
| 178 | stksess_setkey(t, ts, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | return ts; |
| 182 | } |
| 183 | |
| 184 | /* |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 185 | * Looks in table <t> for a sticky session matching key <key>. |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 186 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 187 | */ |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 188 | struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 189 | { |
| 190 | struct ebmb_node *eb; |
| 191 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 192 | if (t->type == SMP_T_STR) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 193 | 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] | 194 | else |
| 195 | eb = ebmb_lookup(&t->keys, key->key, t->key_size); |
| 196 | |
| 197 | if (unlikely(!eb)) { |
| 198 | /* no session found */ |
| 199 | return NULL; |
| 200 | } |
| 201 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 202 | return ebmb_entry(eb, struct stksess, key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 205 | /* Lookup and touch <key> in <table>, or create the entry if it does not exist. |
| 206 | * This is mainly used for situations where we want to refresh a key's usage so |
| 207 | * that it does not expire, and we want to have it created if it was not there. |
| 208 | * The stksess is returned, or NULL if it could not be created. |
| 209 | */ |
| 210 | struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key) |
| 211 | { |
| 212 | struct stksess *ts; |
| 213 | |
| 214 | ts = stktable_lookup_key(table, key); |
| 215 | if (likely(ts)) |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 216 | return stktable_touch(table, ts, 1); |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 217 | |
| 218 | /* entry does not exist, initialize a new one */ |
| 219 | ts = stksess_new(table, key); |
| 220 | if (likely(ts)) |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 221 | stktable_store(table, ts, 1); |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 222 | return ts; |
| 223 | } |
| 224 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 225 | /* |
| 226 | * Looks in table <t> for a sticky session with same key as <ts>. |
| 227 | * Returns pointer on requested sticky session or NULL if none was found. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 228 | */ |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 229 | struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 230 | { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 231 | struct ebmb_node *eb; |
| 232 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 233 | if (t->type == SMP_T_STR) |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 234 | eb = ebst_lookup(&(t->keys), (char *)ts->key.key); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 235 | else |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 236 | eb = ebmb_lookup(&(t->keys), ts->key.key, t->key_size); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 237 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 238 | if (unlikely(!eb)) |
| 239 | return NULL; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 240 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 241 | return ebmb_entry(eb, struct stksess, key); |
| 242 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 243 | |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 244 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 245 | * The table's expiration timer is updated if set. |
| 246 | */ |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 247 | struct stksess *stktable_touch_with_exp(struct stktable *t, struct stksess *ts, |
| 248 | int local, int expire) |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 249 | { |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 250 | struct eb32_node * eb; |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 251 | ts->expire = expire; |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 252 | if (t->expire) { |
| 253 | t->exp_task->expire = t->exp_next = tick_first(ts->expire, t->exp_next); |
| 254 | task_queue(t->exp_task); |
| 255 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 256 | |
Emeric Brun | aaf5860 | 2015-06-15 17:23:30 +0200 | [diff] [blame] | 257 | /* If sync is enabled and update is local */ |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 258 | if (t->sync_task && local) { |
Emeric Brun | c703a9d | 2015-09-22 15:05:06 +0200 | [diff] [blame] | 259 | /* If this entry is not in the tree |
| 260 | or not scheduled for at least one peer */ |
| 261 | if (!ts->upd.node.leaf_p |
| 262 | || (int)(t->commitupdate - ts->upd.key) >= 0 |
| 263 | || (int)(ts->upd.key - t->localupdate) >= 0) { |
Emeric Brun | aaf5860 | 2015-06-15 17:23:30 +0200 | [diff] [blame] | 264 | ts->upd.key = ++t->update; |
| 265 | t->localupdate = t->update; |
| 266 | eb32_delete(&ts->upd); |
| 267 | eb = eb32_insert(&t->updates, &ts->upd); |
| 268 | if (eb != &ts->upd) { |
| 269 | eb32_delete(eb); |
| 270 | eb32_insert(&t->updates, &ts->upd); |
| 271 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 272 | } |
| 273 | task_wakeup(t->sync_task, TASK_WOKEN_MSG); |
| 274 | } |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 275 | return ts; |
| 276 | } |
| 277 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 278 | /* Update the expiration timer for <ts> but do not touch its expiration node. |
| 279 | * The table's expiration timer is updated if set. The date of expiration coming from |
| 280 | * <t> stick-table configuration. |
| 281 | */ |
| 282 | struct stksess *stktable_touch(struct stktable *t, struct stksess *ts, int local) |
| 283 | { |
| 284 | int expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
| 285 | |
| 286 | return stktable_touch_with_exp(t, ts, local, expire); |
| 287 | } |
| 288 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 289 | /* Insert new sticky session <ts> in the table. It is assumed that it does not |
| 290 | * yet exist (the caller must check this). The table's timeout is updated if it |
| 291 | * is set. <ts> is returned. |
| 292 | */ |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 293 | struct stksess *stktable_store(struct stktable *t, struct stksess *ts, int local) |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 294 | { |
| 295 | ebmb_insert(&t->keys, &ts->key, t->key_size); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 296 | stktable_touch(t, ts, local); |
Willy Tarreau | cb18364 | 2010-06-06 17:58:34 +0200 | [diff] [blame] | 297 | ts->exp.key = ts->expire; |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 298 | eb32_insert(&t->exps, &ts->exp); |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 299 | return ts; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Frédéric Lécaille | 523cc9e | 2016-10-12 17:30:30 +0200 | [diff] [blame] | 302 | /* Same function as stktable_store(), but with <expire> as supplementary argument |
| 303 | * to set the date of expiration of <ts> new sticky session thanks to |
| 304 | * stktable_touch_with_exp(). |
| 305 | */ |
| 306 | struct stksess *stktable_store_with_exp(struct stktable *t, struct stksess *ts, |
| 307 | int local, int expire) |
| 308 | { |
| 309 | ebmb_insert(&t->keys, &ts->key, t->key_size); |
| 310 | stktable_touch_with_exp(t, ts, local, expire); |
| 311 | ts->exp.key = ts->expire; |
| 312 | eb32_insert(&t->exps, &ts->exp); |
| 313 | return ts; |
| 314 | } |
| 315 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 316 | /* Returns a valid or initialized stksess for the specified stktable_key in the |
| 317 | * specified table, or NULL if the key was NULL, or if no entry was found nor |
| 318 | * could be created. The entry's expiration is updated. |
| 319 | */ |
| 320 | struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key) |
| 321 | { |
| 322 | struct stksess *ts; |
| 323 | |
| 324 | if (!key) |
| 325 | return NULL; |
| 326 | |
| 327 | ts = stktable_lookup_key(table, key); |
| 328 | if (ts == NULL) { |
| 329 | /* entry does not exist, initialize a new one */ |
| 330 | ts = stksess_new(table, key); |
| 331 | if (!ts) |
| 332 | return NULL; |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 333 | stktable_store(table, ts, 1); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 334 | } |
| 335 | else |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 336 | stktable_touch(table, ts, 1); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 337 | return ts; |
| 338 | } |
| 339 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 340 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 341 | * Trash expired sticky sessions from table <t>. The next expiration date is |
| 342 | * returned. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 343 | */ |
| 344 | static int stktable_trash_expired(struct stktable *t) |
| 345 | { |
| 346 | struct stksess *ts; |
| 347 | struct eb32_node *eb; |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 348 | int looped = 0; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 349 | |
| 350 | eb = eb32_lookup_ge(&t->exps, now_ms - TIMER_LOOK_BACK); |
| 351 | |
| 352 | while (1) { |
| 353 | if (unlikely(!eb)) { |
| 354 | /* we might have reached the end of the tree, typically because |
| 355 | * <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] | 356 | * half. Let's loop back to the beginning of the tree now if we |
| 357 | * have not yet visited it. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 358 | */ |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 359 | if (looped) |
| 360 | break; |
| 361 | looped = 1; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 362 | eb = eb32_first(&t->exps); |
| 363 | if (likely(!eb)) |
| 364 | break; |
| 365 | } |
| 366 | |
| 367 | if (likely(tick_is_lt(now_ms, eb->key))) { |
| 368 | /* timer not expired yet, revisit it later */ |
| 369 | t->exp_next = eb->key; |
| 370 | return t->exp_next; |
| 371 | } |
| 372 | |
| 373 | /* timer looks expired, detach it from the queue */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 374 | ts = eb32_entry(eb, struct stksess, exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 375 | eb = eb32_next(eb); |
| 376 | |
Willy Tarreau | e7f3d7a | 2010-06-14 14:53:07 +0200 | [diff] [blame] | 377 | /* don't delete an entry which is currently referenced */ |
| 378 | if (ts->ref_cnt) |
| 379 | continue; |
| 380 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 381 | eb32_delete(&ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 382 | |
| 383 | if (!tick_is_expired(ts->expire, now_ms)) { |
| 384 | if (!tick_isset(ts->expire)) |
| 385 | continue; |
| 386 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 387 | ts->exp.key = ts->expire; |
| 388 | eb32_insert(&t->exps, &ts->exp); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 389 | |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 390 | if (!eb || eb->key > ts->exp.key) |
| 391 | eb = &ts->exp; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 392 | continue; |
| 393 | } |
| 394 | |
| 395 | /* session expired, trash it */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame] | 396 | ebmb_delete(&ts->key); |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 397 | eb32_delete(&ts->upd); |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 398 | stksess_free(t, ts); |
| 399 | } |
| 400 | |
| 401 | /* We have found no task to expire in any tree */ |
| 402 | t->exp_next = TICK_ETERNITY; |
| 403 | return t->exp_next; |
| 404 | } |
| 405 | |
| 406 | /* |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 407 | * Task processing function to trash expired sticky sessions. A pointer to the |
| 408 | * task itself is returned since it never dies. |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 409 | */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 410 | static struct task *process_table_expire(struct task *task) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 411 | { |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 412 | struct stktable *t = task->context; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 413 | |
| 414 | task->expire = stktable_trash_expired(t); |
| 415 | return task; |
| 416 | } |
| 417 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 418 | /* 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] | 419 | int stktable_init(struct stktable *t) |
| 420 | { |
| 421 | if (t->size) { |
| 422 | memset(&t->keys, 0, sizeof(t->keys)); |
| 423 | memset(&t->exps, 0, sizeof(t->exps)); |
Emeric Brun | 1c6235d | 2015-12-16 15:28:12 +0100 | [diff] [blame] | 424 | t->updates = EB_ROOT_UNIQUE; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 425 | |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 426 | 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] | 427 | |
| 428 | t->exp_next = TICK_ETERNITY; |
| 429 | if ( t->expire ) { |
| 430 | t->exp_task = task_new(); |
| 431 | t->exp_task->process = process_table_expire; |
| 432 | t->exp_task->expire = TICK_ETERNITY; |
| 433 | t->exp_task->context = (void *)t; |
| 434 | } |
Willy Tarreau | c8b6791 | 2015-05-01 18:29:57 +0200 | [diff] [blame] | 435 | 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] | 436 | peers_register_table(t->peers.p, t); |
| 437 | } |
| 438 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 439 | return t->pool != NULL; |
| 440 | } |
| 441 | return 1; |
| 442 | } |
| 443 | |
| 444 | /* |
| 445 | * Configuration keywords of known table types |
| 446 | */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 447 | struct stktable_type stktable_types[SMP_TYPES] = { |
| 448 | [SMP_T_SINT] = { "integer", 0, 4 }, |
| 449 | [SMP_T_IPV4] = { "ip", 0, 4 }, |
| 450 | [SMP_T_IPV6] = { "ipv6", 0, 16 }, |
| 451 | [SMP_T_STR] = { "string", STK_F_CUSTOM_KEYSIZE, 32 }, |
| 452 | [SMP_T_BIN] = { "binary", STK_F_CUSTOM_KEYSIZE, 32 } |
| 453 | }; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 454 | |
| 455 | /* |
| 456 | * Parse table type configuration. |
| 457 | * Returns 0 on successful parsing, else 1. |
| 458 | * <myidx> is set at next configuration <args> index. |
| 459 | */ |
| 460 | int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size) |
| 461 | { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 462 | for (*type = 0; *type < SMP_TYPES; (*type)++) { |
| 463 | if (!stktable_types[*type].kw) |
| 464 | continue; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 465 | if (strcmp(args[*myidx], stktable_types[*type].kw) != 0) |
| 466 | continue; |
| 467 | |
| 468 | *key_size = stktable_types[*type].default_size; |
| 469 | (*myidx)++; |
| 470 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 471 | if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) { |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 472 | if (strcmp("len", args[*myidx]) == 0) { |
| 473 | (*myidx)++; |
| 474 | *key_size = atol(args[*myidx]); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 475 | if (!*key_size) |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 476 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 477 | if (*type == SMP_T_STR) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 478 | /* null terminated string needs +1 for '\0'. */ |
| 479 | (*key_size)++; |
| 480 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 481 | (*myidx)++; |
| 482 | } |
| 483 | } |
| 484 | return 0; |
| 485 | } |
| 486 | return 1; |
| 487 | } |
| 488 | |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 489 | /* 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] | 490 | * Note that the sample *is* modified and that the returned key may point |
| 491 | * 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] | 492 | * Returns NULL if the sample could not be converted (eg: no matching type), |
| 493 | * otherwise a pointer to the static stktable_key filled with what is needed |
| 494 | * for the lookup. |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 495 | */ |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 496 | struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 497 | { |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 498 | /* Convert sample. */ |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 499 | if (!sample_convert(smp, t->type)) |
Willy Tarreau | 7fc1c6e | 2012-04-26 11:03:17 +0200 | [diff] [blame] | 500 | return NULL; |
| 501 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 502 | /* Fill static_table_key. */ |
| 503 | switch (t->type) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 504 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 505 | case SMP_T_IPV4: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 506 | static_table_key->key = &smp->data.u.ipv4; |
| 507 | static_table_key->key_len = 4; |
| 508 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 509 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 510 | case SMP_T_IPV6: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 511 | static_table_key->key = &smp->data.u.ipv6; |
| 512 | static_table_key->key_len = 16; |
| 513 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 514 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 515 | case SMP_T_SINT: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 516 | /* The stick table require a 32bit unsigned int, "sint" is a |
| 517 | * signed 64 it, so we can convert it inplace. |
| 518 | */ |
| 519 | *(unsigned int *)&smp->data.u.sint = (unsigned int)smp->data.u.sint; |
| 520 | static_table_key->key = &smp->data.u.sint; |
| 521 | static_table_key->key_len = 4; |
| 522 | break; |
| 523 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 524 | case SMP_T_STR: |
Willy Tarreau | ce6955e | 2016-08-09 11:59:12 +0200 | [diff] [blame] | 525 | if (!smp_make_safe(smp)) |
| 526 | return NULL; |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 527 | static_table_key->key = smp->data.u.str.str; |
| 528 | static_table_key->key_len = smp->data.u.str.len; |
| 529 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 530 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 531 | case SMP_T_BIN: |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 532 | if (smp->data.u.str.len < t->key_size) { |
| 533 | /* This type needs padding with 0. */ |
Willy Tarreau | f65c6c0 | 2016-08-09 12:08:41 +0200 | [diff] [blame] | 534 | if (!smp_make_rw(smp)) |
| 535 | return NULL; |
| 536 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 537 | if (smp->data.u.str.size < t->key_size) |
| 538 | if (!smp_dup(smp)) |
| 539 | return NULL; |
| 540 | if (smp->data.u.str.size < t->key_size) |
| 541 | return NULL; |
| 542 | memset(smp->data.u.str.str + smp->data.u.str.len, 0, |
| 543 | t->key_size - smp->data.u.str.len); |
| 544 | smp->data.u.str.len = t->key_size; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 545 | } |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 546 | static_table_key->key = smp->data.u.str.str; |
| 547 | static_table_key->key_len = smp->data.u.str.len; |
| 548 | break; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 549 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 550 | default: /* impossible case. */ |
| 551 | return NULL; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 552 | } |
| 553 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 554 | return static_table_key; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 558 | * Process a fetch + format conversion as defined by the sample expression <expr> |
| 559 | * on request or response considering the <opt> parameter. Returns either NULL if |
| 560 | * no key could be extracted, or a pointer to the converted result stored in |
| 561 | * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset |
| 562 | * 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] | 563 | * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present |
| 564 | * without SMP_OPT_FINAL). The output will be usable like this : |
| 565 | * |
| 566 | * return MAY_CHANGE FINAL Meaning for the sample |
| 567 | * NULL 0 * Not present and will never be (eg: header) |
| 568 | * NULL 1 0 Not present or unstable, could change (eg: req_len) |
| 569 | * NULL 1 1 Not present, will not change anymore |
| 570 | * smp 0 * Present and will not change (eg: header) |
| 571 | * smp 1 0 not possible |
| 572 | * smp 1 1 Present, last known value (eg: request length) |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 573 | */ |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 574 | 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] | 575 | unsigned int opt, struct sample_expr *expr, struct sample *smp) |
| 576 | { |
| 577 | if (smp) |
| 578 | memset(smp, 0, sizeof(*smp)); |
| 579 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 580 | smp = sample_process(px, sess, strm, opt, expr, smp); |
Willy Tarreau | 8fed903 | 2014-07-03 17:02:46 +0200 | [diff] [blame] | 581 | if (!smp) |
| 582 | return NULL; |
| 583 | |
| 584 | if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
| 585 | return NULL; /* we can only use stable samples */ |
| 586 | |
| 587 | return smp_to_stkey(smp, t); |
| 588 | } |
| 589 | |
| 590 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 591 | * 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] | 592 | * type <table_type>, otherwise zero. Used in configuration check. |
| 593 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 594 | int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 595 | { |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 596 | int out_type; |
| 597 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 598 | if (table_type >= SMP_TYPES || !stktable_types[table_type].kw) |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 599 | return 0; |
| 600 | |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 601 | out_type = smp_expr_output_type(expr); |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 602 | |
Thierry FOURNIER | bc8c404 | 2015-08-10 17:53:45 +0200 | [diff] [blame] | 603 | /* Convert sample. */ |
| 604 | if (!sample_casts[out_type][table_type]) |
Thierry FOURNIER | f73eb8f | 2013-11-27 15:30:55 +0100 | [diff] [blame] | 605 | return 0; |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 606 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 607 | return 1; |
| 608 | } |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 609 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 610 | /* Extra data types processing : after the last one, some room may remain |
| 611 | * before STKTABLE_DATA_TYPES that may be used to register extra data types |
| 612 | * at run time. |
| 613 | */ |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 614 | struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES] = { |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 615 | [STKTABLE_DT_SERVER_ID] = { .name = "server_id", .std_type = STD_T_SINT }, |
Thierry FOURNIER | 3cf1111 | 2015-07-28 08:57:05 +0200 | [diff] [blame] | 616 | [STKTABLE_DT_GPT0] = { .name = "gpt0", .std_type = STD_T_UINT }, |
Willy Tarreau | 3b9c6e0 | 2010-07-18 08:04:30 +0200 | [diff] [blame] | 617 | [STKTABLE_DT_GPC0] = { .name = "gpc0", .std_type = STD_T_UINT }, |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 618 | [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] | 619 | [STKTABLE_DT_CONN_CNT] = { .name = "conn_cnt", .std_type = STD_T_UINT }, |
| 620 | [STKTABLE_DT_CONN_RATE] = { .name = "conn_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 621 | [STKTABLE_DT_CONN_CUR] = { .name = "conn_cur", .std_type = STD_T_UINT }, |
| 622 | [STKTABLE_DT_SESS_CNT] = { .name = "sess_cnt", .std_type = STD_T_UINT }, |
| 623 | [STKTABLE_DT_SESS_RATE] = { .name = "sess_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 624 | [STKTABLE_DT_HTTP_REQ_CNT] = { .name = "http_req_cnt", .std_type = STD_T_UINT }, |
| 625 | [STKTABLE_DT_HTTP_REQ_RATE] = { .name = "http_req_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 626 | [STKTABLE_DT_HTTP_ERR_CNT] = { .name = "http_err_cnt", .std_type = STD_T_UINT }, |
| 627 | [STKTABLE_DT_HTTP_ERR_RATE] = { .name = "http_err_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 628 | [STKTABLE_DT_BYTES_IN_CNT] = { .name = "bytes_in_cnt", .std_type = STD_T_ULL }, |
| 629 | [STKTABLE_DT_BYTES_IN_RATE] = { .name = "bytes_in_rate", .std_type = STD_T_FRQP, .arg_type = ARG_T_DELAY }, |
| 630 | [STKTABLE_DT_BYTES_OUT_CNT] = { .name = "bytes_out_cnt", .std_type = STD_T_ULL }, |
| 631 | [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] | 632 | }; |
| 633 | |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 634 | /* Registers stick-table extra data type with index <idx>, name <name>, type |
| 635 | * <std_type> and arg type <arg_type>. If the index is negative, the next free |
| 636 | * index is automatically allocated. The allocated index is returned, or -1 if |
| 637 | * no free index was found or <name> was already registered. The <name> is used |
| 638 | * directly as a pointer, so if it's not stable, the caller must allocate it. |
| 639 | */ |
| 640 | int stktable_register_data_store(int idx, const char *name, int std_type, int arg_type) |
| 641 | { |
| 642 | if (idx < 0) { |
| 643 | for (idx = 0; idx < STKTABLE_DATA_TYPES; idx++) { |
| 644 | if (!stktable_data_types[idx].name) |
| 645 | break; |
| 646 | |
| 647 | if (strcmp(stktable_data_types[idx].name, name) == 0) |
| 648 | return -1; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | if (idx >= STKTABLE_DATA_TYPES) |
| 653 | return -1; |
| 654 | |
| 655 | if (stktable_data_types[idx].name != NULL) |
| 656 | return -1; |
| 657 | |
| 658 | stktable_data_types[idx].name = name; |
| 659 | stktable_data_types[idx].std_type = std_type; |
| 660 | stktable_data_types[idx].arg_type = arg_type; |
| 661 | return idx; |
| 662 | } |
| 663 | |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 664 | /* |
| 665 | * Returns the data type number for the stktable_data_type whose name is <name>, |
| 666 | * or <0 if not found. |
| 667 | */ |
| 668 | int stktable_get_data_type(char *name) |
| 669 | { |
| 670 | int type; |
| 671 | |
| 672 | for (type = 0; type < STKTABLE_DATA_TYPES; type++) { |
Willy Tarreau | edee1d6 | 2014-07-15 16:44:27 +0200 | [diff] [blame] | 673 | if (!stktable_data_types[type].name) |
| 674 | continue; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 675 | if (strcmp(name, stktable_data_types[type].name) == 0) |
| 676 | return type; |
| 677 | } |
| 678 | return -1; |
| 679 | } |
| 680 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 681 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 682 | * it up into this table. Returns true if found, false otherwise. The input |
| 683 | * type is STR so that input samples are converted to string (since all types |
| 684 | * can be converted to strings), then the function casts the string again into |
| 685 | * the table's type. This is a double conversion, but in the future we might |
| 686 | * support automatic input types to perform the cast on the fly. |
| 687 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 688 | 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] | 689 | { |
| 690 | struct stktable *t; |
| 691 | struct stktable_key *key; |
| 692 | struct stksess *ts; |
| 693 | |
| 694 | t = &arg_p[0].data.prx->table; |
| 695 | |
| 696 | key = smp_to_stkey(smp, t); |
| 697 | if (!key) |
| 698 | return 0; |
| 699 | |
| 700 | ts = stktable_lookup_key(t, key); |
| 701 | |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 702 | smp->data.type = SMP_T_BOOL; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 703 | smp->data.u.sint = !!ts; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 704 | smp->flags = SMP_F_VOL_TEST; |
| 705 | return 1; |
| 706 | } |
| 707 | |
| 708 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 709 | * it up into this table. Returns the data rate received from clients in bytes/s |
| 710 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 711 | * be easily performed. If the inspected parameter is not stored in the table, |
| 712 | * <not found> is returned. |
| 713 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 714 | 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] | 715 | { |
| 716 | struct stktable *t; |
| 717 | struct stktable_key *key; |
| 718 | struct stksess *ts; |
| 719 | void *ptr; |
| 720 | |
| 721 | t = &arg_p[0].data.prx->table; |
| 722 | |
| 723 | key = smp_to_stkey(smp, t); |
| 724 | if (!key) |
| 725 | return 0; |
| 726 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 727 | ts = stktable_lookup_key(t, key); |
| 728 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 729 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 730 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 731 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 732 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 733 | if (!ts) /* key not present */ |
| 734 | return 1; |
| 735 | |
| 736 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE); |
| 737 | if (!ptr) |
| 738 | return 0; /* parameter not stored */ |
| 739 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 740 | 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] | 741 | t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
| 742 | return 1; |
| 743 | } |
| 744 | |
| 745 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 746 | * it up into this table. Returns the cumulated number of connections for the key |
| 747 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 748 | * be easily performed. If the inspected parameter is not stored in the table, |
| 749 | * <not found> is returned. |
| 750 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 751 | 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] | 752 | { |
| 753 | struct stktable *t; |
| 754 | struct stktable_key *key; |
| 755 | struct stksess *ts; |
| 756 | void *ptr; |
| 757 | |
| 758 | t = &arg_p[0].data.prx->table; |
| 759 | |
| 760 | key = smp_to_stkey(smp, t); |
| 761 | if (!key) |
| 762 | return 0; |
| 763 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 764 | ts = stktable_lookup_key(t, key); |
| 765 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 766 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 767 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 768 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 769 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 770 | if (!ts) /* key not present */ |
| 771 | return 1; |
| 772 | |
| 773 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
| 774 | if (!ptr) |
| 775 | return 0; /* parameter not stored */ |
| 776 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 777 | smp->data.u.sint = stktable_data_cast(ptr, conn_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 778 | return 1; |
| 779 | } |
| 780 | |
| 781 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 782 | * it up into this table. Returns the number of concurrent connections for the |
| 783 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 784 | * can be easily performed. If the inspected parameter is not stored in the |
| 785 | * table, <not found> is returned. |
| 786 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 787 | 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] | 788 | { |
| 789 | struct stktable *t; |
| 790 | struct stktable_key *key; |
| 791 | struct stksess *ts; |
| 792 | void *ptr; |
| 793 | |
| 794 | t = &arg_p[0].data.prx->table; |
| 795 | |
| 796 | key = smp_to_stkey(smp, t); |
| 797 | if (!key) |
| 798 | return 0; |
| 799 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 800 | ts = stktable_lookup_key(t, key); |
| 801 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 802 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 803 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 804 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 805 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 806 | if (!ts) /* key not present */ |
| 807 | return 1; |
| 808 | |
| 809 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
| 810 | if (!ptr) |
| 811 | return 0; /* parameter not stored */ |
| 812 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 813 | smp->data.u.sint = stktable_data_cast(ptr, conn_cur); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 814 | return 1; |
| 815 | } |
| 816 | |
| 817 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 818 | * it up into this table. Returns the rate of incoming connections from the key |
| 819 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 820 | * be easily performed. If the inspected parameter is not stored in the table, |
| 821 | * <not found> is returned. |
| 822 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 823 | 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] | 824 | { |
| 825 | struct stktable *t; |
| 826 | struct stktable_key *key; |
| 827 | struct stksess *ts; |
| 828 | void *ptr; |
| 829 | |
| 830 | t = &arg_p[0].data.prx->table; |
| 831 | |
| 832 | key = smp_to_stkey(smp, t); |
| 833 | if (!key) |
| 834 | return 0; |
| 835 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 836 | ts = stktable_lookup_key(t, key); |
| 837 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 838 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 839 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 840 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 841 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 842 | if (!ts) /* key not present */ |
| 843 | return 1; |
| 844 | |
| 845 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
| 846 | if (!ptr) |
| 847 | return 0; /* parameter not stored */ |
| 848 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 849 | 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] | 850 | t->data_arg[STKTABLE_DT_CONN_RATE].u); |
| 851 | return 1; |
| 852 | } |
| 853 | |
| 854 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 855 | * it up into this table. Returns the data rate sent to clients in bytes/s |
| 856 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 857 | * be easily performed. If the inspected parameter is not stored in the table, |
| 858 | * <not found> is returned. |
| 859 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 860 | 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] | 861 | { |
| 862 | struct stktable *t; |
| 863 | struct stktable_key *key; |
| 864 | struct stksess *ts; |
| 865 | void *ptr; |
| 866 | |
| 867 | t = &arg_p[0].data.prx->table; |
| 868 | |
| 869 | key = smp_to_stkey(smp, t); |
| 870 | if (!key) |
| 871 | return 0; |
| 872 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 873 | ts = stktable_lookup_key(t, key); |
| 874 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 875 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 876 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 877 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 878 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 879 | if (!ts) /* key not present */ |
| 880 | return 1; |
| 881 | |
| 882 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE); |
| 883 | if (!ptr) |
| 884 | return 0; /* parameter not stored */ |
| 885 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 886 | 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] | 887 | t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
| 888 | return 1; |
| 889 | } |
| 890 | |
| 891 | /* 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] | 892 | * it up into this table. Returns the value of the GPT0 tag for the key |
| 893 | * if the key is present in the table, otherwise false, so that comparisons can |
| 894 | * be easily performed. If the inspected parameter is not stored in the table, |
| 895 | * <not found> is returned. |
| 896 | */ |
| 897 | static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private) |
| 898 | { |
| 899 | struct stktable *t; |
| 900 | struct stktable_key *key; |
| 901 | struct stksess *ts; |
| 902 | void *ptr; |
| 903 | |
| 904 | t = &arg_p[0].data.prx->table; |
| 905 | |
| 906 | key = smp_to_stkey(smp, t); |
| 907 | if (!key) |
| 908 | return 0; |
| 909 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 910 | ts = stktable_lookup_key(t, key); |
| 911 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 912 | smp->flags = SMP_F_VOL_TEST; |
| 913 | smp->data.type = SMP_T_SINT; |
| 914 | smp->data.u.sint = 0; |
| 915 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 916 | if (!ts) /* key not present */ |
| 917 | return 1; |
| 918 | |
| 919 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0); |
| 920 | if (!ptr) |
| 921 | return 0; /* parameter not stored */ |
| 922 | |
| 923 | smp->data.u.sint = stktable_data_cast(ptr, gpt0); |
| 924 | return 1; |
| 925 | } |
| 926 | |
| 927 | /* 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] | 928 | * it up into this table. Returns the value of the GPC0 counter for the key |
| 929 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 930 | * be easily performed. If the inspected parameter is not stored in the table, |
| 931 | * <not found> is returned. |
| 932 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 933 | 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] | 934 | { |
| 935 | struct stktable *t; |
| 936 | struct stktable_key *key; |
| 937 | struct stksess *ts; |
| 938 | void *ptr; |
| 939 | |
| 940 | t = &arg_p[0].data.prx->table; |
| 941 | |
| 942 | key = smp_to_stkey(smp, t); |
| 943 | if (!key) |
| 944 | return 0; |
| 945 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 946 | ts = stktable_lookup_key(t, key); |
| 947 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 948 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 949 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 950 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 951 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 952 | if (!ts) /* key not present */ |
| 953 | return 1; |
| 954 | |
| 955 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0); |
| 956 | if (!ptr) |
| 957 | return 0; /* parameter not stored */ |
| 958 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 959 | smp->data.u.sint = stktable_data_cast(ptr, gpc0); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 960 | return 1; |
| 961 | } |
| 962 | |
| 963 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 964 | * it up into this table. Returns the event rate of the GPC0 counter for the key |
| 965 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 966 | * be easily performed. If the inspected parameter is not stored in the table, |
| 967 | * <not found> is returned. |
| 968 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 969 | 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] | 970 | { |
| 971 | struct stktable *t; |
| 972 | struct stktable_key *key; |
| 973 | struct stksess *ts; |
| 974 | void *ptr; |
| 975 | |
| 976 | t = &arg_p[0].data.prx->table; |
| 977 | |
| 978 | key = smp_to_stkey(smp, t); |
| 979 | if (!key) |
| 980 | return 0; |
| 981 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 982 | ts = stktable_lookup_key(t, key); |
| 983 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 984 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 985 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 986 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 987 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 988 | if (!ts) /* key not present */ |
| 989 | return 1; |
| 990 | |
| 991 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE); |
| 992 | if (!ptr) |
| 993 | return 0; /* parameter not stored */ |
| 994 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 995 | 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] | 996 | t->data_arg[STKTABLE_DT_GPC0_RATE].u); |
| 997 | return 1; |
| 998 | } |
| 999 | |
| 1000 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1001 | * it up into this table. Returns the cumulated number of HTTP request errors |
| 1002 | * for the key if the key is present in the table, otherwise zero, so that |
| 1003 | * comparisons can be easily performed. If the inspected parameter is not stored |
| 1004 | * in the table, <not found> is returned. |
| 1005 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1006 | 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] | 1007 | { |
| 1008 | struct stktable *t; |
| 1009 | struct stktable_key *key; |
| 1010 | struct stksess *ts; |
| 1011 | void *ptr; |
| 1012 | |
| 1013 | t = &arg_p[0].data.prx->table; |
| 1014 | |
| 1015 | key = smp_to_stkey(smp, t); |
| 1016 | if (!key) |
| 1017 | return 0; |
| 1018 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1019 | ts = stktable_lookup_key(t, key); |
| 1020 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1021 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1022 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1023 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1024 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1025 | if (!ts) /* key not present */ |
| 1026 | return 1; |
| 1027 | |
| 1028 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT); |
| 1029 | if (!ptr) |
| 1030 | return 0; /* parameter not stored */ |
| 1031 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1032 | smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1033 | return 1; |
| 1034 | } |
| 1035 | |
| 1036 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1037 | * it up into this table. Returns the HTTP request error rate the key |
| 1038 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1039 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1040 | * <not found> is returned. |
| 1041 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1042 | 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] | 1043 | { |
| 1044 | struct stktable *t; |
| 1045 | struct stktable_key *key; |
| 1046 | struct stksess *ts; |
| 1047 | void *ptr; |
| 1048 | |
| 1049 | t = &arg_p[0].data.prx->table; |
| 1050 | |
| 1051 | key = smp_to_stkey(smp, t); |
| 1052 | if (!key) |
| 1053 | return 0; |
| 1054 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1055 | ts = stktable_lookup_key(t, key); |
| 1056 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1057 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1058 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1059 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1060 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1061 | if (!ts) /* key not present */ |
| 1062 | return 1; |
| 1063 | |
| 1064 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE); |
| 1065 | if (!ptr) |
| 1066 | return 0; /* parameter not stored */ |
| 1067 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1068 | 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] | 1069 | t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
| 1070 | return 1; |
| 1071 | } |
| 1072 | |
| 1073 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1074 | * it up into this table. Returns the cumulated number of HTTP request for the |
| 1075 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1076 | * can be easily performed. If the inspected parameter is not stored in the |
| 1077 | * table, <not found> is returned. |
| 1078 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1079 | 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] | 1080 | { |
| 1081 | struct stktable *t; |
| 1082 | struct stktable_key *key; |
| 1083 | struct stksess *ts; |
| 1084 | void *ptr; |
| 1085 | |
| 1086 | t = &arg_p[0].data.prx->table; |
| 1087 | |
| 1088 | key = smp_to_stkey(smp, t); |
| 1089 | if (!key) |
| 1090 | return 0; |
| 1091 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1092 | ts = stktable_lookup_key(t, key); |
| 1093 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1094 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1095 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1096 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1097 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1098 | if (!ts) /* key not present */ |
| 1099 | return 1; |
| 1100 | |
| 1101 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT); |
| 1102 | if (!ptr) |
| 1103 | return 0; /* parameter not stored */ |
| 1104 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1105 | smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1106 | return 1; |
| 1107 | } |
| 1108 | |
| 1109 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1110 | * it up into this table. Returns the HTTP request rate the key if the key is |
| 1111 | * present in the table, otherwise zero, so that comparisons can be easily |
| 1112 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 1113 | * is returned. |
| 1114 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1115 | 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] | 1116 | { |
| 1117 | struct stktable *t; |
| 1118 | struct stktable_key *key; |
| 1119 | struct stksess *ts; |
| 1120 | void *ptr; |
| 1121 | |
| 1122 | t = &arg_p[0].data.prx->table; |
| 1123 | |
| 1124 | key = smp_to_stkey(smp, t); |
| 1125 | if (!key) |
| 1126 | return 0; |
| 1127 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1128 | ts = stktable_lookup_key(t, key); |
| 1129 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1130 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1131 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1132 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1133 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1134 | if (!ts) /* key not present */ |
| 1135 | return 1; |
| 1136 | |
| 1137 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE); |
| 1138 | if (!ptr) |
| 1139 | return 0; /* parameter not stored */ |
| 1140 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1141 | 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] | 1142 | t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
| 1143 | return 1; |
| 1144 | } |
| 1145 | |
| 1146 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1147 | * it up into this table. Returns the volume of datareceived from clients in kbytes |
| 1148 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1149 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1150 | * <not found> is returned. |
| 1151 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1152 | 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] | 1153 | { |
| 1154 | struct stktable *t; |
| 1155 | struct stktable_key *key; |
| 1156 | struct stksess *ts; |
| 1157 | void *ptr; |
| 1158 | |
| 1159 | t = &arg_p[0].data.prx->table; |
| 1160 | |
| 1161 | key = smp_to_stkey(smp, t); |
| 1162 | if (!key) |
| 1163 | return 0; |
| 1164 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1165 | ts = stktable_lookup_key(t, key); |
| 1166 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1167 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1168 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1169 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1170 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1171 | if (!ts) /* key not present */ |
| 1172 | return 1; |
| 1173 | |
| 1174 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT); |
| 1175 | if (!ptr) |
| 1176 | return 0; /* parameter not stored */ |
| 1177 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1178 | smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1179 | return 1; |
| 1180 | } |
| 1181 | |
| 1182 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1183 | * it up into this table. Returns the volume of data sent to clients in kbytes |
| 1184 | * if the key is present in the table, otherwise zero, so that comparisons can |
| 1185 | * be easily performed. If the inspected parameter is not stored in the table, |
| 1186 | * <not found> is returned. |
| 1187 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1188 | 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] | 1189 | { |
| 1190 | struct stktable *t; |
| 1191 | struct stktable_key *key; |
| 1192 | struct stksess *ts; |
| 1193 | void *ptr; |
| 1194 | |
| 1195 | t = &arg_p[0].data.prx->table; |
| 1196 | |
| 1197 | key = smp_to_stkey(smp, t); |
| 1198 | if (!key) |
| 1199 | return 0; |
| 1200 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1201 | ts = stktable_lookup_key(t, key); |
| 1202 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1203 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1204 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1205 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1206 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1207 | if (!ts) /* key not present */ |
| 1208 | return 1; |
| 1209 | |
| 1210 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT); |
| 1211 | if (!ptr) |
| 1212 | return 0; /* parameter not stored */ |
| 1213 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1214 | smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1215 | return 1; |
| 1216 | } |
| 1217 | |
| 1218 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1219 | * it up into this table. Returns the server ID associated with the key if the |
| 1220 | * key is present in the table, otherwise zero, so that comparisons can be |
| 1221 | * easily performed. If the inspected parameter is not stored in the table, |
| 1222 | * <not found> is returned. |
| 1223 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1224 | 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] | 1225 | { |
| 1226 | struct stktable *t; |
| 1227 | struct stktable_key *key; |
| 1228 | struct stksess *ts; |
| 1229 | void *ptr; |
| 1230 | |
| 1231 | t = &arg_p[0].data.prx->table; |
| 1232 | |
| 1233 | key = smp_to_stkey(smp, t); |
| 1234 | if (!key) |
| 1235 | return 0; |
| 1236 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1237 | ts = stktable_lookup_key(t, key); |
| 1238 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1239 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1240 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1241 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1242 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1243 | if (!ts) /* key not present */ |
| 1244 | return 1; |
| 1245 | |
| 1246 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID); |
| 1247 | if (!ptr) |
| 1248 | return 0; /* parameter not stored */ |
| 1249 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1250 | smp->data.u.sint = stktable_data_cast(ptr, server_id); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1251 | return 1; |
| 1252 | } |
| 1253 | |
| 1254 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1255 | * it up into this table. Returns the cumulated number of sessions for the |
| 1256 | * key if the key is present in the table, otherwise zero, so that comparisons |
| 1257 | * can be easily performed. If the inspected parameter is not stored in the |
| 1258 | * table, <not found> is returned. |
| 1259 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1260 | 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] | 1261 | { |
| 1262 | struct stktable *t; |
| 1263 | struct stktable_key *key; |
| 1264 | struct stksess *ts; |
| 1265 | void *ptr; |
| 1266 | |
| 1267 | t = &arg_p[0].data.prx->table; |
| 1268 | |
| 1269 | key = smp_to_stkey(smp, t); |
| 1270 | if (!key) |
| 1271 | return 0; |
| 1272 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1273 | ts = stktable_lookup_key(t, key); |
| 1274 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1275 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1276 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1277 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1278 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1279 | if (!ts) /* key not present */ |
| 1280 | return 1; |
| 1281 | |
| 1282 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT); |
| 1283 | if (!ptr) |
| 1284 | return 0; /* parameter not stored */ |
| 1285 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1286 | smp->data.u.sint = stktable_data_cast(ptr, sess_cnt); |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1287 | return 1; |
| 1288 | } |
| 1289 | |
| 1290 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1291 | * it up into this table. Returns the session rate the key if the key is |
| 1292 | * present in the table, otherwise zero, so that comparisons can be easily |
| 1293 | * performed. If the inspected parameter is not stored in the table, <not found> |
| 1294 | * is returned. |
| 1295 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1296 | 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] | 1297 | { |
| 1298 | struct stktable *t; |
| 1299 | struct stktable_key *key; |
| 1300 | struct stksess *ts; |
| 1301 | void *ptr; |
| 1302 | |
| 1303 | t = &arg_p[0].data.prx->table; |
| 1304 | |
| 1305 | key = smp_to_stkey(smp, t); |
| 1306 | if (!key) |
| 1307 | return 0; |
| 1308 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1309 | ts = stktable_lookup_key(t, key); |
| 1310 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1311 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1312 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1313 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1314 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1315 | if (!ts) /* key not present */ |
| 1316 | return 1; |
| 1317 | |
| 1318 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE); |
| 1319 | if (!ptr) |
| 1320 | return 0; /* parameter not stored */ |
| 1321 | |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1322 | 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] | 1323 | t->data_arg[STKTABLE_DT_SESS_RATE].u); |
| 1324 | return 1; |
| 1325 | } |
| 1326 | |
| 1327 | /* Casts sample <smp> to the type of the table specified in arg(0), and looks |
| 1328 | * it up into this table. Returns the amount of concurrent connections tracking |
| 1329 | * the same key if the key is present in the table, otherwise zero, so that |
| 1330 | * comparisons can be easily performed. If the inspected parameter is not |
| 1331 | * stored in the table, <not found> is returned. |
| 1332 | */ |
Thierry FOURNIER | 0a9a2b8 | 2015-05-11 15:20:49 +0200 | [diff] [blame] | 1333 | 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] | 1334 | { |
| 1335 | struct stktable *t; |
| 1336 | struct stktable_key *key; |
| 1337 | struct stksess *ts; |
| 1338 | |
| 1339 | t = &arg_p[0].data.prx->table; |
| 1340 | |
| 1341 | key = smp_to_stkey(smp, t); |
| 1342 | if (!key) |
| 1343 | return 0; |
| 1344 | |
Willy Tarreau | f0c730a | 2016-05-25 17:07:56 +0200 | [diff] [blame] | 1345 | ts = stktable_lookup_key(t, key); |
| 1346 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1347 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 1348 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1349 | smp->data.u.sint = 0; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1350 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1351 | if (ts) |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1352 | smp->data.u.sint = ts->ref_cnt; |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1353 | |
| 1354 | return 1; |
| 1355 | } |
| 1356 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1357 | /* Always returns 1. */ |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1358 | 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] | 1359 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1360 | { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1361 | struct stksess *ts; |
| 1362 | struct stkctr *stkctr; |
| 1363 | |
| 1364 | /* Extract the stksess, return OK if no stksess available. */ |
| 1365 | if (s) |
| 1366 | stkctr = &s->stkctr[rule->arg.gpc.sc]; |
| 1367 | else |
| 1368 | stkctr = &sess->stkctr[rule->arg.gpc.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1369 | |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1370 | ts = stkctr_entry(stkctr); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1371 | if (ts) { |
| 1372 | void *ptr1, *ptr2; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1373 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1374 | /* First, update gpc0_rate if it's tracked. Second, update its gpc0 if tracked. */ |
| 1375 | ptr1 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0_RATE); |
| 1376 | if (ptr1) |
| 1377 | update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate), |
| 1378 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1379 | |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1380 | ptr2 = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPC0); |
| 1381 | if (ptr2) |
| 1382 | stktable_data_cast(ptr2, gpc0)++; |
| 1383 | |
| 1384 | /* If data was modified, we need to touch to re-schedule sync */ |
| 1385 | if (ptr1 || ptr2) |
| 1386 | stktable_touch(stkctr->table, ts, 1); |
| 1387 | } |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1388 | return ACT_RET_CONT; |
| 1389 | } |
| 1390 | |
| 1391 | /* This function is a common parser for using variables. It understands |
| 1392 | * the formats: |
| 1393 | * |
| 1394 | * sc-inc-gpc0(<stick-table ID>) |
| 1395 | * |
| 1396 | * It returns 0 if fails and <err> is filled with an error message. Otherwise, |
| 1397 | * it returns 1 and the variable <expr> is filled with the pointer to the |
| 1398 | * expression to execute. |
| 1399 | */ |
| 1400 | static enum act_parse_ret parse_inc_gpc0(const char **args, int *arg, struct proxy *px, |
| 1401 | struct act_rule *rule, char **err) |
| 1402 | { |
| 1403 | const char *cmd_name = args[*arg-1]; |
| 1404 | char *error; |
| 1405 | |
| 1406 | cmd_name += strlen("sc-inc-gpc0"); |
| 1407 | if (*cmd_name == '\0') { |
| 1408 | /* default stick table id. */ |
| 1409 | rule->arg.gpc.sc = 0; |
| 1410 | } else { |
| 1411 | /* parse the stick table id. */ |
| 1412 | if (*cmd_name != '(') { |
| 1413 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1414 | return ACT_RET_PRS_ERR; |
| 1415 | } |
| 1416 | cmd_name++; /* jump the '(' */ |
| 1417 | rule->arg.gpc.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 1418 | if (*error != ')') { |
| 1419 | memprintf(err, "invalid stick table track ID. Expects %s(<Track ID>)", args[*arg-1]); |
| 1420 | return ACT_RET_PRS_ERR; |
| 1421 | } |
| 1422 | |
| 1423 | if (rule->arg.gpc.sc >= ACT_ACTION_TRK_SCMAX) { |
| 1424 | memprintf(err, "invalid stick table track ID. The max allowed ID is %d", |
| 1425 | ACT_ACTION_TRK_SCMAX-1); |
| 1426 | return ACT_RET_PRS_ERR; |
| 1427 | } |
| 1428 | } |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 1429 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1430 | rule->action_ptr = action_inc_gpc0; |
| 1431 | return ACT_RET_PRS_OK; |
| 1432 | } |
| 1433 | |
| 1434 | /* Always returns 1. */ |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1435 | 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] | 1436 | struct session *sess, struct stream *s, int flags) |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1437 | { |
| 1438 | void *ptr; |
| 1439 | struct stksess *ts; |
| 1440 | struct stkctr *stkctr; |
| 1441 | |
| 1442 | /* Extract the stksess, return OK if no stksess available. */ |
| 1443 | if (s) |
| 1444 | stkctr = &s->stkctr[rule->arg.gpt.sc]; |
| 1445 | else |
| 1446 | stkctr = &sess->stkctr[rule->arg.gpt.sc]; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1447 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1448 | ts = stkctr_entry(stkctr); |
| 1449 | if (!ts) |
| 1450 | return ACT_RET_CONT; |
| 1451 | |
| 1452 | /* Store the sample in the required sc, and ignore errors. */ |
| 1453 | ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0); |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1454 | if (ptr) { |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1455 | stktable_data_cast(ptr, gpt0) = rule->arg.gpt.value; |
Willy Tarreau | 79c1e91 | 2016-01-25 14:54:45 +0100 | [diff] [blame] | 1456 | stktable_touch(stkctr->table, ts, 1); |
| 1457 | } |
| 1458 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1459 | return ACT_RET_CONT; |
| 1460 | } |
| 1461 | |
| 1462 | /* This function is a common parser for using variables. It understands |
| 1463 | * the format: |
| 1464 | * |
| 1465 | * set-gpt0(<stick-table ID>) <expression> |
| 1466 | * |
| 1467 | * It returns 0 if fails and <err> is filled with an error message. Otherwise, |
| 1468 | * it returns 1 and the variable <expr> is filled with the pointer to the |
| 1469 | * expression to execute. |
| 1470 | */ |
| 1471 | static enum act_parse_ret parse_set_gpt0(const char **args, int *arg, struct proxy *px, |
| 1472 | struct act_rule *rule, char **err) |
| 1473 | |
| 1474 | |
| 1475 | { |
| 1476 | const char *cmd_name = args[*arg-1]; |
| 1477 | char *error; |
| 1478 | |
| 1479 | cmd_name += strlen("sc-set-gpt0"); |
| 1480 | if (*cmd_name == '\0') { |
| 1481 | /* default stick table id. */ |
| 1482 | rule->arg.gpt.sc = 0; |
| 1483 | } else { |
| 1484 | /* parse the stick table id. */ |
| 1485 | if (*cmd_name != '(') { |
| 1486 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 1487 | return ACT_RET_PRS_ERR; |
| 1488 | } |
| 1489 | cmd_name++; /* jump the '(' */ |
| 1490 | rule->arg.gpt.sc = strtol(cmd_name, &error, 10); /* Convert stick table id. */ |
| 1491 | if (*error != ')') { |
| 1492 | memprintf(err, "invalid stick table track ID '%s'. Expects sc-set-gpt0(<Track ID>)", args[*arg-1]); |
| 1493 | return ACT_RET_PRS_ERR; |
| 1494 | } |
| 1495 | |
| 1496 | if (rule->arg.gpt.sc >= ACT_ACTION_TRK_SCMAX) { |
| 1497 | memprintf(err, "invalid stick table track ID '%s'. The max allowed ID is %d", |
| 1498 | args[*arg-1], ACT_ACTION_TRK_SCMAX-1); |
| 1499 | return ACT_RET_PRS_ERR; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | rule->arg.gpt.value = strtol(args[*arg], &error, 10); |
| 1504 | if (*error != '\0') { |
| 1505 | memprintf(err, "invalid integer value '%s'", args[*arg]); |
| 1506 | return ACT_RET_PRS_ERR; |
| 1507 | } |
| 1508 | (*arg)++; |
| 1509 | |
Thierry FOURNIER | 4214873 | 2015-09-02 17:17:33 +0200 | [diff] [blame] | 1510 | rule->action = ACT_CUSTOM; |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1511 | rule->action_ptr = action_set_gpt0; |
| 1512 | |
| 1513 | return ACT_RET_PRS_OK; |
| 1514 | } |
| 1515 | |
| 1516 | static struct action_kw_list tcp_conn_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1517 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1518 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 1519 | { /* END */ } |
| 1520 | }}; |
| 1521 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 1522 | static struct action_kw_list tcp_sess_kws = { { }, { |
| 1523 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
| 1524 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 1525 | { /* END */ } |
| 1526 | }}; |
| 1527 | |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1528 | static struct action_kw_list tcp_req_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1529 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1530 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 1531 | { /* END */ } |
| 1532 | }}; |
| 1533 | |
| 1534 | static struct action_kw_list tcp_res_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1535 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1536 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 1537 | { /* END */ } |
| 1538 | }}; |
| 1539 | |
| 1540 | static struct action_kw_list http_req_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1541 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1542 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 1543 | { /* END */ } |
| 1544 | }}; |
| 1545 | |
| 1546 | static struct action_kw_list http_res_kws = { { }, { |
Thierry FOURNIER | e0627bd | 2015-08-04 08:20:33 +0200 | [diff] [blame] | 1547 | { "sc-inc-gpc0", parse_inc_gpc0, 1 }, |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1548 | { "sc-set-gpt0", parse_set_gpt0, 1 }, |
| 1549 | { /* END */ } |
| 1550 | }}; |
| 1551 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1552 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 1553 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 2d17db5 | 2016-05-25 17:16:38 +0200 | [diff] [blame] | 1554 | { "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_BOOL }, |
| 1555 | { "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1556 | { "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1557 | { "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1558 | { "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1559 | { "table_conn_rate", sample_conv_table_conn_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1560 | { "table_gpt0", sample_conv_table_gpt0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1561 | { "table_gpc0", sample_conv_table_gpc0, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1562 | { "table_gpc0_rate", sample_conv_table_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1563 | { "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1564 | { "table_http_err_rate", sample_conv_table_http_err_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1565 | { "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1566 | { "table_http_req_rate", sample_conv_table_http_req_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1567 | { "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1568 | { "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1569 | { "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1570 | { "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1571 | { "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_ANY, SMP_T_SINT }, |
| 1572 | { "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] | 1573 | { /* END */ }, |
| 1574 | }}; |
| 1575 | |
| 1576 | __attribute__((constructor)) |
| 1577 | static void __stick_table_init(void) |
| 1578 | { |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1579 | /* register som action keywords. */ |
| 1580 | tcp_req_conn_keywords_register(&tcp_conn_kws); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 1581 | tcp_req_sess_keywords_register(&tcp_sess_kws); |
Thierry FOURNIER | 236657b | 2015-08-19 08:25:14 +0200 | [diff] [blame] | 1582 | tcp_req_cont_keywords_register(&tcp_req_kws); |
| 1583 | tcp_res_cont_keywords_register(&tcp_res_kws); |
| 1584 | http_req_keywords_register(&http_req_kws); |
| 1585 | http_res_keywords_register(&http_res_kws); |
| 1586 | |
Willy Tarreau | d9f316a | 2014-07-10 14:03:38 +0200 | [diff] [blame] | 1587 | /* register sample fetch and format conversion keywords */ |
| 1588 | sample_register_convs(&sample_conv_kws); |
| 1589 | } |