blob: db45760f251fc24e6da4c4d7bb3912177eb0c7e5 [file] [log] [blame]
Emeric Brun3bd697e2010-01-04 15:23:48 +01001/*
2 * include/proto/stick_table.h
3 * Functions for stick tables management.
4 *
5 * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
Willy Tarreau08d5f982010-06-06 13:34:54 +02006 * Copyright (C) 2010 Willy Tarreau <w@1wt.eu>
Emeric Brun3bd697e2010-01-04 15:23:48 +01007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef _PROTO_STICK_TABLE_H
24#define _PROTO_STICK_TABLE_H
25
26#include <types/stick_table.h>
27
Willy Tarreau68129b92010-06-06 16:06:52 +020028#define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type))
29#define stktable_data_cast(ptr, type) ((union stktable_data*)(ptr))->type
30
Willy Tarreau41883e22010-06-06 17:39:30 +020031extern struct stktable_key static_table_key;
32
Emeric Brun3bd697e2010-01-04 15:23:48 +010033struct stksess *stksess_new(struct stktable *t, struct stktable_key *key);
Willy Tarreau393379c2010-06-06 12:11:37 +020034void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key);
Emeric Brun3bd697e2010-01-04 15:23:48 +010035void stksess_free(struct stktable *t, struct stksess *ts);
36
37int stktable_init(struct stktable *t);
38int stktable_parse_type(char **args, int *idx, unsigned long *type, size_t *key_size);
Willy Tarreauf16d2b82010-06-06 15:38:59 +020039struct stksess *stktable_store(struct stktable *t, struct stksess *ts);
Willy Tarreaucb183642010-06-06 17:58:34 +020040struct stksess *stktable_touch(struct stktable *t, struct stksess *ts);
Willy Tarreauf16d2b82010-06-06 15:38:59 +020041struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts);
42struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key);
Willy Tarreauf0b38bf2010-06-06 13:22:23 +020043struct stktable_key *stktable_fetch_key(struct proxy *px, struct session *l4,
44 void *l7, int dir, struct pattern_expr *expr,
45 unsigned long table_type);
46int stktable_compatible_pattern(struct pattern_expr *expr, unsigned long table_type);
Willy Tarreau08d5f982010-06-06 13:34:54 +020047int stktable_get_data_type(char *name);
48
49/* reserve some space for data type <type>. Return non-0 if OK, or 0 if already
50 * allocated (or impossible type).
51 */
52static inline int stktable_alloc_data_type(struct stktable *t, int type)
53{
54 if (type >= STKTABLE_DATA_TYPES)
55 return 0;
56
57 if (t->data_ofs[type])
58 /* already allocated */
59 return 0;
Emeric Brun3bd697e2010-01-04 15:23:48 +010060
Willy Tarreau08d5f982010-06-06 13:34:54 +020061 t->data_size += stktable_data_types[type].data_length;
62 t->data_ofs[type] = -t->data_size;
63 return 1;
64}
Emeric Brun3bd697e2010-01-04 15:23:48 +010065
Willy Tarreau68129b92010-06-06 16:06:52 +020066/* return pointer for data type <type> in sticky session <ts> of table <t>, or
67 * NULL if either <ts> is NULL or the type is not stored.
68 */
69static inline void *stktable_data_ptr(struct stktable *t, struct stksess *ts, int type)
70{
71 if (type >= STKTABLE_DATA_TYPES)
72 return NULL;
73
74 if (!t->data_ofs[type]) /* type not stored */
75 return NULL;
76
77 if (!ts)
78 return NULL;
79
80 return (void *)ts + t->data_ofs[type];
81}
82
Emeric Brun3bd697e2010-01-04 15:23:48 +010083#endif /* _PROTO_STICK_TABLE_H */