Skip to content

Commit

Permalink
update create bridge function
Browse files Browse the repository at this point in the history
  • Loading branch information
voelkera committed Apr 9, 2024
1 parent 9de7bd8 commit ff11860
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions opendut-edgar/src/service/network_interface/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::Arc;
use anyhow::anyhow;
use futures::TryStreamExt;
use netlink_packet_route::link::{LinkAttribute, LinkMessage};
use netlink_packet_route::link::LinkAttribute::Group;
use tokio::process::Command;

use gretap::Gretap;
Expand Down Expand Up @@ -71,12 +72,22 @@ impl NetworkInterfaceManager {
}

pub async fn create_empty_bridge(&self, name: &NetworkInterfaceName) -> Result<Interface, Error> {
self.handle
.link()
.add()
.bridge(name.name())
.execute().await
.map_err(|cause| Error::BridgeCreation { name: name.clone(), cause })?;
let output = Command::new("ip")
.arg("link")
.arg("add")
.arg(name.name())
.arg("group")
.arg("opendut")
.arg("type")
.arg("bridge")
.output()
.await
.map_err(|cause| Error::CommandLineProgramExecution { command: "ip link".to_string(), cause })?;

if ! output.status.success() {
return Err(Error::BridgeCreation { name: name.clone(), cause: format!("{:?}", String::from_utf8_lossy(&output.stderr).trim()) });
}

let interface = self.try_find_interface(name).await?;
Ok(interface)
}
Expand Down Expand Up @@ -176,7 +187,7 @@ impl std::fmt::Display for Interface {
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Failure while creating bridge '{name}': {cause}")]
BridgeCreation { name: NetworkInterfaceName, cause: rtnetlink::Error },
BridgeCreation { name: NetworkInterfaceName, cause: String },
#[error("Failed to establish connection to netlink: {cause}")]
Connecting { cause: io::Error },
#[error("Failure while deleting interface {interface}: {cause}")]
Expand Down

0 comments on commit ff11860

Please sign in to comment.