ulagen 1.0.0

Generate random IPv6 Unique Local Address (ULA) /48 prefixes per RFC 4193, as a library and CLI.
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented3 out of 8 items with examples
  • Size
  • Source code size: 28.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 480.52 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ekline/ulagen
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ekline

ulagen

crates.io docs.rs

Generate random IPv6 Unique Local Address (ULA) /48 prefixes per RFC 4193.

This crate provides:

  • A small, dependency-light library for producing random ULA prefixes from any rand::Rng, and an Ipv6Prefix type with Display / FromStr.
  • A command-line tool (ulagen) that prints one or more prefixes to stdout.

Why ULAs?

Unique Local IPv6 Unicast Addresses are sometimes (incorrectly) described as "RFC 1918 for IPv6". They are not. A key design goal of ULAs is that two independently-generated /48s have a vanishingly small probability of colliding, so networks can be merged or interconnected (VPN, acquisition, etc.) without renumbering or NAT.

To preserve that property, ULAs must be generated with sufficient randomness — not picked by hand, and not allocated sequentially. This crate uses a CSPRNG seeded from the operating system (rand::rng) by default.

Library usage

use ulagen::{generate_ula_prefix, generate_ula_prefix_with};

// Use the default thread-local CSPRNG:
let prefix = generate_ula_prefix();
println!("{prefix}"); // e.g. "fdab:cd12:3456::/48"

// Or supply your own RNG (useful for tests / reproducibility):
let mut rng = rand::rng();
let prefix = generate_ula_prefix_with(&mut rng);
assert_eq!(prefix.prefix_len(), 48);
assert_eq!(prefix.addr().octets()[0], 0xfd);

CLI usage

$ ulagen
fd2a:9c41:7b6e::/48

$ ulagen -n 4 | sort
fd1c:bd44:0e51::/48
fd66:ef2a:9988::/48
fd9b:0203:7c4d::/48
fde0:1122:3344::/48

Install

Library:

[dependencies]
ulagen = "1"

CLI:

cargo install ulagen

RFC 4193 compliance notes

  • The generated prefix is in fd00::/8 (the locally-assigned half of fc00::/7). fc00::/8 is reserved by RFC 4193 §3.1 for an as-yet-undefined centrally assigned scheme.
  • The 40-bit Global ID is filled from the supplied RNG. RFC 4193 §3.2.1 describes a SHA-1-based pseudo-random algorithm; this crate instead uses a CSPRNG, which satisfies the spirit of the requirement (a uniformly distributed, hard-to-predict 40-bit value). If strict §3.2.1 conformance matters for your use case, you should compute the Global ID separately.
  • The bits below /48 (subnet ID and interface ID) are zeroed.

License

MIT — see the LICENSE file.