diff --git a/.gitignore b/.gitignore index bc9123a9..94280f81 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ netclient/netclient-amd64 netclient/netclient-arm netclient/netclient-arm64 netclient/netclient-32 +netclient/netclient32 +netclient/netclient.exe config/dnsconfig/ winsw.exe data/ diff --git a/functions/helpers.go b/functions/helpers.go index a44e5d44..31f892f5 100644 --- a/functions/helpers.go +++ b/functions/helpers.go @@ -108,9 +108,9 @@ func CreateServerToken(netID string) (string, error) { GRPCSSL: "off", } } - log.Println("APIConnString:",servervals.APIConnString) - log.Println("GRPCConnString:",servervals.GRPCConnString) - log.Println("GRPCSSL:",servervals.GRPCSSL) + log.Println("APIConnString:", servervals.APIConnString) + log.Println("GRPCConnString:", servervals.GRPCConnString) + log.Println("GRPCSSL:", servervals.GRPCSSL) accessToken.ServerConfig = servervals accessToken.ClientConfig.Network = netID accessToken.ClientConfig.Key = GenKey() @@ -123,7 +123,7 @@ func CreateServerToken(netID string) (string, error) { return accesskey.AccessString, err } accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(tokenjson)) - log.Println("accessstring:",accesskey.AccessString) + log.Println("accessstring:", accesskey.AccessString) network.AccessKeys = append(network.AccessKeys, accesskey) if data, err := json.Marshal(network); err != nil { return "", err @@ -235,6 +235,7 @@ func UpdateNetworkNodeAddresses(networkName string) error { } node.Address = ipaddr + node.PullChanges = "yes" data, err := json.Marshal(&node) if err != nil { return err diff --git a/go.mod b/go.mod index c3debf8c..0d891c99 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect golang.zx2c4.com/wireguard v0.0.0-20210805125648-3957e9b9dd19 // indirect - golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c + golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210913210325-91d1988e44de golang.zx2c4.com/wireguard/windows v0.4.5 // indirect google.golang.org/genproto v0.0.0-20210201151548-94839c025ad4 // indirect google.golang.org/grpc v1.35.0 diff --git a/go.sum b/go.sum index 9b4b2e54..87d82bb7 100644 --- a/go.sum +++ b/go.sum @@ -340,6 +340,8 @@ golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b h1:l4mBVCYi golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b/go.mod h1:UdS9frhv65KTfwxME1xE8+rHYoFpbm36gOud1GhBe9c= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c h1:ADNrRDI5NR23/TUCnEmlLZLt4u9DnZ2nwRkPrAcFvto= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c/go.mod h1:+1XihzyZUBJcSc5WO9SwNA7v26puQwOEDwanaxfNXPQ= +golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210913210325-91d1988e44de h1:M9Jc92kgqmVmidpnOeegP2VgO2DfHEcsUWtWMmBwNFQ= +golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210913210325-91d1988e44de/go.mod h1:+1XihzyZUBJcSc5WO9SwNA7v26puQwOEDwanaxfNXPQ= golang.zx2c4.com/wireguard/windows v0.4.5 h1:btpw+5IM8UrSl5SILCODt1bXTM2qYpcaYArM6wDlwHA= golang.zx2c4.com/wireguard/windows v0.4.5/go.mod h1:LdS2bRTWu//RpztraGz5ZkPZul60cCbmgtLTPSKrS50= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= diff --git a/models/node.go b/models/node.go index f679927c..609adadd 100644 --- a/models/node.go +++ b/models/node.go @@ -26,7 +26,7 @@ const NODE_NOOP = "noop" var seededRand *rand.Rand = rand.New( rand.NewSource(time.Now().UnixNano())) -//node struct +// node struct type Node struct { ID string `json:"id,omitempty" bson:"id,omitempty"` Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"` diff --git a/netclient/command/commands.go b/netclient/command/commands.go index 8c4631c8..626ff288 100644 --- a/netclient/command/commands.go +++ b/netclient/command/commands.go @@ -64,7 +64,7 @@ func RunUserspaceDaemon() { if err := CheckIn(cfg); err != nil { // pass } - time.Sleep(30 * time.Second) + time.Sleep(15 * time.Second) } } diff --git a/netclient/daemon/windows.go b/netclient/daemon/windows.go index 5da7490d..dbc9b2bd 100644 --- a/netclient/daemon/windows.go +++ b/netclient/daemon/windows.go @@ -35,9 +35,9 @@ func SetupWindowsDaemon() error { ncutils.Log("finished daemon setup") } // install daemon, will not overwrite - ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe install`, true) + ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe install`, false) // start daemon, will not restart or start another - ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, true) + ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false) ncutils.Log(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`) return nil } diff --git a/netclient/functions/common.go b/netclient/functions/common.go index 0098dd31..c1b4e676 100644 --- a/netclient/functions/common.go +++ b/netclient/functions/common.go @@ -131,15 +131,10 @@ func LeaveNetwork(network string) error { } else { wcclient = nodepb.NewNodeServiceClient(conn) - ctx := context.Background() - ctx, err = auth.SetJWT(wcclient, network) + ctx, err := auth.SetJWT(wcclient, network) if err != nil { log.Printf("Failed to authenticate: %v", err) } else { - if !ncutils.IsKernel() { - //wireguard.RemoveConf(node.Interface, true) - //ncutils.PrintLog("removed network tunnel "+node.Interface, 1) - } node.SetID() var header metadata.MD _, err = wcclient.DeleteNode( diff --git a/netclient/main.go b/netclient/main.go index 5c69679b..94ab8bf3 100644 --- a/netclient/main.go +++ b/netclient/main.go @@ -352,7 +352,7 @@ func main() { } if !ncutils.IsKernel() { if !local.IsWGInstalled() { - log.Fatal("Please install Windows WireGuard before using Gravitl Netclient. https://download.wireguard.com") + log.Fatal("Please install WireGuard before using Gravitl Netclient. https://download.wireguard.com") } } if len(os.Args) == 1 && ncutils.IsWindows() { diff --git a/netclient/ncutils/netclientutils.go b/netclient/ncutils/netclientutils.go index ff779f07..a6eb76d4 100644 --- a/netclient/ncutils/netclientutils.go +++ b/netclient/ncutils/netclientutils.go @@ -323,7 +323,9 @@ func Copy(src, dst string) (int64, error) { func RunCmd(command string, printerr bool) (string, error) { args := strings.Fields(command) - out, err := exec.Command(args[0], args[1:]...).CombinedOutput() + cmd := exec.Command(args[0], args[1:]...) + cmd.Wait() + out, err := cmd.CombinedOutput() if err != nil && printerr { log.Println("error running command:", command) log.Println(strings.TrimSuffix(string(out), "\n")) diff --git a/netclient/netclient-32 b/netclient/netclient-32 deleted file mode 100755 index 517ac25f..00000000 Binary files a/netclient/netclient-32 and /dev/null differ diff --git a/netclient/netclient-arm b/netclient/netclient-arm deleted file mode 100755 index 3c55f3dc..00000000 Binary files a/netclient/netclient-arm and /dev/null differ diff --git a/netclient/netclient-arm64 b/netclient/netclient-arm64 deleted file mode 100755 index 6cdb0918..00000000 Binary files a/netclient/netclient-arm64 and /dev/null differ diff --git a/netclient/netclient.exe b/netclient/netclient.exe deleted file mode 100644 index 7abfe949..00000000 Binary files a/netclient/netclient.exe and /dev/null differ diff --git a/netclient/netclient32 b/netclient/netclient32 deleted file mode 100755 index 212721b5..00000000 Binary files a/netclient/netclient32 and /dev/null differ diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 66437529..4e4ad0f7 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -9,6 +9,7 @@ import ( "runtime" "strconv" "strings" + "time" "github.com/gravitl/netmaker/models" "github.com/gravitl/netmaker/netclient/config" @@ -27,6 +28,7 @@ func SetPeers(iface string, keepalive int32, peers []wgtypes.PeerConfig) error { ncutils.PrintLog("failed to start wgctrl", 0) return err } + device, err := client.Device(iface) if err != nil { ncutils.PrintLog("failed to parse interface", 0) @@ -174,7 +176,12 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig return err } // spin up userspace / windows interface + apply the conf file - _ = RemoveConf(ifacename, false) // remove interface first + d, _ := wgclient.Device(ifacename) + for d != nil && d.Name == ifacename { + _ = RemoveConf(ifacename, false) // remove interface first + time.Sleep(time.Second >> 2) + d, _ = wgclient.Device(ifacename) + } err = ApplyConf(confPath) if err != nil { ncutils.PrintLog("failed to create wireguard interface", 1) @@ -274,10 +281,6 @@ func SetWGConfig(network string, peerupdate bool) error { } else { err = InitWireguard(&nodecfg, privkey, peers, hasGateway, gateways) } - if err != nil { - return err - } - return err } @@ -299,7 +302,7 @@ func ApplyConf(confPath string) error { var err error switch os { case "windows": - err = ApplyWindowsConf(confPath) + _ = ApplyWindowsConf(confPath) default: err = ApplyWGQuickConf(confPath) } diff --git a/netclient/wireguard/windows.go b/netclient/wireguard/windows.go index 7f00048f..38afa2cb 100644 --- a/netclient/wireguard/windows.go +++ b/netclient/wireguard/windows.go @@ -3,7 +3,7 @@ package wireguard import "github.com/gravitl/netmaker/netclient/ncutils" func ApplyWindowsConf(confPath string) error { - if _, err := ncutils.RunCmd("wireguard.exe /installtunnelservice "+confPath, true); err != nil { + if _, err := ncutils.RunCmd("wireguard.exe /installtunnelservice "+confPath, false); err != nil { return err } return nil