mirror of
https://github.com/containers/podman.git
synced 2025-05-21 09:05:56 +08:00
Make slirp MTU configurable (network_cmd_options)
The mtu default value is currently forced to 65520. This let the user control it using the config key network_cmd_options, i.e.: network_cmd_options=["mtu=9000"] Signed-off-by: bitstrings <pino.silvaggio@gmail.com>
This commit is contained in:
@ -817,6 +817,7 @@ func AutocompleteNetworkFlag(cmd *cobra.Command, args []string, toComplete strin
|
|||||||
"allow_host_loopback=": getBoolCompletion,
|
"allow_host_loopback=": getBoolCompletion,
|
||||||
"cidr=": nil,
|
"cidr=": nil,
|
||||||
"enable_ipv6=": getBoolCompletion,
|
"enable_ipv6=": getBoolCompletion,
|
||||||
|
"mtu=": nil,
|
||||||
"outbound_addr=": nil,
|
"outbound_addr=": nil,
|
||||||
"outbound_addr6=": nil,
|
"outbound_addr6=": nil,
|
||||||
"port_handler=": func(_ string) ([]string, cobra.ShellCompDirective) {
|
"port_handler=": func(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
@ -638,6 +638,7 @@ Valid _mode_ values are:
|
|||||||
- **private**: create a new namespace for the container (default)
|
- **private**: create a new namespace for the container (default)
|
||||||
- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options:
|
- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options:
|
||||||
- **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false.
|
- **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false.
|
||||||
|
- **mtu=MTU**: Specify the MTU to use for this network. (Default is `65520`).
|
||||||
- **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`).
|
- **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`).
|
||||||
- **enable_ipv6=true|false**: Enable IPv6. Default is false. (Required for `outbound_addr6`).
|
- **enable_ipv6=true|false**: Enable IPv6. Default is false. (Required for `outbound_addr6`).
|
||||||
- **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only).
|
- **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only).
|
||||||
|
@ -674,6 +674,7 @@ Valid _mode_ values are:
|
|||||||
- **private**: create a new namespace for the container (default)
|
- **private**: create a new namespace for the container (default)
|
||||||
- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options:
|
- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options:
|
||||||
- **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false.
|
- **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false.
|
||||||
|
- **mtu=MTU**: Specify the MTU to use for this network. (Default is `65520`).
|
||||||
- **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`).
|
- **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`).
|
||||||
- **enable_ipv6=true|false**: Enable IPv6. Default is false. (Required for `outbound_addr6`).
|
- **enable_ipv6=true|false**: Enable IPv6. Default is false. (Required for `outbound_addr6`).
|
||||||
- **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only).
|
- **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only).
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -42,6 +43,9 @@ const (
|
|||||||
|
|
||||||
// slirp4netnsDNS is the IP for the built-in DNS server in the slirp network
|
// slirp4netnsDNS is the IP for the built-in DNS server in the slirp network
|
||||||
slirp4netnsDNS = "10.0.2.3"
|
slirp4netnsDNS = "10.0.2.3"
|
||||||
|
|
||||||
|
// slirp4netnsMTU the default MTU override
|
||||||
|
slirp4netnsMTU = 65520
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get an OCICNI network config
|
// Get an OCICNI network config
|
||||||
@ -282,6 +286,7 @@ func (r *Runtime) setupSlirp4netns(ctr *Container) error {
|
|||||||
enableIPv6 := false
|
enableIPv6 := false
|
||||||
outboundAddr := ""
|
outboundAddr := ""
|
||||||
outboundAddr6 := ""
|
outboundAddr6 := ""
|
||||||
|
mtu := slirp4netnsMTU
|
||||||
|
|
||||||
if ctr.config.NetworkOptions != nil {
|
if ctr.config.NetworkOptions != nil {
|
||||||
slirpOptions = append(slirpOptions, ctr.config.NetworkOptions["slirp4netns"]...)
|
slirpOptions = append(slirpOptions, ctr.config.NetworkOptions["slirp4netns"]...)
|
||||||
@ -345,6 +350,11 @@ func (r *Runtime) setupSlirp4netns(ctr *Container) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
outboundAddr6 = value
|
outboundAddr6 = value
|
||||||
|
case "mtu":
|
||||||
|
mtu, err = strconv.Atoi(value)
|
||||||
|
if mtu < 68 || err != nil {
|
||||||
|
return errors.Errorf("invalid mtu %q", value)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("unknown option for slirp4netns: %q", o)
|
return errors.Errorf("unknown option for slirp4netns: %q", o)
|
||||||
}
|
}
|
||||||
@ -358,8 +368,8 @@ func (r *Runtime) setupSlirp4netns(ctr *Container) error {
|
|||||||
if disableHostLoopback && slirpFeatures.HasDisableHostLoopback {
|
if disableHostLoopback && slirpFeatures.HasDisableHostLoopback {
|
||||||
cmdArgs = append(cmdArgs, "--disable-host-loopback")
|
cmdArgs = append(cmdArgs, "--disable-host-loopback")
|
||||||
}
|
}
|
||||||
if slirpFeatures.HasMTU {
|
if mtu > -1 && slirpFeatures.HasMTU {
|
||||||
cmdArgs = append(cmdArgs, "--mtu", "65520")
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--mtu=%d", mtu))
|
||||||
}
|
}
|
||||||
if !noPivotRoot && slirpFeatures.HasEnableSandbox {
|
if !noPivotRoot && slirpFeatures.HasEnableSandbox {
|
||||||
cmdArgs = append(cmdArgs, "--enable-sandbox")
|
cmdArgs = append(cmdArgs, "--enable-sandbox")
|
||||||
|
@ -376,6 +376,13 @@ var _ = Describe("Podman run networking", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman run slirp4netns network with mtu", func() {
|
||||||
|
session := podmanTest.Podman([]string{"run", "--network", "slirp4netns:mtu=9000", ALPINE, "ip", "addr"})
|
||||||
|
session.Wait(30)
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("mtu 9000"))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman run slirp4netns network with different cidr", func() {
|
It("podman run slirp4netns network with different cidr", func() {
|
||||||
slirp4netnsHelp := SystemExec("slirp4netns", []string{"--help"})
|
slirp4netnsHelp := SystemExec("slirp4netns", []string{"--help"})
|
||||||
Expect(slirp4netnsHelp.ExitCode()).To(Equal(0))
|
Expect(slirp4netnsHelp.ExitCode()).To(Equal(0))
|
||||||
|
Reference in New Issue
Block a user