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
|
|
|
|
|
2010-06-20 07:11:39 +00:00
|
|
|
#include <common/errors.h>
|
2010-08-03 18:34:06 +00:00
|
|
|
#include <common/ticks.h>
|
|
|
|
#include <common/time.h>
|
2010-01-04 14:23:48 +00:00
|
|
|
#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
|
|
|
|
|
2012-10-29 20:56:59 +00:00
|
|
|
extern struct stktable_key *static_table_key;
|
2010-06-06 15:39:30 +00:00
|
|
|
|
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);
|
2010-08-03 18:34:06 +00:00
|
|
|
void stksess_kill(struct stktable *t, struct stksess *ts);
|
2010-01-04 14:23:48 +00:00
|
|
|
|
|
|
|
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-09-23 16:16:52 +00:00
|
|
|
struct stksess *stktable_store(struct stktable *t, struct stksess *ts, int local);
|
|
|
|
struct stksess *stktable_touch(struct stktable *t, struct stksess *ts, int local);
|
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-20 10:27:21 +00:00
|
|
|
struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key);
|
2014-07-03 15:02:46 +00:00
|
|
|
struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t);
|
2010-09-23 16:02:19 +00:00
|
|
|
struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px,
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
struct stream *l4, void *l7, unsigned int opt,
|
2014-06-25 14:20:53 +00:00
|
|
|
struct sample_expr *expr, struct sample *smp);
|
2012-04-27 19:37:17 +00:00
|
|
|
int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type);
|
2014-07-15 14:44:27 +00:00
|
|
|
int stktable_register_data_store(int idx, const char *name, int std_type, int arg_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);
|
2013-09-04 15:54:01 +00:00
|
|
|
int stktable_trash_oldest(struct stktable *t, int to_batch);
|
2010-01-04 14:23:48 +00:00
|
|
|
|
2010-07-18 06:04:30 +00:00
|
|
|
/* return allocation size for standard data type <type> */
|
|
|
|
static inline int stktable_type_size(int type)
|
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case STD_T_SINT:
|
|
|
|
case STD_T_UINT:
|
|
|
|
return sizeof(int);
|
|
|
|
case STD_T_ULL:
|
|
|
|
return sizeof(unsigned long long);
|
|
|
|
case STD_T_FRQP:
|
|
|
|
return sizeof(struct freq_ctr_period);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-20 07:11:39 +00:00
|
|
|
/* reserve some space for data type <type>, and associate argument at <sa> if
|
|
|
|
* not NULL. Returns PE_NONE (0) if OK or an error code among :
|
|
|
|
* - PE_ENUM_OOR if <type> does not exist
|
|
|
|
* - PE_EXIST if <type> is already registered
|
2010-06-20 08:41:54 +00:00
|
|
|
* - PE_ARG_NOT_USE if <sa> was provided but not expected
|
|
|
|
* - PE_ARG_MISSING if <sa> was expected but not provided
|
2010-06-06 11:34:54 +00:00
|
|
|
*/
|
2010-06-20 07:11:39 +00:00
|
|
|
static inline int stktable_alloc_data_type(struct stktable *t, int type, const char *sa)
|
2010-06-06 11:34:54 +00:00
|
|
|
{
|
|
|
|
if (type >= STKTABLE_DATA_TYPES)
|
2010-06-20 07:11:39 +00:00
|
|
|
return PE_ENUM_OOR;
|
2010-06-06 11:34:54 +00:00
|
|
|
|
|
|
|
if (t->data_ofs[type])
|
|
|
|
/* already allocated */
|
2010-06-20 07:11:39 +00:00
|
|
|
return PE_EXIST;
|
2010-06-06 11:34:54 +00:00
|
|
|
|
2010-06-20 08:41:54 +00:00
|
|
|
switch (stktable_data_types[type].arg_type) {
|
|
|
|
case ARG_T_NONE:
|
|
|
|
if (sa)
|
|
|
|
return PE_ARG_NOT_USED;
|
|
|
|
break;
|
|
|
|
case ARG_T_INT:
|
|
|
|
if (!sa)
|
|
|
|
return PE_ARG_MISSING;
|
|
|
|
t->data_arg[type].i = atoi(sa);
|
|
|
|
break;
|
|
|
|
case ARG_T_DELAY:
|
|
|
|
if (!sa)
|
|
|
|
return PE_ARG_MISSING;
|
|
|
|
sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS);
|
|
|
|
if (sa)
|
|
|
|
return PE_ARG_INVC; /* invalid char */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-18 06:04:30 +00:00
|
|
|
t->data_size += stktable_type_size(stktable_data_types[type].std_type);
|
2010-06-06 11:34:54 +00:00
|
|
|
t->data_ofs[type] = -t->data_size;
|
2010-06-20 07:11:39 +00:00
|
|
|
return PE_NONE;
|
2010-06-06 11:34:54 +00:00
|
|
|
}
|
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-08-03 18:34:06 +00:00
|
|
|
/* kill an entry if it's expired and its ref_cnt is zero */
|
|
|
|
static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *ts)
|
|
|
|
{
|
2010-09-23 16:11:05 +00:00
|
|
|
if (t->expire != TICK_ETERNITY && tick_is_expired(ts->expire, now_ms))
|
2010-08-03 18:34:06 +00:00
|
|
|
stksess_kill(t, ts);
|
|
|
|
}
|
|
|
|
|
2010-01-04 14:23:48 +00:00
|
|
|
#endif /* _PROTO_STICK_TABLE_H */
|