systemd-resolved: judge "in place" from what resolved holds now (review r1 C-4, note c)
C-4: the guard reads the link's domains fresh with rawDomainsOf before skipping a round, never trusting its own applied record alone, so a network manager that rewrites the link's domains, or a restarted resolved, is found and the names are set again. note (c): fallback.json's since is the time of the guard's first round, never the zero time; it moved only on a real turn before, so the first round's write carried a zero since. Builds: design 08 sign-in-page §7, §8, C-4
This commit is contained in:
@@ -365,6 +365,53 @@ func TestAChangedListReplacesTheOldOneOnTheLink(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A network manager that rewrites the link's domains (a DHCP renewal, say) loses the uplink's names; the
|
||||
// guard judges "in place" from what resolved holds now, never its own record alone, and sets them again
|
||||
// (design 08 sign-in-page §7; C-4).
|
||||
func TestANetworkManagerRewriteOfTheLinksDomainsIsSetAgain(t *testing.T) {
|
||||
g, _, f, r := aGuardedMachineWithLinks(t, "wlan0")
|
||||
f.dns = "Link 2 (wlan0): 192.168.1.1\n"
|
||||
f.domain = "Link 2 (wlan0): lan\n"
|
||||
f.ip = "default via 10.0.0.1 dev wlan0 metric 100\n"
|
||||
if err := os.WriteFile(r.UplinkNamesFile, []byte("check.example\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g.KeepUplinkNames(context.Background())
|
||||
if len(f.changed) != 1 || strings.Join(f.changed[0], " ") != "resolvectl domain wlan0 lan ~check.example" {
|
||||
t.Fatalf("the first round gave %v", f.changed)
|
||||
}
|
||||
// The network manager rewrites the link's domains: the uplink's name is gone, the applied record is not.
|
||||
f.domain = "Link 2 (wlan0): lan\n"
|
||||
f.changed = nil
|
||||
g.KeepUplinkNames(context.Background())
|
||||
if len(f.changed) != 1 || strings.Join(f.changed[0], " ") != "resolvectl domain wlan0 lan ~check.example" {
|
||||
t.Errorf("a rewrite that lost the uplink's name was not set again: %v", f.changed)
|
||||
}
|
||||
}
|
||||
|
||||
// resolved itself restarts, forgetting every link's domains; the guard's next round, judging from what
|
||||
// resolved holds now, sets the uplink's names again (design 08 sign-in-page §7; C-4).
|
||||
func TestAResolvedRestartLosingTheLinksDomainsIsSetAgain(t *testing.T) {
|
||||
g, _, f, r := aGuardedMachineWithLinks(t, "wlan0")
|
||||
f.dns = "Link 2 (wlan0): 192.168.1.1\n"
|
||||
f.domain = "Link 2 (wlan0): lan\n"
|
||||
f.ip = "default via 10.0.0.1 dev wlan0 metric 100\n"
|
||||
if err := os.WriteFile(r.UplinkNamesFile, []byte("check.example\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g.KeepUplinkNames(context.Background())
|
||||
if len(f.changed) != 1 {
|
||||
t.Fatalf("the first round gave %v", f.changed)
|
||||
}
|
||||
// resolved restarts: every link's domains are gone, the guard's applied record is not.
|
||||
f.domain = "Link 2 (wlan0):\n"
|
||||
f.changed = nil
|
||||
g.KeepUplinkNames(context.Background())
|
||||
if len(f.changed) != 1 || strings.Join(f.changed[0], " ") != "resolvectl domain wlan0 ~check.example" {
|
||||
t.Errorf("a restarted resolved was not given the uplink's names again: %v", f.changed)
|
||||
}
|
||||
}
|
||||
|
||||
// A guard restarted with an applied file takes the uplink's names off the link it names, never inferring
|
||||
// which (design 08 sign-in-page §8, §9; R-6).
|
||||
func TestARestartedGuardTakesTheUplinkNamesOffTheLinkItNames(t *testing.T) {
|
||||
@@ -446,11 +493,12 @@ func TestTheGuardWritesTheFallbackFileAtEachTurnAndItsFirstRound(t *testing.T) {
|
||||
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.
|
||||
// The first round, the mesh answering, writes the file although nothing changed: since is the first
|
||||
// round's time, never the zero time (design 08 sign-in-page note (c)).
|
||||
g.KeepRoutes(context.Background())
|
||||
first := ReadFallback(g.Resolver.FallbackFile)
|
||||
if first.Silent {
|
||||
t.Fatalf("the first round says %+v, want not silent", first)
|
||||
if first.Silent || !first.Since.Equal(*now) {
|
||||
t.Fatalf("the first round says %+v, want not silent since %v", first, *now)
|
||||
}
|
||||
// A second round with nothing changed does not move `since`.
|
||||
*now = now.Add(time.Second)
|
||||
|
||||
Reference in New Issue
Block a user