#namespaces #linux #networking #container

netns-rs

A library to handle Linux network namespaces in Rust

1 unstable release

0.1.0 Apr 25, 2022

#62 in #namespaces

Download history 1337/week @ 2023-12-23 1272/week @ 2023-12-30 1892/week @ 2024-01-06 1916/week @ 2024-01-13 1936/week @ 2024-01-20 2399/week @ 2024-01-27 2596/week @ 2024-02-03 1921/week @ 2024-02-10 2124/week @ 2024-02-17 2465/week @ 2024-02-24 2605/week @ 2024-03-02 2473/week @ 2024-03-09 2450/week @ 2024-03-16 2131/week @ 2024-03-23 2155/week @ 2024-03-30 2142/week @ 2024-04-06

9,296 downloads per month

Apache-2.0

20KB
383 lines

netns-rs

static UT codecov

The netns-rs 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.

This crate only supports linux kernel.

Build

cargo build

Test(as root)

CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="sudo -E" cargo test

or

sudo -E cargo test

Credits

The main resource so far has been the source code of netns(golang), CNI network plugins and iproute2.

Altnernatives

https://github.com/little-dude/netlink: rtnetlink/src/ns.rs provides the same functionality, but its creation of netns in a new process feels a bit heavy.

License

This code is licensed under Apache-2.0.

Dependencies

~2.5MB
~54K SLoC