wireguard-go/tun
Jason A. Donenfeld 675955de5d tun: add tcpip stack tunnel abstraction
This allows people to initiate connections over WireGuard without any
underlying operating system support.

I'm not crazy about the trash it adds to go.sum, but the code this
actually adds to the binaries seems contained to the gvisor repo.

For the TCP/IP implementation, it uses gvisor. And it borrows some
internals from the Go standard library's resolver in order to bring Dial
and DialContext to tun_net, along with the LookupHost helper function.
This allows for things like HTTP2-over-TLS to work quite well:

    package main

    import (
        "io"
        "log"
        "net"
        "net/http"

        "golang.zx2c4.com/wireguard/device"
        "golang.zx2c4.com/wireguard/tun"
    )

    func main() {
        tun, tnet, err := tun.CreateNetTUN([]net.IP{net.ParseIP("192.168.4.29")}, []net.IP{net.ParseIP("8.8.8.8"), net.ParseIP("8.8.4.4")}, 1420)
        if err != nil {
            log.Panic(err)
        }
        dev := device.NewDevice(tun, &device.Logger{log.Default(), log.Default(), log.Default()})
        dev.IpcSet(`private_key=a8dac1d8a70a751f0f699fb14ba1cff7b79cf4fbd8f09f44c6e6a90d0369604f
    public_key=25123c5dcd3328ff645e4f2a3fce0d754400d3887a0cb7c56f0267e20fbf3c5b
    endpoint=163.172.161.0:12912
    allowed_ip=0.0.0.0/0
    `)
        dev.Up()

        client := http.Client{
            Transport: &http.Transport{
                DialContext: tnet.DialContext,
            },
        }
        resp, err := client.Get("https://www.zx2c4.com/ip")
        if err != nil {
            log.Panic(err)
        }
        body, err := io.ReadAll(resp.Body)
        if err != nil {
            log.Panic(err)
        }
        log.Println(string(body))
    }

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-01-13 16:33:40 +01:00
..
tuntest tun/tuntest: make genICMPv4 allocate less 2021-01-07 14:49:37 +01:00
wintun memmod: apply explicit build tags to _32 and _64 files 2021-01-07 14:49:44 +01:00
operateonfd.go global: update header comments and modules 2020-05-02 02:08:26 -06:00
tun.go global: update header comments and modules 2020-05-02 02:08:26 -06:00
tun_darwin.go tun: use SockaddrCtl from golang.org/x/sys/unix on macOS 2020-10-27 16:20:09 +01:00
tun_freebsd.go global: switch to using %w instead of %v for Errorf 2020-11-07 21:56:32 +01:00
tun_linux.go global: update header comments and modules 2020-05-02 02:08:26 -06:00
tun_net.go tun: add tcpip stack tunnel abstraction 2021-01-13 16:33:40 +01:00
tun_openbsd.go all: use ++ to increment 2021-01-07 14:49:44 +01:00
tun_windows.go tun: make customization of WintunPool and requested GUID more obvious 2021-01-07 14:49:44 +01:00