490 lines
48 KiB
TypeScript
490 lines
48 KiB
TypeScript
import { noteVrfTransitionRefusal, withVrfTransitionSection, type VrfTransitionGuard } from "./vrf-transition-refusal.js"
|
|
import { isIP } from "node:net"
|
|
import { isDeepStrictEqual } from "node:util"
|
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto"
|
|
import { inspectVrfProductionAdmission, VRF_PRODUCTION_REQUIRED_CATALOGS, type VrfProductionAdmission, type VrfProductionBinding, type VrfProductionRequest, type VrfProductionRow, type VrfProductionSnapshot } from "./vrf-production-admission.js"
|
|
import { isVrfProductionTelemetryValue, vrfProductionConfiguration, vrfProductionConfigurationV2 } from "./vrf-production-projection.js"
|
|
|
|
type Row = VrfProductionRow
|
|
export interface VrfProductionTransitionCheckpoint { readonly kind: "vrf-production-transition-checkpoint-v1" }
|
|
interface SnapshotProof { kind: "configuration-sha256-v1" | "configuration-sha256-v2"; serverId: number; sourceProof: string; catalogDigests: Record<string, string> }
|
|
interface CausalProvenance { inactiveCycle?: Row; missingMembers: Row[]; greMembers?: Row[] }
|
|
interface History { snapshot: VrfProductionSnapshot | SnapshotProof; vrfId: string; activeVirtual?: Row; dormantTable?: Row; absentLl: Array<{ address: Row; route: Row; member: string }>; provenance: CausalProvenance }
|
|
const histories = new WeakMap<VrfProductionTransitionCheckpoint, History>()
|
|
export interface VrfProductionCheckpointScope { serverId: number; sourceProof: string; actorId: string; nativeId: string }
|
|
const checkpointPurpose = "mmapp-vrf-production-transition-history-v1\0"
|
|
// Full raw reads already have a 32MiB bound. The durable history contains only
|
|
// provenance subsets plus a constant-size whole-configuration digest; allow the
|
|
// JSON envelope/escaping without imposing a smaller post-ACK catalog limit.
|
|
const maxCheckpointBytes = 64 * 1024 * 1024
|
|
|
|
/** Private durable provenance, stored only inside the existing encrypted
|
|
* operation checkpoint after its exact generic VERIFIED receipt. No write
|
|
* authority is minted, and the next transition still matches the full before. */
|
|
export function sealVrfProductionTransitionCheckpoint(checkpoint: VrfProductionTransitionCheckpoint, scope: VrfProductionCheckpointScope, secret: Uint8Array): string {
|
|
const history = histories.get(checkpoint)
|
|
must(history && history.vrfId === scope.nativeId && history.snapshot.serverId === scope.serverId && history.snapshot.sourceProof === scope.sourceProof && scope.actorId.length > 0 && secret.byteLength >= 32, "checkpoint scope")
|
|
const durable = { ...history, snapshot: "projection" in history.snapshot ? snapshotProof(history.snapshot) : history.snapshot }
|
|
// Re-sealing legacy history cannot mint the missing GRE witnesses.
|
|
const text = JSON.stringify({ version: history.provenance.greMembers === undefined ? 1 : 2, scope, history: durable })
|
|
must(Buffer.byteLength(text) <= maxCheckpointBytes, "private checkpoint budget")
|
|
const payload = Buffer.from(text).toString("base64url")
|
|
return payload + "." + createHmac("sha256", secret).update(checkpointPurpose).update(payload).digest("hex")
|
|
}
|
|
export function openVrfProductionTransitionCheckpoint(sealed: string, scope: VrfProductionCheckpointScope, secret: Uint8Array): VrfProductionTransitionCheckpoint {
|
|
must(typeof sealed === "string" && sealed.length <= maxCheckpointBytes * 2 && secret.byteLength >= 32, "private checkpoint budget/key")
|
|
const parts = sealed.split(".")
|
|
must(parts.length === 2 && /^[A-Za-z0-9_-]+$/.test(parts[0]) && /^[a-f0-9]{64}$/.test(parts[1]), "private checkpoint encoding")
|
|
const expected = createHmac("sha256", secret).update(checkpointPurpose).update(parts[0]).digest()
|
|
must(timingSafeEqual(expected, Buffer.from(parts[1], "hex")), "private checkpoint signature")
|
|
const bytes = Buffer.from(parts[0], "base64url"); must(bytes.byteLength <= maxCheckpointBytes, "private checkpoint budget")
|
|
const value = JSON.parse(bytes.toString("utf8")) as { version: number; scope: VrfProductionCheckpointScope; history: History }
|
|
must([1, 2].includes(value.version) && isDeepStrictEqual(value.scope, scope) && value.history?.vrfId === scope.nativeId, "private checkpoint scope/version")
|
|
const proof = value.history.snapshot as SnapshotProof
|
|
must(["configuration-sha256-v1", "configuration-sha256-v2"].includes(proof?.kind) && proof.catalogDigests && VRF_PRODUCTION_REQUIRED_CATALOGS.every(key => Object.hasOwn(proof.catalogDigests, key)) && Object.values(proof.catalogDigests).every(digest => /^[a-f0-9]{64}$/.test(digest)) && proof.serverId === scope.serverId && proof.sourceProof === scope.sourceProof && Array.isArray(value.history.absentLl) && Array.isArray(value.history.provenance?.missingMembers), "private checkpoint source/history")
|
|
must(value.version === 2 ? Array.isArray(value.history.provenance.greMembers) : !value.history.provenance.missingMembers.some(row => row.type === "gre-tunnel" && !Object.hasOwn(row, "mac-address")), "incomplete legacy GRE provenance")
|
|
const checkpoint: VrfProductionTransitionCheckpoint = Object.freeze({ kind: "vrf-production-transition-checkpoint-v1" })
|
|
histories.set(checkpoint, structuredClone(value.history))
|
|
return checkpoint
|
|
}
|
|
export function assertVrfProductionTransitionCheckpoint(checkpoint: VrfProductionTransitionCheckpoint, before: VrfProductionSnapshot): void {
|
|
const history = histories.get(checkpoint)
|
|
must(history, "unknown private checkpoint")
|
|
snapshotSame(history.snapshot, before)
|
|
}
|
|
export function vrfProductionCheckpointCatalogs(checkpoint: VrfProductionTransitionCheckpoint): string[] {
|
|
const history = histories.get(checkpoint); must(history, "unknown private checkpoint")
|
|
return Object.keys("projection" in history.snapshot ? history.snapshot.catalogs : history.snapshot.catalogDigests)
|
|
}
|
|
const cycleFields = [".id", "id", "type", "vrf", "disabled", "link-downs", "last-link-up-time", "last-link-down-time"]
|
|
function witness(row: Row, fields: readonly string[]): Row { return Object.fromEntries(Object.entries(row).filter(([field]) => fields.includes(field))) }
|
|
function memberWitness(row: Row, snapshot: VrfProductionSnapshot): Row {
|
|
const result = witness(row, [".id", "name", "type", "mac-address"])
|
|
if (typeof result["mac-address"] === "string") result["mac-address"] = result["mac-address"].toLowerCase()
|
|
if (row.type === "gre-tunnel" && !Object.hasOwn(row, "mac-address")) result.greParent = greParent(snapshot, row)
|
|
return result
|
|
}
|
|
/** Prior history is causal provenance, not a lease on the router's complete
|
|
* configuration. The fresh approved ticket fences ALL current dependencies. */
|
|
export function assertVrfProductionHistoryProvenance(checkpoint: VrfProductionTransitionCheckpoint, before: VrfProductionSnapshot): void {
|
|
const history = histories.get(checkpoint); must(history, "unknown private checkpoint")
|
|
must(history.snapshot.serverId === before.serverId && history.snapshot.sourceProof === before.sourceProof, "history source changed")
|
|
const target = before.catalogs.vrf.find(row => row[".id"] === history.vrfId)
|
|
must(history.provenance.greMembers !== undefined || !before.catalogs.interface_inventory.some(row => row.type === "gre-tunnel" && !Object.hasOwn(row, "mac-address") && target && members(target.interfaces).includes(String(row.name))), "incomplete legacy GRE provenance")
|
|
for (const expected of history.provenance.greMembers ?? []) {
|
|
const member = before.catalogs.interface_inventory.find(row => row[".id"] === expected[".id"])
|
|
must(member && isDeepStrictEqual(memberWitness(member, before), expected), "GRE causal parent/endpoint changed")
|
|
}
|
|
if (history.provenance.inactiveCycle) {
|
|
const cycle = history.provenance.inactiveCycle, virtual = before.catalogs.interface_inventory.find(row => row[".id"] === cycle[".id"])
|
|
must(target && yes(target.disabled) && virtual && virtual.name === target.name, "inactive causal identity/context changed")
|
|
inactiveVirtual(virtual)
|
|
must(isDeepStrictEqual(witness(virtual, cycleFields), cycle) && !before.catalogs.routing_table.some(row => row[".id"] === history.vrfId), "inactive causal cycle/table absence changed")
|
|
}
|
|
must(history.provenance.missingMembers.length === new Set(history.absentLl.map(item => item.member)).size, "missing LL causal witnesses")
|
|
for (const expected of history.provenance.missingMembers) {
|
|
const member = before.catalogs.interface_inventory.find(row => row[".id"] === expected[".id"])
|
|
must(target && no(target.disabled) && member && isDeepStrictEqual(memberWitness(member, before), expected) && member.vrf === target.name && context(before.catalogs.vrf, String(member.name)) === target.name, "missing LL member causal identity/MAC/context changed")
|
|
must(!addressSources(before, [String(member.name)]).some(source => source.ll), "historical LL absence changed")
|
|
}
|
|
}
|
|
const yes = (value: unknown) => [true, "true", "yes"].includes(value as string | boolean)
|
|
const no = (value: unknown) => [false, "false", "no"].includes(value as string | boolean)
|
|
function must(value: unknown, reason: string, guard?: VrfTransitionGuard): asserts value {
|
|
if (!value) {
|
|
const error = Error(`VRF production transition refused: ${reason}`)
|
|
noteVrfTransitionRefusal(error, reason, guard)
|
|
throw error
|
|
}
|
|
}
|
|
function nativeId(value: unknown): string { must(typeof value === "string" && /^\*[a-f0-9]+$/i.test(value), "native ID"); return value.slice(1).replace(/^0+/, "").toLowerCase() || "0" }
|
|
const projected = vrfProductionConfiguration
|
|
function same(resource: string, old: Row, current: Row, omit: readonly string[] = []): void { must(isDeepStrictEqual(projected(resource, old, omit), projected(resource, current, omit)), "opaque configuration drift") }
|
|
function valid(snapshot: VrfProductionSnapshot): void {
|
|
must(snapshot.projection === "raw-native-v1" && snapshot.catalogs && VRF_PRODUCTION_REQUIRED_CATALOGS.every(key => Object.hasOwn(snapshot.catalogs, key)), "complete raw17 snapshot")
|
|
const json = (value: unknown, depth = 0): void => {
|
|
must(depth <= 24, "JSON nesting budget")
|
|
if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) return
|
|
must(value && typeof value === "object" && (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype), "non-JSON raw value")
|
|
for (const child of Object.values(value)) json(child, depth + 1)
|
|
}
|
|
let bytes = 0
|
|
for (const [resource, rows] of Object.entries(snapshot.catalogs)) {
|
|
must(Array.isArray(rows) && rows.length < 50000, "catalog budget")
|
|
const ids = new Set<string>()
|
|
if (["ip_settings", "ipv6_settings"].includes(resource)) must(rows.length === 1, "singleton cardinality")
|
|
for (const row of rows) {
|
|
must(row && typeof row === "object" && !Array.isArray(row), "native row")
|
|
json(row)
|
|
if (["ip_settings", "ipv6_settings"].includes(resource)) continue
|
|
const id = nativeId(row[".id"]); must(!ids.has(id), "ambiguous ID aliases"); ids.add(id)
|
|
}
|
|
bytes += Buffer.byteLength(JSON.stringify(rows)); must(bytes < 32 * 1024 * 1024, "raw byte budget")
|
|
}
|
|
}
|
|
function snapshotProof(snapshot: VrfProductionSnapshot, kind: SnapshotProof["kind"] = "configuration-sha256-v2"): SnapshotProof {
|
|
let hash = createHash("sha256")
|
|
const feed = (value: unknown): void => {
|
|
if (Array.isArray(value)) { hash.update("["); for (const child of value) { feed(child); hash.update(",") } hash.update("]"); return }
|
|
if (value && typeof value === "object") { hash.update("{"); for (const [key, child] of Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) { hash.update(JSON.stringify(key)).update(":"); feed(child); hash.update(",") } hash.update("}"); return }
|
|
hash.update(JSON.stringify(value))
|
|
}
|
|
const catalogDigests: Record<string, string> = {}
|
|
const projection = kind === "configuration-sha256-v1" ? vrfProductionConfigurationV2 : projected
|
|
const domain = kind === "configuration-sha256-v1" ? "mmapp-vrf-production-full-catalog-v1\0" : "mmapp-vrf-production-full-catalog-v2\0"
|
|
for (const resource of Object.keys(snapshot.catalogs).sort()) { hash = createHash("sha256").update(domain); feed(resource); feed(snapshot.catalogs[resource].map(row => projection(resource, row))); catalogDigests[resource] = hash.digest("hex") }
|
|
return { kind, serverId: snapshot.serverId, sourceProof: snapshot.sourceProof, catalogDigests }
|
|
}
|
|
function snapshotSame(old: VrfProductionSnapshot | SnapshotProof, current: VrfProductionSnapshot): void {
|
|
if (!("projection" in old)) { const next = snapshotProof(current, old.kind); must(old.serverId === next.serverId && old.sourceProof === next.sourceProof && Object.entries(old.catalogDigests).every(([resource, digest]) => next.catalogDigests[resource] === digest), "checkpoint parent/configuration/order drift"); return }
|
|
snapshotSame(snapshotProof(old), current)
|
|
}
|
|
function members(value: unknown): string[] {
|
|
must(typeof value === "string", "unknown member selector")
|
|
if (value === "none" || value === "") return []
|
|
const names = value.split(",")
|
|
must(names.every(name => name.trim() === name && name.length > 0 && !["all", "none", "dynamic"].includes(name)) && new Set(names).size === names.length, "ambiguous members")
|
|
return names
|
|
}
|
|
/** Strict full-prefix parser; arbitrary static prefixes, no fixture address space. */
|
|
function prefix(raw: unknown, family: 4 | 6): { network: string; host: string; length: number } {
|
|
must(typeof raw === "string" && !/[\s%@.]/.test(family === 6 ? raw : raw.replaceAll(".", "")), "address context")
|
|
const parts = raw.split("/"); must(parts.length === 2 && /^(0|[1-9]\d{0,2})$/.test(parts[1]) && isIP(parts[0]) === family, "CIDR")
|
|
const bits = family === 4 ? 32 : 128, length = Number(parts[1]); must(length <= bits, "prefix length")
|
|
let host = 0n
|
|
if (family === 4) for (const octet of parts[0].split(".")) host = host << 8n | BigInt(octet)
|
|
else {
|
|
const halves = parts[0].split("::"), left = halves[0] ? halves[0].split(":") : [], right = halves[1] ? halves[1].split(":") : []
|
|
const words = halves.length === 1 ? left : [...left, ...Array<string>(8 - left.length - right.length).fill("0"), ...right]
|
|
must(words.length === 8, "IPv6 words"); for (const word of words) host = host << 16n | BigInt(parseInt(word, 16))
|
|
must(host >> 32n !== 0xffffn, "mapped IPv6 alias")
|
|
}
|
|
const network = host >> BigInt(bits - length) << BigInt(bits - length)
|
|
return { network: `${family}:${network.toString(16)}/${length}`, host: parts[0], length }
|
|
}
|
|
function context(vrfs: Row[], name: string): string {
|
|
for (const vrf of vrfs) {
|
|
must(typeof vrf.name === "string" && (yes(vrf.disabled) || no(vrf.disabled)), "VRF identity/enabled state")
|
|
if (vrf.name === "main") { must(vrf.interfaces === "all" && no(vrf.disabled), "main VRF shape"); return "main" }
|
|
if (no(vrf.disabled) && members(vrf.interfaces).includes(name)) return vrf.name
|
|
}
|
|
const error = Error("VRF production transition refused: missing ordered main VRF")
|
|
noteVrfTransitionRefusal(error, "missing ordered main VRF")
|
|
throw error
|
|
}
|
|
function eui64(row: Row, inventory: Row): void {
|
|
must(yes(row.dynamic) && yes(row["auto-link-local"]) && yes(row["link-local"]) && row.vrf === "main" && typeof inventory["mac-address"] === "string" && /^(?:[a-f0-9]{2}:){5}[a-f0-9]{2}$/i.test(inventory["mac-address"]), "link-local parent flags/MAC")
|
|
const mac = inventory["mac-address"].split(":").map(word => parseInt(word, 16)), bytes = [mac[0] ^ 2, mac[1], mac[2], 255, 254, mac[3], mac[4], mac[5]], words = ["fe80", "0", "0", "0", ...[0, 2, 4, 6].map(index => (bytes[index] * 256 + bytes[index + 1]).toString(16))]
|
|
must(prefix(row.address, 6).length === 64 && prefix(row.address, 6).host && prefix(`${words.join(":")}/128`, 6).network === prefix(`${String(row.address).split("/")[0]}/128`, 6).network, "EUI64 link-local address")
|
|
}
|
|
/** Bounded observed RouterOS IPv4 GRE auto-LL form, verified on four native
|
|
* GREs in the V29 capture. This is not a general IPv6 or tunnel derivation.
|
|
* The current concrete GRE and its explicit source parent remain mandatory. */
|
|
function greParent(snapshot: VrfProductionSnapshot, inventory: Row): Row {
|
|
must(inventory.type === "gre-tunnel" && !Object.hasOwn(inventory, "mac-address"), "GRE native no-MAC parent")
|
|
const rows = snapshot.catalogs.gre?.filter(row => row.name === inventory.name) ?? []
|
|
must(rows.length === 1, "GRE exact concrete parent")
|
|
const config = rows[0]; nativeId(config[".id"]); nativeId(inventory[".id"])
|
|
const unicast4 = (value: unknown): value is string => typeof value === "string" && isIP(value) === 4 && Number(value.split(".")[0]) > 0 && Number(value.split(".")[0]) < 224 && value !== "255.255.255.255"
|
|
must(unicast4(config["local-address"]) && unicast4(config["remote-address"]), "GRE explicit IPv4 endpoints")
|
|
const sources = snapshot.catalogs.ipv4_address.filter(row => typeof row.address === "string" && row.address.split("/")[0] === config["local-address"])
|
|
must(sources.length === 1 && no(sources[0].dynamic) && no(sources[0].disabled), "GRE exact static source")
|
|
const roots = snapshot.catalogs.interface_inventory.filter(row => row.name === sources[0].interface)
|
|
must(roots.length === 1 && roots[0][".id"] !== inventory[".id"], "GRE exact source parent")
|
|
const resources: Record<string, string> = { ether: "ethernet", ethernet: "ethernet", bridge: "bridge", vlan: "vlan", wg: "wireguard", wireguard: "wireguard", "gre-tunnel": "gre", "ipip-tunnel": "ipip", "eoip-tunnel": "eoip", vxlan: "vxlan", bond: "bonding", bonding: "bonding", "pppoe-out": "pppoe_client" }
|
|
const resource = resources[String(roots[0].type)], configs = resource ? snapshot.catalogs[resource]?.filter(row => row.name === roots[0].name) ?? [] : []
|
|
must(configs.length === 1, "GRE concrete source parent")
|
|
nativeId(roots[0][".id"]); nativeId(configs[0][".id"])
|
|
// Durable causal history needs identity/endpoints, not opaque configuration
|
|
// or optional GRE secrets. Fresh admission/current reconciliation still fence
|
|
// the complete configuration separately.
|
|
return { configuration: witness(config, [".id", "name", "local-address", "remote-address"]), sourceAddress: witness(sources[0], [".id", "address", "interface", "actual-interface", "dynamic", "disabled", "vrf"]), sourceInventory: witness(roots[0], [".id", "name", "type", "mac-address"]), sourceConfiguration: witness(configs[0], [".id", "name"]), sourceResource: resource }
|
|
}
|
|
function nativeLinkLocal(snapshot: VrfProductionSnapshot, row: Row, inventory: Row): void {
|
|
if (inventory.type !== "gre-tunnel" || Object.hasOwn(inventory, "mac-address")) { eui64(row, inventory); return }
|
|
const parent = greParent(snapshot, inventory), config = parent.configuration as Row
|
|
must(yes(row.dynamic) && yes(row["auto-link-local"]) && yes(row["link-local"]) && no(row.disabled) && row.interface === inventory.name && row["actual-interface"] === inventory.name && no(row.invalid), "GRE auto-link-local native flags/identity")
|
|
const effectiveContext = context(snapshot.catalogs.vrf, String(inventory.name))
|
|
must(inventory.vrf === effectiveContext, "GRE inventory effective context")
|
|
must(row.vrf === effectiveContext, "GRE link-local effective context")
|
|
const octets = String(config["remote-address"]).split(".").map(Number)
|
|
const expected = `fe80::2:${(octets[0] * 256 + octets[1]).toString(16)}:${(octets[2] * 256 + octets[3]).toString(16)}/64`
|
|
const parsed = prefix(row.address, 6)
|
|
must(parsed.length === 64 && prefix(`${parsed.host}/128`, 6).network === prefix(`${expected.split("/")[0]}/128`, 6).network, "GRE observed remote-bound auto-link-local")
|
|
}
|
|
interface Source { resource: "ipv4_address" | "ipv6_address"; row: Row; member: string; network: string; family: 4 | 6; ll: boolean }
|
|
function addressSources(snapshot: VrfProductionSnapshot, names: string[]): Source[] {
|
|
const result: Source[] = []
|
|
for (const [resource, family] of [["ipv4_address", 4], ["ipv6_address", 6]] as const) for (const row of snapshot.catalogs[resource]) {
|
|
if (!names.includes(String(row.interface))) continue
|
|
const member = String(row.interface), ll = yes(row.dynamic)
|
|
must(no(row.disabled) || row.disabled === undefined && ll, "disabled/unknown selected address unsupported")
|
|
const parsed = prefix(row.address, family)
|
|
if (ll) {
|
|
must(family === 6, "dynamic non-link-local address")
|
|
const inventory = snapshot.catalogs.interface_inventory.filter(item => item.name === member); must(inventory.length === 1, "LL inventory"); nativeLinkLocal(snapshot, row, inventory[0])
|
|
} else must(no(row.dynamic) && row.vrf === context(snapshot.catalogs.vrf, member), "static address provenance/context")
|
|
result.push({ resource, row, member, network: parsed.network, family, ll })
|
|
}
|
|
must(new Set(result.map(source => `${source.member}/${source.network}`)).size === result.length, "ambiguous equal-prefix address sources")
|
|
return result
|
|
}
|
|
function routeFor(row: Row, source: Source, vrfs: Row[]): boolean {
|
|
if (!yes(row.dynamic) || ![row.connect, row.connected].some(yes) && row.protocol !== "connect") return false
|
|
if (["connect", "connected"].some(field => row[field] !== undefined && !yes(row[field])) || row.protocol !== undefined && row.protocol !== "connect") return false
|
|
let network: string; try { network = prefix(row["dst-address"], source.family).network } catch { return false }
|
|
if (network !== source.network) return false
|
|
const table = context(vrfs, source.member), gateway = source.member + (table === "main" ? "" : `@${table}`)
|
|
if (row["routing-table"] !== table || row.gateway !== gateway || row["immediate-gw"] !== source.member || row.interface !== undefined && row.interface !== "" && row.interface !== source.member) return false
|
|
return row["local-address"] === undefined || row["local-address"] === `${String(source.row.address).split("/")[0]}%${gateway}`
|
|
}
|
|
/** A terminal DELETE may remove one proven automatic LL from an unchanged,
|
|
* empty concrete bridge. It creates no revival debt for the deleted target. */
|
|
function deletedBridgeLinkLocal(before: VrfProductionSnapshot, after: VrfProductionSnapshot, old: Row, source: Source, oldRoute: Row, beforeSources: Source[], afterSources: Source[]): void {
|
|
const name = source.member
|
|
must(source.ll && source.family === 6 && no(old.disabled) && members(old.interfaces).includes(name) && context(before.catalogs.vrf, name) === old.name && context(after.catalogs.vrf, name) === "main" && !after.catalogs.vrf.some(row => row[".id"] === old[".id"]), "DELETE bridge LL owned context")
|
|
const parents = [before, after].map(snapshot => snapshot.catalogs.interface_inventory.filter(row => row.name === name))
|
|
must(parents.every(rows => rows.length === 1) && parents.every(rows => rows[0].type === "bridge" && rows[0].disabled === "false" && rows[0].running === "true" && rows[0].dynamic === "false") && parents[0][0][".id"] === parents[1][0][".id"] && parents[0][0]["mac-address"] === parents[1][0]["mac-address"], "DELETE bridge LL concrete parent")
|
|
const parent = parents[0][0], id = parent[".id"]
|
|
for (const snapshot of [before, after]) {
|
|
const bridges = snapshot.catalogs.bridge.filter(row => row.name === name)
|
|
const reference = (value: unknown) => typeof value === "string" && value.split(",").some(item => [name, id].includes(item.trim()))
|
|
must(bridges.length === 1 && bridges[0][".id"] === id && bridges[0].disabled === "false" && bridges[0].dynamic === "false" && bridges[0].running === "true" && bridges[0]["mac-address"] === parent["mac-address"] && !snapshot.catalogs.bridge_port.some(row => reference(row.bridge) || reference(row.interface)) && !snapshot.catalogs.bridge_vlan.some(row => reference(row.bridge) || reference(row.tagged) || reference(row.untagged) || reference(row["current-tagged"]) || reference(row["current-untagged"])) && !(snapshot.catalogs.vlan ?? []).some(row => reference(row.interface)), "DELETE bridge LL empty configuration")
|
|
}
|
|
same("bridge", before.catalogs.bridge.find(row => row.name === name)!, after.catalogs.bridge.find(row => row.name === name)!)
|
|
must(source.row.dynamic === "true" && source.row["auto-link-local"] === "true" && source.row["link-local"] === "true" && source.row.disabled === "false" && source.row.invalid === "false" && source.row.interface === name && source.row["actual-interface"] === name, "DELETE bridge LL automatic provenance")
|
|
eui64(source.row, parent)
|
|
const statics = beforeSources.filter(item => item.member === name && !item.ll)
|
|
must(statics.some(item => item.family === 4) && statics.every(item => afterSources.some(next => next.member === name && next.resource === item.resource && !next.ll && next.row[".id"] === item.row[".id"] && next.network === item.network)) && !afterSources.some(item => item.member === name && item.ll), "DELETE bridge LL static address closure")
|
|
const routeReference = (row: Row) => [row.gateway, row["immediate-gw"], row.interface].some(value => typeof value === "string" && (value === name || value === id || value.startsWith(name + "@") || value.startsWith(String(id) + "@")))
|
|
const linkLocalRoute = (row: Row) => { try { return prefix(row["dst-address"], 6).network === source.network && routeReference(row) } catch { return false } }
|
|
must(before.catalogs.ipv6_route.filter(linkLocalRoute).length === 1 && before.catalogs.ipv6_route.filter(linkLocalRoute)[0] === oldRoute && !after.catalogs.ipv6_route.some(linkLocalRoute), "DELETE bridge LL connected route closure")
|
|
}
|
|
/** Existing object guards must see the exact concrete parent/dependent
|
|
* identities already proved by admission, not a guessed numeric namespace. */
|
|
export function vrfProductionDependencyObjects(snapshot: VrfProductionSnapshot, admission: VrfProductionAdmission): Array<{ kind: string; id: string; serverId: number }> {
|
|
valid(snapshot)
|
|
must(snapshot.serverId === admission.binding.serverId && snapshot.sourceProof === admission.binding.sourceProof, "dependency object source")
|
|
const objects = new Map<string, { kind: string; id: string; serverId: number }>()
|
|
const add = (kind: string, id: unknown) => { nativeId(id); const object = { kind, id: String(id), serverId: snapshot.serverId }; objects.set(`${kind}/${String(id)}`, object) }
|
|
for (const member of admission.members) {
|
|
for (const parent of member.parents) { add(parent.resource, parent.configurationId); add("interface_inventory", parent.id) }
|
|
for (const address of member.addresses) add(address.resource, address.id)
|
|
}
|
|
for (const source of addressSources(snapshot, admission.members.map(member => member.name))) {
|
|
const resource = source.family === 4 ? "ipv4_route" : "ipv6_route"
|
|
const routes = snapshot.catalogs[resource].filter(row => routeFor(row, source, snapshot.catalogs.vrf))
|
|
must(routes.length === 1, "dependency connected route identity")
|
|
add(resource, routes[0][".id"])
|
|
}
|
|
const target = snapshot.catalogs.vrf.find(row => row[".id"] === admission.request.id)
|
|
if (target) {
|
|
for (const row of snapshot.catalogs.routing_table.filter(row => row[".id"] === target[".id"] && row.name === target.name)) add("routing_table", row[".id"])
|
|
for (const row of snapshot.catalogs.interface_inventory.filter(row => row.type === "vrf" && row.name === target.name && row.vrf === "main")) add("interface_inventory", row[".id"])
|
|
}
|
|
return [...objects.values()]
|
|
}
|
|
const timestamp = (value: unknown): value is string => typeof value === "string" && /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/.test(value) && !Number.isNaN(Date.parse(value.replace(" ", "T") + "Z")) && new Date(value.replace(" ", "T") + "Z").toISOString().slice(0, 19).replace("T", " ") === value
|
|
const greMemberChronology = ["link-downs", "last-link-up-time", "last-link-down-time"] as const
|
|
/** One observed no-MAC GRE context-transfer cycle only. No chronology becomes
|
|
* telemetry: unchanged context and every other concrete type remain strict. */
|
|
function memberInventoryOmissions(before: VrfProductionSnapshot, after: VrfProductionSnapshot, name: string, old: Row, current: Row): string[] {
|
|
const omit = ["vrf", "status"]
|
|
if (isDeepStrictEqual(witness(old, greMemberChronology), witness(current, greMemberChronology))) return omit
|
|
const previousContext = context(before.catalogs.vrf, name), nextContext = context(after.catalogs.vrf, name)
|
|
must(old.type === "gre-tunnel" && current.type === "gre-tunnel" && old.name === name && current.name === name && old[".id"] === current[".id"] && !Object.hasOwn(old, "mac-address") && !Object.hasOwn(current, "mac-address") && previousContext !== nextContext && old.vrf === previousContext && current.vrf === nextContext, "bounded GRE cycle member identity/context")
|
|
must(no(old.disabled) && no(current.disabled) && old.running === "true" && current.running === "true", "bounded GRE cycle active state")
|
|
const a = greParent(before, old), b = greParent(after, current)
|
|
const parent = (snapshot: VrfProductionSnapshot, resource: string, id: unknown) => snapshot.catalogs[resource]?.find(row => row[".id"] === id)
|
|
const oldGre = before.catalogs.gre.find(row => row.name === name), newGre = after.catalogs.gre.find(row => row.name === name)
|
|
const resource = String(a.sourceResource)
|
|
const oldRoot = parent(before, resource, (a.sourceConfiguration as Row)[".id"]), newRoot = parent(after, resource, (b.sourceConfiguration as Row)[".id"])
|
|
const oldAddress = parent(before, "ipv4_address", (a.sourceAddress as Row)[".id"]), newAddress = parent(after, "ipv4_address", (b.sourceAddress as Row)[".id"])
|
|
must(isDeepStrictEqual(a, b) && oldGre && newGre && oldRoot && newRoot && oldAddress && newAddress && isDeepStrictEqual(projected("gre", oldGre), projected("gre", newGre)) && isDeepStrictEqual(projected(resource, oldRoot), projected(resource, newRoot)) && isDeepStrictEqual(projected("ipv4_address", oldAddress), projected("ipv4_address", newAddress)), "bounded GRE cycle parent/configuration")
|
|
const oldCount = old["link-downs"], newCount = current["link-downs"]
|
|
// Twenty canonical digits are a local parsing budget, not a native bit-width claim.
|
|
must(typeof oldCount === "string" && /^(0|[1-9]\d{0,19})$/.test(oldCount) && typeof newCount === "string" && /^(0|[1-9]\d{0,19})$/.test(newCount) && BigInt(newCount) === BigInt(oldCount) + 1n, "bounded GRE cycle count")
|
|
const oldUp = old["last-link-up-time"], oldDown = old["last-link-down-time"], newDown = current["last-link-down-time"], newUp = current["last-link-up-time"]
|
|
must(timestamp(oldUp) && (oldDown === undefined || timestamp(oldDown)) && timestamp(newDown) && timestamp(newUp) && (oldDown === undefined || oldDown <= oldUp) && newDown >= oldUp && (oldDown === undefined || newDown >= oldDown) && newDown <= newUp, "bounded GRE cycle chronology")
|
|
return [...omit, ...greMemberChronology]
|
|
}
|
|
function matchesGeneratedVrfIfname(ifname: unknown, vrfId: string): boolean {
|
|
const id = nativeId(vrfId)
|
|
// RouterOS can render the primary VRF ID in lowercase hexadecimal.
|
|
return ifname === `vrf${id}` || ifname === `vrf${BigInt("0x" + id)}`
|
|
}
|
|
function activeVirtual(row: Row, vrfId: string): void {
|
|
const ifname = row.ifname
|
|
const knownIfnameShape = typeof ifname === "string" && (/^vrf\d+$/.test(ifname) || matchesGeneratedVrfIfname(ifname, vrfId))
|
|
must(row.type === "vrf" && row.vrf === "main" && no(row.disabled) && row.running === "true" && row.status === "--LERU--O---------------" && row.flags === " UP RUNNING NOARP MASTER LOWER_UP (0x104c1)" && row["actual-mtu"] === "65536" && row.mtu === "65536" && knownIfnameShape && typeof row.ifindex === "string" && /^[1-9]\d*$/.test(row.ifindex) && typeof row["mac-address"] === "string" && /^(?:[a-f0-9]{2}:){5}[a-f0-9]{2}$/i.test(row["mac-address"]) && (parseInt(row["mac-address"].slice(0, 2), 16) & 3) === 2 && timestamp(row["last-link-up-time"]), "bounded native active virtual shape")
|
|
}
|
|
function inactiveVirtual(row: Row): void {
|
|
must(row.type === "vrf" && row.vrf === "main" && yes(row.disabled) && row.running === "false" && row.status === "------------------------" && row.mtu === "65536" && row["mac-address"] === "00:00:00:00:00:00" && ["ifname", "ifindex", "flags", "actual-mtu"].every(field => !Object.hasOwn(row, field)), "bounded native inactive virtual shape")
|
|
must(row["last-link-down-time"] === undefined || timestamp(row["last-link-down-time"]), "inactive virtual chronology")
|
|
}
|
|
|
|
export interface VrfProductionTransitionInput {
|
|
before: VrfProductionSnapshot; after: VrfProductionSnapshot; binding: VrfProductionBinding; request: VrfProductionRequest; sealed: string; secret: Uint8Array; now: number
|
|
/** Trusted primary ACK identity for CREATE only; classification grants no write. */
|
|
acknowledgedId?: string
|
|
previous?: VrfProductionTransitionCheckpoint
|
|
}
|
|
/** Pure post-ACK classification only. No executor, ownership adoption, network,
|
|
* durable claim, recovery permission, or forwarding attestation is provided. */
|
|
export function classifyVrfProductionTransition(input: VrfProductionTransitionInput): { status: "explained-native-transition"; executionAvailable: false; forwardingVerified: false; checkpoint: VrfProductionTransitionCheckpoint; explainedRows: number } {
|
|
valid(input.before); valid(input.after)
|
|
const before = structuredClone(input.before), after = structuredClone(input.after), request = structuredClone(input.request)
|
|
const admission = inspectVrfProductionAdmission({ snapshot: before, binding: input.binding, request, sealed: input.sealed, secret: input.secret, now: input.now }).admission
|
|
valid(before); valid(after)
|
|
must(before.serverId === after.serverId && before.sourceProof === after.sourceProof && isDeepStrictEqual(Object.keys(before.catalogs).sort(), Object.keys(after.catalogs).sort()), "after source/catalog set changed")
|
|
const history = input.previous ? histories.get(input.previous) : undefined
|
|
if (input.previous) { must(history, "unrecognized serialized checkpoint"); assertVrfProductionHistoryProvenance(input.previous, before) }
|
|
const vrfId = request.action === "create" ? input.acknowledgedId : request.id
|
|
must(typeof vrfId === "string", "missing primary ACK target ID"); nativeId(vrfId)
|
|
if (history) must(history.vrfId === vrfId, "checkpoint target changed")
|
|
const old = before.catalogs.vrf.find(row => row[".id"] === vrfId), current = after.catalogs.vrf.find(row => row[".id"] === vrfId)
|
|
const oldForeign = before.catalogs.vrf.filter(row => row !== old), newForeign = after.catalogs.vrf.filter(row => row !== current)
|
|
must(isDeepStrictEqual(oldForeign.map(row => projected("vrf", row)), newForeign.map(row => projected("vrf", row))), "foreign VRF configuration/order changed")
|
|
if (request.action === "create") {
|
|
must(!old && current && !before.catalogs.vrf.some(row => nativeId(row[".id"]) === nativeId(vrfId)), "CREATE exact new ACK identity")
|
|
must(Object.keys(current).every(field => [".id", "disabled", ...Object.keys(request.fields)].includes(field)) && (yes(request.fields.disabled) ? yes(current.disabled) : no(current.disabled)), "unreviewed CREATE defaults")
|
|
must(after.catalogs.vrf.indexOf(current) + 1 === after.catalogs.vrf.findIndex(row => row[".id"] === request.placeBeforeId), "CREATE exact ordered insertion")
|
|
} else if (request.action === "delete") must(old && !current, "DELETE exact target")
|
|
else { must(old && current && before.catalogs.vrf.indexOf(old) === after.catalogs.vrf.indexOf(current), "PATCH exact target/order"); same("vrf", old, current, Object.keys(request.fields)) }
|
|
if (current) for (const [field, value] of Object.entries(request.fields)) must(current[field] === value, "requested primary field mismatch")
|
|
const names = admission.members.map(member => member.name)
|
|
const oldContext = new Map(names.map(name => [name, context(before.catalogs.vrf, name)])), newContext = new Map(names.map(name => [name, context(after.catalogs.vrf, name)]))
|
|
const changes = names.filter(name => oldContext.get(name) !== newContext.get(name))
|
|
const transfer = request.action === "patch" && request.fields.interfaces !== undefined && old && current && no(old.disabled) && no(current.disabled) && members(old.interfaces).length === 1 && members(current.interfaces).length === 1 && old.interfaces !== current.interfaces && oldContext.get(String(old.interfaces)) === old.name && newContext.get(String(current.interfaces)) === current.name
|
|
const disable = old && current && no(old.disabled) && yes(current.disabled), reenable = old && current && yes(old.disabled) && no(current.disabled)
|
|
if (disable || reenable) must(Object.hasOwn(request.fields, "disabled"), "unrequested enabled transition")
|
|
const exemptBefore = new Map<string, Set<Row>>(), exemptAfter = new Map<string, Set<Row>>()
|
|
const explain = (resource: string, previous: Row | undefined, next: Row | undefined) => { if (previous) { const rows = exemptBefore.get(resource) ?? new Set<Row>(); rows.add(previous); exemptBefore.set(resource, rows) } if (next) { const rows = exemptAfter.get(resource) ?? new Set<Row>(); rows.add(next); exemptAfter.set(resource, rows) } }
|
|
explain("vrf", old, current)
|
|
withVrfTransitionSection("member-inventory", () => {
|
|
for (const name of changes) {
|
|
const a = before.catalogs.interface_inventory.filter(row => row.name === name), b = after.catalogs.interface_inventory.filter(row => row.name === name)
|
|
// The signed admission already resolves exact concrete physical/VLAN/etc
|
|
// configuration IDs and their full parent closure. Moving context may alter
|
|
// only this same inventory identity's VRF marker, never its concrete type.
|
|
must(a.length === 1 && b.length === 1 && a[0].type === b[0].type && a[0][".id"] === b[0][".id"], "member concrete type/parent identity changed")
|
|
must(a[0].vrf === oldContext.get(name) && b[0].vrf === newContext.get(name), "member native VRF context")
|
|
if (a[0].status !== b[0].status) {
|
|
const x = String(a[0].status), y = String(b[0].status)
|
|
must(x.length === 24 && y.length === 24 && x.slice(0, 20) === y.slice(0, 20) && x.slice(21) === y.slice(21) && x[20] === (oldContext.get(name) === "main" ? "-" : "V") && y[20] === (newContext.get(name) === "main" ? "-" : "V"), "member status native shape")
|
|
}
|
|
same("interface_inventory", a[0], b[0], memberInventoryOmissions(before, after, name, a[0], b[0])); explain("interface_inventory", a[0], b[0])
|
|
}
|
|
})
|
|
const beforeSources = withVrfTransitionSection("before-address", () => addressSources(before, names))
|
|
const afterSources = withVrfTransitionSection("after-address", () => addressSources(after, names))
|
|
const absences: History["absentLl"] = []
|
|
const routeResource = (source: Source) => source.family === 4 ? "ipv4_route" : "ipv6_route"
|
|
const route = (snapshot: VrfProductionSnapshot, source: Source): Row => withVrfTransitionSection("connected-route", () => { const matches = snapshot.catalogs[routeResource(source)].filter(row => routeFor(row, source, snapshot.catalogs.vrf)); must(matches.length === 1, "missing/ambiguous proven connected route"); return matches[0] })
|
|
const usedAfter = new Set<Source>()
|
|
for (const source of beforeSources) {
|
|
const successors = afterSources.filter(candidate => candidate.member === source.member && candidate.network === source.network && candidate.ll === source.ll)
|
|
must(successors.length <= 1, "ambiguous address successor")
|
|
const successor = successors[0], oldRoute = route(before, source)
|
|
if (!successor) {
|
|
if (request.action === "delete" && source.ll) {
|
|
withVrfTransitionSection("LL-comparison", () => deletedBridgeLinkLocal(before, after, old!, source, oldRoute, beforeSources, afterSources))
|
|
explain(source.resource, source.row, undefined); explain(routeResource(source), oldRoute, undefined); continue
|
|
}
|
|
must(source.ll && transfer && current!.interfaces === source.member && oldContext.get(source.member) === "main", "address/route absence outside exact acquisition")
|
|
absences.push({ address: structuredClone(source.row), route: structuredClone(oldRoute), member: source.member }); explain(source.resource, source.row, undefined); explain(routeResource(source), oldRoute, undefined); continue
|
|
}
|
|
usedAfter.add(successor)
|
|
const moved = changes.includes(source.member)
|
|
if (source.ll) {
|
|
const concreteNoMacGre = [before, after].every(snapshot => snapshot.catalogs.interface_inventory.some(row => row.name === source.member && row.type === "gre-tunnel" && !Object.hasOwn(row, "mac-address")))
|
|
withVrfTransitionSection("LL-comparison", () => same(source.resource, source.row, successor.row, moved && concreteNoMacGre ? [".id", "vrf"] : [".id"]))
|
|
}
|
|
else { must(source.row[".id"] === successor.row[".id"], "static address identity changed"); same(source.resource, source.row, successor.row, ["vrf"]) }
|
|
const newRoute = route(after, successor)
|
|
must(Object.hasOwn(oldRoute, "local-address") === Object.hasOwn(newRoute, "local-address"), "connected route local-address shape changed")
|
|
const ownedDelete = request.action === "delete" && oldContext.get(source.member) === old!.name
|
|
withVrfTransitionSection("connected-route", () => same(routeResource(source), oldRoute, newRoute, moved ? [".id", "gateway", "immediate-gw", "routing-table", "local-address"] : transfer || ownedDelete ? [".id"] : []))
|
|
if (source.ll && source.row[".id"] !== successor.row[".id"]) must(moved || transfer || ownedDelete, "LL ID changed outside native move")
|
|
explain(source.resource, source.row, successor.row); explain(routeResource(source), oldRoute, newRoute)
|
|
}
|
|
for (const successor of afterSources.filter(source => !usedAfter.has(source))) {
|
|
const missing = history?.absentLl.filter(item => item.member === successor.member) ?? []
|
|
must(request.action === "delete" && successor.ll && missing.length === 1, "new address/route adoption forbidden")
|
|
withVrfTransitionSection("LL-comparison", () => same(successor.resource, missing[0].address, successor.row, [".id"])); const nextRoute = route(after, successor)
|
|
must(Object.hasOwn(missing[0].route, "local-address") === Object.hasOwn(nextRoute, "local-address"), "revived route local-address shape")
|
|
same(routeResource(successor), missing[0].route, nextRoute, [".id", "gateway", "immediate-gw", "routing-table", "local-address"])
|
|
explain(successor.resource, undefined, successor.row); explain(routeResource(successor), undefined, nextRoute)
|
|
}
|
|
for (const missing of history?.absentLl ?? []) if (!afterSources.some(source => source.member === missing.member && source.ll)) { must(request.action !== "delete", "DELETE missing expected LL revival"); absences.push(structuredClone(missing)) }
|
|
let active: Row | undefined, dormant: Row | undefined
|
|
withVrfTransitionSection("virtual", () => {
|
|
for (const resource of ["routing_table", "interface_inventory"]) {
|
|
const find = (snapshot: VrfProductionSnapshot, vrf: Row | undefined): Row | undefined => {
|
|
if (!vrf) return undefined
|
|
const matches = snapshot.catalogs[resource].filter(row => resource === "routing_table" ? row[".id"] === vrfId : row.type === "vrf" && row.name === vrf.name && row.vrf === "main")
|
|
must(matches.length <= 1, "ambiguous target companion"); return matches[0]
|
|
}
|
|
const a = find(before, old), b = find(after, current)
|
|
if (resource === "routing_table") {
|
|
const check = (row: Row | undefined, vrf: Row | undefined) => { if (vrf && no(vrf.disabled)) must(row && row[".id"] === vrfId && row.name === vrf.name && yes(row.dynamic) && row.fib === "" && row.vrf === undefined, "VRF table exact native parent"); else must(!row, "disabled/deleted table unexpectedly present") }
|
|
check(a, old); check(b, current)
|
|
if (a && b) same(resource, a, b, ["name"])
|
|
else if (!old && b) must(Object.keys(b).every(field => isVrfProductionTelemetryValue(resource, field, b[field]) || [".id", "name", "dynamic", "fib"].includes(field)), "new table unknown fields")
|
|
else if (reenable && b) {
|
|
if (history?.dormantTable) same(resource, history.dormantTable, b, ["name"])
|
|
else must(Object.keys(b).every(field => isVrfProductionTelemetryValue(resource, field, b[field]) || [".id", "name", "dynamic", "fib"].includes(field)), "newly enabled table unknown fields")
|
|
}
|
|
else if (disable && a) dormant = structuredClone(a)
|
|
else if (old && current && yes(old.disabled)) dormant = history?.dormantTable
|
|
} else {
|
|
if (old) must(a, "missing prior virtual interface")
|
|
if (current) must(b, "missing resulting virtual interface")
|
|
if (!old && b) {
|
|
const enabled = current && no(current.disabled)
|
|
if (enabled) activeVirtual(b, vrfId); else inactiveVirtual(b)
|
|
must(Object.keys(b).every(field => isVrfProductionTelemetryValue(resource, field, b[field]) || [".id", "caps", "disabled", "flags", "fp-rps-drop", "id", "ifindex", "ifname", "last-link-up-time", "link-downs", "mac-address", "mtu", "name", "status", "type", "vrf"].includes(field)) && b.caps === "" && b["fp-rps-drop"] === "0" && b["link-downs"] === "0" && typeof b.id === "string" && /^\d+$/.test(b.id) && BigInt(b.id) === BigInt("0x" + nativeId(b[".id"])) && (!enabled || matchesGeneratedVrfIfname(b.ifname, vrfId) && after.catalogs.interface_inventory.filter(row => row.ifindex === b.ifindex).length === 1 && after.catalogs.interface_inventory.filter(row => String(row["mac-address"]).toLowerCase() === String(b["mac-address"]).toLowerCase()).length === 1), "new virtual unknown fields/defaults/generated identity")
|
|
if (enabled) active = structuredClone(b)
|
|
} else if (a && b) {
|
|
must(a[".id"] === b[".id"], "virtual interface ID changed")
|
|
if (disable) {
|
|
activeVirtual(a, vrfId)
|
|
must(yes(b.disabled) && b.status === "------------------------" && b["mac-address"] === "00:00:00:00:00:00" && a["link-downs"] === "0" && b["link-downs"] === "1" && a["last-link-down-time"] === undefined && timestamp(b["last-link-down-time"]) && String(b["last-link-down-time"]) >= String(a["last-link-up-time"]) && b.running === "false" && ["ifname", "ifindex", "flags", "actual-mtu"].every(field => !Object.hasOwn(b, field)), "bounded virtual disable shape")
|
|
same(resource, a, b, ["name", "disabled", "status", "mac-address", "link-downs", "last-link-down-time", "ifname", "ifindex", "flags"]); active = structuredClone(a)
|
|
} else if (reenable) {
|
|
inactiveVirtual(a); activeVirtual(b, vrfId)
|
|
const previousIfname = history?.activeVirtual?.ifname
|
|
const sameIfname = previousIfname === undefined ? matchesGeneratedVrfIfname(b.ifname, vrfId) : b.ifname === previousIfname
|
|
must(sameIfname && (a["last-link-down-time"] === undefined || timestamp(a["last-link-down-time"]) && String(b["last-link-up-time"]) >= a["last-link-down-time"]) && after.catalogs.interface_inventory.filter(row => row.ifindex === b.ifindex).length === 1 && after.catalogs.interface_inventory.filter(row => typeof row["mac-address"] === "string" && String(row["mac-address"]).toLowerCase() === String(b["mac-address"]).toLowerCase()).length === 1, "reenable generated identity/chronology")
|
|
same(resource, a, b, ["name", "disabled", "status", "mac-address", "ifname", "ifindex", "flags", "last-link-up-time"]); active = structuredClone(b)
|
|
} else { same(resource, a, b, ["name"]); active = history?.activeVirtual }
|
|
}
|
|
}
|
|
explain(resource, a, b)
|
|
}
|
|
})
|
|
// No explained successor may acquire an ID belonging to a foreign row.
|
|
withVrfTransitionSection("foreign", () => {
|
|
for (const resource of Object.keys(before.catalogs)) {
|
|
const a = exemptBefore.get(resource) ?? new Set<Row>(), b = exemptAfter.get(resource) ?? new Set<Row>()
|
|
const foreignBefore = before.catalogs[resource].filter(row => !a.has(row)), foreignAfter = after.catalogs[resource].filter(row => !b.has(row))
|
|
must(isDeepStrictEqual(foreignBefore.map(row => projected(resource, row)), foreignAfter.map(row => projected(resource, row))), `foreign ${resource} configuration/order changed`, "FOREIGN_CATALOG_CONFIGURATION_ORDER_CHANGED")
|
|
for (const row of b) must(!foreignBefore.some(previous => nativeId(previous[".id"]) === nativeId(row[".id"])), "companion acquired foreign ID")
|
|
}
|
|
})
|
|
const checkpoint: VrfProductionTransitionCheckpoint = Object.freeze({ kind: "vrf-production-transition-checkpoint-v1" })
|
|
const provenance: CausalProvenance = { missingMembers: [...new Set(absences.map(item => item.member))].map(name => {
|
|
const inventory = after.catalogs.interface_inventory.find(row => row.name === name); must(inventory, "missing LL causal member")
|
|
return memberWitness(inventory, after)
|
|
}), greMembers: [...new Set([...names, ...(history?.provenance.greMembers ?? []).map(row => String(row.name))])].flatMap(name => {
|
|
const inventory = after.catalogs.interface_inventory.find(row => row.name === name)
|
|
return inventory?.type === "gre-tunnel" && !Object.hasOwn(inventory, "mac-address") ? [memberWitness(inventory, after)] : []
|
|
}) }
|
|
if (current && yes(current.disabled) && (active || dormant)) {
|
|
const virtual = after.catalogs.interface_inventory.find(row => row.type === "vrf" && row.name === current.name && row.vrf === "main")
|
|
must(virtual, "missing inactive causal virtual"); provenance.inactiveCycle = witness(virtual, cycleFields)
|
|
}
|
|
histories.set(checkpoint, { snapshot: structuredClone(after), vrfId, activeVirtual: active, dormantTable: dormant, absentLl: absences, provenance })
|
|
return { status: "explained-native-transition", executionAvailable: false, forwardingVerified: false, checkpoint, explainedRows: [...exemptAfter.values()].reduce((sum, rows) => sum + rows.size, 0) }
|
|
}
|