From 294ad91085aca612cae2c7e2753b305d47c1ba87 Mon Sep 17 00:00:00 2001 From: Frando Date: Thu, 19 Nov 2026 10:22:57 +0100 Subject: [PATCH 1/5] feat!: mark growable public enums as non_exhaustive These enums hold presets and modes that we expect to extend: `Firewall`, `PortPolicy`, `OutDir`, `Ipv6DadMode`, `Ipv6ProvisioningMode`, `Ipv6Profile`, `Nat`, `NatMapping`, `NatV6Mode`, and `RouterPreset`. A new variant then no longer breaks callers. A `match` on one of them outside patchbay needs a wildcard arm. `LinkDirection`, `NatFiltering`, and `IpSupport` stay exhaustive, because their sets are closed. Co-Authored-By: Claude Opus 5.5 --- patchbay/src/firewall.rs | 2 ++ patchbay/src/lab.rs | 4 ++++ patchbay/src/nat.rs | 3 +++ patchbay/src/router.rs | 1 + 4 files changed, 10 insertions(+) diff --git a/patchbay/src/firewall.rs b/patchbay/src/firewall.rs index f3f4f65..fece409 100644 --- a/patchbay/src/firewall.rs +++ b/patchbay/src/firewall.rs @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize}; /// Use [`Firewall::Custom`] for full control. #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] +#[non_exhaustive] pub enum Firewall { /// No filtering beyond NAT (default). #[default] @@ -58,6 +59,7 @@ pub enum Firewall { /// traversing the router's forward chain. #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] +#[non_exhaustive] pub enum PortPolicy { /// All destination ports are allowed (no filtering). #[default] diff --git a/patchbay/src/lab.rs b/patchbay/src/lab.rs index a11f9ec..c59a2db 100644 --- a/patchbay/src/lab.rs +++ b/patchbay/src/lab.rs @@ -388,6 +388,7 @@ pub struct LabBuilder { /// Where the lab writes event logs and state files. #[derive(Clone, Debug)] +#[non_exhaustive] pub enum OutDir { /// Parent directory — lab creates a timestamped subdirectory inside it. Nested(PathBuf), @@ -398,6 +399,7 @@ pub enum OutDir { /// Controls IPv6 duplicate address detection behavior in created namespaces. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Deserialize)] #[serde(rename_all = "snake_case")] +#[non_exhaustive] pub enum Ipv6DadMode { /// Keep kernel default behavior, DAD enabled. Enabled, @@ -409,6 +411,7 @@ pub enum Ipv6DadMode { /// Controls how IPv6 routes are provisioned for hosts and routers. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Deserialize)] #[serde(rename_all = "snake_case")] +#[non_exhaustive] pub enum Ipv6ProvisioningMode { /// Install routes directly from patchbay wiring logic. #[default] @@ -430,6 +433,7 @@ pub enum Ipv6ProvisioningMode { /// order, or link-local gateway behavior. #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)] #[serde(rename_all = "snake_case")] +#[non_exhaustive] pub enum Ipv6Profile { /// DAD disabled, static route wiring. Fast and reproducible for tests. Deterministic, diff --git a/patchbay/src/nat.rs b/patchbay/src/nat.rs index f5c905a..852bfbf 100644 --- a/patchbay/src/nat.rs +++ b/patchbay/src/nat.rs @@ -44,6 +44,7 @@ use serde::{Deserialize, Serialize}; strum::Display, )] #[serde(rename_all = "kebab-case")] +#[non_exhaustive] pub enum Nat { /// No NAT. The device has a publicly routable address. #[default] @@ -145,6 +146,7 @@ impl From for Option { /// packets. #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] +#[non_exhaustive] pub enum NatMapping { /// Same external port for all destinations. /// @@ -414,6 +416,7 @@ impl NatConfigBuilder { /// IPv6 NAT mode for a router. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] +#[non_exhaustive] pub enum NatV6Mode { /// No translation; devices use global unicast directly. #[default] diff --git a/patchbay/src/router.rs b/patchbay/src/router.rs index e01765e..045c3f9 100644 --- a/patchbay/src/router.rs +++ b/patchbay/src/router.rs @@ -734,6 +734,7 @@ impl Router { /// .build().await?; /// ``` #[derive(Clone, Copy, Debug)] +#[non_exhaustive] pub enum RouterPreset { /// Residential home router. /// From 441fd94a946383d1164397cf43ceb3019e8c8851 Mon Sep 17 00:00:00 2001 From: Frando Date: Thu, 19 Nov 2026 10:23:11 +0100 Subject: [PATCH 2/5] feat!: mark event and state structs as non_exhaustive `LabEvent`, the snapshot and state structs in `event`, and `DefaultRegions` are output types: patchbay builds them and callers read them. A new field then no longer breaks callers. Code outside patchbay can no longer build them with a struct literal, and a pattern needs `..`. Co-Authored-By: Claude Opus 5.5 --- patchbay/src/event.rs | 9 +++++++++ patchbay/src/lab.rs | 1 + 2 files changed, 10 insertions(+) diff --git a/patchbay/src/event.rs b/patchbay/src/event.rs index 61bc33a..0ee3a4b 100644 --- a/patchbay/src/event.rs +++ b/patchbay/src/event.rs @@ -22,6 +22,7 @@ use crate::{ /// A single lab event with global ordering. #[derive(Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] pub struct LabEvent { /// Monotonically increasing operation id. pub opid: u64, @@ -279,6 +280,7 @@ pub enum LabEventKind { /// Snapshot of a device interface at the time of an event. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[non_exhaustive] pub struct IfaceSnapshot { /// Interface name. pub name: String, @@ -301,6 +303,7 @@ pub struct IfaceSnapshot { /// Traffic counters for one interface (from `/proc/net/dev`). #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[non_exhaustive] pub struct IfaceCounters { /// Interface name. pub iface: String, @@ -320,6 +323,7 @@ pub struct IfaceCounters { /// Lab state derived from the event stream. Mirrors the `state.json` schema. #[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[non_exhaustive] pub struct LabState { /// Latest applied opid. pub opid: u64, @@ -346,6 +350,7 @@ pub struct LabState { /// IX state in state.json. #[derive(Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] pub struct IxState { /// Bridge name. pub bridge: String, @@ -361,6 +366,7 @@ pub struct IxState { /// Router state in state.json. #[derive(Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] pub struct RouterState { /// Namespace name. pub ns: String, @@ -406,6 +412,7 @@ pub struct RouterState { /// Device state in state.json. #[derive(Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] pub struct DeviceState { /// Namespace name. pub ns: String, @@ -421,6 +428,7 @@ pub struct DeviceState { /// Region state in state.json. #[derive(Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] pub struct RegionState { /// Router assigned to this region. pub router: String, @@ -428,6 +436,7 @@ pub struct RegionState { /// Inter-region link state. #[derive(Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] pub struct RegionLinkState { /// Router A name. pub a: String, diff --git a/patchbay/src/lab.rs b/patchbay/src/lab.rs index c59a2db..525dfc8 100644 --- a/patchbay/src/lab.rs +++ b/patchbay/src/lab.rs @@ -146,6 +146,7 @@ impl RegionLink { } /// Pre-built regions from [`Lab::add_default_regions`]. +#[non_exhaustive] pub struct DefaultRegions { /// US region (198.18.0.0/20). pub us: Region, From 9b9bfb99fc6d32291e0bc00270265bc3c8f24e95 Mon Sep 17 00:00:00 2001 From: Frando Date: Thu, 19 Nov 2026 10:23:37 +0100 Subject: [PATCH 3/5] feat!: mark input config structs as non_exhaustive `RegionLink`, `FirewallConfig`, and the TOML structs in `config` get new knobs over time. A new field then no longer breaks callers. Code outside patchbay can no longer build them with a struct literal. It starts from a constructor or from `Default` and sets the public fields: `RegionLink::good`, `FirewallConfig::builder`, `LabConfig::default`, `RegionConfig::default`, and the new `RouterConfig::new`. Co-Authored-By: Claude Opus 5.5 --- patchbay-runner/src/sim/topology.rs | 19 ++++--------------- patchbay/src/config.rs | 22 +++++++++++++++++++++- patchbay/src/firewall.rs | 1 + patchbay/src/lab.rs | 1 + 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/patchbay-runner/src/sim/topology.rs b/patchbay-runner/src/sim/topology.rs index 0324431..8849069 100644 --- a/patchbay-runner/src/sim/topology.rs +++ b/patchbay-runner/src/sim/topology.rs @@ -103,27 +103,16 @@ gateway = "r1" #[test] fn rejects_inline_when_topology_ref_set() { - let sim = SimFile { + let mut sim = SimFile { sim: SimMeta { name: "x".into(), topology: Some("a".into()), }, - topology: patchbay::config::LabConfig { - router: vec![patchbay::config::RouterConfig { - name: "r1".into(), - region: None, - upstream: None, - nat: patchbay::Nat::None, - ip_support: patchbay::IpSupport::V4Only, - nat_v6: patchbay::NatV6Mode::None, - ra_enabled: None, - ra_interval_secs: None, - ra_lifetime_secs: None, - }], - ..Default::default() - }, ..Default::default() }; + sim.topology + .router + .push(patchbay::config::RouterConfig::new("r1")); let err = match load_topology(&sim, Path::new("sims/sim.toml")) { Ok(_) => panic!("expected inline-topology rejection"), Err(err) => err, diff --git a/patchbay/src/config.rs b/patchbay/src/config.rs index 972bd78..4b010a8 100644 --- a/patchbay/src/config.rs +++ b/patchbay/src/config.rs @@ -8,6 +8,7 @@ use crate::{IpSupport, Nat, NatV6Mode}; /// Parsed lab configuration from TOML. #[derive(Deserialize, Clone, Default)] +#[non_exhaustive] pub struct LabConfig { /// Optional region-latency map. pub region: Option>, @@ -20,7 +21,8 @@ pub struct LabConfig { } /// Per-region latency configuration. -#[derive(Deserialize, Clone)] +#[derive(Deserialize, Clone, Default)] +#[non_exhaustive] pub struct RegionConfig { /// Map of target-region name to one-way latency in ms. #[serde(default)] @@ -29,6 +31,7 @@ pub struct RegionConfig { /// Router configuration entry. #[derive(Deserialize, Clone)] +#[non_exhaustive] pub struct RouterConfig { /// Router name. pub name: String, @@ -52,3 +55,20 @@ pub struct RouterConfig { /// Optional RA lifetime in seconds. pub ra_lifetime_secs: Option, } + +impl RouterConfig { + /// Creates a router entry named `name` with the defaults of the TOML format. + pub fn new(name: impl Into) -> Self { + Self { + name: name.into(), + region: None, + upstream: None, + nat: Nat::default(), + ip_support: IpSupport::default(), + nat_v6: NatV6Mode::default(), + ra_enabled: None, + ra_interval_secs: None, + ra_lifetime_secs: None, + } + } +} diff --git a/patchbay/src/firewall.rs b/patchbay/src/firewall.rs index fece409..7cc3dc4 100644 --- a/patchbay/src/firewall.rs +++ b/patchbay/src/firewall.rs @@ -82,6 +82,7 @@ pub enum PortPolicy { /// .build(); /// ``` #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] pub struct FirewallConfig { /// Block unsolicited inbound traffic on the WAN interface (RFC 6092). /// When true, only established/related return traffic is allowed inbound. diff --git a/patchbay/src/lab.rs b/patchbay/src/lab.rs index 525dfc8..4c1801f 100644 --- a/patchbay/src/lab.rs +++ b/patchbay/src/lab.rs @@ -112,6 +112,7 @@ impl Region { /// Parameters for an inter-region link passed to [`Lab::link_regions`]. #[derive(Clone, Debug)] +#[non_exhaustive] pub struct RegionLink { /// One-way latency in milliseconds (RTT = 2x). pub latency_ms: u32, From 7aabda527d46b0b51bee9544771fd05ba71e54aa Mon Sep 17 00:00:00 2001 From: Frando Date: Thu, 19 Nov 2026 10:23:50 +0100 Subject: [PATCH 4/5] feat!: make the NodeId value private The docs call `NodeId` opaque, but the public field let callers build arbitrary ids and read the counter behind them. With the field private, the id can change its form without a breaking release. `Display` still prints the number. Co-Authored-By: Claude Opus 5.5 --- patchbay/src/core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patchbay/src/core.rs b/patchbay/src/core.rs index 72ef252..dbf35e6 100644 --- a/patchbay/src/core.rs +++ b/patchbay/src/core.rs @@ -61,7 +61,7 @@ pub(crate) struct CoreConfig { /// Cheaply copyable and usable as a hash-map key. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, derive_more::Display)] #[display("{_0}")] -pub struct NodeId(pub u64); +pub struct NodeId(pub(crate) u64); /// Selects the address pool used for router downstream links. #[derive(Clone, Copy, Debug, PartialEq, Eq)] From 328c8a5a9f390a642c5c1e87ceac6c10761400e5 Mon Sep 17 00:00:00 2001 From: Frando Date: Thu, 19 Nov 2026 10:27:02 +0100 Subject: [PATCH 5/5] feat!: mark the variants of LabEventKind as non_exhaustive The events carry fields that we extend over time. A new field on a variant then no longer breaks callers. A pattern on a variant outside patchbay needs `..`, and code outside patchbay can no longer build an event. Co-Authored-By: Claude Opus 5.5 --- patchbay/src/event.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/patchbay/src/event.rs b/patchbay/src/event.rs index 0ee3a4b..24c9cab 100644 --- a/patchbay/src/event.rs +++ b/patchbay/src/event.rs @@ -41,6 +41,7 @@ pub struct LabEvent { pub enum LabEventKind { // ── Lifecycle ── /// Emitted once during `Lab::new()`. + #[non_exhaustive] LabCreated { /// The lab's process-unique prefix (e.g. `"lab-p12340"`). lab_prefix: String, @@ -48,12 +49,14 @@ pub enum LabEventKind { label: Option, }, /// Full state snapshot, emitted by `Lab::from_config()`. + #[non_exhaustive] InitialState { /// Serialized [`LabState`]. state: serde_json::Value, }, // ── IX ── /// Emitted once during `Lab::new()` after IX bridge creation. + #[non_exhaustive] IxCreated { /// IX bridge name (e.g. `"br-p1230-1"`). bridge: String, @@ -69,6 +72,7 @@ pub enum LabEventKind { // ── Topology ── /// A router was added to the lab. + #[non_exhaustive] RouterAdded { /// Router name. name: String, @@ -77,11 +81,13 @@ pub enum LabEventKind { state: Box, }, /// A router was removed from the lab. + #[non_exhaustive] RouterRemoved { /// Router name. name: String, }, /// A device was added to the lab. + #[non_exhaustive] DeviceAdded { /// Device name. name: String, @@ -90,6 +96,7 @@ pub enum LabEventKind { state: DeviceState, }, /// A device was removed from the lab. + #[non_exhaustive] DeviceRemoved { /// Device name. name: String, @@ -97,6 +104,7 @@ pub enum LabEventKind { // ── Regions ── /// A region was added. + #[non_exhaustive] RegionAdded { /// Region name. name: String, @@ -104,6 +112,7 @@ pub enum LabEventKind { router: String, }, /// An inter-region link was created. + #[non_exhaustive] RegionLinkAdded { /// Router A name. router_a: String, @@ -111,6 +120,7 @@ pub enum LabEventKind { router_b: String, }, /// An inter-region link was broken/impaired. + #[non_exhaustive] RegionLinkBroken { /// Router A name. router_a: String, @@ -120,6 +130,7 @@ pub enum LabEventKind { condition: Option, }, /// An inter-region link was restored. + #[non_exhaustive] RegionLinkRestored { /// Router A name. router_a: String, @@ -129,6 +140,7 @@ pub enum LabEventKind { // ── Mutations ── /// Router NAT mode changed. + #[non_exhaustive] NatChanged { /// Router name. router: String, @@ -136,6 +148,7 @@ pub enum LabEventKind { nat: Option, }, /// Router IPv6 NAT mode changed. + #[non_exhaustive] NatV6Changed { /// Router name. router: String, @@ -143,11 +156,13 @@ pub enum LabEventKind { nat_v6: NatV6Mode, }, /// Router NAT conntrack state flushed. + #[non_exhaustive] NatStateFlushed { /// Router name. router: String, }, /// Router firewall changed. + #[non_exhaustive] FirewallChanged { /// Router name. router: String, @@ -155,6 +170,7 @@ pub enum LabEventKind { firewall: Firewall, }, /// Device interface link condition changed. + #[non_exhaustive] LinkConditionChanged { /// Device name. device: String, @@ -166,6 +182,7 @@ pub enum LabEventKind { ingress: Option, }, /// Router downlink condition changed (affects all downstream traffic). + #[non_exhaustive] DownlinkConditionChanged { /// Router name. router: String, @@ -173,6 +190,7 @@ pub enum LabEventKind { condition: Option, }, /// Device interface brought up. + #[non_exhaustive] LinkUp { /// Device name. device: String, @@ -180,6 +198,7 @@ pub enum LabEventKind { iface: String, }, /// Device interface brought down. + #[non_exhaustive] LinkDown { /// Device name. device: String, @@ -201,6 +220,7 @@ pub enum LabEventKind { iface: String, }, /// A new interface was added to a device. + #[non_exhaustive] InterfaceAdded { /// Device name. device: String, @@ -208,6 +228,7 @@ pub enum LabEventKind { iface: IfaceSnapshot, }, /// An interface was removed from a device. + #[non_exhaustive] InterfaceRemoved { /// Device name. device: String, @@ -215,6 +236,7 @@ pub enum LabEventKind { iface_name: String, }, /// A device interface was replugged to a different router. + #[non_exhaustive] InterfaceReplugged { /// Device name. device: String, @@ -230,6 +252,7 @@ pub enum LabEventKind { new_ip_v6: Option, }, /// Device IP address changed (e.g. DHCP renewal). + #[non_exhaustive] DeviceIpChanged { /// Device name. device: String, @@ -243,6 +266,7 @@ pub enum LabEventKind { // ── Processes ── /// A command was spawned in a node namespace. + #[non_exhaustive] CommandSpawned { /// Node name (device or router). node: String, @@ -252,6 +276,7 @@ pub enum LabEventKind { cmd: String, }, /// A spawned command exited. + #[non_exhaustive] CommandExited { /// Node name. node: String, @@ -263,6 +288,7 @@ pub enum LabEventKind { // ── Counters ── /// Packet counters snapshot for a node. + #[non_exhaustive] PacketCounters { /// Node name. node: String, @@ -272,6 +298,7 @@ pub enum LabEventKind { // ── Test lifecycle ── /// Test completed with a result. + #[non_exhaustive] TestCompleted { /// Whether the test passed. passed: bool,