Update client_truncate.go

Signed-off-by: songee2020 <61627765+songee2020@users.noreply.github.com>
This commit is contained in:
songee2020 2025-04-11 04:50:26 -03:00 committed by GitHub
parent 0d6e834066
commit b2e02f4500
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,14 +10,14 @@ func TruncateDNSMessage(request *dns.Msg, response *dns.Msg, headroom int) (*buf
maxLen := 512 maxLen := 512
if edns0Option := request.IsEdns0(); edns0Option != nil { if edns0Option := request.IsEdns0(); edns0Option != nil {
if udpSize := int(edns0Option.UDPSize()); udpSize > 512 { if udpSize := int(edns0Option.UDPSize()); udpSize > 512 {
dns.Compress = true response.Compress = true
} }
} }
responseLen := response.Len() responseLen := response.Len()
if responseLen > maxLen { if responseLen > maxLen {
copyResponse := *response copyResponse := *response
response = &copyResponse response = &copyResponse
dns.Compress = true dresponse.Compress = true
response.Truncate(maxLen) response.Truncate(maxLen)
} }
buffer := buf.NewSize(headroom*2 + 1 + maxLen) buffer := buf.NewSize(headroom*2 + 1 + maxLen)