From 35d3c6eb7383b180626fc4a3ce56655be6ed5e56 Mon Sep 17 00:00:00 2001 From: Jing Chen Date: Fri, 11 Oct 2024 01:31:55 -0700 Subject: [PATCH] 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: 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: 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: mtu 1234 link/loopback 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff ``` PiperOrigin-RevId: 684746090 --- pkg/tcpip/link/ethernet/ethernet.go | 5 +---- pkg/tcpip/link/ethernet/ethernet_test.go | 12 ++---------- test/rtnetlink/linux/setlink_test.sh | 2 +- test/syscalls/linux/socket_netlink_route.cc | 8 +++----- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/pkg/tcpip/link/ethernet/ethernet.go b/pkg/tcpip/link/ethernet/ethernet.go index 4e54e0e8e..fe9b165c3 100644 --- a/pkg/tcpip/link/ethernet/ethernet.go +++ b/pkg/tcpip/link/ethernet/ethernet.go @@ -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. diff --git a/pkg/tcpip/link/ethernet/ethernet_test.go b/pkg/tcpip/link/ethernet/ethernet_test.go index 832dbbe1d..f51758077 100644 --- a/pkg/tcpip/link/ethernet/ethernet_test.go +++ b/pkg/tcpip/link/ethernet/ethernet_test.go @@ -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, }, } diff --git a/test/rtnetlink/linux/setlink_test.sh b/test/rtnetlink/linux/setlink_test.sh index 6744b5974..28ed2c486 100755 --- a/test/rtnetlink/linux/setlink_test.sh +++ b/test/rtnetlink/linux/setlink_test.sh @@ -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 diff --git a/test/syscalls/linux/socket_netlink_route.cc b/test/syscalls/linux/socket_netlink_route.cc index 138c27df8..01a069da1 100644 --- a/test/syscalls/linux/socket_netlink_route.cc +++ b/test/syscalls/linux/socket_netlink_route.cc @@ -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;