This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RedBoot patch to support a DNS domain name


On Fri, Jun 01, 2007 at 01:57:48PM +0200, Hans Rosenfeld wrote:
> The attached patch adds support for a DNS domain name to RedBoot.
> The domain name can be set at compile time, configured with fconfig or
> received from a BOOTP/DHCP server.

Hi Hans

Thanks for you patch. I've spent a little time rearranging it a little
and added more CDL to control it. I also extended the ip_address
command with a new flag, -D <domain> for setting the domain name.

Im away from home at the moment, so don't have any hardware to test
with. I know this code compiles in different configurations, but
please could you test it.

       Thanks

          Andrew
? redboot/current/doc/aaed2000.html
? redboot/current/doc/alias-command.html
? redboot/current/doc/assabet.html
? redboot/current/doc/at91.html
? redboot/current/doc/at91jtst.html
? redboot/current/doc/atlas.html
? redboot/current/doc/baudrate-command.html
? redboot/current/doc/brutus.html
? redboot/current/doc/cache-command.html
? redboot/current/doc/calmrisc16.html
? redboot/current/doc/calmrisc32.html
? redboot/current/doc/cerfcube.html
? redboot/current/doc/channel-command.html
? redboot/current/doc/cksum-command.html
? redboot/current/doc/common-commands.html
? redboot/current/doc/configuring-the-redboot-environment.html
? redboot/current/doc/disks-command.html
? redboot/current/doc/download-command.html
? redboot/current/doc/dump-command.html
? redboot/current/doc/e7t.html
? redboot/current/doc/ebsa285.html
? redboot/current/doc/edb7xxx.html
? redboot/current/doc/edk7708.html
? redboot/current/doc/excaliburarm9.html
? redboot/current/doc/exec-command.html
? redboot/current/doc/executing-programs.html
? redboot/current/doc/filesystem-commands.html
? redboot/current/doc/fis-create-command.html
? redboot/current/doc/fis-delete-command.html
? redboot/current/doc/fis-erase-command.html
? redboot/current/doc/fis-free-command.html
? redboot/current/doc/fis-init-command.html
? redboot/current/doc/fis-list-command.html
? redboot/current/doc/fis-load-command.html
? redboot/current/doc/fis-lock-command.html
? redboot/current/doc/fis-unlock-command.html
? redboot/current/doc/fis-write-command.html
? redboot/current/doc/flash-image-system.html
? redboot/current/doc/frv400.html
? redboot/current/doc/fs-cd-command.html
? redboot/current/doc/fs-del-command.html
? redboot/current/doc/fs-deldir-command.html
? redboot/current/doc/fs-info-command.html
? redboot/current/doc/fs-list-command.html
? redboot/current/doc/fs-mkdir-command.html
? redboot/current/doc/fs-mount-command.html
? redboot/current/doc/fs-move-command.html
? redboot/current/doc/fs-umount-command.html
? redboot/current/doc/fs-write-command.html
? redboot/current/doc/getting-started-with-redboot.html
? redboot/current/doc/go-command.html
? redboot/current/doc/grg.html
? redboot/current/doc/gunzip-command.html
? redboot/current/doc/help-command.html
? redboot/current/doc/hs7729pci.html
? redboot/current/doc/installation-and-testing.html
? redboot/current/doc/installing-redboot.html
? redboot/current/doc/integrator.html
? redboot/current/doc/iopeek-command.html
? redboot/current/doc/iopoke-command.html
? redboot/current/doc/ip-address-command.html
? redboot/current/doc/ipaq.html
? redboot/current/doc/iq80310.html
? redboot/current/doc/iq80321.html
? redboot/current/doc/ixdp425.html
? redboot/current/doc/malta.html
? redboot/current/doc/mb93091.html
? redboot/current/doc/mb93093.html
? redboot/current/doc/mbx.html
? redboot/current/doc/mcmp-command.html
? redboot/current/doc/mcopy-command.html
? redboot/current/doc/mfill-command.html
? redboot/current/doc/nano.html
? redboot/current/doc/ocelot.html
? redboot/current/doc/persistent-state-flash.html
? redboot/current/doc/pid.html
? redboot/current/doc/ping-command.html
? redboot/current/doc/prpmc1100.html
? redboot/current/doc/rebuilding-redboot.html
? redboot/current/doc/redboot-command-history.html
? redboot/current/doc/redboot-commands-and-examples.html
? redboot/current/doc/redboot-editing-commands.html
? redboot/current/doc/redboot-guide.html
? redboot/current/doc/reset-command.html
? redboot/current/doc/resource-usage.html
? redboot/current/doc/sa1100mm.html
? redboot/current/doc/se7709.html
? redboot/current/doc/se7751.html
? redboot/current/doc/se77x9.html
? redboot/current/doc/startup-mode.html
? redboot/current/doc/updating-redboot.html
? redboot/current/doc/user-interface.html
? redboot/current/doc/version-command.html
? redboot/current/doc/viper.html
? redboot/current/doc/vrc4375.html
? redboot/current/doc/x86pc.html
Index: redboot/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.254
diff -u -r1.254 ChangeLog
--- redboot/current/ChangeLog	2 Jun 2007 17:50:32 -0000	1.254
+++ redboot/current/ChangeLog	3 Jun 2007 17:26:36 -0000
@@ -1,3 +1,14 @@
+2007-06-03  Andrew Lunn <andrew.lunn@ascom.ch>
+
+	*src/net/net_io.c: (do_ip_addr): Option to set domain name.
+	* doc/redboot_cmds.sgml: Document new option.
+	
+2007-06-03  Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
+
+	* cdl/redboot.cdl: CDL to control the use of DNS domain name.
+	* src/net/bootp.c: Get the domain name from the reply.
+	* src/net/dns.c: Domain name from CDL, fconfig and DHCP.
+	
 2007-06-02  Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
 
 	* src/flash.c: (fis_list): fis list will now list an image
