From c741cbfc2ceb4660bc8115f421cfaf93ab40bb3f Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 16:58:46 -0500 Subject: [PATCH 1/8] fixing mac daemon --- netclient/daemon/macos.go | 42 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/netclient/daemon/macos.go b/netclient/daemon/macos.go index 4badac4d..6ef8b64b 100644 --- a/netclient/daemon/macos.go +++ b/netclient/daemon/macos.go @@ -88,25 +88,29 @@ func CreateMacService(servicename string) error { // MacDaemonString - the file contents for the mac netclient daemon service (launchdaemon) func MacDaemonString() string { return ` - - - - Labelcom.gravitl.netclient - ProgramArguments - - /usr/local/bin/netclient - daemon - - StandardOutPath/etc/netclient/com.gravitl.netclient.log - StandardErrorPath/etc/netclient/com.gravitl.netclient.log - AbandonProcessGroup - EnvironmentVariables - - PATH - /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin - - - + + + + Labelcom.gravitl.netclient + ProgramArguments + + /usr/local/bin/netclient + daemon + + StandardOutPath/etc/netclient/com.gravitl.netclient.log + StandardErrorPath/etc/netclient/com.gravitl.netclient.log + RunAtLoad + + KeepAlive + + AbandonProcessGroup + EnvironmentVariables + + PATH + /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin + + + ` } From 1f9a94a4ed45996fb09dd652b9d49ab8046d24fc Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 17:46:42 -0500 Subject: [PATCH 2/8] test logs --- netclient/wireguard/mac.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netclient/wireguard/mac.go b/netclient/wireguard/mac.go index ae22530e..bc896ddf 100644 --- a/netclient/wireguard/mac.go +++ b/netclient/wireguard/mac.go @@ -3,6 +3,7 @@ package wireguard import ( "bufio" "errors" + "log" "os" "strconv" "strings" @@ -228,6 +229,7 @@ func getConfig(path string) string { // SetMacPeerRoutes - sets routes for interface from the peer list for all AllowedIps func SetMacPeerRoutes(realIface string) error { + log.Println("DELETE ME: setting mac peer routes") var err error peerIPs := getPeerIPs(realIface) if len(peerIPs) == 0 { @@ -235,6 +237,7 @@ func SetMacPeerRoutes(realIface string) error { } for _, i := range peerIPs { if i != "" { + log.Println("DELETE ME: adding route " + i + " on iface " + realIface) err = addRoute(i, realIface) if err != nil { ncutils.PrintLog("error adding route to "+realIface+" for "+i, 1) From a06b451bd94c9cf625fb27e0b4b9b5a0800de431 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 19:49:13 -0500 Subject: [PATCH 3/8] test logs --- netclient/functions/mqhandlers.go | 2 ++ netclient/wireguard/mac.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/netclient/functions/mqhandlers.go b/netclient/functions/mqhandlers.go index 321c0079..fdb15415 100644 --- a/netclient/functions/mqhandlers.go +++ b/netclient/functions/mqhandlers.go @@ -3,6 +3,7 @@ package functions import ( "encoding/json" "fmt" + "log" "runtime" "strings" "time" @@ -183,6 +184,7 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) { ncutils.Log("error retrieving mac iface: " + err.Error()) return } + log.Println("DELETE ME: got iface for mac:" + iface) } err = wireguard.SetPeers(iface, &cfg.Node, peerUpdate.Peers) if err != nil { diff --git a/netclient/wireguard/mac.go b/netclient/wireguard/mac.go index bc896ddf..1004b945 100644 --- a/netclient/wireguard/mac.go +++ b/netclient/wireguard/mac.go @@ -232,6 +232,8 @@ func SetMacPeerRoutes(realIface string) error { log.Println("DELETE ME: setting mac peer routes") var err error peerIPs := getPeerIPs(realIface) + log.Println("DELETE ME: peer ips:") + log.Println(peerIPs) if len(peerIPs) == 0 { return err } From 2c93986ad0750e572d0c3430794b946ae82a5bd0 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 19:59:24 -0500 Subject: [PATCH 4/8] additional log --- netclient/wireguard/mac.go | 1 + 1 file changed, 1 insertion(+) diff --git a/netclient/wireguard/mac.go b/netclient/wireguard/mac.go index 1004b945..545ac1ec 100644 --- a/netclient/wireguard/mac.go +++ b/netclient/wireguard/mac.go @@ -203,6 +203,7 @@ func addRoute(addr string, iface string) error { return err } if !(strings.Contains(out, iface)) { + log.Println("DELETE ME: running command - route -q -n add -" + inetx + " " + addr + " -interface " + iface) _, err = ncutils.RunCmd("route -q -n add -"+inetx+" "+addr+" -interface "+iface, true) } return err From 0109ed0480ed221f6e4f09ff5316c961a3ee3297 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 20:06:31 -0500 Subject: [PATCH 5/8] cmd.Start --- netclient/ncutils/netclientutils_darwin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netclient/ncutils/netclientutils_darwin.go b/netclient/ncutils/netclientutils_darwin.go index 6817ee49..56e301f8 100644 --- a/netclient/ncutils/netclientutils_darwin.go +++ b/netclient/ncutils/netclientutils_darwin.go @@ -10,6 +10,7 @@ import ( func RunCmd(command string, printerr bool) (string, error) { args := strings.Fields(command) cmd := exec.Command(args[0], args[1:]...) + cmd.Start() cmd.Wait() out, err := cmd.CombinedOutput() if err != nil && printerr { @@ -28,5 +29,3 @@ func RunCmdFormatted(command string, printerr bool) (string, error) { func GetEmbedded() error { return nil } - - From d59dbdbebd1e2f4668f0977234a825c970995bfd Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 20:08:31 -0500 Subject: [PATCH 6/8] cmd.Start --- netclient/ncutils/netclientutils_darwin.go | 1 - 1 file changed, 1 deletion(-) diff --git a/netclient/ncutils/netclientutils_darwin.go b/netclient/ncutils/netclientutils_darwin.go index 56e301f8..2f4d9f81 100644 --- a/netclient/ncutils/netclientutils_darwin.go +++ b/netclient/ncutils/netclientutils_darwin.go @@ -10,7 +10,6 @@ import ( func RunCmd(command string, printerr bool) (string, error) { args := strings.Fields(command) cmd := exec.Command(args[0], args[1:]...) - cmd.Start() cmd.Wait() out, err := cmd.CombinedOutput() if err != nil && printerr { From f686b12bce854fcf115a0b50b461c87667492f9a Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 20:34:14 -0500 Subject: [PATCH 7/8] removing logs --- netclient/functions/mqhandlers.go | 2 -- netclient/wireguard/mac.go | 4 ---- 2 files changed, 6 deletions(-) diff --git a/netclient/functions/mqhandlers.go b/netclient/functions/mqhandlers.go index fdb15415..321c0079 100644 --- a/netclient/functions/mqhandlers.go +++ b/netclient/functions/mqhandlers.go @@ -3,7 +3,6 @@ package functions import ( "encoding/json" "fmt" - "log" "runtime" "strings" "time" @@ -184,7 +183,6 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) { ncutils.Log("error retrieving mac iface: " + err.Error()) return } - log.Println("DELETE ME: got iface for mac:" + iface) } err = wireguard.SetPeers(iface, &cfg.Node, peerUpdate.Peers) if err != nil { diff --git a/netclient/wireguard/mac.go b/netclient/wireguard/mac.go index 545ac1ec..3c60ce2a 100644 --- a/netclient/wireguard/mac.go +++ b/netclient/wireguard/mac.go @@ -203,7 +203,6 @@ func addRoute(addr string, iface string) error { return err } if !(strings.Contains(out, iface)) { - log.Println("DELETE ME: running command - route -q -n add -" + inetx + " " + addr + " -interface " + iface) _, err = ncutils.RunCmd("route -q -n add -"+inetx+" "+addr+" -interface "+iface, true) } return err @@ -230,17 +229,14 @@ func getConfig(path string) string { // SetMacPeerRoutes - sets routes for interface from the peer list for all AllowedIps func SetMacPeerRoutes(realIface string) error { - log.Println("DELETE ME: setting mac peer routes") var err error peerIPs := getPeerIPs(realIface) - log.Println("DELETE ME: peer ips:") log.Println(peerIPs) if len(peerIPs) == 0 { return err } for _, i := range peerIPs { if i != "" { - log.Println("DELETE ME: adding route " + i + " on iface " + realIface) err = addRoute(i, realIface) if err != nil { ncutils.PrintLog("error adding route to "+realIface+" for "+i, 1) From 54c63543874ffdd001c5c34a45f2a4367cb8ef12 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 21 Feb 2022 21:49:08 -0500 Subject: [PATCH 8/8] removing logs --- netclient/daemon/macos.go | 46 +++++++++++++++++++------------------- netclient/wireguard/mac.go | 2 -- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/netclient/daemon/macos.go b/netclient/daemon/macos.go index 6ef8b64b..9de874a8 100644 --- a/netclient/daemon/macos.go +++ b/netclient/daemon/macos.go @@ -88,29 +88,29 @@ func CreateMacService(servicename string) error { // MacDaemonString - the file contents for the mac netclient daemon service (launchdaemon) func MacDaemonString() string { return ` - - - - Labelcom.gravitl.netclient - ProgramArguments - - /usr/local/bin/netclient - daemon - - StandardOutPath/etc/netclient/com.gravitl.netclient.log - StandardErrorPath/etc/netclient/com.gravitl.netclient.log - RunAtLoad - - KeepAlive - - AbandonProcessGroup - EnvironmentVariables - - PATH - /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin - - - + + + + Labelcom.gravitl.netclient + ProgramArguments + + /usr/local/bin/netclient + daemon + + StandardOutPath/etc/netclient/com.gravitl.netclient.log + StandardErrorPath/etc/netclient/com.gravitl.netclient.log + RunAtLoad + + KeepAlive + + AbandonProcessGroup + EnvironmentVariables + + PATH + /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin + + + ` } diff --git a/netclient/wireguard/mac.go b/netclient/wireguard/mac.go index 3c60ce2a..ae22530e 100644 --- a/netclient/wireguard/mac.go +++ b/netclient/wireguard/mac.go @@ -3,7 +3,6 @@ package wireguard import ( "bufio" "errors" - "log" "os" "strconv" "strings" @@ -231,7 +230,6 @@ func getConfig(path string) string { func SetMacPeerRoutes(realIface string) error { var err error peerIPs := getPeerIPs(realIface) - log.Println(peerIPs) if len(peerIPs) == 0 { return err }