From 155ca06eb2bd9a167fdadc5b1d7ec952659c8e60 Mon Sep 17 00:00:00 2001 From: Mary Lincy Dcouto Date: Thu, 20 May 2021 14:42:15 +0530 Subject: [PATCH] cleanup ziti network adapter profile, set the lower interface metric --- ZitiUpdateService/UpdateService.cs | 2 +- service/windns/windns.go | 20 ++++++++++++++++++++ service/ziti-tunnel/service/ipc.go | 4 ++-- service/ziti-tunnel/service/state.go | 3 +++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ZitiUpdateService/UpdateService.cs b/ZitiUpdateService/UpdateService.cs index 5f8c7fee..bfd6e615 100644 --- a/ZitiUpdateService/UpdateService.cs +++ b/ZitiUpdateService/UpdateService.cs @@ -193,7 +193,7 @@ namespace ZitiUpdateService { outputIpconfigInfo(destinationLocation); outputSystemInfo(destinationLocation); - // removing this as of 1.9.0+ since we use NRPT... outputDnsCache(destinationLocation); + outputDnsCache(destinationLocation); outputExternalIP(destinationLocation); outputTasklist(destinationLocation); outputRouteInfo(destinationLocation); diff --git a/service/windns/windns.go b/service/windns/windns.go index 23e63f74..0d38d8f6 100644 --- a/service/windns/windns.go +++ b/service/windns/windns.go @@ -288,3 +288,23 @@ func removeSingleNrtpRule(nrptRule string) { log.Errorf("ERROR removing the nrpt rules: %v", err) } } + +func CleanUpNetworkAdapterProfile() { + script := fmt.Sprintf(`$key="Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged\*" +Get-ItemProperty -Path $key | where {$_.FirstNetwork -match "ziti.*"} | Remove-Item + +$key="Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\*" +Get-ItemProperty -Path $key | where {$_.ProfileName -match "Ziti.*"} | Remove-Item`) + log.Debugf("Cleaning up the Network Adapter profiles with: %s", script) + + cmd := exec.Command("powershell", "-Command", script) + cmd.Stderr = os.Stdout + output := new(bytes.Buffer) + cmd.Stdout = output + + err := cmd.Run() + if err != nil { + log.Errorf("ERROR Cleaning up the Network Adapter profiles: %v", err) + } + +} \ No newline at end of file diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 1a64eea2..7126d5b4 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -65,6 +65,8 @@ var shutdown = make(chan bool, 8) //a channel informing go routines to exit func SubMain(ops chan string, changes chan<- svc.Status) error { log.Info("============================== service begins ==============================") windns.RemoveAllNrptRules() + // cleanup old ziti tun profiles + windns.CleanUpNetworkAdapterProfile() rts.LoadConfig() l := rts.state.LogLevel @@ -287,8 +289,6 @@ func initialize(cLogLevel int) error { return err } - cziti.SetInterfaceMetric(TunName, 255) - cziti.Start(rts, rts.state.TunIpv4, rts.state.TunIpv4Mask, cLogLevel) err = cziti.HookupTun(*t) if err != nil { diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index dbfb8fc1..82b36607 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -234,6 +234,9 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int, applyDns bool) (net. } //for windows 10+, could 'domains' be able to replace NRPT? dunno - didn't test it luid.SetDNS(windows.AF_INET, []net.IP{ip}, nil) + cziti.SetInterfaceMetric(TunName, 5) + } else { + cziti.SetInterfaceMetric(TunName, 255) } return ip, t.tun, nil