From patchwork Wed Oct 20 16:48:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gray Remlin X-Patchwork-Id: 71909 Return-Path: X-Original-To: wd@gemini.denx.de Delivered-To: wd@gemini.denx.de Received: from diddl.denx.de (diddl.denx.de [10.0.0.6]) by gemini.denx.de (Postfix) with ESMTP id C0461136320 for ; Wed, 20 Oct 2010 18:51:23 +0200 (CEST) Received: from diddl.denx.de (localhost.localdomain [127.0.0.1]) by diddl.denx.de (Postfix) with ESMTP id A48F0348C9D1 for ; Wed, 20 Oct 2010 18:51:23 +0200 (CEST) Received: from pop.mnet-online.de by diddl.denx.de with POP3 (fetchmail-6.3.17) for (single-drop); Wed, 20 Oct 2010 18:51:23 +0200 (CEST) Received: from murder ([192.168.8.180]) by backend2 (Cyrus v2.2.12) with LMTPA; Wed, 20 Oct 2010 18:49:09 +0200 X-Sieve: CMU Sieve 2.2 Received: from mail.m-online.net (localhost [127.0.0.1]) by frontend1.mail.m-online.net (Cyrus v2.2.12) with LMTPA; Wed, 20 Oct 2010 18:49:08 +0200 Received: from scanner-3.m-online.net (unknown [192.168.6.168]) by mail.m-online.net (Postfix) with ESMTP id E49611C000F6; Wed, 20 Oct 2010 18:49:08 +0200 (CEST) Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by mxin-1.m-online.net (Postfix) with ESMTP id 246E646C0A0; Wed, 20 Oct 2010 18:48:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E0997281CB; Wed, 20 Oct 2010 18:48:55 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E86KmVeduYdu; Wed, 20 Oct 2010 18:48:55 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 842E2281B6; Wed, 20 Oct 2010 18:48:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1E577281AF for ; Wed, 20 Oct 2010 18:48:48 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nfQMbS02qItL for ; Wed, 20 Oct 2010 18:48:46 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from nm17-vm0.bullet.mail.ukl.yahoo.com (nm17-vm0.bullet.mail.ukl.yahoo.com [217.146.183.93]) by theia.denx.de (Postfix) with SMTP id 068DA281AB for ; Wed, 20 Oct 2010 18:48:44 +0200 (CEST) Received: from [217.146.183.216] by nm17.bullet.mail.ukl.yahoo.com with NNFMP; 20 Oct 2010 16:48:44 -0000 Received: from [217.146.183.177] by tm9.bullet.mail.ukl.yahoo.com with NNFMP; 20 Oct 2010 16:48:43 -0000 Received: from [127.0.0.1] by omp1018.mail.ukl.yahoo.com with NNFMP; 20 Oct 2010 16:48:43 -0000 X-Yahoo-Newman-Id: 683478.13618.bm@omp1018.mail.ukl.yahoo.com Received: (qmail 44954 invoked from network); 20 Oct 2010 16:48:43 -0000 Received: from phenom.research.lan (g_remlin@178.110.85.149 with plain) by smtp141.mail.ukl.yahoo.com with SMTP; 20 Oct 2010 16:48:42 +0000 GMT X-Yahoo-SMTP: cuoQNyCswBCkPlR5hugWtcAYMXb_2kD6BwSxvxHBn7VG_YHo X-YMail-OSG: DwMZhkkVM1nihPTAJFVe..rH4MyAznZNlrpznQ9DmujX7Xv etGOWhW6zHUtbH_lQ9msAKf33VQ6UtdLxv363Pc8nIWH57UZ1.pFZpn6Cks_ pxFW_ZA4nTx84THVvyEptIuXoOxZuOXQGMpFLKgbKLdT5Z5d7aYWmAyt8pBH 435nq0zqKVtAHCoHMn3LxLIOg0RAPzj7XHRxy2GnFg7.mzPSXVNHvrBnhRp7 .YQQ7dBWtJ_XZxw-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4CBF1D5D.3070208@rocketmail.com> Date: Wed, 20 Oct 2010 17:48:29 +0100 From: Gray Remlin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc13 Lightning/1.0b3pre Thunderbird/3.1.4 ThunderBrowse/3.3.2 MIME-Version: 1.0 To: u-boot@lists.denx.de Cc: biggerbadderben@gmail.com Subject: [U-Boot] Subject: [PATCH v2] Support for sending DHCP client options X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Virus-Scanned: by amavisd-new at m-online.net If CONFIG_BOOTP_OPTIONS is defined at compile-time, the environment will be checked for the supported DHCPv4 client options during construction of a "DHCP Discover" or "DHCP Request" packet. Any found (as listed below, prefixed with dhcp_) will have their value included in the dhcp packet. dhcp_vendor-class-identifier dhcp_user-class dhcp_dhcp-client-identifier Signed-off-by: Gray Remlin --- v2: Remove redundant return value from dhcp_options_prep function Change dhcp_options_prep function return type to static void Correct grammatical error in README README | 7 +++++++ common/cmd_nvedit.c | 3 +++ net/bootp.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/env/fw_env.c | 4 +++- 4 files changed, 64 insertions(+), 1 deletions(-) errno = EROFS; -- diff --git a/README b/README index a52f3bf..cd892cc 100644 --- a/README +++ b/README @@ -1279,6 +1279,7 @@ The following options need to be configured: CONFIG_BOOTP_NTPSERVER CONFIG_BOOTP_TIMEOFFSET CONFIG_BOOTP_VENDOREX + CONFIG_BOOTP_OPTIONS CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip environment variable, not the BOOTP server. @@ -1299,6 +1300,12 @@ The following options need to be configured: of the "hostname" environment variable is passed as option 12 to the DHCP server. + CONFIG_BOOTP_OPTIONS - The environment is checked for the + supported DHCPv4 client options (prefixed with dhcp_), any + found are sent during a "DHCP Discover" and "DHCP Request". + The DHCP server can use this information to conditionally + tailor its response. + CONFIG_BOOTP_DHCP_REQUEST_DELAY A 32bit value in microseconds for a delay between diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 3d30c32..2094e8e 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -224,6 +224,9 @@ int _do_env_set (int flag, int argc, char * const argv[]) if (ep) { /* variable exists */ #ifndef CONFIG_ENV_OVERWRITE if ((strcmp (name, "serial#") == 0) || +#if defined(CONFIG_BOOTP_OPTIONS) + (strcmp(name, "dhcp_vendor-class-identifier") == 0) || +#endif /* CONFIG_BOOTP_OPTIONS */ ((strcmp (name, "ethaddr") == 0) #if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR) && (strcmp (ep->data,MK_STR(CONFIG_ETHADDR)) != 0) diff --git a/net/bootp.c b/net/bootp.c index 1289e3b..61ecede 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -68,6 +68,53 @@ extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */ extern u8 *dhcp_vendorex_proc (u8 *e); /*rtn next e if mine,else NULL */ #endif +#if defined(CONFIG_BOOTP_OPTIONS) /* check environment for dhcp client options */ + +/* + * The vendor-specifiable options should not be changeable + * unless CONFIG_ENV_OVERWRITE has been defined, however + * user-specifiable options should be changeable regardless + */ +static void dhcp_options_prep(u8 **ep) +{ + u8 *e = *ep; + char *ptr; + + debug("DHCP Client options start\n"); + + /* vendor-specifiable identification string */ + if ((ptr = getenv("dhcp_vendor-class-identifier"))) { + debug("dhcp_vendor-class-identifier=%s\n",ptr); + *e++ = 60; + *e++ = strlen(ptr); + while (*ptr) + *e++ = *ptr++; + } + + /* user-specifiable identification string */ + if ((ptr = getenv("dhcp_dhcp-client-identifier"))) { + debug("dhcp_dhcp-client-identifier=%s\n",ptr); + *e++ = 61; + *e++ = strlen(ptr); + while (*ptr) + *e++ = *ptr++; + } + + /* user-specifiable identification string */ + if ((ptr = getenv("dhcp_user-class"))) { + debug("dhcp_user-class=%s\n",ptr); + *e++ = 77; + *e++ = strlen(ptr); + while (*ptr) + *e++ = *ptr++; + } + + *ep = e; + debug("DHCP Client options end\n"); +} + +#endif /* CONFIG_BOOTP_OPTIONS */ + #endif static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len) @@ -412,6 +459,10 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R } #endif +#if defined(CONFIG_BOOTP_OPTIONS) + dhcp_options_prep (&e); +#endif + #if defined(CONFIG_BOOTP_VENDOREX) if ((x = dhcp_vendorex_prep (e))) return x - start; diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 8ff7052..ae37d15 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -391,9 +391,11 @@ int fw_env_write(char *name, char *value) */ if (oldval) { /* - * Ethernet Address and serial# can be set only once + * Ethernet Address, vendor DHCP options, + * and serial# can be set only once */ if ((strcmp (name, "ethaddr") == 0) || + (strcmp(name, "dhcp_vendor-class-identifier") == 0) || (strcmp (name, "serial#") == 0)) { fprintf (stderr, "Can't overwrite \"%s\"\n", name);