From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] run env: strip out domain name from hostname
Date: Fri, 17 Nov 2023 11:55:15 +0100 [thread overview]
Message-ID: <20231117105524.274413-1-c.heiss@proxmox.com> (raw)
The FQDN (retrieved via the DHCP `host-name` option) might contain the
domain name too, as allowed by RFC 2132.
E.g. if the DHCP server sends
`host-name` => "foo.bar" `domain-name` => "bar"
that would show up in the network setup screen in both UIs as
"foo.bar.bar" as hostname/FQDN.
Fixes: a805423 ("run env: do not store emtpy hostname")
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Tested this with various possible settings for the `host-name` DHCP
option, also including e.g. if `host-name` is set to "" in the lease
(which should never happen but you never know what shoddy DHCP
implementations are out there).
Proxmox/Install/RunEnv.pm | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm
index c393f67..214a001 100644
--- a/Proxmox/Install/RunEnv.pm
+++ b/Proxmox/Install/RunEnv.pm
@@ -258,18 +258,24 @@ sub query_installation_environment : prototype() {
my $output = {};
my $routes = query_routes();
+ my $dns = query_dns();
log_info("query block devices");
$output->{disks} = Proxmox::Sys::Block::get_cached_disks();
$output->{network} = {
interfaces => query_netdevs(),
routes => $routes,
- dns => query_dns(),
+ dns => $dns,
};
# avoid serializing out null or an empty string, that can trip up the UIs
if (my $fqdn = Proxmox::Sys::Net::get_dhcp_fqdn()) {
- $output->{network}->{hostname} = $fqdn;
+ # strip out the domain name if contained in the FQDN
+ if (defined($dns->{domain}) && $fqdn =~ m/^(.*)\.$dns->{domain}$/) {
+ $output->{network}->{hostname} = $1;
+ } else {
+ $output->{network}->{hostname} = $fqdn;
+ }
}
# FIXME: move whatever makes sense over to Proxmox::Sys::Net:: and keep that as single source,
--
2.42.0
reply other threads:[~2023-11-17 10:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20231117105524.274413-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox