]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Sorting seems off
authorMiek Gieben <miekg@NLnetLabs.nl>
Tue, 13 Dec 2005 12:52:30 +0000 (12:52 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Tue, 13 Dec 2005 12:52:30 +0000 (12:52 +0000)
ldns-zonesplit finaly works correctly

Changelog
dname.c
examples/ldns-splitzone.c
rdata.c
zone.c

index e05b6a9213f508d9e4828668e509d7a890151876..b7cf087d70e9feaf0dcac71cc6fde2a9a79fcd5b 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -5,6 +5,9 @@ December??? 2005: 1.0.1: ldns-team
        * Starting usage of assert throughout the library to catch illegal calls
        * Solaris 9 testing was carried out. Ldns now compiles on that
          platform; some gnuism were identified and fixed.
+       * The ldns_zone structure was stress tested. The current setup
+        (ie. just a list of rrs) can scale to zone file in order of
+        megabytes. Sorting such zone is still difficult.
 
        Drill:
        * -r was killed in favor of -o <header bit mnemonic> which 
@@ -21,6 +24,7 @@ December??? 2005: 1.0.1: ldns-team
        
        Code:
        * All networking code was moved to net.c
+       * rdata.c: added asserts to the rdf set/get functions
 
        API:
        Changed:
diff --git a/dname.c b/dname.c
index de73d40004898167378865842ccb19e13eb9bd95..db82e8d7fff22fd1b26fe8c5c5f12c63b37c5c4a 100644 (file)
--- a/dname.c
+++ b/dname.c
@@ -225,8 +225,20 @@ ldns_dname_compare(const ldns_rdf *dname1, const ldns_rdf *dname2)
        /* see RFC4034 for this algorithm */
        /* this algorithm assumes the names are normalized to case */
 
+        /* only when both are not NULL we can say anything about them */
+        if (!dname1 && !dname2) {
+                return 0;
+        }
+        if (!dname1 || !dname2) {
+                return -1;
+        }
+       /* asserts must happen later as we are looking in the
+        * dname, which could be NULL. But this case is handled
+        * above
+        */
        assert(ldns_rdf_get_type(dname1) == LDNS_RDF_TYPE_DNAME);
        assert(ldns_rdf_get_type(dname2) == LDNS_RDF_TYPE_DNAME);
+
        
        lc1 = ldns_dname_label_count(dname1);
        lc2 = ldns_dname_label_count(dname2);
index ae40aec5cc54774c43c8f4f56f5a50b9d307441e..e700f095f0bec506c4c027418f056dbec7b2a241 100644 (file)
 #include <errno.h>
 #include <ldns/dns.h>
 
-#define DEFAULT_SPLIT  1000
+#define DEFAULT_SPLIT  500
 #define FILE_SIZE      255
+#define SPLIT_MAX      999 
+#define NO_SPLIT       0
+#define INTENT_TO_SPLIT 1
+#define SPLIT_NOW      2
 
 void
 usage(FILE *f, char *progname)
@@ -31,6 +35,30 @@ usage(FILE *f, char *progname)
                fprintf(f, "-o ORIGIN\tUse this as initial origin. For zones starting with @\n");
 }
 
