Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Michael Zeltner <m@niij.org>
To: wireguard@lists.zx2c4.com
Cc: Michael Zeltner <m@niij.org>
Subject: [PATCH] tun: openbsd: Don't change MTU when it's already the expected size
Date: Mon, 15 Jul 2019 19:46:35 -0400	[thread overview]
Message-ID: <20190715234634.13018-1-m@niij.org> (raw)

Allows for running wireguard-go as non-root user
---
 tun/tun_openbsd.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tun/tun_openbsd.go b/tun/tun_openbsd.go
index 1e6191f..bdca231 100644
--- a/tun/tun_openbsd.go
+++ b/tun/tun_openbsd.go
@@ -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
 }
 
-- 
2.21.0

_______________________________________________
WireGuard mailing list
WireGuard@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/wireguard

             reply	other threads:[~2019-07-17 20:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-15 23:46 Michael Zeltner [this message]
2019-07-17 21:04 ` Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190715234634.13018-1-m@niij.org \
    --to=m@niij.org \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).