core/dnsserver: add Config.UDPDecorateWriterFunc for external plugins (#8257)

* core/dnsserver: add Config.UDPDecorateWriterFunc for external plugins

Allow external plugins to install a dns.DecorateWriter (an existing
miekg/dns Server field CoreDNS never sets) on plain-UDP servers, e.g.
for per-socket write disciplines or overload protection; UDP is the
only transport without a Max*-style concurrency setting.

The field is a factory called once per Server in ServePacket, so each
socket gets its own decorator under multisocket; the *Server argument
is the same value handlers see via ctx.Value(dnsserver.Key{}). Follows
the Config.HTTPRequestValidateFunc precedent, including server-block
propagation and the ServePacket-time lookup over s.zones. Nil (the
default) changes nothing.

Signed-off-by: Ryan Brewster <rpb@anthropic.com>

* core/dnsserver: select UDP writer decorator deterministically in NewServer

Review feedback: s.zones is a map, so choosing the decorator in
ServePacket was non-deterministic when several server blocks share a
listener. Select it in NewServer from the group slice instead (stable
config order, last one set wins) and document the resolution order.

Signed-off-by: Ryan Brewster <rpb@anthropic.com>

* core/dnsserver: group decorator selection with the other last-writer-wins fields

Pure move: place it next to ProxyProtoConnPolicy, the existing field
resolved the same way at the same point.

Signed-off-by: Ryan Brewster <rpb@anthropic.com>

---------

Signed-off-by: Ryan Brewster <rpb@anthropic.com>
This commit is contained in:
rpb-ant
2026-07-09 13:15:13 -04:00
committed by GitHub
parent 7df9238255
commit 2d106be341
4 changed files with 87 additions and 1 deletions

View File

@@ -279,6 +279,10 @@ func propagateConfigParams(configs []*Config) {
// Propagate HTTPRequestValidateFunc so that custom path validators work in
// multi-transport blocks. Otherwise HTTPS 404s on non-"/dns-query" paths.
c.HTTPRequestValidateFunc = c.firstConfigInBlock.HTTPRequestValidateFunc
// Propagate UDPDecorateWriterFunc so a decorator configured once in a
// server block applies to the block's UDP listener(s).
c.UDPDecorateWriterFunc = c.firstConfigInBlock.UDPDecorateWriterFunc
}
}