X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fip.c;h=08d32f21b382937f8f4974533e67bc9dc896cf3f;hb=2cee425af0f8c425a410ff12a51f05a175a0c80b;hp=04b86060fa42cd23e31ed36b0641fb71e509cad3;hpb=80fea873648ca2ab2e592999a336c59cf054ab55;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/ip.c b/src/src/ip.c index 04b86060f..08d32f21b 100644 --- a/src/src/ip.c +++ b/src/src/ip.c @@ -2,12 +2,12 @@ * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2016 */ +/* Copyright (c) University of Cambridge 1995 - 2017 */ /* See the file NOTICE for conditions of use and distribution. */ /* Functions for doing things with sockets. With the advent of IPv6 this has got messier, so that it's worth pulling out the code into separate functions -that other parts of Exim can call, expecially as there are now several +that other parts of Exim can call, especially as there are now several different places in the code where sockets are used. */ @@ -175,12 +175,14 @@ Arguments: address the remote address, in text form port the remote port timeout a timeout (zero for indefinite timeout) + fastopen TRUE iff TCP_FASTOPEN can be used Returns: 0 on success; -1 on failure, with errno set */ int -ip_connect(int sock, int af, const uschar *address, int port, int timeout) +ip_connect(int sock, int af, const uschar *address, int port, int timeout, + BOOL fastopen) { struct sockaddr_in s_in4; struct sockaddr *s_ptr; @@ -221,7 +223,32 @@ timer, thereby allowing the inbuilt OS timeout to operate. */ callout_address = string_sprintf("[%s]:%d", address, port); sigalrm_seen = FALSE; if (timeout > 0) alarm(timeout); -rc = connect(sock, s_ptr, s_len); + +#if defined(TCP_FASTOPEN) && defined(MSG_FASTOPEN) +/* TCP Fast Open, if the system has a cookie from a previous call to +this peer, can send data in the SYN packet. The peer can send data +before it gets our ACK of its SYN,ACK - the latter is useful for +the SMTP banner. Is there any usage where the former might be? +We might extend the ip_connect() args for data if so. For now, +connect in FASTOPEN mode but with zero data. +*/ + +if (fastopen) + { + if ((rc = sendto(sock, NULL, 0, MSG_FASTOPEN | MSG_DONTWAIT, s_ptr, s_len)) < 0) + if (errno == EINPROGRESS) /* the expected case */ + rc = 0; + else if(errno == EOPNOTSUPP) + { + DEBUG(D_transport) + debug_printf("Tried TCP Fast Open but apparently not enabled by sysctl\n"); + rc = connect(sock, s_ptr, s_len); + } + } +else +#endif + rc = connect(sock, s_ptr, s_len); + save_errno = errno; alarm(0); @@ -277,6 +304,7 @@ int namelen, port; host_item shost; host_item *h; int af = 0, fd, fd4 = -1, fd6 = -1; +BOOL fastopen = tcp_fastopen_ok && type == SOCK_STREAM; shost.next = NULL; shost.address = NULL; @@ -319,7 +347,7 @@ else /* Try to connect to the server - test each IP till one works */ -for (h = &shost; h != NULL; h = h->next) +for (h = &shost; h; h = h->next) { fd = Ustrchr(h->address, ':') != 0 ? fd6 < 0 ? (fd6 = ip_socket(type, af = AF_INET6)) : fd6 @@ -332,7 +360,7 @@ for (h = &shost; h != NULL; h = h->next) } for(port = portlo; port <= porthi; port++) - if (ip_connect(fd, af, h->address, port, timeout) == 0) + if (ip_connect(fd, af, h->address, port, timeout, fastopen) == 0) { if (fd != fd6) close(fd6); if (fd != fd4) close(fd4); @@ -430,7 +458,7 @@ ip_keepalive(int sock, const uschar *address, BOOL torf) { int fodder = 1; if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, - (uschar *)(&fodder), sizeof(fodder)) != 0) + US (&fodder), sizeof(fodder)) != 0) log_write(0, LOG_MAIN, "setsockopt(SO_KEEPALIVE) on connection %s %s " "failed: %s", torf? "to":"from", address, strerror(errno)); } @@ -465,7 +493,7 @@ if (time_left <= 0) do { - struct timeval tv = { time_left, 0 }; + struct timeval tv = { .tv_sec = time_left, .tv_usec = 0 }; FD_ZERO (&select_inset); FD_SET (fd, &select_inset);