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:
1 parent
9dec056349
commit
ef67e1c0ae
70 files changed
+6199
-1181
No files matched your search
@@ -1179,6 +1179,19 @@ impl Agent {
|
||||
self.inner.networks.read().await.contains_key(&network_id)
|
||||
}
|
||||
|
||||
/// Retrieve the locally stored secret for an explicit user export.
|
||||
/// Status and ordinary network listings never include it.
|
||||
pub async fn network_secret(&self, network_id: NetworkId) -> Result<NetworkSecret> {
|
||||
self.inner
|
||||
.storage
|
||||
.list_networks()
|
||||
.await?
|
||||
.into_iter()
|
||||
.find(|network| network.network_id == network_id)
|
||||
.map(|network| network.secret)
|
||||
.ok_or(Error::NetworkUnknown(network_id))
|
||||
}
|
||||
|
||||
/// Lists configured networks and whether each is running.
|
||||
pub async fn list_networks(&self) -> Result<Vec<ConfiguredNetwork>> {
|
||||
let active: Vec<NetworkId> = self.inner.networks.read().await.keys().copied().collect();
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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()))
|
||||
|
||||
@@ -254,12 +254,16 @@ impl EndpointAdapter {
|
||||
Arc::new(std::sync::RwLock::new(config.interface_name.to_lowercase()));
|
||||
{
|
||||
let interface_filter = Arc::clone(&owned_interface);
|
||||
let factory = config.tun_factory.clone();
|
||||
let filter = iroh::address_lookup::AddrFilter::new(move |addrs| {
|
||||
let owned_interface = interface_filter
|
||||
.read()
|
||||
.unwrap_or_else(|p| p.into_inner())
|
||||
.clone();
|
||||
let mut overlay_ips = std::collections::HashSet::new();
|
||||
if let Some(factory) = &factory {
|
||||
overlay_ips.extend(factory.assigned_addresses());
|
||||
}
|
||||
for iface in netdev::get_interfaces() {
|
||||
let name = iface.name.to_lowercase();
|
||||
let friendly = iface
|
||||
|
||||
@@ -35,6 +35,8 @@ pub struct ExitHostPlan {
|
||||
pub offer: Vec<Ipv4Range>,
|
||||
/// Whether this device sends its internet traffic through a member.
|
||||
pub client: bool,
|
||||
/// Local address in the selected exit network, for hosts that choose a primary address.
|
||||
pub client_source: Option<std::net::Ipv4Addr>,
|
||||
/// The range of every network on the interface. Only the using side
|
||||
/// reads it, to keep this agent's own traffic *to* the overlay inside it
|
||||
/// where the host has no per-user routing (macOS).
|
||||
|
||||
@@ -407,6 +407,7 @@ mod tests {
|
||||
overlay: vec![range()],
|
||||
bypass: vec![Ipv4Addr::new(138, 201, 61, 182)],
|
||||
bypass_hosts: vec!["relay.example".into()],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,6 +231,7 @@ impl Interface {
|
||||
let tally = Arc::new(Tally::default());
|
||||
|
||||
let vip_task = {
|
||||
let factory = Arc::clone(&factory);
|
||||
let routes = Arc::clone(&routes);
|
||||
let carrier = Arc::clone(&carrier);
|
||||
tokio::spawn(async move {
|
||||
@@ -242,7 +243,10 @@ impl Interface {
|
||||
_=interval.tick()=>{
|
||||
let (probes,jobs)=routes.vips.tick(routes.vips.check_capacity().saturating_sub(checks.len()));
|
||||
for (route,packet) in probes {carrier.carry(route,packet);}
|
||||
for job in jobs {checks.spawn(job.run());}
|
||||
for job in jobs {
|
||||
let factory = Arc::clone(&factory);
|
||||
checks.spawn(job.run(move |socket, source| factory.bind_overlay_socket(socket, source)));
|
||||
}
|
||||
},
|
||||
Some(result)=checks.join_next(),if !checks.is_empty()=>{
|
||||
if let Ok((job,ok))=result {routes.vips.checked(job,ok);}
|
||||
@@ -415,7 +419,7 @@ impl Interface {
|
||||
.collect();
|
||||
ranges.sort_by_key(|range| (range.base, range.prefix_len));
|
||||
ranges.dedup();
|
||||
let client = self.routes.exit_via().is_some();
|
||||
let (client, client_source) = self.routes.exit_client();
|
||||
let overlay = self.routes.overlay_ranges();
|
||||
let (bypass, bypass_hosts) = if client && exit.needs_bypass() {
|
||||
self.underlay_targets(&overlay)
|
||||
@@ -426,6 +430,7 @@ impl Interface {
|
||||
interface: self.name.clone(),
|
||||
offer: ranges,
|
||||
client,
|
||||
client_source,
|
||||
overlay,
|
||||
bypass,
|
||||
bypass_hosts,
|
||||
|
||||
@@ -281,6 +281,15 @@ impl RoutingTable {
|
||||
exit_via(&self.read())
|
||||
}
|
||||
|
||||
/// Whether a default route is selected and the local source valid in that network.
|
||||
pub(crate) fn exit_client(&self) -> (bool, Option<Ipv4Addr>) {
|
||||
let networks = self.read();
|
||||
match exit_via(&networks) {
|
||||
Some((id, _)) => (true, networks.get(&id).and_then(|routes| routes.local)),
|
||||
None => (false, None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Networks that offer this agent as an exit node, with the range each
|
||||
/// agreed. A network that has not agreed one yet has nothing to
|
||||
/// masquerade and is left out.
|
||||
|
||||
@@ -90,6 +90,21 @@ pub trait TunFactory: Send + Sync + std::fmt::Debug + 'static {
|
||||
/// land on the second.
|
||||
fn on_host(&self) -> bool;
|
||||
|
||||
/// Bind a socket carrying a VIP health check to this overlay on platforms
|
||||
/// that explicitly route mesh transport sockets outside the VPN.
|
||||
fn bind_overlay_socket(
|
||||
&self,
|
||||
_socket: &tokio::net::TcpSocket,
|
||||
_source: std::net::Ipv4Addr,
|
||||
) -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Assigned overlay addresses when the OS chooses a new interface name on reconfiguration.
|
||||
fn assigned_addresses(&self) -> Vec<std::net::IpAddr> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Creates a device.
|
||||
fn create<'a>(
|
||||
&'a self,
|
||||
@@ -229,37 +244,34 @@ impl TunDevice for MemoryTun {
|
||||
/// enough here: the agent chose the address, so anything else holding it is a
|
||||
/// problem in its own right.
|
||||
pub fn address_is_local(address: std::net::IpAddr) -> bool {
|
||||
if std::net::UdpSocket::bind((address, 0)).is_ok() {
|
||||
return true;
|
||||
}
|
||||
let bound = std::net::UdpSocket::bind((address, 0)).is_ok();
|
||||
#[cfg(all(feature = "tun-device", target_os = "windows"))]
|
||||
{
|
||||
if let Ok(interfaces) = std::panic::catch_unwind(netdev::get_interfaces) {
|
||||
for iface in interfaces {
|
||||
if iface.is_up() {
|
||||
match address {
|
||||
std::net::IpAddr::V4(v4) => {
|
||||
if iface.ipv4.iter().any(|ip| ip.addr() == v4) {
|
||||
return true;
|
||||
}
|
||||
if !bound && let Ok(interfaces) = std::panic::catch_unwind(netdev::get_interfaces) {
|
||||
for iface in interfaces {
|
||||
if iface.is_up() {
|
||||
match address {
|
||||
std::net::IpAddr::V4(v4) => {
|
||||
if iface.ipv4.iter().any(|ip| ip.addr() == v4) {
|
||||
return true;
|
||||
}
|
||||
std::net::IpAddr::V6(v6) => {
|
||||
if iface.ipv6.iter().any(|ip| ip.addr() == v6) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
std::net::IpAddr::V6(v6) => {
|
||||
if iface.ipv6.iter().any(|ip| ip.addr() == v6) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
bound
|
||||
}
|
||||
|
||||
/// Creates [`MemoryTun`] devices.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct MemoryTunFactory {
|
||||
created: Arc<std::sync::Mutex<Vec<Arc<MemoryTun>>>>,
|
||||
rules: Option<Arc<dyn super::hostrules::BroadcastHostRules>>,
|
||||
}
|
||||
|
||||
impl MemoryTunFactory {
|
||||
@@ -268,6 +280,12 @@ impl MemoryTunFactory {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Simulate host rule outcomes alongside this in-memory interface.
|
||||
pub fn with_host_rules(mut self, rules: Arc<dyn super::hostrules::BroadcastHostRules>) -> Self {
|
||||
self.rules = Some(rules);
|
||||
self
|
||||
}
|
||||
|
||||
/// The device created for an interface name, if any.
|
||||
pub fn device(&self, name: &str) -> Option<Arc<MemoryTun>> {
|
||||
let guard = match self.created.lock() {
|
||||
@@ -291,6 +309,9 @@ impl MemoryTunFactory {
|
||||
}
|
||||
|
||||
impl TunFactory for MemoryTunFactory {
|
||||
fn host_rules(&self) -> Option<Arc<dyn super::hostrules::BroadcastHostRules>> {
|
||||
self.rules.clone()
|
||||
}
|
||||
fn name(&self) -> &str {
|
||||
"memory"
|
||||
}
|
||||
|
||||
@@ -92,18 +92,20 @@ type CheckKey = (NetworkId, EndpointId, Ipv4Addr, Protocol, u16);
|
||||
/// A bounded TCP connect check prepared off the packet path.
|
||||
pub(crate) struct CheckJob {
|
||||
key: CheckKey,
|
||||
source: Ipv4Addr,
|
||||
timeout: Duration,
|
||||
}
|
||||
impl CheckJob {
|
||||
pub async fn run(self) -> (Self, bool) {
|
||||
let ok = matches!(
|
||||
tokio::time::timeout(
|
||||
self.timeout,
|
||||
tokio::net::TcpStream::connect((self.key.2, self.key.4))
|
||||
)
|
||||
.await,
|
||||
Ok(Ok(_))
|
||||
);
|
||||
pub async fn run(
|
||||
self,
|
||||
bind: impl FnOnce(&tokio::net::TcpSocket, Ipv4Addr) -> std::io::Result<()>,
|
||||
) -> (Self, bool) {
|
||||
let connect = async {
|
||||
let socket = tokio::net::TcpSocket::new_v4()?;
|
||||
bind(&socket, self.source)?;
|
||||
socket.connect((self.key.2, self.key.4).into()).await
|
||||
};
|
||||
let ok = matches!(tokio::time::timeout(self.timeout, connect).await, Ok(Ok(_)));
|
||||
(self, ok)
|
||||
}
|
||||
}
|
||||
@@ -396,6 +398,7 @@ impl VipRouter {
|
||||
for (l, b) in listeners {
|
||||
let key = (network, peer, address, l.protocol, b.port);
|
||||
wanted_checks.insert(key);
|
||||
let Some(source) = source else { continue };
|
||||
if l.protocol != Protocol::Tcp || !l.port_check {
|
||||
continue;
|
||||
}
|
||||
@@ -412,6 +415,7 @@ impl VipRouter {
|
||||
{
|
||||
jobs.push(CheckJob {
|
||||
key,
|
||||
source,
|
||||
timeout: Duration::from_millis(u64::from(l.check_timeout_ms)),
|
||||
});
|
||||
}
|
||||
@@ -1078,6 +1082,38 @@ mod tests {
|
||||
};
|
||||
assert_eq!(packet::tuple(&reply), Some(t.reverse()));
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn tcp_check_connects_only_after_the_overlay_socket_is_bound() {
|
||||
use std::io;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
let (_, network, local, _, _, _) = fixture(Protocol::Tcp);
|
||||
let server = tokio::net::TcpListener::bind((Ipv4Addr::LOCALHOST, 0))
|
||||
.await
|
||||
.unwrap();
|
||||
let port = server.local_addr().unwrap().port();
|
||||
let job = || CheckJob {
|
||||
key: (network, local, Ipv4Addr::LOCALHOST, Protocol::Tcp, port),
|
||||
source: Ipv4Addr::LOCALHOST,
|
||||
timeout: Duration::from_secs(1),
|
||||
};
|
||||
let called = AtomicUsize::new(0);
|
||||
let (_, ok) = job()
|
||||
.run(|_, source| {
|
||||
assert_eq!(source, Ipv4Addr::LOCALHOST);
|
||||
called.fetch_add(1, Ordering::Relaxed);
|
||||
Err(io::Error::other("VPN replaced"))
|
||||
})
|
||||
.await;
|
||||
assert!(!ok);
|
||||
assert_eq!(called.load(Ordering::Relaxed), 1);
|
||||
let (_, ok) = job()
|
||||
.run(|socket, source| socket.bind((source, 0).into()))
|
||||
.await;
|
||||
assert!(ok);
|
||||
let (_, peer) = server.accept().await.unwrap();
|
||||
assert_eq!(peer.ip(), Ipv4Addr::LOCALHOST);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn active_tcp_port_checks_recover_after_a_real_listener_appears() {
|
||||
let (r, n, local, _, _, _) = fixture(Protocol::Tcp);
|
||||
@@ -1099,7 +1135,7 @@ mod tests {
|
||||
}
|
||||
let (_, jobs) = r.tick(32);
|
||||
for job in jobs {
|
||||
let (job, ok) = job.run().await;
|
||||
let (job, ok) = job.run(|_, _| Ok(())).await;
|
||||
assert!(ok);
|
||||
r.checked(job, ok);
|
||||
}
|
||||
@@ -1112,7 +1148,7 @@ mod tests {
|
||||
}
|
||||
let (_, jobs) = r.tick(32);
|
||||
for job in jobs {
|
||||
let (job, ok) = job.run().await;
|
||||
let (job, ok) = job.run(|_, _| Ok(())).await;
|
||||
assert!(!ok);
|
||||
r.checked(job, ok);
|
||||
}
|
||||
@@ -1127,7 +1163,7 @@ mod tests {
|
||||
}
|
||||
let (_, jobs) = r.tick(32);
|
||||
for job in jobs {
|
||||
let (job, ok) = job.run().await;
|
||||
let (job, ok) = job.run(|_, _| Ok(())).await;
|
||||
r.checked(job, ok);
|
||||
}
|
||||
assert!(r.statuses(n)[0].listeners[0].selected.is_some());
|
||||
|
||||
Reference in new issue
Block a user