wgengine/netstack: delete some dead code, old comment, use atomic int types

Noticed while looking at something else; #cleanup.

Change-Id: Icde7749363014eab9bebe1dd80708f5491f933d1
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/6837/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent 82b9689e25
commit caa2fe394f

@ -107,8 +107,8 @@ type Impl struct {
lb *ipnlocal.LocalBackend // or nil
dns *dns.Manager
peerapiPort4Atomic uint32 // uint16 port number for IPv4 peerapi
peerapiPort6Atomic uint32 // uint16 port number for IPv6 peerapi
peerapiPort4Atomic atomic.Uint32 // uint16 port number for IPv4 peerapi
peerapiPort6Atomic atomic.Uint32 // uint16 port number for IPv6 peerapi
// atomicIsLocalIPFunc holds a func that reports whether an IP
// is a local (non-subnet) Tailscale IP address of this
@ -518,7 +518,7 @@ func (ns *Impl) processSSH() bool {
return ns.lb != nil && ns.lb.ShouldRunSSH()
}
func (ns *Impl) peerAPIPortAtomic(ip netip.Addr) *uint32 {
func (ns *Impl) peerAPIPortAtomic(ip netip.Addr) *atomic.Uint32 {
if ip.Is4() {
return &ns.peerapiPort4Atomic
} else {
@ -542,10 +542,10 @@ func (ns *Impl) shouldProcessInbound(p *packet.Parsed, t *tstun.Wrapper) bool {
if p.TCPFlags&packet.TCPSynAck == packet.TCPSyn {
if port, ok := ns.lb.GetPeerAPIPort(dstIP); ok {
peerAPIPort = port
atomic.StoreUint32(ns.peerAPIPortAtomic(dstIP), uint32(port))
ns.peerAPIPortAtomic(dstIP).Store(uint32(port))
}
} else {
peerAPIPort = uint16(atomic.LoadUint32(ns.peerAPIPortAtomic(dstIP)))
peerAPIPort = uint16(ns.peerAPIPortAtomic(dstIP).Load())
}
dport := p.Dst.Port()
if dport == peerAPIPort {
@ -559,11 +559,6 @@ func (ns *Impl) shouldProcessInbound(p *packet.Parsed, t *tstun.Wrapper) bool {
if p.IPVersion == 6 && !isLocal && viaRange.Contains(dstIP) {
return ns.lb != nil && ns.lb.ShouldHandleViaIP(dstIP)
}
if !ns.ProcessLocalIPs && !ns.ProcessSubnets {
// Fast path for common case (e.g. Linux server in TUN mode) where
// netstack isn't used at all; don't even do an isLocalIP lookup.
return false
}
if ns.ProcessLocalIPs && isLocal {
return true
}

@ -8,7 +8,6 @@ import (
"fmt"
"net/netip"
"runtime"
"sync/atomic"
"testing"
"tailscale.com/ipn"
@ -423,8 +422,8 @@ func TestShouldProcessInbound(t *testing.T) {
i.atomicIsLocalIPFunc.Store(func(netip.Addr) bool { return false })
// Set the PeerAPI port to the Dst port above.
atomic.StoreUint32(&i.peerapiPort4Atomic, 5555)
atomic.StoreUint32(&i.peerapiPort6Atomic, 5555)
i.peerapiPort4Atomic.Store(5555)
i.peerapiPort6Atomic.Store(5555)
},
want: false,
},

Loading…
Cancel
Save