Fix detection of wireguard kernel module on non-amd64 archs (#200)

This commit is contained in:
Steffen Vogel
2022-01-24 22:45:52 +01:00
committed by GitHub
parent fd7282d3cf
commit 30625c68a9
2 changed files with 27 additions and 145 deletions

View File

@@ -1,16 +1,42 @@
package iface
import (
"errors"
"fmt"
"math"
"os"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"os"
)
const (
wireguarModuleName = "wireguard"
)
type NativeLink struct {
Link *netlink.Link
}
func WireguardModExists() bool {
link := newWGLink("mustnotexist")
// 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 existance of the wireguard module without actually
// creating a link.
//
// As a side-effect, this will also let the kernel lazy-load
// the wireguard module.
link.attrs.MTU = math.MaxInt
err := netlink.LinkAdd(link)
return errors.Is(err, syscall.EINVAL)
}
// Create Creates a new Wireguard interface, sets a given IP and brings it up.
// Will reuse an existing one.
func (w *WGIface) Create() error {