Ninlil loads a list of hosts files into one name table and reloads it when a file changes #174

Open
opened 2026-10-31 12:42:20 -04:00 by claude · 0 comments
Owner
  • Draft: PN-30
  • Priority: medium
  • Agent: coder
  • Depends on: none
  • Decisions: Q-PN-11, R2-HOSTS-DEF

Why

See #173: the loader is the base the resolver and the API read.

What changes

  • New project src/dotnet/src/Ninlil.Dns.Server.HostsFiles (packed like its siblings, in Ninlil.slnx) with Extension/ServiceCollectionHostsFilesExtension.cs, and test project src/dotnet/tests/Ninlil.Dns.Server.HostsFiles.Tests.
  • HostsFilesOptions as #173 defines it (empty Paths, 60 s TTL). Add it to src/dotnet/src/Ninlil.Web/EnvironmentVariables/OptionsEnvironmentVariableRegistry.cs; ENVIRONMENT.md rows for NINLIL_DNS_SERVER_HOSTS_FILES_EXPAND_DOMAIN, ..._TIME_TO_LIVE_SECONDS and ..._POLL_INTERVAL, a note that Paths has no variable, and the totals counted from OptionsEnvironmentVariableMap.BuildMappings.
  • HostsFileParser:
    • one entry per name and address; aliases are names too
    • names checked with DnsName (RFC 1123 §2.1); IPv6 with a zone index (fe80::1%eth0) skipped
    • invalid lines counted, never echoed (a mistaken path such as a password file must not leak its content through the status)
    • Technical call: no boilerplate-name list. Unlike a block list, an operator's hosts file means what it says; the default empty Paths already keeps the system file out.
  • HostsFileTable: immutable, case-insensitive name to addresses lookup, plus address to first name, with the ExpandDomain forms.
  • HostsFileLoader (hosted service): load on start, watch plus poll, swap the table atomically, keep the last good entries of an unreadable file. Caps as constants (for example 16 MiB per file, 1,000,000 entries in total) with one warning when hit. It re-reads Paths through IOptionsMonitor, so a settings change applies without a restart.
  • IHostsFileStatusProvider: per path its kind (file or directory), entries loaded, invalid line count, last load time and last error.
  • Register in Program.cs. Nothing answers queries yet (#175).

Acceptance

  • This test fails first: Parse_ForALineWithAliases_ReturnsOneEntryPerName in src/dotnet/tests/Ninlil.Dns.Server.HostsFiles.Tests.
  • Tests: IPv6; comments; an invalid name; a zone-index address skipped; a directory read in name order; ExpandDomain; the same name in two files gives both addresses; a rewritten file reloads within one poll interval (temp folder, short interval); an unreadable file keeps its previous entries and reports an error; caps; the defaults are an empty list and 60 s.
  • ENVIRONMENT.md and the registry updated; dotnet test src/dotnet/tests/Ninlil.Web.Tests --filter FullyQualifiedName~EnvironmentVariable passes.
  • Gate: dotnet test src/dotnet/tests/Ninlil.Dns.Server.HostsFiles.Tests, dotnet test src/dotnet/tests/Ninlil.Web.Tests.

Source

audit-feature-parity.md §2A #15; hosts(5) manual page for the file layout.
Owner decision 2026-10-31: Q-PN-11; round 2 R2-HOSTS-DEF ("empty list by default, 60 s TTL").

- **Draft:** PN-30 - **Priority:** medium - **Agent:** coder - **Depends on:** none - **Decisions:** Q-PN-11, R2-HOSTS-DEF ### Why See #173: the loader is the base the resolver and the API read. ### What changes - New project `src/dotnet/src/Ninlil.Dns.Server.HostsFiles` (packed like its siblings, in `Ninlil.slnx`) with `Extension/ServiceCollectionHostsFilesExtension.cs`, and test project `src/dotnet/tests/Ninlil.Dns.Server.HostsFiles.Tests`. - `HostsFilesOptions` as #173 defines it (empty `Paths`, 60 s TTL). Add it to `src/dotnet/src/Ninlil.Web/EnvironmentVariables/OptionsEnvironmentVariableRegistry.cs`; ENVIRONMENT.md rows for `NINLIL_DNS_SERVER_HOSTS_FILES_EXPAND_DOMAIN`, `..._TIME_TO_LIVE_SECONDS` and `..._POLL_INTERVAL`, a note that `Paths` has no variable, and the totals counted from `OptionsEnvironmentVariableMap.BuildMappings`. - `HostsFileParser`: - one entry per name and address; aliases are names too - names checked with `DnsName` (RFC 1123 §2.1); IPv6 with a zone index (`fe80::1%eth0`) skipped - invalid lines counted, never echoed (a mistaken path such as a password file must not leak its content through the status) - Technical call: no boilerplate-name list. Unlike a block list, an operator's hosts file means what it says; the default empty `Paths` already keeps the system file out. - `HostsFileTable`: immutable, case-insensitive name to addresses lookup, plus address to first name, with the `ExpandDomain` forms. - `HostsFileLoader` (hosted service): load on start, watch plus poll, swap the table atomically, keep the last good entries of an unreadable file. Caps as constants (for example 16 MiB per file, 1,000,000 entries in total) with one warning when hit. It re-reads `Paths` through `IOptionsMonitor`, so a settings change applies without a restart. - `IHostsFileStatusProvider`: per path its kind (file or directory), entries loaded, invalid line count, last load time and last error. - Register in `Program.cs`. Nothing answers queries yet (#175). ### Acceptance - [ ] This test fails first: `Parse_ForALineWithAliases_ReturnsOneEntryPerName` in `src/dotnet/tests/Ninlil.Dns.Server.HostsFiles.Tests`. - [ ] Tests: IPv6; comments; an invalid name; a zone-index address skipped; a directory read in name order; `ExpandDomain`; the same name in two files gives both addresses; a rewritten file reloads within one poll interval (temp folder, short interval); an unreadable file keeps its previous entries and reports an error; caps; the defaults are an empty list and 60 s. - [ ] ENVIRONMENT.md and the registry updated; `dotnet test src/dotnet/tests/Ninlil.Web.Tests --filter FullyQualifiedName~EnvironmentVariable` passes. - [ ] Gate: `dotnet test src/dotnet/tests/Ninlil.Dns.Server.HostsFiles.Tests`, `dotnet test src/dotnet/tests/Ninlil.Web.Tests`. ### Source `audit-feature-parity.md` §2A #15; hosts(5) manual page for the file layout. Owner decision 2026-10-31: Q-PN-11; round 2 R2-HOSTS-DEF ("empty list by default, 60 s TTL").
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#174
No description provided.