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 |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 29 | #include <haproxy/api-t.h> |
Willy Tarreau | 6019fab | 2020-05-27 16:26:00 +0200 | [diff] [blame] | 30 | #include <haproxy/openssl-compat.h> |
Emeric Brun | 0b8d4d9 | 2012-05-18 15:46:21 +0200 | [diff] [blame] | 31 | #endif |
| 32 | |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 33 | #include <haproxy/list-t.h> |
Christopher Faulet | 8d8aa0d | 2017-05-30 15:36:50 +0200 | [diff] [blame] | 34 | #include <common/hathreads.h> |
| 35 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 36 | #include <types/obj_type.h> |
Willy Tarreau | 8d2b777 | 2020-05-27 10:58:19 +0200 | [diff] [blame] | 37 | #include <import/eb32tree.h> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 39 | /* Some pointer types reference below */ |
| 40 | struct task; |
| 41 | struct protocol; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 42 | struct xprt_ops; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 43 | struct proxy; |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 44 | struct fe_counters; |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 45 | |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 46 | /* listener state */ |
Willy Tarreau | f6502c5 | 2013-12-06 21:18:49 +0100 | [diff] [blame] | 47 | enum li_state { |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 48 | LI_NEW = 0, /* not initialized yet */ |
| 49 | LI_INIT, /* all parameters filled in, but not assigned yet */ |
| 50 | LI_ASSIGNED, /* assigned to the protocol, but not listening yet */ |
| 51 | LI_PAUSED, /* listener was paused, it's bound but not listening */ |
Olivier Houchard | 1fc0516 | 2017-04-06 01:05:05 +0200 | [diff] [blame] | 52 | LI_ZOMBIE, /* The listener doesn't belong to the process, but is kept opened */ |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 53 | LI_LISTEN, /* started, listening but not enabled */ |
| 54 | LI_READY, /* started, listening and enabled */ |
| 55 | LI_FULL, /* reached its connection limit */ |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 56 | LI_LIMITED, /* transient state: limits have been reached, listener is queued */ |
Willy Tarreau | f6502c5 | 2013-12-06 21:18:49 +0100 | [diff] [blame] | 57 | } __attribute__((packed)); |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 58 | |
| 59 | /* Listener transitions |
| 60 | * calloc() set() add_listener() bind() |
| 61 | * -------> NEW ----> INIT ----------> ASSIGNED -----> LISTEN |
| 62 | * <------- <---- <---------- <----- |
| 63 | * free() bzero() del_listener() unbind() |
| 64 | * |
| 65 | * The file descriptor is valid only during these three states : |
| 66 | * |
| 67 | * disable() |
| 68 | * LISTEN <------------ READY |
| 69 | * A| ------------> |A |
| 70 | * || !max & enable() || |
| 71 | * || || |
| 72 | * || max || |
| 73 | * || max & enable() V| !max |
| 74 | * |+---------------> FULL |
| 75 | * +----------------- |
| 76 | * disable() |
| 77 | * |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 78 | * The LIMITED state my be used when a limit has been detected just before |
| 79 | * using a listener. In this case, the listener MUST be queued into the |
| 80 | * appropriate wait queue (either the proxy's or the global one). It may be |
| 81 | * set back to the READY state at any instant and for any reason, so one must |
| 82 | * not rely on this state. |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 83 | */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 84 | |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 85 | /* listener socket options */ |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 86 | #define LI_O_NONE 0x0000 |
| 87 | #define LI_O_NOLINGER 0x0001 /* disable linger on this socket */ |
Joseph Herlant | 75a323f | 2018-11-25 13:36:58 -0800 | [diff] [blame] | 88 | #define LI_O_FOREIGN 0x0002 /* permit listening on foreign addresses ("transparent") */ |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 89 | #define LI_O_NOQUICKACK 0x0004 /* disable quick ack of immediate data (linux) */ |
| 90 | #define LI_O_DEF_ACCEPT 0x0008 /* wait up to 1 second for data before accepting */ |
| 91 | #define LI_O_TCP_L4_RULES 0x0010 /* run TCP L4 rules checks on the incoming connection */ |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 92 | #define LI_O_TCP_L5_RULES 0x0020 /* run TCP L5 rules checks on the incoming session */ |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 93 | #define LI_O_CHK_MONNET 0x0040 /* check the source against a monitor-net rule */ |
| 94 | #define LI_O_ACC_PROXY 0x0080 /* find the proxied address in the first request line */ |
| 95 | #define LI_O_UNLIMITED 0x0100 /* listener not subject to global limits (peers & stats socket) */ |
| 96 | #define LI_O_TCP_FO 0x0200 /* enable TCP Fast Open (linux >= 3.7) */ |
| 97 | #define LI_O_V6ONLY 0x0400 /* bind to IPv6 only on Linux >= 2.4.21 */ |
| 98 | #define LI_O_V4V6 0x0800 /* bind to IPv4/IPv6 on Linux >= 2.4.21 */ |
| 99 | #define LI_O_ACC_CIP 0x1000 /* find the proxied address in the NetScaler Client IP header */ |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 100 | #define LI_O_INHERITED 0x2000 /* inherited FD from the parent process (fd@) */ |
William Lallemand | e22f11f | 2018-09-11 10:06:27 +0200 | [diff] [blame] | 101 | #define LI_O_MWORKER 0x4000 /* keep the FD open in the master but close it in the children */ |
William Lallemand | c59f988 | 2018-11-16 16:57:21 +0100 | [diff] [blame] | 102 | #define LI_O_NOSTOP 0x8000 /* keep the listener active even after a soft stop */ |
Willy Tarreau | 3c63fd8 | 2011-09-07 18:00:47 +0200 | [diff] [blame] | 103 | |
| 104 | /* Note: if a listener uses LI_O_UNLIMITED, it is highly recommended that it adds its own |
| 105 | * maxconn setting to the global.maxsock value so that its resources are reserved. |
| 106 | */ |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 107 | |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 108 | #ifdef USE_OPENSSL |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 109 | #define BC_SSL_O_NONE 0x0000 |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 110 | #define BC_SSL_O_NO_TLS_TICKETS 0x0100 /* disable session resumption tickets */ |
Lukas Tribus | 53ae85c | 2017-05-04 15:45:40 +0000 | [diff] [blame] | 111 | #define BC_SSL_O_PREF_CLIE_CIPH 0x0200 /* prefer client ciphers */ |
Emeric Brun | 8967549 | 2012-10-05 13:48:26 +0200 | [diff] [blame] | 112 | #endif |
| 113 | |
William Lallemand | c0cdaff | 2020-05-15 00:20:53 +0200 | [diff] [blame] | 114 | struct tls_version_filter { |
| 115 | uint16_t flags; /* ssl options */ |
| 116 | uint8_t min; /* min TLS version */ |
| 117 | uint8_t max; /* max TLS version */ |
| 118 | }; |
| 119 | |
Emmanuel Hocdet | 9826329 | 2016-12-29 18:26:15 +0100 | [diff] [blame] | 120 | /* ssl "bind" settings */ |
| 121 | struct ssl_bind_conf { |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 122 | #ifdef USE_OPENSSL |
Emmanuel Hocdet | 9826329 | 2016-12-29 18:26:15 +0100 | [diff] [blame] | 123 | #ifdef OPENSSL_NPN_NEGOTIATED |
| 124 | char *npn_str; /* NPN protocol string */ |
| 125 | int npn_len; /* NPN protocol string length */ |
| 126 | #endif |
| 127 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
| 128 | char *alpn_str; /* ALPN protocol string */ |
| 129 | int alpn_len; /* ALPN protocol string length */ |
| 130 | #endif |
Tim Duesterhus | 6a0dd73 | 2020-01-18 01:32:49 +0100 | [diff] [blame] | 131 | unsigned int verify:3; /* verify method (set of SSL_VERIFY_* flags) */ |
| 132 | unsigned int no_ca_names:1;/* do not send ca names to clients (ca_file related) */ |
| 133 | unsigned int early_data:1; /* early data allowed */ |
Emmanuel Hocdet | 842e94e | 2019-12-16 16:39:17 +0100 | [diff] [blame] | 134 | char *ca_file; /* CAfile to use on verify and ca-names */ |
| 135 | char *ca_verify_file; /* CAverify file to use on verify only */ |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 136 | char *crl_file; /* CRLfile to use on verify */ |
Emmanuel Hocdet | 9826329 | 2016-12-29 18:26:15 +0100 | [diff] [blame] | 137 | char *ciphers; /* cipher suite to use if non-null */ |
Willy Tarreau | 9a1ab08 | 2019-05-09 13:26:41 +0200 | [diff] [blame] | 138 | #if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER) |
Dirkjan Bussink | 415150f | 2018-09-14 11:14:21 +0200 | [diff] [blame] | 139 | char *ciphersuites; /* TLS 1.3 cipher suite to use if non-null */ |
| 140 | #endif |
Emmanuel Hocdet | e7f2b73 | 2017-01-09 16:15:54 +0100 | [diff] [blame] | 141 | char *curves; /* curves suite to use for ECDHE */ |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 142 | char *ecdhe; /* named curve to use for ECDHE */ |
William Lallemand | 8177ad9 | 2020-05-20 16:49:02 +0200 | [diff] [blame] | 143 | struct tls_version_filter ssl_methods_cfg; /* original ssl methods found in configuration */ |
| 144 | struct tls_version_filter ssl_methods; /* actual ssl methods used at runtime */ |
Emmanuel Hocdet | 9826329 | 2016-12-29 18:26:15 +0100 | [diff] [blame] | 145 | #endif |
| 146 | }; |
| 147 | |
| 148 | /* "bind" line settings */ |
| 149 | struct bind_conf { |
| 150 | #ifdef USE_OPENSSL |
| 151 | struct ssl_bind_conf ssl_conf; /* ssl conf for ctx setting */ |
| 152 | unsigned long long ca_ignerr; /* ignored verify errors in handshake if depth > 0 */ |
| 153 | unsigned long long crt_ignerr; /* ignored verify errors in handshake if depth == 0 */ |
Emmanuel Hocdet | f6b37c6 | 2017-03-06 15:34:44 +0100 | [diff] [blame] | 154 | SSL_CTX *initial_ctx; /* SSL context for initial negotiation */ |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 155 | SSL_CTX *default_ctx; /* SSL context of first/default certificate */ |
Emmanuel Hocdet | 9826329 | 2016-12-29 18:26:15 +0100 | [diff] [blame] | 156 | struct ssl_bind_conf *default_ssl_conf; /* custom SSL conf of default_ctx */ |
Emmanuel Hocdet | 6562337 | 2013-01-24 17:17:15 +0100 | [diff] [blame] | 157 | int strict_sni; /* refuse negotiation if sni doesn't match a certificate */ |
Emmanuel Hocdet | 4608ed9 | 2017-01-20 13:06:27 +0100 | [diff] [blame] | 158 | int ssl_options; /* ssl options */ |
William Lallemand | 150bfa8 | 2019-09-19 17:12:49 +0200 | [diff] [blame] | 159 | __decl_hathreads(HA_RWLOCK_T sni_lock); /* lock the SNI trees during add/del operations */ |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 160 | struct eb_root sni_ctx; /* sni_ctx tree of all known certs full-names sorted by name */ |
| 161 | struct eb_root sni_w_ctx; /* sni_ctx tree of all known certs wildcards sorted by name */ |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 162 | struct tls_keys_ref *keys_ref; /* TLS ticket keys reference */ |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 163 | |
| 164 | char *ca_sign_file; /* CAFile used to generate and sign server certificates */ |
| 165 | char *ca_sign_pass; /* CAKey passphrase */ |
| 166 | |
| 167 | X509 *ca_sign_cert; /* CA certificate referenced by ca_file */ |
| 168 | EVP_PKEY *ca_sign_pkey; /* CA private key referenced by ca_key */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 169 | #endif |
Willy Tarreau | c95bad5 | 2016-12-22 00:13:31 +0100 | [diff] [blame] | 170 | struct proxy *frontend; /* the frontend all these listeners belong to, or NULL */ |
Willy Tarreau | a004ae3 | 2018-12-02 13:03:57 +0100 | [diff] [blame] | 171 | const struct mux_proto_list *mux_proto; /* the mux to use for all incoming connections (specified by the "proto" keyword) */ |
Willy Tarreau | 71a8c7c | 2016-12-21 22:04:54 +0100 | [diff] [blame] | 172 | struct xprt_ops *xprt; /* transport-layer operations for all listeners */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 173 | int is_ssl; /* SSL is required for these listeners */ |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 174 | int generate_certs; /* 1 if generate-certificates option is set, else 0 */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 175 | int level; /* stats access level (ACCESS_LVL_*) */ |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 176 | int severity_output; /* default severity output format in cli feedback messages */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 177 | struct list listeners; /* list of listeners using this bind config */ |
Willy Tarreau | b2b50a7 | 2019-02-03 11:14:25 +0100 | [diff] [blame] | 178 | unsigned long bind_proc; /* bitmask of processes allowed to use these listeners */ |
| 179 | unsigned long bind_thread; /* bitmask of threads allowed to use these listeners */ |
Bertrand Jacquin | 93b227d | 2016-06-04 15:11:10 +0100 | [diff] [blame] | 180 | uint32_t ns_cip_magic; /* Excepted NetScaler Client IP magic number */ |
Willy Tarreau | b2b50a7 | 2019-02-03 11:14:25 +0100 | [diff] [blame] | 181 | struct list by_fe; /* next binding for the same frontend, or NULL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 182 | char *arg; /* argument passed to "bind" for better error reporting */ |
| 183 | char *file; /* file where the section appears */ |
| 184 | int line; /* line where the section appears */ |
Willy Tarreau | b2b50a7 | 2019-02-03 11:14:25 +0100 | [diff] [blame] | 185 | struct { /* UNIX socket permissions */ |
| 186 | uid_t uid; /* -1 to leave unchanged */ |
| 187 | gid_t gid; /* -1 to leave unchanged */ |
| 188 | mode_t mode; /* 0 to leave unchanged */ |
| 189 | } ux; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 190 | }; |
| 191 | |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 192 | /* The listener will be directly referenced by the fdtab[] which holds its |
| 193 | * socket. The listener provides the protocol-specific accept() function to |
| 194 | * the fdtab. |
| 195 | */ |
| 196 | struct listener { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 197 | enum obj_type obj_type; /* object type = OBJ_TYPE_LISTENER */ |
Willy Tarreau | f6502c5 | 2013-12-06 21:18:49 +0100 | [diff] [blame] | 198 | enum li_state state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */ |
Ilya Shipitsin | 856aabc | 2020-04-16 23:51:34 +0500 | [diff] [blame] | 199 | short int nice; /* nice value to assign to the instantiated tasks */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 200 | int fd; /* the listen socket */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 201 | int luid; /* listener universally unique ID, used for SNMP */ |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 202 | int options; /* socket options : LI_O_* */ |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 203 | struct fe_counters *counters; /* statistics counters */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 204 | struct protocol *proto; /* protocol this listener belongs to */ |
| 205 | int nbconn; /* current number of connections on this listener */ |
| 206 | int maxconn; /* maximum connections allowed on this listener */ |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 207 | unsigned int backlog; /* if set, listen backlog */ |
Christopher Faulet | 102854c | 2019-04-30 12:17:13 +0200 | [diff] [blame] | 208 | int maxaccept; /* if set, max number of connections accepted at once (-1 when disabled) */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 209 | int (*accept)(struct listener *l, int fd, struct sockaddr_storage *addr); /* upper layer's accept() */ |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 210 | enum obj_type *default_target; /* default target to use for accepted sessions or NULL */ |
Willy Tarreau | 4ed84c9 | 2019-02-03 10:28:24 +0100 | [diff] [blame] | 211 | /* cache line boundary */ |
Olivier Houchard | 859dc80 | 2019-08-08 15:47:21 +0200 | [diff] [blame] | 212 | struct mt_list wait_queue; /* link element to make the listener wait for something (LI_LIMITED) */ |
Willy Tarreau | 0cf3317 | 2019-03-06 15:26:33 +0100 | [diff] [blame] | 213 | unsigned int thr_idx; /* thread indexes for queue distribution : (t2<<16)+t1 */ |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 214 | unsigned int analysers; /* bitmap of required protocol analysers */ |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 215 | int maxseg; /* for TCP, advertised MSS */ |
Willy Tarreau | 2af207a | 2015-02-04 00:45:58 +0100 | [diff] [blame] | 216 | int tcp_ut; /* for TCP, user timeout */ |
Willy Tarreau | f6502c5 | 2013-12-06 21:18:49 +0100 | [diff] [blame] | 217 | char *interface; /* interface name or NULL */ |
Willy Tarreau | 4ed84c9 | 2019-02-03 10:28:24 +0100 | [diff] [blame] | 218 | char *name; /* listener's name */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 219 | |
Christopher Faulet | 9dcf9b6 | 2017-11-13 10:34:01 +0100 | [diff] [blame] | 220 | __decl_hathreads(HA_SPINLOCK_T lock); |
Christopher Faulet | 8d8aa0d | 2017-05-30 15:36:50 +0200 | [diff] [blame] | 221 | |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 222 | const struct netns_entry *netns; /* network namespace of the listener*/ |
| 223 | |
Willy Tarreau | 4ed84c9 | 2019-02-03 10:28:24 +0100 | [diff] [blame] | 224 | /* cache line boundary */ |
Willy Tarreau | 9e85318 | 2019-02-03 10:36:29 +0100 | [diff] [blame] | 225 | unsigned int thr_conn[MAX_THREADS]; /* number of connections per thread */ |
| 226 | |
| 227 | /* cache line boundary */ |
Willy Tarreau | 0cf3317 | 2019-03-06 15:26:33 +0100 | [diff] [blame] | 228 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 229 | struct list by_fe; /* chaining in frontend's list of listeners */ |
| 230 | struct list by_bind; /* chaining in bind_conf's list of listeners */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 231 | struct bind_conf *bind_conf; /* "bind" line settings, include SSL settings among other things */ |
Willy Tarreau | 4ed84c9 | 2019-02-03 10:28:24 +0100 | [diff] [blame] | 232 | struct list proto_list; /* list in the protocol header */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 233 | |
Willy Tarreau | 7b81563 | 2011-10-21 18:51:57 +0200 | [diff] [blame] | 234 | /* warning: this struct is huge, keep it at the bottom */ |
| 235 | struct sockaddr_storage addr; /* the address we listen to */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 236 | struct { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 237 | struct eb32_node id; /* place in the tree of used IDs */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 238 | } conf; /* config information */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 239 | }; |
| 240 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 241 | /* Descriptor for a "bind" keyword. The ->parse() function returns 0 in case of |
| 242 | * success, or a combination of ERR_* flags if an error is encountered. The |
| 243 | * 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] | 244 | * access to the current "bind" config line. The ->skip value tells the parser |
| 245 | * how many words have to be skipped after the keyword. |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 246 | */ |
| 247 | struct bind_kw { |
| 248 | const char *kw; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 249 | 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] | 250 | int skip; /* nb of args to skip */ |
| 251 | }; |
Emmanuel Hocdet | 9826329 | 2016-12-29 18:26:15 +0100 | [diff] [blame] | 252 | struct ssl_bind_kw { |
| 253 | const char *kw; |
| 254 | int (*parse)(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err); |
| 255 | int skip; /* nb of args to skip */ |
| 256 | }; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 257 | |
| 258 | /* |
| 259 | * A keyword list. It is a NULL-terminated array of keywords. It embeds a |
| 260 | * struct list in order to be linked to other lists, allowing it to easily |
| 261 | * be declared where it is needed, and linked without duplicating data nor |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 262 | * 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] | 263 | */ |
| 264 | struct bind_kw_list { |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 265 | const char *scope; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 266 | struct list list; |
| 267 | struct bind_kw kw[VAR_ARRAY]; |
| 268 | }; |
| 269 | |
| 270 | |
Olivier Houchard | f73629d | 2017-04-05 22:33:04 +0200 | [diff] [blame] | 271 | struct xfer_sock_list { |
| 272 | int fd; |
| 273 | char *iface; |
| 274 | char *namespace; |
| 275 | int options; /* socket options LI_O_* */ |
| 276 | struct xfer_sock_list *prev; |
| 277 | struct xfer_sock_list *next; |
| 278 | struct sockaddr_storage addr; |
| 279 | }; |
| 280 | |
Willy Tarreau | 1efafce | 2019-01-27 15:37:19 +0100 | [diff] [blame] | 281 | /* This is used to create the accept queue, optimized to be 64 bytes long. */ |
| 282 | struct accept_queue_entry { |
| 283 | struct listener *listener; // 8 bytes |
| 284 | int fd __attribute__((aligned(8))); // 4 bytes |
| 285 | int addr_len; // 4 bytes |
| 286 | |
| 287 | union { |
| 288 | sa_family_t family; // 2 bytes |
| 289 | struct sockaddr_in in; // 16 bytes |
| 290 | struct sockaddr_in6 in6; // 28 bytes |
| 291 | } addr; // this is normally 28 bytes |
| 292 | /* 20-bytes hole here */ |
| 293 | char pad0[0] __attribute((aligned(64))); |
| 294 | }; |
| 295 | |
| 296 | /* The per-thread accept queue ring, must be a power of two minus 1 */ |
| 297 | #define ACCEPT_QUEUE_SIZE ((1<<8) - 1) |
| 298 | |
| 299 | struct accept_queue_ring { |
| 300 | unsigned int head; |
| 301 | unsigned int tail; |
Willy Tarreau | 2bd65a7 | 2019-09-24 06:55:18 +0200 | [diff] [blame] | 302 | struct tasklet *tasklet; /* tasklet of the thread owning this ring */ |
Willy Tarreau | 1efafce | 2019-01-27 15:37:19 +0100 | [diff] [blame] | 303 | struct accept_queue_entry entry[ACCEPT_QUEUE_SIZE] __attribute((aligned(64))); |
| 304 | }; |
| 305 | |
| 306 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 307 | #endif /* _TYPES_LISTENER_H */ |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * Local variables: |
| 311 | * c-indent-level: 8 |
| 312 | * c-basic-offset: 8 |
| 313 | * End: |
| 314 | */ |