Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectTCPIPHandler func use payload origin addr and port #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tcpip.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ func DirectTCPIPHandler(srv *Server, conn *gossh.ServerConn, newChan gossh.NewCh
return
}

dest := net.JoinHostPort(d.DestAddr, strconv.FormatInt(int64(d.DestPort), 10))

var dialer net.Dialer
dconn, err := dialer.DialContext(ctx, "tcp", dest)
laddr := &net.TCPAddr{
IP: net.ParseIP(d.OriginAddr),
Port: int(d.OriginPort),
}
raddr := &net.TCPAddr{
IP: net.ParseIP(d.DestAddr),
Port: int(d.DestPort),
}
dconn, err := net.DialTCP("tcp", laddr, raddr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it would be a worthwhile change (though I'm not 100% sure I understand it), but I'd like for it to be done without dropping ctx from the dial call.

I believe this can be done by setting dialer. LocalAddr to the laddr and using the previous method of creating the raddr.

if err != nil {
newChan.Reject(gossh.ConnectionFailed, err.Error())
return
Expand Down