wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: wireguard@lists.zx2c4.com
Subject: Re: Userspace Networking Stack + WireGuard + Go
Date: Fri, 15 Jan 2021 00:25:37 +0100	[thread overview]
Message-ID: <YADS8ehdQltHFpum@zx2c4.com> (raw)
In-Reply-To: <X/8aDfdkod+rCPqK@zx2c4.com>

Another example, for the curious. This one hosts a web server entirely in
userspace. All the kernel sees are incoming and outgoing encrypted
WireGuard UDP packets.

    package main
    import (
    func main() {
        tun, tnet, err := tun.CreateNetTUN(
            []net.IP{net.ParseIP(""), net.ParseIP("")},
        if err != nil {
        dev := device.NewDevice(tun, &device.Logger{log.Default(), log.Default(), log.Default()})
        listener, err := tnet.ListenTCP(&net.TCPAddr{Port: 80})
        if err != nil {
        http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
            log.Printf("> %s - %s - %s", request.RemoteAddr, request.URL.String(), request.UserAgent())
            io.WriteString(writer, "Hello from userspace TCP!")
        err = http.Serve(listener, nil)
        if err != nil {

Here's a gif: https://data.zx2c4.com/wireguard-go-userspace-networking-to-host-a-server.gif

      parent reply	other threads:[~2021-01-14 23:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 16:04 Userspace Networking Stack + WireGuard + Go Jason A. Donenfeld
2021-01-13 16:26 ` Julian Orth
2021-01-13 16:33   ` network namespace wireguard routing [Was: Re: Userspace Networking Stack + WireGuard + Go] Jason A. Donenfeld
2021-01-13 16:40     ` Julian Orth
2021-01-13 16:46     ` Toke Høiland-Jørgensen
2021-01-13 16:49       ` Jason A. Donenfeld
2021-01-14 10:44         ` Toke Høiland-Jørgensen
2021-01-15  8:12   ` Userspace Networking Stack + WireGuard + Go Marc-André Lureau
2021-01-14 23:25 ` Jason A. Donenfeld [this message]

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:

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

  git send-email \
    --in-reply-to=YADS8ehdQltHFpum@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=wireguard@lists.zx2c4.com \


* 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).