NAT66 Userspace solution [enhancement]
Background & Motivation
In Interface mode, VirtualAP currently handles IPv6 on a best-effort basis:
- Clients receive global addresses from the phone's own upstream
/64via SLAAC and NDP proxying. - Per-client
/128routes are added onap0. - A background loop pings
ff02::1every 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
- Internal prefix allocation. Assign a local prefix to
ap0, either a ULA fromfc00::/7or 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. - 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.
- 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::1discovery 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
- Install Magic V2Ray and start the core.
- Turn on Enable IPv6 and Advertise IPv6 to apps.
- Magic V2Ray assigns a random
2001:db8:6875:736b::xxxx:xxxx/64address to the current interface, even if the interface already has a real IPv6/64. - VirtualAP then picks that address as its upstream.
Option B: use the TUN interface as upstream
- Start the core and turn on Enable IPv6.
- Select
xraytun0as 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.
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
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.
Almost stock roms don't have nat66, so nat66 won't work on 90% devices
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.