Browse code

Relax SRV name validation and fix external SRV query handling

Signed-off-by: Santhosh Manohar <santhosh@docker.com>

Santhosh Manohar authored on 2016/08/13 07:40:39
Showing 3 changed files
... ...
@@ -411,10 +411,10 @@ func TestSRVServiceQuery(t *testing.T) {
411 411
 		t.Fatal(err)
412 412
 	}
413 413
 
414
-	// Try resolving a service name with invalid protocol, should fail..
415
-	_, _, err = ep.Info().Sandbox().ResolveService("_http._icmp.web.swarm")
416
-	if err == nil {
417
-		t.Fatal(err)
414
+	// Service name with invalid protocol name. Should fail without error
415
+	_, ip, err = ep.Info().Sandbox().ResolveService("_http._icmp.web.swarm")
416
+	if len(ip) != 0 {
417
+		t.Fatal("Valid response for invalid service name")
418 418
 	}
419 419
 }
420 420
 
... ...
@@ -255,6 +255,9 @@ func (r *resolver) handleSRVQuery(svc string, query *dns.Msg) (*dns.Msg, error)
255 255
 	if err != nil {
256 256
 		return nil, err
257 257
 	}
258
+	if len(srv) == 0 {
259
+		return nil, nil
260
+	}
258 261
 	if len(srv) != len(ip) {
259 262
 		return nil, fmt.Errorf("invalid reply for SRV query %s", svc)
260 263
 	}
... ...
@@ -444,16 +444,16 @@ func (sb *sandbox) ResolveService(name string) ([]*net.SRV, []net.IP, error) {
444 444
 
445 445
 	log.Debugf("Service name To resolve: %v", name)
446 446
 
447
+	// There are DNS implementaions that allow SRV queries for names not in
448
+	// the format defined by RFC 2782. Hence specific validations checks are
449
+	// not done
447 450
 	parts := strings.Split(name, ".")
448 451
 	if len(parts) < 3 {
449
-		return nil, nil, fmt.Errorf("invalid service name, %s", name)
452
+		return nil, nil, nil
450 453
 	}
451 454
 
452 455
 	portName := parts[0]
453 456
 	proto := parts[1]
454
-	if proto != "_tcp" && proto != "_udp" {
455
-		return nil, nil, fmt.Errorf("invalid protocol in service, %s", name)
456
-	}
457 457
 	svcName := strings.Join(parts[2:], ".")
458 458
 
459 459
 	for _, ep := range sb.getConnectedEndpoints() {