mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/8] Network update DHCP/BOOTP
@ 2012-03-30  4:27 Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 1/8] net: dhcp: reset env variable before do a dhcp request Jean-Christophe PLAGNIOL-VILLARD
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:27 UTC (permalink / raw)
  To: barebox

HI,

	the following patch series update the network dhcp and bootp support
	to support options 66, 150, 61, 77, 97

	this will also help to add pxe boot support later

The following changes since commit 485cee59cf64b5019c5a294074007b93509b83e0:

  Merge branch 'work/imx51-babbage-clk' into next (2012-03-23 21:22:14 +0100)

are available in the git repository at:


  git://git.jcrosoft.org/barebox.git net

for you to fetch changes up to 2e991cac2e1444def3d27ec06fd10724fe3e19ba:

  defaultenv: add support of etherboot_file (2012-03-30 12:40:18 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (8):
      net: dhcp: reset env variable before do a dhcp request
      net: dhcp: add support of tftp name server
      net: dhcp: add support of tftp server ip or Etherboot file (option 150)
      net: dhcp: allow to set transmitted client id
      net: dhcp: allow to set transmitted client uuid
      net: dhcp: allow to set transmitted user class
      net: dns: export resolved ip to var resolved_ip
      defaultenv: add support of etherboot_file

 defaultenv/bin/boot |    4 ++
 net/dhcp.c          |  118 ++++++++++++++++++++++++++++++++++++++++++++-------
 net/dns.c           |    5 ++
 3 files changed, 111 insertions(+), 16 deletions(-)

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/8] net: dhcp: reset env variable before do a dhcp request
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 2/8] net: dhcp: add support of tftp name server Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

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

diff --git a/net/dhcp.c b/net/dhcp.c
index 53eed6c..1ba4def 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -453,6 +453,12 @@ static int do_dhcp(int argc, char *argv[])
 	int ret, opt;
 	char *vendor_id = (char*)getenv("dhcp_vendor_id");
 
+	setenv("bootfile","");
+	setenv("nameserver","");
+	setenv("hostname","");
+	setenv("domainname","");
+	setenv("rootpath","");
+
 	while((opt = getopt(argc, argv, "v:")) > 0) {
 		switch(opt) {
 		case 'v':
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/8] net: dhcp: add support of tftp name server
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 1/8] net: dhcp: reset env variable before do a dhcp request Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150) Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

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@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 1/8] net: dhcp: reset env variable before do a dhcp request Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 2/8] net: dhcp: add support of tftp name server Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  9:21   ` Sascha Hauer
  2012-03-30  4:31 ` [PATCH 4/8] net: dhcp: allow to set transmitted client id Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

if tftp server ip
	Use the tftp server name only if this option is not set.
	Export it also via env tftp_server_ip.
else
	Export it via end etherboot_file

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

  | option option-150 code 150 = ip-address;
  | option option-150-etherboot-file code 150 = string;
  |
  | 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 option-150 192.168.200.98;
  |         next-server 192.168.200.98;
  |         option root-path "192.168.200.98:/opt/work/buildroot/build/sam9x5/target";
  |         if substring (option dhcp-client-identifier,0,7) = "ser2net" {
  |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
  |                 ption option-150-etherboot-file "/tftpboot/test.sh";
  |         }
  | }

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

diff --git a/net/dhcp.c b/net/dhcp.c
index 6728717..adfb4a0 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -195,6 +195,8 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
 	*cnt += 1;
 	*e++  = 66;		/* TFTP server name */
 	*cnt += 1;
+	*e++  = 150;		/* TFTP server ip */
+	*cnt += 1;
 	*e++  = 255;		/* End of the list */
 
 	/* Pad to minimal length */
@@ -255,6 +257,7 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
 	IPaddr_t ip;
 	char str[256];
 	char tftpname[256];
+	bool is_tftpserverip = false;
 
 	while (popt < end && *popt != 0xff) {
 		oplen = *(popt + 1);
@@ -327,6 +330,18 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
 					setenv("bootfile", str);
 			}
 			break;
+		case 150:	/* TFTP server ip or Etherboot*/
+			if (oplen == sizeof(IPaddr_t)) {
+				is_tftpserverip = true;
+				ip = net_read_ip(popt + 2);
+				net_set_serverip(ip);
+				setenv_ip("tftp_server_ip", ip);
+			} else {
+				memcpy(str, popt + 2, oplen);
+				str[oplen] = 0;
+				setenv("etherboot_file", str);
+			}
+			break;
 		default:
 #ifdef CONFIG_BOOTP_VENDOREX
 			if (dhcp_vendorex_proc (popt))
@@ -338,7 +353,7 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
 		popt += oplen + 2;	/* Process next option */
 	}
 
-	if (tftpname[0] != 0)
+	if (!is_tftpserverip && tftpname[0] != 0)
 		net_set_serverip(resolv(tftpname));
 }
 
@@ -468,6 +483,8 @@ static int do_dhcp(int argc, char *argv[])
 	setenv("domainname","");
 	setenv("rootpath","");
 	setenv("tftp_server_name","");
+	setenv("tftp_server_ip","");
+	setenv("etherboot_file","");
 
 	while((opt = getopt(argc, argv, "v:")) > 0) {
 		switch(opt) {
@@ -537,3 +554,5 @@ 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");
+BAREBOX_MAGICVAR(tftp_server_ip, "TFTP server IP returned from DHCP request");
+BAREBOX_MAGICVAR(etherboot_file, "Etherboot File returned from DHCP request");
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/8] net: dhcp: allow to set transmitted client id
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 preceding siblings ...)
  2012-03-30  4:31 ` [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150) Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 5/8] net: dhcp: allow to set transmitted client uuid Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

For net boot setups it is useful to submit boot params like server or
bootfile over dhcp. To distinguish diffrent type of OS running on the same hardware,
a custom vendor id can be sent in dhcp discover/request messages.

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";
 |         if substring (option dhcp-client-identifier,0,7) = "ser2net" {
 |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
 |         }
 |         option tftp-server-name "192.168.200.98";
 |         option option-150 192.168.200.98;
 |         next-server 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@jcrosoft.com>
---
 net/dhcp.c |   54 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index adfb4a0..8945587 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -75,6 +75,8 @@ static dhcp_state_t dhcp_state;
 static uint32_t dhcp_leasetime;
 static IPaddr_t net_dhcp_server_ip;
 static uint64_t dhcp_start;
+static char *client_id;
+static char *vendor_id;
 
 static int bootp_check_packet(unsigned char *pkt, unsigned src, unsigned len)
 {
@@ -125,15 +127,32 @@ static void bootp_copy_net_params(struct bootp *bp)
 	debug("bootfile: %s\n", bp->bp_file);
 }
 
+static int dhcp_set_string_options(u8 *e, int option, char* str)
+{
+	int str_len;
+
+	if (!str)
+		return 0;
+
+	str_len = strlen(str);
+	if (!str_len)
+		return 0;
+
+	*e++ = option;
+	*e++ = str_len;
+	memcpy(e, str, str_len);
+
+	return str_len + 2;
+}
+
 /*
  * Initialize BOOTP extension fields in the request.
  */
 static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
-			  IPaddr_t RequestedIP, char *vendor_id)
+			  IPaddr_t RequestedIP)
 {
 	u8 *start = e;
 	u8 *cnt;
-	int vendor_id_len = vendor_id ? strlen(vendor_id) : 0;
 
 	*e++ = 99;		/* RFC1048 Magic Cookie */
 	*e++ = 130;
@@ -171,12 +190,8 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
 		*e++ = tmp & 0xff;
 	}
 
-	if (vendor_id_len > 0) {
-		*e++ = 60;
-		*e++ = vendor_id_len;
-		memcpy(e, vendor_id, vendor_id_len);
-		 e  += vendor_id_len;
-	}
+	 e += dhcp_set_string_options(e, 60, vendor_id);
+	 e += dhcp_set_string_options(e, 61, client_id);
 
 	*e++ = 55;		/* Parameter Request List */
 	 cnt = e++;		/* Pointer to count of requested items */
@@ -237,8 +252,7 @@ static int bootp_request(void)
 		safe_strncpy (bp->bp_file, bfile, sizeof(bp->bp_file));
 
 	/* Request additional information from the BOOTP/DHCP server */
-	ext_len = dhcp_extended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0,
-				dhcp_con->priv);
+	ext_len = dhcp_extended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
 
 	Bootp_id = (uint32_t)get_time_ns();
 	net_copy_uint32(&bp->bp_id, &Bootp_id);
@@ -409,7 +423,7 @@ static void dhcp_send_request_packet(struct bootp *bp_offer)
 	 */
 	net_copy_ip(&OfferedIP, &bp->bp_yiaddr);
 	extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_REQUEST, net_dhcp_server_ip,
-				OfferedIP, dhcp_con->priv);
+				OfferedIP);
 
 	debug("Transmitting DHCPREQUEST packet\n");
 	net_udp_send(dhcp_con, sizeof(*bp) + extlen);
@@ -475,7 +489,8 @@ static void dhcp_handler(void *ctx, char *packet, unsigned int len)
 static int do_dhcp(int argc, char *argv[])
 {
 	int ret, opt;
-	char *vendor_id = (char*)getenv("dhcp_vendor_id");
+	vendor_id = (char*)getenv("dhcp_vendor_id");
+	client_id = (char*)getenv("dhcp_client_id");
 
 	setenv("bootfile","");
 	setenv("nameserver","");
@@ -486,15 +501,21 @@ static int do_dhcp(int argc, char *argv[])
 	setenv("tftp_server_ip","");
 	setenv("etherboot_file","");
 
-	while((opt = getopt(argc, argv, "v:")) > 0) {
+	while((opt = getopt(argc, argv, "v:c:")) > 0) {
 		switch(opt) {
 		case 'v':
 			vendor_id = optarg;
 			break;
+		case 'c':
+			client_id = optarg;
+			break;
 		}
 	}
 
-	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, vendor_id);
+	pr_debug("vendor_id: '%s'\n", vendor_id);
+	pr_debug("client_id: '%s'\n", client_id);
+
+	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
 	if (IS_ERR(dhcp_con)) {
 		ret = PTR_ERR(dhcp_con);
 		goto out;
@@ -538,6 +559,10 @@ BAREBOX_CMD_HELP_SHORT("Invoke dhcp client to obtain ip/boot params.\n")
 BAREBOX_CMD_HELP_OPT  ("-v <vendor_id>",
 "DHCP Vendor ID (code 60) submitted in DHCP requests. It can\n"
 "be used in the DHCP server's configuration to select options\n"
+"(e.g. bootfile or server) which are valid for barebox clients only.\n")
+BAREBOX_CMD_HELP_OPT  ("-c <client_id>",
+"DHCP Client ID (code 61) submitted in DHCP requests. It can\n"
+"be used in the DHCP server's configuration to select options\n"
 "(e.g. bootfile or server) which are valid for barebox clients only.\n");
 BAREBOX_CMD_HELP_END
 
@@ -553,6 +578,7 @@ 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(dhcp_client_id, "cliend id to send to the DHCP server");
 BAREBOX_MAGICVAR(tftp_server_name, "TFTP server Name returned from DHCP request");
 BAREBOX_MAGICVAR(tftp_server_ip, "TFTP server IP returned from DHCP request");
 BAREBOX_MAGICVAR(etherboot_file, "Etherboot File returned from DHCP request");
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 5/8] net: dhcp: allow to set transmitted client uuid
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 preceding siblings ...)
  2012-03-30  4:31 ` [PATCH 4/8] net: dhcp: allow to set transmitted client id Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 6/8] net: dhcp: allow to set transmitted user class Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

For net boot setups it is useful to submit boot params like server or
bootfile over dhcp. To distinguish diffrent type of OS running on the same hardware,
a custom vendor id can be sent in dhcp discover/request messages.

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

 | option client-uuid code 97 = { unsigned integer 8, string };
 | class "at91sam9x5ek" {
 |         match if substring (option vendor-class-identifier,0,20) = "barebox-at91sam9x5ek";
 |
 |         filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage";
 |         if substring (option dhcp-client-identifier,0,7) = "ser2net" {
 |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
 |         }
 |         if substring (option client-uuid,0,7) = "test" {
 |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
 |         }
 |         option tftp-server-name "192.168.200.98";
 |         option option-150 192.168.200.98;
 |         next-server 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@jcrosoft.com>
---
 net/dhcp.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index 8945587..ae4bdd0 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -77,6 +77,7 @@ static IPaddr_t net_dhcp_server_ip;
 static uint64_t dhcp_start;
 static char *client_id;
 static char *vendor_id;
+static char *client_uuid;
 
 static int bootp_check_packet(unsigned char *pkt, unsigned src, unsigned len)
 {
@@ -192,6 +193,7 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
 
 	 e += dhcp_set_string_options(e, 60, vendor_id);
 	 e += dhcp_set_string_options(e, 61, client_id);
+	 e += dhcp_set_string_options(e, 97, client_uuid);
 
 	*e++ = 55;		/* Parameter Request List */
 	 cnt = e++;		/* Pointer to count of requested items */
@@ -491,6 +493,7 @@ static int do_dhcp(int argc, char *argv[])
 	int ret, opt;
 	vendor_id = (char*)getenv("dhcp_vendor_id");
 	client_id = (char*)getenv("dhcp_client_id");
+	client_uuid = (char*)getenv("dhcp_client_uuid");
 
 	setenv("bootfile","");
 	setenv("nameserver","");
@@ -501,7 +504,7 @@ static int do_dhcp(int argc, char *argv[])
 	setenv("tftp_server_ip","");
 	setenv("etherboot_file","");
 
-	while((opt = getopt(argc, argv, "v:c:")) > 0) {
+	while((opt = getopt(argc, argv, "v:c:u:")) > 0) {
 		switch(opt) {
 		case 'v':
 			vendor_id = optarg;
@@ -509,11 +512,15 @@ static int do_dhcp(int argc, char *argv[])
 		case 'c':
 			client_id = optarg;
 			break;
+		case 'u':
+			client_uuid = optarg;
+			break;
 		}
 	}
 
 	pr_debug("vendor_id: '%s'\n", vendor_id);
 	pr_debug("client_id: '%s'\n", client_id);
+	pr_debug("client_uuid: '%s'\n", client_uuid);
 
 	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
 	if (IS_ERR(dhcp_con)) {
@@ -563,6 +570,10 @@ BAREBOX_CMD_HELP_OPT  ("-v <vendor_id>",
 BAREBOX_CMD_HELP_OPT  ("-c <client_id>",
 "DHCP Client ID (code 61) submitted in DHCP requests. It can\n"
 "be used in the DHCP server's configuration to select options\n"
+"(e.g. bootfile or server) which are valid for barebox clients only.\n")
+BAREBOX_CMD_HELP_OPT  ("-u <client_uuid>",
+"DHCP Client UUID (code 97) submitted in DHCP requests. It can\n"
+"be used in the DHCP server's configuration to select options\n"
 "(e.g. bootfile or server) which are valid for barebox clients only.\n");
 BAREBOX_CMD_HELP_END
 
@@ -578,6 +589,7 @@ 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(dhcp_client_uuid, "cliend uuid to send to the DHCP server");
 BAREBOX_MAGICVAR(dhcp_client_id, "cliend id to send to the DHCP server");
 BAREBOX_MAGICVAR(tftp_server_name, "TFTP server Name returned from DHCP request");
 BAREBOX_MAGICVAR(tftp_server_ip, "TFTP server IP returned from DHCP request");
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 6/8] net: dhcp: allow to set transmitted user class
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 preceding siblings ...)
  2012-03-30  4:31 ` [PATCH 5/8] net: dhcp: allow to set transmitted client uuid Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  4:31 ` [PATCH 7/8] net: dns: export resolved ip to var resolved_ip Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

For net boot setups it is useful to submit boot params like server or
bootfile over dhcp. To distinguish diffrent type of OS running on the same hardware,
a custom vendor id can be sent in dhcp discover/request messages.

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

 | option client-uuid code 97 = { unsigned integer 8, string };
 | class "at91sam9x5ek" {
 |         match if substring (option vendor-class-identifier,0,20) = "barebox-at91sam9x5ek";
 |
 |         filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage";
 |         if substring (option dhcp-client-identifier,0,7) = "ser2net" {
 |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
 |         }
 |         if substring (option client-uuid,0,7) = "test" {
 |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
 |         }
 |         if substring (option user-class,0,4) = "toto" {
 |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-toto";
 |         }
 |         option tftp-server-name "192.168.200.98";
 |         option option-150 192.168.200.98;
 |         next-server 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@jcrosoft.com>
---
 net/dhcp.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index ae4bdd0..4c3b9a3 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -78,6 +78,7 @@ static uint64_t dhcp_start;
 static char *client_id;
 static char *vendor_id;
 static char *client_uuid;
+static char *user_class;
 
 static int bootp_check_packet(unsigned char *pkt, unsigned src, unsigned len)
 {
@@ -193,6 +194,7 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
 
 	 e += dhcp_set_string_options(e, 60, vendor_id);
 	 e += dhcp_set_string_options(e, 61, client_id);
+	 e += dhcp_set_string_options(e, 77, user_class);
 	 e += dhcp_set_string_options(e, 97, client_uuid);
 
 	*e++ = 55;		/* Parameter Request List */
@@ -494,6 +496,7 @@ static int do_dhcp(int argc, char *argv[])
 	vendor_id = (char*)getenv("dhcp_vendor_id");
 	client_id = (char*)getenv("dhcp_client_id");
 	client_uuid = (char*)getenv("dhcp_client_uuid");
+	user_class = (char*)getenv("dhcp_user_class");
 
 	setenv("bootfile","");
 	setenv("nameserver","");
@@ -504,7 +507,7 @@ static int do_dhcp(int argc, char *argv[])
 	setenv("tftp_server_ip","");
 	setenv("etherboot_file","");
 
-	while((opt = getopt(argc, argv, "v:c:u:")) > 0) {
+	while((opt = getopt(argc, argv, "v:c:u:U:")) > 0) {
 		switch(opt) {
 		case 'v':
 			vendor_id = optarg;
@@ -515,12 +518,16 @@ static int do_dhcp(int argc, char *argv[])
 		case 'u':
 			client_uuid = optarg;
 			break;
+		case 'U':
+			user_class = optarg;
+			break;
 		}
 	}
 
 	pr_debug("vendor_id: '%s'\n", vendor_id);
 	pr_debug("client_id: '%s'\n", client_id);
 	pr_debug("client_uuid: '%s'\n", client_uuid);
+	pr_debug("user_class: '%s'\n", user_class);
 
 	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
 	if (IS_ERR(dhcp_con)) {
@@ -574,6 +581,10 @@ BAREBOX_CMD_HELP_OPT  ("-c <client_id>",
 BAREBOX_CMD_HELP_OPT  ("-u <client_uuid>",
 "DHCP Client UUID (code 97) submitted in DHCP requests. It can\n"
 "be used in the DHCP server's configuration to select options\n"
+"(e.g. bootfile or server) which are valid for barebox clients only.\n")
+BAREBOX_CMD_HELP_OPT  ("-U <user_class>",
+"DHCP User class (code 77) submitted in DHCP requests. It can\n"
+"be used in the DHCP server's configuration to select options\n"
 "(e.g. bootfile or server) which are valid for barebox clients only.\n");
 BAREBOX_CMD_HELP_END
 
@@ -591,6 +602,7 @@ BAREBOX_MAGICVAR(rootpath, "rootpath returned from DHCP request");
 BAREBOX_MAGICVAR(dhcp_vendor_id, "vendor id to send to the DHCP server");
 BAREBOX_MAGICVAR(dhcp_client_uuid, "cliend uuid to send to the DHCP server");
 BAREBOX_MAGICVAR(dhcp_client_id, "cliend id to send to the DHCP server");
+BAREBOX_MAGICVAR(dhcp_user_class, "user class to send to the DHCP server");
 BAREBOX_MAGICVAR(tftp_server_name, "TFTP server Name returned from DHCP request");
 BAREBOX_MAGICVAR(tftp_server_ip, "TFTP server IP returned from DHCP request");
 BAREBOX_MAGICVAR(etherboot_file, "Etherboot File returned from DHCP request");
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 7/8] net: dns: export resolved ip to var resolved_ip
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 preceding siblings ...)
  2012-03-30  4:31 ` [PATCH 6/8] net: dhcp: allow to set transmitted user class Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30  9:12   ` Sascha Hauer
  2012-03-30  4:31 ` [PATCH 8/8] defaultenv: add support of etherboot_file Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

This will allow to use it in scripting.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 net/dns.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/net/dns.c b/net/dns.c
index 3c7aa5f..50d953b 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -27,6 +27,7 @@
 #include <net.h>
 #include <clock.h>
 #include <environment.h>
+#include <magicvar.h>
 #include <linux/err.h>
 
 #define DNS_PORT 53
@@ -238,6 +239,8 @@ static int do_host(int argc, char *argv[])
 {
 	IPaddr_t ip;
 
+	setenv("resolved_ip", "");
+
 	if (argc != 2)
 		return COMMAND_ERROR_USAGE;
 
@@ -248,6 +251,7 @@ static int do_host(int argc, char *argv[])
 		printf("%s is at ", argv[1]);
 		print_IPaddr(ip);
 		printf("\n");
+		setenv_ip("resolved_ip", ip);
 	}
 
 	return 0;
@@ -262,3 +266,4 @@ BAREBOX_CMD_START(host)
 	BAREBOX_CMD_HELP(cmd_host_help)
 BAREBOX_CMD_END
 
+BAREBOX_MAGICVAR(resolved_ip, "Resolved IP");
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 8/8] defaultenv: add support of etherboot_file
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 preceding siblings ...)
  2012-03-30  4:31 ` [PATCH 7/8] net: dns: export resolved ip to var resolved_ip Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  4:31 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-03-30 10:39 ` [PATCH 7/8 v2] net: env: getenv_ip use resolv Jean-Christophe PLAGNIOL-VILLARD
  2012-04-02 11:17 ` [PATCH 0/8] Network update DHCP/BOOTP Sascha Hauer
  9 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30  4:31 UTC (permalink / raw)
  To: barebox

We will use the etherboot_file as script

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 defaultenv/bin/boot |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/defaultenv/bin/boot b/defaultenv/bin/boot
index ba04373..2c09a23 100644
--- a/defaultenv/bin/boot
+++ b/defaultenv/bin/boot
@@ -48,6 +48,10 @@ if [ x$ip = xdhcp -o x$ip = "xdhcp-barebox" ]; then
 		if [ x$bootfile != x ]; then
 			kernelimage=$bootfile
 		fi
+		if [ x$etherboot_file != x ]; then
+			$kernel_loc $etherboot_file /etherboot_file.sh || exit 1
+			. /etherboot_file.sh || exit 1
+		fi
 	fi
 fi
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 7/8] net: dns: export resolved ip to var resolved_ip
  2012-03-30  4:31 ` [PATCH 7/8] net: dns: export resolved ip to var resolved_ip Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  9:12   ` Sascha Hauer
  2012-03-30 10:16     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 17+ messages in thread
From: Sascha Hauer @ 2012-03-30  9:12 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Mar 30, 2012 at 06:31:52AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> This will allow to use it in scripting.
> 
>  {
>  	IPaddr_t ip;
>  
> +	setenv("resolved_ip", "");
> +
>  	if (argc != 2)
>  		return COMMAND_ERROR_USAGE;
>  
> @@ -248,6 +251,7 @@ static int do_host(int argc, char *argv[])
>  		printf("%s is at ", argv[1]);
>  		print_IPaddr(ip);
>  		printf("\n");
> +		setenv_ip("resolved_ip", ip);

I smell complex environment scripts here. Maybe we should rather
integrate dns into getenv_ip. This will help all commands using ip
addresses instead of putting the burden of resolving a host name into
the environment.

Sascha

>  	}
>  
>  	return 0;
> @@ -262,3 +266,4 @@ BAREBOX_CMD_START(host)
>  	BAREBOX_CMD_HELP(cmd_host_help)
>  BAREBOX_CMD_END
>  
> +BAREBOX_MAGICVAR(resolved_ip, "Resolved IP");
> -- 
> 1.7.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)
  2012-03-30  4:31 ` [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150) Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30  9:21   ` Sascha Hauer
  2012-03-30 10:14     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 17+ messages in thread
From: Sascha Hauer @ 2012-03-30  9:21 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Mar 30, 2012 at 06:31:48AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> if tftp server ip
> 	Use the tftp server name only if this option is not set.
> 	Export it also via env tftp_server_ip.
> else
> 	Export it via end etherboot_file
> 
> E.g. the ISC dhcp server can be configured with
> 
>   | option option-150 code 150 = ip-address;
>   | option option-150-etherboot-file code 150 = string;
>   |
>   | 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 option-150 192.168.200.98;
>   |         next-server 192.168.200.98;
>   |         option root-path "192.168.200.98:/opt/work/buildroot/build/sam9x5/target";
>   |         if substring (option dhcp-client-identifier,0,7) = "ser2net" {
>   |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
>   |                 ption option-150-etherboot-file "/tftpboot/test.sh";
>   |         }
>   | }
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  net/dhcp.c |   21 ++++++++++++++++++++-
>  1 files changed, 20 insertions(+), 1 deletions(-)
> 
> diff --git a/net/dhcp.c b/net/dhcp.c
> index 6728717..adfb4a0 100644
> --- a/net/dhcp.c
> +++ b/net/dhcp.c
> @@ -195,6 +195,8 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
>  	*cnt += 1;
>  	*e++  = 66;		/* TFTP server name */
>  	*cnt += 1;
> +	*e++  = 150;		/* TFTP server ip */
> +	*cnt += 1;
>  	*e++  = 255;		/* End of the list */
>  
>  	/* Pad to minimal length */
> @@ -255,6 +257,7 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
>  	IPaddr_t ip;
>  	char str[256];
>  	char tftpname[256];
> +	bool is_tftpserverip = false;
>  
>  	while (popt < end && *popt != 0xff) {
>  		oplen = *(popt + 1);
> @@ -327,6 +330,18 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
>  					setenv("bootfile", str);
>  			}
>  			break;
> +		case 150:	/* TFTP server ip or Etherboot*/
> +			if (oplen == sizeof(IPaddr_t)) {
> +				is_tftpserverip = true;
> +				ip = net_read_ip(popt + 2);
> +				net_set_serverip(ip);
> +				setenv_ip("tftp_server_ip", ip);
> +			} else {
> +				memcpy(str, popt + 2, oplen);
> +				str[oplen] = 0;
> +				setenv("etherboot_file", str);
> +			}

This seems fragile. What if the etherboot filename has a length of 4?

Sascha

> +			break;
>  		default:
>  #ifdef CONFIG_BOOTP_VENDOREX
>  			if (dhcp_vendorex_proc (popt))
> @@ -338,7 +353,7 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
>  		popt += oplen + 2;	/* Process next option */
>  	}
>  
> -	if (tftpname[0] != 0)
> +	if (!is_tftpserverip && tftpname[0] != 0)
>  		net_set_serverip(resolv(tftpname));
>  }
>  
> @@ -468,6 +483,8 @@ static int do_dhcp(int argc, char *argv[])
>  	setenv("domainname","");
>  	setenv("rootpath","");
>  	setenv("tftp_server_name","");
> +	setenv("tftp_server_ip","");
> +	setenv("etherboot_file","");
>  
>  	while((opt = getopt(argc, argv, "v:")) > 0) {
>  		switch(opt) {
> @@ -537,3 +554,5 @@ 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");
> +BAREBOX_MAGICVAR(tftp_server_ip, "TFTP server IP returned from DHCP request");
> +BAREBOX_MAGICVAR(etherboot_file, "Etherboot File returned from DHCP request");
> -- 
> 1.7.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)
  2012-03-30  9:21   ` Sascha Hauer
@ 2012-03-30 10:14     ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-02 10:49       ` Sascha Hauer
  0 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30 10:14 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 11:21 Fri 30 Mar     , Sascha Hauer wrote:
> On Fri, Mar 30, 2012 at 06:31:48AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > if tftp server ip
> > 	Use the tftp server name only if this option is not set.
> > 	Export it also via env tftp_server_ip.
> > else
> > 	Export it via end etherboot_file
> > 
> > E.g. the ISC dhcp server can be configured with
> > 
> >   | option option-150 code 150 = ip-address;
> >   | option option-150-etherboot-file code 150 = string;
> >   |
> >   | 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 option-150 192.168.200.98;
> >   |         next-server 192.168.200.98;
> >   |         option root-path "192.168.200.98:/opt/work/buildroot/build/sam9x5/target";
> >   |         if substring (option dhcp-client-identifier,0,7) = "ser2net" {
> >   |                 filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage-ser2net";
> >   |                 ption option-150-etherboot-file "/tftpboot/test.sh";
> >   |         }
> >   | }
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> >  net/dhcp.c |   21 ++++++++++++++++++++-
> >  1 files changed, 20 insertions(+), 1 deletions(-)
> > 
> > diff --git a/net/dhcp.c b/net/dhcp.c
> > index 6728717..adfb4a0 100644
> > --- a/net/dhcp.c
> > +++ b/net/dhcp.c
> > @@ -195,6 +195,8 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
> >  	*cnt += 1;
> >  	*e++  = 66;		/* TFTP server name */
> >  	*cnt += 1;
> > +	*e++  = 150;		/* TFTP server ip */
> > +	*cnt += 1;
> >  	*e++  = 255;		/* End of the list */
> >  
> >  	/* Pad to minimal length */
> > @@ -255,6 +257,7 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
> >  	IPaddr_t ip;
> >  	char str[256];
> >  	char tftpname[256];
> > +	bool is_tftpserverip = false;
> >  
> >  	while (popt < end && *popt != 0xff) {
> >  		oplen = *(popt + 1);
> > @@ -327,6 +330,18 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
> >  					setenv("bootfile", str);
> >  			}
> >  			break;
> > +		case 150:	/* TFTP server ip or Etherboot*/
> > +			if (oplen == sizeof(IPaddr_t)) {
> > +				is_tftpserverip = true;
> > +				ip = net_read_ip(popt + 2);
> > +				net_set_serverip(ip);
> > +				setenv_ip("tftp_server_ip", ip);
> > +			} else {
> > +				memcpy(str, popt + 2, oplen);
> > +				str[oplen] = 0;
> > +				setenv("etherboot_file", str);
> > +			}
> 
> This seems fragile. What if the etherboot filename has a length of 4?
agree but this is really unlikely and I did want to add an option in the
client to ask a file name

And we can not detect it via the DHCP RFC

btw IPaddr_t need to be fix on 64bit

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 7/8] net: dns: export resolved ip to var resolved_ip
  2012-03-30  9:12   ` Sascha Hauer
@ 2012-03-30 10:16     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30 10:16 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 11:12 Fri 30 Mar     , Sascha Hauer wrote:
> On Fri, Mar 30, 2012 at 06:31:52AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > This will allow to use it in scripting.
> > 
> >  {
> >  	IPaddr_t ip;
> >  
> > +	setenv("resolved_ip", "");
> > +
> >  	if (argc != 2)
> >  		return COMMAND_ERROR_USAGE;
> >  
> > @@ -248,6 +251,7 @@ static int do_host(int argc, char *argv[])
> >  		printf("%s is at ", argv[1]);
> >  		print_IPaddr(ip);
> >  		printf("\n");
> > +		setenv_ip("resolved_ip", ip);
> 
> I smell complex environment scripts here. Maybe we should rather
> integrate dns into getenv_ip. This will help all commands using ip
> addresses instead of putting the burden of resolving a host name into
> the environment.

yeah didn't think about it

not really complex sript but bootp with tftp server with name instead of IP

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 7/8 v2] net: env: getenv_ip use resolv
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 preceding siblings ...)
  2012-03-30  4:31 ` [PATCH 8/8] defaultenv: add support of etherboot_file Jean-Christophe PLAGNIOL-VILLARD
@ 2012-03-30 10:39 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-02 11:17 ` [PATCH 0/8] Network update DHCP/BOOTP Sascha Hauer
  9 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-03-30 10:39 UTC (permalink / raw)
  To: barebox

Introduce getenv_ip_dns to be able to do not do the resolv when using it in
resolv for the nameserver (Do not loop).

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
v2:

	replace PATCH 7/8] net: dns: export resolved ip to var resolved_ip

	update git

The following changes since commit 485cee59cf64b5019c5a294074007b93509b83e0:

  Merge branch 'work/imx51-babbage-clk' into next (2012-03-23 21:22:14 +0100)

are available in the git repository at:


  git://git.jcrosoft.org/barebox.git net

for you to fetch changes up to 561566cab8df8a5146590a0bd9186fbf7aa05a7c:

  defaultenv: add support of etherboot_file (2012-03-30 18:50:30 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (8):
      net: dhcp: reset env variable before do a dhcp request
      net: dhcp: add support of tftp name server
      net: dhcp: add support of tftp server ip or Etherboot file (option 150)
      net: dhcp: allow to set transmitted client id
      net: dhcp: allow to set transmitted client uuid
      net: dhcp: allow to set transmitted user class
      net: env: getenv_ip use resolv
      defaultenv: add support of etherboot_file

 defaultenv/bin/boot |    4 ++
 include/net.h       |    6 ++-
 net/dhcp.c          |  118 ++++++++++++++++++++++++++++++++++++++++++++-------
 net/dns.c           |    2 +-
 net/net.c           |    9 +++-
 5 files changed, 118 insertions(+), 21 deletions(-)
Best Regards,
J.

 include/net.h |    6 +++++-
 net/dns.c     |    2 +-
 net/net.c     |    9 ++++++---
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/include/net.h b/include/net.h
index 2eec47f..0ebe198 100644
--- a/include/net.h
+++ b/include/net.h
@@ -277,7 +277,11 @@ char *ip_to_string (IPaddr_t x, char *s);
 /* Convert a string to ip address */
 int string_to_ip(const char *s, IPaddr_t *ip);
 
-IPaddr_t getenv_ip(const char *name);
+IPaddr_t getenv_ip_dns(const char *name, int dns);
+static inline IPaddr_t getenv_ip(const char *name)
+{
+	return getenv_ip_dns(name, 0);
+}
 int setenv_ip(const char *name, IPaddr_t ip);
 
 int string_to_ethaddr(const char *str, char *enetaddr);
diff --git a/net/dns.c b/net/dns.c
index 3c7aa5f..fb1178a 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -205,7 +205,7 @@ IPaddr_t resolv(char *host)
 
 	dns_state = STATE_INIT;
 
-	ip = getenv_ip("nameserver");
+	ip = getenv_ip_dns("nameserver", 0);
 	if (!ip)
 		return 0;
 
diff --git a/net/net.c b/net/net.c
index 2752884..39db75e 100644
--- a/net/net.c
+++ b/net/net.c
@@ -127,7 +127,7 @@ int string_to_ip(const char *s, IPaddr_t *ip)
 	return 0;
 }
 
-IPaddr_t getenv_ip(const char *name)
+IPaddr_t getenv_ip_dns(const char *name, int dns)
 {
 	IPaddr_t ip;
 	const char *var = getenv(name);
@@ -135,10 +135,13 @@ IPaddr_t getenv_ip(const char *name)
 	if (!var)
 		return 0;
 
-	if (string_to_ip(var, &ip))
+	if (!string_to_ip(var, &ip))
+		return ip;
+
+	if (!dns)
 		return 0;
 
-	return ip;
+	return resolv((char*)var);
 }
 
 int setenv_ip(const char *name, IPaddr_t ip)
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)
  2012-03-30 10:14     ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-02 10:49       ` Sascha Hauer
  2012-04-02 11:18         ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 17+ messages in thread
From: Sascha Hauer @ 2012-04-02 10:49 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Mar 30, 2012 at 12:14:32PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 11:21 Fri 30 Mar     , Sascha Hauer wrote:
> > >  					setenv("bootfile", str);
> > >  			}
> > >  			break;
> > > +		case 150:	/* TFTP server ip or Etherboot*/
> > > +			if (oplen == sizeof(IPaddr_t)) {
> > > +				is_tftpserverip = true;
> > > +				ip = net_read_ip(popt + 2);
> > > +				net_set_serverip(ip);
> > > +				setenv_ip("tftp_server_ip", ip);
> > > +			} else {
> > > +				memcpy(str, popt + 2, oplen);
> > > +				str[oplen] = 0;
> > > +				setenv("etherboot_file", str);
> > > +			}
> > 
> > This seems fragile. What if the etherboot filename has a length of 4?
> agree but this is really unlikely and I did want to add an option in the
> client to ask a file name
> 
> And we can not detect it via the DHCP RFC

For tftp server ip it's not one server ip but a list of server ips, so
the check for sizeof(IPaddr_t) is not even correct, you must check for
multiple of sizeof(IPaddr_t) which makes the above code even more
fragile. No way to accept this.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/8] Network update DHCP/BOOTP
  2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 preceding siblings ...)
  2012-03-30 10:39 ` [PATCH 7/8 v2] net: env: getenv_ip use resolv Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-02 11:17 ` Sascha Hauer
  9 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-04-02 11:17 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Mar 30, 2012 at 06:27:13AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> HI,
