@push.rocks/smartnftables 2.6.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/changelog.md +33 -0
  2. package/dist_rust/smartnftables_linux_amd64_musl +0 -0
  3. package/dist_rust/smartnftables_linux_amd64_musl.tsrust-build.json +5 -5
  4. package/dist_rust/smartnftables_linux_arm64_musl +0 -0
  5. package/dist_rust/smartnftables_linux_arm64_musl.tsrust-build.json +5 -5
  6. package/dist_ts/00_commitinfo_data.js +1 -1
  7. package/dist_ts/classes.manageddockerforwarding.js +3 -4
  8. package/dist_ts/classes.managednftables.d.ts +14 -2
  9. package/dist_ts/classes.managednftables.js +48 -8
  10. package/dist_ts/managed.egress.types.d.ts +25 -3
  11. package/dist_ts/managed.types.d.ts +14 -0
  12. package/package.json +7 -7
  13. package/readme.md +262 -64
  14. package/rust/src/docker.policy.rs +2 -1
  15. package/rust/src/egress.compile.rs +153 -76
  16. package/rust/src/egress.host.rs +24 -51
  17. package/rust/src/egress.hostgrant.rs +1 -1
  18. package/rust/src/egress.keys.rs +305 -0
  19. package/rust/src/egress.leased.rs +399 -0
  20. package/rust/src/egress.private.rs +197 -0
  21. package/rust/src/egress.published.rs +370 -0
  22. package/rust/src/egress.router.rs +61 -294
  23. package/rust/src/egress.rs +140 -19
  24. package/rust/src/egress_hostgrant_tests.rs +158 -20
  25. package/rust/src/egress_localport_tests.rs +11 -2
  26. package/rust/src/egress_publishedrange_tests.rs +812 -0
  27. package/rust/src/egress_routerequivalence_tests.rs +448 -0
  28. package/rust/src/egress_tests.rs +289 -230
  29. package/rust/src/egress_workloadgrant_tests.rs +21 -13
  30. package/rust/src/main.rs +57 -3
  31. package/rust/src/owner.rs +69 -14
  32. package/rust/src/owner_host_traffic_tests.rs +4 -0
  33. package/rust/src/owner_identity_tests.rs +166 -80
  34. package/rust/src/owner_publishedrange_traffic_tests.rs +306 -0
  35. package/rust/src/owner_router_traffic_tests.rs +2 -0
  36. package/rust/src/owner_scale_traffic_tests.rs +383 -0
  37. package/rust/src/owner_tests.rs +6 -0
  38. package/rust/src/policy.rs +30 -29
  39. package/rust/src/tests.rs +100 -0
  40. package/ts/00_commitinfo_data.ts +1 -1
  41. package/ts/classes.manageddockerforwarding.ts +2 -3
  42. package/ts/classes.managednftables.ts +46 -8
  43. package/ts/managed.egress.types.ts +25 -3
  44. package/ts/managed.types.ts +17 -0
package/readme.md CHANGED
@@ -163,7 +163,7 @@ Subscribe to `failureSignal` before starting or admitting policy work, and check
163
163
  exit, ambiguous operation failures, native inspection reporting failed ownership,
164
164
  and unconfirmed cleanup abort the signal once with `ManagedNftablesError` code
165
165
  `OWNER_LOST`. Local input rejection, effect-free native compiler validation and
166
- native `INVALID` responses do not abort it. Other native errors can occur after
166
+ native `INVALID` and `EXHAUSTED` responses do not abort it. Other native errors can occur after
167
167
  kernel effects or ownership loss and conservatively abort it. Successful orderly
168
168
  close, including a cancelled startup, does not signal an unexpected failure;
169
169
  ambiguous mutations still signal loss while close is draining them.
@@ -253,6 +253,62 @@ workload before treating revocation as complete or reusing its addresses and
253
253
  interfaces. Table deletion does not release IP allocation authority or clean up
254
254
  conntrack/NAT state. This restriction also applies to private veth/TUN forwarding.
255
255
 
