- add dns
Subsystems (2)
PATCH 1/1 - add dns
On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg10216.html
Quoted 6 lines
DNS can be enabled by setting
CFG_CMD_DNS. After performing a query, the serverip environment var is updated.Probably there are some cosmetic issues with the patch. Unfortunatly I do not have the time to correct these. So if anybody else likes DNS support in U-Boot and has the time, feel free to patch it in the main tree.
Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for timeout)
- use built in functions (memcpy) rather than byte copy.
bfin> dhcp
BOOTP broadcast 1
DHCP client bound to address 192.168.0.4
bfin> dns pool.ntp.org
69.36.241.112
bfin> sntp $(serverip)
Date: 2009-07-17 Time: 19:16:51
bfin> dns www.google.com
64.233.161.147
bfin> ping $(serverip)
Using Blackfin EMAC device
host 64.233.161.147 is alive
common/cmd_net.c | 32 ++++ include/configs/bfin_adi_common.h | 7 include/net.h | 4 net/Makefile | 1 net/dns.c | 213 ++++++++++++++++++++++++++++ net/dns.h | 38 ++++ net/net.c | 20 ++ 7 files changed, 314 insertions(+), 1 deletion(-)
---
net.h +4 -0
@@ -361,6 +361,10 @@/* from net/net.c */ extern char BootFile[128 ];/* Boot File name */ +#if defined(CONFIG_CMD_DNS ) +extern char NetDNSResolve[255 ];/* The host to resolve */ +#endif +#if defined(CONFIG_CMD_PING )extern IPaddr_t NetPingIP;/* the ip address to ping */ #endif
configs/bfin_adi_common.h +7 -0
@@ -13,6 +13,13 @@# if ADI_CMDS_NETWORK # define CONFIG_CMD_DHCP # define CONFIG_CMD_PING +# define CONFIG_BOOTP_DNS +# define CONFIG_BOOTP_DNS2 +# define CONFIG_CMD_DNS +# ifdef CONFIG_RTC_BFIN +# define CONFIG_CMD_SNTP +# define CONFIG_BOOTP_NTPSERVER +# endif # ifdef CONFIG_BFIN_MAC # define CONFIG_CMD_MII # endif
dns.c +213 -0
213 lines not on this page · raw message
net.c +19 -1
@@ -92,6 +92,9 @@#if defined(CONFIG_CDP_VERSION )#include <timestamp.h> #endif +#if defined(CONFIG_CMD_DNS ) +#include "dns.h" +#endif #if defined(CONFIG_CMD_NET )
@@ -165,7 +168,6 @@ushort NetOurNativeVLAN =0xFFFF ;/* ditto */ char BootFile[128 ];/* Boot File name */ -#if defined(CONFIG_CMD_PING )IPaddr_t NetPingIP;/* the ip address to ping */
@@ -291,6 +293,9 @@ NetServerIP =getenv_IPaddr ("serverip" ); NetOurNativeVLAN =getenv_VLAN ("nvlan" ); NetOurVLAN =getenv_VLAN ("vlan" ); +#if defined(CONFIG_CMD_DNS ) + NetOurDNSIP =getenv_IPaddr ("dnsip" ); +#endif env_changed_id = env_id; }
@@ -426,6 +432,11 @@SntpStart ();break ;#endif +#if defined(CONFIG_CMD_DNS ) +case DNS : +DnsStart (); +break ; +#endif default :break ; }
@@ -1518,6 +1529,14 @@ } goto common;#endif +#if defined(CONFIG_CMD_DNS ) +case DNS : +if (NetOurDNSIP ==0 ) { +puts ("*** ERROR: DNS server address not given\n" ); +return 1 ; + } + goto common; +#endif #if defined(CONFIG_CMD_NFS )case NFS :#endif
dns.h +38 -0
@@ -0,0 +1,39 @@ +/* +* (C) Masami Komiya <[email protected]> 2005 +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2, or (at +* your option) any later version. +*/ + +#ifndef __DNS_H__ +#define __DNS_H__ + +#define DNS_SERVICE_PORT 53 +#define DNS_MAX 1025/* Maximum host name */ +#define DNS_TIMEOUT 10000UL + +/* http://en.wikipedia.org/wiki/List_of_DNS_record_types */ +enum dns_query_type { +DNS_A_RECORD =0x01 , +DNS_CNAME_RECORD =0x05 , +DNS_MX_RECORD =0x0f }; + +/* +* DNS network packet +*/ +struct header { +uint16_t tid;/* Transaction ID */ +uint16_t flags;/* Flags */ +uint16_t nqueries;/* Questions */ +uint16_t nanswers;/* Answers */ +uint16_t nauth;/* Authority PRs */ +uint16_t nother;/* Other PRs */ +unsigned char data[1 ];/* Data, variable length */ +}; + +extern void DnsStart (void );/* Begin DNS */ + +#endif
Makefile +1 -0
@@ -34,6 +34,7 @@ COBJS-y += eth.o COBJS-y += nfs.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o +COBJS-$(CONFIG_CMD_DNS) += dns.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
cmd_net.c +32 -0
@@ -353,3 +353,35 @@"[NTP server IP]\n" );#endif + +#if defined(CONFIG_CMD_DNS ) +int do_dns (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) +{ +if (argc <2 ) { +cmd_usage (cmdtp); +return -1 ; + } + +if (strlen (argv[1 ]) >sizeof (NetDNSResolve) -1 ) { +puts ("Name too long.\n" ); +return -1 ; + } + +strcpy (NetDNSResolve, argv[1 ]); + +if (NetLoop (DNS ) <0 ) { +printf ("dns lookup of %s failed, check setup\n" , argv[1 ]); +return 1 ; + } + +return 0 ; +} + +U_BOOT_CMD ( + dns,2 ,1 , do_dns, +"lookup the IP of a hostname" , +"[machine to lookup]\n" +); + +#endif /* CONFIG_CMD_DNS */ +
PATCH 1/1 - add dns
Dear Robin Getz,
Quoted 19 lines · In message <[email protected]> you wrote:
On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg10216.html
Quoted 6 lines
DNS can be enabled by setting
CFG_CMD_DNS. After performing a query, the serverip environment var is updated.Probably there are some cosmetic issues with the patch. Unfortunatly I do not have the time to correct these. So if anybody else likes DNS support in U-Boot and has the time, feel free to patch it in the main tree.
Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for timeout)
- use built in functions (memcpy) rather than byte copy.
Quoted 12 lines
bfin> dhcp
BOOTP broadcast 1
DHCP client bound to address 192.168.0.4
bfin> dns pool.ntp.org
69.36.241.112
bfin> sntp $(serverip)
Date: 2009-07-17 Time: 19:16:51
bfin> dns www.google.com
64.233.161.147
bfin> ping $(serverip)
Using Blackfin EMAC device
host 64.233.161.147 is alive
Note that the use of "$(...)" is deprecated. Please use "${...}" instead,
Quoted 4 lines
Signed-off-by Robin Getz <[email protected]>Signed-off-by Pieter Voorthuijsen <[email protected]>
Quoted 8 lines
common/cmd_net.c | 32 ++++ include/configs/bfin_adi_common.h | 7 include/net.h | 4 net/Makefile | 1 net/dns.c | 213 ++++++++++++++++++++++++++++ net/dns.h | 38 ++++ net/net.c | 20 ++ 7 files changed, 314 insertions(+), 1 deletion(-)
You probably should add a doc/README.* file to explain how that is supposed to be used.
net.h
Quoted 4 lines
Index:
include/net.h
===================================================================net.h +0
-0
Could you generate a git patch instead?
net.h line 366
Quoted 7 lines
net.h +3
-0@@ -361,6 +361,10 @@/* from net/net.c */ extern char BootFile[128 ];/* Boot File name */ +#if defined(CONFIG_CMD_DNS ) +extern char NetDNSResolve[255 ];/* The host to resolve */ +#endif
Can this buffer overflow?
Quoted 5 lines
Index:
net/dns.c
===================================================================
dns.c line 9
Quoted 9 lines
dns.c +9
-0@@ -0,0 +1,213 @@ +/* +* DNS support driver +* +* Copyright (c) 2008 Pieter Voorthuijsen <[email protected]> +* Copyright (c) 2009 Robin Getz <[email protected]> +* +* This is a simple DNS implementation for U-Boot. It will use the first IP +* in the DNS response as NetServerIP. This can then be used for any other +* network related activities.
Hmmm... why do you assume that the address we're trying to resolve is the server IP?
To me it makes at least as much sense to resolve the "ipaddr" value.
dns.c line 31
Quoted 1 line
dns.c +1
-0+char NetDNSResolve[255 ];/* The host to resolve */
See above.
Quoted 5 lines
dns.c +5
-0+static int DnsOurPort; + +static void +DnsSend (void ) +{
...
Quoted 9 lines
dns.c +9
-0+ do { + s = strchr(name, '.'); + if (!s) + s = name + name_len; + + n = s - name; /* Chunk length */ + *p++ = n; /* Copy length */ + memcpy(p, name, n); /* Copy chunk */ + p += n;
dns.c line 79
Quoted 10 lines
dns.c +10
-0+ +if (*s =='.' ) + n++; + + name += n; + name_len -= n; + }while (*s !='\0' ); + + *p++ =0 ;/* Mark end of host name */ + *p++ =0 ;/* Well, lets put this byte as well */
Why that?
Quoted 3 lines
dns.c +3
-0+static void +DnsHandler (uchar *pkt,unsigned dest,unsigned src,unsigned len) +{
...
dns.c line 130
Quoted 4 lines
dns.c +4
-0+/* Received 0 answers */ +if (header->nanswers ==0 ) { +debug ("DNS server returned no answers\n" ); +puts ("server can't find hostname\n" );
Debug and regular output are redundant. Omit the debug(). Actually I recommend to use the debug() message text, which is IMO more precise.
dns.c line 145
Quoted 3 lines
dns.c +3
-0+if (&p[5 ] > e ||ntohs (tmp) !=DNS_A_RECORD ) { +debug ("Query was not A record\n" ); +puts ("server can't find IP number of hostname\n" );
Ditto.
dns.c line 193
Quoted 4 lines
dns.c +4
-0+if (p + dlen <= e) { +ip_to_string (IPAddress, IPStr); + NetServerIP = IPAddress; +setenv ("serverip" , IPStr);
I object to this part. I think it is a very bad idea to meddle with the NetServerIP and "serverip" settings here - this may be wanted by the user, or maybe not.
I am aware that we don't have an easy way of passing results from a command back to U-Boot's "shell", so I suggest a syntactical change, see below.
Makefile line 37
Quoted 9 lines
Index: net/Makefile
===================================================================Makefile +1
-0@@ -34,6 +34,7 @@ COBJS-y += eth.o COBJS-y += nfs.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o +COBJS-$(CONFIG_CMD_DNS) += dns.o
Please keep list sorted.
Quoted 4 lines
Index:
common/cmd_net.c
===================================================================cmd_net.c +0
-0
...
cmd_net.c line 384
Quoted 5 lines
cmd_net.c +5
-0+U_BOOT_CMD ( + dns,2 ,1 , do_dns, +"lookup the IP of a hostname" , +"[machine to lookup]\n" +);
I suggest to change "machine to lookup" into "hostname".
Hmmm... is this argument really optional as the brackets suggest? I don't think so. And why do you allow for 2 arguments? And the newline is bogus, too.
I suggest to change this as follows:
U_BOOT_CMD(
dns, 2, 1, do_dns, "lookup the IP of a hostname", "hostname [envvar]"
);
If you use the command with one argument (just the host name to look up), it will only print the result, like this:
=> dns www.denx.de 85.214.87.163
Note that this command does NOT change any environment settings!
To do the equivalent of your implementation, you have to tell the command the name of the environment variable where trhe result (if any) shall be stored:
=> dns www.denx.de serverip 85.214.87.163
In this case the command will print the result _and_ store the value in the environment variable given on the command line. This seems more flexible to me, as I can then also do things like
=> dns ${hostname} ipaddretc.
What do you think?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Killing is wrong. -- Losira, "That Which Survives", stardate unknown
PATCH 1/1 - add dns
On Fri 17 Jul 2009 16:55, Wolfgang Denk pondered:
Quoted 35 lines
Dear Robin Getz,
Quoted 19 lines · In message <[email protected]> you wrote:
On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg10216.html
Quoted 6 lines
DNS can be enabled by setting
CFG_CMD_DNS. After performing a query, the serverip environment var is updated.Probably there are some cosmetic issues with the patch. Unfortunatly I do not have the time to correct these. So if anybody else likes DNS support in U-Boot and has the time, feel free to patch it in the main tree.
Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for timeout)
- use built in functions (memcpy) rather than byte copy.Quoted 12 lines
bfin> dhcp
BOOTP broadcast 1
DHCP client bound to address 192.168.0.4
bfin> dns pool.ntp.org
69.36.241.112
bfin> sntp $(serverip)
Date: 2009-07-17 Time: 19:16:51
bfin> dns www.google.com
64.233.161.147
bfin> ping $(serverip)
Using Blackfin EMAC device
host 64.233.161.147 is alive
Quoted 2 lines
Note that the use of "$(...)" is deprecated. Please use "${...}" instead,
OK.
Quoted 13 lines
Quoted 4 lines
Signed-off-by Robin Getz <[email protected]>Signed-off-by Pieter Voorthuijsen <[email protected]>Quoted 8 lines
common/cmd_net.c | 32 ++++ include/configs/bfin_adi_common.h | 7 include/net.h | 4 net/Makefile | 1 net/dns.c | 213 ++++++++++++++++++++++++++++ net/dns.h | 38 ++++ net/net.c | 20 ++ 7 files changed, 314 insertions(+), 1 deletion(-)
Quoted 2 lines
You probably should add a doc/README.* file to explain how that is supposed to be used.
Will do.
What is the rule for when things go in ./doc/README.* vs ./README ?
Quoted 6 lines
net.h
Quoted 4 lines
Index:
include/net.h
===================================================================net.h +0
-0Could you generate a git patch instead?
Sure - I'll generate something from the net tree?
Quoted 9 lines
net.h line 366
Quoted 7 lines
net.h +3
-0@@ -361,6 +361,10 @@/* from net/net.c */ extern char BootFile[128 ];/* Boot File name */ +#if defined(CONFIG_CMD_DNS ) +extern char NetDNSResolve[255 ];/* The host to resolve */ +#endif Can this buffer overflow?
Shouldn't.
+ if (strlen(argv[1]) > sizeof(NetDNSResolve) - 1) {
+ puts("Name too long.\n");
+ return -1;
+ }
+
Quoted 18 lines
Quoted 5 lines
Index:
net/dns.c
===================================================================dns.c line 9
Quoted 9 lines
dns.c +9
-0@@ -0,0 +1,213 @@ +/* +* DNS support driver +* +* Copyright (c) 2008 Pieter Voorthuijsen <[email protected]> +* Copyright (c) 2009 Robin Getz <[email protected]> +* +* This is a simple DNS implementation for U-Boot. It will use the first IP +* in the DNS response as NetServerIP. This can then be used for any other +* network related activities. Hmmm... why do you assume that the address we're trying to resolve is the server IP?
Quoted 1 line
To me it makes at least as much sense to resolve the "ipaddr" value.
Yeah, this was my biggest issue for things too (from the original patch).
but you can easily :
set nameip ${serverip}
to transfer it to something else. - or just use it directly.
Originally I thought about dnsip, but that pre-existing, and is used to store the nameserver ip (which is poorly named IMHO).
any better suggestions welcome.
Quoted 3 lines
dns.c line 31
Quoted 1 line
dns.c +1
-0+char NetDNSResolve[255 ];/* The host to resolve */ See above.
See answer :)
Quoted 19 lines
Quoted 5 lines
dns.c +5
-0+static int DnsOurPort; + +static void +DnsSend (void ) +{...
Quoted 13 lines
dns.c +13
-0+ do { + s = strchr(name, '.'); + if (!s) + s = name + name_len; + + n = s - name; /* Chunk length */ + *p++ = n; /* Copy length */ + memcpy(p, name, n); /* Copy chunk */ + p += n; + + if (*s == '.') + n++; +
Quoted 8 lines
dns.c line 79
Quoted 6 lines
dns.c +6
-0+ name += n; + name_len -= n; + }while (*s !='\0' ); + + *p++ =0 ;/* Mark end of host name */ + *p++ =0 ;/* Well, lets put this byte as well */ Why that?
No idea - that was in the original....
Hmm -- according to my TCP/IP Illustrated - names are suppost to be double null terminated - so I think that is a requirement.
Quoted 4 lines
Quoted 3 lines
dns.c +3
-0+static void +DnsHandler (uchar *pkt,unsigned dest,unsigned src,unsigned len) +{...
Quoted 8 lines
dns.c line 130
Quoted 4 lines
dns.c +4
-0+/* Received 0 answers */ +if (header->nanswers ==0 ) { +debug ("DNS server returned no answers\n" ); +puts ("server can't find hostname\n" );Debug and regular output are redundant. Omit the
debug(). Actually I recommend to use thedebug()message text, which is IMO more precise.
No problem.
Quoted 15 lines
dns.c line 145
Quoted 3 lines
dns.c +3
-0+if (&p[5 ] > e ||ntohs (tmp) !=DNS_A_RECORD ) { +debug ("Query was not A record\n" ); +puts ("server can't find IP number of hostname\n" );Ditto.
dns.c line 193
Quoted 4 lines
dns.c +4
-0+if (p + dlen <= e) { +ip_to_string (IPAddress, IPStr); + NetServerIP = IPAddress; +setenv ("serverip" , IPStr);I object to this part. I think it is a very bad idea to meddle with the NetServerIP and "serverip" settings here - this may be wanted by the user, or maybe not.
Quoted 3 lines
I am aware that we don't have an easy way of passing results from a command back to U-Boot's "shell", so I suggest a syntactical change, see below.
OK.
Quoted 11 lines
Makefile line 37
Quoted 9 lines
Index: net/Makefile
===================================================================Makefile +1
-0@@ -34,6 +34,7 @@ COBJS-y += eth.o COBJS-y += nfs.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o +COBJS-$(CONFIG_CMD_DNS) += dns.oPlease keep list sorted.
OK
Quoted 5 lines
Quoted 4 lines
Index:
common/cmd_net.c
===================================================================cmd_net.c +0
-0...
Quoted 7 lines
cmd_net.c line 384
Quoted 5 lines
cmd_net.c +5
-0+U_BOOT_CMD ( + dns,2 ,1 , do_dns, +"lookup the IP of a hostname" , +"[machine to lookup]\n" +);I suggest to change "machine to lookup" into "hostname".
OK
Quoted 3 lines
Hmmm... is this argument really optional as the brackets suggest? I don't think so. And why do you allow for 2 arguments? And the newline is bogus, too.
Yeah, sorry - I don't completely grok the U-Boot help syntax. I'll fix.
Quoted 27 lines
I suggest to change this as follows:
U_BOOT_CMD(
dns, 2, 1, do_dns, "lookup the IP of a hostname", "hostname [envvar]");
If you use the command with one argument (just the host name to look up), it will only print the result, like this:
=> dns www.denx.de 85.214.87.163Note that this command does NOT change any environment settings!
To do the equivalent of your implementation, you have to tell the command the name of the environment variable where trhe result (if any) shall be stored:
=> dns www.denx.de serverip 85.214.87.163In this case the command will print the result _and_ store the value in the environment variable given on the command line. This seems more flexible to me, as I can then also do things like
Quoted 5 lines
=> dns ${hostname} ipaddretc.
What do you think?
that is more flexible that the current implementation...
but also a little more complex.
saving it in a predefined env var (like 'dnshostip') is also OK.
dns www.denx.de
set serverip ${dnshostip}
-- is going to be a little smaller...
Up to you...
-Robin
PATCH 1/1 - add dns
Dear Robin Getz,
Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines
You probably should add a doc/README.* file to explain how that is supposed to be used.
Will do.
What is the rule for when things go in ./doc/README.* vs ./README ?
Size - anything that takes more than 5...10 lines ?
Quoted 3 lines
Quoted 1 line
Could you generate a git patch instead?
Sure - I'll generate something from the net tree?
Please use the mainline repo / "master" branch as reference.
Quoted 7 lines
Quoted 5 lines
net.h line 366
Quoted 3 lines
net.h +3
-0+#if defined(CONFIG_CMD_DNS ) +extern char NetDNSResolve[255 ];/* The host to resolve */ +#endif Can this buffer overflow?
Shouldn't.
Agreed. I've seen the tests later in the code but forgot to remove this.
...
Quoted 5 lines
Quoted 4 lines
Hmmm... why do you assume that the address we're trying to resolve is the server IP?
To me it makes at least as much sense to resolve the "ipaddr" value.
Quoted 7 lines
Yeah, this was my biggest issue for things too (from the original patch).
but you can easily :
set nameip ${serverip}
to transfer it to something else. - or just use it directly.
But you lost the original "serverip" setting, which may not be wanted.
Quoted 9 lines
Quoted 4 lines
dns.c line 79
Quoted 2 lines
dns.c +2
-0+ *p++ =0 ;/* Mark end of host name */ + *p++ =0 ;/* Well, lets put this byte as well */ Why that?
No idea - that was in the original....
Hmm -- according to my TCP/IP Illustrated - names are suppost to be double null terminated - so I think that is a requirement.
Then please remove the comment that automatically triggers such "why that?" questions (and eventually replace it with a better explanation).
Quoted 1 line
Quoted 1 line
I suggest to change this as follows:
...
Quoted 3 lines
Quoted 1 line
What do you think?
that is more flexible that the current implementation...
Indeed :-)
Quoted 1 line
but also a little more complex.
Not really. Yes, you have to add 3 lines of code to check for the 2nd argument, butexcept from that you just change the
setenv("serverip", IPStr);
into
setenv(argvp, IPStr);Quoted 8 lines
saving it in a predefined env var (like 'dnshostip') is also OK.
dns www.denx.de
set serverip ${dnshostip}-- is going to be a little smaller...
Up to you...
I like my proposal better, as it avoids adding another predefined env var which is of not much use to most users, as it will only serve as temp storage; and your proposal requires a second command, i. e. more typing and thus more chances for typos.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The Wright Bothers weren't the first to fly. They were just the first not to crash.
PATCH 1/1 - add dns
On Fri 17 Jul 2009 18:01, Wolfgang Denk pondered:
Quoted 11 lines
Dear Robin Getz,
Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines
You probably should add a doc/README.* file to explain how that is supposed to be used.
Will do.
What is the rule for when things go in ./doc/README.* vs ./README ?
Quoted 7 lines
Size - anything that takes more than 5...10 lines ?
Quoted 3 lines
Quoted 1 line
Could you generate a git patch instead?
Sure - I'll generate something from the net tree?
Please use the mainline repo / "master" branch as reference.
Sure - but master's dhcp does not work for me until unassigned-patches/39 is applied.
PATCH 1/1 - add dns
In reply to Wolfgang DenkOn Fri 17 Jul 2009 18:01, Wolfgang Denk pondered:
Quoted 11 lines
Dear Robin Getz,
Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines
You probably should add a doc/README.* file to explain how that is supposed to be used.
Will do.
What is the rule for when things go in ./doc/README.* vs ./README ?
Quoted 7 lines
Size - anything that takes more than 5...10 lines ?
Quoted 3 lines
Quoted 1 line
Could you generate a git patch instead?
Sure - I'll generate something from the net tree?
Please use the mainline repo / "master" branch as reference.
v2 - based on mainline repo "master"
- implemented feedback from Wolfgang
common/cmd_net.c | 47 ++++++++ doc/README.dns | 64 +++++++++++ include/net.h | 5 net/Makefile | 1 net/dns.c | 212 ++++++++++++++++++++++++++++++++++++++ net/dns.h | 38 ++++++ net/net.c | 19 +++ 8 files changed, 393 insertions(+)
-------
common/cmd_net.c +47 -0
@@ -353,3 +353,50 @@ U_BOOT_CMD("[NTP server IP]\n" );#endif + +#if defined(CONFIG_CMD_DNS ) +int do_dns (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) +{ +if (argc ==1 ) { +cmd_usage (cmdtp); +return -1 ; + } + +/* +* We should check for a valid hostname: +* - Each label must be between 1 and 63 characters long +* - the entire hostname has a maximum of 255 characters +* - only the ASCII letters 'a' through 'z' (case-insensitive), +* the digits '0' through '9', and the hyphen +* - cannot begin or end with a hyphen +* - no other symbols, punctuation characters, or blank spaces are permitted +* but hey - this is a minimalist implmentation, so only check length +*/ +if (strlen (argv[1 ]) >=255 ) { +printf ("dns error: hostname too long\n" ); +return 1 ; + } + + NetDNSResolve = argv[1 ]; + +if (argc ==3 ) + NetDNSenvvar = argv[2 ]; +else + NetDNSenvvar =NULL ; + +if (NetLoop (DNS ) <0 ) { +printf ("dns lookup of %s failed, check setup\n" , argv[1 ]); +return 1 ; + } + +return 0 ; +} + +U_BOOT_CMD ( + dns,3 ,1 , do_dns, +"lookup the IP of a hostname" , +"hostname [envvar]" +); + +#endif /* CONFIG_CMD_DNS */ +
doc/README.dns new file +64 -0
64 lines not on this page · raw message
include/net.h +5 -0
@@ -361,6 +361,11 @@ typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP/* from net/net.c */ extern char BootFile[128 ];/* Boot File name */ +#if defined(CONFIG_CMD_DNS ) +extern char *NetDNSResolve;/* The host to resolve */ +extern char *NetDNSenvvar;/* the env var to put the ip into */ +#endif +#if defined(CONFIG_CMD_PING )extern IPaddr_t NetPingIP;/* the ip address to ping */ #endif
net/Makefile +1 -0
@@ -33,6 +33,7 @@ COBJS-y += bootp.o COBJS-y += rarp.o COBJS-y += eth.o COBJS-y += nfs.o +COBJS-$(CONFIG_CMD_DNS) += dns.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o COBJS := $(COBJS-y)
net/dns.c new file +212 -0
212 lines not on this page · raw message
net/dns.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* (C) Masami Komiya <[email protected]> 2005 +* Copyright 2009, Robin Getz <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2, or (at +* your option) any later version. +*/ + +#ifndef __DNS_H__ +#define __DNS_H__ + +#define DNS_SERVICE_PORT 53 +#define DNS_TIMEOUT 10000UL + +/* http://en.wikipedia.org/wiki/List_of_DNS_record_types */ +enum dns_query_type { +DNS_A_RECORD =0x01 , +DNS_CNAME_RECORD =0x05 , +DNS_MX_RECORD =0x0f }; + +/* +* DNS network packet +*/ +struct header { +uint16_t tid;/* Transaction ID */ +uint16_t flags;/* Flags */ +uint16_t nqueries;/* Questions */ +uint16_t nanswers;/* Answers */ +uint16_t nauth;/* Authority PRs */ +uint16_t nother;/* Other PRs */ +unsigned char data[1 ];/* Data, variable length */ +}; + +extern void DnsStart (void );/* Begin DNS */ + +#endif
net/net.c +19 -0
@@ -92,6 +92,9 @@#if defined(CONFIG_CDP_VERSION )#include <timestamp.h> #endif +#if defined(CONFIG_CMD_DNS ) +#include "dns.h" +#endif #if defined(CONFIG_CMD_NET )
@@ -291,6 +294,9 @@ NetInitLoop(proto_t protocol) NetServerIP =getenv_IPaddr ("serverip" ); NetOurNativeVLAN =getenv_VLAN ("nvlan" ); NetOurVLAN =getenv_VLAN ("vlan" ); +#if defined(CONFIG_CMD_DNS ) + NetOurDNSIP =getenv_IPaddr ("dnsip" ); +#endif env_changed_id = env_id; }
@@ -426,6 +435,11 @@ restart:SntpStart ();break ;#endif +#if defined(CONFIG_CMD_DNS ) +case DNS : +DnsStart (); +break ; +#endif default :break ; }
@@ -1518,6 +1532,14 @@ static int net_check_prereq (proto_t protocol) } goto common;#endif +#if defined(CONFIG_CMD_DNS ) +case DNS : +if (NetOurDNSIP ==0 ) { +puts ("*** ERROR: DNS server address not given\n" ); +return 1 ; + } + goto common; +#endif #if defined(CONFIG_CMD_NFS )case NFS :#endif
PATCH 1/1 - add dns
net/dns.c line 89
Quoted 1 line · On Saturday 18 July 2009 01:14:25 Robin Getz wrote:
net/dns.c new file +1
-0+ DnsOurPort =10000 + (get_timer (0 ) %4096 );
4096 port range seems kind of small. i dont think the requests really need to be greater than 10000. not sure if services would get pissed about being below the 1024 limit though, so this is probably better:
1024 + (get_timer() % 0x8000);
keep the modulus something with only 1 bit set so gcc will optimize into a simple and operation. probably add a comment about it too:
/* make src port a little random, but use something trivial to compute */
net/dns.c line 208
Quoted 6 lines
net/dns.c new file +6
-0+void +DnsStart (void ) +{ +NetSetTimeout (DNS_TIMEOUT , DnsTimeout); +NetSetHandler (DnsHandler); +memset (NetServerEther,0 ,6 );
is clearing the ether address really necessary ? if so, why should the dns code care about it ?
net/dns.h line 21
Quoted 5 lines
net/dns.h new file +5
-0+/* http://en.wikipedia.org/wiki/List_of_DNS_record_types */ +enum dns_query_type { +DNS_A_RECORD =0x01 , +DNS_CNAME_RECORD =0x05 , +DNS_MX_RECORD =0x0f };
that last }; should be on a line by itself, and the last entry should still have a comma at the end
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090718/ceb9e8c5/attachment.pgp
PATCH 1/1 - add dns
On Sat 18 Jul 2009 18:11, Mike Frysinger pondered:
Quoted 7 lines · On Saturday 18 July 2009 01:14:25 Robin Getz wrote:
net/dns.c line 89
Quoted 1 line
net/dns.c new file +1
-0+ DnsOurPort =10000 + (get_timer (0 ) %4096 );4096 port range seems kind of small. i dont think the requests really need to be greater than 10000. not sure if services would get pissed about being below the 1024 limit though, so this is probably better:
1024 + (get_timer()%0x8000);
Sure.
Quoted 3 lines
keep the modulus something with only 1 bit set so gcc will optimize into a simple and operation. probably add a comment about it too:
/* make src port a little random, but use something trivial to compute */
OK - So, this would give three different variations:
net/sntp.c: SntpOurPort = 10000 + (get_timer(0) % 4096); net/tftp.c: TftpOurPort = 1024 + (get_timer(0) % 3072); net/nfs.c: NfsOurPort = 4096 + (get_ticks() % 3072);
Does it make sense to have 4 different ones? (not to me)...
Or something new & common in ./net.c:random_port()
Ben?
Quoted 9 lines
net/dns.c line 208
Quoted 6 lines
net/dns.c new file +6
-0+void +DnsStart (void ) +{ +NetSetTimeout (DNS_TIMEOUT , DnsTimeout); +NetSetHandler (DnsHandler); +memset (NetServerEther,0 ,6 );is clearing the ether address really necessary ? if so, why should the dns code care about it ?
Nope - I can remove that...
Quoted 8 lines
net/dns.h line 21
Quoted 5 lines
net/dns.h new file +5
-0+/* http://en.wikipedia.org/wiki/List_of_DNS_record_types */ +enum dns_query_type { +DNS_A_RECORD =0x01 , +DNS_CNAME_RECORD =0x05 , +DNS_MX_RECORD =0x0f };that last }; should be on a line by itself, and the last entry should still have a comma at the end
Hmm - didn't notice that one from the orginal. Thanks (I'm surprised that checkpatch didn't complain).
Since there aren't any functionality differences - I'll send out a new version on Monday for Ben - since he is away anyway (unless someone else comments tomorrow).
-Robin
PATCH 1/1 - add dns
Quoted 8 lines · On Saturday 18 July 2009 20:27:00 Robin Getz wrote:
On Sat 18 Jul 2009 18:11, Mike Frysinger pondered:
Quoted 4 lines
keep the modulus something with only 1 bit set so gcc will optimize into a simple and operation. probably add a comment about it too:
/* make src port a little random, but use something trivial to compute*/
OK - So, this would give three different variations:
Quoted 7 lines
net/sntp.c: SntpOurPort = 10000 + (get_timer(0) % 4096); net/tftp.c: TftpOurPort = 1024 + (get_timer(0) % 3072); net/nfs.c: NfsOurPort = 4096 + (get_ticks() % 3072);Does it make sense to have 4 different ones? (not to me)...
Or something new & common in ./net.c:random_port()
i would make a new patch that adds a new random_port() function and converts existing consumers to that, and then have the dns code rely on that.
and you should adopt my implementation because the generated code is much much nicer than the others ;)
a quick google shows:
- sntp - any non-zero source port is OK
- tftp - "between 0 and 65535"
- nfs - couldnt find anything, but i'm pretty sure there isnt one
get_ticks() and get_timer(0) are pretty much equivalent
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090718/905c3665/attachment.pgp
PATCH 1/1 - add dns
On Sat 18 Jul 2009 21:15, Mike Frysinger pondered:
Quoted 9 lines · On Saturday 18 July 2009 20:27:00 Robin Getz wrote:
Quoted 8 lines
On Sat 18 Jul 2009 18:11, Mike Frysinger pondered:
Quoted 4 lines
keep the modulus something with only 1 bit set so gcc will optimize into a simple and operation. probably add a comment about it too:
/* make src port a little random, but use something trivial to compute*/
OK - So, this would give three different variations:
So, these are definitality ugly...
Quoted 1 line
Quoted 1 line
net/tftp.c: TftpOurPort = 1024 + (get_timer(0)% 3072);
00000000 <_random_port>:
0: 78 05 [--SP] = (R7:7);
2: 67 01 [--SP] = RETS;
4: a6 6f SP += -0xc; /* (-12) */
6: 00 60 R0 = 0x0 (X); /* R0=0x0( 0) */
8: ff e3 fc ff CALL 0x0 <_random_port>;
a: R_BFIN_PCREL24 _get_timer
c: 41 e1 aa aa R1.H = 0xaaaa; /* (-21846) R1=0xaaaa000c(-1431699444) */
10: 01 e1 ab aa R1.L = 0xaaab; /* (-21845) R1=0xaaaaaaab(-1431655765) */
14: 38 30 R7 = R0;
16: ff e3 f5 ff CALL 0x0 <_random_port>;
18: R_BFIN_PCREL24 ___umulsi3_highpart
1a: 58 4e R0 >>= 0xb;
1c: 21 e1 00 0c R1 = 0xc00 (X); /* R1=0xc00(3072) */
20: c8 40 R0 *= R1;
22: 66 6c SP += 0xc; /* ( 12) */
24: c7 53 R7 = R7 - R0;
26: 20 e1 00 04 R0 = 0x400 (X); /* R0=0x400(1024) */
2a: c7 51 R7 = R7 + R0;
2c: 27 01 RETS = [SP++];
2e: 07 30 R0 = R7;
30: 38 05 (R7:7) = [SP++];
32: 10 00 RTS;Disassembly of section .text.NetSetTimeout:
Quoted 1 line
Quoted 1 line
net/nfs.c: NfsOurPort = 4096 + (get_ticks()% 3072);
00000000 <_random_port>:
0: 67 01 [--SP] = RETS;
2: 86 6f SP += -0x10; /* (-16) */
4: ff e3 fe ff CALL 0x0 <_random_port>;
6: R_BFIN_PCREL24 _get_ticks
8: 02 60 R2 = 0x0 (X); /* R2=0x0( 0) */
a: f2 b0 [SP + 0xc] = R2;
c: 22 e1 00 0c R2 = 0xc00 (X); /* R2=0xc00(3072) */
10: ff e3 f8 ff CALL 0x0 <_random_port>;
12: R_BFIN_PCREL24 ___umoddi3
14: 86 6c SP += 0x10; /* ( 16) */
16: 08 30 R1 = R0;
18: 27 01 RETS = [SP++];
1a: 20 e1 00 10 R0 = 0x1000 (X); /* R0=0x1000(4096) */
1e: 01 50 R0 = R1 + R0;
20: 10 00 RTS;Quoted 1 line
Quoted 1 line
net/sntp.c: SntpOurPort = 10000 + (get_timer(0)% 4096);
00000000 <_random_port>:
0: 67 01 [--SP] = RETS;
2: a6 6f SP += -0xc; /* (-12) */
4: 00 60 R0 = 0x0 (X); /* R0=0x0( 0) */
6: ff e3 fd ff CALL 0x0 <_random_port>;
8: R_BFIN_PCREL24 _get_timer
a: 21 e1 ff 0f R1 = 0xfff (X); /* R1=0xfff(4095) */
e: 66 6c SP += 0xc; /* ( 12) */
10: 08 54 R0 = R0 & R1;
12: 27 01 RETS = [SP++];
14: 21 e1 10 27 R1 = 0x2710 (X); /* R1=0x2710(10000) */
18: 08 50 R0 = R0 + R1;
1a: 10 00 RTS;Disassembly of section .text.NetSetTimeout:
Quoted 1 line
1024 + (
get_timer(0)%0x8000);
00000000 <_random_port>:
0: 67 01 [--SP] = RETS;
2: a6 6f SP += -0xc; /* (-12) */
4: 00 60 R0 = 0x0 (X); /* R0=0x0( 0) */
6: ff e3 fd ff CALL 0x0 <_random_port>;
8: R_BFIN_PCREL24 _get_timer
a: 21 e1 ff 7f R1 = 0x7fff (X); /* R1=0x7fff(32767) */
e: 66 6c SP += 0xc; /* ( 12) */
10: 08 54 R0 = R0 & R1;
12: 27 01 RETS = [SP++];
14: 21 e1 00 04 R1 = 0x400 (X); /* R1=0x400(1024) */
18: 08 50 R0 = R0 + R1;
1a: 10 00 RTS;Disassembly of section .text.NetSetTimeout:
Quoted 9 lines
Quoted 3 lines
Does it make sense to have 4 different ones? (not to me)...
Or something new & common in ./net.c:random_port()
i would make a new patch that adds a new
random_port()function and converts existing consumers to that, and then have the dns code rely on that.and you should adopt my implementation because the generated code is much much nicer than the others ;)
At least on Blackfin - the sntp version and yours are computationally equal - although I think yours ends up being more random - so yeah, I'll use that one.
Quoted 6 lines
a quick google shows:
- sntp - any non-zero source port is OK
- tftp - "between 0 and 65535"
- nfs - couldnt find anything, but i'm pretty sure there isnt one
get_ticks()andget_timer(0)are pretty much equivalent
Sounds great.
PATCH 1/1 - add dns
Quoted 10 lines · On Sunday 19 July 2009 19:30:43 Robin Getz wrote:
On Sat 18 Jul 2009 21:15, Mike Frysinger pondered:
Quoted 9 lines · On Saturday 18 July 2009 20:27:00 Robin Getz wrote:
Quoted 3 lines
Does it make sense to have 4 different ones? (not to me)...
Or something new & common in ./net.c:random_port()
i would make a new patch that adds a new
random_port()function and converts existing consumers to that, and then have the dns code rely on that.
Quoted 6 lines
Quoted 2 lines
and you should adopt my implementation because the generated code is much much nicer than the others ;)
At least on Blackfin - the sntp version and yours are computationally equal - although I think yours ends up being more random - so yeah, I'll use that one.
any arch that has an instruction for doing the "and" operation should end up being computationally as simple as the Blackfin code. afaik, pretty much all do, and the ones who dont are screwed anyways, so nothing to be done for them. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090719/a1e9be32/attachment-0001.pgp
PATCH 1/1 - add dns
In reply to Wolfgang DenkOn Fri 17 Jul 2009 16:55, Wolfgang Denk pondered:
Quoted 11 lines
Makefile line 37
Quoted 9 lines
Index: net/Makefile
===================================================================Makefile +1
-0@@ -34,6 +34,7 @@ COBJS-y += eth.o COBJS-y += nfs.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o +COBJS-$(CONFIG_CMD_DNS) += dns.oPlease keep list sorted.
sorted how? What we have today is:
COBJS-y += net.o
COBJS-y += tftp.o
COBJS-y += bootp.o
COBJS-y += rarp.o
COBJS-y += eth.o
COBJS-y += nfs.o
COBJS-$(CONFIG_CMD_SNTP) += sntp.o
It is not sorted alphabetically... ???
It's not sorted by length???
Seems to be sorted by date added, with the last ones on the bottom.
PATCH 1/1 - add dns
Dear Robin Getz,
Quoted 23 lines · In message <[email protected]> you wrote:
On Fri 17 Jul 2009 16:55, Wolfgang Denk pondered:
Quoted 11 lines
Makefile line 37
Quoted 9 lines
Index: net/Makefile
===================================================================Makefile +1
-0@@ -34,6 +34,7 @@ COBJS-y += eth.o COBJS-y += nfs.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o +COBJS-$(CONFIG_CMD_DNS) += dns.oPlease keep list sorted.
sorted how? What we have today is:
COBJS-y += net.o
COBJS-y += tftp.o
COBJS-y += bootp.o
COBJS-y += rarp.o
COBJS-y += eth.o
COBJS-y += nfs.o
COBJS-$(CONFIG_CMD_SNTP) += sntp.o
Quoted 1 line
It is not sorted alphabetically... ???
I see. Sorry. Well, please use the opportunity to sort that list, then. Alphabetically.
Quoted 1 line
Seems to be sorted by date added, with the last ones on the bottom.
Indeed. But that's not what I meant :-) Thanks.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de A memorandum is written not to inform the reader, but to protect the writer. -- Dean Acheson
PATCH 1/1 - add dns
On Sun 19 Jul 2009 03:48, Wolfgang Denk pondered:
Quoted 15 lines
Dear Robin Getz,
Quoted 13 lines · In message <[email protected]> you wrote:
On Fri 17 Jul 2009 16:55, Wolfgang Denk pondered:
Quoted 1 line
Please keep list sorted.
sorted how? What we have today is:
COBJS-y += net.o
COBJS-y += tftp.o
COBJS-y += bootp.o
COBJS-y += rarp.o
COBJS-y += eth.o
COBJS-y += nfs.o
COBJS-$(CONFIG_CMD_SNTP) += sntp.o
Quoted 5 lines
Quoted 1 line
It is not sorted alphabetically... ???
I see. Sorry. Well, please use the opportunity to sort that list, then. Alphabetically.
Ok -- what I have is this then. I'll wrap it up tomorrow and send to Ben, assuming he doesn't have anything else...
net/Makefile +4 -3
@@ -27,13 +27,14 @@ include $(TOPDIR)/config.mk LIB = $(obj)libnet.a -COBJS-y += net.o -COBJS-y += tftp.o COBJS-y += bootp.o -COBJS-y += rarp.o +COBJS-$(CONFIG_CMD_DNS) += dns.o COBJS-y += eth.o +COBJS-y += net.o COBJS-y += nfs.o +COBJS-y += rarp.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o +COBJS-y += tftp.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
PATCH 1/1 v3 - add dns
In reply to Robin GetzOn 04 Oct 2008 Pieter posted a dns implementation for U-Boot.
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg10216.html
Quoted 7 lines
DNS can be enabled by setting
CFG_CMD_DNS. After performing a query, the serverip environment var is updated.Probably there are some cosmetic issues with the patch. Unfortunatly I do not have the time to correct these. So if anybody else likes DNS support in U-Boot and has the time, feel free to patch it in the main tree.
Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for timeout)
- use built in functions (memcpy) rather than byte copy.
common/cmd_net.c | 49 ++++++++++ doc/README.dns | 64 +++++++++++++ include/net.h | 5 + net/Makefile | 7 - net/dns.c | 211 +++++++++++++++++++++++++++++++++++++++++++++ net/dns.h | 39 ++++++++ net/net.c | 29 ++++++ 7 files changed, 401 insertions(+), 3 deletions(-)
---
common/cmd_net.c +49 -0
@@ -353,3 +353,52 @@ U_BOOT_CMD("[NTP server IP]\n" );#endif + +#if defined(CONFIG_CMD_DNS ) +int do_dns (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) +{ +if (argc ==1 ) { +cmd_usage (cmdtp); +return -1 ; + } + +/* +* We should check for a valid hostname: +* - Each label must be between 1 and 63 characters long +* - the entire hostname has a maximum of 255 characters +* - only the ASCII letters 'a' through 'z' (case-insensitive), +* the digits '0' through '9', and the hyphen +* - cannot begin or end with a hyphen +* - no other symbols, punctuation characters, or blank spaces are +* permitted +* but hey - this is a minimalist implmentation, so only check length +* and let the name server deal with things. +*/ +if (strlen (argv[1 ]) >=255 ) { +printf ("dns error: hostname too long\n" ); +return 1 ; + } + + NetDNSResolve = argv[1 ]; + +if (argc ==3 ) + NetDNSenvvar = argv[2 ]; +else + NetDNSenvvar =NULL ; + +if (NetLoop (DNS ) <0 ) { +printf ("dns lookup of %s failed, check setup\n" , argv[1 ]); +return 1 ; + } + +return 0 ; +} + +U_BOOT_CMD ( + dns,3 ,1 , do_dns, +"lookup the IP of a hostname" , +"hostname [envvar]" +); + +#endif /* CONFIG_CMD_DNS */ +
doc/README.dns new file +64 -0
64 lines not on this page · raw message
include/net.h +5 -0
@@ -361,6 +361,11 @@ typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP/* from net/net.c */ extern char BootFile[128 ];/* Boot File name */ +#if defined(CONFIG_CMD_DNS ) +extern char *NetDNSResolve;/* The host to resolve */ +extern char *NetDNSenvvar;/* the env var to put the ip into */ +#endif +#if defined(CONFIG_CMD_PING )extern IPaddr_t NetPingIP;/* the ip address to ping */ #endif
net/Makefile +4 -3
@@ -27,13 +27,14 @@ include $(TOPDIR)/config.mk LIB = $(obj)libnet.a -COBJS-y += net.o -COBJS-y += tftp.o COBJS-y += bootp.o -COBJS-y += rarp.o +COBJS-$(CONFIG_CMD_DNS) += dns.o COBJS-y += eth.o +COBJS-y += net.o COBJS-y += nfs.o +COBJS-y += rarp.o COBJS-$(CONFIG_CMD_SNTP) += sntp.o +COBJS-y += tftp.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
net/dns.c new file +211 -0
211 lines not on this page · raw message
net/dns.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* (C) Masami Komiya <[email protected]> 2005 +* Copyright 2009, Robin Getz <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2, or (at +* your option) any later version. +*/ + +#ifndef __DNS_H__ +#define __DNS_H__ + +#define DNS_SERVICE_PORT 53 +#define DNS_TIMEOUT 10000UL + +/* http://en.wikipedia.org/wiki/List_of_DNS_record_types */ +enum dns_query_type { +DNS_A_RECORD =0x01 , +DNS_CNAME_RECORD =0x05 , +DNS_MX_RECORD =0x0f , +}; + +/* +* DNS network packet +*/ +struct header { +uint16_t tid;/* Transaction ID */ +uint16_t flags;/* Flags */ +uint16_t nqueries;/* Questions */ +uint16_t nanswers;/* Answers */ +uint16_t nauth;/* Authority PRs */ +uint16_t nother;/* Other PRs */ +unsigned char data[1 ];/* Data, variable length */ +}; + +extern void DnsStart (void );/* Begin DNS */ + +#endif
net/net.c +29 -0
@@ -92,6 +92,9 @@#if defined(CONFIG_CDP_VERSION )#include <timestamp.h> #endif +#if defined(CONFIG_CMD_DNS ) +#include "dns.h" +#endif #if defined(CONFIG_CMD_NET )
@@ -291,6 +294,9 @@ NetInitLoop(proto_t protocol) NetServerIP =getenv_IPaddr ("serverip" ); NetOurNativeVLAN =getenv_VLAN ("nvlan" ); NetOurVLAN =getenv_VLAN ("vlan" ); +#if defined(CONFIG_CMD_DNS ) + NetOurDNSIP =getenv_IPaddr ("dnsip" ); +#endif env_changed_id = env_id; }
@@ -426,6 +435,11 @@ restart:SntpStart ();break ;#endif +#if defined(CONFIG_CMD_DNS ) +case DNS : +DnsStart (); +break ; +#endif default :break ; }
@@ -1518,6 +1532,14 @@ static int net_check_prereq (proto_t protocol) } goto common;#endif +#if defined(CONFIG_CMD_DNS ) +case DNS : +if (NetOurDNSIP ==0 ) { +puts ("*** ERROR: DNS server address not given\n" ); +return 1 ; + } + goto common; +#endif #if defined(CONFIG_CMD_NFS )case NFS :#endif
@@ -1681,6 +1703,16 @@ void copy_filename (char *dst, char *src, int size)#endif +#if defined(CONFIG_CMD_NFS ) || defined(CONFIG_CMD_SNTP ) || defined(CONFIG_CMD_DNS ) +/* +* make port a little random, but use something trivial to compute +*/ +unsigned int random_port (void ) +{ +return 1024 + (get_timer (0 ) %0x8000 );; +} +#endif +void ip_to_string (IPaddr_t x,char *s) { x =ntohl (x);
PATCH 1/1 v3 - add dns
Hi Robin,
Quoted 28 lines · Robin Getz
On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg10216.html
Quoted 7 lines
DNS can be enabled by setting
CFG_CMD_DNS. After performing a query, the serverip environment var is updated.Probably there are some cosmetic issues with the patch. Unfortunatly I do not have the time to correct these. So if anybody else likes DNS support in U-Boot and has the time, feel free to patch it in the main tree.
Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store the result in)
- add a randomport()function innet.c
- sortMakefilein ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for timeout)
- use built in functions (memcpy) rather than byte copy.
Quoted 3 lines
Signed-off-by Robin Getz <[email protected]>Signed-off-by Pieter Voorthuijsen <[email protected]>
Looks like I missed a pretty interesting discussion here. Anyway, patch V3 is applied to the net repo with some cosmetic changes to the changelog (no changes to the patch).
thanks,
Ben