Skip to contentSkip to conversation

tun: openbsd: Don't change MTU when it's already the expected size

PATCH In review Michael Zeltner 2 participants 2 messages Jul 17, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tun: openbsd: Don't change MTU when it's already the expected size

Allows for running wireguard-go as non-root user

---
 tun/tun_openbsd.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tun/tun_openbsd.go +10 -1
index 1e6191f..bdca231 100644
@@ -173,12 +173,21 @@ func CreateTUNFromFile(file *os.File, mtu int) (Device, error) {
 
 	go tun.routineRouteListener(tunIfindex)
 
-	err = tun.setMTU(mtu)
+	var cur_mtu int
+	cur_mtu, err = tun.MTU()
 	if err != nil {
 		tun.Close()
 		return nil, err
 	}
 
+	if cur_mtu != mtu {
+		err = tun.setMTU(mtu)
+		if err != nil {
+			tun.Close()
+			return nil, err
+		}
+	}
+
 	return tun, nil
 }
 
Signature · 6 lines
2.21.0

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard