Home | History | Annotate | Line # | Download | only in dist
      1 /*
      2  * difffile.h - nsd.diff file handling header file. Read/write diff files.
      3  *
      4  * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
      5  *
      6  * See LICENSE for the license.
      7  *
      8  */
      9 #ifndef DIFFFILE_H
     10 #define DIFFFILE_H
     11 
     12 #include "rbtree.h"
     13 #include "namedb.h"
     14 #include "options.h"
     15 #include "udb.h"
     16 struct nsd;
     17 struct nsdst;
     18 struct ixfr_store;
     19 
     20 #define DIFF_PART_XXFR ('X'<<24 | 'X'<<16 | 'F'<<8 | 'R')
     21 #define DIFF_PART_XFRF ('X'<<24 | 'F'<<16 | 'R'<<8 | 'F')
     22 
     23 #define DIFF_NOT_COMMITTED (0u) /* XFR not (yet) committed to disk */
     24 #define DIFF_COMMITTED (1u<<0) /* XFR committed to disk */
     25 #define DIFF_CORRUPT (1u<<1) /* XFR corrupt */
     26 #define DIFF_INCONSISTENT (1u<<2) /* IXFR cannot be applied */
     27 #define DIFF_VERIFIED (1u<<3) /* XFR already verified */
     28 
     29 /* write an xfr packet data to the diff file, type=IXFR.
     30    The diff file is created if necessary, with initial header(notcommitted). */
     31 void diff_write_packet(const char* zone, const char* pat, uint32_t old_serial,
     32 	uint32_t new_serial, uint32_t seq_nr, uint8_t* data, size_t len,
     33 	struct nsd* nsd, uint64_t filenumber);
     34 
     35 /*
     36  * Overwrite header of diff file with committed vale and other data.
     37  * append log string.
     38  */
     39 void diff_write_commit(const char* zone, uint32_t old_serial,
     40 	uint32_t new_serial, uint32_t num_parts, uint8_t commit,
     41 	const char* log_msg, struct nsd* nsd, uint64_t filenumber);
     42 
     43 /*
     44  * Overwrite committed value of diff file with discarded to ensure diff
     45  * file is not reapplied on reload.
     46  */
     47 void diff_update_commit(const char* zone,
     48 	uint8_t commit, struct nsd* nsd, uint64_t filenumber);
     49 
     50 /*
     51  * These functions read parts of the diff file.
     52  */
     53 int diff_read_32(FILE *in, uint32_t* result);
     54 int diff_read_8(FILE *in, uint8_t* result);
     55 int diff_read_str(FILE* in, char* buf, size_t len);
     56 
     57 /* delete the RRs for a zone from memory */
     58 void delete_zone_rrs(namedb_type* db, zone_type* zone);
     59 /* delete an RR */
     60 int delete_RR(namedb_type* db, const dname_type* dname,
     61 	uint16_t type, uint16_t klass, uint32_t ttl,
     62 	buffer_type* packet, size_t rdatalen, zone_type *zone,
     63 	region_type* temp_region, int* softfail,
     64 	struct ixfr_store* ixfr_store);
     65 /* add an RR */
     66 int add_RR(namedb_type* db, const dname_type* dname,
     67 	uint16_t type, uint16_t klass, uint32_t ttl,
     68 	buffer_type* packet, size_t rdatalen, zone_type *zone,
     69 	int* softfail, struct ixfr_store* ixfr_store);
     70 
     71 /* apply the xfr file identified by xfrfilenr to zone */
     72 int apply_ixfr_for_zone(struct nsd* nsd, zone_type* zone, FILE* in,
     73         struct nsd_options* opt, udb_base* taskudb, uint32_t xfrfilenr);
     74 
     75 enum soainfo_hint {
     76 	soainfo_ok,
     77 	soainfo_gone,
     78 	soainfo_bad
     79 };
     80 
     81 /* task udb structure */
     82 struct task_list_d {
     83 	/** next task in list */
     84 	udb_rel_ptr next;
     85 	/** task type */
     86 	enum {
     87 		/** expire or un-expire a zone */
     88 		task_expire,
     89 		/** apply an ixfr or axfr to a zone */
     90 		task_apply_xfr,
     91 		/** soa info for zone */
     92 		task_soa_info,
     93 		/** check mtime of zonefiles and read them, done on SIGHUP */
     94 		task_check_zonefiles,
     95 		/** write zonefiles (if changed) */
     96 		task_write_zonefiles,
     97 		/** set verbosity */
     98 		task_set_verbosity,
     99 		/** add a zone */
    100 		task_add_zone,
    101 		/** delete zone */
    102 		task_del_zone,
    103 		/** add TSIG key */
    104 		task_add_key,
    105 		/** delete TSIG key */
    106 		task_del_key,
    107 		/** add pattern */
    108 		task_add_pattern,
    109 		/** delete pattern */
    110 		task_del_pattern,
    111 		/** options change */
    112 		task_opt_change,
    113 		/** zonestat increment */
    114 		task_zonestat_inc,
    115 		/** cookies */
    116 		task_cookies,
    117 	} task_type;
    118 	uint32_t size; /* size of this struct */
    119 
    120 	/** soainfo: zonename dname, soaRR wireform, yesno is soainfo_hint */
    121 	/** expire: zonename, boolyesno */
    122 	/** apply_xfr: zonename, serials, yesno is filenamecounter */
    123 	uint32_t oldserial, newserial;
    124 	/** general variable.  for some used to see if zname is present. */
    125 	uint64_t yesno;
    126 	struct dname zname[0];
    127 };
    128 #define TASKLIST(ptr) ((struct task_list_d*)UDB_PTR(ptr))
    129 /** create udb for tasks */
    130 struct udb_base* task_file_create(const char* file);
    131 void task_remap(udb_base* udb);
    132 void task_process_sync(udb_base* udb);
    133 void task_clear(udb_base* udb);
    134 void task_new_soainfo(udb_base* udb, udb_ptr* last, struct zone* z, enum soainfo_hint hint);
    135 void task_new_expire(udb_base* udb, udb_ptr* last,
    136 	const struct dname* z, int expired);
    137 void task_new_check_zonefiles(udb_base* udb, udb_ptr* last,
    138 	const dname_type* zone);
    139 void task_new_write_zonefiles(udb_base* udb, udb_ptr* last,
    140 	const dname_type* zone);
    141 void task_new_set_verbosity(udb_base* udb, udb_ptr* last, int v);
    142 void task_new_add_zone(udb_base* udb, udb_ptr* last, const char* zone,
    143 	const char* pattern, unsigned zonestatid);
    144 void task_new_del_zone(udb_base* udb, udb_ptr* last, const dname_type* dname);
    145 void task_new_add_key(udb_base* udb, udb_ptr* last, struct key_options* key);
    146 void task_new_del_key(udb_base* udb, udb_ptr* last, const char* name);
    147 void task_new_add_pattern(udb_base* udb, udb_ptr* last,
    148 	struct pattern_options* p);
    149 void task_new_del_pattern(udb_base* udb, udb_ptr* last, const char* name);
    150 void task_new_opt_change(udb_base* udb, udb_ptr* last, struct nsd_options* opt);
    151 void task_new_zonestat_inc(udb_base* udb, udb_ptr* last, unsigned sz);
    152 void task_new_cookies(udb_base* udb, udb_ptr* last, int answer_cookie,
    153 		size_t cookie_count, void* cookie_secrets);
    154 int task_new_apply_xfr(udb_base* udb, udb_ptr* last, const dname_type* zone,
    155 	uint32_t old_serial, uint32_t new_serial, uint64_t filenumber);
    156 void task_process_apply_xfr(struct nsd* nsd, udb_base* udb, udb_ptr *task);
    157 void task_process_in_reload(struct nsd* nsd, udb_base* udb, udb_ptr *last_task,
    158 	udb_ptr* task);
    159 void task_process_expire(namedb_type* db, struct task_list_d* task);
    160 
    161 #endif /* DIFFFILE_H */
    162