blob: a7e2b0d06619de530138324c6676017fc6c335ad [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 Tarreau1bc4aab2012-10-08 20:11:03 +020021#include <common/accept4.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020022#include <common/config.h>
Willy Tarreaudabf2e22007-10-28 21:59:24 +010023#include <common/errors.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020024#include <common/mini-clist.h>
25#include <common/standard.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020026#include <common/time.h>
27
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>
Willy Tarreaub648d632007-10-28 22:13:50 +010032#include <proto/fd.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020033#include <proto/freq_ctr.h>
34#include <proto/log.h>
Willy Tarreau7a798e52016-04-14 11:13:20 +020035#include <proto/listener.h>
Willy Tarreau0de59fd2017-09-15 08:10:44 +020036#include <proto/protocol.h>
Willy Tarreau0ccb7442013-01-07 22:54:17 +010037#include <proto/sample.h>
Willy Tarreaufb0afa72015-04-03 14:46:27 +020038#include <proto/stream.h>
Willy Tarreaubbebbbf2012-05-07 21:22:09 +020039#include <proto/task.h>
Willy Tarreaub648d632007-10-28 22:13:50 +010040
Willy Tarreau26982662012-09-12 23:17:10 +020041/* List head of all known bind keywords */
42static struct bind_kw_list bind_keywords = {
43 .list = LIST_HEAD_INIT(bind_keywords.list)
44};
45
Olivier Houchardf73629d2017-04-05 22:33:04 +020046struct xfer_sock_list *xfer_sock_list = NULL;
47
Willy Tarreaudabf2e22007-10-28 21:59:24 +010048/* This function adds the specified listener's file descriptor to the polling
49 * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
Willy Tarreauae302532014-05-07 19:22:24 +020050 * LI_FULL state depending on its number of connections. In deamon mode, we
51 * also support binding only the relevant processes to their respective
52 * listeners. We don't do that in debug mode however.
Willy Tarreaudabf2e22007-10-28 21:59:24 +010053 */
Christopher Fauletf5b8adc2017-06-02 10:00:35 +020054static void enable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +010055{
56 if (listener->state == LI_LISTEN) {
William Lallemand095ba4c2017-06-01 17:38:50 +020057 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreauae302532014-05-07 19:22:24 +020058 listener->bind_conf->bind_proc &&
59 !(listener->bind_conf->bind_proc & (1UL << (relative_pid - 1)))) {
60 /* we don't want to enable this listener and don't
61 * want any fd event to reach it.
62 */
Olivier Houchard1fc05162017-04-06 01:05:05 +020063 if (!(global.tune.options & GTUNE_SOCKET_TRANSFER))
64 unbind_listener(listener);
65 else {
66 unbind_listener_no_close(listener);
67 listener->state = LI_LISTEN;
68 }
Willy Tarreauae302532014-05-07 19:22:24 +020069 }
70 else if (listener->nbconn < listener->maxconn) {
Willy Tarreau49b046d2012-08-09 12:11:58 +020071 fd_want_recv(listener->fd);
Willy Tarreaudabf2e22007-10-28 21:59:24 +010072 listener->state = LI_READY;
Willy Tarreauae302532014-05-07 19:22:24 +020073 }
74 else {
Willy Tarreaudabf2e22007-10-28 21:59:24 +010075 listener->state = LI_FULL;
76 }
77 }
78}
79
80/* This function removes the specified listener's file descriptor from the
81 * polling lists if it is in the LI_READY or in the LI_FULL state. The listener
82 * enters LI_LISTEN.
83 */
Christopher Fauletf5b8adc2017-06-02 10:00:35 +020084static void disable_listener(struct listener *listener)
Willy Tarreaudabf2e22007-10-28 21:59:24 +010085{
86 if (listener->state < LI_READY)
87 return;
88 if (listener->state == LI_READY)
Willy Tarreau49b046d2012-08-09 12:11:58 +020089 fd_stop_recv(listener->fd);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +020090 if (listener->state == LI_LIMITED)
91 LIST_DEL(&listener->wait_queue);
Willy Tarreaudabf2e22007-10-28 21:59:24 +010092 listener->state = LI_LISTEN;
93}
94
Willy Tarreaube58c382011-07-24 18:28:10 +020095/* This function tries to temporarily disable a listener, depending on the OS
96 * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
97 * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
98 * closes upon SHUT_WR and refuses to rebind. So a common validation path
99 * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling
100 * is disabled. It normally returns non-zero, unless an error is reported.
101 */
102int pause_listener(struct listener *l)
103{
Olivier Houchard1fc05162017-04-06 01:05:05 +0200104 if (l->state <= LI_ZOMBIE)
Willy Tarreaube58c382011-07-24 18:28:10 +0200105 return 1;
106
Willy Tarreau092d8652014-07-07 20:22:12 +0200107 if (l->proto->pause) {
108 /* Returns < 0 in case of failure, 0 if the listener
109 * was totally stopped, or > 0 if correctly paused.
110 */
111 int ret = l->proto->pause(l);
Willy Tarreaube58c382011-07-24 18:28:10 +0200112
Willy Tarreau092d8652014-07-07 20:22:12 +0200113 if (ret < 0)
114 return 0;
115 else if (ret == 0)
116 return 1;
Willy Tarreaub3fb60b2012-10-04 08:56:31 +0200117 }
Willy Tarreaube58c382011-07-24 18:28:10 +0200118
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200119 if (l->state == LI_LIMITED)
120 LIST_DEL(&l->wait_queue);
121
Willy Tarreau49b046d2012-08-09 12:11:58 +0200122 fd_stop_recv(l->fd);
Willy Tarreaube58c382011-07-24 18:28:10 +0200123 l->state = LI_PAUSED;
124 return 1;
125}
126
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200127/* This function tries to resume a temporarily disabled listener. Paused, full,
128 * limited and disabled listeners are handled, which means that this function
129 * may replace enable_listener(). The resulting state will either be LI_READY
130 * or LI_FULL. 0 is returned in case of failure to resume (eg: dead socket).
Willy Tarreauae302532014-05-07 19:22:24 +0200131 * Listeners bound to a different process are not woken up unless we're in
Willy Tarreauaf2fd582015-04-14 12:07:16 +0200132 * foreground mode, and are ignored. If the listener was only in the assigned
133 * state, it's totally rebound. This can happen if a pause() has completely
134 * stopped it. If the resume fails, 0 is returned and an error might be
135 * displayed.
Willy Tarreaube58c382011-07-24 18:28:10 +0200136 */
137int resume_listener(struct listener *l)
138{
William Lallemand095ba4c2017-06-01 17:38:50 +0200139 if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
Willy Tarreau3569df32017-03-15 12:47:46 +0100140 l->bind_conf->bind_proc &&
141 !(l->bind_conf->bind_proc & (1UL << (relative_pid - 1))))
142 return 1;
143
Willy Tarreau1c4b8142014-07-07 21:06:24 +0200144 if (l->state == LI_ASSIGNED) {
145 char msg[100];
146 int err;
147
148 err = l->proto->bind(l, msg, sizeof(msg));
149 if (err & ERR_ALERT)
150 Alert("Resuming listener: %s\n", msg);
151 else if (err & ERR_WARN)
152 Warning("Resuming listener: %s\n", msg);
153
154 if (err & (ERR_FATAL | ERR_ABORT))
155 return 0;
156 }
157
Olivier Houchard1fc05162017-04-06 01:05:05 +0200158 if (l->state < LI_PAUSED || l->state == LI_ZOMBIE)
Willy Tarreaube58c382011-07-24 18:28:10 +0200159 return 0;
160
Willy Tarreaub3fb60b2012-10-04 08:56:31 +0200161 if (l->proto->sock_prot == IPPROTO_TCP &&
162 l->state == LI_PAUSED &&
Willy Tarreaube58c382011-07-24 18:28:10 +0200163 listen(l->fd, l->backlog ? l->backlog : l->maxconn) != 0)
164 return 0;
165
166 if (l->state == LI_READY)
167 return 1;
168
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200169 if (l->state == LI_LIMITED)
170 LIST_DEL(&l->wait_queue);
171
Willy Tarreaube58c382011-07-24 18:28:10 +0200172 if (l->nbconn >= l->maxconn) {
173 l->state = LI_FULL;
174 return 1;
175 }
176
Willy Tarreau49b046d2012-08-09 12:11:58 +0200177 fd_want_recv(l->fd);
Willy Tarreaube58c382011-07-24 18:28:10 +0200178 l->state = LI_READY;
179 return 1;
180}
181
Willy Tarreau87b09662015-04-03 00:22:06 +0200182/* Marks a ready listener as full so that the stream code tries to re-enable
Willy Tarreau62793712011-07-24 19:23:38 +0200183 * it upon next close() using resume_listener().
184 */
Christopher Faulet5580ba22017-08-28 15:29:20 +0200185static void listener_full(struct listener *l)
Willy Tarreau62793712011-07-24 19:23:38 +0200186{
187 if (l->state >= LI_READY) {
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200188 if (l->state == LI_LIMITED)
189 LIST_DEL(&l->wait_queue);
190
Willy Tarreau49b046d2012-08-09 12:11:58 +0200191 fd_stop_recv(l->fd);
Willy Tarreau62793712011-07-24 19:23:38 +0200192 l->state = LI_FULL;
193 }
194}
195
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200196/* Marks a ready listener as limited so that we only try to re-enable it when
197 * resources are free again. It will be queued into the specified queue.
198 */
Christopher Faulet5580ba22017-08-28 15:29:20 +0200199static void limit_listener(struct listener *l, struct list *list)
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200200{
201 if (l->state == LI_READY) {
202 LIST_ADDQ(list, &l->wait_queue);
Willy Tarreau49b046d2012-08-09 12:11:58 +0200203 fd_stop_recv(l->fd);
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200204 l->state = LI_LIMITED;
205 }
206}
207
Willy Tarreaudabf2e22007-10-28 21:59:24 +0100208/* This function adds all of the protocol's listener's file descriptors to the
209 * polling lists when they are in the LI_LISTEN state. It is intended to be
210 * used as a protocol's generic enable_all() primitive, for use after the
211 * fork(). It puts the listeners into LI_READY or LI_FULL states depending on
212 * their number of connections. It always returns ERR_NONE.
213 */
214int enable_all_listeners(struct protocol *proto)
215{
216 struct listener *listener;
217
218 list_for_each_entry(listener, &proto->listeners, proto_list)
219 enable_listener(listener);
220 return ERR_NONE;
221}
222
223/* This function removes all of the protocol's listener's file descriptors from
224 * the polling lists when they are in the LI_READY or LI_FULL states. It is
225 * intended to be used as a protocol's generic disable_all() primitive. It puts
226 * the listeners into LI_LISTEN, and always returns ERR_NONE.
227 */
228int disable_all_listeners(struct protocol *proto)
229{
230 struct listener *listener;
231
232 list_for_each_entry(listener, &proto->listeners, proto_list)
233 disable_listener(listener);
234 return ERR_NONE;
235}
236
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200237/* Dequeues all of the listeners waiting for a resource in wait queue <queue>. */
238void dequeue_all_listeners(struct list *list)
239{
240 struct listener *listener, *l_back;
241
242 list_for_each_entry_safe(listener, l_back, list, wait_queue) {
243 /* This cannot fail because the listeners are by definition in
244 * the LI_LIMITED state. The function also removes the entry
245 * from the queue.
246 */
247 resume_listener(listener);
248 }
249}
250
Olivier Houchard1fc05162017-04-06 01:05:05 +0200251static int do_unbind_listener(struct listener *listener, int do_close)
Willy Tarreaub648d632007-10-28 22:13:50 +0100252{
253 if (listener->state == LI_READY)
Willy Tarreau49b046d2012-08-09 12:11:58 +0200254 fd_stop_recv(listener->fd);
Willy Tarreaub648d632007-10-28 22:13:50 +0100255
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +0200256 if (listener->state == LI_LIMITED)
257 LIST_DEL(&listener->wait_queue);
258
Willy Tarreaube58c382011-07-24 18:28:10 +0200259 if (listener->state >= LI_PAUSED) {
Olivier Houchard1fc05162017-04-06 01:05:05 +0200260 if (do_close) {
261 fd_delete(listener->fd);
262 listener->fd = -1;
263 }
264 else
265 fd_remove(listener->fd);
Willy Tarreaub648d632007-10-28 22:13:50 +0100266 listener->state = LI_ASSIGNED;
267 }
268 return ERR_NONE;
269}
270
Olivier Houchard1fc05162017-04-06 01:05:05 +0200271/* This function closes the listening socket for the specified listener,
272 * provided that it's already in a listening state. The listener enters the
273 * LI_ASSIGNED state. It always returns ERR_NONE. This function is intended
274 * to be used as a generic function for standard protocols.
275 */
276int unbind_listener(struct listener *listener)
277{
278 return do_unbind_listener(listener, 1);
279}
280
281/* This function pretends the listener is dead, but keeps the FD opened, so
282 * that we can provide it, for conf reloading.
283 */
284int unbind_listener_no_close(struct listener *listener)
285{
286 return do_unbind_listener(listener, 0);
287}
288
Willy Tarreau3acf8c32007-10-28 22:35:41 +0100289/* This function closes all listening sockets bound to the protocol <proto>,
290 * and the listeners end in LI_ASSIGNED state if they were higher. It does not
291 * detach them from the protocol. It always returns ERR_NONE.
292 */
293int unbind_all_listeners(struct protocol *proto)
294{
295 struct listener *listener;
296
297 list_for_each_entry(listener, &proto->listeners, proto_list)
298 unbind_listener(listener);
299 return ERR_NONE;
300}
301
Willy Tarreau0de59fd2017-09-15 08:10:44 +0200302/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
303 * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
304 * allocation). The address family is taken from ss->ss_family. The number of
305 * jobs and listeners is automatically increased by the number of listeners
306 * created. It returns non-zero on success, zero on error with the error message
307 * set in <err>.
308 */
309int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
310 int portl, int porth, int fd, char **err)
311{
312 struct protocol *proto = protocol_by_family(ss->ss_family);
313 struct listener *l;
314 int port;
315
316 if (!proto) {
317 memprintf(err, "unsupported protocol family %d", ss->ss_family);
318 return 0;
319 }
320
321 for (port = portl; port <= porth; port++) {
322 l = calloc(1, sizeof(*l));
323 if (!l) {
324 memprintf(err, "out of memory");
325 return 0;
326 }
327 l->obj_type = OBJ_TYPE_LISTENER;
328 LIST_ADDQ(&bc->frontend->conf.listeners, &l->by_fe);
329 LIST_ADDQ(&bc->listeners, &l->by_bind);
330 l->bind_conf = bc;
331
332 l->fd = fd;
333 memcpy(&l->addr, ss, sizeof(*ss));
334 l->state = LI_INIT;
335
336 proto->add(l, port);
337
338 jobs++;
339 listeners++;
340 }
341 return 1;
342}
343
Willy Tarreau1a64d162007-10-28 22:26:05 +0100344/* Delete a listener from its protocol's list of listeners. The listener's
345 * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
Willy Tarreau2cc5bae2017-09-15 08:18:11 +0200346 * number of listeners is updated, as well as the global number of listeners
347 * and jobs. Note that the listener must have previously been unbound. This
348 * is the generic function to use to remove a listener.
Willy Tarreau1a64d162007-10-28 22:26:05 +0100349 */
350void delete_listener(struct listener *listener)
351{
352 if (listener->state != LI_ASSIGNED)
353 return;
354 listener->state = LI_INIT;
355 LIST_DEL(&listener->proto_list);
356 listener->proto->nb_listeners--;
Willy Tarreau2cc5bae2017-09-15 08:18:11 +0200357 listeners--;
358 jobs--;
Willy Tarreau1a64d162007-10-28 22:26:05 +0100359}
360
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200361/* This function is called on a read event from a listening socket, corresponding
362 * to an accept. It tries to accept as many connections as possible, and for each
363 * calls the listener's accept handler (generally the frontend's accept handler).
364 */
Willy Tarreauafad0e02012-08-09 14:45:22 +0200365void listener_accept(int fd)
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200366{
367 struct listener *l = fdtab[fd].owner;
Willy Tarreauc95bad52016-12-22 00:13:31 +0100368 struct proxy *p = l->bind_conf->frontend;
Willy Tarreau50de90a2012-11-23 20:11:45 +0100369 int max_accept = l->maxaccept ? l->maxaccept : 1;
Willy Tarreaubb660302014-05-07 19:47:02 +0200370 int expire;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200371 int cfd;
372 int ret;
Willy Tarreau818dca52014-01-31 19:40:19 +0100373#ifdef USE_ACCEPT4
374 static int accept4_broken;
375#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200376
377 if (unlikely(l->nbconn >= l->maxconn)) {
378 listener_full(l);
Willy Tarreauafad0e02012-08-09 14:45:22 +0200379 return;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200380 }
381
Willy Tarreau93e7c002013-10-07 18:51:07 +0200382 if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
383 int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
Willy Tarreau93e7c002013-10-07 18:51:07 +0200384
385 if (unlikely(!max)) {
386 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200387 expire = tick_add(now_ms, next_event_delay(&global.sess_per_sec, global.sps_lim, 0));
Willy Tarreaubb660302014-05-07 19:47:02 +0200388 goto wait_expire;
Willy Tarreau93e7c002013-10-07 18:51:07 +0200389 }
390
391 if (max_accept > max)
392 max_accept = max;
393 }
394
395 if (!(l->options & LI_O_UNLIMITED) && global.cps_lim) {
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200396 int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
397
398 if (unlikely(!max)) {
399 /* frontend accept rate limit was reached */
Willy Tarreau93e7c002013-10-07 18:51:07 +0200400 expire = tick_add(now_ms, next_event_delay(&global.conn_per_sec, global.cps_lim, 0));
Willy Tarreaubb660302014-05-07 19:47:02 +0200401 goto wait_expire;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200402 }
403
404 if (max_accept > max)
405 max_accept = max;
406 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200407#ifdef USE_OPENSSL
408 if (!(l->options & LI_O_UNLIMITED) && global.ssl_lim && l->bind_conf && l->bind_conf->is_ssl) {
409 int max = freq_ctr_remain(&global.ssl_per_sec, global.ssl_lim, 0);
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200410
Willy Tarreaue43d5322013-10-07 20:01:52 +0200411 if (unlikely(!max)) {
412 /* frontend accept rate limit was reached */
Willy Tarreaue43d5322013-10-07 20:01:52 +0200413 expire = tick_add(now_ms, next_event_delay(&global.ssl_per_sec, global.ssl_lim, 0));
Willy Tarreaubb660302014-05-07 19:47:02 +0200414 goto wait_expire;
Willy Tarreaue43d5322013-10-07 20:01:52 +0200415 }
416
417 if (max_accept > max)
418 max_accept = max;
419 }
420#endif
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200421 if (p && p->fe_sps_lim) {
422 int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0);
423
424 if (unlikely(!max)) {
425 /* frontend accept rate limit was reached */
426 limit_listener(l, &p->listener_queue);
427 task_schedule(p->task, tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0)));
Willy Tarreauafad0e02012-08-09 14:45:22 +0200428 return;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200429 }
430
431 if (max_accept > max)
432 max_accept = max;
433 }
434
435 /* Note: if we fail to allocate a connection because of configured
436 * limits, we'll schedule a new attempt worst 1 second later in the
437 * worst case. If we fail due to system limits or temporary resource
438 * shortage, we try again 100ms later in the worst case.
439 */
440 while (max_accept--) {
441 struct sockaddr_storage addr;
442 socklen_t laddr = sizeof(addr);
443
444 if (unlikely(actconn >= global.maxconn) && !(l->options & LI_O_UNLIMITED)) {
445 limit_listener(l, &global_listener_queue);
446 task_schedule(global_listener_queue_task, tick_add(now_ms, 1000)); /* try again in 1 second */
Willy Tarreauafad0e02012-08-09 14:45:22 +0200447 return;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200448 }
449
450 if (unlikely(p && p->feconn >= p->maxconn)) {
451 limit_listener(l, &p->listener_queue);
Willy Tarreauafad0e02012-08-09 14:45:22 +0200452 return;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200453 }
454
Willy Tarreau1bc4aab2012-10-08 20:11:03 +0200455#ifdef USE_ACCEPT4
Willy Tarreau818dca52014-01-31 19:40:19 +0100456 /* only call accept4() if it's known to be safe, otherwise
457 * fallback to the legacy accept() + fcntl().
458 */
459 if (unlikely(accept4_broken ||
460 ((cfd = accept4(fd, (struct sockaddr *)&addr, &laddr, SOCK_NONBLOCK)) == -1 &&
461 (errno == ENOSYS || errno == EINVAL || errno == EBADF) &&
462 (accept4_broken = 1))))
463#endif
Willy Tarreau6b3b0d42012-10-22 19:32:55 +0200464 if ((cfd = accept(fd, (struct sockaddr *)&addr, &laddr)) != -1)
465 fcntl(cfd, F_SETFL, O_NONBLOCK);
Willy Tarreau818dca52014-01-31 19:40:19 +0100466
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200467 if (unlikely(cfd == -1)) {
468 switch (errno) {
469 case EAGAIN:
Willy Tarreaubb660302014-05-07 19:47:02 +0200470 if (fdtab[fd].ev & FD_POLL_HUP) {
471 /* the listening socket might have been disabled in a shared
472 * process and we're a collateral victim. We'll just pause for
473 * a while in case it comes back. In the mean time, we need to
474 * clear this sticky flag.
475 */
476 fdtab[fd].ev &= ~FD_POLL_HUP;
477 goto transient_error;
478 }
Willy Tarreauf817e9f2014-01-10 16:58:45 +0100479 fd_cant_recv(fd);
Willy Tarreauafad0e02012-08-09 14:45:22 +0200480 return; /* nothing more to accept */
Willy Tarreaubb660302014-05-07 19:47:02 +0200481 case EINVAL:
482 /* might be trying to accept on a shut fd (eg: soft stop) */
483 goto transient_error;
Willy Tarreaua593ec52014-01-20 21:21:30 +0100484 case EINTR:
485 case ECONNABORTED:
486 continue;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200487 case ENFILE:
488 if (p)
489 send_log(p, LOG_EMERG,
490 "Proxy %s reached system FD limit at %d. Please check system tunables.\n",
491 p->id, maxfd);
Willy Tarreaubb660302014-05-07 19:47:02 +0200492 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200493 case EMFILE:
494 if (p)
495 send_log(p, LOG_EMERG,
496 "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n",
497 p->id, maxfd);
Willy Tarreaubb660302014-05-07 19:47:02 +0200498 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200499 case ENOBUFS:
500 case ENOMEM:
501 if (p)
502 send_log(p, LOG_EMERG,
503 "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n",
504 p->id, maxfd);
Willy Tarreaubb660302014-05-07 19:47:02 +0200505 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200506 default:
Willy Tarreaua593ec52014-01-20 21:21:30 +0100507 /* unexpected result, let's give up and let other tasks run */
Willy Tarreau6c11bd22014-01-24 00:54:27 +0100508 goto stop;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200509 }
510 }
511
512 if (unlikely(cfd >= global.maxsock)) {
513 send_log(p, LOG_EMERG,
514 "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n",
515 p->id);
516 close(cfd);
517 limit_listener(l, &global_listener_queue);
518 task_schedule(global_listener_queue_task, tick_add(now_ms, 1000)); /* try again in 1 second */
Willy Tarreauafad0e02012-08-09 14:45:22 +0200519 return;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200520 }
521
522 /* increase the per-process number of cumulated connections */
523 if (!(l->options & LI_O_UNLIMITED)) {
524 update_freq_ctr(&global.conn_per_sec, 1);
525 if (global.conn_per_sec.curr_ctr > global.cps_max)
526 global.cps_max = global.conn_per_sec.curr_ctr;
527 actconn++;
528 }
529
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200530 l->nbconn++;
531
532 if (l->counters) {
533 if (l->nbconn > l->counters->conn_max)
534 l->counters->conn_max = l->nbconn;
535 }
536
537 ret = l->accept(l, cfd, &addr);
538 if (unlikely(ret <= 0)) {
Willy Tarreau87b09662015-04-03 00:22:06 +0200539 /* The connection was closed by stream_accept(). Either
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200540 * we just have to ignore it (ret == 0) or it's a critical
541 * error due to a resource shortage, and we must stop the
542 * listener (ret < 0).
543 */
544 if (!(l->options & LI_O_UNLIMITED))
545 actconn--;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200546 l->nbconn--;
547 if (ret == 0) /* successful termination */
548 continue;
549
Willy Tarreaubb660302014-05-07 19:47:02 +0200550 goto transient_error;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200551 }
552
553 if (l->nbconn >= l->maxconn) {
554 listener_full(l);
Willy Tarreauafad0e02012-08-09 14:45:22 +0200555 return;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200556 }
557
Willy Tarreau93e7c002013-10-07 18:51:07 +0200558 /* increase the per-process number of cumulated connections */
559 if (!(l->options & LI_O_UNLIMITED)) {
560 update_freq_ctr(&global.sess_per_sec, 1);
561 if (global.sess_per_sec.curr_ctr > global.sps_max)
562 global.sps_max = global.sess_per_sec.curr_ctr;
563 }
Willy Tarreaue43d5322013-10-07 20:01:52 +0200564#ifdef USE_OPENSSL
565 if (!(l->options & LI_O_UNLIMITED) && l->bind_conf && l->bind_conf->is_ssl) {
566
567 update_freq_ctr(&global.ssl_per_sec, 1);
568 if (global.ssl_per_sec.curr_ctr > global.ssl_max)
569 global.ssl_max = global.ssl_per_sec.curr_ctr;
570 }
571#endif
Willy Tarreau93e7c002013-10-07 18:51:07 +0200572
Willy Tarreauaece46a2012-07-06 12:25:58 +0200573 } /* end of while (max_accept--) */
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200574
Willy Tarreauaece46a2012-07-06 12:25:58 +0200575 /* we've exhausted max_accept, so there is no need to poll again */
Willy Tarreau6c11bd22014-01-24 00:54:27 +0100576 stop:
577 fd_done_recv(fd);
Willy Tarreauafad0e02012-08-09 14:45:22 +0200578 return;
Willy Tarreaubb660302014-05-07 19:47:02 +0200579
580 transient_error:
581 /* pause the listener and try again in 100 ms */
582 expire = tick_add(now_ms, 100);
583
584 wait_expire:
585 limit_listener(l, &global_listener_queue);
586 task_schedule(global_listener_queue_task, tick_first(expire, global_listener_queue_task->expire));
587 return;
Willy Tarreaubbebbbf2012-05-07 21:22:09 +0200588}
589
Willy Tarreau05f50472017-09-15 09:19:58 +0200590/* Notify the listener that a connection initiated from it was released. This
591 * is used to keep the connection count consistent and to possibly re-open
592 * listening when it was limited.
593 */
594void listener_release(struct listener *l)
595{
596 struct proxy *fe = l->bind_conf->frontend;
597
598 if (!(l->options & LI_O_UNLIMITED))
599 actconn--;
600 l->nbconn--;
601 if (l->state == LI_FULL)
602 resume_listener(l);
603
604 /* Dequeues all of the listeners waiting for a resource */
605 if (!LIST_ISEMPTY(&global_listener_queue))
606 dequeue_all_listeners(&global_listener_queue);
607
608 if (!LIST_ISEMPTY(&fe->listener_queue) &&
609 (!fe->fe_sps_lim || freq_ctr_remain(&fe->fe_sess_per_sec, fe->fe_sps_lim, 0) > 0))
610 dequeue_all_listeners(&fe->listener_queue);
611}
612
Willy Tarreau26982662012-09-12 23:17:10 +0200613/*
614 * Registers the bind keyword list <kwl> as a list of valid keywords for next
615 * parsing sessions.
616 */
617void bind_register_keywords(struct bind_kw_list *kwl)
618{
619 LIST_ADDQ(&bind_keywords.list, &kwl->list);
620}
621
622/* Return a pointer to the bind keyword <kw>, or NULL if not found. If the
623 * keyword is found with a NULL ->parse() function, then an attempt is made to
624 * find one with a valid ->parse() function. This way it is possible to declare
625 * platform-dependant, known keywords as NULL, then only declare them as valid
626 * if some options are met. Note that if the requested keyword contains an
627 * opening parenthesis, everything from this point is ignored.
628 */
629struct bind_kw *bind_find_kw(const char *kw)
630{
631 int index;
632 const char *kwend;
633 struct bind_kw_list *kwl;
634 struct bind_kw *ret = NULL;
635
636 kwend = strchr(kw, '(');
637 if (!kwend)
638 kwend = kw + strlen(kw);
639
640 list_for_each_entry(kwl, &bind_keywords.list, list) {
641 for (index = 0; kwl->kw[index].kw != NULL; index++) {
642 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
643 kwl->kw[index].kw[kwend-kw] == 0) {
644 if (kwl->kw[index].parse)
645 return &kwl->kw[index]; /* found it !*/
646 else
647 ret = &kwl->kw[index]; /* may be OK */
648 }
649 }
650 }
651 return ret;
652}
653
Willy Tarreau8638f482012-09-18 18:01:17 +0200654/* Dumps all registered "bind" keywords to the <out> string pointer. The
655 * unsupported keywords are only dumped if their supported form was not
656 * found.
657 */
658void bind_dump_kws(char **out)
659{
660 struct bind_kw_list *kwl;
661 int index;
662
663 *out = NULL;
664 list_for_each_entry(kwl, &bind_keywords.list, list) {
665 for (index = 0; kwl->kw[index].kw != NULL; index++) {
666 if (kwl->kw[index].parse ||
667 bind_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) {
Willy Tarreau51fb7652012-09-18 18:24:39 +0200668 memprintf(out, "%s[%4s] %s%s%s\n", *out ? *out : "",
669 kwl->scope,
Willy Tarreau8638f482012-09-18 18:01:17 +0200670 kwl->kw[index].kw,
Willy Tarreau51fb7652012-09-18 18:24:39 +0200671 kwl->kw[index].skip ? " <arg>" : "",
672 kwl->kw[index].parse ? "" : " (not supported)");
Willy Tarreau8638f482012-09-18 18:01:17 +0200673 }
674 }
675 }
676}
677
Willy Tarreau645513a2010-05-24 20:55:15 +0200678/************************************************************************/
Willy Tarreau0ccb7442013-01-07 22:54:17 +0100679/* All supported sample and ACL keywords must be declared here. */
Willy Tarreau645513a2010-05-24 20:55:15 +0200680/************************************************************************/
681
Willy Tarreaua5e37562011-12-16 17:06:15 +0100682/* set temp integer to the number of connexions to the same listening socket */
Willy Tarreau645513a2010-05-24 20:55:15 +0200683static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +0200684smp_fetch_dconn(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau645513a2010-05-24 20:55:15 +0200685{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200686 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200687 smp->data.u.sint = smp->sess->listener->nbconn;
Willy Tarreau645513a2010-05-24 20:55:15 +0200688 return 1;
689}
690
Willy Tarreaua5e37562011-12-16 17:06:15 +0100691/* set temp integer to the id of the socket (listener) */
Willy Tarreau645513a2010-05-24 20:55:15 +0200692static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +0200693smp_fetch_so_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau37406352012-04-23 16:16:37 +0200694{
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200695 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200696 smp->data.u.sint = smp->sess->listener->luid;
Willy Tarreau645513a2010-05-24 20:55:15 +0200697 return 1;
698}
699
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200700/* parse the "accept-proxy" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200701static 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 +0200702{
703 struct listener *l;
704
Willy Tarreau4348fad2012-09-20 16:48:07 +0200705 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200706 l->options |= LI_O_ACC_PROXY;
707
708 return 0;
709}
710
Bertrand Jacquin93b227d2016-06-04 15:11:10 +0100711/* parse the "accept-netscaler-cip" bind keyword */
712static int bind_parse_accept_netscaler_cip(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
713{
714 struct listener *l;
715 uint32_t val;
716
717 if (!*args[cur_arg + 1]) {
718 memprintf(err, "'%s' : missing value", args[cur_arg]);
719 return ERR_ALERT | ERR_FATAL;
720 }
721
722 val = atol(args[cur_arg + 1]);
723 if (val <= 0) {
724 memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
725 return ERR_ALERT | ERR_FATAL;
726 }
727
728 list_for_each_entry(l, &conf->listeners, by_bind) {
729 l->options |= LI_O_ACC_CIP;
730 conf->ns_cip_magic = val;
731 }
732
733 return 0;
734}
735
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200736/* parse the "backlog" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200737static 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 +0200738{
739 struct listener *l;
740 int val;
741
742 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200743 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200744 return ERR_ALERT | ERR_FATAL;
745 }
746
747 val = atol(args[cur_arg + 1]);
748 if (val <= 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200749 memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200750 return ERR_ALERT | ERR_FATAL;
751 }
752
Willy Tarreau4348fad2012-09-20 16:48:07 +0200753 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200754 l->backlog = val;
755
756 return 0;
757}
758
759/* parse the "id" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200760static 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 +0200761{
762 struct eb32_node *node;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200763 struct listener *l, *new;
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +0100764 char *error;
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200765
Willy Tarreau4348fad2012-09-20 16:48:07 +0200766 if (conf->listeners.n != conf->listeners.p) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200767 memprintf(err, "'%s' can only be used with a single socket", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200768 return ERR_ALERT | ERR_FATAL;
769 }
770
771 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200772 memprintf(err, "'%s' : expects an integer argument", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200773 return ERR_ALERT | ERR_FATAL;
774 }
775
Willy Tarreau4348fad2012-09-20 16:48:07 +0200776 new = LIST_NEXT(&conf->listeners, struct listener *, by_bind);
Thierry Fourniere7fe8eb2016-02-26 08:45:58 +0100777 new->luid = strtol(args[cur_arg + 1], &error, 10);
778 if (*error != '\0') {
779 memprintf(err, "'%s' : expects an integer argument, found '%s'", args[cur_arg], args[cur_arg + 1]);
780 return ERR_ALERT | ERR_FATAL;
781 }
Willy Tarreau4348fad2012-09-20 16:48:07 +0200782 new->conf.id.key = new->luid;
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200783
Willy Tarreau4348fad2012-09-20 16:48:07 +0200784 if (new->luid <= 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200785 memprintf(err, "'%s' : custom id has to be > 0", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200786 return ERR_ALERT | ERR_FATAL;
787 }
788
Willy Tarreau4348fad2012-09-20 16:48:07 +0200789 node = eb32_lookup(&px->conf.used_listener_id, new->luid);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200790 if (node) {
791 l = container_of(node, struct listener, conf.id);
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200792 memprintf(err, "'%s' : custom id %d already used at %s:%d ('bind %s')",
793 args[cur_arg], l->luid, l->bind_conf->file, l->bind_conf->line,
794 l->bind_conf->arg);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200795 return ERR_ALERT | ERR_FATAL;
796 }
797
Willy Tarreau4348fad2012-09-20 16:48:07 +0200798 eb32_insert(&px->conf.used_listener_id, &new->conf.id);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200799 return 0;
800}
801
802/* parse the "maxconn" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200803static 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 +0200804{
805 struct listener *l;
806 int val;
807
808 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200809 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200810 return ERR_ALERT | ERR_FATAL;
811 }
812
813 val = atol(args[cur_arg + 1]);
814 if (val <= 0) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200815 memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200816 return ERR_ALERT | ERR_FATAL;
817 }
818
Willy Tarreau4348fad2012-09-20 16:48:07 +0200819 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200820 l->maxconn = val;
821
822 return 0;
823}
824
825/* parse the "name" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200826static 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 +0200827{
828 struct listener *l;
829
830 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200831 memprintf(err, "'%s' : missing name", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200832 return ERR_ALERT | ERR_FATAL;
833 }
834
Willy Tarreau4348fad2012-09-20 16:48:07 +0200835 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200836 l->name = strdup(args[cur_arg + 1]);
837
838 return 0;
839}
840
841/* parse the "nice" bind keyword */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200842static 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 +0200843{
844 struct listener *l;
845 int val;
846
847 if (!*args[cur_arg + 1]) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200848 memprintf(err, "'%s' : missing value", args[cur_arg]);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200849 return ERR_ALERT | ERR_FATAL;
850 }
851
852 val = atol(args[cur_arg + 1]);
853 if (val < -1024 || val > 1024) {
Willy Tarreaueb6cead2012-09-20 19:43:14 +0200854 memprintf(err, "'%s' : invalid value %d, allowed range is -1024..1024", args[cur_arg], val);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200855 return ERR_ALERT | ERR_FATAL;
856 }
857
Willy Tarreau4348fad2012-09-20 16:48:07 +0200858 list_for_each_entry(l, &conf->listeners, by_bind)
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200859 l->nice = val;
860
861 return 0;
862}
863
Willy Tarreau6ae1ba62014-05-07 19:01:58 +0200864/* parse the "process" bind keyword */
865static int bind_parse_process(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
866{
867 unsigned long set = 0;
868 unsigned int low, high;
869
870 if (strcmp(args[cur_arg + 1], "all") == 0) {
871 set = 0;
872 }
873 else if (strcmp(args[cur_arg + 1], "odd") == 0) {
874 set |= ~0UL/3UL; /* 0x555....555 */
875 }
876 else if (strcmp(args[cur_arg + 1], "even") == 0) {
877 set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
878 }
879 else if (isdigit((int)*args[cur_arg + 1])) {
880 char *dash = strchr(args[cur_arg + 1], '-');
881
882 low = high = str2uic(args[cur_arg + 1]);
883 if (dash)
884 high = str2uic(dash + 1);
885
886 if (high < low) {
887 unsigned int swap = low;
888 low = high;
889 high = swap;
890 }
891
892 if (low < 1 || high > LONGBITS) {
893 memprintf(err, "'%s' : invalid range %d-%d, allowed range is 1..%d", args[cur_arg], low, high, LONGBITS);
894 return ERR_ALERT | ERR_FATAL;
895 }
896 while (low <= high)
897 set |= 1UL << (low++ - 1);
898 }
899 else {
900 memprintf(err, "'%s' expects 'all', 'odd', 'even', or a process range with numbers from 1 to %d.", args[cur_arg], LONGBITS);
901 return ERR_ALERT | ERR_FATAL;
902 }
903
904 conf->bind_proc = set;
905 return 0;
906}
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200907
Willy Tarreau61612d42012-04-19 18:42:05 +0200908/* Note: must not be declared <const> as its list will be overwritten.
909 * Please take care of keeping this list alphabetically sorted.
910 */
Willy Tarreaudc13c112013-06-21 23:16:39 +0200911static struct sample_fetch_kw_list smp_kws = {ILH, {
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200912 { "dst_conn", smp_fetch_dconn, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
913 { "so_id", smp_fetch_so_id, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, },
Willy Tarreau0ccb7442013-01-07 22:54:17 +0100914 { /* END */ },
915}};
916
917/* Note: must not be declared <const> as its list will be overwritten.
918 * Please take care of keeping this list alphabetically sorted.
919 */
Willy Tarreaudc13c112013-06-21 23:16:39 +0200920static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau0ccb7442013-01-07 22:54:17 +0100921 { /* END */ },
Willy Tarreau645513a2010-05-24 20:55:15 +0200922}};
923
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200924/* Note: must not be declared <const> as its list will be overwritten.
925 * Please take care of keeping this list alphabetically sorted, doing so helps
926 * all code contributors.
927 * Optional keywords are also declared with a NULL ->parse() function so that
928 * the config parser can report an appropriate error when a known keyword was
929 * not enabled.
930 */
Willy Tarreau51fb7652012-09-18 18:24:39 +0200931static struct bind_kw_list bind_kws = { "ALL", { }, {
Bertrand Jacquin93b227d2016-06-04 15:11:10 +0100932 { "accept-netscaler-cip", bind_parse_accept_netscaler_cip, 1 }, /* enable NetScaler Client IP insertion protocol */
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200933 { "accept-proxy", bind_parse_accept_proxy, 0 }, /* enable PROXY protocol */
934 { "backlog", bind_parse_backlog, 1 }, /* set backlog of listening socket */
935 { "id", bind_parse_id, 1 }, /* set id of listening socket */
936 { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */
937 { "name", bind_parse_name, 1 }, /* set name of listening socket */
938 { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */
Willy Tarreau6ae1ba62014-05-07 19:01:58 +0200939 { "process", bind_parse_process, 1 }, /* set list of allowed process for this socket */
Willy Tarreau0ccb7442013-01-07 22:54:17 +0100940 { /* END */ },
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200941}};
942
Willy Tarreau645513a2010-05-24 20:55:15 +0200943__attribute__((constructor))
Willy Tarreaud1d54542012-09-12 22:58:11 +0200944static void __listener_init(void)
Willy Tarreau645513a2010-05-24 20:55:15 +0200945{
Willy Tarreau0ccb7442013-01-07 22:54:17 +0100946 sample_register_fetches(&smp_kws);
Willy Tarreau645513a2010-05-24 20:55:15 +0200947 acl_register_keywords(&acl_kws);
Willy Tarreau3dcc3412012-09-18 17:17:28 +0200948 bind_register_keywords(&bind_kws);
Willy Tarreau645513a2010-05-24 20:55:15 +0200949}
950
951/*
952 * Local variables:
953 * c-indent-level: 8
954 * c-basic-offset: 8
955 * End:
956 */