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