blob: 7124f565f57a434b62317f673c8ce4b8ff2a03f6 [file] [log] [blame]
William Lallemand2fe7dd02018-09-11 16:51:29 +02001/*
2 * Socket Pair protocol layer (sockpair)
3 *
4 * Copyright HAProxy Technologies - William Lallemand <wlallemand@haproxy.com>
5 *
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
13#include <ctype.h>
14#include <errno.h>
15#include <fcntl.h>
16#include <pwd.h>
17#include <grp.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <syslog.h>
22#include <time.h>
23
24#include <sys/socket.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27#include <sys/un.h>
28
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020029#include <haproxy/api.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020030#include <haproxy/connection.h>
Willy Tarreau8d366972020-05-27 16:10:29 +020031#include <haproxy/errors.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020032#include <haproxy/fd.h>
33#include <haproxy/freq_ctr.h>
Willy Tarreauf268ee82020-06-04 17:05:57 +020034#include <haproxy/global.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020035#include <haproxy/list.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020036#include <haproxy/listener.h>
Willy Tarreau344b8fc2020-10-15 09:43:31 +020037#include <haproxy/log.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020038#include <haproxy/protocol.h>
Willy Tarreau62292b22020-09-02 17:52:23 +020039#include <haproxy/proto_sockpair.h>
Willy Tarreau686fa3d2020-09-25 19:09:53 +020040#include <haproxy/sock.h>
Willy Tarreau92b4f132020-06-01 11:05:15 +020041#include <haproxy/time.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020042#include <haproxy/tools.h>
Willy Tarreaud6788052020-05-27 15:59:00 +020043#include <haproxy/version.h>
William Lallemand2fe7dd02018-09-11 16:51:29 +020044
William Lallemand2fe7dd02018-09-11 16:51:29 +020045
William Lallemand2fe7dd02018-09-11 16:51:29 +020046static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen);
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +020047static void sockpair_enable_listener(struct listener *listener);
48static void sockpair_disable_listener(struct listener *listener);
Olivier Houchardfdcb0072019-05-06 18:32:29 +020049static int sockpair_connect_server(struct connection *conn, int flags);
Willy Tarreau7d053e42020-10-15 09:19:43 +020050static int sockpair_accepting_conn(const struct receiver *rx);
Willy Tarreau344b8fc2020-10-15 09:43:31 +020051struct connection *sockpair_accept_conn(struct listener *l, int *status);
William Lallemand2fe7dd02018-09-11 16:51:29 +020052
Willy Tarreaub0254cb2020-09-04 08:07:11 +020053struct proto_fam proto_fam_sockpair = {
54 .name = "sockpair",
55 .sock_domain = AF_CUST_SOCKPAIR,
56 .sock_family = AF_UNIX,
57 .sock_addrlen = sizeof(struct sockaddr_un),
58 .l3_addrlen = sizeof(((struct sockaddr_un*)0)->sun_path),
59 .addrcmp = NULL,
60 .bind = sockpair_bind_receiver,
61 .get_src = NULL,
62 .get_dst = NULL,
63};
64
William Lallemand2fe7dd02018-09-11 16:51:29 +020065/* Note: must not be declared <const> as its list will be overwritten */
Willy Tarreaub9b2fd72020-12-08 14:13:11 +010066struct protocol proto_sockpair = {
Willy Tarreaub366c9a2020-12-08 14:54:20 +010067 .name = "sockpair",
68
69 /* connection layer */
70 .ctrl_type = SOCK_STREAM,
71 .listen = sockpair_bind_listener,
72 .enable = sockpair_enable_listener,
73 .disable = sockpair_disable_listener,
74 .add = default_add_listener,
75 .unbind = default_unbind_listener,
76 .accept_conn = sockpair_accept_conn,
Willy Tarreaude471c42020-12-08 15:50:56 +010077 .ctrl_init = sock_conn_ctrl_init,
78 .ctrl_close = sock_conn_ctrl_close,
Willy Tarreaub366c9a2020-12-08 14:54:20 +010079 .connect = sockpair_connect_server,
80
81 /* binding layer */
82 /* Note: suspend/resume not supported */
83
84 /* address family */
85 .fam = &proto_fam_sockpair,
86
87 /* socket layer */
88 .sock_type = SOCK_STREAM,
89 .sock_prot = 0,
90 .rx_enable = sock_enable,
91 .rx_disable = sock_disable,
92 .rx_unbind = sock_unbind,
93 .rx_listening = sockpair_accepting_conn,
94 .default_iocb = sock_accept_iocb,
95 .receivers = LIST_HEAD_INIT(proto_sockpair.receivers),
96 .nb_receivers = 0,
William Lallemand2fe7dd02018-09-11 16:51:29 +020097};
98
Willy Tarreau0108d902018-11-25 19:14:37 +010099INITCALL1(STG_REGISTER, protocol_register, &proto_sockpair);
100
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200101/* Enable receipt of incoming connections for listener <l>. The receiver must
Willy Tarreaua4380b22020-11-04 13:59:04 +0100102 * still be valid.
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200103 */
104static void sockpair_enable_listener(struct listener *l)
105{
Willy Tarreaua4380b22020-11-04 13:59:04 +0100106 fd_want_recv_safe(l->rx.fd);
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200107}
108
109/* Disable receipt of incoming connections for listener <l>. The receiver must
Willy Tarreaua4380b22020-11-04 13:59:04 +0100110 * still be valid.
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200111 */
112static void sockpair_disable_listener(struct listener *l)
113{
Willy Tarreaua4380b22020-11-04 13:59:04 +0100114 fd_stop_recv(l->rx.fd);
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200115}
116
Willy Tarreau233ad282020-10-15 21:45:15 +0200117/* Binds receiver <rx>, and assigns rx->iocb and rx->owner as the callback
118 * and context, respectively, with ->bind_thread as the thread mask. Returns an
119 * error code made of ERR_* bits on failure or ERR_NONE on success. On failure,
120 * an error message may be passed into <errmsg>. Note that the binding address
121 * is only an FD to receive the incoming FDs on. Thus by definition there is no
122 * real "bind" operation, this only completes the receiver. Such FDs are not
Willy Tarreau62292b22020-09-02 17:52:23 +0200123 * inherited upon reload.
124 */
Willy Tarreau233ad282020-10-15 21:45:15 +0200125int sockpair_bind_receiver(struct receiver *rx, char **errmsg)
Willy Tarreau62292b22020-09-02 17:52:23 +0200126{
127 int err;
128
129 /* ensure we never return garbage */
130 if (errmsg)
131 *errmsg = 0;
132
133 err = ERR_NONE;
134
135 if (rx->flags & RX_F_BOUND)
136 return ERR_NONE;
137
138 if (rx->fd == -1) {
139 err |= ERR_FATAL | ERR_ALERT;
140 memprintf(errmsg, "sockpair may be only used with inherited FDs");
141 goto bind_return;
142 }
143
144 if (rx->fd >= global.maxsock) {
145 err |= ERR_FATAL | ERR_ABORT | ERR_ALERT;
146 memprintf(errmsg, "not enough free sockets (raise '-n' parameter)");
147 goto bind_close_return;
148 }
149
150 if (fcntl(rx->fd, F_SETFL, O_NONBLOCK) == -1) {
151 err |= ERR_FATAL | ERR_ALERT;
152 memprintf(errmsg, "cannot make socket non-blocking");
153 goto bind_close_return;
154 }
155
156 rx->flags |= RX_F_BOUND;
157
Willy Tarreau233ad282020-10-15 21:45:15 +0200158 fd_insert(rx->fd, rx->owner, rx->iocb, thread_mask(rx->settings->bind_thread) & all_threads_mask);
Willy Tarreau62292b22020-09-02 17:52:23 +0200159 return err;
160
161 bind_return:
162 if (errmsg && *errmsg)
163 memprintf(errmsg, "%s [fd %d]", *errmsg, rx->fd);
164
165 return err;
166
167 bind_close_return:
168 close(rx->fd);
169 goto bind_return;
170}
171
William Lallemand2fe7dd02018-09-11 16:51:29 +0200172/* This function changes the state from ASSIGNED to LISTEN. The socket is NOT
173 * enabled for polling. The return value is composed from ERR_NONE,
174 * ERR_RETRYABLE and ERR_FATAL. It may return a warning or an error message in
175 * <errmsg> if the message is at most <errlen> bytes long (including '\0').
176 * Note that <errmsg> may be NULL if <errlen> is also zero.
177 */
178static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen)
179{
William Lallemand2fe7dd02018-09-11 16:51:29 +0200180 int err;
Willy Tarreau9eda7a62020-09-02 18:02:00 +0200181 char *msg = NULL;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200182
183 err = ERR_NONE;
184
185 /* ensure we never return garbage */
186 if (errlen)
187 *errmsg = 0;
188
189 if (listener->state != LI_ASSIGNED)
190 return ERR_NONE; /* already bound */
191
Willy Tarreauad33acf2020-09-02 18:40:02 +0200192 if (!(listener->rx.flags & RX_F_BOUND)) {
193 msg = "receiving socket not bound";
194 goto err_return;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200195 }
Willy Tarreauad33acf2020-09-02 18:40:02 +0200196
Willy Tarreaua37b2442020-09-24 07:23:45 +0200197 listener_set_state(listener, LI_LISTEN);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200198 return err;
199
200 err_return:
201 if (msg && errlen)
Willy Tarreau9eda7a62020-09-02 18:02:00 +0200202 snprintf(errmsg, errlen, "%s [fd %d]", msg, listener->rx.fd);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200203 return err;
204}
205
206/*
207 * Send FD over a unix socket
208 *
209 * <send_fd> is the FD to send
210 * <fd> is the fd of the unix socket to use for the transfer
211 *
212 * The iobuf variable could be use in the future to enhance the protocol.
213 */
214int send_fd_uxst(int fd, int send_fd)
215{
216 char iobuf[2];
217 struct iovec iov;
218 struct msghdr msghdr;
219
220 char cmsgbuf[CMSG_SPACE(sizeof(int))];
221 char buf[CMSG_SPACE(sizeof(int))];
222 struct cmsghdr *cmsg = (void *)buf;
223
224 int *fdptr;
225
226 iov.iov_base = iobuf;
227 iov.iov_len = sizeof(iobuf);
228
229 memset(&msghdr, 0, sizeof(msghdr));
230 msghdr.msg_iov = &iov;
231 msghdr.msg_iovlen = 1;
232
233 /* Now send the fds */
234 msghdr.msg_control = cmsgbuf;
235 msghdr.msg_controllen = CMSG_SPACE(sizeof(int));
236
237 cmsg = CMSG_FIRSTHDR(&msghdr);
238 cmsg->cmsg_len = CMSG_LEN(sizeof(int));
239 cmsg->cmsg_level = SOL_SOCKET;
240 cmsg->cmsg_type = SCM_RIGHTS;
241
242 fdptr = (int *)CMSG_DATA(cmsg);
243 memcpy(fdptr, &send_fd, sizeof(send_fd));
244
245 if (sendmsg(fd, &msghdr, 0) != sizeof(iobuf)) {
246 ha_warning("Failed to transfer socket\n");
247 return 1;
248 }
249
250 return 0;
251}
252
253/*
254 *
Joseph Herlant8bb32ae2018-11-25 11:43:27 -0800255 * This function works like uxst_connect_server but instead of creating a
William Lallemand2fe7dd02018-09-11 16:51:29 +0200256 * socket and establishing a connection, it creates a pair of connected
257 * sockets, and send one of them through the destination FD. The destination FD
Willy Tarreau3f4fa092019-07-17 16:42:04 +0200258 * is stored in conn->dst->sin_addr.s_addr during configuration parsing.
William Lallemand2fe7dd02018-09-11 16:51:29 +0200259 *
260 * conn->target may point either to a valid server or to a backend, depending
261 * on conn->target. Only OBJ_TYPE_PROXY and OBJ_TYPE_SERVER are supported. The
262 * <data> parameter is a boolean indicating whether there are data waiting for
263 * being sent or not, in order to adjust data write polling and on some
264 * platforms. The <delack> argument is ignored.
265 *
266 * Note that a pending send_proxy message accounts for data.
267 *
268 * It can return one of :
269 * - SF_ERR_NONE if everything's OK
270 * - SF_ERR_SRVTO if there are no more servers
271 * - SF_ERR_SRVCL if the connection was refused by the server
272 * - SF_ERR_PRXCOND if the connection has been limited by the proxy (maxconn)
273 * - SF_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...)
274 * - SF_ERR_INTERNAL for any other purely internal errors
275 * Additionally, in the case of SF_ERR_RESOURCE, an emergency log will be emitted.
276 *
277 * The connection's fd is inserted only when SF_ERR_NONE is returned, otherwise
278 * it's invalid and the caller has nothing to do.
279 */
Olivier Houchardfdcb0072019-05-06 18:32:29 +0200280static int sockpair_connect_server(struct connection *conn, int flags)
William Lallemand2fe7dd02018-09-11 16:51:29 +0200281{
282 int sv[2], fd, dst_fd = -1;
283
284 /* the FD is stored in the sockaddr struct */
Willy Tarreau3f4fa092019-07-17 16:42:04 +0200285 dst_fd = ((struct sockaddr_in *)conn->dst)->sin_addr.s_addr;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200286
William Lallemand2fe7dd02018-09-11 16:51:29 +0200287 if (obj_type(conn->target) != OBJ_TYPE_PROXY &&
288 obj_type(conn->target) != OBJ_TYPE_SERVER) {
289 conn->flags |= CO_FL_ERROR;
290 return SF_ERR_INTERNAL;
291 }
292
293 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
294 ha_alert("socketpair(): Cannot create socketpair. Giving up.\n");
295 conn->flags |= CO_FL_ERROR;
296 return SF_ERR_RESOURCE;
297 }
298
299 fd = conn->handle.fd = sv[1];
300
301 if (fd >= global.maxsock) {
302 /* do not log anything there, it's a normal condition when this option
303 * is used to serialize connections to a server !
304 */
305 ha_alert("socket(): not enough free sockets. Raise -n argument. Giving up.\n");
306 close(sv[0]);
307 close(sv[1]);
308 conn->err_code = CO_ER_CONF_FDLIM;
309 conn->flags |= CO_FL_ERROR;
310 return SF_ERR_PRXCOND; /* it is a configuration limit */
311 }
312
313 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
314 qfprintf(stderr,"Cannot set client socket to non blocking mode.\n");
315 close(sv[0]);
316 close(sv[1]);
317 conn->err_code = CO_ER_SOCK_ERR;
318 conn->flags |= CO_FL_ERROR;
319 return SF_ERR_INTERNAL;
320 }
321
William Lallemandc03eb012018-11-27 12:02:37 +0100322 if (master == 1 && (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)) {
323 ha_alert("Cannot set CLOEXEC on client socket.\n");
324 close(sv[0]);
325 close(sv[1]);
326 conn->err_code = CO_ER_SOCK_ERR;
327 conn->flags |= CO_FL_ERROR;
328 return SF_ERR_INTERNAL;
329 }
330
William Lallemand2fe7dd02018-09-11 16:51:29 +0200331 /* if a send_proxy is there, there are data */
Olivier Houchardfdcb0072019-05-06 18:32:29 +0200332 if (conn->send_proxy_ofs)
333 flags |= CONNECT_HAS_DATA;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200334
335 if (global.tune.server_sndbuf)
336 setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &global.tune.server_sndbuf, sizeof(global.tune.server_sndbuf));
337
338 if (global.tune.server_rcvbuf)
339 setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &global.tune.server_rcvbuf, sizeof(global.tune.server_rcvbuf));
340
341 /* The new socket is sent on the other side, it should be retrieved and
342 * considered as an 'accept' socket on the server side */
343 if (send_fd_uxst(dst_fd, sv[0]) == -1) {
344 close(sv[0]);
345 close(sv[1]);
346 conn->err_code = CO_ER_SOCK_ERR;
347 conn->flags |= CO_FL_ERROR;
348 return SF_ERR_INTERNAL;
349 }
350
351 close(sv[0]); /* we don't need this side anymore */
352
353 conn->flags &= ~CO_FL_WAIT_L4_CONN;
354
355 conn->flags |= CO_FL_ADDR_TO_SET;
356
357 /* Prepare to send a few handshakes related to the on-wire protocol. */
358 if (conn->send_proxy_ofs)
359 conn->flags |= CO_FL_SEND_PROXY;
360
361 conn_ctrl_init(conn); /* registers the FD */
362 fdtab[fd].linger_risk = 0; /* no need to disable lingering */
363
364 if (conn_xprt_init(conn) < 0) {
365 conn_full_close(conn);
366 conn->flags |= CO_FL_ERROR;
367 return SF_ERR_RESOURCE;
368 }
369
William Lallemand2fe7dd02018-09-11 16:51:29 +0200370 return SF_ERR_NONE; /* connection is OK */
371}
372
373
374/*
Joseph Herlant8bb32ae2018-11-25 11:43:27 -0800375 * Receives a file descriptor transferred from a unix socket.
William Lallemand2fe7dd02018-09-11 16:51:29 +0200376 *
377 * Return -1 or a socket fd;
378 *
Joseph Herlant8bb32ae2018-11-25 11:43:27 -0800379 * The iobuf variable could be used in the future to enhance the protocol.
William Lallemand2fe7dd02018-09-11 16:51:29 +0200380 */
381int recv_fd_uxst(int sock)
382{
383 struct msghdr msghdr;
384 struct iovec iov;
385 char iobuf[2];
386
387 char cmsgbuf[CMSG_SPACE(sizeof(int))];
388 char buf[CMSG_SPACE(sizeof(int))];
389 struct cmsghdr *cmsg = (void *)buf;
390
391
392 int recv_fd = -1;
393 int ret = -1;
394
395 memset(&msghdr, 0, sizeof(msghdr));
396
397 iov.iov_base = iobuf;
398 iov.iov_len = sizeof(iobuf);
399
400 msghdr.msg_iov = &iov;
401 msghdr.msg_iovlen = 1;
402
403 msghdr.msg_control = cmsgbuf;
404 msghdr.msg_controllen = CMSG_SPACE(sizeof(int));
405
406 iov.iov_len = sizeof(iobuf);
407 iov.iov_base = iobuf;
408
409 while (1) {
410 ret = recvmsg(sock, &msghdr, 0);
411 if (ret == -1 && errno == EINTR)
412 continue;
413 else
414 break;
415 }
416
417 if (ret == -1)
418 return ret;
419
420 cmsg = CMSG_FIRSTHDR(&msghdr);
Willy Tarreau7d7ab432018-09-20 11:39:39 +0200421 if (cmsg && cmsg->cmsg_level == SOL_SOCKET &&
William Lallemand2fe7dd02018-09-11 16:51:29 +0200422 cmsg->cmsg_type == SCM_RIGHTS) {
423 size_t totlen = cmsg->cmsg_len -
424 CMSG_LEN(0);
425 memcpy(&recv_fd, CMSG_DATA(cmsg), totlen);
426 }
427 return recv_fd;
428}
429
Willy Tarreaucc8b6532020-10-13 17:27:34 +0200430/* Tests if the receiver supports accepting connections. Returns positive on
431 * success, 0 if not possible, negative if the socket is non-recoverable. In
432 * practice zero is never returned since we don't support suspending sockets.
433 * The real test consists in verifying we have a connected SOCK_STREAM of
434 * family AF_UNIX.
435 */
Willy Tarreau7d053e42020-10-15 09:19:43 +0200436static int sockpair_accepting_conn(const struct receiver *rx)
Willy Tarreaucc8b6532020-10-13 17:27:34 +0200437{
438 struct sockaddr sa;
439 socklen_t len;
440 int val;
441
442 len = sizeof(val);
443 if (getsockopt(rx->fd, SOL_SOCKET, SO_TYPE, &val, &len) == -1)
444 return -1;
445
446 if (val != SOCK_STREAM)
447 return -1;
448
449 len = sizeof(sa);
450 if (getsockname(rx->fd, &sa, &len) != 0)
451 return -1;
452
453 if (sa.sa_family != AF_UNIX)
454 return -1;
455
456 len = sizeof(val);
457 if (getsockopt(rx->fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == -1)
458 return -1;
459
460 /* Note: cannot be a listening socket, must be established */
461 if (val)
462 return -1;
463
464 return 1;
465}
466
Willy Tarreau344b8fc2020-10-15 09:43:31 +0200467/* Accept an incoming connection from listener <l>, and return it, as well as
468 * a CO_AC_* status code into <status> if not null. Null is returned on error.
469 * <l> must be a valid listener with a valid frontend.
470 */
471struct connection *sockpair_accept_conn(struct listener *l, int *status)
472{
473 struct proxy *p = l->bind_conf->frontend;
474 struct connection *conn = NULL;
475 int ret;
476 int cfd;
477
478 if ((cfd = recv_fd_uxst(l->rx.fd)) != -1)
479 fcntl(cfd, F_SETFL, O_NONBLOCK);
480
481 if (likely(cfd != -1)) {
482 /* Perfect, the connection was accepted */
483 conn = conn_new(&l->obj_type);
484 if (!conn)
485 goto fail_conn;
486
487 if (!sockaddr_alloc(&conn->src, NULL, 0))
488 goto fail_addr;
489
490 /* just like with UNIX sockets, only the family is filled */
491 conn->src->ss_family = AF_UNIX;
492 conn->handle.fd = cfd;
493 conn->flags |= CO_FL_ADDR_FROM_SET;
494 ret = CO_AC_DONE;
495 goto done;
496 }
497
498 switch (errno) {
499 case EAGAIN:
500 ret = CO_AC_DONE; /* nothing more to accept */
501 if (fdtab[l->rx.fd].ev & (FD_POLL_HUP|FD_POLL_ERR)) {
502 /* the listening socket might have been disabled in a shared
503 * process and we're a collateral victim. We'll just pause for
504 * a while in case it comes back. In the mean time, we need to
505 * clear this sticky flag.
506 */
507 _HA_ATOMIC_AND(&fdtab[l->rx.fd].ev, ~(FD_POLL_HUP|FD_POLL_ERR));
508 ret = CO_AC_PAUSE;
509 }
510 fd_cant_recv(l->rx.fd);
511 break;
512
513 case EINVAL:
514 /* might be trying to accept on a shut fd (eg: soft stop) */
515 ret = CO_AC_PAUSE;
516 break;
517
518 case EINTR:
519 case ECONNABORTED:
520 ret = CO_AC_RETRY;
521 break;
522
523 case ENFILE:
524 if (p)
525 send_log(p, LOG_EMERG,
526 "Proxy %s reached system FD limit (maxsock=%d). Please check system tunables.\n",
527 p->id, global.maxsock);
528 ret = CO_AC_PAUSE;
529 break;
530
531 case EMFILE:
532 if (p)
533 send_log(p, LOG_EMERG,
534 "Proxy %s reached process FD limit (maxsock=%d). Please check 'ulimit-n' and restart.\n",
535 p->id, global.maxsock);
536 ret = CO_AC_PAUSE;
537 break;
538
539 case ENOBUFS:
540 case ENOMEM:
541 if (p)
542 send_log(p, LOG_EMERG,
543 "Proxy %s reached system memory limit (maxsock=%d). Please check system tunables.\n",
544 p->id, global.maxsock);
545 ret = CO_AC_PAUSE;
546 break;
547
548 default:
549 /* unexpected result, let's give up and let other tasks run */
550 ret = CO_AC_YIELD;
551 }
552 done:
553 if (status)
554 *status = ret;
555 return conn;
556
557 fail_addr:
558 conn_free(conn);
559 conn = NULL;
560 fail_conn:
561 ret = CO_AC_PAUSE;
562 goto done;
563}
564
William Lallemand2fe7dd02018-09-11 16:51:29 +0200565/*
566 * Local variables:
567 * c-indent-level: 8
568 * c-basic-offset: 8
569 * End:
570 */