Skip to content

Commit

Permalink
libpod: move slirp magic IPs to consts
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe authored and mheon committed Feb 3, 2021
1 parent ca3caa3 commit 83ab19a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,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...)
}
}

Expand Down Expand Up @@ -1607,7 +1607,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
Expand Down
11 changes: 10 additions & 1 deletion libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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
Expand Down Expand Up @@ -544,7 +553,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 {
Expand Down

0 comments on commit 83ab19a

Please sign in to comment.