From frank@pinky.sax.de  Mon Mar 20 17:23:02 2006
Return-Path: <frank@pinky.sax.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2995516A401
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Mar 2006 17:23:02 +0000 (UTC)
	(envelope-from frank@pinky.sax.de)
Received: from pinky.frank-behrens.de (pinky.frank-behrens.de [82.139.199.24])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B7C8F43D64
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Mar 2006 17:23:00 +0000 (GMT)
	(envelope-from frank@pinky.sax.de)
Received: from moon.behrens (localhost [127.0.0.1])
	by pinky.frank-behrens.de (8.13.4/8.13.4) with ESMTP/MSA id k2KHMw1e008129
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Mar 2006 18:22:58 +0100 (CET)
	(envelope-from frank@moon.behrens)
Received: (from frank@localhost)
	by moon.behrens (8.13.4/8.13.4/Submit) id k2KHMwuD008128;
	Mon, 20 Mar 2006 18:22:58 +0100 (CET)
	(envelope-from frank)
Message-Id: <200603201722.k2KHMwuD008128@moon.behrens>
Date: Mon, 20 Mar 2006 18:22:58 +0100 (CET)
From: Frank Behrens <frank@pinky.sax.de>
To: FreeBSD-gnats-submit@freebsd.org
Subject: dhclient(8) should send hostname [patch]
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         94743
>Category:       bin
>Synopsis:       [patch] dhclient(8) should send hostname
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brooks
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 20 17:30:16 GMT 2006
>Closed-Date:    Sat May 13 03:48:06 GMT 2006
>Last-Modified:  Sat May 13 03:48:06 GMT 2006
>Originator:     Frank Behrens
>Release:        FreeBSD 6.1-PRERELEASE-200602270917 i386
>Organization:
>Environment:
>Description:
dhclient(8) should send the clients hostname to DHCP server.
In that case the DHCP server can make dynamic updates on
a DNS server. This simplifies the setup of DHCP client networks.

With this change a default FreeBSD installation, where the network
adapter is configured by DHCP, is immediately visible in DNS
with forward and reverse lookups for the given host name. It is 
however required that DHCP and DNS server are setup accordingly.
The ability to overwrite the hostname with another value
in dhclient.conf(5) is not affected.

A short investigation shows the behaviour of default operating system
installations (tcpdump):

Knoppix 5.0 as Debain based Linux with pump(8) as DHCP client:
	  Client Ethernet Address: 00:0c:29:c6:cb:9b
	  Vendor-rfc1048:
	    DHCP:REQUEST
	    CID:[ether]00:0c:29:c6:cb:9b
	    MSZ:548
	    PR:SM+DG+NS+DN+BR+HN+LOG+LPR+NTP+XFS+XDM+MTU
	    HN:"Knoppix^@"
	    LT:43200
	    SID:192.168.99.10
	    RQ:192.168.99.70

Windows XP SP2 (Windows-98 not traced, but same behaviour):
	  Client Ethernet Address: 00:10:dc:31:73:47
	  Vendor-rfc1048:
	    DHCP:REQUEST
	    CID:[ether]00:10:dc:31:73:47
	    RQ:192.168.99.69
	    SID:192.168.99.10
	    HN:"myhost"
	    VC:"MSFT 5.0"
	    PR:SM+DN+DG+NS+WNS+WNT+WSC+RD+SR+T249+VO

NetBSD, FreeBSD 4.2, FreeBSD 6.x:	    
	  Client Ethernet Address: 00:0c:29:c6:cb:9b
	  Vendor-rfc1048:
	    DHCP:REQUEST
	    RQ:192.168.99.70
	    PR:SM+BR+TZ+DG+DN+NS+HN

FreeBSD 6.x with patch:	   
	  Client Ethernet Address: 00:0c:29:c6:cb:9b
	  Vendor-rfc1048:
	    DHCP:REQUEST
	    RQ:192.168.99.70
	    HN:"myhost"
	    PR:SM+BR+TZ+DG+DN+NS+HN

