diff --git a/.gitignore b/.gitignore index 22268fe..a0902fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ water.test water.test.exe + +.vscode +.idea diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a20e391 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: go +go: + - 1.18 +script: + - go test -v ./... \ No newline at end of file diff --git a/README.md b/README.md index d2d9c86..a86b16f 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ If you are going to use multiple TUN devices on the Windows, there is a way to s DeviceType: water.TUN, PlatformSpecificParams: water.PlatformSpecificParams{ Name: "wintun", - Network: "172.16.1.10/24", + Network: []string{"172.16.1.10/24"}, }, }) ``` diff --git a/if.go b/if.go index 4023a1a..fdeb048 100644 --- a/if.go +++ b/if.go @@ -3,6 +3,7 @@ package water import ( "errors" "io" + "reflect" ) // Interface is a TUN/TAP interface. @@ -50,10 +51,10 @@ var zeroConfig Config // New creates a new TUN/TAP interface using config. func New(config Config) (ifce *Interface, err error) { - if zeroConfig == config { + if reflect.DeepEqual(config, zeroConfig) { config = defaultConfig() } - if config.PlatformSpecificParams == zeroConfig.PlatformSpecificParams { + if reflect.DeepEqual(config.PlatformSpecificParams, zeroConfig.PlatformSpecificParams) { config.PlatformSpecificParams = defaultPlatformSpecificParams() } switch config.DeviceType { diff --git a/params_windows.go b/params_windows.go index b417eb0..979a4dd 100644 --- a/params_windows.go +++ b/params_windows.go @@ -14,12 +14,12 @@ type PlatformSpecificParams struct { // For detail, please refer // https://github.com/OpenVPN/tap-windows6/blob/master/src/device.c#L431 // and https://github.com/songgao/water/pull/13#issuecomment-270341777 - Network string + Network []string } func defaultPlatformSpecificParams() PlatformSpecificParams { return PlatformSpecificParams{ Name: "wintun", - Network: "172.16.1.10/24", + Network: []string{"172.16.1.10/24"}, } } diff --git a/syscalls_windows.go b/syscalls_windows.go index bed5f1b..91448e4 100644 --- a/syscalls_windows.go +++ b/syscalls_windows.go @@ -2,7 +2,6 @@ package water import ( "net/netip" - "strings" "github.com/net-byte/water/winipcfg" "golang.org/x/sys/windows" @@ -42,7 +41,10 @@ func openDev(config Config) (ifce *Interface, err error) { nativeTunDevice := dev.(*tun.NativeTun) link := winipcfg.LUID(nativeTunDevice.LUID()) - networks := strings.Split(config.PlatformSpecificParams.Network, ",") + networks := config.PlatformSpecificParams.Network + if len(networks) == 0 { + panic("network is empty") + } ipPrefix := []netip.Prefix{} for _, n := range networks { ip, err := netip.ParsePrefix(n)