From 994f40f95c5f892b75f28f65a0507d513b68e35f Mon Sep 17 00:00:00 2001 From: netbyte Date: Tue, 26 Jul 2022 23:00:18 +0800 Subject: [PATCH] update params --- params_darwin.go | 13 +++++++++++-- params_linux.go | 11 +++++++++++ params_windows.go | 6 +++--- syscalls_windows.go | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/params_darwin.go b/params_darwin.go index f33a07a..915a3bf 100644 --- a/params_darwin.go +++ b/params_darwin.go @@ -17,14 +17,23 @@ const ( // Currently it is not possible to set the interface name in macOS. type PlatformSpecificParams struct { // Name is the name for the interface to be used. - // // For TunTapOSXDriver, it should be something like "tap0". // For SystemDriver, the name should match `utun[0-9]+`, e.g. utun233 Name string - // Driver should be set if an alternative driver is desired // e.g. TunTapOSXDriver Driver MacOSDriverProvider + // Network is required when creating a TUN interface. The library will call + // net.ParseCIDR() to parse this string into LocalIP, RemoteNetaddr, + // RemoteNetmask. The underlying driver will need those to generate ARP + // response to Windows kernel, to emulate an TUN interface. + // Please note that it cannot perceive the IP changes caused by DHCP, user + // configuration to the adapter and etc,. If IP changed, please reconfigure + // the adapter using syscall, just like openDev(). + // 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 } func defaultPlatformSpecificParams() PlatformSpecificParams { diff --git a/params_linux.go b/params_linux.go index 34e9898..b7f2007 100644 --- a/params_linux.go +++ b/params_linux.go @@ -38,6 +38,17 @@ type PlatformSpecificParams struct { // uses multiple file descriptors (queues) to parallelize packets sending // or receiving. MultiQueue bool + // Network is required when creating a TUN interface. The library will call + // net.ParseCIDR() to parse this string into LocalIP, RemoteNetaddr, + // RemoteNetmask. The underlying driver will need those to generate ARP + // response to Windows kernel, to emulate an TUN interface. + // Please note that it cannot perceive the IP changes caused by DHCP, user + // configuration to the adapter and etc,. If IP changed, please reconfigure + // the adapter using syscall, just like openDev(). + // 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 } func defaultPlatformSpecificParams() PlatformSpecificParams { diff --git a/params_windows.go b/params_windows.go index 7a193e3..b417eb0 100644 --- a/params_windows.go +++ b/params_windows.go @@ -3,7 +3,7 @@ package water // PlatformSpecificParams defines parameters in Config that are specific to // Windows. A zero-value of such type is valid. type PlatformSpecificParams struct { - InterfaceName string + Name string // Network is required when creating a TUN interface. The library will call // net.ParseCIDR() to parse this string into LocalIP, RemoteNetaddr, // RemoteNetmask. The underlying driver will need those to generate ARP @@ -19,7 +19,7 @@ type PlatformSpecificParams struct { func defaultPlatformSpecificParams() PlatformSpecificParams { return PlatformSpecificParams{ - InterfaceName: "wintun", - Network: "172.16.1.10/24", + Name: "wintun", + Network: "172.16.1.10/24", } } diff --git a/syscalls_windows.go b/syscalls_windows.go index 4ccc985..f0be7d4 100644 --- a/syscalls_windows.go +++ b/syscalls_windows.go @@ -31,7 +31,7 @@ func openDev(config Config) (ifce *Interface, err error) { 0xFFFF, [8]byte{0xFF, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}, } - dev, err := tun.CreateTUNWithRequestedGUID(config.PlatformSpecificParams.InterfaceName, id, 0) + dev, err := tun.CreateTUNWithRequestedGUID(config.PlatformSpecificParams.Name, id, 0) if err != nil { return nil, err }