RsCNI
A Rust library for building CNI (Container Network Interface) plugins with trait-based architecture.
RsCNI provides a type-safe API for implementing CNI plugins in Rust, following the CNI specification v1.1.0.
Breaking Changes in v0.1.0
The API has been completely redesigned from v0.0.4 with a new trait-based architecture.
Features
- Idiomatic Rust: Trait-based design with type safety and zero-cost abstractions
- Async Support: Optional async/await support for high-performance plugins
- CNI Spec Compliant: Supports CNI specification v0.3.1, v0.4.0, v1.0.0, and v1.1.0
- Well-tested: Comprehensive unit tests and integration tests
Installation
Add this to your Cargo.toml:
[]
= "0.1"
For async support, you need to enable the async feature and add async-trait and an async runtime (such as tokio):
[]
= { = "0.1", = ["async"] }
= "0.1"
= { = "1", = ["full"] }
Quick Start
Basic Plugin (Sync)
Implement the Cni trait to create your CNI plugin:
use ;
use ;
;
Async Plugin
Enable the async feature and implement the async Cni trait:
use async_trait;
use ;
use ;
;
async
Examples
Complete working examples are available in the examples/ directory:
- rscni-debug - Synchronous CNI plugin for debugging
- async-rscni-debug - Asynchronous CNI plugin for debugging
Run examples:
# Build the debug plugin
# Test with CNI environment
CNI_COMMAND=VERSION
CNI Data Types
RsCNI provides strongly-typed structures for CNI configurations:
Args- CNI command arguments (container ID, netns, ifname, etc.)NetConf- Network configuration from stdinCNIResult- Plugin execution result with IPs, routes, DNSPluginInfo- Plugin version information
See the API documentation for complete type definitions.
Testing
RsCNI includes comprehensive test coverage:
# Run unit tests only
# Run with async feature
# Run integration tests
License
RsCNI is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.