Preserve mesh transport through an internet exit in 1.0.3-rc1

On macOS a connected socket using the physical source lost its route before
PF could see the packet. Fresh sockets could leave via the physical uplink,
but Darwin rejected reverse-NAT replies delivered to a utun address there.
With two live meshes remote control and data sessions expired within a minute.

Install matching interface-scoped uplink routes before capturing the two
unscoped defaults. Keep PF state on the physical interface, preserve transport
ports and return tagged replies via loopback. Reconcile uplink changes and
recover only owned routes using a private journal and kernel markers. On
Windows keep existing LAN routes, retain recent verified reconnect paths and
refresh the gateway and relay DNS without replacing the split defaults.

Exercise two memberships of the same peer, new and established native
transport sockets, ordinary application traffic and scoped route cleanup.
Run hosted macOS and Windows native regressions on affected changes. Bump the
packages to 1.0.3-rc1 and encode Debian prereleases with a tilde so apt can
upgrade to the final release. Mesh wire formats and identities are unchanged.

Checked workspace formatting, strict Clippy and the full workspace suite on
macOS (586 passed, four opt-in tests skipped by default). The privileged macOS
kernel test passed separately. A launchd trial of the RC kept master and ch
reachable over both meshes and used the external exit past the original
timeout. Disabling the exit restored the physical IP and cleared the routes.
Linux ARM64 passed four real-agent exit tests and the privileged netns
regression. The RC APK passed the dual-subnet UDP/ICMP test on an Android 37
ARM64 emulator. Verified Debian and pacman version ordering. Native Windows
execution is covered by the hosted workflow and was not run on this Mac.
This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-25 03:47:49 +02:00
1 parent 32aa73721a
commit a189d0ad3e
28 files changed
+1698 -185

No files matched your search

+6 -6
View File
@@ -1,6 +1,6 @@
[package]
name = "tsunagi"
version = "1.0.2"
version = "1.0.3-rc1"
description = "The tsunagi command line agent."
edition.workspace = true
rust-version.workspace = true
@@ -12,11 +12,11 @@ name = "tsng"
path = "src/main.rs"
[dependencies]
tsunagi-runtime = { path = "../tsunagi-runtime", version = "1.0.2" }
tsunagi-core = { path = "../tsunagi-core", version = "1.0.2", features = ["tun-device", "dns-publish"] }
tsunagi-wireguard = { path = "../tsunagi-wireguard", version = "1.0.2" }
tsunagi-wg-quic = { path = "../tsunagi-wg-quic", version = "1.0.2" }
tsunagi-tcp-tls = { path = "../tsunagi-tcp-tls", version = "1.0.2" }
tsunagi-runtime = { path = "../tsunagi-runtime", version = "1.0.3-rc1" }
tsunagi-core = { path = "../tsunagi-core", version = "1.0.3-rc1", features = ["tun-device", "dns-publish"] }
tsunagi-wireguard = { path = "../tsunagi-wireguard", version = "1.0.3-rc1" }
tsunagi-wg-quic = { path = "../tsunagi-wg-quic", version = "1.0.3-rc1" }
tsunagi-tcp-tls = { path = "../tsunagi-tcp-tls", version = "1.0.3-rc1" }
iroh.workspace = true
tokio = { version = "1.53", features = ["rt", "rt-multi-thread", "sync", "time", "macros", "signal"] }
tracing.workspace = true
+14 -6
View File
@@ -4658,7 +4658,7 @@ async fn up(args: UpArgs) -> Result<(), Box<dyn std::error::Error>> {
let tun_factory: Arc<dyn TunFactory> = if args.no_tun {
Arc::new(MemoryTunFactory::new())
} else {
system_tun_factory()?
system_tun_factory(&paths.state_dir)?
};
let mtu = args.mtu.unwrap_or(tsunagi_wg_quic::DEFAULT_MTU);
config = config.with_interface(tun_factory, args.interface.clone(), mtu);
@@ -4955,7 +4955,9 @@ async fn stop_signal() -> &'static str {
/// an open file descriptor and goes away with the agent, however the agent
/// goes away.
#[cfg(target_os = "linux")]
fn system_tun_factory() -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
fn system_tun_factory(
_state_dir: &std::path::Path,
) -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
use tsunagi::overlay::{ManagedTunFactory, NetlinkProvisioner};
let provisioner = NetlinkProvisioner::new()?;
let rules = Arc::new(provisioner.host_rules());
@@ -4967,7 +4969,9 @@ fn system_tun_factory() -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error
/// The Wintun adapter, created and configured by the agent and removed when it
/// exits, the same as the Linux one.
#[cfg(target_os = "windows")]
fn system_tun_factory() -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
fn system_tun_factory(
_state_dir: &std::path::Path,
) -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
use tsunagi::overlay::{ManagedTunFactory, WindowsHostRules, WintunProvisioner};
let provisioner = WintunProvisioner::new()?;
Ok(Arc::new(
@@ -4980,12 +4984,14 @@ fn system_tun_factory() -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error
/// exits, the same as the Linux and Windows ones. The kernel assigns the utun
/// unit, so the interface reports a `utunN` name the agent adopts.
#[cfg(target_os = "macos")]
fn system_tun_factory() -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
fn system_tun_factory(
state_dir: &std::path::Path,
) -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
use tsunagi::overlay::{MacosHostRules, ManagedTunFactory, UtunProvisioner};
let provisioner = UtunProvisioner::new()?;
Ok(Arc::new(
ManagedTunFactory::new(Arc::new(provisioner))
.with_host_rules(Arc::new(MacosHostRules::new())),
.with_host_rules(Arc::new(MacosHostRules::with_state_dir(state_dir))),
))
}
@@ -4994,7 +5000,9 @@ fn system_tun_factory() -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error
/// Refused here rather than at the first packet, and with the one thing that
/// does work on every platform named.
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
fn system_tun_factory() -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
fn system_tun_factory(
_state_dir: &std::path::Path,
) -> Result<Arc<dyn TunFactory>, Box<dyn std::error::Error>> {
Err(format!(
"managing the overlay interface is not implemented on {} yet. \
Run with `--no-tun` to keep the tunnels off the operating system.",