appc,ipn/ipnlocal: receive AppConnector updates via the event bus (#17411)
Add subscribers for AppConnector events Make the RouteAdvertiser interface optional We cannot yet remove it because the tests still depend on it to verify correctness. We will need to separately update the test fixtures to remove that dependency. Publish RouteInfo via the event bus, so we do not need a callback to do that. Replace it with a flag that indicates whether to treat the route info the connector has as "definitive" for filtering purposes. Update the tests to simplify the construction of AppConnector values now that a store callback is no longer required. Also fix a couple of pre-existing racy tests that were hidden by not being concurrent in the same way production is. Updates #15160 Updates #17192 Change-Id: Id39525c0f02184e88feaf0d8a3c05504850e47ee Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
+61
-27
@@ -75,8 +75,6 @@ import (
|
||||
"tailscale.com/wgengine/wgcfg"
|
||||
)
|
||||
|
||||
func fakeStoreRoutes(*appctype.RouteInfo) error { return nil }
|
||||
|
||||
func inRemove(ip netip.Addr) bool {
|
||||
for _, pfx := range removeFromDefaultRoute {
|
||||
if pfx.Contains(ip) {
|
||||
@@ -2321,14 +2319,9 @@ func TestOfferingAppConnector(t *testing.T) {
|
||||
if b.OfferingAppConnector() {
|
||||
t.Fatal("unexpected offering app connector")
|
||||
}
|
||||
rc := &appctest.RouteCollector{}
|
||||
if shouldStore {
|
||||
b.appConnector = appc.NewAppConnector(appc.Config{
|
||||
Logf: t.Logf, EventBus: bus, RouteAdvertiser: rc, RouteInfo: &appctype.RouteInfo{}, StoreRoutesFunc: fakeStoreRoutes,
|
||||
})
|
||||
} else {
|
||||
b.appConnector = appc.NewAppConnector(appc.Config{Logf: t.Logf, EventBus: bus, RouteAdvertiser: rc})
|
||||
}
|
||||
b.appConnector = appc.NewAppConnector(appc.Config{
|
||||
Logf: t.Logf, EventBus: bus, HasStoredRoutes: shouldStore,
|
||||
})
|
||||
if !b.OfferingAppConnector() {
|
||||
t.Fatal("unexpected not offering app connector")
|
||||
}
|
||||
@@ -2379,6 +2372,7 @@ func TestObserveDNSResponse(t *testing.T) {
|
||||
for _, shouldStore := range []bool{false, true} {
|
||||
b := newTestBackend(t)
|
||||
bus := b.sys.Bus.Get()
|
||||
w := eventbustest.NewWatcher(t, bus)
|
||||
|
||||
// ensure no error when no app connector is configured
|
||||
if err := b.ObserveDNSResponse(dnsResponse("example.com.", "192.0.0.8")); err != nil {
|
||||
@@ -2386,28 +2380,30 @@ func TestObserveDNSResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
rc := &appctest.RouteCollector{}
|
||||
if shouldStore {
|
||||
b.appConnector = appc.NewAppConnector(appc.Config{
|
||||
Logf: t.Logf,
|
||||
EventBus: bus,
|
||||
RouteAdvertiser: rc,
|
||||
RouteInfo: &appctype.RouteInfo{},
|
||||
StoreRoutesFunc: fakeStoreRoutes,
|
||||
})
|
||||
} else {
|
||||
b.appConnector = appc.NewAppConnector(appc.Config{Logf: t.Logf, EventBus: bus, RouteAdvertiser: rc})
|
||||
}
|
||||
b.appConnector.UpdateDomains([]string{"example.com"})
|
||||
b.appConnector.Wait(context.Background())
|
||||
a := appc.NewAppConnector(appc.Config{
|
||||
Logf: t.Logf,
|
||||
EventBus: bus,
|
||||
RouteAdvertiser: rc,
|
||||
HasStoredRoutes: shouldStore,
|
||||
})
|
||||
a.UpdateDomains([]string{"example.com"})
|
||||
a.Wait(t.Context())
|
||||
b.appConnector = a
|
||||
|
||||
if err := b.ObserveDNSResponse(dnsResponse("example.com.", "192.0.0.8")); err != nil {
|
||||
t.Errorf("ObserveDNSResponse: %v", err)
|
||||
}
|
||||
b.appConnector.Wait(context.Background())
|
||||
a.Wait(t.Context())
|
||||
wantRoutes := []netip.Prefix{netip.MustParsePrefix("192.0.0.8/32")}
|
||||
if !slices.Equal(rc.Routes(), wantRoutes) {
|
||||
t.Fatalf("got routes %v, want %v", rc.Routes(), wantRoutes)
|
||||
}
|
||||
|
||||
if err := eventbustest.Expect(w,
|
||||
eqUpdate(appctype.RouteUpdate{Advertise: mustPrefix("192.0.0.8/32")}),
|
||||
); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2558,7 +2554,7 @@ func TestBackfillAppConnectorRoutes(t *testing.T) {
|
||||
|
||||
// Store the test IP in profile data, but not in Prefs.AdvertiseRoutes.
|
||||
b.ControlKnobs().AppCStoreRoutes.Store(true)
|
||||
if err := b.storeRouteInfo(&appctype.RouteInfo{
|
||||
if err := b.storeRouteInfo(appctype.RouteInfo{
|
||||
Domains: map[string][]netip.Addr{
|
||||
"example.com": {ip},
|
||||
},
|
||||
@@ -5511,10 +5507,10 @@ func TestReadWriteRouteInfo(t *testing.T) {
|
||||
b.pm.currentProfile = prof1.View()
|
||||
|
||||
// set up routeInfo
|
||||
ri1 := &appctype.RouteInfo{}
|
||||
ri1 := appctype.RouteInfo{}
|
||||
ri1.Wildcards = []string{"1"}
|
||||
|
||||
ri2 := &appctype.RouteInfo{}
|
||||
ri2 := appctype.RouteInfo{}
|
||||
ri2.Wildcards = []string{"2"}
|
||||
|
||||
// read before write
|
||||
@@ -7066,3 +7062,41 @@ func toStrings[T ~string](in []T) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type textUpdate struct {
|
||||
Advertise []string
|
||||
Unadvertise []string
|
||||
}
|
||||
|
||||
func routeUpdateToText(u appctype.RouteUpdate) textUpdate {
|
||||
var out textUpdate
|
||||
for _, p := range u.Advertise {
|
||||
out.Advertise = append(out.Advertise, p.String())
|
||||
}
|
||||
for _, p := range u.Unadvertise {
|
||||
out.Unadvertise = append(out.Unadvertise, p.String())
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func mustPrefix(ss ...string) (out []netip.Prefix) {
|
||||
for _, s := range ss {
|
||||
out = append(out, netip.MustParsePrefix(s))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// eqUpdate generates an eventbus test filter that matches an appctype.RouteUpdate
|
||||
// message equal to want, or reports an error giving a human-readable diff.
|
||||
//
|
||||
// TODO(creachadair): This is copied from the appc test package, but we can't
|
||||
// put it into the appctest package because the appc tests depend on it and
|
||||
// that makes a cycle. Clean up those tests and put this somewhere common.
|
||||
func eqUpdate(want appctype.RouteUpdate) func(appctype.RouteUpdate) error {
|
||||
return func(got appctype.RouteUpdate) error {
|
||||
if diff := cmp.Diff(routeUpdateToText(got), routeUpdateToText(want)); diff != "" {
|
||||
return fmt.Errorf("wrong update (-got, +want):\n%s", diff)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user