ipn/ipnlocal: add support for funnel in tsnet
Previously the part that handled Funnel connections was not aware of any listeners that tsnet.Servers might have had open so it would check against the ServeConfig and fail. Adding a ServeConfig for a TCP proxy was also not suitable in this scenario as that would mean creating two different listeners and have one forward to the other, which really meant that you could not have funnel and tailnet-only listeners on the same port. This also introduces the ipn.FunnelConn as a way for users to identify whether the call is coming over funnel or not. Currently it only holds the underlying conn and the target as presented in the "Tailscale-Ingress-Target" header. Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -519,6 +519,7 @@ func (s *Server) start() (reterr error) {
|
||||
if err != nil {
|
||||
return fmt.Errorf("NewLocalBackend: %v", err)
|
||||
}
|
||||
lb.SetTCPHandlerForFunnelFlow(s.getTCPHandlerForFunnelFlow)
|
||||
lb.SetVarRoot(s.rootPath)
|
||||
logf("tsnet starting with hostname %q, varRoot %q", s.hostname, s.rootPath)
|
||||
s.lb = lb
|
||||
@@ -660,6 +661,27 @@ func (s *Server) listenerForDstAddr(netBase string, dst netip.AddrPort) (_ *list
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (s *Server) getTCPHandlerForFunnelFlow(src netip.AddrPort, dstPort uint16) (handler func(net.Conn)) {
|
||||
ipv4, ipv6 := s.TailscaleIPs()
|
||||
var dst netip.AddrPort
|
||||
if src.Addr().Is4() {
|
||||
if !ipv4.IsValid() {
|
||||
return nil
|
||||
}
|
||||
dst = netip.AddrPortFrom(ipv4, dstPort)
|
||||
} else {
|
||||
if !ipv6.IsValid() {
|
||||
return nil
|
||||
}
|
||||
dst = netip.AddrPortFrom(ipv6, dstPort)
|
||||
}
|
||||
ln, ok := s.listenerForDstAddr("tcp", dst)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return ln.handle
|
||||
}
|
||||
|
||||
func (s *Server) getTCPHandlerForFlow(src, dst netip.AddrPort) (handler func(net.Conn), intercept bool) {
|
||||
ln, ok := s.listenerForDstAddr("tcp", dst)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user