Skip to content

Commit 8e0ea74

Browse files
authored
No SERVFAIL and no forwarding multicast names (#86)
* Return NXDOMAIN instead of SERVFAIL * Actually reorder template and return noerror
1 parent 0668c78 commit 8e0ea74

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ RUN \
1717
&& git clone --depth 1 -b v${COREDNS_VERSION} https://github.com/coredns/coredns \
1818
&& cp -rf plugins/* coredns/plugin/ \
1919
&& cd coredns \
20+
&& sed -i "/^template:template/d" plugin.cfg \
21+
&& sed -i "/^hosts:.*/a template:template" plugin.cfg \
2022
&& sed -i "/^forward:.*/i fallback:fallback" plugin.cfg \
2123
&& sed -i "/^hosts:.*/a mdns:mdns" plugin.cfg \
2224
&& sed -i "/route53:route53/d" plugin.cfg \

plugins/mdns/mdns.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (m MDNS) AddARecord(msg *dns.Msg, state *request.Request, name string, addr
6969
}
7070

7171
func (m MDNS) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
72+
// If systemd-resolved isn't available, plugin can't do anything. Pass to the next one.
7273
if m.Resolver == nil {
7374
return plugin.NextOrFailure(m.Name(), m.Next, ctx, w, r)
7475
}
@@ -99,14 +100,16 @@ func (m MDNS) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
99100
// There may be uncommon errors though so not swallowing it while debugging
100101
log.Debug(err)
101102

102-
} else if m.AddARecord(msg, &state, hostName, addresses) {
103+
} else {
104+
m.AddARecord(msg, &state, hostName, addresses)
103105
log.Debug(msg)
104-
w.WriteMsg(msg)
105-
return dns.RcodeSuccess, nil
106106
}
107107

108-
log.Debugf("No records found for '%s', forwarding to next plugin.", state.QName())
109-
return plugin.NextOrFailure(m.Name(), m.Next, ctx, w, r)
108+
// Plugin only processes A and AAAA type multicast queries (.local or single name)
109+
// Whether an answer was found or not this is end of the line, do not forward to external resolvers
110+
// Always return NOERROR since we are not authoritative for this domain
111+
w.WriteMsg(msg)
112+
return dns.RcodeSuccess, nil
110113
}
111114

112115
func GetPrimaryInterface(ctx context.Context, resolver *resolve1.Manager) int32 {

rootfs/usr/share/tempio/corefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
template ANY AAAA local.hass.io hassio {
1212
rcode NOERROR
1313
}
14+
template ANY A local.hass.io hassio {
15+
rcode NXDOMAIN
16+
}
1417
mdns
1518
forward . {{ join " " .servers }} {{ if len .locals | eq 0 }}dns://127.0.0.11{{ else }}{{ join " " .locals }}{{ end }} {
1619
except local.hass.io

0 commit comments

Comments
 (0)