diff --git a/go/chisel/share/tunnel/tunnel_in_proxy.go b/go/chisel/share/tunnel/tunnel_in_proxy.go index 6d8f79b905e1..307a6a29c437 100644 --- a/go/chisel/share/tunnel/tunnel_in_proxy.go +++ b/go/chisel/share/tunnel/tunnel_in_proxy.go @@ -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 { diff --git a/go/chisel/share/tunnel/tunnel_in_proxy_udp.go b/go/chisel/share/tunnel/tunnel_in_proxy_udp.go index a5df813bb011..596d00775f7f 100644 --- a/go/chisel/share/tunnel/tunnel_in_proxy_udp.go +++ b/go/chisel/share/tunnel/tunnel_in_proxy_udp.go @@ -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{