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