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 | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 51 | /* sticky session */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 52 | struct stksess { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 53 | int sid; /* id of server to use for this session */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 54 | unsigned int expire; /* session expiration date */ |
| 55 | struct eb32_node exps; /* ebtree node used to hold the session in expiration tree */ |
| 56 | struct ebmb_node keys; /* ebtree node used to hold the session in table */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 57 | /* 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] | 58 | }; |
| 59 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 60 | /* stick table */ |
| 61 | struct stktable { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 62 | struct eb_root keys; /* head of sticky session tree */ |
| 63 | struct eb_root exps; /* head of sticky session expiration tree */ |
| 64 | struct pool_head *pool; /* pool used to allocate sticky sessions */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 65 | struct task *exp_task; /* expiration task */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 66 | unsigned long type; /* type of table (determines key format) */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 67 | 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] | 68 | unsigned int size; /* maximum number of sticky sessions in table */ |
| 69 | unsigned int current; /* number of sticky sessions currently in table */ |
| 70 | int nopurge; /* if non-zero, don't purge sticky sessions when full */ |
| 71 | int exp_next; /* next expiration date (ticks) */ |
| 72 | int expire; /* time to live for sticky sessions (milliseconds) */ |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 75 | /*** The definitions below should probably be better placed in pattern.h ***/ |
| 76 | |
Emeric Brun | 3bd697e | 2010-01-04 15:23:48 +0100 | [diff] [blame] | 77 | /* stick table key data */ |
| 78 | union stktable_key_data { |
| 79 | struct in_addr ip; /* used to store an ip key */ |
| 80 | uint32_t integer; /* used to store an integer key */ |
| 81 | char buf[BUFSIZE]; /* used to store a null terminated string key */ |
| 82 | }; |
| 83 | |
| 84 | /* stick table key */ |
| 85 | struct stktable_key { |
| 86 | void *key; /* pointer on key buffer */ |
| 87 | size_t key_len; /* data len to read in buff in case of null terminated string */ |
| 88 | union stktable_key_data data; /* data */ |
| 89 | }; |
| 90 | |
| 91 | #endif /* _TYPES_STICK_TABLE_H */ |
| 92 | |