RE: Does old_fqdn take on the value of new_dhcp6_fqdn?
Walrath, Paul
Fri Aug 14 23:52:05 2015
I'm seeing another unexplainable behavior that may be tied in with this. If I change my DHCP servers from the DHCPv6 server providing DHCPv6 Option 39 Client FQDN to having the DHCPv4 server providing DHCPv4 Option 12 Hostname and DHCPv4 Option 15 Domain Name to my device then do an ifdown followed by an ifup on my device's network interface, the domain name changes (/etc/resolv.conf) to the DHCPv4 provided name but the host name remains the same. If I power-cycle my device, the host name gets updated.
I can make the host name get updated with just the ifdown/ifup sequence by making the following change in 30-hostname in the set_hostname function:
Existing code:
set_hostname()
{
local hfqdn=false hshort=false
need_hostname || return
New code:
set_hostname()
{
local hfqdn=false hshort=false
if [ need_hostname ]; then
# Walrath: Debug
printf "NEEDED\n" >> /var/log/rpw
else
# Walrath: Debug
printf "NOT NEEDED\n" >> /var/log/rpw
return
fi
I'm using the shell from Busybox (which is called ash).
It appears as though the "if [ need_hostname] " method is more reliable. Don't ask me why. I did some printf tracing and here's what it showed:
Old Code
====================================================
Begin 30-hostname: Reason BOUND
new_fqdn =
new_dhcp6_fqdn =
new_host_name = webhost4
new_domain_name = webdomain4.walrath.name
old_fqdn =
old_dhcp6_fqdn =
old_host_name =
old_domain_name =
Checking need_hostname...
End 30-hostname: Reason BOUND
New Code
====================================================
Begin 30-hostname: Reason BOUND
new_fqdn =
new_dhcp6_fqdn =
new_host_name = webhost4
new_domain_name = webdomain4.walrath.name
old_fqdn =
old_dhcp6_fqdn =
old_host_name =
old_domain_name =
Checking need_hostname...NEEDED
Continue with set_hostname()
Trying hostname webhost4.webdomain4.walrath.name
Set host name using /bin/hostname
End 30-hostname: Reason BOUND
-----Original Message-----
From: Roy Marples [mailto:roy@xxxxxxxxxxxx]
Sent: Friday, August 14, 2015 3:25 PM
To: dhcpcd-discuss@xxxxxxxxxxxx
Cc: Walrath, Paul
Subject: Re: [dhcpcd-discuss] Does old_fqdn take on the value of new_dhcp6_fqdn?
Hi Paul
On Friday 14 August 2015 17:24:16 Walrath, Paul wrote:
> In the 30-hostname hook script there is the following:
>
> # For ease of use, map DHCP6 names onto our DHCP4 names
> case "$reason" in
> BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
> new_fqdn="$new_dhcp6_fqdn"
> ;;
> esac
>
> The next time this script is run, does $old_fqdn have the value remembered
> from $new_dhcp6_fqdn or is it still set to the $new_fqdn value from
> processing a previous DHCPv4 reply?
old_fqdn would be generated from a prior DHCPv4 lease only
> If the $new_dhcp6_fqdn value is not used for $old_fqdn, then I think some of
> the code in 30-hostname won't run correctly. Specifically this part in
> need_hostname():
>
>
> if [ -n "$old_fqdn" ]; then
>
> if ${hfqdn} || ! ${hsort}; then
>
> [ "$hostname" = "$old_fqdn" ]
>
> else
>
> [ "$hostname" = "${old_fqdn%%.*}" ]
>
> fi
>
> elif [ -n "$old_host_name" ]; then
You're right.
This patch should fix it
Index: dhcpcd-hooks/30-hostname
==================================================================
--- dhcpcd-hooks/30-hostname
+++ dhcpcd-hooks/30-hostname
@@ -144,11 +144,12 @@
# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
new_fqdn="$new_dhcp6_fqdn"
+ old_fqdn="$old_dhcp6_fqdn"
;;
esac
if $if_up; then
set_hostname
fi
http://roy.marples.name/projects/dhcpcd/vpatch?from=33ba0b530f22a445&to=3592407ffc5ed593
Roy
Archive administrator: postmaster@marples.name