From 94c10243701c6a5d884c0f5f106d65ad34e6729d Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Tue, 7 May 2024 11:24:19 -0700 Subject: [PATCH] Modify "runsc do" veth creation to match the default device's MTU. PiperOrigin-RevId: 631489949 --- runsc/cmd/do.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/runsc/cmd/do.go b/runsc/cmd/do.go index f8576063d..fd0008d96 100644 --- a/runsc/cmd/do.go +++ b/runsc/cmd/do.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "math/rand" + "net" "os" "os/exec" "path/filepath" @@ -253,6 +254,10 @@ func (c *Do) setupNet(cid string, spec *specs.Spec) (func(), error) { if err != nil { return nil, errNoDefaultInterface } + mtu, err := deviceMTU(dev) + if err != nil { + return nil, err + } peerIP, err := calculatePeerIP(c.ip) if err != nil { return nil, err @@ -260,7 +265,7 @@ func (c *Do) setupNet(cid string, spec *specs.Spec) (func(), error) { veth, peer := deviceNames(cid) cmds := []string{ - fmt.Sprintf("ip link add %s type veth peer name %s", veth, peer), + fmt.Sprintf("ip link add %s mtu %v type veth peer name %s", veth, mtu, peer), // Setup device outside the namespace. fmt.Sprintf("ip addr add %s/24 dev %s", peerIP, peer), @@ -367,6 +372,14 @@ func defaultDevice() (string, error) { return parts[4], nil } +func deviceMTU(dev string) (int, error) { + intf, err := net.InterfaceByName(dev) + if err != nil { + return 0, err + } + return intf.MTU, nil +} + func makeFile(dest, content string, spec *specs.Spec) (string, error) { tmpFile, err := ioutil.TempFile("", filepath.Base(dest)) if err != nil {