Skip to content

Commit

Permalink
HOTFIX allow bridged apps without netns
Browse files Browse the repository at this point in the history
  • Loading branch information
koalo committed Sep 28, 2024
1 parent 4c9b672 commit 6e0ccfc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
15 changes: 8 additions & 7 deletions src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ async fn fetch_expanded_configuration(
validate_are_some!(
app_config,
virtual_interface_app,
netns_app,
virtual_interface_bridge,
)?;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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![]),
)
Expand All @@ -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)
Expand Down Expand Up @@ -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?;

Expand Down
26 changes: 17 additions & 9 deletions src/interface_setup/iproute2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand All @@ -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
Expand All @@ -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(())
}
Expand Down Expand Up @@ -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"))?;

Expand Down
4 changes: 2 additions & 2 deletions src/interface_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>;
Expand Down Expand Up @@ -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<()> {
Expand Down

0 comments on commit 6e0ccfc

Please sign in to comment.