mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 01:07:41 +08:00
use wireguard.conf files for all
This commit is contained in:
@@ -8,8 +8,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
nodepb "github.com/gravitl/netmaker/grpc"
|
nodepb "github.com/gravitl/netmaker/grpc"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
@@ -244,22 +242,7 @@ func RemoveLocalInstance(cfg *config.ClientConfig, networkName string) error {
|
|||||||
|
|
||||||
// DeleteInterface - delete an interface of a network
|
// DeleteInterface - delete an interface of a network
|
||||||
func DeleteInterface(ifacename string, postdown string) error {
|
func DeleteInterface(ifacename string, postdown string) error {
|
||||||
var err error
|
return wireguard.RemoveConf(ifacename, true)
|
||||||
if !ncutils.IsKernel() {
|
|
||||||
err = wireguard.RemoveConf(ifacename, true)
|
|
||||||
} else {
|
|
||||||
ipExec, errN := exec.LookPath("ip")
|
|
||||||
err = errN
|
|
||||||
if err != nil {
|
|
||||||
ncutils.PrintLog(err.Error(), 1)
|
|
||||||
}
|
|
||||||
_, err = ncutils.RunCmd(ipExec+" link del "+ifacename, false)
|
|
||||||
if postdown != "" {
|
|
||||||
runcmds := strings.Split(postdown, "; ")
|
|
||||||
err = ncutils.RunCmds(runcmds, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WipeLocal - wipes local instance
|
// WipeLocal - wipes local instance
|
||||||
@@ -271,27 +254,11 @@ func WipeLocal(network string) error {
|
|||||||
nodecfg := cfg.Node
|
nodecfg := cfg.Node
|
||||||
ifacename := nodecfg.Interface
|
ifacename := nodecfg.Interface
|
||||||
if ifacename != "" {
|
if ifacename != "" {
|
||||||
if !ncutils.IsKernel() {
|
|
||||||
if err = wireguard.RemoveConf(ifacename, true); err == nil {
|
if err = wireguard.RemoveConf(ifacename, true); err == nil {
|
||||||
ncutils.PrintLog("removed WireGuard interface: "+ifacename, 1)
|
ncutils.PrintLog("removed WireGuard interface: "+ifacename, 1)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ipExec, err := exec.LookPath("ip")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
out, err := ncutils.RunCmd(ipExec+" link del "+ifacename, false)
|
|
||||||
dontprint := strings.Contains(out, "does not exist") || strings.Contains(out, "Cannot find device")
|
|
||||||
if err != nil && !dontprint {
|
|
||||||
ncutils.PrintLog("error running command: "+ipExec+" link del "+ifacename, 1)
|
|
||||||
ncutils.PrintLog(out, 1)
|
|
||||||
}
|
|
||||||
if nodecfg.PostDown != "" {
|
|
||||||
runcmds := strings.Split(nodecfg.PostDown, "; ")
|
|
||||||
_ = ncutils.RunCmds(runcmds, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
home := ncutils.GetNetclientPathSpecific()
|
home := ncutils.GetNetclientPathSpecific()
|
||||||
if ncutils.FileExists(home + "netconfig-" + network) {
|
if ncutils.FileExists(home + "netconfig-" + network) {
|
||||||
_ = os.Remove(home + "netconfig-" + network)
|
_ = os.Remove(home + "netconfig-" + network)
|
||||||
|
Reference in New Issue
Block a user