mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
tsnet: expose ForwardTCPHandler from netstack
Expose the newly added netstack.Impl.ForwardTCPHandler in tsnet so that callers don't have to implement it themselves when writing TCP forwarders. Updates #13513 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
f51c968b2a
commit
bba4452220
@ -162,6 +162,20 @@ type Server struct {
|
||||
// over the TCP conn.
|
||||
type FallbackTCPHandler func(src, dst netip.AddrPort) (handler func(net.Conn), intercept bool)
|
||||
|
||||
// ForwardTCPHandler returns a handler that forwards TCP connections to the
|
||||
// provided destination address. The handler can be used to implement a
|
||||
// [FallbackTCPHandler]. It returns an error if the destination cannot be
|
||||
// reached.
|
||||
func (s *Server) ForwardTCPHandler(dialCtx context.Context, dst string) (func(net.Conn), error) {
|
||||
h, err := s.netstack.ForwardTCPHandler(dialCtx, dst)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return func(c net.Conn) {
|
||||
h(c)
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Dial connects to the address on the tailnet.
|
||||
// It will start the server if it has not been started yet.
|
||||
func (s *Server) Dial(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user