Expand description

This crate provides an ultra-simple interface for handling network namespaces in Rust. Changing namespaces requires elevated privileges, so in most cases this code needs to be run as root.

We can simply create a NetNs using NetNs::new. Once created, the netns instance can be used.

Examples

use netns_rs::NetNs;

// create a new netns in `/var/run/netns` by default.
let mut ns = NetNs::new("my_netns").unwrap();

ns.run(|_| {
    // do something in the new netns. eg. ip link add.
}).unwrap();

// removes netns.
ns.remove().unwrap();

To get a Netns that already exists, you can use the NetNs::get series of functions.

use netns_rs::NetNs;

let ns = NetNs::get("my_netns").unwrap();

Or use get_from_current_thread to get the netns of the current thread.

use netns_rs::get_from_current_thread;

let ns = get_from_current_thread().unwrap();

Structs

A default network namespace environment.

A network namespace type.

Enums

Traits

Defines a NetNs environment behavior.

Functions

Returns the NetNs of current thread.

Returns the NetNs with the spectified path.

Type Definitions