From fe389a82c9f9f29c54768e3b3ac947487ff85d59 Mon Sep 17 00:00:00 2001
From: stroese <stroese>
Date: Thu, 28 Aug 2003 14:17:32 +0000
Subject: [PATCH] - Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to
 CONFIG_BOOTP_MASK.

---
 README                      | 24 ++++++++++++++++++++++++
 common/cmd_net.c            |  7 +++++++
 include/cmd_confdefs.h      |  2 ++
 include/configs/CPCI405.h   | 10 ++++------
 include/configs/CPCI4052.h  | 10 ++++------
 include/configs/CPCI405AB.h |  5 ++++-
 include/net.h               |  3 +++
 net/bootp.c                 | 23 +++++++++++++++++++++++
 net/net.c                   |  3 +++
 9 files changed, 74 insertions(+), 13 deletions(-)

diff --git a/README b/README
index efd4693306..fb2529aac9 100644
--- a/README
+++ b/README
@@ -901,6 +901,29 @@ The following options need to be configured:
 		4th and following
 		BOOTP requests:		delay 0 ... 8 sec
 
+- DHCP Advanced Options:
+		CONFIG_BOOTP_MASK
+
+		You can fine tune the DHCP functionality by adding
+		these flags to the CONFIG_BOOTP_MASK define:
+
+		CONFIG_BOOTP_DNS2 - If a DHCP client requests the DNS
+		serverip from a DHCP server, it is possible that more
+		than one DNS serverip is offered to the client.
+		If CONFIG_BOOTP_DNS2 is enabled, the secondary DNS
+		serverip will be stored in the additional environment
+		variable "dnsip2". The first DNS serverip is always
+		stored in the variable "dnsip", when CONFIG_BOOTP_DNS
+		is added to the CONFIG_BOOTP_MASK.
+
+		CONFIG_BOOTP_SEND_HOSTNAME - Some DHCP servers are capable
+		to do a dynamic update of a DNS server. To do this, they
+		need the hostname of the DHCP requester.
+		If CONFIG_BOOP_SEND_HOSTNAME is added to the
+		CONFIG_BOOTP_MASK, the content of the "hostname"
+		environment variable is passed as option 12 to
+		the DHCP server.
+
 - Status LED:	CONFIG_STATUS_LED
 
 		Several configurations allow to display the current
@@ -2118,6 +2141,7 @@ depending the information provided by your boot server:
 
   bootfile	- see above
   dnsip		- IP address of your Domain Name Server
+  dnsip2	- IP address of your secondary Domain Name Server
   gatewayip	- IP address of the Gateway (Router) to use
   hostname	- Target hostname
   ipaddr	- see above
diff --git a/common/cmd_net.c b/common/cmd_net.c
index 4d4a1ea9ed..e9b54d2450 100644
--- a/common/cmd_net.c
+++ b/common/cmd_net.c
@@ -116,6 +116,13 @@ static void netboot_update_env(void)
 	setenv("dnsip", tmp);
     }
 
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
+    if (NetOurDNS2IP) {
+	    ip_to_string (NetOurDNS2IP, tmp);
+	    setenv("dnsip2", tmp);
+    }
+#endif
+
     if (NetOurNISDomain[0])
 	setenv("domain", NetOurNISDomain);
 
diff --git a/include/cmd_confdefs.h b/include/cmd_confdefs.h
index 8b8b0f58e7..d7f1fd4fed 100644
--- a/include/cmd_confdefs.h
+++ b/include/cmd_confdefs.h
@@ -148,6 +148,8 @@
 #define CONFIG_BOOTP_BOOTPATH		0x00000010
 #define CONFIG_BOOTP_BOOTFILESIZE	0x00000020
 #define CONFIG_BOOTP_DNS		0x00000040
+#define CONFIG_BOOTP_DNS2		0x00000080
+#define CONFIG_BOOTP_SEND_HOSTNAME      0x00000100
 
 #define CONFIG_BOOTP_VENDOREX		0x80000000
 
diff --git a/include/configs/CPCI405.h b/include/configs/CPCI405.h
index 4be94ed854..b877043712 100644
--- a/include/configs/CPCI405.h
+++ b/include/configs/CPCI405.h
@@ -69,12 +69,10 @@
 #define CONFIG_MII		1	/* MII PHY management		*/
 #define	CONFIG_PHY_ADDR		0	/* PHY address			*/
 
-#if 0 /* test-only */
-#define CONFIG_BOOTP_MASK	(CONFIG_BOOTP_DEFAULT |  \
-				 CONFIG_BOOTP_VENDOREX)
-#else
-#define CONFIG_BOOTP_MASK       (CONFIG_BOOTP_DEFAULT)
-#endif
+#define CONFIG_BOOTP_MASK       (CONFIG_BOOTP_DEFAULT | \
+				 CONFIG_BOOTP_DNS | \
+				 CONFIG_BOOTP_DNS2 | \
+				 CONFIG_BOOTP_SEND_HOSTNAME )
 
 #define CONFIG_COMMANDS	      ( CONFIG_CMD_DFL	| \
 				CFG_CMD_DHCP	| \
diff --git a/include/configs/CPCI4052.h b/include/configs/CPCI4052.h
index 1f9d39c606..dd2fa7ffea 100644
--- a/include/configs/CPCI4052.h
+++ b/include/configs/CPCI4052.h
@@ -72,12 +72,10 @@
 
 #define CONFIG_RTC_M48T35A	1		/* ST Electronics M48 timekeeper */
 
