From 00268c0cb8a54498aacb51b589d0bb5d8f9b827b Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Wed, 21 Jun 2023 09:31:50 +0200 Subject: [PATCH] tui: make auto-deteced routes optional If, for some reason, the network is not properly configured (due to e.g. no DHCP server being present on the network), there will be no routes in the runtime environment as well. So do not depend on that, otherwise the installer fails at the start. Signed-off-by: Christoph Heiss --- proxmox-tui-installer/src/options.rs | 30 +++++++++++++++------------- proxmox-tui-installer/src/setup.rs | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/proxmox-tui-installer/src/options.rs b/proxmox-tui-installer/src/options.rs index 5787868..aab3c95 100644 --- a/proxmox-tui-installer/src/options.rs +++ b/proxmox-tui-installer/src/options.rs @@ -359,24 +359,26 @@ impl From<&NetworkInfo> for NetworkOptions { this.fqdn = Fqdn::from(&format!("pve.{}", domain)).unwrap_or_else(|_| domain.clone()); } - let mut filled = false; - if let Some(gw) = &info.routes.gateway4 { - if let Some(iface) = info.interfaces.get(&gw.dev) { - if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv4()) { - this.ifname = iface.name.clone(); - this.gateway = gw.gateway; - this.address = addr.clone(); - filled = true; - } - } - } - if !filled { - if let Some(gw) = &info.routes.gateway6 { + if let Some(routes) = &info.routes { + let mut filled = false; + if let Some(gw) = &routes.gateway4 { if let Some(iface) = info.interfaces.get(&gw.dev) { - if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv6()) { + if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv4()) { this.ifname = iface.name.clone(); this.gateway = gw.gateway; this.address = addr.clone(); + filled = true; + } + } + } + if !filled { + if let Some(gw) = &routes.gateway6 { + if let Some(iface) = info.interfaces.get(&gw.dev) { + if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv6()) { + this.ifname = iface.name.clone(); + this.gateway = gw.gateway; + this.address = addr.clone(); + } } } } diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs index 5731c4d..3aa3abf 100644 --- a/proxmox-tui-installer/src/setup.rs +++ b/proxmox-tui-installer/src/setup.rs @@ -349,7 +349,7 @@ pub struct RuntimeInfo { #[derive(Clone, Deserialize)] pub struct NetworkInfo { pub dns: Dns, - pub routes: Routes, + pub routes: Option, /// Maps devices to their configuration, if it has a usable configuration. /// (Contains no entries for devices with only link-local addresses.)