Skip to content

Commit

Permalink
fix: fix netstack to forward TCP sessions to local addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
spikecurtis committed Oct 2, 2024
1 parent ddd4a72 commit b3b2e15
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions wgengine/netstack/netstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,17 +878,17 @@ func (ns *Impl) acceptTCP(r *tcp.ForwarderRequest) {
clientRemoteAddrPort := netip.AddrPortFrom(clientRemoteIP, clientRemotePort)

dialIP := netaddrIPFromNetstackIP(reqDetails.LocalAddress)
isTailscaleIP := tsaddr.IsTailscaleIP(dialIP)
isLocal := ns.isLocalIP(dialIP)

dstAddrPort := netip.AddrPortFrom(dialIP, reqDetails.LocalPort)

if viaRange.Contains(dialIP) {
isTailscaleIP = false
isLocal = false
dialIP = tsaddr.UnmapVia(dialIP)
}

defer func() {
if !isTailscaleIP {
if !isLocal {
// if this is a subnet IP, we added this in before the TCP handshake
// so netstack is happy TCP-handshaking as a subnet IP
ns.removeSubnetAddress(dialIP)
Expand Down Expand Up @@ -975,7 +975,7 @@ func (ns *Impl) acceptTCP(r *tcp.ForwarderRequest) {
return
}
}
if isTailscaleIP {
if isLocal {
dialIP = netaddr.IPv4(127, 0, 0, 1)
}
dialAddr := netip.AddrPortFrom(dialIP, uint16(reqDetails.LocalPort))
Expand Down

0 comments on commit b3b2e15

Please sign in to comment.