Skip to content

Implement TSO on linux tun device#10

Draft
hulthe wants to merge 7 commits intomainfrom
tso
Draft

Implement TSO on linux tun device#10
hulthe wants to merge 7 commits intomainfrom
tso

Conversation

@hulthe
Copy link
Copy Markdown
Contributor

@hulthe hulthe commented Aug 29, 2025

This change is Reviewable

@hulthe hulthe force-pushed the tso branch 9 times, most recently from 4be4cf9 to bef7b6e Compare September 1, 2025 08:17
@hulthe hulthe force-pushed the mullvad branch 3 times, most recently from 9ca82fc to 474e2a3 Compare September 12, 2025 15:12
@hulthe hulthe force-pushed the tso branch 3 times, most recently from 66a3a15 to c743c80 Compare February 26, 2026 16:37
DivMode added a commit to DivMode/gotatun that referenced this pull request Apr 29, 2026
…eTunnelPeers

Tasks 7-9 of PRD #1618. Brings the JNI surface from "skeleton" to
"functionally complete" — every Java native call now drives real
GotaTun work.

New modules:

- runtime.rs: process-wide Tokio multi-thread runtime + tunnel
  registry. Type-erased Device behind a DeviceShutdown trait so the
  registry doesn't propagate the DeviceTransports generic. Lazy
  OnceLock for the runtime so we only pay the build cost on first
  awgTurnOn.

- tun_bridge.rs: wraps a raw Linux TUN fd (delivered over JNI from
  Android's VpnService.Builder().establish()) as a tun::AsyncDevice
  via Configuration::raw_fd, then hands to gotatun TunDevice.

- udp_factory.rs: FdRecordingUdpFactory wraps GotaTun's UdpSocketFactory
  and captures bound socket fds via UdpSocket's AsFd impl. The
  Atomic<i32> handles are cloned into the TunnelEntry so the JNI
  surface can read them without holding a reference to the factory
  (which lives inside the Device's transport state).

awgTurnOn flow:
  parse settings → build TunDevice from raw fd → DeviceBuilder.with_uapi
  + with_udp(FdRecording) + with_ip(tun) → block_on .build() →
  UapiClient.send_sync(Set) to install peers → store in registry → return
  i32 handle.

awgTurnOff: Registry.remove(handle) → DeviceShutdown.stop_blocking()
  drops UAPI client + awaits Device::stop on the runtime.

awgGetSocketV4/V6: read AtomicI32 from registry entry. -1 if handle
  unknown or socket not yet bound (transient before DeviceBuilder
  finishes; awgTurnOn has already returned by that point in practice).

awgGetConfig: send Request::Get(Get::default()) via UapiClient,
  format the GetResponse via its Display impl. Returns "" on error so
  the Kotlin side gets a parseable empty config.

awgUpdateTunnelPeers: parse new settings, strip interface-level
  fields, build a peers-only Set with replace_peers=true, send via
  UapiClient. Matches amneziawg-go's CreatePeerIPCRequest semantics —
  replaces the peer table without disturbing the private key/listen
  port.

Tests: 19/19 still passing on host. New runtime/tun_bridge/udp_factory
modules don't have unit tests because they need a real TUN device or
real UDP bind to exercise — those are integration-level concerns
covered by the localhost-loopback test in task mullvad#10 and the live phone
test in task mullvad#11.

Tracks: DivMode/catchseo#1618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant