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.


-- 
%SYSTEM-F-ANARCHISM, The operating system has been overthrown
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     1 Jun 2007 11:54:24 -0000
@@ -512,6 +512,25 @@
                       This option sets the IP of the default DNS. The IP can be
                       changed at runtime as well."
                 }
+
+                cdl_option CYGPKG_REDBOOT_NETWORKING_DNS_DOMAIN {
+                    display         "Default DNS domain"
+                    flavor          booldata
+                    active_if       !CYGSEM_REDBOOT_FLASH_CONFIG
+                    default_value   false
+                    description "
+                      This option sets the default DNS domain name."
+                }
+
+                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 CYGNUM_REDBOOT_NETWORKING_DNS_TIMEOUT {
                     display         "Timeout in DNS lookup"
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   1 Jun 2007 11:54:24 -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   1 Jun 2007 11:54:25 -0000
@@ -360,6 +360,8 @@
 #endif
 
 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS
+extern char __bootp_dns_domain[CYGNUM_REDBOOT_NETWORK_DNS_DOMAIN_BUFSIZE];
+extern cyg_bool __bootp_dns_domain_set;
 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     1 Jun 2007 11:54:26 -0000
@@ -303,6 +303,13 @@
                                memcpy(&__bootp_dns_addr, p, 4);
                                __bootp_dns_set = 1;
                                break;
+                            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
                             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       1 Jun 2007 11:54:26 -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,10 @@
 struct in_addr __bootp_dns_addr;
 cyg_bool __bootp_dns_set = false;
 
+/* DNS domain name possibly returned from bootp */
+char __bootp_dns_domain[CYGNUM_REDBOOT_NETWORK_DNS_DOMAIN_BUFSIZE];
+cyg_bool __bootp_dns_domain_set = false;
+
 struct sockaddr_in server;
 
 /* static buffers so we can make do without malloc */
@@ -240,7 +251,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;
     }
@@ -260,23 +273,34 @@
     /* 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) );
+        if(__bootp_dns_domain_set) 
+            setdomainname(__bootp_dns_domain, strlen(__bootp_dns_domain));
        s = 0;
     }
     else {
 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
     {
         ip_addr_t dns_ip;
+        char *dns_domain = NULL;
 
         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)
             return -1;
         memcpy(&server.sin_addr, &dns_ip, sizeof(dns_ip));
+
+        flash_get_config("dns_domain", &dns_domain, CONFIG_STRING);
+        if(dns_domain != NULL && dns_domain[0] != '\0')
+                setdomainname(dns_domain, strlen(dns_domain));
+
         /* server config is valid */
         s = 0;
     }
 #else
       // Use static configuration
        set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP));
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DOMAIN
+        setdomainname(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DOMAIN), 
strlen(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DOMAIN)));
+#endif
 #endif
     }
 

Reply via email to