summaryrefslogtreecommitdiff
path: root/libpod/networking_linux.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-03-14 12:05:49 -0700
committerGitHub <noreply@github.com>2019-03-14 12:05:49 -0700
commit31f11a8a9bddc4dcfc22463097b852fcdc9f0172 (patch)
tree3e8ca61fd8c55ef823ba73e87ea59bd1ac5e60b5 /libpod/networking_linux.go
parentfc5951ad55b5d9c4e2cc9ca0188c1adf8a12a3bb (diff)
parentbd4441b0d33eef47481585cafe9e9576c072eba0 (diff)
downloadpodman-31f11a8a9bddc4dcfc22463097b852fcdc9f0172.tar.gz
podman-31f11a8a9bddc4dcfc22463097b852fcdc9f0172.tar.bz2
podman-31f11a8a9bddc4dcfc22463097b852fcdc9f0172.zip
Merge pull request #2653 from giuseppe/fix-slirp4netns-check
rootless: fix CI regression when using slirp4netns
Diffstat (limited to 'libpod/networking_linux.go')
-rw-r--r--libpod/networking_linux.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 809584804..d8b0cffcb 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -134,6 +134,15 @@ type slirp4netnsCmd struct {
Args slirp4netnsCmdArg `json:"arguments"`
}
+func checkSlirpFlags(path string) (bool, bool, error) {
+ cmd := exec.Command(path, "--help")
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ return false, false, err
+ }
+ return strings.Contains(string(out), "--disable-host-loopback"), strings.Contains(string(out), "--mtu"), nil
+}
+
// Configure the network namespace for a rootless container
func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
defer ctr.rootlessSlirpSyncR.Close()
@@ -159,13 +168,24 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
havePortMapping := len(ctr.Config().PortMappings) > 0
apiSocket := filepath.Join(r.ociRuntime.tmpDir, fmt.Sprintf("%s.net", ctr.config.ID))
- var cmd *exec.Cmd
+
+ cmdArgs := []string{}
if havePortMapping {
- // if we need ports to be mapped from the host, create a API socket to use for communicating with slirp4netns.
- cmd = exec.Command(path, "--disable-host-loopback", "--mtu", "65520", "-c", "-e", "3", "-r", "4", "--api-socket", apiSocket, fmt.Sprintf("%d", ctr.state.PID), "tap0")
- } else {
- cmd = exec.Command(path, "--disable-host-loopback", "--mtu", "65520", "-c", "-e", "3", "-r", "4", fmt.Sprintf("%d", ctr.state.PID), "tap0")
+ cmdArgs = append(cmdArgs, "--api-socket", apiSocket, fmt.Sprintf("%d", ctr.state.PID))
}
+ dhp, mtu, err := checkSlirpFlags(path)
+ if err != nil {
+ return errors.Wrapf(err, "error checking slirp4netns binary %s", path)
+ }
+ if dhp {
+ cmdArgs = append(cmdArgs, "--disable-host-loopback")
+ }
+ if mtu {
+ cmdArgs = append(cmdArgs, "--mtu", "65520")
+ }
+ cmdArgs = append(cmdArgs, "-c", "-e", "3", "-r", "4", fmt.Sprintf("%d", ctr.state.PID), "tap0")
+
+ cmd := exec.Command(path, cmdArgs...)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,