Skip to content

Commit

Permalink
Print an error if creating the tun device fails
Browse files Browse the repository at this point in the history
It seems that it is not generally understood that network interface
names need to be unique, or that the error generated is "device
busy"/EBUSY in case of a collision. For now, explicitly add an error
log until #213 is implemented.

Signed-off-by: Lee Smet <[email protected]>
  • Loading branch information
LeeSmet committed May 21, 2024
1 parent 4932943 commit d9a7036
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion mycelium/src/tun/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ pub async fn new(
"TUN device name must be of the form 'utunXXX...' where X is a digit",
))?;
}
let mut tun = create_tun_interface(&tun_config.name)?;
let mut tun = match create_tun_interface(&tun_config.name) {
Ok(tun) => tun,
Err(e) => {
error!(
"Could not create tun device named \"{}\", make sure the name is not yet in use, and you have sufficient privileges to create a network device",
tun_config.name,
);
return Err(e);
}
};
let iface = Iface::by_name(&tun_config.name)?;
iface.add_address(tun_config.node_subnet, tun_config.route_subnet)?;

Expand Down
11 changes: 10 additions & 1 deletion mycelium/src/tun/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ pub async fn new(
),
Box<dyn std::error::Error>,
> {
let tun = create_tun_interface(&tun_config.name)?;
let tun = match create_tun_interface(&tun_config.name) {
Ok(tun) => tun,
Err(e) => {
error!(
"Could not create tun device named \"{}\", make sure the name is not yet in use, and you have sufficient privileges to create a network device",
tun_config.name,
);
return Err(e);
}
};

let (conn, handle, _) = rtnetlink::new_connection()?;
let netlink_task_handle = tokio::spawn(conn);
Expand Down

0 comments on commit d9a7036

Please sign in to comment.