Modify "runsc do" veth creation to match the default device's MTU.

PiperOrigin-RevId: 631489949
This commit is contained in:
Lucas Manning
2024-05-07 11:27:38 -07:00
committed by gVisor bot
parent a8ea8c8356
commit 94c1024370
+14 -1
View File
@@ -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 {