Home / Companies / Tailscale / Blog / Post Details
Content Deep Dive

netaddr.IP: a new IP address type for Go

Blog post from Tailscale

Post Details
Company
Date Published
Author
Brad Fitzpatrick
Word Count
3,152
Language
-
Hacker News Points
-
Summary

Tailscale, a networking application primarily written in Go, developed a new IP address type to address limitations in Go's standard library net.IP and net.IPNet types. The main issues with the existing types include mutability, lack of comparability, size inefficiencies, and allocation overheads, which hinder performance and usability. To overcome these problems, Tailscale introduced inet.af/netaddr, a package featuring a new IP type that is immutable, comparable, allocation-free, and supports both IPv4 and IPv6 with zones using a more compact 24-byte representation. This new type employs innovative techniques, such as using a uint128 struct for storage and leveraging pointers for zone representation, enabling faster operations and better memory efficiency. Additionally, the package includes other constructs like IPPort, IPPrefix, IPRange, and IPSet, offering more versatile solutions for handling IP addresses and networks in Go applications.