aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorDoug Rabson <dfr@rabson.org>2022-08-27 15:13:24 +0100
committerDoug Rabson <dfr@rabson.org>2022-09-05 10:20:50 +0100
commit212b11c34cf366e6408cb889a5a07660bdabb3e6 (patch)
treee0611cedce0f59e206ccef21478e398d662b2451 /libpod
parenteab4291d996e8aab34f97d79d76816afa976687e (diff)
downloadpodman-212b11c34cf366e6408cb889a5a07660bdabb3e6.tar.gz
podman-212b11c34cf366e6408cb889a5a07660bdabb3e6.tar.bz2
podman-212b11c34cf366e6408cb889a5a07660bdabb3e6.zip
libpod: Factor out handling of slirp4netns and net=none
[NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_common.go35
-rw-r--r--libpod/container_internal_freebsd.go13
-rw-r--r--libpod/container_internal_linux.go43
-rw-r--r--libpod/networking_unsupported.go5
4 files changed, 65 insertions, 31 deletions
diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go
index 11e791063..f44b8a625 100644
--- a/libpod/container_internal_common.go
+++ b/libpod/container_internal_common.go
@@ -1919,14 +1919,7 @@ func (c *Container) generateResolvConf() error {
// when we add network dns server we also have to add the search domains
search = networkSearchDomains
// slirp4netns has a built in DNS forwarder.
- if c.config.NetMode.IsSlirp4netns() {
- slirp4netnsDNS, err := GetSlirp4netnsDNS(c.slirp4netnsSubnet)
- if err != nil {
- logrus.Warn("Failed to determine Slirp4netns DNS: ", err.Error())
- } else {
- nameservers = append(nameservers, slirp4netnsDNS.String())
- }
- }
+ nameservers = c.addSlirp4netnsDNS(nameservers)
}
if len(c.config.DNSSearch) > 0 || len(c.runtime.config.Containers.DNSSearches) > 0 {
@@ -1970,19 +1963,7 @@ func (c *Container) checkForIPv6(netStatus map[string]types.StatusBlock) (bool,
}
}
- if c.config.NetMode.IsSlirp4netns() {
- ctrNetworkSlipOpts := []string{}
- if c.config.NetworkOptions != nil {
- ctrNetworkSlipOpts = append(ctrNetworkSlipOpts, c.config.NetworkOptions["slirp4netns"]...)
- }
- slirpOpts, err := parseSlirp4netnsNetworkOptions(c.runtime, ctrNetworkSlipOpts)
- if err != nil {
- return false, err
- }
- return slirpOpts.enableIPv6, nil
- }
-
- return false, nil
+ return c.isSlirp4netnsIPv6()
}
// Add a new nameserver to the container's resolv.conf, ensuring that it is the
@@ -2046,16 +2027,8 @@ func (c *Container) getHostsEntries() (etchosts.HostEntries, error) {
}
entries = etchosts.HostEntries{{IP: ip.String(), Names: names}}
default:
- // check for net=none
- if !c.config.CreateNetNS {
- for _, ns := range c.config.Spec.Linux.Namespaces {
- if ns.Type == spec.NetworkNamespace {
- if ns.Path == "" {
- entries = etchosts.HostEntries{{IP: "127.0.0.1", Names: names}}
- }
- break
- }
- }
+ if c.hasNetNone() {
+ entries = etchosts.HostEntries{{IP: "127.0.0.1", Names: names}}
}
}
return entries, nil
diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go
index aa4983291..5936df590 100644
--- a/libpod/container_internal_freebsd.go
+++ b/libpod/container_internal_freebsd.go
@@ -464,3 +464,16 @@ func (c *Container) setMountLabel(g *generate.Generator) {
func (c *Container) setCgroupsPath(g *generate.Generator) error {
return nil
}
+
+func (c *Container) addSlirp4netnsDNS(nameservers []string) []string {
+ return nameservers
+}
+
+func (c *Container) isSlirp4netnsIPv6() (bool, error) {
+ return false, nil
+}
+
+// check for net=none
+func (c *Container) hasNetNone() bool {
+ return c.state.NetworkJail == ""
+}
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 752ecae77..52ebece58 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -770,3 +770,46 @@ func (c *Container) setCgroupsPath(g *generate.Generator) error {
g.SetLinuxCgroupsPath(cgroupPath)
return nil
}
+
+func (c *Container) addSlirp4netnsDNS(nameservers []string) []string {
+ // slirp4netns has a built in DNS forwarder.
+ if c.config.NetMode.IsSlirp4netns() {
+ slirp4netnsDNS, err := GetSlirp4netnsDNS(c.slirp4netnsSubnet)
+ if err != nil {
+ logrus.Warn("Failed to determine Slirp4netns DNS: ", err.Error())
+ } else {
+ nameservers = append(nameservers, slirp4netnsDNS.String())
+ }
+ }
+ return nameservers
+}
+
+func (c *Container) isSlirp4netnsIPv6() (bool, error) {
+ if c.config.NetMode.IsSlirp4netns() {
+ ctrNetworkSlipOpts := []string{}
+ if c.config.NetworkOptions != nil {
+ ctrNetworkSlipOpts = append(ctrNetworkSlipOpts, c.config.NetworkOptions["slirp4netns"]...)
+ }
+ slirpOpts, err := parseSlirp4netnsNetworkOptions(c.runtime, ctrNetworkSlipOpts)
+ if err != nil {
+ return false, err
+ }
+ return slirpOpts.enableIPv6, nil
+ }
+
+ return false, nil
+}
+
+// check for net=none
+func (c *Container) hasNetNone() bool {
+ if !c.config.CreateNetNS {
+ for _, ns := range c.config.Spec.Linux.Namespaces {
+ if ns.Type == spec.NetworkNamespace {
+ if ns.Path == "" {
+ return true
+ }
+ }
+ }
+ }
+ return false
+}
diff --git a/libpod/networking_unsupported.go b/libpod/networking_unsupported.go
index 76ffabb5e..9429287f9 100644
--- a/libpod/networking_unsupported.go
+++ b/libpod/networking_unsupported.go
@@ -5,6 +5,7 @@ package libpod
import (
"errors"
+ "net"
"path/filepath"
"github.com/containers/common/libnetwork/types"
@@ -84,3 +85,7 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
func (c *Container) convertPortMappings() []types.PortMapping {
return []types.PortMapping{}
}
+
+func GetSlirp4netnsIP(subnet *net.IPNet) (*net.IP, error) {
+ return nil, errors.New("not implemented GetSlirp4netnsIP")
+}