ignore Z flag in queries, clear Z flag in automatic replies (#976)

This commit is contained in:
Yaroslav Kolomiiets 2019-05-23 20:54:24 +01:00 committed by Miek Gieben
parent fbd426fefa
commit 1545072057
3 changed files with 29 additions and 3 deletions

View File

@ -35,9 +35,6 @@ func defaultMsgAcceptFunc(dh Header) MsgAcceptAction {
return MsgReject
}
if isZero := dh.Bits&_Z != 0; isZero {
return MsgReject
}
if dh.Qdcount != 1 {
return MsgReject
}

View File

@ -571,6 +571,7 @@ func (srv *Server) serveDNS(m []byte, w *response) {
req.SetRcodeFormatError(req)
// Are we allowed to delete any OPT records here?
req.Ns, req.Answer, req.Extra = nil, nil, nil
req.Zero = false
w.WriteMsg(req)
fallthrough

View File

@ -187,6 +187,34 @@ func TestServing(t *testing.T) {
}
}
// Verify that the server responds to a query with Z flag on, ignoring the flag, and does not echoes it back
func TestServeIgnoresZFlag(t *testing.T) {
HandleFunc("example.com.", AnotherHelloServer)
s, addrstr, err := RunLocalUDPServer(":0")
if err != nil {
t.Fatalf("unable to run test server: %v", err)
}
defer s.Shutdown()
c := new(Client)
m := new(Msg)
// Test the Z flag is not echoed
m.SetQuestion("example.com.", TypeTXT)
m.Zero = true
r, _, err := c.Exchange(m, addrstr)
if err != nil {
t.Fatal("failed to exchange example.com with +zflag", err)
}
if r.Zero {
t.Error("the response should not have Z flag set - even for a query which does")
}
if r.Rcode != RcodeSuccess {
t.Errorf("expected rcode %v, got %v", RcodeSuccess, r.Rcode)
}
}
func TestServingTLS(t *testing.T) {
HandleFunc("miek.nl.", HelloServer)
HandleFunc("example.com.", AnotherHelloServer)