VirtualAP icon indicating copy to clipboard operation
VirtualAP copied to clipboard

NAT66 Userspace solution [enhancement]

Open vincentng295 opened this issue 1 month ago • 4 comments

Background & Motivation

In Interface mode, VirtualAP currently handles IPv6 on a best-effort basis:

  • Clients receive global addresses from the phone's own upstream /64 via SLAAC and NDP proxying.
  • Per-client /128 routes are added on ap0.
  • A background loop pings ff02::1 every two seconds to discover clients.

This approach is fragile:

  • Stock Android kernels rarely ship ip6table_nat, so kernel-side NAT66 is usually unavailable.
  • Upstream networks often change prefixes or restrict NDP proxying, especially on cellular interfaces and strict public or enterprise Wi-Fi.

As a result, IPv6 frequently fails or drops out, and the hotspot degrades to IPv4-only.

Proposal

Add a userspace NAT66 mode for Interface mode, so IPv6 works independently of upstream NDP proxy behavior and of kernel NAT module support.

Prior art: vpnhotspot, a project similar to VirtualAP, already implements userspace NAT66.

How It Could Work

  1. Internal prefix allocation. Assign a local prefix to ap0, either a ULA from fc00::/7 or another stable internal /64 (e.g. 2001:db8:dead:cafe::/64). It would be managed entirely by a userspace daemon and rules, rather than by borrowing addresses from the upstream /64.
  2. Userspace translation (NAT66). Rewrite outbound client packets from the internal prefix to the upstream global IPv6 address, and map return traffic back to the client's internal address. Existing cores such as xray-core, sing-box or mihomo could perform the translation.
  3. No kernel dependency. Because translation happens in userspace (or with lightweight packet-processing tools), it does not need ip6table_nat, giving consistent IPv6 behavior across different Android kernels.

Benefits

  • Reliability: removes the fragile 2-second ff02::1 discovery loop and the dependence on NDP proxying.
  • Consistency: IPv6 no longer drops out when switching between restrictive cellular networks and Wi-Fi uplinks.
  • Seamless integration: Interface mode stays lightweight, and clients get working IPv6 out of the box.
  • Client hiding: all clients egress through a single IPv6 address, making it harder for the carrier to detect devices behind the hotspot.

Current Workaround (Magic V2Ray)

A similar result can already be achieved today with Magic V2Ray:

Option A: use the virtual address as upstream

  1. Install Magic V2Ray and start the core.
  2. Turn on Enable IPv6 and Advertise IPv6 to apps.
  3. Magic V2Ray assigns a random 2001:db8:6875:736b::xxxx:xxxx/64 address to the current interface, even if the interface already has a real IPv6 /64.
  4. VirtualAP then picks that address as its upstream.

Option B: use the TUN interface as upstream

  1. Start the core and turn on Enable IPv6.
  2. Select xraytun0 as the upstream interface in VirtualAP, see Magic_V2Ray/service.sh#L1249

This workaround depends on a third-party module, so a built-in solution would be more convenient and predictable.

vincentng295 avatar Nov 01 '26 13:11 vincentng295

We can use hev-socks5-tunnel + hev-socks5-server (take only ~500kb), route all traffic from fc00:abcd:ef12:9876::/64 to tunnel created by hev-socks5-tunnel

kokoromagic avatar Nov 02 '26 01:11 kokoromagic

I have to think about this. Already added NAT66 support for supported kernels in the re-written backend. The recommended way of using VirtualAP is using the managed mode, where OpenWrt handles everything.

ravindu644 avatar Nov 04 '26 09:11 ravindu644

Almost stock roms don't have nat66, so nat66 won't work on 90% devices

kokoromagic avatar Nov 04 '26 09:11 kokoromagic

4. Almost stock roms don't have nat66, so nat66 won't work on 90% devices

I know. This is part of the Droidspaces project. Droidspaces won't work on 99% of devices unless the kernel is built and Droidspaces users need NAT66 enabled in their kernels.

So, we have to accept this.

ravindu644 avatar Nov 04 '26 09:11 ravindu644