Large refactor of EDNS0 UDP packet size handling.

This was kinda strange before, with a lot of cargo-cult copied code,
and no clear strategy.

Now it works like this:

When talking upstream we always add a pseudoheader, and set the
UDP packet size to --edns-packet-max unless we've had problems
talking to a server, when it's reduced to 1280 if that fixes things.

Answering queries from downstream, we get the answer (either from
upstream or local data) If local data won't fit the advertised size
(or 512 if there's not pseudoheader) return truncated. If upstream
returns truncated, do likewise. If upstream is OK, but the answer is
too big for downstream, truncate the answer.
This commit is contained in:
Simon Kelley
2024-11-23 22:38:41 +00:00
parent e778a28eee
commit e5e8c14d87
6 changed files with 157 additions and 184 deletions

View File

@@ -2204,11 +2204,10 @@ int dnskey_keytag(int alg, int flags, unsigned char *key, int keylen)
}
size_t dnssec_generate_query(struct dns_header *header, unsigned char *end, char *name,
int class, int id, int type, int edns_pktsz)
int class, int id, int type)
{
unsigned char *p;
size_t ret;
header->qdcount = htons(1);
header->ancount = htons(0);
header->nscount = htons(0);
@@ -2228,12 +2227,7 @@ size_t dnssec_generate_query(struct dns_header *header, unsigned char *end, char
PUTSHORT(type, p);
PUTSHORT(class, p);
ret = add_do_bit(header, p - (unsigned char *)header, end);
if (find_pseudoheader(header, ret, NULL, &p, NULL, NULL))
PUTSHORT(edns_pktsz, p);
return ret;
return add_do_bit(header, p - (unsigned char *)header, end);
}
int errflags_to_ede(int status)