Skip to content

Commit

Permalink
Use the TcpListenter and UdpConn from the remote
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouzierinverse committed Dec 18, 2024
1 parent 68719d4 commit fc4db88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
23 changes: 14 additions & 9 deletions go/chisel/share/tunnel/tunnel_in_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@ func (p *Proxy) listen() error {
if p.remote.Stdio {
//TODO check if pipes active?
} else if p.remote.LocalProto == "tcp" {
addr, err := net.ResolveTCPAddr("tcp", p.remote.LocalHost+":"+p.remote.LocalPort)
if err != nil {
return p.Errorf("resolve: %s", err)
}
l, err := net.ListenTCP("tcp", addr)
if err != nil {
return p.Errorf("tcp: %s", err)
if p.remote.ReusedTcpListener != nil {
p.tcp = p.remote.ReusedTcpListener
p.remote.ReusedTcpListener = nil
} else {
addr, err := net.ResolveTCPAddr("tcp", p.remote.LocalHost+":"+p.remote.LocalPort)
if err != nil {
return p.Errorf("resolve: %s", err)
}
l, err := net.ListenTCP("tcp", addr)
if err != nil {
return p.Errorf("tcp: %s", err)
}
p.Infof("Listening")
p.tcp = l
}
p.Infof("Listening")
p.tcp = l
} else if p.remote.LocalProto == "udp" {
l, err := listenUDP(p.Logger, p.sshTun, p.remote)
if err != nil {
Expand Down
20 changes: 13 additions & 7 deletions go/chisel/share/tunnel/tunnel_in_proxy_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ import (
// of time, so that when the exit node receives a response on 6345, it
// knows to return it to 1111.
func listenUDP(l *cio.Logger, sshTun sshTunnel, remote *settings.Remote) (*udpListener, error) {
a, err := net.ResolveUDPAddr("udp", remote.Local())
if err != nil {
return nil, l.Errorf("resolve: %s", err)
}
conn, err := net.ListenUDP("udp", a)
if err != nil {
return nil, l.Errorf("listen: %s", err)
var conn *net.UDPConn
if remote.ReusedUdpConn != nil {
conn = remote.ReusedUdpConn
remote.ReusedUdpConn = nil
} else {
a, err := net.ResolveUDPAddr("udp", remote.Local())
if err != nil {
return nil, l.Errorf("resolve: %s", err)
}
conn, err = net.ListenUDP("udp", a)
if err != nil {
return nil, l.Errorf("listen: %s", err)
}
}
//ready
u := &udpListener{
Expand Down

0 comments on commit fc4db88

Please sign in to comment.