2
0
Эх сурвалжийг харах

Merge pull request #3 from repos-holder/windows

Fix Windows support
Ettore Di Giacinto 3 жил өмнө
parent
commit
b2c8754f7a

+ 22 - 1
pkg/edgevpn/interface_windows.go

@@ -3,7 +3,11 @@
 
 package edgevpn
 
-import "github.com/songgao/water"
+import (
+	"net"
+
+	"github.com/songgao/water"
+)
 
 func (e *EdgeVPN) prepareInterface() error {
 
@@ -11,8 +15,25 @@ func (e *EdgeVPN) prepareInterface() error {
 }
 
 func (e *EdgeVPN) createInterface() (*water.Interface, error) {
+	// TUN on Windows requires address and network to be set on device creation stage
+	// We also set network to 0.0.0.0/0 so we able to reach networks behind the node
+	// https://github.com/songgao/water/blob/master/params_windows.go
+	// https://gitlab.com/openconnect/openconnect/-/blob/master/tun-win32.c
+	ip, _, err := net.ParseCIDR(e.config.InterfaceAddress)
+	if err != nil {
+		return nil, err
+	}
+	network := net.IPNet{
+		IP:   ip,
+		Mask: net.IPv4Mask(0,0,0,0),
+	}
 	config := water.Config{
 		DeviceType: e.config.DeviceType,
+		PlatformSpecificParams: water.PlatformSpecificParams{
+			ComponentID:   "tap0901",
+			InterfaceName: e.config.InterfaceName,
+			Network:       network.String(),
+		},
 	}
 
 	return water.New(config)