[roads] QA F-02: going direct never takes what the tunnel carries out of it

A goes-direct subnet was only checked to be canonical, and the kill switch
dropped it only when it reached the internet, so 100.96.0.0/16 (every mesh
address) or the home LAN that the plan routes into the tunnel compiled cleanly.

Now, decided here because the plan has to say which route wins:
- a goes-direct subnet other than /0 that holds a mesh address is refused
  (direct.mesh);
- per device, a direct subnet inside a net the plan tunnels is dropped and
  reported (direct.tunnelled);
- a direct subnet that holds tunnelled nets keeps them in the tunnel, listed
  in the new plan field direct[].except. A platform that cannot honour except
  (an app-level bypass) must not apply the entry.

The F-02 test now checks that every overlap is covered by except, and that
only the mesh subnet is refused. Golden plans and the pinned jana-phone digest
are regenerated: the only change is the except lists. Plan format 1 has not
been released, so it changes in place.
This commit is contained in:
2026-11-25 08:54:51 +01:00
parent ecafe194a5
commit 80f73a0154
17 changed files with 132 additions and 5 deletions
+66
View File
@@ -256,6 +256,27 @@ fn check(
Some(d) if d.classic => classic_peers.push(&d.name),
Some(_) => {}
},
Some(Place::Subnet(n)) if road.verb == Verb::GoesDirect && n.prefix_len() > 0 => {
// Going direct never takes the mesh's own addresses out of the tunnel (QA F-02). The default
// route is the one exception: it keeps every tunnelled net in, as `except` (below).
let mut inside: Vec<&str> = devs
.mesh_addresses()
.filter(|(_, a)| n.contains_addr(&a.0))
.map(|(d, _)| d.name.as_str())
.collect();
if !inside.is_empty() {
inside.sort();
inside.dedup();
out.push(p(
"object",
r::DIRECT_MESH,
format!(
"{n} holds the mesh address of {}: mesh traffic never goes direct",
inside.join(", ")
),
));
}
}
Some(Place::Subnet(_)) => {}
None => {}
}
@@ -629,6 +650,50 @@ pub fn compile(store: &Store, now: Instant) -> Compiled {
build_plan(key, dev, devs, &mine, extras.remove(key), expiry.get(key)),
);
}
// What the tunnel carries wins over going direct (QA F-02). A direct subnet inside a net this plan sends
// through the tunnel is dropped; one that holds such nets keeps them in the tunnel, listed in `except`,
// so no platform has to guess which route wins.
for plan in out.plans.values_mut() {
let tunnelled: BTreeSet<Net> = plan
.peers
.iter()
.flat_map(|p| p.allowed_ips.iter().copied())
.filter(|n| n.prefix_len() > 0)
.collect();
let mut kept = Vec::new();
for mut d in std::mem::take(&mut plan.direct) {
if let Some(t) = tunnelled.iter().find(|t| t.contains(&d.subnet)) {
for id in &d.roads {
let road = store
.roads
.iter()
.find(|r| &r.id == id)
.expect("a granting road");
out.problems.push(
Problem::inactive(
&road.path,
Some("object"),
r::DIRECT_TUNNELLED,
format!(
"for {}: {} is inside {t}, which goes through the tunnel; it does not go direct",
plan.name, d.subnet
),
)
.at(road.line_of("object")),
);
}
continue;
}
d.except = tunnelled
.iter()
.filter(|t| d.subnet.overlaps(t))
.copied()
.collect();
kept.push(d);
}
plan.direct = kept;
}
out.problems.sort();
out
}
@@ -819,6 +884,7 @@ fn build_plan(
.map(|((app, subnet), roads)| plan::Direct {
app,
subnet,
except: Vec::new(),
roads: roads.into_iter().collect(),
})
.collect(),
+3
View File
@@ -134,6 +134,9 @@ pub struct Direct {
/// `None`: all traffic to `subnet`; `Some`: only that app's.
pub app: Option<AppId>,
pub subnet: Net,
/// The nets inside `subnet` that this plan sends through the tunnel: they stay in it (QA F-02). A
/// platform that cannot keep them in (an app-level bypass, say) must not apply this entry at all.
pub except: Vec<Net>,
pub roads: Vec<RoadId>,
}
+4
View File
@@ -29,6 +29,7 @@ pub const OBJECT_UNKNOWN: &str = "object.unknown";
pub const OBJECT_NOT_EXIT: &str = "object.not-exit";
pub const SUBNET_NOT_CANONICAL: &str = "subnet.not-canonical";
pub const SUBNET_UNROUTED: &str = "subnet.unrouted";
pub const DIRECT_MESH: &str = "direct.mesh";
pub const UNTIL_FORMAT: &str = "until.format";
pub const CREATED_FORMAT: &str = "created.format";
pub const PORTS_FORMAT: &str = "ports.format";
@@ -49,6 +50,7 @@ pub const ROAD_SELF: &str = "road.self";
pub const EXIT_CONFLICT: &str = "exit.conflict";
pub const DIRECT_KILL_SWITCH: &str = "direct.kill-switch";
pub const ROAD_FAMILY: &str = "road.family";
pub const DIRECT_TUNNELLED: &str = "direct.tunnelled";
// Snapshots
pub const SNAPSHOT_JSON: &str = "snapshot.json";
@@ -97,6 +99,7 @@ pub const ALL: &[&str] = &[
OBJECT_NOT_EXIT,
SUBNET_NOT_CANONICAL,
SUBNET_UNROUTED,
DIRECT_MESH,
UNTIL_FORMAT,
CREATED_FORMAT,
PORTS_FORMAT,
@@ -115,6 +118,7 @@ pub const ALL: &[&str] = &[
EXIT_CONFLICT,
DIRECT_KILL_SWITCH,
ROAD_FAMILY,
DIRECT_TUNNELLED,
SNAPSHOT_JSON,
SNAPSHOT_FORMAT,
DIRECTORY_ID,
+5
View File
@@ -79,6 +79,11 @@ impl Devices {
.find_map(|d| d.services.iter().find(|s| &s.host == host).map(|s| (d, s)))
}
/// Every mesh address: each device's own. Never goes direct (QA F-02).
pub fn mesh_addresses(&self) -> impl Iterator<Item = (&Device, Addr)> {
self.devices.values().map(|d| (d, d.address))
}
/// The one device whose routes cover `net`.
pub fn router_of(&self, net: &Net) -> Option<&Device> {
self.devices
@@ -42,6 +42,9 @@
{
"app": "steam",
"subnet": "0.0.0.0/0",
"except": [
"100.96.0.7/32"
],
"roads": [
"e5yj1s"
]
@@ -177,6 +177,12 @@
{
"app": "steam",
"subnet": "0.0.0.0/0",
"except": [
"100.96.0.1/32",
"100.96.0.3/32",
"100.96.0.4/32",
"100.96.0.5/32"
],
"roads": [
"e5yj1s"
]
@@ -40,6 +40,9 @@
{
"app": "steam",
"subnet": "0.0.0.0/0",
"except": [
"100.96.0.2/32"
],
"roads": [
"e5yj1s"
]
@@ -40,6 +40,9 @@
{
"app": "steam",
"subnet": "0.0.0.0/0",
"except": [
"100.96.0.2/32"
],
"roads": [
"e5yj1s"
]
@@ -37,6 +37,7 @@
{
"app": "steam",
"subnet": "0.0.0.0/0",
"except": [],
"roads": [
"e5yj1s"
]
+3
View File
@@ -31,6 +31,9 @@
{
"app": "steam",
"subnet": "0.0.0.0/0",
"except": [
"100.96.0.2/32"
],
"roads": [
"e5yj1s"
]
+2
View File
@@ -46,6 +46,8 @@ road a00044-tab.md yaml.refused -
road a00045-empty-until.md key.empty until
road a00046-until-comment.md key.empty until
road a00047-empty-ports.md key.empty ports
road a00048-direct-mesh.md direct.mesh object
road a00049-direct-tunnelled.md direct.tunnelled object
directory unknown-field.directory.json snapshot.json -
directory format-two.directory.json snapshot.format format
directory bad-person-id.directory.json directory.id people[3].id
@@ -0,0 +1,7 @@
---
id: a00048
subject: person:jana
verb: goes-direct
object: subnet:100.96.0.0/24
created: 2026-11-25T10:00:00+01:00
---
@@ -0,0 +1,7 @@
---
id: a00049
subject: person:mark
verb: goes-direct
object: subnet:192.168.100.0/25
created: 2026-11-25T10:00:00+01:00
---
+14 -2
View File
@@ -52,7 +52,6 @@ fn f01_a_service_road_grants_only_that_service() {
/// plan also routes into the tunnel is told to bypass it, on whatever network the device is on, and the
/// kill switch does not stop it because the subnet is "private".
#[test]
#[ignore = "QA F-02 (major): goes-direct can take mesh addresses and tunnelled subnets out of the tunnel"]
fn f02_going_direct_never_overlaps_what_the_tunnel_carries() {
let mark_pc = key(1);
for subnet in ["100.96.0.0/16", "192.168.100.0/24", "192.168.0.0/16"] {
@@ -77,15 +76,28 @@ fn f02_going_direct_never_overlaps_what_the_tunnel_carries() {
.flat_map(|p| p.allowed_ips.iter())
.filter(|n| n.prefix_len() > 0)
.collect();
// Decision (owner session): a direct subnet that holds tunnelled nets keeps them in the tunnel, listed
// in `except`; one inside a tunnelled net is dropped; one holding a mesh address is refused. So every
// overlap must be covered by `except`.
for d in &plan.direct {
for n in &tunnelled {
assert!(
!d.subnet.overlaps(n),
!d.subnet.overlaps(n) || d.except.iter().any(|e| e.contains(n)),
"goes-direct {} overlaps {n}, which the plan sends through the tunnel",
d.subnet
);
}
}
let refused = c
.problems
.iter()
.any(|p| p.path.contains("f02aaa") && p.code == roads::rules::DIRECT_MESH);
assert_eq!(
refused,
subnet == "100.96.0.0/16",
"{subnet}: {:?}",
c.problems
);
}
}
+1
View File
@@ -43,6 +43,7 @@ fn inactive_code(code: &str) -> bool {
rules::EXIT_CONFLICT,
rules::DIRECT_KILL_SWITCH,
rules::ROAD_FAMILY,
rules::DIRECT_TUNNELLED,
]
.contains(&code)
}