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.
135 lines
4.7 KiB
Rust
135 lines
4.7 KiB
Rust
//! A DNS view of the overlay.
|
|
//!
|
|
//! The names and addresses of a network, served to the host that runs the
|
|
//! agent, so members can be reached by name. Answered from signed state, so a
|
|
//! member that is switched off still resolves.
|
|
//!
|
|
//! Three parts, kept apart on purpose:
|
|
//!
|
|
//! * [`zone`] decides what the answer is. Pure, and knows nothing about
|
|
//! packets or sockets.
|
|
//! * [`server`] puts that on the wire.
|
|
//! * `publish` tells the operating system where to send its questions,
|
|
//! which is the only part that differs between platforms.
|
|
|
|
pub mod publish;
|
|
pub mod server;
|
|
pub mod zone;
|
|
|
|
pub use publish::{DnsPublisher, PublishError, Published};
|
|
|
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
|
|
|
|
/// Where the server listens, one list per address family.
|
|
///
|
|
/// Loopback, and only loopback. The zones are a view *for the host running
|
|
/// the agent*: it is that host's resolver that is pointed at them. Binding
|
|
/// an overlay address instead would put them in front of the whole mesh —
|
|
/// and an agent in several networks would then answer one network's
|
|
/// questions about another's names, which is precisely what separate
|
|
/// networks are for.
|
|
///
|
|
/// Both families, and independently: a question arrives over whichever one
|
|
/// the resolver happens to use, and on a host with one of them switched off
|
|
/// the other must still answer. So neither list failing says anything about
|
|
/// the other, and a listener is opened from each.
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct ListenPlan {
|
|
/// IPv4 candidates, best first.
|
|
pub v4: Vec<SocketAddr>,
|
|
/// IPv6 candidates, best first.
|
|
pub v6: Vec<SocketAddr>,
|
|
}
|
|
|
|
impl ListenPlan {
|
|
/// The two lists, so a caller can bind one listener from each.
|
|
pub fn families(&self) -> [&[SocketAddr]; 2] {
|
|
[&self.v4, &self.v6]
|
|
}
|
|
}
|
|
|
|
/// Builds the listen plan for one port.
|
|
pub fn listen_plan(port: u16) -> ListenPlan {
|
|
ListenPlan {
|
|
v4: vec![SocketAddr::from((Ipv4Addr::LOCALHOST, port))],
|
|
v6: vec![SocketAddr::from((Ipv6Addr::LOCALHOST, port))],
|
|
}
|
|
}
|
|
|
|
pub use server::{DnsServer, SharedZone};
|
|
pub use zone::{Answer, Query, Zone, ZoneError, ZoneName, Zones};
|
|
|
|
/// Authoritative zones and the publication diagnostics for one agent snapshot.
|
|
pub struct RosterZones {
|
|
/// Member and service records indexed by zone.
|
|
pub zones: Zones,
|
|
/// Zone names in configured-network order.
|
|
pub labels: Vec<String>,
|
|
/// Unusable or potentially conflicting zone names.
|
|
pub warnings: Vec<String>,
|
|
}
|
|
|
|
impl RosterZones {
|
|
/// Build the desktop and mobile DNS view from the same signed state.
|
|
pub fn from_networks(networks: &[crate::NetworkStatus]) -> Self {
|
|
let mut zones = Vec::new();
|
|
let mut labels = Vec::new();
|
|
let mut warnings = Vec::new();
|
|
for network in networks {
|
|
let zone = match ZoneName::new(network.name.as_str()) {
|
|
Ok(zone) => zone,
|
|
Err(err) => {
|
|
warnings.push(format!(
|
|
"`{}` cannot be a zone, so its members have no names: {err}",
|
|
network.name
|
|
));
|
|
continue;
|
|
}
|
|
};
|
|
if let Some(warning) = zone.collision() {
|
|
warnings.push(warning);
|
|
}
|
|
labels.push(zone.as_str().to_string());
|
|
let members = network
|
|
.members
|
|
.iter()
|
|
.filter_map(|member| Some((member.hostname.clone()?, member.overlay_address_v4?)));
|
|
let services = network
|
|
.vips
|
|
.iter()
|
|
.filter(|vip| vip.error.is_none())
|
|
.filter_map(|vip| Some((vip.config.name.clone(), vip.address?)));
|
|
zones.push(Zone::new(zone, members.chain(services)).with_reverse_range(network.range));
|
|
}
|
|
Self {
|
|
zones: Zones::new(zones),
|
|
labels,
|
|
warnings,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn both_families_are_planned_for_and_neither_is_reachable_off_this_host() {
|
|
let plan = listen_plan(5354);
|
|
assert_eq!(
|
|
plan.v4,
|
|
vec!["127.0.0.1:5354".parse::<SocketAddr>().unwrap()]
|
|
);
|
|
assert_eq!(plan.v6, vec!["[::1]:5354".parse::<SocketAddr>().unwrap()]);
|
|
assert_eq!(plan.families().len(), 2);
|
|
// Nothing here is reachable from another member: the zones are a
|
|
// view for this host, and an agent in two networks must not answer
|
|
// one network's questions about the other's names.
|
|
for address in plan.families().concat() {
|
|
assert!(address.ip().is_loopback(), "{address} is not loopback");
|
|
}
|
|
}
|
|
}
|