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>
This commit is contained in:
parent
ea729aea4a
commit
d47b3ef4c9
1 changed files with 35 additions and 31 deletions
|
@ -1300,44 +1300,48 @@ func (n *Network) EndpointByID(id string) (*Endpoint, error) {
|
|||
return ep, nil
|
||||
}
|
||||
|
||||
// updateSvcRecord adds or deletes local DNS records for a given Endpoint.
|
||||
func (n *Network) updateSvcRecord(ep *Endpoint, isAdd bool) {
|
||||
iface := ep.Iface()
|
||||
if iface == nil || iface.Address() == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var ipv6 net.IP
|
||||
epName := ep.Name()
|
||||
if iface := ep.Iface(); iface != nil && iface.Address() != nil {
|
||||
myAliases := ep.MyAliases()
|
||||
if iface.AddressIPv6() != nil {
|
||||
ipv6 = iface.AddressIPv6().IP
|
||||
}
|
||||
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")
|
||||
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 {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue