Fix Tailscale 4via6 subnet routing

This commit is contained in:
世界
2026-07-22 14:49:44 +08:00
parent 3c4a5a6ed3
commit 9d7e9b9562

View File

@@ -706,6 +706,10 @@ func (t *Endpoint) NewConnectionEx(ctx context.Context, conn net.Conn, source M.
metadata.Inbound = t.Tag() metadata.Inbound = t.Tag()
metadata.InboundType = t.Type() metadata.InboundType = t.Type()
metadata.Source = source metadata.Source = source
destinationAddress := tsaddr.UnmapVia(destination.Addr)
if destinationAddress != destination.Addr {
destination.Addr = destinationAddress
} else {
addr4, addr6 := t.server.TailscaleIPs() addr4, addr6 := t.server.TailscaleIPs()
switch destination.Addr { switch destination.Addr {
case addr4: case addr4:
@@ -713,6 +717,7 @@ func (t *Endpoint) NewConnectionEx(ctx context.Context, conn net.Conn, source M.
case addr6: case addr6:
destination.Addr = netip.IPv6Loopback() destination.Addr = netip.IPv6Loopback()
} }
}
metadata.Destination = destination metadata.Destination = destination
t.logger.InfoContext(ctx, "inbound connection from ", source) t.logger.InfoContext(ctx, "inbound connection from ", source)
t.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination) t.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
@@ -724,16 +729,22 @@ func (t *Endpoint) NewPacketConnectionEx(ctx context.Context, conn N.PacketConn,
metadata.Inbound = t.Tag() metadata.Inbound = t.Tag()
metadata.InboundType = t.Type() metadata.InboundType = t.Type()
metadata.Source = source metadata.Source = source
originDestination := destination
destinationAddress := tsaddr.UnmapVia(destination.Addr)
if destinationAddress != destination.Addr {
destination.Addr = destinationAddress
} else {
addr4, addr6 := t.server.TailscaleIPs() addr4, addr6 := t.server.TailscaleIPs()
switch destination.Addr { switch destination.Addr {
case addr4: case addr4:
metadata.OriginDestination = destination
destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1}) destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
conn = bufio.NewNATPacketConn(bufio.NewNetPacketConn(conn), metadata.OriginDestination, destination)
case addr6: case addr6:
metadata.OriginDestination = destination
destination.Addr = netip.IPv6Loopback() destination.Addr = netip.IPv6Loopback()
conn = bufio.NewNATPacketConn(bufio.NewNetPacketConn(conn), metadata.OriginDestination, destination) }
}
if destination != originDestination {
metadata.OriginDestination = originDestination
conn = bufio.NewNATPacketConn(bufio.NewNetPacketConn(conn), originDestination, destination)
} }
metadata.Destination = destination metadata.Destination = destination
t.logger.InfoContext(ctx, "inbound packet connection from ", source) t.logger.InfoContext(ctx, "inbound packet connection from ", source)