]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: fix fastopen fallback
authorLennart Poettering <lennart@poettering.net>
Mon, 7 Oct 2024 11:03:51 +0000 (13:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 8 Oct 2024 10:09:34 +0000 (12:09 +0200)
We should not invalidate the socket address size before we use it.

Fixes: #34579
src/resolve/resolved-dns-stream.c

index 8c1512006af30e5bfaeac4c1aab9645be6be5593..c3e825abf431fcbcafa39370b63e982812f357a2 100644 (file)
@@ -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;