Development discussion of WireGuard
 help / color / mirror / Atom feed
From: "KeXianbin(http://diyism.com)" <kexianbin@diyism.com>
To: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Any possibility to run wireguard-go with android vpnservice?
Date: Tue, 9 Mar 2021 21:44:56 +0800	[thread overview]
Message-ID: <CAKVinOUJVEyxfT-bOhUe4gZb7yUN_=xwun13pnt+iDZus=LRXQ@mail.gmail.com> (raw)

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

             reply	other threads:[~2021-03-09 21:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 13:44 KeXianbin(http://diyism.com) [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKVinOUJVEyxfT-bOhUe4gZb7yUN_=xwun13pnt+iDZus=LRXQ@mail.gmail.com' \
    --to=kexianbin@diyism.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).