Generation publication and recovery

Publication #

peios_ntfe_policy_publish(packet, raw, flow, reporting_level) is process context under a mutex. It runs the cross-forest check, then materializes the counter store for the union of every forest's views (The stores) — so a store that cannot be built (allocation, more than eight windows on one table) refuses the generation before anything is swapped. Only then does it advance the generation counter, allocate the new struct peios_ntfe_policy (three opaque forest pointers plus the reporting level) and rcu_assign_pointer() it into place. Hook-path readers dereference it under rcu_read_lock() and never block; they see the old generation or the new one, never a mix. The old policy is released by call_rcu(), and its forests by ntfe_rust_forest_free() in the callback after grace.

Every walk records its outcome: last_ingest_error (0, or the positive errno of the last failed walk) and last_ingest_t_ns, both in the status. A refusal leaves the previous generation active and says so in the kernel log. contexts in the status is the number of interfaces in the active context table.

In the event stream #

NTFE writes its own lifecycle to KMES, origin class KMES_ORIGIN_NTFE (4), beside the reports of The stores. Every publication writes one ntfe.policy.published, after the swap; a refusal writes none. Its payload is one policy map: generation, the generation now in force; generation-previous, the generation of the policy it replaced, 0 for the first since boot; layers, the layers that have a forest, in the order raw-packet, packet, flow, and an empty list for a policy of no forests; and report-threshold and report-threshold-previous, the new and the replaced CurrentReportingLevel, the latter 1 when nothing was replaced. A walk whose digest is unchanged publishes nothing, and so writes nothing. A context-table change advances the generation without a policy and writes no ntfe.policy.published either, so the generations between two of these events are the earlier policy under a changed context.

A refused rules walk writes one ntfe.policy.rejected. Its policy map holds the generation still in force and previous-retained, always true. Its outcome map holds errno, the walk's negative errno, and reason. When the refusal is in, or names, one rule, a rule map follows. It holds layer when the refusal arose building one layer's forest, and action-error for a bad-action. It holds name, the rule's path relative to its layer key; a path longer than 255 bytes is cut at a character boundary, with name-truncated.

The errno is the walk's, unchanged. The reason is new: the bridge's ntfe_rust_builder_build_why() and ntfe_rust_forests_check_why() fill a struct peios_ntfe_build_why from pnp-core's BuildError. A builder refusal keeps its own name and its rule's path, such as unknown-fact, bad-action with its action error, bad-priority, or tag-downward-read from the cross-forest checks, which name the rule but no layer. The walk names the refusals it makes itself:

  • rule-too-deep and too-many-rules, with -E2BIG;
  • bad-value-type, bad-value-length and not-utf8, in the rule that holds the value;
  • bad-reporting-level, counter-store-refused and out-of-memory;
  • registry-read-failed for a source round trip that failed.

A walk that finds no Rules key writes the event too, with reason no-rules-key, no errno and no rule.

Every walk re-reads the policy, including the walks netd's inventory writes cause, so a broken policy is refused again and again until it is fixed. The event is written once per distinct refusal: a walk whose digest, errno and reason equal those of the last refusal written writes none. A walk the rules stage accepts, published or unchanged, clears that memory, so the next refusal is written whatever it is. A missing Rules key is therefore written once each time the key goes missing. The kernel log line is written for every refusal, as before, and now names the reason. Both events are built on the stack in process context, under the publication mutex or the walk mutex; neither is ever written from the packet path.

In force #

A registry write that has returned is delivered, not enforced: the walk that reads it runs after the debounce. Two status counters say which a writer is looking at. changes_noted is incremented by peios_ntfe_network_registry_changed() for every watch event, and LCS delivers its internal watches inside the write that caused them, after the commit and before the syscall returns, so a writer that reads the status after its write sees its own change counted. The deferred work reads changes_noted under the same lock that clears the pending flag, before it walks, and stores that value in changes_walked when the walk returns, whether it published or was refused.

So a writer is in force once changes_walked reaches the changes_noted it read after writing: the walk that satisfied it started after the write committed. A change that lands mid-walk raises changes_noted again and re-arms the work, so the pair stays unequal until a later walk covers it. A refused walk still advances changes_walked; the writer then reads last_ingest_error to learn that what it wrote is not what is enforced. The walk records its error before it stores changes_walked, and the status reads them in the other order, so a status that shows a change walked shows that walk's error or a later one's, never an older one. The bootstrap walk is not a noted change and moves neither counter. net policy wait is this loop.

Generation 0 #

Until the first successful ingestion there is no policy at all, and every layer is permissive: judged stays 0, permissive counts traversals, no events are emitted (there is no decision to attribute), and the status reports enforcing = 0. The init log line says it plainly. This is the ratified loud default — the alternative, a compiled-in policy the registry cannot see, was rejected.

A new generation does not touch the flows: every sentence written under the old one is stale by generation and is re-judged on its flow's next packet (The Flow layer). That is how a policy change — and a context change, which advances the same counter — reaches running connections without a walk of the conntrack table.

Edit this page