Skip to content

Commit

Permalink
podman: Added find slirp4netns binary file from helper_binaries_dir
Browse files Browse the repository at this point in the history
[NO NEW TESTS NEEDED]

Fixes: containers#18568
Signed-off-by: binghongtao <[email protected]>
  • Loading branch information
HirazawaUi committed May 19, 2023
1 parent abea786 commit 2974936
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion docs/source/markdown/podman.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
3 changes: 1 addition & 2 deletions libpod/info_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"math"
"os"
"os/exec"
"strconv"
"strings"

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions libpod/networking_slirp4netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down

0 comments on commit 2974936

Please sign in to comment.