4 releases

new 0.0.4 Apr 9, 2024
0.0.3 Jan 16, 2024
0.0.2 Jan 13, 2024
0.0.1 Jan 13, 2024

#598 in Network programming

Download history 16/week @ 2024-01-12 3/week @ 2024-02-16 24/week @ 2024-02-23 54/week @ 2024-03-01 9/week @ 2024-03-08 11/week @ 2024-03-15 12/week @ 2024-03-29 199/week @ 2024-04-05

222 downloads per month

Custom license

84KB
2K SLoC

RsCNI

RsCNI is a CNI plugin library for Rust. This is based on containernetworking/cni.

GitHub release crate-name at crates.io crate-name at docs.rs CI

[!WARNING] RsCNI is under experimental.

Use

RsCNI has a similar APIs to containernetworking/cni/pkg/skel.

The entrypoint structure is Plugin. It accepts callback functions defined as CmdFn to represent CNI Add, Del and Check commands.

pub struct Plugin {
    add: CmdFn,
    del: CmdFn,
    check: CmdFn,
    version_info: PluginInfo,
    about: String,
    dispatcher: Dispatcher,
}

CmdFn is the type for CNI commands. It is the function type that accepts Args that is CNI arguments and return CNIResult or Error. As we implement some functions satisfy this type, we can build our own CNI plugin.

pub type CmdFn = fn(args: Args) -> Result<CNIResult, Error>;

For async version, we have to implement the following type.

[!NOTE] To use async version of rscni, please enable the async feature in your Cargo.toml.

pub type CmdFn = fn(Args) -> Pin<Box<dyn Future<Output = Result<CNIResult, Error>>>>;

To run Plugin, we can call run() method like following.

fn main() {
    let version_info = PluginInfo::default();
    let mut dispatcher = Plugin::new(add, del, check, version_info, ABOUT_MSG);

    dispatcher.run().expect("Failed to complete the CNI call");
}

For details, please see examples/rscni-debug.

Example project

License

RsCNI is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Dependencies

~0.7–1.5MB
~33K SLoC