Skip to content

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

Merged
therealaleph merged 1 commit intotherealaleph:mainfrom
yyoyoian-pixel:feat/udpgw-cli-api-clean
Apr 26, 2026
Merged

feat: enable udpgw client via tun2proxy CLI API — no fork needed#271
therealaleph merged 1 commit intotherealaleph:mainfrom
yyoyoian-pixel:feat/udpgw-cli-api-clean

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. Cargo.toml: enable udpgw feature on upstream tun2proxy (features = ["udpgw"]), remove [patch.crates-io]
  2. MhrvVpnService.kt: builds CLI args string with --udpgw-server 198.18.0.1:7300 in full mode
  3. Native.runTun2proxy() → Rust JNI wrapper resolves tun2proxy_run_with_cli_args at runtime via dlsym from libtun2proxy.so
  4. Tun2proxy.kt: reverted to upstream signature (no extra parameter)

Why dlsym?

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

Changes

File What
Cargo.toml features = ["udpgw"], remove [patch.crates-io]
Cargo.lock Updated
MhrvVpnService.kt CLI args with --udpgw-server in full mode
Native.kt runTun2proxy(cliArgs, tunMtu) declaration
android_jni.rs dlsym wrapper for tun2proxy_run_with_cli_args
Tun2proxy.kt Reverted to upstream 6-param signature

Test plan

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

🤖 Generated with Claude Code

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.

- Cargo.toml: enable udpgw feature, remove [patch.crates-io]
- MhrvVpnService.kt: build CLI args with --udpgw-server in full mode
- Native.kt + android_jni.rs: dlsym wrapper for the C API
- Tun2proxy.kt: reverted to upstream signature

No fork, no patch, no submodule.

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
@Feiabyte
Copy link
Copy Markdown

Whish there was an easy way to use this on the other platforms as well. do you think proxifier would be able to use the somehow?

@yyoyoian-pixel
Copy link
Copy Markdown
Contributor Author

@Feiabyte tun2proxy cli works universally.

@therealaleph therealaleph merged commit 536aa00 into therealaleph:main Apr 26, 2026
1 check passed
@Feiabyte
Copy link
Copy Markdown

@Feiabyte tun2proxy cli works universally.

does that mean if i use proxifier i can get the same results as on android?

therealaleph added a commit that referenced this pull request Apr 26, 2026
Move from yyoyoian-pixel/tun2proxy fork (with patched JNI signature)
to canonical tun2proxy 0.7.21 from crates.io with feature flag
"udpgw". Cargo.toml [patch.crates-io] section removed entirely.

The Android side now resolves tun2proxy_run_with_cli_args at runtime
via dlsym from libtun2proxy.so, which is the upstream maintainer's
recommended path for callers that need full CLI flexibility.
mhrv-rs builds the CLI string in MhrvVpnService and passes it through
Native.runTun2proxy → src/android_jni.rs → dlsym → tun2proxy.

Future tun2proxy upgrades are now a single Cargo version bump.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

3 participants