From: Miek Gieben Date: Tue, 13 Dec 2005 12:52:30 +0000 (+0000) Subject: Sorting seems off X-Git-Tag: release-1.1.0~519 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=581ba9359b97bdec645158152b4bdc46da276163;p=thirdparty%2Fldns.git Sorting seems off ldns-zonesplit finaly works correctly --- diff --git a/Changelog b/Changelog index e05b6a92..b7cf087d 100644 --- 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
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 de73d400..db82e8d7 100644 --- 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); diff --git a/examples/ldns-splitzone.c b/examples/ldns-splitzone.c index ae40aec5..e700f095 100644 --- a/examples/ldns-splitzone.c +++ b/examples/ldns-splitzone.c @@ -18,8 +18,12 @@ #include #include -#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 c28fcf34..59001337 100644 --- a/rdata.c +++ b/rdata.c @@ -27,18 +27,21 @@ 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 8fefe9f6..dbcc4a87 100644 --- 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); }