Skip to content

Commit

Permalink
Revert "net: send EDNS(0) packet length in DNS query"
Browse files Browse the repository at this point in the history
This reverts https://go.dev/cl/385035. For 1.18 we will use a simple
change to increase the accepted DNS packet size, to handle what appear
to be broken resolvers that don't honor the 512 byte limit. For 1.19
we will restore CL 385035 to make a proper EDNS request, so that it
has more testing time before it goes out in a release.

For #6464
For #21160
For #44135
For #51127
For #51153

Change-Id: Ie4a0eb85ca0a6a73bee5cd4cfc6b7d2a15ef259f
Reviewed-on: https://go-review.googlesource.com/c/go/+/386014
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
  • Loading branch information
ianlancetaylor committed Feb 15, 2022
1 parent d199cef commit d3c9ef5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 74 deletions.
19 changes: 1 addition & 18 deletions src/net/dnsclient_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ const (
// to be used as a useTCP parameter to exchange
useTCPOnly = true
useUDPOrTCP = false

// Requested DNS packet size.
// Value taken from https://dnsflagday.net/2020/.
maxDNSPacketSize = 1232
)

var (
Expand All @@ -60,19 +56,6 @@ func newRequest(q dnsmessage.Question) (id uint16, udpReq, tcpReq []byte, err er
if err := b.Question(q); err != nil {
return 0, nil, nil, err
}

// Accept packets up to maxDNSPacketSize. RFC 6891.
if err := b.StartAdditionals(); err != nil {
return 0, nil, nil, err
}
var rh dnsmessage.ResourceHeader
if err := rh.SetEDNS0(maxDNSPacketSize, dnsmessage.RCodeSuccess, false); err != nil {
return 0, nil, nil, err
}
if err := b.OPTResource(rh, dnsmessage.OPTResource{}); err != nil {
return 0, nil, nil, err
}

tcpReq, err = b.Finish()
udpReq = tcpReq[2:]
l := len(tcpReq) - 2
Expand All @@ -99,7 +82,7 @@ func dnsPacketRoundTrip(c Conn, id uint16, query dnsmessage.Question, b []byte)
return dnsmessage.Parser{}, dnsmessage.Header{}, err
}

b = make([]byte, maxDNSPacketSize)
b = make([]byte, 512) // see RFC 1035
for {
n, err := c.Read(b)
if err != nil {
Expand Down
57 changes: 1 addition & 56 deletions src/net/dnsclient_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ func (f *fakeDNSPacketConn) Close() error {
func TestIgnoreDNSForgeries(t *testing.T) {
c, s := Pipe()
go func() {
b := make([]byte, maxDNSPacketSize)
b := make([]byte, 512)
n, err := s.Read(b)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -2161,58 +2161,3 @@ func TestRootNS(t *testing.T) {
t.Errorf("records = [%v]; want [%v]", strings.Join(records, " "), want[0])
}
}

// Test that we advertise support for a larger DNS packet size.
// This isn't a great test as it just tests the dnsmessage package
// against itself.
func TestDNSPacketSize(t *testing.T) {
fake := fakeDNSServer{
rh: func(_, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) {
if len(q.Additionals) == 0 {
t.Error("missing EDNS record")
} else if opt, ok := q.Additionals[0].Body.(*dnsmessage.OPTResource); !ok {
t.Errorf("additional record type %T, expected OPTResource", q.Additionals[0])
} else if len(opt.Options) != 0 {
t.Errorf("found %d Options, expected none", len(opt.Options))
} else {
got := int(q.Additionals[0].Header.Class)
t.Logf("EDNS packet size == %d", got)
if got != maxDNSPacketSize {
t.Errorf("EDNS packet size == %d, want %d", got, maxDNSPacketSize)
}
}

// Hand back a dummy answer to verify that
// LookupIPAddr completes.
r := dnsmessage.Message{
Header: dnsmessage.Header{
ID: q.Header.ID,
Response: true,
RCode: dnsmessage.RCodeSuccess,
},
Questions: q.Questions,
}
if q.Questions[0].Type == dnsmessage.TypeA {
r.Answers = []dnsmessage.Resource{
{
Header: dnsmessage.ResourceHeader{
Name: q.Questions[0].Name,
Type: dnsmessage.TypeA,
Class: dnsmessage.ClassINET,
Length: 4,
},
Body: &dnsmessage.AResource{
A: TestAddr,
},
},
}
}
return r, nil
},
}

r := &Resolver{PreferGo: true, Dial: fake.DialContext}
if _, err := r.LookupIPAddr(context.Background(), "go.dev"); err != nil {
t.Errorf("lookup failed: %v", err)
}
}

0 comments on commit d3c9ef5

Please sign in to comment.