Skip to content

Commit 40f4a78

Browse files
committed
Merge pull request hashicorp#18 from gonzojive/hostname-questions
Make MDNSService respond to questions for A/AAAA records about its hostname.
2 parents 827e8b3 + 5699c71 commit 40f4a78

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

zone.go

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ func (m *MDNSService) Records(q dns.Question) []dns.RR {
138138
return m.serviceRecords(q)
139139
case m.instanceAddr:
140140
return m.instanceRecords(q)
141+
case m.HostName:
142+
if q.Qtype == dns.TypeA || q.Qtype == dns.TypeAAAA {
143+
return m.instanceRecords(q)
144+
}
145+
fallthrough
141146
default:
142147
return nil
143148
}

zone_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,40 @@ func TestMDNSService_InstanceAddr_TXT(t *testing.T) {
219219
t.Fatalf("TXT record mismatch for %v: got %v, want %v", recs[0], got, want)
220220
}
221221
}
222+
223+
func TestMDNSService_HostNameQuery(t *testing.T) {
224+
s := makeService(t)
225+
for _, test := range []struct {
226+
q dns.Question
227+
want []dns.RR
228+
}{
229+
{
230+
dns.Question{Name: "testhost.", Qtype: dns.TypeA},
231+
[]dns.RR{&dns.A{
232+
Hdr: dns.RR_Header{
233+
Name: "testhost.",
234+
Rrtype: dns.TypeA,
235+
Class: dns.ClassINET,
236+
Ttl: 10,
237+
},
238+
A: net.IP([]byte{192, 168, 0, 42}),
239+
}},
240+
},
241+
{
242+
dns.Question{Name: "testhost.", Qtype: dns.TypeAAAA},
243+
[]dns.RR{&dns.AAAA{
244+
Hdr: dns.RR_Header{
245+
Name: "testhost.",
246+
Rrtype: dns.TypeAAAA,
247+
Class: dns.ClassINET,
248+
Ttl: 10,
249+
},
250+
AAAA: net.ParseIP("2620:0:1000:1900:b0c2:d0b2:c411:18bc"),
251+
}},
252+
},
253+
} {
254+
if got := s.Records(test.q); !reflect.DeepEqual(got, test.want) {
255+
t.Errorf("hostname query failed: s.Records(%v) = %v, want %v", test.q, got, test.want)
256+
}
257+
}
258+
}

0 commit comments

Comments
 (0)