Skip to content

feat: enable udpgw client via tun2proxy CLI API — no fork needed#270

Closed
yyoyoian-pixel wants to merge 3 commits intotherealaleph:mainfrom
yyoyoian-pixel:feat/udpgw-cli-api
Closed

feat: enable udpgw client via tun2proxy CLI API — no fork needed#270
yyoyoian-pixel wants to merge 3 commits intotherealaleph:mainfrom
yyoyoian-pixel:feat/udpgw-cli-api

Conversation

@yyoyoian-pixel
Copy link
Copy Markdown
Contributor

Summary

Enables udpgw on Android using upstream tun2proxy's tun2proxy_run_with_cli_args C API — no fork, no patch, no submodule.

The tun2proxy maintainer recommended this approach over modifying the JNI run() signature. The CLI API accepts --udpgw-server natively and offers more flexibility.

How it works

  1. MhrvVpnService.kt builds a CLI args string: tun2proxy --proxy socks5://... --tun-fd N --udpgw-server 198.18.0.1:7300 ...
  2. Native.runTun2proxy() calls the Rust JNI wrapper
  3. android_jni.rs resolves tun2proxy_run_with_cli_args at runtime via dlsym from libtun2proxy.so
  4. The function blocks until Tun2proxy.stop() is called (same shutdown path)

Why dlsym?

Android's linker namespaces prevent compile-time cross-.so symbol resolution. libmhrv_rs.so can't statically link against libtun2proxy.so symbols — the app crashes on library load with UnsatisfiedLinkError. Runtime dlsym avoids this.

Changes

File What
Cargo.toml Enable udpgw feature on tun2proxy, remove [patch.crates-io]
MhrvVpnService.kt Build CLI args with --udpgw-server 198.18.0.1:7300 in full mode
Native.kt Add runTun2proxy(cliArgs, tunMtu) declaration
android_jni.rs dlsym-based wrapper calling tun2proxy_run_with_cli_args
Tun2proxy.kt Reverted to upstream signature (no extra param)
Cargo.lock Updated for udpgw feature

Test plan

  • App launches without crash
  • Full mode connects with udpgw enabled
  • VoIP calls work through tunnel
  • Tun2proxy.stop() cleanly shuts down
  • No fork, no patch, no submodule — pure upstream tun2proxy 0.7

🤖 Generated with Claude Code

yyoyoian-pixel and others added 3 commits April 26, 2026 18:46
…, and share sheet

- Clipboard paste: banner auto-detects mhrv:// or raw JSON in clipboard,
  one tap to import. Clipboard cleared after successful import.
- Export dialog: QR code + compressed hash + copy button + Android share
  sheet (sends QR image + text together).
- QR scanner: ZXing embedded scanner in portrait orientation.
- Deep link: mhrv:// URIs auto-open the app and import the config.
- Compact encoding: only non-default fields included, DEFLATE compressed
  before base64. Accepts both compressed and raw JSON on import.
- ConfigStore.loadFromJson() deduplicated — shared by file load + import.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…s:// scheme

Security fix: deep link (mhrv-rs://) no longer auto-imports config.
Stashes decoded config for UI confirmation dialog — same flow as
clipboard paste and QR scan.

Import confirmation dialog now shows:
- Trust warning: "Importing routes your traffic through the deployment
  IDs in this config. Only import from trusted sources."
- Mode and deployment ID count with first 3 IDs previewed
- Explicit Import / Cancel buttons

Also:
- Renamed scheme from mhrv:// to mhrv-rs:// (less collision risk)
- Deduplicated import dialog into shared ImportConfirmDialog composable

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Uses tun2proxy_run_with_cli_args (the C API) via dlsym instead of
modifying the JNI run() signature. The upstream tun2proxy maintainer
recommended this path — the CLI API accepts --udpgw-server natively
and offers more flexibility than the JNI entry point.

Changes:
- Cargo.toml: enable udpgw feature on tun2proxy, remove [patch.crates-io]
- MhrvVpnService.kt: build CLI args string with --udpgw-server in full mode
- Native.kt + android_jni.rs: Native.runTun2proxy() resolves
  tun2proxy_run_with_cli_args at runtime via dlsym from libtun2proxy.so
- Tun2proxy.kt: reverted to upstream signature (no extra parameter)

No fork, no patch, no submodule. Upstream tun2proxy 0.7 with
features = ["udpgw"] is all that's needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the type: feature feat: PR — auto-applied by release-drafter label Apr 26, 2026
@yyoyoian-pixel
Copy link
Copy Markdown
Contributor Author

Superseded by clean branch without config sharing changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature feat: PR — auto-applied by release-drafter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant