Home | History | Annotate | Line # | Download | only in dist
      1 /*
      2  * ixfrcreate.h -- generating IXFR differences from zonefiles.
      3  *
      4  * Copyright (c) 2021, NLnet Labs. All rights reserved.
      5  *
      6  * See LICENSE for the license.
      7  *
      8  */
      9 
     10 #ifndef IXFRCREATE_H
     11 #define IXFRCREATE_H
     12 #include "dns.h"
     13 struct zone;
     14 struct nsd;
     15 
     16 /* the ixfr create data structure while the ixfr difference from zone files
     17  * is created. */
     18 struct ixfr_create {
     19 	/* the old serial and new serial */
     20 	uint32_t old_serial, new_serial;
     21 	/* the file with the spooled old zone data */
     22 	char* file_name;
     23 	/* zone name in uncompressed wireformat */
     24 	uint8_t* zone_name;
     25 	/* length of zone name */
     26 	size_t zone_name_len;
     27 	/* max size of ixfr in bytes */
     28 	size_t max_size;
     29 	/* we are in checkzone, errors should go to the console, not to the
     30 	 * serverlog */
     31 	int errorcmdline;
     32 };
     33 
     34 /* start ixfr creation */
     35 struct ixfr_create* ixfr_create_start(struct zone* zone, const char* zfile,
     36 	uint64_t ixfr_size, int errorcmdline);
     37 
     38 /* free ixfr create */
     39 void ixfr_create_free(struct ixfr_create* ixfrcr);
     40 
     41 /* create the IXFR from differences. The old zone is spooled to file
     42  * and the new zone is in memory now.
     43  * With append_mem it does not only write to file but sticks it into the
     44  * memory lookup structure for IXFRs used by the server. */
     45 int ixfr_create_perform(struct ixfr_create* ixfrcr, struct zone* zone,
     46 	int append_mem, struct nsd* nsd, const char* zfile,
     47 	uint32_t ixfr_number);
     48 
     49 /* cancel ixfrcreation, that was started, but not performed yet.
     50  * It removes the temporary file. */
     51 void ixfr_create_cancel(struct ixfr_create* ixfrcr);
     52 
     53 /* returns true if ixfr should be created by taking difference between
     54  * zone file contents. Also checks if ixfr is enabled for the zone. */
     55 int ixfr_create_from_difference(struct zone* zone, const char* zfile,
     56 	int* ixfr_create_already_done_flag);
     57 
     58 /* readup existing file if it already exists */
     59 void ixfr_readup_exist(struct zone* zone, struct nsd* nsd, const char* zfile);
     60 
     61 /*
     62  * Structure to keep track of spool domain name iterator.
     63  * This reads from the spool file and steps over the domain name
     64  * elements one by one. It keeps track of: is the first one read yet,
     65  * are we at end nothing more, is the element processed yet that is
     66  * current read into the buffer?
     67  */
     68 struct spool_dname_iterator {
     69 	/* the domain name that has recently been read, but can be none
     70 	 * if before first or after last. */
     71 	uint8_t dname[MAXDOMAINLEN+1];
     72 	/* length of the dname, if one is read, otherwise 0 */
     73 	size_t dname_len;
     74 	/* if we are before the first element, hence nothing is read yet */
     75 	int read_first;
     76 	/* if we are after the last element, nothing to read, end of file */
     77 	int eof;
     78 	/* is the element processed that is currently in dname? */
     79 	int is_processed;
     80 	/* the file to read from */
     81 	FILE* spool;
     82 	/* filename for error printout */
     83 	char* file_name;
     84 };
     85 
     86 #endif /* IXFRCREATE_H */
     87