Skip to content

Commit

Permalink
use the dynamic port from the remote settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouzierinverse committed Dec 17, 2024
1 parent 4e44e90 commit 68719d4
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions go/chisel/server/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/inverse-inc/packetfence/go/pfconfigdriver"
"github.com/inverse-inc/packetfence/go/pfk8s"
"github.com/inverse-inc/packetfence/go/unifiedapiclient"
"github.com/phayes/freeport"
"golang.org/x/crypto/ssh"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -261,23 +260,17 @@ func (s *Server) handleDynReverse(w http.ResponseWriter, req *http.Request) {
if o, ok := activeTunnels.Load(connectorId); ok {
for i := 0; i < DYNREVERSE_BIND_ATTEMPTS; i++ {
tun := o.(*tunnel.Tunnel)
dynPort, err := freeport.GetFreePort()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(unifiedapiclient.ErrorReply{Status: http.StatusInternalServerError, Message: fmt.Sprintf("Unable to find available port: %s", err)})
return
}
to := payload.To
remoteStr := fmt.Sprintf("R:%d:%s", dynPort, to)
remoteStr := fmt.Sprintf("R:0:%s", to)
remote, err := settings.DecodeRemote(remoteStr)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(unifiedapiclient.ErrorReply{Status: http.StatusBadRequest, Message: fmt.Sprintf("The format for the remote (%s) is invalid: %s", to, err)})
return
}

remote.Dynamic = true
remote.LastTouched = time.Now()
dynPort := remote.LocalPort
settings.ActiveDynReverse.Store(cacheKey, remote)
bindErrChan := make(chan error)
go func() {
Expand Down

0 comments on commit 68719d4

Please sign in to comment.