mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-10-07 17:40:56 +08:00
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>
This commit is contained in:

committed by
Jason A. Donenfeld

parent
6aefb61355
commit
203554620d
36
device/bindsocketshim.go
Normal file
36
device/bindsocketshim.go
Normal file
@@ -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
|
||||
}
|
Reference in New Issue
Block a user