dns: return NXDOMAIN for DHCP leases once they expire
This commit is contained in:
parent
fa82132962
commit
70edcab16b
@ -448,7 +448,12 @@ func (s *Server) resolveSubname(hostname string, q dns.Question) (dns.RR, error)
|
||||
|
||||
if lower := strings.ToLower(q.Name); lower == hostname+"." ||
|
||||
lower == hostname+"."+s.domain+"." {
|
||||
host, _ := s.hostByName(hostname)
|
||||
host, ok := s.hostByName(hostname)
|
||||
if !ok {
|
||||
// The corresponding DHCP lease might have expired, but this
|
||||
// handler is still installed on the mux.
|
||||
return nil, nil // NXDOMAIN
|
||||
}
|
||||
if q.Qtype == dns.TypeA {
|
||||
return dns.NewRR(q.Name + " 3600 IN A " + host)
|
||||
}
|
||||
@ -482,7 +487,7 @@ func (s *Server) subnameHandler(hostname string) func(w dns.ResponseWriter, r *d
|
||||
w.WriteMsg(m)
|
||||
return
|
||||
}
|
||||
log.Fatal(err)
|
||||
log.Fatalf("question %#v: %v", r.Question[0], err)
|
||||
}
|
||||
if rr != nil {
|
||||
m := new(dns.Msg)
|
||||
|
@ -187,6 +187,11 @@ func TestDHCP(t *testing.T) {
|
||||
Addr: net.IP{192, 168, 42, 150},
|
||||
Expiry: expired,
|
||||
},
|
||||
{
|
||||
Hostname: "aged",
|
||||
Addr: net.IP{192, 168, 42, 42},
|
||||
Expiry: time.Now().Add(1 * time.Minute),
|
||||
},
|
||||
})
|
||||
|
||||
t.Run("testtarget.lan. (expired)", func(t *testing.T) {
|
||||
@ -203,6 +208,23 @@ func TestDHCP(t *testing.T) {
|
||||
t.Fatalf("unexpected rcode: got %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
s.SetLeases([]dhcp4d.Lease{
|
||||
{
|
||||
Hostname: "aged",
|
||||
Addr: net.IP{192, 168, 42, 42},
|
||||
Expiry: expired,
|
||||
},
|
||||
})
|
||||
|
||||
t.Run("aged.lan. (expired)", func(t *testing.T) {
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("aged.lan.", dns.TypeA)
|
||||
s.Mux.ServeDNS(r, m)
|
||||
if got, want := r.response.Rcode, dns.RcodeNameError; got != want {
|
||||
t.Fatalf("unexpected rcode: got %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestHostname(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user