systemd-resolved: routes answers the uplink's names and the mesh's fallback (issue 960)
routes (bus and the machine socket) gains uplink_names {names, link,
refused}, the applied list's names resolved holds on that link now, never
the file's, and mesh_resolvers {silent, since} from the guard's fallback
state. The guard writes that state at each of ADR 0688's two turns, and
once more at its own first round, since it goes at every boot.
Builds: design 08 sign-in-page §2, §8, §9
This commit is contained in:
@@ -41,6 +41,7 @@ func aGuardedMachineWithLinks(t *testing.T, links ...string) (*Guard, *time.Time
|
||||
now := time.Date(2026, 10, 7, 12, 0, 0, 0, time.UTC)
|
||||
f := &fakeResolved{}
|
||||
r := aMachine(t, f, links...)
|
||||
r.FallbackFile = filepath.Join(dir, "run", "fallback.json")
|
||||
g := &Guard{Path: filepath.Join(dir, "etc/resolv.conf"), KeptPath: filepath.Join(dir, "etc/node-resolver/resolv.conf"),
|
||||
Dir: filepath.Join(dir, "run"), Hold: Hold, Now: func() time.Time { return now },
|
||||
Resolver: r, Log: t.Logf, wake: make(chan struct{}, 1)}
|
||||
@@ -409,6 +410,73 @@ func TestARefusalByResolvedIsJournalledOncePerChange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The guard writes Resolver.FallbackFile at each of ADR 0688's two turns, and once more at its own first
|
||||
// round, since it goes at every boot (design 08 sign-in-page §8; S-N5, R2-2; R-9).
|
||||
func TestTheGuardWritesTheFallbackFileAtEachTurnAndItsFirstRound(t *testing.T) {
|
||||
g, now, f := aGuardedMachine(t)
|
||||
meshAnswers := true
|
||||
g.Resolver.Answers = func(context.Context, string) bool { return meshAnswers }
|
||||
f.dns = "Global: 10.42.0.1\n"
|
||||
f.domain = "Global: ~.\n"
|
||||
// The first round, the mesh answering, writes the file although nothing changed.
|
||||
g.KeepRoutes(context.Background())
|
||||
first := ReadFallback(g.Resolver.FallbackFile)
|
||||
if first.Silent {
|
||||
t.Fatalf("the first round says %+v, want not silent", first)
|
||||
}
|
||||
// A second round with nothing changed does not move `since`.
|
||||
*now = now.Add(time.Second)
|
||||
g.KeepRoutes(context.Background())
|
||||
if again := ReadFallback(g.Resolver.FallbackFile); !again.Since.Equal(first.Since) {
|
||||
t.Errorf("an unchanged round moved since: %v, was %v", again.Since, first.Since)
|
||||
}
|
||||
// The mesh goes silent: the turn is written with the new since.
|
||||
*now = now.Add(time.Second)
|
||||
meshAnswers = false
|
||||
g.KeepRoutes(context.Background())
|
||||
silentState := ReadFallback(g.Resolver.FallbackFile)
|
||||
if !silentState.Silent || !silentState.Since.Equal(*now) {
|
||||
t.Errorf("the silent turn is %+v, want silent since %v", silentState, *now)
|
||||
}
|
||||
// It answers again: the other turn.
|
||||
*now = now.Add(time.Second)
|
||||
meshAnswers = true
|
||||
g.KeepRoutes(context.Background())
|
||||
answering := ReadFallback(g.Resolver.FallbackFile)
|
||||
if answering.Silent || !answering.Since.Equal(*now) {
|
||||
t.Errorf("the answering turn is %+v, want not silent since %v", answering, *now)
|
||||
}
|
||||
}
|
||||
|
||||
// routes answers uplink_names with the applied list's names resolved holds on that link now, resolved's
|
||||
// refusal, and mesh_resolvers from the fallback file (design 08 sign-in-page §2, §9; R-9).
|
||||
func TestRoutesAnswersUplinkNamesAndMeshResolvers(t *testing.T) {
|
||||
f := &fakeResolved{dns: "Link 2 (wlan0): 192.168.1.1\n", domain: "Link 2 (wlan0): lan ~check.example\n"}
|
||||
r := aMachine(t, f, "wlan0")
|
||||
applied := UplinkApplied{Names: []string{"check.example", "not-held.example"}, Link: "wlan0", Refused: "refused once"}
|
||||
raw, _ := json.Marshal(applied)
|
||||
if err := os.WriteFile(r.UplinkNamesAppliedFile, raw, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
since := time.Date(2026, 11, 24, 10, 0, 0, 0, time.UTC)
|
||||
fb, _ := json.Marshal(FallbackState{Silent: true, Since: since})
|
||||
if err := os.WriteFile(r.FallbackFile, fb, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
routes, err := r.Routes(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
un := r.UplinkNamesAnswer(routes)
|
||||
if names, _ := un["names"].([]string); strings.Join(names, ",") != "check.example" || un["link"] != "wlan0" || un["refused"] != "refused once" {
|
||||
t.Errorf("uplink_names is %+v", un)
|
||||
}
|
||||
mr := r.MeshResolversAnswer()
|
||||
if mr["silent"] != true || !mr["since"].(time.Time).Equal(since) {
|
||||
t.Errorf("mesh_resolvers is %+v", mr)
|
||||
}
|
||||
}
|
||||
|
||||
// A network joined while the mesh's resolvers are silent keeps its default route, and loses it once one answers.
|
||||
// (1981/AC2)
|
||||
func TestANetworkJoinedWhileTheMeshIsSilentKeepsItsDefaultRoute(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user