Browse Source

libnetwork/osl: Namespace.Restore: conditionally fetch IPs

We're only using the results if the interface doesn't have an address
yet, so skip this step if we don't use it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 year ago
parent
commit
47f9e70385
1 changed files with 4 additions and 4 deletions
  1. 4 4
      libnetwork/osl/namespace_linux.go

+ 4 - 4
libnetwork/osl/namespace_linux.go

@@ -506,10 +506,6 @@ func (n *Namespace) Restore(interfaces map[Iface][]IfaceOption, routes []*types.
 			// due to the docker network connect/disconnect, so the dstName should
 			// restore from the namespace
 			for _, link := range links {
-				addresses, err := n.nlHandle.AddrList(link, netlink.FAMILY_V4)
-				if err != nil {
-					return err
-				}
 				ifaceName := link.Attrs().Name
 				if i.dstName == "vxlan" && strings.HasPrefix(ifaceName, "vxlan") {
 					i.dstName = ifaceName
@@ -517,6 +513,10 @@ func (n *Namespace) Restore(interfaces map[Iface][]IfaceOption, routes []*types.
 				}
 				// find the interface name by ip
 				if i.address != nil {
+					addresses, err := n.nlHandle.AddrList(link, netlink.FAMILY_V4)
+					if err != nil {
+						return err
+					}
 					for _, addr := range addresses {
 						if addr.IPNet.String() == i.address.String() {
 							i.dstName = ifaceName