From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 5/6] common: options: allow user-supplied domain for network options
Date: Thu, 27 Mar 2025 16:17:16 +0100 [thread overview]
Message-ID: <20250327151718.1084841-6-c.heiss@proxmox.com> (raw)
In-Reply-To: <20250327151718.1084841-1-c.heiss@proxmox.com>
Add an optional parameter to allow specifying a domain, which will take
precedence over both the DHCP-supplied domain (if any) and the hardcoded
default domain.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
proxmox-auto-installer/src/utils.rs | 2 +-
proxmox-installer-common/src/options.rs | 95 ++++++++++++++++++++-----
proxmox-tui-installer/src/main.rs | 2 +-
3 files changed, 80 insertions(+), 19 deletions(-)
diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs
index 655fecb..cf072b8 100644
--- a/proxmox-auto-installer/src/utils.rs
+++ b/proxmox-auto-installer/src/utils.rs
@@ -24,7 +24,7 @@ fn get_network_settings(
runtime_info: &RuntimeInfo,
setup_info: &SetupInfo,
) -> Result<NetworkOptions> {
- let mut network_options = NetworkOptions::defaults_from(setup_info, &runtime_info.network);
+ let mut network_options = NetworkOptions::defaults_from(setup_info, &runtime_info.network, None);
info!("Setting network configuration");
diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs
index 28f2971..562d285 100644
--- a/proxmox-installer-common/src/options.rs
+++ b/proxmox-installer-common/src/options.rs
@@ -408,10 +408,18 @@ pub struct NetworkOptions {
impl NetworkOptions {
const DEFAULT_DOMAIN: &'static str = "example.invalid";
- pub fn defaults_from(setup: &SetupInfo, network: &NetworkInfo) -> Self {
+ pub fn defaults_from(
+ setup: &SetupInfo,
+ network: &NetworkInfo,
+ default_domain: Option<&str>,
+ ) -> Self {
let mut this = Self {
ifname: String::new(),
- fqdn: Self::construct_fqdn(network, setup.config.product.default_hostname()),
+ fqdn: Self::construct_fqdn(
+ network,
+ 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(),
@@ -454,14 +462,23 @@ impl NetworkOptions {
this
}
- fn construct_fqdn(network: &NetworkInfo, default_hostname: &str) -> Fqdn {
+ pub fn construct_fqdn(
+ network: &NetworkInfo,
+ default_hostname: &str,
+ default_domain: Option<&str>,
+ ) -> Fqdn {
let hostname = network.hostname.as_deref().unwrap_or(default_hostname);
- let domain = network
- .dns
- .domain
- .as_deref()
- .unwrap_or(Self::DEFAULT_DOMAIN);
+ // First, use the provided default domain if provided. If that is unset,
+ // use the one from the host network configuration, i.e. as and if provided by DHCP.
+ // As last fallback, use [`Self::DEFAULT_DOMAIN`].
+ let domain = default_domain.unwrap_or_else(|| {
+ network
+ .dns
+ .domain
+ .as_deref()
+ .unwrap_or(Self::DEFAULT_DOMAIN)
+ });
Fqdn::from(&format!("{hostname}.{domain}")).unwrap_or_else(|_| {
// Safety: This will always result in a valid FQDN, as we control & know
@@ -527,10 +544,7 @@ mod tests {
}
}
- #[test]
- fn network_options_from_setup_network_info() {
- let setup = SetupInfo::mocked();
-
+ fn mock_setup_network() -> (SetupInfo, NetworkInfo) {
let mut interfaces = BTreeMap::new();
interfaces.insert(
"eth0".to_owned(),
@@ -545,7 +559,7 @@ mod tests {
},
);
- let mut info = NetworkInfo {
+ let info = NetworkInfo {
dns: Dns {
domain: Some("bar.com".to_owned()),
dns: Vec::new(),
@@ -561,8 +575,15 @@ mod tests {
hostname: Some("foo".to_owned()),
};
+ (SetupInfo::mocked(), info)
+ }
+
+ #[test]
+ fn network_options_from_setup_network_info() {
+ let (setup, mut info) = mock_setup_network();
+
pretty_assertions::assert_eq!(
- NetworkOptions::defaults_from(&setup, &info),
+ NetworkOptions::defaults_from(&setup, &info, None),
NetworkOptions {
ifname: "eth0".to_owned(),
fqdn: Fqdn::from("foo.bar.com").unwrap(),
@@ -574,7 +595,7 @@ mod tests {
info.hostname = None;
pretty_assertions::assert_eq!(
- NetworkOptions::defaults_from(&setup, &info),
+ NetworkOptions::defaults_from(&setup, &info, None),
NetworkOptions {
ifname: "eth0".to_owned(),
fqdn: Fqdn::from("pve.bar.com").unwrap(),
@@ -586,7 +607,7 @@ mod tests {
info.dns.domain = None;
pretty_assertions::assert_eq!(
- NetworkOptions::defaults_from(&setup, &info),
+ NetworkOptions::defaults_from(&setup, &info, None),
NetworkOptions {
ifname: "eth0".to_owned(),
fqdn: Fqdn::from("pve.example.invalid").unwrap(),
@@ -598,7 +619,7 @@ mod tests {
info.hostname = Some("foo".to_owned());
pretty_assertions::assert_eq!(
- NetworkOptions::defaults_from(&setup, &info),
+ NetworkOptions::defaults_from(&setup, &info, None),
NetworkOptions {
ifname: "eth0".to_owned(),
fqdn: Fqdn::from("foo.example.invalid").unwrap(),
@@ -608,4 +629,44 @@ mod tests {
}
);
}
+
+ #[test]
+ fn network_options_correctly_handles_user_supplied_default_domain() {
+ let (setup, mut info) = mock_setup_network();
+
+ pretty_assertions::assert_eq!(
+ NetworkOptions::defaults_from(&setup, &info, None),
+ NetworkOptions {
+ ifname: "eth0".to_owned(),
+ 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(),
+ }
+ );
+
+ info.dns.domain = None;
+ pretty_assertions::assert_eq!(
+ NetworkOptions::defaults_from(&setup, &info, Some("custom.local")),
+ NetworkOptions {
+ ifname: "eth0".to_owned(),
+ 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(),
+ }
+ );
+
+ info.dns.domain = Some("some.domain.local".to_owned());
+ pretty_assertions::assert_eq!(
+ NetworkOptions::defaults_from(&setup, &info, Some("custom.local")),
+ NetworkOptions {
+ ifname: "eth0".to_owned(),
+ 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(),
+ }
+ );
+ }
}
diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 341e60c..57a334f 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -169,7 +169,7 @@ fn main() {
bootdisk: BootdiskOptions::defaults_from(&runtime_info.disks[0]),
timezone: TimezoneOptions::defaults_from(&runtime_info, &locales),
password: Default::default(),
- network: NetworkOptions::defaults_from(&setup_info, &runtime_info.network),
+ network: NetworkOptions::defaults_from(&setup_info, &runtime_info.network, None),
autoreboot: true,
},
setup_info,
--
2.48.1
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-03-27 15:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 15:17 [pve-devel] [PATCH installer 0/6] fix #5811: add option to retrieve FQDN from DHCP configuration Christoph Heiss
2025-03-27 15:17 ` [pve-devel] [PATCH installer 1/6] auto: utils: avoid a force unwrap() Christoph Heiss
2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht
2025-03-27 15:17 ` [pve-devel] [PATCH installer 2/6] auto: tests: parse-answer: allow per-test runtime env Christoph Heiss
2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht
2025-03-27 15:17 ` [pve-devel] [PATCH installer 3/6] auto: tests: allow testing for serde parse errors of answer files Christoph Heiss
2025-04-04 12:51 ` [pve-devel] applied: " Thomas Lamprecht
2025-03-27 15:17 ` [pve-devel] [PATCH installer 4/6] tui, common: move network option tests to correct crate Christoph Heiss
2025-04-04 12:54 ` Thomas Lamprecht
2025-03-27 15:17 ` Christoph Heiss [this message]
2025-03-27 15:17 ` [pve-devel] [PATCH installer 6/6] fix #5811: auto: add option to retrieve FQDN from DHCP configuration Christoph Heiss
2025-04-01 13:15 ` Daniel Kral
2025-04-01 13:25 ` Christoph Heiss
2025-04-01 13:29 ` Stefan Hanreich
2025-04-01 13:44 ` Daniel Kral
2025-04-01 14:58 ` Thomas Lamprecht
2025-04-01 13:45 ` [pve-devel] [PATCH installer 0/6] fix #5811: " Daniel Kral
2025-04-01 14:05 ` Christoph Heiss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250327151718.1084841-6-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.