blob: b63b790e7a48d7bd6ceaceb6b9d1653ab7c310a6 [file] [log] [blame]
Emeric Brun3bd697e2010-01-04 15:23:48 +01001/*
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 Tarreauaea940e2010-06-06 11:56:36 +020034enum {
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 Brun3bd697e2010-01-04 15:23:48 +010040
Willy Tarreauaea940e2010-06-06 11:56:36 +020041/* stick table key type flags */
42#define STK_F_CUSTOM_KEYSIZE 0x00000001 /* this table's key size is configurable */
Emeric Brun3bd697e2010-01-04 15:23:48 +010043
44/* stick table keyword type */
45struct stktable_type {
Willy Tarreauaea940e2010-06-06 11:56:36 +020046 const char *kw; /* keyword string */
47 int flags; /* type flags */
48 size_t default_size; /* default key size */
Emeric Brun3bd697e2010-01-04 15:23:48 +010049};
50
Willy Tarreauaea940e2010-06-06 11:56:36 +020051/* sticky session */
Emeric Brun3bd697e2010-01-04 15:23:48 +010052struct stksess {
Willy Tarreauaea940e2010-06-06 11:56:36 +020053 int sid; /* id of server to use for this session */
Emeric Brun3bd697e2010-01-04 15:23:48 +010054 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 Tarreauaea940e2010-06-06 11:56:36 +020057 /* WARNING! do not put anything after <keys>, it's used by the key */
Emeric Brun3bd697e2010-01-04 15:23:48 +010058};
59
Emeric Brun3bd697e2010-01-04 15:23:48 +010060/* stick table */
61struct stktable {
Willy Tarreauaea940e2010-06-06 11:56:36 +020062 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 Brun3bd697e2010-01-04 15:23:48 +010065 struct task *exp_task; /* expiration task */
Willy Tarreauaea940e2010-06-06 11:56:36 +020066 unsigned long type; /* type of table (determines key format) */
Emeric Brun3bd697e2010-01-04 15:23:48 +010067 size_t key_size; /* size of a key, maximum size in case of string */
Willy Tarreauaea940e2010-06-06 11:56:36 +020068 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 Brun3bd697e2010-01-04 15:23:48 +010073};
74
Willy Tarreauaea940e2010-06-06 11:56:36 +020075/*** The definitions below should probably be better placed in pattern.h ***/
76
Emeric Brun3bd697e2010-01-04 15:23:48 +010077/* stick table key data */
78union 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 */
85struct 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