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:
jochen
2026-11-24 22:01:01 +01:00
parent 717f8ec2e5
commit bd6dcdcd0c
2 changed files with 89 additions and 12 deletions
@@ -364,9 +364,9 @@ func (g *Guard) KeepRoutes(ctx context.Context) {
}
if !g.Resolver.TheMeshAnswers(ctx, routes.Mesh.Servers) {
if turn := !g.silent; turn || !g.fallbackWritten {
if turn {
g.silentSince = g.Now()
}
// since is this round's time whether it is a real turn or the guard's first round
// establishing where things stand (design 08 sign-in-page §8, note (c)): never the zero time.
g.silentSince = g.Now()
g.silent = true
g.writeFallback()
if turn {
@@ -379,9 +379,7 @@ func (g *Guard) KeepRoutes(ctx context.Context) {
return
}
if turn := g.silent; turn || !g.fallbackWritten {
if turn {
g.silentSince = g.Now()
}
g.silentSince = g.Now()
g.silent = false
g.writeFallback()
if turn {
@@ -472,6 +470,32 @@ func (g *Guard) setLinkUplinkNames(ctx context.Context, link string, names []str
return err
}
// uplinkNamesHeld is whether resolved holds every name on the link now, read fresh with rawDomainsOf
// (design 08 sign-in-page §7, C-4): never the guard's 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.
func (g *Guard) uplinkNamesHeld(ctx context.Context, link string, names []string) bool {
if len(names) == 0 {
return true
}
if link == "" {
return false
}
raw, err := g.rawDomainsOf(ctx, link)
if err != nil {
return false
}
has := map[string]bool{}
for _, d := range raw {
has[d] = true
}
for _, n := range names {
if !has["~"+n] {
return false
}
}
return true
}
// KeepUplinkNames gives the names in the file to the link carrying the default route, every round (design
// 08 sign-in-page §7, §8): it never sets a link's servers, its default route for names, its addresses or
// its routes. A round in which they are already in place changes nothing.
@@ -486,9 +510,11 @@ func (g *Guard) KeepUplinkNames(ctx context.Context) {
g.Log("the kernel's default routes: %v", err)
return
}
if link == g.applied.Link && sameNames(given, g.applied.Names) && g.applied.Refused == "" {
held := g.uplinkNamesHeld(ctx, link, given)
if link == g.applied.Link && g.applied.Refused == "" && held {
return
}
missing := link == g.applied.Link && sameNames(given, g.applied.Names) && !held
if g.applied.Link != "" && g.applied.Link != link {
if err := g.setLinkUplinkNames(ctx, g.applied.Link, nil); err != nil {
g.Log("taking the uplink's names off %s failed: %v", g.applied.Link, err)
@@ -500,9 +526,12 @@ func (g *Guard) KeepUplinkNames(ctx context.Context) {
refused = err.Error()
}
}
if link != g.applied.Link {
switch {
case link != g.applied.Link:
g.Log("the uplink's names are now answered over %q, were %q", link, g.applied.Link)
} else if !sameNames(given, g.applied.Names) {
case missing:
g.Log("the uplink's names were missing from %s, as resolved holds it now; set again", link)
case !sameNames(given, g.applied.Names):
g.Log("the uplink's names change on %s", link)
}
if refused != g.applied.Refused {