-#if 0 /* test-only */
-#define CONFIG_BOOTP_MASK	(CONFIG_BOOTP_DEFAULT |  \
-				 CONFIG_BOOTP_VENDOREX)
-#else
-#define CONFIG_BOOTP_MASK       (CONFIG_BOOTP_DEFAULT)
-#endif
+#define CONFIG_BOOTP_MASK       (CONFIG_BOOTP_DEFAULT | \
+				 CONFIG_BOOTP_DNS | \
+				 CONFIG_BOOTP_DNS2 | \
+				 CONFIG_BOOTP_SEND_HOSTNAME )
 
 #define CONFIG_COMMANDS	      ( CONFIG_CMD_DFL	| \
 				CFG_CMD_DHCP	| \
diff --git a/include/configs/CPCI405AB.h b/include/configs/CPCI405AB.h
index 00adfd5998..d55b51eb97 100644
--- a/include/configs/CPCI405AB.h
+++ b/include/configs/CPCI405AB.h
@@ -65,7 +65,10 @@
 
 #define CONFIG_RTC_M48T35A	1		/* ST Electronics M48 timekeeper */
 
-#define CONFIG_BOOTP_MASK       (CONFIG_BOOTP_DEFAULT)
+#define CONFIG_BOOTP_MASK       (CONFIG_BOOTP_DEFAULT | \
+				 CONFIG_BOOTP_DNS | \
+				 CONFIG_BOOTP_DNS2 | \
+				 CONFIG_BOOTP_SEND_HOSTNAME )
 
 #define CONFIG_COMMANDS	      ( CONFIG_CMD_DFL	| \
 				CFG_CMD_DHCP	| \
diff --git a/include/net.h b/include/net.h
index dd8d378045..2d4aa94d0d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -275,6 +275,9 @@ typedef struct icmphdr {
 extern IPaddr_t		NetOurGatewayIP;	/* Our gateway IP addresse	*/
 extern IPaddr_t		NetOurSubnetMask;	/* Our subnet mask (0 = unknown)*/
 extern IPaddr_t		NetOurDNSIP;	 /* Our Domain Name Server (0 = unknown)*/
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
+extern IPaddr_t		NetOurDNS2IP;	 /* Our 2nd Domain Name Server (0 = unknown)*/
+#endif
 extern char		NetOurNISDomain[32];	/* Our NIS domain		*/
 extern char		NetOurHostName[32];	/* Our hostname			*/
 extern char		NetOurRootPath[64];	/* Our root path		*/
diff --git a/net/bootp.c b/net/bootp.c
index 31b224327e..854ca16d6a 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -174,6 +174,11 @@ static void BootpVendorFieldProcess(u8 *ext)
 		if (NetOurDNSIP == 0) {
 			NetCopyIP(&NetOurDNSIP, (IPaddr_t*)(ext+2));
 		}
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
+		if ((NetOurDNS2IP == 0) && (size > 4)) {
+			NetCopyIP(&NetOurDNS2IP, (IPaddr_t*)(ext+2+4));
+		}
+#endif
 		break;
 	case 7:		/* Log server - Not yet supported		*/
 		break;
@@ -365,6 +370,9 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, IPaddr_t Req
 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
     u8 *x;
 #endif
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME)
+    uchar *hostname;
+#endif
 
     *e++ =  99;		/* RFC1048 Magic Cookie */
     *e++ = 130;
@@ -402,6 +410,16 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, IPaddr_t Req
 	    *e++ = tmp & 0xff;
     }
 
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME)
+    if ( (hostname = getenv("hostname")) ) {
+	    int hostnamelen = strlen(hostname);
+	    *e++ = 12;        /* Hostname */
+	    *e++ = hostnamelen;
+	    memcpy(e,hostname,hostnamelen);
+	    e += hostnamelen;
+    }
+#endif
+
 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
     if ((x = dhcp_vendorex_prep (e)))
 	return x - start ;
@@ -690,6 +708,11 @@ static void DhcpOptionsProcess(uchar *popt)
 				break;
 			case  6:
 				NetCopyIP(&NetOurDNSIP, (popt+2));
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
+				if ( *(popt+1) > 4 ) {
+					NetCopyIP(&NetOurDNS2IP, (popt+2+4));
+				}
+#endif
 				break;
 			case 12:
 				size = truncate_sz ("Host Name",
diff --git a/net/net.c b/net/net.c
index dafcc561e6..a139742292 100644
--- a/net/net.c
+++ b/net/net.c
@@ -84,6 +84,9 @@
 IPaddr_t	NetOurSubnetMask=0;		/* Our subnet mask (0=unknown)	*/
 IPaddr_t	NetOurGatewayIP=0;		/* Our gateways IP address	*/
 IPaddr_t	NetOurDNSIP=0;			/* Our DNS IP address		*/
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
+IPaddr_t	NetOurDNS2IP=0;			/* Our 2nd DNS IP address	*/
+#endif
 char		NetOurNISDomain[32]={0,};	/* Our NIS domain		*/
 char		NetOurHostName[32]={0,};	/* Our hostname			*/
 char		NetOurRootPath[64]={0,};	/* Our bootpath			*/
-- 
2.39.5