Index: redboot/current/cdl/redboot.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/cdl/redboot.cdl,v
retrieving revision 1.78
diff -u -r1.78 redboot.cdl
--- redboot/current/cdl/redboot.cdl	19 Dec 2006 03:11:41 -0000	1.78
+++ redboot/current/cdl/redboot.cdl	3 Jun 2007 17:26:37 -0000
@@ -512,7 +512,7 @@
                       This option sets the IP of the default DNS. The IP can be
                       changed at runtime as well."
                 }
-    
+
                 cdl_option CYGNUM_REDBOOT_NETWORKING_DNS_TIMEOUT {
                     display         "Timeout in DNS lookup"
                     flavor          data
@@ -522,6 +522,55 @@
                       address via the DNS. Default is 10 seconds."
                 }
     
+                cdl_component CYGPKG_REDBOOT_NETWORKING_DNS_WITH_DOMAIN {
+                    display         "Support the use of a domain name"
+                    flavor          bool
+                    default_value   0
+                    description     "
+                       This option controls if Redboot supports domain
+                       names when performing DNS lookups"
+                       
+                    cdl_option    CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN {
+                        display         "Default DNS domain"
+                        flavor          booldata
+                        default_value   0
+                        description "
+                            This option sets the default DNS domain name.
+                            This value will be overwritten by the value in
+                            flash or a domain returned by DHCP"
+                    }
+
+                    cdl_option    CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN {
+                        display         "Get DNS domain from Flash"
+                        flavor          bool
+                        active_if       CYGSEM_REDBOOT_FLASH_CONFIG
+                        default_value   0
+                        description "
+                            This option enables getting the domain name 
+                            from the flash configuration. This can later be 
+                            overwritten by a value learnt from DHCP"
+                    }
+
+                    cdl_option    CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN {
+                        display         "Use DNS domain from DHCP"
+                        flavor          bool
+                        default_value   0
+                        description "
+                            This option enables the use of the domain name
+                            returned by DHCP."
+                    }
+
+                    cdl_option CYGNUM_REDBOOT_NETWORK_DNS_DOMAIN_BUFSIZE {
+                        display         "BOOTP/DHCP DNS domain buffer size"
+                        flavor          data
+                        default_value   32
+                        description "
+                           This options sets the size of the static
+                           buffer used by BOOTP/DHCP to store the DNS
+                           domain name. The domain name will not be
+                           set if the buffer is too small to hold it."
+                    }
+                }
             }
 
 	    cdl_option CYGDAT_REDBOOT_DEFAULT_NETWORK_DEVICE {
Index: redboot/current/doc/redboot_cmds.sgml
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/doc/redboot_cmds.sgml,v
retrieving revision 1.17
diff -u -r1.17 redboot_cmds.sgml
--- redboot/current/doc/redboot_cmds.sgml	15 Dec 2006 12:30:59 -0000	1.17
+++ redboot/current/doc/redboot_cmds.sgml	3 Jun 2007 17:26:39 -0000
@@ -1245,28 +1245,35 @@
 Display the current network settings. 
 <screen> 
 RedBoot> <userinput>ip_address</userinput> 
-IP: 192.168.1.31, Default server: 192.168.1.101, DNS server IP: 0.0.0.0 
+IP: 192.168.1.31, Default server: 192.168.1.101, DNS server IP: 0.0.0.0, DNS domain name:  
 </screen> 
 </para>
 <para>
 Change the DNS server address. 
 <screen> 
 RedBoot> <userinput>ip_address -d 192.168.1.101</userinput> 
-IP: 192.168.1.31, Default server: 192.168.1.101, DNS server IP: 192.168.1.101 
+IP: 192.168.1.31, Default server: 192.168.1.101, DNS server IP: 192.168.1.101, DNS domain name:  
+</screen> 
+</para>
+<para>
+Change the DNS domain name. 
+<screen> 
+RedBoot> <userinput>ip_address -D example.com</userinput> 
+IP: 192.168.1.31, Default server: 192.168.1.101, DNS server IP: 192.168.1.101, DNS domain name: example.com 
 </screen> 
 </para>
 <para>
 Change the default server address. 
 <screen> 
 RedBoot> <userinput>ip_address -h 192.168.1.104</userinput> 
-IP: 192.168.1.31, Default server: 192.168.1.104, DNS server IP: 192.168.1.101
+IP: 192.168.1.31, Default server: 192.168.1.104, DNS server IP: 192.168.1.101, DNS domain name: 
 </screen>
 </para>
 <para>
 Set the IP address to something new, with a 255.255.255.0 netmask
 <screen> 
 RedBoot> <userinput>ip_address -l 192.168.1.32/24</userinput> 
-IP: 192.168.1.32, Default server: 192.168.1.104, DNS server IP: 192.168.1.101
+IP: 192.168.1.32, Default server: 192.168.1.104, DNS server IP: 192.168.1.101, DNS domain name: 
 </screen>
       </para>
     </refsect1>
@@ -3700,6 +3707,7 @@
 Local IP address: 192.168.1.29
 Default server IP address: 192.168.1.101
 DNS server IP address: 192.168.1.1
+DNS domain name: example.com
 GDB connection port: 9000
 Network debug at boot time: false
 </screen></para>
Index: redboot/current/include/redboot.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/include/redboot.h,v
retrieving revision 1.37
diff -u -r1.37 redboot.h
--- redboot/current/include/redboot.h	20 Jul 2006 20:27:47 -0000	1.37
+++ redboot/current/include/redboot.h	3 Jun 2007 17:26:40 -0000
@@ -350,6 +350,7 @@
 externC void set_dns(char* new_ip);
 externC void show_dns(void);
 externC struct hostent *gethostbyname(const char *host);
+externC int setdomainname(const char *, size_t);
 
 // Error reporting
 externC int h_errno;
Index: redboot/current/include/net/net.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/include/net/net.h,v
retrieving revision 1.20
diff -u -r1.20 net.h
--- redboot/current/include/net/net.h	27 Jun 2005 18:17:37 -0000	1.20
+++ redboot/current/include/net/net.h	3 Jun 2007 17:26:40 -0000
@@ -360,6 +360,10 @@
 #endif
 
 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN
+extern char __bootp_dns_domain[CYGNUM_REDBOOT_NETWORK_DNS_DOMAIN_BUFSIZE];
+extern cyg_bool __bootp_dns_domain_set;
+#endif
 extern struct in_addr __bootp_dns_addr;
 extern cyg_bool __bootp_dns_set;
 #endif
Index: redboot/current/src/net/bootp.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/bootp.c,v
retrieving revision 1.23
diff -u -r1.23 bootp.c
--- redboot/current/src/net/bootp.c	1 Feb 2005 18:25:52 -0000	1.23
+++ redboot/current/src/net/bootp.c	3 Jun 2007 17:26:41 -0000
@@ -303,7 +303,18 @@
 				memcpy(&__bootp_dns_addr, p, 4);
 				__bootp_dns_set = 1;
 				break;
-#endif
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN
+                            case TAG_DOMAIN_NAME:
+                                if(optlen < sizeof(__bootp_dns_domain)) {
+                                    memcpy(__bootp_dns_domain, p, optlen);
+                                    __bootp_dns_domain[optlen] = '\0';
+                                    __bootp_dns_domain_set = 1;
+                                } else {
+                                  diag_printf("DNS domain name too long\n");
+                                }
+                                break;
+#endif //CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN
+#endif //CYGPKG_REDBOOT_NETWORKING_DNS
                             default:
                                 break;
                             }
