diff options
Diffstat (limited to 'libpod/networking_linux.go')
-rw-r--r-- | libpod/networking_linux.go | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 0db0896cf..a312f5a0c 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -23,6 +23,7 @@ import ( "github.com/containers/common/libnetwork/etchosts" "github.com/containers/common/libnetwork/types" "github.com/containers/common/pkg/config" + "github.com/containers/common/pkg/machine" "github.com/containers/common/pkg/netns" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/libpod/events" @@ -62,7 +63,7 @@ const ( // This is need because a HostIP of 127.0.0.1 would now allow the gvproxy forwarder to reach to open ports. // For machine the HostIP must only be used by gvproxy and never in the VM. func (c *Container) convertPortMappings() []types.PortMapping { - if !c.runtime.config.Engine.MachineEnabled || len(c.config.PortMappings) == 0 { + if !machine.IsGvProxyBased() || len(c.config.PortMappings) == 0 { return c.config.PortMappings } // if we run in a machine VM we have to ignore the host IP part @@ -74,7 +75,7 @@ func (c *Container) convertPortMappings() []types.PortMapping { return newPorts } -func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOptions) (types.NetworkOptions, error) { +func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOptions) types.NetworkOptions { opts := types.NetworkOptions{ ContainerID: c.config.ID, ContainerName: getCNIPodName(c), @@ -88,7 +89,7 @@ func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOpt } else { opts.Networks = networkOpts } - return opts, nil + return opts } type RootlessNetNS struct { @@ -653,10 +654,7 @@ func (r *Runtime) configureNetNS(ctr *Container, ctrNS ns.NetNS) (status map[str return nil, nil } - netOpts, err := ctr.getNetworkOptions(networks) - if err != nil { - return nil, err - } + netOpts := ctr.getNetworkOptions(networks) netStatus, err := r.setUpNetwork(ctrNS.Path(), netOpts) if err != nil { return nil, err @@ -814,10 +812,7 @@ func (r *Runtime) teardownCNI(ctr *Container) error { } if !ctr.config.NetMode.IsSlirp4netns() && len(networks) > 0 { - netOpts, err := ctr.getNetworkOptions(networks) - if err != nil { - return err - } + netOpts := ctr.getNetworkOptions(networks) return r.teardownNetwork(ctr.state.NetNS.Path(), netOpts) } return nil @@ -1000,11 +995,9 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e if c.state.NetNS == nil { if networkNSPath := c.joinedNetworkNSPath(); networkNSPath != "" { if result, err := c.inspectJoinedNetworkNS(networkNSPath); err == nil { - if basicConfig, err := resultToBasicNetworkConfig(result); err == nil { - // fallback to dummy configuration - settings.InspectBasicNetworkConfig = basicConfig - return settings, nil - } + // fallback to dummy configuration + settings.InspectBasicNetworkConfig = resultToBasicNetworkConfig(result) + return settings, nil } // do not propagate error inspecting a joined network ns logrus.Errorf("Inspecting network namespace: %s of container %s: %v", networkNSPath, c.ID(), err) @@ -1047,14 +1040,8 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e result := netStatus[name] addedNet := new(define.InspectAdditionalNetwork) addedNet.NetworkID = name - - basicConfig, err := resultToBasicNetworkConfig(result) - if err != nil { - return nil, err - } addedNet.Aliases = opts.Aliases - - addedNet.InspectBasicNetworkConfig = basicConfig + addedNet.InspectBasicNetworkConfig = resultToBasicNetworkConfig(result) settings.Networks[name] = addedNet } @@ -1074,11 +1061,7 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e if len(netStatus) == 1 { for _, status := range netStatus { - basicConfig, err := resultToBasicNetworkConfig(status) - if err != nil { - return nil, err - } - settings.InspectBasicNetworkConfig = basicConfig + settings.InspectBasicNetworkConfig = resultToBasicNetworkConfig(status) } } return settings, nil @@ -1152,7 +1135,7 @@ func (c *Container) inspectJoinedNetworkNS(networkns string) (q types.StatusBloc // resultToBasicNetworkConfig produces an InspectBasicNetworkConfig from a CNI // result -func resultToBasicNetworkConfig(result types.StatusBlock) (define.InspectBasicNetworkConfig, error) { +func resultToBasicNetworkConfig(result types.StatusBlock) define.InspectBasicNetworkConfig { config := define.InspectBasicNetworkConfig{} interfaceNames := make([]string, 0, len(result.Interfaces)) for interfaceName := range result.Interfaces { @@ -1190,7 +1173,7 @@ func resultToBasicNetworkConfig(result types.StatusBlock) (define.InspectBasicNe config.AdditionalMacAddresses = append(config.AdditionalMacAddresses, netInt.MacAddress.String()) } } - return config, nil + return config } type logrusDebugWriter struct { |