From 9f3f566b7d5a67f7eaa53865804fe79212bddffb Mon Sep 17 00:00:00 2001 From: Antonio Mika Date: Thu, 7 Mar 2024 18:33:15 -0500 Subject: [PATCH] Update to go 1.22 and use multilistener (#298) * Update to go 1.22 and use multilistener * Update * Updates * Set ports for tcp addresses properly * Fix address separator * Fixes * Update multilistener * Cleanup rogue log --- .github/workflows/build.yml | 2 +- .github/workflows/docs.yml | 2 +- .github/workflows/release.yml | 2 +- Dockerfile | 2 +- go.mod | 35 ++++++++-------- go.sum | 76 +++++++++++++++++------------------ httpmuxer/httpmuxer.go | 4 +- sshmuxer/handle.go | 2 +- sshmuxer/httphandler.go | 2 +- sshmuxer/requests.go | 3 +- sshmuxer/sshmuxer.go | 8 ++-- sshmuxer/tcphandler.go | 9 ++--- utils/listen.go | 64 +++++++++++++++++++++++++++++ utils/utils.go | 32 +++++++-------- 14 files changed, 153 insertions(+), 90 deletions(-) create mode 100644 utils/listen.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f6d8033..3e9daae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.6 + go-version: 1.22 - name: Checkout repo uses: actions/checkout@v3 - name: Lint the codebase diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 915e860..36807ae 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -13,7 +13,7 @@ jobs: run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - uses: actions/setup-go@v4 with: - go-version: '1.21' + go-version: '1.22' - name: build docs site run: make ssg - name: publish to pgs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 88bc2ff..e7afdb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.21.6 + go-version: 1.22 - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: diff --git a/Dockerfile b/Dockerfile index 26d7406..586dda2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.21.6-alpine as builder +FROM --platform=$BUILDPLATFORM golang:1.22-alpine as builder LABEL maintainer="Antonio Mika " ENV CGO_ENABLED 0 diff --git a/go.mod b/go.mod index 789705a..5fdf45b 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,10 @@ module github.com/antoniomika/sish -go 1.21 +go 1.22 require ( github.com/ScaleFT/sshkeys v1.2.0 + github.com/antoniomika/multilistener v0.0.0-20240307222635-f0dc097d8acc github.com/antoniomika/syncmap v1.0.0 github.com/caddyserver/certmagic v0.20.0 github.com/fsnotify/fsnotify v1.7.0 @@ -12,36 +13,36 @@ require ( github.com/jpillora/ipfilter v1.2.9 github.com/logrusorgru/aurora v2.0.3+incompatible github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a - github.com/picosh/pdocs v0.0.0-20240218162954-0dec737a7805 + github.com/picosh/pdocs v0.0.0-20240303160411-1e3ac645dce0 github.com/pires/go-proxyproto v0.7.0 github.com/radovskyb/watcher v1.0.7 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 github.com/vulcand/oxy v1.4.2 - golang.org/x/crypto v0.18.0 + golang.org/x/crypto v0.21.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) require ( github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect github.com/alecthomas/chroma v0.10.0 // indirect - github.com/bytedance/sonic v1.10.2 // indirect + github.com/bytedance/sonic v1.11.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect - github.com/dlclark/regexp2 v1.10.0 // indirect + github.com/dlclark/regexp2 v1.11.0 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.17.0 // indirect + github.com/go-playground/validator/v10 v10.19.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.6 // indirect - github.com/leodido/go-urn v1.3.0 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect github.com/libdns/libdns v0.2.1 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mailgun/timetools v0.0.0-20170619190023-f3a7b8ffff47 // indirect @@ -52,7 +53,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.1.1 // indirect - github.com/phuslu/iploc v1.0.20231229 // indirect + github.com/phuslu/iploc v1.0.20240229 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/segmentio/fasthash v1.0.3 // indirect @@ -64,21 +65,21 @@ require ( github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect - github.com/yuin/goldmark v1.6.0 // indirect + github.com/yuin/goldmark v1.7.0 // indirect github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 // indirect github.com/yuin/goldmark-meta v1.1.0 // indirect github.com/zeebo/blake3 v0.2.3 // indirect go.abhg.dev/goldmark/anchor v0.1.1 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.26.0 // indirect + go.uber.org/zap v1.27.0 // indirect golang.org/x/arch v0.7.0 // indirect - golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect - golang.org/x/mod v0.14.0 // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/mod v0.16.0 // indirect + golang.org/x/net v0.22.0 // indirect + golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.17.0 // indirect - google.golang.org/protobuf v1.32.0 // indirect + golang.org/x/tools v0.19.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index fd1f1d0..b04969b 100644 --- a/go.sum +++ b/go.sum @@ -8,14 +8,16 @@ github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00I github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= +github.com/antoniomika/multilistener v0.0.0-20240307222635-f0dc097d8acc h1:M4VZoRaaFhYQgkqJdo4AxzUPyGUNsM2DbUWm5dNH3sU= +github.com/antoniomika/multilistener v0.0.0-20240307222635-f0dc097d8acc/go.mod h1:mSQGXvJEcrZy/3FZmNTh/ly9YhQRJKr3bf5EsV2Idyk= github.com/antoniomika/oxy v1.1.1-0.20210804032133-5924ea01c950 h1:AZcTu5Wwh+MJqW+m4eA+Bv9H9VV4xedv+lElnCfM1k0= github.com/antoniomika/oxy v1.1.1-0.20210804032133-5924ea01c950/go.mod h1:pJou3S+yPP9m4CrgeBtKj/4gl31Kbte2j5JS1iP0WVc= github.com/antoniomika/syncmap v1.0.0 h1:iFSfbQFQOvHZILFZF+hqWosO0no+W9+uF4y2VEyMKWU= github.com/antoniomika/syncmap v1.0.0/go.mod h1:fK2829foEYnO4riNfyUn0SHQZt4ue3DStYjGU+sJj38= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= -github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A= +github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/caddyserver/certmagic v0.20.0 h1:bTw7LcEZAh9ucYCRXyCpIrSAGplplI0vGYJ4BpCQ/Fc= github.com/caddyserver/certmagic v0.20.0/go.mod h1:N4sXgpICQUskEWpj7zVzvWD41p3NYacrNoZYiRM2jTg= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= @@ -34,8 +36,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU= github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0= github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= -github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0= -github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= @@ -54,8 +56,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74= -github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= +github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= @@ -79,8 +81,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= -github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= -github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -89,8 +91,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.3.0 h1:jX8FDLfW4ThVXctBNZ+3cIWnCSnrACDV73r76dy0aQQ= -github.com/leodido/go-urn v1.3.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis= github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40= github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= @@ -122,12 +124,10 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/phuslu/iploc v1.0.20230201/go.mod h1:gsgExGWldwv1AEzZm+Ki9/vGfyjkL33pbSr9HGpt2Xg= -github.com/phuslu/iploc v1.0.20231229 h1:zZVEFTAJu7tQIKssTPtUomSqjpBjI32t44q37Zu3S7E= -github.com/phuslu/iploc v1.0.20231229/go.mod h1:gsgExGWldwv1AEzZm+Ki9/vGfyjkL33pbSr9HGpt2Xg= -github.com/picosh/pdocs v0.0.0-20240129152315-9f5b0c177ce9 h1:yQs7vFisLhP2RHfUeNnHlIp6u+yg4V4qPb3w9sFp/XY= -github.com/picosh/pdocs v0.0.0-20240129152315-9f5b0c177ce9/go.mod h1:4Ei1K68K1qYyqSx5shNdw4++PN1Ws3QhD1u5eJYBmsA= -github.com/picosh/pdocs v0.0.0-20240218162954-0dec737a7805 h1:DlHwGHcZKm76+kK7EGG16ExG8S/GM+uz6VDVljmksxw= -github.com/picosh/pdocs v0.0.0-20240218162954-0dec737a7805/go.mod h1:4Ei1K68K1qYyqSx5shNdw4++PN1Ws3QhD1u5eJYBmsA= +github.com/phuslu/iploc v1.0.20240229 h1:f/5R+f6SoCxim3m3Yio2pynT3Vzy93CTYx03iizDk3M= +github.com/phuslu/iploc v1.0.20240229/go.mod h1:gsgExGWldwv1AEzZm+Ki9/vGfyjkL33pbSr9HGpt2Xg= +github.com/picosh/pdocs v0.0.0-20240303160411-1e3ac645dce0 h1:JUY71YvFHEMcFpCqkZiTcp8mIyQlxHqgS1vY9ovffLc= +github.com/picosh/pdocs v0.0.0-20240303160411-1e3ac645dce0/go.mod h1:4Ei1K68K1qYyqSx5shNdw4++PN1Ws3QhD1u5eJYBmsA= github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs= github.com/pires/go-proxyproto v0.7.0/go.mod h1:Vz/1JPY/OACxWGQNIRY2BeyDmpoaWmEP40O9LbuiFR4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -182,8 +182,8 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/vulcand/predicate v1.1.0/go.mod h1:mlccC5IRBoc2cIFmCB8ZM62I3VDb6p2GXESMHa3CnZg= github.com/yuin/goldmark v1.4.5/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= -github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68= -github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA= +github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 h1:yHfZyN55+5dp1wG7wDKv8HQ044moxkyGq12KFFMFDxg= github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594/go.mod h1:U9ihbh+1ZN7fR5Se3daSPoz1CGF9IYtSvWwVQtnzGHU= github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= @@ -196,12 +196,12 @@ github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo= github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= go.abhg.dev/goldmark/anchor v0.1.1 h1:NUH3hAzhfeymRqZKOkSoFReZlEAmfXBZlbXEzpD2Qgc= go.abhg.dev/goldmark/anchor v0.1.1/go.mod h1:zYKiaHXTdugwVJRZqInVdmNGQRM3ZRJ6AGBC7xP7its= -go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= -go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= @@ -209,28 +209,28 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA= -golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= +golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= @@ -246,12 +246,12 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= -golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -261,8 +261,8 @@ golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= +golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= +golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -271,8 +271,8 @@ gonum.org/v1/gonum v0.8.2 h1:CCXrcPKiGGotvnN6jfUsKk4rRqm7q09/YbKb5xCEvtM= gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/httpmuxer/httpmuxer.go b/httpmuxer/httpmuxer.go index 9acd245..a6d5e0a 100644 --- a/httpmuxer/httpmuxer.go +++ b/httpmuxer/httpmuxer.go @@ -399,7 +399,7 @@ func Start(state *utils.State) { go func() { // We'll replace this with a custom listener // That listener will then check the hostname of the request and choose the connection to send it to - portListener, err := net.Listen("tcp", httpsServer.Addr) + portListener, err := utils.Listen(httpsServer.Addr) if err != nil { log.Fatalf("couldn't listen to %q: %q\n", httpsServer.Addr, err.Error()) } @@ -473,7 +473,7 @@ func Start(state *utils.State) { var httpListener net.Listener - l, err := net.Listen("tcp", httpServer.Addr) + l, err := utils.Listen(httpServer.Addr) if err != nil { log.Fatalf("couldn't listen to %q: %q\n", httpServer.Addr, err.Error()) } diff --git a/sshmuxer/handle.go b/sshmuxer/handle.go index e190eb8..0fda661 100644 --- a/sshmuxer/handle.go +++ b/sshmuxer/handle.go @@ -40,7 +40,7 @@ func handleRequest(newRequest *ssh.Request, sshConn *utils.SSHConnection, state } // checkSession will check a session to see that it has a session. -func checkSession(newRequest *ssh.Request, sshConn *utils.SSHConnection, state *utils.State) { +func checkSession(_ *ssh.Request, sshConn *utils.SSHConnection, state *utils.State) { sshConn.SetupLock.Lock() if sshConn.CleanupHandler { sshConn.SetupLock.Unlock() diff --git a/sshmuxer/httphandler.go b/sshmuxer/httphandler.go index fac4250..eb8ad63 100644 --- a/sshmuxer/httphandler.go +++ b/sshmuxer/httphandler.go @@ -18,7 +18,7 @@ import ( // handleHTTPListener handles the creation of the httpHandler // (or addition for load balancing) and set's up the underlying listeners. -func handleHTTPListener(check *channelForwardMsg, stringPort string, requestMessages string, listenerHolder *utils.ListenerHolder, state *utils.State, sshConn *utils.SSHConnection, scheme string) (*utils.HTTPHolder, *url.URL, string, error) { +func handleHTTPListener(check *channelForwardMsg, _ string, requestMessages string, listenerHolder *utils.ListenerHolder, state *utils.State, sshConn *utils.SSHConnection, scheme string) (*utils.HTTPHolder, *url.URL, string, error) { hostUrl, pH := utils.GetOpenHost(check.Addr, state, sshConn) if (hostUrl == nil || !strings.HasPrefix(hostUrl.Host, check.Addr)) && viper.GetBool("force-requested-subdomains") { diff --git a/sshmuxer/requests.go b/sshmuxer/requests.go index 29350d5..f87f64b 100644 --- a/sshmuxer/requests.go +++ b/sshmuxer/requests.go @@ -10,6 +10,7 @@ import ( "sync" "time" + "github.com/antoniomika/multilistener" "github.com/antoniomika/sish/utils" "github.com/logrusorgru/aurora" "github.com/pires/go-proxyproto" @@ -245,7 +246,7 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *utils.SSHConnection, return } - portChannelForwardReplyPayload.Rport = uint32(tH.Listener.Addr().(*net.TCPAddr).Port) + portChannelForwardReplyPayload.Rport = uint32(tH.Listener.Addr().(*multilistener.MultiListener).Addresses()[0].(*net.TCPAddr).Port) mainRequestMessages = requestMessages diff --git a/sshmuxer/sshmuxer.go b/sshmuxer/sshmuxer.go index 60e2ccc..6fe5d6d 100644 --- a/sshmuxer/sshmuxer.go +++ b/sshmuxer/sshmuxer.go @@ -29,17 +29,17 @@ func Start() { sshPort int ) - _, httpPortString, err := net.SplitHostPort(viper.GetString("http-address")) + _, httpPortString, err := utils.ParseAddress(viper.GetString("http-address")) if err != nil { log.Fatalln("Error parsing address:", err) } - _, httpsPortString, err := net.SplitHostPort(viper.GetString("https-address")) + _, httpsPortString, err := utils.ParseAddress(viper.GetString("https-address")) if err != nil { log.Fatalln("Error parsing address:", err) } - _, sshPortString, err := net.SplitHostPort(viper.GetString("ssh-address")) + _, sshPortString, err := utils.ParseAddress(viper.GetString("ssh-address")) if err != nil { log.Fatalln("Error parsing address:", err) } @@ -163,7 +163,7 @@ func Start() { var listener net.Listener - l, err := net.Listen("tcp", viper.GetString("ssh-address")) + l, err := utils.Listen(viper.GetString("ssh-address")) if err != nil { log.Fatal(err) } diff --git a/sshmuxer/tcphandler.go b/sshmuxer/tcphandler.go index 6505ac0..4d41b26 100644 --- a/sshmuxer/tcphandler.go +++ b/sshmuxer/tcphandler.go @@ -8,6 +8,7 @@ import ( "net/url" "strings" + "github.com/antoniomika/multilistener" "github.com/antoniomika/sish/utils" "github.com/antoniomika/syncmap" "github.com/logrusorgru/aurora" @@ -33,16 +34,12 @@ func handleTCPListener(check *channelForwardMsg, bindPort uint32, requestMessage } if tH == nil { - lis, err := net.Listen("tcp", tcpAddr) + lis, err := utils.Listen(tcpAddr) if err != nil { log.Println("Error listening on addr:", err) return nil, nil, "", nil, "", "", err } - realAddr := lis.Addr().(*net.TCPAddr) - - tcpAddr = strings.ReplaceAll(realAddr.String(), "[::]", "") - tH = &utils.TCPHolder{ TCPHost: tcpAddr, SSHConnections: syncmap.New[string, *utils.SSHConnection](), @@ -120,7 +117,7 @@ func handleTCPListener(check *channelForwardMsg, bindPort uint32, requestMessage connType = "TLS" } - listenPort := tH.Listener.Addr().(*net.TCPAddr).Port + listenPort := tH.Listener.Addr().(*multilistener.MultiListener).Addresses()[0].(*net.TCPAddr).Port requestMessages += fmt.Sprintf("%s: %s:%d\r\n", aurora.BgBlue(connType), domainName, listenPort) log.Printf("%s forwarding started: %s:%d -> %s for client: %s\n", aurora.BgBlue(connType), domainName, listenPort, listenerHolder.Addr().String(), sshConn.SSHConn.RemoteAddr().String()) diff --git a/utils/listen.go b/utils/listen.go new file mode 100644 index 0000000..40c9cf0 --- /dev/null +++ b/utils/listen.go @@ -0,0 +1,64 @@ +package utils + +import ( + "fmt" + "net" + "strings" + + "github.com/antoniomika/multilistener" +) + +const ( + // AddressSeparator is the separtor when providing multiple addresses. + AddressSeparator = "," + + // NetworkSeparator is the sepator between a network and address. + NetworkSeparator = "://" +) + +// Listen uses the multilistener package to generate a net.Listener that uses multiple addresses. +func Listen(addresses string) (net.Listener, error) { + listeners := map[string][]string{} + addressList := strings.Split(addresses, AddressSeparator) + + for _, address := range addressList { + addressSplit := strings.Split(address, NetworkSeparator) + if len(addressSplit) != 2 { + if _, ok := listeners["tcp"]; !ok { + listeners["tcp"] = []string{} + } + listeners["tcp"] = append(listeners["tcp"], address) + continue + } + + if _, ok := listeners[addressSplit[0]]; !ok { + listeners[addressSplit[0]] = []string{} + } + listeners[addressSplit[0]] = append(listeners[addressSplit[0]], addressSplit[1]) + } + + return multilistener.Listen(listeners) +} + +// ParseAddress parse a list of addresses into a host, port, err split. +func ParseAddress(addresses string) (string, string, error) { + addressList := strings.Split(addresses, AddressSeparator) + addressSplit := strings.Split(addressList[0], NetworkSeparator) + + address := addressSplit[0] + if len(addressList) == 2 { + address = addressSplit[1] + } + return net.SplitHostPort(address) +} + +// GenerateAddress generates an address string with ports set. +func GenerateAddress(addresses string, port uint32) string { + newAddressList := []string{} + addressList := strings.Split(addresses, AddressSeparator) + + for _, address := range addressList { + newAddressList = append(newAddressList, fmt.Sprintf("%s:%d", address, port)) + } + return strings.Join(newAddressList, AddressSeparator) +} diff --git a/utils/utils.go b/utils/utils.go index 9e22243..5b30b4f 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -135,7 +135,7 @@ func LoadProxyProtoConfig(l *proxyproto.Listener) { // GetRandomPortInRange returns a random port in the provided range. // The port range is a comma separated list of ranges or ports. -func GetRandomPortInRange(portRange string) uint32 { +func GetRandomPortInRange(listenAddr string, portRange string) uint32 { var bindPort uint32 ranges := strings.Split(strings.TrimSpace(portRange), ",") @@ -173,9 +173,9 @@ func GetRandomPortInRange(portRange string) uint32 { bindPort = uint32(mathrand.Intn(int(possible[locHolder][1]-possible[locHolder][0])) + int(possible[locHolder][0])) } - ln, err := net.Listen("tcp", fmt.Sprintf(":%d", bindPort)) + ln, err := Listen(GenerateAddress(listenAddr, bindPort)) if err != nil { - return GetRandomPortInRange(portRange) + return GetRandomPortInRange(listenAddr, portRange) } ln.Close() @@ -684,21 +684,21 @@ func GetOpenPort(addr string, port uint32, state *State, sshConn *SSHConnection, bindErr = fmt.Errorf("unable to bind requested port") } - sshConn.SendMessage(aurora.Sprintf("The TCP port %s is unavailable.%s", aurora.Red(listenAddr), extra), true) + sshConn.SendMessage(aurora.Sprintf("The TCP port %d is unavailable.%s", aurora.Red(bindPort), extra), true) } } - checkPort := func(checkerAddr string, checkerPort uint32) bool { + checkPort := func(checkerPort uint32) bool { if bindErr != nil { return false } - listenAddr = fmt.Sprintf("%s:%d", bindAddr, bindPort) + listenAddr = GenerateAddress(bindAddr, bindPort) checkedPort, err := CheckPort(checkerPort, viper.GetString("port-bind-range")) _, ok := state.TCPListeners.Load(listenAddr) if err == nil && (!viper.GetBool("tcp-load-balancer") || (viper.GetBool("tcp-load-balancer") && !ok) || (sniProxyEnabled && !ok)) { - ln, listenErr := net.Listen("tcp", listenAddr) + ln, listenErr := Listen(listenAddr) if listenErr != nil { err = listenErr } else { @@ -710,7 +710,7 @@ func GetOpenPort(addr string, port uint32, state *State, sshConn *SSHConnection, reportUnavailable(true) if viper.GetString("port-bind-range") != "" { - bindPort = GetRandomPortInRange(viper.GetString("port-bind-range")) + bindPort = GetRandomPortInRange(bindAddr, viper.GetString("port-bind-range")) } else { bindPort = 0 } @@ -718,7 +718,7 @@ func GetOpenPort(addr string, port uint32, state *State, sshConn *SSHConnection, bindPort = checkedPort } - listenAddr = fmt.Sprintf("%s:%d", bindAddr, bindPort) + listenAddr = GenerateAddress(bindAddr, bindPort) holder, ok := state.TCPListeners.Load(listenAddr) if ok && (!sniProxyEnabled && viper.GetBool("tcp-load-balancer") || (sniProxyEnabled && viper.GetBool("sni-load-balancer"))) { tH = holder @@ -731,7 +731,7 @@ func GetOpenPort(addr string, port uint32, state *State, sshConn *SSHConnection, return ok } - for checkPort(bindAddr, bindPort) { + for checkPort(bindPort) { } return listenAddr, bindPort, tH @@ -790,7 +790,7 @@ func GetOpenSNIHost(addr string, state *State, sshConn *SSHConnection, tH *TCPHo } } - checkHost := func(checkHost string) bool { + checkHost := func() bool { if bindErr != nil { return false } @@ -826,7 +826,7 @@ func GetOpenSNIHost(addr string, state *State, sshConn *SSHConnection, tH *TCPHo return ok } - for checkHost(host) { + for checkHost() { } return host, bindErr @@ -920,7 +920,7 @@ func GetOpenHost(addr string, state *State, sshConn *SSHConnection) (*url.URL, * } } - checkHost := func(checkHost string) bool { + checkHost := func() bool { if bindErr != nil { return false } @@ -961,7 +961,7 @@ func GetOpenHost(addr string, state *State, sshConn *SSHConnection) (*url.URL, * return ok } - for checkHost(host) { + for checkHost() { } if bindErr != nil { @@ -1007,7 +1007,7 @@ func GetOpenAlias(addr string, port string, state *State, sshConn *SSHConnection } } - checkAlias := func(checkAlias string) bool { + checkAlias := func() bool { if bindErr != nil { return false } @@ -1029,7 +1029,7 @@ func GetOpenAlias(addr string, port string, state *State, sshConn *SSHConnection return ok } - for checkAlias(alias) { + for checkAlias() { } if bindErr != nil {