summaryrefslogtreecommitdiff
path: root/conn/boundif_windows.go
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@tailscale.com>2019-11-07 11:13:05 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2020-05-02 01:46:42 -0600
commit203554620dc8114de1ff70bb30b80f828e9e26ad (patch)
tree49f36961f2090dc07d15cad3204a1a3531dc233d /conn/boundif_windows.go
parent6aefb61355c9da539383dd0c2bc5f2bb3dbb3963 (diff)
downloadwireguard-go-203554620dc8114de1ff70bb30b80f828e9e26ad.tar.gz
wireguard-go-203554620dc8114de1ff70bb30b80f828e9e26ad.zip
conn: introduce new package that splits out the Bind and Endpoint types
The sticky socket code stays in the device package for now, as it reaches deeply into the peer list. This is the first step in an effort to split some code out of the very busy device package. Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
Diffstat (limited to '')
-rw-r--r--conn/boundif_windows.go (renamed from device/boundif_windows.go)19
1 files changed, 7 insertions, 12 deletions
diff --git a/device/boundif_windows.go b/conn/boundif_windows.go
index 6908415..fe38d05 100644
--- a/device/boundif_windows.go
+++ b/conn/boundif_windows.go
@@ -3,11 +3,10 @@
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
-package device
+package conn
import (
"encoding/binary"
- "errors"
"unsafe"
"golang.org/x/sys/windows"
@@ -18,17 +17,13 @@ const (
sockoptIPV6_UNICAST_IF = 31
)
-func (device *Device) BindSocketToInterface4(interfaceIndex uint32, blackhole bool) error {
+func (bind *nativeBind) BindSocketToInterface4(interfaceIndex uint32, blackhole bool) error {
/* MSDN says for IPv4 this needs to be in net byte order, so that it's like an IP address with leading zeros. */
bytes := make([]byte, 4)
binary.BigEndian.PutUint32(bytes, interfaceIndex)
interfaceIndex = *(*uint32)(unsafe.Pointer(&bytes[0]))
- if device.net.bind == nil {
- return errors.New("Bind is not yet initialized")
- }
-
- sysconn, err := device.net.bind.(*nativeBind).ipv4.SyscallConn()
+ sysconn, err := bind.ipv4.SyscallConn()
if err != nil {
return err
}
@@ -41,12 +36,12 @@ func (device *Device) BindSocketToInterface4(interfaceIndex uint32, blackhole bo
if err != nil {
return err
}
- device.net.bind.(*nativeBind).blackhole4 = blackhole
+ bind.blackhole4 = blackhole
return nil
}
-func (device *Device) BindSocketToInterface6(interfaceIndex uint32, blackhole bool) error {
- sysconn, err := device.net.bind.(*nativeBind).ipv6.SyscallConn()
+func (bind *nativeBind) BindSocketToInterface6(interfaceIndex uint32, blackhole bool) error {
+ sysconn, err := bind.ipv6.SyscallConn()
if err != nil {
return err
}
@@ -59,6 +54,6 @@ func (device *Device) BindSocketToInterface6(interfaceIndex uint32, blackhole bo
if err != nil {
return err
}
- device.net.bind.(*nativeBind).blackhole6 = blackhole
+ bind.blackhole6 = blackhole
return nil
}