From 6e0ccfcd1f49bd4120f204fd2494a95489bea006 Mon Sep 17 00:00:00 2001 From: Florian Kauer Date: Sat, 28 Sep 2024 20:00:10 +0000 Subject: [PATCH] HOTFIX allow bridged apps without netns --- src/controller/mod.rs | 15 ++++++++------- src/interface_setup/iproute2.rs | 26 +++++++++++++++++--------- src/interface_setup/mod.rs | 4 ++-- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/controller/mod.rs b/src/controller/mod.rs index c6b53a5..6f0187f 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -167,7 +167,6 @@ async fn fetch_expanded_configuration( validate_are_some!( app_config, virtual_interface_app, - netns_app, virtual_interface_bridge, )?; } @@ -278,16 +277,16 @@ fn collect_expanded_interfaces( let mut network_namespace = None; for app_config in bridged_apps.values() { let veth_app = app_config.virtual_interface_app()?; - let netns_app = app_config.netns_app()?; + let netns_app = app_config.netns_app_opt(); if veth_app == name { - network_namespace = Some(netns_app.to_owned()); + network_namespace = netns_app.cloned(); // Some(netns_app.to_owned()); break; } for vid in app_config.vlans_opt().unwrap_or(&vec![]) { if &format!("{veth_app}.{vid}") == name { - network_namespace = Some(netns_app.to_owned()); + network_namespace = netns_app.cloned(); //Some(netns_app.to_owned()); break; } } @@ -423,7 +422,7 @@ impl Setup for Controller { locked_interface_setup .setup_veth_pair_with_vlans( virtual_interface_app, - app_config.netns_app()?, + app_config.netns_app_opt(), app_config.virtual_interface_bridge()?, app_config.vlans_opt().unwrap_or(&vec![]), ) @@ -439,7 +438,8 @@ impl Setup for Controller { .pin_xdp_pass(xdp_pin_path) .context("Pinning dummy XDP failed")?; - let netns = Some(app_config.netns_app()?.to_owned()); + //let netns = Some(app_config.netns_app()?.to_owned()); + let netns = app_config.netns_app_opt().cloned(); locked_interface_setup .attach_pinned_xdp(virtual_interface_app, &netns, xdp_pin_path) @@ -674,7 +674,8 @@ async fn set_veths_up( ) .await?; - let netns = Some(app_config.netns_app()?.clone()); + //let netns = Some(app_config.netns_app()?.clone()); + let netns = app_config.netns_app_opt().cloned(); set_interface_state(veth_app, LinkState::Up, &netns, &*locked_interface_setup).await?; diff --git a/src/interface_setup/iproute2.rs b/src/interface_setup/iproute2.rs index bf0b555..a971e53 100644 --- a/src/interface_setup/iproute2.rs +++ b/src/interface_setup/iproute2.rs @@ -370,7 +370,7 @@ impl InterfaceSetup for Iproute2Setup { async fn setup_veth_pair_with_vlans( &self, veth_app: &str, - netns_app: &str, + netns_app: Option<&String>, veth_bridge: &str, vlan_ids: &[u16], ) -> Result<()> { @@ -380,9 +380,11 @@ impl InterfaceSetup for Iproute2Setup { } // Setup network namespace if it does not exist - let ns_path = namespace_path(netns_app); - if !ns_path.exists() { - Self::execute_ip(&["netns", "add", netns_app], &None).await?; + if let Some(netns) = netns_app { + let ns_path = namespace_path(netns); + if !ns_path.exists() { + Self::execute_ip(&["netns", "add", netns], &None).await?; + } } // Create veth pair @@ -407,10 +409,14 @@ impl InterfaceSetup for Iproute2Setup { self.setup_vlan_interface(veth_app, vlan_interface, *vid) .await?; - Self::move_to_namespace(netns_app, vlan_interface).await?; + if let Some(netns) = netns_app { + Self::move_to_namespace(netns, vlan_interface).await?; + } } - Self::move_to_namespace(netns_app, veth_app).await?; + if let Some(netns) = netns_app { + Self::move_to_namespace(netns, veth_app).await?; + } Ok(()) } @@ -535,19 +541,21 @@ fn validate_vlan_link( async fn validate_veth_link( veth_bridge_link: &Value, veth_app: &str, - netns_app: &str, + netns_app: Option<&String>, vlan_ids: &[u16], ) -> Result<()> { for vid in vlan_ids { let vlan_interface = &format!("{veth_app}.{vid}"); - let vlan_link = Iproute2Setup::get_interface(vlan_interface, &Some(netns_app.to_owned())) + //let vlan_link = Iproute2Setup::get_interface(vlan_interface, &Some(netns_app.to_owned())) + let vlan_link = Iproute2Setup::get_interface(vlan_interface, &netns_app.cloned()) .await? .ok_or_else(|| anyhow!("interface {vlan_interface} not found"))?; validate_vlan_link(&vlan_link, vlan_interface, veth_app, *vid)?; } - let veth_app_link = Iproute2Setup::get_interface(veth_app, &Some(netns_app.to_owned())) + //let veth_app_link = Iproute2Setup::get_interface(veth_app, &Some(netns_app.to_owned())) + let veth_app_link = Iproute2Setup::get_interface(veth_app, &netns_app.cloned()) .await? .ok_or_else(|| anyhow!("interface not found"))?; diff --git a/src/interface_setup/mod.rs b/src/interface_setup/mod.rs index 1925344..144afa2 100644 --- a/src/interface_setup/mod.rs +++ b/src/interface_setup/mod.rs @@ -106,7 +106,7 @@ pub trait InterfaceSetup { async fn setup_veth_pair_with_vlans( &self, veth_app: &str, - netns_app: &str, + netns_app: Option<&String>, veth_bridge: &str, vlan_ids: &[u16], ) -> Result<()>; @@ -210,7 +210,7 @@ impl InterfaceSetup for DummyInterfaceSetup { async fn setup_veth_pair_with_vlans( &self, _veth_app: &str, - _netns_app: &str, + _netns_app: Option<&String>, _veth_bridge: &str, _vlan_ids: &[u16], ) -> Result<()> {