mirror of
https://github.com/net-byte/water.git
synced 2024-04-21 12:21:38 +00:00
update config
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
water.test
|
||||
water.test.exe
|
||||
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.18
|
||||
script:
|
||||
- go test -v ./...
|
||||
@@ -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,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
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user