Do not expand query UDP buffer size if already set to a smaller value (#5602)

Signed-off-by: Krzysztof Narkiewicz <knarkiewicz@bloomberg.net>

Signed-off-by: Krzysztof Narkiewicz <knarkiewicz@bloomberg.net>
Co-authored-by: Krzysztof Narkiewicz <knarkiewicz@bloomberg.net>
This commit is contained in:
Chris Narkiewicz
2022-09-07 14:53:30 +01:00
committed by GitHub
parent 0511ca2e4d
commit 07159c8d87
2 changed files with 81 additions and 60 deletions

View File

@@ -1,4 +1,4 @@
// Package bufsize implements a plugin that modifies EDNS0 buffer size.
// Package bufsize implements a plugin that clamps EDNS0 buffer size preventing packet fragmentation.
package bufsize
import (
@@ -17,10 +17,9 @@ type Bufsize struct {
// ServeDNS implements the plugin.Handler interface.
func (buf Bufsize) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
if option := r.IsEdns0(); option != nil {
if option := r.IsEdns0(); option != nil && int(option.UDPSize()) > buf.Size {
option.SetUDPSize(uint16(buf.Size))
}
return plugin.NextOrFailure(buf.Name(), buf.Next, ctx, w, r)
}