From 0f3c279b86e2dfd9472e45e5b08ca399c15a6058 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 17 Sep 2023 10:27:54 -0500 Subject: [PATCH] ipn/ipnlocal: delete some unused code Updates #cleanup Change-Id: I90b46c476f135124d97288e776c2b428b351b8b8 Signed-off-by: Brad Fitzpatrick --- ipn/ipnlocal/local.go | 47 ---------------- ipn/ipnlocal/local_test.go | 107 ------------------------------------- 2 files changed, 154 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 70e56696c..3ac6d185a 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -1833,53 +1833,6 @@ func shrinkDefaultRoute(route netip.Prefix, localInterfaceRoutes *netipx.IPSet, return b.IPSet() } -// dnsCIDRsEqual determines whether two CIDR lists are equal -// for DNS map construction purposes (that is, only the first entry counts). -func dnsCIDRsEqual(newAddr, oldAddr views.Slice[netip.Prefix]) bool { - if newAddr.Len() != oldAddr.Len() { - return false - } - if newAddr.Len() == 0 || newAddr.At(0) == oldAddr.At(0) { - return true - } - return false -} - -// dnsMapsEqual determines whether the new and the old network map -// induce the same DNS map. It does so without allocating memory, -// at the expense of giving false negatives if peers are reordered. -func dnsMapsEqual(new, old *netmap.NetworkMap) bool { - if (old == nil) != (new == nil) { - return false - } - if old == nil && new == nil { - return true - } - - if len(new.Peers) != len(old.Peers) { - return false - } - - if new.Name != old.Name { - return false - } - if !dnsCIDRsEqual(views.SliceOf(new.Addresses), views.SliceOf(old.Addresses)) { - return false - } - - for i, newPeer := range new.Peers { - oldPeer := old.Peers[i] - if newPeer.Name() != oldPeer.Name() { - return false - } - if !dnsCIDRsEqual(newPeer.Addresses(), oldPeer.Addresses()) { - return false - } - } - - return true -} - // readPoller is a goroutine that receives service lists from // b.portpoll and propagates them into the controlclient's HostInfo. func (b *LocalBackend) readPoller() { diff --git a/ipn/ipnlocal/local_test.go b/ipn/ipnlocal/local_test.go index ad32a9757..81a7ba068 100644 --- a/ipn/ipnlocal/local_test.go +++ b/ipn/ipnlocal/local_test.go @@ -34,113 +34,6 @@ "tailscale.com/wgengine/wgcfg" ) -func TestNetworkMapCompare(t *testing.T) { - prefix1, err := netip.ParsePrefix("192.168.0.0/24") - if err != nil { - t.Fatal(err) - } - node1 := &tailcfg.Node{Addresses: []netip.Prefix{prefix1}} - - prefix2, err := netip.ParsePrefix("10.0.0.0/8") - if err != nil { - t.Fatal(err) - } - node2 := &tailcfg.Node{Addresses: []netip.Prefix{prefix2}} - - tests := []struct { - name string - a, b *netmap.NetworkMap - want bool - }{ - { - "both nil", - nil, - nil, - true, - }, - { - "b nil", - &netmap.NetworkMap{}, - nil, - false, - }, - { - "a nil", - nil, - &netmap.NetworkMap{}, - false, - }, - { - "both default", - &netmap.NetworkMap{}, - &netmap.NetworkMap{}, - true, - }, - { - "names identical", - &netmap.NetworkMap{Name: "map1"}, - &netmap.NetworkMap{Name: "map1"}, - true, - }, - { - "names differ", - &netmap.NetworkMap{Name: "map1"}, - &netmap.NetworkMap{Name: "map2"}, - false, - }, - { - "Peers identical", - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{})}, - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{})}, - true, - }, - { - "Peer list length", - // length of Peers list differs - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{}})}, - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{})}, - false, - }, - { - "Node names identical", - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "A"}})}, - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "A"}})}, - true, - }, - { - "Node names differ", - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "A"}})}, - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "B"}})}, - false, - }, - { - "Node lists identical", - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node1})}, - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node1})}, - true, - }, - { - "Node lists differ", - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node1})}, - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node2})}, - false, - }, - { - "Node Users differ", - // User field is not checked. - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{User: 0}})}, - &netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{User: 1}})}, - true, - }, - } - for _, tt := range tests { - got := dnsMapsEqual(tt.a, tt.b) - if got != tt.want { - t.Errorf("%s: Equal = %v; want %v", tt.name, got, tt.want) - } - } -} - func inRemove(ip netip.Addr) bool { for _, pfx := range removeFromDefaultRoute { if pfx.Contains(ip) {