Subject: bin/33174: Bug in dhcpd
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Wolfgang Stukenbrock <Wolfgang.Stukenbrock@nagler-company.com>
List: netbsd-bugs
Date: 03/31/2006 10:05:00
>Number:         33174
>Category:       bin
>Synopsis:       dhcpd fails to deliver hostnames for dynamic ranges
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 31 10:05:00 +0000 2006
>Originator:     Wolfgang Stukenbrock
>Release:        NetBSD 3.0
>Organization:
Dr. Nagler & Company GmbH
>Environment:
System: NetBSD s012 2.1 NetBSD 2.1 (NSW-S012) #10: Mon Dec 12 12:03:54 CET 2005 wgstuken@s011:/export/netbsd-2.1/usr/src/sys/arch/i386/compile/NSW-S012 i386
Architecture: i386
Machine: i386
>Description:
	The option GET_LEASE_HOSTNANE in dhcpd.conf should instruct dhcpd to do a hostname lookup
	if no hostname ist explicitly defined in the dhcpd.conf file for a requesting host.
	This is always true for dynamic IP-Ranges.
	Due to a bug in the search for the presence for a hostname specification in the wrong "universe", no
	hostname will be retrieved even it it should be done.
	On Sun-Solaris dhcp-clients this results in a missing hostname (or hostname equal "unknown").

	remark: The machine where I send this bug is my compilation-server. The bug is found in the 3.0 source tree too.

>How-To-Repeat:
	In our configuration it is reproducable all the time. Accedently in the server-universe and
	the dhcp-universe different sets of options are used and I haven't spend additional time in
	searching the corresponding option to be able to present a failing config file here.
	You can verify the wrong universe be having a look at the block above this block (around line 2435)
	where a similar check ist done in the correct way.

START-OF-CODE-FRAGMENT
/* Use the hostname from the host declaration if there is one
   and no hostname has otherwise been provided, and if the
   use-host-decl-name flag is set. */
   i = DHO_HOST_NAME;
   j = SV_USE_HOST_DECL_NAMES;
   if (!lookup_option (&dhcp_universe, state -> options, i) &&
        lease -> host && lease -> host -> name &&
        (evaluate_boolean_option_cache
         (&ignorep, packet, lease, (struct client_state *)0,
          packet -> options, state -> options, &lease -> scope,
          lookup_option (&server_universe, state -> options, j), MDL))) {
END-OF-CODE-FRAGMENT
	
	The fix has been tested and it corrects the problem.
>Fix:
	The file "/usr/src/dist/dhcp/server/dhpc.c needs the following fix to correct the problem.

*** dhcp.c      2006/03/31 09:38:46     1.1
--- dhcp.c      2006/03/31 09:40:23
***************
*** 2497,2503 ****
        /* If we don't have a hostname yet, and we've been asked to do
           a reverse lookup to find the hostname, do it. */
        j = SV_GET_LEASE_HOSTNAMES;
!       if (!lookup_option (&server_universe, state -> options, i) &&
            (evaluate_boolean_option_cache
             (&ignorep, packet, lease, (struct client_state *)0,
              packet -> options, state -> options, &lease -> scope,
--- 2497,2503 ----
        /* If we don't have a hostname yet, and we've been asked to do
           a reverse lookup to find the hostname, do it. */
        j = SV_GET_LEASE_HOSTNAMES;
!       if (!lookup_option (&dhcp_universe, state -> options, i) &&
            (evaluate_boolean_option_cache
             (&ignorep, packet, lease, (struct client_state *)0,
              packet -> options, state -> options, &lease -> scope,