xref: /openbsd-src/usr.sbin/nsd/difffile.h (revision bf87c3c07c3ad89262e2b8cae09f17e70aa9e1ee)
162ac0c33Sjakob /*
262ac0c33Sjakob  * difffile.h - nsd.diff file handling header file. Read/write diff files.
362ac0c33Sjakob  *
4d3fecca9Ssthen  * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
562ac0c33Sjakob  *
662ac0c33Sjakob  * See LICENSE for the license.
762ac0c33Sjakob  *
862ac0c33Sjakob  */
962ac0c33Sjakob #ifndef DIFFFILE_H
1062ac0c33Sjakob #define DIFFFILE_H
1162ac0c33Sjakob 
1262ac0c33Sjakob #include "rbtree.h"
1362ac0c33Sjakob #include "namedb.h"
1462ac0c33Sjakob #include "options.h"
15d3fecca9Ssthen #include "udb.h"
16d3fecca9Ssthen struct nsd;
17d3fecca9Ssthen struct nsdst;
1862ac0c33Sjakob 
19d3fecca9Ssthen #define DIFF_PART_XXFR ('X'<<24 | 'X'<<16 | 'F'<<8 | 'R')
20d3fecca9Ssthen #define DIFF_PART_XFRF ('X'<<24 | 'F'<<16 | 'R'<<8 | 'F')
2162ac0c33Sjakob 
223f21e8ccSflorian #define DIFF_NOT_COMMITTED (0u) /* XFR not (yet) committed to disk */
233f21e8ccSflorian #define DIFF_COMMITTED (1u<<0) /* XFR committed to disk */
243f21e8ccSflorian #define DIFF_CORRUPT (1u<<1) /* XFR corrupt */
253f21e8ccSflorian #define DIFF_INCONSISTENT (1u<<2) /* IXFR cannot be applied */
263f21e8ccSflorian #define DIFF_VERIFIED (1u<<3) /* XFR already verified */
273f21e8ccSflorian 
2862ac0c33Sjakob /* write an xfr packet data to the diff file, type=IXFR.
29d3fecca9Ssthen    The diff file is created if necessary, with initial header(notcommitted). */
30d3fecca9Ssthen void diff_write_packet(const char* zone, const char* pat, uint32_t old_serial,
31d3fecca9Ssthen 	uint32_t new_serial, uint32_t seq_nr, uint8_t* data, size_t len,
32d3fecca9Ssthen 	struct nsd* nsd, uint64_t filenumber);
3362ac0c33Sjakob 
3462ac0c33Sjakob /*
35d3fecca9Ssthen  * Overwrite header of diff file with committed vale and other data.
36d3fecca9Ssthen  * append log string.
3762ac0c33Sjakob  */
3862ac0c33Sjakob void diff_write_commit(const char* zone, uint32_t old_serial,
39d3fecca9Ssthen 	uint32_t new_serial, uint32_t num_parts, uint8_t commit,
40d3fecca9Ssthen 	const char* log_msg, struct nsd* nsd, uint64_t filenumber);
4162ac0c33Sjakob 
4262ac0c33Sjakob /*
433f21e8ccSflorian  * Overwrite committed value of diff file with discarded to ensure diff
443f21e8ccSflorian  * file is not reapplied on reload.
453f21e8ccSflorian  */
463f21e8ccSflorian void diff_update_commit(const char* zone,
473f21e8ccSflorian 	uint8_t commit, struct nsd* nsd, uint64_t filenumber);
483f21e8ccSflorian 
493f21e8ccSflorian /*
5062ac0c33Sjakob  * These functions read parts of the diff file.
5162ac0c33Sjakob  */
5262ac0c33Sjakob int diff_read_32(FILE *in, uint32_t* result);
5362ac0c33Sjakob int diff_read_8(FILE *in, uint8_t* result);
5462ac0c33Sjakob int diff_read_str(FILE* in, char* buf, size_t len);
5562ac0c33Sjakob 
56d3fecca9Ssthen /* delete the RRs for a zone from memory */
57d3fecca9Ssthen void delete_zone_rrs(namedb_type* db, zone_type* zone);
58d3fecca9Ssthen /* delete an RR */
59d3fecca9Ssthen int delete_RR(namedb_type* db, const dname_type* dname,
60d3fecca9Ssthen 	uint16_t type, uint16_t klass,
61d3fecca9Ssthen 	buffer_type* packet, size_t rdatalen, zone_type *zone,
62b71395eaSflorian 	region_type* temp_region, int* softfail);
63d3fecca9Ssthen /* add an RR */
64d3fecca9Ssthen int add_RR(namedb_type* db, const dname_type* dname,
65d3fecca9Ssthen 	uint16_t type, uint16_t klass, uint32_t ttl,
66d3fecca9Ssthen 	buffer_type* packet, size_t rdatalen, zone_type *zone,
67b71395eaSflorian 	int* softfail);
68d3fecca9Ssthen 
69*bf87c3c0Sflorian /* apply the xfr file identified by xfrfilenr to zone */
70*bf87c3c0Sflorian int apply_ixfr_for_zone(struct nsd* nsd, zone_type* zone, FILE* in,
71*bf87c3c0Sflorian         struct nsd_options* opt, udb_base* taskudb, udb_ptr* last_task,
72*bf87c3c0Sflorian         uint32_t xfrfilenr);
73*bf87c3c0Sflorian 
743f21e8ccSflorian enum soainfo_hint {
753f21e8ccSflorian 	soainfo_ok,
763f21e8ccSflorian 	soainfo_gone,
773f21e8ccSflorian 	soainfo_bad
783f21e8ccSflorian };
793f21e8ccSflorian 
80d3fecca9Ssthen /* task udb structure */
81d3fecca9Ssthen struct task_list_d {
82d3fecca9Ssthen 	/** next task in list */
83d3fecca9Ssthen 	udb_rel_ptr next;
84d3fecca9Ssthen 	/** task type */
85d3fecca9Ssthen 	enum {
86d3fecca9Ssthen 		/** expire or un-expire a zone */
87d3fecca9Ssthen 		task_expire,
88d3fecca9Ssthen 		/** apply an ixfr or axfr to a zone */
89d3fecca9Ssthen 		task_apply_xfr,
90d3fecca9Ssthen 		/** soa info for zone */
91d3fecca9Ssthen 		task_soa_info,
92d3fecca9Ssthen 		/** check mtime of zonefiles and read them, done on SIGHUP */
93d3fecca9Ssthen 		task_check_zonefiles,
94d3fecca9Ssthen 		/** write zonefiles (if changed) */
95d3fecca9Ssthen 		task_write_zonefiles,
96d3fecca9Ssthen 		/** set verbosity */
97d3fecca9Ssthen 		task_set_verbosity,
98d3fecca9Ssthen 		/** add a zone */
99d3fecca9Ssthen 		task_add_zone,
100d3fecca9Ssthen 		/** delete zone */
101d3fecca9Ssthen 		task_del_zone,
102d3fecca9Ssthen 		/** add TSIG key */
103d3fecca9Ssthen 		task_add_key,
104d3fecca9Ssthen 		/** delete TSIG key */
105d3fecca9Ssthen 		task_del_key,
106d3fecca9Ssthen 		/** add pattern */
107d3fecca9Ssthen 		task_add_pattern,
108d3fecca9Ssthen 		/** delete pattern */
109d3fecca9Ssthen 		task_del_pattern,
110d3fecca9Ssthen 		/** options change */
1119e506f0aSbrad 		task_opt_change,
1129e506f0aSbrad 		/** zonestat increment */
113063644e9Sflorian 		task_zonestat_inc,
114063644e9Sflorian 		/** add a new cookie secret */
115063644e9Sflorian 		task_add_cookie_secret,
116063644e9Sflorian 		/** drop the oldest cookie secret */
117063644e9Sflorian 		task_drop_cookie_secret,
118063644e9Sflorian 		/** make staging cookie secret active */
119063644e9Sflorian 		task_activate_cookie_secret,
120d3fecca9Ssthen 	} task_type;
121d3fecca9Ssthen 	uint32_t size; /* size of this struct */
122d3fecca9Ssthen 
1233f21e8ccSflorian 	/** soainfo: zonename dname, soaRR wireform, yesno is soainfo_hint */
124d3fecca9Ssthen 	/** expire: zonename, boolyesno */
125d3fecca9Ssthen 	/** apply_xfr: zonename, serials, yesno is filenamecounter */
126d3fecca9Ssthen 	uint32_t oldserial, newserial;
127d3fecca9Ssthen 	/** general variable.  for some used to see if zname is present. */
128d3fecca9Ssthen 	uint64_t yesno;
129d3fecca9Ssthen 	struct dname zname[0];
130d3fecca9Ssthen };
131d3fecca9Ssthen #define TASKLIST(ptr) ((struct task_list_d*)UDB_PTR(ptr))
132d3fecca9Ssthen /** create udb for tasks */
133d3fecca9Ssthen struct udb_base* task_file_create(const char* file);
134d3fecca9Ssthen void task_remap(udb_base* udb);
135d3fecca9Ssthen void task_process_sync(udb_base* udb);
136d3fecca9Ssthen void task_clear(udb_base* udb);
1373f21e8ccSflorian void task_new_soainfo(udb_base* udb, udb_ptr* last, struct zone* z, enum soainfo_hint hint);
138d3fecca9Ssthen void task_new_expire(udb_base* udb, udb_ptr* last,
139d3fecca9Ssthen 	const struct dname* z, int expired);
140d3fecca9Ssthen void task_new_check_zonefiles(udb_base* udb, udb_ptr* last,
141d3fecca9Ssthen 	const dname_type* zone);
142d3fecca9Ssthen void task_new_write_zonefiles(udb_base* udb, udb_ptr* last,
143d3fecca9Ssthen 	const dname_type* zone);
144d3fecca9Ssthen void task_new_set_verbosity(udb_base* udb, udb_ptr* last, int v);
145d3fecca9Ssthen void task_new_add_zone(udb_base* udb, udb_ptr* last, const char* zone,
1469e506f0aSbrad 	const char* pattern, unsigned zonestatid);
147d3fecca9Ssthen void task_new_del_zone(udb_base* udb, udb_ptr* last, const dname_type* dname);
148fe5fe5f6Sflorian void task_new_add_key(udb_base* udb, udb_ptr* last, struct key_options* key);
149d3fecca9Ssthen void task_new_del_key(udb_base* udb, udb_ptr* last, const char* name);
150fe5fe5f6Sflorian void task_new_add_pattern(udb_base* udb, udb_ptr* last,
151fe5fe5f6Sflorian 	struct pattern_options* p);
152d3fecca9Ssthen void task_new_del_pattern(udb_base* udb, udb_ptr* last, const char* name);
153fe5fe5f6Sflorian void task_new_opt_change(udb_base* udb, udb_ptr* last, struct nsd_options* opt);
1549e506f0aSbrad void task_new_zonestat_inc(udb_base* udb, udb_ptr* last, unsigned sz);
155063644e9Sflorian void task_new_add_cookie_secret(udb_base* udb, udb_ptr* last, const char* secret);
156063644e9Sflorian void task_new_drop_cookie_secret(udb_base* udb, udb_ptr* last);
157063644e9Sflorian void task_new_activate_cookie_secret(udb_base* udb, udb_ptr* last);
158d3fecca9Ssthen int task_new_apply_xfr(udb_base* udb, udb_ptr* last, const dname_type* zone,
159d3fecca9Ssthen 	uint32_t old_serial, uint32_t new_serial, uint64_t filenumber);
160d3fecca9Ssthen void task_process_in_reload(struct nsd* nsd, udb_base* udb, udb_ptr *last_task,
161d3fecca9Ssthen 	udb_ptr* task);
162d3fecca9Ssthen void task_process_expire(namedb_type* db, struct task_list_d* task);
163d3fecca9Ssthen 
16462ac0c33Sjakob #endif /* DIFFFILE_H */
165