mib-rs
SNMP MIB parser and resolver for Rust.
Note
This library is not currently stable. While pre-v1.0, breaking changes may occur in minor releases with no attempt to maintain backward compatibility.
Features
- SMIv1 and SMIv2 parsing: Supports RFC 1155/1212/1215 and RFC 2578/2579/2580 constructs
- Six-phase resolver: Registration, imports, types, OIDs, semantics, and checks
- OID tree: Numeric and symbolic OID resolution, subtree walking, instance lookups
- Type chains: Inherited base types, display hints, enums, and constraints
- Display-hint formatting: RFC 2579 value formatting, numeric scaling, and octet-string rendering
- Table support: Rows, columns, indexes (including augmented/implied)
- Diagnostics: Configurable strictness levels with collected diagnostics instead of fail-fast
- Lossless CST tooling: Preserves source text and recovery regions in typed syntax nodes, with cursor context and source-safe semantic navigation
- Resolution tracing: Explains domain-specific symbol selection, import provenance, fallbacks, and unresolved references
- Canonical SMIv2 writer: Emits deterministic SMIv2 text from resolved modules
- Parallel bulk loading: Loading all discoverable modules uses available CPUs; selected-module loading and resolution are sequential
- Embedded foundation modules: RFC-derived source fallbacks, byte-synchronized with gomib and deliberately adapted, for SNMPv2-SMI, SNMPv2-TC, SNMPv2-CONF, RFC1155-SMI, and others
- System path discovery: Auto-detects net-snmp and libsmi MIB directories
- Layered API: Handle-based query API, low-level arena access, and public compiler pipeline
Installation
Or add to your Cargo.toml:
[]
= "0.10"
Quick Start
Load and query a MIB module
use ;
let source = memory;
let mib = new
.source
.modules
.load
.expect;
let obj = mib.object.expect;
assert_eq!;
let ty = obj.ty.expect;
assert_eq!;
Load from system MIB directories
use Loader;
let mib = new
.system_paths
.modules
.load
.expect;
let node = mib.resolve_node.expect;
println!;
Resolve OIDs
use Loader;
let mib = new
.system_paths
.modules
.load
.expect;
// Symbolic to numeric
let oid = mib.resolve_oid.expect;
println!; // 1.3.6.1.2.1.2.2.1.2
// Instance OIDs
let instance = mib.resolve_oid.expect;
println!; // 1.3.6.1.2.1.2.2.1.2.7
// Reverse lookup
let node = mib.lookup_oid;
println!; // ifDescr
Decode and encode table indexes
Compile table index metadata while the MIB is available, then retain the owned codec in a runtime plan. Exact decoding rejects malformed, truncated, and trailing arcs; canonical encoding checks value kinds and constraints.
use Arc;
use ;
// Assume IF-MIB is already loaded into `mib`.
let codec = ;
drop; // the codec owns the metadata it needs
let decoded = codec.decode_exact.unwrap;
assert_eq!;
let encoded = codec
.encode_canonical
.unwrap;
assert_eq!;
CLI Tool
The optional mib-rs binary provides commands for working with MIBs:
Global options
When no -p paths are given, system MIB directories (net-snmp, libsmi) are used automatically.
Commands
# Load and validate modules (omit names to load all available)
# Look up an OID or name
# Show a subtree
# Search for nodes by pattern (case-insensitive, * and ? wildcards)
# Output format: MODULE::NAME OID KIND
# notification, group, compliance, capability,
# module-identity, object-identity
# Inspect a symbol in detail
# Explain symbol resolution in a specific reference domain
# Domains: type, oid, object, group-member, index, notification-object, conformance
# Emit canonical SMIv2 (stdout requires exactly one selected module)
# Omit module names with --output-dir to normalize all available user modules
# List available modules
# Show MIB search paths (custom and auto-discovered system paths)
# Lint with strict diagnostics
# Export as JSON (diagnostics go to stderr)
Feature Flags
| Feature | Default | Description |
|---|---|---|
serde |
yes | Serde support and JSON export |
cli |
no | CLI binary (mib-rs); enables serde |
To use the library without defaults:
[]
= { = "0.10", = false }
Minimum Supported Rust Version
This crate requires Rust 1.88 or later. The MSRV may be increased in minor releases.
License
Licensed under either the Apache License, Version 2.0 or the MIT license, at your option.
Contributing
Contributions are welcome. Please see CONTRIBUTING.md for guidelines.