Run one agent for all joined networks behind Android's VPN service. Share transport registration and reporting with the CLI, and move the tray's egui forms into a Rust UI crate. Phones use compact device rows and a full-width exit picker with RTT and data path. All four transports retain their per-network selection and priority. The phone consumes remote IPv4 exits and keeps the existing desktop identity and wire protocols. Send discovery and transport traffic over the physical network and bind VIP TCP health checks to the mesh. Build local DNS zones from the same signed membership and VIP records on desktop and Android. Answer UDP and TCP queries on the VPN, keep unknown mesh names local, and resolve public names through Android's underlying resolver, including with an exit. Show an ongoing notification for the selected exit. Guard its disconnect action against a stale selection and keep mesh routing and DNS alive when it removes the default route. Remove the app notification in mesh-only mode. Document Android 14's unlocked-device swipe behavior. Checked formatting and ran locked all-target workspace Clippy with warnings denied and tests on macOS (547 passed, 2 ignored). Built the arm64 debug APK. A physical Pixel resolved a mesh member and a Kubernetes VIP, answered UDP and TCP DNS, and reached the API over TLS (HTTP 401 without credentials). On a separate Android emulator the notification action removed the default route and notice while mesh DNS still worked.
86 lines
2.8 KiB
Rust
86 lines
2.8 KiB
Rust
//! All addresses and routes installed in the one Android VPN.
|
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
|
|
|
use tsunagi::overlay::Cidr;
|
|
|
|
/// An exhaustive VpnService configuration, derived from local core policy.
|
|
#[derive(Clone, Default, Debug, PartialEq, Eq)]
|
|
pub struct VpnPlan {
|
|
/// One address in each active, non-overlapping network.
|
|
pub addresses: Vec<Cidr>,
|
|
/// Payload MTU for every attached network.
|
|
pub mtu: u32,
|
|
/// Capture IPv4 traffic outside the mesh.
|
|
pub full_tunnel: bool,
|
|
/// Preferred IPv4 source for the default route.
|
|
pub exit: Option<IpAddr>,
|
|
/// Capture the limited broadcast when requested by the core.
|
|
pub broadcast: bool,
|
|
}
|
|
|
|
impl VpnPlan {
|
|
/// Device-local DNS endpoint. Never take an address from a joined mesh.
|
|
pub fn dns_address(&self) -> Option<Ipv4Addr> {
|
|
if self.addresses.is_empty() {
|
|
return None;
|
|
}
|
|
[
|
|
Ipv4Addr::new(192, 0, 2, 53),
|
|
Ipv4Addr::new(198, 51, 100, 53),
|
|
Ipv4Addr::new(203, 0, 113, 53),
|
|
]
|
|
.into_iter()
|
|
.find(|candidate| {
|
|
!self.addresses.iter().any(|cidr| {
|
|
let IpAddr::V4(base) = cidr.addr else {
|
|
return false;
|
|
};
|
|
tsunagi::state::Ipv4Range {
|
|
base,
|
|
prefix_len: cidr.prefix_len,
|
|
}
|
|
.contains(*candidate)
|
|
})
|
|
})
|
|
}
|
|
|
|
/// Android uses the first address as primary for unscoped IPv4 traffic.
|
|
pub fn addresses_in_order(&self) -> Vec<Cidr> {
|
|
let mut ordered = self.addresses.clone();
|
|
ordered.sort_by_key(|cidr| (Some(cidr.addr) != self.exit, *cidr));
|
|
ordered
|
|
}
|
|
|
|
/// Explicitly route the entire agreed subnet, including its virtual services.
|
|
pub fn routes(&self) -> Vec<String> {
|
|
let mut routes: Vec<_> = self
|
|
.addresses
|
|
.iter()
|
|
.map(|cidr| {
|
|
let p = cidr.prefix_len;
|
|
let base = match cidr.addr {
|
|
IpAddr::V4(a) => IpAddr::V4(Ipv4Addr::from(
|
|
u32::from(a) & u32::MAX.checked_shl(u32::from(32 - p)).unwrap_or(0),
|
|
)),
|
|
IpAddr::V6(a) => IpAddr::V6(Ipv6Addr::from(
|
|
u128::from(a) & u128::MAX.checked_shl(u32::from(128 - p)).unwrap_or(0),
|
|
)),
|
|
};
|
|
format!("{base}/{p}")
|
|
})
|
|
.collect();
|
|
if let Some(dns) = self.dns_address() {
|
|
routes.push(format!("{dns}/32"));
|
|
}
|
|
if self.full_tunnel {
|
|
routes.push("0.0.0.0/0".into());
|
|
}
|
|
if self.broadcast {
|
|
routes.push("255.255.255.255/32".into());
|
|
}
|
|
routes.sort();
|
|
routes.dedup();
|
|
routes
|
|
}
|
|
}
|