blob: 0c07f8c334657a6b84d6c82a3811786cd05da6a0 [file] [log] [blame]
Willy Tarreau59f98392012-07-06 14:13:49 +02001/*
2 * include/proto/connection.h
3 * This file contains connection function prototypes
4 *
5 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _PROTO_CONNECTION_H
23#define _PROTO_CONNECTION_H
24
25#include <common/config.h>
Willy Tarreauf2943dc2012-10-26 20:10:28 +020026#include <common/memory.h>
Willy Tarreau59f98392012-07-06 14:13:49 +020027#include <types/connection.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020028#include <types/listener.h>
Willy Tarreau2b199c92012-11-23 17:32:21 +010029#include <proto/fd.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010030#include <proto/obj_type.h>
Willy Tarreau59f98392012-07-06 14:13:49 +020031
Willy Tarreauf2943dc2012-10-26 20:10:28 +020032extern struct pool_head *pool2_connection;
33
34/* perform minimal intializations, report 0 in case of error, 1 if OK. */
35int init_connection();
36
Willy Tarreau59f98392012-07-06 14:13:49 +020037/* I/O callback for fd-based connections. It calls the read/write handlers
Willy Tarreauafad0e02012-08-09 14:45:22 +020038 * provided by the connection's sock_ops. Returns 0.
Willy Tarreau59f98392012-07-06 14:13:49 +020039 */
40int conn_fd_handler(int fd);
41
Willy Tarreau22cda212012-08-31 17:43:29 +020042/* receive a PROXY protocol header over a connection */
43int conn_recv_proxy(struct connection *conn, int flag);
Willy Tarreaue1e4a612012-10-05 00:10:55 +020044int make_proxy_line(char *buf, int buf_len, struct sockaddr_storage *src, struct sockaddr_storage *dst);
Willy Tarreau22cda212012-08-31 17:43:29 +020045
Willy Tarreauf7bc57c2012-10-03 00:19:48 +020046/* calls the init() function of the transport layer if any.
47 * Returns <0 in case of error.
Willy Tarreau15678ef2012-08-31 13:54:11 +020048 */
Willy Tarreauf7bc57c2012-10-03 00:19:48 +020049static inline int conn_xprt_init(struct connection *conn)
Willy Tarreau15678ef2012-08-31 13:54:11 +020050{
Willy Tarreauf7bc57c2012-10-03 00:19:48 +020051 if (conn->xprt && conn->xprt->init)
52 return conn->xprt->init(conn);
Willy Tarreau15678ef2012-08-31 13:54:11 +020053 return 0;
54}
55
Willy Tarreau6c03a642012-10-12 17:00:05 +020056/* Calls the close() function of the transport layer if any, and always unsets
Willy Tarreau1e954912012-10-12 17:50:05 +020057 * the transport layer. However this is not done if the CO_FL_XPRT_TRACKED flag
58 * is set, which allows logs to take data from the transport layer very late if
59 * needed.
Willy Tarreau6c03a642012-10-12 17:00:05 +020060 */
Willy Tarreauf7bc57c2012-10-03 00:19:48 +020061static inline void conn_xprt_close(struct connection *conn)
Willy Tarreau8b117082012-08-06 15:06:49 +020062{
Willy Tarreau1e954912012-10-12 17:50:05 +020063 if (conn->xprt && !(conn->flags & CO_FL_XPRT_TRACKED)) {
Willy Tarreau6c03a642012-10-12 17:00:05 +020064 if (conn->xprt->close)
65 conn->xprt->close(conn);
66 conn->xprt = NULL;
67 }
Willy Tarreau8b117082012-08-06 15:06:49 +020068}
69
Willy Tarreau2b199c92012-11-23 17:32:21 +010070/* If the connection still has a transport layer, then call its close() function
71 * if any, and delete the file descriptor if a control layer is set. This is
72 * used to close everything at once and atomically. However this is not done if
73 * the CO_FL_XPRT_TRACKED flag is set, which allows logs to take data from the
74 * transport layer very late if needed.
75 */
76static inline void conn_full_close(struct connection *conn)
77{
78 if (conn->xprt && !(conn->flags & CO_FL_XPRT_TRACKED)) {
79 if (conn->xprt->close)
80 conn->xprt->close(conn);
81 if (conn->ctrl)
82 fd_delete(conn->t.sock.fd);
83 conn->xprt = NULL;
84 }
85}
86
Willy Tarreaue9dfa792012-09-01 17:26:16 +020087/* Update polling on connection <c>'s file descriptor depending on its current
88 * state as reported in the connection's CO_FL_CURR_* flags, reports of EAGAIN
89 * in CO_FL_WAIT_*, and the sock layer expectations indicated by CO_FL_SOCK_*.
90 * The connection flags are updated with the new flags at the end of the
Willy Tarreau0ffde2c2012-10-04 22:21:15 +020091 * operation. Polling is totally disabled if an error was reported.
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +020092 */
Willy Tarreaue9dfa792012-09-01 17:26:16 +020093void conn_update_sock_polling(struct connection *c);
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +020094
Willy Tarreaue9dfa792012-09-01 17:26:16 +020095/* Update polling on connection <c>'s file descriptor depending on its current
96 * state as reported in the connection's CO_FL_CURR_* flags, reports of EAGAIN
97 * in CO_FL_WAIT_*, and the data layer expectations indicated by CO_FL_DATA_*.
98 * The connection flags are updated with the new flags at the end of the
Willy Tarreau0ffde2c2012-10-04 22:21:15 +020099 * operation. Polling is totally disabled if an error was reported.
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200100 */
Willy Tarreaue9dfa792012-09-01 17:26:16 +0200101void conn_update_data_polling(struct connection *c);
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200102
Willy Tarreau5f1504f2012-10-04 23:55:57 +0200103/* This callback is used to send a valid PROXY protocol line to a socket being
104 * established from the local machine. It sets the protocol addresses to the
105 * local and remote address. This is typically used with health checks or when
106 * it is not possible to determine the other end's address. It returns 0 if it
107 * fails in a fatal way or needs to poll to go further, otherwise it returns
108 * non-zero and removes itself from the connection's flags (the bit is provided
109 * in <flag> by the caller). It is designed to be called by the connection
110 * handler and relies on it to commit polling changes. Note that this function
111 * expects to be able to send the whole line at once, which should always be
112 * possible since it is supposed to start at the first byte of the outgoing
113 * data segment.
114 */
115int conn_local_send_proxy(struct connection *conn, unsigned int flag);
116
Willy Tarreau7d281492012-12-16 19:19:13 +0100117/* Refresh the connection's polling flags from its file descriptor status.
118 * This should be called at the beginning of a connection handler.
119 */
120static inline void conn_refresh_polling_flags(struct connection *conn)
121{
122 conn->flags &= ~(CO_FL_WAIT_ROOM | CO_FL_WAIT_RD | CO_FL_WAIT_DATA | CO_FL_WAIT_WR);
123
124 if (conn->ctrl) {
125 unsigned int flags = conn->flags & ~(CO_FL_CURR_RD_ENA | CO_FL_CURR_WR_ENA);
126
127 if (fd_ev_is_set(conn->t.sock.fd, DIR_RD))
128 flags |= CO_FL_CURR_RD_ENA;
129 if (fd_ev_is_set(conn->t.sock.fd, DIR_WR))
130 flags |= CO_FL_CURR_WR_ENA;
131 conn->flags = flags;
132 }
133}
134
Willy Tarreaue9dfa792012-09-01 17:26:16 +0200135/* inspects c->flags and returns non-zero if DATA ENA changes from the CURR ENA
Willy Tarreauc8dd77f2012-11-05 17:52:26 +0100136 * or if the WAIT flags are set with their respective ENA flags. Additionally,
Willy Tarreau0ffde2c2012-10-04 22:21:15 +0200137 * non-zero is also returned if an error was reported on the connection. This
138 * function is used quite often and is inlined. In order to proceed optimally
139 * with very little code and CPU cycles, the bits are arranged so that a change
Willy Tarreauc8dd77f2012-11-05 17:52:26 +0100140 * can be detected by a few left shifts, a xor, and a mask. These operations
141 * detect when W&D are both enabled for either direction, when C&D differ for
142 * either direction and when Error is set. The trick consists in first keeping
143 * only the bits we're interested in, since they don't collide when shifted,
144 * and to perform the AND at the end. In practice, the compiler is able to
145 * replace the last AND with a TEST in boolean conditions. This results in
146 * checks that are done in 4-6 cycles and less than 30 bytes.
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200147 */
148static inline unsigned int conn_data_polling_changes(const struct connection *c)
149{
Willy Tarreauc8dd77f2012-11-05 17:52:26 +0100150 unsigned int f = c->flags;
151 f &= CO_FL_DATA_WR_ENA | CO_FL_DATA_RD_ENA | CO_FL_CURR_WR_ENA |
152 CO_FL_CURR_RD_ENA | CO_FL_ERROR | CO_FL_WAIT_WR | CO_FL_WAIT_RD;
153
154 f = (f & (f << 2)) | /* test W & D */
155 ((f ^ (f << 1)) & (CO_FL_CURR_WR_ENA|CO_FL_CURR_RD_ENA)); /* test C ^ D */
156 return f & (CO_FL_WAIT_WR | CO_FL_WAIT_RD | CO_FL_CURR_WR_ENA | CO_FL_CURR_RD_ENA | CO_FL_ERROR);
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200157}
158
Willy Tarreaue9dfa792012-09-01 17:26:16 +0200159/* inspects c->flags and returns non-zero if SOCK ENA changes from the CURR ENA
Willy Tarreauc8dd77f2012-11-05 17:52:26 +0100160 * or if the WAIT flags are set with their respective ENA flags. Additionally,
Willy Tarreau0ffde2c2012-10-04 22:21:15 +0200161 * non-zero is also returned if an error was reported on the connection. This
162 * function is used quite often and is inlined. In order to proceed optimally
163 * with very little code and CPU cycles, the bits are arranged so that a change
Willy Tarreauc8dd77f2012-11-05 17:52:26 +0100164 * can be detected by a few left shifts, a xor, and a mask. These operations
165 * detect when W&S are both enabled for either direction, when C&S differ for
166 * either direction and when Error is set. The trick consists in first keeping
167 * only the bits we're interested in, since they don't collide when shifted,
168 * and to perform the AND at the end. In practice, the compiler is able to
169 * replace the last AND with a TEST in boolean conditions. This results in
170 * checks that are done in 4-6 cycles and less than 30 bytes.
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200171 */
172static inline unsigned int conn_sock_polling_changes(const struct connection *c)
173{
Willy Tarreauc8dd77f2012-11-05 17:52:26 +0100174 unsigned int f = c->flags;
175 f &= CO_FL_SOCK_WR_ENA | CO_FL_SOCK_RD_ENA | CO_FL_CURR_WR_ENA |
176 CO_FL_CURR_RD_ENA | CO_FL_ERROR | CO_FL_WAIT_WR | CO_FL_WAIT_RD;
177
178 f = (f & (f << 3)) | /* test W & S */
179 ((f ^ (f << 2)) & (CO_FL_CURR_WR_ENA|CO_FL_CURR_RD_ENA)); /* test C ^ S */
180 return f & (CO_FL_WAIT_WR | CO_FL_WAIT_RD | CO_FL_CURR_WR_ENA | CO_FL_CURR_RD_ENA | CO_FL_ERROR);
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200181}
182
183/* Automatically updates polling on connection <c> depending on the DATA flags
184 * if no handshake is in progress.
185 */
186static inline void conn_cond_update_data_polling(struct connection *c)
187{
188 if (!(c->flags & CO_FL_POLL_SOCK) && conn_data_polling_changes(c))
189 conn_update_data_polling(c);
190}
191
192/* Automatically updates polling on connection <c> depending on the SOCK flags
193 * if a handshake is in progress.
194 */
195static inline void conn_cond_update_sock_polling(struct connection *c)
196{
197 if ((c->flags & CO_FL_POLL_SOCK) && conn_sock_polling_changes(c))
198 conn_update_sock_polling(c);
199}
200
Willy Tarreau36fb02c2012-11-24 11:09:07 +0100201/* Stop all polling on the fd. This might be used when an error is encountered
202 * for example.
203 */
204static inline void conn_stop_polling(struct connection *c)
205{
206 c->flags &= ~(CO_FL_CURR_RD_ENA | CO_FL_CURR_WR_ENA |
207 CO_FL_SOCK_RD_ENA | CO_FL_SOCK_WR_ENA |
208 CO_FL_DATA_RD_ENA | CO_FL_DATA_WR_ENA);
209 fd_stop_both(c->t.sock.fd);
210}
211
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200212/* Automatically update polling on connection <c> depending on the DATA and
213 * SOCK flags, and on whether a handshake is in progress or not. This may be
214 * called at any moment when there is a doubt about the effectiveness of the
215 * polling state, for instance when entering or leaving the handshake state.
216 */
217static inline void conn_cond_update_polling(struct connection *c)
218{
Willy Tarreau36fb02c2012-11-24 11:09:07 +0100219 if (unlikely(c->flags & CO_FL_ERROR))
220 conn_stop_polling(c);
221 else if (!(c->flags & CO_FL_POLL_SOCK) && conn_data_polling_changes(c))
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200222 conn_update_data_polling(c);
223 else if ((c->flags & CO_FL_POLL_SOCK) && conn_sock_polling_changes(c))
224 conn_update_sock_polling(c);
225}
226
227/***** Event manipulation primitives for use by DATA I/O callbacks *****/
228/* The __conn_* versions do not propagate to lower layers and are only meant
229 * to be used by handlers called by the connection handler. The other ones
230 * may be used anywhere.
231 */
232static inline void __conn_data_want_recv(struct connection *c)
233{
234 c->flags |= CO_FL_DATA_RD_ENA;
235}
236
237static inline void __conn_data_stop_recv(struct connection *c)
238{
239 c->flags &= ~CO_FL_DATA_RD_ENA;
240}
241
242static inline void __conn_data_poll_recv(struct connection *c)
243{
Willy Tarreaue9dfa792012-09-01 17:26:16 +0200244 c->flags |= CO_FL_WAIT_RD | CO_FL_DATA_RD_ENA;
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200245}
246
247static inline void __conn_data_want_send(struct connection *c)
248{
249 c->flags |= CO_FL_DATA_WR_ENA;
250}
251
252static inline void __conn_data_stop_send(struct connection *c)
253{
254 c->flags &= ~CO_FL_DATA_WR_ENA;
255}
256
257static inline void __conn_data_poll_send(struct connection *c)
258{
Willy Tarreaue9dfa792012-09-01 17:26:16 +0200259 c->flags |= CO_FL_WAIT_WR | CO_FL_DATA_WR_ENA;
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200260}
261
262static inline void __conn_data_stop_both(struct connection *c)
263{
264 c->flags &= ~(CO_FL_DATA_WR_ENA | CO_FL_DATA_RD_ENA);
265}
266
267static inline void conn_data_want_recv(struct connection *c)
268{
269 __conn_data_want_recv(c);
270 conn_cond_update_data_polling(c);
271}
272
273static inline void conn_data_stop_recv(struct connection *c)
274{
275 __conn_data_stop_recv(c);
276 conn_cond_update_data_polling(c);
277}
278
279static inline void conn_data_poll_recv(struct connection *c)
280{
281 __conn_data_poll_recv(c);
282 conn_cond_update_data_polling(c);
283}
284
285static inline void conn_data_want_send(struct connection *c)
286{
287 __conn_data_want_send(c);
288 conn_cond_update_data_polling(c);
289}
290
291static inline void conn_data_stop_send(struct connection *c)
292{
293 __conn_data_stop_send(c);
294 conn_cond_update_data_polling(c);
295}
296
297static inline void conn_data_poll_send(struct connection *c)
298{
299 __conn_data_poll_send(c);
300 conn_cond_update_data_polling(c);
301}
302
303static inline void conn_data_stop_both(struct connection *c)
304{
305 __conn_data_stop_both(c);
306 conn_cond_update_data_polling(c);
307}
308
309/***** Event manipulation primitives for use by handshake I/O callbacks *****/
310/* The __conn_* versions do not propagate to lower layers and are only meant
311 * to be used by handlers called by the connection handler. The other ones
312 * may be used anywhere.
313 */
314static inline void __conn_sock_want_recv(struct connection *c)
315{
316 c->flags |= CO_FL_SOCK_RD_ENA;
317}
318
319static inline void __conn_sock_stop_recv(struct connection *c)
320{
321 c->flags &= ~CO_FL_SOCK_RD_ENA;
322}
323
324static inline void __conn_sock_poll_recv(struct connection *c)
325{
Willy Tarreaue9dfa792012-09-01 17:26:16 +0200326 c->flags |= CO_FL_WAIT_RD | CO_FL_SOCK_RD_ENA;
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200327}
328
329static inline void __conn_sock_want_send(struct connection *c)
330{
331 c->flags |= CO_FL_SOCK_WR_ENA;
332}
333
334static inline void __conn_sock_stop_send(struct connection *c)
335{
336 c->flags &= ~CO_FL_SOCK_WR_ENA;
337}
338
339static inline void __conn_sock_poll_send(struct connection *c)
340{
Willy Tarreaue9dfa792012-09-01 17:26:16 +0200341 c->flags |= CO_FL_WAIT_WR | CO_FL_SOCK_WR_ENA;
Willy Tarreaub5e2cbd2012-08-17 11:55:04 +0200342}
343
344static inline void __conn_sock_stop_both(struct connection *c)
345{
346 c->flags &= ~(CO_FL_SOCK_WR_ENA | CO_FL_SOCK_RD_ENA);
347}
348
349static inline void conn_sock_want_recv(struct connection *c)
350{
351 __conn_sock_want_recv(c);
352 conn_cond_update_sock_polling(c);
353}
354
355static inline void conn_sock_stop_recv(struct connection *c)
356{
357 __conn_sock_stop_recv(c);
358 conn_cond_update_sock_polling(c);
359}
360
361static inline void conn_sock_poll_recv(struct connection *c)
362{
363 __conn_sock_poll_recv(c);
364 conn_cond_update_sock_polling(c);
365}
366
367static inline void conn_sock_want_send(struct connection *c)
368{
369 __conn_sock_want_send(c);
370 conn_cond_update_sock_polling(c);
371}
372
373static inline void conn_sock_stop_send(struct connection *c)
374{
375 __conn_sock_stop_send(c);
376 conn_cond_update_sock_polling(c);
377}
378
379static inline void conn_sock_poll_send(struct connection *c)
380{
381 __conn_sock_poll_send(c);
382 conn_cond_update_sock_polling(c);
383}
384
385static inline void conn_sock_stop_both(struct connection *c)
386{
387 __conn_sock_stop_both(c);
388 conn_cond_update_sock_polling(c);
389}
Willy Tarreau8b117082012-08-06 15:06:49 +0200390
Willy Tarreau3af56a92012-08-20 16:55:48 +0200391/* shutdown management */
392static inline void conn_sock_read0(struct connection *c)
393{
394 c->flags |= CO_FL_SOCK_RD_SH;
395 __conn_sock_stop_recv(c);
396}
397
398static inline void conn_data_read0(struct connection *c)
399{
400 c->flags |= CO_FL_DATA_RD_SH;
401 __conn_data_stop_recv(c);
402}
403
404static inline void conn_sock_shutw(struct connection *c)
405{
406 c->flags |= CO_FL_SOCK_WR_SH;
407 __conn_sock_stop_send(c);
408}
409
410static inline void conn_data_shutw(struct connection *c)
411{
412 c->flags |= CO_FL_DATA_WR_SH;
413 __conn_data_stop_send(c);
414}
415
416/* detect sock->data read0 transition */
417static inline int conn_data_read0_pending(struct connection *c)
418{
419 return (c->flags & (CO_FL_DATA_RD_SH | CO_FL_SOCK_RD_SH)) == CO_FL_SOCK_RD_SH;
420}
421
422/* detect data->sock shutw transition */
423static inline int conn_sock_shutw_pending(struct connection *c)
424{
425 return (c->flags & (CO_FL_DATA_WR_SH | CO_FL_SOCK_WR_SH)) == CO_FL_DATA_WR_SH;
426}
427
Willy Tarreau986a9d22012-08-30 21:11:38 +0200428/* Retrieves the connection's source address */
429static inline void conn_get_from_addr(struct connection *conn)
430{
431 if (conn->flags & CO_FL_ADDR_FROM_SET)
432 return;
433
434 if (!conn->ctrl || !conn->ctrl->get_src)
435 return;
436
437 if (conn->ctrl->get_src(conn->t.sock.fd, (struct sockaddr *)&conn->addr.from,
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100438 sizeof(conn->addr.from),
439 obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
Willy Tarreau986a9d22012-08-30 21:11:38 +0200440 return;
441 conn->flags |= CO_FL_ADDR_FROM_SET;
442}
443
444/* Retrieves the connection's original destination address */
445static inline void conn_get_to_addr(struct connection *conn)
446{
447 if (conn->flags & CO_FL_ADDR_TO_SET)
448 return;
449
450 if (!conn->ctrl || !conn->ctrl->get_dst)
451 return;
452
453 if (conn->ctrl->get_dst(conn->t.sock.fd, (struct sockaddr *)&conn->addr.to,
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100454 sizeof(conn->addr.to),
455 obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
Willy Tarreau986a9d22012-08-30 21:11:38 +0200456 return;
457 conn->flags |= CO_FL_ADDR_TO_SET;
458}
459
Willy Tarreaubd99aab2012-10-02 20:57:19 +0200460/* Assigns a connection with the appropriate data, ctrl, transport layers, and owner. */
461static inline void conn_assign(struct connection *conn, const struct data_cb *data,
462 const struct protocol *ctrl, const struct xprt_ops *xprt,
463 void *owner)
Willy Tarreaudda5e7c2012-09-24 17:15:42 +0200464{
Willy Tarreau74beec32012-10-03 00:41:04 +0200465 conn->data = data;
Willy Tarreaudda5e7c2012-09-24 17:15:42 +0200466 conn->ctrl = ctrl;
Willy Tarreauf7bc57c2012-10-03 00:19:48 +0200467 conn->xprt = xprt;
Willy Tarreaucd379952012-09-27 22:14:33 +0200468 conn->owner = owner;
Willy Tarreaubd99aab2012-10-02 20:57:19 +0200469}
470
471/* prepares a connection with the appropriate data, ctrl, transport layers, and
472 * owner. The transport state and context are set to 0.
473 */
474static inline void conn_prepare(struct connection *conn, const struct data_cb *data,
475 const struct protocol *ctrl, const struct xprt_ops *xprt,
476 void *owner)
477{
478 conn_assign(conn, data, ctrl, xprt, owner);
Willy Tarreauf7bc57c2012-10-03 00:19:48 +0200479 conn->xprt_st = 0;
480 conn->xprt_ctx = NULL;
Willy Tarreaudda5e7c2012-09-24 17:15:42 +0200481}
Willy Tarreau986a9d22012-08-30 21:11:38 +0200482
Willy Tarreau0af29122012-12-03 15:35:00 +0100483/* returns a human-readable error code for conn->err_code, or NULL if the code
484 * is unknown.
485 */
486static inline const char *conn_err_code_str(struct connection *c)
487{
488 switch (c->err_code) {
489 case CO_ER_NONE: return "Success";
Willy Tarreau8e3bf692012-12-03 15:41:18 +0100490 case CO_ER_PRX_EMPTY: return "Connection closed while waiting for PROXY protocol header";
491 case CO_ER_PRX_ABORT: return "Connection error while waiting for PROXY protocol header";
Willy Tarreau0af29122012-12-03 15:35:00 +0100492 case CO_ER_PRX_TIMEOUT: return "Timeout while waiting for PROXY protocol header";
Willy Tarreau8e3bf692012-12-03 15:41:18 +0100493 case CO_ER_PRX_TRUNCATED: return "Truncated PROXY protocol header received";
494 case CO_ER_PRX_NOT_HDR: return "Received something which does not look like a PROXY protocol header";
495 case CO_ER_PRX_BAD_HDR: return "Received an invalid PROXY protocol header";
496 case CO_ER_PRX_BAD_PROTO: return "Received an unhandled protocol in the PROXY protocol header";
Willy Tarreau20879a02012-12-03 16:32:10 +0100497 case CO_ER_SSL_EMPTY: return "Connection closed during SSL handshake";
498 case CO_ER_SSL_ABORT: return "Connection error during SSL handshake";
Willy Tarreau0af29122012-12-03 15:35:00 +0100499 case CO_ER_SSL_TIMEOUT: return "Timeout during SSL handshake";
Willy Tarreau20879a02012-12-03 16:32:10 +0100500 case CO_ER_SSL_TOO_MANY: return "Too many SSL connections";
501 case CO_ER_SSL_NO_MEM: return "Out of memory when initializing an SSL connection";
502 case CO_ER_SSL_RENEG: return "Rejected a client-initiated SSL renegociation attempt";
503 case CO_ER_SSL_CA_FAIL: return "SSL client CA chain cannot be verified";
504 case CO_ER_SSL_CRT_FAIL: return "SSL client certificate not trusted";
505 case CO_ER_SSL_HANDSHAKE: return "SSL handshake failure";
506 case CO_ER_SSL_NO_TARGET: return "Attempt to use SSL on an unknownn target (internal error)";
Willy Tarreau0af29122012-12-03 15:35:00 +0100507 }
508 return NULL;
509}
510
Willy Tarreau59f98392012-07-06 14:13:49 +0200511#endif /* _PROTO_CONNECTION_H */
512
513/*
514 * Local variables:
515 * c-indent-level: 8
516 * c-basic-offset: 8
517 * End:
518 */