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 */ |
| 34 | #define STKTABLE_TYPE_IP 0 /* table key is ipv4 */ |
| 35 | #define STKTABLE_TYPE_INTEGER 1 /* table key is unsigned 32bit integer */ |
| 36 | #define STKTABLE_TYPE_STRING 2 /* table key is a null terminated string */ |
| 37 | |
| 38 | #define STKTABLE_TYPES 3 /* Increase this value if you add a type */ |
| 39 | |
| 40 | /* stick table type flags */ |
| 41 | #define STKTABLE_TYPEFLAG_CUSTOMKEYSIZE 0x00000001 /* this table type maxsize is configurable */ |
| 42 | |
| 43 | /* stick table keyword type */ |
| 44 | struct stktable_type { |
| 45 | const char *kw; /* keyword string */ |
| 46 | int flags; /* type flags */ |
| 47 | size_t default_size; /* default key size */ |
| 48 | }; |
| 49 | |
| 50 | /* stuck session */ |
| 51 | struct stksess { |
| 52 | int sid; /* id of server to use for session */ |
| 53 | unsigned int expire; /* session expiration date */ |
| 54 | struct eb32_node exps; /* ebtree node used to hold the session in expiration tree */ |
| 55 | struct ebmb_node keys; /* ebtree node used to hold the session in table */ |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | /* stick table */ |
| 60 | struct stktable { |
| 61 | struct eb_root keys; /* head of stuck session tree */ |
| 62 | struct eb_root exps; /* head of stuck session expiration tree */ |
| 63 | struct pool_head *pool; /* pool used to allocate stuck sessions */ |
| 64 | struct task *exp_task; /* expiration task */ |
| 65 | unsigned long type; /* type of table (determine key format) */ |
| 66 | size_t key_size; /* size of a key, maximum size in case of string */ |
| 67 | unsigned int size; /* maximum stuck session in table */ |
| 68 | unsigned int current; /* number of stuck session in table */ |
| 69 | int nopurge; /* 1 never purge stuck sessions */ |
| 70 | int exp_next; /* next epiration date */ |
| 71 | int expire; /* duration before expiration of stuck session */ |
| 72 | }; |
| 73 | |
| 74 | /* stick table key data */ |
| 75 | union stktable_key_data { |
| 76 | struct in_addr ip; /* used to store an ip key */ |
| 77 | uint32_t integer; /* used to store an integer key */ |
| 78 | char buf[BUFSIZE]; /* used to store a null terminated string key */ |
| 79 | }; |
| 80 | |
| 81 | /* stick table key */ |
| 82 | struct stktable_key { |
| 83 | void *key; /* pointer on key buffer */ |
| 84 | size_t key_len; /* data len to read in buff in case of null terminated string */ |
| 85 | union stktable_key_data data; /* data */ |
| 86 | }; |
| 87 | |
| 88 | #endif /* _TYPES_STICK_TABLE_H */ |
| 89 | |