changeset 1315:49e5a36e706d

* include/dhcp.h: Added prototype for dhcp_set_hostname(). * src/dhcp_prot.c (set_default_dhcp_tags): Added TAG_HOST_NAME and TAG_DHCP_CLIENTID DHCP/BOOTP option support. * cdl/net.cdl: Added host name (CYGOPT_NET_DHCP_OPTION_HOST_NAME) and MAC address client ID (CYGOPT_NET_DHCP_OPTION_DHCP_CLIENTID_MAC) support.
author asl
date Thu, 16 Oct 2003 08:13:45 +0000
parents 6c521260528e
children b91538194ae8
files packages/net/common/current/ChangeLog packages/net/common/current/cdl/net.cdl packages/net/common/current/include/dhcp.h packages/net/common/current/src/dhcp_prot.c
diffstat 4 files changed, 80 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/packages/net/common/current/ChangeLog
+++ b/packages/net/common/current/ChangeLog
@@ -1,3 +1,11 @@
+2003-10-13  Jay Foster  <jay@systech.com>
+
+	* include/dhcp.h: Added prototype for dhcp_set_hostname().
+	* src/dhcp_prot.c (set_default_dhcp_tags): Added TAG_HOST_NAME and
+      TAG_DHCP_CLIENTID DHCP/BOOTP option support.
+	* cdl/net.cdl: Added host name (CYGOPT_NET_DHCP_OPTION_HOST_NAME) and
+      MAC address client ID (CYGOPT_NET_DHCP_OPTION_DHCP_CLIENTID_MAC) support.
+
 2003-10-12  Jay Foster  <jay@systech.com>
  
  	* cdl/net.cdl: Added configuration interface for
--- a/packages/net/common/current/cdl/net.cdl
+++ b/packages/net/common/current/cdl/net.cdl
@@ -268,6 +268,37 @@ cdl_package CYGPKG_NET {
                 requested options in the DHCP/BOOTP request list.
                 These are a comma separated list of TAG_xxx values."
         }
+
+        cdl_component CYGOPT_NET_DHCP_OPTION_HOST_NAME {
+            display "DHCP host name option"
+            flavor  bool
+            default_value 0
+            active_if CYGOPT_NET_DHCP_DHCP_THREAD
+            description "
+                This option adds the TAG_HOST_NAME option to the DHCP/BOOTP
+                requests.  The host name is defined by calling the function
+                dhcp_set_hostname(), prior to calling init_all_network_interfaces()."
+
+            cdl_option CYGNUM_NET_DHCP_OPTION_HOST_NAME_LEN {
+                display "DHCP host name maximum length"
+                flavor  data
+                default_value 60
+                active_if CYGOPT_NET_DHCP_OPTION_HOST_NAME
+                description "
+                    This option defines the maximum length allowed for the 
+                    host name set by dhcp_set_hostname()."
+            }
+        }
+
+        cdl_option CYGOPT_NET_DHCP_OPTION_DHCP_CLIENTID_MAC {
+            display "DHCP client ID option"
+            flavor  bool
+            default_value 0
+            active_if CYGOPT_NET_DHCP_DHCP_THREAD
+            description "
+                This option adds the TAG_DHCP_CLIENTID option to the DHCP/BOOTP
+                requests.  It uses the interface MAC address for the identifier."
+        }
     }
 
     cdl_component CYGPKG_NET_IPV6_ROUTING {
--- a/packages/net/common/current/include/dhcp.h
+++ b/packages/net/common/current/include/dhcp.h
@@ -161,6 +161,15 @@ extern int dhcp_release( void );
 //
 // ------------------------------------------------------------------------
 
+// Set hostname to be used with the DHCP TAG_HOST_NAME option.
+// Call this before calling init_all_network_interfaces() to
+// set the hostname value.
+#ifdef CYGOPT_NET_DHCP_OPTION_HOST_NAME
+extern void dhcp_set_hostname(char *hostname);
+#else
+#define dhcp_set_hostname(hostname)        CYG_EMPTY_STATEMENT
+#endif
+
 #ifdef CYGOPT_NET_DHCP_DHCP_THREAD
 // Then we provide such a thread...
 
--- a/packages/net/common/current/src/dhcp_prot.c
+++ b/packages/net/common/current/src/dhcp_prot.c
@@ -73,6 +73,19 @@
 
 extern int  cyg_arc4random(void);
 
+#ifdef CYGOPT_NET_DHCP_OPTION_HOST_NAME
+static char dhcp_hostname[CYGNUM_NET_DHCP_OPTION_HOST_NAME_LEN+1];
+
+// Set the hostname used by the DHCP TAG_HOST_NAME option.  We
+// copy the callers name into a private buffer, since we don't
+// know the context in which the callers hostname was allocated.
+void dhcp_set_hostname(char *hostname)
+{
+    CYG_ASSERT( (strlen(hostname)<=CYGNUM_NET_DHCP_OPTION_HOST_NAME_LEN), "dhcp hostname too long" );
+    strncpy(dhcp_hostname, hostname, CYGNUM_NET_DHCP_OPTION_HOST_NAME_LEN);
+}
+#endif
+
 // ------------------------------------------------------------------------
 // Returns a pointer to the end of dhcp message (or NULL if invalid)
 // meaning the address of the byte *after* the TAG_END token in the vendor
@@ -540,6 +553,25 @@ static void set_default_dhcp_tags( struc
         set_variable_tag( xmit, TAG_DHCP_PARM_REQ_LIST,
                           &req_list[0], sizeof( req_list ) );
 
+#ifdef CYGOPT_NET_DHCP_OPTION_HOST_NAME
+{
+    int nlen = strlen(dhcp_hostname);
+
+    if (nlen > 0)
+    	set_variable_tag( xmit, TAG_HOST_NAME, dhcp_hostname, nlen + 1);
+}
+#endif
+#ifdef CYGOPT_NET_DHCP_OPTION_DHCP_CLIENTID_MAC
+{
+	cyg_uint8 id[16+1];	/* sizeof bp_chaddr[] + 1 */
+
+	id[0] = 1;  /* 1-byte hardware type: 1=ethernet. */
+    CYG_ASSERT( xmit->bp_hlen<=(sizeof(id)-1), "HW address invalid" );
+    memcpy(&id[1], &xmit->bp_chaddr, xmit->bp_hlen);
+    set_variable_tag( xmit, TAG_DHCP_CLIENTID, id, xmit->bp_hlen+1);
+}
+#endif
+
     // Explicitly specify our max message size.
     set_fixed_tag( xmit, TAG_DHCP_MAX_MSGSZ, BP_MINPKTSZ, 2 );
 }