mirror of https://github.com/hashicorp/consul
Merge pull request #2690 from zeroae/f-simple-rfc2782
RFC 2782 support with optional .service tagpull/2786/head
commit
3103f7f673
|
@ -304,12 +304,20 @@ func (d *DNSServer) dispatch(network string, req, resp *dns.Msg) {
|
||||||
// Split into the label parts
|
// Split into the label parts
|
||||||
labels := dns.SplitDomainName(qName)
|
labels := dns.SplitDomainName(qName)
|
||||||
|
|
||||||
// The last label is either "node", "service", "query", or a datacenter name
|
// The last label is either "node", "service", "query", "_<protocol>", or a datacenter name
|
||||||
PARSE:
|
PARSE:
|
||||||
n := len(labels)
|
n := len(labels)
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
goto INVALID
|
goto INVALID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this is a SRV query the "service" label is optional, we add it back to use the
|
||||||
|
// existing code-path.
|
||||||
|
if req.Question[0].Qtype == dns.TypeSRV && strings.HasPrefix(labels[n-1], "_") {
|
||||||
|
labels = append(labels, "service")
|
||||||
|
n = n + 1
|
||||||
|
}
|
||||||
|
|
||||||
switch labels[n-1] {
|
switch labels[n-1] {
|
||||||
case "service":
|
case "service":
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
|
|
|
@ -3488,8 +3488,16 @@ func TestDNS_ServiceLookup_SRV_RFC(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
questions := []string{
|
||||||
|
"_db._master.service.dc1.consul.",
|
||||||
|
"_db._master.service.consul.",
|
||||||
|
"_db._master.dc1.consul.",
|
||||||
|
"_db._master.consul.",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, question := range questions {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetQuestion("_db._master.service.consul.", dns.TypeSRV)
|
m.SetQuestion(question, dns.TypeSRV)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
addr, _ := srv.agent.config.ClientListener("", srv.agent.config.Ports.DNS)
|
addr, _ := srv.agent.config.ClientListener("", srv.agent.config.Ports.DNS)
|
||||||
|
@ -3531,6 +3539,8 @@ func TestDNS_ServiceLookup_SRV_RFC(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestDNS_ServiceLookup_SRV_RFC_TCP_Default(t *testing.T) {
|
func TestDNS_ServiceLookup_SRV_RFC_TCP_Default(t *testing.T) {
|
||||||
dir, srv := makeDNSServer(t)
|
dir, srv := makeDNSServer(t)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
@ -3555,8 +3565,16 @@ func TestDNS_ServiceLookup_SRV_RFC_TCP_Default(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
questions := []string{
|
||||||
|
"_db._tcp.service.dc1.consul.",
|
||||||
|
"_db._tcp.service.consul.",
|
||||||
|
"_db._tcp.dc1.consul.",
|
||||||
|
"_db._tcp.consul.",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, question := range questions {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetQuestion("_db._tcp.service.consul.", dns.TypeSRV)
|
m.SetQuestion(question, dns.TypeSRV)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
addr, _ := srv.agent.config.ClientListener("", srv.agent.config.Ports.DNS)
|
addr, _ := srv.agent.config.ClientListener("", srv.agent.config.Ports.DNS)
|
||||||
|
@ -3598,6 +3616,8 @@ func TestDNS_ServiceLookup_SRV_RFC_TCP_Default(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestDNS_ServiceLookup_FilterACL(t *testing.T) {
|
func TestDNS_ServiceLookup_FilterACL(t *testing.T) {
|
||||||
confFn := func(c *Config) {
|
confFn := func(c *Config) {
|
||||||
c.ACLMasterToken = "root"
|
c.ACLMasterToken = "root"
|
||||||
|
|
|
@ -138,7 +138,7 @@ foobar.node.dc1.consul. 0 IN A 10.1.10.12
|
||||||
|
|
||||||
The format for RFC 2782 SRV lookups is:
|
The format for RFC 2782 SRV lookups is:
|
||||||
|
|
||||||
_<service>._<protocol>.service[.datacenter][.domain]
|
_<service>._<protocol>[.service][.datacenter][.domain]
|
||||||
|
|
||||||
Per [RFC 2782](https://tools.ietf.org/html/rfc2782), SRV queries should use
|
Per [RFC 2782](https://tools.ietf.org/html/rfc2782), SRV queries should use
|
||||||
underscores, `_`, as a prefix to the `service` and `protocol` values in a query to
|
underscores, `_`, as a prefix to the `service` and `protocol` values in a query to
|
||||||
|
|
Loading…
Reference in New Issue