]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: match windows CreateTUN signature to the Linux variant
authorAvery Pennarun <apenwarr@gmail.com>
Sat, 20 Apr 2019 07:28:06 +0000 (03:28 -0400)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 17 Oct 2019 13:19:20 +0000 (15:19 +0200)
Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
[zx2c4: fix default value]

main_windows.go
tun/tun_windows.go

index 5380f567bc65b5c7d035b6e123e16db2ed0aadd4..f57bc8d6ce27e77fb046e708293ee5f6cd956eb0 100644 (file)
@@ -37,7 +37,7 @@ func main() {
        logger.Info.Println("Starting wireguard-go version", device.WireGuardGoVersion)
        logger.Debug.Println("Debug log enabled")
 
-       tun, err := tun.CreateTUN(interfaceName)
+       tun, err := tun.CreateTUN(interfaceName, 0)
        if err == nil {
                realInterfaceName, err2 := tun.Name()
                if err2 == nil {
index 4b5da02050499b1a7f7846ad7be9bbe217666c8f..daad4aa5bf9aa3d5652f9fbb6a3d0934c224aea8 100644 (file)
@@ -54,15 +54,15 @@ func nanotime() int64
 // CreateTUN creates a Wintun interface with the given name. Should a Wintun
 // interface with the same name exist, it is reused.
 //
-func CreateTUN(ifname string) (Device, error) {
-       return CreateTUNWithRequestedGUID(ifname, nil)
+func CreateTUN(ifname string, mtu int) (Device, error) {
+       return CreateTUNWithRequestedGUID(ifname, nil, mtu)
 }
 
 //
 // CreateTUNWithRequestedGUID creates a Wintun interface with the given name and
 // a requested GUID. Should a Wintun interface with the same name exist, it is reused.
 //
-func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Device, error) {
+func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID, mtu int) (Device, error) {
        var err error
        var wt *wintun.Interface
 
@@ -80,12 +80,17 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Dev
                return nil, fmt.Errorf("Error creating interface: %v", err)
        }
 
+       forcedMTU := 1420
+       if mtu > 0 {
+               forcedMTU = mtu
+       }
+
        tun := &NativeTun{
                wt:        wt,
                handle:    windows.InvalidHandle,
                events:    make(chan Event, 10),
                errors:    make(chan error, 1),
-               forcedMTU: 1500,
+               forcedMTU: forcedMTU,
        }
 
        err = tun.rings.Init()