diff options
| author | Maisem Ali <maisem@tailscale.com> | 2024-09-18 18:34:18 -0700 |
|---|---|---|
| committer | Maisem Ali <maisem@tailscale.com> | 2024-09-18 18:34:18 -0700 |
| commit | bba445222080ef50d97e1c81c1fe7c7016438818 (patch) | |
| tree | 0532d3e206a291887a30a0e70e6ae470070ac14b | |
| parent | f51c968b2a840804ac66b3a75e4950c14ab3d78c (diff) | |
| download | tailscale-maisem/tsnet-forward.tar.xz tailscale-maisem/tsnet-forward.zip | |
tsnet: expose ForwardTCPHandler from netstackmaisem/tsnet-forward
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>
| -rw-r--r-- | tsnet/tsnet.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tsnet/tsnet.go b/tsnet/tsnet.go index ca6c44ea7..3ddd175f9 100644 --- a/tsnet/tsnet.go +++ b/tsnet/tsnet.go @@ -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) { |
