From 39a4dfb85c61ec9adc781aaf8cec4f595485796f Mon Sep 17 00:00:00 2001 From: James Sanderson Date: Thu, 30 Jan 2025 16:04:29 +0000 Subject: [PATCH] WIP: Testing Netmaps + client packet filter end to end --- control/controlclient/auto.go | 19 +++++++++++++++++++ control/controlclient/direct.go | 1 + control/controlclient/map.go | 4 ++++ ipn/ipnlocal/local.go | 4 ++++ 4 files changed, 28 insertions(+) diff --git a/control/controlclient/auto.go b/control/controlclient/auto.go index da123f8c4..4d68fdf64 100644 --- a/control/controlclient/auto.go +++ b/control/controlclient/auto.go @@ -201,6 +201,21 @@ func NewNoStart(opts Options) (_ *Auto, err error) { } +func NewForTest(direct *Direct, observer Observer, ctx context.Context) *Auto { + c := &Auto{ + direct: direct, + logf: func(fmt string, args ...any) {}, + updateCh: make(chan struct{}, 1), + authDone: make(chan struct{}), + mapDone: make(chan struct{}), + updateDone: make(chan struct{}), + observer: observer, + mapCtx: ctx, + } + + return c +} + // SetPaused controls whether HTTP activity should be paused. // // The client can be paused and unpaused repeatedly, unlike Start and Shutdown, which can only be used once. @@ -468,6 +483,10 @@ func (mrs mapRoutineState) UpdateNetmapDelta(muts []netmap.NodeMutation) bool { return err == nil && ok } +func (c *Auto) MapRoutineForTest() { + c.mapRoutine() +} + // mapRoutine is responsible for keeping a read-only streaming connection to the // control server, and keeping the netmap up to date. func (c *Auto) mapRoutine() { diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index f327ecc2a..ac994e59b 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -1044,6 +1044,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap vlogf("netmap: decode error: %v", err) return err } + vlogf("raw netmap: %+v", resp) watchdogTimer.Stop() metricMapResponseMessages.Add(1) diff --git a/control/controlclient/map.go b/control/controlclient/map.go index f0a11bdf1..4b767bde4 100644 --- a/control/controlclient/map.go +++ b/control/controlclient/map.go @@ -117,6 +117,10 @@ func newMapSession(privateNodeKey key.NodePrivate, nu NetmapUpdater, controlKnob return ms } +func NewMapSessionForTestOnlyDoNotUse(privateNodeKey key.NodePrivate, nu NetmapUpdater, controlKnobs *controlknobs.Knobs) *mapSession { + return newMapSession(privateNodeKey, nu, controlKnobs) +} + // occasionallyPrintSummary logs summary at most once very 5 minutes. The // summary is the Netmap.VeryConcise result from the last received map response. func (ms *mapSession) occasionallyPrintSummary(summary string) { diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index a6e3f1952..6ca917683 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -1417,6 +1417,10 @@ func (b *LocalBackend) peerCapsLocked(src netip.Addr) tailcfg.PeerCapMap { return nil } +func (b *LocalBackend) GetFilterForTest() *filter.Filter { + return b.filterAtomic.Load() +} + // SetControlClientStatus is the callback invoked by the control client whenever it posts a new status. // Among other things, this is where we update the netmap, packet filters, DNS and DERP maps. func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st controlclient.Status) {