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>
| ... | ... |
@@ -1300,44 +1300,48 @@ func (n *Network) EndpointByID(id string) (*Endpoint, error) {
|
| 1300 | 1300 |
return ep, nil |
| 1301 | 1301 |
} |
| 1302 | 1302 |
|
| 1303 |
+// updateSvcRecord adds or deletes local DNS records for a given Endpoint. |
|
| 1303 | 1304 |
func (n *Network) updateSvcRecord(ep *Endpoint, isAdd bool) {
|
| 1305 |
+ iface := ep.Iface() |
|
| 1306 |
+ if iface == nil || iface.Address() == nil {
|
|
| 1307 |
+ return |
|
| 1308 |
+ } |
|
| 1309 |
+ |
|
| 1304 | 1310 |
var ipv6 net.IP |
| 1305 | 1311 |
epName := ep.Name() |
| 1306 |
- if iface := ep.Iface(); iface != nil && iface.Address() != nil {
|
|
| 1307 |
- myAliases := ep.MyAliases() |
|
| 1308 |
- if iface.AddressIPv6() != nil {
|
|
| 1309 |
- ipv6 = iface.AddressIPv6().IP |
|
| 1310 |
- } |
|
| 1311 |
- |
|
| 1312 |
- serviceID := ep.svcID |
|
| 1313 |
- if serviceID == "" {
|
|
| 1314 |
- serviceID = ep.ID() |
|
| 1315 |
- } |
|
| 1316 |
- if isAdd {
|
|
| 1317 |
- // If anonymous endpoint has an alias use the first alias |
|
| 1318 |
- // for ip->name mapping. Not having the reverse mapping |
|
| 1319 |
- // breaks some apps |
|
| 1320 |
- if ep.isAnonymous() {
|
|
| 1321 |
- if len(myAliases) > 0 {
|
|
| 1322 |
- n.addSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1323 |
- } |
|
| 1324 |
- } else {
|
|
| 1325 |
- n.addSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1326 |
- } |
|
| 1327 |
- for _, alias := range myAliases {
|
|
| 1328 |
- n.addSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord") |
|
| 1312 |
+ myAliases := ep.MyAliases() |
|
| 1313 |
+ if iface.AddressIPv6() != nil {
|
|
| 1314 |
+ ipv6 = iface.AddressIPv6().IP |
|
| 1315 |
+ } |
|
| 1316 |
+ |
|
| 1317 |
+ serviceID := ep.svcID |
|
| 1318 |
+ if serviceID == "" {
|
|
| 1319 |
+ serviceID = ep.ID() |
|
| 1320 |
+ } |
|
| 1321 |
+ if isAdd {
|
|
| 1322 |
+ // If anonymous endpoint has an alias use the first alias |
|
| 1323 |
+ // for ip->name mapping. Not having the reverse mapping |
|
| 1324 |
+ // breaks some apps |
|
| 1325 |
+ if ep.isAnonymous() {
|
|
| 1326 |
+ if len(myAliases) > 0 {
|
|
| 1327 |
+ n.addSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1329 | 1328 |
} |
| 1330 | 1329 |
} else {
|
| 1331 |
- if ep.isAnonymous() {
|
|
| 1332 |
- if len(myAliases) > 0 {
|
|
| 1333 |
- n.deleteSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1334 |
- } |
|
| 1335 |
- } else {
|
|
| 1336 |
- n.deleteSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1337 |
- } |
|
| 1338 |
- for _, alias := range myAliases {
|
|
| 1339 |
- n.deleteSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord") |
|
| 1330 |
+ n.addSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1331 |
+ } |
|
| 1332 |
+ for _, alias := range myAliases {
|
|
| 1333 |
+ n.addSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord") |
|
| 1334 |
+ } |
|
| 1335 |
+ } else {
|
|
| 1336 |
+ if ep.isAnonymous() {
|
|
| 1337 |
+ if len(myAliases) > 0 {
|
|
| 1338 |
+ n.deleteSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1340 | 1339 |
} |
| 1340 |
+ } else {
|
|
| 1341 |
+ n.deleteSvcRecords(ep.ID(), epName, serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") |
|
| 1342 |
+ } |
|
| 1343 |
+ for _, alias := range myAliases {
|
|
| 1344 |
+ n.deleteSvcRecords(ep.ID(), alias, serviceID, iface.Address().IP, ipv6, false, "updateSvcRecord") |
|
| 1341 | 1345 |
} |
| 1342 | 1346 |
} |
| 1343 | 1347 |
} |