update config

This commit is contained in:
Alex Tsai
2022-08-28 13:10:16 +08:00
parent 0193f36b6a
commit 7d45f12425
6 changed files with 18 additions and 7 deletions
+3
View File
@@ -1,2 +1,5 @@
water.test
water.test.exe
.vscode
.idea
+5
View File
@@ -0,0 +1,5 @@
language: go
go:
- 1.18
script:
- go test -v ./...
+1 -1
View File
@@ -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"},
},
})
```
+3 -2
View File
@@ -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 {
+2 -2
View File
@@ -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"},
}
}
+4 -2
View File
@@ -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)