Index: redboot/current/src/net/dns.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/dns.c,v
retrieving revision 1.3
diff -u -r1.3 dns.c
--- redboot/current/src/net/dns.c	7 Nov 2003 18:14:10 -0000	1.3
+++ redboot/current/src/net/dns.c	3 Jun 2007 17:26:41 -0000
@@ -73,6 +73,13 @@
                       CONFIG_IP,
                       0
     );
+
+RedBoot_config_option("DNS domain name",
+                      dns_domain,
+                      ALWAYS_ENABLED, true,
+                      CONFIG_STRING,
+                      0
+        );
 #endif
 
 /* So we remember which ports have been used */
@@ -87,6 +94,12 @@
 struct in_addr __bootp_dns_addr;
 cyg_bool __bootp_dns_set = false;
 
+/* DNS domain name possibly returned from bootp */
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN
+char __bootp_dns_domain[CYGNUM_REDBOOT_NETWORK_DNS_DOMAIN_BUFSIZE];
+cyg_bool __bootp_dns_domain_set = false;
+#endif
+
 struct sockaddr_in server;
 
 /* static buffers so we can make do without malloc */
@@ -240,7 +253,9 @@
 void
 show_dns(void)
 {
-    diag_printf(", DNS server IP: %s", inet_ntoa((in_addr_t *)&server.sin_addr));
+    diag_printf("\nDNS server IP: %s, DNS domain name: %s", 
+                inet_ntoa((in_addr_t *)&server.sin_addr),
+                domainname);
     if (0 == server.sin_addr.s_addr) {
         s = -1;
     }
@@ -251,16 +266,41 @@
 int  
 redboot_dns_res_init(void)
 {
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN
+  char *dns_domain = NULL;
+#endif
     memset((char *)&server, 0, sizeof(server));
     server.sin_len = sizeof(server);
     server.sin_family = AF_INET;
     server.sin_port = htons(DOMAIN_PORT);
     cyg_drv_mutex_init(&dns_mutex);
 
-    /* If we got a DNS server address from the DHCP/BOOTP, then use that address */
+    /* Set the default DNS domain first, so that it can be overwritten
+       latter */
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN
+        setdomainname(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN), 
+                      strlen(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN)));
+#endif
+        /* Set the domain name from flash so that DHCP can later
+           overwrite it. */
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN
+        flash_get_config("dns_domain", &dns_domain, CONFIG_STRING);
+        if(dns_domain != NULL && dns_domain[0] != '\0')
+                setdomainname(dns_domain, strlen(dns_domain));
+#endif
+
+    /* If we got a DNS server address from the DHCP/BOOTP, then use
+       that address */
     if ( __bootp_dns_set ) {
-	memcpy(&server.sin_addr, &__bootp_dns_addr, sizeof(__bootp_dns_addr) );
-	s = 0;
+	memcpy(&server.sin_addr, &__bootp_dns_addr, 
+               sizeof(__bootp_dns_addr) );
+    
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN        
+        if(__bootp_dns_domain_set) 
+            setdomainname(__bootp_dns_domain, strlen(__bootp_dns_domain));
+#endif
+        /* server config is valid */
+        s = 0; 
     }
     else {
 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
@@ -268,15 +308,17 @@
         ip_addr_t dns_ip;
 
         flash_get_config("dns_ip", &dns_ip, CONFIG_IP);
-        if (dns_ip[0] == 0 && dns_ip[1] == 0 && dns_ip[2] == 0 && dns_ip[3] == 0)
+        if (dns_ip[0] == 0 && dns_ip[1] == 0 && 
+            dns_ip[2] == 0 && dns_ip[3] == 0)
             return -1;
         memcpy(&server.sin_addr, &dns_ip, sizeof(dns_ip));
         /* server config is valid */
         s = 0;
     }
 #else
