From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 80F011FF162 for <inbox@lore.proxmox.com>; Mon, 7 Apr 2025 17:48:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 09D0039F8; Mon, 7 Apr 2025 17:48:18 +0200 (CEST) From: Christoph Heiss <c.heiss@proxmox.com> To: pve-devel@lists.proxmox.com Date: Mon, 7 Apr 2025 17:47:47 +0200 Message-ID: <20250407154810.1565150-1-c.heiss@proxmox.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH installer] common: options: use more sensible fallback values for network options X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> When no DHCP server is configured on the network and/or no DHCP lease is received, the auto-installer falls back to Ipv4Addr::UNSPECIFIED - which resolves to `0.0.0.0/0` - for the interface address, gateway and DNS server. This is then written to /etc/network/interfaces and could cause further issues after the installation. At the same time, this also means that no interface name will be set, which causes the low-level installer to write out an invalid /etc/network/interfaces entry. Reported-by: Christian Ebner <c.ebner@proxmox.com> Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- proxmox-installer-common/src/options.rs | 73 +++++++++++++++++++++---- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 889e721..9cc4ee0 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -389,6 +389,8 @@ impl NetworkOptions { network: &NetworkInfo, default_domain: Option<&str>, ) -> Self { + // Sets up sensible defaults as much as possible, such that even in the + // worse case nothing breaks down *completely*. let mut this = Self { ifname: String::new(), fqdn: Self::construct_fqdn( @@ -396,10 +398,11 @@ impl NetworkOptions { setup.config.product.default_hostname(), default_domain, ), - // Safety: The provided mask will always be valid. - address: CidrAddress::new(Ipv4Addr::UNSPECIFIED, 0).unwrap(), - gateway: Ipv4Addr::UNSPECIFIED.into(), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + // Safety: The provided IP address/mask is always valid. + // These are the same as used in the GTK-based installer. + address: CidrAddress::new(Ipv4Addr::new(192, 168, 100, 2), 24).unwrap(), + gateway: Ipv4Addr::new(192, 168, 100, 1).into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), }; if let Some(ip) = network.dns.dns.first() { @@ -435,6 +438,16 @@ impl NetworkOptions { } } + // In case no there are no routes defined at all (e.g. no DHCP lease), + // try to set the interface name to *some* valid values. At least one + // NIC should always be present here, as the installation will abort + // earlier in that case, so use the first one enumerated. + if this.ifname.is_empty() { + if let Some(iface) = network.interfaces.values().min_by_key(|v| v.index) { + this.ifname.clone_from(&iface.name); + } + } + this } @@ -542,7 +555,7 @@ mod tests { fqdn: Fqdn::from("foo.bar.com").unwrap(), address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), } ); @@ -554,7 +567,7 @@ mod tests { fqdn: Fqdn::from("pve.bar.com").unwrap(), address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), } ); @@ -566,7 +579,7 @@ mod tests { fqdn: Fqdn::from("pve.example.invalid").unwrap(), address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), } ); @@ -578,7 +591,7 @@ mod tests { fqdn: Fqdn::from("foo.example.invalid").unwrap(), address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), } ); } @@ -594,7 +607,7 @@ mod tests { fqdn: Fqdn::from("foo.bar.com").unwrap(), address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), } ); @@ -606,7 +619,7 @@ mod tests { fqdn: Fqdn::from("foo.custom.local").unwrap(), address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), } ); @@ -618,7 +631,45 @@ mod tests { fqdn: Fqdn::from("foo.custom.local").unwrap(), address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), - dns_server: Ipv4Addr::UNSPECIFIED.into(), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), + } + ); + } + + #[test] + fn network_options_default_addresses_are_sane() { + let mut interfaces = BTreeMap::new(); + interfaces.insert( + "eth0".to_owned(), + Interface { + name: "eth0".to_owned(), + index: 0, + state: InterfaceState::Up, + mac: "01:23:45:67:89:ab".to_owned(), + addresses: None, + }, + ); + + let info = NetworkInfo { + dns: Dns { + domain: None, + dns: vec![], + }, + routes: None, + interfaces, + hostname: None, + }; + + let setup = SetupInfo::mocked(); + + pretty_assertions::assert_eq!( + NetworkOptions::defaults_from(&setup, &info, None), + NetworkOptions { + ifname: "eth0".to_owned(), + fqdn: Fqdn::from("pve.example.invalid").unwrap(), + address: CidrAddress::new(Ipv4Addr::new(192, 168, 100, 2), 24).unwrap(), + gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 100, 1)), + dns_server: Ipv4Addr::new(192, 168, 100, 1).into(), } ); } -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel