diff options
author | David Crawshaw <crawshaw@tailscale.com> | 2019-11-07 11:13:05 -0500 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-05-02 01:46:42 -0600 |
commit | 203554620dc8114de1ff70bb30b80f828e9e26ad (patch) | |
tree | 49f36961f2090dc07d15cad3204a1a3531dc233d /device/bindsocketshim.go | |
parent | 6aefb61355c9da539383dd0c2bc5f2bb3dbb3963 (diff) | |
download | wireguard-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-- | device/bindsocketshim.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/device/bindsocketshim.go b/device/bindsocketshim.go new file mode 100644 index 0000000..c4dd4ef --- /dev/null +++ b/device/bindsocketshim.go @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved. + */ + +package device + +import ( + "errors" + + "golang.zx2c4.com/wireguard/conn" +) + +// TODO(crawshaw): this method is a compatibility shim. Replace with direct use of conn. +func (device *Device) BindSocketToInterface4(interfaceIndex uint32, blackhole bool) error { + if device.net.bind == nil { + return errors.New("Bind is not yet initialized") + } + + if iface, ok := device.net.bind.(conn.BindToInterface); ok { + return iface.BindToInterface4(interfaceIndex, blackhole) + } + return nil +} + +// TODO(crawshaw): this method is a compatibility shim. Replace with direct use of conn. +func (device *Device) BindSocketToInterface6(interfaceIndex uint32, blackhole bool) error { + if device.net.bind == nil { + return errors.New("Bind is not yet initialized") + } + + if iface, ok := device.net.bind.(conn.BindToInterface); ok { + return iface.BindToInterface6(interfaceIndex, blackhole) + } + return nil +} |