]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: make auto-deteced routes optional
authorChristoph Heiss <c.heiss@proxmox.com>
Wed, 21 Jun 2023 07:31:50 +0000 (09:31 +0200)
committerChristoph Heiss <c.heiss@proxmox.com>
Wed, 21 Jun 2023 07:31:50 +0000 (09:31 +0200)
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 <c.heiss@proxmox.com>
proxmox-tui-installer/src/options.rs
proxmox-tui-installer/src/setup.rs

index 5787868492f5bd85279d2cc9d76dc7b56d97d1a2..aab3c95b935a3d84b2def2496ee8daf8b35f3675 100644 (file)
@@ -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();
+                        }
                     }
                 }
             }
index 5731c4d2c2fdd0637a4fadeebaa73d6d2c1e2ec8..3aa3abf2910f7499acc6ef72db72c2d6e9cc5a6f 100644 (file)
@@ -349,7 +349,7 @@ pub struct RuntimeInfo {
 #[derive(Clone, Deserialize)]
 pub struct NetworkInfo {
     pub dns: Dns,
-    pub routes: Routes,
+    pub routes: Option<Routes>,
 
     /// Maps devices to their configuration, if it has a usable configuration.
     /// (Contains no entries for devices with only link-local addresses.)