Files
whitelist-bypass/relay/mobile/tun_android.go
T
84da73c324 V0.1.7 (#5)
* save url when connected and allow toggling connection on app start (#2)

* mask ip in logs, reduce keep-alive logs frequency

* update comment about debug link, migrate prefs to ktx

* auto-connect for telemost

* fix ice ipv6 resolving

* auto-connect for vk

* refactor hooks names

* regenerate android resources

* remove stale telemost dc

* kick disconnected user from vk, refactor relay on mobile client, prevent double hook injection

* refactor constants

* set low importance for notification to avoid signals

* stop vpn/relay at app destroy, reset state at vpn disconnect

* prevent vk session close at video tunnel

* kick disconnected user from vk, refactor relay on mobile client, prevent double hook injection

* multiple tabs/calls, write android logs in file

* update ux, fix fd lifecycle in tun2socks

* increment release version

---------

Co-authored-by: HukuToc2288 <hukutoc2288@yandex.ru>
Co-authored-by: kulikov <user@Mac.lan>
2026-03-26 09:54:48 +01:00

55 lines
1.1 KiB
Go

//go:build android
package mobile
import (
"fmt"
"os"
"sync"
"syscall"
"github.com/xjasonlyu/tun2socks/v2/engine"
)
var (
tunReady sync.WaitGroup
tunOrigFd int = -1
)
func StartTun2Socks(fd, mtu, socksPort int) error {
// dup the fd: tun2socks will close the dup on Stop(),
// we keep the original open to prevent the kernel from
// recycling the fd number while gvisor goroutines drain
dupFd, err := syscall.Dup(fd)
if err != nil {
return fmt.Errorf("dup tun fd: %w", err)
}
tunOrigFd = fd
proxy := fmt.Sprintf("socks5://127.0.0.1:%d", socksPort)
logMsg("tun2socks: starting fd=%d (dup=%d) mtu=%d proxy=%s", fd, dupFd, mtu, proxy)
os.Setenv("TUN2SOCKS_LOG_LEVEL", "info")
key := &engine.Key{
Proxy: proxy,
Device: fmt.Sprintf("fd://%d", dupFd),
MTU: mtu,
}
tunReady.Add(1)
engine.Insert(key)
engine.Start()
tunReady.Done()
logMsg("tun2socks: running")
return nil
}
func StopTun2Socks() {
tunReady.Wait()
engine.Stop()
// now safe to close the original - gvisor goroutines are done
if tunOrigFd >= 0 {
syscall.Close(tunOrigFd)
tunOrigFd = -1
}
logMsg("tun2socks: stopped")
}