From df9cadd9389b87632f53129123ab269d939118a1 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 19 Jul 2018 10:01:12 +0100 Subject: [PATCH] Cap MTU on Linux in TAP mode --- src/yggdrasil/tun_linux.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/yggdrasil/tun_linux.go b/src/yggdrasil/tun_linux.go index 24c5aa9..14c2f0a 100644 --- a/src/yggdrasil/tun_linux.go +++ b/src/yggdrasil/tun_linux.go @@ -29,6 +29,14 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) } tun.iface = iface tun.mtu = getSupportedMTU(mtu) + // The following check is specific to Linux, as the TAP driver only supports + // an MTU of 65535-14 to make room for the ethernet headers. This makes sure + // that the MTU gets rounded down to 65521 instead of causing a panic. + if iftapmode { + if tun.mtu > 65535-tun_ETHER_HEADER_LENGTH { + tun.mtu = 65535-tun_ETHER_HEADER_LENGTH + } + } return tun.setupAddress(addr) }