blob: 0b929b906f2347d7833d404fdc7f0e123f4b6a77 [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;
Willy Tarreaua1d97f82019-12-10 11:18:41 +010048
49
Willy Tarreau1efafce2019-01-27 15:37:19 +010050#if defined(USE_THREAD)
51
52struct accept_queue_ring accept_queue_rings[MAX_THREADS] __attribute__((aligned(64))) = { };
53
54/* dequeue and process a pending connection from the local accept queue (single
Willy Tarreau83efc322020-10-14 17:37:17 +020055 * consumer). Returns the accepted connection or NULL if none was found.
Willy Tarreau1efafce2019-01-27 15:37:19 +010056 */
Willy Tarreau83efc322020-10-14 17:37:17 +020057struct connection *accept_queue_pop_sc(struct accept_queue_ring *ring)
Willy Tarreau1efafce2019-01-27 15:37:19 +010058{
Willy Tarreau1efafce2019-01-27 15:37:19 +010059 unsigned int pos, next;
Willy Tarreau83efc322020-10-14 17:37:17 +020060 struct connection *ptr;
61 struct connection **e;
Willy Tarreau1efafce2019-01-27 15:37:19 +010062
63 pos = ring->head;
64
65 if (pos == ring->tail)
Willy Tarreau83efc322020-10-14 17:37:17 +020066 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +010067
68 next = pos + 1;
69 if (next >= ACCEPT_QUEUE_SIZE)
70 next = 0;
71
72 e = &ring->entry[pos];
73
74 /* wait for the producer to update the listener's pointer */
75 while (1) {
Willy Tarreau83efc322020-10-14 17:37:17 +020076 ptr = *e;
Willy Tarreau1efafce2019-01-27 15:37:19 +010077 __ha_barrier_load();
78 if (ptr)
79 break;
80 pl_cpu_relax();
81 }
82
Willy Tarreau1efafce2019-01-27 15:37:19 +010083 /* release the entry */
Willy Tarreau83efc322020-10-14 17:37:17 +020084 *e = NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +010085
86 __ha_barrier_store();
87 ring->head = next;
Willy Tarreau83efc322020-10-14 17:37:17 +020088 return ptr;
Willy Tarreau1efafce2019-01-27 15:37:19 +010089}
90
91
Willy Tarreau83efc322020-10-14 17:37:17 +020092/* tries to push a new accepted connection <conn> into ring <ring>. Returns
93 * non-zero if it succeeds, or zero if the ring is full. Supports multiple
94 * producers.
Willy Tarreau1efafce2019-01-27 15:37:19 +010095 */
Willy Tarreau83efc322020-10-14 17:37:17 +020096int accept_queue_push_mp(struct accept_queue_ring *ring, struct connection *conn)
Willy Tarreau1efafce2019-01-27 15:37:19 +010097{
Willy Tarreau1efafce2019-01-27 15:37:19 +010098 unsigned int pos, next;
99
100 pos = ring->tail;
101 do {
102 next = pos + 1;
103 if (next >= ACCEPT_QUEUE_SIZE)
104 next = 0;
105 if (next == ring->head)
106 return 0; // ring full
Olivier Houchard64213e92019-03-08 18:52:57 +0100107 } while (unlikely(!_HA_ATOMIC_CAS(&ring->tail, &pos, next)));
Willy Tarreau1efafce2019-01-27 15:37:19 +0100108
Willy Tarreau83efc322020-10-14 17:37:17 +0200109 ring->entry[pos] = conn;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100110 __ha_barrier_store();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100111 return 1;
112}
113
Willy Tarreaufb5401f2021-01-29 12:25:23 +0100114/* proceed with accepting new connections. Don't mark it static so that it appears
115 * in task dumps.
116 */
117struct task *accept_queue_process(struct task *t, void *context, unsigned short state)
Willy Tarreau1efafce2019-01-27 15:37:19 +0100118{
119 struct accept_queue_ring *ring = context;
Willy Tarreau83efc322020-10-14 17:37:17 +0200120 struct connection *conn;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100121 struct listener *li;
Christopher Faulet102854c2019-04-30 12:17:13 +0200122 unsigned int max_accept;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100123 int ret;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100124
Christopher Faulet102854c2019-04-30 12:17:13 +0200125 /* if global.tune.maxaccept is -1, then max_accept is UINT_MAX. It
126 * is not really illimited, but it is probably enough.
127 */
128 max_accept = global.tune.maxaccept ? global.tune.maxaccept : 64;
129 for (; max_accept; max_accept--) {
Willy Tarreau83efc322020-10-14 17:37:17 +0200130 conn = accept_queue_pop_sc(ring);
131 if (!conn)
Willy Tarreau1efafce2019-01-27 15:37:19 +0100132 break;
133
Willy Tarreau83efc322020-10-14 17:37:17 +0200134 li = __objt_listener(conn->target);
Olivier Houchard64213e92019-03-08 18:52:57 +0100135 _HA_ATOMIC_ADD(&li->thr_conn[tid], 1);
Willy Tarreau83efc322020-10-14 17:37:17 +0200136 ret = li->accept(conn);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100137 if (ret <= 0) {
138 /* connection was terminated by the application */
139 continue;
140 }
141
142 /* increase the per-process number of cumulated sessions, this
143 * may only be done once l->accept() has accepted the connection.
144 */
145 if (!(li->options & LI_O_UNLIMITED)) {
146 HA_ATOMIC_UPDATE_MAX(&global.sps_max,
147 update_freq_ctr(&global.sess_per_sec, 1));
148 if (li->bind_conf && li->bind_conf->is_ssl) {
149 HA_ATOMIC_UPDATE_MAX(&global.ssl_max,
150 update_freq_ctr(&global.ssl_per_sec, 1));
151 }
152 }
153 }
154
155 /* ran out of budget ? Let's come here ASAP */
Christopher Faulet102854c2019-04-30 12:17:13 +0200156 if (!max_accept)
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200157 tasklet_wakeup(ring->tasklet);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100158
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200159 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100160}
161
162/* Initializes the accept-queues. Returns 0 on success, otherwise ERR_* flags */
163static int accept_queue_init()
164{
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200165 struct tasklet *t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100166 int i;
167
168 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200169 t = tasklet_new();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100170 if (!t) {
171 ha_alert("Out of memory while initializing accept queue for thread %d\n", i);
172 return ERR_FATAL|ERR_ABORT;
173 }
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200174 t->tid = i;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100175 t->process = accept_queue_process;
176 t->context = &accept_queue_rings[i];
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200177 accept_queue_rings[i].tasklet = t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100178 }
179 return 0;
180}
181
182REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
183
184#endif // USE_THREAD
185
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200186/* adjust the listener's state and its proxy's listener counters if needed.
187 * It must be called under the listener's lock, but uses atomic ops to change
188 * the proxy's counters so that the proxy lock is not needed.
189 */
Willy Tarreaua37b2442020-09-24 07:23:45 +0200190void listener_set_state(struct listener *l, enum li_state st)
191{
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200192 struct proxy *px = l->bind_conf->frontend;
193
194 if (px) {
195 /* from state */
196 switch (l->state) {
197 case LI_NEW: /* first call */
198 _HA_ATOMIC_ADD(&px->li_all, 1);
199 break;
200 case LI_INIT:
201 case LI_ASSIGNED:
202 break;
203 case LI_PAUSED:
204 _HA_ATOMIC_SUB(&px->li_paused, 1);
205 break;
206 case LI_LISTEN:
207 _HA_ATOMIC_SUB(&px->li_bound, 1);
208 break;
209 case LI_READY:
210 case LI_FULL:
211 case LI_LIMITED:
212 _HA_ATOMIC_SUB(&px->li_ready, 1);
213 break;
214 }
215
216 /* to state */
217 switch (st) {
218 case LI_NEW:
219 case LI_INIT:
220 case LI_ASSIGNED:
221 break;
222 case LI_PAUSED:
Willy Tarreau95a34602020-10-08 15:32:21 +0200223 BUG_ON(l->rx.fd == -1);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200224 _HA_ATOMIC_ADD(&px->li_paused, 1);
225 break;
226 case LI_LISTEN:
Willy Tarreau95a34602020-10-08 15:32:21 +0200227 BUG_ON(l->rx.fd == -1);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200228 _HA_ATOMIC_ADD(&px->li_bound, 1);
229 break;
230 case LI_READY:
231 case LI_FULL:
232 case LI_LIMITED:
Willy Tarreau95a34602020-10-08 15:32:21 +0200233 BUG_ON(l->rx.fd == -1);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200234 _HA_ATOMIC_ADD(&px->li_ready, 1);
235 break;
236 }
237 }
Willy Tarreaua37b2442020-09-24 07:23:45 +0200238 l->state = st;
239}
240
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100241/* This function adds the specified listener's file descriptor to the polling
242 * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500243 * LI_FULL state depending on its number of connections. In daemon mode, we
Willy Tarreauae302532014-05-07 19:22:24 +0200244 * also support binding only the relevant processes to their respective
245 * listeners. We don't do that in debug mode however.
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100246 */
Willy Tarreau7834a3f2020-09-25 16:40:18 +0200247void enable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100248{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100249 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaud6afb532020-10-09 10:35:40 +0200250
251 /* If this listener is supposed to be only in the master, close it in
252 * the workers. Conversely, if it's supposed to be only in the workers
253 * close it in the master.
254 */
Willy Tarreau18c20d22020-10-09 16:11:46 +0200255 if (!!master != !!(listener->rx.flags & RX_F_MWORKER))
Willy Tarreau75c98d12020-10-09 15:55:23 +0200256 do_unbind_listener(listener);
Willy Tarreaud6afb532020-10-09 10:35:40 +0200257
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100258 if (listener->state == LI_LISTEN) {
Willy Tarreau95a34602020-10-08 15:32:21 +0200259 BUG_ON(listener->rx.fd == -1);
William Lallemand095ba4c2017-06-01 17:38:50 +0200260 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau38dba272020-11-04 13:54:00 +0100261 (!!master != !!(listener->rx.flags & RX_F_MWORKER) ||
262 !(proc_mask(listener->rx.settings->bind_proc) & pid_bit))) {
Willy Tarreauae302532014-05-07 19:22:24 +0200263 /* we don't want to enable this listener and don't
264 * want any fd event to reach it.
265 */
Willy Tarreau75c98d12020-10-09 15:55:23 +0200266 do_unbind_listener(listener);
Willy Tarreauae302532014-05-07 19:22:24 +0200267 }
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100268 else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200269 listener->rx.proto->enable(listener);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200270 listener_set_state(listener, LI_READY);
Willy Tarreauae302532014-05-07 19:22:24 +0200271 }
272 else {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200273 listener_set_state(listener, LI_FULL);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100274 }
275 }
Willy Tarreaud6afb532020-10-09 10:35:40 +0200276
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100277 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100278}
279
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200280/*
281 * This function completely stops a listener. It will need to operate under the
282 * proxy's lock, the protocol's lock, and the listener's lock. The caller is
283 * responsible for indicating in lpx, lpr, lli whether the respective locks are
284 * already held (non-zero) or not (zero) so that the function picks the missing
285 * ones, in this order. The proxy's listeners count is updated and the proxy is
286 * disabled and woken up after the last one is gone.
287 */
288void stop_listener(struct listener *l, int lpx, int lpr, int lli)
289{
290 struct proxy *px = l->bind_conf->frontend;
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200291
292 if (l->options & LI_O_NOSTOP) {
293 /* master-worker sockpairs are never closed but don't count as a
294 * job.
295 */
296 return;
297 }
298
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200299 if (!lpx)
Willy Tarreauac66d6b2020-10-20 17:24:27 +0200300 HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200301
302 if (!lpr)
303 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
304
305 if (!lli)
306 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
307
308 if (l->state > LI_INIT) {
Willy Tarreau75c98d12020-10-09 15:55:23 +0200309 do_unbind_listener(l);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200310
311 if (l->state >= LI_ASSIGNED)
312 __delete_listener(l);
313
Willy Tarreauacde1522020-10-07 16:31:39 +0200314 proxy_cond_disable(px);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200315 }
316
317 if (!lli)
318 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
319
320 if (!lpr)
321 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
322
323 if (!lpx)
Willy Tarreauac66d6b2020-10-20 17:24:27 +0200324 HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200325}
326
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100327/* This function adds the specified <listener> to the protocol <proto>. It
328 * does nothing if the protocol was already added. The listener's state is
329 * automatically updated from LI_INIT to LI_ASSIGNED. The number of listeners
330 * for the protocol is updated. This must be called with the proto lock held.
331 */
332void default_add_listener(struct protocol *proto, struct listener *listener)
333{
334 if (listener->state != LI_INIT)
335 return;
336 listener_set_state(listener, LI_ASSIGNED);
337 listener->rx.proto = proto;
338 LIST_ADDQ(&proto->receivers, &listener->rx.proto_list);
339 proto->nb_receivers++;
340}
341
Willy Tarreaue03204c2020-10-09 17:02:21 +0200342/* default function called to suspend a listener: it simply passes the call to
343 * the underlying receiver. This is find for most socket-based protocols. This
344 * must be called under the listener's lock. It will return non-zero on success,
345 * 0 on failure. If no receiver-level suspend is provided, the operation is
346 * assumed to succeed.
347 */
348int default_suspend_listener(struct listener *l)
349{
350 int ret = 1;
351
352 if (!l->rx.proto->rx_suspend)
353 return 1;
354
355 ret = l->rx.proto->rx_suspend(&l->rx);
356 return ret > 0 ? ret : 0;
357}
358
359
360/* Tries to resume a suspended listener, and returns non-zero on success or
361 * zero on failure. On certain errors, an alert or a warning might be displayed.
362 * It must be called with the listener's lock held. Depending on the listener's
363 * state and protocol, a listen() call might be used to resume operations, or a
364 * call to the receiver's resume() function might be used as well. This is
365 * suitable as a default function for TCP and UDP. This must be called with the
366 * listener's lock held.
367 */
368int default_resume_listener(struct listener *l)
369{
370 int ret = 1;
371
372 if (l->state == LI_ASSIGNED) {
373 char msg[100];
374 int err;
375
376 err = l->rx.proto->listen(l, msg, sizeof(msg));
377 if (err & ERR_ALERT)
378 ha_alert("Resuming listener: %s\n", msg);
379 else if (err & ERR_WARN)
380 ha_warning("Resuming listener: %s\n", msg);
381
382 if (err & (ERR_FATAL | ERR_ABORT)) {
383 ret = 0;
384 goto end;
385 }
386 }
387
388 if (l->state < LI_PAUSED) {
389 ret = 0;
390 goto end;
391 }
392
393 if (l->state == LI_PAUSED && l->rx.proto->rx_resume &&
394 l->rx.proto->rx_resume(&l->rx) <= 0)
395 ret = 0;
396 end:
397 return ret;
398}
399
400
Willy Tarreaube58c382011-07-24 18:28:10 +0200401/* This function tries to temporarily disable a listener, depending on the OS
402 * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
403 * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
404 * closes upon SHUT_WR and refuses to rebind. So a common validation path
405 * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling
406 * is disabled. It normally returns non-zero, unless an error is reported.
407 */
408int pause_listener(struct listener *l)
409{
Willy Tarreau58651b42020-09-24 16:03:29 +0200410 struct proxy *px = l->bind_conf->frontend;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200411 int ret = 1;
412
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100413 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200414
Willy Tarreau02e19752020-09-23 17:17:22 +0200415 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
416 !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
417 goto end;
418
Willy Tarreau9b3a9322020-09-24 14:46:34 +0200419 if (l->state <= LI_PAUSED)
420 goto end;
421
Willy Tarreaue03204c2020-10-09 17:02:21 +0200422 if (l->rx.proto->suspend)
423 ret = l->rx.proto->suspend(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200424
Olivier Houchard859dc802019-08-08 15:47:21 +0200425 MT_LIST_DEL(&l->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200426
Willy Tarreaua37b2442020-09-24 07:23:45 +0200427 listener_set_state(l, LI_PAUSED);
Willy Tarreau58651b42020-09-24 16:03:29 +0200428
429 if (px && !px->li_ready) {
430 ha_warning("Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
431 send_log(px, LOG_WARNING, "Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
432 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200433 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100434 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200435 return ret;
Willy Tarreaube58c382011-07-24 18:28:10 +0200436}
437
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200438/* This function tries to resume a temporarily disabled listener. Paused, full,
439 * limited and disabled listeners are handled, which means that this function
440 * may replace enable_listener(). The resulting state will either be LI_READY
441 * or LI_FULL. 0 is returned in case of failure to resume (eg: dead socket).
Willy Tarreauae302532014-05-07 19:22:24 +0200442 * Listeners bound to a different process are not woken up unless we're in
Willy Tarreauaf2fd582015-04-14 12:07:16 +0200443 * foreground mode, and are ignored. If the listener was only in the assigned
444 * state, it's totally rebound. This can happen if a pause() has completely
445 * stopped it. If the resume fails, 0 is returned and an error might be
446 * displayed.
Willy Tarreaube58c382011-07-24 18:28:10 +0200447 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100448int resume_listener(struct listener *l)
Willy Tarreaube58c382011-07-24 18:28:10 +0200449{
Willy Tarreau58651b42020-09-24 16:03:29 +0200450 struct proxy *px = l->bind_conf->frontend;
451 int was_paused = px && px->li_paused;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200452 int ret = 1;
453
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100454 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200455
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200456 /* check that another thread didn't to the job in parallel (e.g. at the
457 * end of listen_accept() while we'd come from dequeue_all_listeners().
458 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200459 if (MT_LIST_ADDED(&l->wait_queue))
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200460 goto end;
461
William Lallemand095ba4c2017-06-01 17:38:50 +0200462 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau818a92e2020-09-03 07:50:19 +0200463 !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200464 goto end;
Willy Tarreau3569df32017-03-15 12:47:46 +0100465
Willy Tarreau5d7f9ce2020-09-24 18:54:11 +0200466 if (l->state == LI_READY)
467 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200468
Willy Tarreaue03204c2020-10-09 17:02:21 +0200469 if (l->rx.proto->resume)
470 ret = l->rx.proto->resume(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200471
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100472 if (l->maxconn && l->nbconn >= l->maxconn) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200473 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200474 listener_set_state(l, LI_FULL);
Willy Tarreau58651b42020-09-24 16:03:29 +0200475 goto done;
Willy Tarreaube58c382011-07-24 18:28:10 +0200476 }
477
Willy Tarreau4b51f422020-09-25 20:32:28 +0200478 l->rx.proto->enable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200479 listener_set_state(l, LI_READY);
Willy Tarreau58651b42020-09-24 16:03:29 +0200480
481 done:
482 if (was_paused && !px->li_paused) {
483 ha_warning("Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
484 send_log(px, LOG_WARNING, "Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
485 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200486 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100487 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200488 return ret;
489}
490
Willy Tarreau87b09662015-04-03 00:22:06 +0200491/* Marks a ready listener as full so that the stream code tries to re-enable
Willy Tarreau62793712011-07-24 19:23:38 +0200492 * it upon next close() using resume_listener().
493 */
Christopher Faulet5580ba22017-08-28 15:29:20 +0200494static void listener_full(struct listener *l)
Willy Tarreau62793712011-07-24 19:23:38 +0200495{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100496 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200497 if (l->state >= LI_READY) {
Olivier Houchard859dc802019-08-08 15:47:21 +0200498 MT_LIST_DEL(&l->wait_queue);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100499 if (l->state != LI_FULL) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200500 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200501 listener_set_state(l, LI_FULL);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100502 }
Willy Tarreau62793712011-07-24 19:23:38 +0200503 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100504 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200505}
506
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200507/* Marks a ready listener as limited so that we only try to re-enable it when
508 * resources are free again. It will be queued into the specified queue.
509 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200510static void limit_listener(struct listener *l, struct mt_list *list)
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200511{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100512 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200513 if (l->state == LI_READY) {
Willy Tarreaude4db172020-07-10 08:10:29 +0200514 MT_LIST_TRY_ADDQ(list, &l->wait_queue);
Willy Tarreau4b51f422020-09-25 20:32:28 +0200515 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200516 listener_set_state(l, LI_LIMITED);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200517 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100518 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200519}
520
Willy Tarreau241797a2019-12-10 14:10:52 +0100521/* Dequeues all listeners waiting for a resource the global wait queue */
522void dequeue_all_listeners()
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200523{
Willy Tarreau01abd022019-02-28 10:27:18 +0100524 struct listener *listener;
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200525
Willy Tarreau241797a2019-12-10 14:10:52 +0100526 while ((listener = MT_LIST_POP(&global_listener_queue, struct listener *, wait_queue))) {
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200527 /* This cannot fail because the listeners are by definition in
Willy Tarreau01abd022019-02-28 10:27:18 +0100528 * the LI_LIMITED state.
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200529 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100530 resume_listener(listener);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200531 }
532}
533
Willy Tarreau241797a2019-12-10 14:10:52 +0100534/* Dequeues all listeners waiting for a resource in proxy <px>'s queue */
535void dequeue_proxy_listeners(struct proxy *px)
536{
537 struct listener *listener;
538
539 while ((listener = MT_LIST_POP(&px->listener_queue, struct listener *, wait_queue))) {
540 /* This cannot fail because the listeners are by definition in
541 * the LI_LIMITED state.
542 */
543 resume_listener(listener);
544 }
545}
546
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200547
548/* default function used to unbind a listener. This is for use by standard
549 * protocols working on top of accepted sockets. The receiver's rx_unbind()
550 * will automatically be used after the listener is disabled if the socket is
551 * still bound. This must be used under the listener's lock.
Christopher Faulet510c0d62018-03-16 10:04:47 +0100552 */
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200553void default_unbind_listener(struct listener *listener)
Willy Tarreaub648d632007-10-28 22:13:50 +0100554{
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200555 if (listener->state <= LI_ASSIGNED)
556 goto out_close;
557
558 if (listener->rx.fd == -1) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200559 listener_set_state(listener, LI_ASSIGNED);
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200560 goto out_close;
561 }
562
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200563 if (listener->state >= LI_READY) {
564 listener->rx.proto->disable(listener);
565 if (listener->rx.flags & RX_F_BOUND)
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200566 listener_set_state(listener, LI_LISTEN);
Willy Tarreaub6607bf2020-09-23 16:24:23 +0200567 }
568
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200569 out_close:
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200570 if (listener->rx.flags & RX_F_BOUND)
571 listener->rx.proto->rx_unbind(&listener->rx);
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200572}
573
574/* This function closes the listening socket for the specified listener,
575 * provided that it's already in a listening state. The protocol's unbind()
576 * is called to put the listener into LI_ASSIGNED or LI_LISTEN and handle
577 * the unbinding tasks. The listener enters then the LI_ASSIGNED state if
578 * the receiver is unbound. Must be called with the lock held.
579 */
580void do_unbind_listener(struct listener *listener)
581{
582 MT_LIST_DEL(&listener->wait_queue);
583
584 if (listener->rx.proto->unbind)
585 listener->rx.proto->unbind(listener);
Willy Tarreau374e9af2020-10-09 15:47:17 +0200586
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200587 /* we may have to downgrade the listener if the rx was closed */
588 if (!(listener->rx.flags & RX_F_BOUND) && listener->state > LI_ASSIGNED)
Willy Tarreau374e9af2020-10-09 15:47:17 +0200589 listener_set_state(listener, LI_ASSIGNED);
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100590}
591
Olivier Houchard1fc05162017-04-06 01:05:05 +0200592/* This function closes the listening socket for the specified listener,
593 * provided that it's already in a listening state. The listener enters the
Willy Tarreau75c98d12020-10-09 15:55:23 +0200594 * LI_ASSIGNED state, except if the FD is not closed, in which case it may
595 * remain in LI_LISTEN. This function is intended to be used as a generic
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100596 * function for standard protocols.
Olivier Houchard1fc05162017-04-06 01:05:05 +0200597 */
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100598void unbind_listener(struct listener *listener)
Olivier Houchard1fc05162017-04-06 01:05:05 +0200599{
Christopher Faulet510c0d62018-03-16 10:04:47 +0100600 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau75c98d12020-10-09 15:55:23 +0200601 do_unbind_listener(listener);
Christopher Faulet510c0d62018-03-16 10:04:47 +0100602 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200603}
604
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200605/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
606 * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200607 * allocation). The address family is taken from ss->ss_family, and the protocol
Willy Tarreaud2fb99f2020-10-15 21:22:29 +0200608 * passed in <proto> must be usable on this family. The protocol's default iocb
609 * is automatically preset as the receivers' iocb. The number of jobs and
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200610 * listeners is automatically increased by the number of listeners created. It
611 * returns non-zero on success, zero on error with the error message set in <err>.
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200612 */
613int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200614 int portl, int porth, int fd, struct protocol *proto, char **err)
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200615{
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200616 struct listener *l;
617 int port;
618
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200619 for (port = portl; port <= porth; port++) {
620 l = calloc(1, sizeof(*l));
621 if (!l) {
622 memprintf(err, "out of memory");
623 return 0;
624 }
625 l->obj_type = OBJ_TYPE_LISTENER;
626 LIST_ADDQ(&bc->frontend->conf.listeners, &l->by_fe);
627 LIST_ADDQ(&bc->listeners, &l->by_bind);
628 l->bind_conf = bc;
Willy Tarreau0fce6bc2020-09-03 07:46:06 +0200629 l->rx.settings = &bc->settings;
Willy Tarreaueef45422020-09-03 10:05:03 +0200630 l->rx.owner = l;
Willy Tarreaud2fb99f2020-10-15 21:22:29 +0200631 l->rx.iocb = proto->default_iocb;
Willy Tarreau38ba6472020-08-27 08:16:52 +0200632 l->rx.fd = fd;
Willy Tarreau07400c52020-12-04 14:49:11 +0100633
Willy Tarreau37159062020-08-27 07:48:42 +0200634 memcpy(&l->rx.addr, ss, sizeof(*ss));
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100635 if (proto->fam->set_port)
636 proto->fam->set_port(&l->rx.addr, port);
Willy Tarreau07400c52020-12-04 14:49:11 +0100637
Olivier Houchard859dc802019-08-08 15:47:21 +0200638 MT_LIST_INIT(&l->wait_queue);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200639 listener_set_state(l, LI_INIT);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200640
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100641 proto->add(proto, l);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200642
Willy Tarreau909c23b2020-09-15 13:50:58 +0200643 if (fd != -1)
Willy Tarreau43046fa2020-09-01 15:41:59 +0200644 l->rx.flags |= RX_F_INHERITED;
William Lallemand75ea0a02017-11-15 19:02:58 +0100645
Amaury Denoyelle7f8f6cb2020-11-10 14:24:31 +0100646 l->extra_counters = NULL;
647
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100648 HA_SPIN_INIT(&l->lock);
Olivier Houchard64213e92019-03-08 18:52:57 +0100649 _HA_ATOMIC_ADD(&jobs, 1);
650 _HA_ATOMIC_ADD(&listeners, 1);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200651 }
652 return 1;
653}
654
Willy Tarreau1a64d162007-10-28 22:26:05 +0100655/* Delete a listener from its protocol's list of listeners. The listener's
656 * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
Willy Tarreau2cc5bae2017-09-15 08:18:11 +0200657 * number of listeners is updated, as well as the global number of listeners
658 * and jobs. Note that the listener must have previously been unbound. This
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200659 * is a low-level function expected to be called with the proto_lock and the
660 * listener's lock held.
Willy Tarreau1a64d162007-10-28 22:26:05 +0100661 */
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200662void __delete_listener(struct listener *listener)
Willy Tarreau1a64d162007-10-28 22:26:05 +0100663{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100664 if (listener->state == LI_ASSIGNED) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200665 listener_set_state(listener, LI_INIT);
Willy Tarreaub7436612020-08-28 19:51:44 +0200666 LIST_DEL(&listener->rx.proto_list);
Willy Tarreaud7f331c2020-09-25 17:01:43 +0200667 listener->rx.proto->nb_receivers--;
Olivier Houchard64213e92019-03-08 18:52:57 +0100668 _HA_ATOMIC_SUB(&jobs, 1);
669 _HA_ATOMIC_SUB(&listeners, 1);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100670 }
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200671}
672
673/* Delete a listener from its protocol's list of listeners (please check
674 * __delete_listener() above). The proto_lock and the listener's lock will
675 * be grabbed in this order.
676 */
677void delete_listener(struct listener *listener)
678{
679 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
680 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
681 __delete_listener(listener);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100682 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau6ee9f8d2019-08-26 10:55:52 +0200683 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
Willy Tarreau1a64d162007-10-28 22:26:05 +0100684}
685
Willy Tarreaue2711c72019-02-27 15:39:41 +0100686/* Returns a suitable value for a listener's backlog. It uses the listener's,
687 * otherwise the frontend's backlog, otherwise the listener's maxconn,
688 * otherwise the frontend's maxconn, otherwise 1024.
689 */
690int listener_backlog(const struct listener *l)
691{
692 if (l->backlog)
693 return l->backlog;
694
695 if (l->bind_conf->frontend->backlog)
696 return l->bind_conf->frontend->backlog;
697
698 if (l->maxconn)
699 return l->maxconn;
700
701 if (l->bind_conf->frontend->maxconn)
702 return l->bind_conf->frontend->maxconn;
703
704 return 1024;
705}
706
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200707/* This function is called on a read event from a listening socket, corresponding
708 * to an accept. It tries to accept as many connections as possible, and for each
709 * calls the listener's accept handler (generally the frontend's accept handler).
710 */
Willy Tarreaua74cb382020-10-15 21:29:49 +0200711void listener_accept(struct listener *l)
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200712{
Willy Tarreau83efc322020-10-14 17:37:17 +0200713 struct connection *cli_conn;
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100714 struct proxy *p;
Christopher Faulet102854c2019-04-30 12:17:13 +0200715 unsigned int max_accept;
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100716 int next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100717 int next_feconn = 0;
718 int next_actconn = 0;
Willy Tarreaubb660302014-05-07 19:47:02 +0200719 int expire;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200720 int ret;
721
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100722 p = l->bind_conf->frontend;
Christopher Faulet102854c2019-04-30 12:17:13 +0200723
724 /* if l->maxaccept is -1, then max_accept is UINT_MAX. It is not really
725 * illimited, but it is probably enough.
726 */
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100727 max_accept = l->maxaccept ? l->maxaccept : 1;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200728
Willy Tarreau93e7c002013-10-07 18:51:07 +0200729 if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
730 int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
Willy Tarreau93e7c002013-10-07 18:51:07 +0200731
732 if (unlikely(!max)) {
733 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200734 expire = tick_add(now_ms, next_event_delay(&global.sess_per_sec, global.sps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100735 goto limit_global;
Willy Tarreau93e7c002013-10-07 18:51:07 +0200736 }
737
738 if (max_accept > max)
739 max_accept = max;
740 }
741
742 if (!(l->options & LI_O_UNLIMITED) && global.cps_lim) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200743 int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
744
745 if (unlikely(!max)) {
746 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200747 expire = tick_add(now_ms, next_event_delay(&global.conn_per_sec, global.cps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100748 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200749 }
750
751 if (max_accept > max)
752 max_accept = max;
753 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200754#ifdef USE_OPENSSL
755 if (!(l->options & LI_O_UNLIMITED) && global.ssl_lim && l->bind_conf && l->bind_conf->is_ssl) {
756 int max = freq_ctr_remain(&global.ssl_per_sec, global.ssl_lim, 0);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200757
Willy Tarreaue43d5322013-10-07 20:01:52 +0200758 if (unlikely(!max)) {
759 /* frontend accept rate limit was reached */
Willy Tarreaue43d5322013-10-07 20:01:52 +0200760 expire = tick_add(now_ms, next_event_delay(&global.ssl_per_sec, global.ssl_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100761 goto limit_global;
Willy Tarreaue43d5322013-10-07 20:01:52 +0200762 }
763
764 if (max_accept > max)
765 max_accept = max;
766 }
767#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200768 if (p && p->fe_sps_lim) {
769 int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0);
770
771 if (unlikely(!max)) {
772 /* frontend accept rate limit was reached */
Willy Tarreau0591bf72019-12-10 12:01:21 +0100773 expire = tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0));
774 goto limit_proxy;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200775 }
776
777 if (max_accept > max)
778 max_accept = max;
779 }
780
781 /* Note: if we fail to allocate a connection because of configured
782 * limits, we'll schedule a new attempt worst 1 second later in the
783 * worst case. If we fail due to system limits or temporary resource
784 * shortage, we try again 100ms later in the worst case.
785 */
Willy Tarreau02757d02021-01-28 18:07:24 +0100786 for (; max_accept; next_conn = next_feconn = next_actconn = 0, max_accept--) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200787 unsigned int count;
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200788 int status;
Willy Tarreau0aa5a5b2020-10-16 17:43:04 +0200789 __decl_thread(unsigned long mask);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200790
Willy Tarreau82c97892019-02-27 19:32:32 +0100791 /* pre-increase the number of connections without going too far.
792 * We process the listener, then the proxy, then the process.
793 * We know which ones to unroll based on the next_xxx value.
794 */
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100795 do {
796 count = l->nbconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100797 if (unlikely(l->maxconn && count >= l->maxconn)) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100798 /* the listener was marked full or another
799 * thread is going to do it.
800 */
801 next_conn = 0;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100802 listener_full(l);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100803 goto end;
804 }
805 next_conn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000806 } while (!_HA_ATOMIC_CAS(&l->nbconn, (int *)(&count), next_conn));
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100807
Willy Tarreau82c97892019-02-27 19:32:32 +0100808 if (p) {
809 do {
810 count = p->feconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100811 if (unlikely(count >= p->maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100812 /* the frontend was marked full or another
813 * thread is going to do it.
814 */
815 next_feconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100816 expire = TICK_ETERNITY;
817 goto limit_proxy;
Willy Tarreau82c97892019-02-27 19:32:32 +0100818 }
819 next_feconn = count + 1;
Olivier Houchard64213e92019-03-08 18:52:57 +0100820 } while (!_HA_ATOMIC_CAS(&p->feconn, &count, next_feconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200821 }
822
Willy Tarreau82c97892019-02-27 19:32:32 +0100823 if (!(l->options & LI_O_UNLIMITED)) {
824 do {
825 count = actconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100826 if (unlikely(count >= global.maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100827 /* the process was marked full or another
828 * thread is going to do it.
829 */
830 next_actconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100831 expire = tick_add(now_ms, 1000); /* try again in 1 second */
832 goto limit_global;
Willy Tarreau82c97892019-02-27 19:32:32 +0100833 }
834 next_actconn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000835 } while (!_HA_ATOMIC_CAS(&actconn, (int *)(&count), next_actconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200836 }
837
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200838 cli_conn = l->rx.proto->accept_conn(l, &status);
839 if (!cli_conn) {
840 switch (status) {
841 case CO_AC_DONE:
842 goto end;
Willy Tarreau818dca52014-01-31 19:40:19 +0100843
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200844 case CO_AC_RETRY: /* likely a signal */
Olivier Houchard64213e92019-03-08 18:52:57 +0100845 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100846 if (p)
Olivier Houchard64213e92019-03-08 18:52:57 +0100847 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100848 if (!(l->options & LI_O_UNLIMITED))
Olivier Houchard64213e92019-03-08 18:52:57 +0100849 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreaua593ec52014-01-20 21:21:30 +0100850 continue;
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200851
852 case CO_AC_YIELD:
Willy Tarreau92079932019-12-10 09:30:05 +0100853 max_accept = 0;
854 goto end;
William Lallemandd9138002018-11-27 12:02:39 +0100855
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200856 default:
857 goto transient_error;
Willy Tarreau83efc322020-10-14 17:37:17 +0200858 }
859 }
860
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100861 /* The connection was accepted, it must be counted as such */
862 if (l->counters)
863 HA_ATOMIC_UPDATE_MAX(&l->counters->conn_max, next_conn);
864
Willy Tarreau82c97892019-02-27 19:32:32 +0100865 if (p)
866 HA_ATOMIC_UPDATE_MAX(&p->fe_counters.conn_max, next_feconn);
867
868 proxy_inc_fe_conn_ctr(l, p);
869
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100870 if (!(l->options & LI_O_UNLIMITED)) {
871 count = update_freq_ctr(&global.conn_per_sec, 1);
872 HA_ATOMIC_UPDATE_MAX(&global.cps_max, count);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100873 }
874
Willy Tarreau64a9c052019-04-12 15:27:17 +0200875 _HA_ATOMIC_ADD(&activity[tid].accepted, 1);
876
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200877 if (unlikely(cli_conn->handle.fd >= global.maxsock)) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200878 send_log(p, LOG_EMERG,
879 "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n",
880 p->id);
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200881 close(cli_conn->handle.fd);
William Dauchy835712a2020-10-18 18:37:43 +0200882 conn_free(cli_conn);
Willy Tarreau0591bf72019-12-10 12:01:21 +0100883 expire = tick_add(now_ms, 1000); /* try again in 1 second */
884 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200885 }
886
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100887 /* past this point, l->accept() will automatically decrement
Willy Tarreau82c97892019-02-27 19:32:32 +0100888 * l->nbconn, feconn and actconn once done. Setting next_*conn=0
889 * allows the error path not to rollback on nbconn. It's more
890 * convenient than duplicating all exit labels.
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100891 */
892 next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100893 next_feconn = 0;
894 next_actconn = 0;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200895
Willy Tarreau83efc322020-10-14 17:37:17 +0200896
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100897#if defined(USE_THREAD)
Willy Tarreau818a92e2020-09-03 07:50:19 +0200898 mask = thread_mask(l->rx.settings->bind_thread) & all_threads_mask;
Willy Tarreaua7da5e82020-03-12 17:33:29 +0100899 if (atleast2(mask) && (global.tune.options & GTUNE_LISTENER_MQ) && !stopping) {
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100900 struct accept_queue_ring *ring;
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100901 unsigned int t, t0, t1, t2;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100902
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100903 /* The principle is that we have two running indexes,
904 * each visiting in turn all threads bound to this
905 * listener. The connection will be assigned to the one
906 * with the least connections, and the other one will
907 * be updated. This provides a good fairness on short
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100908 * connections (round robin) and on long ones (conn
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100909 * count), without ever missing any idle thread.
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100910 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100911
912 /* keep a copy for the final update. thr_idx is composite
913 * and made of (t2<<16) + t1.
914 */
Willy Tarreau0cf33172019-03-06 15:26:33 +0100915 t0 = l->thr_idx;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100916 do {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100917 unsigned long m1, m2;
918 int q1, q2;
919
920 t2 = t1 = t0;
921 t2 >>= 16;
922 t1 &= 0xFFFF;
923
924 /* t1 walks low to high bits ;
925 * t2 walks high to low.
926 */
927 m1 = mask >> t1;
928 m2 = mask & (t2 ? nbits(t2 + 1) : ~0UL);
929
Willy Tarreau85d04242019-04-16 18:09:13 +0200930 if (unlikely(!(m1 & 1))) {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100931 m1 &= ~1UL;
932 if (!m1) {
933 m1 = mask;
934 t1 = 0;
935 }
936 t1 += my_ffsl(m1) - 1;
937 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100938
Willy Tarreau85d04242019-04-16 18:09:13 +0200939 if (unlikely(!(m2 & (1UL << t2)) || t1 == t2)) {
940 /* highest bit not set */
941 if (!m2)
942 m2 = mask;
943
944 t2 = my_flsl(m2) - 1;
945 }
946
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100947 /* now we have two distinct thread IDs belonging to the mask */
948 q1 = accept_queue_rings[t1].tail - accept_queue_rings[t1].head + ACCEPT_QUEUE_SIZE;
949 if (q1 >= ACCEPT_QUEUE_SIZE)
950 q1 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100951
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100952 q2 = accept_queue_rings[t2].tail - accept_queue_rings[t2].head + ACCEPT_QUEUE_SIZE;
953 if (q2 >= ACCEPT_QUEUE_SIZE)
954 q2 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100955
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100956 /* we have 3 possibilities now :
957 * q1 < q2 : t1 is less loaded than t2, so we pick it
958 * and update t2 (since t1 might still be
959 * lower than another thread)
960 * q1 > q2 : t2 is less loaded than t1, so we pick it
961 * and update t1 (since t2 might still be
962 * lower than another thread)
963 * q1 = q2 : both are equally loaded, thus we pick t1
964 * and update t1 as it will become more loaded
965 * than t2.
966 */
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100967
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100968 q1 += l->thr_conn[t1];
969 q2 += l->thr_conn[t2];
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100970
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100971 if (q1 - q2 < 0) {
972 t = t1;
973 t2 = t2 ? t2 - 1 : LONGBITS - 1;
974 }
975 else if (q1 - q2 > 0) {
976 t = t2;
977 t1++;
978 if (t1 >= LONGBITS)
979 t1 = 0;
980 }
981 else {
982 t = t1;
983 t1++;
984 if (t1 >= LONGBITS)
985 t1 = 0;
986 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100987
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100988 /* new value for thr_idx */
989 t1 += (t2 << 16);
Olivier Houchard64213e92019-03-08 18:52:57 +0100990 } while (unlikely(!_HA_ATOMIC_CAS(&l->thr_idx, &t0, t1)));
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100991
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100992 /* We successfully selected the best thread "t" for this
993 * connection. We use deferred accepts even if it's the
994 * local thread because tests show that it's the best
995 * performing model, likely due to better cache locality
996 * when processing this loop.
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100997 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100998 ring = &accept_queue_rings[t];
Willy Tarreau83efc322020-10-14 17:37:17 +0200999 if (accept_queue_push_mp(ring, cli_conn)) {
Olivier Houchard64213e92019-03-08 18:52:57 +01001000 _HA_ATOMIC_ADD(&activity[t].accq_pushed, 1);
Willy Tarreau2bd65a72019-09-24 06:55:18 +02001001 tasklet_wakeup(ring->tasklet);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001002 continue;
1003 }
1004 /* If the ring is full we do a synchronous accept on
1005 * the local thread here.
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001006 */
Olivier Houchard64213e92019-03-08 18:52:57 +01001007 _HA_ATOMIC_ADD(&activity[t].accq_full, 1);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001008 }
1009#endif // USE_THREAD
1010
Olivier Houchard64213e92019-03-08 18:52:57 +01001011 _HA_ATOMIC_ADD(&l->thr_conn[tid], 1);
Willy Tarreau83efc322020-10-14 17:37:17 +02001012 ret = l->accept(cli_conn);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001013 if (unlikely(ret <= 0)) {
Willy Tarreau87b09662015-04-03 00:22:06 +02001014 /* The connection was closed by stream_accept(). Either
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001015 * we just have to ignore it (ret == 0) or it's a critical
1016 * error due to a resource shortage, and we must stop the
1017 * listener (ret < 0).
1018 */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001019 if (ret == 0) /* successful termination */
1020 continue;
1021
Willy Tarreaubb660302014-05-07 19:47:02 +02001022 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001023 }
1024
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001025 /* increase the per-process number of cumulated sessions, this
1026 * may only be done once l->accept() has accepted the connection.
1027 */
Willy Tarreau93e7c002013-10-07 18:51:07 +02001028 if (!(l->options & LI_O_UNLIMITED)) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001029 count = update_freq_ctr(&global.sess_per_sec, 1);
1030 HA_ATOMIC_UPDATE_MAX(&global.sps_max, count);
Willy Tarreau93e7c002013-10-07 18:51:07 +02001031 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001032#ifdef USE_OPENSSL
1033 if (!(l->options & LI_O_UNLIMITED) && l->bind_conf && l->bind_conf->is_ssl) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001034 count = update_freq_ctr(&global.ssl_per_sec, 1);
1035 HA_ATOMIC_UPDATE_MAX(&global.ssl_max, count);
Willy Tarreaue43d5322013-10-07 20:01:52 +02001036 }
1037#endif
Willy Tarreau93e7c002013-10-07 18:51:07 +02001038
Willy Tarreau8d2c98b2020-05-01 09:51:11 +02001039 ti->flags &= ~TI_FL_STUCK; // this thread is still running
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001040 } /* end of for (max_accept--) */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001041
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001042 end:
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001043 if (next_conn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001044 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau741b4d62019-02-25 15:02:04 +01001045
Willy Tarreau82c97892019-02-27 19:32:32 +01001046 if (p && next_feconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001047 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001048
1049 if (next_actconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001050 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001051
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001052 if ((l->state == LI_FULL && (!l->maxconn || l->nbconn < l->maxconn)) ||
Willy Tarreau02757d02021-01-28 18:07:24 +01001053 (l->state == LI_LIMITED &&
Willy Tarreaucdcba112019-12-11 15:06:30 +01001054 ((!p || p->feconn < p->maxconn) && (actconn < global.maxconn) &&
1055 (!tick_isset(global_listener_queue_task->expire) ||
1056 tick_is_expired(global_listener_queue_task->expire, now_ms))))) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001057 /* at least one thread has to this when quitting */
1058 resume_listener(l);
1059
Willy Tarreau02757d02021-01-28 18:07:24 +01001060 /* Dequeues all of the listeners waiting for a resource */
Willy Tarreau241797a2019-12-10 14:10:52 +01001061 dequeue_all_listeners();
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001062
Olivier Houchard859dc802019-08-08 15:47:21 +02001063 if (p && !MT_LIST_ISEMPTY(&p->listener_queue) &&
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001064 (!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 +01001065 dequeue_proxy_listeners(p);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001066 }
Willy Tarreau0591bf72019-12-10 12:01:21 +01001067 return;
1068
1069 transient_error:
1070 /* pause the listener for up to 100 ms */
1071 expire = tick_add(now_ms, 100);
1072
Willy Tarreau258b3512020-10-13 17:46:05 +02001073 /* This may be a shared socket that was paused by another process.
1074 * Let's put it to pause in this case.
1075 */
1076 if (l->rx.proto && l->rx.proto->rx_listening(&l->rx) == 0) {
1077 pause_listener(l);
1078 goto end;
1079 }
1080
Willy Tarreau0591bf72019-12-10 12:01:21 +01001081 limit_global:
1082 /* (re-)queue the listener to the global queue and set it to expire no
1083 * later than <expire> ahead. The listener turns to LI_LIMITED.
1084 */
1085 limit_listener(l, &global_listener_queue);
1086 task_schedule(global_listener_queue_task, expire);
1087 goto end;
1088
1089 limit_proxy:
1090 /* (re-)queue the listener to the proxy's queue and set it to expire no
1091 * later than <expire> ahead. The listener turns to LI_LIMITED.
1092 */
1093 limit_listener(l, &p->listener_queue);
Willy Tarreaueeea8082020-01-08 19:15:07 +01001094 if (p->task && tick_isset(expire))
1095 task_schedule(p->task, expire);
Willy Tarreau0591bf72019-12-10 12:01:21 +01001096 goto end;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001097}
1098
Willy Tarreau05f50472017-09-15 09:19:58 +02001099/* Notify the listener that a connection initiated from it was released. This
1100 * is used to keep the connection count consistent and to possibly re-open
1101 * listening when it was limited.
1102 */
1103void listener_release(struct listener *l)
1104{
1105 struct proxy *fe = l->bind_conf->frontend;
1106
1107 if (!(l->options & LI_O_UNLIMITED))
Willy Tarreau02757d02021-01-28 18:07:24 +01001108 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001109 if (fe)
Olivier Houchard64213e92019-03-08 18:52:57 +01001110 _HA_ATOMIC_SUB(&fe->feconn, 1);
1111 _HA_ATOMIC_SUB(&l->nbconn, 1);
1112 _HA_ATOMIC_SUB(&l->thr_conn[tid], 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001113
1114 if (l->state == LI_FULL || l->state == LI_LIMITED)
Willy Tarreau05f50472017-09-15 09:19:58 +02001115 resume_listener(l);
1116
Willy Tarreau02757d02021-01-28 18:07:24 +01001117 /* Dequeues all of the listeners waiting for a resource */
1118 dequeue_all_listeners();
1119
Olivier Houchard859dc802019-08-08 15:47:21 +02001120 if (!MT_LIST_ISEMPTY(&fe->listener_queue) &&
Willy Tarreau05f50472017-09-15 09:19:58 +02001121 (!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 +01001122 dequeue_proxy_listeners(fe);
Willy Tarreau05f50472017-09-15 09:19:58 +02001123}
1124
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001125/* Initializes the listener queues. Returns 0 on success, otherwise ERR_* flags */
1126static int listener_queue_init()
1127{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001128 global_listener_queue_task = task_new(MAX_THREADS_MASK);
1129 if (!global_listener_queue_task) {
1130 ha_alert("Out of memory when initializing global listener queue\n");
1131 return ERR_FATAL|ERR_ABORT;
1132 }
1133 /* very simple initialization, users will queue the task if needed */
1134 global_listener_queue_task->context = NULL; /* not even a context! */
1135 global_listener_queue_task->process = manage_global_listener_queue;
1136
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001137 return 0;
1138}
1139
1140static void listener_queue_deinit()
1141{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001142 task_destroy(global_listener_queue_task);
1143 global_listener_queue_task = NULL;
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001144}
1145
1146REGISTER_CONFIG_POSTPARSER("multi-threaded listener queue", listener_queue_init);
1147REGISTER_POST_DEINIT(listener_queue_deinit);
1148
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001149
1150/* This is the global management task for listeners. It enables listeners waiting
1151 * for global resources when there are enough free resource, or at least once in
Willy Tarreaud597ec22021-01-29 14:29:06 +01001152 * a while. It is designed to be called as a task. It's exported so that it's easy
1153 * to spot in "show tasks" or "show profiling".
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001154 */
Willy Tarreaud597ec22021-01-29 14:29:06 +01001155struct task *manage_global_listener_queue(struct task *t, void *context, unsigned short state)
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001156{
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 */