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