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 <c.heiss@proxmox.com>
This commit is contained in:
Christoph Heiss 2023-06-21 09:31:50 +02:00
parent cc82d42e8d
commit 00268c0cb8
2 changed files with 17 additions and 15 deletions

View 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();
}
}
}
}

View 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.)