> 
> 	the following patch series update the network dhcp and bootp support
> 	to support options 66, 150, 61, 77, 97
> 
> 	this will also help to add pxe boot support later
> 
> The following changes since commit 485cee59cf64b5019c5a294074007b93509b83e0:
> 
>   Merge branch 'work/imx51-babbage-clk' into next (2012-03-23 21:22:14 +0100)
> 
> are available in the git repository at:
> 
> 
>   git://git.jcrosoft.org/barebox.git net
> 
> for you to fetch changes up to 2e991cac2e1444def3d27ec06fd10724fe3e19ba:
> 
>   defaultenv: add support of etherboot_file (2012-03-30 12:40:18 +0800)
> 
> ----------------------------------------------------------------
> Jean-Christophe PLAGNIOL-VILLARD (8):
>       net: dhcp: reset env variable before do a dhcp request
>       net: dhcp: add support of tftp name server
>       net: dhcp: add support of tftp server ip or Etherboot file (option 150)
>       net: dhcp: allow to set transmitted client id
>       net: dhcp: allow to set transmitted client uuid
>       net: dhcp: allow to set transmitted user class
>       net: dns: export resolved ip to var resolved_ip
>       defaultenv: add support of etherboot_file

Given the current poor state of net/dhcp.c I'm not very willing to
accept feature patches to this. I think what we need is a struct
dhcp_opt:

struct dhcp_opt {
	unsigned char option;
	const char *barebox_var_name;
#define DHCP_OPT_IP		1
#define DHCP_OPT_STRING		2
	unsigned long flags;
};

With this we could loop around all opts and
- unset existing environment variables before a dhcp request
- construct the request packet
- parse response

Also nice to have are defines for the different dhcp options and a
consistent dhcp_ prefix for all environment variables modified by the
dhcp command.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)
  2012-04-02 10:49       ` Sascha Hauer
@ 2012-04-02 11:18         ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-02 11:18 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 12:49 Mon 02 Apr     , Sascha Hauer wrote:
> On Fri, Mar 30, 2012 at 12:14:32PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 11:21 Fri 30 Mar     , Sascha Hauer wrote:
> > > >  					setenv("bootfile", str);
> > > >  			}
> > > >  			break;
> > > > +		case 150:	/* TFTP server ip or Etherboot*/
> > > > +			if (oplen == sizeof(IPaddr_t)) {
> > > > +				is_tftpserverip = true;
> > > > +				ip = net_read_ip(popt + 2);
> > > > +				net_set_serverip(ip);
> > > > +				setenv_ip("tftp_server_ip", ip);
> > > > +			} else {
> > > > +				memcpy(str, popt + 2, oplen);
> > > > +				str[oplen] = 0;
> > > > +				setenv("etherboot_file", str);
> > > > +			}
> > > 
> > > This seems fragile. What if the etherboot filename has a length of 4?
> > agree but this is really unlikely and I did want to add an option in the
> > client to ask a file name
> > 
> > And we can not detect it via the DHCP RFC
> 
> For tftp server ip it's not one server ip but a list of server ips, so
> the check for sizeof(IPaddr_t) is not even correct, you must check for
> multiple of sizeof(IPaddr_t) which makes the above code even more
> fragile. No way to accept this.
yeah because option 150 is use by etherboot when they do not respect the RFC
and nearly no dhcp server send more than one server ip via options 150

Best Regards,
J.

> 
> Sascha
> 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-04-02 11:34 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-30  4:27 [PATCH 0/8] Network update DHCP/BOOTP Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 1/8] net: dhcp: reset env variable before do a dhcp request Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 2/8] net: dhcp: add support of tftp name server Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150) Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  9:21   ` Sascha Hauer
2012-03-30 10:14     ` Jean-Christophe PLAGNIOL-VILLARD
2012-04-02 10:49       ` Sascha Hauer
2012-04-02 11:18         ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 4/8] net: dhcp: allow to set transmitted client id Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 5/8] net: dhcp: allow to set transmitted client uuid Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 6/8] net: dhcp: allow to set transmitted user class Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 7/8] net: dns: export resolved ip to var resolved_ip Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  9:12   ` Sascha Hauer
2012-03-30 10:16     ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-30  4:31 ` [PATCH 8/8] defaultenv: add support of etherboot_file Jean-Christophe PLAGNIOL-VILLARD
2012-03-30 10:39 ` [PATCH 7/8 v2] net: env: getenv_ip use resolv Jean-Christophe PLAGNIOL-VILLARD
2012-04-02 11:17 ` [PATCH 0/8] Network update DHCP/BOOTP Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox