Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * include/types/stick_table.h |
| 3 | * Macros, variables and structures for stick tables management. |
| 4 | * |
| 5 | * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _TYPES_STICK_TABLE_H |
| 23 | #define _TYPES_STICK_TABLE_H |
| 24 | |
| 25 | #include <sys/socket.h> |
| 26 | #include <netinet/in.h> |
| 27 | |
| 28 | #include <ebtree.h> |
| 29 | #include <ebmbtree.h> |
| 30 | #include <eb32tree.h> |
| 31 | #include <common/memory.h> |
| 32 | |
| 33 | /* stick table key types */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 34 | enum { |
| 35 | STKTABLE_TYPE_IP = 0, /* table key is ipv4 */ |
| 36 | STKTABLE_TYPE_INTEGER, /* table key is unsigned 32bit integer */ |
| 37 | STKTABLE_TYPE_STRING, /* table key is a null terminated string */ |
| 38 | STKTABLE_TYPES /* Number of types, must always be last */ |
| 39 | }; |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 40 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 41 | /* stick table key type flags */ |
| 42 | #define STK_F_CUSTOM_KEYSIZE 0x00000001 /* this table's key size is configurable */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 43 | |
| 44 | /* stick table keyword type */ |
| 45 | struct stktable_type { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 46 | const char *kw; /* keyword string */ |
| 47 | int flags; /* type flags */ |
| 48 | size_t default_size; /* default key size */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 51 | /* Sticky session. |
| 52 | * Any additional data related to the stuck session is installed *before* |
| 53 | * stksess (with negative offsets). This allows us to run variable-sized |
| 54 | * keys and variable-sized data without making use of intermediate pointers. |
| 55 | */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 56 | struct stksess { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 57 | int sid; /* id of server to use for this session */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 58 | unsigned int expire; /* session expiration date */ |
Willy Tarreau | 86257dc | 2010-06-06 12:57:10 +0200 | [diff] [blame^] | 59 | struct eb32_node exp; /* ebtree node used to hold the session in expiration tree */ |
| 60 | struct ebmb_node key; /* ebtree node used to hold the session in table */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 61 | /* WARNING! do not put anything after <keys>, it's used by the key */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 64 | /* stick table */ |
| 65 | struct stktable { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 66 | struct eb_root keys; /* head of sticky session tree */ |
| 67 | struct eb_root exps; /* head of sticky session expiration tree */ |
| 68 | struct pool_head *pool; /* pool used to allocate sticky sessions */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 69 | struct task *exp_task; /* expiration task */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 70 | unsigned long type; /* type of table (determines key format) */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 71 | size_t key_size; /* size of a key, maximum size in case of string */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 72 | unsigned int size; /* maximum number of sticky sessions in table */ |
| 73 | unsigned int current; /* number of sticky sessions currently in table */ |
| 74 | int nopurge; /* if non-zero, don't purge sticky sessions when full */ |
| 75 | int exp_next; /* next expiration date (ticks) */ |
| 76 | int expire; /* time to live for sticky sessions (milliseconds) */ |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 77 | int data_size; /* the size of the data that is prepended *before* stksess */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 78 | }; |
| 79 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 80 | /*** The definitions below should probably be better placed in pattern.h ***/ |
| 81 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 82 | /* stick table key data */ |
| 83 | union stktable_key_data { |
| 84 | struct in_addr ip; /* used to store an ip key */ |
| 85 | uint32_t integer; /* used to store an integer key */ |
| 86 | char buf[BUFSIZE]; /* used to store a null terminated string key */ |
| 87 | }; |
| 88 | |
| 89 | /* stick table key */ |
| 90 | struct stktable_key { |
| 91 | void *key; /* pointer on key buffer */ |
| 92 | size_t key_len; /* data len to read in buff in case of null terminated string */ |
| 93 | union stktable_key_data data; /* data */ |
| 94 | }; |
| 95 | |
| 96 | #endif /* _TYPES_STICK_TABLE_H */ |
| 97 | |