Add a Rust Android mesh client with shared tray views

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.
This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-24 17:28:23 +02:00
1 parent 9dec056349
commit ef67e1c0ae
70 files changed
+6199 -1181

No files matched your search

+50
View File
@@ -59,6 +59,56 @@ pub fn listen_plan(port: u16) -> ListenPlan {
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)]
+50 -19
View File
@@ -81,7 +81,22 @@ impl SharedZone {
/// server should reply to, and replying anyway would make this a useful
/// amplifier for somebody spoofing a source address.
pub fn respond(zones: &Zones, query: &[u8]) -> Option<Vec<u8>> {
let packet = simple_dns::Packet::parse(query).ok()?;
match resolve(zones, query)? {
Resolution::Local(reply) | Resolution::Outside(reply) => Some(reply),
}
}
/// An authoritative decision for a host resolver that also handles external domains.
pub enum Resolution {
/// Answer locally, including authoritative denials and protocol errors.
Local(Vec<u8>),
/// A well-formed question outside all mesh zones, with the authoritative server's REFUSED reply.
Outside(Vec<u8>),
}
/// Distinguish an external question from an unknown name inside a mesh zone.
pub fn resolve(zones: &Zones, query: &[u8]) -> Option<Resolution> {
let packet = parse_message(query)?;
if packet.has_flags(PacketFlag::RESPONSE) {
return None;
}
@@ -95,18 +110,18 @@ pub fn respond(zones: &Zones, query: &[u8]) -> Option<Vec<u8>> {
if packet.opcode() != simple_dns::OPCODE::StandardQuery {
*reply.rcode_mut() = RCODE::NotImplemented;
return reply.build_bytes_vec().ok();
return reply.build_bytes_vec().ok().map(Resolution::Local);
}
// Exactly one question. Zero is nothing to answer; more than one has no
// agreed meaning and every real server rejects it.
let [question] = packet.questions.as_slice() else {
*reply.rcode_mut() = RCODE::FormatError;
return reply.build_bytes_vec().ok();
return reply.build_bytes_vec().ok().map(Resolution::Local);
};
if !matches!(question.qclass, QCLASS::CLASS(simple_dns::CLASS::IN)) {
*reply.rcode_mut() = RCODE::Refused;
return reply.build_bytes_vec().ok();
return reply.build_bytes_vec().ok().map(Resolution::Local);
}
let qname = question.qname.to_string();
@@ -117,7 +132,10 @@ pub fn respond(zones: &Zones, query: &[u8]) -> Option<Vec<u8>> {
None => {
reply.questions.push(question.clone());
*reply.rcode_mut() = RCODE::Refused;
return reply.build_bytes_vec_compressed().ok();
return reply
.build_bytes_vec_compressed()
.ok()
.map(Resolution::Outside);
}
};
reply.questions.push(question.clone());
@@ -163,7 +181,22 @@ pub fn respond(zones: &Zones, query: &[u8]) -> Option<Vec<u8>> {
}
}
reply.build_bytes_vec_compressed().ok()
reply
.build_bytes_vec_compressed()
.ok()
.map(Resolution::Local)
}
/// Parse a DNS message only after bounding its section allocations against the bytes received.
pub fn parse_message(wire: &[u8]) -> Option<simple_dns::Packet<'_>> {
let header = wire.get(..12)?;
let counts = |at: usize| usize::from(u16::from_be_bytes([header[at], header[at + 1]]));
// Even a root question needs five bytes. An empty root resource record needs eleven.
let minimum = 12 + counts(4) * 5 + (counts(6) + counts(8) + counts(10)) * 11;
if wire.len() < minimum || wire.len() > usize::from(u16::MAX) {
return None;
}
simple_dns::Packet::parse(wire).ok()
}
/// The zone's start of authority.
@@ -202,8 +235,7 @@ fn query_kind(qtype: QTYPE) -> Query {
/// Whether the client offered EDNS, and so how large an answer it will take.
fn udp_limit(query: &[u8]) -> usize {
simple_dns::Packet::parse(query)
.ok()
parse_message(query)
.and_then(|packet| packet.opt().map(|opt| opt.udp_packet_size as usize))
.unwrap_or(CLASSIC_UDP_LIMIT as u16 as usize)
.clamp(CLASSIC_UDP_LIMIT, MAX_MESSAGE_LEN)
@@ -214,20 +246,19 @@ fn udp_limit(query: &[u8]) -> usize {
/// The records are dropped and the truncated bit set, which tells a resolver
/// to ask again over TCP. Sending a reply it cannot reassemble would just
/// look like packet loss.
fn truncate_for_udp(query: &[u8], reply: Vec<u8>) -> Vec<u8> {
let limit = udp_limit(query);
pub fn truncate_for_udp(query: &[u8], reply: Vec<u8>, payload_limit: usize) -> Vec<u8> {
let limit = udp_limit(query).min(payload_limit);
if reply.len() <= limit {
return reply;
}
let Ok(parsed) = simple_dns::Packet::parse(&reply) else {
let Some(mut short) = parse_message(&reply) else {
return reply;
};
let mut short = simple_dns::Packet::new_reply(parsed.id());
short.set_flags(PacketFlag::TRUNCATION | PacketFlag::AUTHORITATIVE_ANSWER);
*short.rcode_mut() = parsed.rcode();
for question in &parsed.questions {
short.questions.push(question.clone());
}
short.set_flags(PacketFlag::TRUNCATION);
short.answers.clear();
short.name_servers.clear();
short.additional_records.clear();
*short.opt_mut() = None;
short.build_bytes_vec().unwrap_or(reply)
}
@@ -264,7 +295,7 @@ impl DnsServer {
let Some(reply) = respond(&udp_zone.get(), query) else {
continue;
};
let reply = truncate_for_udp(query, reply);
let reply = truncate_for_udp(query, reply, MAX_MESSAGE_LEN);
if let Err(err) = udp.send_to(&reply, from).await {
tracing::debug!(%err, "dns udp reply failed");
}
@@ -494,7 +525,7 @@ mod tests {
"the test needs a big answer"
);
let short = truncate_for_udp(&query, full);
let short = truncate_for_udp(&query, full, MAX_MESSAGE_LEN);
assert!(short.len() <= CLASSIC_UDP_LIMIT);
let parsed = simple_dns::Packet::parse(&short).unwrap();
assert!(parsed.has_flags(PacketFlag::TRUNCATION));
+18
View File
@@ -208,6 +208,7 @@ pub enum Answer {
#[derive(Debug, Clone)]
pub struct Zone {
origin: ZoneName,
reverse_range: Option<crate::state::Ipv4Range>,
/// Name relative to the origin, to the addresses it answers to.
hosts: BTreeMap<String, Vec<Ipv4Addr>>,
/// Address to the name that holds it.
@@ -246,12 +247,23 @@ impl Zone {
let serial = content_serial(&hosts);
Self {
origin,
// Standalone authoritative zones retain their original broad PTR view.
// Agent snapshots scope the authority to each network's actual range.
reverse_range: Some(crate::state::Ipv4Range {
base: Ipv4Addr::UNSPECIFIED,
prefix_len: 0,
}),
hosts,
names,
serial,
}
}
pub(super) fn with_reverse_range(mut self, range: Option<crate::state::Ipv4Range>) -> Self {
self.reverse_range = range;
self
}
/// The zone's origin.
pub fn origin(&self) -> &ZoneName {
&self.origin
@@ -300,6 +312,12 @@ impl Zone {
/// Answers one question.
pub fn lookup(&self, qname: &str, query: Query) -> Answer {
if let Some(address) = reverse_address(qname) {
if !self
.reverse_range
.is_some_and(|range| range.contains(address))
{
return Answer::NotOurs;
}
return match self.names.get(&address) {
Some(name) if query == Query::Ptr => {
Answer::Name(format!("{name}.{}", self.origin.as_str()))