From 44604448de37953db67fae8139fa6fd15db8392b Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 27 May 2022 17:01:41 -0400 Subject: [PATCH] freebsd_network: Automatically switch to jumbo-sized MTUs if possible. Unfortunately there is no way to ask if a device supports jumbo MTUs besides actually activating it. But that's fine, because for now, Haiku's own network stack does not actually support changing MTUs at the device level! Probably that should be fixed, too, but that is a problem for another day. With preceding commits, this fixes #17728, and all BSD network drivers will use jumbo frames if possible by default. --- src/libs/compat/freebsd_network/device_hooks.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/compat/freebsd_network/device_hooks.c b/src/libs/compat/freebsd_network/device_hooks.c index 1d8cf98247..9389a6b99e 100644 --- a/src/libs/compat/freebsd_network/device_hooks.c +++ b/src/libs/compat/freebsd_network/device_hooks.c @@ -236,7 +236,18 @@ compat_control(void *cookie, uint32 op, void *arg, size_t length) if (length < 4) return B_BAD_VALUE; - frameSize = ifp->if_mtu + ETHER_HDR_LEN; + // This is (usually) only invoked during initialization to get the + // maximum frame size. Thus we try to set the largest possible one, + // as there is no way to determine what the driver might support. + struct ifreq ifr; + ifr.ifr_mtu = ETHERMTU_JUMBO; + if (compat_control(cookie, SIOCSIFMTU, &ifr, sizeof(ifr)) != 0) { + // Try again with 4K at least. + ifr.ifr_mtu = 4096 - (ETHER_HDR_LEN + ETHER_CRC_LEN); + compat_control(cookie, SIOCSIFMTU, &ifr, sizeof(ifr)); + } + + frameSize = ifp->if_mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN); return user_memcpy(arg, &frameSize, 4); }