]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Add cache_found_zone() function.
authorTed Lemon <source@isc.org>
Thu, 12 Oct 2000 08:58:11 +0000 (08:58 +0000)
committerTed Lemon <source@isc.org>
Thu, 12 Oct 2000 08:58:11 +0000 (08:58 +0000)
common/dns.c

index a7d808abfda2fca3f1fc16fad75a65d57e0126ea..ef423cef2209d22281706644a5b93ea5c4995008 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dns.c,v 1.28 2000/09/14 11:29:43 mellon Exp $ Copyright (c) 2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dns.c,v 1.29 2000/10/12 08:58:11 mellon Exp $ Copyright (c) 2000 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -396,6 +396,70 @@ void repudiate_zone (struct dns_zone **zone)
        (*zone) -> timeout = cur_time - 1;
        dns_zone_dereference (zone, MDL);
 }
+
+void cache_found_zone (ns_class class,
+                      char *zname, struct in_addr *addrs, int naddrs)
+{
+       isc_result_t status = ISC_R_NOTFOUND;
+       const char *np;
+       struct dns_zone *zone = (struct dns_zone *)0;
+       struct data_string nsaddrs;
+       int ix = strlen (zname);
+
+       if (zname [ix - 1] == '.')
+               ix = 0;
+
+       /* See if there's already such a zone. */
+       if (dns_zone_lookup (&zone, np) == ISC_R_SUCCESS) {
+               /* If it's not a dynamic zone, leave it alone. */
+               if (!zone -> timeout)
+                       return;
+               /* Address may have changed, so just blow it away. */
+               if (zone -> primary)
+                       option_cache_dereference (&zone -> primary, MDL);
+               if (zone -> secondary)
+                       option_cache_dereference (&zone -> secondary, MDL);
+       }
+
+       if (!dns_zone_allocate (&zone, MDL))
+               return;
+
+       if (!zone -> name) {
+               zone -> name =
+                       dmalloc (strlen (zname) + 1 + (ix != 0), MDL);
+               if (!zone -> name) {
+                       dns_zone_dereference (&zone, MDL);
+                       return;
+               }
+               strcpy (zone -> name, zname);
+               /* Add a trailing '.' if it was missing. */
+               if (ix) {
+                       zone -> name [ix] = '.';
+                       zone -> name [ix + 1] = 0;
+               }
+       }
+
+       /* XXX Need to get the lower-level code to push the actual zone
+          XXX TTL up to us. */
+       zone -> timeout = cur_time + 1800;
+       
+       if (!option_cache_allocate (&zone -> primary, MDL)) {
+               dns_zone_dereference (&zone, MDL);
+               return;
+       }
+       if (!buffer_allocate (&zone -> primary -> data.buffer,
+                             naddrs * sizeof (struct in_addr), MDL)) {
+               dns_zone_dereference (&zone, MDL);
+               return;
+       }
+       memcpy (zone -> primary -> data.buffer -> data,
+               addrs, naddrs * sizeof *addrs);
+       zone -> primary -> data.data =
+               &zone -> primary -> data.buffer -> data [0];
+       zone -> primary -> data.len = naddrs * sizeof *addrs;
+
+       enter_dns_zone (zone);
+}
 #endif /* NSUPDATE */
 
 HASH_FUNCTIONS (dns_zone, const char *, struct dns_zone)