mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #1393 from sanimej/2782
Relax SRV name validation and fix external SRV query handling
This commit is contained in:
commit
30b53a73c1
3 changed files with 11 additions and 8 deletions
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue