dns-stream: only read DNS packet data if we identified the peer properly

If we use TCP fastopen to connect to a DNS server via TCP, and it
responds really quickly between our connection attempt and our immediate
check back, then we have not identified the peer yet, and will not be
able to use the peer metadata to fill in our packet info.

Let's fix that, and simply not read from the socket until identification
is complete.

Fixes: #34956
This commit is contained in:
Lennart Poettering
2025-03-04 12:33:53 +00:00
committed by Luca Boccassi
parent 8113361e82
commit facc9439a7
+2 -1
View File
@@ -360,7 +360,8 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
}
}
while ((revents & (EPOLLIN|EPOLLHUP|EPOLLRDHUP)) &&
while (s->identified && /* Only read data once we identified the peer, because we cannot fill in the DNS packet meta info otherwise */
(revents & (EPOLLIN|EPOLLHUP|EPOLLRDHUP)) &&
(!s->read_packet ||
s->n_read < sizeof(s->read_size) + s->read_packet->size)) {