aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-08-31 13:40:51 +0200
committerHimbeer <himbeer@disroot.org>2024-08-31 13:40:51 +0200
commitc9380e091a2b0e1a19786890eef5b0316ffc48fd (patch)
treec7e05149a1e1990a6c5865024a9eeb574aa0fb4e
parent7acd232c7278ca7bca25ed93678c6cfd27d8fb51 (diff)
Fix "File exists" error on restart
VLAN creation now checks if the VLAN interface already exists. If so, no creation attempt is made. The interface is still set to "up" and configured. This fixes the service falling into a permanent restart loop if it crashes, potentially enabling network access to the device for better debugging.
-rw-r--r--src/main.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 57bca23..c2862a1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -116,7 +116,9 @@ fn create_vlans(conn: &Connection) -> Result<()> {
let vlan_id = 10 * (i + 1);
let vlan_name = format!("eth0.{}", vlan_id);
- conn.link_add_vlan(vlan_name.clone(), "eth0".to_string(), vlan_id as u16)?;
+ if !conn.link_exists(vlan_name.clone())? {
+ conn.link_add_vlan(vlan_name.clone(), "eth0".to_string(), vlan_id as u16)?;
+ }
conn.link_set(vlan_name.clone(), true)?;
conn.address_flush(vlan_name.clone())?;