Update MTU value for ethernet devices.

L2 MTU includes both payload and ethernet header. gVisor has supported setting
data link layer MTU, it will be  up to users to set up proper value for a
device's MTU if a larger value is expected.

By doing the change, gVisor will be consistent with runc:

```shell
# runc
root@cec4d7238802:/# ip link set dev lo mtu 1234
root@cec4d7238802:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1234 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

# runsc before the change.
root@7cd89278d414:/# ip link set dev lo mtu 1234
root@7cd89278d414:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1220
    link/loopback 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff

# runsc after the change.
root@e811c5851226:/# ip link set dev lo mtu 1234
root@e811c5851226:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1234
    link/loopback 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
```
PiperOrigin-RevId: 684746090
This commit is contained in:
Jing Chen
2024-10-11 01:36:07 -07:00
committed by gVisor bot
parent 56ccc08f37
commit 35d3c6eb73
4 changed files with 7 additions and 20 deletions
+1 -4
View File
@@ -54,10 +54,7 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress {
// MTU implements stack.LinkEndpoint.
func (e *Endpoint) MTU() uint32 {
if mtu := e.Endpoint.MTU(); mtu > header.EthernetMinimumSize {
return mtu - header.EthernetMinimumSize
}
return 0
return e.Endpoint.MTU()
}
// DeliverNetworkPacket implements stack.NetworkDispatcher.
+2 -10
View File
@@ -143,21 +143,13 @@ func TestMTU(t *testing.T) {
maxFrameSize: 0,
expectedMTU: 0,
},
{
maxFrameSize: header.EthernetMinimumSize - 1,
expectedMTU: 0,
},
{
maxFrameSize: header.EthernetMinimumSize,
expectedMTU: 0,
},
{
maxFrameSize: header.EthernetMinimumSize + 1,
expectedMTU: 1,
expectedMTU: header.EthernetMinimumSize,
},
{
maxFrameSize: maxFrameSize,
expectedMTU: maxFrameSize - header.EthernetMinimumSize,
expectedMTU: maxFrameSize,
},
}
+1 -1
View File
@@ -20,7 +20,7 @@ source "$(dirname "$0")/rtnetlink_test.sh"
# Create a new veth pair in the current namespace and change the MTU.
ip link add name test_veth01 type veth peer name test_veth02
ip link set test_veth01 mtu 3000
ip link show test_veth01 | grep -E "mtu (2986|3000)"
ip link show test_veth01 | grep -E "mtu 3000"
ip link del name test_veth01
# Check that test_veth02 has been destroyed.
if ! wait_for ! ip link show test_veth02; then
+3 -5
View File
@@ -302,13 +302,11 @@ TEST_P(NetlinkSetLinkTest, ChangeMTU) {
req.ifm.ifi_index = loopback_link.index;
req.rtattr.rta_type = IFLA_MTU;
req.rtattr.rta_len = RTA_LENGTH(sizeof(uint32_t));
req.mtu = 1500;
ASSERT_NE(req.mtu, loopback_link.mtu);
req.mtu = loopback_link.mtu + 10;
EXPECT_NO_ERRNO(NetlinkRequestAckOrError(fd, kSeq, &req, sizeof(req)));
// See b/348220986, this is a known issue. The interface MTU is slightly
// different because of the package header size.
loopback_link.mtu = 1486;
// Update the local loopback_link's MTU to the requested value.
loopback_link.mtu = req.mtu;
// Verify the new MTU.
struct searchrequest {
struct nlmsghdr hdr;