From rea-fbsd@codelabs.ru  Wed Sep  3 21:14:06 2008
Return-Path: <rea-fbsd@codelabs.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id EEEBE1065675
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  3 Sep 2008 21:14:05 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45])
	by mx1.freebsd.org (Postfix) with ESMTP id A19008FC27
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  3 Sep 2008 21:14:05 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from phoenix.codelabs.ru (ppp85-141-64-252.pppoe.mtu-net.ru [85.141.64.252])
	by 0.mx.codelabs.ru with esmtps (TLSv1:CAMELLIA256-SHA:256)
	id 1Kazfw-000Cdj-N5 for FreeBSD-gnats-submit@freebsd.org; Thu, 04 Sep 2008 01:14:04 +0400
Message-Id: <20080903195036.2F1B6F1836@phoenix.codelabs.ru>
Date: Wed,  3 Sep 2008 23:50:36 +0400 (MSD)
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Reply-To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] teach dhclient to recognize options 66 and 67
X-Send-Pr-Version: 3.113
X-GNATS-Notify: brooks@freebsd.org

>Number:         127076
>Category:       bin
>Synopsis:       [patch] teach dhclient(8) to recognize options 66 and 67
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    brooks
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 03 21:20:02 UTC 2008
>Closed-Date:    Sun Oct 26 19:28:30 UTC 2008
>Last-Modified:  Sun Oct 26 19:28:30 UTC 2008
>Originator:     Eygene Ryabinkin
>Release:        FreeBSD 7.1-PRERELEASE i386
>Organization:
Code Labs
>Environment:

System: FreeBSD XXX 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #7: Wed Sep 3 16:42:27 MSD 2008 root@XXX:/usr/src/sys/i386/compile/XXX i386

>Description:

Dhclient does not pass option 66, TFTP server name, and option 67,
bootfile name, to the dhclient-script, because these options are not
validated in the check_option().

These options are used for PXE/diskless environments.  I am using them
to discover TFTP server and sysinstall configuration file template
during automated PXE installation of FreeBSD.

>How-To-Repeat:

Set up DHCP server to give away tftp-server-name and bootfile-name.
For ISC dhcpd it will look like
-----
host XXX {
  ...
  option tftp-server-name "172.16.0.254";
  option bootfile-name "machine.img";
}
-----

Then spawn dhclient and watch for output entries like
-----
unknown dhcp option value 0x42
unknown dhcp option value 0x43
-----

Also try to get the values of environment variables 'new-tftp-server-name'
and 'new-bootfile-name' in /sbin/dhclient-script -- they will be unset.

>Fix:

The following patch adds recognition for the mentioned options.  There
is no real validation, since both options are strings and may have
arbitrary structure.

I had tested this patch with dhclient from 7-STABLE and ISC dhcpd 3.x.
Works as expected.

--- dhclient-options-66-and-67.patch begins here ---
From 9e60cf5c6f86ef6dfe4fa02cf5b0388f8e11004c Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Date: Wed, 3 Sep 2008 23:31:12 +0400

Option 66, TFTP server name, and option 67, bootfile name, are often
used when one wants to retrieve TFTP server name and boot file via DHCP
in PXE or diskless environments.  Teach dhclient to recognize these
options and pass them to the dhclient-script.

Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
---
 sbin/dhclient/dhclient.c |    2 ++
 sbin/dhclient/dhcp.h     |    2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index a18e17c..88f0030 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -2390,6 +2390,8 @@ check_option(struct client_lease *l, int option)
 	case DHO_DHCP_CLIENT_IDENTIFIER:
 	case DHO_DHCP_USER_CLASS_ID:
 	case DHO_END:
