[pve-devel] [PATCH installer] run env: strip out domain name from hostname
Christoph Heiss
c.heiss at proxmox.com
Fri Nov 17 11:55:15 CET 2023
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 at 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
More information about the pve-devel
mailing list