blob: 6714e91cfacf1a3c04fa5a8c248a7fa502e72b7d [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 Tarreau6ae1ba62014-05-07 19:01:58 +020013#include <ctype.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020014#include <errno.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020015#include <stdio.h>
16#include <string.h>
Willy Tarreau95ccdde2014-02-01 09:28:36 +010017#include <unistd.h>
18#include <fcntl.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020019
Willy Tarreaudcc048a2020-06-04 19:11:43 +020020#include <haproxy/acl.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020021#include <haproxy/api.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020022#include <haproxy/cfgparse.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020023#include <haproxy/connection.h>
Willy Tarreau8d366972020-05-27 16:10:29 +020024#include <haproxy/errors.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020025#include <haproxy/fd.h>
26#include <haproxy/freq_ctr.h>
Willy Tarreauf268ee82020-06-04 17:05:57 +020027#include <haproxy/global.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020028#include <haproxy/list.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020029#include <haproxy/listener.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020030#include <haproxy/log.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020031#include <haproxy/protocol-t.h>
32#include <haproxy/protocol.h>
33#include <haproxy/sample.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020034#include <haproxy/stream.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020035#include <haproxy/task.h>
Willy Tarreau92b4f132020-06-01 11:05:15 +020036#include <haproxy/time.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020037#include <haproxy/tools.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020038
Willy Tarreaub648d632007-10-28 22:13:50 +010039
Willy Tarreau26982662012-09-12 23:17:10 +020040/* List head of all known bind keywords */
41static struct bind_kw_list bind_keywords = {
42 .list = LIST_HEAD_INIT(bind_keywords.list)
43};
44
Willy Tarreaua1d97f82019-12-10 11:18:41 +010045/* list of the temporarily limited listeners because of lack of resource */
46static struct mt_list global_listener_queue = MT_LIST_HEAD_INIT(global_listener_queue);
47static struct task *global_listener_queue_task;
48static struct task *manage_global_listener_queue(struct task *t, void *context, unsigned short state);
49
50
Willy Tarreau1efafce2019-01-27 15:37:19 +010051#if defined(USE_THREAD)
52
53struct accept_queue_ring accept_queue_rings[MAX_THREADS] __attribute__((aligned(64))) = { };
54
55/* dequeue and process a pending connection from the local accept queue (single
Willy Tarreau83efc322020-10-14 17:37:17 +020056 * consumer). Returns the accepted connection or NULL if none was found.
Willy Tarreau1efafce2019-01-27 15:37:19 +010057 */
Willy Tarreau83efc322020-10-14 17:37:17 +020058struct connection *accept_queue_pop_sc(struct accept_queue_ring *ring)
Willy Tarreau1efafce2019-01-27 15:37:19 +010059{
Willy Tarreau1efafce2019-01-27 15:37:19 +010060 unsigned int pos, next;
Willy Tarreau83efc322020-10-14 17:37:17 +020061 struct connection *ptr;
62 struct connection **e;
Willy Tarreau1efafce2019-01-27 15:37:19 +010063
64 pos = ring->head;
65
66 if (pos == ring->tail)
Willy Tarreau83efc322020-10-14 17:37:17 +020067 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +010068
69 next = pos + 1;
70 if (next >= ACCEPT_QUEUE_SIZE)
71 next = 0;
72
73 e = &ring->entry[pos];
74
75 /* wait for the producer to update the listener's pointer */
76 while (1) {
Willy Tarreau83efc322020-10-14 17:37:17 +020077 ptr = *e;
Willy Tarreau1efafce2019-01-27 15:37:19 +010078 __ha_barrier_load();
79 if (ptr)
80 break;
81 pl_cpu_relax();
82 }
83
Willy Tarreau1efafce2019-01-27 15:37:19 +010084 /* release the entry */
Willy Tarreau83efc322020-10-14 17:37:17 +020085 *e = NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +010086
87 __ha_barrier_store();
88 ring->head = next;
Willy Tarreau83efc322020-10-14 17:37:17 +020089 return ptr;
Willy Tarreau1efafce2019-01-27 15:37:19 +010090}
91
92
Willy Tarreau83efc322020-10-14 17:37:17 +020093/* tries to push a new accepted connection <conn> into ring <ring>. Returns
94 * non-zero if it succeeds, or zero if the ring is full. Supports multiple
95 * producers.
Willy Tarreau1efafce2019-01-27 15:37:19 +010096 */
Willy Tarreau83efc322020-10-14 17:37:17 +020097int accept_queue_push_mp(struct accept_queue_ring *ring, struct connection *conn)
Willy Tarreau1efafce2019-01-27 15:37:19 +010098{
Willy Tarreau1efafce2019-01-27 15:37:19 +010099 unsigned int pos, next;
100
101 pos = ring->tail;
102 do {
103 next = pos + 1;
104 if (next >= ACCEPT_QUEUE_SIZE)
105 next = 0;
106 if (next == ring->head)
107 return 0; // ring full
Olivier Houchard64213e92019-03-08 18:52:57 +0100108 } while (unlikely(!_HA_ATOMIC_CAS(&ring->tail, &pos, next)));
Willy Tarreau1efafce2019-01-27 15:37:19 +0100109
Willy Tarreau83efc322020-10-14 17:37:17 +0200110 ring->entry[pos] = conn;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100111 __ha_barrier_store();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100112 return 1;
113}
114
Willy Tarreaufb5401f2021-01-29 12:25:23 +0100115/* proceed with accepting new connections. Don't mark it static so that it appears
116 * in task dumps.
117 */
118struct task *accept_queue_process(struct task *t, void *context, unsigned short state)
Willy Tarreau1efafce2019-01-27 15:37:19 +0100119{
120 struct accept_queue_ring *ring = context;
Willy Tarreau83efc322020-10-14 17:37:17 +0200121 struct connection *conn;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100122 struct listener *li;
Christopher Faulet102854c2019-04-30 12:17:13 +0200123 unsigned int max_accept;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100124 int ret;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100125
Christopher Faulet102854c2019-04-30 12:17:13 +0200126 /* if global.tune.maxaccept is -1, then max_accept is UINT_MAX. It
127 * is not really illimited, but it is probably enough.
128 */
129 max_accept = global.tune.maxaccept ? global.tune.maxaccept : 64;
130 for (; max_accept; max_accept--) {
Willy Tarreau83efc322020-10-14 17:37:17 +0200131 conn = accept_queue_pop_sc(ring);
132 if (!conn)
Willy Tarreau1efafce2019-01-27 15:37:19 +0100133 break;
134
Willy Tarreau83efc322020-10-14 17:37:17 +0200135 li = __objt_listener(conn->target);
Olivier Houchard64213e92019-03-08 18:52:57 +0100136 _HA_ATOMIC_ADD(&li->thr_conn[tid], 1);
Willy Tarreau83efc322020-10-14 17:37:17 +0200137 ret = li->accept(conn);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100138 if (ret <= 0) {
139 /* connection was terminated by the application */
140 continue;
141 }
142
143 /* increase the per-process number of cumulated sessions, this
144 * may only be done once l->accept() has accepted the connection.
145 */
146 if (!(li->options & LI_O_UNLIMITED)) {
147 HA_ATOMIC_UPDATE_MAX(&global.sps_max,
148 update_freq_ctr(&global.sess_per_sec, 1));
149 if (li->bind_conf && li->bind_conf->is_ssl) {
150 HA_ATOMIC_UPDATE_MAX(&global.ssl_max,
151 update_freq_ctr(&global.ssl_per_sec, 1));
152 }
153 }
154 }
155
156 /* ran out of budget ? Let's come here ASAP */
Christopher Faulet102854c2019-04-30 12:17:13 +0200157 if (!max_accept)
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200158 tasklet_wakeup(ring->tasklet);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100159
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200160 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100161}
162
163/* Initializes the accept-queues. Returns 0 on success, otherwise ERR_* flags */
164static int accept_queue_init()
165{
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200166 struct tasklet *t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100167 int i;
168
169 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200170 t = tasklet_new();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100171 if (!t) {
172 ha_alert("Out of memory while initializing accept queue for thread %d\n", i);
173 return ERR_FATAL|ERR_ABORT;
174 }
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200175 t->tid = i;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100176 t->process = accept_queue_process;
177 t->context = &accept_queue_rings[i];
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200178 accept_queue_rings[i].tasklet = t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100179 }
180 return 0;
181}
182
183REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
184
185#endif // USE_THREAD
186
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200187/* adjust the listener's state and its proxy's listener counters if needed.
188 * It must be called under the listener's lock, but uses atomic ops to change
189 * the proxy's counters so that the proxy lock is not needed.
190 */
Willy Tarreaua37b2442020-09-24 07:23:45 +0200191void listener_set_state(struct listener *l, enum li_state st)
192{
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200193 struct proxy *px = l->bind_conf->frontend;
194
195 if (px) {
196 /* from state */
197 switch (l->state) {
198 case LI_NEW: /* first call */
199 _HA_ATOMIC_ADD(&px->li_all, 1);
200 break;
201 case LI_INIT:
202 case LI_ASSIGNED:
203 break;
204 case LI_PAUSED:
205 _HA_ATOMIC_SUB(&px->li_paused, 1);
206 break;
207 case LI_LISTEN:
208 _HA_ATOMIC_SUB(&px->li_bound, 1);
209 break;
210 case LI_READY:
211 case LI_FULL:
212 case LI_LIMITED:
213 _HA_ATOMIC_SUB(&px->li_ready, 1);
214 break;
215 }
216
217 /* to state */
218 switch (st) {
219 case LI_NEW:
220 case LI_INIT:
221 case LI_ASSIGNED:
222 break;
223 case LI_PAUSED:
Willy Tarreau95a34602020-10-08 15:32:21 +0200224 BUG_ON(l->rx.fd == -1);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200225 _HA_ATOMIC_ADD(&px->li_paused, 1);
226 break;
227 case LI_LISTEN:
Willy Tarreau95a34602020-10-08 15:32:21 +0200228 BUG_ON(l->rx.fd == -1);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200229 _HA_ATOMIC_ADD(&px->li_bound, 1);
230 break;
231 case LI_READY:
232 case LI_FULL:
233 case LI_LIMITED:
Willy Tarreau95a34602020-10-08 15:32:21 +0200234 BUG_ON(l->rx.fd == -1);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200235 _HA_ATOMIC_ADD(&px->li_ready, 1);
236 break;
237 }
238 }
Willy Tarreaua37b2442020-09-24 07:23:45 +0200239 l->state = st;
240}
241
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100242/* This function adds the specified listener's file descriptor to the polling
243 * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500244 * LI_FULL state depending on its number of connections. In daemon mode, we
Willy Tarreauae302532014-05-07 19:22:24 +0200245 * also support binding only the relevant processes to their respective
246 * listeners. We don't do that in debug mode however.
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100247 */
Willy Tarreau7834a3f2020-09-25 16:40:18 +0200248void enable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100249{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100250 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaud6afb532020-10-09 10:35:40 +0200251
252 /* If this listener is supposed to be only in the master, close it in
253 * the workers. Conversely, if it's supposed to be only in the workers
254 * close it in the master.
255 */
Willy Tarreau18c20d22020-10-09 16:11:46 +0200256 if (!!master != !!(listener->rx.flags & RX_F_MWORKER))
Willy Tarreau75c98d12020-10-09 15:55:23 +0200257 do_unbind_listener(listener);
Willy Tarreaud6afb532020-10-09 10:35:40 +0200258
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100259 if (listener->state == LI_LISTEN) {
Willy Tarreau95a34602020-10-08 15:32:21 +0200260 BUG_ON(listener->rx.fd == -1);
William Lallemand095ba4c2017-06-01 17:38:50 +0200261 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau38dba272020-11-04 13:54:00 +0100262 (!!master != !!(listener->rx.flags & RX_F_MWORKER) ||
263 !(proc_mask(listener->rx.settings->bind_proc) & pid_bit))) {
Willy Tarreauae302532014-05-07 19:22:24 +0200264 /* we don't want to enable this listener and don't
265 * want any fd event to reach it.
266 */
Willy Tarreau75c98d12020-10-09 15:55:23 +0200267 do_unbind_listener(listener);
Willy Tarreauae302532014-05-07 19:22:24 +0200268 }
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100269 else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200270 listener->rx.proto->enable(listener);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200271 listener_set_state(listener, LI_READY);
Willy Tarreauae302532014-05-07 19:22:24 +0200272 }
273 else {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200274 listener_set_state(listener, LI_FULL);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100275 }
276 }
Willy Tarreaud6afb532020-10-09 10:35:40 +0200277
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100278 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100279}
280
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200281/*
282 * This function completely stops a listener. It will need to operate under the
283 * proxy's lock, the protocol's lock, and the listener's lock. The caller is
284 * responsible for indicating in lpx, lpr, lli whether the respective locks are
285 * already held (non-zero) or not (zero) so that the function picks the missing
286 * ones, in this order. The proxy's listeners count is updated and the proxy is
287 * disabled and woken up after the last one is gone.
288 */
289void stop_listener(struct listener *l, int lpx, int lpr, int lli)
290{
291 struct proxy *px = l->bind_conf->frontend;
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200292
293 if (l->options & LI_O_NOSTOP) {
294 /* master-worker sockpairs are never closed but don't count as a
295 * job.
296 */
297 return;
298 }
299
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200300 if (!lpx)
Willy Tarreauac66d6b2020-10-20 17:24:27 +0200301 HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200302
303 if (!lpr)
304 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
305
306 if (!lli)
307 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
308
309 if (l->state > LI_INIT) {
Willy Tarreau75c98d12020-10-09 15:55:23 +0200310 do_unbind_listener(l);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200311
312 if (l->state >= LI_ASSIGNED)
313 __delete_listener(l);
314
Willy Tarreauacde1522020-10-07 16:31:39 +0200315 proxy_cond_disable(px);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200316 }
317
318 if (!lli)
319 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
320
321 if (!lpr)
322 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
323
324 if (!lpx)
Willy Tarreauac66d6b2020-10-20 17:24:27 +0200325 HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200326}
327
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100328/* This function adds the specified <listener> to the protocol <proto>. It
329 * does nothing if the protocol was already added. The listener's state is
330 * automatically updated from LI_INIT to LI_ASSIGNED. The number of listeners
331 * for the protocol is updated. This must be called with the proto lock held.
332 */
333void default_add_listener(struct protocol *proto, struct listener *listener)
334{
335 if (listener->state != LI_INIT)
336 return;
337 listener_set_state(listener, LI_ASSIGNED);
338 listener->rx.proto = proto;
339 LIST_ADDQ(&proto->receivers, &listener->rx.proto_list);
340 proto->nb_receivers++;
341}
342
Willy Tarreaue03204c2020-10-09 17:02:21 +0200343/* default function called to suspend a listener: it simply passes the call to
344 * the underlying receiver. This is find for most socket-based protocols. This
345 * must be called under the listener's lock. It will return non-zero on success,
346 * 0 on failure. If no receiver-level suspend is provided, the operation is
347 * assumed to succeed.
348 */
349int default_suspend_listener(struct listener *l)
350{
351 int ret = 1;
352
353 if (!l->rx.proto->rx_suspend)
354 return 1;
355
356 ret = l->rx.proto->rx_suspend(&l->rx);
357 return ret > 0 ? ret : 0;
358}
359
360
361/* Tries to resume a suspended listener, and returns non-zero on success or
362 * zero on failure. On certain errors, an alert or a warning might be displayed.
363 * It must be called with the listener's lock held. Depending on the listener's
364 * state and protocol, a listen() call might be used to resume operations, or a
365 * call to the receiver's resume() function might be used as well. This is
366 * suitable as a default function for TCP and UDP. This must be called with the
367 * listener's lock held.
368 */
369int default_resume_listener(struct listener *l)
370{
371 int ret = 1;
372
373 if (l->state == LI_ASSIGNED) {
374 char msg[100];
375 int err;
376
377 err = l->rx.proto->listen(l, msg, sizeof(msg));
378 if (err & ERR_ALERT)
379 ha_alert("Resuming listener: %s\n", msg);
380 else if (err & ERR_WARN)
381 ha_warning("Resuming listener: %s\n", msg);
382
383 if (err & (ERR_FATAL | ERR_ABORT)) {
384 ret = 0;
385 goto end;
386 }
387 }
388
389 if (l->state < LI_PAUSED) {
390 ret = 0;
391 goto end;
392 }
393
394 if (l->state == LI_PAUSED && l->rx.proto->rx_resume &&
395 l->rx.proto->rx_resume(&l->rx) <= 0)
396 ret = 0;
397 end:
398 return ret;
399}
400
401
Willy Tarreaube58c382011-07-24 18:28:10 +0200402/* This function tries to temporarily disable a listener, depending on the OS
403 * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
404 * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
405 * closes upon SHUT_WR and refuses to rebind. So a common validation path
406 * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling
407 * is disabled. It normally returns non-zero, unless an error is reported.
408 */
409int pause_listener(struct listener *l)
410{
Willy Tarreau58651b42020-09-24 16:03:29 +0200411 struct proxy *px = l->bind_conf->frontend;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200412 int ret = 1;
413
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100414 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200415
Willy Tarreau02e19752020-09-23 17:17:22 +0200416 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
417 !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
418 goto end;
419
Willy Tarreau9b3a9322020-09-24 14:46:34 +0200420 if (l->state <= LI_PAUSED)
421 goto end;
422
Willy Tarreaue03204c2020-10-09 17:02:21 +0200423 if (l->rx.proto->suspend)
424 ret = l->rx.proto->suspend(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200425
Olivier Houchard859dc802019-08-08 15:47:21 +0200426 MT_LIST_DEL(&l->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200427
Willy Tarreaua37b2442020-09-24 07:23:45 +0200428 listener_set_state(l, LI_PAUSED);
Willy Tarreau58651b42020-09-24 16:03:29 +0200429
430 if (px && !px->li_ready) {
431 ha_warning("Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
432 send_log(px, LOG_WARNING, "Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
433 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200434 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100435 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200436 return ret;
Willy Tarreaube58c382011-07-24 18:28:10 +0200437}
438
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200439/* This function tries to resume a temporarily disabled listener. Paused, full,
440 * limited and disabled listeners are handled, which means that this function
441 * may replace enable_listener(). The resulting state will either be LI_READY
442 * or LI_FULL. 0 is returned in case of failure to resume (eg: dead socket).
Willy Tarreauae302532014-05-07 19:22:24 +0200443 * Listeners bound to a different process are not woken up unless we're in
Willy Tarreauaf2fd582015-04-14 12:07:16 +0200444 * foreground mode, and are ignored. If the listener was only in the assigned
445 * state, it's totally rebound. This can happen if a pause() has completely
446 * stopped it. If the resume fails, 0 is returned and an error might be
447 * displayed.
Willy Tarreaube58c382011-07-24 18:28:10 +0200448 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100449int resume_listener(struct listener *l)
Willy Tarreaube58c382011-07-24 18:28:10 +0200450{
Willy Tarreau58651b42020-09-24 16:03:29 +0200451 struct proxy *px = l->bind_conf->frontend;
452 int was_paused = px && px->li_paused;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200453 int ret = 1;
454
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100455 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200456
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200457 /* check that another thread didn't to the job in parallel (e.g. at the
458 * end of listen_accept() while we'd come from dequeue_all_listeners().
459 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200460 if (MT_LIST_ADDED(&l->wait_queue))
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200461 goto end;
462
William Lallemand095ba4c2017-06-01 17:38:50 +0200463 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau818a92e2020-09-03 07:50:19 +0200464 !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200465 goto end;
Willy Tarreau3569df32017-03-15 12:47:46 +0100466
Willy Tarreau5d7f9ce2020-09-24 18:54:11 +0200467 if (l->state == LI_READY)
468 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200469
Willy Tarreaue03204c2020-10-09 17:02:21 +0200470 if (l->rx.proto->resume)
471 ret = l->rx.proto->resume(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200472
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100473 if (l->maxconn && l->nbconn >= l->maxconn) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200474 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200475 listener_set_state(l, LI_FULL);
Willy Tarreau58651b42020-09-24 16:03:29 +0200476 goto done;
Willy Tarreaube58c382011-07-24 18:28:10 +0200477 }
478
Willy Tarreau4b51f422020-09-25 20:32:28 +0200479 l->rx.proto->enable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200480 listener_set_state(l, LI_READY);
Willy Tarreau58651b42020-09-24 16:03:29 +0200481
482 done:
483 if (was_paused && !px->li_paused) {
484 ha_warning("Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
485 send_log(px, LOG_WARNING, "Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
486 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200487 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100488 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200489 return ret;
490}
491
Willy Tarreau87b09662015-04-03 00:22:06 +0200492/* Marks a ready listener as full so that the stream code tries to re-enable
Willy Tarreau62793712011-07-24 19:23:38 +0200493 * it upon next close() using resume_listener().
494 */
Christopher Faulet5580ba22017-08-28 15:29:20 +0200495static void listener_full(struct listener *l)
Willy Tarreau62793712011-07-24 19:23:38 +0200496{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100497 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200498 if (l->state >= LI_READY) {
Olivier Houchard859dc802019-08-08 15:47:21 +0200499 MT_LIST_DEL(&l->wait_queue);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100500 if (l->state != LI_FULL) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200501 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200502 listener_set_state(l, LI_FULL);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100503 }
Willy Tarreau62793712011-07-24 19:23:38 +0200504 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100505 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200506}
507
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200508/* Marks a ready listener as limited so that we only try to re-enable it when
509 * resources are free again. It will be queued into the specified queue.
510 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200511static void limit_listener(struct listener *l, struct mt_list *list)
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200512{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100513 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200514 if (l->state == LI_READY) {
Willy Tarreaude4db172020-07-10 08:10:29 +0200515 MT_LIST_TRY_ADDQ(list, &l->wait_queue);
Willy Tarreau4b51f422020-09-25 20:32:28 +0200516 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200517 listener_set_state(l, LI_LIMITED);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200518 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100519 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200520}
521
Willy Tarreau241797a2019-12-10 14:10:52 +0100522/* Dequeues all listeners waiting for a resource the global wait queue */
523void dequeue_all_listeners()
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200524{
Willy Tarreau01abd022019-02-28 10:27:18 +0100525 struct listener *listener;
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200526
Willy Tarreau241797a2019-12-10 14:10:52 +0100527 while ((listener = MT_LIST_POP(&global_listener_queue, struct listener *, wait_queue))) {
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200528 /* This cannot fail because the listeners are by definition in
Willy Tarreau01abd022019-02-28 10:27:18 +0100529 * the LI_LIMITED state.
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200530 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100531 resume_listener(listener);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200532 }
533}
534
Willy Tarreau241797a2019-12-10 14:10:52 +0100535/* Dequeues all listeners waiting for a resource in proxy <px>'s queue */
536void dequeue_proxy_listeners(struct proxy *px)
537{
538 struct listener *listener;
539
540 while ((listener = MT_LIST_POP(&px->listener_queue, struct listener *, wait_queue))) {
541 /* This cannot fail because the listeners are by definition in
542 * the LI_LIMITED state.
543 */
544 resume_listener(listener);
545 }
546}
547
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200548
549/* default function used to unbind a listener. This is for use by standard
550 * protocols working on top of accepted sockets. The receiver's rx_unbind()
551 * will automatically be used after the listener is disabled if the socket is
552 * still bound. This must be used under the listener's lock.
Christopher Faulet510c0d62018-03-16 10:04:47 +0100553 */
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200554void default_unbind_listener(struct listener *listener)
Willy Tarreaub648d632007-10-28 22:13:50 +0100555{
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200556 if (listener->state <= LI_ASSIGNED)
557 goto out_close;
558
559 if (listener->rx.fd == -1) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200560 listener_set_state(listener, LI_ASSIGNED);
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200561 goto out_close;
562 }
563
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200564 if (listener->state >= LI_READY) {
565 listener->rx.proto->disable(listener);
566 if (listener->rx.flags & RX_F_BOUND)
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200567 listener_set_state(listener, LI_LISTEN);
Willy Tarreaub6607bf2020-09-23 16:24:23 +0200568 }
569
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200570 out_close:
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200571 if (listener->rx.flags & RX_F_BOUND)
572 listener->rx.proto->rx_unbind(&listener->rx);
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200573}
574
575/* This function closes the listening socket for the specified listener,
576 * provided that it's already in a listening state. The protocol's unbind()
577 * is called to put the listener into LI_ASSIGNED or LI_LISTEN and handle
578 * the unbinding tasks. The listener enters then the LI_ASSIGNED state if
579 * the receiver is unbound. Must be called with the lock held.
580 */
581void do_unbind_listener(struct listener *listener)
582{
583 MT_LIST_DEL(&listener->wait_queue);
584
585 if (listener->rx.proto->unbind)
586 listener->rx.proto->unbind(listener);
Willy Tarreau374e9af2020-10-09 15:47:17 +0200587
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200588 /* we may have to downgrade the listener if the rx was closed */
589 if (!(listener->rx.flags & RX_F_BOUND) && listener->state > LI_ASSIGNED)
Willy Tarreau374e9af2020-10-09 15:47:17 +0200590 listener_set_state(listener, LI_ASSIGNED);
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100591}
592
Olivier Houchard1fc05162017-04-06 01:05:05 +0200593/* This function closes the listening socket for the specified listener,
594 * provided that it's already in a listening state. The listener enters the
Willy Tarreau75c98d12020-10-09 15:55:23 +0200595 * LI_ASSIGNED state, except if the FD is not closed, in which case it may
596 * remain in LI_LISTEN. This function is intended to be used as a generic
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100597 * function for standard protocols.
Olivier Houchard1fc05162017-04-06 01:05:05 +0200598 */
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100599void unbind_listener(struct listener *listener)
Olivier Houchard1fc05162017-04-06 01:05:05 +0200600{
Christopher Faulet510c0d62018-03-16 10:04:47 +0100601 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau75c98d12020-10-09 15:55:23 +0200602 do_unbind_listener(listener);
Christopher Faulet510c0d62018-03-16 10:04:47 +0100603 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200604}
605
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200606/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
607 * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200608 * allocation). The address family is taken from ss->ss_family, and the protocol
Willy Tarreaud2fb99f2020-10-15 21:22:29 +0200609 * passed in <proto> must be usable on this family. The protocol's default iocb
610 * is automatically preset as the receivers' iocb. The number of jobs and
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200611 * listeners is automatically increased by the number of listeners created. It
612 * returns non-zero on success, zero on error with the error message set in <err>.
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200613 */
614int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200615 int portl, int porth, int fd, struct protocol *proto, char **err)
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200616{
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200617 struct listener *l;
618 int port;
619
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200620 for (port = portl; port <= porth; port++) {
621 l = calloc(1, sizeof(*l));
622 if (!l) {
623 memprintf(err, "out of memory");
624 return 0;
625 }
626 l->obj_type = OBJ_TYPE_LISTENER;
627 LIST_ADDQ(&bc->frontend->conf.listeners, &l->by_fe);
628 LIST_ADDQ(&bc->listeners, &l->by_bind);
629 l->bind_conf = bc;
Willy Tarreau0fce6bc2020-09-03 07:46:06 +0200630 l->rx.settings = &bc->settings;
Willy Tarreaueef45422020-09-03 10:05:03 +0200631 l->rx.owner = l;
Willy Tarreaud2fb99f2020-10-15 21:22:29 +0200632 l->rx.iocb = proto->default_iocb;
Willy Tarreau38ba6472020-08-27 08:16:52 +0200633 l->rx.fd = fd;
Willy Tarreau07400c52020-12-04 14:49:11 +0100634
Willy Tarreau37159062020-08-27 07:48:42 +0200635 memcpy(&l->rx.addr, ss, sizeof(*ss));
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100636 if (proto->fam->set_port)
637 proto->fam->set_port(&l->rx.addr, port);
Willy Tarreau07400c52020-12-04 14:49:11 +0100638
Olivier Houchard859dc802019-08-08 15:47:21 +0200639 MT_LIST_INIT(&l->wait_queue);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200640 listener_set_state(l, LI_INIT);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200641
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100642 proto->add(proto, l);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200643
Willy Tarreau909c23b2020-09-15 13:50:58 +0200644 if (fd != -1)
Willy Tarreau43046fa2020-09-01 15:41:59 +0200645 l->rx.flags |= RX_F_INHERITED;
William Lallemand75ea0a02017-11-15 19:02:58 +0100646
Amaury Denoyelle7f8f6cb2020-11-10 14:24:31 +0100647 l->extra_counters = NULL;
648
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100649 HA_SPIN_INIT(&l->lock);
Olivier Houchard64213e92019-03-08 18:52:57 +0100650 _HA_ATOMIC_ADD(&jobs, 1);
651 _HA_ATOMIC_ADD(&listeners, 1);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200652 }
653 return 1;
654}
655
Willy Tarreau1a64d162007-10-28 22:26:05 +0100656/* Delete a listener from its protocol's list of listeners. The listener's
657 * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
Willy Tarreau2cc5bae2017-09-15 08:18:11 +0200658 * number of listeners is updated, as well as the global number of listeners
659 * and jobs. Note that the listener must have previously been unbound. This
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200660 * is a low-level function expected to be called with the proto_lock and the
661 * listener's lock held.
Willy Tarreau1a64d162007-10-28 22:26:05 +0100662 */
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200663void __delete_listener(struct listener *listener)
Willy Tarreau1a64d162007-10-28 22:26:05 +0100664{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100665 if (listener->state == LI_ASSIGNED) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200666 listener_set_state(listener, LI_INIT);
Willy Tarreaub7436612020-08-28 19:51:44 +0200667 LIST_DEL(&listener->rx.proto_list);
Willy Tarreaud7f331c2020-09-25 17:01:43 +0200668 listener->rx.proto->nb_receivers--;
Olivier Houchard64213e92019-03-08 18:52:57 +0100669 _HA_ATOMIC_SUB(&jobs, 1);
670 _HA_ATOMIC_SUB(&listeners, 1);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100671 }
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200672}
673
674/* Delete a listener from its protocol's list of listeners (please check
675 * __delete_listener() above). The proto_lock and the listener's lock will
676 * be grabbed in this order.
677 */
678void delete_listener(struct listener *listener)
679{
680 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
681 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
682 __delete_listener(listener);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100683 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau6ee9f8d2019-08-26 10:55:52 +0200684 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
Willy Tarreau1a64d162007-10-28 22:26:05 +0100685}
686
Willy Tarreaue2711c72019-02-27 15:39:41 +0100687/* Returns a suitable value for a listener's backlog. It uses the listener's,
688 * otherwise the frontend's backlog, otherwise the listener's maxconn,
689 * otherwise the frontend's maxconn, otherwise 1024.
690 */
691int listener_backlog(const struct listener *l)
692{
693 if (l->backlog)
694 return l->backlog;
695
696 if (l->bind_conf->frontend->backlog)
697 return l->bind_conf->frontend->backlog;
698
699 if (l->maxconn)
700 return l->maxconn;
701
702 if (l->bind_conf->frontend->maxconn)
703 return l->bind_conf->frontend->maxconn;
704
705 return 1024;
706}
707
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200708/* This function is called on a read event from a listening socket, corresponding
709 * to an accept. It tries to accept as many connections as possible, and for each
710 * calls the listener's accept handler (generally the frontend's accept handler).
711 */
Willy Tarreaua74cb382020-10-15 21:29:49 +0200712void listener_accept(struct listener *l)
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200713{
Willy Tarreau83efc322020-10-14 17:37:17 +0200714 struct connection *cli_conn;
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100715 struct proxy *p;
Christopher Faulet102854c2019-04-30 12:17:13 +0200716 unsigned int max_accept;
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100717 int next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100718 int next_feconn = 0;
719 int next_actconn = 0;
Willy Tarreaubb660302014-05-07 19:47:02 +0200720 int expire;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200721 int ret;
722
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100723 p = l->bind_conf->frontend;
Christopher Faulet102854c2019-04-30 12:17:13 +0200724
725 /* if l->maxaccept is -1, then max_accept is UINT_MAX. It is not really
726 * illimited, but it is probably enough.
727 */
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100728 max_accept = l->maxaccept ? l->maxaccept : 1;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200729
Willy Tarreau93e7c002013-10-07 18:51:07 +0200730 if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
731 int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
Willy Tarreau93e7c002013-10-07 18:51:07 +0200732
733 if (unlikely(!max)) {
734 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200735 expire = tick_add(now_ms, next_event_delay(&global.sess_per_sec, global.sps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100736 goto limit_global;
Willy Tarreau93e7c002013-10-07 18:51:07 +0200737 }
738
739 if (max_accept > max)
740 max_accept = max;
741 }
742
743 if (!(l->options & LI_O_UNLIMITED) && global.cps_lim) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200744 int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
745
746 if (unlikely(!max)) {
747 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200748 expire = tick_add(now_ms, next_event_delay(&global.conn_per_sec, global.cps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100749 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200750 }
751
752 if (max_accept > max)
753 max_accept = max;
754 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200755#ifdef USE_OPENSSL
756 if (!(l->options & LI_O_UNLIMITED) && global.ssl_lim && l->bind_conf && l->bind_conf->is_ssl) {
757 int max = freq_ctr_remain(&global.ssl_per_sec, global.ssl_lim, 0);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200758
Willy Tarreaue43d5322013-10-07 20:01:52 +0200759 if (unlikely(!max)) {
760 /* frontend accept rate limit was reached */
Willy Tarreaue43d5322013-10-07 20:01:52 +0200761 expire = tick_add(now_ms, next_event_delay(&global.ssl_per_sec, global.ssl_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100762 goto limit_global;
Willy Tarreaue43d5322013-10-07 20:01:52 +0200763 }
764
765 if (max_accept > max)
766 max_accept = max;
767 }
768#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200769 if (p && p->fe_sps_lim) {
770 int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0);
771
772 if (unlikely(!max)) {
773 /* frontend accept rate limit was reached */
Willy Tarreau0591bf72019-12-10 12:01:21 +0100774 expire = tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0));
775 goto limit_proxy;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200776 }
777
778 if (max_accept > max)
779 max_accept = max;
780 }
781
782 /* Note: if we fail to allocate a connection because of configured
783 * limits, we'll schedule a new attempt worst 1 second later in the
784 * worst case. If we fail due to system limits or temporary resource
785 * shortage, we try again 100ms later in the worst case.
786 */
Willy Tarreau02757d02021-01-28 18:07:24 +0100787 for (; max_accept; next_conn = next_feconn = next_actconn = 0, max_accept--) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200788 unsigned int count;
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200789 int status;
Willy Tarreau0aa5a5b2020-10-16 17:43:04 +0200790 __decl_thread(unsigned long mask);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200791
Willy Tarreau82c97892019-02-27 19:32:32 +0100792 /* pre-increase the number of connections without going too far.
793 * We process the listener, then the proxy, then the process.
794 * We know which ones to unroll based on the next_xxx value.
795 */
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100796 do {
797 count = l->nbconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100798 if (unlikely(l->maxconn && count >= l->maxconn)) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100799 /* the listener was marked full or another
800 * thread is going to do it.
801 */
802 next_conn = 0;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100803 listener_full(l);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100804 goto end;
805 }
806 next_conn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000807 } while (!_HA_ATOMIC_CAS(&l->nbconn, (int *)(&count), next_conn));
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100808
Willy Tarreau82c97892019-02-27 19:32:32 +0100809 if (p) {
810 do {
811 count = p->feconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100812 if (unlikely(count >= p->maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100813 /* the frontend was marked full or another
814 * thread is going to do it.
815 */
816 next_feconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100817 expire = TICK_ETERNITY;
818 goto limit_proxy;
Willy Tarreau82c97892019-02-27 19:32:32 +0100819 }
820 next_feconn = count + 1;
Olivier Houchard64213e92019-03-08 18:52:57 +0100821 } while (!_HA_ATOMIC_CAS(&p->feconn, &count, next_feconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200822 }
823
Willy Tarreau82c97892019-02-27 19:32:32 +0100824 if (!(l->options & LI_O_UNLIMITED)) {
825 do {
826 count = actconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100827 if (unlikely(count >= global.maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100828 /* the process was marked full or another
829 * thread is going to do it.
830 */
831 next_actconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100832 expire = tick_add(now_ms, 1000); /* try again in 1 second */
833 goto limit_global;
Willy Tarreau82c97892019-02-27 19:32:32 +0100834 }
835 next_actconn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000836 } while (!_HA_ATOMIC_CAS(&actconn, (int *)(&count), next_actconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200837 }
838
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200839 cli_conn = l->rx.proto->accept_conn(l, &status);
840 if (!cli_conn) {
841 switch (status) {
842 case CO_AC_DONE:
843 goto end;
Willy Tarreau818dca52014-01-31 19:40:19 +0100844
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200845 case CO_AC_RETRY: /* likely a signal */
Olivier Houchard64213e92019-03-08 18:52:57 +0100846 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100847 if (p)
Olivier Houchard64213e92019-03-08 18:52:57 +0100848 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100849 if (!(l->options & LI_O_UNLIMITED))
Olivier Houchard64213e92019-03-08 18:52:57 +0100850 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreaua593ec52014-01-20 21:21:30 +0100851 continue;
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200852
853 case CO_AC_YIELD:
Willy Tarreau92079932019-12-10 09:30:05 +0100854 max_accept = 0;
855 goto end;
William Lallemandd9138002018-11-27 12:02:39 +0100856
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200857 default:
858 goto transient_error;
Willy Tarreau83efc322020-10-14 17:37:17 +0200859 }
860 }
861
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100862 /* The connection was accepted, it must be counted as such */
863 if (l->counters)
864 HA_ATOMIC_UPDATE_MAX(&l->counters->conn_max, next_conn);
865
Willy Tarreau82c97892019-02-27 19:32:32 +0100866 if (p)
867 HA_ATOMIC_UPDATE_MAX(&p->fe_counters.conn_max, next_feconn);
868
869 proxy_inc_fe_conn_ctr(l, p);
870
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100871 if (!(l->options & LI_O_UNLIMITED)) {
872 count = update_freq_ctr(&global.conn_per_sec, 1);
873 HA_ATOMIC_UPDATE_MAX(&global.cps_max, count);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100874 }
875
Willy Tarreau64a9c052019-04-12 15:27:17 +0200876 _HA_ATOMIC_ADD(&activity[tid].accepted, 1);
877
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200878 if (unlikely(cli_conn->handle.fd >= global.maxsock)) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200879 send_log(p, LOG_EMERG,
880 "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n",
881 p->id);
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200882 close(cli_conn->handle.fd);
William Dauchy835712a2020-10-18 18:37:43 +0200883 conn_free(cli_conn);
Willy Tarreau0591bf72019-12-10 12:01:21 +0100884 expire = tick_add(now_ms, 1000); /* try again in 1 second */
885 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200886 }
887
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100888 /* past this point, l->accept() will automatically decrement
Willy Tarreau82c97892019-02-27 19:32:32 +0100889 * l->nbconn, feconn and actconn once done. Setting next_*conn=0
890 * allows the error path not to rollback on nbconn. It's more
891 * convenient than duplicating all exit labels.
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100892 */
893 next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100894 next_feconn = 0;
895 next_actconn = 0;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200896
Willy Tarreau83efc322020-10-14 17:37:17 +0200897
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100898#if defined(USE_THREAD)
Willy Tarreau818a92e2020-09-03 07:50:19 +0200899 mask = thread_mask(l->rx.settings->bind_thread) & all_threads_mask;
Willy Tarreaua7da5e82020-03-12 17:33:29 +0100900 if (atleast2(mask) && (global.tune.options & GTUNE_LISTENER_MQ) && !stopping) {
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100901 struct accept_queue_ring *ring;
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100902 unsigned int t, t0, t1, t2;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100903
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100904 /* The principle is that we have two running indexes,
905 * each visiting in turn all threads bound to this
906 * listener. The connection will be assigned to the one
907 * with the least connections, and the other one will
908 * be updated. This provides a good fairness on short
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100909 * connections (round robin) and on long ones (conn
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100910 * count), without ever missing any idle thread.
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100911 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100912
913 /* keep a copy for the final update. thr_idx is composite
914 * and made of (t2<<16) + t1.
915 */
Willy Tarreau0cf33172019-03-06 15:26:33 +0100916 t0 = l->thr_idx;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100917 do {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100918 unsigned long m1, m2;
919 int q1, q2;
920
921 t2 = t1 = t0;
922 t2 >>= 16;
923 t1 &= 0xFFFF;
924
925 /* t1 walks low to high bits ;
926 * t2 walks high to low.
927 */
928 m1 = mask >> t1;
929 m2 = mask & (t2 ? nbits(t2 + 1) : ~0UL);
930
Willy Tarreau85d04242019-04-16 18:09:13 +0200931 if (unlikely(!(m1 & 1))) {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100932 m1 &= ~1UL;
933 if (!m1) {
934 m1 = mask;
935 t1 = 0;
936 }
937 t1 += my_ffsl(m1) - 1;
938 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100939
Willy Tarreau85d04242019-04-16 18:09:13 +0200940 if (unlikely(!(m2 & (1UL << t2)) || t1 == t2)) {
941 /* highest bit not set */
942 if (!m2)
943 m2 = mask;
944
945 t2 = my_flsl(m2) - 1;
946 }
947
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100948 /* now we have two distinct thread IDs belonging to the mask */
949 q1 = accept_queue_rings[t1].tail - accept_queue_rings[t1].head + ACCEPT_QUEUE_SIZE;
950 if (q1 >= ACCEPT_QUEUE_SIZE)
951 q1 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100952
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100953 q2 = accept_queue_rings[t2].tail - accept_queue_rings[t2].head + ACCEPT_QUEUE_SIZE;
954 if (q2 >= ACCEPT_QUEUE_SIZE)
955 q2 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100956
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100957 /* we have 3 possibilities now :
958 * q1 < q2 : t1 is less loaded than t2, so we pick it
959 * and update t2 (since t1 might still be
960 * lower than another thread)
961 * q1 > q2 : t2 is less loaded than t1, so we pick it
962 * and update t1 (since t2 might still be
963 * lower than another thread)
964 * q1 = q2 : both are equally loaded, thus we pick t1
965 * and update t1 as it will become more loaded
966 * than t2.
967 */
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100968
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100969 q1 += l->thr_conn[t1];
970 q2 += l->thr_conn[t2];
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100971
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100972 if (q1 - q2 < 0) {
973 t = t1;
974 t2 = t2 ? t2 - 1 : LONGBITS - 1;
975 }
976 else if (q1 - q2 > 0) {
977 t = t2;
978 t1++;
979 if (t1 >= LONGBITS)
980 t1 = 0;
981 }
982 else {
983 t = t1;
984 t1++;
985 if (t1 >= LONGBITS)
986 t1 = 0;
987 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100988
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100989 /* new value for thr_idx */
990 t1 += (t2 << 16);
Olivier Houchard64213e92019-03-08 18:52:57 +0100991 } while (unlikely(!_HA_ATOMIC_CAS(&l->thr_idx, &t0, t1)));
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100992
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100993 /* We successfully selected the best thread "t" for this
994 * connection. We use deferred accepts even if it's the
995 * local thread because tests show that it's the best
996 * performing model, likely due to better cache locality
997 * when processing this loop.
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100998 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100999 ring = &accept_queue_rings[t];
Willy Tarreau83efc322020-10-14 17:37:17 +02001000 if (accept_queue_push_mp(ring, cli_conn)) {
Olivier Houchard64213e92019-03-08 18:52:57 +01001001 _HA_ATOMIC_ADD(&activity[t].accq_pushed, 1);
Willy Tarreau2bd65a72019-09-24 06:55:18 +02001002 tasklet_wakeup(ring->tasklet);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001003 continue;
1004 }
1005 /* If the ring is full we do a synchronous accept on
1006 * the local thread here.
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001007 */
Olivier Houchard64213e92019-03-08 18:52:57 +01001008 _HA_ATOMIC_ADD(&activity[t].accq_full, 1);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001009 }
1010#endif // USE_THREAD
1011
Olivier Houchard64213e92019-03-08 18:52:57 +01001012 _HA_ATOMIC_ADD(&l->thr_conn[tid], 1);
Willy Tarreau83efc322020-10-14 17:37:17 +02001013 ret = l->accept(cli_conn);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001014 if (unlikely(ret <= 0)) {
Willy Tarreau87b09662015-04-03 00:22:06 +02001015 /* The connection was closed by stream_accept(). Either
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001016 * we just have to ignore it (ret == 0) or it's a critical
1017 * error due to a resource shortage, and we must stop the
1018 * listener (ret < 0).
1019 */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001020 if (ret == 0) /* successful termination */
1021 continue;
1022
Willy Tarreaubb660302014-05-07 19:47:02 +02001023 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001024 }
1025
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001026 /* increase the per-process number of cumulated sessions, this
1027 * may only be done once l->accept() has accepted the connection.
1028 */
Willy Tarreau93e7c002013-10-07 18:51:07 +02001029 if (!(l->options & LI_O_UNLIMITED)) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001030 count = update_freq_ctr(&global.sess_per_sec, 1);
1031 HA_ATOMIC_UPDATE_MAX(&global.sps_max, count);
Willy Tarreau93e7c002013-10-07 18:51:07 +02001032 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001033#ifdef USE_OPENSSL
1034 if (!(l->options & LI_O_UNLIMITED) && l->bind_conf && l->bind_conf->is_ssl) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001035 count = update_freq_ctr(&global.ssl_per_sec, 1);
1036 HA_ATOMIC_UPDATE_MAX(&global.ssl_max, count);
Willy Tarreaue43d5322013-10-07 20:01:52 +02001037 }
1038#endif
Willy Tarreau93e7c002013-10-07 18:51:07 +02001039
Willy Tarreau8d2c98b2020-05-01 09:51:11 +02001040 ti->flags &= ~TI_FL_STUCK; // this thread is still running
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001041 } /* end of for (max_accept--) */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001042
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001043 end:
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001044 if (next_conn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001045 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau741b4d62019-02-25 15:02:04 +01001046
Willy Tarreau82c97892019-02-27 19:32:32 +01001047 if (p && next_feconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001048 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001049
1050 if (next_actconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001051 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001052
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001053 if ((l->state == LI_FULL && (!l->maxconn || l->nbconn < l->maxconn)) ||
Willy Tarreau02757d02021-01-28 18:07:24 +01001054 (l->state == LI_LIMITED &&
Willy Tarreaucdcba112019-12-11 15:06:30 +01001055 ((!p || p->feconn < p->maxconn) && (actconn < global.maxconn) &&
1056 (!tick_isset(global_listener_queue_task->expire) ||
1057 tick_is_expired(global_listener_queue_task->expire, now_ms))))) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001058 /* at least one thread has to this when quitting */
1059 resume_listener(l);
1060
Willy Tarreau02757d02021-01-28 18:07:24 +01001061 /* Dequeues all of the listeners waiting for a resource */
Willy Tarreau241797a2019-12-10 14:10:52 +01001062 dequeue_all_listeners();
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001063
Olivier Houchard859dc802019-08-08 15:47:21 +02001064 if (p && !MT_LIST_ISEMPTY(&p->listener_queue) &&
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001065 (!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 +01001066 dequeue_proxy_listeners(p);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001067 }
Willy Tarreau0591bf72019-12-10 12:01:21 +01001068 return;
1069
1070 transient_error:
1071 /* pause the listener for up to 100 ms */
1072 expire = tick_add(now_ms, 100);
1073
Willy Tarreau258b3512020-10-13 17:46:05 +02001074 /* This may be a shared socket that was paused by another process.
1075 * Let's put it to pause in this case.
1076 */
1077 if (l->rx.proto && l->rx.proto->rx_listening(&l->rx) == 0) {
1078 pause_listener(l);
1079 goto end;
1080 }
1081
Willy Tarreau0591bf72019-12-10 12:01:21 +01001082 limit_global:
1083 /* (re-)queue the listener to the global queue and set it to expire no
1084 * later than <expire> ahead. The listener turns to LI_LIMITED.
1085 */
1086 limit_listener(l, &global_listener_queue);
1087 task_schedule(global_listener_queue_task, expire);
1088 goto end;
1089
1090 limit_proxy:
1091 /* (re-)queue the listener to the proxy's queue and set it to expire no
1092 * later than <expire> ahead. The listener turns to LI_LIMITED.
1093 */
1094 limit_listener(l, &p->listener_queue);
Willy Tarreaueeea8082020-01-08 19:15:07 +01001095 if (p->task && tick_isset(expire))
1096 task_schedule(p->task, expire);
Willy Tarreau0591bf72019-12-10 12:01:21 +01001097 goto end;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001098}
1099
Willy Tarreau05f50472017-09-15 09:19:58 +02001100/* Notify the listener that a connection initiated from it was released. This
1101 * is used to keep the connection count consistent and to possibly re-open
1102 * listening when it was limited.
1103 */
1104void listener_release(struct listener *l)
1105{
1106 struct proxy *fe = l->bind_conf->frontend;
1107
1108 if (!(l->options & LI_O_UNLIMITED))
Willy Tarreau02757d02021-01-28 18:07:24 +01001109 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001110 if (fe)
Olivier Houchard64213e92019-03-08 18:52:57 +01001111 _HA_ATOMIC_SUB(&fe->feconn, 1);
1112 _HA_ATOMIC_SUB(&l->nbconn, 1);
1113 _HA_ATOMIC_SUB(&l->thr_conn[tid], 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001114
1115 if (l->state == LI_FULL || l->state == LI_LIMITED)
Willy Tarreau05f50472017-09-15 09:19:58 +02001116 resume_listener(l);
1117
Willy Tarreau02757d02021-01-28 18:07:24 +01001118 /* Dequeues all of the listeners waiting for a resource */
1119 dequeue_all_listeners();
1120
Olivier Houchard859dc802019-08-08 15:47:21 +02001121 if (!MT_LIST_ISEMPTY(&fe->listener_queue) &&
Willy Tarreau05f50472017-09-15 09:19:58 +02001122 (!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 +01001123 dequeue_proxy_listeners(fe);
Willy Tarreau05f50472017-09-15 09:19:58 +02001124}
1125
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001126/* Initializes the listener queues. Returns 0 on success, otherwise ERR_* flags */
1127static int listener_queue_init()
1128{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001129 global_listener_queue_task = task_new(MAX_THREADS_MASK);
1130 if (!global_listener_queue_task) {
1131 ha_alert("Out of memory when initializing global listener queue\n");
1132 return ERR_FATAL|ERR_ABORT;
1133 }
1134 /* very simple initialization, users will queue the task if needed */
1135 global_listener_queue_task->context = NULL; /* not even a context! */
1136 global_listener_queue_task->process = manage_global_listener_queue;
1137
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001138 return 0;
1139}
1140
1141static void listener_queue_deinit()
1142{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001143 task_destroy(global_listener_queue_task);
1144 global_listener_queue_task = NULL;
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001145}
1146
1147REGISTER_CONFIG_POSTPARSER("multi-threaded listener queue", listener_queue_init);
1148REGISTER_POST_DEINIT(listener_queue_deinit);
1149
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001150
1151/* This is the global management task for listeners. It enables listeners waiting
1152 * for global resources when there are enough free resource, or at least once in
1153 * a while. It is designed to be called as a task.
1154 */
1155static struct task *manage_global_listener_queue(struct task *t, void *context, unsigned short state)
1156{
1157 /* If there are still too many concurrent connections, let's wait for
1158 * some of them to go away. We don't need to re-arm the timer because
1159 * each of them will scan the queue anyway.
1160 */
1161 if (unlikely(actconn >= global.maxconn))
1162 goto out;
1163
1164 /* We should periodically try to enable listeners waiting for a global
1165 * resource here, because it is possible, though very unlikely, that
1166 * they have been blocked by a temporary lack of global resource such
1167 * as a file descriptor or memory and that the temporary condition has
1168 * disappeared.
1169 */
1170 dequeue_all_listeners();
1171
1172 out:
1173 t->expire = TICK_ETERNITY;
1174 task_queue(t);
1175 return t;
1176}
1177
Willy Tarreau26982662012-09-12 23:17:10 +02001178/*
1179 * Registers the bind keyword list <kwl> as a list of valid keywords for next
1180 * parsing sessions.
1181 */
1182void bind_register_keywords(struct bind_kw_list *kwl)
1183{
1184 LIST_ADDQ(&bind_keywords.list, &kwl->list);
1185}
1186
1187/* Return a pointer to the bind keyword <kw>, or NULL if not found. If the
1188 * keyword is found with a NULL ->parse() function, then an attempt is made to
1189 * find one with a valid ->parse() function. This way it is possible to declare
1190 * platform-dependant, known keywords as NULL, then only declare them as valid
1191 * if some options are met. Note that if the requested keyword contains an
1192 * opening parenthesis, everything from this point is ignored.
1193 */
1194struct bind_kw *bind_find_kw(const char *kw)
1195{
1196 int index;
1197 const char *kwend;
1198 struct bind_kw_list *kwl;
1199 struct bind_kw *ret = NULL;
1200
1201 kwend = strchr(kw, '(');
1202 if (!kwend)
1203 kwend = kw + strlen(kw);
1204
1205 list_for_each_entry(kwl, &bind_keywords.list, list) {
1206 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1207 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
1208 kwl->kw[index].kw[kwend-kw] == 0) {
1209 if (kwl->kw[index].parse)
1210 return &kwl->kw[index]; /* found it !*/
1211 else
1212 ret = &kwl->kw[index]; /* may be OK */
1213 }
1214 }
1215 }
1216 return ret;
1217}
1218
Willy Tarreau8638f482012-09-18 18:01:17 +02001219/* Dumps all registered "bind" keywords to the <out> string pointer. The
1220 * unsupported keywords are only dumped if their supported form was not
1221 * found.
1222 */
1223void bind_dump_kws(char **out)
1224{
1225 struct bind_kw_list *kwl;
1226 int index;
1227
Christopher Faulet784063e2020-05-18 12:14:18 +02001228 if (!out)
1229 return;
1230
Willy Tarreau8638f482012-09-18 18:01:17 +02001231 *out = NULL;
1232 list_for_each_entry(kwl, &bind_keywords.list, list) {
1233 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1234 if (kwl->kw[index].parse ||
1235 bind_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) {
Willy Tarreau51fb7652012-09-18 18:24:39 +02001236 memprintf(out, "%s[%4s] %s%s%s\n", *out ? *out : "",
1237 kwl->scope,
Willy Tarreau8638f482012-09-18 18:01:17 +02001238 kwl->kw[index].kw,
Willy Tarreau51fb7652012-09-18 18:24:39 +02001239 kwl->kw[index].skip ? " <arg>" : "",
1240 kwl->kw[index].parse ? "" : " (not supported)");
Willy Tarreau8638f482012-09-18 18:01:17 +02001241 }
1242 }
1243 }
1244}
1245
Willy Tarreau645513a2010-05-24 20:55:15 +02001246/************************************************************************/
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001247/* All supported sample and ACL keywords must be declared here. */
Willy Tarreau645513a2010-05-24 20:55:15 +02001248/************************************************************************/
1249
Willy Tarreaua5e37562011-12-16 17:06:15 +01001250/* set temp integer to the number of connexions to the same listening socket */
Willy Tarreau645513a2010-05-24 20:55:15 +02001251static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001252smp_fetch_dconn(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau645513a2010-05-24 20:55:15 +02001253{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001254 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001255 smp->data.u.sint = smp->sess->listener->nbconn;
Willy Tarreau645513a2010-05-24 20:55:15 +02001256 return 1;
1257}
1258
Willy Tarreaua5e37562011-12-16 17:06:15 +01001259/* set temp integer to the id of the socket (listener) */
Willy Tarreau645513a2010-05-24 20:55:15 +02001260static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001261smp_fetch_so_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau37406352012-04-23 16:16:37 +02001262{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001263 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001264 smp->data.u.sint = smp->sess->listener->luid;
Willy Tarreau645513a2010-05-24 20:55:15 +02001265 return 1;
1266}
Jerome Magnineb421b22020-03-27 22:08:40 +01001267static int
1268smp_fetch_so_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
1269{
1270 smp->data.u.str.area = smp->sess->listener->name;
1271 if (!smp->data.u.str.area)
1272 return 0;
1273
1274 smp->data.type = SMP_T_STR;
1275 smp->flags = SMP_F_CONST;
1276 smp->data.u.str.data = strlen(smp->data.u.str.area);
1277 return 1;
1278}
Willy Tarreau645513a2010-05-24 20:55:15 +02001279
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001280/* parse the "accept-proxy" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001281static 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 +02001282{
1283 struct listener *l;
1284
Willy Tarreau4348fad2012-09-20 16:48:07 +02001285 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001286 l->options |= LI_O_ACC_PROXY;
1287
1288 return 0;
1289}
1290
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001291/* parse the "accept-netscaler-cip" bind keyword */
1292static int bind_parse_accept_netscaler_cip(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1293{
1294 struct listener *l;
1295 uint32_t val;
1296
1297 if (!*args[cur_arg + 1]) {
1298 memprintf(err, "'%s' : missing value", args[cur_arg]);
1299 return ERR_ALERT | ERR_FATAL;
1300 }
1301
1302 val = atol(args[cur_arg + 1]);
1303 if (val <= 0) {
Willy Tarreaue2711c72019-02-27 15:39:41 +01001304 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001305 return ERR_ALERT | ERR_FATAL;
1306 }
1307
1308 list_for_each_entry(l, &conf->listeners, by_bind) {
1309 l->options |= LI_O_ACC_CIP;
1310 conf->ns_cip_magic = val;
1311 }
1312
1313 return 0;
1314}
1315
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001316/* parse the "backlog" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001317static 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 +02001318{
1319 struct listener *l;
1320 int val;
1321
1322 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001323 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001324 return ERR_ALERT | ERR_FATAL;
1325 }
1326
1327 val = atol(args[cur_arg + 1]);
Willy Tarreaue2711c72019-02-27 15:39:41 +01001328 if (val < 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001329 memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001330 return ERR_ALERT | ERR_FATAL;
1331 }
1332
Willy Tarreau4348fad2012-09-20 16:48:07 +02001333 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001334 l->backlog = val;
1335
1336 return 0;
1337}
1338
1339/* parse the "id" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001340static 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 +02001341{
1342 struct eb32_node *node;
Willy Tarreau4348fad2012-09-20 16:48:07 +02001343 struct listener *l, *new;
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001344 char *error;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001345
Willy Tarreau4348fad2012-09-20 16:48:07 +02001346 if (conf->listeners.n != conf->listeners.p) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001347 memprintf(err, "'%s' can only be used with a single socket", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001348 return ERR_ALERT | ERR_FATAL;
1349 }
1350
1351 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001352 memprintf(err, "'%s' : expects an integer argument", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001353 return ERR_ALERT | ERR_FATAL;
1354 }
1355
Willy Tarreau4348fad2012-09-20 16:48:07 +02001356 new = LIST_NEXT(&conf->listeners, struct listener *, by_bind);
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001357 new->luid = strtol(args[cur_arg + 1], &error, 10);
1358 if (*error != '\0') {
1359 memprintf(err, "'%s' : expects an integer argument, found '%s'", args[cur_arg], args[cur_arg + 1]);
1360 return ERR_ALERT | ERR_FATAL;
1361 }
Willy Tarreau4348fad2012-09-20 16:48:07 +02001362 new->conf.id.key = new->luid;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001363
Willy Tarreau4348fad2012-09-20 16:48:07 +02001364 if (new->luid <= 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001365 memprintf(err, "'%s' : custom id has to be > 0", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001366 return ERR_ALERT | ERR_FATAL;
1367 }
1368
Willy Tarreau4348fad2012-09-20 16:48:07 +02001369 node = eb32_lookup(&px->conf.used_listener_id, new->luid);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001370 if (node) {
1371 l = container_of(node, struct listener, conf.id);
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001372 memprintf(err, "'%s' : custom id %d already used at %s:%d ('bind %s')",
1373 args[cur_arg], l->luid, l->bind_conf->file, l->bind_conf->line,
1374 l->bind_conf->arg);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001375 return ERR_ALERT | ERR_FATAL;
1376 }
1377
Willy Tarreau4348fad2012-09-20 16:48:07 +02001378 eb32_insert(&px->conf.used_listener_id, &new->conf.id);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001379 return 0;
1380}
1381
1382/* parse the "maxconn" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001383static 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 +02001384{
1385 struct listener *l;
1386 int val;
1387
1388 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001389 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001390 return ERR_ALERT | ERR_FATAL;
1391 }
1392
1393 val = atol(args[cur_arg + 1]);
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001394 if (val < 0) {
1395 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001396 return ERR_ALERT | ERR_FATAL;
1397 }
1398
Willy Tarreau4348fad2012-09-20 16:48:07 +02001399 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001400 l->maxconn = val;
1401
1402 return 0;
1403}
1404
1405/* parse the "name" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001406static 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 +02001407{
1408 struct listener *l;
1409
1410 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001411 memprintf(err, "'%s' : missing name", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001412 return ERR_ALERT | ERR_FATAL;
1413 }
1414
Willy Tarreau4348fad2012-09-20 16:48:07 +02001415 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001416 l->name = strdup(args[cur_arg + 1]);
1417
1418 return 0;
1419}
1420
1421/* parse the "nice" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001422static 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 +02001423{
1424 struct listener *l;
1425 int val;
1426
1427 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001428 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001429 return ERR_ALERT | ERR_FATAL;
1430 }
1431
1432 val = atol(args[cur_arg + 1]);
1433 if (val < -1024 || val > 1024) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001434 memprintf(err, "'%s' : invalid value %d, allowed range is -1024..1024", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001435 return ERR_ALERT | ERR_FATAL;
1436 }
1437
Willy Tarreau4348fad2012-09-20 16:48:07 +02001438 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001439 l->nice = val;
1440
1441 return 0;
1442}
1443
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001444/* parse the "process" bind keyword */
1445static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1446{
Christopher Fauletc644fa92017-11-23 22:44:11 +01001447 char *slash;
1448 unsigned long proc = 0, thread = 0;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001449
Christopher Fauletc644fa92017-11-23 22:44:11 +01001450 if ((slash = strchr(args[cur_arg + 1], '/')) != NULL)
1451 *slash = 0;
1452
Willy Tarreauff9c9142019-02-07 10:39:36 +01001453 if (parse_process_number(args[cur_arg + 1], &proc, MAX_PROCS, NULL, err)) {
Christopher Fauletf1f0c5f2017-11-22 12:06:43 +01001454 memprintf(err, "'%s' : %s", args[cur_arg], *err);
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001455 return ERR_ALERT | ERR_FATAL;
1456 }
1457
Christopher Fauletc644fa92017-11-23 22:44:11 +01001458 if (slash) {
Willy Tarreauc9a82e42019-01-26 13:25:14 +01001459 if (parse_process_number(slash+1, &thread, MAX_THREADS, NULL, err)) {
Christopher Fauletc644fa92017-11-23 22:44:11 +01001460 memprintf(err, "'%s' : %s", args[cur_arg], *err);
1461 return ERR_ALERT | ERR_FATAL;
1462 }
1463 *slash = '/';
1464 }
1465
Willy Tarreaue26993c2020-09-03 07:18:55 +02001466 conf->settings.bind_proc |= proc;
1467 conf->settings.bind_thread |= thread;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001468 return 0;
1469}
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001470
Christopher Fauleta717b992018-04-10 14:43:00 +02001471/* parse the "proto" bind keyword */
1472static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1473{
1474 struct ist proto;
1475
1476 if (!*args[cur_arg + 1]) {
1477 memprintf(err, "'%s' : missing value", args[cur_arg]);
1478 return ERR_ALERT | ERR_FATAL;
1479 }
1480
1481 proto = ist2(args[cur_arg + 1], strlen(args[cur_arg + 1]));
1482 conf->mux_proto = get_mux_proto(proto);
1483 if (!conf->mux_proto) {
1484 memprintf(err, "'%s' : unknown MUX protocol '%s'", args[cur_arg], args[cur_arg+1]);
1485 return ERR_ALERT | ERR_FATAL;
1486 }
Christopher Fauleta717b992018-04-10 14:43:00 +02001487 return 0;
1488}
1489
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001490/* config parser for global "tune.listener.multi-queue", accepts "on" or "off" */
1491static int cfg_parse_tune_listener_mq(char **args, int section_type, struct proxy *curpx,
1492 struct proxy *defpx, const char *file, int line,
1493 char **err)
1494{
1495 if (too_many_args(1, args, err, NULL))
1496 return -1;
1497
1498 if (strcmp(args[1], "on") == 0)
1499 global.tune.options |= GTUNE_LISTENER_MQ;
1500 else if (strcmp(args[1], "off") == 0)
1501 global.tune.options &= ~GTUNE_LISTENER_MQ;
1502 else {
1503 memprintf(err, "'%s' expects either 'on' or 'off' but got '%s'.", args[0], args[1]);
1504 return -1;
1505 }
1506 return 0;
1507}
1508
Willy Tarreau61612d42012-04-19 18:42:05 +02001509/* Note: must not be declared <const> as its list will be overwritten.
1510 * Please take care of keeping this list alphabetically sorted.
1511 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001512static struct sample_fetch_kw_list smp_kws = {ILH, {
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02001513 { "dst_conn", smp_fetch_dconn, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
1514 { "so_id", smp_fetch_so_id, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
Jerome Magnineb421b22020-03-27 22:08:40 +01001515 { "so_name", smp_fetch_so_name, 0, NULL, SMP_T_STR, SMP_USE_FTEND, },
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001516 { /* END */ },
1517}};
1518
Willy Tarreau0108d902018-11-25 19:14:37 +01001519INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
1520
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001521/* Note: must not be declared <const> as its list will be overwritten.
1522 * Please take care of keeping this list alphabetically sorted.
1523 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001524static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001525 { /* END */ },
Willy Tarreau645513a2010-05-24 20:55:15 +02001526}};
1527
Willy Tarreau0108d902018-11-25 19:14:37 +01001528INITCALL1(STG_REGISTER, acl_register_keywords, &acl_kws);
1529
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001530/* Note: must not be declared <const> as its list will be overwritten.
1531 * Please take care of keeping this list alphabetically sorted, doing so helps
1532 * all code contributors.
1533 * Optional keywords are also declared with a NULL ->parse() function so that
1534 * the config parser can report an appropriate error when a known keyword was
1535 * not enabled.
1536 */
Willy Tarreau51fb7652012-09-18 18:24:39 +02001537static struct bind_kw_list bind_kws = { "ALL", { }, {
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001538 { "accept-netscaler-cip", bind_parse_accept_netscaler_cip, 1 }, /* enable NetScaler Client IP insertion protocol */
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001539 { "accept-proxy", bind_parse_accept_proxy, 0 }, /* enable PROXY protocol */
1540 { "backlog", bind_parse_backlog, 1 }, /* set backlog of listening socket */
1541 { "id", bind_parse_id, 1 }, /* set id of listening socket */
1542 { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */
1543 { "name", bind_parse_name, 1 }, /* set name of listening socket */
1544 { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001545 { "process", bind_parse_process, 1 }, /* set list of allowed process for this socket */
Christopher Fauleta717b992018-04-10 14:43:00 +02001546 { "proto", bind_parse_proto, 1 }, /* set the proto to use for all incoming connections */
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001547 { /* END */ },
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001548}};
1549
Willy Tarreau0108d902018-11-25 19:14:37 +01001550INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
1551
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001552/* config keyword parsers */
1553static struct cfg_kw_list cfg_kws = {ILH, {
1554 { CFG_GLOBAL, "tune.listener.multi-queue", cfg_parse_tune_listener_mq },
1555 { 0, NULL, NULL }
1556}};
1557
1558INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
1559
Willy Tarreau645513a2010-05-24 20:55:15 +02001560/*
1561 * Local variables:
1562 * c-indent-level: 8
1563 * c-basic-offset: 8
1564 * End:
1565 */