Keep every active mesh reachable through a single internet exit
With several IPv4 aliases on a single TUN, the default route could select an address from a different mesh. The exit peer then rejected internet traffic as an invalid source. Concurrent cross-network exit selections could also clear each other in the running agent while SQLite kept one winner. Serialize validated exit choices with network lifecycle and persist each choice before publishing it to the shared routing table. Replace the previous exit atomically and preserve it across allocation updates. Both mesh subnets keep their own routes. Only replies from the selected exit to the local address of its network qualify for the external-source exception. Prefer the selected source on Linux and macOS default routes. Preserve physical transport paths and update split routes in place. On Windows reuse the Android packet translation to restore off-mesh TCP, UDP and ICMP replies to the original local socket. Existing databases, IPC commands and wire protocols remain compatible. On macOS, formatting and strict workspace Clippy passed. The full locked workspace suite passed 577 tests with three ignored, after correcting a stale Windows script-test matcher. Three real agents covered switching, concurrent selection, offline isolation and restart. On Linux arm64, 88 focused tests and the privileged kernel routing/firewall test passed. The Android arm64 library built and linked. Wintun and privileged macOS utun were not exercised on live hosts.
This commit is contained in:
1 parent
21b8381fa3
commit
32aa73721a
23 files changed
+1167
-304
No files matched your search
Generated
+1
@@ -6384,6 +6384,7 @@ dependencies = [
|
||||
"serde",
|
||||
"sha2",
|
||||
"simple-dns",
|
||||
"smoltcp",
|
||||
"subtle",
|
||||
"tempfile",
|
||||
"thiserror 2.0.20",
|
||||
|
||||
@@ -114,10 +114,13 @@ explicit Save. [Commands, health, metrics and limits](docs/vip.md).
|
||||
```sh
|
||||
tsng network exit-node home on # on the machine that should be the exit
|
||||
tsng exit-node # on another one: who offers an exit
|
||||
tsng exit-node laptop # send everything through it
|
||||
tsng exit-node laptop # send internet traffic through it
|
||||
tsng exit-node off
|
||||
```
|
||||
|
||||
One exit serves the whole agent. Peers in every active Tsunagi network stay
|
||||
reachable on their own mesh routes.
|
||||
|
||||
The tray does the same with a checkbox. An exit node sees everything you send
|
||||
through it, so use only members you trust.
|
||||
[Details and per-OS notes](docs/exit-node.md).
|
||||
|
||||
@@ -6,8 +6,6 @@ pub mod plan;
|
||||
#[cfg(target_os = "android")]
|
||||
mod android;
|
||||
pub mod service;
|
||||
#[cfg(unix)]
|
||||
mod source;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! A stable packet device over the file descriptors replaced by VpnService.
|
||||
use crate::dns::{Resolver, stack::DnsPort};
|
||||
use crate::plan::VpnPlan;
|
||||
use crate::source::SourceFlows;
|
||||
use bytes::Bytes;
|
||||
use std::{
|
||||
fmt,
|
||||
@@ -21,6 +20,7 @@ use tsunagi::{
|
||||
BroadcastHostRules, BroadcastRulesPlan, BroadcastRulesReport, ExitHostPlan,
|
||||
ExitHostReport, ExitHostRules, RuleOutcome,
|
||||
},
|
||||
source::{SourceFlows, SourceMode},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -114,11 +114,16 @@ impl AndroidTun {
|
||||
.clone()
|
||||
.and_then(|fd| fd.packets().take());
|
||||
let fd = device.map(|(file, dns)| {
|
||||
let aliases = next.addresses_in_order();
|
||||
let exit = match (next.full_tunnel, next.exit) {
|
||||
(true, Some(std::net::IpAddr::V4(source))) => Some(source),
|
||||
_ => None,
|
||||
};
|
||||
let flows = if let Some(mut previous) = previous {
|
||||
previous.flows.reconfigure(&next);
|
||||
previous.flows.reconfigure(&aliases, exit, next.mtu);
|
||||
previous.flows
|
||||
} else {
|
||||
SourceFlows::new(&next)
|
||||
SourceFlows::new(&aliases, exit, next.mtu, SourceMode::Primary)
|
||||
};
|
||||
Arc::new(Attachment {
|
||||
device: file,
|
||||
|
||||
@@ -59,6 +59,8 @@ rand = "0.10"
|
||||
# zone logic is ours and a full server framework would be a large dependency
|
||||
# for answering A records from memory.
|
||||
simple-dns = "0.12"
|
||||
# IPv4 packet and checksum codecs shared by the Android VPN and Wintun.
|
||||
smoltcp = { version = "0.12", default-features = false, features = ["std", "proto-ipv4"] }
|
||||
# The IANA top-level domain list, compiled in: one function, no
|
||||
# dependencies, no network. Used only to warn that a zone name shadows a
|
||||
# real public domain, never to refuse one.
|
||||
|
||||
@@ -104,7 +104,7 @@ struct Inner {
|
||||
networks: RwLock<HashMap<NetworkId, NetworkHandle>>,
|
||||
shutdown: Shutdown,
|
||||
/// Serialises start, stop, switching and conflict cleanup, including teardown.
|
||||
lifecycle: Mutex<()>,
|
||||
lifecycle: Arc<Mutex<()>>,
|
||||
range_changed: watch::Sender<()>,
|
||||
range_task: std::sync::Mutex<Option<JoinHandle<()>>>,
|
||||
accept_task: std::sync::Mutex<Option<JoinHandle<()>>>,
|
||||
@@ -450,7 +450,7 @@ impl Agent {
|
||||
events,
|
||||
networks: RwLock::new(HashMap::new()),
|
||||
shutdown: Shutdown::new(),
|
||||
lifecycle: Mutex::new(()),
|
||||
lifecycle: Arc::new(Mutex::new(())),
|
||||
range_changed,
|
||||
range_task: std::sync::Mutex::new(None),
|
||||
accept_task: std::sync::Mutex::new(None),
|
||||
@@ -797,47 +797,27 @@ impl Agent {
|
||||
/// choice in the others. The member has to be connected and offering
|
||||
/// to be an exit node. Remembered across restarts.
|
||||
pub async fn set_exit_via(&self, network_id: NetworkId, via: Option<EndpointId>) -> Result<()> {
|
||||
let active = self.is_active(network_id).await;
|
||||
if via.is_some() && !active {
|
||||
return Err(Error::NetworkNotActive(network_id));
|
||||
}
|
||||
if active {
|
||||
let (reply, receive) = oneshot::channel();
|
||||
self.command(network_id, NetCommand::SetExitVia { via, reply })
|
||||
.await?;
|
||||
receive
|
||||
.await
|
||||
.map_err(|_| Error::Stopped)?
|
||||
.map_err(|reason| Error::Rejected { reason })?;
|
||||
}
|
||||
self.inner
|
||||
.storage
|
||||
.set_exit_via(network_id, via.map(|peer| *peer.as_bytes()))
|
||||
.await?;
|
||||
if via.is_some() {
|
||||
// One default route: whatever the other networks were doing, they
|
||||
// are not any more.
|
||||
let others: Vec<NetworkId> = self
|
||||
.inner
|
||||
.networks
|
||||
.read()
|
||||
.await
|
||||
.keys()
|
||||
.copied()
|
||||
.filter(|other| *other != network_id)
|
||||
.collect();
|
||||
for other in others {
|
||||
let (reply, receive) = oneshot::channel();
|
||||
if self
|
||||
.command(other, NetCommand::SetExitVia { via: None, reply })
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
let _ = receive.await;
|
||||
}
|
||||
let lifecycle = self.inner.lifecycle.clone().lock_owned().await;
|
||||
if !self.is_active(network_id).await {
|
||||
if via.is_some() {
|
||||
return Err(Error::NetworkNotActive(network_id));
|
||||
}
|
||||
return self.inner.storage.set_exit_via(network_id, None).await;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
// The actor owns the guard through validation, persistence and routing,
|
||||
// even if the requesting IPC client disconnects halfway through.
|
||||
let (reply, receive) = oneshot::channel();
|
||||
self.command(
|
||||
network_id,
|
||||
NetCommand::SetExitVia {
|
||||
via,
|
||||
lifecycle,
|
||||
reply,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
receive.await.map_err(|_| Error::Stopped)?
|
||||
}
|
||||
|
||||
/// Changes a network's local broadcast policy now and after restart.
|
||||
@@ -961,6 +941,13 @@ impl Agent {
|
||||
)?;
|
||||
}
|
||||
let range = self.desired_range(network_id).await?;
|
||||
let exit = crate::overlay::ExitPolicy {
|
||||
offer: stored.as_ref().is_some_and(|s| s.exit_node),
|
||||
via: stored
|
||||
.as_ref()
|
||||
.and_then(|s| s.exit_via)
|
||||
.and_then(|bytes| EndpointId::from_bytes(&bytes).ok()),
|
||||
};
|
||||
if let Some(range) = range {
|
||||
let conflicts = self.inner.routes.overlapping_networks(network_id, range);
|
||||
if !conflicts.is_empty() {
|
||||
@@ -970,19 +957,20 @@ impl Agent {
|
||||
conflicts: conflicts.into_iter().map(|(id, _)| id).collect(),
|
||||
});
|
||||
}
|
||||
self.inner
|
||||
.routes
|
||||
.set_network(
|
||||
network_id,
|
||||
crate::overlay::NetworkRoutes {
|
||||
range: Some(range),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.map_err(|err| Error::Rejected {
|
||||
reason: err.to_string(),
|
||||
})?;
|
||||
}
|
||||
self.inner
|
||||
.routes
|
||||
.set_network(
|
||||
network_id,
|
||||
crate::overlay::NetworkRoutes {
|
||||
range,
|
||||
exit,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.map_err(|err| Error::Rejected {
|
||||
reason: err.to_string(),
|
||||
})?;
|
||||
let mut backends = Vec::new();
|
||||
if let Some(discovery) = &self.inner.config.discovery {
|
||||
backends.push(discovery.clone());
|
||||
@@ -1006,17 +994,10 @@ impl Agent {
|
||||
if !plugins.is_empty() {
|
||||
self.inner.ensure_interface().await;
|
||||
}
|
||||
let exit_offer = stored.as_ref().is_some_and(|stored| stored.exit_node);
|
||||
let exit_via = stored
|
||||
.as_ref()
|
||||
.and_then(|stored| stored.exit_via)
|
||||
.and_then(|bytes| EndpointId::from_bytes(&bytes).ok());
|
||||
let handle = network::spawn(RuntimeParams {
|
||||
vips,
|
||||
retirements,
|
||||
broadcast,
|
||||
exit_offer,
|
||||
exit_via,
|
||||
keys,
|
||||
adapter: self.inner.adapter.clone(),
|
||||
storage: self.inner.storage.clone(),
|
||||
|
||||
@@ -96,7 +96,8 @@ pub(crate) enum NetCommand {
|
||||
/// Send this device's internet traffic through a member, or stop.
|
||||
SetExitVia {
|
||||
via: Option<EndpointId>,
|
||||
reply: oneshot::Sender<std::result::Result<(), String>>,
|
||||
lifecycle: tokio::sync::OwnedMutexGuard<()>,
|
||||
reply: oneshot::Sender<Result<()>>,
|
||||
},
|
||||
/// Resend this agent's announcement to every peer of this network.
|
||||
Reannounce,
|
||||
@@ -177,10 +178,6 @@ pub(crate) struct RuntimeParams {
|
||||
pub(crate) vips: crate::vip::VipSet,
|
||||
pub(crate) retirements: Vec<SignedRetirement>,
|
||||
pub(crate) broadcast: bool,
|
||||
/// This agent offers itself as an exit node here.
|
||||
pub(crate) exit_offer: bool,
|
||||
/// The member this device's internet traffic goes through.
|
||||
pub(crate) exit_via: Option<EndpointId>,
|
||||
pub(crate) keys: NetworkKeys,
|
||||
pub(crate) adapter: EndpointAdapter,
|
||||
pub(crate) storage: Storage,
|
||||
@@ -689,25 +686,24 @@ impl Runtime {
|
||||
let _ = reply.send(());
|
||||
}
|
||||
NetCommand::SetExitOffer { enabled, reply } => {
|
||||
self.params.exit_offer = enabled;
|
||||
self.params
|
||||
.routes
|
||||
.update_exit(self.network_id, |exit| exit.offer = enabled);
|
||||
self.apply_exit().await;
|
||||
self.reannounce();
|
||||
let _ = reply.send(());
|
||||
}
|
||||
NetCommand::SetExitVia { via, reply } => {
|
||||
let outcome = match via {
|
||||
Some(peer) if !self.exit_node_online(peer) => Err(
|
||||
"that member is not connected or does not offer to be an exit node"
|
||||
.to_string(),
|
||||
),
|
||||
_ => Ok(()),
|
||||
};
|
||||
if outcome.is_ok() {
|
||||
self.params.exit_via = via;
|
||||
self.exit_via_was_online = via.is_some();
|
||||
NetCommand::SetExitVia {
|
||||
via,
|
||||
lifecycle,
|
||||
reply,
|
||||
} => {
|
||||
let result = self.select_exit(via).await;
|
||||
drop(lifecycle);
|
||||
if result.is_ok() {
|
||||
self.apply_exit().await;
|
||||
}
|
||||
let _ = reply.send(outcome);
|
||||
let _ = reply.send(result);
|
||||
}
|
||||
NetCommand::Recheck => self.discovery_round().await,
|
||||
NetCommand::Reannounce => {
|
||||
@@ -907,7 +903,12 @@ impl Runtime {
|
||||
/// the relays in use. Only hosts that cannot exempt the agent from an
|
||||
/// exit node's default route read it.
|
||||
async fn refresh_underlay(&self) {
|
||||
let Some(interface) = self.params.interface.clone() else {
|
||||
let Some(interface) = self
|
||||
.params
|
||||
.interface
|
||||
.as_ref()
|
||||
.filter(|i| i.needs_underlay_targets())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let mut addresses = Vec::new();
|
||||
@@ -1308,7 +1309,7 @@ impl Runtime {
|
||||
"the node is online; only offline history can be forgotten".into(),
|
||||
));
|
||||
}
|
||||
if self.params.exit_via == Some(peer) {
|
||||
if self.exit_policy().via == Some(peer) {
|
||||
return Err(Error::ForgetNode(
|
||||
"stop using this exit node before forgetting it".into(),
|
||||
));
|
||||
@@ -1770,20 +1771,36 @@ impl Runtime {
|
||||
}
|
||||
|
||||
fn exit_policy(&self) -> crate::overlay::ExitPolicy {
|
||||
crate::overlay::ExitPolicy {
|
||||
offer: self.params.exit_offer,
|
||||
via: self.params.exit_via,
|
||||
self.params
|
||||
.routes
|
||||
.exit_settings(self.network_id)
|
||||
.map(|(policy, _)| policy)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
async fn select_exit(&mut self, via: Option<EndpointId>) -> Result<()> {
|
||||
if via.is_some_and(|peer| !self.exit_node_online(peer)) {
|
||||
return Err(Error::Rejected {
|
||||
reason: "that member is not connected or does not offer to be an exit node".into(),
|
||||
});
|
||||
}
|
||||
self.params
|
||||
.storage
|
||||
.set_exit_via(self.network_id, via.map(|peer| *peer.as_bytes()))
|
||||
.await?;
|
||||
self.params
|
||||
.routes
|
||||
.update_exit(self.network_id, |exit| exit.via = via);
|
||||
self.exit_via_was_online = via.is_some();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Whether this agent offers to be an exit node and can really be one.
|
||||
fn exit_ready(&self) -> bool {
|
||||
self.params.exit_offer
|
||||
&& self
|
||||
.params
|
||||
.interface
|
||||
.as_ref()
|
||||
.is_some_and(|interface| interface.exit_offer_ready(self.network_id))
|
||||
self.params
|
||||
.interface
|
||||
.as_ref()
|
||||
.is_some_and(|interface| interface.exit_offer_ready(self.network_id))
|
||||
}
|
||||
|
||||
/// Whether a member is connected and says it is an exit node.
|
||||
@@ -1793,15 +1810,12 @@ impl Runtime {
|
||||
.is_some_and(|session| session.exit_node)
|
||||
}
|
||||
|
||||
/// Puts the exit settings into the routing table and the host rules.
|
||||
/// Reconciles the host rules with the shared routing table.
|
||||
///
|
||||
/// The routes and the rules stay as they are when the exit node in use
|
||||
/// goes away: dropping them would send the traffic out the old way, in
|
||||
/// the clear, without anyone having asked.
|
||||
async fn apply_exit(&mut self) {
|
||||
self.params
|
||||
.routes
|
||||
.set_exit(self.network_id, self.exit_policy());
|
||||
if let Some(interface) = self.params.interface.clone() {
|
||||
interface.sync_exit_rules().await;
|
||||
}
|
||||
@@ -1814,7 +1828,7 @@ impl Runtime {
|
||||
|
||||
/// Says so, once, when the exit node in use is lost or comes back.
|
||||
fn watch_exit_via(&mut self) {
|
||||
let Some(via) = self.params.exit_via else {
|
||||
let Some(via) = self.exit_policy().via else {
|
||||
return;
|
||||
};
|
||||
let online = self.exit_node_online(via);
|
||||
@@ -1865,7 +1879,7 @@ impl Runtime {
|
||||
// a packet for ourselves does not go over a tunnel.
|
||||
let local = self.state.address_of(&self.local_id);
|
||||
let routes = crate::overlay::NetworkRoutes {
|
||||
exit: self.exit_policy(),
|
||||
exit: Default::default(),
|
||||
broadcast: self.broadcast_policy(),
|
||||
range: Some(range),
|
||||
local,
|
||||
@@ -1878,7 +1892,7 @@ impl Runtime {
|
||||
if self
|
||||
.params
|
||||
.routes
|
||||
.set_network(self.network_id, routes)
|
||||
.update_allocations(self.network_id, routes)
|
||||
.is_err()
|
||||
{
|
||||
self.range_blocked
|
||||
@@ -2647,6 +2661,9 @@ impl Runtime {
|
||||
|
||||
let snapshot = snapshot_connection(&conn);
|
||||
self.sessions.insert(peer, session);
|
||||
// An exit may be selected as soon as the peer advertises it, before
|
||||
// the next discovery tick. Keep this transport on its physical path.
|
||||
self.refresh_underlay().await;
|
||||
if let Some(worker) = &self.discovery_worker {
|
||||
worker.set_connected(true);
|
||||
}
|
||||
@@ -3246,6 +3263,7 @@ impl Runtime {
|
||||
members.sort_by(|a, b| a.endpoint_id.as_bytes().cmp(b.endpoint_id.as_bytes()));
|
||||
members.dedup_by(|a, b| a.endpoint_id == b.endpoint_id);
|
||||
|
||||
let exit = self.exit_policy();
|
||||
NetworkStatus {
|
||||
vips: self.params.routes.vips.statuses(self.network_id),
|
||||
protocols: self
|
||||
@@ -3256,12 +3274,9 @@ impl Runtime {
|
||||
.collect(),
|
||||
auto_start: true,
|
||||
broadcast: self.params.broadcast,
|
||||
exit_offer: self.params.exit_offer,
|
||||
exit_via: self.params.exit_via,
|
||||
exit_via_online: self
|
||||
.params
|
||||
.exit_via
|
||||
.is_some_and(|via| self.exit_node_online(via)),
|
||||
exit_offer: exit.offer,
|
||||
exit_via: exit.via,
|
||||
exit_via_online: exit.via.is_some_and(|via| self.exit_node_online(via)),
|
||||
exit_rules: self
|
||||
.params
|
||||
.interface
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
//! Policy routing, with no `/1` routes and nothing in the main table:
|
||||
//!
|
||||
//! ```text
|
||||
//! table 0x7473: default dev <if>
|
||||
//! table 0x7473: default dev <if> src <selected overlay address>
|
||||
//! 5205: from all fwmark 0x40000000/0x40000000 lookup main
|
||||
//! 5206: from all uidrange <euid>-<euid> lookup main
|
||||
//! 5290: from all lookup main suppress_prefixlength 0
|
||||
@@ -45,6 +45,7 @@
|
||||
|
||||
use crate::BoxFuture;
|
||||
use crate::state::Ipv4Range;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
use super::RuleOutcome;
|
||||
use super::exit::{ExitHostPlan, ExitHostReport, ExitHostRules, exit_tag, exit_tag_prefix};
|
||||
@@ -441,7 +442,7 @@ impl LinuxHostRules {
|
||||
.map_err(|err| format!("the task failed: {err}"))
|
||||
}
|
||||
|
||||
async fn apply_client(&self, interface: &str) -> RuleOutcome {
|
||||
async fn apply_client(&self, interface: &str, source: Option<Ipv4Addr>) -> RuleOutcome {
|
||||
let xdg = std::env::var("XDG_RUNTIME_DIR").ok();
|
||||
if let Some(reason) = client_refusal(xdg.as_deref()) {
|
||||
// Whatever an earlier run left must not stay in force.
|
||||
@@ -461,7 +462,15 @@ impl LinuxHostRules {
|
||||
.as_ref()
|
||||
.is_some_and(|(name, _, routed)| name == interface && *routed);
|
||||
if installed {
|
||||
// A failed socket refresh must never remove an active exit route.
|
||||
// A different network can now supply the exit on this same TUN.
|
||||
// Preserve the policy rules and underlay protection during the switch.
|
||||
let route = self.route.clone();
|
||||
let name = interface.to_string();
|
||||
match Self::blocking(move || route.update_exit_source(&name, source)).await {
|
||||
Ok(Ok(())) => {}
|
||||
Ok(Err(err)) => return RuleOutcome::Failed(err.to_string()),
|
||||
Err(reason) => return RuleOutcome::Failed(reason),
|
||||
}
|
||||
return self
|
||||
.refresh_sockets(interface)
|
||||
.await
|
||||
@@ -492,7 +501,8 @@ impl LinuxHostRules {
|
||||
}
|
||||
let route = self.route.clone();
|
||||
let name = interface.to_string();
|
||||
let outcome = match Self::blocking(move || route.set_exit_client(&name, euid)).await {
|
||||
let outcome = match Self::blocking(move || route.set_exit_client(&name, euid, source)).await
|
||||
{
|
||||
Ok(Ok(())) => RuleOutcome::Applied,
|
||||
Ok(Err(err)) => RuleOutcome::Failed(err.to_string()),
|
||||
Err(reason) => RuleOutcome::Failed(reason),
|
||||
@@ -616,7 +626,7 @@ impl ExitHostRules for LinuxHostRules {
|
||||
forwarding_state(read_sysctl, &interface)
|
||||
};
|
||||
let client = if plan.client {
|
||||
Some(self.apply_client(&interface).await)
|
||||
Some(self.apply_client(&interface, plan.client_source).await)
|
||||
} else {
|
||||
if let Err(reason) = self.clear_client(&interface).await {
|
||||
tracing::warn!(%reason, "cannot remove exit-client rules");
|
||||
|
||||
@@ -217,7 +217,9 @@ fn client() {
|
||||
ip(&["-6", "route", "add", "throw", prefix, "table", "52"]);
|
||||
}
|
||||
let mut passive = spawn_listener("listener");
|
||||
route.set_exit_client("tsun0", 990).unwrap();
|
||||
route
|
||||
.set_exit_client("tsun0", 990, Some("10.99.0.1".parse().unwrap()))
|
||||
.unwrap();
|
||||
// uid bypass alone cannot protect reverse lookups, reproducing the bug.
|
||||
run_probes("blocked");
|
||||
install(&run_firewall, "tsun0", 990, true).unwrap();
|
||||
@@ -248,6 +250,25 @@ for family,source,target in [(socket.AF_INET,'198.51.100.2','192.0.2.1'),(socket
|
||||
install(&run_firewall, "tsun0", 990, true).unwrap();
|
||||
run_probes("pass");
|
||||
assert!(ip(&["-4", "route", "get", "198.51.100.2", "uid", "991"]).contains("dev tsun0"));
|
||||
// Check our own default table without the foreign VPN's higher-priority default.
|
||||
ip(&["-4", "rule", "del", "priority", "5270"]);
|
||||
for (destination, source) in [
|
||||
("10.13.37.2", "10.13.37.1"),
|
||||
("10.99.0.2", "10.99.0.1"),
|
||||
("198.51.100.2", "10.99.0.1"),
|
||||
] {
|
||||
let result = ip(&["-4", "route", "get", destination, "uid", "991"]);
|
||||
assert!(
|
||||
result.contains("dev tsun0") && result.contains(&format!("src {source}")),
|
||||
"{result}"
|
||||
);
|
||||
}
|
||||
route
|
||||
.update_exit_source("tsun0", Some("10.13.37.1".parse().unwrap()))
|
||||
.unwrap();
|
||||
assert!(ip(&["-4", "route", "get", "198.51.100.2", "uid", "991"]).contains("src 10.13.37.1"));
|
||||
assert!(ip(&["-4", "route", "get", "10.99.0.2", "uid", "991"]).contains("src 10.99.0.1"));
|
||||
ip(&["-4", "rule", "add", "priority", "5270", "table", "52"]);
|
||||
let blocked = Command::new("ip")
|
||||
.args(["-6", "route", "get", "2001:db8:2::2", "uid", "991"])
|
||||
.output()
|
||||
@@ -384,6 +405,15 @@ fn strict_firewall_preserves_underlay_and_application_exit_routing() {
|
||||
"tsun0",
|
||||
]);
|
||||
ip(&["-n", &client_name, "link", "set", "tsun0", "up"]);
|
||||
ip(&[
|
||||
"-n",
|
||||
&client_name,
|
||||
"addr",
|
||||
"add",
|
||||
"10.99.0.1/24",
|
||||
"dev",
|
||||
"tsun0",
|
||||
]);
|
||||
let echo_code = r#"import socket,selectors,sys
|
||||
selector=selectors.DefaultSelector()
|
||||
for family in [socket.AF_INET,socket.AF_INET6]:
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
//! Linux scheme does not carry over. Instead:
|
||||
//!
|
||||
//! ```text
|
||||
//! route add -net 0.0.0.0/1 -interface <if>
|
||||
//! route add -net 128.0.0.0/1 -interface <if>
|
||||
//! route add -net 0.0.0.0/1 -interface <if> -ifa <selected overlay address>
|
||||
//! route add -net 128.0.0.0/1 -interface <if> -ifa <selected overlay address>
|
||||
//! pass out quick on <if> route-to (<egress> <gateway>) inet proto { tcp udp }
|
||||
//! from any to ! <overlay ranges> user <agent uid>
|
||||
//! nat on <egress> inet from (<if>) to any -> (<egress>)
|
||||
@@ -104,6 +104,7 @@ pub(super) fn run_tool(tool: Tool, args: &[String], stdin: Option<&str>) -> Ran
|
||||
|
||||
let mut command = Command::new(tool.path());
|
||||
command
|
||||
.env("LC_ALL", "C")
|
||||
.args(args)
|
||||
.stdin(if stdin.is_some() {
|
||||
Stdio::piped()
|
||||
@@ -206,8 +207,8 @@ fn run_ok(
|
||||
Ran::Exited {
|
||||
success: true,
|
||||
stdout,
|
||||
..
|
||||
} => Ok(stdout),
|
||||
stderr,
|
||||
} if tool != Tool::Route || stderr.is_empty() => Ok(stdout),
|
||||
Ran::Exited { stderr, stdout, .. } => Err(format!(
|
||||
"{} {} failed: {}",
|
||||
tool.path(),
|
||||
@@ -380,8 +381,17 @@ const HALVES: [&str; 2] = ["0.0.0.0/1", "128.0.0.0/1"];
|
||||
/// The IPv6 halves, made unreachable.
|
||||
const HALVES_V6: [&str; 2] = ["::/1", "8000::/1"];
|
||||
|
||||
fn route_add_args(half: &str, interface: &str) -> Vec<String> {
|
||||
owned(&["-q", "-n", "add", "-net", half, "-interface", interface])
|
||||
fn route_set_args(
|
||||
action: &str,
|
||||
half: &str,
|
||||
interface: &str,
|
||||
source: Option<Ipv4Addr>,
|
||||
) -> Vec<String> {
|
||||
let mut args = owned(&["-q", "-n", action, "-net", half, "-interface", interface]);
|
||||
if let Some(source) = source {
|
||||
args.extend(["-ifa".into(), source.to_string()]);
|
||||
}
|
||||
args
|
||||
}
|
||||
|
||||
fn route_del_args(half: &str, interface: &str) -> Vec<String> {
|
||||
@@ -407,12 +417,57 @@ fn clear_routes(run: Run<'_>, interface: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_routes(run: Run<'_>, interface: &str) -> Result<(), String> {
|
||||
clear_routes(run, interface);
|
||||
/// Installs a split default, or changes its source in place when the route
|
||||
/// already belongs to this utun. Returns whether this call added it.
|
||||
fn set_half(
|
||||
run: Run<'_>,
|
||||
half: &str,
|
||||
interface: &str,
|
||||
source: Option<Ipv4Addr>,
|
||||
) -> Result<bool, String> {
|
||||
match run_ok(
|
||||
run,
|
||||
Tool::Route,
|
||||
&route_set_args("add", half, interface, source),
|
||||
None,
|
||||
) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(why) if why.contains("File exists") => {
|
||||
let lookup = run_ok(run, Tool::Route, &owned(&["-n", "get", "-net", half]), None)
|
||||
.map_err(|inspect| format!("{why}; {inspect}"))?;
|
||||
let field = |key: &str| {
|
||||
lookup
|
||||
.lines()
|
||||
.filter_map(|line| line.trim().split_once(':'))
|
||||
.find_map(|(name, value)| (name == key).then(|| value.trim()))
|
||||
};
|
||||
if field("mask") != Some("128.0.0.0") || field("interface") != Some(interface) {
|
||||
return Err(why);
|
||||
}
|
||||
run_ok(
|
||||
run,
|
||||
Tool::Route,
|
||||
&route_set_args("change", half, interface, source),
|
||||
None,
|
||||
)?;
|
||||
Ok(false)
|
||||
}
|
||||
Err(why) => Err(why),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_routes(run: Run<'_>, interface: &str, source: Option<Ipv4Addr>) -> Result<(), String> {
|
||||
let mut added = Vec::new();
|
||||
for half in HALVES {
|
||||
if let Err(why) = run_ok(run, Tool::Route, &route_add_args(half, interface), None) {
|
||||
clear_routes(run, interface);
|
||||
return Err(why);
|
||||
match set_half(run, half, interface, source) {
|
||||
Ok(true) => added.push(half),
|
||||
Ok(false) => {}
|
||||
Err(why) => {
|
||||
for half in added {
|
||||
let _ = run(Tool::Route, &route_del_args(half, interface), None);
|
||||
}
|
||||
return Err(why);
|
||||
}
|
||||
}
|
||||
}
|
||||
for half in HALVES_V6 {
|
||||
@@ -490,7 +545,7 @@ fn apply_rules(
|
||||
// The routes come after the rules that keep the agent's own traffic off
|
||||
// them: the other order would loop for as long as it takes.
|
||||
if plan.client {
|
||||
set_routes(run, interface)?;
|
||||
set_routes(run, interface, plan.client_source)?;
|
||||
} else {
|
||||
clear_routes(run, interface);
|
||||
}
|
||||
@@ -545,6 +600,7 @@ destination: default\n\
|
||||
pf_missing: bool,
|
||||
pf_load_fails: bool,
|
||||
route_add_fails: bool,
|
||||
half_interface: Option<&'static str>,
|
||||
pf_enable_output: &'static str,
|
||||
}
|
||||
|
||||
@@ -558,6 +614,7 @@ destination: default\n\
|
||||
pf_missing: false,
|
||||
pf_load_fails: false,
|
||||
route_add_fails: false,
|
||||
half_interface: None,
|
||||
pf_enable_output: "pf enabled\nToken : 4242\n",
|
||||
}
|
||||
}
|
||||
@@ -581,14 +638,29 @@ destination: default\n\
|
||||
match tool {
|
||||
Tool::Id => ok("0\n", ""),
|
||||
Tool::Sysctl => ok(self.forwarding, ""),
|
||||
Tool::Route
|
||||
if args.iter().any(|arg| arg == "get")
|
||||
&& args.iter().any(|arg| arg == "-net") =>
|
||||
{
|
||||
match self.half_interface {
|
||||
Some(name) => ok(&format!("mask: 128.0.0.0\ninterface: {name}\n"), ""),
|
||||
None => fail("not in table"),
|
||||
}
|
||||
}
|
||||
Tool::Route if args.first().map(String::as_str) == Some("-n") => {
|
||||
match &self.default_route {
|
||||
Some(text) => ok(text, ""),
|
||||
None => fail("route: writing to routing socket: not in table"),
|
||||
}
|
||||
}
|
||||
Tool::Route if args.contains(&"add".to_string()) && self.route_add_fails => {
|
||||
fail("route: writing to routing socket: File exists")
|
||||
Tool::Route
|
||||
if args.contains(&"add".to_string())
|
||||
&& ((self.route_add_fails && args.iter().any(|a| a == HALVES[1]))
|
||||
|| (self.half_interface.is_some()
|
||||
&& HALVES.iter().any(|half| args.iter().any(|a| a == half)))) =>
|
||||
{
|
||||
// Darwin route can return success after a routing-socket write failed.
|
||||
ok("", "route: writing to routing socket: File exists")
|
||||
}
|
||||
Tool::Route => ok("", ""),
|
||||
Tool::Pfctl if self.pf_missing => Ran::Missing,
|
||||
@@ -718,7 +790,7 @@ destination: default\n\
|
||||
#[test]
|
||||
fn the_overlay_default_routes_are_halves_and_ipv6_is_rejected() {
|
||||
assert_eq!(
|
||||
route_add_args("0.0.0.0/1", "utun5").join(" "),
|
||||
route_set_args("add", "0.0.0.0/1", "utun5", None).join(" "),
|
||||
"-q -n add -net 0.0.0.0/1 -interface utun5"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -805,6 +877,55 @@ destination: default\n\
|
||||
assert!(fake.position("-n get default").unwrap() < add);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both_exit_halves_use_the_selected_networks_address_on_a_shared_utun() {
|
||||
let fake = Fake::new();
|
||||
let token = Mutex::new(None);
|
||||
let mut selected = plan(false, true);
|
||||
selected.overlay.push("10.99.0.0/24".parse().unwrap());
|
||||
for source in ["10.99.0.17", "10.13.37.34"] {
|
||||
selected.client_source = Some(source.parse().unwrap());
|
||||
let report = apply_plan(&|t, a, s| fake.run(t, a, s), &token, &selected);
|
||||
assert_eq!(report.client, Some(RuleOutcome::Applied));
|
||||
for half in HALVES {
|
||||
assert!(
|
||||
fake.position(&format!("add -net {half} -interface utun5 -ifa {source}"))
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changing_the_active_exit_keeps_both_halves_routed_through_its_utun() {
|
||||
let mut selected = plan(false, true);
|
||||
selected.client_source = Some("10.99.0.17".parse().unwrap());
|
||||
let mut fake = Fake::new();
|
||||
fake.half_interface = Some("utun5");
|
||||
let report = apply_plan(&|t, a, s| fake.run(t, a, s), &Mutex::new(None), &selected);
|
||||
assert_eq!(report.client, Some(RuleOutcome::Applied));
|
||||
for half in HALVES {
|
||||
assert!(
|
||||
fake.position(&format!(
|
||||
"change -net {half} -interface utun5 -ifa 10.99.0.17"
|
||||
))
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
assert_eq!(fake.count(" delete "), 0);
|
||||
|
||||
let mut foreign = Fake::new();
|
||||
foreign.half_interface = Some("utun9");
|
||||
let report = apply_plan(
|
||||
&|t, a, s| foreign.run(t, a, s),
|
||||
&Mutex::new(None),
|
||||
&selected,
|
||||
);
|
||||
assert!(matches!(report.client, Some(RuleOutcome::Failed(_))));
|
||||
assert_eq!(foreign.count(" change "), 0);
|
||||
assert_eq!(foreign.count(" delete "), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_routes_are_added_when_the_rules_did_not_load() {
|
||||
let mut fake = Fake::new();
|
||||
|
||||
@@ -141,13 +141,18 @@ fn bypass_script(index: u32, gateway: Ipv4Addr, addresses: &[Ipv4Addr]) -> Strin
|
||||
.collect();
|
||||
format!(
|
||||
"$ErrorActionPreference = 'Stop'\n\
|
||||
$keep = @(@({}) | ForEach-Object {{ \"$_/32\" }})\n\
|
||||
foreach ($p in $keep) {{\n\
|
||||
if (-not (Get-NetRoute -DestinationPrefix $p -InterfaceIndex {index} -NextHop '{gateway}' \
|
||||
-PolicyStore ActiveStore -ErrorAction SilentlyContinue)) {{\n\
|
||||
New-NetRoute -DestinationPrefix $p -InterfaceIndex {index} -NextHop '{gateway}' \
|
||||
-RouteMetric {BYPASS_METRIC} -PolicyStore ActiveStore | Out-Null\n\
|
||||
}}\n\
|
||||
}}\n\
|
||||
Get-NetRoute -AddressFamily IPv4 -PolicyStore ActiveStore -ErrorAction SilentlyContinue | \
|
||||
Where-Object {{ $_.RouteMetric -eq {BYPASS_METRIC} -and $_.DestinationPrefix.EndsWith('/32') }} | \
|
||||
Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue\n\
|
||||
foreach ($ip in @({})) {{\n\
|
||||
New-NetRoute -DestinationPrefix \"$ip/32\" -InterfaceIndex {index} -NextHop '{gateway}' \
|
||||
-RouteMetric {BYPASS_METRIC} -PolicyStore ActiveStore -ErrorAction SilentlyContinue | Out-Null\n\
|
||||
}}\n",
|
||||
Where-Object {{ $_.RouteMetric -eq {BYPASS_METRIC} -and $_.DestinationPrefix.EndsWith('/32') -and \
|
||||
($keep -notcontains $_.DestinationPrefix -or $_.InterfaceIndex -ne {index} -or $_.NextHop -ne '{gateway}') }} | \
|
||||
Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue\n",
|
||||
list.join(", ")
|
||||
)
|
||||
}
|
||||
@@ -159,14 +164,14 @@ fn halves_script(interface: &str) -> String {
|
||||
"$ErrorActionPreference = 'Stop'\n\
|
||||
$alias = {alias}\n\
|
||||
foreach ($p in '0.0.0.0/1', '128.0.0.0/1') {{\n\
|
||||
Get-NetRoute -DestinationPrefix $p -InterfaceAlias $alias -PolicyStore ActiveStore \
|
||||
-ErrorAction SilentlyContinue | Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue\n\
|
||||
if (Get-NetRoute -DestinationPrefix $p -InterfaceAlias $alias -NextHop '0.0.0.0' \
|
||||
-PolicyStore ActiveStore -ErrorAction SilentlyContinue) {{ continue }}\n\
|
||||
New-NetRoute -DestinationPrefix $p -InterfaceAlias $alias -NextHop '0.0.0.0' \
|
||||
-RouteMetric 1 -PolicyStore ActiveStore | Out-Null\n\
|
||||
}}\n\
|
||||
foreach ($p in '::/1', '8000::/1') {{\n\
|
||||
Get-NetRoute -DestinationPrefix $p -InterfaceAlias $alias -PolicyStore ActiveStore \
|
||||
-ErrorAction SilentlyContinue | Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue\n\
|
||||
if (Get-NetRoute -DestinationPrefix $p -InterfaceAlias $alias -NextHop '::' \
|
||||
-PolicyStore ActiveStore -ErrorAction SilentlyContinue) {{ continue }}\n\
|
||||
New-NetRoute -DestinationPrefix $p -InterfaceAlias $alias -NextHop '::' \
|
||||
-RouteMetric 1 -PolicyStore ActiveStore -ErrorAction SilentlyContinue | Out-Null\n\
|
||||
}}\n"
|
||||
@@ -197,13 +202,21 @@ fn bypass_addresses(
|
||||
resolve: Resolve<'_>,
|
||||
addresses: &[Ipv4Addr],
|
||||
hosts: &[String],
|
||||
overlay: &[Ipv4Range],
|
||||
) -> Vec<Ipv4Addr> {
|
||||
let mut all: std::collections::BTreeSet<Ipv4Addr> = addresses.iter().copied().collect();
|
||||
for host in hosts {
|
||||
all.extend(resolve(host));
|
||||
}
|
||||
all.into_iter()
|
||||
.filter(|a| !a.is_loopback() && !a.is_unspecified() && !a.is_multicast())
|
||||
.filter(|a| {
|
||||
!a.is_loopback()
|
||||
&& !a.is_unspecified()
|
||||
&& !a.is_multicast()
|
||||
&& !a.is_link_local()
|
||||
&& !a.is_broadcast()
|
||||
&& !overlay.iter().any(|range| range.contains(*a))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -216,7 +229,7 @@ fn apply_client(
|
||||
let gateway = run(&gateway_script(interface))?;
|
||||
let (index, hop) = parse_gateway(&gateway)
|
||||
.ok_or_else(|| format!("cannot read the default gateway from `{}`", gateway.trim()))?;
|
||||
let addresses = bypass_addresses(resolve, &plan.bypass, &plan.bypass_hosts);
|
||||
let addresses = bypass_addresses(resolve, &plan.bypass, &plan.bypass_hosts, &plan.overlay);
|
||||
run(&bypass_script(index, hop, &addresses))?;
|
||||
if let Err(why) = run(&halves_script(interface)) {
|
||||
// Do not leave a half-installed set: bypass routes alone are harmless
|
||||
@@ -437,8 +450,10 @@ mod tests {
|
||||
assert!(script.contains("-InterfaceIndex 12 -NextHop '192.168.1.1'"));
|
||||
assert!(script.contains("-RouteMetric 7373"));
|
||||
assert!(script.contains("-PolicyStore ActiveStore"));
|
||||
// Stale marked routes go first, and only /32 ones with our metric.
|
||||
assert!(script.find("Remove-NetRoute").unwrap() < script.find("New-NetRoute").unwrap());
|
||||
// Install missing routes before pruning stale entries. Existing paths
|
||||
// continue carrying the tunnel throughout another network's update.
|
||||
assert!(script.find("New-NetRoute").unwrap() < script.find("Remove-NetRoute").unwrap());
|
||||
assert!(script.contains("$keep -notcontains $_.DestinationPrefix"));
|
||||
assert!(script.contains("RouteMetric -eq 7373"));
|
||||
assert!(script.contains("EndsWith('/32')"));
|
||||
}
|
||||
@@ -446,6 +461,10 @@ mod tests {
|
||||
#[test]
|
||||
fn the_halves_go_through_the_overlay_and_ipv6_is_blackholed() {
|
||||
let script = halves_script("tsun0");
|
||||
assert!(
|
||||
!script.contains("Remove-NetRoute"),
|
||||
"reapplying must keep existing split defaults: {script}"
|
||||
);
|
||||
assert!(script.contains("'0.0.0.0/1', '128.0.0.0/1'"));
|
||||
assert!(script.contains("-InterfaceAlias $alias -NextHop '0.0.0.0'"));
|
||||
assert!(script.contains("'::/1', '8000::/1'"));
|
||||
@@ -473,6 +492,7 @@ mod tests {
|
||||
Ipv4Addr::UNSPECIFIED,
|
||||
],
|
||||
&["relay.example".into(), "gone.example".into()],
|
||||
&[],
|
||||
);
|
||||
assert_eq!(
|
||||
all,
|
||||
@@ -505,12 +525,36 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relay_dns_cannot_install_a_host_route_over_either_overlay() {
|
||||
let mut plan = client_plan();
|
||||
plan.overlay.push("10.99.0.0/24".parse().unwrap());
|
||||
let resolve = |_: &str| {
|
||||
["10.13.37.4", "10.99.0.6", "9.9.9.9"]
|
||||
.map(|ip| ip.parse().unwrap())
|
||||
.to_vec()
|
||||
};
|
||||
let calls = RefCell::new(Vec::new());
|
||||
let run = |script: &str| {
|
||||
calls.borrow_mut().push(script.to_string());
|
||||
Ok("12 192.168.1.1".to_string())
|
||||
};
|
||||
apply_client(&run, &resolve, &plan).unwrap();
|
||||
let calls = calls.borrow();
|
||||
let bypass = calls
|
||||
.iter()
|
||||
.find(|c| c.contains("-RouteMetric 7373"))
|
||||
.unwrap();
|
||||
assert!(bypass.contains("'9.9.9.9'") && bypass.contains("'138.201.61.182'"));
|
||||
assert!(!bypass.contains("'10.13.37.4'") && !bypass.contains("'10.99.0.6'"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_goes_through_the_overlay_when_the_bypass_cannot_be_written() {
|
||||
let run = |script: &str| -> Result<String, String> {
|
||||
if script.contains("Select-Object -First 1") {
|
||||
Ok("12 192.168.1.1".to_string())
|
||||
} else if script.contains("-RouteMetric 7373") && script.contains("foreach ($ip") {
|
||||
} else if script.contains("-RouteMetric 7373") && script.contains("New-NetRoute") {
|
||||
Err("Access is denied".to_string())
|
||||
} else {
|
||||
assert!(!script.contains("-NextHop '0.0.0.0'"), "{script}");
|
||||
|
||||
@@ -35,7 +35,7 @@ use super::hostrules::{
|
||||
RuleOutcome, offer_detail,
|
||||
};
|
||||
use super::packet::IpHeader;
|
||||
use super::router::{Route, RoutingTable};
|
||||
use super::router::{PacketSource, Route, RoutingTable};
|
||||
use super::tun::{TunDevice, TunFactory, TunRequest};
|
||||
use super::{Cidr, OverlayError};
|
||||
|
||||
@@ -428,6 +428,9 @@ impl Interface {
|
||||
ranges.sort_by_key(|range| (range.base, range.prefix_len));
|
||||
ranges.dedup();
|
||||
let (client, client_source) = self.routes.exit_client();
|
||||
#[cfg(windows)]
|
||||
self.device
|
||||
.set_exit_source(&self.wanted_addresses(), client_source);
|
||||
let overlay = self.routes.overlay_ranges();
|
||||
let (bypass, bypass_hosts) = if client && exit.needs_bypass() {
|
||||
self.underlay_targets(&overlay)
|
||||
@@ -521,6 +524,14 @@ impl Interface {
|
||||
state.report = Some(report);
|
||||
}
|
||||
|
||||
/// Whether the host routes its own transport by destination.
|
||||
pub(crate) fn needs_underlay_targets(&self) -> bool {
|
||||
self.host_rules
|
||||
.as_ref()
|
||||
.and_then(|rules| rules.exit_rules())
|
||||
.is_some_and(|exit| exit.needs_bypass())
|
||||
}
|
||||
|
||||
/// Tells the interface where a network's runtime reaches peers and
|
||||
/// relays outside the overlay. When the host needs those kept out of the
|
||||
/// exit node's default route and the set changed, the rules follow.
|
||||
@@ -545,13 +556,7 @@ impl Interface {
|
||||
map.insert(network, new.clone()) != Some(new)
|
||||
}
|
||||
};
|
||||
let needed = changed
|
||||
&& self.routes.exit_via().is_some()
|
||||
&& self
|
||||
.host_rules
|
||||
.as_ref()
|
||||
.and_then(|rules| rules.exit_rules())
|
||||
.is_some_and(|exit| exit.needs_bypass());
|
||||
let needed = changed && self.routes.exit_via().is_some() && self.needs_underlay_targets();
|
||||
if needed {
|
||||
self.sync_exit_rules().await;
|
||||
}
|
||||
@@ -831,12 +836,19 @@ impl Interface {
|
||||
self.tally.wrong_source.fetch_add(1, Ordering::Relaxed);
|
||||
return Err(Rejected::WrongFamily);
|
||||
};
|
||||
if !self.routes.may_send_from(network, peer, source) {
|
||||
let Some(origin) = self.routes.packet_source(network, peer, source) else {
|
||||
self.tally.wrong_source.fetch_add(1, Ordering::Relaxed);
|
||||
return Err(Rejected::WrongSource);
|
||||
}
|
||||
let broadcast = match header.destination() {
|
||||
IpAddr::V4(destination) if self.routes.is_broadcast(destination) => {
|
||||
};
|
||||
let broadcast = match (origin, header.destination()) {
|
||||
(PacketSource::ExitReply { local: Some(local) }, IpAddr::V4(destination))
|
||||
if destination == local =>
|
||||
{
|
||||
false
|
||||
}
|
||||
(PacketSource::Member, IpAddr::V4(destination))
|
||||
if self.routes.is_broadcast(destination) =>
|
||||
{
|
||||
if !super::broadcast::valid_udp(&packet)
|
||||
|| !self.routes.accepts_broadcast(network, peer, destination)
|
||||
{
|
||||
@@ -845,12 +857,10 @@ impl Interface {
|
||||
}
|
||||
true
|
||||
}
|
||||
IpAddr::V4(destination) if self.routes.is_local_destination(network, destination) => {
|
||||
false
|
||||
}
|
||||
// This agent is an exit node of this network: a member's packet
|
||||
// for the internet goes to the host, which masquerades it.
|
||||
IpAddr::V4(destination) if self.routes.accepts_exit_traffic(network, destination) => {
|
||||
(PacketSource::Member, IpAddr::V4(destination))
|
||||
if self.routes.is_local_destination(network, destination)
|
||||
|| self.routes.accepts_exit_traffic(network, destination) =>
|
||||
{
|
||||
false
|
||||
}
|
||||
_ => {
|
||||
@@ -1575,6 +1585,47 @@ mod tests {
|
||||
assert_eq!(interface.counters().received, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_exit_reply_must_terminate_locally_even_while_this_agent_offers_forwarding() {
|
||||
use super::super::broadcast::BroadcastPolicy;
|
||||
let (interface, device, routes, _, id) = interface(false).await;
|
||||
routes.set_exit(
|
||||
id,
|
||||
ExitPolicy {
|
||||
offer: true,
|
||||
via: Some(peer(2)),
|
||||
},
|
||||
);
|
||||
routes.set_broadcast(
|
||||
id,
|
||||
BroadcastPolicy {
|
||||
enabled: true,
|
||||
peers: [peer(2)].into_iter().collect(),
|
||||
},
|
||||
);
|
||||
|
||||
let udp = [0, 1, 0, 2, 0, 8, 0, 0];
|
||||
for destination in [Ipv4Addr::new(1, 1, 1, 1), Ipv4Addr::BROADCAST] {
|
||||
assert_eq!(
|
||||
interface
|
||||
.deliver(id, peer(2), ipv4(INTERNET, destination, &udp))
|
||||
.await,
|
||||
Err(Rejected::WrongDestination)
|
||||
);
|
||||
}
|
||||
assert_eq!(interface.counters().received, 0);
|
||||
|
||||
// The same peer can still return internet traffic to us, and can
|
||||
// originate its own ordinary packets under the network's offer.
|
||||
for packet in [ipv4(INTERNET, addr(1), &udp), ipv4(addr(2), INTERNET, &udp)] {
|
||||
interface
|
||||
.deliver(id, peer(2), packet.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(device.pop_to_os().await.unwrap(), packet);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_exit_node_hands_a_members_internet_packet_to_the_host_only_while_offering() {
|
||||
let (interface, device, routes, _carrier, id) = interface(false).await;
|
||||
@@ -1675,6 +1726,19 @@ mod tests {
|
||||
vec![Ipv4Addr::new(5, 6, 7, 8)]
|
||||
);
|
||||
|
||||
let second = network("second underlay");
|
||||
let second_path = Ipv4Addr::new(203, 0, 113, 10);
|
||||
interface.set_underlay(second, [second_path], []).await;
|
||||
assert_eq!(
|
||||
rules.exit().installed().unwrap().bypass,
|
||||
[Ipv4Addr::new(5, 6, 7, 8), second_path]
|
||||
);
|
||||
interface.set_underlay(second, [], []).await;
|
||||
assert_eq!(
|
||||
rules.exit().installed().unwrap().bypass,
|
||||
[Ipv4Addr::new(5, 6, 7, 8)]
|
||||
);
|
||||
|
||||
// Not using an exit node: nothing to keep direct.
|
||||
routes.set_exit(id, Default::default());
|
||||
interface.sync_exit_rules().await;
|
||||
|
||||
@@ -46,6 +46,7 @@ pub mod interface;
|
||||
pub mod packet;
|
||||
pub mod provision;
|
||||
pub mod router;
|
||||
pub mod source;
|
||||
pub mod tun;
|
||||
|
||||
pub use config::{Cidr, DEFAULT_INTERFACE_PREFIX, MAX_INTERFACE_NAME_LEN, interface_name};
|
||||
|
||||
@@ -76,7 +76,9 @@ enum Command {
|
||||
DelBroadcastRoute(String, Reply<()>),
|
||||
/// Send the host's default traffic through this interface, except what
|
||||
/// this user id sends.
|
||||
SetExitClient(String, u32, Reply<()>),
|
||||
SetExitClient(String, u32, Option<Ipv4Addr>, Reply<()>),
|
||||
/// Replace only the default route on an already protected interface.
|
||||
UpdateExitSource(String, Option<Ipv4Addr>, Reply<()>),
|
||||
/// Take those routing rules away again.
|
||||
ClearExitClient(Reply<()>),
|
||||
/// Stop the thread.
|
||||
@@ -213,10 +215,25 @@ impl RouteHandle {
|
||||
|
||||
/// Sends the host's default traffic through `interface`, except what the
|
||||
/// user id `uid` sends. Replaces what an earlier call set up.
|
||||
pub(crate) fn set_exit_client(&self, interface: &str, uid: u32) -> Result<(), OverlayError> {
|
||||
pub(crate) fn set_exit_client(
|
||||
&self,
|
||||
interface: &str,
|
||||
uid: u32,
|
||||
source: Option<Ipv4Addr>,
|
||||
) -> Result<(), OverlayError> {
|
||||
let interface = interface.to_string();
|
||||
call_thread(&self.commands, |reply| {
|
||||
Command::SetExitClient(interface, uid, reply)
|
||||
Command::SetExitClient(interface, uid, source, reply)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn update_exit_source(
|
||||
&self,
|
||||
interface: &str,
|
||||
source: Option<Ipv4Addr>,
|
||||
) -> Result<(), OverlayError> {
|
||||
call_thread(&self.commands, |reply| {
|
||||
Command::UpdateExitSource(interface.to_string(), source, reply)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -346,7 +363,8 @@ fn netlink_thread(requests: mpsc::Receiver<Command>) {
|
||||
| Command::Configure(_, reply)
|
||||
| Command::SetBroadcastRoute(_, _, reply)
|
||||
| Command::DelBroadcastRoute(_, reply)
|
||||
| Command::SetExitClient(_, _, reply) => {
|
||||
| Command::SetExitClient(_, _, _, reply)
|
||||
| Command::UpdateExitSource(_, _, reply) => {
|
||||
let _ = reply.send(Err(OverlayError::Unavailable(message)));
|
||||
}
|
||||
Command::ClearExitClient(reply) => {
|
||||
@@ -398,9 +416,19 @@ fn netlink_thread(requests: mpsc::Receiver<Command>) {
|
||||
});
|
||||
let _ = reply.send(result);
|
||||
}
|
||||
Command::SetExitClient(name, uid, reply) => {
|
||||
Command::SetExitClient(name, uid, source, reply) => {
|
||||
let result = NetAdmin::acquire().and_then(|guard| {
|
||||
let result = runtime.block_on(set_exit_client(&name, uid));
|
||||
let result = runtime.block_on(set_exit_client(&name, uid, source));
|
||||
drop(guard);
|
||||
result
|
||||
});
|
||||
let _ = reply.send(result);
|
||||
}
|
||||
Command::UpdateExitSource(name, source, reply) => {
|
||||
let result = NetAdmin::acquire().and_then(|guard| {
|
||||
let result = runtime.block_on(with_netlink(|handle| async move {
|
||||
replace_exit_default(&handle, &name, source).await
|
||||
}));
|
||||
drop(guard);
|
||||
result
|
||||
});
|
||||
@@ -704,13 +732,19 @@ fn is_exit_rule(rule: &RuleMessage) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn exit_default_route(index: Option<u32>) -> rtnetlink::packet_route::route::RouteMessage {
|
||||
fn exit_default_route(
|
||||
index: Option<u32>,
|
||||
source: Option<Ipv4Addr>,
|
||||
) -> rtnetlink::packet_route::route::RouteMessage {
|
||||
let mut builder = RouteMessageBuilder::<Ipv4Addr>::new()
|
||||
.destination_prefix(Ipv4Addr::UNSPECIFIED, 0)
|
||||
.table_id(EXIT_TABLE);
|
||||
if let Some(index) = index {
|
||||
builder = builder.output_interface(index).scope(RouteScope::Link);
|
||||
}
|
||||
if let Some(source) = source {
|
||||
builder = builder.pref_source(source);
|
||||
}
|
||||
builder.build()
|
||||
}
|
||||
|
||||
@@ -772,7 +806,12 @@ async fn remove_exit_rules(
|
||||
|
||||
async fn remove_exit_client(handle: &rtnetlink::Handle) -> Result<(), OverlayError> {
|
||||
remove_exit_rules(handle, IpVersion::V4).await?;
|
||||
match handle.route().del(exit_default_route(None)).execute().await {
|
||||
match handle
|
||||
.route()
|
||||
.del(exit_default_route(None, None))
|
||||
.execute()
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
// "No such process": no such route, which is the goal.
|
||||
Err(err) if err.to_string().contains("No such") => {}
|
||||
@@ -797,10 +836,32 @@ async fn remove_exit_client(handle: &rtnetlink::Handle) -> Result<(), OverlayErr
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace the default route atomically when the selected overlay address changes.
|
||||
async fn replace_exit_default(
|
||||
handle: &rtnetlink::Handle,
|
||||
name: &str,
|
||||
source: Option<Ipv4Addr>,
|
||||
) -> Result<(), OverlayError> {
|
||||
let index = link_index(handle, name).await.ok_or_else(|| {
|
||||
OverlayError::Unavailable(format!(
|
||||
"interface `{name}` disappeared before the exit node route could be added"
|
||||
))
|
||||
})?;
|
||||
handle
|
||||
.route()
|
||||
.add(exit_default_route(Some(index), source))
|
||||
.replace()
|
||||
.execute()
|
||||
.await
|
||||
.map_err(|err| {
|
||||
OverlayError::Unavailable(format!("cannot set the exit node default route: {err}"))
|
||||
})
|
||||
}
|
||||
|
||||
/// Sets up the using side of an exit node.
|
||||
///
|
||||
/// ```text
|
||||
/// ip route replace default dev <if> table 0x7473
|
||||
/// ip route replace default dev <if> src <selected overlay address> table 0x7473
|
||||
/// ip rule add priority 5205 fwmark 0x40000000/0x40000000 lookup main
|
||||
/// ip rule add priority 5206 uidrange <uid>-<uid> lookup main
|
||||
/// ip rule add priority 5290 lookup main suppress_prefixlength 0
|
||||
@@ -813,24 +874,17 @@ async fn remove_exit_client(handle: &rtnetlink::Handle) -> Result<(), OverlayErr
|
||||
/// What an earlier call left is removed first, so repeating it is safe, and
|
||||
/// the rules go in last, so a failure part way never leaves a rule that
|
||||
/// sends traffic to a table with no route in it.
|
||||
async fn set_exit_client(name: &str, uid: u32) -> Result<(), OverlayError> {
|
||||
async fn set_exit_client(
|
||||
name: &str,
|
||||
uid: u32,
|
||||
source: Option<Ipv4Addr>,
|
||||
) -> Result<(), OverlayError> {
|
||||
with_netlink(|handle| async move {
|
||||
let index = link_index(&handle, name).await.ok_or_else(|| {
|
||||
OverlayError::Unavailable(format!(
|
||||
"interface `{name}` disappeared before the exit node routes could be added"
|
||||
))
|
||||
})?;
|
||||
remove_exit_client(&handle).await?;
|
||||
let fail = |what: &str, err: rtnetlink::Error| {
|
||||
OverlayError::Unavailable(format!("cannot add the exit node {what}: {err}"))
|
||||
};
|
||||
handle
|
||||
.route()
|
||||
.add(exit_default_route(Some(index)))
|
||||
.replace()
|
||||
.execute()
|
||||
.await
|
||||
.map_err(|err| fail("default route", err))?;
|
||||
replace_exit_default(&handle, name, source).await?;
|
||||
|
||||
add_mark_bypass(&handle, false).await?;
|
||||
|
||||
@@ -1190,13 +1244,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn the_default_route_of_the_exit_table_names_the_table_and_the_interface() {
|
||||
let route = exit_default_route(Some(7));
|
||||
let source = Ipv4Addr::new(10, 99, 0, 1);
|
||||
let route = exit_default_route(Some(7), Some(source));
|
||||
assert_eq!(route.header.destination_prefix_length, 0);
|
||||
let debug = format!("{route:?}");
|
||||
assert!(debug.contains(&format!("Table({EXIT_TABLE})")), "{debug}");
|
||||
assert!(debug.contains("Oif(7)"), "{debug}");
|
||||
assert!(route.attributes.contains(
|
||||
&rtnetlink::packet_route::route::RouteAttribute::PrefSource(source.into())
|
||||
));
|
||||
// Deleting names no interface, so it matches whatever it was added on.
|
||||
assert!(!format!("{:?}", exit_default_route(None)).contains("Oif"));
|
||||
assert!(!format!("{:?}", exit_default_route(None, None)).contains("Oif"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -40,6 +40,12 @@ pub struct Route {
|
||||
pub peer: EndpointId,
|
||||
}
|
||||
|
||||
/// An internet source is valid only for a reply to our address in the exit's network.
|
||||
pub(super) enum PacketSource {
|
||||
Member,
|
||||
ExitReply { local: Option<Ipv4Addr> },
|
||||
}
|
||||
|
||||
/// A network's exit-node settings, as far as packets are concerned.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub struct ExitPolicy {
|
||||
@@ -120,7 +126,29 @@ impl RoutingTable {
|
||||
/// interface an address can belong to only one network, and guessing
|
||||
/// which would send somebody's traffic to a stranger.
|
||||
pub fn set_network(&self, network: NetworkId, routes: NetworkRoutes) -> Result<(), RouteError> {
|
||||
self.replace_network(&mut self.write(), network, routes)
|
||||
}
|
||||
|
||||
/// A fresh allocation snapshot cannot change the operator's exit settings.
|
||||
pub(crate) fn update_allocations(
|
||||
&self,
|
||||
network: NetworkId,
|
||||
mut routes: NetworkRoutes,
|
||||
) -> Result<(), RouteError> {
|
||||
let mut networks = self.write();
|
||||
routes.exit = networks
|
||||
.get(&network)
|
||||
.map(|current| current.exit)
|
||||
.unwrap_or_default();
|
||||
self.replace_network(&mut networks, network, routes)
|
||||
}
|
||||
|
||||
fn replace_network(
|
||||
&self,
|
||||
networks: &mut HashMap<NetworkId, NetworkRoutes>,
|
||||
network: NetworkId,
|
||||
routes: NetworkRoutes,
|
||||
) -> Result<(), RouteError> {
|
||||
if let Some(range) = routes.range {
|
||||
for (other, existing) in networks.iter() {
|
||||
if *other == network {
|
||||
@@ -139,9 +167,12 @@ impl RoutingTable {
|
||||
}
|
||||
}
|
||||
}
|
||||
if routes.exit.via.is_some() {
|
||||
clear_other_exits(networks, network);
|
||||
}
|
||||
networks.insert(network, routes);
|
||||
self.broadcast
|
||||
.store(Arc::new(BroadcastTable::build(&networks)));
|
||||
.store(Arc::new(BroadcastTable::build(networks)));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -172,8 +203,16 @@ impl RoutingTable {
|
||||
/// A network that has no entry yet (its range is not agreed) takes them
|
||||
/// from [`NetworkRoutes::exit`] when it is added.
|
||||
pub fn set_exit(&self, network: NetworkId, policy: ExitPolicy) {
|
||||
if let Some(routes) = self.write().get_mut(&network) {
|
||||
routes.exit = policy;
|
||||
self.update_exit(network, |current| *current = policy);
|
||||
}
|
||||
|
||||
pub(crate) fn update_exit(&self, network: NetworkId, update: impl FnOnce(&mut ExitPolicy)) {
|
||||
let mut networks = self.write();
|
||||
if let Some(routes) = networks.get_mut(&network) {
|
||||
update(&mut routes.exit);
|
||||
if routes.exit.via.is_some() {
|
||||
clear_other_exits(&mut networks, network);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,20 +280,30 @@ impl RoutingTable {
|
||||
/// internet carries the internet's addresses, so from *that* peer any
|
||||
/// source outside the overlay ranges is accepted.
|
||||
pub fn may_send_from(&self, network: NetworkId, peer: EndpointId, source: Ipv4Addr) -> bool {
|
||||
self.packet_source(network, peer, source).is_some()
|
||||
}
|
||||
|
||||
pub(super) fn packet_source(
|
||||
&self,
|
||||
network: NetworkId,
|
||||
peer: EndpointId,
|
||||
source: Ipv4Addr,
|
||||
) -> Option<PacketSource> {
|
||||
let networks = self.read();
|
||||
let Some(routes) = networks.get(&network) else {
|
||||
return false;
|
||||
};
|
||||
let routes = networks.get(&network)?;
|
||||
if routes
|
||||
.peers
|
||||
.iter()
|
||||
.any(|(address, holder)| *address == source && *holder == peer)
|
||||
{
|
||||
return true;
|
||||
return Some(PacketSource::Member);
|
||||
}
|
||||
routes.exit.via == Some(peer)
|
||||
(exit_via(&networks) == Some((network, peer))
|
||||
&& is_internet_destination(source)
|
||||
&& !in_any_range(&networks, source)
|
||||
&& !in_any_range(&networks, source))
|
||||
.then_some(PacketSource::ExitReply {
|
||||
local: routes.local,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether this agent, as an exit node of `network`, takes a member's
|
||||
@@ -275,8 +324,7 @@ impl RoutingTable {
|
||||
|
||||
/// The network and member this device sends its internet traffic through.
|
||||
///
|
||||
/// One default route, so one answer; if several networks claim one (they
|
||||
/// should not) the lowest network id decides, so two runs agree.
|
||||
/// Choosing another exit replaces the previous one under the table's write lock.
|
||||
pub fn exit_via(&self) -> Option<(NetworkId, EndpointId)> {
|
||||
exit_via(&self.read())
|
||||
}
|
||||
@@ -423,12 +471,19 @@ fn in_any_range(networks: &HashMap<NetworkId, NetworkRoutes>, address: Ipv4Addr)
|
||||
.any(|routes| routes.range.is_some_and(|range| range.contains(address)))
|
||||
}
|
||||
|
||||
/// The exit node in use, if any, from the lowest network that names one.
|
||||
fn clear_other_exits(networks: &mut HashMap<NetworkId, NetworkRoutes>, selected: NetworkId) {
|
||||
for (id, routes) in networks {
|
||||
if *id != selected {
|
||||
routes.exit.via = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Only the selected network can have an exit peer.
|
||||
fn exit_via(networks: &HashMap<NetworkId, NetworkRoutes>) -> Option<(NetworkId, EndpointId)> {
|
||||
networks
|
||||
.iter()
|
||||
.filter_map(|(network, routes)| Some((*network, routes.exit.via?)))
|
||||
.min_by_key(|(network, _)| *network)
|
||||
.find_map(|(network, routes)| Some((*network, routes.exit.via?)))
|
||||
}
|
||||
|
||||
/// Whether two ranges share any address.
|
||||
@@ -745,6 +800,46 @@ mod tests {
|
||||
|
||||
const INTERNET: Ipv4Addr = Ipv4Addr::new(93, 184, 216, 34);
|
||||
|
||||
#[test]
|
||||
fn refreshing_either_networks_addresses_preserves_the_last_exit_choice() {
|
||||
let table = RoutingTable::new();
|
||||
let (a, b) = (network("first"), network("second"));
|
||||
let first = with_exit(true, Some(peer(2)));
|
||||
let second = NetworkRoutes {
|
||||
range: Some("10.99.0.0/24".parse().unwrap()),
|
||||
local: Some(Ipv4Addr::new(10, 99, 0, 1)),
|
||||
..Default::default()
|
||||
};
|
||||
table.set_network(a, first.clone()).unwrap();
|
||||
table.set_network(b, second.clone()).unwrap();
|
||||
table.set_exit(
|
||||
b,
|
||||
ExitPolicy {
|
||||
offer: false,
|
||||
via: Some(peer(3)),
|
||||
},
|
||||
);
|
||||
|
||||
table.update_allocations(a, first).unwrap();
|
||||
table.update_allocations(b, second).unwrap();
|
||||
assert_eq!(
|
||||
table.exit_client(),
|
||||
(true, Some(Ipv4Addr::new(10, 99, 0, 1)))
|
||||
);
|
||||
assert_eq!(table.exit_via(), Some((b, peer(3))));
|
||||
assert_eq!(
|
||||
table.exit_settings(a).unwrap().0,
|
||||
ExitPolicy {
|
||||
offer: true,
|
||||
via: None
|
||||
}
|
||||
);
|
||||
table.remove_network(a);
|
||||
assert_eq!(table.exit_via(), Some((b, peer(3))));
|
||||
table.remove_network(b);
|
||||
assert_eq!(table.exit_via(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_an_exit_node_the_internet_has_nowhere_to_go() {
|
||||
let table = RoutingTable::new();
|
||||
@@ -819,7 +914,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_exit_choices_resolve_to_the_lowest_network_id() {
|
||||
fn competing_exit_choices_use_the_same_peer_for_requests_and_replies() {
|
||||
let table = RoutingTable::new();
|
||||
let (a, b) = (network("one"), network("two"));
|
||||
table
|
||||
@@ -838,9 +933,10 @@ mod tests {
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let (chosen, _) = table.exit_via().unwrap();
|
||||
assert_eq!(chosen, a.min(b));
|
||||
assert_eq!(table.route(INTERNET).unwrap().network, a.min(b));
|
||||
assert_eq!(table.exit_via(), Some((b, peer(9))));
|
||||
assert_eq!(table.route(INTERNET).unwrap().network, b);
|
||||
assert!(table.may_send_from(b, peer(9), INTERNET));
|
||||
assert!(!table.may_send_from(a, peer(2), INTERNET));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
//! Normalize Android's primary IPv4 source at the local VPN boundary.
|
||||
use crate::plan::VpnPlan;
|
||||
//! Translate host-selected IPv4 aliases at the local packet interface.
|
||||
use super::Cidr;
|
||||
use super::packet::{Ipv4Reassembly, fragment_ipv4};
|
||||
use bytes::Bytes;
|
||||
use smoltcp::wire::{Ipv4Cidr, Ipv4Packet};
|
||||
use std::collections::HashMap;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::time::{Duration, Instant};
|
||||
use tsunagi::overlay::packet::{Ipv4Reassembly, fragment_ipv4};
|
||||
|
||||
mod icmp;
|
||||
|
||||
#[cfg(any(all(windows, feature = "tun-device"), test))]
|
||||
pub(crate) mod windows;
|
||||
|
||||
// No mappings are persisted, and a new flow cannot evict a live socket.
|
||||
const MAX_FLOWS: usize = 4096;
|
||||
const MAX_FRAGMENTED: usize = 16;
|
||||
@@ -74,16 +77,27 @@ struct Binding {
|
||||
expires: Instant,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
/// How the host chooses a source at the TUN boundary.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum SourceMode {
|
||||
/// Android can choose the primary VPN address even for another mesh.
|
||||
Primary,
|
||||
/// Windows chooses the matching subnet for mesh traffic, but may select
|
||||
/// any local alias for a default route.
|
||||
ExitOnly,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Domains {
|
||||
aliases: Vec<Ipv4Cidr>,
|
||||
exit: Option<Ipv4Addr>,
|
||||
mode: SourceMode,
|
||||
}
|
||||
|
||||
impl Domains {
|
||||
fn from_plan(plan: &VpnPlan) -> Self {
|
||||
let aliases = plan
|
||||
.addresses_in_order()
|
||||
.into_iter()
|
||||
fn new(addresses: &[Cidr], exit: Option<Ipv4Addr>, mode: SourceMode) -> Self {
|
||||
let aliases = addresses
|
||||
.iter()
|
||||
.filter_map(|cidr| match cidr.addr {
|
||||
IpAddr::V4(addr) if cidr.prefix_len <= 32 => {
|
||||
Some(Ipv4Cidr::new(addr, cidr.prefix_len))
|
||||
@@ -93,10 +107,15 @@ impl Domains {
|
||||
.collect();
|
||||
Self {
|
||||
aliases,
|
||||
exit: match (plan.full_tunnel, plan.exit) {
|
||||
(true, Some(IpAddr::V4(addr))) => Some(addr),
|
||||
_ => None,
|
||||
},
|
||||
exit,
|
||||
mode,
|
||||
}
|
||||
}
|
||||
|
||||
fn primary(&self) -> Option<Ipv4Addr> {
|
||||
match self.mode {
|
||||
SourceMode::Primary => self.aliases.first().map(Ipv4Cidr::address),
|
||||
SourceMode::ExitOnly => None,
|
||||
}
|
||||
}
|
||||
fn has(&self, addr: Ipv4Addr) -> bool {
|
||||
@@ -112,15 +131,15 @@ impl Domains {
|
||||
return None;
|
||||
}
|
||||
if let Some(prefix) = self.aliases.iter().find(|p| p.contains_addr(&remote)) {
|
||||
return (prefix.broadcast() != Some(remote)).then(|| prefix.address());
|
||||
return (self.mode == SourceMode::Primary && prefix.broadcast() != Some(remote))
|
||||
.then(|| prefix.address());
|
||||
}
|
||||
self.exit
|
||||
}
|
||||
}
|
||||
|
||||
/// Android's VPN routes name only the interface. The local host socket keeps
|
||||
/// its address while authenticated mesh traffic uses the subnet's own alias.
|
||||
pub(crate) struct SourceFlows {
|
||||
/// Bounded flow bindings restore replies to the socket that opened each flow.
|
||||
pub struct SourceFlows {
|
||||
domains: Domains,
|
||||
mtu: u32,
|
||||
flows: HashMap<Ipv4Addr, HashMap<WireFlow, Binding>>,
|
||||
@@ -131,10 +150,11 @@ pub(crate) struct SourceFlows {
|
||||
}
|
||||
|
||||
impl SourceFlows {
|
||||
pub(crate) fn new(plan: &VpnPlan) -> Self {
|
||||
/// Addresses are in the same order as on the device, primary first where applicable.
|
||||
pub fn new(addresses: &[Cidr], exit: Option<Ipv4Addr>, mtu: u32, mode: SourceMode) -> Self {
|
||||
Self {
|
||||
domains: Domains::from_plan(plan),
|
||||
mtu: plan.mtu,
|
||||
domains: Domains::new(addresses, exit, mode),
|
||||
mtu,
|
||||
flows: HashMap::new(),
|
||||
primary_has_translations: false,
|
||||
last_sweep: Instant::now(),
|
||||
@@ -143,9 +163,10 @@ impl SourceFlows {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn reconfigure(&mut self, plan: &VpnPlan) {
|
||||
self.domains = Domains::from_plan(plan);
|
||||
self.mtu = plan.mtu;
|
||||
/// Keep live bindings whose host and wire addresses still belong to the same domains.
|
||||
pub fn reconfigure(&mut self, addresses: &[Cidr], exit: Option<Ipv4Addr>, mtu: u32) {
|
||||
self.domains = Domains::new(addresses, exit, self.domains.mode);
|
||||
self.mtu = mtu;
|
||||
self.flows.retain(|_, table| {
|
||||
table.retain(|wire, entry| {
|
||||
self.domains.has(entry.host) && self.domains.owner(wire.remote) == Some(wire.local)
|
||||
@@ -159,7 +180,7 @@ impl SourceFlows {
|
||||
}
|
||||
|
||||
fn refresh_primary(&mut self) {
|
||||
if let Some(primary) = self.domains.aliases.first().map(Ipv4Cidr::address) {
|
||||
if let Some(primary) = self.domains.primary() {
|
||||
self.primary_has_translations = self
|
||||
.flows
|
||||
.get(&primary)
|
||||
@@ -170,11 +191,13 @@ impl SourceFlows {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn outbound(&mut self, packet: Bytes) -> Vec<Bytes> {
|
||||
/// Packets read from the host.
|
||||
pub fn outbound(&mut self, packet: Bytes) -> Vec<Bytes> {
|
||||
self.process(packet, true)
|
||||
}
|
||||
|
||||
pub(crate) fn inbound(&mut self, packet: Bytes) -> Vec<Bytes> {
|
||||
/// Packets admitted by the mesh and destined for the host.
|
||||
pub fn inbound(&mut self, packet: Bytes) -> Vec<Bytes> {
|
||||
self.process(packet, false)
|
||||
}
|
||||
|
||||
@@ -186,7 +209,7 @@ impl SourceFlows {
|
||||
return vec![];
|
||||
};
|
||||
let h = usize::from(ip.header_len());
|
||||
if h < 20 || usize::from(ip.total_len()) != packet.len() || !ip.verify_checksum() {
|
||||
if h < 20 || usize::from(ip.total_len()) != packet.len() {
|
||||
return vec![];
|
||||
}
|
||||
let (local, remote) = if outbound {
|
||||
@@ -197,11 +220,27 @@ impl SourceFlows {
|
||||
// ICMP errors can come from a router other than the original peer.
|
||||
let is_icmp = packet[9] == 1;
|
||||
let owner = self.domains.owner(remote);
|
||||
let primary = self.domains.aliases[0].address();
|
||||
let fragmented = ip.more_frags() || ip.frag_offset() != 0;
|
||||
if self.domains.mode == SourceMode::ExitOnly {
|
||||
// A mesh router can report PMTU for an internet flow whose source
|
||||
// we translated. All other native mesh and forwarded packets pass
|
||||
// directly, including fragments and packets headed to the gateway.
|
||||
let exit_error = !outbound
|
||||
&& Some(local) == self.domains.exit
|
||||
&& is_icmp
|
||||
&& (fragmented || matches!(packet.get(h), Some(3 | 11 | 12)));
|
||||
if !self.domains.has(local) || (owner.is_none() && !exit_error) {
|
||||
return vec![packet];
|
||||
}
|
||||
}
|
||||
if !ip.verify_checksum() {
|
||||
return vec![];
|
||||
}
|
||||
let primary = self.domains.primary();
|
||||
// The kernel already uses the primary address for its own subnet. A
|
||||
// primary change can leave earlier translated sockets draining there.
|
||||
if local == primary
|
||||
&& (!outbound || owner == Some(primary))
|
||||
if Some(local) == primary
|
||||
&& (!outbound || owner == primary)
|
||||
&& !self.primary_has_translations
|
||||
{
|
||||
return vec![packet];
|
||||
@@ -223,7 +262,6 @@ impl SourceFlows {
|
||||
self.refresh_primary();
|
||||
self.last_sweep = now;
|
||||
}
|
||||
let fragmented = u16::from_be_bytes([packet[6], packet[7]]) & 0x3fff != 0;
|
||||
let packet = if fragmented {
|
||||
let parts = if outbound {
|
||||
&mut self.outgoing_parts
|
||||
@@ -253,9 +291,15 @@ impl SourceFlows {
|
||||
.is_some_and(|kind| matches!(kind, 3 | 11 | 12))
|
||||
{
|
||||
icmp::rewrite_error(packet, h, !outbound, |quote, quote_outbound| {
|
||||
let flow = WireFlow::parse(quote, quote_outbound)?;
|
||||
let binding = WireFlow::parse(quote, quote_outbound)
|
||||
.and_then(|flow| self.domains.owner(flow.remote).map(|alias| (flow, alias)));
|
||||
let Some((flow, alias)) = binding else {
|
||||
// The quote passed validation but never required exit translation,
|
||||
// for example a native socket talking to a peer inside the mesh.
|
||||
return (self.domains.mode == SourceMode::ExitOnly).then_some((local, local));
|
||||
};
|
||||
let wire = WireFlow {
|
||||
local: self.domains.owner(flow.remote)?,
|
||||
local: alias,
|
||||
..flow
|
||||
};
|
||||
let entry = self
|
||||
@@ -264,8 +308,10 @@ impl SourceFlows {
|
||||
.and_then(|table| table.get(&wire))
|
||||
.filter(|entry| now < entry.expires);
|
||||
let Some(entry) = entry else {
|
||||
return (wire.local == primary && flow.local == primary)
|
||||
.then_some((primary, primary));
|
||||
return (wire.local == flow.local
|
||||
&& (Some(wire.local) == primary
|
||||
|| self.domains.mode == SourceMode::ExitOnly))
|
||||
.then_some((wire.local, wire.local));
|
||||
};
|
||||
if quote_outbound {
|
||||
(flow.local == wire.local).then_some((wire.local, entry.host))
|
||||
@@ -333,17 +379,21 @@ impl SourceFlows {
|
||||
table.remove(&wire);
|
||||
}
|
||||
if !table.contains_key(&wire) {
|
||||
if alias == self.domains.aliases.first()?.address() && local == alias {
|
||||
if Some(alias) == self.domains.primary() && local == alias {
|
||||
return Some(packet);
|
||||
}
|
||||
if table.len() >= MAX_FLOWS {
|
||||
return None;
|
||||
}
|
||||
if outbound && local != alias {
|
||||
let primary = self.domains.aliases.first()?.address();
|
||||
if local != primary || flow.protocol == 6 && data[13] & 0x12 != 2 {
|
||||
return None;
|
||||
}
|
||||
if outbound
|
||||
&& local != alias
|
||||
&& (self
|
||||
.domains
|
||||
.primary()
|
||||
.is_some_and(|primary| primary != local)
|
||||
|| flow.protocol == 6 && data[13] & 0x12 != 2)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
let entry = table.entry(wire).or_insert(Binding {
|
||||
@@ -356,7 +406,7 @@ impl SourceFlows {
|
||||
let wildcard_reply = entry.remote_initiated
|
||||
&& entry.host == alias
|
||||
&& flow.protocol == 17
|
||||
&& self.domains.aliases.first()?.address() == local;
|
||||
&& self.domains.primary() == Some(local);
|
||||
if !wildcard_reply {
|
||||
return None;
|
||||
}
|
||||
@@ -416,21 +466,16 @@ fn update_checksum(checksum: u16, old: Ipv4Addr, new: Ipv4Addr) -> u16 {
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
||||
use super::*;
|
||||
use tsunagi::overlay::Cidr;
|
||||
|
||||
const FIRST: Ipv4Addr = Ipv4Addr::new(10, 1, 0, 1);
|
||||
const SECOND: Ipv4Addr = Ipv4Addr::new(10, 2, 0, 1);
|
||||
const PEER: Ipv4Addr = Ipv4Addr::new(10, 2, 0, 8);
|
||||
|
||||
fn plan() -> VpnPlan {
|
||||
VpnPlan {
|
||||
addresses: vec![
|
||||
Cidr::new(FIRST.into(), 24).unwrap(),
|
||||
Cidr::new(SECOND.into(), 24).unwrap(),
|
||||
],
|
||||
mtu: 1280,
|
||||
..Default::default()
|
||||
}
|
||||
fn aliases() -> Vec<Cidr> {
|
||||
vec![
|
||||
Cidr::new(FIRST.into(), 24).unwrap(),
|
||||
Cidr::new(SECOND.into(), 24).unwrap(),
|
||||
]
|
||||
}
|
||||
|
||||
fn udp(src: Ipv4Addr, dst: Ipv4Addr, sport: u16, dport: u16, payload: &[u8]) -> Bytes {
|
||||
@@ -455,7 +500,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn connected_udp_keeps_its_kernel_address_while_the_peer_sees_the_right_alias() {
|
||||
let mut flows = SourceFlows::new(&plan());
|
||||
let mut flows = SourceFlows::new(&aliases(), None, 1280, SourceMode::Primary);
|
||||
let request = udp(FIRST, PEER, 4123, 1234, b"request");
|
||||
assert_eq!(
|
||||
flows.outbound(request),
|
||||
@@ -484,9 +529,68 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_exit_accepts_any_local_alias_and_restores_external_replies() {
|
||||
let mut flows = SourceFlows::new(&aliases(), Some(FIRST), 1280, SourceMode::ExitOnly);
|
||||
let internet = Ipv4Addr::new(203, 0, 113, 2);
|
||||
let request = udp(SECOND, internet, 4123, 443, b"external");
|
||||
assert_eq!(
|
||||
flows.outbound(request),
|
||||
[udp(FIRST, internet, 4123, 443, b"external")]
|
||||
);
|
||||
assert_eq!(
|
||||
flows.inbound(udp(internet, FIRST, 443, 4123, b"reply")),
|
||||
[udp(internet, SECOND, 443, 4123, b"reply")]
|
||||
);
|
||||
// An explicitly bound socket cannot take replies from this flow.
|
||||
assert!(
|
||||
flows
|
||||
.outbound(udp(FIRST, internet, 4123, 443, b"collision"))
|
||||
.is_empty()
|
||||
);
|
||||
// An address in either overlay, including the gateway itself, stays native.
|
||||
let mesh = udp(SECOND, PEER, 4123, 443, b"mesh");
|
||||
assert_eq!(flows.outbound(mesh.clone()), [mesh]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn wintun_normalizes_only_external_flows_while_an_exit_is_selected() {
|
||||
use super::windows::ExitSourceTun;
|
||||
use crate::overlay::{MemoryTun, TunDevice};
|
||||
|
||||
let device = MemoryTun::new("test", 1280);
|
||||
let tun = ExitSourceTun::new(device.clone());
|
||||
let internet = Ipv4Addr::new(203, 0, 113, 2);
|
||||
let request = udp(FIRST, internet, 4000, 80, &[1; 1600]);
|
||||
let on_wire = udp(SECOND, internet, 4000, 80, &[1; 1600]);
|
||||
tun.set_exit_source(&aliases(), Some(SECOND));
|
||||
for part in fragment_ipv4(request.clone(), 1280) {
|
||||
device.push_from_os(part);
|
||||
}
|
||||
for expected in fragment_ipv4(on_wire, 1280) {
|
||||
assert_eq!(tun.recv().await, Some(expected));
|
||||
}
|
||||
// Periodic exit rule refreshes must preserve the original socket.
|
||||
tun.set_exit_source(&aliases(), Some(SECOND));
|
||||
tun.send(udp(internet, SECOND, 80, 4000, b"reply"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
device.pop_to_os().await,
|
||||
Some(udp(internet, FIRST, 80, 4000, b"reply"))
|
||||
);
|
||||
let forwarded = udp(PEER, internet, 4000, 80, b"forwarded");
|
||||
device.push_from_os(forwarded.clone());
|
||||
assert_eq!(tun.recv().await, Some(forwarded));
|
||||
|
||||
tun.set_exit_source(&aliases(), None);
|
||||
device.push_from_os(request.clone());
|
||||
assert_eq!(tun.recv().await, Some(request));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proper_bound_flows_and_limited_broadcast_keep_their_identity() {
|
||||
let mut flows = SourceFlows::new(&plan());
|
||||
let mut flows = SourceFlows::new(&aliases(), None, 1280, SourceMode::Primary);
|
||||
let native = udp(SECOND, PEER, 3000, 3001, b"bound");
|
||||
assert_eq!(flows.outbound(native.clone()), vec![native]);
|
||||
assert!(
|
||||
@@ -533,15 +637,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn tcp_keeps_direction_and_bindings_survive_unrelated_plans() {
|
||||
let mut plan = plan();
|
||||
let mut flows = SourceFlows::new(&plan);
|
||||
let mut aliases = aliases();
|
||||
let mut flows = SourceFlows::new(&aliases, None, 1280, SourceMode::Primary);
|
||||
assert!(flows.outbound(tcp(FIRST, PEER, 333, 443, 16)).is_empty());
|
||||
assert_eq!(
|
||||
flows.outbound(tcp(FIRST, PEER, 333, 443, 2)),
|
||||
[tcp(SECOND, PEER, 333, 443, 2)]
|
||||
);
|
||||
plan.broadcast = !plan.broadcast;
|
||||
flows.reconfigure(&plan);
|
||||
flows.reconfigure(&aliases, None, 1280);
|
||||
assert_eq!(
|
||||
flows.inbound(tcp(PEER, SECOND, 443, 333, 18)),
|
||||
[tcp(PEER, FIRST, 443, 333, 18)]
|
||||
@@ -552,8 +655,8 @@ mod tests {
|
||||
assert_eq!(flows.inbound(inbound.clone()), [inbound]);
|
||||
let syn_ack = tcp(SECOND, PEER, 80, 12345, 18);
|
||||
assert_eq!(flows.outbound(syn_ack.clone()), [syn_ack]);
|
||||
plan.addresses.remove(0);
|
||||
flows.reconfigure(&plan);
|
||||
aliases.remove(0);
|
||||
flows.reconfigure(&aliases, None, 1280);
|
||||
assert!(
|
||||
!flows
|
||||
.flows
|
||||
@@ -564,12 +667,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn a_new_primary_drains_earlier_translations_and_passes_its_own_packets() {
|
||||
let mut plan = plan();
|
||||
let mut flows = SourceFlows::new(&plan);
|
||||
let mut aliases = aliases();
|
||||
let mut flows = SourceFlows::new(&aliases, None, 1280, SourceMode::Primary);
|
||||
assert_eq!(flows.outbound(udp(FIRST, PEER, 2222, 53, b"q")).len(), 1);
|
||||
plan.full_tunnel = true;
|
||||
plan.exit = Some(SECOND.into());
|
||||
flows.reconfigure(&plan);
|
||||
aliases.swap(0, 1);
|
||||
flows.reconfigure(&aliases, Some(SECOND), 1280);
|
||||
assert_eq!(
|
||||
flows.inbound(udp(PEER, SECOND, 53, 2222, b"a")),
|
||||
[udp(PEER, FIRST, 53, 2222, b"a")]
|
||||
@@ -583,8 +685,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn untracked_primary_errors_and_point_to_point_destinations_are_preserved() {
|
||||
let mut plan = plan();
|
||||
let mut flows = SourceFlows::new(&plan);
|
||||
let mut aliases = aliases();
|
||||
let mut flows = SourceFlows::new(&aliases, None, 1280, SourceMode::Primary);
|
||||
let router = Ipv4Addr::new(10, 1, 0, 7);
|
||||
let mut unreachable = vec![3, 1, 0, 0, 0, 0, 0, 0];
|
||||
unreachable.extend_from_slice(&udp(FIRST, router, 50_000, 7, b"probe")[..28]);
|
||||
@@ -594,8 +696,8 @@ mod tests {
|
||||
let directed = udp(FIRST, Ipv4Addr::new(10, 2, 0, 255), 5, 6, b"broadcast");
|
||||
assert_eq!(flows.outbound(directed.clone()), [directed]);
|
||||
let point = Ipv4Addr::new(10, 2, 0, 0);
|
||||
plan.addresses[1] = Cidr::new(point.into(), 31).unwrap();
|
||||
flows.reconfigure(&plan);
|
||||
aliases[1] = Cidr::new(point.into(), 31).unwrap();
|
||||
flows.reconfigure(&aliases, None, 1280);
|
||||
assert_eq!(
|
||||
flows.outbound(udp(FIRST, SECOND, 5, 6, b"p2p")),
|
||||
[udp(point, SECOND, 5, 6, b"p2p")]
|
||||
@@ -604,7 +706,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn echo_ids_can_match_in_both_directions() {
|
||||
let mut flows = SourceFlows::new(&plan());
|
||||
let mut flows = SourceFlows::new(&aliases(), None, 1280, SourceMode::Primary);
|
||||
let message = |src, dst, kind| {
|
||||
use smoltcp::wire::Icmpv4Packet;
|
||||
let mut data = [kind, 0, 0, 0, 0x12, 0x34, 0, 2];
|
||||
@@ -631,7 +733,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn saturated_network_does_not_take_another_networks_capacity() {
|
||||
let mut flows = SourceFlows::new(&plan());
|
||||
let mut flows = SourceFlows::new(&aliases(), None, 1280, SourceMode::Primary);
|
||||
for port in 0..MAX_FLOWS {
|
||||
assert_eq!(
|
||||
flows
|
||||
@@ -661,7 +763,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn fragmented_udp_translates_after_assembly_in_both_directions() {
|
||||
let mut flows = SourceFlows::new(&plan());
|
||||
let mut flows = SourceFlows::new(&aliases(), None, 1280, SourceMode::Primary);
|
||||
let mut original = udp(FIRST, PEER, 3333, 4444, &[7; 1900]);
|
||||
let parts = fragment_ipv4(original.clone(), 1280);
|
||||
let mut output = Vec::new();
|
||||
+38
-9
@@ -133,19 +133,48 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inbound_pmtu_restores_a_truncated_udp_quote_and_preserves_the_reporting_router() {
|
||||
use crate::plan::VpnPlan;
|
||||
use crate::source::SourceFlows;
|
||||
use tsunagi::overlay::Cidr;
|
||||
fn wintun_keeps_mesh_errors_and_restores_exit_errors_from_a_mesh_router() {
|
||||
use super::super::{SourceFlows, SourceMode};
|
||||
use crate::overlay::Cidr;
|
||||
|
||||
let mut flows = SourceFlows::new(&VpnPlan {
|
||||
addresses: vec![
|
||||
let external = Ipv4Addr::new(203, 0, 113, 200);
|
||||
let mut flows = SourceFlows::new(
|
||||
&[
|
||||
Cidr::new(APP.into(), 24).unwrap(),
|
||||
Cidr::new(WIRE.into(), 24).unwrap(),
|
||||
],
|
||||
mtu: 1280,
|
||||
..Default::default()
|
||||
});
|
||||
Some(WIRE),
|
||||
1280,
|
||||
SourceMode::ExitOnly,
|
||||
);
|
||||
let mut udp = [0; 8];
|
||||
udp[4..6].copy_from_slice(&8u16.to_be_bytes());
|
||||
let mesh_packet = ipv4(17, WIRE, PEER, &udp);
|
||||
let mesh_error = error(ROUTER, WIRE, &mesh_packet);
|
||||
assert_eq!(flows.inbound(mesh_error.clone()), [mesh_error]);
|
||||
|
||||
let original = ipv4(17, APP, external, &udp);
|
||||
let translated = flows.outbound(original.clone().into()).pop().unwrap();
|
||||
assert_eq!(
|
||||
flows.inbound(error(ROUTER, WIRE, &translated)),
|
||||
[error(ROUTER, APP, &original)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inbound_pmtu_restores_a_truncated_udp_quote_and_preserves_the_reporting_router() {
|
||||
use super::super::{SourceFlows, SourceMode};
|
||||
use crate::overlay::Cidr;
|
||||
|
||||
let mut flows = SourceFlows::new(
|
||||
&[
|
||||
Cidr::new(APP.into(), 24).unwrap(),
|
||||
Cidr::new(WIRE.into(), 24).unwrap(),
|
||||
],
|
||||
None,
|
||||
1280,
|
||||
SourceMode::Primary,
|
||||
);
|
||||
let mut udp = [0x71; 16];
|
||||
udp[4..6].copy_from_slice(&16u16.to_be_bytes());
|
||||
UdpPacket::new_unchecked(&mut udp[..]).fill_checksum(&APP.into(), &PEER.into());
|
||||
@@ -0,0 +1,102 @@
|
||||
//! Wintun default routes cannot specify a preferred IPv4 source address.
|
||||
use super::{Domains, SourceFlows, SourceMode};
|
||||
use crate::BoxFuture;
|
||||
use crate::overlay::{Cidr, OverlayError, TunDevice};
|
||||
use bytes::Bytes;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
|
||||
pub(crate) struct ExitSourceTun {
|
||||
device: Arc<dyn TunDevice>,
|
||||
state: Mutex<Option<State>>,
|
||||
}
|
||||
|
||||
struct State {
|
||||
flows: SourceFlows,
|
||||
pending: std::vec::IntoIter<Bytes>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ExitSourceTun {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("ExitSourceTun").field(&self.device).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl ExitSourceTun {
|
||||
pub(crate) fn new(device: Arc<dyn TunDevice>) -> Self {
|
||||
Self {
|
||||
device,
|
||||
state: Mutex::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn state(&self) -> MutexGuard<'_, Option<State>> {
|
||||
self.state.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
impl TunDevice for ExitSourceTun {
|
||||
fn name(&self) -> &str {
|
||||
self.device.name()
|
||||
}
|
||||
|
||||
fn mtu(&self) -> u32 {
|
||||
self.device.mtu()
|
||||
}
|
||||
|
||||
fn set_exit_source(&self, addresses: &[Cidr], source: Option<Ipv4Addr>) {
|
||||
let mut active = self.state();
|
||||
let domains = Domains::new(addresses, source, SourceMode::ExitOnly);
|
||||
if domains.aliases.len() < 2 || !source.is_some_and(|addr| domains.has(addr)) {
|
||||
*active = None;
|
||||
return;
|
||||
}
|
||||
if let Some(state) = active.as_mut() {
|
||||
if state.flows.domains != domains {
|
||||
state.flows.reconfigure(addresses, source, self.mtu());
|
||||
state.pending = Vec::new().into_iter();
|
||||
}
|
||||
} else {
|
||||
*active = Some(State {
|
||||
flows: SourceFlows::new(addresses, source, self.mtu(), SourceMode::ExitOnly),
|
||||
pending: Vec::new().into_iter(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn recv(&self) -> BoxFuture<'_, Option<Bytes>> {
|
||||
Box::pin(async {
|
||||
if let Some(part) = self.state().as_mut().and_then(|s| s.pending.next()) {
|
||||
return Some(part);
|
||||
}
|
||||
loop {
|
||||
let packet = self.device.recv().await?;
|
||||
let mut active = self.state();
|
||||
let Some(state) = active.as_mut() else {
|
||||
return Some(packet);
|
||||
};
|
||||
state.pending = state.flows.outbound(packet).into_iter();
|
||||
if let Some(part) = state.pending.next() {
|
||||
return Some(part);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn send(&self, packet: Bytes) -> BoxFuture<'_, Result<(), OverlayError>> {
|
||||
Box::pin(async move {
|
||||
let parts = self
|
||||
.state()
|
||||
.as_mut()
|
||||
.map(|s| s.flows.inbound(packet.clone()));
|
||||
if let Some(parts) = parts {
|
||||
for part in parts {
|
||||
self.device.send(part).await?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
self.device.send(packet).await
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,10 @@ pub trait TunDevice: Send + Sync + std::fmt::Debug + 'static {
|
||||
/// The interface MTU.
|
||||
fn mtu(&self) -> u32;
|
||||
|
||||
/// Supply the local Wintun address and exit selection used for off-mesh flows.
|
||||
#[cfg(any(windows, test))]
|
||||
fn set_exit_source(&self, _addresses: &[super::Cidr], _source: Option<std::net::Ipv4Addr>) {}
|
||||
|
||||
/// The next packet the operating system wants to send, or `None` once the
|
||||
/// device is gone.
|
||||
fn recv(&self) -> BoxFuture<'_, Option<Bytes>>;
|
||||
@@ -476,12 +480,16 @@ mod system {
|
||||
let name = request.name.clone();
|
||||
|
||||
let (reader, writer) = tokio::io::split(device);
|
||||
Ok(Arc::new(SystemTun {
|
||||
let device: Arc<dyn TunDevice> = Arc::new(SystemTun {
|
||||
name,
|
||||
mtu: request.mtu,
|
||||
reader: Mutex::new(reader),
|
||||
writer: Mutex::new(writer),
|
||||
}) as Arc<dyn TunDevice>)
|
||||
});
|
||||
#[cfg(windows)]
|
||||
let device: Arc<dyn TunDevice> =
|
||||
Arc::new(crate::overlay::source::windows::ExitSourceTun::new(device));
|
||||
Ok(device)
|
||||
}
|
||||
|
||||
fn open_error(name: &str, error: tun::Error) -> OverlayError {
|
||||
|
||||
@@ -20,6 +20,7 @@ use tsunagi::dataplane::IpPlugin;
|
||||
use tsunagi::discovery::SharedMemoryDiscovery;
|
||||
use tsunagi::identity::NetworkId;
|
||||
use tsunagi::overlay::{MemoryTun, MemoryTunFactory, MockHostRules};
|
||||
use tsunagi::state::{DEFAULT_IPV4_RANGE, Ipv4Range};
|
||||
use tsunagi::testing::{network, wait_until};
|
||||
use tsunagi::{Agent, NetworkStatus};
|
||||
use tsunagi_wg_quic::{WireguardConfig, WireguardPlugin};
|
||||
@@ -27,7 +28,7 @@ use tsunagi_wg_quic::{WireguardConfig, WireguardPlugin};
|
||||
const INTERNET: Ipv4Addr = Ipv4Addr::new(93, 184, 216, 34);
|
||||
|
||||
struct Node {
|
||||
_dir: TempDir,
|
||||
dir: TempDir,
|
||||
agent: Agent,
|
||||
plugin: Arc<WireguardPlugin>,
|
||||
tuns: MemoryTunFactory,
|
||||
@@ -36,7 +37,21 @@ struct Node {
|
||||
|
||||
impl Node {
|
||||
async fn spawn(discovery: &SharedMemoryDiscovery, tag: &str) -> Self {
|
||||
let dir = TempDir::new().unwrap();
|
||||
Self::open(
|
||||
TempDir::new().unwrap(),
|
||||
discovery,
|
||||
tag,
|
||||
Some(DEFAULT_IPV4_RANGE),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn open(
|
||||
dir: TempDir,
|
||||
discovery: &SharedMemoryDiscovery,
|
||||
tag: &str,
|
||||
range: Option<Ipv4Range>,
|
||||
) -> Self {
|
||||
let tuns = MemoryTunFactory::new();
|
||||
let rules = MockHostRules::new();
|
||||
let plugin = WireguardPlugin::open(
|
||||
@@ -47,7 +62,7 @@ impl Node {
|
||||
.unwrap();
|
||||
let agent = Agent::spawn(
|
||||
tsunagi::testing::config_with(dir.path(), discovery)
|
||||
.with_overlay_ipv4_range(Some(tsunagi::state::DEFAULT_IPV4_RANGE))
|
||||
.with_overlay_ipv4_range(range)
|
||||
.with_interface(
|
||||
Arc::new(tuns.clone().with_host_rules(Arc::new(rules.clone()))),
|
||||
tag,
|
||||
@@ -61,7 +76,7 @@ impl Node {
|
||||
.await
|
||||
.unwrap();
|
||||
Self {
|
||||
_dir: dir,
|
||||
dir,
|
||||
agent,
|
||||
plugin,
|
||||
tuns,
|
||||
@@ -99,6 +114,22 @@ impl Node {
|
||||
async fn status(&self, network: NetworkId) -> NetworkStatus {
|
||||
self.agent.network_status(network).await.unwrap()
|
||||
}
|
||||
|
||||
async fn selected_exits(&self) -> Vec<(NetworkId, EndpointId)> {
|
||||
self.agent
|
||||
.status()
|
||||
.await
|
||||
.unwrap()
|
||||
.networks
|
||||
.into_iter()
|
||||
.filter_map(|network| Some((network.network_id, network.exit_via?)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn shutdown(self) -> TempDir {
|
||||
self.agent.shutdown().await;
|
||||
self.dir
|
||||
}
|
||||
}
|
||||
|
||||
fn ipv4_packet(source: Ipv4Addr, destination: Ipv4Addr, payload: &[u8]) -> Bytes {
|
||||
@@ -124,6 +155,151 @@ async fn next(tun: &MemoryTun) -> Bytes {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
struct ExitNetwork<'a> {
|
||||
id: NetworkId,
|
||||
peer: &'a Node,
|
||||
client_addr: Ipv4Addr,
|
||||
peer_addr: Ipv4Addr,
|
||||
peer_tun: Arc<MemoryTun>,
|
||||
}
|
||||
|
||||
impl<'a> ExitNetwork<'a> {
|
||||
async fn join(client: &Node, peer: &'a Node, name: &str, range: Ipv4Range) -> Self {
|
||||
let (name, secret) = network(name);
|
||||
let id = peer.agent.join_network(&name, &secret).await.unwrap();
|
||||
peer.overlay(id).await;
|
||||
peer.agent.set_exit_offer(id, true).await.unwrap();
|
||||
client.agent.join_network(&name, &secret).await.unwrap();
|
||||
client.wait_for_tunnels(id, 1).await;
|
||||
peer.wait_for_tunnels(id, 1).await;
|
||||
let client_addr = wait_until(
|
||||
"client adopts the peer's range and sees its exit offer",
|
||||
|| async {
|
||||
let address = client.plugin.overview(id)?.overlay_address_v4?;
|
||||
(range.contains(address)
|
||||
&& client
|
||||
.status(id)
|
||||
.await
|
||||
.peers
|
||||
.iter()
|
||||
.any(|p| p.endpoint_id == peer.id() && p.exit_node))
|
||||
.then_some(address)
|
||||
},
|
||||
)
|
||||
.await;
|
||||
Self {
|
||||
id,
|
||||
peer,
|
||||
client_addr,
|
||||
peer_addr: peer.overlay(id).await,
|
||||
peer_tun: peer.tun().await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn check_mesh(&self, client_tun: &MemoryTun) {
|
||||
let request = ipv4_packet(self.client_addr, self.peer_addr, self.id.as_bytes());
|
||||
client_tun.push_from_os(request.clone());
|
||||
assert_eq!(next(&self.peer_tun).await, request);
|
||||
let reply = ipv4_packet(self.peer_addr, self.client_addr, self.id.as_bytes());
|
||||
self.peer_tun.push_from_os(reply.clone());
|
||||
assert_eq!(next(client_tun).await, reply);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn switching_the_exit_between_networks_keeps_both_overlays_reachable() {
|
||||
let discovery = SharedMemoryDiscovery::new();
|
||||
let client = Node::open(TempDir::new().unwrap(), &discovery, "client", None).await;
|
||||
let left = Node::spawn(&discovery, "left").await;
|
||||
let right_range = "10.99.0.0/16".parse().unwrap();
|
||||
let right = Node::open(
|
||||
TempDir::new().unwrap(),
|
||||
&discovery,
|
||||
"right",
|
||||
Some(right_range),
|
||||
)
|
||||
.await;
|
||||
let alpha = ExitNetwork::join(&client, &left, "exit-left", DEFAULT_IPV4_RANGE).await;
|
||||
let beta = ExitNetwork::join(&client, &right, "exit-right", right_range).await;
|
||||
let tun = client.tun().await;
|
||||
|
||||
for exit in [&alpha, &beta] {
|
||||
client
|
||||
.agent
|
||||
.set_exit_via(exit.id, Some(exit.peer.id()))
|
||||
.await
|
||||
.unwrap();
|
||||
let plan = client.rules.exit().installed().unwrap();
|
||||
assert_eq!(plan.client_source, Some(exit.client_addr));
|
||||
assert_eq!(plan.overlay.len(), 2);
|
||||
let internet = ipv4_packet(exit.client_addr, INTERNET, b"request");
|
||||
tun.push_from_os(internet.clone());
|
||||
assert_eq!(next(&exit.peer_tun).await, internet);
|
||||
let reply = ipv4_packet(INTERNET, exit.client_addr, b"reply");
|
||||
exit.peer_tun.push_from_os(reply.clone());
|
||||
assert_eq!(next(&tun).await, reply);
|
||||
|
||||
for net in [&alpha, &beta] {
|
||||
let selected = (net.id == exit.id).then(|| net.peer.id());
|
||||
assert_eq!(client.status(net.id).await.exit_via, selected);
|
||||
net.check_mesh(&tun).await;
|
||||
}
|
||||
}
|
||||
// Right offers on beta only. An invalid replacement must preserve the live route.
|
||||
assert!(
|
||||
client
|
||||
.agent
|
||||
.set_exit_via(alpha.id, Some(right.id()))
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(client.selected_exits().await, [(beta.id, right.id())]);
|
||||
let request = ipv4_packet(beta.client_addr, INTERNET, b"still using beta");
|
||||
tun.push_from_os(request.clone());
|
||||
assert_eq!(next(&beta.peer_tun).await, request);
|
||||
|
||||
// Two independent commands may race. Both must leave one effective exit,
|
||||
// and restarting from the same SQLite state must restore that exact choice.
|
||||
let (one, two) = tokio::join!(
|
||||
client.agent.set_exit_via(alpha.id, Some(left.id())),
|
||||
client.agent.set_exit_via(beta.id, Some(right.id())),
|
||||
);
|
||||
one.unwrap();
|
||||
two.unwrap();
|
||||
let exits = client.selected_exits().await;
|
||||
assert!(
|
||||
exits == [(alpha.id, left.id())] || exits == [(beta.id, right.id())],
|
||||
"{exits:?}"
|
||||
);
|
||||
let (lost, live) = if exits[0].0 == alpha.id {
|
||||
(&alpha, &beta)
|
||||
} else {
|
||||
(&beta, &alpha)
|
||||
};
|
||||
lost.peer.agent.shutdown().await;
|
||||
client.wait_for_tunnels(lost.id, 0).await;
|
||||
wait_until("the selected exit is offline", || async {
|
||||
let status = client.status(lost.id).await;
|
||||
(status.exit_via == Some(lost.peer.id()) && !status.exit_via_online).then_some(())
|
||||
})
|
||||
.await;
|
||||
assert!(client.rules.exit().installed().unwrap().client);
|
||||
let dropped = client.agent.overlay().unwrap().counters.undeliverable;
|
||||
tun.push_from_os(ipv4_packet(lost.client_addr, INTERNET, b"offline exit"));
|
||||
wait_until(
|
||||
"internet traffic cannot use the other offering peer",
|
||||
|| async { (client.agent.overlay()?.counters.undeliverable > dropped).then_some(()) },
|
||||
)
|
||||
.await;
|
||||
live.check_mesh(&tun).await;
|
||||
|
||||
let dir = client.shutdown().await;
|
||||
let restarted = Node::open(dir, &discovery, "client", None).await;
|
||||
assert_eq!(restarted.selected_exits().await, exits);
|
||||
restarted.agent.shutdown().await;
|
||||
live.peer.agent.shutdown().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_member_sends_its_internet_traffic_through_an_exit_node_and_gets_the_answers() {
|
||||
let discovery = SharedMemoryDiscovery::new();
|
||||
|
||||
@@ -80,7 +80,8 @@ enum Command {
|
||||
/// device's internet traffic through one.
|
||||
///
|
||||
/// The other half of `tsng network exit-node`, which is what makes a
|
||||
/// device offer itself. A device uses one exit node at a time.
|
||||
/// device offer itself. One exit serves all active networks. Traffic to
|
||||
/// peers and services in each mesh keeps its own route.
|
||||
ExitNode(ExitNodeArgs),
|
||||
/// Removes everything this device has stored and starts over.
|
||||
Wipe(WipeArgs),
|
||||
|
||||
+23
-13
@@ -1,8 +1,8 @@
|
||||
# Exit nodes
|
||||
|
||||
A member can offer itself as an **exit node** in a network. Other members can
|
||||
then send *all* their internet traffic through it, the way a commercial VPN
|
||||
or Tailscale's exit nodes work. Linux only for now.
|
||||
then send their default IPv4 internet traffic through it. Linux, macOS and
|
||||
Windows can offer or use an exit node. Android can use one.
|
||||
|
||||
## Using it
|
||||
|
||||
@@ -23,16 +23,20 @@ The using side:
|
||||
|
||||
```sh
|
||||
tsng exit-node # who offers one
|
||||
tsng exit-node <name|id> # send everything through it
|
||||
tsng exit-node <name|id> # choose the device's internet exit
|
||||
tsng exit-node -n work gateway # choose gateway in work if the name is ambiguous
|
||||
tsng exit-node off
|
||||
```
|
||||
|
||||
The tray does the same: a checkbox on the network tile to offer, and an icon on
|
||||
each device in the devices window that offers one, with a confirmation.
|
||||
|
||||
One device has one default route, so it uses **one** exit node at a time;
|
||||
choosing another replaces the first. Offering is per network, so a device can
|
||||
be an exit node in one network and not in another.
|
||||
An agent uses **one exit node across all active networks**. Choosing another
|
||||
replaces the previous selection and survives restart. Internet packets use
|
||||
the local address in the selected exit's network. Each active mesh keeps
|
||||
its own subnet route, including routes to the exit peer's overlay address,
|
||||
other peers and virtual services. An unused address inside an active mesh
|
||||
subnet is dropped locally. Offering an exit remains a per-network choice.
|
||||
|
||||
## How it works
|
||||
|
||||
@@ -44,7 +48,8 @@ be an exit node in one network and not in another.
|
||||
network stops, and when the agent exits. Only networks that offer have
|
||||
rules, so the others' traffic is not forwarded.
|
||||
- **Client:** policy routing, with no change to the main table. Table `29811`
|
||||
holds `default dev <interface>`. Rules `5205 fwmark 0x40000000/0x40000000
|
||||
holds `default dev <interface> src <local address in the exit network>` once
|
||||
that address is assigned. Rules `5205 fwmark 0x40000000/0x40000000
|
||||
lookup main` and `5206 uidrange <agent uid> lookup main` keep the agent's
|
||||
sockets and their replies outside the tunnel, before Tailscale's rules.
|
||||
`5290 lookup main suppress_prefixlength 0` preserves LAN and other specific
|
||||
@@ -73,9 +78,9 @@ be an exit node in one network and not in another.
|
||||
error if marks would be ignored. It never disables `rp_filter` or changes
|
||||
host sysctls. Netfilter strict reverse checks also need their mark-aware
|
||||
form, such as `rpfilter --validmark`, which NixOS already uses.
|
||||
- Packets for addresses outside every overlay range are sent to the exit node
|
||||
by the router; the exit node's replies are accepted from any source. A member
|
||||
that is not your exit node cannot do that.
|
||||
- The router sends ordinary IPv4 unicast outside all active mesh ranges to
|
||||
the selected exit. It accepts replies with external source addresses from
|
||||
that peer only when they target this device's address in the exit network.
|
||||
- **IPv6 is blocked while you use one.** There is no IPv6 through an exit node,
|
||||
and letting it go the ordinary way would leak it. The same three rules exist
|
||||
for IPv6 with an `unreachable default` in the table, so applications get an
|
||||
@@ -96,7 +101,8 @@ is built from `pf` and `route`. The agent runs as root there.
|
||||
macOS forgets at reboot. The egress is the default route's interface **at the
|
||||
time the rules are applied**; after it changes (Wi-Fi to Ethernet) switch the
|
||||
offer off and on.
|
||||
- **Using:** `0.0.0.0/1` and `128.0.0.0/1` routes through the overlay interface,
|
||||
- **Using:** `0.0.0.0/1` and `128.0.0.0/1` routes through the overlay interface
|
||||
with the local address of the exit network as their source,
|
||||
and a `pf` `route-to` rule that sends the agent's own traffic (matched by its
|
||||
user id, root) back out the physical interface, with translation to that
|
||||
interface's address. Anything else you run as root also bypasses the tunnel.
|
||||
@@ -119,8 +125,12 @@ is built from `pf` and `route`. The agent runs as root there.
|
||||
through the physical default gateway is added for every address the agent
|
||||
talks to directly: verified direct paths of its connections, plus the relays
|
||||
it uses, resolved when the rules are applied. The set follows path changes. A
|
||||
path that appears after the last apply goes through the tunnel until the next
|
||||
one. IPv6 is blackholed with `::/1` and `8000::/1` on the overlay interface,
|
||||
newly authenticated connection supplies its direct paths immediately and the
|
||||
discovery tick refreshes them. Physical bypass routes exclude every active
|
||||
mesh subnet. Wintun can choose any local alias for the default route. For
|
||||
TCP, UDP and ICMP echo, the agent uses the exit network's address on the
|
||||
tunnel and restores replies to the address the Windows socket used.
|
||||
IPv6 is blackholed with `::/1` and `8000::/1` on the overlay interface,
|
||||
so applications fall back to IPv4 after a delay rather than at once.
|
||||
Everything is in the active store: a reboot clears it.
|
||||
- Not verified on a live host when this was written. To inspect:
|
||||
|
||||
@@ -225,6 +225,12 @@ retained. It requires root, iproute2,
|
||||
iptables/ip6tables and Python; it does not run in the default suite or claim
|
||||
to test the entire mesh inside these namespaces.
|
||||
|
||||
`tsunagi-wg-quic/tests/exit_node.rs` runs a client in two disjoint meshes
|
||||
with a different exit peer in each. It switches the internet route, exchanges
|
||||
packets in both meshes over encrypted tunnels, races two exit selections and
|
||||
restarts the client from its SQLite directory to check the winning choice.
|
||||
The interfaces in this test are memory TUNs.
|
||||
|
||||
Devices-window tests render the egui grid at multiple widths with its real
|
||||
scroll area. They check stretching and shrinking without an expanding first
|
||||
column, control RTT without internal handshake/protocol clutter, unknown measurements
|
||||
|
||||
Reference in new issue
Block a user