* Any possibility to run wireguard-go with android vpnservice?
@ 2021-03-09 13:44 KeXianbin(http://diyism.com)
2021-03-09 21:26 ` Jason A. Donenfeld
0 siblings, 1 reply; 4+ messages in thread
From: KeXianbin(http://diyism.com) @ 2021-03-09 13:44 UTC (permalink / raw)
To: WireGuard mailing list
Sorry for bothering,
I'm trying to run wireguard-go with android vpnservice:
first, I started a vpnservice and got the fd integer:
vpnConn=builder.establish();
int fd=vpnConn.getFd();
The key icon showed on the right-top corner of android phone and the
fd value is 114.
then, I modify tun_linux.go of wireguard-go:
func CreateUnmonitoredTUNFromFD1(fd int) (Device, error) {
err := unix.SetNonblock(fd, true)
if err != nil {
return nil, err
}
file := os.NewFile(uintptr(fd), "/dev/tun")
tun := &NativeTun{
tunFile: file,
events: make(chan Event, 5),
errors: make(chan error, 5),
nopi: true,
}
//name, err := tun.Name()
if err != nil {
return nil, err
}
return tun, nil
}
and modify main.go :
tun, err := func() (tun.Device, error) {
tunFdStr := os.Getenv(ENV_WG_TUN_FD)
if tunFdStr == "" {
return tun.CreateTUN(interfaceName, device.DefaultMTU)
}
fd, err := strconv.Atoi(tunFdStr);
return tun.CreateUnmonitoredTUNFromFD1(fd);
But when I run this in android directory /local/data/tmp:
WG_TUN_FD=114 ./wireguard-go wg0
It gives me: Failed to create TUN device: bad file descriptor
It seems that my try is nonsense,
but is there any possibility to run wireguard-go with vpn service
without gomobile jni?
Thanks.
Malcolm Ke
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Any possibility to run wireguard-go with android vpnservice?
2021-03-09 13:44 Any possibility to run wireguard-go with android vpnservice? KeXianbin(http://diyism.com)
@ 2021-03-09 21:26 ` Jason A. Donenfeld
2021-03-10 0:31 ` KeXianbin(http://diyism.com)
0 siblings, 1 reply; 4+ messages in thread
From: Jason A. Donenfeld @ 2021-03-09 21:26 UTC (permalink / raw)
To: KeXianbin(http://diyism.com); +Cc: WireGuard mailing list
What you're trying to do has actually already been done and is
available with a nice Java wrapper:
https://git.zx2c4.com/wireguard-android/about/#embedding
https://search.maven.org/artifact/com.wireguard.android/tunnel
https://javadoc.io/doc/com.wireguard.android/tunnel/latest/index.html
This should hopefully save you a bunch of time.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Any possibility to run wireguard-go with android vpnservice?
2021-03-09 21:26 ` Jason A. Donenfeld
@ 2021-03-10 0:31 ` KeXianbin(http://diyism.com)
2021-03-10 0:53 ` Jason A. Donenfeld
0 siblings, 1 reply; 4+ messages in thread
From: KeXianbin(http://diyism.com) @ 2021-03-10 0:31 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: WireGuard mailing list
Thanks, but I knew android-gui, it used gomobile JNI,
What I'm trying to do is use the same control script (I've integrated
PHP into android) to manage wireguard process cross multiple
platforms (for example: Android phone and armbian linux TV).
So in my case, command line wireguard accessibility is in first priority.
I saw that someone did it with
tun2socks(https://github.com/jackyflame/Yysk/blob/8ac2b21c1b11eba30205d92e8f96c6d80caaa1dd/app/src/main/java/im/socks/yysk/ssr/SsrTunnel.java#L286):
first Runtime.getRuntime().exec( ... tun2socks --tunfd
vpnConn.getFd() --sock-path /local/data/tmp/wg0.sock ...)
then System.sendFd(vpnConn.getFd(), "/local/data/tmp/wg0.sock");
So I'm trying to imitate it with wireguard-go arm64 binary, but I got
no progress
Thanks for your great work
Malcolm Ke
On Wed, Mar 10, 2021 at 5:26 AM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> What you're trying to do has actually already been done and is
> available with a nice Java wrapper:
>
> https://git.zx2c4.com/wireguard-android/about/#embedding
> https://search.maven.org/artifact/com.wireguard.android/tunnel
> https://javadoc.io/doc/com.wireguard.android/tunnel/latest/index.html
>
> This should hopefully save you a bunch of time.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Any possibility to run wireguard-go with android vpnservice?
2021-03-10 0:31 ` KeXianbin(http://diyism.com)
@ 2021-03-10 0:53 ` Jason A. Donenfeld
0 siblings, 0 replies; 4+ messages in thread
From: Jason A. Donenfeld @ 2021-03-10 0:53 UTC (permalink / raw)
To: KeXianbin(http://diyism.com); +Cc: WireGuard mailing list
> So in my case, command line wireguard accessibility is in first priority.
The library I sent you does actually set up a listening socket that
wg(8) can talk to. You should be able to control it from the command
line.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-10 0:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09 13:44 Any possibility to run wireguard-go with android vpnservice? KeXianbin(http://diyism.com)
2021-03-09 21:26 ` Jason A. Donenfeld
2021-03-10 0:31 ` KeXianbin(http://diyism.com)
2021-03-10 0:53 ` Jason A. Donenfeld
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).