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/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) 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 3fe58301..00000000 Binary files a/service/publish.bat.swp and /dev/null differ diff --git a/service/quick.bat b/service/quick.bat index ba412d04..002b4b0a 100644 --- a/service/quick.bat +++ b/service/quick.bat @@ -1 +1,16 @@ +@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 call build quick diff --git a/service/reset-nw.bat b/service/reset-nw.bat deleted file mode 100644 index 68d04339..00000000 --- a/service/reset-nw.bat +++ /dev/null @@ -1 +0,0 @@ -get-netipinterface | ForEach-Object { Set-DnsClientServerAddress -InterfaceIndex $_.ifIndex -ResetServerAddresses} \ No newline at end of file diff --git a/service/reset-nw.ps1 b/service/reset-nw.ps1 new file mode 100644 index 00000000..f5b84865 --- /dev/null +++ b/service/reset-nw.ps1 @@ -0,0 +1,15 @@ +# 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. +# +get-netipinterface | ForEach-Object { Set-DnsClientServerAddress -InterfaceIndex $_.ifIndex -ResetServerAddresses} \ No newline at end of file diff --git a/service/set-env.bat b/service/set-env.bat index db03d590..bded25db 100644 --- a/service/set-env.bat +++ b/service/set-env.bat @@ -1,4 +1,19 @@ -set SVC_ROOT_DIR=%~dp0 -SET TUNNELER_SDK_DIR=%SVC_ROOT_DIR%deps\ziti-tunneler-sdk-c\ -SET CGO_CFLAGS=-DNOGDI -I %TUNNELER_SDK_DIR%install\include +@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 SVC_ROOT_DIR=%~dp0 +SET TUNNELER_SDK_DIR=%SVC_ROOT_DIR%deps\ziti-tunneler-sdk-c\ +SET CGO_CFLAGS=-DNOGDI -I %TUNNELER_SDK_DIR%install\include SET CGO_LDFLAGS=-L %TUNNELER_SDK_DIR%install\lib \ No newline at end of file diff --git a/service/ziti-tunnel/api/api.go b/service/ziti-tunnel/api/api.go index 5b61bdd8..6bb1c7e2 100644 --- a/service/ziti-tunnel/api/api.go +++ b/service/ziti-tunnel/api/api.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 api import ( diff --git a/service/ziti-tunnel/constants/consts.go b/service/ziti-tunnel/constants/consts.go index 9d5561f0..4c254157 100644 --- a/service/ziti-tunnel/constants/consts.go +++ b/service/ziti-tunnel/constants/consts.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 constants const( @@ -5,6 +22,4 @@ const( Ipv4MaxMask = 8 Ipv4MinMask = 28 Ipv4DefaultMask = 24 - - DnsIpv4Default = "127.0.0.1" ) \ No newline at end of file diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index cd84dfb2..b2096290 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -155,7 +155,7 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) (net.IP, error) { if err != nil { return nil, fmt.Errorf("failed to set IP address to %v: (%v)", ip, err) } - + dnsServers := []net.IP{ ip } log.Infof("adding DNS servers to TUN: %s", dnsServers) diff --git a/service/ziti-tunnel/util/detect-ip-changes.go b/service/ziti-tunnel/util/detect-ip-changes.go index 51623cb2..fc0c6318 100644 --- a/service/ziti-tunnel/util/detect-ip-changes.go +++ b/service/ziti-tunnel/util/detect-ip-changes.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 util import (