Sfoglia il codice sorgente

libnet: early return from updateSvcRecord if no addr available

Early return if the iface or its address is nil to make the whole
function slightly easier to read.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Albin Kerouanton 1 anno fa
parent
commit
d47b3ef4c9
1 ha cambiato i file con 36 aggiunte e 32 eliminazioni
  1. 36 32
      libnetwork/network.go

+ 36 - 32
libnetwork/network.go

@@ -1300,44 +1300,48 @@ func (n *Network) EndpointByID(id string) (*Endpoint, error) {
 	return ep, nil
 	return ep, nil
 }
 }
 
 
+// updateSvcRecord adds or deletes local DNS records for a given Endpoint.
 func (n *Network) updateSvcRecord(ep *Endpoint, isAdd bool) {
 func (n *Network) updateSvcRecord(ep *Endpoint, isAdd bool) {
+	iface := ep.Iface()
+	if iface == nil || iface.Address() == nil {
+		return
+	}
+
 	var ipv6 net.IP
 	var ipv6 net.IP
 	epName := ep.Name()
 	epName := ep.Name()
-	if iface := ep.Iface(); iface != nil && iface.Address() != nil {
-		myAliases := ep.MyAliases()
-		if iface.AddressIPv6() != nil {
-			ipv6 = iface.AddressIPv6().IP
-		}
-
-		serviceID := ep.svcID
-		if serviceID == "" {
-			serviceID = ep.ID()
-		}
-		if isAdd {
-			// If anonymous endpoint has an alias use the first alias
-			// for ip->name mapping. Not having the reverse mapping
-			// breaks some apps
-			if ep.isAnonymous() {
-				if len(myAliases) > 0 {
-					n.addSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
-				}
-			} else {
-				n.addSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
-			}
-			for _, alias := range myAliases {
-				n.addSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord")
+	myAliases := ep.MyAliases()
+	if iface.AddressIPv6() != nil {
+		ipv6 = iface.AddressIPv6().IP
+	}
+
+	serviceID := ep.svcID
+	if serviceID == "" {
+		serviceID = ep.ID()
+	}
+	if isAdd {
+		// If anonymous endpoint has an alias use the first alias
+		// for ip->name mapping. Not having the reverse mapping
+		// breaks some apps
+		if ep.isAnonymous() {
+			if len(myAliases) > 0 {
+				n.addSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
 			}
 			}
 		} else {
 		} else {
-			if ep.isAnonymous() {
-				if len(myAliases) > 0 {
-					n.deleteSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
-				}
-			} else {
-				n.deleteSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
-			}
-			for _, alias := range myAliases {
-				n.deleteSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord")
+			n.addSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
+		}
+		for _, alias := range myAliases {
+			n.addSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord")
+		}
+	} else {
+		if ep.isAnonymous() {
+			if len(myAliases) > 0 {
+				n.deleteSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
 			}
 			}
+		} else {
+			n.deleteSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord")
+		}
+		for _, alias := range myAliases {
+			n.deleteSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord")
 		}
 		}
 	}
 	}
 }
 }