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:
@@ -99,6 +99,9 @@ type Resolver struct {
|
||||
UplinkNamesFile string
|
||||
// UplinkNamesAppliedFile is what the guard last gave the link carrying the default route (§8).
|
||||
UplinkNamesAppliedFile string
|
||||
// FallbackFile is `routes`'s state for ADR 0688's fallback (§8): whether the mesh's resolvers are
|
||||
// silent, and since when.
|
||||
FallbackFile string
|
||||
// WriteUplinkNames writes UplinkNamesFile whole, as root (§6); stood in for in tests.
|
||||
WriteUplinkNames func(ctx context.Context, content []byte) error
|
||||
// Now is the clock the uplink-names verb stamps its answer with; stood in for in tests.
|
||||
@@ -109,7 +112,8 @@ type Resolver struct {
|
||||
func ThisResolver() *Resolver {
|
||||
r := &Resolver{Change: execRunner, Read: readRunner, NetDir: "/sys/class/net", SuffixFile: SuffixPath,
|
||||
AnswerWithinFile: AnswerWithinPath, PrivateInterfaceFile: PrivateInterfacePath,
|
||||
UplinkNamesFile: UplinkNamesPath, UplinkNamesAppliedFile: UplinkNamesAppliedPath, Now: time.Now}
|
||||
UplinkNamesFile: UplinkNamesPath, UplinkNamesAppliedFile: UplinkNamesAppliedPath, FallbackFile: Fallback,
|
||||
Now: time.Now}
|
||||
r.Answers = r.asks
|
||||
r.WriteUplinkNames = r.writeUplinkNamesFile
|
||||
return r
|
||||
@@ -281,6 +285,36 @@ func (r *Resolver) Routes(ctx context.Context) (*Routes, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UplinkNamesAnswer is `routes`'s `uplink_names` field (design 08 sign-in-page §2, §9; DQ-3): the applied
|
||||
// list's names that resolved holds on that link now, never the file's, the link, and resolved's refusal or
|
||||
// empty.
|
||||
func (r *Resolver) UplinkNamesAnswer(routes *Routes) map[string]any {
|
||||
applied := ReadUplinkApplied(r.UplinkNamesAppliedFile)
|
||||
held := []string{}
|
||||
for _, l := range routes.Links {
|
||||
if l.Link != applied.Link {
|
||||
continue
|
||||
}
|
||||
has := map[string]bool{}
|
||||
for _, d := range l.Domains {
|
||||
has[d] = true
|
||||
}
|
||||
for _, n := range applied.Names {
|
||||
if has[n] {
|
||||
held = append(held, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
return map[string]any{"names": held, "link": applied.Link, "refused": applied.Refused}
|
||||
}
|
||||
|
||||
// MeshResolversAnswer is `routes`'s `mesh_resolvers` field (design 08 sign-in-page §9; S-N5): whether the
|
||||
// mesh's resolvers are silent now, by ADR 0688's guard, and since when.
|
||||
func (r *Resolver) MeshResolversAnswer() map[string]any {
|
||||
s := ReadFallback(r.FallbackFile)
|
||||
return map[string]any{"silent": s.Silent, "since": s.Since}
|
||||
}
|
||||
|
||||
// withoutMarked is domains without those marked (design 08 sign-in-page DMC-2).
|
||||
func withoutMarked(domains []string, marked map[string]bool) []string {
|
||||
out := make([]string, 0, len(domains))
|
||||
|
||||
Reference in New Issue
Block a user