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 Mon, Jun 04, 2007 at 02:46:17PM +0200, Hans Rosenfeld wrote:
> On Sun, Jun 03, 2007 at 07:29:13PM +0200, Andrew Lunn wrote:
> > 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.
> 
> net_io.c didn't compile, two #endif and a brace were missing.
> The opts array had to be extended, too, and I updated the usage string.

Thanks.

The attached patch has been committed to CVS.

    Andrew
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.254
diff -u -r1.254 ChangeLog
--- ChangeLog	2 Jun 2007 17:50:32 -0000	1.254
+++ ChangeLog	4 Jun 2007 20:29:48 -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: 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
--- cdl/redboot.cdl	19 Dec 2006 03:11:41 -0000	1.78
+++ cdl/redboot.cdl	4 Jun 2007 20:29:49 -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: 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
--- doc/redboot_cmds.sgml	15 Dec 2006 12:30:59 -0000	1.17
+++ doc/redboot_cmds.sgml	4 Jun 2007 20:29:52 -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: 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
--- include/redboot.h	20 Jul 2006 20:27:47 -0000	1.37
+++ include/redboot.h	4 Jun 2007 20:29:53 -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: 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
--- include/net/net.h	27 Jun 2005 18:17:37 -0000	1.20
+++ include/net/net.h	4 Jun 2007 20:29:53 -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: 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
--- src/net/bootp.c	1 Feb 2005 18:25:52 -0000	1.23
+++ src/net/bootp.c	4 Jun 2007 20:29:53 -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: 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
--- src/net/dns.c	7 Nov 2003 18:14:10 -0000	1.3
+++ src/net/dns.c	4 Jun 2007 20:29:53 -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: 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
--- src/net/net_io.c	19 Dec 2006 03:11:41 -0000	1.47
+++ src/net/net_io.c	4 Jun 2007 20:29:53 -0000
@@ -817,7 +817,10 @@
 
 static char usage[] = "[-b] [-l <local_ip_address>[/<mask_len>]] [-h <server_address>]"
 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS
-	" [-d <dns_server_address]"
+	" [-d <dns_server_address>]"
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN                                                  
+        " [-D <dns_domain_name>]" 
+#endif
 #endif
         ;
 
@@ -832,7 +835,7 @@
 void 
 do_ip_addr(int argc, char *argv[])
 {
-    struct option_info opts[4];
+    struct option_info opts[5];
     char *ip_addr, *host_addr;
     bool ip_addr_set, host_addr_set;
     bool do_bootp = false;
@@ -840,6 +843,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,8 +866,12 @@
     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
 #endif
-
     CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options");
 
     if (!scan_opts(argc, argv, 1, opts, num_opts, 0, 0, "")) {
@@ -907,6 +918,11 @@
     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
 #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]