blob: 04ce4e33f14a2c63b145ce767892e6c2735da2ee [file] [log] [blame]
Willy Tarreaudd815982007-10-16 12:25:14 +02001/*
Willy Tarreaud1d54542012-09-12 22:58:11 +02002 * Listener management functions.
Willy Tarreaudd815982007-10-16 12:25:14 +02003 *
Willy Tarreau0ccb7442013-01-07 22:54:17 +01004 * Copyright 2000-2013 Willy Tarreau <w@1wt.eu>
Willy Tarreaudd815982007-10-16 12:25:14 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Willy Tarreau44489252014-01-14 17:52:01 +010013#define _GNU_SOURCE
Willy Tarreau6ae1ba62014-05-07 19:01:58 +020014#include <ctype.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020015#include <errno.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020016#include <stdio.h>
17#include <string.h>
Willy Tarreau95ccdde2014-02-01 09:28:36 +010018#include <unistd.h>
19#include <fcntl.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020020
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020021#include <haproxy/api.h>
Christopher Fauletf1f0c5f2017-11-22 12:06:43 +010022#include <common/cfgparse.h>
Willy Tarreau8d366972020-05-27 16:10:29 +020023#include <haproxy/errors.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020024#include <haproxy/list.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020025#include <common/standard.h>
Willy Tarreau92b4f132020-06-01 11:05:15 +020026#include <haproxy/time.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020027
28#include <types/global.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020029#include <types/protocol.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020030
Willy Tarreau645513a2010-05-24 20:55:15 +020031#include <proto/acl.h>
Christopher Fauleta717b992018-04-10 14:43:00 +020032#include <proto/connection.h>
Willy Tarreaub648d632007-10-28 22:13:50 +010033#include <proto/fd.h>
Willy Tarreau66347942020-06-01 12:18:08 +020034#include <haproxy/freq_ctr.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020035#include <proto/log.h>
Willy Tarreau7a798e52016-04-14 11:13:20 +020036#include <proto/listener.h>
Willy Tarreau0de59fd2017-09-15 08:10:44 +020037#include <proto/protocol.h>
William Lallemand2fe7dd02018-09-11 16:51:29 +020038#include <proto/proto_sockpair.h>
Willy Tarreau0ccb7442013-01-07 22:54:17 +010039#include <proto/sample.h>
Willy Tarreaufb0afa72015-04-03 14:46:27 +020040#include <proto/stream.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020041#include <proto/task.h>
Willy Tarreaub648d632007-10-28 22:13:50 +010042
Willy Tarreau26982662012-09-12 23:17:10 +020043/* List head of all known bind keywords */
44static struct bind_kw_list bind_keywords = {
45 .list = LIST_HEAD_INIT(bind_keywords.list)
46};
47
Olivier Houchardf73629d2017-04-05 22:33:04 +020048struct xfer_sock_list *xfer_sock_list = NULL;
49
Willy Tarreauf2cb1692019-07-11 10:08:31 +020050/* there is one listener queue per thread so that a thread unblocking the
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +050051 * global queue can wake up listeners bound only to foreign threads by
Willy Tarreau2bd65a72019-09-24 06:55:18 +020052 * moving them to the remote queues and waking up the associated tasklet.
Willy Tarreauf2cb1692019-07-11 10:08:31 +020053 */
54static struct work_list *local_listener_queue;
55
Willy Tarreaua1d97f82019-12-10 11:18:41 +010056/* list of the temporarily limited listeners because of lack of resource */
57static struct mt_list global_listener_queue = MT_LIST_HEAD_INIT(global_listener_queue);
58static struct task *global_listener_queue_task;
59static struct task *manage_global_listener_queue(struct task *t, void *context, unsigned short state);
60
61
Willy Tarreau1efafce2019-01-27 15:37:19 +010062#if defined(USE_THREAD)
63
64struct accept_queue_ring accept_queue_rings[MAX_THREADS] __attribute__((aligned(64))) = { };
65
66/* dequeue and process a pending connection from the local accept queue (single
67 * consumer). Returns the accepted fd or -1 if none was found. The listener is
68 * placed into *li. The address is copied into *addr for no more than *addr_len
69 * bytes, and the address length is returned into *addr_len.
70 */
71int accept_queue_pop_sc(struct accept_queue_ring *ring, struct listener **li, void *addr, int *addr_len)
72{
73 struct accept_queue_entry *e;
74 unsigned int pos, next;
75 struct listener *ptr;
76 int len;
77 int fd;
78
79 pos = ring->head;
80
81 if (pos == ring->tail)
82 return -1;
83
84 next = pos + 1;
85 if (next >= ACCEPT_QUEUE_SIZE)
86 next = 0;
87
88 e = &ring->entry[pos];
89
90 /* wait for the producer to update the listener's pointer */
91 while (1) {
92 ptr = e->listener;
93 __ha_barrier_load();
94 if (ptr)
95 break;
96 pl_cpu_relax();
97 }
98
99 fd = e->fd;
100 len = e->addr_len;
101 if (len > *addr_len)
102 len = *addr_len;
103
104 if (likely(len > 0))
105 memcpy(addr, &e->addr, len);
106
107 /* release the entry */
108 e->listener = NULL;
109
110 __ha_barrier_store();
111 ring->head = next;
112
113 *addr_len = len;
114 *li = ptr;
115
116 return fd;
117}
118
119
120/* tries to push a new accepted connection <fd> into ring <ring> for listener
121 * <li>, from address <addr> whose length is <addr_len>. Returns non-zero if it
122 * succeeds, or zero if the ring is full. Supports multiple producers.
123 */
124int accept_queue_push_mp(struct accept_queue_ring *ring, int fd,
125 struct listener *li, const void *addr, int addr_len)
126{
127 struct accept_queue_entry *e;
128 unsigned int pos, next;
129
130 pos = ring->tail;
131 do {
132 next = pos + 1;
133 if (next >= ACCEPT_QUEUE_SIZE)
134 next = 0;
135 if (next == ring->head)
136 return 0; // ring full
Olivier Houchard64213e92019-03-08 18:52:57 +0100137 } while (unlikely(!_HA_ATOMIC_CAS(&ring->tail, &pos, next)));
Willy Tarreau1efafce2019-01-27 15:37:19 +0100138
139
140 e = &ring->entry[pos];
141
142 if (addr_len > sizeof(e->addr))
143 addr_len = sizeof(e->addr);
144
145 if (addr_len)
146 memcpy(&e->addr, addr, addr_len);
147
148 e->addr_len = addr_len;
149 e->fd = fd;
150
151 __ha_barrier_store();
152 /* now commit the change */
153
154 e->listener = li;
155 return 1;
156}
157
158/* proceed with accepting new connections */
159static struct task *accept_queue_process(struct task *t, void *context, unsigned short state)
160{
161 struct accept_queue_ring *ring = context;
162 struct listener *li;
163 struct sockaddr_storage addr;
Christopher Faulet102854c2019-04-30 12:17:13 +0200164 unsigned int max_accept;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100165 int addr_len;
166 int ret;
167 int fd;
168
Christopher Faulet102854c2019-04-30 12:17:13 +0200169 /* if global.tune.maxaccept is -1, then max_accept is UINT_MAX. It
170 * is not really illimited, but it is probably enough.
171 */
172 max_accept = global.tune.maxaccept ? global.tune.maxaccept : 64;
173 for (; max_accept; max_accept--) {
Willy Tarreau1efafce2019-01-27 15:37:19 +0100174 addr_len = sizeof(addr);
175 fd = accept_queue_pop_sc(ring, &li, &addr, &addr_len);
176 if (fd < 0)
177 break;
178
Olivier Houchard64213e92019-03-08 18:52:57 +0100179 _HA_ATOMIC_ADD(&li->thr_conn[tid], 1);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100180 ret = li->accept(li, fd, &addr);
181 if (ret <= 0) {
182 /* connection was terminated by the application */
183 continue;
184 }
185
186 /* increase the per-process number of cumulated sessions, this
187 * may only be done once l->accept() has accepted the connection.
188 */
189 if (!(li->options & LI_O_UNLIMITED)) {
190 HA_ATOMIC_UPDATE_MAX(&global.sps_max,
191 update_freq_ctr(&global.sess_per_sec, 1));
192 if (li->bind_conf && li->bind_conf->is_ssl) {
193 HA_ATOMIC_UPDATE_MAX(&global.ssl_max,
194 update_freq_ctr(&global.ssl_per_sec, 1));
195 }
196 }
197 }
198
199 /* ran out of budget ? Let's come here ASAP */
Christopher Faulet102854c2019-04-30 12:17:13 +0200200 if (!max_accept)
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200201 tasklet_wakeup(ring->tasklet);
Willy Tarreau1efafce2019-01-27 15:37:19 +0100202
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200203 return NULL;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100204}
205
206/* Initializes the accept-queues. Returns 0 on success, otherwise ERR_* flags */
207static int accept_queue_init()
208{
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200209 struct tasklet *t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100210 int i;
211
212 for (i = 0; i < global.nbthread; i++) {
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200213 t = tasklet_new();
Willy Tarreau1efafce2019-01-27 15:37:19 +0100214 if (!t) {
215 ha_alert("Out of memory while initializing accept queue for thread %d\n", i);
216 return ERR_FATAL|ERR_ABORT;
217 }
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200218 t->tid = i;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100219 t->process = accept_queue_process;
220 t->context = &accept_queue_rings[i];
Willy Tarreau2bd65a72019-09-24 06:55:18 +0200221 accept_queue_rings[i].tasklet = t;
Willy Tarreau1efafce2019-01-27 15:37:19 +0100222 }
223 return 0;
224}
225
226REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
227
228#endif // USE_THREAD
229
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100230/* This function adds the specified listener's file descriptor to the polling
231 * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500232 * LI_FULL state depending on its number of connections. In daemon mode, we
Willy Tarreauae302532014-05-07 19:22:24 +0200233 * also support binding only the relevant processes to their respective
234 * listeners. We don't do that in debug mode however.
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100235 */
Christopher Fauletf5b8adc2017-06-02 10:00:35 +0200236static void enable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100237{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100238 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100239 if (listener->state == LI_LISTEN) {
William Lallemand095ba4c2017-06-01 17:38:50 +0200240 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau6daac192019-02-02 17:39:53 +0100241 !(proc_mask(listener->bind_conf->bind_proc) & pid_bit)) {
Willy Tarreauae302532014-05-07 19:22:24 +0200242 /* we don't want to enable this listener and don't
243 * want any fd event to reach it.
244 */
Olivier Houchard1fc05162017-04-06 01:05:05 +0200245 if (!(global.tune.options & GTUNE_SOCKET_TRANSFER))
Christopher Faulet510c0d62018-03-16 10:04:47 +0100246 do_unbind_listener(listener, 1);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200247 else {
Christopher Faulet510c0d62018-03-16 10:04:47 +0100248 do_unbind_listener(listener, 0);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200249 listener->state = LI_LISTEN;
250 }
Willy Tarreauae302532014-05-07 19:22:24 +0200251 }
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100252 else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
Willy Tarreau49b046d2012-08-09 12:11:58 +0200253 fd_want_recv(listener->fd);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100254 listener->state = LI_READY;
Willy Tarreauae302532014-05-07 19:22:24 +0200255 }
256 else {
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100257 listener->state = LI_FULL;
258 }
259 }
William Lallemande22f11f2018-09-11 10:06:27 +0200260 /* if this listener is supposed to be only in the master, close it in the workers */
261 if ((global.mode & MODE_MWORKER) &&
262 (listener->options & LI_O_MWORKER) &&
263 master == 0) {
264 do_unbind_listener(listener, 1);
265 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100266 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100267}
268
269/* This function removes the specified listener's file descriptor from the
270 * polling lists if it is in the LI_READY or in the LI_FULL state. The listener
271 * enters LI_LISTEN.
272 */
Christopher Fauletf5b8adc2017-06-02 10:00:35 +0200273static void disable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100274{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100275 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100276 if (listener->state < LI_READY)
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200277 goto end;
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100278 if (listener->state == LI_READY)
Willy Tarreau49b046d2012-08-09 12:11:58 +0200279 fd_stop_recv(listener->fd);
Olivier Houchard859dc802019-08-08 15:47:21 +0200280 MT_LIST_DEL(&listener->wait_queue);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100281 listener->state = LI_LISTEN;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200282 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100283 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100284}
285
Willy Tarreaube58c382011-07-24 18:28:10 +0200286/* This function tries to temporarily disable a listener, depending on the OS
287 * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
288 * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
289 * closes upon SHUT_WR and refuses to rebind. So a common validation path
290 * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling
291 * is disabled. It normally returns non-zero, unless an error is reported.
292 */
293int pause_listener(struct listener *l)
294{
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200295 int ret = 1;
296
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100297 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200298
Olivier Houchard1fc05162017-04-06 01:05:05 +0200299 if (l->state <= LI_ZOMBIE)
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200300 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200301
Willy Tarreau092d8652014-07-07 20:22:12 +0200302 if (l->proto->pause) {
303 /* Returns < 0 in case of failure, 0 if the listener
304 * was totally stopped, or > 0 if correctly paused.
305 */
306 int ret = l->proto->pause(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200307
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200308 if (ret < 0) {
309 ret = 0;
310 goto end;
311 }
Willy Tarreau092d8652014-07-07 20:22:12 +0200312 else if (ret == 0)
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200313 goto end;
Willy Tarreaub3fb60b2012-10-04 08:56:31 +0200314 }
Willy Tarreaube58c382011-07-24 18:28:10 +0200315
Olivier Houchard859dc802019-08-08 15:47:21 +0200316 MT_LIST_DEL(&l->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200317
Willy Tarreau49b046d2012-08-09 12:11:58 +0200318 fd_stop_recv(l->fd);
Willy Tarreaube58c382011-07-24 18:28:10 +0200319 l->state = LI_PAUSED;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200320 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100321 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200322 return ret;
Willy Tarreaube58c382011-07-24 18:28:10 +0200323}
324
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200325/* This function tries to resume a temporarily disabled listener. Paused, full,
326 * limited and disabled listeners are handled, which means that this function
327 * may replace enable_listener(). The resulting state will either be LI_READY
328 * or LI_FULL. 0 is returned in case of failure to resume (eg: dead socket).
Willy Tarreauae302532014-05-07 19:22:24 +0200329 * Listeners bound to a different process are not woken up unless we're in
Willy Tarreauaf2fd582015-04-14 12:07:16 +0200330 * foreground mode, and are ignored. If the listener was only in the assigned
331 * state, it's totally rebound. This can happen if a pause() has completely
332 * stopped it. If the resume fails, 0 is returned and an error might be
333 * displayed.
Willy Tarreaube58c382011-07-24 18:28:10 +0200334 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100335int resume_listener(struct listener *l)
Willy Tarreaube58c382011-07-24 18:28:10 +0200336{
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200337 int ret = 1;
338
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100339 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200340
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200341 /* check that another thread didn't to the job in parallel (e.g. at the
342 * end of listen_accept() while we'd come from dequeue_all_listeners().
343 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200344 if (MT_LIST_ADDED(&l->wait_queue))
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200345 goto end;
346
William Lallemand095ba4c2017-06-01 17:38:50 +0200347 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau6daac192019-02-02 17:39:53 +0100348 !(proc_mask(l->bind_conf->bind_proc) & pid_bit))
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200349 goto end;
Willy Tarreau3569df32017-03-15 12:47:46 +0100350
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200351 if (l->state == LI_ASSIGNED) {
352 char msg[100];
353 int err;
354
355 err = l->proto->bind(l, msg, sizeof(msg));
356 if (err & ERR_ALERT)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100357 ha_alert("Resuming listener: %s\n", msg);
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200358 else if (err & ERR_WARN)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100359 ha_warning("Resuming listener: %s\n", msg);
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200360
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200361 if (err & (ERR_FATAL | ERR_ABORT)) {
362 ret = 0;
363 goto end;
364 }
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200365 }
366
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200367 if (l->state < LI_PAUSED || l->state == LI_ZOMBIE) {
368 ret = 0;
369 goto end;
370 }
Willy Tarreaube58c382011-07-24 18:28:10 +0200371
Willy Tarreaub3fb60b2012-10-04 08:56:31 +0200372 if (l->proto->sock_prot == IPPROTO_TCP &&
373 l->state == LI_PAUSED &&
Willy Tarreaue2711c72019-02-27 15:39:41 +0100374 listen(l->fd, listener_backlog(l)) != 0) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200375 ret = 0;
376 goto end;
377 }
Willy Tarreaube58c382011-07-24 18:28:10 +0200378
379 if (l->state == LI_READY)
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200380 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200381
Olivier Houchard859dc802019-08-08 15:47:21 +0200382 MT_LIST_DEL(&l->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200383
Willy Tarreaua8cf66b2019-02-27 16:49:00 +0100384 if (l->maxconn && l->nbconn >= l->maxconn) {
Willy Tarreaube58c382011-07-24 18:28:10 +0200385 l->state = LI_FULL;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200386 goto end;
Willy Tarreaube58c382011-07-24 18:28:10 +0200387 }
388
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200389 if (!(thread_mask(l->bind_conf->bind_thread) & tid_bit)) {
390 /* we're not allowed to touch this listener's FD, let's requeue
391 * the listener into one of its owning thread's queue instead.
392 */
Willy Tarreau50b65942020-02-12 10:01:29 +0100393 int first_thread = my_flsl(thread_mask(l->bind_conf->bind_thread) & all_threads_mask) - 1;
Willy Tarreauf2cb1692019-07-11 10:08:31 +0200394 work_list_add(&local_listener_queue[first_thread], &l->wait_queue);
395 goto end;
396 }
397
Willy Tarreau49b046d2012-08-09 12:11:58 +0200398 fd_want_recv(l->fd);
Willy Tarreaube58c382011-07-24 18:28:10 +0200399 l->state = LI_READY;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200400 end:
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100401 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200402 return ret;
403}
404
Willy Tarreau87b09662015-04-03 00:22:06 +0200405/* Marks a ready listener as full so that the stream code tries to re-enable
Willy Tarreau62793712011-07-24 19:23:38 +0200406 * it upon next close() using resume_listener().
407 */
Christopher Faulet5580ba22017-08-28 15:29:20 +0200408static void listener_full(struct listener *l)
Willy Tarreau62793712011-07-24 19:23:38 +0200409{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100410 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200411 if (l->state >= LI_READY) {
Olivier Houchard859dc802019-08-08 15:47:21 +0200412 MT_LIST_DEL(&l->wait_queue);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100413 if (l->state != LI_FULL) {
414 fd_stop_recv(l->fd);
415 l->state = LI_FULL;
416 }
Willy Tarreau62793712011-07-24 19:23:38 +0200417 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100418 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau62793712011-07-24 19:23:38 +0200419}
420
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200421/* Marks a ready listener as limited so that we only try to re-enable it when
422 * resources are free again. It will be queued into the specified queue.
423 */
Olivier Houchard859dc802019-08-08 15:47:21 +0200424static void limit_listener(struct listener *l, struct mt_list *list)
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200425{
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100426 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200427 if (l->state == LI_READY) {
Olivier Houchard859dc802019-08-08 15:47:21 +0200428 MT_LIST_ADDQ(list, &l->wait_queue);
Willy Tarreau49b046d2012-08-09 12:11:58 +0200429 fd_stop_recv(l->fd);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200430 l->state = LI_LIMITED;
431 }
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100432 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200433}
434
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100435/* This function adds all of the protocol's listener's file descriptors to the
436 * polling lists when they are in the LI_LISTEN state. It is intended to be
437 * used as a protocol's generic enable_all() primitive, for use after the
438 * fork(). It puts the listeners into LI_READY or LI_FULL states depending on
439 * their number of connections. It always returns ERR_NONE.
Willy Tarreaudaacf362019-07-24 16:45:02 +0200440 *
441 * Must be called with proto_lock held.
442 *
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100443 */
444int enable_all_listeners(struct protocol *proto)
445{
446 struct listener *listener;
447
448 list_for_each_entry(listener, &proto->listeners, proto_list)
449 enable_listener(listener);
450 return ERR_NONE;
451}
452
453/* This function removes all of the protocol's listener's file descriptors from
454 * the polling lists when they are in the LI_READY or LI_FULL states. It is
455 * intended to be used as a protocol's generic disable_all() primitive. It puts
456 * the listeners into LI_LISTEN, and always returns ERR_NONE.
Willy Tarreaudaacf362019-07-24 16:45:02 +0200457 *
458 * Must be called with proto_lock held.
459 *
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100460 */
461int disable_all_listeners(struct protocol *proto)
462{
463 struct listener *listener;
464
465 list_for_each_entry(listener, &proto->listeners, proto_list)
466 disable_listener(listener);
467 return ERR_NONE;
468}
469
Willy Tarreau241797a2019-12-10 14:10:52 +0100470/* Dequeues all listeners waiting for a resource the global wait queue */
471void dequeue_all_listeners()
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200472{
Willy Tarreau01abd022019-02-28 10:27:18 +0100473 struct listener *listener;
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200474
Willy Tarreau241797a2019-12-10 14:10:52 +0100475 while ((listener = MT_LIST_POP(&global_listener_queue, struct listener *, wait_queue))) {
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200476 /* This cannot fail because the listeners are by definition in
Willy Tarreau01abd022019-02-28 10:27:18 +0100477 * the LI_LIMITED state.
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200478 */
Willy Tarreau01abd022019-02-28 10:27:18 +0100479 resume_listener(listener);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200480 }
481}
482
Willy Tarreau241797a2019-12-10 14:10:52 +0100483/* Dequeues all listeners waiting for a resource in proxy <px>'s queue */
484void dequeue_proxy_listeners(struct proxy *px)
485{
486 struct listener *listener;
487
488 while ((listener = MT_LIST_POP(&px->listener_queue, struct listener *, wait_queue))) {
489 /* This cannot fail because the listeners are by definition in
490 * the LI_LIMITED state.
491 */
492 resume_listener(listener);
493 }
494}
495
Christopher Faulet510c0d62018-03-16 10:04:47 +0100496/* Must be called with the lock held. Depending on <do_close> value, it does
497 * what unbind_listener or unbind_listener_no_close should do.
498 */
499void do_unbind_listener(struct listener *listener, int do_close)
Willy Tarreaub648d632007-10-28 22:13:50 +0100500{
Olivier Houcharda5188562019-03-08 15:35:42 +0100501 if (listener->state == LI_READY && fd_updt)
Willy Tarreau49b046d2012-08-09 12:11:58 +0200502 fd_stop_recv(listener->fd);
Willy Tarreaub648d632007-10-28 22:13:50 +0100503
Olivier Houchard859dc802019-08-08 15:47:21 +0200504 MT_LIST_DEL(&listener->wait_queue);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200505
Willy Tarreaube58c382011-07-24 18:28:10 +0200506 if (listener->state >= LI_PAUSED) {
Olivier Houchard1fc05162017-04-06 01:05:05 +0200507 if (do_close) {
508 fd_delete(listener->fd);
509 listener->fd = -1;
510 }
511 else
512 fd_remove(listener->fd);
Willy Tarreaub648d632007-10-28 22:13:50 +0100513 listener->state = LI_ASSIGNED;
514 }
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100515}
516
Olivier Houchard1fc05162017-04-06 01:05:05 +0200517/* This function closes the listening socket for the specified listener,
518 * provided that it's already in a listening state. The listener enters the
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100519 * LI_ASSIGNED state. This function is intended to be used as a generic
520 * function for standard protocols.
Olivier Houchard1fc05162017-04-06 01:05:05 +0200521 */
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100522void unbind_listener(struct listener *listener)
Olivier Houchard1fc05162017-04-06 01:05:05 +0200523{
Christopher Faulet510c0d62018-03-16 10:04:47 +0100524 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100525 do_unbind_listener(listener, 1);
Christopher Faulet510c0d62018-03-16 10:04:47 +0100526 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200527}
528
529/* This function pretends the listener is dead, but keeps the FD opened, so
530 * that we can provide it, for conf reloading.
531 */
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100532void unbind_listener_no_close(struct listener *listener)
Olivier Houchard1fc05162017-04-06 01:05:05 +0200533{
Christopher Faulet510c0d62018-03-16 10:04:47 +0100534 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreaubbd09b92017-11-05 11:38:44 +0100535 do_unbind_listener(listener, 0);
Christopher Faulet510c0d62018-03-16 10:04:47 +0100536 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Olivier Houchard1fc05162017-04-06 01:05:05 +0200537}
538
Willy Tarreau3acf8c32007-10-28 22:35:41 +0100539/* This function closes all listening sockets bound to the protocol <proto>,
540 * and the listeners end in LI_ASSIGNED state if they were higher. It does not
541 * detach them from the protocol. It always returns ERR_NONE.
Willy Tarreaudaacf362019-07-24 16:45:02 +0200542 *
543 * Must be called with proto_lock held.
544 *
Willy Tarreau3acf8c32007-10-28 22:35:41 +0100545 */
546int unbind_all_listeners(struct protocol *proto)
547{
548 struct listener *listener;
549
550 list_for_each_entry(listener, &proto->listeners, proto_list)
551 unbind_listener(listener);
552 return ERR_NONE;
553}
554
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200555/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
556 * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
557 * allocation). The address family is taken from ss->ss_family. The number of
558 * jobs and listeners is automatically increased by the number of listeners
William Lallemand75ea0a02017-11-15 19:02:58 +0100559 * created. If the <inherited> argument is set to 1, it specifies that the FD
560 * was obtained from a parent process.
561 * It returns non-zero on success, zero on error with the error message
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200562 * set in <err>.
563 */
564int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
William Lallemand75ea0a02017-11-15 19:02:58 +0100565 int portl, int porth, int fd, int inherited, char **err)
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200566{
567 struct protocol *proto = protocol_by_family(ss->ss_family);
568 struct listener *l;
569 int port;
570
571 if (!proto) {
572 memprintf(err, "unsupported protocol family %d", ss->ss_family);
573 return 0;
574 }
575
576 for (port = portl; port <= porth; port++) {
577 l = calloc(1, sizeof(*l));
578 if (!l) {
579 memprintf(err, "out of memory");
580 return 0;
581 }
582 l->obj_type = OBJ_TYPE_LISTENER;
583 LIST_ADDQ(&bc->frontend->conf.listeners, &l->by_fe);
584 LIST_ADDQ(&bc->listeners, &l->by_bind);
585 l->bind_conf = bc;
586
587 l->fd = fd;
588 memcpy(&l->addr, ss, sizeof(*ss));
Olivier Houchard859dc802019-08-08 15:47:21 +0200589 MT_LIST_INIT(&l->wait_queue);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200590 l->state = LI_INIT;
591
592 proto->add(l, port);
593
William Lallemand75ea0a02017-11-15 19:02:58 +0100594 if (inherited)
595 l->options |= LI_O_INHERITED;
596
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100597 HA_SPIN_INIT(&l->lock);
Olivier Houchard64213e92019-03-08 18:52:57 +0100598 _HA_ATOMIC_ADD(&jobs, 1);
599 _HA_ATOMIC_ADD(&listeners, 1);
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200600 }
601 return 1;
602}
603
Willy Tarreau1a64d162007-10-28 22:26:05 +0100604/* Delete a listener from its protocol's list of listeners. The listener's
605 * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
Willy Tarreau2cc5bae2017-09-15 08:18:11 +0200606 * number of listeners is updated, as well as the global number of listeners
607 * and jobs. Note that the listener must have previously been unbound. This
608 * is the generic function to use to remove a listener.
Willy Tarreaudaacf362019-07-24 16:45:02 +0200609 *
610 * Will grab the proto_lock.
611 *
Willy Tarreau1a64d162007-10-28 22:26:05 +0100612 */
613void delete_listener(struct listener *listener)
614{
Willy Tarreau6ee9f8d2019-08-26 10:55:52 +0200615 HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100616 HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100617 if (listener->state == LI_ASSIGNED) {
618 listener->state = LI_INIT;
619 LIST_DEL(&listener->proto_list);
620 listener->proto->nb_listeners--;
Olivier Houchard64213e92019-03-08 18:52:57 +0100621 _HA_ATOMIC_SUB(&jobs, 1);
622 _HA_ATOMIC_SUB(&listeners, 1);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100623 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100624 HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
Willy Tarreau6ee9f8d2019-08-26 10:55:52 +0200625 HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
Willy Tarreau1a64d162007-10-28 22:26:05 +0100626}
627
Willy Tarreaue2711c72019-02-27 15:39:41 +0100628/* Returns a suitable value for a listener's backlog. It uses the listener's,
629 * otherwise the frontend's backlog, otherwise the listener's maxconn,
630 * otherwise the frontend's maxconn, otherwise 1024.
631 */
632int listener_backlog(const struct listener *l)
633{
634 if (l->backlog)
635 return l->backlog;
636
637 if (l->bind_conf->frontend->backlog)
638 return l->bind_conf->frontend->backlog;
639
640 if (l->maxconn)
641 return l->maxconn;
642
643 if (l->bind_conf->frontend->maxconn)
644 return l->bind_conf->frontend->maxconn;
645
646 return 1024;
647}
648
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200649/* This function is called on a read event from a listening socket, corresponding
650 * to an accept. It tries to accept as many connections as possible, and for each
651 * calls the listener's accept handler (generally the frontend's accept handler).
652 */
Willy Tarreauafad0e02012-08-09 14:45:22 +0200653void listener_accept(int fd)
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200654{
655 struct listener *l = fdtab[fd].owner;
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100656 struct proxy *p;
Christopher Faulet102854c2019-04-30 12:17:13 +0200657 unsigned int max_accept;
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100658 int next_conn = 0;
Willy Tarreau82c97892019-02-27 19:32:32 +0100659 int next_feconn = 0;
660 int next_actconn = 0;
Willy Tarreaubb660302014-05-07 19:47:02 +0200661 int expire;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200662 int cfd;
663 int ret;
Willy Tarreau818dca52014-01-31 19:40:19 +0100664#ifdef USE_ACCEPT4
665 static int accept4_broken;
666#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200667
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100668 if (!l)
669 return;
670 p = l->bind_conf->frontend;
Christopher Faulet102854c2019-04-30 12:17:13 +0200671
672 /* if l->maxaccept is -1, then max_accept is UINT_MAX. It is not really
673 * illimited, but it is probably enough.
674 */
Olivier Houchardd16a9df2019-02-25 16:18:16 +0100675 max_accept = l->maxaccept ? l->maxaccept : 1;
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200676
Willy Tarreau93e7c002013-10-07 18:51:07 +0200677 if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
678 int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
Willy Tarreau93e7c002013-10-07 18:51:07 +0200679
680 if (unlikely(!max)) {
681 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200682 expire = tick_add(now_ms, next_event_delay(&global.sess_per_sec, global.sps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100683 goto limit_global;
Willy Tarreau93e7c002013-10-07 18:51:07 +0200684 }
685
686 if (max_accept > max)
687 max_accept = max;
688 }
689
690 if (!(l->options & LI_O_UNLIMITED) && global.cps_lim) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200691 int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
692
693 if (unlikely(!max)) {
694 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200695 expire = tick_add(now_ms, next_event_delay(&global.conn_per_sec, global.cps_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100696 goto limit_global;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200697 }
698
699 if (max_accept > max)
700 max_accept = max;
701 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200702#ifdef USE_OPENSSL
703 if (!(l->options & LI_O_UNLIMITED) && global.ssl_lim && l->bind_conf && l->bind_conf->is_ssl) {
704 int max = freq_ctr_remain(&global.ssl_per_sec, global.ssl_lim, 0);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200705
Willy Tarreaue43d5322013-10-07 20:01:52 +0200706 if (unlikely(!max)) {
707 /* frontend accept rate limit was reached */
Willy Tarreaue43d5322013-10-07 20:01:52 +0200708 expire = tick_add(now_ms, next_event_delay(&global.ssl_per_sec, global.ssl_lim, 0));
Willy Tarreau0591bf72019-12-10 12:01:21 +0100709 goto limit_global;
Willy Tarreaue43d5322013-10-07 20:01:52 +0200710 }
711
712 if (max_accept > max)
713 max_accept = max;
714 }
715#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200716 if (p && p->fe_sps_lim) {
717 int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0);
718
719 if (unlikely(!max)) {
720 /* frontend accept rate limit was reached */
Willy Tarreau0591bf72019-12-10 12:01:21 +0100721 expire = tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0));
722 goto limit_proxy;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200723 }
724
725 if (max_accept > max)
726 max_accept = max;
727 }
728
729 /* Note: if we fail to allocate a connection because of configured
730 * limits, we'll schedule a new attempt worst 1 second later in the
731 * worst case. If we fail due to system limits or temporary resource
732 * shortage, we try again 100ms later in the worst case.
733 */
Christopher Faulet102854c2019-04-30 12:17:13 +0200734 for (; max_accept; next_conn = next_feconn = next_actconn = 0, max_accept--) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200735 struct sockaddr_storage addr;
736 socklen_t laddr = sizeof(addr);
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200737 unsigned int count;
Willy Tarreauaf613e82020-06-05 08:40:51 +0200738 __decl_thread(unsigned long mask);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200739
Willy Tarreau82c97892019-02-27 19:32:32 +0100740 /* pre-increase the number of connections without going too far.
741 * We process the listener, then the proxy, then the process.
742 * We know which ones to unroll based on the next_xxx value.
743 */
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100744 do {
745 count = l->nbconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100746 if (unlikely(l->maxconn && count >= l->maxconn)) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100747 /* the listener was marked full or another
748 * thread is going to do it.
749 */
750 next_conn = 0;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100751 listener_full(l);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100752 goto end;
753 }
754 next_conn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000755 } while (!_HA_ATOMIC_CAS(&l->nbconn, (int *)(&count), next_conn));
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100756
Willy Tarreau82c97892019-02-27 19:32:32 +0100757 if (p) {
758 do {
759 count = p->feconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100760 if (unlikely(count >= p->maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100761 /* the frontend was marked full or another
762 * thread is going to do it.
763 */
764 next_feconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100765 expire = TICK_ETERNITY;
766 goto limit_proxy;
Willy Tarreau82c97892019-02-27 19:32:32 +0100767 }
768 next_feconn = count + 1;
Olivier Houchard64213e92019-03-08 18:52:57 +0100769 } while (!_HA_ATOMIC_CAS(&p->feconn, &count, next_feconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200770 }
771
Willy Tarreau82c97892019-02-27 19:32:32 +0100772 if (!(l->options & LI_O_UNLIMITED)) {
773 do {
774 count = actconn;
Willy Tarreau93604ed2019-11-15 10:20:07 +0100775 if (unlikely(count >= global.maxconn)) {
Willy Tarreau82c97892019-02-27 19:32:32 +0100776 /* the process was marked full or another
777 * thread is going to do it.
778 */
779 next_actconn = 0;
Willy Tarreau0591bf72019-12-10 12:01:21 +0100780 expire = tick_add(now_ms, 1000); /* try again in 1 second */
781 goto limit_global;
Willy Tarreau82c97892019-02-27 19:32:32 +0100782 }
783 next_actconn = count + 1;
David Carlier56716622019-03-27 16:08:42 +0000784 } while (!_HA_ATOMIC_CAS(&actconn, (int *)(&count), next_actconn));
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200785 }
786
William Lallemand2fe7dd02018-09-11 16:51:29 +0200787 /* with sockpair@ we don't want to do an accept */
788 if (unlikely(l->addr.ss_family == AF_CUST_SOCKPAIR)) {
789 if ((cfd = recv_fd_uxst(fd)) != -1)
William Lallemandd9138002018-11-27 12:02:39 +0100790 fcntl(cfd, F_SETFL, O_NONBLOCK);
Willy Tarreau888d5672019-01-27 18:34:12 +0100791 /* just like with UNIX sockets, only the family is filled */
792 addr.ss_family = AF_UNIX;
793 laddr = sizeof(addr.ss_family);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200794 } else
795
Willy Tarreau1bc4aab2012-10-08 20:11:03 +0200796#ifdef USE_ACCEPT4
Willy Tarreau818dca52014-01-31 19:40:19 +0100797 /* only call accept4() if it's known to be safe, otherwise
798 * fallback to the legacy accept() + fcntl().
799 */
800 if (unlikely(accept4_broken ||
William Lallemandd9138002018-11-27 12:02:39 +0100801 ((cfd = accept4(fd, (struct sockaddr *)&addr, &laddr, SOCK_NONBLOCK)) == -1 &&
Willy Tarreau818dca52014-01-31 19:40:19 +0100802 (errno == ENOSYS || errno == EINVAL || errno == EBADF) &&
803 (accept4_broken = 1))))
804#endif
Willy Tarreau6b3b0d42012-10-22 19:32:55 +0200805 if ((cfd = accept(fd, (struct sockaddr *)&addr, &laddr)) != -1)
William Lallemandd9138002018-11-27 12:02:39 +0100806 fcntl(cfd, F_SETFL, O_NONBLOCK);
Willy Tarreau818dca52014-01-31 19:40:19 +0100807
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200808 if (unlikely(cfd == -1)) {
809 switch (errno) {
810 case EAGAIN:
Willy Tarreau20aeb1c2019-12-10 08:42:21 +0100811 if (fdtab[fd].ev & (FD_POLL_HUP|FD_POLL_ERR)) {
Willy Tarreaubb660302014-05-07 19:47:02 +0200812 /* the listening socket might have been disabled in a shared
813 * process and we're a collateral victim. We'll just pause for
814 * a while in case it comes back. In the mean time, we need to
815 * clear this sticky flag.
816 */
Willy Tarreau20aeb1c2019-12-10 08:42:21 +0100817 _HA_ATOMIC_AND(&fdtab[fd].ev, ~(FD_POLL_HUP|FD_POLL_ERR));
Willy Tarreaubb660302014-05-07 19:47:02 +0200818 goto transient_error;
819 }
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +0200820 goto end; /* nothing more to accept */
Willy Tarreaubb660302014-05-07 19:47:02 +0200821 case EINVAL:
822 /* might be trying to accept on a shut fd (eg: soft stop) */
823 goto transient_error;
Willy Tarreaua593ec52014-01-20 21:21:30 +0100824 case EINTR:
825 case ECONNABORTED:
Olivier Houchard64213e92019-03-08 18:52:57 +0100826 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100827 if (p)
Olivier Houchard64213e92019-03-08 18:52:57 +0100828 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +0100829 if (!(l->options & LI_O_UNLIMITED))
Olivier Houchard64213e92019-03-08 18:52:57 +0100830 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreaua593ec52014-01-20 21:21:30 +0100831 continue;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200832 case ENFILE:
833 if (p)
834 send_log(p, LOG_EMERG,
Willy Tarreauc5532ac2018-01-29 15:06:04 +0100835 "Proxy %s reached system FD limit (maxsock=%d). Please check system tunables.\n",
836 p->id, global.maxsock);
Willy Tarreaubb660302014-05-07 19:47:02 +0200837 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200838 case EMFILE:
839 if (p)
840 send_log(p, LOG_EMERG,
Willy Tarreauc5532ac2018-01-29 15:06:04 +0100841 "Proxy %s reached process FD limit (maxsock=%d). Please check 'ulimit-n' and restart.\n",
842 p->id, global.maxsock);
Willy Tarreaubb660302014-05-07 19:47:02 +0200843 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200844 case ENOBUFS:
845 case ENOMEM:
846 if (p)
847 send_log(p, LOG_EMERG,
Willy Tarreauc5532ac2018-01-29 15:06:04 +0100848 "Proxy %s reached system memory limit (maxsock=%d). Please check system tunables.\n",
849 p->id, global.maxsock);
Willy Tarreaubb660302014-05-07 19:47:02 +0200850 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200851 default:
Willy Tarreaua593ec52014-01-20 21:21:30 +0100852 /* unexpected result, let's give up and let other tasks run */
Willy Tarreau92079932019-12-10 09:30:05 +0100853 max_accept = 0;
854 goto end;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200855 }
856 }
857
William Lallemandd9138002018-11-27 12:02:39 +0100858 /* we don't want to leak the FD upon reload if it's in the master */
859 if (unlikely(master == 1))
860 fcntl(cfd, F_SETFD, FD_CLOEXEC);
861
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100862 /* The connection was accepted, it must be counted as such */
863 if (l->counters)
864 HA_ATOMIC_UPDATE_MAX(&l->counters->conn_max, next_conn);
865
Willy Tarreau82c97892019-02-27 19:32:32 +0100866 if (p)
867 HA_ATOMIC_UPDATE_MAX(&p->fe_counters.conn_max, next_feconn);
868
869 proxy_inc_fe_conn_ctr(l, p);
870
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100871 if (!(l->options & LI_O_UNLIMITED)) {
872 count = update_freq_ctr(&global.conn_per_sec, 1);
873 HA_ATOMIC_UPDATE_MAX(&global.cps_max, count);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +0100874 }
875
Willy Tarreau64a9c052019-04-12 15:27:17 +0200876 _HA_ATOMIC_ADD(&activity[tid].accepted, 1);
877
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200878 if (unlikely(cfd >= global.maxsock)) {
879 send_log(p, LOG_EMERG,
880 "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n",
881 p->id);
882 close(cfd);
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 Tarreaue0e9c482019-01-27 15:37:19 +0100896#if defined(USE_THREAD)
Willy Tarreau897e2c52019-03-13 15:03:53 +0100897 mask = thread_mask(l->bind_conf->bind_thread) & all_threads_mask;
Willy Tarreaua7da5e82020-03-12 17:33:29 +0100898 if (atleast2(mask) && (global.tune.options & GTUNE_LISTENER_MQ) && !stopping) {
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100899 struct accept_queue_ring *ring;
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100900 unsigned int t, t0, t1, t2;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100901
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100902 /* The principle is that we have two running indexes,
903 * each visiting in turn all threads bound to this
904 * listener. The connection will be assigned to the one
905 * with the least connections, and the other one will
906 * be updated. This provides a good fairness on short
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100907 * connections (round robin) and on long ones (conn
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100908 * count), without ever missing any idle thread.
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100909 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100910
911 /* keep a copy for the final update. thr_idx is composite
912 * and made of (t2<<16) + t1.
913 */
Willy Tarreau0cf33172019-03-06 15:26:33 +0100914 t0 = l->thr_idx;
Willy Tarreaufc630bd2019-03-04 19:57:34 +0100915 do {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100916 unsigned long m1, m2;
917 int q1, q2;
918
919 t2 = t1 = t0;
920 t2 >>= 16;
921 t1 &= 0xFFFF;
922
923 /* t1 walks low to high bits ;
924 * t2 walks high to low.
925 */
926 m1 = mask >> t1;
927 m2 = mask & (t2 ? nbits(t2 + 1) : ~0UL);
928
Willy Tarreau85d04242019-04-16 18:09:13 +0200929 if (unlikely(!(m1 & 1))) {
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100930 m1 &= ~1UL;
931 if (!m1) {
932 m1 = mask;
933 t1 = 0;
934 }
935 t1 += my_ffsl(m1) - 1;
936 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100937
Willy Tarreau85d04242019-04-16 18:09:13 +0200938 if (unlikely(!(m2 & (1UL << t2)) || t1 == t2)) {
939 /* highest bit not set */
940 if (!m2)
941 m2 = mask;
942
943 t2 = my_flsl(m2) - 1;
944 }
945
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100946 /* now we have two distinct thread IDs belonging to the mask */
947 q1 = accept_queue_rings[t1].tail - accept_queue_rings[t1].head + ACCEPT_QUEUE_SIZE;
948 if (q1 >= ACCEPT_QUEUE_SIZE)
949 q1 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100950
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100951 q2 = accept_queue_rings[t2].tail - accept_queue_rings[t2].head + ACCEPT_QUEUE_SIZE;
952 if (q2 >= ACCEPT_QUEUE_SIZE)
953 q2 -= ACCEPT_QUEUE_SIZE;
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100954
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100955 /* we have 3 possibilities now :
956 * q1 < q2 : t1 is less loaded than t2, so we pick it
957 * and update t2 (since t1 might still be
958 * lower than another thread)
959 * q1 > q2 : t2 is less loaded than t1, so we pick it
960 * and update t1 (since t2 might still be
961 * lower than another thread)
962 * q1 = q2 : both are equally loaded, thus we pick t1
963 * and update t1 as it will become more loaded
964 * than t2.
965 */
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100966
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100967 q1 += l->thr_conn[t1];
968 q2 += l->thr_conn[t2];
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100969
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100970 if (q1 - q2 < 0) {
971 t = t1;
972 t2 = t2 ? t2 - 1 : LONGBITS - 1;
973 }
974 else if (q1 - q2 > 0) {
975 t = t2;
976 t1++;
977 if (t1 >= LONGBITS)
978 t1 = 0;
979 }
980 else {
981 t = t1;
982 t1++;
983 if (t1 >= LONGBITS)
984 t1 = 0;
985 }
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100986
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100987 /* new value for thr_idx */
988 t1 += (t2 << 16);
Olivier Houchard64213e92019-03-08 18:52:57 +0100989 } while (unlikely(!_HA_ATOMIC_CAS(&l->thr_idx, &t0, t1)));
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100990
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100991 /* We successfully selected the best thread "t" for this
992 * connection. We use deferred accepts even if it's the
993 * local thread because tests show that it's the best
994 * performing model, likely due to better cache locality
995 * when processing this loop.
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100996 */
Willy Tarreau0fe703b2019-03-05 08:46:28 +0100997 ring = &accept_queue_rings[t];
Willy Tarreaue0e9c482019-01-27 15:37:19 +0100998 if (accept_queue_push_mp(ring, cfd, l, &addr, laddr)) {
Olivier Houchard64213e92019-03-08 18:52:57 +0100999 _HA_ATOMIC_ADD(&activity[t].accq_pushed, 1);
Willy Tarreau2bd65a72019-09-24 06:55:18 +02001000 tasklet_wakeup(ring->tasklet);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001001 continue;
1002 }
1003 /* If the ring is full we do a synchronous accept on
1004 * the local thread here.
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001005 */
Olivier Houchard64213e92019-03-08 18:52:57 +01001006 _HA_ATOMIC_ADD(&activity[t].accq_full, 1);
Willy Tarreaue0e9c482019-01-27 15:37:19 +01001007 }
1008#endif // USE_THREAD
1009
Olivier Houchard64213e92019-03-08 18:52:57 +01001010 _HA_ATOMIC_ADD(&l->thr_conn[tid], 1);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001011 ret = l->accept(l, cfd, &addr);
1012 if (unlikely(ret <= 0)) {
Willy Tarreau87b09662015-04-03 00:22:06 +02001013 /* The connection was closed by stream_accept(). Either
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001014 * we just have to ignore it (ret == 0) or it's a critical
1015 * error due to a resource shortage, and we must stop the
1016 * listener (ret < 0).
1017 */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001018 if (ret == 0) /* successful termination */
1019 continue;
1020
Willy Tarreaubb660302014-05-07 19:47:02 +02001021 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001022 }
1023
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001024 /* increase the per-process number of cumulated sessions, this
1025 * may only be done once l->accept() has accepted the connection.
1026 */
Willy Tarreau93e7c002013-10-07 18:51:07 +02001027 if (!(l->options & LI_O_UNLIMITED)) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001028 count = update_freq_ctr(&global.sess_per_sec, 1);
1029 HA_ATOMIC_UPDATE_MAX(&global.sps_max, count);
Willy Tarreau93e7c002013-10-07 18:51:07 +02001030 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001031#ifdef USE_OPENSSL
1032 if (!(l->options & LI_O_UNLIMITED) && l->bind_conf && l->bind_conf->is_ssl) {
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001033 count = update_freq_ctr(&global.ssl_per_sec, 1);
1034 HA_ATOMIC_UPDATE_MAX(&global.ssl_max, count);
Willy Tarreaue43d5322013-10-07 20:01:52 +02001035 }
1036#endif
Willy Tarreau93e7c002013-10-07 18:51:07 +02001037
Willy Tarreau8d2c98b2020-05-01 09:51:11 +02001038 ti->flags &= ~TI_FL_STUCK; // this thread is still running
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001039 } /* end of for (max_accept--) */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001040
Christopher Faulet8d8aa0d2017-05-30 15:36:50 +02001041 end:
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001042 if (next_conn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001043 _HA_ATOMIC_SUB(&l->nbconn, 1);
Willy Tarreau741b4d62019-02-25 15:02:04 +01001044
Willy Tarreau82c97892019-02-27 19:32:32 +01001045 if (p && next_feconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001046 _HA_ATOMIC_SUB(&p->feconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001047
1048 if (next_actconn)
Olivier Houchard64213e92019-03-08 18:52:57 +01001049 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001050
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001051 if ((l->state == LI_FULL && (!l->maxconn || l->nbconn < l->maxconn)) ||
Willy Tarreaucdcba112019-12-11 15:06:30 +01001052 (l->state == LI_LIMITED &&
1053 ((!p || p->feconn < p->maxconn) && (actconn < global.maxconn) &&
1054 (!tick_isset(global_listener_queue_task->expire) ||
1055 tick_is_expired(global_listener_queue_task->expire, now_ms))))) {
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001056 /* at least one thread has to this when quitting */
1057 resume_listener(l);
1058
1059 /* Dequeues all of the listeners waiting for a resource */
Willy Tarreau241797a2019-12-10 14:10:52 +01001060 dequeue_all_listeners();
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001061
Olivier Houchard859dc802019-08-08 15:47:21 +02001062 if (p && !MT_LIST_ISEMPTY(&p->listener_queue) &&
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001063 (!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 +01001064 dequeue_proxy_listeners(p);
Willy Tarreau3f0d02b2019-02-25 19:23:37 +01001065 }
Willy Tarreau4c044e22019-12-05 07:40:32 +01001066
Willy Tarreau92079932019-12-10 09:30:05 +01001067 /* Now it's getting tricky. The listener was supposed to be in LI_READY
1068 * state but in the mean time we might have changed it to LI_FULL or
1069 * LI_LIMITED, and another thread might also have turned it to
1070 * LI_PAUSED, LI_LISTEN or even LI_INI when stopping a proxy. We must
1071 * be certain to keep the FD enabled when in the READY state but we
1072 * must also stop it for other states that we might have switched to
1073 * while others re-enabled polling.
1074 */
1075 HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
1076 if (l->state == LI_READY) {
1077 if (max_accept > 0)
1078 fd_cant_recv(fd);
1079 else
1080 fd_done_recv(fd);
1081 } else if (l->state > LI_ASSIGNED) {
Willy Tarreau4c044e22019-12-05 07:40:32 +01001082 fd_stop_recv(l->fd);
Willy Tarreau92079932019-12-10 09:30:05 +01001083 }
1084 HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
Willy Tarreau0591bf72019-12-10 12:01:21 +01001085 return;
1086
1087 transient_error:
1088 /* pause the listener for up to 100 ms */
1089 expire = tick_add(now_ms, 100);
1090
1091 limit_global:
1092 /* (re-)queue the listener to the global queue and set it to expire no
1093 * later than <expire> ahead. The listener turns to LI_LIMITED.
1094 */
1095 limit_listener(l, &global_listener_queue);
1096 task_schedule(global_listener_queue_task, expire);
1097 goto end;
1098
1099 limit_proxy:
1100 /* (re-)queue the listener to the proxy's queue and set it to expire no
1101 * later than <expire> ahead. The listener turns to LI_LIMITED.
1102 */
1103 limit_listener(l, &p->listener_queue);
Willy Tarreaueeea8082020-01-08 19:15:07 +01001104 if (p->task && tick_isset(expire))
1105 task_schedule(p->task, expire);
Willy Tarreau0591bf72019-12-10 12:01:21 +01001106 goto end;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +02001107}
1108
Willy Tarreau05f50472017-09-15 09:19:58 +02001109/* Notify the listener that a connection initiated from it was released. This
1110 * is used to keep the connection count consistent and to possibly re-open
1111 * listening when it was limited.
1112 */
1113void listener_release(struct listener *l)
1114{
1115 struct proxy *fe = l->bind_conf->frontend;
1116
1117 if (!(l->options & LI_O_UNLIMITED))
Olivier Houchard64213e92019-03-08 18:52:57 +01001118 _HA_ATOMIC_SUB(&actconn, 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001119 if (fe)
Olivier Houchard64213e92019-03-08 18:52:57 +01001120 _HA_ATOMIC_SUB(&fe->feconn, 1);
1121 _HA_ATOMIC_SUB(&l->nbconn, 1);
1122 _HA_ATOMIC_SUB(&l->thr_conn[tid], 1);
Willy Tarreau82c97892019-02-27 19:32:32 +01001123
1124 if (l->state == LI_FULL || l->state == LI_LIMITED)
Willy Tarreau05f50472017-09-15 09:19:58 +02001125 resume_listener(l);
1126
1127 /* Dequeues all of the listeners waiting for a resource */
Willy Tarreau241797a2019-12-10 14:10:52 +01001128 dequeue_all_listeners();
Willy Tarreau05f50472017-09-15 09:19:58 +02001129
Olivier Houchard859dc802019-08-08 15:47:21 +02001130 if (!MT_LIST_ISEMPTY(&fe->listener_queue) &&
Willy Tarreau05f50472017-09-15 09:19:58 +02001131 (!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 +01001132 dequeue_proxy_listeners(fe);
Willy Tarreau05f50472017-09-15 09:19:58 +02001133}
1134
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001135/* resume listeners waiting in the local listener queue. They are still in LI_LIMITED state */
1136static struct task *listener_queue_process(struct task *t, void *context, unsigned short state)
1137{
1138 struct work_list *wl = context;
1139 struct listener *l;
1140
Olivier Houchard859dc802019-08-08 15:47:21 +02001141 while ((l = MT_LIST_POP(&wl->head, struct listener *, wait_queue))) {
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001142 /* The listeners are still in the LI_LIMITED state */
1143 resume_listener(l);
1144 }
1145 return t;
1146}
1147
1148/* Initializes the listener queues. Returns 0 on success, otherwise ERR_* flags */
1149static int listener_queue_init()
1150{
1151 local_listener_queue = work_list_create(global.nbthread, listener_queue_process, NULL);
1152 if (!local_listener_queue) {
1153 ha_alert("Out of memory while initializing listener queues.\n");
1154 return ERR_FATAL|ERR_ABORT;
1155 }
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001156
1157 global_listener_queue_task = task_new(MAX_THREADS_MASK);
1158 if (!global_listener_queue_task) {
1159 ha_alert("Out of memory when initializing global listener queue\n");
1160 return ERR_FATAL|ERR_ABORT;
1161 }
1162 /* very simple initialization, users will queue the task if needed */
1163 global_listener_queue_task->context = NULL; /* not even a context! */
1164 global_listener_queue_task->process = manage_global_listener_queue;
1165
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001166 return 0;
1167}
1168
1169static void listener_queue_deinit()
1170{
1171 work_list_destroy(local_listener_queue, global.nbthread);
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001172 task_destroy(global_listener_queue_task);
1173 global_listener_queue_task = NULL;
Willy Tarreauf2cb1692019-07-11 10:08:31 +02001174}
1175
1176REGISTER_CONFIG_POSTPARSER("multi-threaded listener queue", listener_queue_init);
1177REGISTER_POST_DEINIT(listener_queue_deinit);
1178
Willy Tarreaua1d97f82019-12-10 11:18:41 +01001179
1180/* This is the global management task for listeners. It enables listeners waiting
1181 * for global resources when there are enough free resource, or at least once in
1182 * a while. It is designed to be called as a task.
1183 */
1184static struct task *manage_global_listener_queue(struct task *t, void *context, unsigned short state)
1185{
1186 /* If there are still too many concurrent connections, let's wait for
1187 * some of them to go away. We don't need to re-arm the timer because
1188 * each of them will scan the queue anyway.
1189 */
1190 if (unlikely(actconn >= global.maxconn))
1191 goto out;
1192
1193 /* We should periodically try to enable listeners waiting for a global
1194 * resource here, because it is possible, though very unlikely, that
1195 * they have been blocked by a temporary lack of global resource such
1196 * as a file descriptor or memory and that the temporary condition has
1197 * disappeared.
1198 */
1199 dequeue_all_listeners();
1200
1201 out:
1202 t->expire = TICK_ETERNITY;
1203 task_queue(t);
1204 return t;
1205}
1206
Willy Tarreau26982662012-09-12 23:17:10 +02001207/*
1208 * Registers the bind keyword list <kwl> as a list of valid keywords for next
1209 * parsing sessions.
1210 */
1211void bind_register_keywords(struct bind_kw_list *kwl)
1212{
1213 LIST_ADDQ(&bind_keywords.list, &kwl->list);
1214}
1215
1216/* Return a pointer to the bind keyword <kw>, or NULL if not found. If the
1217 * keyword is found with a NULL ->parse() function, then an attempt is made to
1218 * find one with a valid ->parse() function. This way it is possible to declare
1219 * platform-dependant, known keywords as NULL, then only declare them as valid
1220 * if some options are met. Note that if the requested keyword contains an
1221 * opening parenthesis, everything from this point is ignored.
1222 */
1223struct bind_kw *bind_find_kw(const char *kw)
1224{
1225 int index;
1226 const char *kwend;
1227 struct bind_kw_list *kwl;
1228 struct bind_kw *ret = NULL;
1229
1230 kwend = strchr(kw, '(');
1231 if (!kwend)
1232 kwend = kw + strlen(kw);
1233
1234 list_for_each_entry(kwl, &bind_keywords.list, list) {
1235 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1236 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
1237 kwl->kw[index].kw[kwend-kw] == 0) {
1238 if (kwl->kw[index].parse)
1239 return &kwl->kw[index]; /* found it !*/
1240 else
1241 ret = &kwl->kw[index]; /* may be OK */
1242 }
1243 }
1244 }
1245 return ret;
1246}
1247
Willy Tarreau8638f482012-09-18 18:01:17 +02001248/* Dumps all registered "bind" keywords to the <out> string pointer. The
1249 * unsupported keywords are only dumped if their supported form was not
1250 * found.
1251 */
1252void bind_dump_kws(char **out)
1253{
1254 struct bind_kw_list *kwl;
1255 int index;
1256
Christopher Faulet784063e2020-05-18 12:14:18 +02001257 if (!out)
1258 return;
1259
Willy Tarreau8638f482012-09-18 18:01:17 +02001260 *out = NULL;
1261 list_for_each_entry(kwl, &bind_keywords.list, list) {
1262 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1263 if (kwl->kw[index].parse ||
1264 bind_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) {
Willy Tarreau51fb7652012-09-18 18:24:39 +02001265 memprintf(out, "%s[%4s] %s%s%s\n", *out ? *out : "",
1266 kwl->scope,
Willy Tarreau8638f482012-09-18 18:01:17 +02001267 kwl->kw[index].kw,
Willy Tarreau51fb7652012-09-18 18:24:39 +02001268 kwl->kw[index].skip ? " <arg>" : "",
1269 kwl->kw[index].parse ? "" : " (not supported)");
Willy Tarreau8638f482012-09-18 18:01:17 +02001270 }
1271 }
1272 }
1273}
1274
Willy Tarreau645513a2010-05-24 20:55:15 +02001275/************************************************************************/
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001276/* All supported sample and ACL keywords must be declared here. */
Willy Tarreau645513a2010-05-24 20:55:15 +02001277/************************************************************************/
1278
Willy Tarreaua5e37562011-12-16 17:06:15 +01001279/* set temp integer to the number of connexions to the same listening socket */
Willy Tarreau645513a2010-05-24 20:55:15 +02001280static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001281smp_fetch_dconn(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau645513a2010-05-24 20:55:15 +02001282{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001283 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001284 smp->data.u.sint = smp->sess->listener->nbconn;
Willy Tarreau645513a2010-05-24 20:55:15 +02001285 return 1;
1286}
1287
Willy Tarreaua5e37562011-12-16 17:06:15 +01001288/* set temp integer to the id of the socket (listener) */
Willy Tarreau645513a2010-05-24 20:55:15 +02001289static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001290smp_fetch_so_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau37406352012-04-23 16:16:37 +02001291{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02001292 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02001293 smp->data.u.sint = smp->sess->listener->luid;
Willy Tarreau645513a2010-05-24 20:55:15 +02001294 return 1;
1295}
Jerome Magnineb421b22020-03-27 22:08:40 +01001296static int
1297smp_fetch_so_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
1298{
1299 smp->data.u.str.area = smp->sess->listener->name;
1300 if (!smp->data.u.str.area)
1301 return 0;
1302
1303 smp->data.type = SMP_T_STR;
1304 smp->flags = SMP_F_CONST;
1305 smp->data.u.str.data = strlen(smp->data.u.str.area);
1306 return 1;
1307}
Willy Tarreau645513a2010-05-24 20:55:15 +02001308
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001309/* parse the "accept-proxy" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001310static 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 +02001311{
1312 struct listener *l;
1313
Willy Tarreau4348fad2012-09-20 16:48:07 +02001314 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001315 l->options |= LI_O_ACC_PROXY;
1316
1317 return 0;
1318}
1319
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001320/* parse the "accept-netscaler-cip" bind keyword */
1321static int bind_parse_accept_netscaler_cip(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1322{
1323 struct listener *l;
1324 uint32_t val;
1325
1326 if (!*args[cur_arg + 1]) {
1327 memprintf(err, "'%s' : missing value", args[cur_arg]);
1328 return ERR_ALERT | ERR_FATAL;
1329 }
1330
1331 val = atol(args[cur_arg + 1]);
1332 if (val <= 0) {
Willy Tarreaue2711c72019-02-27 15:39:41 +01001333 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001334 return ERR_ALERT | ERR_FATAL;
1335 }
1336
1337 list_for_each_entry(l, &conf->listeners, by_bind) {
1338 l->options |= LI_O_ACC_CIP;
1339 conf->ns_cip_magic = val;
1340 }
1341
1342 return 0;
1343}
1344
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001345/* parse the "backlog" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001346static 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 +02001347{
1348 struct listener *l;
1349 int val;
1350
1351 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001352 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001353 return ERR_ALERT | ERR_FATAL;
1354 }
1355
1356 val = atol(args[cur_arg + 1]);
Willy Tarreaue2711c72019-02-27 15:39:41 +01001357 if (val < 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001358 memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001359 return ERR_ALERT | ERR_FATAL;
1360 }
1361
Willy Tarreau4348fad2012-09-20 16:48:07 +02001362 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001363 l->backlog = val;
1364
1365 return 0;
1366}
1367
1368/* parse the "id" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001369static 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 +02001370{
1371 struct eb32_node *node;
Willy Tarreau4348fad2012-09-20 16:48:07 +02001372 struct listener *l, *new;
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001373 char *error;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001374
Willy Tarreau4348fad2012-09-20 16:48:07 +02001375 if (conf->listeners.n != conf->listeners.p) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001376 memprintf(err, "'%s' can only be used with a single socket", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001377 return ERR_ALERT | ERR_FATAL;
1378 }
1379
1380 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001381 memprintf(err, "'%s' : expects an integer argument", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001382 return ERR_ALERT | ERR_FATAL;
1383 }
1384
Willy Tarreau4348fad2012-09-20 16:48:07 +02001385 new = LIST_NEXT(&conf->listeners, struct listener *, by_bind);
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +01001386 new->luid = strtol(args[cur_arg + 1], &error, 10);
1387 if (*error != '\0') {
1388 memprintf(err, "'%s' : expects an integer argument, found '%s'", args[cur_arg], args[cur_arg + 1]);
1389 return ERR_ALERT | ERR_FATAL;
1390 }
Willy Tarreau4348fad2012-09-20 16:48:07 +02001391 new->conf.id.key = new->luid;
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001392
Willy Tarreau4348fad2012-09-20 16:48:07 +02001393 if (new->luid <= 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001394 memprintf(err, "'%s' : custom id has to be > 0", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001395 return ERR_ALERT | ERR_FATAL;
1396 }
1397
Willy Tarreau4348fad2012-09-20 16:48:07 +02001398 node = eb32_lookup(&px->conf.used_listener_id, new->luid);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001399 if (node) {
1400 l = container_of(node, struct listener, conf.id);
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001401 memprintf(err, "'%s' : custom id %d already used at %s:%d ('bind %s')",
1402 args[cur_arg], l->luid, l->bind_conf->file, l->bind_conf->line,
1403 l->bind_conf->arg);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001404 return ERR_ALERT | ERR_FATAL;
1405 }
1406
Willy Tarreau4348fad2012-09-20 16:48:07 +02001407 eb32_insert(&px->conf.used_listener_id, &new->conf.id);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001408 return 0;
1409}
1410
1411/* parse the "maxconn" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001412static 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 +02001413{
1414 struct listener *l;
1415 int val;
1416
1417 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001418 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001419 return ERR_ALERT | ERR_FATAL;
1420 }
1421
1422 val = atol(args[cur_arg + 1]);
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001423 if (val < 0) {
1424 memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001425 return ERR_ALERT | ERR_FATAL;
1426 }
1427
Willy Tarreau4348fad2012-09-20 16:48:07 +02001428 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001429 l->maxconn = val;
1430
1431 return 0;
1432}
1433
1434/* parse the "name" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001435static 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 +02001436{
1437 struct listener *l;
1438
1439 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001440 memprintf(err, "'%s' : missing name", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001441 return ERR_ALERT | ERR_FATAL;
1442 }
1443
Willy Tarreau4348fad2012-09-20 16:48:07 +02001444 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001445 l->name = strdup(args[cur_arg + 1]);
1446
1447 return 0;
1448}
1449
1450/* parse the "nice" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +02001451static 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 +02001452{
1453 struct listener *l;
1454 int val;
1455
1456 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001457 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001458 return ERR_ALERT | ERR_FATAL;
1459 }
1460
1461 val = atol(args[cur_arg + 1]);
1462 if (val < -1024 || val > 1024) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +02001463 memprintf(err, "'%s' : invalid value %d, allowed range is -1024..1024", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001464 return ERR_ALERT | ERR_FATAL;
1465 }
1466
Willy Tarreau4348fad2012-09-20 16:48:07 +02001467 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001468 l->nice = val;
1469
1470 return 0;
1471}
1472
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001473/* parse the "process" bind keyword */
1474static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1475{
Christopher Fauletc644fa92017-11-23 22:44:11 +01001476 char *slash;
1477 unsigned long proc = 0, thread = 0;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001478
Christopher Fauletc644fa92017-11-23 22:44:11 +01001479 if ((slash = strchr(args[cur_arg + 1], '/')) != NULL)
1480 *slash = 0;
1481
Willy Tarreauff9c9142019-02-07 10:39:36 +01001482 if (parse_process_number(args[cur_arg + 1], &proc, MAX_PROCS, NULL, err)) {
Christopher Fauletf1f0c5f2017-11-22 12:06:43 +01001483 memprintf(err, "'%s' : %s", args[cur_arg], *err);
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001484 return ERR_ALERT | ERR_FATAL;
1485 }
1486
Christopher Fauletc644fa92017-11-23 22:44:11 +01001487 if (slash) {
Willy Tarreauc9a82e42019-01-26 13:25:14 +01001488 if (parse_process_number(slash+1, &thread, MAX_THREADS, NULL, err)) {
Christopher Fauletc644fa92017-11-23 22:44:11 +01001489 memprintf(err, "'%s' : %s", args[cur_arg], *err);
1490 return ERR_ALERT | ERR_FATAL;
1491 }
1492 *slash = '/';
1493 }
1494
1495 conf->bind_proc |= proc;
Willy Tarreaua36b3242019-02-02 13:14:34 +01001496 conf->bind_thread |= thread;
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001497 return 0;
1498}
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001499
Christopher Fauleta717b992018-04-10 14:43:00 +02001500/* parse the "proto" bind keyword */
1501static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1502{
1503 struct ist proto;
1504
1505 if (!*args[cur_arg + 1]) {
1506 memprintf(err, "'%s' : missing value", args[cur_arg]);
1507 return ERR_ALERT | ERR_FATAL;
1508 }
1509
1510 proto = ist2(args[cur_arg + 1], strlen(args[cur_arg + 1]));
1511 conf->mux_proto = get_mux_proto(proto);
1512 if (!conf->mux_proto) {
1513 memprintf(err, "'%s' : unknown MUX protocol '%s'", args[cur_arg], args[cur_arg+1]);
1514 return ERR_ALERT | ERR_FATAL;
1515 }
Christopher Fauleta717b992018-04-10 14:43:00 +02001516 return 0;
1517}
1518
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001519/* config parser for global "tune.listener.multi-queue", accepts "on" or "off" */
1520static int cfg_parse_tune_listener_mq(char **args, int section_type, struct proxy *curpx,
1521 struct proxy *defpx, const char *file, int line,
1522 char **err)
1523{
1524 if (too_many_args(1, args, err, NULL))
1525 return -1;
1526
1527 if (strcmp(args[1], "on") == 0)
1528 global.tune.options |= GTUNE_LISTENER_MQ;
1529 else if (strcmp(args[1], "off") == 0)
1530 global.tune.options &= ~GTUNE_LISTENER_MQ;
1531 else {
1532 memprintf(err, "'%s' expects either 'on' or 'off' but got '%s'.", args[0], args[1]);
1533 return -1;
1534 }
1535 return 0;
1536}
1537
Willy Tarreau61612d42012-04-19 18:42:05 +02001538/* Note: must not be declared <const> as its list will be overwritten.
1539 * Please take care of keeping this list alphabetically sorted.
1540 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001541static struct sample_fetch_kw_list smp_kws = {ILH, {
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02001542 { "dst_conn", smp_fetch_dconn, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
1543 { "so_id", smp_fetch_so_id, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
Jerome Magnineb421b22020-03-27 22:08:40 +01001544 { "so_name", smp_fetch_so_name, 0, NULL, SMP_T_STR, SMP_USE_FTEND, },
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001545 { /* END */ },
1546}};
1547
Willy Tarreau0108d902018-11-25 19:14:37 +01001548INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
1549
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001550/* Note: must not be declared <const> as its list will be overwritten.
1551 * Please take care of keeping this list alphabetically sorted.
1552 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001553static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001554 { /* END */ },
Willy Tarreau645513a2010-05-24 20:55:15 +02001555}};
1556
Willy Tarreau0108d902018-11-25 19:14:37 +01001557INITCALL1(STG_REGISTER, acl_register_keywords, &acl_kws);
1558
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001559/* Note: must not be declared <const> as its list will be overwritten.
1560 * Please take care of keeping this list alphabetically sorted, doing so helps
1561 * all code contributors.
1562 * Optional keywords are also declared with a NULL ->parse() function so that
1563 * the config parser can report an appropriate error when a known keyword was
1564 * not enabled.
1565 */
Willy Tarreau51fb7652012-09-18 18:24:39 +02001566static struct bind_kw_list bind_kws = { "ALL", { }, {
Bertrand Jacquin93b227d2016-06-04 15:11:10 +01001567 { "accept-netscaler-cip", bind_parse_accept_netscaler_cip, 1 }, /* enable NetScaler Client IP insertion protocol */
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001568 { "accept-proxy", bind_parse_accept_proxy, 0 }, /* enable PROXY protocol */
1569 { "backlog", bind_parse_backlog, 1 }, /* set backlog of listening socket */
1570 { "id", bind_parse_id, 1 }, /* set id of listening socket */
1571 { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */
1572 { "name", bind_parse_name, 1 }, /* set name of listening socket */
1573 { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02001574 { "process", bind_parse_process, 1 }, /* set list of allowed process for this socket */
Christopher Fauleta717b992018-04-10 14:43:00 +02001575 { "proto", bind_parse_proto, 1 }, /* set the proto to use for all incoming connections */
Willy Tarreau0ccb7442013-01-07 22:54:17 +01001576 { /* END */ },
Willy Tarreau3dcc3412012-09-18 17:17:28 +02001577}};
1578
Willy Tarreau0108d902018-11-25 19:14:37 +01001579INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
1580
Willy Tarreau7ac908b2019-02-27 12:02:18 +01001581/* config keyword parsers */
1582static struct cfg_kw_list cfg_kws = {ILH, {
1583 { CFG_GLOBAL, "tune.listener.multi-queue", cfg_parse_tune_listener_mq },
1584 { 0, NULL, NULL }
1585}};
1586
1587INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
1588
Willy Tarreau645513a2010-05-24 20:55:15 +02001589/*
1590 * Local variables:
1591 * c-indent-level: 8
1592 * c-basic-offset: 8
1593 * End:
1594 */