xref: /openbsd/usr.sbin/nsd/difffile.h (revision e5dd7070)
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 /* write an xfr packet data to the diff file, type=IXFR.
23    The diff file is created if necessary, with initial header(notcommitted). */
24 void diff_write_packet(const char* zone, const char* pat, uint32_t old_serial,
25 	uint32_t new_serial, uint32_t seq_nr, uint8_t* data, size_t len,
26 	struct nsd* nsd, uint64_t filenumber);
27 
28 /*
29  * Overwrite header of diff file with committed vale and other data.
30  * append log string.
31  */
32 void diff_write_commit(const char* zone, uint32_t old_serial,
33 	uint32_t new_serial, uint32_t num_parts, uint8_t commit,
34 	const char* log_msg, struct nsd* nsd, uint64_t filenumber);
35 
36 /*
37  * These functions read parts of the diff file.
38  */
39 int diff_read_32(FILE *in, uint32_t* result);
40 int diff_read_8(FILE *in, uint8_t* result);
41 int diff_read_str(FILE* in, char* buf, size_t len);
42 
43 /* delete the RRs for a zone from memory */
44 void delete_zone_rrs(namedb_type* db, zone_type* zone);
45 /* delete an RR */
46 int delete_RR(namedb_type* db, const dname_type* dname,
47 	uint16_t type, uint16_t klass,
48 	buffer_type* packet, size_t rdatalen, zone_type *zone,
49 	region_type* temp_region, struct udb_ptr* udbz, int* softfail);
50 /* add an RR */
51 int add_RR(namedb_type* db, const dname_type* dname,
52 	uint16_t type, uint16_t klass, uint32_t ttl,
53 	buffer_type* packet, size_t rdatalen, zone_type *zone,
54 	struct udb_ptr* udbz, int* softfail);
55 
56 /* task udb structure */
57 struct task_list_d {
58 	/** next task in list */
59 	udb_rel_ptr next;
60 	/** task type */
61 	enum {
62 		/** expire or un-expire a zone */
63 		task_expire,
64 		/** apply an ixfr or axfr to a zone */
65 		task_apply_xfr,
66 		/** soa info for zone */
67 		task_soa_info,
68 		/** check mtime of zonefiles and read them, done on SIGHUP */
69 		task_check_zonefiles,
70 		/** write zonefiles (if changed) */
71 		task_write_zonefiles,
72 		/** set verbosity */
73 		task_set_verbosity,
74 		/** statistic info */
75 		task_stat_info,
76 		/** add a zone */
77 		task_add_zone,
78 		/** delete zone */
79 		task_del_zone,
80 		/** add TSIG key */
81 		task_add_key,
82 		/** delete TSIG key */
83 		task_del_key,
84 		/** add pattern */
85 		task_add_pattern,
86 		/** delete pattern */
87 		task_del_pattern,
88 		/** options change */
89 		task_opt_change,
90 		/** zonestat increment */
91 		task_zonestat_inc
92 	} task_type;
93 	uint32_t size; /* size of this struct */
94 
95 	/** soainfo: zonename dname, soaRR wireform */
96 	/** expire: zonename, boolyesno */
97 	/** apply_xfr: zonename, serials, yesno is filenamecounter */
98 	uint32_t oldserial, newserial;
99 	/** general variable.  for some used to see if zname is present. */
100 	uint64_t yesno;
101 	struct dname zname[0];
102 };
103 #define TASKLIST(ptr) ((struct task_list_d*)UDB_PTR(ptr))
104 /** create udb for tasks */
105 struct udb_base* task_file_create(const char* file);
106 void task_remap(udb_base* udb);
107 void task_process_sync(udb_base* udb);
108 void task_clear(udb_base* udb);
109 void task_new_soainfo(udb_base* udb, udb_ptr* last, struct zone* z, int gone);
110 void task_new_expire(udb_base* udb, udb_ptr* last,
111 	const struct dname* z, int expired);
112 void* task_new_stat_info(udb_base* udb, udb_ptr* last, struct nsdst* stat,
113 	size_t child_count);
114 void task_new_check_zonefiles(udb_base* udb, udb_ptr* last,
115 	const dname_type* zone);
116 void task_new_write_zonefiles(udb_base* udb, udb_ptr* last,
117 	const dname_type* zone);
118 void task_new_set_verbosity(udb_base* udb, udb_ptr* last, int v);
119 void task_new_add_zone(udb_base* udb, udb_ptr* last, const char* zone,
120 	const char* pattern, unsigned zonestatid);
121 void task_new_del_zone(udb_base* udb, udb_ptr* last, const dname_type* dname);
122 void task_new_add_key(udb_base* udb, udb_ptr* last, struct key_options* key);
123 void task_new_del_key(udb_base* udb, udb_ptr* last, const char* name);
124 void task_new_add_pattern(udb_base* udb, udb_ptr* last,
125 	struct pattern_options* p);
126 void task_new_del_pattern(udb_base* udb, udb_ptr* last, const char* name);
127 void task_new_opt_change(udb_base* udb, udb_ptr* last, struct nsd_options* opt);
128 void task_new_zonestat_inc(udb_base* udb, udb_ptr* last, unsigned sz);
129 int task_new_apply_xfr(udb_base* udb, udb_ptr* last, const dname_type* zone,
130 	uint32_t old_serial, uint32_t new_serial, uint64_t filenumber);
131 void task_process_in_reload(struct nsd* nsd, udb_base* udb, udb_ptr *last_task,
132 	udb_ptr* task);
133 void task_process_expire(namedb_type* db, struct task_list_d* task);
134 
135 #endif /* DIFFFILE_H */
136