Skip to content

Commit

Permalink
Merge pull request moby#47956 from thaJeztah/cleanup_getDefaultNetwor…
Browse files Browse the repository at this point in the history
…kSettings

daemon: cleanup getDefaultNetworkSettings
  • Loading branch information
thaJeztah authored Jun 12, 2024
2 parents bcd280a + 2154103 commit 4fec999
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions daemon/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (daemon *Daemon) ContainerInspectCurrent(ctx context.Context, name string,
SecondaryIPAddresses: ctr.NetworkSettings.SecondaryIPAddresses,
SecondaryIPv6Addresses: ctr.NetworkSettings.SecondaryIPv6Addresses,
},
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(ctr.NetworkSettings.Networks),
DefaultNetworkSettings: getDefaultNetworkSettings(ctr.NetworkSettings.Networks),
Networks: apiNetworks,
}

Expand Down Expand Up @@ -247,18 +247,20 @@ func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, err

// getDefaultNetworkSettings creates the deprecated structure that holds the information
// about the bridge network for a container.
func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
var settings types.DefaultNetworkSettings

if defaultNetwork, ok := networks[networktypes.NetworkBridge]; ok && defaultNetwork.EndpointSettings != nil {
settings.EndpointID = defaultNetwork.EndpointID
settings.Gateway = defaultNetwork.Gateway
settings.GlobalIPv6Address = defaultNetwork.GlobalIPv6Address
settings.GlobalIPv6PrefixLen = defaultNetwork.GlobalIPv6PrefixLen
settings.IPAddress = defaultNetwork.IPAddress
settings.IPPrefixLen = defaultNetwork.IPPrefixLen
settings.IPv6Gateway = defaultNetwork.IPv6Gateway
settings.MacAddress = defaultNetwork.MacAddress
func getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
nw, ok := networks[networktypes.NetworkBridge]
if !ok || nw.EndpointSettings == nil {
return types.DefaultNetworkSettings{}
}

return types.DefaultNetworkSettings{
EndpointID: nw.EndpointSettings.EndpointID,
Gateway: nw.EndpointSettings.Gateway,
GlobalIPv6Address: nw.EndpointSettings.GlobalIPv6Address,
GlobalIPv6PrefixLen: nw.EndpointSettings.GlobalIPv6PrefixLen,
IPAddress: nw.EndpointSettings.IPAddress,
IPPrefixLen: nw.EndpointSettings.IPPrefixLen,
IPv6Gateway: nw.EndpointSettings.IPv6Gateway,
MacAddress: nw.EndpointSettings.MacAddress,
}
return settings
}

0 comments on commit 4fec999

Please sign in to comment.