plugin/forward: Fix UDP forwarding so a malformed upstream datagram wont block valid ones later (#8287)

* plugin/plugin: Fix UDP forwarding so a malformed upstream datagram wont block valid ones later

This PR fixes UDP forwarding so a malformed upstream datagram
does not prevent CoreDNS from accepting a subsequent valid response
before the existing read deadline.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Address review and add additonal tests

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Cover branch

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

---------

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2026-07-21 15:21:25 -07:00
committed by GitHub
parent d1a6ab0eb9
commit 989a188d13
2 changed files with 128 additions and 0 deletions

View File

@@ -186,6 +186,12 @@ func (p *Proxy) lookupDNS(_ctx context.Context, state request.Request, opts Opti
for {
ret, err = pc.c.ReadMsg()
if err != nil {
if p.transport.transportTypeFromConn(pc) == typeUDP &&
((ret == nil && errors.Is(err, dns.ErrShortRead)) ||
(ret != nil && ret.Id != state.Req.Id)) {
continue
}
if ret != nil && (state.Req.Id == ret.Id) && p.transport.transportTypeFromConn(pc) == typeUDP && shouldTruncateResponse(err) {
// For UDP, if the error is an overflow, we probably have an upstream misbehaving in some way.
// (e.g. sending >512 byte responses without an eDNS0 OPT RR).