~ubuntu-branches/ubuntu/vivid/haproxy/vivid

« back to all changes in this revision

Viewing changes to include/types/stick_table.h

  • Committer: Package Import Robot
  • Author(s): Apollon Oikonomopoulos
  • Date: 2014-06-20 11:05:17 UTC
  • mfrom: (1.1.15) (15.1.12 experimental)
  • Revision ID: package-import@ubuntu.com-20140620110517-u6q5p9kyy2f3ozw9
Tags: 1.5.0-1
* New upstream stable series. Notable changes since the 1.4 series:
  + Native SSL support on both sides with SNI/NPN/ALPN and OCSP stapling.
  + IPv6 and UNIX sockets are supported everywhere
  + End-to-end HTTP keep-alive for better support of NTLM and improved
    efficiency in static farms
  + HTTP/1.1 response compression (deflate, gzip) to save bandwidth
  + PROXY protocol versions 1 and 2 on both sides
  + Data sampling on everything in request or response, including payload
  + ACLs can use any matching method with any input sample
  + Maps and dynamic ACLs updatable from the CLI
  + Stick-tables support counters to track activity on any input sample
  + Custom format for logs, unique-id, header rewriting, and redirects
  + Improved health checks (SSL, scripted TCP, check agent, ...)
  + Much more scalable configuration supports hundreds of thousands of
    backends and certificates without sweating

* Upload to unstable, merge all 1.5 work from experimental. Most important
  packaging changes since 1.4.25-1 include:
  + systemd support.
  + A more sane default config file.
  + Zero-downtime upgrades between 1.5 releases by gracefully reloading
    HAProxy during upgrades.
  + HTML documentation shipped in the haproxy-doc package.
  + kqueue support for kfreebsd.

* Packaging changes since 1.5~dev26-2:
  + Drop patches merged upstream:
    o Fix-reference-location-in-manpage.patch
    o 0001-BUILD-stats-workaround-stupid-and-bogus-Werror-forma.patch
  + d/watch: look for stable 1.5 releases
  + systemd: respect CONFIG and EXTRAOPTS when specified in
    /etc/default/haproxy.
  + initscript: test the configuration before start or reload.
  + initscript: remove the ENABLED flag and logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * Macros, variables and structures for stick tables management.
4
4
 *
5
5
 * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
 
6
 * Copyright (C) 2010 Willy Tarreau <w@1wt.eu>
6
7
 *
7
8
 * This library is free software; you can redistribute it and/or
8
9
 * modify it under the terms of the GNU Lesser General Public
29
30
#include <ebmbtree.h>
30
31
#include <eb32tree.h>
31
32
#include <common/memory.h>
 
33
#include <types/freq_ctr.h>
32
34
 
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 */
37
 
 
38
 
#define STKTABLE_TYPES  3  /* Increase this value if you add a type */
39
 
 
40
 
/* stick table type flags */
41
 
#define STKTABLE_TYPEFLAG_CUSTOMKEYSIZE 0x00000001 /* this table type maxsize is configurable */
 
36
enum {
 
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 */
 
43
};
 
44
 
 
45
/* The types of extra data we can store in a stick table */
 
46
enum {
 
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 */
 
64
};
 
65
 
 
66
/* The equivalent standard types of the stored data */
 
67
enum {
 
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 */
 
72
};
 
73
 
 
74
/* The types of optional arguments to stored data */
 
75
enum {
 
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 */
 
79
};
 
80
 
 
81
/* stick_table extra data. This is mainly used for casting or size computation */
 
82
union stktable_data {
 
83
        /* standard types for easy casting */
 
84
        int std_t_sint;
 
85
        unsigned int std_t_uint;
 
86
        unsigned long long std_t_ull;
 
87
        struct freq_ctr_period std_t_frqp;
 
88
 
 
89
        /* types of each storable data */
 
90
        int server_id;
 
91
        unsigned int gpc0;
 
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;
 
106
};
 
107
 
 
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_* */
 
113
};
 
114
 
 
115
/* stick table key type flags */
 
116
#define STK_F_CUSTOM_KEYSIZE      0x00000001   /* this table's key size is configurable */
42
117
 
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 */
48
123
};
49
124
 
50
 
/* stuck session */
 
125
extern struct stktable_type stktable_types[];
 
126
 
 
127
/* Sticky session.
 
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.
 
131
 */
51
132
struct stksess {
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 */
56
139
};
57
140
 
58
141
 
59
142
/* stick table */
60
143
struct stktable {
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 */
 
151
        unsigned int update;
 
152
        unsigned int localupdate;
 
153
        unsigned int syncing;     /* number of sync tasks watching this table now */
 
154
        union {
 
155
                struct peers *p; /* sync peers */
 
156
                char *name;
 
157
        } peers;
 
158
 
 
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 */
 
168
        union {
 
169
                int i;
 
170
                unsigned int u;
 
171
                void *p;
 
172
        } data_arg[STKTABLE_DATA_TYPES]; /* optional argument of each data type */
72
173
};
73
174
 
 
175
extern struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES];
 
176
 
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 */
79
183
};
80
184
 
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 */
86
190
};
87
191
 
88
192
#endif /* _TYPES_STICK_TABLE_H */
89