blob: bbb9d0d0f6c95680cfcdd14c13ec31ecd745a029 [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 Tarreau393379c2010-06-06 12:11:37 +020051/* 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 Brun3bd697e2010-01-04 15:23:48 +010056struct stksess {
Willy Tarreauaea940e2010-06-06 11:56:36 +020057 int sid; /* id of server to use for this session */
Emeric Brun3bd697e2010-01-04 15:23:48 +010058 unsigned int expire; /* session expiration date */
59 struct eb32_node exps; /* ebtree node used to hold the session in expiration tree */
60 struct ebmb_node keys; /* ebtree node used to hold the session in table */
Willy Tarreauaea940e2010-06-06 11:56:36 +020061 /* WARNING! do not put anything after <keys>, it's used by the key */
Emeric Brun3bd697e2010-01-04 15:23:48 +010062};
63
Emeric Brun3bd697e2010-01-04 15:23:48 +010064/* stick table */
65struct stktable {
Willy Tarreauaea940e2010-06-06 11:56:36 +020066 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 Brun3bd697e2010-01-04 15:23:48 +010069 struct task *exp_task; /* expiration task */
Willy Tarreauaea940e2010-06-06 11:56:36 +020070 unsigned long type; /* type of table (determines key format) */
Emeric Brun3bd697e2010-01-04 15:23:48 +010071 size_t key_size; /* size of a key, maximum size in case of string */
Willy Tarreauaea940e2010-06-06 11:56:36 +020072 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 Tarreau393379c2010-06-06 12:11:37 +020077 int data_size; /* the size of the data that is prepended *before* stksess */
Emeric Brun3bd697e2010-01-04 15:23:48 +010078};
79
Willy Tarreauaea940e2010-06-06 11:56:36 +020080/*** The definitions below should probably be better placed in pattern.h ***/
81
Emeric Brun3bd697e2010-01-04 15:23:48 +010082/* stick table key data */
83union 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 */
90struct 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