From db9ed1f15012fea838bf5edb4feb8e9fb55c9879 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 28 Oct 2020 09:21:59 -0400 Subject: [PATCH 1/2] add missing copyright headers --- service/build.bat | 16 ++++++++++++- service/cziti/cbuff.go | 17 ++++++++++++++ service/publish.bat | 14 ++++++++++++ service/publish.bat.swp | Bin 12288 -> 0 bytes service/quick.bat | 15 +++++++++++++ service/reset-nw.bat | 1 - service/reset-nw.ps1 | 15 +++++++++++++ service/set-env.bat | 21 +++++++++++++++--- service/ziti-tunnel/api/api.go | 17 ++++++++++++++ service/ziti-tunnel/constants/consts.go | 19 ++++++++++++++-- service/ziti-tunnel/service/state.go | 2 +- service/ziti-tunnel/util/detect-ip-changes.go | 17 ++++++++++++++ 12 files changed, 146 insertions(+), 8 deletions(-) delete mode 100644 service/publish.bat.swp delete mode 100644 service/reset-nw.bat create mode 100644 service/reset-nw.ps1 diff --git a/service/build.bat b/service/build.bat index 85e7a535..92c1503d 100644 --- a/service/build.bat +++ b/service/build.bat @@ -1,4 +1,18 @@ @echo off +REM Copyright NetFoundry, Inc. +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM https://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. +REM set CURDIR=%CD% set SVC_ROOT_DIR=%~dp0 @@ -41,7 +55,7 @@ cd %SVC_ROOT_DIR% SET REPO_URL=https://github.com/openziti/ziti-tunneler-sdk-c.git SET ZITI_TUNNEL_REPO_BRANCH=v0.6.11 SET TUNNELER_SDK_DIR=%SVC_ROOT_DIR%deps\ziti-tunneler-sdk-c\ -SET CGO_CFLAGS=-DNOGDI -O3 -g3 -I %TUNNELER_SDK_DIR%install\include +SET CGO_CFLAGS=-DNOGDI -I %TUNNELER_SDK_DIR%install\include SET CGO_LDFLAGS=-L %TUNNELER_SDK_DIR%install\lib if exist %SVC_ROOT_DIR%ziti.dll ( diff --git a/service/cziti/cbuff.go b/service/cziti/cbuff.go index 3bcd15a2..ccb6b857 100644 --- a/service/cziti/cbuff.go +++ b/service/cziti/cbuff.go @@ -1,3 +1,20 @@ +/* + * Copyright NetFoundry, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package cziti var cbuff = make([][]byte, MaxDnsRequests) diff --git a/service/publish.bat b/service/publish.bat index 464a886d..81c41ff8 100644 --- a/service/publish.bat +++ b/service/publish.bat @@ -1,4 +1,18 @@ @echo off +REM Copyright NetFoundry, Inc. +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM https://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. +REM set CURDIR=%CD% set SVC_ROOT_DIR=%~dp0 diff --git a/service/publish.bat.swp b/service/publish.bat.swp deleted file mode 100644 index 3fe58301e8ce4edeb378481793b5332ea814e40e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2OKclO7{{ljQ2L^!+>nq4gHd}}Z=6(sB3#u?+}4sC2iwVoM%H?FY)`Y^S$1ZV zru1>(2uCCiAR#2K?S%teK}cLE96<;W;?N76D#Q(m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51 -0400 Subject: [PATCH 2/2] undo recent dns related bug added and add warns if channel full --- service/cziti/dns-proxy.go | 13 ++++++++++--- service/cziti/windns.go | 30 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/service/cziti/dns-proxy.go b/service/cziti/dns-proxy.go index c52b3eb2..a20542cd 100644 --- a/service/cziti/dns-proxy.go +++ b/service/cziti/dns-proxy.go @@ -183,7 +183,9 @@ func runListener(ip *net.IP, port int, reqch chan dnsreq) { log.Panicf("An unexpected and unrecoverable error has occurred while %s: %v", "reading a udp message", err) } } - + if len(reqch) == cap(reqch) { + log.Warn("DNS req will be blocked. If this warning is continuously displayed please report") + } reqch <- dnsreq{ q: b[:nb], s: server, @@ -203,6 +205,9 @@ type proxiedReq struct { } func proxyDNS(req *dns.Msg, peer *net.UDPAddr, serv *net.UDPConn, ipVer int) { + if len(proxiedRequests) == cap(proxiedRequests) { + log.Warn("proxiedRequests will be blocked. If this warning is continuously displayed please report") + } proxiedRequests <- &proxiedReq{ req: req, peer: peer, @@ -224,10 +229,9 @@ func dnsPanicRecover(localDnsServers []net.IP) { } func runDNSproxy(upstreamDnsServers []string, localDnsServers []net.IP) { - log.Infof("restarting DNS proxy") + log.Infof("starting DNS proxy upstream: %v, local: %v", upstreamDnsServers, localDnsServers) domains = GetConnectionSpecificDomains() log.Infof("ConnectionSpecificDomains: %v", domains) - log.Infof("dnsServers: %v", upstreamDnsServers) defer func() { if err := recover(); err != nil { log.Errorf("Recovering from panic due to DNS-related issue. %v", err) @@ -279,6 +283,9 @@ func runDNSproxy(upstreamDnsServers []string, localDnsServers []net.IP) { log.Warnf("odd error: %v", err) } } else { + if len(respChan) == cap(respChan) { + log.Warn("respChan will be blocked. If this warning is continuously displayed please report") + } respChan <- resp[:n] } } diff --git a/service/cziti/windns.go b/service/cziti/windns.go index e2daef2a..faf0a364 100644 --- a/service/cziti/windns.go +++ b/service/cziti/windns.go @@ -110,7 +110,7 @@ func ReplaceDNS(ips []net.IP) { } ipsAsString := strings.Join(ipsStrArr, ",") - log.Infof("Injecting DNS servers [%s] onto interfaces", ipsAsString) + log.Infof("injecting DNS servers [%s] onto interfaces", ipsAsString) script := fmt.Sprintf(`$dnsinfo=Get-DnsClientServerAddress $dnsIps=@(%s) @@ -119,31 +119,33 @@ $dnsIps=@(%s) $IPv4=2 $IPv6=23 -$dnsPerInterface = @{} +$dnsUpdates = @{} foreach ($dns in $dnsinfo) { - if($dnsPerInterface[$dns.InterfaceIndex] -eq $null) { - $dnsPerInterface[$dns.InterfaceIndex]=[System.Collections.ArrayList]@() - } else { + if($dnsUpdates[$dns.InterfaceIndex] -eq $null) { $dnsUpdates[$dns.InterfaceIndex]=[System.Collections.ArrayList]@() } + if($dns.AddressFamily -eq $IPv6) { $dnsServers=$dns.ServerAddresses $ArrList=[System.Collections.ArrayList]@($dnsServers) - foreach ($dnsIp in $dnsIps) - { - if(($dnsServers -ne $null) -and ($ArrList.Contains($dnsIp)) ) { - # uncomment when debugging echo ($dns.InterfaceAlias + " IPv4 already contains ${dnsIp}") + $dnsUpdates[$dns.InterfaceIndex].AddRange($ArrList) + } + elseif($dns.AddressFamily -eq $IPv4){ + $dnsServers=$dns.ServerAddresses + $ArrList=[System.Collections.ArrayList]@($dnsServers) + foreach($d in $dnsIps) { + if(($dnsServers -ne $null) -and ($dnsServers.Contains($d)) ) { + # uncomment when debugging echo ($dns.InterfaceAlias + " IPv4 already contains 127.0.0.1") } else { - $ArrList.Insert(0, $dnsIp) + $ArrList.Insert(0,$d) } } - $dnsPerInterface[$dns.InterfaceIndex].AddRange($ArrList) + $dnsUpdates[$dns.InterfaceIndex].AddRange($ArrList) } } -foreach ($key in $dnsPerInterface.Keys) +foreach ($key in $dnsUpdates.Keys) { - $dnsServers=$dnsPerInterface[$key] - Set-DnsClientServerAddress -InterfaceIndex $key -ServerAddresses ($dnsServers) + Set-DnsClientServerAddress -InterfaceIndex $key -ServerAddresses ($dnsUpdates[$key]) }`, ipsAsString) cmd := exec.Command("powershell", "-Command", script)