-      // Use static configuration
-	set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP));
+    // Use static configuration. If CYGPKG_REDBOOT_NETWORKING_DNS_IP
+    // is valid s will set set as a side effect.
+    set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP));
 #endif
     }
 
Index: redboot/current/src/net/net_io.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/net_io.c,v
retrieving revision 1.47
diff -u -r1.47 net_io.c
--- redboot/current/src/net/net_io.c	19 Dec 2006 03:11:41 -0000	1.47
+++ redboot/current/src/net/net_io.c	3 Jun 2007 17:26:41 -0000
@@ -840,6 +840,10 @@
 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS
     char *dns_addr;
     bool dns_addr_set;
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN 
+    char *dns_domain;
+    bool dns_domain_set;
+#endif
 #endif
     int num_opts;
  
@@ -859,6 +863,10 @@
     init_opts(&opts[num_opts], 'd', true, OPTION_ARG_TYPE_STR, 
               (void *)&dns_addr, (bool *)&dns_addr_set, "DNS server address");
     num_opts++;
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN 
+    init_opts(&opts[num_opts], 'D', true, OPTION_ARG_TYPE_STR, 
+              (void *)&dns_domain, (bool *)&dns_domain_set, "DNS domain");
+    num_opts++;
 #endif
 
     CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options");
@@ -907,6 +915,9 @@
     if (dns_addr_set) {
         set_dns(dns_addr);
     }
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN 
+    if (dns_domain_set) {
+      setdomainname(dns_domain, strlen(dns_domain));
 #endif
     show_addrs();
     if (!have_net) {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]