From f8181b8875294e53009e79944f7eeb42893009e2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 27 Aug 2023 13:56:10 +0200 Subject: [PATCH 1/2] libnetwork: Endpoint.Iface, Endpoint.Interface remove redundant "if" Signed-off-by: Sebastiaan van Stijn --- libnetwork/endpoint_info.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/libnetwork/endpoint_info.go b/libnetwork/endpoint_info.go index f0b2afd9a2..7065c23b80 100644 --- a/libnetwork/endpoint_info.go +++ b/libnetwork/endpoint_info.go @@ -203,23 +203,13 @@ func (ep *Endpoint) Info() EndpointInfo { func (ep *Endpoint) Iface() *EndpointInterface { ep.mu.Lock() defer ep.mu.Unlock() - - if ep.iface != nil { - return ep.iface - } - - return nil + return ep.iface } func (ep *Endpoint) Interface() driverapi.InterfaceInfo { ep.mu.Lock() defer ep.mu.Unlock() - - if ep.iface != nil { - return ep.iface - } - - return nil + return ep.iface } // SetMacAddress allows the driver to set the mac address to the endpoint interface From 8b21609654bb05305a725a3fdc1ca48272631983 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 27 Aug 2023 14:37:10 +0200 Subject: [PATCH 2/2] libnetwork: remove Endpoint.Interface This method is not part of any interface, and identical to Endpoint.Iface, but one returns an Interface-type (driverapi.InterfaceInfo) and the other returns a concrete type (EndpointInterface). Interface-matching should generally happen on the receiver side, and this function was only used in a single location, and passed as argument to Driver.CreateEndpoint, which already matches the interface by accepting a driverapi.InterfaceInfo. Signed-off-by: Sebastiaan van Stijn --- libnetwork/endpoint_info.go | 6 ------ libnetwork/network.go | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/libnetwork/endpoint_info.go b/libnetwork/endpoint_info.go index 7065c23b80..edc813aa90 100644 --- a/libnetwork/endpoint_info.go +++ b/libnetwork/endpoint_info.go @@ -206,12 +206,6 @@ func (ep *Endpoint) Iface() *EndpointInterface { return ep.iface } -func (ep *Endpoint) Interface() driverapi.InterfaceInfo { - ep.mu.Lock() - defer ep.mu.Unlock() - return ep.iface -} - // SetMacAddress allows the driver to set the mac address to the endpoint interface // during the call to CreateEndpoint, if the mac address is not already set. func (epi *EndpointInterface) SetMacAddress(mac net.HardwareAddr) error { diff --git a/libnetwork/network.go b/libnetwork/network.go index 586994bcc1..a0fd365a1f 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -1085,7 +1085,7 @@ func (n *Network) addEndpoint(ep *Endpoint) error { return fmt.Errorf("failed to add endpoint: %v", err) } - err = d.CreateEndpoint(n.id, ep.id, ep.Interface(), ep.generic) + err = d.CreateEndpoint(n.id, ep.id, ep.Iface(), ep.generic) if err != nil { return types.InternalErrorf("failed to create endpoint %s on network %s: %v", ep.Name(), n.Name(), err)