From 62efdf81734c6648986c2e8083dd2c99df544fcd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Oct 2024 13:03:51 +0200 Subject: [PATCH] resolved: fix fastopen fallback We should not invalidate the socket address size before we use it. Fixes: #34579 (cherry picked from commit 5699e4c2d470a12c922c4b7c86a8987837911626) (cherry picked from commit 964f7772ad0ff637db80ae0a9e0afb41a40f5b04) (cherry picked from commit 4dca5688cb4c97f9072fe1c668923b2e56bfdf15) (cherry picked from commit 969f4f3ea1163a5caa2b22ca05ea68aaed97034b) --- src/resolve/resolved-dns-stream.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index 50b069abee..6a5358a248 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -205,6 +205,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 +225,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;