+	case DHO_TFTP_SERVER_NAME:
+	case DHO_BOOTFILE_NAME:
 		return (1);
 	case DHO_CLASSLESS_ROUTES:
 		return (check_classless_option(l->options[option].data,
diff --git a/sbin/dhclient/dhcp.h b/sbin/dhclient/dhcp.h
index aa69930..22d698d 100644
--- a/sbin/dhclient/dhcp.h
+++ b/sbin/dhclient/dhcp.h
@@ -155,6 +155,8 @@ struct dhcp_packet {
 #define DHO_DHCP_REBINDING_TIME		59
 #define DHO_DHCP_CLASS_IDENTIFIER	60
 #define DHO_DHCP_CLIENT_IDENTIFIER	61
+#define DHO_TFTP_SERVER_NAME		66
+#define DHO_BOOTFILE_NAME		67
 #define DHO_SMTP_SERVER			69
 #define DHO_POP_SERVER			70
 #define DHO_NNTP_SERVER			71
-- 
1.5.6.4
--- dhclient-options-66-and-67.patch ends here ---
>Release-Note:
>Audit-Trail:

From: Jung-uk Kim <jkim@FreeBSD.org>
To: bug-followup@FreeBSD.org,
 rea-fbsd@codelabs.ru
Cc:  
Subject: Re: bin/127076: [patch] teach dhclient(8) to recognize options 66 and 67
Date: Thu, 4 Sep 2008 14:30:48 -0400

 --Boundary-00=_clCwIcfQZalDZk1
 Content-Type: text/plain;
   charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 Actually 'tftp-server-name' must be a valid hostname and it has to be 
 validated with res_hnok() function.  Please try the attached patch.  
 It will add all options listed in dhcp-options(5) and RFC 2132 as the 
 manual page says.
 
 Jung-uk Kim
 
 --Boundary-00=_clCwIcfQZalDZk1
 Content-Type: text/x-diff;
   charset="iso-8859-1";
   name="dhclient.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="dhclient.diff"
 
 Index: sbin/dhclient/tables.c
 ===================================================================
 --- sbin/dhclient/tables.c	(revision 182762)
 +++ sbin/dhclient/tables.c	(working copy)
 @@ -387,13 +387,25 @@
  	DHO_FONT_SERVERS,
  	DHO_X_DISPLAY_MANAGER,
  	DHO_DHCP_PARAMETER_REQUEST_LIST,
 +	DHO_NISPLUS_DOMAIN,
 +	DHO_NISPLUS_SERVERS,
 +	DHO_TFTP_SERVER_NAME,
 +	DHO_BOOTFILE_NAME,
 +	DHO_MOBILE_IP_HOME_AGENT,
 +	DHO_SMTP_SERVER,
 +	DHO_POP_SERVER,
 +	DHO_NNTP_SERVER,
 +	DHO_WWW_SERVER,
 +	DHO_FINGER_SERVER,
 +	DHO_IRC_SERVER,
 +	DHO_STREETTALK_SERVER,
 +	DHO_STREETTALK_DA_SERVER,
  
  	/* Presently-undefined options... */
 -	62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
 -	78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
 -	93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
 -	107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
 -	119, 120, 122, 123, 124, 125, 126, 127, 128, 129, 130,
 +	62, 63, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
 +	92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
 +	106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
 +	118, 119, 120, 122, 123, 124, 125, 126, 127, 128, 129, 130,
  	131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
  	143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
  	155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
 Index: sbin/dhclient/dhcp.h
 ===================================================================
 --- sbin/dhclient/dhcp.h	(revision 182762)
 +++ sbin/dhclient/dhcp.h	(working copy)
 @@ -155,12 +155,19 @@
  #define DHO_DHCP_REBINDING_TIME		59
  #define DHO_DHCP_CLASS_IDENTIFIER	60
  #define DHO_DHCP_CLIENT_IDENTIFIER	61
 +#define	DHO_NISPLUS_DOMAIN		64
 +#define	DHO_NISPLUS_SERVERS		65
 +#define	DHO_TFTP_SERVER_NAME		66
 +#define	DHO_BOOTFILE_NAME		67
 +#define	DHO_MOBILE_IP_HOME_AGENT	68
  #define DHO_SMTP_SERVER			69
  #define DHO_POP_SERVER			70
  #define DHO_NNTP_SERVER			71
  #define DHO_WWW_SERVER			72
  #define DHO_FINGER_SERVER		73
  #define DHO_IRC_SERVER			74
 +#define	DHO_STREETTALK_SERVER		75
 +#define	DHO_STREETTALK_DA_SERVER	76
  #define DHO_DHCP_USER_CLASS_ID		77
  #define DHO_CLASSLESS_ROUTES		121
  #define DHO_END				255
 Index: sbin/dhclient/dhclient.c
 ===================================================================
 --- sbin/dhclient/dhclient.c	(revision 182762)
 +++ sbin/dhclient/dhclient.c	(working copy)
 @@ -2317,12 +2317,16 @@
  	case DHO_NETBIOS_DD_SERVER:
  	case DHO_FONT_SERVERS:
  	case DHO_DHCP_SERVER_IDENTIFIER:
 +	case DHO_NISPLUS_SERVERS:
 +	case DHO_MOBILE_IP_HOME_AGENT:
  	case DHO_SMTP_SERVER:
  	case DHO_POP_SERVER:
  	case DHO_NNTP_SERVER:
  	case DHO_WWW_SERVER:
  	case DHO_FINGER_SERVER:
  	case DHO_IRC_SERVER:
 +	case DHO_STREETTALK_SERVER:
 +	case DHO_STREETTALK_DA_SERVER:
  		if (!ipv4addrs(opbuf)) {
  			warning("Invalid IP address in option: %s", opbuf);
  			return (0);
 @@ -2330,6 +2334,8 @@
  		return (1)  ;
  	case DHO_HOST_NAME:
  	case DHO_NIS_DOMAIN:
 +	case DHO_NISPLUS_DOMAIN:
 +	case DHO_TFTP_SERVER_NAME:
  		if (!res_hnok(sbuf)) {
  			warning("Bogus Host Name option %d: %s (%s)", option,
  			    sbuf, opbuf);
 @@ -2388,6 +2394,7 @@
  	case DHO_DHCP_REBINDING_TIME:
  	case DHO_DHCP_CLASS_IDENTIFIER:
  	case DHO_DHCP_CLIENT_IDENTIFIER:
 +	case DHO_BOOTFILE_NAME:
  	case DHO_DHCP_USER_CLASS_ID:
  	case DHO_END:
  		return (1);
 
 --Boundary-00=_clCwIcfQZalDZk1--

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Jung-uk Kim <jkim@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/127076: [patch] teach dhclient(8) to recognize options 66
	and 67
Date: Thu, 4 Sep 2008 23:33:40 +0400

 --yZnyZsPjQYjG7xG7
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Jung-uk, good evening.
 
 Thu, Sep 04, 2008 at 02:30:48PM -0400, Jung-uk Kim wrote:
 > Actually 'tftp-server-name' must be a valid hostname and it has to be=20
 > validated with res_hnok() function.  Please try the attached patch. =20
 > It will add all options listed in dhcp-options(5) and RFC 2132 as the=20
 > manual page says.
 
 Works for me.  Could it be committed?
 
 Thank you!
 --=20
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual  =20
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook=20
     {_.-``-'         {_/            #
 
 --yZnyZsPjQYjG7xG7
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.9 (FreeBSD)
 
 iEYEARECAAYFAkjAOBQACgkQthUKNsbL7Yi9HQCggfgN2ixzbcfp4QSC5lKpCYAQ
 01wAnirDV90hd2YDcdOrC+BNBKBHuajL
 =MXW1
 -----END PGP SIGNATURE-----
 
 --yZnyZsPjQYjG7xG7--

From: Jung-uk Kim <jkim@FreeBSD.org>
To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Cc: bug-followup@FreeBSD.org,
 brooks@FreeBSD.org
Subject: Re: bin/127076: [patch] teach dhclient(8) to recognize options 66 and 67
Date: Thu, 4 Sep 2008 16:13:58 -0400

 On Thursday 04 September 2008 03:33 pm, Eygene Ryabinkin wrote:
 > Jung-uk, good evening.
 >
 > Thu, Sep 04, 2008 at 02:30:48PM -0400, Jung-uk Kim wrote:
 > > Actually 'tftp-server-name' must be a valid hostname and it has
 > > to be validated with res_hnok() function.  Please try the
 > > attached patch. It will add all options listed in dhcp-options(5)
 > > and RFC 2132 as the manual page says.
 >
 > Works for me.  Could it be committed?
 
 dhclient(8) is owned by brooks.  It quires review from him (CC'ed).
 
 Jung-uk Kim

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Jung-uk Kim <jkim@FreeBSD.org>
Cc: bug-followup@FreeBSD.org, brooks@FreeBSD.org
Subject: Re: bin/127076: [patch] teach dhclient(8) to recognize options 66
	and 67
Date: Fri, 5 Sep 2008 00:36:09 +0400

 --bg08WKrSYDhXBjb5
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Thu, Sep 04, 2008 at 04:13:58PM -0400, Jung-uk Kim wrote:
 > On Thursday 04 September 2008 03:33 pm, Eygene Ryabinkin wrote:
 > > Works for me.  Could it be committed?
 >=20
 > dhclient(8) is owned by brooks.  It quires review from him (CC'ed).
 
 Fine, thanks!
 --=20
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual  =20
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook=20
     {_.-``-'         {_/            #
 
 --bg08WKrSYDhXBjb5
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.9 (FreeBSD)
 
 iEYEARECAAYFAkjARrkACgkQthUKNsbL7YhoaACgqftRvQCZAAcIxCAONNr1o/e8
 TigAmwaOajozvy48vHTa+VoPdvd01ZUg
 =4jyf
 -----END PGP SIGNATURE-----
 
 --bg08WKrSYDhXBjb5--
Responsible-Changed-From-To: freebsd-bugs->brooks 
Responsible-Changed-By: joel 
Responsible-Changed-When: Mon Sep 15 16:32:47 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=127076 
State-Changed-From-To: open->patched 
State-Changed-By: brooks 
State-Changed-When: Fri Oct 17 13:31:05 UTC 2008 
State-Changed-Why:  
Committed.  Sorry for the delay. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=127076 
State-Changed-From-To: patched->closed 
State-Changed-By: brooks 
State-Changed-When: Sun Oct 26 19:28:08 UTC 2008 
State-Changed-Why:  
MFC'd to 6 and 7 stable for 6.4 and 7.1. 

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