Building a net.Conn type from the ground up

By Matt Layher

Elevator Pitch

Package net is a one-stop shop for Go networking with TCP or UDP, but there are many other interesting and unusual socket types in the wild. This talk will demonstrate how to build a net.Conn type using the Linux system call interface, and show how that type can be used to serve SSH, HTTP, and more!

Description

The standard library’s net package is a fundamental building block for creating highly concurrent networking applications in Go. Package net supports TCP, UDP, UNIX, and even IP-layer socket networking. However, for some low-level networking applications, these building blocks may be insufficient.

Some time ago, I discovered an interesting new Linux socket family: Linux virtual machine sockets (“AF_VSOCK” or just “vsock”). The vsock address family enables reliable communication between a hypervisor and its virtual machines (VMs), very much like a TCP connection. The primary benefit of vsock is that it can be used to implement guest agents within VMs, which are able to communicate with their underlying hypervisor. Unlike TCP, vsock can be used even if no network interfaces are present within the guest VM. With great excitement, I decided to get to work on a Go implementation of vsock functionality; but how does one go about implementing a new socket family in Go?

This talk will demonstrate how to package a low-level Linux system call interface in a high-level net.Conn wrapper. This wrapper can be used to easily add new protocol support for existing Go networking libraries, and even to serve SSH, HTTP, and more. As we build out the vsock package, the audience will learn:

  • the required package net interfaces our custom types must implement
  • the expected behaviorial contract that net.Conn types must fulfill
  • the basics of the BSD sockets API using golang.org/x/sys/unix
  • the work that Go’s runtime network poller does behind the scenes, and how to take advantage of its features

During this talk, I will share both my successes and failures encountered while building low-level networking applications in Go. Real world examples will be used to demonstrate the true power and flexibility of Go’s networking primitives. At the presentation’s conclusion, audience members will walk away with a better understanding of how to build efficient and flexible networking libraries in Go.

Notes

This talk is intended for intermediate-to-advanced Go users who are interested in building unusual, operating system-specific, networking applications with Go. I will explain how to package a low-level Linux system call interface in a high-level net.Conn wrapper: one that can be used for applications such as SSH, HTTP, and more.

Some Go programmers may have never worked directly with low-level sockets, but it can be incredibly helpful to understand how some of these concepts truly work under the hood. Go’s package net implements convenient high-level abstractions over TCP and UDP sockets, but it also abstracts away much of the complexity related to the runtime network poller. I believe that implementing the Linux VM sockets (vsock) family in Go could provide a great opportunity to discuss and share why many of these abstractions are in place, and why they are beneficial in real applications. In particular, vsock is a great choice because it provides reliable message transmission like TCP, making it suitable for use in a net.Conn type, and in HTTP, SSH, and other servers.

I’ve been working in Go for the past 5 years, and have a great deal of experience exposing low-level socket interfaces as high-level APIs in my open source projects. I believe I can effectively convey many of the important concepts in a conference presentation format. I have previously spoken at several software conferences related to Go and other projects, and would absolutely love an opportunity to share my knowledge with the Go community at [conference].

Thank you very much for your time and for your consideration.