From caa2fe394fb2b5fd4d65bee0b4bd30bf5d738949 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 22 Dec 2022 12:53:56 -0800 Subject: [PATCH] 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 --- wgengine/netstack/netstack.go | 15 +++++---------- wgengine/netstack/netstack_test.go | 5 ++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/wgengine/netstack/netstack.go b/wgengine/netstack/netstack.go index f5392eaf1..4f4ba6e63 100644 --- a/wgengine/netstack/netstack.go +++ b/wgengine/netstack/netstack.go @@ -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 } diff --git a/wgengine/netstack/netstack_test.go b/wgengine/netstack/netstack_test.go index d1303f8d5..c92f1edb6 100644 --- a/wgengine/netstack/netstack_test.go +++ b/wgengine/netstack/netstack_test.go @@ -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, },