core/dnsserver: add opt-in opcode admission (#8469)

Keep miekg/dns's default request policy unless a plugin explicitly registers an additional opcode. Aggregate the policy at the listener, then enforce it again after zone routing so mixed server blocks on one socket remain isolated.

Apply the same policy to UDP, TCP, and DNS-over-TLS while preserving TSIG verification and the one-question requirement.

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
houyuwushang
2026-08-26 16:41:28 +08:00
committed by GitHub
parent b8720090b5
commit 70b5d6b5be
7 changed files with 378 additions and 14 deletions

View File

@@ -184,6 +184,17 @@ func (c *Config) AddPlugin(m plugin.Plugin) {
c.Plugin = append(c.Plugin, m)
}
// AllowOpcode permits a non-default DNS opcode to reach this config's plugin chain
// on UDP, TCP, and DNS-over-TLS listeners. Plugins should call it during setup.
// The listener still requires exactly one question, and configs that do not opt in
// continue to reject the opcode.
func (c *Config) AllowOpcode(opcode int) {
if c.allowedOpcodes == nil {
c.allowedOpcodes = make(map[int]struct{})
}
c.allowedOpcodes[opcode] = struct{}{}
}
// registerHandler adds a handler to a site's handler registration. Handlers
//
// use this to announce that they exist to other plugin.
@@ -276,6 +287,7 @@ func propagateConfigParams(configs []*Config) {
c.IdleTimeout = c.firstConfigInBlock.IdleTimeout
c.MaxTCPQueries = c.firstConfigInBlock.MaxTCPQueries
c.TsigSecret = c.firstConfigInBlock.TsigSecret
c.allowedOpcodes = c.firstConfigInBlock.allowedOpcodes
// Propagate HTTPRequestValidateFunc so that custom path validators work in
// multi-transport blocks. Otherwise HTTPS 404s on non-"/dns-query" paths.