resolved: set stream type during DnsStream creation

The DnsStreamType was added to track different types of DNS TCP streams,
instead of refcounting all of them together.  However, the stream type was
not actually set into the stream->type field, so while the reference count
was correctly incremented per-stream-type, the reference count was always
decremented in the cleanup function for stream type 0, leading to
underflow for the type 0 stream (unsigned) refcount, and preventing new
type 0 streams from being created.

Since type 0 is DNS_STREAM_LOOKUP, which is used to communicate with
upstream nameservers, once the refcount underflows the stub resolver
no longer is able to successfully fall back to TCP upstream lookups
for any truncated UDP packets.

This was found because lookups of A records with a large number of
addresses, too much to fit into a single 512 byte DNS UDP reply,
were causing getaddrinfo() to fall back to TCP and trigger this bug,
which then caused the TCP fallback for later large record lookups
to fail with 'connection timed out; no servers could be reached'.

The stream type was introduced in commit:
652ba568c6
This commit is contained in:
Dan Streetman 2019-10-23 14:47:59 -04:00 committed by Yu Watanabe
parent f2106b1789
commit 1c089741d3
1 changed files with 1 additions and 0 deletions

View File

@ -515,6 +515,7 @@ int dns_stream_new(
.n_ref = 1,
.fd = -1,
.protocol = protocol,
.type = type,
};
r = ordered_set_ensure_allocated(&s->write_queue, &dns_packet_hash_ops);