Respond to _services._dns-sd._udp.<domain> dns question
This commit is contained in:
parent
a57b761c4d
commit
d456efdb2f
24
zone.go
24
zone.go
@ -33,6 +33,7 @@ type MDNSService struct {
|
|||||||
|
|
||||||
serviceAddr string // Fully qualified service address
|
serviceAddr string // Fully qualified service address
|
||||||
instanceAddr string // Fully qualified instance address
|
instanceAddr string // Fully qualified instance address
|
||||||
|
enumAddr string // _services._dns-sd._udp.<domain>
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateFQDN returns an error if the passed string is not a fully qualified
|
// validateFQDN returns an error if the passed string is not a fully qualified
|
||||||
@ -123,6 +124,7 @@ func NewMDNSService(instance, service, domain, hostName string, port int, ips []
|
|||||||
TXT: txt,
|
TXT: txt,
|
||||||
serviceAddr: fmt.Sprintf("%s.%s.", trimDot(service), trimDot(domain)),
|
serviceAddr: fmt.Sprintf("%s.%s.", trimDot(service), trimDot(domain)),
|
||||||
instanceAddr: fmt.Sprintf("%s.%s.%s.", instance, trimDot(service), trimDot(domain)),
|
instanceAddr: fmt.Sprintf("%s.%s.%s.", instance, trimDot(service), trimDot(domain)),
|
||||||
|
enumAddr: fmt.Sprintf("_services._dns-sd._udp.%s.", trimDot(domain)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +136,8 @@ func trimDot(s string) string {
|
|||||||
// Records returns DNS records in response to a DNS question.
|
// Records returns DNS records in response to a DNS question.
|
||||||
func (m *MDNSService) Records(q dns.Question) []dns.RR {
|
func (m *MDNSService) Records(q dns.Question) []dns.RR {
|
||||||
switch q.Name {
|
switch q.Name {
|
||||||
|
case m.enumAddr:
|
||||||
|
return m.serviceEnum(q)
|
||||||
case m.serviceAddr:
|
case m.serviceAddr:
|
||||||
return m.serviceRecords(q)
|
return m.serviceRecords(q)
|
||||||
case m.instanceAddr:
|
case m.instanceAddr:
|
||||||
@ -148,6 +152,26 @@ func (m *MDNSService) Records(q dns.Question) []dns.RR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MDNSService) serviceEnum(q dns.Question) []dns.RR {
|
||||||
|
switch q.Qtype {
|
||||||
|
case dns.TypeANY:
|
||||||
|
fallthrough
|
||||||
|
case dns.TypePTR:
|
||||||
|
rr := &dns.PTR{
|
||||||
|
Hdr: dns.RR_Header{
|
||||||
|
Name: q.Name,
|
||||||
|
Rrtype: dns.TypePTR,
|
||||||
|
Class: dns.ClassINET,
|
||||||
|
Ttl: defaultTTL,
|
||||||
|
},
|
||||||
|
Ptr: m.serviceAddr,
|
||||||
|
}
|
||||||
|
return []dns.RR{rr}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// serviceRecords is called when the query matches the service name
|
// serviceRecords is called when the query matches the service name
|
||||||
func (m *MDNSService) serviceRecords(q dns.Question) []dns.RR {
|
func (m *MDNSService) serviceRecords(q dns.Question) []dns.RR {
|
||||||
switch q.Qtype {
|
switch q.Qtype {
|
||||||
|
Loading…
Reference in New Issue
Block a user