Skip to contentSkip to conversation

Support for sending DHCP client options

PATCH New Gray Remlin 2 participants 2 messages Oct 19, 2010 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support for sending DHCP client options

---
 README              |    7 ++++++
 common/cmd_nvedit.c |    3 ++
 net/bootp.c         |   52
+++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/env/fw_env.c  |    4 ++-
 4 files changed, 65 insertions(+), 1 deletions(-)
README +7 -0
index a52f3bf..90da375 100644
@@ -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 it's response.
+
                CONFIG_BOOTP_DHCP_REQUEST_DELAY
 
                A 32bit value in microseconds for a delay between
common/cmd_nvedit.c +0 -0
index 3d30c32..2094e8e 100644
@@ -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)
net/bootp.c +0 -0
index 1289e3b..9e687b0 100644
@@ -68,6 +68,54 @@ 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

+ */
+u8 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++;
+       }
+
+       debug("DHCP Client options end\n");
+       *ep = e;
+       return e;

+}
+
+#endif /* CONFIG_BOOTP_OPTIONS */
+
#endif

static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src,
unsigned len)
@@ -412,6 +460,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;
tools/env/fw_env.c +3 -1
index 8ff7052..ae37d15 100644
@@ -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);
                        errno = EROFS;

--

#1 lore raw

PATCH 1/1 Support for sending DHCP client options

Quoted 22 lines · Gray Remlin
---
 README              |    7 ++++++
 common/cmd_nvedit.c |    3 ++
 net/bootp.c         |   52
+++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/env/fw_env.c  |    4 ++-
 4 files changed, 65 insertions(+), 1 deletions(-)
README +1 -0
index a52f3bf..90da375 100644
@@ -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.

README The following options need to be configured: · line 1307

Quoted 8 lines
README +5 -0
@@ -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 it's response.

s/it's/its/

Signature · 4 lines
It is of fundamental importance to understand   |
that the primary recipient of your source code  | Email to 'CTZ001'
is not the compiler but your coworkers.         |    at 'email.mot.com'
   -- KreaTV SW Dev Guidelines                  |