MCPcopy
hub / github.com/gliderlabs/ssh / DirectTCPIPHandler

Function DirectTCPIPHandler

tcpip.go:28–66  ·  view source on GitHub ↗

DirectTCPIPHandler can be enabled by adding it to the server's ChannelHandlers under direct-tcpip.

(srv *Server, conn *gossh.ServerConn, newChan gossh.NewChannel, ctx Context)

Source from the content-addressed store, hash-verified

26// DirectTCPIPHandler can be enabled by adding it to the server's
27// ChannelHandlers under direct-tcpip.
28func DirectTCPIPHandler(srv *Server, conn *gossh.ServerConn, newChan gossh.NewChannel, ctx Context) {
29 d := localForwardChannelData{}
30 if err := gossh.Unmarshal(newChan.ExtraData(), &d); err != nil {
31 newChan.Reject(gossh.ConnectionFailed, "error parsing forward data: "+err.Error())
32 return
33 }
34
35 if srv.LocalPortForwardingCallback == nil || !srv.LocalPortForwardingCallback(ctx, d.DestAddr, d.DestPort) {
36 newChan.Reject(gossh.Prohibited, "port forwarding is disabled")
37 return
38 }
39
40 dest := net.JoinHostPort(d.DestAddr, strconv.FormatInt(int64(d.DestPort), 10))
41
42 var dialer net.Dialer
43 dconn, err := dialer.DialContext(ctx, "tcp", dest)
44 if err != nil {
45 newChan.Reject(gossh.ConnectionFailed, err.Error())
46 return
47 }
48
49 ch, reqs, err := newChan.Accept()
50 if err != nil {
51 dconn.Close()
52 return
53 }
54 go gossh.DiscardRequests(reqs)
55
56 go func() {
57 defer ch.Close()
58 defer dconn.Close()
59 io.Copy(ch, dconn)
60 }()
61 go func() {
62 defer ch.Close()
63 defer dconn.Close()
64 io.Copy(dconn, ch)
65 }()
66}
67
68type remoteForwardRequest struct {
69 BindAddr string

Callers

nothing calls this directly

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…