diff --git a/windows/crates/ps-core/src/render/routing.rs b/windows/crates/ps-core/src/render/routing.rs index c923582..9a4f5ab 100644 --- a/windows/crates/ps-core/src/render/routing.rs +++ b/windows/crates/ps-core/src/render/routing.rs @@ -147,20 +147,23 @@ fn always_rules(input: &Input, known: &dyn Fn(&str) -> bool, warnings: &mut Vec< } if cfg.per_app_routing.enable { for prof in &cfg.per_app_routing.profiles { - if !derived::BUILTIN_TAGS.contains(&prof.outbound.as_str()) && !known(&prof.outbound) { + // An app held to an outbound that is not running is blocked, not let out another way. + let outbound = if derived::BUILTIN_TAGS.contains(&prof.outbound.as_str()) || known(&prof.outbound) { + prof.outbound.as_str() + } else { warnings.push(format!( - "per-app profile '{}': no outbound or group named '{}' is running; its programs follow the routing", + "per-app profile '{}': no outbound or group named '{}' is running; its programs are blocked until it is", prof.name, prof.outbound )); - continue; - } + "block" + }; let inbound = per_app_inbound(&prof.name); - rules.push(target(json!({ "inbound": [inbound] }), &prof.outbound)); + rules.push(target(json!({ "inbound": [inbound] }), outbound)); if !prof.process_names.is_empty() { - rules.push(target(json!({ "process_name": prof.process_names }), &prof.outbound)); + rules.push(target(json!({ "process_name": prof.process_names }), outbound)); } if !prof.process_paths.is_empty() { - rules.push(target(json!({ "process_path": prof.process_paths }), &prof.outbound)); + rules.push(target(json!({ "process_path": prof.process_paths }), outbound)); } } } @@ -209,24 +212,33 @@ pub(super) fn route(input: &Input, hop_ports: &[u16], known: &dyn Fn(&str) -> bo if ob.routing.is_empty() { continue; } - if !known(&ob.tag) { - warnings.push(format!("outbound '{}' is not running: its routing is left out", ob.tag)); - continue; - } - sections.push(custom_section(100, &ob.tag, &ob.routing, &[], &[])); + let outbound = if known(&ob.tag) { + ob.tag.as_str() + } else { + warnings.push(format!("outbound '{}' is not running: what its routing sends to it is blocked until it is", ob.tag)); + "block" + }; + sections.push(custom_section(100, outbound, &ob.routing, &[], &[])); } for (i, rule) in r.rules.iter().enumerate() { if rule.disabled { continue; } let name = rule.name.clone().unwrap_or_else(|| format!("#{i}")); - if !derived::BUILTIN_TAGS.contains(&rule.outbound.as_str()) && !known(&rule.outbound) { - warnings.push(format!("routing rule {name}: no outbound or group named '{}' is running; the rule is left out", rule.outbound)); - continue; - } + // As a group with nothing to pick does: what the rule matches must not fall through to + // another rule, or to direct. + let outbound = if derived::BUILTIN_TAGS.contains(&rule.outbound.as_str()) || known(&rule.outbound) { + rule.outbound.as_str() + } else { + warnings.push(format!( + "routing rule {name}: no outbound or group named '{}' is running; what it matches is blocked until it is", + rule.outbound + )); + "block" + }; sections.push(custom_section( rule.priority.unwrap_or(100), - &rule.outbound, + outbound, &rule.matches, &rule.process_names, &rule.process_paths, diff --git a/windows/crates/ps-core/tests/render.rs b/windows/crates/ps-core/tests/render.rs index e30c8f8..93a140e 100644 --- a/windows/crates/ps-core/tests/render.rs +++ b/windows/crates/ps-core/tests/render.rs @@ -165,6 +165,8 @@ fn everything_at_once_checks() { assert!(tags.contains(&"chained") && !tags.contains(&"broken"), "{tags:?}"); assert!(r.warnings.iter().any(|w| w.contains("'broken'")), "{:?}", r.warnings); assert!(r.warnings.iter().any(|w| w.contains("'gone'")), "{:?}", r.warnings); + let gone = sb["route"]["rules"].as_array().unwrap().iter().find(|r| r["domain_suffix"] == json!(["x.example"])).unwrap(); + assert_eq!(gone["outbound"], "block"); assert_eq!(sb["endpoints"][0]["tag"], "warp"); assert_eq!(r.inventory.detours["chained"], "nl"); assert!(r.inventory.excluded.contains(&"tor".to_owned()));