diff --git a/client.go b/client.go index db9c4601..349c12d5 100644 --- a/client.go +++ b/client.go @@ -29,6 +29,7 @@ type Conn struct { // A Client defines parameters for a DNS client. type Client struct { Net string // if "tcp" a TCP query will be initiated, otherwise an UDP one (default is "" for UDP) + UDPSize uint16 // Minimum receive buffer for UDP messages DialTimeout time.Duration // net.DialTimeout (ns), defaults to 2 * 1e9 ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections (ns), defaults to 2 * 1e9 WriteTimeout time.Duration // net.Conn.SetWriteTimeout value for connections (ns), defaults to 2 * 1e9 @@ -136,9 +137,14 @@ func (c *Client) exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro co.SetWriteDeadline(time.Now().Add(timeout)) defer co.Close() opt := m.IsEdns0() + // If EDNS0 is used use that for size if opt != nil && opt.UDPSize() >= MinMsgSize { co.UDPSize = opt.UDPSize() } + // Otherwise use the client's configured UDP size + if opt == nil && c.UDPSize >= MinMsgSize { + co.UDPSize = c.UDPSize + } co.TsigSecret = c.TsigSecret if err = co.WriteMsg(m); err != nil { return nil, 0, err @@ -167,6 +173,9 @@ func (co *Conn) ReadMsg() (*Msg, error) { return nil, err } p = p[:n] + if n > 512 { + println("HALLO") + } if err := m.Unpack(p); err != nil { return nil, err } diff --git a/server_test.go b/server_test.go index 4dc9bde8..ee51a2d3 100644 --- a/server_test.go +++ b/server_test.go @@ -218,4 +218,11 @@ func TestServingLargeResponses(t *testing.T) { t.Logf("Failed to fail exchange, this should generate packet error") t.Fail() } + // But this must work again + c.UDPSize = 7000 + _, _, err = c.Exchange(m, "127.0.0.1:10000") + if err != nil { + t.Logf("Failed to exchange: %s", err.Error()) + t.Fail() + } }