ipn/ipnlocal: add localNodeContext with netmap-related fields and methods
Updates #12614 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
+34
-29
@@ -920,15 +920,15 @@ func TestWatchNotificationsCallbacks(t *testing.T) {
|
||||
// tests LocalBackend.updateNetmapDeltaLocked
|
||||
func TestUpdateNetmapDelta(t *testing.T) {
|
||||
b := newTestLocalBackend(t)
|
||||
if b.updateNetmapDeltaLocked(nil) {
|
||||
if b.currentNode().UpdateNetmapDelta(nil) {
|
||||
t.Errorf("updateNetmapDeltaLocked() = true, want false with nil netmap")
|
||||
}
|
||||
|
||||
b.netMap = &netmap.NetworkMap{}
|
||||
nm := &netmap.NetworkMap{}
|
||||
for i := range 5 {
|
||||
b.netMap.Peers = append(b.netMap.Peers, (&tailcfg.Node{ID: (tailcfg.NodeID(i) + 1)}).View())
|
||||
nm.Peers = append(nm.Peers, (&tailcfg.Node{ID: (tailcfg.NodeID(i) + 1)}).View())
|
||||
}
|
||||
b.updatePeersFromNetmapLocked(b.netMap)
|
||||
b.currentNode().SetNetMap(nm)
|
||||
|
||||
someTime := time.Unix(123, 0)
|
||||
muts, ok := netmap.MutationsFromMapResponse(&tailcfg.MapResponse{
|
||||
@@ -955,7 +955,7 @@ func TestUpdateNetmapDelta(t *testing.T) {
|
||||
t.Fatal("netmap.MutationsFromMapResponse failed")
|
||||
}
|
||||
|
||||
if !b.updateNetmapDeltaLocked(muts) {
|
||||
if !b.currentNode().UpdateNetmapDelta(muts) {
|
||||
t.Fatalf("updateNetmapDeltaLocked() = false, want true with new netmap")
|
||||
}
|
||||
|
||||
@@ -978,9 +978,9 @@ func TestUpdateNetmapDelta(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, want := range wants {
|
||||
gotv, ok := b.peers[want.ID]
|
||||
gotv, ok := b.currentNode().PeerByID(want.ID)
|
||||
if !ok {
|
||||
t.Errorf("netmap.Peer %v missing from b.peers", want.ID)
|
||||
t.Errorf("netmap.Peer %v missing from b.profile.Peers", want.ID)
|
||||
continue
|
||||
}
|
||||
got := gotv.AsStruct()
|
||||
@@ -1398,7 +1398,7 @@ func TestCoveredRouteRangeNoDefault(t *testing.T) {
|
||||
|
||||
func TestReconfigureAppConnector(t *testing.T) {
|
||||
b := newTestBackend(t)
|
||||
b.reconfigAppConnectorLocked(b.netMap, b.pm.prefs)
|
||||
b.reconfigAppConnectorLocked(b.NetMap(), b.pm.prefs)
|
||||
if b.appConnector != nil {
|
||||
t.Fatal("unexpected app connector")
|
||||
}
|
||||
@@ -1411,7 +1411,7 @@ func TestReconfigureAppConnector(t *testing.T) {
|
||||
},
|
||||
AppConnectorSet: true,
|
||||
})
|
||||
b.reconfigAppConnectorLocked(b.netMap, b.pm.prefs)
|
||||
b.reconfigAppConnectorLocked(b.NetMap(), b.pm.prefs)
|
||||
if b.appConnector == nil {
|
||||
t.Fatal("expected app connector")
|
||||
}
|
||||
@@ -1422,15 +1422,19 @@ func TestReconfigureAppConnector(t *testing.T) {
|
||||
"connectors": ["tag:example"]
|
||||
}`
|
||||
|
||||
b.netMap.SelfNode = (&tailcfg.Node{
|
||||
Name: "example.ts.net",
|
||||
Tags: []string{"tag:example"},
|
||||
CapMap: (tailcfg.NodeCapMap)(map[tailcfg.NodeCapability][]tailcfg.RawMessage{
|
||||
"tailscale.com/app-connectors": {tailcfg.RawMessage(appCfg)},
|
||||
}),
|
||||
}).View()
|
||||
nm := &netmap.NetworkMap{
|
||||
SelfNode: (&tailcfg.Node{
|
||||
Name: "example.ts.net",
|
||||
Tags: []string{"tag:example"},
|
||||
CapMap: (tailcfg.NodeCapMap)(map[tailcfg.NodeCapability][]tailcfg.RawMessage{
|
||||
"tailscale.com/app-connectors": {tailcfg.RawMessage(appCfg)},
|
||||
}),
|
||||
}).View(),
|
||||
}
|
||||
|
||||
b.reconfigAppConnectorLocked(b.netMap, b.pm.prefs)
|
||||
b.currentNode().SetNetMap(nm)
|
||||
|
||||
b.reconfigAppConnectorLocked(b.NetMap(), b.pm.prefs)
|
||||
b.appConnector.Wait(context.Background())
|
||||
|
||||
want := []string{"example.com"}
|
||||
@@ -1450,7 +1454,7 @@ func TestReconfigureAppConnector(t *testing.T) {
|
||||
},
|
||||
AppConnectorSet: true,
|
||||
})
|
||||
b.reconfigAppConnectorLocked(b.netMap, b.pm.prefs)
|
||||
b.reconfigAppConnectorLocked(b.NetMap(), b.pm.prefs)
|
||||
if b.appConnector != nil {
|
||||
t.Fatal("expected no app connector")
|
||||
}
|
||||
@@ -1482,7 +1486,7 @@ func TestBackfillAppConnectorRoutes(t *testing.T) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.reconfigAppConnectorLocked(b.netMap, b.pm.prefs)
|
||||
b.reconfigAppConnectorLocked(b.NetMap(), b.pm.prefs)
|
||||
|
||||
// Smoke check that AdvertiseRoutes doesn't have the test IP.
|
||||
ip := netip.MustParseAddr("1.2.3.4")
|
||||
@@ -1503,7 +1507,7 @@ func TestBackfillAppConnectorRoutes(t *testing.T) {
|
||||
|
||||
// Mimic b.authReconfigure for the app connector bits.
|
||||
b.mu.Lock()
|
||||
b.reconfigAppConnectorLocked(b.netMap, b.pm.prefs)
|
||||
b.reconfigAppConnectorLocked(b.NetMap(), b.pm.prefs)
|
||||
b.mu.Unlock()
|
||||
b.readvertiseAppConnectorRoutes()
|
||||
|
||||
@@ -1819,7 +1823,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
|
||||
}
|
||||
pm := must.Get(newProfileManager(new(mem.Store), t.Logf, new(health.Tracker)))
|
||||
pm.prefs = test.prefs.View()
|
||||
b.netMap = test.nm
|
||||
b.currentNode().SetNetMap(test.nm)
|
||||
b.pm = pm
|
||||
b.lastSuggestedExitNode = test.lastSuggestedExitNode
|
||||
|
||||
@@ -1946,8 +1950,7 @@ func TestUpdateNetmapDeltaAutoExitNode(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b := newTestLocalBackend(t)
|
||||
b.netMap = tt.netmap
|
||||
b.updatePeersFromNetmapLocked(b.netMap)
|
||||
b.currentNode().SetNetMap(tt.netmap)
|
||||
b.lastSuggestedExitNode = tt.lastSuggestedExitNode
|
||||
b.sys.MagicSock.Get().SetLastNetcheckReportForTest(b.ctx, tt.report)
|
||||
b.SetPrefsForTest(b.pm.CurrentPrefs().AsStruct())
|
||||
@@ -2065,14 +2068,14 @@ func TestAutoExitNodeSetNetInfoCallback(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
b.netMap = &netmap.NetworkMap{
|
||||
b.currentNode().SetNetMap(&netmap.NetworkMap{
|
||||
SelfNode: selfNode.View(),
|
||||
Peers: []tailcfg.NodeView{
|
||||
peer1,
|
||||
peer2,
|
||||
},
|
||||
DERPMap: defaultDERPMap,
|
||||
}
|
||||
})
|
||||
b.lastSuggestedExitNode = peer1.StableID()
|
||||
b.SetPrefsForTest(b.pm.CurrentPrefs().AsStruct())
|
||||
if eid := b.Prefs().ExitNodeID(); eid != peer1.StableID() {
|
||||
@@ -2137,7 +2140,7 @@ func TestSetControlClientStatusAutoExitNode(t *testing.T) {
|
||||
syspolicy.ExitNodeID, "auto:any",
|
||||
))
|
||||
syspolicy.MustRegisterStoreForTest(t, "TestStore", setting.DeviceScope, policyStore)
|
||||
b.netMap = nm
|
||||
b.currentNode().SetNetMap(nm)
|
||||
b.lastSuggestedExitNode = peer1.StableID()
|
||||
b.sys.MagicSock.Get().SetLastNetcheckReportForTest(b.ctx, report)
|
||||
b.SetPrefsForTest(b.pm.CurrentPrefs().AsStruct())
|
||||
@@ -3068,9 +3071,11 @@ func TestDriveManageShares(t *testing.T) {
|
||||
b.driveSetSharesLocked(tt.existing)
|
||||
}
|
||||
if !tt.disabled {
|
||||
self := b.netMap.SelfNode.AsStruct()
|
||||
nm := ptr.To(*b.currentNode().NetMap())
|
||||
self := nm.SelfNode.AsStruct()
|
||||
self.CapMap = tailcfg.NodeCapMap{tailcfg.NodeAttrsTaildriveShare: nil}
|
||||
b.netMap.SelfNode = self.View()
|
||||
nm.SelfNode = self.View()
|
||||
b.currentNode().SetNetMap(nm)
|
||||
b.sys.Set(driveimpl.NewFileSystemForRemote(b.logf))
|
||||
}
|
||||
b.mu.Unlock()
|
||||
@@ -5323,7 +5328,7 @@ func TestSrcCapPacketFilter(t *testing.T) {
|
||||
}},
|
||||
})
|
||||
|
||||
f := lb.GetFilterForTest()
|
||||
f := lb.currentNode().GetFilterForTest()
|
||||
res := f.Check(netip.MustParseAddr("2.2.2.2"), netip.MustParseAddr("1.1.1.1"), 22, ipproto.TCP)
|
||||
if res != filter.Accept {
|
||||
t.Errorf("Check(2.2.2.2, ...) = %s, want %s", res, filter.Accept)
|
||||
|
||||
Reference in New Issue
Block a user