blob: d0d334e8f59d25fc5e690c41ffc57cbae9f27b80 [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.h>
Willy Tarreau5958c432021-05-08 20:30:37 +020032#include <haproxy/proxy.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#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
William Dauchy3679d0c2021-02-14 23:22:55 +010049/* listener status for stats */
50const char* li_status_st[LI_STATE_COUNT] = {
51 [LI_STATUS_WAITING] = "WAITING",
52 [LI_STATUS_OPEN] = "OPEN",
53 [LI_STATUS_FULL] = "FULL",
54};
Willy Tarreaua1d97f82019-12-10 11:18:41 +010055
Willy Tarreau1efafce2019-01-27 15:37:19 +010056#if defined(USE_THREAD)
57
58struct accept_queue_ring accept_queue_rings[MAX_THREADS] __attribute__((aligned(64))) = { };
59
60/* dequeue and process a pending connection from the local accept queue (single
Willy Tarreau83efc322020-10-14 17:37:17 +020061 * consumer). Returns the accepted connection or NULL if none was found.
Willy Tarreau1efafce2019-01-27 15:37:19 +010062 */
Willy Tarreau83efc322020-10-14 17:37:17 +020063struct connection *accept_queue_pop_sc(struct accept_queue_ring *ring)
Willy Tarreau1efafce2019-01-27 15:37:19 +010064{
Willy Tarreau1efafce2019-01-27 15:37:19 +010065 unsigned int pos, next;
Willy Tarreau83efc322020-10-14 17:37:17 +020066 struct connection *ptr;
67 struct connection **e;
Willy Tarreau1efafce2019-01-27 15:37:19 +010068
69 pos = ring->head;
70
71 if (pos == ring->tail)
Willy Tarreau83efc322020-10-14 17:37:17 +020072 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +010073
74 next = pos + 1;
75 if (next >= ACCEPT_QUEUE_SIZE)
76 next = 0;
77
78 e = &ring->entry[pos];
79
80 /* wait for the producer to update the listener's pointer */
81 while (1) {
Willy Tarreau83efc322020-10-14 17:37:17 +020082 ptr = *e;
Willy Tarreau1efafce2019-01-27 15:37:19 +010083 __ha_barrier_load();
84 if (ptr)
85 break;
86 pl_cpu_relax();
87 }
88
Willy Tarreau1efafce2019-01-27 15:37:19 +010089 /* release the entry */
Willy Tarreau83efc322020-10-14 17:37:17 +020090 *e = NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +010091
92 __ha_barrier_store();
93 ring->head = next;
Willy Tarreau83efc322020-10-14 17:37:17 +020094 return ptr;
Willy Tarreau1efafce2019-01-27 15:37:19 +010095}
96
97
Willy Tarreau83efc322020-10-14 17:37:17 +020098/* tries to push a new accepted connection <conn> into ring <ring>. Returns
99 * non-zero if it succeeds, or zero if the ring is full. Supports multiple
100 * producers.
Willy Tarreau1efafce2019-01-27 15:37:19 +0100101 */
Willy Tarreau83efc322020-10-14 17:37:17 +0200102int accept_queue_push_mp(struct accept_queue_ring *ring, struct connection *conn)
Willy Tarreau1efafce2019-01-27 15:37:19 +0100103{
Willy Tarreau1efafce2019-01-27 15:37:19 +0100104 unsigned int pos, next;
105
106 pos = ring->tail;
107 do {
108 next = pos + 1;
109 if (next >= ACCEPT_QUEUE_SIZE)
110 next = 0;
111 if (next == ring->head)
112 return 0; // ring full
Olivier Houchard64213e92019-03-08 18:52:57 +0100113 } while (unlikely(!_HA_ATOMIC_CAS(&ring->tail, &pos, next)));
Willy Tarreau1efafce2019-01-27 15:37:19 +0100114
Willy Tarreau83efc322020-10-14 17:37:17 +0200115 ring->entry[pos] = conn;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100116 __ha_barrier_store();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100117 return 1;
118}
119
Willy Tarreaufb5401f2021-01-29 12:25:23 +0100120/* proceed with accepting new connections. Don't mark it static so that it appears
121 * in task dumps.
122 */
Willy Tarreau144f84a2021-03-02 16:09:26 +0100123struct task *accept_queue_process(struct task *t, void *context, unsigned int state)
Willy Tarreau1efafce2019-01-27 15:37:19 +0100124{
125 struct accept_queue_ring *ring = context;
Willy Tarreau83efc322020-10-14 17:37:17 +0200126 struct connection *conn;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100127 struct listener *li;
Christopher Faulet102854c2019-04-30 12:17:13 +0200128 unsigned int max_accept;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100129 int ret;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100130
Christopher Faulet102854c2019-04-30 12:17:13 +0200131 /* if global.tune.maxaccept is -1, then max_accept is UINT_MAX. It
132 * is not really illimited, but it is probably enough.
133 */
Willy Tarreau66161322021-02-19 15:50:27 +0100134 max_accept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT;
Christopher Faulet102854c2019-04-30 12:17:13 +0200135 for (; max_accept; max_accept--) {
Willy Tarreau83efc322020-10-14 17:37:17 +0200136 conn = accept_queue_pop_sc(ring);
137 if (!conn)
Willy Tarreau1efafce2019-01-27 15:37:19 +0100138 break;
139
Willy Tarreau83efc322020-10-14 17:37:17 +0200140 li = __objt_listener(conn->target);
Willy Tarreau4781b152021-04-06 13:53:36 +0200141 _HA_ATOMIC_INC(&li->thr_conn[tid]);
Willy Tarreau83efc322020-10-14 17:37:17 +0200142 ret = li->accept(conn);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100143 if (ret <= 0) {
144 /* connection was terminated by the application */
145 continue;
146 }
147
148 /* increase the per-process number of cumulated sessions, this
149 * may only be done once l->accept() has accepted the connection.
150 */
151 if (!(li->options & LI_O_UNLIMITED)) {
152 HA_ATOMIC_UPDATE_MAX(&global.sps_max,
153 update_freq_ctr(&global.sess_per_sec, 1));
154 if (li->bind_conf && li->bind_conf->is_ssl) {
155 HA_ATOMIC_UPDATE_MAX(&global.ssl_max,
156 update_freq_ctr(&global.ssl_per_sec, 1));
157 }
158 }
159 }
160
161 /* ran out of budget ? Let's come here ASAP */
Christopher Faulet102854c2019-04-30 12:17:13 +0200162 if (!max_accept)
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200163 tasklet_wakeup(ring->tasklet);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100164
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200165 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100166}
167
168/* Initializes the accept-queues. Returns 0 on success, otherwise ERR_* flags */
169static int accept_queue_init()
170{
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200171 struct tasklet *t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100172 int i;
173
174 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200175 t = tasklet_new();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100176 if (!t) {
177 ha_alert("Out of memory while initializing accept queue for thread %d\n", i);
178 return ERR_FATAL|ERR_ABORT;
179 }
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200180 t->tid = i;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100181 t->process = accept_queue_process;
182 t->context = &accept_queue_rings[i];
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200183 accept_queue_rings[i].tasklet = t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100184 }
185 return 0;
186}
187
188REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
189
190#endif // USE_THREAD
191
William Dauchy3679d0c2021-02-14 23:22:55 +0100192/* helper to get listener status for stats */
193enum li_status get_li_status(struct listener *l)
194{
195 if (!l->maxconn || l->nbconn < l->maxconn) {
196 if (l->state == LI_LIMITED)
197 return LI_STATUS_WAITING;
198 else
199 return LI_STATUS_OPEN;
200 }
201 return LI_STATUS_FULL;
202}
203
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200204/* adjust the listener's state and its proxy's listener counters if needed.
205 * It must be called under the listener's lock, but uses atomic ops to change
206 * the proxy's counters so that the proxy lock is not needed.
207 */
Willy Tarreaua37b2442020-09-24 07:23:45 +0200208void listener_set_state(struct listener *l, enum li_state st)
209{
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200210 struct proxy *px = l->bind_conf->frontend;
211
212 if (px) {
213 /* from state */
214 switch (l->state) {
215 case LI_NEW: /* first call */
Willy Tarreau4781b152021-04-06 13:53:36 +0200216 _HA_ATOMIC_INC(&px->li_all);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200217 break;
218 case LI_INIT:
219 case LI_ASSIGNED:
220 break;
221 case LI_PAUSED:
Willy Tarreau4781b152021-04-06 13:53:36 +0200222 _HA_ATOMIC_DEC(&px->li_paused);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200223 break;
224 case LI_LISTEN:
Willy Tarreau4781b152021-04-06 13:53:36 +0200225 _HA_ATOMIC_DEC(&px->li_bound);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200226 break;
227 case LI_READY:
228 case LI_FULL:
229 case LI_LIMITED:
Willy Tarreau4781b152021-04-06 13:53:36 +0200230 _HA_ATOMIC_DEC(&px->li_ready);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200231 break;
232 }
233
234 /* to state */
235 switch (st) {
236 case LI_NEW:
237 case LI_INIT:
238 case LI_ASSIGNED:
239 break;
240 case LI_PAUSED:
Willy Tarreau95a34602020-10-08 15:32:21 +0200241 BUG_ON(l->rx.fd == -1);
Willy Tarreau4781b152021-04-06 13:53:36 +0200242 _HA_ATOMIC_INC(&px->li_paused);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200243 break;
244 case LI_LISTEN:
Willy Tarreau95a34602020-10-08 15:32:21 +0200245 BUG_ON(l->rx.fd == -1);
Willy Tarreau4781b152021-04-06 13:53:36 +0200246 _HA_ATOMIC_INC(&px->li_bound);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200247 break;
248 case LI_READY:
249 case LI_FULL:
250 case LI_LIMITED:
Willy Tarreau95a34602020-10-08 15:32:21 +0200251 BUG_ON(l->rx.fd == -1);
Willy Tarreau4781b152021-04-06 13:53:36 +0200252 _HA_ATOMIC_INC(&px->li_ready);
Willy Tarreauefc0eec2020-09-24 07:27:06 +0200253 break;
254 }
255 }
Willy Tarreaua37b2442020-09-24 07:23:45 +0200256 l->state = st;
257}
258
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100259/* This function adds the specified listener's file descriptor to the polling
260 * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500261 * LI_FULL state depending on its number of connections. In daemon mode, we
Willy Tarreauae302532014-05-07 19:22:24 +0200262 * also support binding only the relevant processes to their respective
263 * listeners. We don't do that in debug mode however.
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100264 */
Willy Tarreau7834a3f2020-09-25 16:40:18 +0200265void enable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100266{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100267 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaud6afb532020-10-09 10:35:40 +0200268
269 /* If this listener is supposed to be only in the master, close it in
270 * the workers. Conversely, if it's supposed to be only in the workers
271 * close it in the master.
272 */
Willy Tarreau18c20d22020-10-09 16:11:46 +0200273 if (!!master != !!(listener->rx.flags & RX_F_MWORKER))
Willy Tarreau75c98d12020-10-09 15:55:23 +0200274 do_unbind_listener(listener);
Willy Tarreaud6afb532020-10-09 10:35:40 +0200275
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100276 if (listener->state == LI_LISTEN) {
Willy Tarreau95a34602020-10-08 15:32:21 +0200277 BUG_ON(listener->rx.fd == -1);
William Lallemand095ba4c2017-06-01 17:38:50 +0200278 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau72faef32021-06-15 08:36:30 +0200279 (!!master != !!(listener->rx.flags & RX_F_MWORKER))) {
Willy Tarreauae302532014-05-07 19:22:24 +0200280 /* we don't want to enable this listener and don't
281 * want any fd event to reach it.
282 */
Willy Tarreau75c98d12020-10-09 15:55:23 +0200283 do_unbind_listener(listener);
Willy Tarreauae302532014-05-07 19:22:24 +0200284 }
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100285 else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200286 listener->rx.proto->enable(listener);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200287 listener_set_state(listener, LI_READY);
Willy Tarreauae302532014-05-07 19:22:24 +0200288 }
289 else {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200290 listener_set_state(listener, LI_FULL);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100291 }
292 }
Willy Tarreaud6afb532020-10-09 10:35:40 +0200293
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100294 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100295}
296
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200297/*
298 * This function completely stops a listener. It will need to operate under the
299 * proxy's lock, the protocol's lock, and the listener's lock. The caller is
300 * responsible for indicating in lpx, lpr, lli whether the respective locks are
301 * already held (non-zero) or not (zero) so that the function picks the missing
302 * ones, in this order. The proxy's listeners count is updated and the proxy is
303 * disabled and woken up after the last one is gone.
304 */
305void stop_listener(struct listener *l, int lpx, int lpr, int lli)
306{
307 struct proxy *px = l->bind_conf->frontend;
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200308
309 if (l->options & LI_O_NOSTOP) {
310 /* master-worker sockpairs are never closed but don't count as a
311 * job.
312 */
313 return;
314 }
315
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200316 if (!lpx)
Willy Tarreauac66d6b2020-10-20 17:24:27 +0200317 HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200318
319 if (!lpr)
320 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
321
322 if (!lli)
323 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
324
325 if (l->state > LI_INIT) {
Willy Tarreau75c98d12020-10-09 15:55:23 +0200326 do_unbind_listener(l);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200327
328 if (l->state >= LI_ASSIGNED)
329 __delete_listener(l);
330
Willy Tarreauacde1522020-10-07 16:31:39 +0200331 proxy_cond_disable(px);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200332 }
333
334 if (!lli)
335 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
336
337 if (!lpr)
338 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
339
340 if (!lpx)
Willy Tarreauac66d6b2020-10-20 17:24:27 +0200341 HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock);
Willy Tarreaucaa7df12020-10-07 15:58:50 +0200342}
343
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100344/* This function adds the specified <listener> to the protocol <proto>. It
345 * does nothing if the protocol was already added. The listener's state is
346 * automatically updated from LI_INIT to LI_ASSIGNED. The number of listeners
347 * for the protocol is updated. This must be called with the proto lock held.
348 */
349void default_add_listener(struct protocol *proto, struct listener *listener)
350{
351 if (listener->state != LI_INIT)
352 return;
353 listener_set_state(listener, LI_ASSIGNED);
354 listener->rx.proto = proto;
Willy Tarreau2b718102021-04-21 07:32:39 +0200355 LIST_APPEND(&proto->receivers, &listener->rx.proto_list);
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100356 proto->nb_receivers++;
357}
358
Willy Tarreaue03204c2020-10-09 17:02:21 +0200359/* default function called to suspend a listener: it simply passes the call to
360 * the underlying receiver. This is find for most socket-based protocols. This
361 * must be called under the listener's lock. It will return non-zero on success,
362 * 0 on failure. If no receiver-level suspend is provided, the operation is
363 * assumed to succeed.
364 */
365int default_suspend_listener(struct listener *l)
366{
367 int ret = 1;
368
369 if (!l->rx.proto->rx_suspend)
370 return 1;
371
372 ret = l->rx.proto->rx_suspend(&l->rx);
373 return ret > 0 ? ret : 0;
374}
375
376
377/* Tries to resume a suspended listener, and returns non-zero on success or
378 * zero on failure. On certain errors, an alert or a warning might be displayed.
379 * It must be called with the listener's lock held. Depending on the listener's
380 * state and protocol, a listen() call might be used to resume operations, or a
381 * call to the receiver's resume() function might be used as well. This is
382 * suitable as a default function for TCP and UDP. This must be called with the
383 * listener's lock held.
384 */
385int default_resume_listener(struct listener *l)
386{
387 int ret = 1;
388
389 if (l->state == LI_ASSIGNED) {
390 char msg[100];
391 int err;
392
393 err = l->rx.proto->listen(l, msg, sizeof(msg));
394 if (err & ERR_ALERT)
395 ha_alert("Resuming listener: %s\n", msg);
396 else if (err & ERR_WARN)
397 ha_warning("Resuming listener: %s\n", msg);
398
399 if (err & (ERR_FATAL | ERR_ABORT)) {
400 ret = 0;
401 goto end;
402 }
403 }
404
405 if (l->state < LI_PAUSED) {
406 ret = 0;
407 goto end;
408 }
409
410 if (l->state == LI_PAUSED && l->rx.proto->rx_resume &&
411 l->rx.proto->rx_resume(&l->rx) <= 0)
412 ret = 0;
413 end:
414 return ret;
415}
416
417
Willy Tarreaube58c382011-07-24 18:28:10 +0200418/* This function tries to temporarily disable a listener, depending on the OS
419 * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
420 * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
421 * closes upon SHUT_WR and refuses to rebind. So a common validation path
422 * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling
423 * is disabled. It normally returns non-zero, unless an error is reported.
424 */
425int pause_listener(struct listener *l)
426{
Willy Tarreau58651b42020-09-24 16:03:29 +0200427 struct proxy *px = l->bind_conf->frontend;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200428 int ret = 1;
429
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100430 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200431
Willy Tarreau9b3a9322020-09-24 14:46:34 +0200432 if (l->state <= LI_PAUSED)
433 goto end;
434
Willy Tarreaue03204c2020-10-09 17:02:21 +0200435 if (l->rx.proto->suspend)
436 ret = l->rx.proto->suspend(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200437
Willy Tarreau2b718102021-04-21 07:32:39 +0200438 MT_LIST_DELETE(&l->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200439
Willy Tarreaua37b2442020-09-24 07:23:45 +0200440 listener_set_state(l, LI_PAUSED);
Willy Tarreau58651b42020-09-24 16:03:29 +0200441
442 if (px && !px->li_ready) {
443 ha_warning("Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
444 send_log(px, LOG_WARNING, "Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
445 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200446 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100447 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200448 return ret;
Willy Tarreaube58c382011-07-24 18:28:10 +0200449}
450
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200451/* This function tries to resume a temporarily disabled listener. Paused, full,
452 * limited and disabled listeners are handled, which means that this function
453 * may replace enable_listener(). The resulting state will either be LI_READY
454 * or LI_FULL. 0 is returned in case of failure to resume (eg: dead socket).
Willy Tarreauae302532014-05-07 19:22:24 +0200455 * Listeners bound to a different process are not woken up unless we're in
Willy Tarreauaf2fd582015-04-14 12:07:16 +0200456 * foreground mode, and are ignored. If the listener was only in the assigned
457 * state, it's totally rebound. This can happen if a pause() has completely
458 * stopped it. If the resume fails, 0 is returned and an error might be
459 * displayed.
Willy Tarreaube58c382011-07-24 18:28:10 +0200460 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100461int resume_listener(struct listener *l)
Willy Tarreaube58c382011-07-24 18:28:10 +0200462{
Willy Tarreau58651b42020-09-24 16:03:29 +0200463 struct proxy *px = l->bind_conf->frontend;
464 int was_paused = px && px->li_paused;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200465 int ret = 1;
466
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100467 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200468
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200469 /* check that another thread didn't to the job in parallel (e.g. at the
470 * end of listen_accept() while we'd come from dequeue_all_listeners().
471 */
Willy Tarreau2b718102021-04-21 07:32:39 +0200472 if (MT_LIST_INLIST(&l->wait_queue))
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200473 goto end;
474
Willy Tarreau5d7f9ce2020-09-24 18:54:11 +0200475 if (l->state == LI_READY)
476 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200477
Willy Tarreaue03204c2020-10-09 17:02:21 +0200478 if (l->rx.proto->resume)
479 ret = l->rx.proto->resume(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200480
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100481 if (l->maxconn && l->nbconn >= l->maxconn) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200482 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200483 listener_set_state(l, LI_FULL);
Willy Tarreau58651b42020-09-24 16:03:29 +0200484 goto done;
Willy Tarreaube58c382011-07-24 18:28:10 +0200485 }
486
Willy Tarreau4b51f422020-09-25 20:32:28 +0200487 l->rx.proto->enable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200488 listener_set_state(l, LI_READY);
Willy Tarreau58651b42020-09-24 16:03:29 +0200489
490 done:
491 if (was_paused && !px->li_paused) {
492 ha_warning("Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
493 send_log(px, LOG_WARNING, "Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
494 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200495 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100496 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200497 return ret;
498}
499
Willy Tarreau87b09662015-04-03 00:22:06 +0200500/* Marks a ready listener as full so that the stream code tries to re-enable
Willy Tarreau62793712011-07-24 19:23:38 +0200501 * it upon next close() using resume_listener().
502 */
Christopher Faulet5580ba22017-08-28 15:29:20 +0200503static void listener_full(struct listener *l)
Willy Tarreau62793712011-07-24 19:23:38 +0200504{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100505 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200506 if (l->state >= LI_READY) {
Willy Tarreau2b718102021-04-21 07:32:39 +0200507 MT_LIST_DELETE(&l->wait_queue);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100508 if (l->state != LI_FULL) {
Willy Tarreau4b51f422020-09-25 20:32:28 +0200509 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200510 listener_set_state(l, LI_FULL);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100511 }
Willy Tarreau62793712011-07-24 19:23:38 +0200512 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100513 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200514}
515
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200516/* Marks a ready listener as limited so that we only try to re-enable it when
517 * resources are free again. It will be queued into the specified queue.
518 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200519static void limit_listener(struct listener *l, struct mt_list *list)
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200520{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100521 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200522 if (l->state == LI_READY) {
Willy Tarreau2b718102021-04-21 07:32:39 +0200523 MT_LIST_TRY_APPEND(list, &l->wait_queue);
Willy Tarreau4b51f422020-09-25 20:32:28 +0200524 l->rx.proto->disable(l);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200525 listener_set_state(l, LI_LIMITED);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200526 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100527 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200528}
529
Willy Tarreau241797a2019-12-10 14:10:52 +0100530/* Dequeues all listeners waiting for a resource the global wait queue */
531void dequeue_all_listeners()
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200532{
Willy Tarreau01abd022019-02-28 10:27:18 +0100533 struct listener *listener;
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200534
Willy Tarreau241797a2019-12-10 14:10:52 +0100535 while ((listener = MT_LIST_POP(&global_listener_queue, struct listener *, wait_queue))) {
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200536 /* This cannot fail because the listeners are by definition in
Willy Tarreau01abd022019-02-28 10:27:18 +0100537 * the LI_LIMITED state.
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200538 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100539 resume_listener(listener);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200540 }
541}
542
Willy Tarreau241797a2019-12-10 14:10:52 +0100543/* Dequeues all listeners waiting for a resource in proxy <px>'s queue */
544void dequeue_proxy_listeners(struct proxy *px)
545{
546 struct listener *listener;
547
548 while ((listener = MT_LIST_POP(&px->listener_queue, struct listener *, wait_queue))) {
549 /* This cannot fail because the listeners are by definition in
550 * the LI_LIMITED state.
551 */
552 resume_listener(listener);
553 }
554}
555
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200556
557/* default function used to unbind a listener. This is for use by standard
558 * protocols working on top of accepted sockets. The receiver's rx_unbind()
559 * will automatically be used after the listener is disabled if the socket is
560 * still bound. This must be used under the listener's lock.
Christopher Faulet510c0d62018-03-16 10:04:47 +0100561 */
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200562void default_unbind_listener(struct listener *listener)
Willy Tarreaub648d632007-10-28 22:13:50 +0100563{
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200564 if (listener->state <= LI_ASSIGNED)
565 goto out_close;
566
567 if (listener->rx.fd == -1) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200568 listener_set_state(listener, LI_ASSIGNED);
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200569 goto out_close;
570 }
571
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200572 if (listener->state >= LI_READY) {
573 listener->rx.proto->disable(listener);
574 if (listener->rx.flags & RX_F_BOUND)
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200575 listener_set_state(listener, LI_LISTEN);
Willy Tarreaub6607bf2020-09-23 16:24:23 +0200576 }
577
Willy Tarreau87acd4e2020-10-08 15:36:46 +0200578 out_close:
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200579 if (listener->rx.flags & RX_F_BOUND)
580 listener->rx.proto->rx_unbind(&listener->rx);
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200581}
582
583/* This function closes the listening socket for the specified listener,
584 * provided that it's already in a listening state. The protocol's unbind()
585 * is called to put the listener into LI_ASSIGNED or LI_LISTEN and handle
586 * the unbinding tasks. The listener enters then the LI_ASSIGNED state if
587 * the receiver is unbound. Must be called with the lock held.
588 */
589void do_unbind_listener(struct listener *listener)
590{
Willy Tarreau2b718102021-04-21 07:32:39 +0200591 MT_LIST_DELETE(&listener->wait_queue);
Willy Tarreau7b2febd2020-10-09 17:18:29 +0200592
593 if (listener->rx.proto->unbind)
594 listener->rx.proto->unbind(listener);
Willy Tarreau374e9af2020-10-09 15:47:17 +0200595
Willy Tarreauf58b8db2020-10-09 16:32:08 +0200596 /* we may have to downgrade the listener if the rx was closed */
597 if (!(listener->rx.flags & RX_F_BOUND) && listener->state > LI_ASSIGNED)
Willy Tarreau374e9af2020-10-09 15:47:17 +0200598 listener_set_state(listener, LI_ASSIGNED);
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100599}
600
Olivier Houchard1fc05162017-04-06 01:05:05 +0200601/* This function closes the listening socket for the specified listener,
602 * provided that it's already in a listening state. The listener enters the
Willy Tarreau75c98d12020-10-09 15:55:23 +0200603 * LI_ASSIGNED state, except if the FD is not closed, in which case it may
604 * remain in LI_LISTEN. This function is intended to be used as a generic
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100605 * function for standard protocols.
Olivier Houchard1fc05162017-04-06 01:05:05 +0200606 */
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100607void unbind_listener(struct listener *listener)
Olivier Houchard1fc05162017-04-06 01:05:05 +0200608{
Christopher Faulet510c0d62018-03-16 10:04:47 +0100609 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau75c98d12020-10-09 15:55:23 +0200610 do_unbind_listener(listener);
Christopher Faulet510c0d62018-03-16 10:04:47 +0100611 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200612}
613
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200614/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
615 * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200616 * allocation). The address family is taken from ss->ss_family, and the protocol
Willy Tarreaud2fb99f2020-10-15 21:22:29 +0200617 * passed in <proto> must be usable on this family. The protocol's default iocb
618 * is automatically preset as the receivers' iocb. The number of jobs and
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200619 * listeners is automatically increased by the number of listeners created. It
620 * returns non-zero on success, zero on error with the error message set in <err>.
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200621 */
622int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
Willy Tarreau9b3178d2020-09-16 17:58:55 +0200623 int portl, int porth, int fd, struct protocol *proto, char **err)
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200624{
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200625 struct listener *l;
626 int port;
627
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200628 for (port = portl; port <= porth; port++) {
629 l = calloc(1, sizeof(*l));
630 if (!l) {
631 memprintf(err, "out of memory");
632 return 0;
633 }
634 l->obj_type = OBJ_TYPE_LISTENER;
Willy Tarreau2b718102021-04-21 07:32:39 +0200635 LIST_APPEND(&bc->frontend->conf.listeners, &l->by_fe);
636 LIST_APPEND(&bc->listeners, &l->by_bind);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200637 l->bind_conf = bc;
Willy Tarreau0fce6bc2020-09-03 07:46:06 +0200638 l->rx.settings = &bc->settings;
Willy Tarreaueef45422020-09-03 10:05:03 +0200639 l->rx.owner = l;
Willy Tarreaud2fb99f2020-10-15 21:22:29 +0200640 l->rx.iocb = proto->default_iocb;
Willy Tarreau38ba6472020-08-27 08:16:52 +0200641 l->rx.fd = fd;
Willy Tarreau07400c52020-12-04 14:49:11 +0100642
Willy Tarreau37159062020-08-27 07:48:42 +0200643 memcpy(&l->rx.addr, ss, sizeof(*ss));
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100644 if (proto->fam->set_port)
645 proto->fam->set_port(&l->rx.addr, port);
Willy Tarreau07400c52020-12-04 14:49:11 +0100646
Olivier Houchard859dc802019-08-08 15:47:21 +0200647 MT_LIST_INIT(&l->wait_queue);
Willy Tarreaua37b2442020-09-24 07:23:45 +0200648 listener_set_state(l, LI_INIT);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200649
Willy Tarreaud1f250f2020-12-04 15:03:36 +0100650 proto->add(proto, l);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200651
Willy Tarreau909c23b2020-09-15 13:50:58 +0200652 if (fd != -1)
Willy Tarreau43046fa2020-09-01 15:41:59 +0200653 l->rx.flags |= RX_F_INHERITED;
William Lallemand75ea0a02017-11-15 19:02:58 +0100654
Amaury Denoyelle7f8f6cb2020-11-10 14:24:31 +0100655 l->extra_counters = NULL;
656
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100657 HA_SPIN_INIT(&l->lock);
Willy Tarreau4781b152021-04-06 13:53:36 +0200658 _HA_ATOMIC_INC(&jobs);
659 _HA_ATOMIC_INC(&listeners);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200660 }
661 return 1;
662}
663
Willy Tarreau1a64d162007-10-28 22:26:05 +0100664/* Delete a listener from its protocol's list of listeners. The listener's
665 * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
Willy Tarreau2cc5bae2017-09-15 08:18:11 +0200666 * number of listeners is updated, as well as the global number of listeners
667 * and jobs. Note that the listener must have previously been unbound. This
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200668 * is a low-level function expected to be called with the proto_lock and the
669 * listener's lock held.
Willy Tarreau1a64d162007-10-28 22:26:05 +0100670 */
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200671void __delete_listener(struct listener *listener)
Willy Tarreau1a64d162007-10-28 22:26:05 +0100672{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100673 if (listener->state == LI_ASSIGNED) {
Willy Tarreaua37b2442020-09-24 07:23:45 +0200674 listener_set_state(listener, LI_INIT);
Willy Tarreau2b718102021-04-21 07:32:39 +0200675 LIST_DELETE(&listener->rx.proto_list);
Willy Tarreaud7f331c2020-09-25 17:01:43 +0200676 listener->rx.proto->nb_receivers--;
Willy Tarreau4781b152021-04-06 13:53:36 +0200677 _HA_ATOMIC_DEC(&jobs);
678 _HA_ATOMIC_DEC(&listeners);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100679 }
Willy Tarreaub4c083f2020-10-07 15:36:16 +0200680}
681
682/* Delete a listener from its protocol's list of listeners (please check
683 * __delete_listener() above). The proto_lock and the listener's lock will
684 * be grabbed in this order.
685 */
686void delete_listener(struct listener *listener)
687{
688 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
689 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
690 __delete_listener(listener);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100691 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau6ee9f8d2019-08-26 10:55:52 +0200692 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
Willy Tarreau1a64d162007-10-28 22:26:05 +0100693}
694
Willy Tarreaue2711c72019-02-27 15:39:41 +0100695/* Returns a suitable value for a listener's backlog. It uses the listener's,
696 * otherwise the frontend's backlog, otherwise the listener's maxconn,
697 * otherwise the frontend's maxconn, otherwise 1024.
698 */
699int listener_backlog(const struct listener *l)
700{
701 if (l->backlog)
702 return l->backlog;
703
704 if (l->bind_conf->frontend->backlog)
705 return l->bind_conf->frontend->backlog;
706
707 if (l->maxconn)
708 return l->maxconn;
709
710 if (l->bind_conf->frontend->maxconn)
711 return l->bind_conf->frontend->maxconn;
712
713 return 1024;
714}
715
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200716/* This function is called on a read event from a listening socket, corresponding
717 * to an accept. It tries to accept as many connections as possible, and for each
718 * calls the listener's accept handler (generally the frontend's accept handler).
719 */
Willy Tarreaua74cb382020-10-15 21:29:49 +0200720void listener_accept(struct listener *l)
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200721{
Willy Tarreau83efc322020-10-14 17:37:17 +0200722 struct connection *cli_conn;
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100723 struct proxy *p;
Christopher Faulet102854c2019-04-30 12:17:13 +0200724 unsigned int max_accept;
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100725 int next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100726 int next_feconn = 0;
727 int next_actconn = 0;
Willy Tarreaubb660302014-05-07 19:47:02 +0200728 int expire;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200729 int ret;
730
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100731 p = l->bind_conf->frontend;
Christopher Faulet102854c2019-04-30 12:17:13 +0200732
733 /* if l->maxaccept is -1, then max_accept is UINT_MAX. It is not really
734 * illimited, but it is probably enough.
735 */
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100736 max_accept = l->maxaccept ? l->maxaccept : 1;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200737
Willy Tarreau93e7c002013-10-07 18:51:07 +0200738 if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
739 int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
Willy Tarreau93e7c002013-10-07 18:51:07 +0200740
741 if (unlikely(!max)) {
742 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200743 expire = tick_add(now_ms, next_event_delay(&global.sess_per_sec, global.sps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100744 goto limit_global;
Willy Tarreau93e7c002013-10-07 18:51:07 +0200745 }
746
747 if (max_accept > max)
748 max_accept = max;
749 }
750
751 if (!(l->options & LI_O_UNLIMITED) && global.cps_lim) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200752 int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
753
754 if (unlikely(!max)) {
755 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200756 expire = tick_add(now_ms, next_event_delay(&global.conn_per_sec, global.cps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100757 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200758 }
759
760 if (max_accept > max)
761 max_accept = max;
762 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200763#ifdef USE_OPENSSL
764 if (!(l->options & LI_O_UNLIMITED) && global.ssl_lim && l->bind_conf && l->bind_conf->is_ssl) {
765 int max = freq_ctr_remain(&global.ssl_per_sec, global.ssl_lim, 0);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200766
Willy Tarreaue43d5322013-10-07 20:01:52 +0200767 if (unlikely(!max)) {
768 /* frontend accept rate limit was reached */
Willy Tarreaue43d5322013-10-07 20:01:52 +0200769 expire = tick_add(now_ms, next_event_delay(&global.ssl_per_sec, global.ssl_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100770 goto limit_global;
Willy Tarreaue43d5322013-10-07 20:01:52 +0200771 }
772
773 if (max_accept > max)
774 max_accept = max;
775 }
776#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200777 if (p && p->fe_sps_lim) {
778 int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0);
779
780 if (unlikely(!max)) {
781 /* frontend accept rate limit was reached */
Willy Tarreau0591bf72019-12-10 12:01:21 +0100782 expire = tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0));
783 goto limit_proxy;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200784 }
785
786 if (max_accept > max)
787 max_accept = max;
788 }
789
790 /* Note: if we fail to allocate a connection because of configured
791 * limits, we'll schedule a new attempt worst 1 second later in the
792 * worst case. If we fail due to system limits or temporary resource
793 * shortage, we try again 100ms later in the worst case.
794 */
Willy Tarreau02757d02021-01-28 18:07:24 +0100795 for (; max_accept; next_conn = next_feconn = next_actconn = 0, max_accept--) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200796 unsigned int count;
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200797 int status;
Willy Tarreau0aa5a5b2020-10-16 17:43:04 +0200798 __decl_thread(unsigned long mask);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200799
Willy Tarreau82c97892019-02-27 19:32:32 +0100800 /* pre-increase the number of connections without going too far.
801 * We process the listener, then the proxy, then the process.
802 * We know which ones to unroll based on the next_xxx value.
803 */
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100804 do {
805 count = l->nbconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100806 if (unlikely(l->maxconn && count >= l->maxconn)) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100807 /* the listener was marked full or another
808 * thread is going to do it.
809 */
810 next_conn = 0;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100811 listener_full(l);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100812 goto end;
813 }
814 next_conn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000815 } while (!_HA_ATOMIC_CAS(&l->nbconn, (int *)(&count), next_conn));
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100816
Willy Tarreau82c97892019-02-27 19:32:32 +0100817 if (p) {
818 do {
819 count = p->feconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100820 if (unlikely(count >= p->maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100821 /* the frontend was marked full or another
822 * thread is going to do it.
823 */
824 next_feconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100825 expire = TICK_ETERNITY;
826 goto limit_proxy;
Willy Tarreau82c97892019-02-27 19:32:32 +0100827 }
828 next_feconn = count + 1;
Olivier Houchard64213e92019-03-08 18:52:57 +0100829 } while (!_HA_ATOMIC_CAS(&p->feconn, &count, next_feconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200830 }
831
Willy Tarreau82c97892019-02-27 19:32:32 +0100832 if (!(l->options & LI_O_UNLIMITED)) {
833 do {
834 count = actconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100835 if (unlikely(count >= global.maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100836 /* the process was marked full or another
837 * thread is going to do it.
838 */
839 next_actconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100840 expire = tick_add(now_ms, 1000); /* try again in 1 second */
841 goto limit_global;
Willy Tarreau82c97892019-02-27 19:32:32 +0100842 }
843 next_actconn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000844 } while (!_HA_ATOMIC_CAS(&actconn, (int *)(&count), next_actconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200845 }
846
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200847 cli_conn = l->rx.proto->accept_conn(l, &status);
848 if (!cli_conn) {
849 switch (status) {
850 case CO_AC_DONE:
851 goto end;
Willy Tarreau818dca52014-01-31 19:40:19 +0100852
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200853 case CO_AC_RETRY: /* likely a signal */
Willy Tarreau4781b152021-04-06 13:53:36 +0200854 _HA_ATOMIC_DEC(&l->nbconn);
Willy Tarreau82c97892019-02-27 19:32:32 +0100855 if (p)
Willy Tarreau4781b152021-04-06 13:53:36 +0200856 _HA_ATOMIC_DEC(&p->feconn);
Willy Tarreau82c97892019-02-27 19:32:32 +0100857 if (!(l->options & LI_O_UNLIMITED))
Willy Tarreau4781b152021-04-06 13:53:36 +0200858 _HA_ATOMIC_DEC(&actconn);
Willy Tarreaua593ec52014-01-20 21:21:30 +0100859 continue;
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200860
861 case CO_AC_YIELD:
Willy Tarreau92079932019-12-10 09:30:05 +0100862 max_accept = 0;
863 goto end;
William Lallemandd9138002018-11-27 12:02:39 +0100864
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200865 default:
866 goto transient_error;
Willy Tarreau83efc322020-10-14 17:37:17 +0200867 }
868 }
869
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100870 /* The connection was accepted, it must be counted as such */
871 if (l->counters)
872 HA_ATOMIC_UPDATE_MAX(&l->counters->conn_max, next_conn);
873
Willy Tarreau82c97892019-02-27 19:32:32 +0100874 if (p)
875 HA_ATOMIC_UPDATE_MAX(&p->fe_counters.conn_max, next_feconn);
876
877 proxy_inc_fe_conn_ctr(l, p);
878
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100879 if (!(l->options & LI_O_UNLIMITED)) {
880 count = update_freq_ctr(&global.conn_per_sec, 1);
881 HA_ATOMIC_UPDATE_MAX(&global.cps_max, count);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100882 }
883
Willy Tarreau4781b152021-04-06 13:53:36 +0200884 _HA_ATOMIC_INC(&activity[tid].accepted);
Willy Tarreau64a9c052019-04-12 15:27:17 +0200885
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200886 if (unlikely(cli_conn->handle.fd >= global.maxsock)) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200887 send_log(p, LOG_EMERG,
888 "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n",
889 p->id);
Willy Tarreau9378bbe2020-10-15 10:09:31 +0200890 close(cli_conn->handle.fd);
William Dauchy835712a2020-10-18 18:37:43 +0200891 conn_free(cli_conn);
Willy Tarreau0591bf72019-12-10 12:01:21 +0100892 expire = tick_add(now_ms, 1000); /* try again in 1 second */
893 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200894 }
895
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100896 /* past this point, l->accept() will automatically decrement
Willy Tarreau82c97892019-02-27 19:32:32 +0100897 * l->nbconn, feconn and actconn once done. Setting next_*conn=0
898 * allows the error path not to rollback on nbconn. It's more
899 * convenient than duplicating all exit labels.
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100900 */
901 next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100902 next_feconn = 0;
903 next_actconn = 0;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200904
Willy Tarreau83efc322020-10-14 17:37:17 +0200905
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100906#if defined(USE_THREAD)
Willy Tarreau818a92e2020-09-03 07:50:19 +0200907 mask = thread_mask(l->rx.settings->bind_thread) & all_threads_mask;
Willy Tarreaua7da5e82020-03-12 17:33:29 +0100908 if (atleast2(mask) && (global.tune.options & GTUNE_LISTENER_MQ) && !stopping) {
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100909 struct accept_queue_ring *ring;
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100910 unsigned int t, t0, t1, t2;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100911
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100912 /* The principle is that we have two running indexes,
913 * each visiting in turn all threads bound to this
914 * listener. The connection will be assigned to the one
915 * with the least connections, and the other one will
916 * be updated. This provides a good fairness on short
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100917 * connections (round robin) and on long ones (conn
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100918 * count), without ever missing any idle thread.
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100919 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100920
921 /* keep a copy for the final update. thr_idx is composite
922 * and made of (t2<<16) + t1.
923 */
Willy Tarreau0cf33172019-03-06 15:26:33 +0100924 t0 = l->thr_idx;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100925 do {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100926 unsigned long m1, m2;
927 int q1, q2;
928
929 t2 = t1 = t0;
930 t2 >>= 16;
931 t1 &= 0xFFFF;
932
933 /* t1 walks low to high bits ;
934 * t2 walks high to low.
935 */
936 m1 = mask >> t1;
937 m2 = mask & (t2 ? nbits(t2 + 1) : ~0UL);
938
Willy Tarreau85d04242019-04-16 18:09:13 +0200939 if (unlikely(!(m1 & 1))) {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100940 m1 &= ~1UL;
941 if (!m1) {
942 m1 = mask;
943 t1 = 0;
944 }
945 t1 += my_ffsl(m1) - 1;
946 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100947
Willy Tarreau85d04242019-04-16 18:09:13 +0200948 if (unlikely(!(m2 & (1UL << t2)) || t1 == t2)) {
949 /* highest bit not set */
950 if (!m2)
951 m2 = mask;
952
953 t2 = my_flsl(m2) - 1;
954 }
955
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100956 /* now we have two distinct thread IDs belonging to the mask */
957 q1 = accept_queue_rings[t1].tail - accept_queue_rings[t1].head + ACCEPT_QUEUE_SIZE;
958 if (q1 >= ACCEPT_QUEUE_SIZE)
959 q1 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100960
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100961 q2 = accept_queue_rings[t2].tail - accept_queue_rings[t2].head + ACCEPT_QUEUE_SIZE;
962 if (q2 >= ACCEPT_QUEUE_SIZE)
963 q2 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100964
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100965 /* we have 3 possibilities now :
966 * q1 < q2 : t1 is less loaded than t2, so we pick it
967 * and update t2 (since t1 might still be
968 * lower than another thread)
969 * q1 > q2 : t2 is less loaded than t1, so we pick it
970 * and update t1 (since t2 might still be
971 * lower than another thread)
972 * q1 = q2 : both are equally loaded, thus we pick t1
973 * and update t1 as it will become more loaded
974 * than t2.
975 */
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100976
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100977 q1 += l->thr_conn[t1];
978 q2 += l->thr_conn[t2];
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100979
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100980 if (q1 - q2 < 0) {
981 t = t1;
982 t2 = t2 ? t2 - 1 : LONGBITS - 1;
983 }
984 else if (q1 - q2 > 0) {
985 t = t2;
986 t1++;
987 if (t1 >= LONGBITS)
988 t1 = 0;
989 }
990 else {
991 t = t1;
992 t1++;
993 if (t1 >= LONGBITS)
994 t1 = 0;
995 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100996
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100997 /* new value for thr_idx */
998 t1 += (t2 << 16);
Olivier Houchard64213e92019-03-08 18:52:57 +0100999 } while (unlikely(!_HA_ATOMIC_CAS(&l->thr_idx, &t0, t1)));
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001000
Willy Tarreau0fe703b2019-03-05 08:46:28 +01001001 /* We successfully selected the best thread "t" for this
1002 * connection. We use deferred accepts even if it's the
1003 * local thread because tests show that it's the best
1004 * performing model, likely due to better cache locality
1005 * when processing this loop.
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001006 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +01001007 ring = &accept_queue_rings[t];
Willy Tarreau83efc322020-10-14 17:37:17 +02001008 if (accept_queue_push_mp(ring, cli_conn)) {
Willy Tarreau4781b152021-04-06 13:53:36 +02001009 _HA_ATOMIC_INC(&activity[t].accq_pushed);
Willy Tarreau2bd65a72019-09-24 06:55:18 +02001010 tasklet_wakeup(ring->tasklet);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001011 continue;
1012 }
1013 /* If the ring is full we do a synchronous accept on
1014 * the local thread here.
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001015 */
Willy Tarreau4781b152021-04-06 13:53:36 +02001016 _HA_ATOMIC_INC(&activity[t].accq_full);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001017 }
1018#endif // USE_THREAD
1019
Willy Tarreau4781b152021-04-06 13:53:36 +02001020 _HA_ATOMIC_INC(&l->thr_conn[tid]);
Willy Tarreau83efc322020-10-14 17:37:17 +02001021 ret = l->accept(cli_conn);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001022 if (unlikely(ret <= 0)) {
Willy Tarreau87b09662015-04-03 00:22:06 +02001023 /* The connection was closed by stream_accept(). Either
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001024 * we just have to ignore it (ret == 0) or it's a critical
1025 * error due to a resource shortage, and we must stop the
1026 * listener (ret < 0).
1027 */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001028 if (ret == 0) /* successful termination */
1029 continue;
1030
Willy Tarreaubb660302014-05-07 19:47:02 +02001031 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001032 }
1033
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001034 /* increase the per-process number of cumulated sessions, this
1035 * may only be done once l->accept() has accepted the connection.
1036 */
Willy Tarreau93e7c002013-10-07 18:51:07 +02001037 if (!(l->options & LI_O_UNLIMITED)) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001038 count = update_freq_ctr(&global.sess_per_sec, 1);
1039 HA_ATOMIC_UPDATE_MAX(&global.sps_max, count);
Willy Tarreau93e7c002013-10-07 18:51:07 +02001040 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001041#ifdef USE_OPENSSL
1042 if (!(l->options & LI_O_UNLIMITED) && l->bind_conf && l->bind_conf->is_ssl) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001043 count = update_freq_ctr(&global.ssl_per_sec, 1);
1044 HA_ATOMIC_UPDATE_MAX(&global.ssl_max, count);
Willy Tarreaue43d5322013-10-07 20:01:52 +02001045 }
1046#endif
Willy Tarreau93e7c002013-10-07 18:51:07 +02001047
Willy Tarreau8d2c98b2020-05-01 09:51:11 +02001048 ti->flags &= ~TI_FL_STUCK; // this thread is still running
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001049 } /* end of for (max_accept--) */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001050
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001051 end:
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001052 if (next_conn)
Willy Tarreau4781b152021-04-06 13:53:36 +02001053 _HA_ATOMIC_DEC(&l->nbconn);
Willy Tarreau741b4d62019-02-25 15:02:04 +01001054
Willy Tarreau82c97892019-02-27 19:32:32 +01001055 if (p && next_feconn)
Willy Tarreau4781b152021-04-06 13:53:36 +02001056 _HA_ATOMIC_DEC(&p->feconn);
Willy Tarreau82c97892019-02-27 19:32:32 +01001057
1058 if (next_actconn)
Willy Tarreau4781b152021-04-06 13:53:36 +02001059 _HA_ATOMIC_DEC(&actconn);
Willy Tarreau82c97892019-02-27 19:32:32 +01001060
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001061 if ((l->state == LI_FULL && (!l->maxconn || l->nbconn < l->maxconn)) ||
Willy Tarreau02757d02021-01-28 18:07:24 +01001062 (l->state == LI_LIMITED &&
Willy Tarreaucdcba112019-12-11 15:06:30 +01001063 ((!p || p->feconn < p->maxconn) && (actconn < global.maxconn) &&
1064 (!tick_isset(global_listener_queue_task->expire) ||
1065 tick_is_expired(global_listener_queue_task->expire, now_ms))))) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001066 /* at least one thread has to this when quitting */
1067 resume_listener(l);
1068
Willy Tarreau02757d02021-01-28 18:07:24 +01001069 /* Dequeues all of the listeners waiting for a resource */
Willy Tarreau241797a2019-12-10 14:10:52 +01001070 dequeue_all_listeners();
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001071
Olivier Houchard859dc802019-08-08 15:47:21 +02001072 if (p && !MT_LIST_ISEMPTY(&p->listener_queue) &&
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001073 (!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 +01001074 dequeue_proxy_listeners(p);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001075 }
Willy Tarreau0591bf72019-12-10 12:01:21 +01001076 return;
1077
1078 transient_error:
1079 /* pause the listener for up to 100 ms */
1080 expire = tick_add(now_ms, 100);
1081
Willy Tarreau258b3512020-10-13 17:46:05 +02001082 /* This may be a shared socket that was paused by another process.
1083 * Let's put it to pause in this case.
1084 */
1085 if (l->rx.proto && l->rx.proto->rx_listening(&l->rx) == 0) {
1086 pause_listener(l);
1087 goto end;
1088 }
1089
Willy Tarreau0591bf72019-12-10 12:01:21 +01001090 limit_global:
1091 /* (re-)queue the listener to the global queue and set it to expire no
1092 * later than <expire> ahead. The listener turns to LI_LIMITED.
1093 */
1094 limit_listener(l, &global_listener_queue);
1095 task_schedule(global_listener_queue_task, expire);
1096 goto end;
1097
1098 limit_proxy:
1099 /* (re-)queue the listener to the proxy's queue and set it to expire no
1100 * later than <expire> ahead. The listener turns to LI_LIMITED.
1101 */
1102 limit_listener(l, &p->listener_queue);
Willy Tarreaueeea8082020-01-08 19:15:07 +01001103 if (p->task && tick_isset(expire))
1104 task_schedule(p->task, expire);
Willy Tarreau0591bf72019-12-10 12:01:21 +01001105 goto end;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001106}
1107
Willy Tarreau05f50472017-09-15 09:19:58 +02001108/* Notify the listener that a connection initiated from it was released. This
1109 * is used to keep the connection count consistent and to possibly re-open
1110 * listening when it was limited.
1111 */
1112void listener_release(struct listener *l)
1113{
1114 struct proxy *fe = l->bind_conf->frontend;
1115
1116 if (!(l->options & LI_O_UNLIMITED))
Willy Tarreau4781b152021-04-06 13:53:36 +02001117 _HA_ATOMIC_DEC(&actconn);
Willy Tarreau82c97892019-02-27 19:32:32 +01001118 if (fe)
Willy Tarreau4781b152021-04-06 13:53:36 +02001119 _HA_ATOMIC_DEC(&fe->feconn);
1120 _HA_ATOMIC_DEC(&l->nbconn);
1121 _HA_ATOMIC_DEC(&l->thr_conn[tid]);
Willy Tarreau82c97892019-02-27 19:32:32 +01001122
1123 if (l->state == LI_FULL || l->state == LI_LIMITED)
Willy Tarreau05f50472017-09-15 09:19:58 +02001124 resume_listener(l);
1125
Willy Tarreau02757d02021-01-28 18:07:24 +01001126 /* Dequeues all of the listeners waiting for a resource */
1127 dequeue_all_listeners();
1128
Olivier Houchard859dc802019-08-08 15:47:21 +02001129 if (!MT_LIST_ISEMPTY(&fe->listener_queue) &&
Willy Tarreau05f50472017-09-15 09:19:58 +02001130 (!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 +01001131 dequeue_proxy_listeners(fe);
Willy Tarreau05f50472017-09-15 09:19:58 +02001132}
1133
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001134/* Initializes the listener queues. Returns 0 on success, otherwise ERR_* flags */
1135static int listener_queue_init()
1136{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001137 global_listener_queue_task = task_new(MAX_THREADS_MASK);
1138 if (!global_listener_queue_task) {
1139 ha_alert("Out of memory when initializing global listener queue\n");
1140 return ERR_FATAL|ERR_ABORT;
1141 }
1142 /* very simple initialization, users will queue the task if needed */
1143 global_listener_queue_task->context = NULL; /* not even a context! */
1144 global_listener_queue_task->process = manage_global_listener_queue;
1145
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001146 return 0;
1147}
1148
1149static void listener_queue_deinit()
1150{
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001151 task_destroy(global_listener_queue_task);
1152 global_listener_queue_task = NULL;
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001153}
1154
1155REGISTER_CONFIG_POSTPARSER("multi-threaded listener queue", listener_queue_init);
1156REGISTER_POST_DEINIT(listener_queue_deinit);
1157
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001158
1159/* This is the global management task for listeners. It enables listeners waiting
1160 * for global resources when there are enough free resource, or at least once in
Willy Tarreaud597ec22021-01-29 14:29:06 +01001161 * a while. It is designed to be called as a task. It's exported so that it's easy
1162 * to spot in "show tasks" or "show profiling".
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001163 */
Willy Tarreau144f84a2021-03-02 16:09:26 +01001164struct task *manage_global_listener_queue(struct task *t, void *context, unsigned int state)
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001165{
1166 /* If there are still too many concurrent connections, let's wait for
1167 * some of them to go away. We don't need to re-arm the timer because
1168 * each of them will scan the queue anyway.
1169 */
1170 if (unlikely(actconn >= global.maxconn))
1171 goto out;
1172
1173 /* We should periodically try to enable listeners waiting for a global
1174 * resource here, because it is possible, though very unlikely, that
1175 * they have been blocked by a temporary lack of global resource such
1176 * as a file descriptor or memory and that the temporary condition has
1177 * disappeared.
1178 */
1179 dequeue_all_listeners();
1180
1181 out:
1182 t->expire = TICK_ETERNITY;
1183 task_queue(t);
1184 return t;
1185}
1186
Willy Tarreau26982662012-09-12 23:17:10 +02001187/*
1188 * Registers the bind keyword list <kwl> as a list of valid keywords for next
1189 * parsing sessions.
1190 */
1191void bind_register_keywords(struct bind_kw_list *kwl)
1192{
Willy Tarreau2b718102021-04-21 07:32:39 +02001193 LIST_APPEND(&bind_keywords.list, &kwl->list);
Willy Tarreau26982662012-09-12 23:17:10 +02001194}
1195
1196/* Return a pointer to the bind keyword <kw>, or NULL if not found. If the
1197 * keyword is found with a NULL ->parse() function, then an attempt is made to
1198 * find one with a valid ->parse() function. This way it is possible to declare
1199 * platform-dependant, known keywords as NULL, then only declare them as valid
1200 * if some options are met. Note that if the requested keyword contains an
1201 * opening parenthesis, everything from this point is ignored.
1202 */
1203struct bind_kw *bind_find_kw(const char *kw)
1204{
1205 int index;
1206 const char *kwend;
1207 struct bind_kw_list *kwl;
1208 struct bind_kw *ret = NULL;
1209
1210 kwend = strchr(kw, '(');
1211 if (!kwend)
1212 kwend = kw + strlen(kw);
1213
1214 list_for_each_entry(kwl, &bind_keywords.list, list) {
1215 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1216 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
1217 kwl->kw[index].kw[kwend-kw] == 0) {
1218 if (kwl->kw[index].parse)
1219 return &kwl->kw[index]; /* found it !*/
1220 else
1221 ret = &kwl->kw[index]; /* may be OK */
1222 }
1223 }
1224 }
1225 return ret;
1226}
1227
Willy Tarreau8638f482012-09-18 18:01:17 +02001228/* Dumps all registered "bind" keywords to the <out> string pointer. The
1229 * unsupported keywords are only dumped if their supported form was not
1230 * found.
1231 */
1232void bind_dump_kws(char **out)
1233{
1234 struct bind_kw_list *kwl;
1235 int index;
1236
Christopher Faulet784063e2020-05-18 12:14:18 +02001237 if (!out)
1238 return;
1239
Willy Tarreau8638f482012-09-18 18:01:17 +02001240 *out = NULL;
1241 list_for_each_entry(kwl, &bind_keywords.list, list) {
1242 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1243 if (kwl->kw[index].parse ||
1244 bind_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) {
Willy Tarreau51fb7652012-09-18 18:24:39 +02001245 memprintf(out, "%s[%4s] %s%s%s\n", *out ? *out : "",
1246 kwl->scope,
Willy Tarreau8638f482012-09-18 18:01:17 +02001247 kwl->kw[index].kw,
Willy Tarreau51fb7652012-09-18 18:24:39 +02001248 kwl->kw[index].skip ? " <arg>" : "",
1249 kwl->kw[index].parse ? "" : " (not supported)");
Willy Tarreau8638f482012-09-18 18:01:17 +02001250 }
1251 }
1252 }
1253}
1254
Willy Tarreau433b05f2021-03-12 10:14:07 +01001255/* Try to find in srv_keyword the word that looks closest to <word> by counting
1256 * transitions between letters, digits and other characters. Will return the
1257 * best matching word if found, otherwise NULL.
1258 */
1259const char *bind_find_best_kw(const char *word)
1260{
1261 uint8_t word_sig[1024];
1262 uint8_t list_sig[1024];
1263 const struct bind_kw_list *kwl;
1264 const char *best_ptr = NULL;
1265 int dist, best_dist = INT_MAX;
1266 int index;
1267
1268 make_word_fingerprint(word_sig, word);
1269 list_for_each_entry(kwl, &bind_keywords.list, list) {
1270 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1271 make_word_fingerprint(list_sig, kwl->kw[index].kw);
1272 dist = word_fingerprint_distance(word_sig, list_sig);
1273 if (dist < best_dist) {
1274 best_dist = dist;
1275 best_ptr = kwl->kw[index].kw;
1276 }
1277 }
1278 }
1279
1280 if (best_dist > 2 * strlen(word) || (best_ptr && best_dist > 2 * strlen(best_ptr)))
1281 best_ptr = NULL;
1282
1283 return best_ptr;
1284}
1285
Willy Tarreau645513a2010-05-24 20:55:15 +02001286/************************************************************************/
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001287/* All supported sample and ACL keywords must be declared here. */
Willy Tarreau645513a2010-05-24 20:55:15 +02001288/************************************************************************/
1289
Willy Tarreaua5e37562011-12-16 17:06:15 +01001290/* set temp integer to the number of connexions to the same listening socket */
Willy Tarreau645513a2010-05-24 20:55:15 +02001291static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001292smp_fetch_dconn(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau645513a2010-05-24 20:55:15 +02001293{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001294 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001295 smp->data.u.sint = smp->sess->listener->nbconn;
Willy Tarreau645513a2010-05-24 20:55:15 +02001296 return 1;
1297}
1298
Willy Tarreaua5e37562011-12-16 17:06:15 +01001299/* set temp integer to the id of the socket (listener) */
Willy Tarreau645513a2010-05-24 20:55:15 +02001300static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001301smp_fetch_so_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau37406352012-04-23 16:16:37 +02001302{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001303 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001304 smp->data.u.sint = smp->sess->listener->luid;
Willy Tarreau645513a2010-05-24 20:55:15 +02001305 return 1;
1306}
Jerome Magnineb421b22020-03-27 22:08:40 +01001307static int
1308smp_fetch_so_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
1309{
1310 smp->data.u.str.area = smp->sess->listener->name;
1311 if (!smp->data.u.str.area)
1312 return 0;
1313
1314 smp->data.type = SMP_T_STR;
1315 smp->flags = SMP_F_CONST;
1316 smp->data.u.str.data = strlen(smp->data.u.str.area);
1317 return 1;
1318}
Willy Tarreau645513a2010-05-24 20:55:15 +02001319
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001320/* parse the "accept-proxy" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001321static 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 +02001322{
1323 struct listener *l;
1324
Willy Tarreau4348fad2012-09-20 16:48:07 +02001325 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001326 l->options |= LI_O_ACC_PROXY;
1327
1328 return 0;
1329}
1330
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001331/* parse the "accept-netscaler-cip" bind keyword */
1332static int bind_parse_accept_netscaler_cip(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1333{
1334 struct listener *l;
1335 uint32_t val;
1336
1337 if (!*args[cur_arg + 1]) {
1338 memprintf(err, "'%s' : missing value", args[cur_arg]);
1339 return ERR_ALERT | ERR_FATAL;
1340 }
1341
1342 val = atol(args[cur_arg + 1]);
1343 if (val <= 0) {
Willy Tarreaue2711c72019-02-27 15:39:41 +01001344 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001345 return ERR_ALERT | ERR_FATAL;
1346 }
1347
1348 list_for_each_entry(l, &conf->listeners, by_bind) {
1349 l->options |= LI_O_ACC_CIP;
1350 conf->ns_cip_magic = val;
1351 }
1352
1353 return 0;
1354}
1355
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001356/* parse the "backlog" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001357static 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 +02001358{
1359 struct listener *l;
1360 int val;
1361
1362 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001363 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001364 return ERR_ALERT | ERR_FATAL;
1365 }
1366
1367 val = atol(args[cur_arg + 1]);
Willy Tarreaue2711c72019-02-27 15:39:41 +01001368 if (val < 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001369 memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001370 return ERR_ALERT | ERR_FATAL;
1371 }
1372
Willy Tarreau4348fad2012-09-20 16:48:07 +02001373 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001374 l->backlog = val;
1375
1376 return 0;
1377}
1378
1379/* parse the "id" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001380static 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 +02001381{
1382 struct eb32_node *node;
Willy Tarreau4348fad2012-09-20 16:48:07 +02001383 struct listener *l, *new;
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001384 char *error;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001385
Willy Tarreau4348fad2012-09-20 16:48:07 +02001386 if (conf->listeners.n != conf->listeners.p) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001387 memprintf(err, "'%s' can only be used with a single socket", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001388 return ERR_ALERT | ERR_FATAL;
1389 }
1390
1391 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001392 memprintf(err, "'%s' : expects an integer argument", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001393 return ERR_ALERT | ERR_FATAL;
1394 }
1395
Willy Tarreau4348fad2012-09-20 16:48:07 +02001396 new = LIST_NEXT(&conf->listeners, struct listener *, by_bind);
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001397 new->luid = strtol(args[cur_arg + 1], &error, 10);
1398 if (*error != '\0') {
1399 memprintf(err, "'%s' : expects an integer argument, found '%s'", args[cur_arg], args[cur_arg + 1]);
1400 return ERR_ALERT | ERR_FATAL;
1401 }
Willy Tarreau4348fad2012-09-20 16:48:07 +02001402 new->conf.id.key = new->luid;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001403
Willy Tarreau4348fad2012-09-20 16:48:07 +02001404 if (new->luid <= 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001405 memprintf(err, "'%s' : custom id has to be > 0", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001406 return ERR_ALERT | ERR_FATAL;
1407 }
1408
Willy Tarreau4348fad2012-09-20 16:48:07 +02001409 node = eb32_lookup(&px->conf.used_listener_id, new->luid);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001410 if (node) {
1411 l = container_of(node, struct listener, conf.id);
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001412 memprintf(err, "'%s' : custom id %d already used at %s:%d ('bind %s')",
1413 args[cur_arg], l->luid, l->bind_conf->file, l->bind_conf->line,
1414 l->bind_conf->arg);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001415 return ERR_ALERT | ERR_FATAL;
1416 }
1417
Willy Tarreau4348fad2012-09-20 16:48:07 +02001418 eb32_insert(&px->conf.used_listener_id, &new->conf.id);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001419 return 0;
1420}
1421
1422/* parse the "maxconn" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001423static 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 +02001424{
1425 struct listener *l;
1426 int val;
1427
1428 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001429 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001430 return ERR_ALERT | ERR_FATAL;
1431 }
1432
1433 val = atol(args[cur_arg + 1]);
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001434 if (val < 0) {
1435 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001436 return ERR_ALERT | ERR_FATAL;
1437 }
1438
Willy Tarreau4348fad2012-09-20 16:48:07 +02001439 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001440 l->maxconn = val;
1441
1442 return 0;
1443}
1444
1445/* parse the "name" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001446static 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 +02001447{
1448 struct listener *l;
1449
1450 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001451 memprintf(err, "'%s' : missing name", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001452 return ERR_ALERT | ERR_FATAL;
1453 }
1454
Willy Tarreau4348fad2012-09-20 16:48:07 +02001455 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001456 l->name = strdup(args[cur_arg + 1]);
1457
1458 return 0;
1459}
1460
1461/* parse the "nice" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001462static 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 +02001463{
1464 struct listener *l;
1465 int val;
1466
1467 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001468 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001469 return ERR_ALERT | ERR_FATAL;
1470 }
1471
1472 val = atol(args[cur_arg + 1]);
1473 if (val < -1024 || val > 1024) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001474 memprintf(err, "'%s' : invalid value %d, allowed range is -1024..1024", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001475 return ERR_ALERT | ERR_FATAL;
1476 }
1477
Willy Tarreau4348fad2012-09-20 16:48:07 +02001478 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001479 l->nice = val;
1480
1481 return 0;
1482}
1483
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001484/* parse the "process" bind keyword */
1485static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1486{
Christopher Fauletc644fa92017-11-23 22:44:11 +01001487 char *slash;
1488 unsigned long proc = 0, thread = 0;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001489
Christopher Fauletc644fa92017-11-23 22:44:11 +01001490 if ((slash = strchr(args[cur_arg + 1], '/')) != NULL)
1491 *slash = 0;
1492
Willy Tarreau72faef32021-06-15 08:36:30 +02001493 if (parse_process_number(args[cur_arg + 1], &proc, 1, NULL, err)) {
Christopher Fauletf1f0c5f2017-11-22 12:06:43 +01001494 memprintf(err, "'%s' : %s", args[cur_arg], *err);
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001495 return ERR_ALERT | ERR_FATAL;
1496 }
1497
Christopher Fauletc644fa92017-11-23 22:44:11 +01001498 if (slash) {
Willy Tarreauc9a82e42019-01-26 13:25:14 +01001499 if (parse_process_number(slash+1, &thread, MAX_THREADS, NULL, err)) {
Christopher Fauletc644fa92017-11-23 22:44:11 +01001500 memprintf(err, "'%s' : %s", args[cur_arg], *err);
1501 return ERR_ALERT | ERR_FATAL;
1502 }
1503 *slash = '/';
1504 }
1505
Willy Tarreaue26993c2020-09-03 07:18:55 +02001506 conf->settings.bind_thread |= thread;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001507 return 0;
1508}
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001509
Christopher Fauleta717b992018-04-10 14:43:00 +02001510/* parse the "proto" bind keyword */
1511static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1512{
1513 struct ist proto;
1514
1515 if (!*args[cur_arg + 1]) {
1516 memprintf(err, "'%s' : missing value", args[cur_arg]);
1517 return ERR_ALERT | ERR_FATAL;
1518 }
1519
Tim Duesterhusdcf753a2021-03-04 17:31:47 +01001520 proto = ist(args[cur_arg + 1]);
Christopher Fauleta717b992018-04-10 14:43:00 +02001521 conf->mux_proto = get_mux_proto(proto);
1522 if (!conf->mux_proto) {
1523 memprintf(err, "'%s' : unknown MUX protocol '%s'", args[cur_arg], args[cur_arg+1]);
1524 return ERR_ALERT | ERR_FATAL;
1525 }
Christopher Fauleta717b992018-04-10 14:43:00 +02001526 return 0;
1527}
1528
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001529/* config parser for global "tune.listener.multi-queue", accepts "on" or "off" */
1530static int cfg_parse_tune_listener_mq(char **args, int section_type, struct proxy *curpx,
Willy Tarreau01825162021-03-09 09:53:46 +01001531 const struct proxy *defpx, const char *file, int line,
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001532 char **err)
1533{
1534 if (too_many_args(1, args, err, NULL))
1535 return -1;
1536
1537 if (strcmp(args[1], "on") == 0)
1538 global.tune.options |= GTUNE_LISTENER_MQ;
1539 else if (strcmp(args[1], "off") == 0)
1540 global.tune.options &= ~GTUNE_LISTENER_MQ;
1541 else {
1542 memprintf(err, "'%s' expects either 'on' or 'off' but got '%s'.", args[0], args[1]);
1543 return -1;
1544 }
1545 return 0;
1546}
1547
Willy Tarreau61612d42012-04-19 18:42:05 +02001548/* Note: must not be declared <const> as its list will be overwritten.
1549 * Please take care of keeping this list alphabetically sorted.
1550 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001551static struct sample_fetch_kw_list smp_kws = {ILH, {
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02001552 { "dst_conn", smp_fetch_dconn, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
1553 { "so_id", smp_fetch_so_id, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
Jerome Magnineb421b22020-03-27 22:08:40 +01001554 { "so_name", smp_fetch_so_name, 0, NULL, SMP_T_STR, SMP_USE_FTEND, },
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001555 { /* END */ },
1556}};
1557
Willy Tarreau0108d902018-11-25 19:14:37 +01001558INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
1559
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001560/* Note: must not be declared <const> as its list will be overwritten.
1561 * Please take care of keeping this list alphabetically sorted.
1562 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001563static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001564 { /* END */ },
Willy Tarreau645513a2010-05-24 20:55:15 +02001565}};
1566
Willy Tarreau0108d902018-11-25 19:14:37 +01001567INITCALL1(STG_REGISTER, acl_register_keywords, &acl_kws);
1568
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001569/* Note: must not be declared <const> as its list will be overwritten.
1570 * Please take care of keeping this list alphabetically sorted, doing so helps
1571 * all code contributors.
1572 * Optional keywords are also declared with a NULL ->parse() function so that
1573 * the config parser can report an appropriate error when a known keyword was
1574 * not enabled.
1575 */
Willy Tarreau51fb7652012-09-18 18:24:39 +02001576static struct bind_kw_list bind_kws = { "ALL", { }, {
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001577 { "accept-netscaler-cip", bind_parse_accept_netscaler_cip, 1 }, /* enable NetScaler Client IP insertion protocol */
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001578 { "accept-proxy", bind_parse_accept_proxy, 0 }, /* enable PROXY protocol */
1579 { "backlog", bind_parse_backlog, 1 }, /* set backlog of listening socket */
1580 { "id", bind_parse_id, 1 }, /* set id of listening socket */
1581 { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */
1582 { "name", bind_parse_name, 1 }, /* set name of listening socket */
1583 { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001584 { "process", bind_parse_process, 1 }, /* set list of allowed process for this socket */
Christopher Fauleta717b992018-04-10 14:43:00 +02001585 { "proto", bind_parse_proto, 1 }, /* set the proto to use for all incoming connections */
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001586 { /* END */ },
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001587}};
1588
Willy Tarreau0108d902018-11-25 19:14:37 +01001589INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
1590
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001591/* config keyword parsers */
1592static struct cfg_kw_list cfg_kws = {ILH, {
1593 { CFG_GLOBAL, "tune.listener.multi-queue", cfg_parse_tune_listener_mq },
1594 { 0, NULL, NULL }
1595}};
1596
1597INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
1598
Willy Tarreau645513a2010-05-24 20:55:15 +02001599/*
1600 * Local variables:
1601 * c-indent-level: 8
1602 * c-basic-offset: 8
1603 * End:
1604 */