[fpc-pascal] Buffer size for TCP DNS queries in netdb
Michael Van Canneyt
michael at freepascal.org
Sat Sep 26 11:07:22 CEST 2020
On Sat, 26 Sep 2020, Noel Duffy via fpc-pascal wrote:
> Hi all,
>
> I've spent some time this past couple of weeks reading through the DNS
> resolver code in netdb and poring over RFCs that specify the protocol with a
> view to adding support for additional resource record queries. Things like
> TXT, SOA, and so forth. I'm using netdb from fpc 3.2.0 as the starting point.
> That code only supports querying DNS over UDP. Because TXT records can be up
> to 64k in size, they frequently get too big to fit inside a UDP packet. The
> RFCs mandate that resolvers must fall back to TCP in that case. That's the
> part I'm currently looking at.
>
> The maximum size for a DNS response over TCP is 65,535 octets. The netdb code
> defines a type TPayload that's a 512 octet buffer for receiving DNS
> responses. That's the largest response possible over UDP. The simplest path
> forward for me is to extend that buffer from 512 octets to 65,535. While that
> increase in size would hardly register on most machines, I wonder whether it
> might be too much on some of the more memory-restricted platforms that FPC
> supports. DOS, for instance. I also see IFDEFs for Android in this code.
>
> The alternative is to use different types for TCP queries, or to have the
> buffer allocated dynamically.
>
> To restate the question, is 64k too much overhead for DNS queries? That
> overhead would be present on all queries, regardless of whether UDP or TCP
> was used.
I would then prefer to allocate a dynamic buffer. A simple "Array of Byte" can
easily be managed with SetLength() and it is automatically disposed of when
not needed.
Michael.
More information about the fpc-pascal
mailing list