Files
cunicu/pkg/wg/kernel_linux.go
Steffen Vogel 7eb4a9afdd fix spelling of WireGuard
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2022-08-25 18:55:53 +02:00

31 lines
700 B
Go

package wg
import (
"errors"
"math"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
)
func KernelModuleExists() bool {
l := &netlink.Wireguard{
LinkAttrs: netlink.NewLinkAttrs(),
}
l.LinkAttrs.Name = "must-not-exist"
// We willingly try to create a device with an invalid
// MTU here as the validation of the MTU will be performed after
// the validation of the link kind and hence allows us to check
// for the existence of the WireGuard module without actually
// creating a link.
//
// As a side-effect, this will also let the kernel lazy-load
// the WireGuard module.
l.LinkAttrs.MTU = math.MaxInt
err := netlink.LinkAdd(l)
return errors.Is(err, unix.EINVAL)
}