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