Add client.UDPsize
This allows a client to set a default UDPSize with resorting to EDNS0 headers 'n stuff.
This commit is contained in:
parent
3fca11e695
commit
e81b46d580
|
@ -29,6 +29,7 @@ type Conn struct {
|
||||||
// A Client defines parameters for a DNS client.
|
// A Client defines parameters for a DNS client.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Net string // if "tcp" a TCP query will be initiated, otherwise an UDP one (default is "" for UDP)
|
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
|
DialTimeout time.Duration // net.DialTimeout (ns), defaults to 2 * 1e9
|
||||||
ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections (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
|
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))
|
co.SetWriteDeadline(time.Now().Add(timeout))
|
||||||
defer co.Close()
|
defer co.Close()
|
||||||
opt := m.IsEdns0()
|
opt := m.IsEdns0()
|
||||||
|
// If EDNS0 is used use that for size
|
||||||
if opt != nil && opt.UDPSize() >= MinMsgSize {
|
if opt != nil && opt.UDPSize() >= MinMsgSize {
|
||||||
co.UDPSize = opt.UDPSize()
|
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
|
co.TsigSecret = c.TsigSecret
|
||||||
if err = co.WriteMsg(m); err != nil {
|
if err = co.WriteMsg(m); err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -167,6 +173,9 @@ func (co *Conn) ReadMsg() (*Msg, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p = p[:n]
|
p = p[:n]
|
||||||
|
if n > 512 {
|
||||||
|
println("HALLO")
|
||||||
|
}
|
||||||
if err := m.Unpack(p); err != nil {
|
if err := m.Unpack(p); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,4 +218,11 @@ func TestServingLargeResponses(t *testing.T) {
|
||||||
t.Logf("Failed to fail exchange, this should generate packet error")
|
t.Logf("Failed to fail exchange, this should generate packet error")
|
||||||
t.Fail()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue