From 0ba1942f261158b9526310aac7ee5f183a109440 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jan 2021 13:54:24 +0100 Subject: networking: lookup child IP in networks if a CNI network is added to the container, use the IP address in that network instead of hard-coding the slirp4netns default. commit 5e65f0ba30f3fca73f8c207825632afef08378c1 introduced this regression. Closes: https://github.com/containers/podman/issues/9065 Signed-off-by: Giuseppe Scrivano --- libpod/networking_linux.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 09fdea496..ef2f034ab 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -550,13 +550,25 @@ func (r *Runtime) setupRootlessPortMappingViaRLK(ctr *Container, netnsPath strin } } + childIP := slirp4netnsIP +outer: + for _, r := range ctr.state.NetworkStatus { + for _, i := range r.IPs { + ipv4 := i.Address.IP.To4() + if ipv4 != nil { + childIP = ipv4.String() + break outer + } + } + } + cfg := rootlessport.Config{ Mappings: ctr.config.PortMappings, NetNSPath: netnsPath, ExitFD: 3, ReadyFD: 4, TmpDir: ctr.runtime.config.Engine.TmpDir, - ChildIP: slirp4netnsIP, + ChildIP: childIP, } cfgJSON, err := json.Marshal(cfg) if err != nil { -- cgit v1.2.3-54-g00ecf