summaryrefslogtreecommitdiffhomepage
path: root/device/bindsocketshim.go
blob: 68e150408370295b4c3ccf6bb5b156d4b1bfa613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2017-2020 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.BindSocketToInterface); ok {
		return iface.BindSocketToInterface4(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.BindSocketToInterface); ok {
		return iface.BindSocketToInterface6(interfaceIndex, blackhole)
	}
	return nil
}

// TODO(crawshaw): this method is a compatibility shim. Replace with direct use of conn.
func (device *Device) PeekLookAtSocketFd4() (fd int, err error) {
	if device.net.bind == nil {
		return -1, errors.New("Bind is not yet initialized")
	}

	if iface, ok := device.net.bind.(conn.PeekLookAtSocketFd); ok {
		return iface.PeekLookAtSocketFd4()
	}
	return -1, errors.New("unimplemented")
}

// TODO(crawshaw): this method is a compatibility shim. Replace with direct use of conn.
func (device *Device) PeekLookAtSocketFd6() (fd int, err error) {
	if device.net.bind == nil {
		return -1, errors.New("Bind is not yet initialized")
	}

	if iface, ok := device.net.bind.(conn.PeekLookAtSocketFd); ok {
		return iface.PeekLookAtSocketFd6()
	}
	return -1, errors.New("unimplemented")
}