[PATCH 2/8] net: dhcp: add support of tftp name server

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Fri Mar 30 00:31:47 EDT 2012


if the DNS is enable resolve it. The server ip will be set if no server ip it
is set in the bootp.
Export it via env tftp_server_name.

E.g. the ISC dhcp server can be configured with

   | class "at91sam9x5ek" {
   |         match if substring (option vendor-class-identifier,0,20) = "barebox-at91sam9x5ek";
   |
   |         filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage";
   |         option tftp-server-name "192.168.200.98";
   |         option root-path "192.168.200.98:/opt/work/buildroot/build/sam9x5/target";
   |         }
   | }

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 net/dhcp.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index 1ba4def..6728717 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -193,6 +193,8 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
 	*cnt += 1;
 	*e++  = 17;		/* Boot path */
 	*cnt += 1;
+	*e++  = 66;		/* TFTP server name */
+	*cnt += 1;
 	*e++  = 255;		/* End of the list */
 
 	/* Pad to minimal length */
@@ -252,6 +254,7 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
 	int oplen;
 	IPaddr_t ip;
 	char str[256];
+	char tftpname[256];
 
 	while (popt < end && *popt != 0xff) {
 		oplen = *(popt + 1);
@@ -295,7 +298,10 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
 			break;
 		case 59:	/* Ignore Rebinding Time Option */
 			break;
-		case 66:	/* Ignore TFTP server name */
+		case 66:	/* TFTP server name */
+			memcpy(tftpname, popt + 2, oplen);
+			tftpname[oplen] = 0;
+			setenv("tftp_server_name", tftpname);
 			break;
 		case 67:	/* vendor opt bootfile */
 			/*
@@ -331,6 +337,9 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
 		}
 		popt += oplen + 2;	/* Process next option */
 	}
+
+	if (tftpname[0] != 0)
+		net_set_serverip(resolv(tftpname));
 }
 
 static int dhcp_message_type(unsigned char *popt)
@@ -458,6 +467,7 @@ static int do_dhcp(int argc, char *argv[])
 	setenv("hostname","");
 	setenv("domainname","");
 	setenv("rootpath","");
+	setenv("tftp_server_name","");
 
 	while((opt = getopt(argc, argv, "v:")) > 0) {
 		switch(opt) {
@@ -526,3 +536,4 @@ BAREBOX_MAGICVAR(hostname, "hostname returned from DHCP request");
 BAREBOX_MAGICVAR(domainname, "domainname returned from DHCP request");
 BAREBOX_MAGICVAR(rootpath, "rootpath returned from DHCP request");
 BAREBOX_MAGICVAR(dhcp_vendor_id, "vendor id to send to the DHCP server");
+BAREBOX_MAGICVAR(tftp_server_name, "TFTP server Name returned from DHCP request");
-- 
1.7.9.1




More information about the barebox mailing list