mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-03 17:14:06 +02:00
add support for moving devices into the namespace
This commit is contained in:
parent
6ecb4b384d
commit
3fa69dc434
11 changed files with 411 additions and 88 deletions
13
src/up.rs
13
src/up.rs
|
|
@ -1,6 +1,7 @@
|
|||
use crate::config::{Config, NamespaceName};
|
||||
use crate::namespace::NetNs;
|
||||
use main_error::MainResult;
|
||||
use tracing::error;
|
||||
|
||||
pub fn up(config: Config) -> MainResult {
|
||||
let mut namespaces = NetNs::existing(false)?
|
||||
|
|
@ -15,7 +16,13 @@ pub fn up(config: Config) -> MainResult {
|
|||
|
||||
for new in config.namespaces {
|
||||
if !has_namespace(&namespaces, &new.name) {
|
||||
namespaces.push(NetNs::new(new.name)?);
|
||||
namespaces.push(NetNs::new(new.name.clone())?);
|
||||
}
|
||||
let namespace = get_namespace(&namespaces, &new.name).expect("namespace is just created");
|
||||
for device in new.devices {
|
||||
if let Err(error) = namespace.move_device(&device) {
|
||||
error!(%error, "failed to move device into namespace");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -25,3 +32,7 @@ pub fn up(config: Config) -> MainResult {
|
|||
fn has_namespace(namespaces: &[NetNs], name: &NamespaceName) -> bool {
|
||||
namespaces.iter().any(|existing| existing.name() == name)
|
||||
}
|
||||
|
||||
fn get_namespace<'a>(namespaces: &'a [NetNs], name: &NamespaceName) -> Option<&'a NetNs> {
|
||||
namespaces.iter().find(|existing| existing.name() == name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue