From 29749362a079da211c3d4e94bfff354a1d23b526 Mon Sep 17 00:00:00 2001 From: binghongtao <695097494plus@gmail.com> Date: Sat, 20 May 2023 01:33:07 +0800 Subject: [PATCH] podman: Added find slirp4netns binary file from helper_binaries_dir [NO NEW TESTS NEEDED] Fixes: #18568 Signed-off-by: binghongtao <695097494plus@gmail.com> --- cmd/podman/root.go | 3 ++- docs/source/markdown/podman.1.md | 4 +++- libpod/info_linux.go | 3 +-- libpod/networking_linux.go | 2 +- libpod/networking_slirp4netns.go | 9 ++++++--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 726bd119e5..659740f8cb 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -438,7 +438,8 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { pFlags.StringVar(&podmanConfig.ConmonPath, conmonFlagName, "", "Path of the conmon binary") _ = cmd.RegisterFlagCompletionFunc(conmonFlagName, completion.AutocompleteDefault) - // TODO (5.0): remove this option with the next major release after https://github.com/containers/podman/issues/18560 was implemented + // TODO (5.0): --network-cmd-path is deprecated, remove this option with the next major release + // We need to find all the places that use r.config.Engine.NetworkCmdPath and remove it networkCmdPathFlagName := "network-cmd-path" pFlags.StringVar(&podmanConfig.ContainersConf.Engine.NetworkCmdPath, networkCmdPathFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.NetworkCmdPath, "Path to the command for configuring the network") _ = cmd.RegisterFlagCompletionFunc(networkCmdPathFlagName, completion.AutocompleteDefault) diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md index 7f9412c305..b9d3cfe2a0 100644 --- a/docs/source/markdown/podman.1.md +++ b/docs/source/markdown/podman.1.md @@ -83,7 +83,9 @@ Remote connections use local containers.conf for default. Log messages at and above specified level: debug, info, warn, error, fatal or panic (default: "warn") #### **--network-cmd-path**=*path* -Path to the `slirp4netns(1)` command binary to use for setting up a slirp4netns network. If "" is used then the binary is looked up using the $PATH environment variable. +Path to the `slirp4netns(1)` command binary to use for setting up a slirp4netns network. +If "" is used, then the binary will first be searched using the `helper_binaries_dir` option in `containers.conf`, and second using the `$PATH` environment variable. +**Note:** This option is deprecated and will be removed with Podman 5.0. Use the `helper_binaries_dir` option in `containers.conf` instead. #### **--network-config-dir**=*directory* diff --git a/libpod/info_linux.go b/libpod/info_linux.go index 44beafa8c9..a3073cb2d3 100644 --- a/libpod/info_linux.go +++ b/libpod/info_linux.go @@ -5,7 +5,6 @@ import ( "fmt" "math" "os" - "os/exec" "strconv" "strings" @@ -57,7 +56,7 @@ func (r *Runtime) setPlatformHostInfo(info *define.HostInfo) error { slirp4netnsPath := r.config.Engine.NetworkCmdPath if slirp4netnsPath == "" { - slirp4netnsPath, _ = exec.LookPath("slirp4netns") + slirp4netnsPath, _ = r.config.FindHelperBinary(slirp4netnsBinaryName, true) } if slirp4netnsPath != "" { version, err := programVersion(slirp4netnsPath) diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 13befa0b37..7e97b1041b 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -392,7 +392,7 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) { path := r.config.Engine.NetworkCmdPath if path == "" { var err error - path, err = exec.LookPath("slirp4netns") + path, err = r.config.FindHelperBinary(slirp4netnsBinaryName, true) if err != nil { return nil, err } diff --git a/libpod/networking_slirp4netns.go b/libpod/networking_slirp4netns.go index 8e6dc8b901..0d185885d7 100644 --- a/libpod/networking_slirp4netns.go +++ b/libpod/networking_slirp4netns.go @@ -61,7 +61,10 @@ type slirp4netnsNetworkOptions struct { outboundAddr6 string } -const ipv6ConfDefaultAcceptDadSysctl = "/proc/sys/net/ipv6/conf/default/accept_dad" +const ( + ipv6ConfDefaultAcceptDadSysctl = "/proc/sys/net/ipv6/conf/default/accept_dad" + slirp4netnsBinaryName = "slirp4netns" +) func checkSlirpFlags(path string) (*slirpFeatures, error) { cmd := exec.Command(path, "--help") @@ -216,7 +219,7 @@ func (r *Runtime) setupSlirp4netns(ctr *Container, netns string) error { path := r.config.Engine.NetworkCmdPath if path == "" { var err error - path, err = exec.LookPath("slirp4netns") + path, err = r.config.FindHelperBinary(slirp4netnsBinaryName, true) if err != nil { return fmt.Errorf("could not find slirp4netns, the network namespace can't be configured: %w", err) } @@ -234,7 +237,7 @@ func (r *Runtime) setupSlirp4netns(ctr *Container, netns string) error { ctrNetworkSlipOpts := []string{} if ctr.config.NetworkOptions != nil { - ctrNetworkSlipOpts = append(ctrNetworkSlipOpts, ctr.config.NetworkOptions["slirp4netns"]...) + ctrNetworkSlipOpts = append(ctrNetworkSlipOpts, ctr.config.NetworkOptions[slirp4netnsBinaryName]...) } netOptions, err := parseSlirp4netnsNetworkOptions(r, ctrNetworkSlipOpts) if err != nil {