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 <Jason@zx2c4.com>
This commit is contained in:
Michael Zeltner 2019-07-17 23:04:01 +02:00 committed by Jason A. Donenfeld
parent 9ea9a92117
commit 4d5819183e

View file

@ -173,11 +173,14 @@ func CreateTUNFromFile(file *os.File, mtu int) (Device, error) {
go tun.routineRouteListener(tunIfindex) go tun.routineRouteListener(tunIfindex)
currentMTU, err := tun.MTU()
if err != nil || currentMTU != mtu {
err = tun.setMTU(mtu) err = tun.setMTU(mtu)
if err != nil { if err != nil {
tun.Close() tun.Close()
return nil, err return nil, err
} }
}
return tun, nil return tun, nil
} }