Merge pull request #34665 from poettering/fastopen-fallback

resolved: fix MSG_FASTOPEN fallback logic
This commit is contained in:
Yu Watanabe
2024-10-10 03:21:35 +09:00
committed by GitHub
+10 -6
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <linux/if_arp.h>
#include <netinet/tcp.h>
#include <unistd.h>
@@ -205,6 +206,7 @@ static int dns_stream_identify(DnsStream *s) {
ssize_t dns_stream_writev(DnsStream *s, const struct iovec *iov, size_t iovcnt, int flags) {
ssize_t m;
int r;
assert(s);
assert(iov);
@@ -224,12 +226,14 @@ ssize_t dns_stream_writev(DnsStream *s, const struct iovec *iov, size_t iovcnt,
m = sendmsg(s->fd, &hdr, MSG_FASTOPEN);
if (m < 0) {
if (errno == EOPNOTSUPP) {
s->tfo_salen = 0;
if (connect(s->fd, &s->tfo_address.sa, s->tfo_salen) < 0)
return -errno;
if (ERRNO_IS_NOT_SUPPORTED(errno)) {
/* MSG_FASTOPEN not supported? Then try to connect() traditionally */
r = RET_NERRNO(connect(s->fd, &s->tfo_address.sa, s->tfo_salen));
s->tfo_salen = 0; /* connection is made */
if (r < 0 && r != -EINPROGRESS)
return r;
return -EAGAIN;
return -EAGAIN; /* In case of EINPROGRESS, EAGAIN or success: return EAGAIN, so that caller calls us again */
}
if (errno == EINPROGRESS)
return -EAGAIN;
@@ -565,7 +569,7 @@ int dns_stream_new(
if (tfo_address) {
s->tfo_address = *tfo_address;
s->tfo_salen = tfo_address->sa.sa_family == AF_INET6 ? sizeof(tfo_address->in6) : sizeof(tfo_address->in);
s->tfo_salen = SOCKADDR_LEN(*tfo_address);
}
*ret = TAKE_PTR(s);