256
+ ### Refusals: `INVALID` and `EXHAUSTED`
257
+
258
+ Every failure is a `ManagedNftablesError` with a stable `code`. Two codes are
259
+ refusals of the input itself, raised by the facade's capture or by the native owner
260
+ before any kernel work:
261
+
262
+ - `INVALID`: the input is outside the contract (schema, identifiers, addresses,
263
+ overlaps, authority, or a bound of the topology's shape). A smaller policy does
264
+ not help; the input must change.
265
+ - `EXHAUSTED`: the policy is too big for one atomic replacement. It exceeds the
266
+ compiled budget described under the router below, or an input count that exists
267
+ to hold that budget. A smaller policy may fit.
268
+
269
+ Both carry the native refusal text in `reason` (bounded, printable ASCII, never
270
+ policy content) and in the message, `Managed nftables EXHAUSTED: <reason>`.
271
+ `EXHAUSTED` also names its bound in `details`, `{ bound, limit, actual }`:
272
+
273
+ | `bound` | `limit` | Counts |
274
+ | --- | --- | --- |
275
+ | `ruleBytes` | 100,000 | encoded rules, chains and sets of the target |
276
+ | `targetBytes` | 212,000 | the complete target with its set elements |
277
+ | `operations` | 768 | messages of the target |
278
+ | `endpoints` | 32 (v1), 128 (router) | private endpoints |
279
+ | `links` | 128 | router links |
280
+ | `rules` | 128 (v1), 1024 (router) | private directed rules |
281
+ | `grants` | 1024 | router egress grants across every generation |
282
+ | `hostGrants` | 1024 | host grants of one scope |
283
+ | `workloadGrants` | 1024 | router workload grants |
284
+ | `publishedPorts` | 1024 | publications of one scope |
285
+ | `localTcpPortOwners` | 8 | loopback TCP port owners of the pool guard |
286
+ | `restoreRules` | 192 | Docker forwarding contribution rules |
287
+ | `restoreBytes` | 100,000 | Docker forwarding contribution command bytes |
288
+
289
+ `actual` is always above `limit`. It is exact for input counts and for the
290
+ schema-v1 budget, which measures its complete program. For the other compiled
291
+ budgets (`ruleBytes`, `targetBytes`, `operations`, `restoreRules`, `restoreBytes`)
292
+ compilation stops at the first message or rule past the limit, so the complete
293
+ policy needs at least `actual`. Input counts are checked
294
+ before their entries are validated, so a smaller policy can still be `INVALID`.
295
+ Every other bound (identifier and interface-name lengths, source prefixes per
296
+ endpoint, addresses per link, protected prefixes, platform endpoints, active
297
+ generations, handoffs and allocations, ranges per allocation, guarded pools, the
298
+ IPC and capture limits) describes the shape of the topology and stays `INVALID`.
299
+ Other codes, and the facade's own local rejections, carry neither `reason` nor
300
+ `details`. A native refusal outside this shape is `PROTOCOL`.
301
+
302
+ ```typescript
303
+ try {
304
+ prepared = await owner.prepare(policy);
305
+ } catch (error) {
306
+ if (error instanceof ManagedNftablesError && error.code === 'EXHAUSTED' && error.details?.bound === 'publishedPorts') {
307
+ // Publish fewer ports and prepare again.
308
+ } else throw error;
309
+ }
310
+ ```
311
+
256
312
  ### Combined router egress and host transit
257
313
 
258
314
  `ManagedNftables<IManagedNftPolicyV2>` accepts the exported schema-v2 policy.
@@ -264,8 +320,8 @@ allocation-pool guard policy kinds.
264
320
 
265
321
  | V2 scope | Required authority and behavior |
266
322
  | --- | --- |
267
- | `routerEgress` | Private `endpoints` and `rules`, one exact `links` binding per endpoint, a separate veth `handoff`, `protection`, and active `generations`. Private veth/TUN/local DNS and egress share one table so terminal private denial cannot override a separate egress table. Optional `publishedPorts` add the inbound second hop from the handoff to a workload endpoint; both directions are classified into the default conntrack zone ahead of every leased classifier, so a published endpoint port is dedicated to its publication and never becomes leased egress. Optional `hostGrants` forward exact host-origin flows from the handoff to a workload endpoint. Optional `workloadGrants` let one workload open one exact port of another, one way. |
268
- | `hostTransit` | Exact handoff `link`/`allocations` pairs, complete `protection`, an explicit veth or Ethernet `uplink`, and its current `snatAddress`. It checks each handoff's leased source address and protocol/port range, default conntrack zone, direction, uplink, and protected destinations before outer SNAT. Optional `publishedPorts` add inbound uplink destination NAT inside the same generation. Optional `hostGrants` let the host's own address on a handoff dial exact workload ports. Optional `localPlatformEndpoints` serve platform endpoints on the host's own addresses to leased flows. |
323
+ | `routerEgress` | Private `endpoints` and `rules`, one exact `links` binding per endpoint, a separate veth `handoff`, `protection`, and active `generations`. Private veth/TUN/local DNS and egress share one table so terminal private denial cannot override a separate egress table. Optional `publishedPorts` add the inbound second hop from the handoff to a workload endpoint, one port or a port range; both directions are classified into the default conntrack zone ahead of every leased classifier, so a published endpoint port is dedicated to its publication and never becomes leased egress. A `symmetric` publication also lets the workload open flows from its published ports. Optional `hostGrants` forward exact host-origin flows from the handoff to a workload endpoint. Optional `workloadGrants` let one workload open one exact port of another, one way. |
324
+ | `hostTransit` | Exact handoff `link`/`allocations` pairs, complete `protection`, an explicit veth or Ethernet `uplink`, and its current `snatAddress`. It checks each handoff's leased source address and protocol/port range, default conntrack zone, direction, uplink, and protected destinations before outer SNAT. Optional `publishedPorts` add inbound uplink destination NAT inside the same generation, one port or a port range, and a `symmetric` publication also carries the workload's own flows from its published ports out through the uplink. Optional `hostGrants` let the host's own address on a handoff dial exact workload ports. Optional `localPlatformEndpoints` serve platform endpoints on the host's own addresses to leased flows. |
269
325
  | `allocationPoolGuard` | An authenticated `authorityDigest` and complete current allocation-pool `prefixes`. Installs host-wide IPv4 destination denial before any handoff exists, without link, uplink or SNAT dependencies. Optional `hostGrants` are its only exceptions. Optional `localTcpPortOwners` restrict loopback TCP ports to one local user each. |
270
326
 
271
327
  `allocationPoolGuard` accepts 1–64 canonical, disjoint RFC1918 prefixes. Supply
@@ -317,7 +373,8 @@ handoffs, unmatched handoff traffic and IPv6 forwarding are denied.
317
373
 
318
374
  `hostTransit.publishedPorts` is optional. Absent and empty are the same canonical
319
375
  policy, so an unpublished scope keeps its exact previous digest and compiled bytes.
320
- Each entry is `{ protocol, hostPort, targetPort, targetAddress, hostIp }`. `hostIp`
376
+ Each entry is `{ protocol, hostPort, targetPort, targetAddress, hostIp }`, with an
377
+ optional `hostPortEnd` and an optional `symmetric`. `hostIp`
321
378
  must be an exact current uplink address, which rtnetlink verifies at apply, recovery
322
379
  and inspection; there is no wildcard, secondary-link or default-route inference.
323
380
  `targetAddress` must be a current leased `transitSourceAddress` of one allocation,
@@ -328,21 +385,59 @@ including across uplink addresses, and a port published on the `snatAddress` may
328
385
  fall inside any leased outbound source-port range of the same protocol, because outer
329
386
  SNAT translates to that same address.
330
387
 
331
- A publication compiles inside the generation: one destination NAT rule in this
332
- table's own prerouting `nat` chain at priority -100, plus three forward admissions
333
- placed ahead of the capture barrier — original direction NEW and ESTABLISHED, with
334
- opening TCP restricted to SYN with FIN/RST/ACK clear, and the ESTABLISHED reply.
335
- Every admission checks both links, the conntrack protocol, the default zone, the
336
- direction, the translated current address/port and the original conntrack
337
- destination, so foreign NAT cannot borrow the exception for another flow. Published
338
- traffic is not source-translated, so the workload observes the actual client address.
339
- The chain, its translation and its admissions are created, replaced and deleted with
340
- the generation: a target without the entry, a failed batch, or release removes them,
341
- and a caller never needs a separate teardown.
342
-
343
- Input bounds are 64 entries, but the atomic graph reserve binds first. A publication
344
- costs four operations and about 6,000 bytes, so roughly a dozen fit beside a small
345
- host-transit graph and `prepare()` rejects an excessive set before any kernel work.
388
+ `hostPortEnd` publishes the range `hostPort..hostPortEnd`. It must be greater than
389
+ `hostPort`, and `targetPort` must equal `hostPort`: a range keeps every port, so port
390
+ `p` of the uplink reaches port `p` of `targetAddress`. One port has exactly one
391
+ canonical form, without `hostPortEnd`. Ranges follow the same rules as single ports:
392
+ no two publications of one protocol overlap anywhere in the scope, and no published
393
+ port on the `snatAddress` falls inside a leased range. A range translates the
394
+ address only, which never changes a port.
395
+
396
+ Publications are set elements, not rules. The generation compiles CONSTANT named
397
+ sets and maps of concatenated fields in which the port fields are inclusive
398
+ intervals (the kernel's pipapo backend), so one element holds one port or a whole
399
+ range: `published_port` maps a one-port publication's uplink address, protocols and
400
+ port to its target address and port, `published_address` maps a range to its target
401
+ address alone, and `published_forward` holds every publication's inbound tuple. A
402
+ constant number of rules looks them up whatever the number of publications: one
403
+ destination NAT rule per map in this table's own prerouting `nat` chain at priority
404
+ -100, and four forward admissions ahead of the capture barrier — the ESTABLISHED
405
+ original direction, a NEW opening per protocol with opening TCP restricted to SYN
406
+ with FIN/RST/ACK clear, and the ESTABLISHED reply. Every rule checks the uplink, the
407
+ default zone and the direction, and every key carries the exact handoff (index and
408
+ name), the packet and conntrack protocols, the translated current address and port
409
+ and the original conntrack destination, so foreign NAT cannot borrow the exception
410
+ for another flow. Published traffic is not source-translated, so the workload
411
+ observes the actual client address. The chain, its sets, its translations and its
412
+ admissions are created, replaced and deleted with the generation: a target without
413
+ the entry, a failed batch, or release removes them, and a caller never needs a
414
+ separate teardown. Owner verification reads every set back with its description,
415
+ every element with its interval bounds and map data, and every lookup with its
416
+ registers, so apply, inspection, adoption and recovery reject a changed element
417
+ exactly as they reject a changed rule.
418
+
419
+ Without `symmetric`, a publication carries inbound flows only: a flow the workload
420
+ opens from its target address and port toward the uplink is denied. With `symmetric:
421
+ true`, a flow from exactly `targetAddress` and the published target port(s) on the
422
+ exact handoff may leave through the uplink, NEW (a TCP opening only with SYN) or
423
+ ESTABLISHED, with its ESTABLISHED replies, and outer source NAT translates it to
424
+ `hostIp` and the published uplink port. These flows are elements of one more map,
425
+ `published_symmetric`, keyed on the handoff, protocols and the live and original
426
+ source and holding the uplink address and port span; four admissions look it up as a
427
+ set and one postrouting rule translates through it. The workload's outbound flows therefore leave
428
+ from the same address and port its clients reach, as Docker host-mode NAT kept them;
429
+ a range keeps each port unless the host itself already holds that exact tuple on
430
+ `hostIp`. The admissions follow the capture barrier, so every protected current or
431
+ original destination, the platform endpoints included, stays denied. A symmetric
432
+ target port may not fall inside a leased range of `targetAddress`, and may not overlap
433
+ the target ports of another publication of the same address and protocol. Absent and
434
+ `false` are the same canonical policy, digest and compiled graph.
435
+
436
+ Input bounds are 1024 entries. The rule graph does not grow with them: with every
437
+ kind of publication present the host compiles at most eleven rules and four sets,
438
+ about 13,400 bytes of the 100,000-byte rule reserve, and each publication costs
439
+ about 150 to 300 bytes of set elements, which share the target budget described
440
+ under host grants. 64 symmetric ranges take about 19,600 element bytes.
346
441
  The caller still owns the route to `targetAddress` through that handoff, the
347
442
  workload listener, and every other packet owner on the host. As with leased egress,
348
443
  an ACCEPT here cannot override Docker's independent FORWARD DROP; the
@@ -366,7 +461,8 @@ There is no broad ESTABLISHED/RELATED bypass.
366
461
  `routerEgress.publishedPorts` is optional and is the second hop of a published
367
462
  host port. Absent and empty are the same canonical policy, so an unpublished scope
368
463
  keeps its exact previous digest and compiled bytes. Each entry is `{ protocol,
369
- transitPort, endpointPort, endpointAddress, transitSourceAddress }`.
464
+ transitPort, endpointPort, endpointAddress, transitSourceAddress }`, with an
465
+ optional `transitPortEnd` and an optional `symmetric`.
370
466
  `transitSourceAddress` must be a current leased generation address that is present
371
467
  on `handoff`, which rtnetlink verifies at apply, recovery and inspection; the
372
468
  handoff can carry several current leased addresses, so the arrival address is
@@ -379,11 +475,24 @@ published exactly once across the scope, and a published port may not fall insid
379
475
  any leased outbound source-port range of the same protocol on that transit address,
380
476
  because source NAT translates to that same address.
381
477
 
382
- A publication compiles inside the generation: one destination NAT rule in this
383
- table's own prerouting `nat` chain at priority -100, two raw classifications, and
384
- three forward admissions placed ahead of the capture barrier — original direction
385
- NEW and ESTABLISHED, with opening TCP restricted to SYN with FIN/RST/ACK clear,
386
- and the ESTABLISHED reply. The handoff ingress classification precedes the
478
+ `transitPortEnd` publishes the range `transitPort..transitPortEnd`, the second hop of
479
+ a host range. It must be greater than `transitPort`, and `endpointPort` must equal
480
+ `transitPort`, so every port keeps its number on both hops; one port has exactly one
481
+ canonical form, without `transitPortEnd`. No two publications of one protocol overlap
482
+ anywhere in the scope, and no published port falls inside a leased range of its
483
+ transit address. The destination NAT of a range translates the address only.
484
+
485
+ Publications are set elements here too: `published_arrival` (protocol, transit
486
+ address and port), `published_endpoint` (workload link, protocol, address and port,
487
+ the union of every publication's workload ports as disjoint canonical intervals),
488
+ the `published_port` and `published_address` translation maps and
489
+ `published_forward`, with the port fields as inclusive intervals. A constant number
490
+ of rules looks them up whatever the number of publications: one destination NAT
491
+ rule per map in this table's own prerouting `nat` chain at priority -100, two raw
492
+ classifications, and four forward admissions placed ahead of the capture barrier —
493
+ the ESTABLISHED original direction, a NEW opening per protocol with opening TCP
494
+ restricted to SYN with FIN/RST/ACK clear, and the ESTABLISHED reply. The handoff
495
+ ingress classification precedes the
387
496
  barrier's protected-source denial, because the uplink or management network that
388
497
  reaches a published port is itself protected space. The endpoint ingress
389
498
  classification matches the exact workload link, address and published endpoint
@@ -393,24 +502,47 @@ would otherwise carry the workload's published packets into that generation, whe
393
502
  the publication's flow does not exist. Both classifications match the arriving
394
503
  tuple only, set no generation zone and leave the flow in the default conntrack
395
504
  zone. The private anti-spoof guards still run first, and every admission checks
396
- both links, the conntrack protocol, the default zone, the direction, the
397
- translated current address/port and the original conntrack destination.
505
+ the handoff, the default zone and the direction, and looks up the exact workload
506
+ link (index and name), both protocols, the translated current address/port and the
507
+ original conntrack destination.
398
508
 
399
- A published `endpointPort` is therefore dedicated to its publication: a new
509
+ A published endpoint port is therefore dedicated to its publication: a new
400
510
  outbound flow that the workload opens from that exact address and port on that
401
- exact link stays in the default zone too and is not translated by the leased
402
- outbound source NAT. Published traffic is not source-translated on either hop, so
403
- the workload observes the actual client address. The chain, its translation, its
404
- classifications and its admissions are created, replaced and deleted with the
405
- generation: a target without the entry, a failed batch, or release removes them.
406
-
407
- Input bounds are 64 entries, but the atomic graph reserve binds first. A router
408
- publication costs six operations and about 7,600 bytes, so a combined
409
- two-endpoint router policy leaves room for roughly five, and `prepare()` rejects an
410
- excessive set before any kernel work. The caller still owns both hops: the exact
411
- matching `hostTransit` publication, the route to the workload through this router,
412
- the workload listener and every other packet owner. A publication grants no egress;
413
- outbound flows still need their leased grants.
511
+ exact link stays in the default zone too and is never translated by the leased
512
+ outbound source NAT. Without `symmetric` such a flow is denied. Inbound published
513
+ traffic is not source-translated on either hop, so the workload observes the actual
514
+ client address. The chain, its sets, its translations, its classifications and its
515
+ admissions are created, replaced and deleted with the generation: a target without
516
+ the entry, a failed batch, or release removes them.
517
+
518
+ With `symmetric: true` the workload may open flows from exactly `endpointAddress`
519
+ and the published endpoint port(s) on its exact link toward the handoff, NEW (a TCP
520
+ opening only with SYN) or ESTABLISHED, with their ESTABLISHED replies, and source
521
+ NAT translates them to `transitSourceAddress` and the published transit port. With
522
+ the matching symmetric `hostTransit` publication the flow reaches the uplink from
523
+ `hostIp` and the published uplink port, the same address and port its clients
524
+ reach, as Docker host-mode NAT kept it; a range keeps each port unless that exact
525
+ tuple is already taken on the translated address. These flows are elements of the
526
+ `published_symmetric` map, keyed on the workload link, protocols and the live and
527
+ original source and holding the transit address and port span, behind four
528
+ admissions and one postrouting translation. Both directions are already in the
529
+ default zone through the publication's endpoint and handoff classifications, so no
530
+ leased classifier can capture them. The admissions follow the capture barrier, so
531
+ every protected current or original destination, the platform endpoints included,
532
+ stays denied; outbound flows anywhere else still need their leased grants. The
533
+ endpoint ports of a symmetric publication may not overlap the endpoint ports of
534
+ another publication of the same address and protocol, since each flow has exactly
535
+ one published source. Absent and `false` are the same canonical policy, digest and
536
+ compiled graph.
537
+
538
+ Input bounds are 1024 entries. The rule graph does not grow with them: with every
539
+ kind of publication present the router compiles at most thirteen rules and six sets,
540
+ about 15,100 bytes of the 100,000-byte rule reserve, and each publication costs
541
+ about 250 to 450 bytes of set elements, which share the target budget with the
542
+ router's endpoints, rules and grants. 64 symmetric ranges take about 28,000 element
543
+ bytes. The caller still owns both hops: the exact matching `hostTransit`
544
+ publication, the route to the workload through this router, the workload listener
545
+ and every other packet owner.
414
546
 
415
547
  #### Host grants
416
548
 
@@ -466,7 +598,7 @@ foreign set exactly as they reject a changed rule; a bound CONSTANT set also
466
598
  refuses element changes from any other socket.
467
599
 
468
600
  Absent and empty are the same canonical policy, so a scope without grants keeps its
469
- exact previous digest and compiled bytes and has no set. Withdrawing a grant is an
601
+ exact previous digest and compiled bytes and has no host grant set. Withdrawing a grant is an
470
602
  ordinary atomic replacement: the batch deletes the previous rules, chains and sets
471
603
  by handle and creates the complete target, so a target without the entry, a failed
472
604
  batch or release removes it, and an established flow stops with it. Apply grants
@@ -531,9 +663,9 @@ tuple in the CONSTANT set `workload_grant`, so a spoofed, renamed or translated
531
663
  never matches and the destination can never open toward the source. Endpoint prefixes
532
664
  are protected, so both directions stay in the default zone ahead of every leased
533
665
  classifier. Owner verification reads both sets back element by element. Up to 1024
534
- grants fit; the sets share the scope's 100,000-byte element budget with `hostGrants`,
535
- so 1024 of each do not fit together and preparation refuses that before any kernel
536
- work. Absent and empty are the same canonical policy, digest and compiled bytes, and
666
+ grants fit; the sets share the scope's target budget with `hostGrants` and every
667
+ other set, and 1024 of each fit together beside the reference router; a scope
668
+ beyond the budget is refused before any kernel work. Absent and empty are the same canonical policy, digest and compiled bytes, and
537
669
  withdrawal is an ordinary atomic replacement that also stops established flows.
538
670
 
539
671
  These flows need no private `rules`. A private rule is stateless: answering through
@@ -588,13 +720,20 @@ applied, retained, recovered and released with the rest of the guard's table; af
588
720
  a reboot the caller applies its retained intent again, like every other member.
589
721
 
590
722
  Input bounds are 1024 grants per scope, the maximum a network projection carries.
591
- Elements have their own 100,000-byte budget beside the 100,000-byte rule graph, and
592
- are sent 256 to a message. At 1024 grants the reference router needs about 94 KB
593
- of elements (two sets), host transit about 66 KB and the guard about 45 KB. A
594
- replacement batch — handle-only deletion of a previous maximum graph, a maximum
595
- rule graph and maximum elements — stays below 320,000 bytes, which the kernel
596
- accepts with any `net.core.wmem_max` of at least 160,016 (the Linux default is
597
- 212,992). The private facade IPC carries up to three complete policies in one
723
+ Elements are sent 256 to a message. At 1024 grants the reference router needs about
724
+ 98 KB of elements (two sets), host transit about 66 KB and the guard about 45 KB.
725
+
726
+ Every replacement is one nfnetlink batch in one `sendmsg`, and Linux refuses a
727
+ netlink message larger than the socket send buffer: the requested 1 MiB `SO_SNDBUF`
728
+ is clamped to `net.core.wmem_max` and doubled, 425,984 bytes with the Linux default
729
+ of 212,992. That is the hard ceiling. This package bounds a batch at 320,000 bytes,
730
+ which fits every `wmem_max` of at least 160,016, and splits it: at most 64 bytes of
731
+ batch framing, at most 107,520 bytes for the handle-only deletion of the previous
732
+ graph (fewer than 768 rules, chains and sets of at most 140 bytes each), and
733
+ 212,000 bytes for the complete target, of which rules, chains and sets may take at
734
+ most 100,000 and set elements the rest. Scopes that grow with their inputs keep
735
+ those inputs in set elements, so the element share grows where the rule share
736
+ shrinks; `prepare()` refuses a target beyond either bound with `EXHAUSTED` before any kernel work. The private facade IPC carries up to three complete policies in one
598
737
  status and is bounded at 1,048,576 bytes per line; the facade captures at most
599
738
  1,000,000 JSON bytes and 65,536 values per request or result. The caller owns the host route
600
739
  to the workload through the handoff, selecting the transit host address as the
@@ -602,18 +741,56 @@ socket's source, the workload listener and every other packet owner.
602
741
 
603
742
  Active overlapping classifiers, duplicate zones/labels and conflicting handoff
604
743
  allocations reject. Empty router generations retain private routing while denying
605
- egress. Input bounds include 32 private endpoints, 128 private rules, 32 active
606
- generations, 128 total egress grants, 128 protected prefixes, 96 platform endpoints,
607
- 16 ranges per allocation, and 32 host handoffs/active allocations. The complete
608
- compiled graph still must fit 768 operations and 100,000 bytes; cross-products can
609
- reach that limit before individual input limits. Exhausted source-port ranges
610
- drop new flows rather than allocate outside the lease.
611
-
612
- The router compiler shares original-direction connection-state and label checks
613
- per generation and protocol. Each jump still checks the complete current/original
614
- tuple, links, zone and direction; replies and source NAT keep their exact checks.
615
- A combined two-endpoint policy with six private rules, five protected prefixes and
616
- six workload/router grants fits the existing atomic graph limit.
744
+ egress. Router input bounds are 128 private endpoints and links, 1024 private
745
+ rules, 32 active generations and 1024 total egress grants; other bounds include 128
746
+ protected prefixes, 96 platform endpoints, 16 ranges per allocation, and 32 host
747
+ handoffs/active allocations. The complete target must fit the budget above; the
748
+ router's rules grow only with its protected prefixes, so its elements bind first.
749
+ Exhausted source-port ranges drop new flows rather than allocate outside the lease.
750
+
751
+ The router compiles its private endpoints, directed rules and leased grants into
752
+ named sets and maps behind a fixed set of rules, whatever the number of workloads:
753
+ - `private_link` holds every endpoint link (index and name) and the absent
754
+ interface of router-local traffic; `private_index` and `private_name` hold every
755
+ endpoint index and name for the terminal denials, either alone enough to deny;
756
+ `private_source` holds each link index with its source prefixes. The anti-spoof
757
+ guard drops a packet on an endpoint link whose address is not one of its
758
+ prefixes, and anything but IPv4 there.
759
+ - `private_any` and `private_port` hold the directed rules: incoming and outgoing
760
+ link index (0 for the router itself), addresses, and for a transport rule the
761
+ protocol and ports.
762
+ - Per kind (platform ahead of the protected barrier, public behind it) and per
763
+ shape (whether the grant names a source port), `leased_*_zone` maps a workload
764
+ or router flow's link, protocol and tuple to its generation zone before conntrack,
765
+ `leased_*_return` maps a translated return to its zone, and `leased_*_flow` maps
766
+ the link, both protocols, the live and originally tracked tuple and the zone to
767
+ the grant's source NAT; the filter admissions look it up as a set.
768
+ `leased_label` holds each generation's zone and label, and `leased_generation`
769
+ maps a zone to the label a fresh flow receives.
770
+ A key's link index names its link because the rule also finds the interface's
771
+ index and name in `private_link`, whose indices are unique. Every element is
772
+ checked, like every rule, on apply, inspection, adoption and recovery. A decision
773
+ corpus of about 133,000 packets across five router fixtures, frozen from the
774
+ per-rule compiler of 2.6.0, is reproduced exactly by the set-backed compiler.
775
+
776
+ A router of 64 workloads, each with local DNS, public TCP and UDP egress, grants to
777
+ four platform endpoints and one to three publications, compiles about 66,000 rule
778
+ bytes and 105,000 element bytes; 89 such workloads fit the target budget:
779
+
780
+ | Workloads | Router rules | Router elements | Host rules | Host elements |
781
+ | --- | --- | --- | --- | --- |
782
+ | 1 | 65,820 | 4,968 | 42,944 | 1,128 |
783
+ | 8 | 65,820 | 16,056 | 42,944 | 2,528 |
784
+ | 32 | 65,820 | 54,072 | 42,944 | 7,328 |
785
+ | 64 | 65,820 | 104,760 | 42,944 | 13,728 |
786
+
787
+ **Upgrading from 2.x:** version 3 changes the compiled identity of every schema-v2
788
+ `routerEgress` table and of every scope with `publishedPorts`, while their policy
789
+ digests stay unchanged. Reconcile or release against such a table applied by 2.x
790
+ returns `Conflict`: the new engine cannot adopt the old graph. Recover and release
791
+ each such table with the exact previous engine and its retained intent and
792
+ receipt, under the same traffic fence as below, before upgrading; tables of other
793
+ scopes and without publications are unchanged.
617
794
 
618
795
  **Upgrading from 1.x:** version 2 changes the compiled identity of schema-v2
619
796
  `routerEgress` tables. Retained router tables and their receipts cannot be adopted
@@ -732,6 +909,27 @@ A client whose source port equals a leased grant's destination port on that gran
732
909
  public address completes the published TCP handshake and receives its UDP reply
733
910
  from the published address, so the leased classifiers of the same generation cannot
734
911
  capture the workload's published packets.
912
+ Published ranges and symmetric publications are qualified across both hops in the
913
+ same topology, with every publication a set element whose kernel dump matches the
914
+ compiled sets and maps: the first, middle and last port of a UDP range reach their listeners
915
+ with the client address preserved and answer from the published address, the ports
916
+ just outside the range stay dark against pre-policy positive controls, symmetric UDP
917
+ from a range port and from the signalling port and symmetric TCP from the signalling
918
+ port reach the uplink peer from the published address with the same port, a later
919
+ request from that peer reaches the workload on the same flow, the plain publication's
920
+ workload port opens nothing, symmetric flows into the protected union stay denied
921
+ against a pre-policy positive control, leased egress keeps its leased range, and the
922
+ range goes dark with release.
923
+ A 64-workload router is qualified in one batch, every workload in its own namespace
924
+ with local DNS, public TCP and UDP egress, four platform endpoints and a
925
+ publication, the first with the SIP shape: the kernel dumps every private, leased
926
+ and published element and the owner verifies it, and on the first, middle and last
927
+ workload local DNS answers, public UDP egress leaves from the leased range, UDP and
928
+ TCP platform endpoints answer through both hops, the publication reaches its
929
+ listener with the client address preserved, and another workload, a protected
930
+ address outside the platform endpoints and an ungranted platform port stay denied
931
+ against pre-policy positive controls, as does another workload's source address.
932
+ The router compiles 82 rules for the 64 workloads.
735
933
  Host grants are qualified across all three tables in the same four-namespace
736
934
  topology with leased public egress on every port of both protocols and 1024 grants
737
935
  in every scope: a member far from the probed tuples passes, the tuple just outside
@@ -129,7 +129,8 @@ impl Prepared {
129
129
  let comment = format!("snftd1:{}:{}:{}:{}",options.owner_id,options.instance_id,self.digest.strip_prefix("sha256:").ok_or(Error::Invalid)?,result.len());
130
130
  args.push(comment.clone());args.extend(["-j","ACCEPT"].map(String::from));
131
131
  bytes += args.iter().map(|arg|arg.len()+1).sum::<usize>()+32;
132
- if result.len() >= 192 || bytes > 100_000 { return Err(Error::Invalid); }
132
+ crate::capacity("restoreRules", 192, result.len() + 1)?;
133
+ crate::capacity("restoreBytes", 100_000, bytes)?;
133
134
  result.push(Rule {comment,args});
134
135
  }
135
136
  }