control/controlclient: do not alias peer CapMap

Updates #cleanup

Change-Id: I10fd5e04310cdd7894a3caa3045b86eb0a06b6a0
Signed-off-by: Adrian Dewhurst <adrian@tailscale.com>
pull/11476/head
Adrian Dewhurst 8 months ago committed by Adrian Dewhurst
parent 067ed0bf6f
commit 2f7e7be2ea

@ -8,6 +8,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"maps"
"net" "net"
"reflect" "reflect"
"slices" "slices"
@ -668,14 +669,14 @@ func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node) (_ *tailcfg.PeerChang
if n.CapMap == nil { if n.CapMap == nil {
pc().CapMap = make(tailcfg.NodeCapMap) pc().CapMap = make(tailcfg.NodeCapMap)
} else { } else {
pc().CapMap = n.CapMap pc().CapMap = maps.Clone(n.CapMap)
} }
break break
} }
was.CapMap().Range(func(k tailcfg.NodeCapability, v views.Slice[tailcfg.RawMessage]) bool { was.CapMap().Range(func(k tailcfg.NodeCapability, v views.Slice[tailcfg.RawMessage]) bool {
nv, ok := n.CapMap[k] nv, ok := n.CapMap[k]
if !ok || !views.SliceEqual(v, views.SliceOf(nv)) { if !ok || !views.SliceEqual(v, views.SliceOf(nv)) {
pc().CapMap = n.CapMap pc().CapMap = maps.Clone(n.CapMap)
return false return false
} }
return true return true

@ -865,6 +865,11 @@ func TestPeerChangeDiff(t *testing.T) {
a: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{tailcfg.CapabilityAdmin: nil}}, a: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{tailcfg.CapabilityAdmin: nil}},
b: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{}}, b: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{}},
want: &tailcfg.PeerChange{NodeID: 1, CapMap: tailcfg.NodeCapMap{}}, want: &tailcfg.PeerChange{NodeID: 1, CapMap: tailcfg.NodeCapMap{}},
}, {
name: "patch-capmap-remove-as-nil",
a: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{tailcfg.CapabilityAdmin: nil}},
b: &tailcfg.Node{ID: 1},
want: &tailcfg.PeerChange{NodeID: 1, CapMap: tailcfg.NodeCapMap{}},
}, { }, {
name: "patch-capmap-add-key-to-empty-map", name: "patch-capmap-add-key-to-empty-map",
a: &tailcfg.Node{ID: 1}, a: &tailcfg.Node{ID: 1},

Loading…
Cancel
Save