#namespaces #linux #networking #container

netns-rs

A library to handle Linux network namespaces in Rust

1 unstable release

0.1.0 Apr 25, 2022

#48 in #namespaces

Download history 2789/week @ 2024-07-23 3024/week @ 2024-07-30 2728/week @ 2024-08-06 3453/week @ 2024-08-13 3568/week @ 2024-08-20 3407/week @ 2024-08-27 3589/week @ 2024-09-03 3347/week @ 2024-09-10 2900/week @ 2024-09-17 3154/week @ 2024-09-24 3181/week @ 2024-10-01 3054/week @ 2024-10-08 3102/week @ 2024-10-15 3214/week @ 2024-10-22 2818/week @ 2024-10-29 2595/week @ 2024-11-05

12,267 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
~52K SLoC