2019-11-07 17:13:05 +01:00
|
|
|
/* SPDX-License-Identifier: MIT
|
|
|
|
*
|
2020-05-02 10:08:26 +02:00
|
|
|
* Copyright (C) 2017-2020 WireGuard LLC. All Rights Reserved.
|
2019-11-07 17:13:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2020-06-07 09:24:06 +02:00
|
|
|
if iface, ok := device.net.bind.(conn.BindSocketToInterface); ok {
|
|
|
|
return iface.BindSocketToInterface4(interfaceIndex, blackhole)
|
2019-11-07 17:13:05 +01:00
|
|
|
}
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2020-06-07 09:24:06 +02:00
|
|
|
if iface, ok := device.net.bind.(conn.BindSocketToInterface); ok {
|
|
|
|
return iface.BindSocketToInterface6(interfaceIndex, blackhole)
|
2019-11-07 17:13:05 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|