Skip to contentSkip to conversation

Network update DHCP/BOOTP

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 17 messages Mar 30, 2012 – Apr 2, 2012 Networking

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Network update DHCP/BOOTP

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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/8 net: dhcp: reset env variable before do a dhcp request

---
 net/dhcp.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
net/dhcp.c +6 -0
index 53eed6c..1ba4def 100644
@@ -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':
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

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

In reply to Jean-Christophe PLAGNIOL-VILLARD

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";
   |         }
   | }
---
 net/dhcp.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
net/dhcp.c +12 -1
index 1ba4def..6728717 100644
@@ -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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/8 net: dhcp: add support of tftp server ip or Etherboot file (option 150)

In reply to Jean-Christophe PLAGNIOL-VILLARD

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";
  |         }
  | }
---
 net/dhcp.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
net/dhcp.c +20 -1
index 6728717..adfb4a0 100644
@@ -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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)

Quoted 56 lines · Jean-Christophe PLAGNIOL-VILLARD

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";
  |         }
  | }
---
 net/dhcp.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
net/dhcp.c +4 -0
index 6728717..adfb4a0 100644
@@ -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*/

net/dhcp.c static void dhcp_options_process(unsigned char *popt, struct bootp *bp) · line 343

Quoted 10 lines
net/dhcp.c +10 -0
+			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

Quoted 37 lines
net/dhcp.c +6 -1
+			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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)

Quoted 61 lines · Sascha Hauer
Quoted 60 lines · Jean-Christophe PLAGNIOL-VILLARD

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";
  |         }
  | }
---
 net/dhcp.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
net/dhcp.c +8 -0
index 6728717..adfb4a0 100644
@@ -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);
Quoted 8 lines

net/dhcp.c static void dhcp_options_process(unsigned char *popt, struct bootp *bp) · line 343

Quoted 6 lines
net/dhcp.c +6 -0
+				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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw

Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)

Quoted 17 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 8 lines · Sascha Hauer
Quoted 8 lines
net/dhcp.c +5 -0
 					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);
Quoted 8 lines

net/dhcp.c static void dhcp_options_process(unsigned char *popt, struct bootp *bp) · line 343

Quoted 6 lines
net/dhcp.c +6 -0
+				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?

Quoted 4 lines

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

Re: [PATCH 3/8] net: dhcp: add support of tftp server ip or Etherboot file (option 150)

Quoted 21 lines · Sascha Hauer
Quoted 20 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 8 lines · Sascha Hauer
Quoted 8 lines
net/dhcp.c +5 -0
 					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);
Quoted 8 lines

net/dhcp.c static void dhcp_options_process(unsigned char *popt, struct bootp *bp) · line 343

Quoted 6 lines
net/dhcp.c +6 -0
+				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

Quoted 6 lines
Quoted 1 line

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.

Quoted 9 lines

Sascha

Signature · 4 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw

PATCH 4/8 net: dhcp: allow to set transmitted client id

In reply to Jean-Christophe PLAGNIOL-VILLARD

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";
 | }
---
 net/dhcp.c |   54 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 40 insertions(+), 14 deletions(-)
net/dhcp.c +40 -14
index adfb4a0..8945587 100644
@@ -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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 5/8 net: dhcp: allow to set transmitted client uuid

In reply to Jean-Christophe PLAGNIOL-VILLARD

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";
 | }
---
 net/dhcp.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
net/dhcp.c +13 -1
index 8945587..ae4bdd0 100644
@@ -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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 6/8 net: dhcp: allow to set transmitted user class

In reply to Jean-Christophe PLAGNIOL-VILLARD

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";
 | }
---
 net/dhcp.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
net/dhcp.c +13 -1
index ae4bdd0..4c3b9a3 100644
@@ -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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

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

In reply to Jean-Christophe PLAGNIOL-VILLARD

This will allow to use it in scripting.

---
 net/dns.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
net/dns.c +5 -0
index 3c7aa5f..50d953b 100644
@@ -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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

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

Quoted 11 lines · Jean-Christophe PLAGNIOL-VILLARD

This will allow to use it in scripting.

{

net/dns.c +2 -0
 	IPaddr_t ip;
 
+	setenv("resolved_ip", "");
+
 	if (argc != 2)
 		return COMMAND_ERROR_USAGE;

net/dns.c static int do_host(int argc, char *argv[]) · line 254

Quoted 4 lines
net/dns.c +1 -0
@@ -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

Quoted 17 lines
net/dns.c +1 -0
 	}
 
 	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");
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

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

Quoted 11 lines · Sascha Hauer
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD

This will allow to use it in scripting.

{

net/dns.c +2 -0
 	IPaddr_t ip;
 
+	setenv("resolved_ip", "");
+
 	if (argc != 2)
 		return COMMAND_ERROR_USAGE;
Quoted 10 lines

net/dns.c static int do_host(int argc, char *argv[]) · line 254

Quoted 5 lines
net/dns.c +1 -0
@@ -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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#14 lore raw

PATCH 8/8 defaultenv: add support of etherboot_file

In reply to Jean-Christophe PLAGNIOL-VILLARD

We will use the etherboot_file as script

---
 defaultenv/bin/boot |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
defaultenv/bin/boot +4 -0
index ba04373..2c09a23 100644
@@ -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
 
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#15 lore raw

PATCH v2 7/8 net: env: getenv_ip use resolv

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

---
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(-)
include/net.h +5 -1
index 2eec47f..0ebe198 100644
@@ -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);
net/dns.c +1 -1
index 3c7aa5f..fb1178a 100644
@@ -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;
 
net/net.c +6 -3
index 2752884..39db75e 100644
@@ -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)
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 20 lines · Jean-Christophe PLAGNIOL-VILLARD

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)

Quoted 10 lines

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox