29
30
#include <ebmbtree.h>
30
31
#include <eb32tree.h>
31
32
#include <common/memory.h>
33
#include <types/freq_ctr.h>
33
35
/* stick table key types */
34
#define STKTABLE_TYPE_IP 0 /* table key is ipv4 */
35
#define STKTABLE_TYPE_INTEGER 1 /* table key is unsigned 32bit integer */
36
#define STKTABLE_TYPE_STRING 2 /* table key is a null terminated string */
38
#define STKTABLE_TYPES 3 /* Increase this value if you add a type */
40
/* stick table type flags */
41
#define STKTABLE_TYPEFLAG_CUSTOMKEYSIZE 0x00000001 /* this table type maxsize is configurable */
37
STKTABLE_TYPE_IP = 0, /* table key is ipv4 */
38
STKTABLE_TYPE_IPV6, /* table key is ipv6 */
39
STKTABLE_TYPE_INTEGER, /* table key is unsigned 32bit integer */
40
STKTABLE_TYPE_STRING, /* table key is a null terminated string */
41
STKTABLE_TYPE_BINARY, /* table key is a buffer of data */
42
STKTABLE_TYPES /* Number of types, must always be last */
45
/* The types of extra data we can store in a stick table */
47
STKTABLE_DT_SERVER_ID, /* the server ID to use with this session if > 0 */
48
STKTABLE_DT_GPC0, /* General Purpose Counter 0 (unsigned 32-bit integer) */
49
STKTABLE_DT_GPC0_RATE, /* General Purpose Counter 0's event rate */
50
STKTABLE_DT_CONN_CNT, /* cumulated number of connections */
51
STKTABLE_DT_CONN_RATE, /* incoming connection rate */
52
STKTABLE_DT_CONN_CUR, /* concurrent number of connections */
53
STKTABLE_DT_SESS_CNT, /* cumulated number of sessions (accepted connections) */
54
STKTABLE_DT_SESS_RATE, /* accepted sessions rate */
55
STKTABLE_DT_HTTP_REQ_CNT, /* cumulated number of incoming HTTP requests */
56
STKTABLE_DT_HTTP_REQ_RATE,/* incoming HTTP request rate */
57
STKTABLE_DT_HTTP_ERR_CNT, /* cumulated number of HTTP requests errors (4xx) */
58
STKTABLE_DT_HTTP_ERR_RATE,/* HTTP request error rate */
59
STKTABLE_DT_BYTES_IN_CNT, /* cumulated bytes count from client to servers */
60
STKTABLE_DT_BYTES_IN_RATE,/* bytes rate from client to servers */
61
STKTABLE_DT_BYTES_OUT_CNT,/* cumulated bytes count from servers to client */
62
STKTABLE_DT_BYTES_OUT_RATE,/* bytes rate from servers to client */
63
STKTABLE_DATA_TYPES /* Number of data types, must always be last */
66
/* The equivalent standard types of the stored data */
68
STD_T_SINT = 0, /* data is of type signed int */
69
STD_T_UINT, /* data is of type unsigned int */
70
STD_T_ULL, /* data is of type unsigned long long */
71
STD_T_FRQP, /* data is of type freq_ctr_period */
74
/* The types of optional arguments to stored data */
76
ARG_T_NONE = 0, /* data type takes no argument (default) */
77
ARG_T_INT, /* signed integer */
78
ARG_T_DELAY, /* a delay which supports time units */
81
/* stick_table extra data. This is mainly used for casting or size computation */
83
/* standard types for easy casting */
85
unsigned int std_t_uint;
86
unsigned long long std_t_ull;
87
struct freq_ctr_period std_t_frqp;
89
/* types of each storable data */
92
struct freq_ctr_period gpc0_rate;
93
unsigned int conn_cnt;
94
struct freq_ctr_period conn_rate;
95
unsigned int conn_cur;
96
unsigned int sess_cnt;
97
struct freq_ctr_period sess_rate;
98
unsigned int http_req_cnt;
99
struct freq_ctr_period http_req_rate;
100
unsigned int http_err_cnt;
101
struct freq_ctr_period http_err_rate;
102
unsigned long long bytes_in_cnt;
103
struct freq_ctr_period bytes_in_rate;
104
unsigned long long bytes_out_cnt;
105
struct freq_ctr_period bytes_out_rate;
108
/* known data types */
109
struct stktable_data_type {
110
const char *name; /* name of the data type */
111
int std_type; /* standard type we can use for this data, STD_T_* */
112
int arg_type; /* type of optional argument, ARG_T_* */
115
/* stick table key type flags */
116
#define STK_F_CUSTOM_KEYSIZE 0x00000001 /* this table's key size is configurable */
43
118
/* stick table keyword type */
44
119
struct stktable_type {
45
const char *kw; /* keyword string */
46
int flags; /* type flags */
47
size_t default_size; /* default key size */
120
const char *kw; /* keyword string */
121
int flags; /* type flags */
122
size_t default_size; /* default key size */
125
extern struct stktable_type stktable_types[];
128
* Any additional data related to the stuck session is installed *before*
129
* stksess (with negative offsets). This allows us to run variable-sized
130
* keys and variable-sized data without making use of intermediate pointers.
52
int sid; /* id of server to use for session */
53
133
unsigned int expire; /* session expiration date */
54
struct eb32_node exps; /* ebtree node used to hold the session in expiration tree */
55
struct ebmb_node keys; /* ebtree node used to hold the session in table */
134
unsigned int ref_cnt; /* reference count, can only purge when zero */
135
struct eb32_node exp; /* ebtree node used to hold the session in expiration tree */
136
struct eb32_node upd; /* ebtree node used to hold the update sequence tree */
137
struct ebmb_node key; /* ebtree node used to hold the session in table */
138
/* WARNING! do not put anything after <keys>, it's used by the key */
61
struct eb_root keys; /* head of stuck session tree */
62
struct eb_root exps; /* head of stuck session expiration tree */
63
struct pool_head *pool; /* pool used to allocate stuck sessions */
144
char *id; /* table id name */
145
struct eb_root keys; /* head of sticky session tree */
146
struct eb_root exps; /* head of sticky session expiration tree */
147
struct eb_root updates; /* head of sticky updates sequence tree */
148
struct pool_head *pool; /* pool used to allocate sticky sessions */
64
149
struct task *exp_task; /* expiration task */
65
unsigned long type; /* type of table (determine key format) */
150
struct task *sync_task; /* sync task */
152
unsigned int localupdate;
153
unsigned int syncing; /* number of sync tasks watching this table now */
155
struct peers *p; /* sync peers */
159
unsigned long type; /* type of table (determines key format) */
66
160
size_t key_size; /* size of a key, maximum size in case of string */
67
unsigned int size; /* maximum stuck session in table */
68
unsigned int current; /* number of stuck session in table */
69
int nopurge; /* 1 never purge stuck sessions */
70
int exp_next; /* next epiration date */
71
int expire; /* duration before expiration of stuck session */
161
unsigned int size; /* maximum number of sticky sessions in table */
162
unsigned int current; /* number of sticky sessions currently in table */
163
int nopurge; /* if non-zero, don't purge sticky sessions when full */
164
int exp_next; /* next expiration date (ticks) */
165
int expire; /* time to live for sticky sessions (milliseconds) */
166
int data_size; /* the size of the data that is prepended *before* stksess */
167
int data_ofs[STKTABLE_DATA_TYPES]; /* negative offsets of present data types, or 0 if absent */
172
} data_arg[STKTABLE_DATA_TYPES]; /* optional argument of each data type */
175
extern struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES];
74
177
/* stick table key data */
75
178
union stktable_key_data {
76
struct in_addr ip; /* used to store an ip key */
179
struct in_addr ip; /* used to store an ipv4 key */
180
struct in6_addr ipv6; /* used to store an ipv6 key */
77
181
uint32_t integer; /* used to store an integer key */
78
char buf[BUFSIZE]; /* used to store a null terminated string key */
182
char buf[0]; /* dynamically allocated, used to store a null terminated string key or a buffer of data */
81
185
/* stick table key */
82
186
struct stktable_key {
83
187
void *key; /* pointer on key buffer */
84
188
size_t key_len; /* data len to read in buff in case of null terminated string */
85
union stktable_key_data data; /* data */
189
union stktable_key_data data; /* data, must always be last */
88
192
#endif /* _TYPES_STICK_TABLE_H */