FreeBSD 6.x with patch and SEND_CLIENT_IDENTIFIER:	   
          Client Ethernet Address: 00:0c:29:c6:cb:9b
          Vendor-rfc1048:
            DHCP:REQUEST
            RQ:192.168.99.65
            CID:[ether]00:0c:29:c6:cb:9b
            HN:"myhost"
            PR:SM+BR+TZ+DG+DN+NS+HN


In the patch is a not activated section "SEND_CLIENT_IDENTIFIER". If
enabled dhclient sends a client identifier compatible with RFC2132,9.14.
This identifier is always sent from Windows clients and can be switched on
via command line argument on Linux pump(8). It may be activated to provide
better compatibility with Windows clients, but the author can not rate 
the advantages.

proposed MFC: after 6.1R
	
>How-To-Repeat:
>Fix:
Index: dhclient.c
===================================================================
RCS file: /data/freebsd/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.6.2.4
diff -u -r1.6.2.4 dhclient.c
--- dhclient.c	24 Jan 2006 05:59:27 -0000	1.6.2.4
+++ dhclient.c	20 Mar 2006 16:38:24 -0000
@@ -54,6 +54,7 @@
  */
 
 #include <sys/cdefs.h>
+#include <unistd.h>
 __FBSDID("$FreeBSD: src/sbin/dhclient/dhclient.c,v 1.6.2.4 2006/01/24 05:59:27 brooks Exp $");
 
 #include "dhcpd.h"
@@ -1553,6 +1554,40 @@
 			    ip->client->config->send_options[i].len;
 			options[i]->timeout = 0xFFFFFFFF;
 		}
+		
+	/* send host name if not set via config file. */
+	char hostname[_POSIX_HOST_NAME_MAX+1];
+	if (!options[DHO_HOST_NAME]) {
+		if (gethostname(hostname, sizeof(hostname)) == 0) {
+			size_t len;
+			char* posDot = strchr(hostname, '.');
+			if (posDot != NULL)
+				len = posDot - hostname;
+			else
+				len = strlen(hostname);
+			options[DHO_HOST_NAME] = &option_elements[DHO_HOST_NAME];
+			options[DHO_HOST_NAME]->value = hostname;
+			options[DHO_HOST_NAME]->len = len;
+			options[DHO_HOST_NAME]->buf_size = len;
+			options[DHO_HOST_NAME]->timeout = 0xFFFFFFFF;
+		}
+	}
+
+#ifdef SEND_CLIENT_IDENTIFIER	
+	/* set unique client identifier */
+	char client_ident[sizeof(struct hardware)];
+	if (!options[DHO_DHCP_CLIENT_IDENTIFIER]) {
+		int hwlen = (ip->hw_address.hlen < sizeof(client_ident)-1) ?
+				ip->hw_address.hlen : sizeof(client_ident)-1;
+		client_ident[0] = ip->hw_address.htype;
+		memcpy(&client_ident[1], ip->hw_address.haddr, hwlen); 
+		options[DHO_DHCP_CLIENT_IDENTIFIER] = &option_elements[DHO_DHCP_CLIENT_IDENTIFIER];
+		options[DHO_DHCP_CLIENT_IDENTIFIER]->value = client_ident;
+		options[DHO_DHCP_CLIENT_IDENTIFIER]->len = hwlen+1;
+		options[DHO_DHCP_CLIENT_IDENTIFIER]->buf_size = hwlen+1;
+		options[DHO_DHCP_CLIENT_IDENTIFIER]->timeout = 0xFFFFFFFF;
+	}
+#endif	
 
 	/* Set up the option buffer... */
 	ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->brooks 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Wed Mar 22 09:11:29 UTC 2006 
Responsible-Changed-Why:  
Assign to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94743 
State-Changed-From-To: open->patched 
State-Changed-By: brooks 
State-Changed-When: Sun May 7 23:31:22 UTC 2006 
State-Changed-Why:  
Applied to HEAD.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94743 
State-Changed-From-To: patched->closed 
State-Changed-By: brooks 
State-Changed-When: Sat May 13 03:47:36 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94743 
>Unformatted:
