Browse Source

tun: match windows CreateTUN signature to the Linux variant

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
[zx2c4: fix default value]
Avery Pennarun 1 year ago
parent
commit
1b6c8ddbe8
2 changed files with 10 additions and 5 deletions
  1. 1
    1
      main_windows.go
  2. 9
    4
      tun/tun_windows.go

+ 1
- 1
main_windows.go View File

@@ -37,7 +37,7 @@ func main() {
37 37
 	logger.Info.Println("Starting wireguard-go version", device.WireGuardGoVersion)
38 38
 	logger.Debug.Println("Debug log enabled")
39 39
 
40
-	tun, err := tun.CreateTUN(interfaceName)
40
+	tun, err := tun.CreateTUN(interfaceName, 0)
41 41
 	if err == nil {
42 42
 		realInterfaceName, err2 := tun.Name()
43 43
 		if err2 == nil {

+ 9
- 4
tun/tun_windows.go View File

@@ -54,15 +54,15 @@ func nanotime() int64
54 54
 // CreateTUN creates a Wintun interface with the given name. Should a Wintun
55 55
 // interface with the same name exist, it is reused.
56 56
 //
57
-func CreateTUN(ifname string) (Device, error) {
58
-	return CreateTUNWithRequestedGUID(ifname, nil)
57
+func CreateTUN(ifname string, mtu int) (Device, error) {
58
+	return CreateTUNWithRequestedGUID(ifname, nil, mtu)
59 59
 }
60 60
 
61 61
 //
62 62
 // CreateTUNWithRequestedGUID creates a Wintun interface with the given name and
63 63
 // a requested GUID. Should a Wintun interface with the same name exist, it is reused.
64 64
 //
65
-func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Device, error) {
65
+func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID, mtu int) (Device, error) {
66 66
 	var err error
67 67
 	var wt *wintun.Interface
68 68
 
@@ -80,12 +80,17 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Dev
80 80
 		return nil, fmt.Errorf("Error creating interface: %v", err)
81 81
 	}
82 82
 
83
+	forcedMTU := 1420
84
+	if mtu > 0 {
85
+		forcedMTU = mtu
86
+	}
87
+
83 88
 	tun := &NativeTun{
84 89
 		wt:        wt,
85 90
 		handle:    windows.InvalidHandle,
86 91
 		events:    make(chan Event, 10),
87 92
 		errors:    make(chan error, 1),
88
-		forcedMTU: 1500,
93
+		forcedMTU: forcedMTU,
89 94
 	}
90 95
 
91 96
 	err = tun.rings.Init()

Loading…
Cancel
Save