From 40fe256ae36f75cd854deca851a7370d88b6e484 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 10:34:24 -0400 Subject: [PATCH 01/20] updating build to see what's going on with travis... again --- service/build.bat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/service/build.bat b/service/build.bat index 08e68bb4..bb7535e9 100644 --- a/service/build.bat +++ b/service/build.bat @@ -15,8 +15,10 @@ ziti-ci version echo generating version info - this will pushed from publish.bat in CI ziti-ci generate-build-info --useVersion=false %SVC_ROOT_DIR%/ziti-tunnel/version.go main +echo version info generated :QUICK +echo changing to %SVC_ROOT_DIR% and setting a bunch of variables cd %SVC_ROOT_DIR% SET REPO_URL=https://github.com/openziti/ziti-tunneler-sdk-c.git @@ -25,8 +27,10 @@ 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 +set BEFORE_GIT=%cd% +echo BEFORE_GIT set to %BEFORE_GIT% + if not exist %SVC_ROOT_DIR%ziti.dll ( - set BEFORE_GIT=%cd% if exist %TUNNELER_SDK_DIR% ( echo ------------------------------------------------------------------------------ echo issuing git pull to pick up any changes From 613b34a8336183f515e42ae4ea0711db2d60616d Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 10:38:40 -0400 Subject: [PATCH 02/20] more echos... more travis debugging --- service/build.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/service/build.bat b/service/build.bat index bb7535e9..0497d52e 100644 --- a/service/build.bat +++ b/service/build.bat @@ -31,6 +31,7 @@ set BEFORE_GIT=%cd% echo BEFORE_GIT set to %BEFORE_GIT% if not exist %SVC_ROOT_DIR%ziti.dll ( + echo ziti.dll does not exist if exist %TUNNELER_SDK_DIR% ( echo ------------------------------------------------------------------------------ echo issuing git pull to pick up any changes From 3c4ad71bd44258fff8e15cc1433e2319be291320 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 10:43:05 -0400 Subject: [PATCH 03/20] an if not exist is exiting with code 255? --- service/build.bat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/service/build.bat b/service/build.bat index 0497d52e..c7970ca5 100644 --- a/service/build.bat +++ b/service/build.bat @@ -29,6 +29,9 @@ set CGO_LDFLAGS=-L %TUNNELER_SDK_DIR%install\lib set BEFORE_GIT=%cd% echo BEFORE_GIT set to %BEFORE_GIT% +dir %SVC_ROOT_DIR% +dir %SVC_ROOT_DIR%ziti.dll +echo :pointup: how is an IF failing??? if not exist %SVC_ROOT_DIR%ziti.dll ( echo ziti.dll does not exist From ab8da78454d0ee7b46366d91c78697c615201163 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 10:47:27 -0400 Subject: [PATCH 04/20] how is an IF failing with exit 255 --- service/build.bat | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/service/build.bat b/service/build.bat index c7970ca5..d49f9467 100644 --- a/service/build.bat +++ b/service/build.bat @@ -33,6 +33,18 @@ dir %SVC_ROOT_DIR% dir %SVC_ROOT_DIR%ziti.dll echo :pointup: how is an IF failing??? +if not exist %SVC_ROOT_DIR% ( + echo i did the FIRST if and it was true +) else ( + echo i did the FIRST if and it was false +) +if not exist %SVC_ROOT_DIR%ziti.dll ( + echo i did the SECOND if and it was true +) else ( + echo i did the SECOND if and it was false +) +echo seriously? we made it HERE??? + if not exist %SVC_ROOT_DIR%ziti.dll ( echo ziti.dll does not exist if exist %TUNNELER_SDK_DIR% ( From ec7312a8d6ac4fb1ecd0ea2ea6ff635007ceb023 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 10:59:17 -0400 Subject: [PATCH 05/20] quiet go get via > NUL --- get-ziti-ci.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get-ziti-ci.bat b/get-ziti-ci.bat index 82f786f1..6f9fc117 100644 --- a/get-ziti-ci.bat +++ b/get-ziti-ci.bat @@ -3,12 +3,12 @@ IF "x%ZITI_CI_VERSION%"=="x" GOTO DEFAULT echo Fetching ziti-ci@%ZITI_CI_VERSION% -go get github.com/netfoundry/ziti-ci@%ZITI_CI_VERSION% +go get github.com/netfoundry/ziti-ci@%ZITI_CI_VERSION% > NUL GOTO END :DEFAULT echo Fetching default ziti-ci -go get github.com/netfoundry/ziti-ci +go get github.com/netfoundry/ziti-ci > NUL GOTO END :END From 54c32cf6f404a85d3afab4b4f4d1a5ef01f84b25 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 11:11:38 -0400 Subject: [PATCH 06/20] binary diffing in travis is 'a proper good time' --- service/build.bat | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/service/build.bat b/service/build.bat index d49f9467..b1df8655 100644 --- a/service/build.bat +++ b/service/build.bat @@ -40,12 +40,6 @@ if not exist %SVC_ROOT_DIR% ( ) if not exist %SVC_ROOT_DIR%ziti.dll ( echo i did the SECOND if and it was true -) else ( - echo i did the SECOND if and it was false -) -echo seriously? we made it HERE??? - -if not exist %SVC_ROOT_DIR%ziti.dll ( echo ziti.dll does not exist if exist %TUNNELER_SDK_DIR% ( echo ------------------------------------------------------------------------------ @@ -82,6 +76,15 @@ if not exist %SVC_ROOT_DIR%ziti.dll ( goto FAIL ) + + +) else ( + echo i did the SECOND if and it was false +) +echo seriously? we made it HERE??? + +if not exist %SVC_ROOT_DIR%ziti.dll ( + echo ------------------------------------------------------------------------------ type %TUNNELER_SDK_DIR%.gitmodules echo. From ff90d70cdfa9602cfdd39416b63de2482faf843f Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 11:25:16 -0400 Subject: [PATCH 07/20] continuing to enjoy travis debugging --- get-ziti-ci.bat | 4 ++-- service/build.bat | 17 ++++++++++++----- service/publish.bat | 10 ++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/get-ziti-ci.bat b/get-ziti-ci.bat index 6f9fc117..1d602bac 100644 --- a/get-ziti-ci.bat +++ b/get-ziti-ci.bat @@ -3,12 +3,12 @@ IF "x%ZITI_CI_VERSION%"=="x" GOTO DEFAULT echo Fetching ziti-ci@%ZITI_CI_VERSION% -go get github.com/netfoundry/ziti-ci@%ZITI_CI_VERSION% > NUL +go get github.com/netfoundry/ziti-ci@%ZITI_CI_VERSION% 2> NUL GOTO END :DEFAULT echo Fetching default ziti-ci -go get github.com/netfoundry/ziti-ci > NUL +go get github.com/netfoundry/ziti-ci 2> NUL GOTO END :END diff --git a/service/build.bat b/service/build.bat index b1df8655..ffdbe4a2 100644 --- a/service/build.bat +++ b/service/build.bat @@ -50,15 +50,22 @@ if not exist %SVC_ROOT_DIR%ziti.dll ( echo ------------------------------------------------------------------------------ ) else ( echo ------------------------------------------------------------------------------ - echo cloning %REPO_URL% + echo mkdir %TUNNELER_SDK_DIR% echo ------------------------------------------------------------------------------ mkdir %TUNNELER_SDK_DIR% + dir %TUNNELER_SDK_DIR% + echo ------------------------------------------------------------------------------ + echo cloning %REPO_URL% + echo ------------------------------------------------------------------------------ git clone %REPO_URL% %TUNNELER_SDK_DIR% --recurse-submodules - ) - IF %ERRORLEVEL% NEQ 0 ( SET ACTUAL_ERR=%ERRORLEVEL% + echo ------------------------------------------------------------------------------ + echo clone is complete + echo ------------------------------------------------------------------------------ + ) + IF %ACTUAL_ERR% NEQ 0 ( echo. - echo Could not pull or clone git repo:%REPO_URL% + echo Could not clone git repo:%REPO_URL% ? echo. goto FAIL ) @@ -77,7 +84,7 @@ if not exist %SVC_ROOT_DIR%ziti.dll ( ) - + ) else ( echo i did the SECOND if and it was false ) diff --git a/service/publish.bat b/service/publish.bat index 4a8948fc..25759b2b 100644 --- a/service/publish.bat +++ b/service/publish.bat @@ -6,6 +6,16 @@ set /p BUILD_VERSION=<%SVC_ROOT_DIR%..\version IF "%BUILD_VERSION%"=="" GOTO BUILD_VERSION_ERROR call %SVC_ROOT_DIR%\build.bat +SET ACTUAL_ERR=%ERRORLEVEL% +if %ACTUAL_ERR% NEQ 0 ( + echo. + echo call to build.bat failed with %ACTUAL_ERR% + echo. + exit /b 1 +) else ( + echo. + echo result of ninja build: %ACTUAL_ERR% +) IF "%GIT_BRANCH%"=="master" GOTO RELEASE @echo Publishing to snapshot repo From acb8cb72b9bd863c8f223b3287d551fd7e8ab0f0 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 12:01:01 -0400 Subject: [PATCH 08/20] rearranging some logic - how is this failing suddenly... --- service/build.bat | 197 +++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 109 deletions(-) diff --git a/service/build.bat b/service/build.bat index ffdbe4a2..fec0b1d5 100644 --- a/service/build.bat +++ b/service/build.bat @@ -18,7 +18,6 @@ ziti-ci generate-build-info --useVersion=false %SVC_ROOT_DIR%/ziti-tunnel/versio echo version info generated :QUICK -echo changing to %SVC_ROOT_DIR% and setting a bunch of variables cd %SVC_ROOT_DIR% SET REPO_URL=https://github.com/openziti/ziti-tunneler-sdk-c.git @@ -27,119 +26,99 @@ 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 -set BEFORE_GIT=%cd% -echo BEFORE_GIT set to %BEFORE_GIT% -dir %SVC_ROOT_DIR% -dir %SVC_ROOT_DIR%ziti.dll -echo :pointup: how is an IF failing??? - -if not exist %SVC_ROOT_DIR% ( - echo i did the FIRST if and it was true -) else ( - echo i did the FIRST if and it was false -) -if not exist %SVC_ROOT_DIR%ziti.dll ( - echo i did the SECOND if and it was true - echo ziti.dll does not exist - if exist %TUNNELER_SDK_DIR% ( - echo ------------------------------------------------------------------------------ - echo issuing git pull to pick up any changes - echo ------------------------------------------------------------------------------ - git pull - git submodule update --init --recursive - echo ------------------------------------------------------------------------------ - ) else ( - echo ------------------------------------------------------------------------------ - echo mkdir %TUNNELER_SDK_DIR% - echo ------------------------------------------------------------------------------ - mkdir %TUNNELER_SDK_DIR% - dir %TUNNELER_SDK_DIR% - echo ------------------------------------------------------------------------------ - echo cloning %REPO_URL% - echo ------------------------------------------------------------------------------ - git clone %REPO_URL% %TUNNELER_SDK_DIR% --recurse-submodules - SET ACTUAL_ERR=%ERRORLEVEL% - echo ------------------------------------------------------------------------------ - echo clone is complete - echo ------------------------------------------------------------------------------ - ) - IF %ACTUAL_ERR% NEQ 0 ( - echo. - echo Could not clone git repo:%REPO_URL% ? - echo. - goto FAIL - ) - - echo changing to %TUNNELER_SDK_DIR% - cd %TUNNELER_SDK_DIR% - echo current directory is %CD% - should be %TUNNELER_SDK_DIR% - echo checking out branch: %ZITI_TUNNEL_REPO_BRANCH% - git checkout %ZITI_TUNNEL_REPO_BRANCH% - IF %ERRORLEVEL% NEQ 0 ( - SET ACTUAL_ERR=%ERRORLEVEL% - echo. - echo Could not checkout branch :%ZITI_TUNNEL_REPO_BRANCH% - echo. - goto FAIL - ) - - - -) else ( - echo i did the SECOND if and it was false -) -echo seriously? we made it HERE??? - -if not exist %SVC_ROOT_DIR%ziti.dll ( - - echo ------------------------------------------------------------------------------ - type %TUNNELER_SDK_DIR%.gitmodules - echo. - echo updating any ssh submodules to https using: - echo powershell "(get-content -path %TUNNELER_SDK_DIR%.gitmodules) -replace 'git@(.*)\:(.*)\.git', 'https://$1/$2.git' | Set-Content -Path %TUNNELER_SDK_DIR%.gitmodules" - echo. - powershell "(get-content -path %TUNNELER_SDK_DIR%.gitmodules) -replace 'git@(.*)\:(.*)\.git', 'https://$1/$2.git' | Set-Content -Path %TUNNELER_SDK_DIR%.gitmodules" - type %TUNNELER_SDK_DIR%.gitmodules - echo ------------------------------------------------------------------------------ - - echo Updating submodules... - git config --get remote.origin.url - git submodule update --init --recursive - IF %ERRORLEVEL% NEQ 0 ( - SET ACTUAL_ERR=%ERRORLEVEL% - echo. - echo Could not update submodules - echo. - goto FAIL - ) - - if not exist %TUNNELER_SDK_DIR%build mkdir %TUNNELER_SDK_DIR%build - if not exist %TUNNELER_SDK_DIR%install mkdir %TUNNELER_SDK_DIR%install - - cmake -G Ninja -S %TUNNELER_SDK_DIR% -B %TUNNELER_SDK_DIR%build -DCMAKE_INSTALL_PREFIX=%TUNNELER_SDK_DIR%install - cmake --build %TUNNELER_SDK_DIR%build --target install - SET ACTUAL_ERR=%ERRORLEVEL% - if %ACTUAL_ERR% NEQ 0 ( - echo. - echo Build of %TUNNELER_SDK_DIR%build failed - echo. - goto FAIL - ) else ( - echo. - echo result of ninja build: %ACTUAL_ERR% - ) - - cp %TUNNELER_SDK_DIR%install\lib\ziti.dll %SVC_ROOT_DIR% - cp %TUNNELER_SDK_DIR%install\lib\libuv.dll %SVC_ROOT_DIR% - - echo COPIED dlls to %SVC_ROOT_DIR% - cd %SVC_ROOT_DIR% -) else ( +if exist %SVC_ROOT_DIR%ziti.dll ( echo ------------------------------------------------------------------------------ echo SKIPPED BUILDING ziti.dll because ziti.dll was found at %SVC_ROOT_DIR%ziti.dll echo ------------------------------------------------------------------------------ + GOTO GOBUILD ) +echo ------------------------------------------------------------------------------ +echo BUILDING ziti.dll begins +echo ------------------------------------------------------------------------------ + +set BEFORE_GIT=%cd% +if exist %TUNNELER_SDK_DIR% ( + echo ------------------------------------------------------------------------------ + echo issuing git pull to pick up any changes + echo ------------------------------------------------------------------------------ + git pull + git submodule update --init --recursive + SET ACTUAL_ERR=%ERRORLEVEL% + echo ------------------------------------------------------------------------------ +) else ( + echo ------------------------------------------------------------------------------ + echo cloning %REPO_URL% + echo ------------------------------------------------------------------------------ + mkdir %TUNNELER_SDK_DIR% + git clone %REPO_URL% %TUNNELER_SDK_DIR% --recurse-submodules + SET ACTUAL_ERR=%ERRORLEVEL% +) +IF %ACTUAL_ERR% NEQ 0 ( + echo. + echo Could not pull or clone git repo:%REPO_URL% + echo. + goto FAIL +) + +echo changing to %TUNNELER_SDK_DIR% +cd %TUNNELER_SDK_DIR% +echo current directory is %CD% - should be %TUNNELER_SDK_DIR% + +echo checking out branch: %ZITI_TUNNEL_REPO_BRANCH% +git checkout %ZITI_TUNNEL_REPO_BRANCH% +IF %ERRORLEVEL% NEQ 0 ( + SET ACTUAL_ERR=%ERRORLEVEL% + echo. + echo Could not checkout branch :%ZITI_TUNNEL_REPO_BRANCH% + echo. + goto FAIL +) + +echo ------------------------------------------------------------------------------ +type %TUNNELER_SDK_DIR%.gitmodules +echo. +echo updating any ssh submodules to https using: +echo powershell "(get-content -path %TUNNELER_SDK_DIR%.gitmodules) -replace 'git@(.*)\:(.*)\.git', 'https://$1/$2.git' | Set-Content -Path %TUNNELER_SDK_DIR%.gitmodules" +echo. +powershell "(get-content -path %TUNNELER_SDK_DIR%.gitmodules) -replace 'git@(.*)\:(.*)\.git', 'https://$1/$2.git' | Set-Content -Path %TUNNELER_SDK_DIR%.gitmodules" +type %TUNNELER_SDK_DIR%.gitmodules +echo ------------------------------------------------------------------------------ + +echo Updating submodules... +git config --get remote.origin.url +git submodule update --init --recursive +IF %ERRORLEVEL% NEQ 0 ( + SET ACTUAL_ERR=%ERRORLEVEL% + echo. + echo Could not update submodules + echo. + goto FAIL +) + +if not exist %TUNNELER_SDK_DIR%build mkdir %TUNNELER_SDK_DIR%build +if not exist %TUNNELER_SDK_DIR%install mkdir %TUNNELER_SDK_DIR%install + +cmake -G Ninja -S %TUNNELER_SDK_DIR% -B %TUNNELER_SDK_DIR%build -DCMAKE_INSTALL_PREFIX=%TUNNELER_SDK_DIR%install +cmake --build %TUNNELER_SDK_DIR%build --target install +SET ACTUAL_ERR=%ERRORLEVEL% +if %ACTUAL_ERR% NEQ 0 ( + echo. + echo Build of %TUNNELER_SDK_DIR%build failed + echo. + goto FAIL +) else ( + echo. + echo result of ninja build: %ACTUAL_ERR% +) + +cp %TUNNELER_SDK_DIR%install\lib\ziti.dll %SVC_ROOT_DIR% +cp %TUNNELER_SDK_DIR%install\lib\libuv.dll %SVC_ROOT_DIR% + +echo COPIED dlls to %SVC_ROOT_DIR% +cd %SVC_ROOT_DIR% + +:GOBUILD echo building the go program go build -a ./ziti-tunnel SET ACTUAL_ERR=%ERRORLEVEL% From c078c63833d09d693a091b002f10b43b8debd375 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 12:12:10 -0400 Subject: [PATCH 09/20] trying to get the output to actually reflect the timeline (stderr/out issue) --- service/publish.bat | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service/publish.bat b/service/publish.bat index 25759b2b..8066e922 100644 --- a/service/publish.bat +++ b/service/publish.bat @@ -34,16 +34,16 @@ exit /b 1 :END echo configuring git - relies on build.bat successfully grabbing ziti-ci -ziti-ci configure-git +ziti-ci configure-git 2>1 @echo publishing complete - committing version.go as ci -git add service/ziti-tunnel/version.go +git add service/ziti-tunnel/version.go 2>1 @echo git add service/ziti-tunnel/version.go complete: %ERRORLEVEL% -git commit -m "[ci skip] committing updated version information" +git commit -m "[ci skip] committing updated version information" 2>1 @echo git commit -m "[ci skip] committing updated version information" complete: %ERRORLEVEL% -git push +git push 2>1 @echo git push complete: %ERRORLEVEL% cd %CURDIR% From 27e405920c24636af05d80ecde8fd840034fd1f2 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 12:21:35 -0400 Subject: [PATCH 10/20] need to change to a legit branch before pushing --- service/publish.bat | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/publish.bat b/service/publish.bat index 8066e922..aae51931 100644 --- a/service/publish.bat +++ b/service/publish.bat @@ -37,6 +37,10 @@ echo configuring git - relies on build.bat successfully grabbing ziti-ci ziti-ci configure-git 2>1 @echo publishing complete - committing version.go as ci + +@echo executing: git checkout %GIT_BRANCH% +git checkout %GIT_BRANCH% + git add service/ziti-tunnel/version.go 2>1 @echo git add service/ziti-tunnel/version.go complete: %ERRORLEVEL% From 354e4493ec17a641ddaf44868cb5eb1f5aaf168c Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 12 Jun 2020 18:22:03 -0400 Subject: [PATCH 11/20] travis still won't push --- service/publish.bat | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/service/publish.bat b/service/publish.bat index aae51931..af4fa99b 100644 --- a/service/publish.bat +++ b/service/publish.bat @@ -32,22 +32,40 @@ GOTO END @echo The build version environment variable was not set - cannot publish exit /b 1 +:FAIL +IF %~1 NEQ 0 ( + echo ================================================================ + echo. + echo FAILURE: + echo %~2 + echo. + echo ================================================================ + exit /b %~1 +) +exit /b 0 + :END echo configuring git - relies on build.bat successfully grabbing ziti-ci ziti-ci configure-git 2>1 @echo publishing complete - committing version.go as ci -@echo executing: git checkout %GIT_BRANCH% -git checkout %GIT_BRANCH% +git stash 2>1 +git checkout %GIT_BRANCH% 2>1 +git stash pop 2>1 +CALL :FAIL %ERRORLEVEL% "checkout failed" +@echo git checkout %GIT_BRANCH% complete: %ERRORLEVEL% git add service/ziti-tunnel/version.go 2>1 +CALL :FAIL %ERRORLEVEL% "git add failed" @echo git add service/ziti-tunnel/version.go complete: %ERRORLEVEL% git commit -m "[ci skip] committing updated version information" 2>1 +CALL :FAIL %ERRORLEVEL% "git commit failed" @echo git commit -m "[ci skip] committing updated version information" complete: %ERRORLEVEL% git push 2>1 +CALL :FAIL %ERRORLEVEL% "git push failed" @echo git push complete: %ERRORLEVEL% cd %CURDIR% From e1e82b403c83e0e761d9d14e186712546e5ba362 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 17 Jun 2020 01:10:59 -0400 Subject: [PATCH 12/20] update to use id over name for intercept. convert to id for lookups. other cleanup/tweaks --- ZitiTunneler/ServiceClient/ClientImpl.cs | 2 ++ service/build.bat | 8 ++++- service/build.sh | 31 ---------------- service/cziti/ctun.go | 20 +++++------ service/cziti/sdk.go | 46 ++++++++++++------------ service/ziti-tunnel/dto/dtos.go | 3 +- service/ziti-tunnel/service/ipc.go | 17 ++++----- version | 2 +- 8 files changed, 55 insertions(+), 74 deletions(-) delete mode 100644 service/build.sh diff --git a/ZitiTunneler/ServiceClient/ClientImpl.cs b/ZitiTunneler/ServiceClient/ClientImpl.cs index 5a443635..d4ce7a6b 100644 --- a/ZitiTunneler/ServiceClient/ClientImpl.cs +++ b/ZitiTunneler/ServiceClient/ClientImpl.cs @@ -340,6 +340,7 @@ namespace ZitiTunneler.ServiceClient public void SetTunnelState(bool onOff) { + /* checkConnected(); try { @@ -352,6 +353,7 @@ namespace ZitiTunneler.ServiceClient //setupPipe(); throw ioe; } + */ } public string GetLogs() diff --git a/service/build.bat b/service/build.bat index fec0b1d5..c10854ce 100644 --- a/service/build.bat +++ b/service/build.bat @@ -7,6 +7,7 @@ set GO111MODULE=on cd /d %ZITI_TUNNEL_WIN_ROOT% IF "%BUILD_VERSION%"=="" GOTO BUILD_VERSION_ERROR +IF "%1"=="clean" GOTO CLEAN IF "%1"=="quick" GOTO QUICK echo fetching ziti-ci @@ -16,12 +17,17 @@ ziti-ci version echo generating version info - this will pushed from publish.bat in CI ziti-ci generate-build-info --useVersion=false %SVC_ROOT_DIR%/ziti-tunnel/version.go main echo version info generated +goto QUICK + +:CLEAN +rmdir /s /q deps +del /q %SVC_ROOT_DIR%ziti.dll :QUICK cd %SVC_ROOT_DIR% SET REPO_URL=https://github.com/openziti/ziti-tunneler-sdk-c.git -SET ZITI_TUNNEL_REPO_BRANCH=5s-moving-avg +SET ZITI_TUNNEL_REPO_BRANCH=master 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 diff --git a/service/build.sh b/service/build.sh deleted file mode 100644 index e327b06f..00000000 --- a/service/build.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -die() { - echo "Error: $1" - exit 1 -} - -[ -z "$TUNNELER_SDK_DIR" ] && die 'set TUNNELER_SDK_DIR' - -if [[ $(type -P cmake) ]]; then - CMAKE=cmake -elif [ -x "/c/Program Files/Cmake/bin/cmake.exe" ]; then - echo "cmake found in standard location" - CMAKE='/c/Program Files/Cmake/bin/cmake.exe' -fi - -mkdir build -mkdir install - -if [[ ! -f ./build/CMakeCache.txt ]]; then - "${CMAKE}" -G Ninja -S ${TUNNELER_SDK_DIR} -B ./build -DCMAKE_INSTALL_PREFIX=./install -fi -"${CMAKE}" --build ./build --target install - -cp ./install/lib/ziti.dll . -cp ./install/lib/libuv.dll . - -export CGO_CFLAGS="-DNOGDI -I $(cygpath -a -m ./install/include)" -export CGO_LDFLAGS="-L $(cygpath -a -m ./install/lib)" -rm ./ziti-wintun.exe -go build -v ./ziti-wintun - diff --git a/service/cziti/ctun.go b/service/cziti/ctun.go index 1a78512f..ed882d4f 100644 --- a/service/cziti/ctun.go +++ b/service/cziti/ctun.go @@ -55,7 +55,7 @@ import ( ) type Tunnel interface { - AddIntercept(service string, hostname string, port int, ctx unsafe.Pointer) + AddIntercept(svcId string, service string, hostname string, port int, ctx unsafe.Pointer) } type tunnel struct { @@ -246,23 +246,23 @@ func (t *tunnel) runWriteLoop() { } } -func (t *tunnel) AddIntercept(service string, host string, port int, ctx unsafe.Pointer) { - log.Debug("about to add intercept for: %s, %s, %d", service, host, port) - res := C.ziti_tunneler_intercept_v1(t.tunCtx, ctx, C.CString(service), C.CString(host), C.int(port)) - log.Debug("intercept added", res) +func (t *tunnel) AddIntercept(svcId string, service string, host string, port int, ctx unsafe.Pointer) { + log.Debugf("about to add intercept for: %s, %s, %d", service, host, port) + res := C.ziti_tunneler_intercept_v1(t.tunCtx, ctx, C.CString(svcId), C.CString(service), C.CString(host), C.int(port)) + log.Debugf("intercept added", res) } -func RemoveIntercept(service string) { +func RemoveIntercept(svcvId string) { for _, t := range devMap { - log.Infof("issuing stop intercepting for %s", service) - C.ziti_tunneler_stop_intercepting(t.tunCtx, C.CString(service)) + log.Infof("issuing stop intercepting for service id: %s", svcvId) + C.ziti_tunneler_stop_intercepting(t.tunCtx, C.CString(svcvId)) } } -func AddIntercept(service string, host string, port uint16, ctx *CZitiCtx) { +func AddIntercept(svcId string, service string, host string, port uint16, ctx *CZitiCtx) { for _, t := range devMap { log.Debug("adding intercept for: %s, %s, %d", service, host, port) - res := C.ziti_tunneler_intercept_v1(t.tunCtx, unsafe.Pointer(ctx.nf), C.CString(service), C.CString(host), C.int(port)) + res := C.ziti_tunneler_intercept_v1(t.tunCtx, unsafe.Pointer(ctx.nf), C.CString(svcId), C.CString(service), C.CString(host), C.int(port)) log.Debug("intercept added", res) } } \ No newline at end of file diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 3b2d760f..68eb6354 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -49,11 +49,9 @@ type sdk struct { libuvCtx *C.libuv_ctx } type ServiceChange struct { - Operation string - Servicename string - Host string - Port int - NFContext *CZitiCtx + Operation string + Service *Service + NFContext *CZitiCtx } var _impl sdk @@ -137,14 +135,21 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un } name := C.GoString(service.name) - log.Tracef("============ INSIDE serviceCB - status: %s - %v, %v, %v ============", name, status, C.ZITI_SERVICE_UNAVAILABLE, C.ZITI_OK) + id := C.GoString(service.id) + log.Errorf("============ INSIDE serviceCB - status: %s:%s - %v, %v, %v ============", name, id, status, C.ZITI_SERVICE_UNAVAILABLE, C.ZITI_OK) if status == C.ZITI_SERVICE_UNAVAILABLE { - DNS.DeregisterService(ctx, name) - ctx.Services.Delete(name) - ServiceChanges <- ServiceChange{ - Operation: REMOVED, - Servicename: name, - NFContext: ctx, + found, ok := ctx.Services.Load(id) + if ok { + DNS.DeregisterService(ctx, name) + ctx.Services.Delete(id) + ServiceChanges <- ServiceChange{ + Operation: REMOVED, + //Servicename: name, + Service: found.(*Service), + NFContext: ctx, + } + } else { + log.Warnf("could not find a service with id: %s, name: %s", service.id, service.name) } } else if status == C.ZITI_OK { cfg := C.ziti_service_get_raw_config(service, tunCfgName) @@ -159,12 +164,13 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un port = int(c["port"].(float64)) } } - ctx.Services.Store(name, Service{ + added := Service{ Name: name, - Id: C.GoString(service.id), + Id: id, InterceptHost: host, InterceptPort: port, - }) + } + ctx.Services.Store(id, added) if host != "" && port != -1 { ip, err := DNS.RegisterService(host, uint16(port), ctx, name) if err != nil { @@ -172,13 +178,11 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un } else { log.Infof("service[%s] is mapped to <%s:%d>", name, ip.String(), port) for _, t := range devMap { - t.AddIntercept(name, ip.String(), port, unsafe.Pointer(ctx.nf)) + t.AddIntercept(id, name, ip.String(), port, unsafe.Pointer(ctx.nf)) } ServiceChanges <- ServiceChange{ Operation: ADDED, - Servicename: name, - Host: host, - Port: port, + Service: &added, NFContext: ctx, } } @@ -217,10 +221,8 @@ func LoadZiti(cfg string) *CZitiCtx { ctx.options.config = C.CString(cfg) ctx.options.init_cb = C.ziti_init_cb(C.initCB) ctx.options.service_cb = C.ziti_service_cb(C.serviceCB) - //TODO don't commit this - ctx.options.refresh_interval = C.long(600) - ctx.options.refresh_interval = C.long(6) + ctx.options.refresh_interval = C.long(15) ctx.options.config_types = C.all_configs - //ctx.options.ctx = unsafe.Pointer(&ctx) ch := make(chan *CZitiCtx) initMap[cfg] = ch diff --git a/service/ziti-tunnel/dto/dtos.go b/service/ziti-tunnel/dto/dtos.go index d2f6ed9d..85a29ac0 100644 --- a/service/ziti-tunnel/dto/dtos.go +++ b/service/ziti-tunnel/dto/dtos.go @@ -20,8 +20,8 @@ package dto import ( idcfg "github.com/netfoundry/ziti-sdk-golang/ziti/config" "github.com/netfoundry/ziti-sdk-golang/ziti/enroll" - "log" "github.com/netfoundry/ziti-tunnel-win/service/cziti" + "log" "github.com/netfoundry/ziti-tunnel-win/service/ziti-tunnel/config" ) @@ -34,6 +34,7 @@ type Service struct { Name string HostName string Port uint16 + Id string } type Identity struct { diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 8db39a12..5c52c3ea 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -667,7 +667,7 @@ func connectIdentity(id *dto.Identity) { } else { log.Debugf("id [%s] is already connected - not reconnecting", id.Name) for _, s := range id.Services { - cziti.AddIntercept(s.Name, s.HostName, s.Port, id.NFContext) + cziti.AddIntercept(s.Id, s.Name, s.HostName, s.Port, id.NFContext) } id.Connected = true } @@ -682,7 +682,7 @@ func disconnectIdentity(id *dto.Identity) error { id.Active = false if id.Connected { for _, s := range id.Services { - cziti.RemoveIntercept(s.Name) + cziti.RemoveIntercept(s.Id) cziti.DNS.DeregisterService(id.NFContext, s.Name) } id.Connected = false @@ -755,7 +755,7 @@ func acceptServices() { case <-shutdown: return case c := <-cziti.ServiceChanges: - log.Debug("processing service change event") + log.Debugf("processing service change event. id:%s name:%s", c.Service.Id, c.Service.Name) matched := false //find the id using the context for _, id := range activeIds { @@ -765,9 +765,10 @@ func acceptServices() { case cziti.ADDED: //add the service to the identity svc := dto.Service{ - Name: c.Servicename, - HostName: c.Host, - Port: uint16(c.Port), + Name: c.Service.Name, + HostName: c.Service.InterceptHost, + Port: uint16(c.Service.InterceptPort), + Id: c.Service.Id, } id.Services = append(id.Services, &svc) @@ -779,7 +780,7 @@ func acceptServices() { log.Debug(" dispatched added service change event") case cziti.REMOVED: for idx, svc := range id.Services { - if svc.Name == c.Servicename { + if svc.Name == c.Service.Name { id.Services = append(id.Services[:idx], id.Services[idx+1:]...) events.broadcast <- dto.ServiceEvent{ ActionEvent: SERVICE_REMOVED, @@ -794,7 +795,7 @@ func acceptServices() { } if !matched { - log.Warnf("service update received but matched no context. this is unexpected. service name: %s", c.Servicename) + log.Warnf("service update received but matched no context. this is unexpected. service name: %s", c.Service.Name) } } } diff --git a/version b/version index d169b2f2..c5d54ec3 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.0.8 +0.0.9 From 778fc592b900eccd929ff70d119a4c0bb290a0ce Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:14:46 -0400 Subject: [PATCH 13/20] rework dns addition to take all existing dns into account so if the service fails the network won't end up looking like it's broken --- service/cziti/ctun.go | 2 +- service/cziti/windns/windns.go | 77 ++++++++++++++++++++++++++++-- service/ziti-tunnel/service/ipc.go | 3 +- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/service/cziti/ctun.go b/service/cziti/ctun.go index ed882d4f..3ea04c7c 100644 --- a/service/cziti/ctun.go +++ b/service/cziti/ctun.go @@ -263,6 +263,6 @@ func AddIntercept(svcId string, service string, host string, port uint16, ctx *C for _, t := range devMap { log.Debug("adding intercept for: %s, %s, %d", service, host, port) res := C.ziti_tunneler_intercept_v1(t.tunCtx, unsafe.Pointer(ctx.nf), C.CString(svcId), C.CString(service), C.CString(host), C.int(port)) - log.Debug("intercept added", res) + log.Debugf("intercept added", res) } } \ No newline at end of file diff --git a/service/cziti/windns/windns.go b/service/cziti/windns/windns.go index 2900a400..1a27a84b 100644 --- a/service/cziti/windns/windns.go +++ b/service/cziti/windns/windns.go @@ -19,18 +19,18 @@ package windns import ( "bytes" - "fmt" + "github.com/michaelquigley/pfxlog" "net" "os" "os/exec" "strings" - - "github.com/michaelquigley/pfxlog" ) var log = pfxlog.Logger() func ResetDNS() { + log.Infof("skipping ResetDNS for now") + log.Infof("resetting dns...") log.Info("restoring dns to original-ish state") @@ -77,14 +77,85 @@ func GetUpstreamDNS() []string { } func ReplaceDNS(ips []net.IP) { + + /* + ifaces, err := net.Interfaces() + if err != nil { + fmt.Print(fmt.Errorf("localAddresses: %+v\n", err.Error())) + return + } + for _, i := range ifaces { + addrs, err := i.Addrs() + if err != nil { + fmt.Print(fmt.Errorf("localAddresses: %+v\n", err.Error())) + continue + } + for _, a := range addrs { + switch v := a.(type) { + case *net.IPAddr: + fmt.Printf("%v : %s (%s)\n", i.Name, v, v.IP.DefaultMask()) + + case *net.IPNet: + fmt.Printf("%v : %s [%v/%v]\n", i.Name, v, v.IP, v.Mask) + } + + } + } + var names []string for _, i := range ips { names = append(names, i.String()) } addresses := strings.Join(names, ",") + + */ + /* script := fmt.Sprintf( `Get-NetIPInterface | ForEach-Object { Set-DnsClientServerAddress -InterfaceIndex $_.ifIndex -ServerAddresses %s }`, addresses) + */ + + + + script := `$dnsinfo=Get-DnsClientServerAddress + +# see https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.addressfamily +$IPv4=2 +$IPv6=23 + +$dnsUpdates = @{} + +foreach ($dns in $dnsinfo) +{ + 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) + if(($dnsServers -ne $null) -and ($dnsServers.Contains("::1")) ) { + echo ($dns.InterfaceAlias + " IPv6 already contains ::1") + } else { + $ArrList.Insert(0,"::1") + } + $dnsUpdates[$dns.InterfaceIndex].AddRange($ArrList) + } + elseif($dns.AddressFamily -eq $IPv4){ + $dnsServers=$dns.ServerAddresses + $ArrList=[System.Collections.ArrayList]@($dnsServers) + if(($dnsServers -ne $null) -and ($dnsServers.Contains("127.0.0.1")) ) { + echo ($dns.InterfaceAlias + " IPv4 already contains 127.0.0.1") + } else { + $ArrList.Insert(0,"127.0.0.1") + } + $dnsUpdates[$dns.InterfaceIndex].AddRange($ArrList) + } +} + +foreach ($key in $dnsUpdates.Keys) +{ + $dnsServers=$dnsUpdates[$key] + Set-DnsClientServerAddress -InterfaceIndex $key -ServerAddresses ($dnsServers) +}` + cmd := exec.Command("powershell", "-Command", script) cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 5c52c3ea..e80512b5 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -681,6 +681,7 @@ func disconnectIdentity(id *dto.Identity) error { id.Active = false if id.Connected { + log.Debugf("ranging over services all services to remove intercept and deregister the service") for _, s := range id.Services { cziti.RemoveIntercept(s.Id) cziti.DNS.DeregisterService(id.NFContext, s.Name) @@ -777,7 +778,7 @@ func acceptServices() { Fingerprint: id.FingerPrint, Service: svc, } - log.Debug(" dispatched added service change event") + log.Debug("dispatched added service change event") case cziti.REMOVED: for idx, svc := range id.Services { if svc.Name == c.Service.Name { From f8ab40c28ae819f52437f884308097eec1e9dd07 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:22:03 -0400 Subject: [PATCH 14/20] fixes #40 - big button will now disable identities --- service/ziti-tunnel/service/ipc.go | 16 +++++++--------- service/ziti-tunnel/service/state.go | 4 ---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index e80512b5..a66fedc5 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -384,6 +384,10 @@ func serveIpc(conn net.Conn) { log.Warnf("Unknown operation: %s. Returning error on pipe", cmd.Function) respondWithError(enc, "Something unexpected has happened", UNKNOWN_ERROR, nil) } + + //save the state + SaveState(&rts) + _ = rw.Flush() } } @@ -496,7 +500,6 @@ func tunnelState(onOff bool, out *json.Encoder) { } setTunnelState(onOff) state.Active = onOff - SaveState(&rts) respond(out, dto.Response{Message: "tunnel state updated successfully", Code: SUCCESS, Error: "", Payload: nil}) log.Debugf("toggle ziti on/off: %t responded to", onOff) @@ -539,7 +542,6 @@ func toggleIdentity(out *json.Encoder, fingerprint string, onOff bool) { respond(out, dto.Response{Message: "identity toggled", Code: SUCCESS, Error: "", Payload: idutil.Clean(*id)}) log.Debugf("toggle ziti on/off for %s: %t responded to", fingerprint, onOff) - SaveState(&rts) } func removeTempFile(file os.File) { @@ -638,9 +640,6 @@ func newIdentity(newId dto.AddIdentity, out *json.Encoder) { //if successful parse the output and add the config to the identity state.Identities = append(state.Identities, &newId.Id) - //save the state - SaveState(&rts) - //return successful message resp := dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: idutil.Clean(newId.Id)} @@ -672,7 +671,6 @@ func connectIdentity(id *dto.Identity) { id.Connected = true } id.Active = true - SaveState(&rts) log.Infof("identity [%s] connected [%t] and set to active [%t]", id.Name, id.Connected, id.Active) } @@ -682,6 +680,9 @@ func disconnectIdentity(id *dto.Identity) error { id.Active = false if id.Connected { log.Debugf("ranging over services all services to remove intercept and deregister the service") + if len(id.Services) < 1 { + log.Errorf("identity with fingerprint %s has no services?", id.FingerPrint) + } for _, s := range id.Services { cziti.RemoveIntercept(s.Id) cziti.DNS.DeregisterService(id.NFContext, s.Name) @@ -690,7 +691,6 @@ func disconnectIdentity(id *dto.Identity) error { } else { log.Debugf("id: %s is already disconnected - not attempting to disconnected again fingerprint:%s", id.Name, id.FingerPrint) } - SaveState(&rts) return nil } @@ -717,8 +717,6 @@ func removeIdentity(out *json.Encoder, fingerprint string) { log.Warn("could not remove file: %s", config.Path()+id.FingerPrint+".json") } - SaveState(&rts) - resp := dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: nil} respond(out, resp) log.Infof("request to remove identity by fingerprint: %s responded to", fingerprint) diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index e69c9c75..b8d4c1fb 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -75,10 +75,6 @@ func SaveState(t *RuntimeState) { w := bufio.NewWriter(bufio.NewWriter(cfg)) enc := json.NewEncoder(w) enc.SetIndent("", " ") - t.state.IpInfo = nil - for _, id := range t.state.Identities { - id.Services = nil - } _ = enc.Encode(t.state) _ = w.Flush() From d81362b239e1e0853b1ec4601ddb281b545d0790 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:48:35 -0400 Subject: [PATCH 15/20] move msg back to debug. change type assertion that was wrong and caused a crash --- service/cziti/sdk.go | 5 +++-- service/ziti-tunnel/service/ipc.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 68eb6354..32691321 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -136,16 +136,17 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un name := C.GoString(service.name) id := C.GoString(service.id) - log.Errorf("============ INSIDE serviceCB - status: %s:%s - %v, %v, %v ============", name, id, status, C.ZITI_SERVICE_UNAVAILABLE, C.ZITI_OK) + log.Debugf("============ INSIDE serviceCB - status: %s:%s - %v, %v, %v ============", name, id, status, C.ZITI_SERVICE_UNAVAILABLE, C.ZITI_OK) if status == C.ZITI_SERVICE_UNAVAILABLE { found, ok := ctx.Services.Load(id) + fs := found.(Service) if ok { DNS.DeregisterService(ctx, name) ctx.Services.Delete(id) ServiceChanges <- ServiceChange{ Operation: REMOVED, //Servicename: name, - Service: found.(*Service), + Service: &fs, NFContext: ctx, } } else { diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index a66fedc5..50befcfb 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -387,7 +387,7 @@ func serveIpc(conn net.Conn) { //save the state SaveState(&rts) - + _ = rw.Flush() } } From 8f3f4005baa4413d6462186f57ab08b3002cb2e3 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 19 Jun 2020 00:23:37 -0400 Subject: [PATCH 16/20] allow ip/mask to be specified in config --- service/cziti/sdk.go | 2 +- service/ziti-tunnel/dto/dtos.go | 12 ++++++---- service/ziti-tunnel/service/ipc.go | 35 ++++++++++++++++++++++------ service/ziti-tunnel/service/state.go | 22 +++++++++++------ 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 32691321..52bfd40f 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -175,7 +175,7 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un if host != "" && port != -1 { ip, err := DNS.RegisterService(host, uint16(port), ctx, name) if err != nil { - log.Error(err) + log.Warn(err) } else { log.Infof("service[%s] is mapped to <%s:%d>", name, ip.String(), port) for _, t := range devMap { diff --git a/service/ziti-tunnel/dto/dtos.go b/service/ziti-tunnel/dto/dtos.go index 85a29ac0..a41f9c08 100644 --- a/service/ziti-tunnel/dto/dtos.go +++ b/service/ziti-tunnel/dto/dtos.go @@ -79,11 +79,13 @@ func (id *Identity) Path() string { } type TunnelStatus struct { - Active bool - Duration int64 - Identities []*Identity - IpInfo *TunIpInfo `json:"IpInfo,omitempty"` - LogLevel string + Active bool + Duration int64 + Identities []*Identity + IpInfo *TunIpInfo `json:"IpInfo,omitempty"` + LogLevel string + TunIpv4 string + TunIpv4Mask int } type ZitiTunnelStatus struct { diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 50befcfb..3165d84a 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -80,7 +80,7 @@ func SubMain(ops chan string, changes chan<- svc.Status) error { } // initialize the network interface - err = initialize() + err = initialize(rts.state.TunIpv4, rts.state.TunIpv4Mask) if err != nil { log.Errorf("unexpected err: %v", err) @@ -219,12 +219,12 @@ func (p *Pipes) shutdownConnections() { log.Info("all events connections closed") } -func initialize() error { - err := rts.CreateTun() +func initialize(ipv4 string, ipv4mask int) error { + err := rts.CreateTun(ipv4, ipv4mask) if err != nil { return err } - setTunInfo(rts.state) + setTunInfo(rts.state, ipv4, ipv4mask) s := rts.state // decide if the tunnel should be active or not and if so - activate it @@ -239,16 +239,37 @@ func initialize() error { return nil } -func setTunInfo(s *dto.TunnelStatus) { +func setTunInfo(s *dto.TunnelStatus, ipv4 string, ipv4mask int) { + if strings.TrimSpace(ipv4) == "" { + log.Infof("ip not provided using default: %d", ipv4) + ipv4 = Ipv4ip + } + if ipv4mask < 16 || ipv4mask > 24 { + log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask) + ipv4mask = Ipv4mask + } + _, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", ipv4, ipv4mask)) + if err != nil { + log.Errorf("error parsing CIDR block: (%v)", err) + return + } //set the tun info into the state s.IpInfo = &dto.TunIpInfo{ - Ip: Ipv4ip, + Ip: ipv4, DNS: Ipv4dns, MTU: 1400, - Subnet: "255.255.255.0", + Subnet: ipv4MaskString(ipnet.Mask), } } +func ipv4MaskString(m []byte) string { + if len(m) != 4 { + panic("ipv4Mask: len must be 4 bytes") + } + + return fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3]) +} + func closeConn(conn net.Conn) { err := conn.Close() if err != nil { diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index b8d4c1fb..63d93ec7 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -31,6 +31,7 @@ import ( "net" "os" "strconv" + "strings" "time" ) @@ -112,7 +113,7 @@ func (t *RuntimeState) ToStatus() dto.TunnelStatus { return clean } -func (t *RuntimeState) CreateTun() error { +func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) error { if noZiti() { log.Warnf("NOZITI set to true. this should be only used for debugging") return nil @@ -136,10 +137,20 @@ func (t *RuntimeState) CreateTun() error { nativeTunDevice := tunDevice.(*tun.NativeTun) luid := winipcfg.LUID(nativeTunDevice.LUID()) - ip, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", Ipv4ip, Ipv4mask)) + + if strings.TrimSpace(ipv4) == "" { + log.Infof("ip not provided using default: %d", ipv4) + ipv4 = Ipv4ip + } + if ipv4mask < 16 || ipv4mask > 24 { + log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask) + ipv4mask = Ipv4mask + } + ip, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", ipv4, ipv4mask)) if err != nil { return fmt.Errorf("error parsing CIDR block: (%v)", err) } + log.Infof("setting TUN interface address to [%s]", ip) err = luid.SetIPAddresses([]net.IPNet{{ip, ipnet.Mask}}) if err != nil { @@ -167,7 +178,7 @@ func (t *RuntimeState) CreateTun() error { } log.Info("routing applied") - cziti.DnsInit(Ipv4ip, 24) + cziti.DnsInit(ipv4, ipv4mask) cziti.Start() _, err = cziti.HookupTun(tunDevice, dns) if err != nil { @@ -232,10 +243,7 @@ func (t *RuntimeState) Close() { log.Fatalf("problem closing tunnel!") } } else { - log.Warn("the TUN WAS NULL? ") - log.Warn("the TUN WAS NULL? ") - log.Warn("the TUN WAS NULL? ") - log.Warn("the TUN WAS NULL? ") + log.Warn("unexpected situation. the TUN was null? ") } } From 2e2931130e02d25378513cfab15ac638d7011e99 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 19 Jun 2020 00:25:30 -0400 Subject: [PATCH 17/20] change range of mask to 8-24 --- service/ziti-tunnel/service/ipc.go | 2 +- service/ziti-tunnel/service/state.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 3165d84a..3b6aac84 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -244,7 +244,7 @@ func setTunInfo(s *dto.TunnelStatus, ipv4 string, ipv4mask int) { log.Infof("ip not provided using default: %d", ipv4) ipv4 = Ipv4ip } - if ipv4mask < 16 || ipv4mask > 24 { + if ipv4mask < 8 || ipv4mask > 24 { log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask) ipv4mask = Ipv4mask } diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index 63d93ec7..c1135726 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -142,7 +142,7 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) error { log.Infof("ip not provided using default: %d", ipv4) ipv4 = Ipv4ip } - if ipv4mask < 16 || ipv4mask > 24 { + if ipv4mask < 8 || ipv4mask > 24 { log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask) ipv4mask = Ipv4mask } From f6d4e914bfded4962f86694cfc000c3d48ab7ceb Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 19 Jun 2020 00:37:14 -0400 Subject: [PATCH 18/20] bump version. new branch for any new changes --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index c5d54ec3..7c1886bb 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.0.9 +0.0.10 From 3047fb207bc1c5ee9d3e3334b5ca9299fe42ce3f Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 19 Jun 2020 12:01:33 -0400 Subject: [PATCH 19/20] minor changes --- service/cziti/sdk.go | 1 - service/ziti-tunnel/service/ipc.go | 2 +- service/ziti-tunnel/service/state.go | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 52bfd40f..ae5f6e49 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -145,7 +145,6 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un ctx.Services.Delete(id) ServiceChanges <- ServiceChange{ Operation: REMOVED, - //Servicename: name, Service: &fs, NFContext: ctx, } diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 3b6aac84..100f406a 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -407,7 +407,7 @@ func serveIpc(conn net.Conn) { } //save the state - SaveState(&rts) + rts.SaveState() _ = rw.Flush() } diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index c1135726..9d919cdd 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -65,7 +65,7 @@ func (t *RuntimeState) FindByIdentity(id dto.Identity) (int, *dto.Identity) { return t.Find(id.FingerPrint) } -func SaveState(t *RuntimeState) { +func (t *RuntimeState) SaveState() { // overwrite file if it exists _ = os.MkdirAll(config.Path(), 0644) From 7528e3cba0944bc2090570309e1adb8b8c8c630a Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Fri, 19 Jun 2020 12:03:02 -0400 Subject: [PATCH 20/20] closes #43 - make the ziti taskbar app status reflect the actual status if detached --- ZitiTunneler/MainWindow.xaml | 2 +- ZitiTunneler/MainWindow.xaml.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ZitiTunneler/MainWindow.xaml b/ZitiTunneler/MainWindow.xaml index d2f1c26a..e777c23d 100644 --- a/ZitiTunneler/MainWindow.xaml +++ b/ZitiTunneler/MainWindow.xaml @@ -7,7 +7,7 @@ mc:Ignorable="d" ShowInTaskbar="False" x:Name="MainUI" - Title="MainWindow" Height="520" + Title="ZitiTunneler" Height="520" Width="350" ResizeMode="NoResize" ClipToBounds="False" Icon="Assets/Images/icon.png" AllowsTransparency="True" diff --git a/ZitiTunneler/MainWindow.xaml.cs b/ZitiTunneler/MainWindow.xaml.cs index ef3a22e1..413e15bc 100644 --- a/ZitiTunneler/MainWindow.xaml.cs +++ b/ZitiTunneler/MainWindow.xaml.cs @@ -310,8 +310,11 @@ namespace ZitiTunneler { LoadIdentities(); } private void SetNotifyIcon(string iconPrefix) { - System.IO.Stream iconStream = System.Windows.Application.GetResourceStream(new Uri("pack://application:,,/Assets/Images/ziti-"+iconPrefix+".ico")).Stream; + var iconUri = new Uri("pack://application:,,/Assets/Images/ziti-" + iconPrefix + ".ico"); + System.IO.Stream iconStream = System.Windows.Application.GetResourceStream(iconUri).Stream; notifyIcon.Icon = new System.Drawing.Icon(iconStream); + + Application.Current.MainWindow.Icon = System.Windows.Media.Imaging.BitmapFrame.Create(iconUri); } private void LoadIdentities() {