userspace implementation

This commit is contained in:
afeiszli
2021-09-21 21:35:52 -04:00
parent a7a45e60e1
commit 50250d5859
5 changed files with 22 additions and 10 deletions

View File

@@ -109,6 +109,8 @@ func Uninstall() error {
daemon.CleanupWindows() daemon.CleanupWindows()
} else if ncutils.IsMac() { } else if ncutils.IsMac() {
daemon.CleanupMac() daemon.CleanupMac()
} else if !ncutils.IsKernel() {
ncutils.PrintLog("manual cleanup required",1)
} }
return err return err

View File

@@ -8,6 +8,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"os/exec" "os/exec"
"os"
"github.com/gravitl/netmaker/netclient/ncutils" "github.com/gravitl/netmaker/netclient/ncutils"
) )
@@ -54,9 +55,8 @@ func SetIPForwardingMac() error {
func IsWGInstalled() bool { func IsWGInstalled() bool {
out, err := ncutils.RunCmd("wg help", true) out, err := ncutils.RunCmd("wg help", true)
if err != nil { if err != nil {
_, err1 := exec.LookPath("wireguard-go") _, err = exec.LookPath(os.Getenv("WG_QUICK_USERSPACE_IMPLEMENTATION"))
_, err2 := exec.LookPath("boringtun") return err == nil
return err1 == nil || err2 == nil
} }
return strings.Contains(out, "Available subcommand") return strings.Contains(out, "Available subcommand")
} }

View File

@@ -341,13 +341,15 @@ func main() {
} }
_, err = exec.LookPath("wg") _, err = exec.LookPath("wg")
uspace := ncutils.GetWireGuard()
if err != nil { if err != nil {
userspace := os.Getenv("WG_QUICK_USERSPACE_IMPLEMENTATION") if uspace == "wg" {
if userspace == "" {
log.Println(err) log.Println(err)
log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.") log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.")
} }
ncutils.PrintLog("Running with userspace wireguard: "+userspace, 0) ncutils.PrintLog("Running with userspace wireguard: "+uspace, 0)
} else if uspace != "wg" {
log.Println("running userspace WireGuard with "+uspace )
} }
} }
if !ncutils.IsKernel() { if !ncutils.IsKernel() {

View File

@@ -48,11 +48,19 @@ func IsLinux() bool {
return runtime.GOOS == "linux" return runtime.GOOS == "linux"
} }
func GetWireGuard() string {
userspace := os.Getenv("WG_QUICK_USERSPACE_IMPLEMENTATION")
if userspace != "" && (userspace == "boringtun" || userspace == "wireguard-go") {
return userspace
}
return "wg"
}
func IsKernel() bool { func IsKernel() bool {
//TODO //TODO
//Replace && true with some config file value //Replace && true with some config file value
//This value should be something like kernelmode, which should be 'on' by default. //This value should be something like kernelmode, which should be 'on' by default.
return IsLinux() && true return IsLinux() && os.Getenv("WG_QUICK_USERSPACE_IMPLEMENTATION") == ""
} }
// == database returned nothing error == // == database returned nothing error ==