forked from WireGuard/wgctrl-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_linux.go
35 lines (29 loc) · 892 Bytes
/
os_linux.go
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
//+build linux
package wgctrl
import (
"golang.zx2c4.com/wireguard/wgctrl/internal/wginternal"
"golang.zx2c4.com/wireguard/wgctrl/internal/wglinux"
"golang.zx2c4.com/wireguard/wgctrl/internal/wguser"
)
// newClients configures wginternal.Clients for Linux systems.
func newClients() ([]wginternal.Client, error) {
var clients []wginternal.Client
// Linux has an in-kernel WireGuard implementation. Determine if it is
// available and make use of it if so.
kc, ok, err := wglinux.New()
if err != nil {
return nil, err
}
if ok {
clients = append(clients, kc)
}
// Although it isn't recommended to use userspace implementations on Linux,
// it can be used. We make use of it in integration tests as well.
uc, err := wguser.New()
if err != nil {
return nil, err
}
// Kernel devices seem to appear first in wg(8).
clients = append(clients, uc)
return clients, nil
}