2010-01-04 14:23:48 +00:00
|
|
|
/*
|
|
|
|
* include/proto/stick_table.h
|
|
|
|
* Functions for stick tables management.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
|
2010-06-06 11:34:54 +00:00
|
|
|
* Copyright (C) 2010 Willy Tarreau <w@1wt.eu>
|
2010-01-04 14:23:48 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
* exclusively.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PROTO_STICK_TABLE_H
|
|
|
|
#define _PROTO_STICK_TABLE_H
|
|
|
|
|
|
|
|
#include <types/stick_table.h>
|
|
|
|
|
2010-06-06 14:06:52 +00:00
|
|
|
#define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type))
|
|
|
|
#define stktable_data_cast(ptr, type) ((union stktable_data*)(ptr))->type
|
|
|
|
|
2010-06-06 15:39:30 +00:00
|
|
|
extern struct stktable_key static_table_key;
|
|
|
|
|
2010-01-04 14:23:48 +00:00
|
|
|
struct stksess *stksess_new(struct stktable *t, struct stktable_key *key);
|
2010-06-06 10:11:37 +00:00
|
|
|
void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key);
|
2010-01-04 14:23:48 +00:00
|
|
|
void stksess_free(struct stktable *t, struct stksess *ts);
|
|
|
|
|
|
|
|
int stktable_init(struct stktable *t);
|
|
|
|
int stktable_parse_type(char **args, int *idx, unsigned long *type, size_t *key_size);
|
2010-06-14 19:04:55 +00:00
|
|
|
struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key);
|
2010-06-06 13:38:59 +00:00
|
|
|
struct stksess *stktable_store(struct stktable *t, struct stksess *ts);
|
2010-06-06 15:58:34 +00:00
|
|
|
struct stksess *stktable_touch(struct stktable *t, struct stksess *ts);
|
2010-06-06 13:38:59 +00:00
|
|
|
struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts);
|
|
|
|
struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key);
|
2010-06-06 11:22:23 +00:00
|
|
|
struct stktable_key *stktable_fetch_key(struct proxy *px, struct session *l4,
|
|
|
|
void *l7, int dir, struct pattern_expr *expr,
|
|
|
|
unsigned long table_type);
|
|
|
|
int stktable_compatible_pattern(struct pattern_expr *expr, unsigned long table_type);
|
2010-06-06 11:34:54 +00:00
|
|
|
int stktable_get_data_type(char *name);
|
2010-06-18 15:26:50 +00:00
|
|
|
struct proxy *find_stktable(const char *name);
|
2010-01-04 14:23:48 +00:00
|
|
|
|
2010-06-06 11:34:54 +00:00
|
|
|
/* reserve some space for data type <type>. Return non-0 if OK, or 0 if already
|
|
|
|
* allocated (or impossible type).
|
|
|
|
*/
|
|
|
|
static inline int stktable_alloc_data_type(struct stktable *t, int type)
|
|
|
|
{
|
|
|
|
if (type >= STKTABLE_DATA_TYPES)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (t->data_ofs[type])
|
|
|
|
/* already allocated */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
t->data_size += stktable_data_types[type].data_length;
|
|
|
|
t->data_ofs[type] = -t->data_size;
|
|
|
|
return 1;
|
|
|
|
}
|
2010-01-04 14:23:48 +00:00
|
|
|
|
2010-06-06 14:06:52 +00:00
|
|
|
/* return pointer for data type <type> in sticky session <ts> of table <t>, or
|
|
|
|
* NULL if either <ts> is NULL or the type is not stored.
|
|
|
|
*/
|
|
|
|
static inline void *stktable_data_ptr(struct stktable *t, struct stksess *ts, int type)
|
|
|
|
{
|
|
|
|
if (type >= STKTABLE_DATA_TYPES)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!t->data_ofs[type]) /* type not stored */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!ts)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (void *)ts + t->data_ofs[type];
|
|
|
|
}
|
|
|
|
|
2010-01-04 14:23:48 +00:00
|
|
|
#endif /* _PROTO_STICK_TABLE_H */
|