Skip to content

Commit

Permalink
Return noerror if any answers found (A or AAAA) (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 committed Mar 4, 2022
1 parent 6f3f20e commit 96a587b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions plugins/mdns/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ func (m MDNS) AddARecord(msg *dns.Msg, state *request.Request, name string, addr
// Add A and AAAA record for name (if it exists) to msg.
// A records need to be returned in A queries, this function
// provides common code for doing so.
// Success is always returned if any answers found, even if they don't match question type
// A noerror on A and nxdomain on AAAA (or vice versa) breaks some clients (musl)
if len(addresses) == 0 {
return false
}

resolved := false
ifc_index := 0
for i := 0; i < len(addresses); i++ {
addr := addresses[i]
Expand All @@ -55,15 +59,13 @@ func (m MDNS) AddARecord(msg *dns.Msg, state *request.Request, name string, addr
} else {
msg.Answer = append(msg.Answer, &dns.A{Hdr: aheader, A: ip})
}
resolved = true

} else if addr.V1 == syscall.AF_INET6 && state.QType() == dns.TypeAAAA {
aaaaheader := dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 60}
msg.Answer = append(msg.Answer, &dns.AAAA{Hdr: aaaaheader, AAAA: ip})
resolved = true
}
}
return resolved
return true
}

func (m MDNS) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
Expand Down
2 changes: 2 additions & 0 deletions plugins/mdns/mdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func TestAddARecord(t *testing.T) {
"myservice.local 60 IN A 192.168.1.1",
"myservice.local 60 IN A 10.1.1.1",
}, true},
{"success on AAAA if only A found", "mymachine.local", dns.TypeAAAA, nilResponseWriter{}, 1, ipv4, []string{}, true},
{"success on A if only AAAA found", "mymachine.local", dns.TypeA, nilResponseWriter{}, 1, ipv6, []string{}, true},
}
for _, tc := range testCases {
m := MDNS{nil, nil, tc.ifc}
Expand Down
4 changes: 2 additions & 2 deletions plugins/mdns/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func setup(c *caddy.Controller) error {
var m MDNS
conn, err := dbus.ConnectSystemBus()
if err != nil {
log.Error("could not connect to systemd resolver due to %s", err)
log.Error("could not connect to systemd resolver due to: ", err)
log.Error("mdns and llmnr urls will not resolve in without this")

m = MDNS{
Resolver: nil,
Ifc: 0,
Ifc: 0,
}
} else {
bus_object := conn.Object("org.freedesktop.resolve1", "/org/freedesktop/resolve1")
Expand Down

0 comments on commit 96a587b

Please sign in to comment.