Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
fix(core): connect to paired devices over Tailscale (#105)
average7142c55d667e
diff --git a/core/nectarlink-core/src/session.rs b/core/nectarlink-core/src/session.rsindex 8c4a8ce..e864916 100644--- a/core/nectarlink-core/src/session.rs+++ b/core/nectarlink-core/src/session.rs@@ -41,15 +41,41 @@ pub(crate) const CLOSE_DUPLICATE: u32 = 100;/// QUIC close code for a normal shutdown.pub(crate) const CLOSE_NORMAL: u32 = 0;-/// Returns true if `ip` is a strictly local/private LAN or loopback address-/// (excluding carrier CGNAT `100.64.0.0/10` and global internet IPv6 `2000::/3`).+/// Returns true if `ip` is a local/private LAN or loopback address, or a+/// Tailscale tailnet address (`100.64.0.0/10`, `fd7a:115c:a1e0::/48`).+/// Global internet addresses (public IPv4, `2000::/3`) are rejected.+///+/// Tailnet addresses count as local: Tailscale's WireGuard network is private+/// to the user's devices, and it's how a PC is reached from another network+/// without relays. Carrier CGNAT shares `100.64.0.0/10`, but a direct path+/// still needs the paired device's key, and relays stay off.pub(crate) fn is_lan_ip(ip: std::net::IpAddr) -> bool {match ip.to_canonical() {- std::net::IpAddr::V4(v4) => v4.is_private() || v4.is_link_local() || v4.is_loopback(),+ std::net::IpAddr::V4(v4) => {+ v4.is_private()+ || v4.is_link_local()+ || v4.is_loopback()+ || is_tailnet_ip(std::net::IpAddr::V4(v4))+ }std::net::IpAddr::V6(v6) => v6.is_loopback() || v6.is_unicast_link_local() || v6.is_unique_local(),}}+/// Returns true if `ip` is in Tailscale's ranges: IPv4 `100.64.0.0/10` (the+/// shared address space it assigns from) or IPv6 `fd7a:115c:a1e0::/48`.+pub(crate) fn is_tailnet_ip(ip: std::net::IpAddr) -> bool {+ match ip.to_canonical() {+ std::net::IpAddr::V4(v4) => {+ let [a, b, ..] = v4.octets();+ a == 100 && (b & 0xC0) == 64+ }+ std::net::IpAddr::V6(v6) => {+ let seg = v6.segments();+ seg[0] == 0xfd7a && seg[1] == 0x115c && seg[2] == 0xa1e0+ }+ }+}+/// Returns true if two IPv6 addresses share the same `/64` subnet prefix.#[cfg(test)]pub(crate) fn is_same_ipv6_subnet(a: std::net::Ipv6Addr, b: std::net::Ipv6Addr) -> bool {@@ -721,11 +747,11 @@ async fn heartbeat(session: &Arc<Session>, shared: &Weak<Shared>) {#[cfg(test)]mod tests {- use super::{is_lan_ip, is_same_ipv6_subnet};+ use super::{is_lan_ip, is_same_ipv6_subnet, is_tailnet_ip};use std::net::{IpAddr, Ipv6Addr};#[test]- fn lan_ip_accepts_private_local_and_rejects_wan_and_cgnat() {+ fn lan_ip_accepts_private_local_and_tailnet_and_rejects_wan() {for ok in ["127.0.0.1","192.168.1.42",@@ -735,18 +761,39 @@ mod tests {"::1","fe80::1234","fd12:3456:789a::1",+ "100.64.0.1",+ "100.101.102.103",+ "100.127.255.254",+ "fd7a:115c:a1e0::1",] {let ip: IpAddr = ok.parse().unwrap();assert!(is_lan_ip(ip), "expected {ok} to be treated as LAN IP");}- for bad in ["8.8.8.8", "100.64.0.1", "100.115.92.2", "2001:4860:4860::8888", "2401:4900:1c2a:8b00::1"]+ for bad in+ ["8.8.8.8", "100.63.255.255", "100.128.0.1", "2001:4860:4860::8888", "2401:4900:1c2a:8b00::1"]{let ip: IpAddr = bad.parse().unwrap();assert!(!is_lan_ip(ip), "expected {bad} to be rejected as non-LAN IP");}}+ #[test]+ fn tailnet_ip_matches_only_tailscale_ranges() {+ for ok in [+ "100.64.0.0",+ "100.100.100.100",+ "100.127.255.255",+ "fd7a:115c:a1e0:ab12::1",+ "::ffff:100.64.1.2",+ ] {+ assert!(is_tailnet_ip(ok.parse().unwrap()), "expected {ok} to be a tailnet IP");+ }+ for bad in ["100.63.0.1", "100.128.0.1", "192.168.1.1", "fd7a:115c:a1e1::1", "fd12::1"] {+ assert!(!is_tailnet_ip(bad.parse().unwrap()), "expected {bad} not to be a tailnet IP");+ }+ }+#[test]fn ipv6_same_subnet_matches_dual_stack_router_prefix_and_rejects_cellular() {let pc_wifi: Ipv6Addr = "2001:db8:2042:8b43:894c:6df4:ca1c:7561".parse().unwrap();diff --git a/docs/technical/tailscale.md b/docs/technical/tailscale.mdnew file mode 100644index 0000000..3b169a7--- /dev/null+++ b/docs/technical/tailscale.md@@ -0,0 +1,49 @@+# Connecting over Tailscale++## Why it failed+Pairing links already carry the PC's tailnet address (`pairing.rs`, `link_addrs`+keeps `100.x`). But with Connect over mobile data (away mode) off, every address+filter in the core used `session::is_lan_ip`, which rejected `100.64.0.0/10`+as carrier CGNAT. So:++- at node start and when away mode is turned off, stored tailnet addresses were+ purged from each peer's `last_addrs` (`node.rs`, `Node::start`, `set_away_mode`);+- `remember_addrs` never fed them to the dialer, and `direct_addrs` never+ advertised them;+- a session that did arrive over a tailnet path was refused+ (`is_connection_allowed` → "refusing session on non-LAN path").++mDNS doesn't cross Tailscale (no multicast), so with the address dropped there+was nothing to dial. Tailscale's IPv6 range (`fd7a:115c:a1e0::/48`) is already a+unique-local address and passed; most setups only route IPv4 by default.+On Windows, the installer's firewall rule covers Private and Domain networks+only; the Tailscale adapter is often a Public network.++## Change+- `is_lan_ip` also accepts tailnet ranges (`is_tailnet_ip`: `100.64.0.0/10`,+ `fd7a:115c:a1e0::/48`). Every LAN-only filter now keeps tailnet addresses,+ so the PC's tailnet address from pairing (or learned from a session) is+ stored, dialed and allowed, with away mode off.+- No new firewall rule. A Public-profile rule for `100.64.0.0/10` would also+ open the port to carrier and hotspot networks that use that range. Instead,+ mark the Tailscale network Private once, in an administrator PowerShell:++ ```powershell+ Set-NetConnectionProfile -InterfaceAlias Tailscale -NetworkCategory Private+ ```++ The installer's existing rule (Private and Domain) then covers it.++Unchanged: pairing, device keys, QUIC end-to-end encryption, relays (still off+unless away mode is on), mDNS.++## Limits and follow-ups+- Carrier CGNAT shares `100.64.0.0/10`; such a direct path is now allowed too.+ It still needs the paired device's key and is rarely reachable.+- A device paired before its tailnet address existed has no tailnet address+ stored. Re-pair once while Tailscale is up on both, or connect once on the+ LAN with Tailscale up so the session learns the path.+- Follow-up: a "Connect by address" field (IP or MagicDNS name) in the apps,+ calling the existing `Node::add_known_addrs`; MagicDNS names need a resolve+ step before it.+- The PC's QUIC port must stay stable (the node already reuses its last port).