xjasonlyu / tun2socks

tun2socks - powered by gVisor TCP/IP stack
https://github.com/xjasonlyu/tun2socks/wiki
GNU General Public License v3.0
2.85k stars 406 forks source link

[Feature request] UNIX Socket support for device model #96

Closed chengziorange closed 2 years ago

chengziorange commented 2 years ago

Is your feature request related to a problem?

87 ,#71

Describe the solution you'd like As it is stated in #71 , unrooted Android device cannot create TUN devices directly, as a result reading from file descriptor is needed. However, subprocess created by JVM doesn't share file descriptor as well. So tun2socks can't read from the fd passed directly by the Android App.

Luckily Android Framework provided a way to share fd between processes. The API LocalSocket.setFileDescriptorsForSend(fd) does the job, by create a UNIX domain socket and then send fd through it, using the Linux API sendmsg(ref).

So I wonder if tun2socks can accept a UNIX socket as parameter of -device, and then use the Linux API recvmsg(ref) to get the really readable file descriptor. That would be a great help for Android developing with this awesome project.

xjasonlyu commented 2 years ago

Sounds great, I'll see what I can do.

xjasonlyu commented 2 years ago

@chengziorange The unix domain socket created by that API uses DATAGRAM type, right?

chengziorange commented 2 years ago

I'm not sure but I think it is SOCK_STREAM, because I've seen some code using sendmsg() and recsmsg() with the SOCK_STREAM type. Maybe you could look for some C examples of these two api.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

chromer030 commented 2 years ago

Comment !

xjasonlyu commented 2 years ago

I suddenly realise that since tun2socks supports fd:// as the input device, which means for any socket-based scenarios including the unix domain socket, we can always open the socket and pass its file descriptor as the fd device.

So I don't think that add unix domain socket device support explicitly is necessary now.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days