diff --git a/libnetwork/libnetwork_internal_test.go b/libnetwork/libnetwork_internal_test.go index 000ba7e5e6..9eb7f6bab5 100644 --- a/libnetwork/libnetwork_internal_test.go +++ b/libnetwork/libnetwork_internal_test.go @@ -411,10 +411,10 @@ func TestSRVServiceQuery(t *testing.T) { t.Fatal(err) } - // Try resolving a service name with invalid protocol, should fail.. - _, _, err = ep.Info().Sandbox().ResolveService("_http._icmp.web.swarm") - if err == nil { - t.Fatal(err) + // Service name with invalid protocol name. Should fail without error + _, ip, err = ep.Info().Sandbox().ResolveService("_http._icmp.web.swarm") + if len(ip) != 0 { + t.Fatal("Valid response for invalid service name") } } diff --git a/libnetwork/resolver.go b/libnetwork/resolver.go index 8ba3860b70..b9eb4f3ff2 100644 --- a/libnetwork/resolver.go +++ b/libnetwork/resolver.go @@ -255,6 +255,9 @@ func (r *resolver) handleSRVQuery(svc string, query *dns.Msg) (*dns.Msg, error) if err != nil { return nil, err } + if len(srv) == 0 { + return nil, nil + } if len(srv) != len(ip) { return nil, fmt.Errorf("invalid reply for SRV query %s", svc) } diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index 8a659b038c..52e9bb6783 100644 --- a/libnetwork/sandbox.go +++ b/libnetwork/sandbox.go @@ -444,16 +444,16 @@ func (sb *sandbox) ResolveService(name string) ([]*net.SRV, []net.IP, error) { log.Debugf("Service name To resolve: %v", name) + // There are DNS implementaions that allow SRV queries for names not in + // the format defined by RFC 2782. Hence specific validations checks are + // not done parts := strings.Split(name, ".") if len(parts) < 3 { - return nil, nil, fmt.Errorf("invalid service name, %s", name) + return nil, nil, nil } portName := parts[0] proto := parts[1] - if proto != "_tcp" && proto != "_udp" { - return nil, nil, fmt.Errorf("invalid protocol in service, %s", name) - } svcName := strings.Join(parts[2:], ".") for _, ep := range sb.getConnectedEndpoints() {