blob: 9c16b2bcfe05d43bb59d390e8f93c1e05c59efcd [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,
Willy Tarreau427c8462020-12-11 16:19:12 +010080 .drain = sock_drain,
Willy Tarreaub366c9a2020-12-08 14:54:20 +010081
82 /* binding layer */
83 /* Note: suspend/resume not supported */
84
85 /* address family */
86 .fam = &proto_fam_sockpair,
87
88 /* socket layer */
89 .sock_type = SOCK_STREAM,
90 .sock_prot = 0,
91 .rx_enable = sock_enable,
92 .rx_disable = sock_disable,
93 .rx_unbind = sock_unbind,
94 .rx_listening = sockpair_accepting_conn,
95 .default_iocb = sock_accept_iocb,
96 .receivers = LIST_HEAD_INIT(proto_sockpair.receivers),
97 .nb_receivers = 0,
William Lallemand2fe7dd02018-09-11 16:51:29 +020098};
99
Willy Tarreau0108d902018-11-25 19:14:37 +0100100INITCALL1(STG_REGISTER, protocol_register, &proto_sockpair);
101
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200102/* Enable receipt of incoming connections for listener <l>. The receiver must
Willy Tarreaua4380b22020-11-04 13:59:04 +0100103 * still be valid.
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200104 */
105static void sockpair_enable_listener(struct listener *l)
106{
Willy Tarreaua4380b22020-11-04 13:59:04 +0100107 fd_want_recv_safe(l->rx.fd);
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200108}
109
110/* Disable receipt of incoming connections for listener <l>. The receiver must
Willy Tarreaua4380b22020-11-04 13:59:04 +0100111 * still be valid.
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200112 */
113static void sockpair_disable_listener(struct listener *l)
114{
Willy Tarreaua4380b22020-11-04 13:59:04 +0100115 fd_stop_recv(l->rx.fd);
Willy Tarreau5ddf1ce2020-09-25 19:27:39 +0200116}
117
Willy Tarreau233ad282020-10-15 21:45:15 +0200118/* Binds receiver <rx>, and assigns rx->iocb and rx->owner as the callback
119 * and context, respectively, with ->bind_thread as the thread mask. Returns an
120 * error code made of ERR_* bits on failure or ERR_NONE on success. On failure,
121 * an error message may be passed into <errmsg>. Note that the binding address
122 * is only an FD to receive the incoming FDs on. Thus by definition there is no
123 * real "bind" operation, this only completes the receiver. Such FDs are not
Willy Tarreau62292b22020-09-02 17:52:23 +0200124 * inherited upon reload.
125 */
Willy Tarreau233ad282020-10-15 21:45:15 +0200126int sockpair_bind_receiver(struct receiver *rx, char **errmsg)
Willy Tarreau62292b22020-09-02 17:52:23 +0200127{
128 int err;
129
130 /* ensure we never return garbage */
131 if (errmsg)
132 *errmsg = 0;
133
134 err = ERR_NONE;
135
136 if (rx->flags & RX_F_BOUND)
137 return ERR_NONE;
138
139 if (rx->fd == -1) {
140 err |= ERR_FATAL | ERR_ALERT;
141 memprintf(errmsg, "sockpair may be only used with inherited FDs");
142 goto bind_return;
143 }
144
145 if (rx->fd >= global.maxsock) {
146 err |= ERR_FATAL | ERR_ABORT | ERR_ALERT;
147 memprintf(errmsg, "not enough free sockets (raise '-n' parameter)");
148 goto bind_close_return;
149 }
150
151 if (fcntl(rx->fd, F_SETFL, O_NONBLOCK) == -1) {
152 err |= ERR_FATAL | ERR_ALERT;
153 memprintf(errmsg, "cannot make socket non-blocking");
154 goto bind_close_return;
155 }
156
157 rx->flags |= RX_F_BOUND;
158
Willy Tarreau233ad282020-10-15 21:45:15 +0200159 fd_insert(rx->fd, rx->owner, rx->iocb, thread_mask(rx->settings->bind_thread) & all_threads_mask);
Willy Tarreau62292b22020-09-02 17:52:23 +0200160 return err;
161
162 bind_return:
163 if (errmsg && *errmsg)
164 memprintf(errmsg, "%s [fd %d]", *errmsg, rx->fd);
165
166 return err;
167
168 bind_close_return:
169 close(rx->fd);
170 goto bind_return;
171}
172
William Lallemand2fe7dd02018-09-11 16:51:29 +0200173/* This function changes the state from ASSIGNED to LISTEN. The socket is NOT
174 * enabled for polling. The return value is composed from ERR_NONE,
175 * ERR_RETRYABLE and ERR_FATAL. It may return a warning or an error message in
176 * <errmsg> if the message is at most <errlen> bytes long (including '\0').
177 * Note that <errmsg> may be NULL if <errlen> is also zero.
178 */
179static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen)
180{
William Lallemand2fe7dd02018-09-11 16:51:29 +0200181 int err;
Willy Tarreau9eda7a62020-09-02 18:02:00 +0200182 char *msg = NULL;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200183
184 err = ERR_NONE;
185
186 /* ensure we never return garbage */
187 if (errlen)
188 *errmsg = 0;
189
190 if (listener->state != LI_ASSIGNED)
191 return ERR_NONE; /* already bound */
192
Willy Tarreauad33acf2020-09-02 18:40:02 +0200193 if (!(listener->rx.flags & RX_F_BOUND)) {
194 msg = "receiving socket not bound";
195 goto err_return;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200196 }
Willy Tarreauad33acf2020-09-02 18:40:02 +0200197
Willy Tarreaua37b2442020-09-24 07:23:45 +0200198 listener_set_state(listener, LI_LISTEN);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200199 return err;
200
201 err_return:
202 if (msg && errlen)
Willy Tarreau9eda7a62020-09-02 18:02:00 +0200203 snprintf(errmsg, errlen, "%s [fd %d]", msg, listener->rx.fd);
William Lallemand2fe7dd02018-09-11 16:51:29 +0200204 return err;
205}
206
207/*
208 * Send FD over a unix socket
209 *
210 * <send_fd> is the FD to send
211 * <fd> is the fd of the unix socket to use for the transfer
212 *
213 * The iobuf variable could be use in the future to enhance the protocol.
214 */
215int send_fd_uxst(int fd, int send_fd)
216{
217 char iobuf[2];
218 struct iovec iov;
219 struct msghdr msghdr;
220
221 char cmsgbuf[CMSG_SPACE(sizeof(int))];
222 char buf[CMSG_SPACE(sizeof(int))];
223 struct cmsghdr *cmsg = (void *)buf;
224
225 int *fdptr;
226
227 iov.iov_base = iobuf;
228 iov.iov_len = sizeof(iobuf);
229
230 memset(&msghdr, 0, sizeof(msghdr));
231 msghdr.msg_iov = &iov;
232 msghdr.msg_iovlen = 1;
233
234 /* Now send the fds */
235 msghdr.msg_control = cmsgbuf;
236 msghdr.msg_controllen = CMSG_SPACE(sizeof(int));
237
238 cmsg = CMSG_FIRSTHDR(&msghdr);
239 cmsg->cmsg_len = CMSG_LEN(sizeof(int));
240 cmsg->cmsg_level = SOL_SOCKET;
241 cmsg->cmsg_type = SCM_RIGHTS;
242
243 fdptr = (int *)CMSG_DATA(cmsg);
244 memcpy(fdptr, &send_fd, sizeof(send_fd));
245
246 if (sendmsg(fd, &msghdr, 0) != sizeof(iobuf)) {
247 ha_warning("Failed to transfer socket\n");
248 return 1;
249 }
250
251 return 0;
252}
253
254/*
255 *
Joseph Herlant8bb32ae2018-11-25 11:43:27 -0800256 * This function works like uxst_connect_server but instead of creating a
William Lallemand2fe7dd02018-09-11 16:51:29 +0200257 * socket and establishing a connection, it creates a pair of connected
258 * sockets, and send one of them through the destination FD. The destination FD
Willy Tarreau3f4fa092019-07-17 16:42:04 +0200259 * is stored in conn->dst->sin_addr.s_addr during configuration parsing.
William Lallemand2fe7dd02018-09-11 16:51:29 +0200260 *
261 * conn->target may point either to a valid server or to a backend, depending
262 * on conn->target. Only OBJ_TYPE_PROXY and OBJ_TYPE_SERVER are supported. The
263 * <data> parameter is a boolean indicating whether there are data waiting for
264 * being sent or not, in order to adjust data write polling and on some
265 * platforms. The <delack> argument is ignored.
266 *
267 * Note that a pending send_proxy message accounts for data.
268 *
269 * It can return one of :
270 * - SF_ERR_NONE if everything's OK
271 * - SF_ERR_SRVTO if there are no more servers
272 * - SF_ERR_SRVCL if the connection was refused by the server
273 * - SF_ERR_PRXCOND if the connection has been limited by the proxy (maxconn)
274 * - SF_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...)
275 * - SF_ERR_INTERNAL for any other purely internal errors
276 * Additionally, in the case of SF_ERR_RESOURCE, an emergency log will be emitted.
277 *
278 * The connection's fd is inserted only when SF_ERR_NONE is returned, otherwise
279 * it's invalid and the caller has nothing to do.
280 */
Olivier Houchardfdcb0072019-05-06 18:32:29 +0200281static int sockpair_connect_server(struct connection *conn, int flags)
William Lallemand2fe7dd02018-09-11 16:51:29 +0200282{
283 int sv[2], fd, dst_fd = -1;
284
285 /* the FD is stored in the sockaddr struct */
Willy Tarreau3f4fa092019-07-17 16:42:04 +0200286 dst_fd = ((struct sockaddr_in *)conn->dst)->sin_addr.s_addr;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200287
William Lallemand2fe7dd02018-09-11 16:51:29 +0200288 if (obj_type(conn->target) != OBJ_TYPE_PROXY &&
289 obj_type(conn->target) != OBJ_TYPE_SERVER) {
290 conn->flags |= CO_FL_ERROR;
291 return SF_ERR_INTERNAL;
292 }
293
294 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
295 ha_alert("socketpair(): Cannot create socketpair. Giving up.\n");
296 conn->flags |= CO_FL_ERROR;
297 return SF_ERR_RESOURCE;
298 }
299
300 fd = conn->handle.fd = sv[1];
301
302 if (fd >= global.maxsock) {
303 /* do not log anything there, it's a normal condition when this option
304 * is used to serialize connections to a server !
305 */
306 ha_alert("socket(): not enough free sockets. Raise -n argument. Giving up.\n");
307 close(sv[0]);
308 close(sv[1]);
309 conn->err_code = CO_ER_CONF_FDLIM;
310 conn->flags |= CO_FL_ERROR;
311 return SF_ERR_PRXCOND; /* it is a configuration limit */
312 }
313
314 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
315 qfprintf(stderr,"Cannot set client socket to non blocking mode.\n");
316 close(sv[0]);
317 close(sv[1]);
318 conn->err_code = CO_ER_SOCK_ERR;
319 conn->flags |= CO_FL_ERROR;
320 return SF_ERR_INTERNAL;
321 }
322
William Lallemandc03eb012018-11-27 12:02:37 +0100323 if (master == 1 && (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)) {
324 ha_alert("Cannot set CLOEXEC on client socket.\n");
325 close(sv[0]);
326 close(sv[1]);
327 conn->err_code = CO_ER_SOCK_ERR;
328 conn->flags |= CO_FL_ERROR;
329 return SF_ERR_INTERNAL;
330 }
331
William Lallemand2fe7dd02018-09-11 16:51:29 +0200332 /* if a send_proxy is there, there are data */
Olivier Houchardfdcb0072019-05-06 18:32:29 +0200333 if (conn->send_proxy_ofs)
334 flags |= CONNECT_HAS_DATA;
William Lallemand2fe7dd02018-09-11 16:51:29 +0200335
336 if (global.tune.server_sndbuf)
337 setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &global.tune.server_sndbuf, sizeof(global.tune.server_sndbuf));
338
339 if (global.tune.server_rcvbuf)
340 setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &global.tune.server_rcvbuf, sizeof(global.tune.server_rcvbuf));
341
342 /* The new socket is sent on the other side, it should be retrieved and
343 * considered as an 'accept' socket on the server side */
344 if (send_fd_uxst(dst_fd, sv[0]) == -1) {
345 close(sv[0]);
346 close(sv[1]);
347 conn->err_code = CO_ER_SOCK_ERR;
348 conn->flags |= CO_FL_ERROR;
349 return SF_ERR_INTERNAL;
350 }
351
352 close(sv[0]); /* we don't need this side anymore */
353
354 conn->flags &= ~CO_FL_WAIT_L4_CONN;
355
356 conn->flags |= CO_FL_ADDR_TO_SET;
357
358 /* Prepare to send a few handshakes related to the on-wire protocol. */
359 if (conn->send_proxy_ofs)
360 conn->flags |= CO_FL_SEND_PROXY;
361
362 conn_ctrl_init(conn); /* registers the FD */
363 fdtab[fd].linger_risk = 0; /* no need to disable lingering */
364
365 if (conn_xprt_init(conn) < 0) {
366 conn_full_close(conn);
367 conn->flags |= CO_FL_ERROR;
368 return SF_ERR_RESOURCE;
369 }
370
William Lallemand2fe7dd02018-09-11 16:51:29 +0200371 return SF_ERR_NONE; /* connection is OK */
372}
373
374
375/*
Joseph Herlant8bb32ae2018-11-25 11:43:27 -0800376 * Receives a file descriptor transferred from a unix socket.
William Lallemand2fe7dd02018-09-11 16:51:29 +0200377 *
378 * Return -1 or a socket fd;
379 *
Joseph Herlant8bb32ae2018-11-25 11:43:27 -0800380 * The iobuf variable could be used in the future to enhance the protocol.
William Lallemand2fe7dd02018-09-11 16:51:29 +0200381 */
382int recv_fd_uxst(int sock)
383{
384 struct msghdr msghdr;
385 struct iovec iov;
386 char iobuf[2];
387
388 char cmsgbuf[CMSG_SPACE(sizeof(int))];
389 char buf[CMSG_SPACE(sizeof(int))];
390 struct cmsghdr *cmsg = (void *)buf;
391
392
393 int recv_fd = -1;
394 int ret = -1;
395
396 memset(&msghdr, 0, sizeof(msghdr));
397
398 iov.iov_base = iobuf;
399 iov.iov_len = sizeof(iobuf);
400
401 msghdr.msg_iov = &iov;
402 msghdr.msg_iovlen = 1;
403
404 msghdr.msg_control = cmsgbuf;
405 msghdr.msg_controllen = CMSG_SPACE(sizeof(int));
406
407 iov.iov_len = sizeof(iobuf);
408 iov.iov_base = iobuf;
409
410 while (1) {
411 ret = recvmsg(sock, &msghdr, 0);
412 if (ret == -1 && errno == EINTR)
413 continue;
414 else
415 break;
416 }
417
418 if (ret == -1)
419 return ret;
420
421 cmsg = CMSG_FIRSTHDR(&msghdr);
Willy Tarreau7d7ab432018-09-20 11:39:39 +0200422 if (cmsg && cmsg->cmsg_level == SOL_SOCKET &&
William Lallemand2fe7dd02018-09-11 16:51:29 +0200423 cmsg->cmsg_type == SCM_RIGHTS) {
424 size_t totlen = cmsg->cmsg_len -
425 CMSG_LEN(0);
426 memcpy(&recv_fd, CMSG_DATA(cmsg), totlen);
427 }
428 return recv_fd;
429}
430
Willy Tarreaucc8b6532020-10-13 17:27:34 +0200431/* Tests if the receiver supports accepting connections. Returns positive on
432 * success, 0 if not possible, negative if the socket is non-recoverable. In
433 * practice zero is never returned since we don't support suspending sockets.
434 * The real test consists in verifying we have a connected SOCK_STREAM of
435 * family AF_UNIX.
436 */
Willy Tarreau7d053e42020-10-15 09:19:43 +0200437static int sockpair_accepting_conn(const struct receiver *rx)
Willy Tarreaucc8b6532020-10-13 17:27:34 +0200438{
439 struct sockaddr sa;
440 socklen_t len;
441 int val;
442
443 len = sizeof(val);
444 if (getsockopt(rx->fd, SOL_SOCKET, SO_TYPE, &val, &len) == -1)
445 return -1;
446
447 if (val != SOCK_STREAM)
448 return -1;
449
450 len = sizeof(sa);
451 if (getsockname(rx->fd, &sa, &len) != 0)
452 return -1;
453
454 if (sa.sa_family != AF_UNIX)
455 return -1;
456
457 len = sizeof(val);
458 if (getsockopt(rx->fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == -1)
459 return -1;
460
461 /* Note: cannot be a listening socket, must be established */
462 if (val)
463 return -1;
464
465 return 1;
466}
467
Willy Tarreau344b8fc2020-10-15 09:43:31 +0200468/* Accept an incoming connection from listener <l>, and return it, as well as
469 * a CO_AC_* status code into <status> if not null. Null is returned on error.
470 * <l> must be a valid listener with a valid frontend.
471 */
472struct connection *sockpair_accept_conn(struct listener *l, int *status)
473{
474 struct proxy *p = l->bind_conf->frontend;
475 struct connection *conn = NULL;
476 int ret;
477 int cfd;
478
479 if ((cfd = recv_fd_uxst(l->rx.fd)) != -1)
480 fcntl(cfd, F_SETFL, O_NONBLOCK);
481
482 if (likely(cfd != -1)) {
483 /* Perfect, the connection was accepted */
484 conn = conn_new(&l->obj_type);
485 if (!conn)
486 goto fail_conn;
487
488 if (!sockaddr_alloc(&conn->src, NULL, 0))
489 goto fail_addr;
490
491 /* just like with UNIX sockets, only the family is filled */
492 conn->src->ss_family = AF_UNIX;
493 conn->handle.fd = cfd;
494 conn->flags |= CO_FL_ADDR_FROM_SET;
495 ret = CO_AC_DONE;
496 goto done;
497 }
498
499 switch (errno) {
500 case EAGAIN:
501 ret = CO_AC_DONE; /* nothing more to accept */
502 if (fdtab[l->rx.fd].ev & (FD_POLL_HUP|FD_POLL_ERR)) {
503 /* the listening socket might have been disabled in a shared
504 * process and we're a collateral victim. We'll just pause for
505 * a while in case it comes back. In the mean time, we need to
506 * clear this sticky flag.
507 */
508 _HA_ATOMIC_AND(&fdtab[l->rx.fd].ev, ~(FD_POLL_HUP|FD_POLL_ERR));
509 ret = CO_AC_PAUSE;
510 }
511 fd_cant_recv(l->rx.fd);
512 break;
513
514 case EINVAL:
515 /* might be trying to accept on a shut fd (eg: soft stop) */
516 ret = CO_AC_PAUSE;
517 break;
518
519 case EINTR:
520 case ECONNABORTED:
521 ret = CO_AC_RETRY;
522 break;
523
524 case ENFILE:
525 if (p)
526 send_log(p, LOG_EMERG,
527 "Proxy %s reached system FD limit (maxsock=%d). Please check system tunables.\n",
528 p->id, global.maxsock);
529 ret = CO_AC_PAUSE;
530 break;
531
532 case EMFILE:
533 if (p)
534 send_log(p, LOG_EMERG,
535 "Proxy %s reached process FD limit (maxsock=%d). Please check 'ulimit-n' and restart.\n",
536 p->id, global.maxsock);
537 ret = CO_AC_PAUSE;
538 break;
539
540 case ENOBUFS:
541 case ENOMEM:
542 if (p)
543 send_log(p, LOG_EMERG,
544 "Proxy %s reached system memory limit (maxsock=%d). Please check system tunables.\n",
545 p->id, global.maxsock);
546 ret = CO_AC_PAUSE;
547 break;
548
549 default:
550 /* unexpected result, let's give up and let other tasks run */
551 ret = CO_AC_YIELD;
552 }
553 done:
554 if (status)
555 *status = ret;
556 return conn;
557
558 fail_addr:
559 conn_free(conn);
560 conn = NULL;
561 fail_conn:
562 ret = CO_AC_PAUSE;
563 goto done;
564}
565
William Lallemand2fe7dd02018-09-11 16:51:29 +0200566/*
567 * Local variables:
568 * c-indent-level: 8
569 * c-basic-offset: 8
570 * End:
571 */