From d9a703696d6c48ea245d7273407991908191aea9 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Tue, 21 May 2024 17:10:30 +0200 Subject: [PATCH] Print an error if creating the tun device fails 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 --- mycelium/src/tun/darwin.rs | 11 ++++++++++- mycelium/src/tun/linux.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mycelium/src/tun/darwin.rs b/mycelium/src/tun/darwin.rs index b585848e..14beb199 100644 --- a/mycelium/src/tun/darwin.rs +++ b/mycelium/src/tun/darwin.rs @@ -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)?; diff --git a/mycelium/src/tun/linux.rs b/mycelium/src/tun/linux.rs index f1452338..90f8d77b 100644 --- a/mycelium/src/tun/linux.rs +++ b/mycelium/src/tun/linux.rs @@ -29,7 +29,16 @@ pub async fn new( ), Box, > { - 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);