mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
userspace implementation
This commit is contained in:
parent
a7a45e60e1
commit
50250d5859
5 changed files with 22 additions and 10 deletions
|
@ -109,6 +109,8 @@ func Uninstall() error {
|
|||
daemon.CleanupWindows()
|
||||
} else if ncutils.IsMac() {
|
||||
daemon.CleanupMac()
|
||||
} else if !ncutils.IsKernel() {
|
||||
ncutils.PrintLog("manual cleanup required",1)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"os/exec"
|
||||
"os"
|
||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||
)
|
||||
|
||||
|
@ -54,9 +55,8 @@ func SetIPForwardingMac() error {
|
|||
func IsWGInstalled() bool {
|
||||
out, err := ncutils.RunCmd("wg help", true)
|
||||
if err != nil {
|
||||
_, err1 := exec.LookPath("wireguard-go")
|
||||
_, err2 := exec.LookPath("boringtun")
|
||||
return err1 == nil || err2 == nil
|
||||
_, err = exec.LookPath(os.Getenv("WG_QUICK_USERSPACE_IMPLEMENTATION"))
|
||||
return err == nil
|
||||
}
|
||||
return strings.Contains(out, "Available subcommand")
|
||||
}
|
||||
|
|
|
@ -341,14 +341,16 @@ func main() {
|
|||
}
|
||||
|
||||
_, err = exec.LookPath("wg")
|
||||
uspace := ncutils.GetWireGuard()
|
||||
if err != nil {
|
||||
userspace := os.Getenv("WG_QUICK_USERSPACE_IMPLEMENTATION")
|
||||
if userspace == "" {
|
||||
if uspace == "wg" {
|
||||
log.Println(err)
|
||||
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 !local.IsWGInstalled() {
|
||||
|
|
|
@ -48,11 +48,19 @@ func IsLinux() bool {
|
|||
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 {
|
||||
//TODO
|
||||
//Replace && true with some config file value
|
||||
//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 ==
|
||||
|
|
|
@ -45,7 +45,7 @@ func SetPeers(iface string, keepalive int32, peers []wgtypes.PeerConfig) error {
|
|||
for _, currentPeer := range devicePeers {
|
||||
if currentPeer.AllowedIPs[0].String() == peer.AllowedIPs[0].String() &&
|
||||
currentPeer.PublicKey.String() != peer.PublicKey.String() {
|
||||
_, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
||||
_, err := ncutils.RunCmd( "wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
||||
if err != nil {
|
||||
log.Println("error removing peer", peer.Endpoint.String())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue