Docs.rs
  • netns-rs-0.1.0
    • netns-rs 0.1.0
    • Permalink
    • Docs.rs crate page
    • Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • github:openanolis:dragonball
    • wllenyj
    • Dependencies
      • nix ^0.23.1 normal
      • thiserror ^1.0.30 normal
    • Versions
    • 45% of the crate is documented
  • Platform
    • i686-unknown-linux-gnu
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate netns_rs

netns_rs0.1.0

  • All Items

Sections

  • Examples

Crate Items

  • Structs
  • Enums
  • Traits
  • Functions
  • Type Aliases

Crates

  • netns_rs

Crate netns_rs

Source
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§

DefaultEnv
A default network namespace environment.
NetNs
A network namespace type.

Enums§

Error

Traits§

Env
Defines a NetNs environment behavior.

Functions§

get_from_current_thread
Returns the NetNs of current thread.
get_from_path
Returns the NetNs with the spectified path.

Type Aliases§

Result

Results

Settings
Help

Query parser error: "Unexpected - (did you mean ->?)".