summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2021-04-23 10:52:52 +0200
committerPaul Holzinger <paul.holzinger@web.de>2021-04-23 11:48:50 +0200
commitca4f6ec1dbdfd06f3d403eda70dbb2eff3824888 (patch)
tree654e5a4ff6fa57998ceaebb8186e7f3a79ed3991
parent8465626e312a582e434851e6e562974cb3e2e1f8 (diff)
downloadpodman-ca4f6ec1dbdfd06f3d403eda70dbb2eff3824888.tar.gz
podman-ca4f6ec1dbdfd06f3d403eda70dbb2eff3824888.tar.bz2
podman-ca4f6ec1dbdfd06f3d403eda70dbb2eff3824888.zip
Parse slirp4netns net options with compat api
Parse the slirp4netns network options when called via compat api. The options must be extracted from the NetworkMode string. Fixes #10110 Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
-rw-r--r--cmd/podman/common/create_opts.go21
-rw-r--r--test/compose/slirp4netns_opts/docker-compose.yml5
-rw-r--r--test/compose/slirp4netns_opts/setup.sh8
-rw-r--r--test/compose/slirp4netns_opts/teardown.sh4
-rw-r--r--test/compose/slirp4netns_opts/tests.sh6
5 files changed, 35 insertions, 9 deletions
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
index 040dc6570..983b9e5ca 100644
--- a/cmd/podman/common/create_opts.go
+++ b/cmd/podman/common/create_opts.go
@@ -252,21 +252,24 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
return nil, nil, err
}
- netNS := specgen.Namespace{
- NSMode: nsmode.NSMode,
- Value: nsmode.Value,
+ var netOpts map[string][]string
+ parts := strings.SplitN(string(cc.HostConfig.NetworkMode), ":", 2)
+ if len(parts) > 1 {
+ netOpts = make(map[string][]string)
+ netOpts[parts[0]] = strings.Split(parts[1], ",")
}
// network
// Note: we cannot emulate compat exactly here. we only allow specifics of networks to be
// defined when there is only one network.
netInfo := entities.NetOptions{
- AddHosts: cc.HostConfig.ExtraHosts,
- DNSOptions: cc.HostConfig.DNSOptions,
- DNSSearch: cc.HostConfig.DNSSearch,
- DNSServers: dns,
- Network: netNS,
- PublishPorts: specPorts,
+ AddHosts: cc.HostConfig.ExtraHosts,
+ DNSOptions: cc.HostConfig.DNSOptions,
+ DNSSearch: cc.HostConfig.DNSSearch,
+ DNSServers: dns,
+ Network: nsmode,
+ PublishPorts: specPorts,
+ NetworkOptions: netOpts,
}
// network names
diff --git a/test/compose/slirp4netns_opts/docker-compose.yml b/test/compose/slirp4netns_opts/docker-compose.yml
new file mode 100644
index 000000000..dcdcae04c
--- /dev/null
+++ b/test/compose/slirp4netns_opts/docker-compose.yml
@@ -0,0 +1,5 @@
+services:
+ alpine:
+ image: alpine
+ network_mode: "slirp4netns:allow_host_loopback=true"
+ command: sh -c "echo teststring | nc 10.0.2.2 5001"
diff --git a/test/compose/slirp4netns_opts/setup.sh b/test/compose/slirp4netns_opts/setup.sh
new file mode 100644
index 000000000..35bbf7c70
--- /dev/null
+++ b/test/compose/slirp4netns_opts/setup.sh
@@ -0,0 +1,8 @@
+# -*- bash -*-
+
+# create tempfile to store nc output
+OUTFILE=$(mktemp)
+# listen on a port, the container will try to connect to it
+nc -l 5001 > $OUTFILE &
+
+nc_pid=$!
diff --git a/test/compose/slirp4netns_opts/teardown.sh b/test/compose/slirp4netns_opts/teardown.sh
new file mode 100644
index 000000000..656724363
--- /dev/null
+++ b/test/compose/slirp4netns_opts/teardown.sh
@@ -0,0 +1,4 @@
+# -*- bash -*-
+
+kill $nc_pid &> /dev/null
+rm -f $OUTFILE
diff --git a/test/compose/slirp4netns_opts/tests.sh b/test/compose/slirp4netns_opts/tests.sh
new file mode 100644
index 000000000..1efce45c4
--- /dev/null
+++ b/test/compose/slirp4netns_opts/tests.sh
@@ -0,0 +1,6 @@
+# -*- bash -*-
+
+output="$(cat $OUTFILE)"
+expected="teststring"
+
+is "$output" "$expected" "$testname : nc received teststring"