mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-08-07 06:15:15 +03:00
Fix Tailscale 4via6 subnet routing
This commit is contained in:
@@ -706,12 +706,17 @@ 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
|
||||||
addr4, addr6 := t.server.TailscaleIPs()
|
destinationAddress := tsaddr.UnmapVia(destination.Addr)
|
||||||
switch destination.Addr {
|
if destinationAddress != destination.Addr {
|
||||||
case addr4:
|
destination.Addr = destinationAddress
|
||||||
destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
|
} else {
|
||||||
case addr6:
|
addr4, addr6 := t.server.TailscaleIPs()
|
||||||
destination.Addr = netip.IPv6Loopback()
|
switch destination.Addr {
|
||||||
|
case addr4:
|
||||||
|
destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
|
||||||
|
case addr6:
|
||||||
|
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)
|
||||||
@@ -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
|
||||||
addr4, addr6 := t.server.TailscaleIPs()
|
originDestination := destination
|
||||||
switch destination.Addr {
|
destinationAddress := tsaddr.UnmapVia(destination.Addr)
|
||||||
case addr4:
|
if destinationAddress != destination.Addr {
|
||||||
metadata.OriginDestination = destination
|
destination.Addr = destinationAddress
|
||||||
destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
|
} else {
|
||||||
conn = bufio.NewNATPacketConn(bufio.NewNetPacketConn(conn), metadata.OriginDestination, destination)
|
addr4, addr6 := t.server.TailscaleIPs()
|
||||||
case addr6:
|
switch destination.Addr {
|
||||||
metadata.OriginDestination = destination
|
case addr4:
|
||||||
destination.Addr = netip.IPv6Loopback()
|
destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
|
||||||
conn = bufio.NewNATPacketConn(bufio.NewNetPacketConn(conn), metadata.OriginDestination, destination)
|
case addr6:
|
||||||
|
destination.Addr = netip.IPv6Loopback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user