Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 2 | * include/types/listener.h |
| 3 | * This file defines the structures needed to manage listeners. |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 4 | * |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 5 | * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 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 | */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 22 | #ifndef _TYPES_LISTENER_H |
| 23 | #define _TYPES_LISTENER_H |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 24 | |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/socket.h> |
| 27 | |
Emeric Brun | 0b8d4d9 | 2012-05-18 15:46:21 +0200 | [diff] [blame] | 28 | #ifdef USE_OPENSSL |
| 29 | #include <openssl/ssl.h> |
| 30 | #endif |
| 31 | |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 32 | #include <common/config.h> |
| 33 | #include <common/mini-clist.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 34 | #include <types/obj_type.h> |
Willy Tarreau | 45cb4fb | 2009-10-26 21:10:04 +0100 | [diff] [blame] | 35 | #include <eb32tree.h> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 36 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 37 | /* Some pointer types reference below */ |
| 38 | struct task; |
| 39 | struct protocol; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 40 | struct xprt_ops; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 41 | struct proxy; |
| 42 | struct licounters; |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 43 | |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 44 | /* listener state */ |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 45 | enum { |
| 46 | LI_NEW = 0, /* not initialized yet */ |
| 47 | LI_INIT, /* all parameters filled in, but not assigned yet */ |
| 48 | LI_ASSIGNED, /* assigned to the protocol, but not listening yet */ |
| 49 | LI_PAUSED, /* listener was paused, it's bound but not listening */ |
| 50 | LI_LISTEN, /* started, listening but not enabled */ |
| 51 | LI_READY, /* started, listening and enabled */ |
| 52 | LI_FULL, /* reached its connection limit */ |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 53 | LI_LIMITED, /* transient state: limits have been reached, listener is queued */ |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 54 | }; |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 55 | |
| 56 | /* Listener transitions |
| 57 | * calloc() set() add_listener() bind() |
| 58 | * -------> NEW ----> INIT ----------> ASSIGNED -----> LISTEN |
| 59 | * <------- <---- <---------- <----- |
| 60 | * free() bzero() del_listener() unbind() |
| 61 | * |
| 62 | * The file descriptor is valid only during these three states : |
| 63 | * |
| 64 | * disable() |
| 65 | * LISTEN <------------ READY |
| 66 | * A| ------------> |A |
| 67 | * || !max & enable() || |
| 68 | * || || |
| 69 | * || max || |
| 70 | * || max & enable() V| !max |
| 71 | * |+---------------> FULL |
| 72 | * +----------------- |
| 73 | * disable() |
| 74 | * |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 75 | * The LIMITED state my be used when a limit has been detected just before |
| 76 | * using a listener. In this case, the listener MUST be queued into the |
| 77 | * appropriate wait queue (either the proxy's or the global one). It may be |
| 78 | * set back to the READY state at any instant and for any reason, so one must |
| 79 | * not rely on this state. |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 80 | */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 81 | |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 82 | /* listener socket options */ |
| 83 | #define LI_O_NONE 0x0000 |
| 84 | #define LI_O_NOLINGER 0x0001 /* disable linger on this socket */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 85 | #define LI_O_FOREIGN 0x0002 /* permit listening on foreing addresses */ |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 86 | #define LI_O_NOQUICKACK 0x0004 /* disable quick ack of immediate data (linux) */ |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 87 | #define LI_O_DEF_ACCEPT 0x0008 /* wait up to 1 second for data before accepting */ |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 88 | #define LI_O_TCP_RULES 0x0010 /* run TCP rules checks on the incoming connection */ |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 89 | #define LI_O_CHK_MONNET 0x0020 /* check the source against a monitor-net rule */ |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 90 | #define LI_O_ACC_PROXY 0x0040 /* find the proxied address in the first request line */ |
Willy Tarreau | 3c63fd8 | 2011-09-07 18:00:47 +0200 | [diff] [blame] | 91 | #define LI_O_UNLIMITED 0x0080 /* listener not subject to global limits (peers & stats socket) */ |
Willy Tarreau | 1c862c5 | 2012-10-05 16:21:00 +0200 | [diff] [blame] | 92 | #define LI_O_TCP_FO 0x0100 /* enable TCP Fast Open (linux >= 3.6) */ |
Willy Tarreau | 9b6700f | 2012-11-24 11:55:28 +0100 | [diff] [blame] | 93 | #define LI_O_V6ONLY 0x0200 /* bind to IPv6 only on Linux >= 2.4.21 */ |
Willy Tarreau | 77e3af9 | 2012-11-24 15:07:23 +0100 | [diff] [blame^] | 94 | #define LI_O_V4V6 0x0400 /* bind to IPv4/IPv6 on Linux >= 2.4.21 */ |
Willy Tarreau | 3c63fd8 | 2011-09-07 18:00:47 +0200 | [diff] [blame] | 95 | |
| 96 | /* Note: if a listener uses LI_O_UNLIMITED, it is highly recommended that it adds its own |
| 97 | * maxconn setting to the global.maxsock value so that its resources are reserved. |
| 98 | */ |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 99 | |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 100 | #ifdef USE_OPENSSL |
| 101 | /* bind_conf ssl options */ |
| 102 | #define BC_SSL_O_NONE 0x0000 |
| 103 | #define BC_SSL_O_NO_SSLV3 0x0001 /* disable SSLv3 */ |
| 104 | #define BC_SSL_O_NO_TLSV10 0x0002 /* disable TLSv10 */ |
| 105 | #define BC_SSL_O_NO_TLSV11 0x0004 /* disable TLSv11 */ |
| 106 | #define BC_SSL_O_NO_TLSV12 0x0008 /* disable TLSv12 */ |
| 107 | /* 0x000F reserved for 'no' protocol version options */ |
Emeric Brun | 2cb7ae5 | 2012-10-05 14:14:21 +0200 | [diff] [blame] | 108 | #define BC_SSL_O_USE_SSLV3 0x0010 /* force SSLv3 */ |
| 109 | #define BC_SSL_O_USE_TLSV10 0x0020 /* force TLSv10 */ |
| 110 | #define BC_SSL_O_USE_TLSV11 0x0040 /* force TLSv11 */ |
| 111 | #define BC_SSL_O_USE_TLSV12 0x0080 /* force TLSv12 */ |
| 112 | /* 0x00F0 reserved for 'force' protocol version options */ |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 113 | #define BC_SSL_O_NO_TLS_TICKETS 0x0100 /* disable session resumption tickets */ |
| 114 | #endif |
| 115 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 116 | /* "bind" line settings */ |
| 117 | struct bind_conf { |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 118 | #ifdef USE_OPENSSL |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 119 | char *ca_file; /* CAfile to use on verify */ |
Emeric Brun | 81c00f0 | 2012-09-21 14:31:21 +0200 | [diff] [blame] | 120 | unsigned long long ca_ignerr; /* ignored verify errors in handshake if depth > 0 */ |
| 121 | unsigned long long crt_ignerr; /* ignored verify errors in handshake if depth == 0 */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 122 | char *ciphers; /* cipher suite to use if non-null */ |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 123 | char *crl_file; /* CRLfile to use on verify */ |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 124 | char *ecdhe; /* named curve to use for ECDHE */ |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 125 | int ssl_options; /* ssl options */ |
Emeric Brun | d94b3fe | 2012-09-20 18:23:56 +0200 | [diff] [blame] | 126 | int verify; /* verify method (set of SSL_VERIFY_* flags) */ |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 127 | SSL_CTX *default_ctx; /* SSL context of first/default certificate */ |
Willy Tarreau | 6c9a3d5 | 2012-10-18 18:57:14 +0200 | [diff] [blame] | 128 | char *npn_str; /* NPN protocol string */ |
| 129 | int npn_len; /* NPN protocol string length */ |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 130 | struct eb_root sni_ctx; /* sni_ctx tree of all known certs full-names sorted by name */ |
| 131 | struct eb_root sni_w_ctx; /* sni_ctx tree of all known certs wildcards sorted by name */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 132 | #endif |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 133 | int is_ssl; /* SSL is required for these listeners */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 134 | struct { /* UNIX socket permissions */ |
| 135 | uid_t uid; /* -1 to leave unchanged */ |
| 136 | gid_t gid; /* -1 to leave unchanged */ |
| 137 | mode_t mode; /* 0 to leave unchanged */ |
| 138 | } ux; |
| 139 | int level; /* stats access level (ACCESS_LVL_*) */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 140 | struct list by_fe; /* next binding for the same frontend, or NULL */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 141 | struct list listeners; /* list of listeners using this bind config */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 142 | char *arg; /* argument passed to "bind" for better error reporting */ |
| 143 | char *file; /* file where the section appears */ |
| 144 | int line; /* line where the section appears */ |
| 145 | }; |
| 146 | |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 147 | /* The listener will be directly referenced by the fdtab[] which holds its |
| 148 | * socket. The listener provides the protocol-specific accept() function to |
| 149 | * the fdtab. |
| 150 | */ |
| 151 | struct listener { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 152 | enum obj_type obj_type; /* object type = OBJ_TYPE_LISTENER */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 153 | int fd; /* the listen socket */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 154 | char *name; /* */ |
| 155 | int luid; /* listener universally unique ID, used for SNMP */ |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 156 | int state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */ |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 157 | int options; /* socket options : LI_O_* */ |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 158 | struct licounters *counters; /* statistics counters */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 159 | struct protocol *proto; /* protocol this listener belongs to */ |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 160 | struct xprt_ops *xprt; /* transport-layer operations for this socket */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 161 | int nbconn; /* current number of connections on this listener */ |
| 162 | int maxconn; /* maximum connections allowed on this listener */ |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 163 | unsigned int backlog; /* if set, listen backlog */ |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 164 | unsigned int maxaccept; /* if set, max number of connections accepted at once */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 165 | struct list proto_list; /* list in the protocol header */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 166 | int (*accept)(struct listener *l, int fd, struct sockaddr_storage *addr); /* upper layer's accept() */ |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 167 | struct task * (*handler)(struct task *t); /* protocol handler. It is a task */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 168 | int *timeout; /* pointer to client-side timeout */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 169 | struct proxy *frontend; /* the frontend this listener belongs to, or NULL */ |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 170 | struct list wait_queue; /* link element to make the listener wait for something (LI_LIMITED) */ |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 171 | unsigned int analysers; /* bitmap of required protocol analysers */ |
Willy Tarreau | 2c9f5b1 | 2009-08-16 19:12:36 +0200 | [diff] [blame] | 172 | int nice; /* nice value to assign to the instanciated tasks */ |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 173 | char *interface; /* interface name or NULL */ |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 174 | int maxseg; /* for TCP, advertised MSS */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 175 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 176 | struct list by_fe; /* chaining in frontend's list of listeners */ |
| 177 | struct list by_bind; /* chaining in bind_conf's list of listeners */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 178 | struct bind_conf *bind_conf; /* "bind" line settings, include SSL settings among other things */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 179 | |
Willy Tarreau | 7b81563 | 2011-10-21 18:51:57 +0200 | [diff] [blame] | 180 | /* warning: this struct is huge, keep it at the bottom */ |
| 181 | struct sockaddr_storage addr; /* the address we listen to */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 182 | struct { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 183 | struct eb32_node id; /* place in the tree of used IDs */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 184 | } conf; /* config information */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 185 | }; |
| 186 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 187 | /* Descriptor for a "bind" keyword. The ->parse() function returns 0 in case of |
| 188 | * success, or a combination of ERR_* flags if an error is encountered. The |
| 189 | * function pointer can be NULL if not implemented. The function also has an |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 190 | * access to the current "bind" config line. The ->skip value tells the parser |
| 191 | * how many words have to be skipped after the keyword. |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 192 | */ |
| 193 | struct bind_kw { |
| 194 | const char *kw; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 195 | int (*parse)(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 196 | int skip; /* nb of args to skip */ |
| 197 | }; |
| 198 | |
| 199 | /* |
| 200 | * A keyword list. It is a NULL-terminated array of keywords. It embeds a |
| 201 | * struct list in order to be linked to other lists, allowing it to easily |
| 202 | * be declared where it is needed, and linked without duplicating data nor |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 203 | * allocating memory. It is also possible to indicate a scope for the keywords. |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 204 | */ |
| 205 | struct bind_kw_list { |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 206 | const char *scope; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 207 | struct list list; |
| 208 | struct bind_kw kw[VAR_ARRAY]; |
| 209 | }; |
| 210 | |
| 211 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 212 | #endif /* _TYPES_LISTENER_H */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Local variables: |
| 216 | * c-indent-level: 8 |
| 217 | * c-basic-offset: 8 |
| 218 | * End: |
| 219 | */ |