+
+FILE *
+open_newfile(char *basename, ldns_zone *z, size_t counter)
+{
+       char filename[FILE_SIZE];
+       FILE *fp;
+
+       if (counter > SPLIT_MAX)  {
+               printf("maximum splits reached %d\n", counter);
+               return NULL;
+       }
+
+       snprintf(filename, FILE_SIZE, "%s.%03d", basename, counter);
+
+       if (!(fp = fopen(filename, "w"))) {
+               printf("cannot open %s\n", filename);
+               return NULL;
+       } else {
+               printf("Opening %s\n", filename);
+       }
+       ldns_rr_print(fp, ldns_zone_soa(z));
+       return fp;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -45,13 +73,14 @@ main(int argc, char **argv)
        size_t i;
        int splitting;
        size_t file_counter;
-       char filename[255];
        ldns_rdf *origin = NULL;
+       ldns_rdf *current_rdf;
+       ldns_rr *current_rr;
 
        progname = strdup(argv[0]);
        split = 0;
-       splitting = 0; /* when true we are about to split */
-       file_counter = 1;
+       splitting = NO_SPLIT; 
+       file_counter = 0;
        lastname = NULL;
 
        while ((c = getopt(argc, argv, "n:o:")) != -1) {
@@ -105,52 +134,51 @@ main(int argc, char **argv)
                printf("Zone could not be parsed\n");
                exit(EXIT_FAILURE);
        }
-       ldns_zone_sort(z);
+       /* ldns_zone_sort(z); ASSUME SORTED ZONE */ 
 
        /* no RRsets may be truncated */
        zrrs = ldns_zone_rrs(z);
        
        /* Setup */
-#if 0
-       snprintf(filename, FILE_SIZE, "%s.%d", argv[0], file_counter);
-       fp = fopen(filename, "w");
-       if (!fp) {
-               printf("whaahah\n");
-               exit(EXIT_FAILURE);
+       if (!(fp = open_newfile(argv[0], z, file_counter))) {
+                       exit(EXIT_FAILURE);
        }
-       ldns_rr_print(fp, ldns_zone_soa(z));
-#endif
 
        for(i = 0; i < ldns_rr_list_rr_count(zrrs); i++) {
        
-               ldns_rr_print(stdout, 
-                               ldns_rr_list_rr(zrrs, i));
+               current_rr = ldns_rr_list_rr(zrrs, i);
+               current_rdf = ldns_rr_owner(current_rr);
 
-#if 0
                if (i > 0 && (i % split) == 0) {
-                       printf("%d %d\n", i, (i & split));
-                       splitting = 1;
+                       splitting = INTENT_TO_SPLIT;
                }
 
-               if (splitting == 1 && 
-                               ldns_dname_compare(ldns_rr_owner(ldns_rr_list_rr(zrrs, i)), lastname) == 0) {
-                       /* equal names, don't split yet */
-               } else {
-                       /* now we are ready to split */
-                       splitting = 2;
+               if (splitting == INTENT_TO_SPLIT) { 
+                       if (ldns_dname_compare(current_rdf, lastname) != 0) {
+                               splitting = SPLIT_NOW;
+                       } 
+                       /* else: do nothing */
                }
-               if (splitting == 2) {
+
+               if (splitting == SPLIT_NOW) {
+                       fclose(fp);
+
                        /* SPLIT */
-                       printf("LDNS INTENT TO SPLIT !!!! \n");
                        lastname = NULL;
-                       continue;
+                       splitting = NO_SPLIT;
+                       file_counter++;
+                       if (!(fp = open_newfile(argv[0], z, file_counter))) {
+                               exit(EXIT_FAILURE);
+                       }
+                       ldns_rr_print(fp, current_rr); 
+               }
+
+               if (splitting == NO_SPLIT || splitting == INTENT_TO_SPLIT) {
+                       ldns_rr_print(fp, current_rr);
                }
-               
-               lastname = ldns_rr_owner(ldns_rr_list_rr(zrrs, i));
-#endif
+               lastname = current_rdf;
        }
-/*     fclose(fp); */
+       fclose(fp); 
 
-       
         exit(EXIT_SUCCESS);
 }
diff --git a/rdata.c b/rdata.c
index c28fcf349a461c7f17d2323b087137a18910cf98..59001337ba8b63e59c3936c478beb41882f84ad3 100644 (file)
--- a/rdata.c
+++ b/rdata.c
 size_t
 ldns_rdf_size(const ldns_rdf *rd)
 {
+       assert(rd != NULL);
        return rd->_size;
 }
 
 ldns_rdf_type
 ldns_rdf_get_type(const ldns_rdf *rd)
 {
+       assert(rd != NULL);
        return rd->_type;
 }
 
 uint8_t *
 ldns_rdf_data(const ldns_rdf *rd)
 {
+       assert(rd != NULL);
        return rd->_data;
 }
 
@@ -46,12 +49,14 @@ ldns_rdf_data(const ldns_rdf *rd)
 void
 ldns_rdf_set_size(ldns_rdf *rd, size_t s)
 {
+       assert(rd != NULL);
        rd->_size = s;
 }
 
 void
 ldns_rdf_set_type(ldns_rdf *rd, ldns_rdf_type t)
 {
+       assert(rd != NULL);
        rd->_type = t;
 }
 
@@ -59,6 +64,7 @@ void
 ldns_rdf_set_data(ldns_rdf *rd, void *d)
 {
        /* only copy the pointer */
+       assert(rd != NULL);
        rd->_data = d;
 }
 
@@ -504,17 +510,13 @@ ldns_rdf_compare(const ldns_rdf *rd1, const ldns_rdf *rd2)
        uint16_t i1, i2, i;
        uint8_t *d1, *d2;
 
-       /* only when both are NULL we can say anything about them */
+       /* only when both are not NULL we can say anything about them */
        if (!rd1 && !rd2) {
                return 0;
        }
-       if (!rd1) {
+       if (!rd1 || !rd2) {
                return -1;
        }
-       if (!rd2) {
-               return 1;
-       }
-       
        i1 = ldns_rdf_size(rd1);
        i2 = ldns_rdf_size(rd1);
 
diff --git a/zone.c b/zone.c
index 8fefe9f6eea908a379b91ebce5126bc0324890fa..dbcc4a872f03354ed33ee5dee0caaab945d30f91 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -261,6 +261,8 @@ ldns_zone_sort_oct(ldns_zone *zone)
        ldns_rr_list *zrr;
        assert(zone != NULL);
 
+#warning "Sorting seems off, dnssec-signzone differs"
+
        zrr = ldns_zone_rrs(zone);
        ldns_rr_list_sort_oct(zrr);
 }
@@ -271,6 +273,8 @@ ldns_zone_sort(ldns_zone *zone)
        ldns_rr_list *zrr;
        assert(zone != NULL);
 
+#warning "Sorting seems off, dnssec-signzone differs"
+
        zrr = ldns_zone_rrs(zone);
        ldns_rr_list_sort(zrr);
 }