NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/55011 dhcpcd(8) sets "localhost" as hostname



The following reply was made to PR bin/55011; it has been noted by GNATS.

From: Roy Marples <roy%marples.name@localhost>
To: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
Cc: gnats-bugs%NetBSD.org@localhost
Subject: Re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Tue, 31 Mar 2020 19:05:46 +0100

 On 31/03/2020 17:10, Izumi Tsutsui wrote:
 > 
 >> Is this report about the manpage being slightly inaccurate - if an invalid
 >> hostname it will set a default hostname of localhost even if no hostname option
 >> in the dhcp message and the current hostname is "invalid" (ie blank, (null) or
 >> localhost)?
 > 
 >> OR is it about changing the default behaviour to not change hostname if blank or
 >> (null) to localhost?
 > 
 > Well I don't know what is "accurate" behavior.
 > 
 > There are two points:
 > 
 > - As noted in the PR, replacing /libexec/dhcpcd-hooks/30-hostname
 >    with 29-lookup-hostname and 30-hostname from NetBSD 6.1.5 makes
 >    dhcpcd(8) use "expected" hostname even in sysinst.
 >    dhclient(8) in NetBSD 8.1 also uses an expected hostname.
 >    (I'm not sure if it's provided from dhcpd or not)
 
 The default behaviour since dhcpcd-6.10 has been to install the 
 29-lookup-hostname as an example script rather than include it as a default script.
 
 Without the default dhcpcd.conf, the hostname option will not be requested.
 
 So this is expected.
 
 > 
 > - The default name of "localhost" is annoying for me because
 >    it's also used by sysinst as default settings in /etc/hosts.
 >    Blank is still better for me.
 
 I've attached a patch below to address this.
 Let me know if it works for you!
 
 > Is there any intentional changes (lookup removal?) from 6.1.5 one?
 
 The 29-lookup-hostname hook was removed from the default installation due to a 
 lot of user complaints.
 It's also IPv4 specific, although that could be improved.
 I have no intention of restoring it as a default hook.
 
 If you want a DHCP client to set the hostname, use the default dhcpcd.conf and 
 ensure the hostname is set in the DHCP message.
 
 OR, set this in /etc/dhcpcd.enter-hook
 
 . /usr/share/examples/dhcpcd/hooks/29-lookup-hostname
 
 Roy
 
  From 645d14292178c4f6a6f7d359ff8eeb87998f7a35 Mon Sep 17 00:00:00 2001
 From: Roy Marples <roy%marples.name@localhost>
 Date: Tue, 31 Mar 2020 18:23:05 +0100
 Subject: hostname: Default to blank instead of localhost
 
 No kernel sets a default value of localhost.
 ---
   hooks/30-hostname | 53 +++++++++++++++++++++++++----------------------------
   1 file changed, 25 insertions(+), 28 deletions(-)
 
 diff --git a/hooks/30-hostname b/hooks/30-hostname
 index 53ae6b11..3ac73ea4 100644
 --- a/hooks/30-hostname
 +++ b/hooks/30-hostname
 @@ -17,16 +17,16 @@
 
   # If we used to set the hostname, but relinquish control of it, we should
   # reset to the default value.
 -: ${hostname_default=localhost}
 +: ${hostname_default=}
 
   # Some systems don't have hostname(1)
   _hostname()
   {
   	if [ -z "${1+x}" ]; then
 -		if type hostname >/dev/null 2>&1; then
 -			hostname
 -		elif [ -r /proc/sys/kernel/hostname ]; then
 +		if [ -r /proc/sys/kernel/hostname ]; then
   			read name </proc/sys/kernel/hostname && echo "$name"
 +		elif type hostname >/dev/null 2>/dev/null; then
 +			hostname
   		elif sysctl kern.hostname >/dev/null 2>&1; then
   			sysctl -n kern.hostname
   		elif sysctl kernel.hostname >/dev/null 2>&1; then
 @@ -37,48 +37,39 @@ _hostname()
   		return $?
   	fi
 
 -	# Always prefer hostname(1) if we have it
 -	if type hostname >/dev/null 2>&1; then
 -		hostname "$1"
 -	elif [ -w /proc/sys/kernel/hostname ]; then
 +	if [ -w /proc/sys/kernel/hostname ]; then
   		echo "$1" >/proc/sys/kernel/hostname
 +	elif [ -n "$1" ] && type hostname >/dev/null 2>&1; then
 +		hostname "$1"
   	elif sysctl kern.hostname >/dev/null 2>&1; then
 -		sysctl -w "kern.hostname=$1"
 +		sysctl -w "kern.hostname=$1" >/dev/null
   	elif sysctl kernel.hostname >/dev/null 2>&1; then
 -		sysctl -w "kernel.hostname=$1"
 +		sysctl -w "kernel.hostname=$1" >/dev/null
   	else
 -		# We know this will fail, but it will now fail
 -		# with an error to stdout
 +		# May fail to set a blank hostname
   		hostname "$1"
   	fi
   }
 
 -set_hostname_vars()
 +is_default_hostname()
   {
 -	hfqdn=false
 -	hshort=false
 -	case "$hostname_fqdn" in
 -	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)	hfqdn=true;;
 -	""|[Ss][Ee][Rr][Vv][Ee][Rr])		;;
 -	*)					hshort=true;;
 +	case "$1" in
 +	""|"(none)"|localhost|localhost.localdomain|"$hostname_default")
 +		return 0;;
   	esac
 +	return 1
   }
 
   need_hostname()
   {
   	# Always load the hostname variable for future use
   	hostname="$(_hostname)"
 -	case "$hostname" in
 -	""|"(none)"|localhost|localhost.localdomain|"$hostname_default")
 -		return 0;;
 -	esac
 +	is_default_hostname "$hostname" && return 0
 
   	case "$force_hostname" in
   	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
   	esac
 
 -	set_hostname_vars
 -
   	if [ -n "$old_fqdn" ]; then
   		if ${hfqdn} || ! ${hshort}; then
   			[ "$hostname" = "$old_fqdn" ]
 @@ -119,9 +110,15 @@ try_hostname()
 
   set_hostname()
   {
 -	need_hostname || return
 +	hfqdn=false
 +	hshort=false
 +	case "$hostname_fqdn" in
 +	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)	hfqdn=true;;
 +	""|[Ss][Ee][Rr][Vv][Ee][Rr])		;;
 +	*)					hshort=true;;
 +	esac
 
 -	set_hostname_vars
 +	need_hostname || return
 
   	if [ -n "$new_fqdn" ]; then
   		if ${hfqdn} || ! ${hshort}; then
 @@ -143,7 +140,7 @@ set_hostname()
   		else
   			try_hostname "$new_host_name"
   		fi
 -	elif [ -n "${hostname_default+x}" ]; then
 +	elif ! is_default_hostname "$hostname"; then
   		try_hostname "$hostname_default"
   	fi
   }
 -- 
 cgit v1.2.3
 


Home | Main Index | Thread Index | Old Index