File: del_netns.rs

package info (click to toggle)
rust-rtnetlink 0.14.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 828 kB
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: MIT

#[cfg(not(target_os = "freebsd"))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[tokio::main]
async fn main() -> Result<(), String> {
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        usage();
        return Ok(());
    }
    let ns_name = &args[1];

    NetworkNamespace::del(ns_name.to_string())
        .await
        .map_err(|e| format!("{e}"))
}

fn usage() {
    eprintln!(
        "usage:
    cargo run --example del_netns -- <ns_name>

Note that you need to run this program as root. Instead of running cargo as root,
build the example normally:

    cd netlink-ip ; cargo build --example del_netns

Then find the binary in the target directory:

    cd ../target/debug/example ; sudo ./del_netns <ns_name>"
    );
}