From ef654941d1b7d3bd8f5af51418aa54e0d6f2d48c Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 21 Jan 2021 20:31:07 +0100 Subject: libpod: move slirp magic IPs to consts Signed-off-by: Giuseppe Scrivano --- libpod/container_internal_linux.go | 4 ++-- libpod/networking_linux.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'libpod') diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 0553cc59c..b41a3fa38 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -1700,7 +1700,7 @@ func (c *Container) generateResolvConf() (string, error) { nameservers = resolvconf.GetNameservers(resolv.Content) // slirp4netns has a built in DNS server. if c.config.NetMode.IsSlirp4netns() { - nameservers = append([]string{"10.0.2.3"}, nameservers...) + nameservers = append([]string{slirp4netnsDNS}, nameservers...) } } @@ -1780,7 +1780,7 @@ func (c *Container) getHosts() string { if c.Hostname() != "" { if c.config.NetMode.IsSlirp4netns() { // When using slirp4netns, the interface gets a static IP - hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.config.Name) + hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", slirp4netnsIP, c.Hostname(), c.config.Name) } else { hasNetNS := false netNone := false diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 6f56d2f8f..09fdea496 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -35,6 +35,15 @@ import ( "golang.org/x/sys/unix" ) +const ( + // slirp4netnsIP is the IP used by slirp4netns to configure the tap device + // inside the network namespace. + slirp4netnsIP = "10.0.2.100" + + // slirp4netnsDNS is the IP for the built-in DNS server in the slirp network + slirp4netnsDNS = "10.0.2.3" +) + // Get an OCICNI network config func (r *Runtime) getPodNetwork(id, name, nsPath string, networks []string, ports []ocicni.PortMapping, staticIP net.IP, staticMAC net.HardwareAddr, netDescriptions ContainerNetworkDescriptions) ocicni.PodNetwork { var networkKey string @@ -547,7 +556,7 @@ func (r *Runtime) setupRootlessPortMappingViaRLK(ctr *Container, netnsPath strin ExitFD: 3, ReadyFD: 4, TmpDir: ctr.runtime.config.Engine.TmpDir, - ChildIP: "10.0.2.100", + ChildIP: slirp4netnsIP, } cfgJSON, err := json.Marshal(cfg) if err != nil { -- cgit v1.2.3-54-g00ecf