From 4d5819183e218e040fa0a73df560b4a4a9a768d7 Mon Sep 17 00:00:00 2001 From: Michael Zeltner Date: Wed, 17 Jul 2019 23:04:01 +0200 Subject: tun: openbsd: don't change MTU when it's already the expected size Allows for running wireguard-go as non-root user. Signed-off-by: Jason A. Donenfeld --- tun/tun_openbsd.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tun/tun_openbsd.go b/tun/tun_openbsd.go index 1e6191f..bbc0432 100644 --- a/tun/tun_openbsd.go +++ b/tun/tun_openbsd.go @@ -173,10 +173,13 @@ func CreateTUNFromFile(file *os.File, mtu int) (Device, error) { go tun.routineRouteListener(tunIfindex) - err = tun.setMTU(mtu) - if err != nil { - tun.Close() - return nil, err + currentMTU, err := tun.MTU() + if err != nil || currentMTU != mtu { + err = tun.setMTU(mtu) + if err != nil { + tun.Close() + return nil, err + } } return tun, nil -- cgit v1.2.3