diff --git a/backend/src/services/ipsec-server-init-model.test.ts b/backend/src/services/ipsec-server-init-model.test.ts index 510cbf3c..0f43a6dd 100644 --- a/backend/src/services/ipsec-server-init-model.test.ts +++ b/backend/src/services/ipsec-server-init-model.test.ts @@ -84,4 +84,8 @@ for (const path of ipsecExternalPoolDependencyPaths) { const system = structuredClone(projected); system.catalogs["/ip/ipsec/profile"][0].dynamic = "true"; assert.throws(() => planIpsecServerInit(system, server, request)) const unknown = structuredClone(projected); unknown.catalogs["/ip/ipsec/profile"][0].opaque = "changed"; assert.notDeepEqual(ipsecServerInitValue(unknown), ipsecServerInitValue(projected)) const expiry = structuredClone(projected); expiry.catalogs["/certificate"][0]["expires-after"] = "123d"; assert.deepEqual(ipsecServerInitValue(expiry), ipsecServerInitValue(projected)) +// A live router's interface counters move between any two reads; configuration and link state stay sealed. +const traffic = structuredClone(projected); Object.assign(traffic.catalogs["/interface"][0], { "rx-byte": "1", "tx-byte": "2", "fp-rx-packet": "3", "link-downs": "1", "last-link-up-time": "2026-11-21 03:00:00" }) +assert.deepEqual(ipsecServerInitValue(traffic), ipsecServerInitValue(projected)) +for (const [key, changed] of [["disabled", "true"], ["running", "false"], ["mtu", "1400"]]) { const link = structuredClone(projected); link.catalogs["/interface"][0][key] = changed; assert.notDeepEqual(ipsecServerInitValue(link), ipsecServerInitValue(projected)) } console.log("IPsec init model: all REST fields, all raw11 catalogs, NAT egress, owned reuse, foreign/system/dependency denial, ACK-only defaults, new-owned-only sign, full opaque proof") diff --git a/backend/src/services/ipsec-server-init.ts b/backend/src/services/ipsec-server-init.ts index 38677984..052b35f3 100644 --- a/backend/src/services/ipsec-server-init.ts +++ b/backend/src/services/ipsec-server-init.ts @@ -13,8 +13,13 @@ import { captureIpsecSnapshot, mapClients, mapServerSummary, type IpsecServerSta import { ipsecServerInitRequest, planIpsecServerInit, projectIpsecServerInit, validateIpsecServerInitState, type IpsecServerInitState } from "./ipsec-server-init-model.js" import { ipsecExternalPoolDependencyPaths, ipsecPoolDependencies } from "./ipsec-pool-dependencies.js" +// Interface counters and link timestamps change with every packet; sealing them made two reads of a live +// router disagree, so prepare, fence and per-command read-back refused. Configuration and `running` stay sealed. +const interfaceTelemetry = ["rx-byte", "tx-byte", "rx-packet", "tx-packet", "rx-drop", "tx-drop", "tx-queue-drop", "rx-error", "tx-error", + "fp-rx-byte", "fp-tx-byte", "fp-rx-packet", "fp-tx-packet", "link-downs", "last-link-up-time", "last-link-down-time"] export function ipsecServerInitValue(state: IpsecServerInitState) { const value = ipsecPeerDeleteValue(state) + for (const row of value.catalogs["/interface"] ?? []) for (const key of interfaceTelemetry) delete row[key] for (const rows of Object.values(value.catalogs)) for (const row of rows) for (const key of ["disabled", "responder", "template", "nat-traversal", "passive", "trusted"]) { if (row[key] === undefined) continue const boolean = observedBoolean(row[key])