nlink - Rust IP utilities
A modern Rust implementation of Linux network management tools, providing both a library crate and CLI binaries.
Overview
nlink is a from-scratch implementation of Linux netlink-based network management. The primary goal is to provide a high-quality Rust library for programmatic network configuration, with CLI tools serving as proof-of-concept binaries.
Key design principles:
- Library-first: Core functionality lives in a single, well-designed crate
- Async/tokio-native: Built for async Rust from the ground up
- Custom netlink: No dependency on rtnetlink or netlink-packet-* crates
- Type-safe: Leverage Rust's type system for correctness
- High-level APIs: Declarative configuration, rate limiting DSL, diagnostics
Installation
# Core netlink functionality
= "0.8"
# With additional features
= { = "0.8", = ["sockdiag", "tuntap", "tc", "output"] }
# All features
= { = "0.8", = ["full"] }
Features
| Feature | Description |
|---|---|
sockdiag |
Socket diagnostics via NETLINK_SOCK_DIAG |
tuntap |
TUN/TAP device management |
tc |
Traffic control utilities |
output |
JSON/text output formatting |
namespace_watcher |
Namespace watching via inotify |
full |
All features enabled |
Quick Start
use ;
use StreamExt;
async
High-Level APIs
Declarative Network Configuration
Define desired network state and let nlink compute and apply changes:
use ;
let config = new
.link
.link
.address;
// Compute diff and apply (idempotent)
config.apply.await?;
Rate Limiting DSL
Simple bandwidth management without TC complexity:
use ;
// Interface-wide rate limiting
let limiter = new
.egress
.ingress;
limiter.apply.await?;
// Per-IP rate limiting
let limiter = new?
.limit_ip?;
limiter.apply.await?;
Network Diagnostics
Scan for issues, check connectivity, find bottlenecks:
use Diagnostics;
let diag = new;
// Full diagnostic scan
let report = diag.scan.await?;
for issue in &report.issues
// Check connectivity to destination
let report = diag.check_connectivity.await?;
// Find bottlenecks
if let Some = diag.find_bottleneck.await?
Documentation
- Library Usage - Detailed library examples: namespaces, TC, WireGuard, error handling
- CLI Tools - ip and tc command reference
- Examples - 40+ runnable examples
Library Modules
| Module | Description |
|---|---|
nlink::netlink |
Core netlink: Connection<Route>, EventStream, namespace, TC |
nlink::netlink::config |
Declarative network configuration |
nlink::netlink::ratelimit |
High-level rate limiting API |
nlink::netlink::diagnostics |
Network diagnostics and issue detection |
nlink::netlink::genl |
Generic Netlink: WireGuard, MACsec, MPTCP |
nlink::netlink::nexthop |
Nexthop objects and ECMP groups (Linux 5.3+) |
nlink::netlink::mpls |
MPLS routes and encapsulation |
nlink::netlink::srv6 |
SRv6 segment routing |
nlink::netlink::fdb |
Bridge FDB management |
nlink::netlink::bridge_vlan |
Bridge VLAN filtering |
nlink::netlink::uevent |
Device hotplug events: Connection<KobjectUevent> |
nlink::netlink::connector |
Process lifecycle events: Connection<Connector> |
nlink::netlink::netfilter |
Connection tracking: Connection<Netfilter> |
nlink::netlink::xfrm |
IPsec SA/SP management: Connection<Xfrm> |
nlink::netlink::fib_lookup |
FIB route lookups: Connection<FibLookup> |
nlink::netlink::audit |
Linux Audit subsystem: Connection<Audit> |
nlink::netlink::selinux |
SELinux events: Connection<SELinux> |
nlink::sockdiag |
Socket diagnostics: Connection<SockDiag> (feature: sockdiag) |
nlink::util |
Parsing utilities, address helpers, name resolution |
nlink::tuntap |
TUN/TAP devices (feature: tuntap) |
Project Status
The library API is production-ready for network monitoring and configuration.
Implemented:
- Core netlink socket and connection handling
- Link operations (show, add, del, set) with 20+ link types
- Address, route, neighbor, and rule operations
- Event monitoring (link, address, route, neighbor, TC)
- TC qdisc operations with 19 qdisc types
- TC class management with typed builders (HTB, HFSC, DRR, QFQ)
- TC filter (9 types) and action (12 types) support
- TC filter chains for complex classification
- Network namespace support
- Tunnel management (GRE, IPIP, SIT, VTI, VXLAN, Geneve)
- WireGuard, MACsec, MPTCP configuration via Generic Netlink
- Nexthop objects and ECMP groups (Linux 5.3+)
- MPLS routes and encapsulation
- SRv6 segment routing and local SIDs
- Bridge FDB and VLAN filtering
- Declarative network configuration
- Rate limiting DSL
- Network diagnostics
- VRF and XFRM/IPSec support
Building
Requires Rust 1.85+ (edition 2024).
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.