blob: 1ad017db8c1dc40357f0291ec898b7fbdeb641fa [file] [log] [blame]
Willy Tarreaudd815982007-10-16 12:25:14 +02001/*
Willy Tarreaud1d54542012-09-12 22:58:11 +02002 * Listener management functions.
Willy Tarreaudd815982007-10-16 12:25:14 +02003 *
Willy Tarreau0ccb7442013-01-07 22:54:17 +01004 * Copyright 2000-2013 Willy Tarreau <w@1wt.eu>
Willy Tarreaudd815982007-10-16 12:25:14 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Willy Tarreau44489252014-01-14 17:52:01 +010013#define _GNU_SOURCE
Willy Tarreau6ae1ba62014-05-07 19:01:58 +020014#include <ctype.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020015#include <errno.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020016#include <stdio.h>
17#include <string.h>
Willy Tarreau95ccdde2014-02-01 09:28:36 +010018#include <unistd.h>
19#include <fcntl.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020020
Willy Tarreaudcc048a2020-06-04 19:11:43 +020021#include <haproxy/acl.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020022#include <haproxy/api.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020023#include <haproxy/cfgparse.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020024#include <haproxy/connection.h>
Willy Tarreau8d366972020-05-27 16:10:29 +020025#include <haproxy/errors.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020026#include <haproxy/fd.h>
27#include <haproxy/freq_ctr.h>
Willy Tarreauf268ee82020-06-04 17:05:57 +020028#include <haproxy/global.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020029#include <haproxy/list.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020030#include <haproxy/listener.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020031#include <haproxy/log.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020032#include <haproxy/proto_sockpair.h>
33#include <haproxy/protocol-t.h>
34#include <haproxy/protocol.h>
35#include <haproxy/sample.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020036#include <haproxy/stream.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020037#include <haproxy/task.h>
Willy Tarreau92b4f132020-06-01 11:05:15 +020038#include <haproxy/time.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020039#include <haproxy/tools.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020040
Willy Tarreaub648d632007-10-28 22:13:50 +010041
Willy Tarreau26982662012-09-12 23:17:10 +020042/* List head of all known bind keywords */
43static struct bind_kw_list bind_keywords = {
44 .list = LIST_HEAD_INIT(bind_keywords.list)
45};
46
Willy Tarreaua1d97f82019-12-10 11:18:41 +010047/* list of the temporarily limited listeners because of lack of resource */
48static struct mt_list global_listener_queue = MT_LIST_HEAD_INIT(global_listener_queue);
49static struct task *global_listener_queue_task;
50static struct task *manage_global_listener_queue(struct task *t, void *context, unsigned short state);
51
52
Willy Tarreau1efafce2019-01-27 15:37:19 +010053#if defined(USE_THREAD)
54
55struct accept_queue_ring accept_queue_rings[MAX_THREADS] __attribute__((aligned(64))) = { };
56
57/* dequeue and process a pending connection from the local accept queue (single
58 * consumer). Returns the accepted fd or -1 if none was found. The listener is
59 * placed into *li. The address is copied into *addr for no more than *addr_len
60 * bytes, and the address length is returned into *addr_len.
61 */
62int accept_queue_pop_sc(struct accept_queue_ring *ring, struct listener **li, void *addr, int *addr_len)
63{
64 struct accept_queue_entry *e;
65 unsigned int pos, next;
66 struct listener *ptr;
67 int len;
68 int fd;
69
70 pos = ring->head;
71
72 if (pos == ring->tail)
73 return -1;
74
75 next = pos + 1;
76 if (next >= ACCEPT_QUEUE_SIZE)
77 next = 0;
78
79 e = &ring->entry[pos];
80
81 /* wait for the producer to update the listener's pointer */
82 while (1) {
83 ptr = e->listener;
84 __ha_barrier_load();
85 if (ptr)
86 break;
87 pl_cpu_relax();
88 }
89
90 fd = e->fd;
91 len = e->addr_len;
92 if (len > *addr_len)
93 len = *addr_len;
94
95 if (likely(len > 0))
96 memcpy(addr, &e->addr, len);
97
98 /* release the entry */
99 e->listener = NULL;
100
101 __ha_barrier_store();
102 ring->head = next;
103
104 *addr_len = len;
105 *li = ptr;
106
107 return fd;
108}
109
110
111/* tries to push a new accepted connection <fd> into ring <ring> for listener
112 * <li>, from address <addr> whose length is <addr_len>. Returns non-zero if it
113 * succeeds, or zero if the ring is full. Supports multiple producers.
114 */
115int accept_queue_push_mp(struct accept_queue_ring *ring, int fd,
116 struct listener *li, const void *addr, int addr_len)
117{
118 struct accept_queue_entry *e;
119 unsigned int pos, next;
120
121 pos = ring->tail;
122 do {
123 next = pos + 1;
124 if (next >= ACCEPT_QUEUE_SIZE)
125 next = 0;
126 if (next == ring->head)
127 return 0; // ring full
Olivier Houchard64213e92019-03-08 18:52:57 +0100128 } while (unlikely(!_HA_ATOMIC_CAS(&ring->tail, &pos, next)));
Willy Tarreau1efafce2019-01-27 15:37:19 +0100129
130
131 e = &ring->entry[pos];
132
133 if (addr_len > sizeof(e->addr))
134 addr_len = sizeof(e->addr);
135
136 if (addr_len)
137 memcpy(&e->addr, addr, addr_len);
138
139 e->addr_len = addr_len;
140 e->fd = fd;
141
142 __ha_barrier_store();
143 /* now commit the change */
144
145 e->listener = li;
146 return 1;
147}
148
149/* proceed with accepting new connections */
150static struct task *accept_queue_process(struct task *t, void *context, unsigned short state)
151{
152 struct accept_queue_ring *ring = context;
153 struct listener *li;
154 struct sockaddr_storage addr;
Christopher Faulet102854c2019-04-30 12:17:13 +0200155 unsigned int max_accept;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100156 int addr_len;
157 int ret;
158 int fd;
159
Christopher Faulet102854c2019-04-30 12:17:13 +0200160 /* if global.tune.maxaccept is -1, then max_accept is UINT_MAX. It
161 * is not really illimited, but it is probably enough.
162 */
163 max_accept = global.tune.maxaccept ? global.tune.maxaccept : 64;
164 for (; max_accept; max_accept--) {
Willy Tarreau1efafce2019-01-27 15:37:19 +0100165 addr_len = sizeof(addr);
166 fd = accept_queue_pop_sc(ring, &li, &addr, &addr_len);
167 if (fd < 0)
168 break;
169
Olivier Houchard64213e92019-03-08 18:52:57 +0100170 _HA_ATOMIC_ADD(&li->thr_conn[tid], 1);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100171 ret = li->accept(li, fd, &addr);
172 if (ret <= 0) {
173 /* connection was terminated by the application */
174 continue;
175 }
176
177 /* increase the per-process number of cumulated sessions, this
178 * may only be done once l->accept() has accepted the connection.
179 */
180 if (!(li->options & LI_O_UNLIMITED)) {
181 HA_ATOMIC_UPDATE_MAX(&global.sps_max,
182 update_freq_ctr(&global.sess_per_sec, 1));
183 if (li->bind_conf && li->bind_conf->is_ssl) {
184 HA_ATOMIC_UPDATE_MAX(&global.ssl_max,
185 update_freq_ctr(&global.ssl_per_sec, 1));
186 }
187 }
188 }
189
190 /* ran out of budget ? Let's come here ASAP */
Christopher Faulet102854c2019-04-30 12:17:13 +0200191 if (!max_accept)
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200192 tasklet_wakeup(ring->tasklet);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100193
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200194 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100195}
196
197/* Initializes the accept-queues. Returns 0 on success, otherwise ERR_* flags */
198static int accept_queue_init()
199{
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200200 struct tasklet *t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100201 int i;
202
203 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200204 t = tasklet_new();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100205 if (!t) {
206 ha_alert("Out of memory while initializing accept queue for thread %d\n", i);
207 return ERR_FATAL|ERR_ABORT;
208 }
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200209 t->tid = i;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100210 t->process = accept_queue_process;
211 t->context = &accept_queue_rings[i];
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200212 accept_queue_rings[i].tasklet = t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100213 }
214 return 0;
215}
216
217REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
218
219#endif // USE_THREAD
220
Willy Tarreaua37b2442020-09-24 07:23:45 +0200221/* adjust the listener's state */
222void listener_set_state(struct listener *l, enum li_state st)
223{
224 l->state = st;
225}
226
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100227/* This function adds the specified listener's file descriptor to the polling
228 * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500229 * LI_FULL state depending on its number of connections. In daemon mode, we
Willy Tarreauae302532014-05-07 19:22:24 +0200230 * also support binding only the relevant processes to their respective
231 * listeners. We don't do that in debug mode however.
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100232 */
Christopher Fauletf5b8adc2017-06-02 10:00:35 +0200233static void enable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100234{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100235 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100236 if (listener->state == LI_LISTEN) {
William Lallemand095ba4c2017-06-01 17:38:50 +0200237 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau818a92e2020-09-03 07:50:19 +0200238 !(proc_mask(listener->rx.settings->bind_proc) & pid_bit)) {
Willy Tarreauae302532014-05-07 19:22:24 +0200239 /* we don't want to enable this listener and don't
240 * want any fd event to reach it.
241 */
Olivier Houchard1fc05162017-04-06 01:05:05 +0200242 if (!(global.tune.options & GTUNE_SOCKET_TRANSFER))
Christopher Faulet510c0d62018-03-16 10:04:47 +0100243 do_unbind_listener(listener, 1);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200244 else {
Christopher Faulet510c0d62018-03-16 10:04:47 +0100245 do_unbind_listener(listener, 0);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200246 listener_set_state(listener, LI_LISTEN);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200247 }
Willy Tarreauae302532014-05-07 19:22:24 +0200248 }
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100249 else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
Willy Tarreau38ba6472020-08-27 08:16:52 +0200250 fd_want_recv(listener->rx.fd);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200251 listener_set_state(listener, LI_READY);
Willy Tarreauae302532014-05-07 19:22:24 +0200252 }
253 else {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200254 listener_set_state(listener, LI_FULL);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100255 }
256 }
William Lallemande22f11f2018-09-11 10:06:27 +0200257 /* if this listener is supposed to be only in the master, close it in the workers */
258 if ((global.mode & MODE_MWORKER) &&
259 (listener->options & LI_O_MWORKER) &&
260 master == 0) {
261 do_unbind_listener(listener, 1);
262 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100263 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100264}
265
266/* This function removes the specified listener's file descriptor from the
267 * polling lists if it is in the LI_READY or in the LI_FULL state. The listener
268 * enters LI_LISTEN.
269 */
Christopher Fauletf5b8adc2017-06-02 10:00:35 +0200270static void disable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100271{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100272 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100273 if (listener->state < LI_READY)
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200274 goto end;
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100275 if (listener->state == LI_READY)
Willy Tarreau38ba6472020-08-27 08:16:52 +0200276 fd_stop_recv(listener->rx.fd);
Olivier Houchard859dc802019-08-08 15:47:21 +0200277 MT_LIST_DEL(&listener->wait_queue);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200278 listener_set_state(listener, LI_LISTEN);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200279 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100280 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100281}
282
Willy Tarreaube58c382011-07-24 18:28:10 +0200283/* This function tries to temporarily disable a listener, depending on the OS
284 * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
285 * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
286 * closes upon SHUT_WR and refuses to rebind. So a common validation path
287 * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling
288 * is disabled. It normally returns non-zero, unless an error is reported.
289 */
290int pause_listener(struct listener *l)
291{
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200292 int ret = 1;
293
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100294 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200295
Willy Tarreau02e19752020-09-23 17:17:22 +0200296 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
297 !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
298 goto end;
299
Willy Tarreaub7436612020-08-28 19:51:44 +0200300 if (l->rx.proto->pause) {
Willy Tarreau092d8652014-07-07 20:22:12 +0200301 /* Returns < 0 in case of failure, 0 if the listener
302 * was totally stopped, or > 0 if correctly paused.
303 */
Willy Tarreaub7436612020-08-28 19:51:44 +0200304 int ret = l->rx.proto->pause(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200305
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200306 if (ret < 0) {
307 ret = 0;
308 goto end;
309 }
Willy Tarreau092d8652014-07-07 20:22:12 +0200310 else if (ret == 0)
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200311 goto end;
Willy Tarreaub3fb60b2012-10-04 08:56:31 +0200312 }
Willy Tarreaube58c382011-07-24 18:28:10 +0200313
Olivier Houchard859dc802019-08-08 15:47:21 +0200314 MT_LIST_DEL(&l->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200315
Willy Tarreau38ba6472020-08-27 08:16:52 +0200316 fd_stop_recv(l->rx.fd);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200317 listener_set_state(l, LI_PAUSED);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200318 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100319 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200320 return ret;
Willy Tarreaube58c382011-07-24 18:28:10 +0200321}
322
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200323/* This function tries to resume a temporarily disabled listener. Paused, full,
324 * limited and disabled listeners are handled, which means that this function
325 * may replace enable_listener(). The resulting state will either be LI_READY
326 * or LI_FULL. 0 is returned in case of failure to resume (eg: dead socket).
Willy Tarreauae302532014-05-07 19:22:24 +0200327 * Listeners bound to a different process are not woken up unless we're in
Willy Tarreauaf2fd582015-04-14 12:07:16 +0200328 * foreground mode, and are ignored. If the listener was only in the assigned
329 * state, it's totally rebound. This can happen if a pause() has completely
330 * stopped it. If the resume fails, 0 is returned and an error might be
331 * displayed.
Willy Tarreaube58c382011-07-24 18:28:10 +0200332 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100333int resume_listener(struct listener *l)
Willy Tarreaube58c382011-07-24 18:28:10 +0200334{
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200335 int ret = 1;
336
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100337 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200338
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200339 /* check that another thread didn't to the job in parallel (e.g. at the
340 * end of listen_accept() while we'd come from dequeue_all_listeners().
341 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200342 if (MT_LIST_ADDED(&l->wait_queue))
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200343 goto end;
344
William Lallemand095ba4c2017-06-01 17:38:50 +0200345 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau818a92e2020-09-03 07:50:19 +0200346 !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200347 goto end;
Willy Tarreau3569df32017-03-15 12:47:46 +0100348
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200349 if (l->state == LI_ASSIGNED) {
350 char msg[100];
351 int err;
352
Willy Tarreaub3580b12020-09-01 10:26:22 +0200353 err = l->rx.proto->listen(l, msg, sizeof(msg));
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200354 if (err & ERR_ALERT)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100355 ha_alert("Resuming listener: %s\n", msg);
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200356 else if (err & ERR_WARN)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100357 ha_warning("Resuming listener: %s\n", msg);
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200358
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200359 if (err & (ERR_FATAL | ERR_ABORT)) {
360 ret = 0;
361 goto end;
362 }
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200363 }
364
Willy Tarreauc6dac6c2020-09-23 17:34:22 +0200365 if (l->state < LI_PAUSED) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200366 ret = 0;
367 goto end;
368 }
Willy Tarreaube58c382011-07-24 18:28:10 +0200369
Willy Tarreaub7436612020-08-28 19:51:44 +0200370 if (l->rx.proto->sock_prot == IPPROTO_TCP &&
Willy Tarreaub3fb60b2012-10-04 08:56:31 +0200371 l->state == LI_PAUSED &&
Willy Tarreau38ba6472020-08-27 08:16:52 +0200372 listen(l->rx.fd, listener_backlog(l)) != 0) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200373 ret = 0;
374 goto end;
375 }
Willy Tarreaube58c382011-07-24 18:28:10 +0200376
377 if (l->state == LI_READY)
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200378 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200379
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100380 if (l->maxconn && l->nbconn >= l->maxconn) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200381 listener_set_state(l, LI_FULL);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200382 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200383 }
384
Willy Tarreau38ba6472020-08-27 08:16:52 +0200385 fd_want_recv(l->rx.fd);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200386 listener_set_state(l, LI_READY);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200387 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100388 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200389 return ret;
390}
391
Willy Tarreau87b09662015-04-03 00:22:06 +0200392/* Marks a ready listener as full so that the stream code tries to re-enable
Willy Tarreau62793712011-07-24 19:23:38 +0200393 * it upon next close() using resume_listener().
394 */
Christopher Faulet5580ba22017-08-28 15:29:20 +0200395static void listener_full(struct listener *l)
Willy Tarreau62793712011-07-24 19:23:38 +0200396{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100397 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200398 if (l->state >= LI_READY) {
Olivier Houchard859dc802019-08-08 15:47:21 +0200399 MT_LIST_DEL(&l->wait_queue);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100400 if (l->state != LI_FULL) {
Willy Tarreau38ba6472020-08-27 08:16:52 +0200401 fd_stop_recv(l->rx.fd);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200402 listener_set_state(l, LI_FULL);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100403 }
Willy Tarreau62793712011-07-24 19:23:38 +0200404 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100405 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200406}
407
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200408/* Marks a ready listener as limited so that we only try to re-enable it when
409 * resources are free again. It will be queued into the specified queue.
410 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200411static void limit_listener(struct listener *l, struct mt_list *list)
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200412{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100413 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200414 if (l->state == LI_READY) {
Willy Tarreaude4db172020-07-10 08:10:29 +0200415 MT_LIST_TRY_ADDQ(list, &l->wait_queue);
Willy Tarreau38ba6472020-08-27 08:16:52 +0200416 fd_stop_recv(l->rx.fd);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200417 listener_set_state(l, LI_LIMITED);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200418 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100419 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200420}
421
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100422/* This function adds all of the protocol's listener's file descriptors to the
423 * polling lists when they are in the LI_LISTEN state. It is intended to be
424 * used as a protocol's generic enable_all() primitive, for use after the
425 * fork(). It puts the listeners into LI_READY or LI_FULL states depending on
426 * their number of connections. It always returns ERR_NONE.
Willy Tarreaudaacf362019-07-24 16:45:02 +0200427 *
428 * Must be called with proto_lock held.
429 *
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100430 */
431int enable_all_listeners(struct protocol *proto)
432{
433 struct listener *listener;
434
Willy Tarreaub7436612020-08-28 19:51:44 +0200435 list_for_each_entry(listener, &proto->listeners, rx.proto_list)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100436 enable_listener(listener);
437 return ERR_NONE;
438}
439
440/* This function removes all of the protocol's listener's file descriptors from
441 * the polling lists when they are in the LI_READY or LI_FULL states. It is
442 * intended to be used as a protocol's generic disable_all() primitive. It puts
443 * the listeners into LI_LISTEN, and always returns ERR_NONE.
Willy Tarreaudaacf362019-07-24 16:45:02 +0200444 *
445 * Must be called with proto_lock held.
446 *
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100447 */
448int disable_all_listeners(struct protocol *proto)
449{
450 struct listener *listener;
451
Willy Tarreaub7436612020-08-28 19:51:44 +0200452 list_for_each_entry(listener, &proto->listeners, rx.proto_list)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100453 disable_listener(listener);
454 return ERR_NONE;
455}
456
Willy Tarreau241797a2019-12-10 14:10:52 +0100457/* Dequeues all listeners waiting for a resource the global wait queue */
458void dequeue_all_listeners()
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200459{
Willy Tarreau01abd022019-02-28 10:27:18 +0100460 struct listener *listener;
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200461
Willy Tarreau241797a2019-12-10 14:10:52 +0100462 while ((listener = MT_LIST_POP(&global_listener_queue, struct listener *, wait_queue))) {
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200463 /* This cannot fail because the listeners are by definition in
Willy Tarreau01abd022019-02-28 10:27:18 +0100464 * the LI_LIMITED state.
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200465 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100466 resume_listener(listener);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200467 }
468}
469
Willy Tarreau241797a2019-12-10 14:10:52 +0100470/* Dequeues all listeners waiting for a resource in proxy <px>'s queue */
471void dequeue_proxy_listeners(struct proxy *px)
472{
473 struct listener *listener;
474
475 while ((listener = MT_LIST_POP(&px->listener_queue, struct listener *, wait_queue))) {
476 /* This cannot fail because the listeners are by definition in
477 * the LI_LIMITED state.
478 */
479 resume_listener(listener);
480 }
481}
482
Christopher Faulet510c0d62018-03-16 10:04:47 +0100483/* Must be called with the lock held. Depending on <do_close> value, it does
Willy Tarreaub6607bf2020-09-23 16:24:23 +0200484 * what unbind_listener or unbind_listener_no_close should do. It can also
485 * close a zombie listener's FD when called in early states.
Christopher Faulet510c0d62018-03-16 10:04:47 +0100486 */
487void do_unbind_listener(struct listener *listener, int do_close)
Willy Tarreaub648d632007-10-28 22:13:50 +0100488{
Olivier Houcharda5188562019-03-08 15:35:42 +0100489 if (listener->state == LI_READY && fd_updt)
Willy Tarreau38ba6472020-08-27 08:16:52 +0200490 fd_stop_recv(listener->rx.fd);
Willy Tarreaub648d632007-10-28 22:13:50 +0100491
Olivier Houchard859dc802019-08-08 15:47:21 +0200492 MT_LIST_DEL(&listener->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200493
Willy Tarreaube58c382011-07-24 18:28:10 +0200494 if (listener->state >= LI_PAUSED) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200495 listener_set_state(listener, LI_ASSIGNED);
Willy Tarreau38ba6472020-08-27 08:16:52 +0200496 fd_stop_both(listener->rx.fd);
Willy Tarreaub6607bf2020-09-23 16:24:23 +0200497 }
498
499 if (do_close && listener->rx.fd != -1) {
500 fd_delete(listener->rx.fd);
501 listener->rx.flags &= ~RX_F_BOUND;
502 listener->rx.fd = -1;
Willy Tarreaub648d632007-10-28 22:13:50 +0100503 }
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100504}
505
Olivier Houchard1fc05162017-04-06 01:05:05 +0200506/* This function closes the listening socket for the specified listener,
507 * provided that it's already in a listening state. The listener enters the
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100508 * LI_ASSIGNED state. This function is intended to be used as a generic
509 * function for standard protocols.
Olivier Houchard1fc05162017-04-06 01:05:05 +0200510 */
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100511void unbind_listener(struct listener *listener)
Olivier Houchard1fc05162017-04-06 01:05:05 +0200512{
Christopher Faulet510c0d62018-03-16 10:04:47 +0100513 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100514 do_unbind_listener(listener, 1);
Christopher Faulet510c0d62018-03-16 10:04:47 +0100515 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200516}
517
518/* This function pretends the listener is dead, but keeps the FD opened, so
519 * that we can provide it, for conf reloading.
520 */
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100521void unbind_listener_no_close(struct listener *listener)
Olivier Houchard1fc05162017-04-06 01:05:05 +0200522{
Christopher Faulet510c0d62018-03-16 10:04:47 +0100523 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100524 do_unbind_listener(listener, 0);
Christopher Faulet510c0d62018-03-16 10:04:47 +0100525 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200526}
527
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200528/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
529 * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200530 * allocation). The address family is taken from ss->ss_family, and the protocol
531 * passed in <proto> must be usable on this family. The number of jobs and
532 * listeners is automatically increased by the number of listeners created. It
533 * returns non-zero on success, zero on error with the error message set in <err>.
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200534 */
535int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200536 int portl, int porth, int fd, struct protocol *proto, char **err)
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200537{
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200538 struct listener *l;
539 int port;
540
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200541 for (port = portl; port <= porth; port++) {
542 l = calloc(1, sizeof(*l));
543 if (!l) {
544 memprintf(err, "out of memory");
545 return 0;
546 }
547 l->obj_type = OBJ_TYPE_LISTENER;
548 LIST_ADDQ(&bc->frontend->conf.listeners, &l->by_fe);
549 LIST_ADDQ(&bc->listeners, &l->by_bind);
550 l->bind_conf = bc;
Willy Tarreau0fce6bc2020-09-03 07:46:06 +0200551 l->rx.settings = &bc->settings;
Willy Tarreaueef45422020-09-03 10:05:03 +0200552 l->rx.owner = l;
Willy Tarreau38ba6472020-08-27 08:16:52 +0200553 l->rx.fd = fd;
Willy Tarreau37159062020-08-27 07:48:42 +0200554 memcpy(&l->rx.addr, ss, sizeof(*ss));
Olivier Houchard859dc802019-08-08 15:47:21 +0200555 MT_LIST_INIT(&l->wait_queue);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200556 listener_set_state(l, LI_INIT);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200557
558 proto->add(l, port);
559
Willy Tarreau909c23b2020-09-15 13:50:58 +0200560 if (fd != -1)
Willy Tarreau43046fa2020-09-01 15:41:59 +0200561 l->rx.flags |= RX_F_INHERITED;
William Lallemand75ea0a02017-11-15 19:02:58 +0100562
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100563 HA_SPIN_INIT(&l->lock);
Olivier Houchard64213e92019-03-08 18:52:57 +0100564 _HA_ATOMIC_ADD(&jobs, 1);
565 _HA_ATOMIC_ADD(&listeners, 1);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200566 }
567 return 1;
568}
569
Willy Tarreau1a64d162007-10-28 22:26:05 +0100570/* Delete a listener from its protocol's list of listeners. The listener's
571 * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
Willy Tarreau2cc5bae2017-09-15 08:18:11 +0200572 * number of listeners is updated, as well as the global number of listeners
573 * and jobs. Note that the listener must have previously been unbound. This
574 * is the generic function to use to remove a listener.
Willy Tarreaudaacf362019-07-24 16:45:02 +0200575 *
576 * Will grab the proto_lock.
577 *
Willy Tarreau1a64d162007-10-28 22:26:05 +0100578 */
579void delete_listener(struct listener *listener)
580{
Willy Tarreau6ee9f8d2019-08-26 10:55:52 +0200581 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100582 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100583 if (listener->state == LI_ASSIGNED) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200584 listener_set_state(listener, LI_INIT);
Willy Tarreaub7436612020-08-28 19:51:44 +0200585 LIST_DEL(&listener->rx.proto_list);
586 listener->rx.proto->nb_listeners--;
Olivier Houchard64213e92019-03-08 18:52:57 +0100587 _HA_ATOMIC_SUB(&jobs, 1);
588 _HA_ATOMIC_SUB(&listeners, 1);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100589 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100590 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau6ee9f8d2019-08-26 10:55:52 +0200591 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
Willy Tarreau1a64d162007-10-28 22:26:05 +0100592}
593
Willy Tarreaue2711c72019-02-27 15:39:41 +0100594/* Returns a suitable value for a listener's backlog. It uses the listener's,
595 * otherwise the frontend's backlog, otherwise the listener's maxconn,
596 * otherwise the frontend's maxconn, otherwise 1024.
597 */
598int listener_backlog(const struct listener *l)
599{
600 if (l->backlog)
601 return l->backlog;
602
603 if (l->bind_conf->frontend->backlog)
604 return l->bind_conf->frontend->backlog;
605
606 if (l->maxconn)
607 return l->maxconn;
608
609 if (l->bind_conf->frontend->maxconn)
610 return l->bind_conf->frontend->maxconn;
611
612 return 1024;
613}
614
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200615/* This function is called on a read event from a listening socket, corresponding
616 * to an accept. It tries to accept as many connections as possible, and for each
617 * calls the listener's accept handler (generally the frontend's accept handler).
618 */
Willy Tarreauafad0e02012-08-09 14:45:22 +0200619void listener_accept(int fd)
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200620{
621 struct listener *l = fdtab[fd].owner;
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100622 struct proxy *p;
Christopher Faulet102854c2019-04-30 12:17:13 +0200623 unsigned int max_accept;
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100624 int next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100625 int next_feconn = 0;
626 int next_actconn = 0;
Willy Tarreaubb660302014-05-07 19:47:02 +0200627 int expire;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200628 int cfd;
629 int ret;
Willy Tarreau818dca52014-01-31 19:40:19 +0100630#ifdef USE_ACCEPT4
631 static int accept4_broken;
632#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200633
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100634 if (!l)
635 return;
636 p = l->bind_conf->frontend;
Christopher Faulet102854c2019-04-30 12:17:13 +0200637
638 /* if l->maxaccept is -1, then max_accept is UINT_MAX. It is not really
639 * illimited, but it is probably enough.
640 */
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100641 max_accept = l->maxaccept ? l->maxaccept : 1;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200642
Willy Tarreau93e7c002013-10-07 18:51:07 +0200643 if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
644 int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
Willy Tarreau93e7c002013-10-07 18:51:07 +0200645
646 if (unlikely(!max)) {
647 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200648 expire = tick_add(now_ms, next_event_delay(&global.sess_per_sec, global.sps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100649 goto limit_global;
Willy Tarreau93e7c002013-10-07 18:51:07 +0200650 }
651
652 if (max_accept > max)
653 max_accept = max;
654 }
655
656 if (!(l->options & LI_O_UNLIMITED) && global.cps_lim) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200657 int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
658
659 if (unlikely(!max)) {
660 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200661 expire = tick_add(now_ms, next_event_delay(&global.conn_per_sec, global.cps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100662 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200663 }
664
665 if (max_accept > max)
666 max_accept = max;
667 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200668#ifdef USE_OPENSSL
669 if (!(l->options & LI_O_UNLIMITED) && global.ssl_lim && l->bind_conf && l->bind_conf->is_ssl) {
670 int max = freq_ctr_remain(&global.ssl_per_sec, global.ssl_lim, 0);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200671
Willy Tarreaue43d5322013-10-07 20:01:52 +0200672 if (unlikely(!max)) {
673 /* frontend accept rate limit was reached */
Willy Tarreaue43d5322013-10-07 20:01:52 +0200674 expire = tick_add(now_ms, next_event_delay(&global.ssl_per_sec, global.ssl_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100675 goto limit_global;
Willy Tarreaue43d5322013-10-07 20:01:52 +0200676 }
677
678 if (max_accept > max)
679 max_accept = max;
680 }
681#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200682 if (p && p->fe_sps_lim) {
683 int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0);
684
685 if (unlikely(!max)) {
686 /* frontend accept rate limit was reached */
Willy Tarreau0591bf72019-12-10 12:01:21 +0100687 expire = tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0));
688 goto limit_proxy;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200689 }
690
691 if (max_accept > max)
692 max_accept = max;
693 }
694
695 /* Note: if we fail to allocate a connection because of configured
696 * limits, we'll schedule a new attempt worst 1 second later in the
697 * worst case. If we fail due to system limits or temporary resource
698 * shortage, we try again 100ms later in the worst case.
699 */
Christopher Faulet102854c2019-04-30 12:17:13 +0200700 for (; max_accept; next_conn = next_feconn = next_actconn = 0, max_accept--) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200701 struct sockaddr_storage addr;
702 socklen_t laddr = sizeof(addr);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200703 unsigned int count;
Willy Tarreauaf613e82020-06-05 08:40:51 +0200704 __decl_thread(unsigned long mask);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200705
Willy Tarreau82c97892019-02-27 19:32:32 +0100706 /* pre-increase the number of connections without going too far.
707 * We process the listener, then the proxy, then the process.
708 * We know which ones to unroll based on the next_xxx value.
709 */
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100710 do {
711 count = l->nbconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100712 if (unlikely(l->maxconn && count >= l->maxconn)) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100713 /* the listener was marked full or another
714 * thread is going to do it.
715 */
716 next_conn = 0;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100717 listener_full(l);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100718 goto end;
719 }
720 next_conn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000721 } while (!_HA_ATOMIC_CAS(&l->nbconn, (int *)(&count), next_conn));
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100722
Willy Tarreau82c97892019-02-27 19:32:32 +0100723 if (p) {
724 do {
725 count = p->feconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100726 if (unlikely(count >= p->maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100727 /* the frontend was marked full or another
728 * thread is going to do it.
729 */
730 next_feconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100731 expire = TICK_ETERNITY;
732 goto limit_proxy;
Willy Tarreau82c97892019-02-27 19:32:32 +0100733 }
734 next_feconn = count + 1;
Olivier Houchard64213e92019-03-08 18:52:57 +0100735 } while (!_HA_ATOMIC_CAS(&p->feconn, &count, next_feconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200736 }
737
Willy Tarreau82c97892019-02-27 19:32:32 +0100738 if (!(l->options & LI_O_UNLIMITED)) {
739 do {
740 count = actconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100741 if (unlikely(count >= global.maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100742 /* the process was marked full or another
743 * thread is going to do it.
744 */
745 next_actconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100746 expire = tick_add(now_ms, 1000); /* try again in 1 second */
747 goto limit_global;
Willy Tarreau82c97892019-02-27 19:32:32 +0100748 }
749 next_actconn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000750 } while (!_HA_ATOMIC_CAS(&actconn, (int *)(&count), next_actconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200751 }
752
William Lallemand2fe7dd02018-09-11 16:51:29 +0200753 /* with sockpair@ we don't want to do an accept */
Willy Tarreau37159062020-08-27 07:48:42 +0200754 if (unlikely(l->rx.addr.ss_family == AF_CUST_SOCKPAIR)) {
William Lallemand2fe7dd02018-09-11 16:51:29 +0200755 if ((cfd = recv_fd_uxst(fd)) != -1)
William Lallemandd9138002018-11-27 12:02:39 +0100756 fcntl(cfd, F_SETFL, O_NONBLOCK);
Willy Tarreau888d5672019-01-27 18:34:12 +0100757 /* just like with UNIX sockets, only the family is filled */
758 addr.ss_family = AF_UNIX;
759 laddr = sizeof(addr.ss_family);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200760 } else
761
Willy Tarreau1bc4aab2012-10-08 20:11:03 +0200762#ifdef USE_ACCEPT4
Willy Tarreau818dca52014-01-31 19:40:19 +0100763 /* only call accept4() if it's known to be safe, otherwise
764 * fallback to the legacy accept() + fcntl().
765 */
766 if (unlikely(accept4_broken ||
William Lallemandd9138002018-11-27 12:02:39 +0100767 ((cfd = accept4(fd, (struct sockaddr *)&addr, &laddr, SOCK_NONBLOCK)) == -1 &&
Willy Tarreau818dca52014-01-31 19:40:19 +0100768 (errno == ENOSYS || errno == EINVAL || errno == EBADF) &&
769 (accept4_broken = 1))))
770#endif
Willy Tarreau6b3b0d42012-10-22 19:32:55 +0200771 if ((cfd = accept(fd, (struct sockaddr *)&addr, &laddr)) != -1)
William Lallemandd9138002018-11-27 12:02:39 +0100772 fcntl(cfd, F_SETFL, O_NONBLOCK);
Willy Tarreau818dca52014-01-31 19:40:19 +0100773
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200774 if (unlikely(cfd == -1)) {
775 switch (errno) {
776 case EAGAIN:
Willy Tarreau20aeb1c2019-12-10 08:42:21 +0100777 if (fdtab[fd].ev & (FD_POLL_HUP|FD_POLL_ERR)) {
Willy Tarreaubb660302014-05-07 19:47:02 +0200778 /* the listening socket might have been disabled in a shared
779 * process and we're a collateral victim. We'll just pause for
780 * a while in case it comes back. In the mean time, we need to
781 * clear this sticky flag.
782 */
Willy Tarreau20aeb1c2019-12-10 08:42:21 +0100783 _HA_ATOMIC_AND(&fdtab[fd].ev, ~(FD_POLL_HUP|FD_POLL_ERR));
Willy Tarreaubb660302014-05-07 19:47:02 +0200784 goto transient_error;
785 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200786 goto end; /* nothing more to accept */
Willy Tarreaubb660302014-05-07 19:47:02 +0200787 case EINVAL:
788 /* might be trying to accept on a shut fd (eg: soft stop) */
789 goto transient_error;
Willy Tarreaua593ec52014-01-20 21:21:30 +0100790 case EINTR:
791 case ECONNABORTED:
Olivier Houchard64213e92019-03-08 18:52:57 +0100792 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100793 if (p)
Olivier Houchard64213e92019-03-08 18:52:57 +0100794 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100795 if (!(l->options & LI_O_UNLIMITED))
Olivier Houchard64213e92019-03-08 18:52:57 +0100796 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreaua593ec52014-01-20 21:21:30 +0100797 continue;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200798 case ENFILE:
799 if (p)
800 send_log(p, LOG_EMERG,
Willy Tarreauc5532ac2018-01-29 15:06:04 +0100801 "Proxy %s reached system FD limit (maxsock=%d). Please check system tunables.\n",
802 p->id, global.maxsock);
Willy Tarreaubb660302014-05-07 19:47:02 +0200803 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200804 case EMFILE:
805 if (p)
806 send_log(p, LOG_EMERG,
Willy Tarreauc5532ac2018-01-29 15:06:04 +0100807 "Proxy %s reached process FD limit (maxsock=%d). Please check 'ulimit-n' and restart.\n",
808 p->id, global.maxsock);
Willy Tarreaubb660302014-05-07 19:47:02 +0200809 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200810 case ENOBUFS:
811 case ENOMEM:
812 if (p)
813 send_log(p, LOG_EMERG,
Willy Tarreauc5532ac2018-01-29 15:06:04 +0100814 "Proxy %s reached system memory limit (maxsock=%d). Please check system tunables.\n",
815 p->id, global.maxsock);
Willy Tarreaubb660302014-05-07 19:47:02 +0200816 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200817 default:
Willy Tarreaua593ec52014-01-20 21:21:30 +0100818 /* unexpected result, let's give up and let other tasks run */
Willy Tarreau92079932019-12-10 09:30:05 +0100819 max_accept = 0;
820 goto end;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200821 }
822 }
823
William Lallemandd9138002018-11-27 12:02:39 +0100824 /* we don't want to leak the FD upon reload if it's in the master */
825 if (unlikely(master == 1))
826 fcntl(cfd, F_SETFD, FD_CLOEXEC);
827
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100828 /* The connection was accepted, it must be counted as such */
829 if (l->counters)
830 HA_ATOMIC_UPDATE_MAX(&l->counters->conn_max, next_conn);
831
Willy Tarreau82c97892019-02-27 19:32:32 +0100832 if (p)
833 HA_ATOMIC_UPDATE_MAX(&p->fe_counters.conn_max, next_feconn);
834
835 proxy_inc_fe_conn_ctr(l, p);
836
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100837 if (!(l->options & LI_O_UNLIMITED)) {
838 count = update_freq_ctr(&global.conn_per_sec, 1);
839 HA_ATOMIC_UPDATE_MAX(&global.cps_max, count);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100840 }
841
Willy Tarreau64a9c052019-04-12 15:27:17 +0200842 _HA_ATOMIC_ADD(&activity[tid].accepted, 1);
843
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200844 if (unlikely(cfd >= global.maxsock)) {
845 send_log(p, LOG_EMERG,
846 "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n",
847 p->id);
848 close(cfd);
Willy Tarreau0591bf72019-12-10 12:01:21 +0100849 expire = tick_add(now_ms, 1000); /* try again in 1 second */
850 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200851 }
852
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100853 /* past this point, l->accept() will automatically decrement
Willy Tarreau82c97892019-02-27 19:32:32 +0100854 * l->nbconn, feconn and actconn once done. Setting next_*conn=0
855 * allows the error path not to rollback on nbconn. It's more
856 * convenient than duplicating all exit labels.
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100857 */
858 next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100859 next_feconn = 0;
860 next_actconn = 0;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200861
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100862#if defined(USE_THREAD)
Willy Tarreau818a92e2020-09-03 07:50:19 +0200863 mask = thread_mask(l->rx.settings->bind_thread) & all_threads_mask;
Willy Tarreaua7da5e82020-03-12 17:33:29 +0100864 if (atleast2(mask) && (global.tune.options & GTUNE_LISTENER_MQ) && !stopping) {
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100865 struct accept_queue_ring *ring;
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100866 unsigned int t, t0, t1, t2;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100867
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100868 /* The principle is that we have two running indexes,
869 * each visiting in turn all threads bound to this
870 * listener. The connection will be assigned to the one
871 * with the least connections, and the other one will
872 * be updated. This provides a good fairness on short
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100873 * connections (round robin) and on long ones (conn
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100874 * count), without ever missing any idle thread.
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100875 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100876
877 /* keep a copy for the final update. thr_idx is composite
878 * and made of (t2<<16) + t1.
879 */
Willy Tarreau0cf33172019-03-06 15:26:33 +0100880 t0 = l->thr_idx;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100881 do {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100882 unsigned long m1, m2;
883 int q1, q2;
884
885 t2 = t1 = t0;
886 t2 >>= 16;
887 t1 &= 0xFFFF;
888
889 /* t1 walks low to high bits ;
890 * t2 walks high to low.
891 */
892 m1 = mask >> t1;
893 m2 = mask & (t2 ? nbits(t2 + 1) : ~0UL);
894
Willy Tarreau85d04242019-04-16 18:09:13 +0200895 if (unlikely(!(m1 & 1))) {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100896 m1 &= ~1UL;
897 if (!m1) {
898 m1 = mask;
899 t1 = 0;
900 }
901 t1 += my_ffsl(m1) - 1;
902 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100903
Willy Tarreau85d04242019-04-16 18:09:13 +0200904 if (unlikely(!(m2 & (1UL << t2)) || t1 == t2)) {
905 /* highest bit not set */
906 if (!m2)
907 m2 = mask;
908
909 t2 = my_flsl(m2) - 1;
910 }
911
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100912 /* now we have two distinct thread IDs belonging to the mask */
913 q1 = accept_queue_rings[t1].tail - accept_queue_rings[t1].head + ACCEPT_QUEUE_SIZE;
914 if (q1 >= ACCEPT_QUEUE_SIZE)
915 q1 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100916
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100917 q2 = accept_queue_rings[t2].tail - accept_queue_rings[t2].head + ACCEPT_QUEUE_SIZE;
918 if (q2 >= ACCEPT_QUEUE_SIZE)
919 q2 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100920
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100921 /* we have 3 possibilities now :
922 * q1 < q2 : t1 is less loaded than t2, so we pick it
923 * and update t2 (since t1 might still be
924 * lower than another thread)
925 * q1 > q2 : t2 is less loaded than t1, so we pick it
926 * and update t1 (since t2 might still be
927 * lower than another thread)
928 * q1 = q2 : both are equally loaded, thus we pick t1
929 * and update t1 as it will become more loaded
930 * than t2.
931 */
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100932
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100933 q1 += l->thr_conn[t1];
934 q2 += l->thr_conn[t2];
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100935
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100936 if (q1 - q2 < 0) {
937 t = t1;
938 t2 = t2 ? t2 - 1 : LONGBITS - 1;
939 }
940 else if (q1 - q2 > 0) {
941 t = t2;
942 t1++;
943 if (t1 >= LONGBITS)
944 t1 = 0;
945 }
946 else {
947 t = t1;
948 t1++;
949 if (t1 >= LONGBITS)
950 t1 = 0;
951 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100952
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100953 /* new value for thr_idx */
954 t1 += (t2 << 16);
Olivier Houchard64213e92019-03-08 18:52:57 +0100955 } while (unlikely(!_HA_ATOMIC_CAS(&l->thr_idx, &t0, t1)));
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100956
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100957 /* We successfully selected the best thread "t" for this
958 * connection. We use deferred accepts even if it's the
959 * local thread because tests show that it's the best
960 * performing model, likely due to better cache locality
961 * when processing this loop.
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100962 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100963 ring = &accept_queue_rings[t];
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100964 if (accept_queue_push_mp(ring, cfd, l, &addr, laddr)) {
Olivier Houchard64213e92019-03-08 18:52:57 +0100965 _HA_ATOMIC_ADD(&activity[t].accq_pushed, 1);
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200966 tasklet_wakeup(ring->tasklet);
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100967 continue;
968 }
969 /* If the ring is full we do a synchronous accept on
970 * the local thread here.
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100971 */
Olivier Houchard64213e92019-03-08 18:52:57 +0100972 _HA_ATOMIC_ADD(&activity[t].accq_full, 1);
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100973 }
974#endif // USE_THREAD
975
Olivier Houchard64213e92019-03-08 18:52:57 +0100976 _HA_ATOMIC_ADD(&l->thr_conn[tid], 1);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200977 ret = l->accept(l, cfd, &addr);
978 if (unlikely(ret <= 0)) {
Willy Tarreau87b09662015-04-03 00:22:06 +0200979 /* The connection was closed by stream_accept(). Either
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200980 * we just have to ignore it (ret == 0) or it's a critical
981 * error due to a resource shortage, and we must stop the
982 * listener (ret < 0).
983 */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200984 if (ret == 0) /* successful termination */
985 continue;
986
Willy Tarreaubb660302014-05-07 19:47:02 +0200987 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200988 }
989
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100990 /* increase the per-process number of cumulated sessions, this
991 * may only be done once l->accept() has accepted the connection.
992 */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200993 if (!(l->options & LI_O_UNLIMITED)) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200994 count = update_freq_ctr(&global.sess_per_sec, 1);
995 HA_ATOMIC_UPDATE_MAX(&global.sps_max, count);
Willy Tarreau93e7c002013-10-07 18:51:07 +0200996 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200997#ifdef USE_OPENSSL
998 if (!(l->options & LI_O_UNLIMITED) && l->bind_conf && l->bind_conf->is_ssl) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200999 count = update_freq_ctr(&global.ssl_per_sec, 1);
1000 HA_ATOMIC_UPDATE_MAX(&global.ssl_max, count);
Willy Tarreaue43d5322013-10-07 20:01:52 +02001001 }
1002#endif
Willy Tarreau93e7c002013-10-07 18:51:07 +02001003
Willy Tarreau8d2c98b2020-05-01 09:51:11 +02001004 ti->flags &= ~TI_FL_STUCK; // this thread is still running
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001005 } /* end of for (max_accept--) */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001006
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001007 end:
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001008 if (next_conn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001009 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau741b4d62019-02-25 15:02:04 +01001010
Willy Tarreau82c97892019-02-27 19:32:32 +01001011 if (p && next_feconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001012 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001013
1014 if (next_actconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001015 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001016
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001017 if ((l->state == LI_FULL && (!l->maxconn || l->nbconn < l->maxconn)) ||
Willy Tarreaucdcba112019-12-11 15:06:30 +01001018 (l->state == LI_LIMITED &&
1019 ((!p || p->feconn < p->maxconn) && (actconn < global.maxconn) &&
1020 (!tick_isset(global_listener_queue_task->expire) ||
1021 tick_is_expired(global_listener_queue_task->expire, now_ms))))) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001022 /* at least one thread has to this when quitting */
1023 resume_listener(l);
1024
1025 /* Dequeues all of the listeners waiting for a resource */
Willy Tarreau241797a2019-12-10 14:10:52 +01001026 dequeue_all_listeners();
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001027
Olivier Houchard859dc802019-08-08 15:47:21 +02001028 if (p && !MT_LIST_ISEMPTY(&p->listener_queue) &&
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001029 (!p->fe_sps_lim || freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0) > 0))
Willy Tarreau241797a2019-12-10 14:10:52 +01001030 dequeue_proxy_listeners(p);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001031 }
Willy Tarreau4c044e22019-12-05 07:40:32 +01001032
Willy Tarreau92079932019-12-10 09:30:05 +01001033 /* Now it's getting tricky. The listener was supposed to be in LI_READY
1034 * state but in the mean time we might have changed it to LI_FULL or
1035 * LI_LIMITED, and another thread might also have turned it to
1036 * LI_PAUSED, LI_LISTEN or even LI_INI when stopping a proxy. We must
1037 * be certain to keep the FD enabled when in the READY state but we
1038 * must also stop it for other states that we might have switched to
1039 * while others re-enabled polling.
1040 */
1041 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
1042 if (l->state == LI_READY) {
1043 if (max_accept > 0)
1044 fd_cant_recv(fd);
1045 else
1046 fd_done_recv(fd);
1047 } else if (l->state > LI_ASSIGNED) {
Willy Tarreau38ba6472020-08-27 08:16:52 +02001048 fd_stop_recv(l->rx.fd);
Willy Tarreau92079932019-12-10 09:30:05 +01001049 }
1050 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau0591bf72019-12-10 12:01:21 +01001051 return;
1052
1053 transient_error:
1054 /* pause the listener for up to 100 ms */
1055 expire = tick_add(now_ms, 100);
1056
1057 limit_global:
1058 /* (re-)queue the listener to the global queue and set it to expire no
1059 * later than <expire> ahead. The listener turns to LI_LIMITED.
1060 */
1061 limit_listener(l, &global_listener_queue);
1062 task_schedule(global_listener_queue_task, expire);
1063 goto end;
1064
1065 limit_proxy:
1066 /* (re-)queue the listener to the proxy's queue and set it to expire no
1067 * later than <expire> ahead. The listener turns to LI_LIMITED.
1068 */
1069 limit_listener(l, &p->listener_queue);
Willy Tarreaueeea8082020-01-08 19:15:07 +01001070 if (p->task && tick_isset(expire))
1071 task_schedule(p->task, expire);
Willy Tarreau0591bf72019-12-10 12:01:21 +01001072 goto end;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001073}
1074
Willy Tarreau05f50472017-09-15 09:19:58 +02001075/* Notify the listener that a connection initiated from it was released. This
1076 * is used to keep the connection count consistent and to possibly re-open
1077 * listening when it was limited.
1078 */
1079void listener_release(struct listener *l)
1080{
1081 struct proxy *fe = l->bind_conf->frontend;
1082
1083 if (!(l->options & LI_O_UNLIMITED))
Olivier Houchard64213e92019-03-08 18:52:57 +01001084 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001085 if (fe)
Olivier Houchard64213e92019-03-08 18:52:57 +01001086 _HA_ATOMIC_SUB(&fe->feconn, 1);
1087 _HA_ATOMIC_SUB(&l->nbconn, 1);
1088 _HA_ATOMIC_SUB(&l->thr_conn[tid], 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001089
1090 if (l->state == LI_FULL || l->state == LI_LIMITED)
Willy Tarreau05f50472017-09-15 09:19:58 +02001091 resume_listener(l);
1092
1093 /* Dequeues all of the listeners waiting for a resource */
Willy Tarreau241797a2019-12-10 14:10:52 +01001094 dequeue_all_listeners();
Willy Tarreau05f50472017-09-15 09:19:58 +02001095
Olivier Houchard859dc802019-08-08 15:47:21 +02001096 if (!MT_LIST_ISEMPTY(&fe->listener_queue) &&
Willy Tarreau05f50472017-09-15 09:19:58 +02001097 (!fe->fe_sps_lim || freq_ctr_remain(&fe->fe_sess_per_sec, fe->fe_sps_lim, 0) > 0))
Willy Tarreau241797a2019-12-10 14:10:52 +01001098 dequeue_proxy_listeners(fe);
Willy Tarreau05f50472017-09-15 09:19:58 +02001099}
1100
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001101/* Initializes the listener queues. Returns 0 on success, otherwise ERR_* flags */
1102static int listener_queue_init()
1103{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001104 global_listener_queue_task = task_new(MAX_THREADS_MASK);
1105 if (!global_listener_queue_task) {
1106 ha_alert("Out of memory when initializing global listener queue\n");
1107 return ERR_FATAL|ERR_ABORT;
1108 }
1109 /* very simple initialization, users will queue the task if needed */
1110 global_listener_queue_task->context = NULL; /* not even a context! */
1111 global_listener_queue_task->process = manage_global_listener_queue;
1112
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001113 return 0;
1114}
1115
1116static void listener_queue_deinit()
1117{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001118 task_destroy(global_listener_queue_task);
1119 global_listener_queue_task = NULL;
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001120}
1121
1122REGISTER_CONFIG_POSTPARSER("multi-threaded listener queue", listener_queue_init);
1123REGISTER_POST_DEINIT(listener_queue_deinit);
1124
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001125
1126/* This is the global management task for listeners. It enables listeners waiting
1127 * for global resources when there are enough free resource, or at least once in
1128 * a while. It is designed to be called as a task.
1129 */
1130static struct task *manage_global_listener_queue(struct task *t, void *context, unsigned short state)
1131{
1132 /* If there are still too many concurrent connections, let's wait for
1133 * some of them to go away. We don't need to re-arm the timer because
1134 * each of them will scan the queue anyway.
1135 */
1136 if (unlikely(actconn >= global.maxconn))
1137 goto out;
1138
1139 /* We should periodically try to enable listeners waiting for a global
1140 * resource here, because it is possible, though very unlikely, that
1141 * they have been blocked by a temporary lack of global resource such
1142 * as a file descriptor or memory and that the temporary condition has
1143 * disappeared.
1144 */
1145 dequeue_all_listeners();
1146
1147 out:
1148 t->expire = TICK_ETERNITY;
1149 task_queue(t);
1150 return t;
1151}
1152
Willy Tarreau26982662012-09-12 23:17:10 +02001153/*
1154 * Registers the bind keyword list <kwl> as a list of valid keywords for next
1155 * parsing sessions.
1156 */
1157void bind_register_keywords(struct bind_kw_list *kwl)
1158{
1159 LIST_ADDQ(&bind_keywords.list, &kwl->list);
1160}
1161
1162/* Return a pointer to the bind keyword <kw>, or NULL if not found. If the
1163 * keyword is found with a NULL ->parse() function, then an attempt is made to
1164 * find one with a valid ->parse() function. This way it is possible to declare
1165 * platform-dependant, known keywords as NULL, then only declare them as valid
1166 * if some options are met. Note that if the requested keyword contains an
1167 * opening parenthesis, everything from this point is ignored.
1168 */
1169struct bind_kw *bind_find_kw(const char *kw)
1170{
1171 int index;
1172 const char *kwend;
1173 struct bind_kw_list *kwl;
1174 struct bind_kw *ret = NULL;
1175
1176 kwend = strchr(kw, '(');
1177 if (!kwend)
1178 kwend = kw + strlen(kw);
1179
1180 list_for_each_entry(kwl, &bind_keywords.list, list) {
1181 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1182 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
1183 kwl->kw[index].kw[kwend-kw] == 0) {
1184 if (kwl->kw[index].parse)
1185 return &kwl->kw[index]; /* found it !*/
1186 else
1187 ret = &kwl->kw[index]; /* may be OK */
1188 }
1189 }
1190 }
1191 return ret;
1192}
1193
Willy Tarreau8638f482012-09-18 18:01:17 +02001194/* Dumps all registered "bind" keywords to the <out> string pointer. The
1195 * unsupported keywords are only dumped if their supported form was not
1196 * found.
1197 */
1198void bind_dump_kws(char **out)
1199{
1200 struct bind_kw_list *kwl;
1201 int index;
1202
Christopher Faulet784063e2020-05-18 12:14:18 +02001203 if (!out)
1204 return;
1205
Willy Tarreau8638f482012-09-18 18:01:17 +02001206 *out = NULL;
1207 list_for_each_entry(kwl, &bind_keywords.list, list) {
1208 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1209 if (kwl->kw[index].parse ||
1210 bind_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) {
Willy Tarreau51fb7652012-09-18 18:24:39 +02001211 memprintf(out, "%s[%4s] %s%s%s\n", *out ? *out : "",
1212 kwl->scope,
Willy Tarreau8638f482012-09-18 18:01:17 +02001213 kwl->kw[index].kw,
Willy Tarreau51fb7652012-09-18 18:24:39 +02001214 kwl->kw[index].skip ? " <arg>" : "",
1215 kwl->kw[index].parse ? "" : " (not supported)");
Willy Tarreau8638f482012-09-18 18:01:17 +02001216 }
1217 }
1218 }
1219}
1220
Willy Tarreau645513a2010-05-24 20:55:15 +02001221/************************************************************************/
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001222/* All supported sample and ACL keywords must be declared here. */
Willy Tarreau645513a2010-05-24 20:55:15 +02001223/************************************************************************/
1224
Willy Tarreaua5e37562011-12-16 17:06:15 +01001225/* set temp integer to the number of connexions to the same listening socket */
Willy Tarreau645513a2010-05-24 20:55:15 +02001226static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001227smp_fetch_dconn(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau645513a2010-05-24 20:55:15 +02001228{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001229 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001230 smp->data.u.sint = smp->sess->listener->nbconn;
Willy Tarreau645513a2010-05-24 20:55:15 +02001231 return 1;
1232}
1233
Willy Tarreaua5e37562011-12-16 17:06:15 +01001234/* set temp integer to the id of the socket (listener) */
Willy Tarreau645513a2010-05-24 20:55:15 +02001235static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001236smp_fetch_so_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau37406352012-04-23 16:16:37 +02001237{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001238 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001239 smp->data.u.sint = smp->sess->listener->luid;
Willy Tarreau645513a2010-05-24 20:55:15 +02001240 return 1;
1241}
Jerome Magnineb421b22020-03-27 22:08:40 +01001242static int
1243smp_fetch_so_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
1244{
1245 smp->data.u.str.area = smp->sess->listener->name;
1246 if (!smp->data.u.str.area)
1247 return 0;
1248
1249 smp->data.type = SMP_T_STR;
1250 smp->flags = SMP_F_CONST;
1251 smp->data.u.str.data = strlen(smp->data.u.str.area);
1252 return 1;
1253}
Willy Tarreau645513a2010-05-24 20:55:15 +02001254
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001255/* parse the "accept-proxy" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001256static int bind_parse_accept_proxy(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001257{
1258 struct listener *l;
1259
Willy Tarreau4348fad2012-09-20 16:48:07 +02001260 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001261 l->options |= LI_O_ACC_PROXY;
1262
1263 return 0;
1264}
1265
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001266/* parse the "accept-netscaler-cip" bind keyword */
1267static int bind_parse_accept_netscaler_cip(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1268{
1269 struct listener *l;
1270 uint32_t val;
1271
1272 if (!*args[cur_arg + 1]) {
1273 memprintf(err, "'%s' : missing value", args[cur_arg]);
1274 return ERR_ALERT | ERR_FATAL;
1275 }
1276
1277 val = atol(args[cur_arg + 1]);
1278 if (val <= 0) {
Willy Tarreaue2711c72019-02-27 15:39:41 +01001279 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001280 return ERR_ALERT | ERR_FATAL;
1281 }
1282
1283 list_for_each_entry(l, &conf->listeners, by_bind) {
1284 l->options |= LI_O_ACC_CIP;
1285 conf->ns_cip_magic = val;
1286 }
1287
1288 return 0;
1289}
1290
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001291/* parse the "backlog" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001292static int bind_parse_backlog(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001293{
1294 struct listener *l;
1295 int val;
1296
1297 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001298 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001299 return ERR_ALERT | ERR_FATAL;
1300 }
1301
1302 val = atol(args[cur_arg + 1]);
Willy Tarreaue2711c72019-02-27 15:39:41 +01001303 if (val < 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001304 memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001305 return ERR_ALERT | ERR_FATAL;
1306 }
1307
Willy Tarreau4348fad2012-09-20 16:48:07 +02001308 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001309 l->backlog = val;
1310
1311 return 0;
1312}
1313
1314/* parse the "id" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001315static int bind_parse_id(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001316{
1317 struct eb32_node *node;
Willy Tarreau4348fad2012-09-20 16:48:07 +02001318 struct listener *l, *new;
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001319 char *error;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001320
Willy Tarreau4348fad2012-09-20 16:48:07 +02001321 if (conf->listeners.n != conf->listeners.p) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001322 memprintf(err, "'%s' can only be used with a single socket", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001323 return ERR_ALERT | ERR_FATAL;
1324 }
1325
1326 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001327 memprintf(err, "'%s' : expects an integer argument", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001328 return ERR_ALERT | ERR_FATAL;
1329 }
1330
Willy Tarreau4348fad2012-09-20 16:48:07 +02001331 new = LIST_NEXT(&conf->listeners, struct listener *, by_bind);
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001332 new->luid = strtol(args[cur_arg + 1], &error, 10);
1333 if (*error != '\0') {
1334 memprintf(err, "'%s' : expects an integer argument, found '%s'", args[cur_arg], args[cur_arg + 1]);
1335 return ERR_ALERT | ERR_FATAL;
1336 }
Willy Tarreau4348fad2012-09-20 16:48:07 +02001337 new->conf.id.key = new->luid;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001338
Willy Tarreau4348fad2012-09-20 16:48:07 +02001339 if (new->luid <= 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001340 memprintf(err, "'%s' : custom id has to be > 0", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001341 return ERR_ALERT | ERR_FATAL;
1342 }
1343
Willy Tarreau4348fad2012-09-20 16:48:07 +02001344 node = eb32_lookup(&px->conf.used_listener_id, new->luid);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001345 if (node) {
1346 l = container_of(node, struct listener, conf.id);
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001347 memprintf(err, "'%s' : custom id %d already used at %s:%d ('bind %s')",
1348 args[cur_arg], l->luid, l->bind_conf->file, l->bind_conf->line,
1349 l->bind_conf->arg);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001350 return ERR_ALERT | ERR_FATAL;
1351 }
1352
Willy Tarreau4348fad2012-09-20 16:48:07 +02001353 eb32_insert(&px->conf.used_listener_id, &new->conf.id);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001354 return 0;
1355}
1356
1357/* parse the "maxconn" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001358static int bind_parse_maxconn(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001359{
1360 struct listener *l;
1361 int val;
1362
1363 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001364 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001365 return ERR_ALERT | ERR_FATAL;
1366 }
1367
1368 val = atol(args[cur_arg + 1]);
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001369 if (val < 0) {
1370 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001371 return ERR_ALERT | ERR_FATAL;
1372 }
1373
Willy Tarreau4348fad2012-09-20 16:48:07 +02001374 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001375 l->maxconn = val;
1376
1377 return 0;
1378}
1379
1380/* parse the "name" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001381static int bind_parse_name(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001382{
1383 struct listener *l;
1384
1385 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001386 memprintf(err, "'%s' : missing name", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001387 return ERR_ALERT | ERR_FATAL;
1388 }
1389
Willy Tarreau4348fad2012-09-20 16:48:07 +02001390 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001391 l->name = strdup(args[cur_arg + 1]);
1392
1393 return 0;
1394}
1395
1396/* parse the "nice" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001397static int bind_parse_nice(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001398{
1399 struct listener *l;
1400 int val;
1401
1402 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001403 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001404 return ERR_ALERT | ERR_FATAL;
1405 }
1406
1407 val = atol(args[cur_arg + 1]);
1408 if (val < -1024 || val > 1024) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001409 memprintf(err, "'%s' : invalid value %d, allowed range is -1024..1024", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001410 return ERR_ALERT | ERR_FATAL;
1411 }
1412
Willy Tarreau4348fad2012-09-20 16:48:07 +02001413 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001414 l->nice = val;
1415
1416 return 0;
1417}
1418
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001419/* parse the "process" bind keyword */
1420static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1421{
Christopher Fauletc644fa92017-11-23 22:44:11 +01001422 char *slash;
1423 unsigned long proc = 0, thread = 0;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001424
Christopher Fauletc644fa92017-11-23 22:44:11 +01001425 if ((slash = strchr(args[cur_arg + 1], '/')) != NULL)
1426 *slash = 0;
1427
Willy Tarreauff9c9142019-02-07 10:39:36 +01001428 if (parse_process_number(args[cur_arg + 1], &proc, MAX_PROCS, NULL, err)) {
Christopher Fauletf1f0c5f2017-11-22 12:06:43 +01001429 memprintf(err, "'%s' : %s", args[cur_arg], *err);
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001430 return ERR_ALERT | ERR_FATAL;
1431 }
1432
Christopher Fauletc644fa92017-11-23 22:44:11 +01001433 if (slash) {
Willy Tarreauc9a82e42019-01-26 13:25:14 +01001434 if (parse_process_number(slash+1, &thread, MAX_THREADS, NULL, err)) {
Christopher Fauletc644fa92017-11-23 22:44:11 +01001435 memprintf(err, "'%s' : %s", args[cur_arg], *err);
1436 return ERR_ALERT | ERR_FATAL;
1437 }
1438 *slash = '/';
1439 }
1440
Willy Tarreaue26993c2020-09-03 07:18:55 +02001441 conf->settings.bind_proc |= proc;
1442 conf->settings.bind_thread |= thread;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001443 return 0;
1444}
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001445
Christopher Fauleta717b992018-04-10 14:43:00 +02001446/* parse the "proto" bind keyword */
1447static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1448{
1449 struct ist proto;
1450
1451 if (!*args[cur_arg + 1]) {
1452 memprintf(err, "'%s' : missing value", args[cur_arg]);
1453 return ERR_ALERT | ERR_FATAL;
1454 }
1455
1456 proto = ist2(args[cur_arg + 1], strlen(args[cur_arg + 1]));
1457 conf->mux_proto = get_mux_proto(proto);
1458 if (!conf->mux_proto) {
1459 memprintf(err, "'%s' : unknown MUX protocol '%s'", args[cur_arg], args[cur_arg+1]);
1460 return ERR_ALERT | ERR_FATAL;
1461 }
Christopher Fauleta717b992018-04-10 14:43:00 +02001462 return 0;
1463}
1464
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001465/* config parser for global "tune.listener.multi-queue", accepts "on" or "off" */
1466static int cfg_parse_tune_listener_mq(char **args, int section_type, struct proxy *curpx,
1467 struct proxy *defpx, const char *file, int line,
1468 char **err)
1469{
1470 if (too_many_args(1, args, err, NULL))
1471 return -1;
1472
1473 if (strcmp(args[1], "on") == 0)
1474 global.tune.options |= GTUNE_LISTENER_MQ;
1475 else if (strcmp(args[1], "off") == 0)
1476 global.tune.options &= ~GTUNE_LISTENER_MQ;
1477 else {
1478 memprintf(err, "'%s' expects either 'on' or 'off' but got '%s'.", args[0], args[1]);
1479 return -1;
1480 }
1481 return 0;
1482}
1483
Willy Tarreau61612d42012-04-19 18:42:05 +02001484/* Note: must not be declared <const> as its list will be overwritten.
1485 * Please take care of keeping this list alphabetically sorted.
1486 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001487static struct sample_fetch_kw_list smp_kws = {ILH, {
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02001488 { "dst_conn", smp_fetch_dconn, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
1489 { "so_id", smp_fetch_so_id, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
Jerome Magnineb421b22020-03-27 22:08:40 +01001490 { "so_name", smp_fetch_so_name, 0, NULL, SMP_T_STR, SMP_USE_FTEND, },
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001491 { /* END */ },
1492}};
1493
Willy Tarreau0108d902018-11-25 19:14:37 +01001494INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
1495
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001496/* Note: must not be declared <const> as its list will be overwritten.
1497 * Please take care of keeping this list alphabetically sorted.
1498 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001499static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001500 { /* END */ },
Willy Tarreau645513a2010-05-24 20:55:15 +02001501}};
1502
Willy Tarreau0108d902018-11-25 19:14:37 +01001503INITCALL1(STG_REGISTER, acl_register_keywords, &acl_kws);
1504
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001505/* Note: must not be declared <const> as its list will be overwritten.
1506 * Please take care of keeping this list alphabetically sorted, doing so helps
1507 * all code contributors.
1508 * Optional keywords are also declared with a NULL ->parse() function so that
1509 * the config parser can report an appropriate error when a known keyword was
1510 * not enabled.
1511 */
Willy Tarreau51fb7652012-09-18 18:24:39 +02001512static struct bind_kw_list bind_kws = { "ALL", { }, {
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001513 { "accept-netscaler-cip", bind_parse_accept_netscaler_cip, 1 }, /* enable NetScaler Client IP insertion protocol */
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001514 { "accept-proxy", bind_parse_accept_proxy, 0 }, /* enable PROXY protocol */
1515 { "backlog", bind_parse_backlog, 1 }, /* set backlog of listening socket */
1516 { "id", bind_parse_id, 1 }, /* set id of listening socket */
1517 { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */
1518 { "name", bind_parse_name, 1 }, /* set name of listening socket */
1519 { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001520 { "process", bind_parse_process, 1 }, /* set list of allowed process for this socket */
Christopher Fauleta717b992018-04-10 14:43:00 +02001521 { "proto", bind_parse_proto, 1 }, /* set the proto to use for all incoming connections */
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001522 { /* END */ },
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001523}};
1524
Willy Tarreau0108d902018-11-25 19:14:37 +01001525INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
1526
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001527/* config keyword parsers */
1528static struct cfg_kw_list cfg_kws = {ILH, {
1529 { CFG_GLOBAL, "tune.listener.multi-queue", cfg_parse_tune_listener_mq },
1530 { 0, NULL, NULL }
1531}};
1532
1533INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
1534
Willy Tarreau645513a2010-05-24 20:55:15 +02001535/*
1536 * Local variables:
1537 * c-indent-level: 8
1538 * c-basic-offset: 8
1539 * End:
1540 */