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