wgctrl-go
wgctrl-go copied to clipboard
internal/wgfreebsd: support for new FreeBSD kernel interface
@mattmacy is working on a FreeBSD kernel implementation of WireGuard at https://github.com/mattmacy/wg-fbsd and the repo is going to be moved to https://git.zx2c4.com/wireguard-freebsd/about/ soon. We should support this interface.
@mdlayher Is there still no support for FreeBSD with wgctrl-go? Just ran into an issue trying to retrieve the interface while attempting to integrate on FreeBSD.
No work has been done on FreeBSD kernel interfaces at this point. Userspace should work fine.
@mdlayher is there any way to tell wgctrl to use userspace when calling wgctrl.New? If not, is there a way to trick it into thinking it should be using userspace? I think that would be sufficient for our purposes.
You shouldn't need to care about the underlying implementation. If wireguard-go or similar is running and exposes a control socket, it should be picked up automatically. We look for sockets using https://github.com/WireGuard/wgctrl-go/blob/master/internal/wguser/conn_unix.go#L19-L26. If they exist at a different path, that path would need to be added too.
I'm definitely missing something. Not sure which path sockets get added to, but wireguard was installed on freebsd using:
pkg install wireguard
There is an active, functioning interface, but no /var/run/wireguard
root@freebsd-machine:~ # wg
interface: wg0
public key: XXXXXXXXXXXXX
private key: (hidden)
listening port: 51821
peer: YYYYYYYYYYYYYY
endpoint: 1.2.3.4:51821
allowed ips: 10.101.0.1/32
latest handshake: 29 seconds ago
transfer: 5.09 KiB received, 20.28 KiB sent
persistent keepalive: every 20 seconds
root@freebsd-machine:~ # sockstat -l
? ? ? ? udp6 *:51821 *:*
? ? ? ? udp4 *:51821 *:*
and wgctrl.New() returns no devices.
Based on https://www.freshports.org/net/wireguard, you're probably using the kernel module implementation, which is not supported yet.
I've started with implementation. Much of the code is similar to the OpenBSD kernel interface with the exception of the encoding which uses FreeBSD's nv(9) library.
I am currently using CGo to link against libnv which might not be optimal but got me started the fastest.
@mdlayher Is it acceptable to use CGo for wgctrl-go? Or do we need to implement a pure Go implementation of libnv?
There is already an incompatible Golang implementation for OpenZFS nvlist here: https://pkg.go.dev/git.dolansoft.org/lorenz/go-zfs/nvlist
Nice work! I have no objections to starting with cgo. Presumably that library is widely used on freebsd anyway?
I have no objections to starting with cgo.
Thanks. I will try to finish the the ConfigureDevice()
today and add some tests.
Presumably that library is widely used on freebsd anyway?
Yes, it ships with the standard installation.
@mdlayher I just pushed a version to #126 which implements the full client interface.
I've tested it with my own code on an ARM64 FreeBSD VM running on my M1 Mac with Parallels.