blob: 6fe21ab888122b7bb6d29005f4728a4caddf1116 [file] [log] [blame]
Willy Tarreaudd815982007-10-16 12:25:14 +02001/*
Willy Tarreaud1d54542012-09-12 22:58:11 +02002 * include/types/listener.h
3 * This file defines the structures needed to manage listeners.
Willy Tarreaube58c382011-07-24 18:28:10 +02004 *
Willy Tarreaud1d54542012-09-12 22:58:11 +02005 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
Willy Tarreaube58c382011-07-24 18:28:10 +02006 *
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 */
Willy Tarreaudd815982007-10-16 12:25:14 +020021
Willy Tarreaud1d54542012-09-12 22:58:11 +020022#ifndef _TYPES_LISTENER_H
23#define _TYPES_LISTENER_H
Willy Tarreaudd815982007-10-16 12:25:14 +020024
25#include <sys/types.h>
26#include <sys/socket.h>
27
Emeric Brun0b8d4d92012-05-18 15:46:21 +020028#ifdef USE_OPENSSL
29#include <openssl/ssl.h>
30#endif
31
Willy Tarreaudd815982007-10-16 12:25:14 +020032#include <common/config.h>
33#include <common/mini-clist.h>
Willy Tarreau45cb4fb2009-10-26 21:10:04 +010034#include <eb32tree.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020035
Willy Tarreaud1d54542012-09-12 22:58:11 +020036/* Some pointer types reference below */
37struct task;
38struct protocol;
Willy Tarreauf7bc57c2012-10-03 00:19:48 +020039struct xprt_ops;
Willy Tarreaud1d54542012-09-12 22:58:11 +020040struct proxy;
41struct licounters;
Willy Tarreaudd815982007-10-16 12:25:14 +020042
Willy Tarreaudd815982007-10-16 12:25:14 +020043/* listener state */
Willy Tarreaube58c382011-07-24 18:28:10 +020044enum {
45 LI_NEW = 0, /* not initialized yet */
46 LI_INIT, /* all parameters filled in, but not assigned yet */
47 LI_ASSIGNED, /* assigned to the protocol, but not listening yet */
48 LI_PAUSED, /* listener was paused, it's bound but not listening */
49 LI_LISTEN, /* started, listening but not enabled */
50 LI_READY, /* started, listening and enabled */
51 LI_FULL, /* reached its connection limit */
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +020052 LI_LIMITED, /* transient state: limits have been reached, listener is queued */
Willy Tarreaube58c382011-07-24 18:28:10 +020053};
Willy Tarreaudabf2e22007-10-28 21:59:24 +010054
55/* Listener transitions
56 * calloc() set() add_listener() bind()
57 * -------> NEW ----> INIT ----------> ASSIGNED -----> LISTEN
58 * <------- <---- <---------- <-----
59 * free() bzero() del_listener() unbind()
60 *
61 * The file descriptor is valid only during these three states :
62 *
63 * disable()
64 * LISTEN <------------ READY
65 * A| ------------> |A
66 * || !max & enable() ||
67 * || ||
68 * || max ||
69 * || max & enable() V| !max
70 * |+---------------> FULL
71 * +-----------------
72 * disable()
73 *
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +020074 * The LIMITED state my be used when a limit has been detected just before
75 * using a listener. In this case, the listener MUST be queued into the
76 * appropriate wait queue (either the proxy's or the global one). It may be
77 * set back to the READY state at any instant and for any reason, so one must
78 * not rely on this state.
Willy Tarreaudabf2e22007-10-28 21:59:24 +010079 */
Willy Tarreaudd815982007-10-16 12:25:14 +020080
Willy Tarreau6fb42e02007-10-28 17:02:33 +010081/* listener socket options */
82#define LI_O_NONE 0x0000
83#define LI_O_NOLINGER 0x0001 /* disable linger on this socket */
Willy Tarreaub1e52e82008-01-13 14:49:51 +010084#define LI_O_FOREIGN 0x0002 /* permit listening on foreing addresses */
Willy Tarreau9ea05a72009-06-14 12:07:01 +020085#define LI_O_NOQUICKACK 0x0004 /* disable quick ack of immediate data (linux) */
Willy Tarreaucb6cd432009-10-13 07:34:14 +020086#define LI_O_DEF_ACCEPT 0x0008 /* wait up to 1 second for data before accepting */
Willy Tarreaua5c0ab22010-05-31 10:30:33 +020087#define LI_O_TCP_RULES 0x0010 /* run TCP rules checks on the incoming connection */
Willy Tarreaude3041d2010-05-31 10:56:17 +020088#define LI_O_CHK_MONNET 0x0020 /* check the source against a monitor-net rule */
Willy Tarreau8a956912010-10-15 14:27:08 +020089#define LI_O_ACC_PROXY 0x0040 /* find the proxied address in the first request line */
Willy Tarreau3c63fd82011-09-07 18:00:47 +020090#define LI_O_UNLIMITED 0x0080 /* listener not subject to global limits (peers & stats socket) */
Willy Tarreau1c862c52012-10-05 16:21:00 +020091#define LI_O_TCP_FO 0x0100 /* enable TCP Fast Open (linux >= 3.6) */
Willy Tarreau3c63fd82011-09-07 18:00:47 +020092
93/* Note: if a listener uses LI_O_UNLIMITED, it is highly recommended that it adds its own
94 * maxconn setting to the global.maxsock value so that its resources are reserved.
95 */
Willy Tarreau6fb42e02007-10-28 17:02:33 +010096
Willy Tarreau2a65ff02012-09-13 17:54:29 +020097/* "bind" line settings */
98struct bind_conf {
Willy Tarreauf5ae8f72012-09-07 16:58:00 +020099#ifdef USE_OPENSSL
Emeric Brund94b3fe2012-09-20 18:23:56 +0200100 char *cafile; /* CAfile to use on verify */
Emeric Brun81c00f02012-09-21 14:31:21 +0200101 unsigned long long ca_ignerr; /* ignored verify errors in handshake if depth > 0 */
102 unsigned long long crt_ignerr; /* ignored verify errors in handshake if depth == 0 */
Willy Tarreauf5ae8f72012-09-07 16:58:00 +0200103 char *ciphers; /* cipher suite to use if non-null */
Emeric Brund94b3fe2012-09-20 18:23:56 +0200104 char *crlfile; /* CRLfile to use on verify */
Emeric Brun2b58d042012-09-20 17:10:03 +0200105 char *ecdhe; /* named curve to use for ECDHE */
Emeric Brun2d0c4822012-10-02 13:45:20 +0200106 int no_tls_tickets; /* disable session resumption tickets */
Willy Tarreauf5ae8f72012-09-07 16:58:00 +0200107 int nosslv3; /* disable SSLv3 */
Emeric Brunc0ff4922012-09-28 19:37:02 +0200108 int notlsv10; /* disable TLSv1.0 */
109 int notlsv11; /* disable TLSv1.1 */
110 int notlsv12; /* disable TLSv1.2 */
Willy Tarreauf5ae8f72012-09-07 16:58:00 +0200111 int prefer_server_ciphers; /* Prefer server ciphers */
Emeric Brund94b3fe2012-09-20 18:23:56 +0200112 int verify; /* verify method (set of SSL_VERIFY_* flags) */
Emeric Brunfc0421f2012-09-07 17:30:07 +0200113 SSL_CTX *default_ctx; /* SSL context of first/default certificate */
114 struct eb_root sni_ctx; /* sni_ctx tree of all known certs full-names sorted by name */
115 struct eb_root sni_w_ctx; /* sni_ctx tree of all known certs wildcards sorted by name */
Willy Tarreauf5ae8f72012-09-07 16:58:00 +0200116#endif
Willy Tarreau2a65ff02012-09-13 17:54:29 +0200117 int is_ssl; /* SSL is required for these listeners */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200118 struct { /* UNIX socket permissions */
119 uid_t uid; /* -1 to leave unchanged */
120 gid_t gid; /* -1 to leave unchanged */
121 mode_t mode; /* 0 to leave unchanged */
122 } ux;
123 int level; /* stats access level (ACCESS_LVL_*) */
Willy Tarreauf5ae8f72012-09-07 16:58:00 +0200124 struct list by_fe; /* next binding for the same frontend, or NULL */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200125 struct list listeners; /* list of listeners using this bind config */
Willy Tarreauf5ae8f72012-09-07 16:58:00 +0200126 char *arg; /* argument passed to "bind" for better error reporting */
127 char *file; /* file where the section appears */
128 int line; /* line where the section appears */
129};
130
Willy Tarreaudd815982007-10-16 12:25:14 +0200131/* The listener will be directly referenced by the fdtab[] which holds its
132 * socket. The listener provides the protocol-specific accept() function to
133 * the fdtab.
134 */
135struct listener {
136 int fd; /* the listen socket */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200137 char *name; /* */
138 int luid; /* listener universally unique ID, used for SNMP */
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100139 int state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */
Willy Tarreau6fb42e02007-10-28 17:02:33 +0100140 int options; /* socket options : LI_O_* */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200141 struct licounters *counters; /* statistics counters */
Willy Tarreaudd815982007-10-16 12:25:14 +0200142 struct protocol *proto; /* protocol this listener belongs to */
Willy Tarreauf7bc57c2012-10-03 00:19:48 +0200143 struct xprt_ops *xprt; /* transport-layer operations for this socket */
Willy Tarreaudd815982007-10-16 12:25:14 +0200144 int nbconn; /* current number of connections on this listener */
145 int maxconn; /* maximum connections allowed on this listener */
Willy Tarreauc73ce2b2008-01-06 10:55:10 +0100146 unsigned int backlog; /* if set, listen backlog */
Willy Tarreaudd815982007-10-16 12:25:14 +0200147 struct list proto_list; /* list in the protocol header */
Willy Tarreaueb472682010-05-28 18:46:57 +0200148 int (*accept)(struct listener *l, int fd, struct sockaddr_storage *addr); /* upper layer's accept() */
Willy Tarreau26c25062009-03-08 09:38:41 +0100149 struct task * (*handler)(struct task *t); /* protocol handler. It is a task */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200150 int *timeout; /* pointer to client-side timeout */
Willy Tarreaueb472682010-05-28 18:46:57 +0200151 struct proxy *frontend; /* the frontend this listener belongs to, or NULL */
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200152 struct list wait_queue; /* link element to make the listener wait for something (LI_LIMITED) */
Willy Tarreau3bc13772008-12-07 11:50:35 +0100153 unsigned int analysers; /* bitmap of required protocol analysers */
Willy Tarreau2c9f5b12009-08-16 19:12:36 +0200154 int nice; /* nice value to assign to the instanciated tasks */
Willy Tarreau5e6e2042009-02-04 17:19:29 +0100155 char *interface; /* interface name or NULL */
Willy Tarreaube1b9182009-06-14 18:48:19 +0200156 int maxseg; /* for TCP, advertised MSS */
Willy Tarreau90a570f2009-10-04 20:54:54 +0200157
Willy Tarreau4348fad2012-09-20 16:48:07 +0200158 struct list by_fe; /* chaining in frontend's list of listeners */
159 struct list by_bind; /* chaining in bind_conf's list of listeners */
Willy Tarreau2a65ff02012-09-13 17:54:29 +0200160 struct bind_conf *bind_conf; /* "bind" line settings, include SSL settings among other things */
Willy Tarreauf5ae8f72012-09-07 16:58:00 +0200161
Willy Tarreau7b815632011-10-21 18:51:57 +0200162 /* warning: this struct is huge, keep it at the bottom */
163 struct sockaddr_storage addr; /* the address we listen to */
Willy Tarreau90a570f2009-10-04 20:54:54 +0200164 struct {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +0200165 struct eb32_node id; /* place in the tree of used IDs */
Willy Tarreau90a570f2009-10-04 20:54:54 +0200166 } conf; /* config information */
Willy Tarreaudd815982007-10-16 12:25:14 +0200167};
168
Willy Tarreau26982662012-09-12 23:17:10 +0200169/* Descriptor for a "bind" keyword. The ->parse() function returns 0 in case of
170 * success, or a combination of ERR_* flags if an error is encountered. The
171 * function pointer can be NULL if not implemented. The function also has an
Willy Tarreau4348fad2012-09-20 16:48:07 +0200172 * access to the current "bind" config line. The ->skip value tells the parser
173 * how many words have to be skipped after the keyword.
Willy Tarreau26982662012-09-12 23:17:10 +0200174 */
175struct bind_kw {
176 const char *kw;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200177 int (*parse)(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err);
Willy Tarreau26982662012-09-12 23:17:10 +0200178 int skip; /* nb of args to skip */
179};
180
181/*
182 * A keyword list. It is a NULL-terminated array of keywords. It embeds a
183 * struct list in order to be linked to other lists, allowing it to easily
184 * be declared where it is needed, and linked without duplicating data nor
Willy Tarreau51fb7652012-09-18 18:24:39 +0200185 * allocating memory. It is also possible to indicate a scope for the keywords.
Willy Tarreau26982662012-09-12 23:17:10 +0200186 */
187struct bind_kw_list {
Willy Tarreau51fb7652012-09-18 18:24:39 +0200188 const char *scope;
Willy Tarreau26982662012-09-12 23:17:10 +0200189 struct list list;
190 struct bind_kw kw[VAR_ARRAY];
191};
192
193
Willy Tarreaud1d54542012-09-12 22:58:11 +0200194#endif /* _TYPES_LISTENER_H */
Willy Tarreaudd815982007-10-16 12:25:14 +0200195
196/*
197 * Local variables:
198 * c-indent-level: 8
199 * c-basic-offset: 8
200 * End:
201 */