From f237e8bd301aded7125ab786d6cafc4831761388 Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Thu, 25 May 2023 14:16:24 +0200 Subject: [PATCH] Windows MTU fix and wg/win version update (#896) - wireguard/windows version update to 0.5.3 - follow up forked wireguard-go MTU related changes - fix MTU settings on Windows --------- Co-authored-by: Maycon Santos --- go.mod | 4 ++-- go.sum | 8 ++++---- iface/tun_windows.go | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 964826948..b9878f02b 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( golang.org/x/sys v0.6.0 golang.zx2c4.com/wireguard v0.0.0-20230223181233-21636207a675 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20211215182854-7a385b3431de - golang.zx2c4.com/wireguard/windows v0.5.1 + golang.zx2c4.com/wireguard/windows v0.5.3 google.golang.org/grpc v1.52.3 google.golang.org/protobuf v1.28.1 gopkg.in/natefinch/lumberjack.v2 v2.0.0 @@ -143,4 +143,4 @@ replace github.com/kardianos/service => github.com/netbirdio/service v0.0.0-2023 replace github.com/getlantern/systray => github.com/netbirdio/systray v0.0.0-20221012095658-dc8eda872c0c -replace golang.zx2c4.com/wireguard => github.com/netbirdio/wireguard-go v0.0.0-20230426151838-5c7986a94d53 +replace golang.zx2c4.com/wireguard => github.com/netbirdio/wireguard-go v0.0.0-20230524172305-5a498a82b33f diff --git a/go.sum b/go.sum index 668f2ff88..741a9ed5b 100644 --- a/go.sum +++ b/go.sum @@ -485,8 +485,8 @@ github.com/netbirdio/service v0.0.0-20230215170314-b923b89432b0 h1:hirFRfx3grVA/ github.com/netbirdio/service v0.0.0-20230215170314-b923b89432b0/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM= github.com/netbirdio/systray v0.0.0-20221012095658-dc8eda872c0c h1:wK/s4nyZj/GF/kFJQjX6nqNfE0G3gcqd6hhnPCyp4sw= github.com/netbirdio/systray v0.0.0-20221012095658-dc8eda872c0c/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= -github.com/netbirdio/wireguard-go v0.0.0-20230426151838-5c7986a94d53 h1:OPbKpisDyMbOf/TDYS0Niw7yc/uoviED/pKyO+8A1C0= -github.com/netbirdio/wireguard-go v0.0.0-20230426151838-5c7986a94d53/go.mod h1:tqur9LnfstdR9ep2LaJT4lFUl0EjlHtge+gAjmsHUG4= +github.com/netbirdio/wireguard-go v0.0.0-20230524172305-5a498a82b33f h1:WQXGYCKPkNs1KusFTLieV73UVTNfZVyez4CFRvlOruM= +github.com/netbirdio/wireguard-go v0.0.0-20230524172305-5a498a82b33f/go.mod h1:tqur9LnfstdR9ep2LaJT4lFUl0EjlHtge+gAjmsHUG4= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -1037,8 +1037,8 @@ golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeu golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20211215182854-7a385b3431de h1:qDZ+lyO5jC9RNJ7ANJA0GWXk3pSn0Fu5SlcAIlgw+6w= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20211215182854-7a385b3431de/go.mod h1:Q2XNgour4QSkFj0BWCkVlW0HWJwQgNMsMahpSlI0Eno= -golang.zx2c4.com/wireguard/windows v0.5.1 h1:OnYw96PF+CsIMrqWo5QP3Q59q5hY1rFErk/yN3cS+JQ= -golang.zx2c4.com/wireguard/windows v0.5.1/go.mod h1:EApyTk/ZNrkbZjurHL1nleDYnsPpJYBO7LZEBCyDAHk= +golang.zx2c4.com/wireguard/windows v0.5.3 h1:On6j2Rpn3OEMXqBq00QEDC7bWSZrPIHKIus8eIuExIE= +golang.zx2c4.com/wireguard/windows v0.5.3/go.mod h1:9TEe8TJmtwyQebdFwAkEWOPr3prrtqm+REGFifP60hI= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= diff --git a/iface/tun_windows.go b/iface/tun_windows.go index e7894d9c3..6fdab43c1 100644 --- a/iface/tun_windows.go +++ b/iface/tun_windows.go @@ -3,9 +3,11 @@ package iface import ( "fmt" "net" + "net/netip" "github.com/pion/transport/v2" log "github.com/sirupsen/logrus" + "golang.org/x/sys/windows" "golang.zx2c4.com/wireguard/device" "golang.zx2c4.com/wireguard/ipc" "golang.zx2c4.com/wireguard/tun" @@ -50,7 +52,6 @@ func (c *tunDevice) createWithUserspace() (NetInterface, error) { if err != nil { return nil, err } - // We need to create a wireguard-go device and listen to configuration requests tunDev := device.NewDevice(tunIface, c.iceBind, device.NewLogger(device.LogLevelSilent, "[netbird] ")) err = tunDev.Up() @@ -59,6 +60,22 @@ func (c *tunDevice) createWithUserspace() (NetInterface, error) { return nil, err } + luid := winipcfg.LUID(tunIface.(*tun.NativeTun).LUID()) + + nbiface, err := luid.IPInterface(windows.AF_INET) + if err != nil { + _ = tunIface.Close() + return nil, fmt.Errorf("got error when getting ip interface %s", err) + } + + nbiface.NLMTU = uint32(c.mtu) + + err = nbiface.Set() + if err != nil { + _ = tunIface.Close() + return nil, fmt.Errorf("got error when getting setting the interface mtu: %s", err) + } + c.uapi, err = c.getUAPI(c.name) if err != nil { _ = tunIface.Close() @@ -142,7 +159,7 @@ func (c *tunDevice) assignAddr() error { tunDev := c.netInterface.(*tun.NativeTun) luid := winipcfg.LUID(tunDev.LUID()) log.Debugf("adding address %s to interface: %s", c.address.IP, c.name) - return luid.SetIPAddresses([]net.IPNet{{c.address.IP, c.address.Network.Mask}}) + return luid.SetIPAddresses([]netip.Prefix{netip.MustParsePrefix(c.address.String())}) } // getUAPI returns a Listener