master.h 11.6 KB
Newer Older
1
/*
Mark Andrews's avatar
Mark Andrews committed
2
 * Copyright (C) 2004-2009, 2011-2014  Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
3
 * Copyright (C) 1999-2002  Internet Software Consortium.
4
 *
Automatic Updater's avatar
Automatic Updater committed
5
 * Permission to use, copy, modify, and/or distribute this software for any
6 7
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
8
 *
Mark Andrews's avatar
Mark Andrews committed
9 10 11 12 13 14 15
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
16 17
 */

18
/* $Id: master.h,v 1.57.8.1 2012/02/07 00:44:16 each Exp $ */
David Lawrence's avatar
David Lawrence committed
19

20 21 22
#ifndef DNS_MASTER_H
#define DNS_MASTER_H 1

23
/*! \file dns/master.h */
24

25 26 27 28
/***
 ***	Imports
 ***/

29 30
#include <stdio.h>

Bob Halley's avatar
Bob Halley committed
31
#include <isc/lang.h>
32 33 34

#include <dns/types.h>

35 36 37
/*
 * Flags to be passed in the 'options' argument in the functions below.
 */
38 39 40 41 42 43 44
#define	DNS_MASTER_AGETTL 	0x00000001	/*%< Age the ttl based on $DATE. */
#define DNS_MASTER_MANYERRORS 	0x00000002	/*%< Continue processing on errors. */
#define DNS_MASTER_NOINCLUDE 	0x00000004	/*%< Disallow $INCLUDE directives. */
#define DNS_MASTER_ZONE 	0x00000008	/*%< Loading a zone master file. */
#define DNS_MASTER_HINT 	0x00000010	/*%< Loading a hint master file. */
#define DNS_MASTER_SLAVE 	0x00000020	/*%< Loading a slave master file. */
#define DNS_MASTER_CHECKNS 	0x00000040	/*%<
Automatic Updater's avatar
Automatic Updater committed
45
						 * Check NS records to see
46 47 48 49 50 51
						 * if they are an address
						 */
#define DNS_MASTER_FATALNS 	0x00000080	/*%<
						 * Treat DNS_MASTER_CHECKNS
						 * matches as fatal
						 */
52 53
#define DNS_MASTER_CHECKNAMES   0x00000100
#define DNS_MASTER_CHECKNAMESFAIL 0x00000200
Mark Andrews's avatar
Mark Andrews committed
54
#define DNS_MASTER_CHECKWILDCARD 0x00000400	/* Check for internal wildcards. */
55 56
#define DNS_MASTER_CHECKMX	0x00000800
#define DNS_MASTER_CHECKMXFAIL	0x00001000
57

58
#define DNS_MASTER_RESIGN	0x00002000
59
#define DNS_MASTER_KEY	 	0x00004000	/*%< Loading a key zone master file. */
60
#define DNS_MASTER_NOTTL	0x00008000	/*%< Don't require ttl. */
Evan Hunt's avatar
Evan Hunt committed
61
#define DNS_MASTER_CHECKTTL	0x00010000	/*%< Check max-zone-ttl */
62

Bob Halley's avatar
Bob Halley committed
63 64
ISC_LANG_BEGINDECLS

65 66 67 68 69 70
/*
 * Structures that implement the "raw" format for master dump.
 * These are provided for a reference purpose only; in the actual
 * encoding, we directly read/write each field so that the encoded data
 * is always "packed", regardless of the hardware architecture.
 */
71 72 73 74 75 76 77 78
#define DNS_RAWFORMAT_VERSION 1

/*
 * Flags to indicate the status of the data in the raw file header
 */
#define DNS_MASTERRAW_COMPAT 		0x01
#define DNS_MASTERRAW_SOURCESERIALSET	0x02
#define DNS_MASTERRAW_LASTXFRINSET	0x04
79 80

/* Common header */
81
struct dns_masterrawheader {
82
	isc_uint32_t		format;		/* must be
Tinderbox User's avatar
Tinderbox User committed
83
						 * dns_masterformat_raw
84
						 * or
Evan Hunt's avatar
Evan Hunt committed
85
						 * dns_masterformat_map */
86 87 88
	isc_uint32_t		version;	/* compatibility for future
						 * extensions */
	isc_uint32_t		dumptime;	/* timestamp on creation
89 90 91 92 93 94 95
						 * (currently unused) */
	isc_uint32_t		flags;		/* Flags */
	isc_uint32_t		sourceserial;	/* Source serial number (used
						 * by inline-signing zones) */
	isc_uint32_t		lastxfrin;	/* timestamp of last transfer
						 * (used by slave zones) */
};
96 97 98 99 100 101 102 103 104 105 106 107 108 109

/* The structure for each RRset */
typedef struct {
	isc_uint32_t		totallen;	/* length of the data for this
						 * RRset, including the
						 * "header" part */
	dns_rdataclass_t	rdclass;	/* 16-bit class */
	dns_rdatatype_t		type;		/* 16-bit type */
	dns_rdatatype_t		covers;		/* same as type */
	dns_ttl_t		ttl;		/* 32-bit TTL */
	isc_uint32_t		nrdata;		/* number of RRs in this set */
	/* followed by encoded owner name, and then rdata */
} dns_masterrawrdataset_t;

110 111 112 113 114 115 116
/*
 * Method prototype: a callback to register each include file as
 * it is encountered.
 */
typedef void
(*dns_masterincludecb_t)(const char *file, void *arg);

117 118 119 120
/***
 ***	Function
 ***/

121 122 123 124 125
isc_result_t
dns_master_loadfile(const char *master_file,
		    dns_name_t *top,
		    dns_name_t *origin,
		    dns_rdataclass_t zclass,
126
		    unsigned int options,
127 128
		    dns_rdatacallbacks_t *callbacks,
		    isc_mem_t *mctx);
Bob Halley's avatar
Bob Halley committed
129

130 131 132 133 134 135 136 137 138 139
isc_result_t
dns_master_loadfile2(const char *master_file,
		     dns_name_t *top,
		     dns_name_t *origin,
		     dns_rdataclass_t zclass,
		     unsigned int options,
		     dns_rdatacallbacks_t *callbacks,
		     isc_mem_t *mctx,
		     dns_masterformat_t format);

140 141 142 143 144 145 146 147 148 149 150
isc_result_t
dns_master_loadfile3(const char *master_file,
		     dns_name_t *top,
		     dns_name_t *origin,
		     dns_rdataclass_t zclass,
		     unsigned int options,
		     isc_uint32_t resign,
		     dns_rdatacallbacks_t *callbacks,
		     isc_mem_t *mctx,
		     dns_masterformat_t format);

151 152 153 154 155 156 157 158 159 160 161 162
isc_result_t
dns_master_loadfile4(const char *master_file,
		     dns_name_t *top,
		     dns_name_t *origin,
		     dns_rdataclass_t zclass,
		     unsigned int options,
		     isc_uint32_t resign,
		     dns_rdatacallbacks_t *callbacks,
		     dns_masterincludecb_t include_cb,
		     void *include_arg, isc_mem_t *mctx,
		     dns_masterformat_t format);

Evan Hunt's avatar
Evan Hunt committed
163 164 165 166 167 168 169 170 171 172 173 174 175
isc_result_t
dns_master_loadfile5(const char *master_file,
		     dns_name_t *top,
		     dns_name_t *origin,
		     dns_rdataclass_t zclass,
		     unsigned int options,
		     isc_uint32_t resign,
		     dns_rdatacallbacks_t *callbacks,
		     dns_masterincludecb_t include_cb,
		     void *include_arg, isc_mem_t *mctx,
		     dns_masterformat_t format,
		     dns_ttl_t maxttl);

176 177 178 179 180
isc_result_t
dns_master_loadstream(FILE *stream,
		      dns_name_t *top,
		      dns_name_t *origin,
		      dns_rdataclass_t zclass,
181
		      unsigned int options,
182 183
		      dns_rdatacallbacks_t *callbacks,
		      isc_mem_t *mctx);
Bob Halley's avatar
Bob Halley committed
184

185 186 187 188 189
isc_result_t
dns_master_loadbuffer(isc_buffer_t *buffer,
		      dns_name_t *top,
		      dns_name_t *origin,
		      dns_rdataclass_t zclass,
190
		      unsigned int options,
191 192
		      dns_rdatacallbacks_t *callbacks,
		      isc_mem_t *mctx);
Bob Halley's avatar
Bob Halley committed
193

194 195 196 197 198 199 200 201 202
isc_result_t
dns_master_loadlexer(isc_lex_t *lex,
		     dns_name_t *top,
		     dns_name_t *origin,
		     dns_rdataclass_t zclass,
		     unsigned int options,
		     dns_rdatacallbacks_t *callbacks,
		     isc_mem_t *mctx);

203 204 205 206 207
isc_result_t
dns_master_loadfileinc(const char *master_file,
		       dns_name_t *top,
		       dns_name_t *origin,
		       dns_rdataclass_t zclass,
208
		       unsigned int options,
209 210 211
		       dns_rdatacallbacks_t *callbacks,
		       isc_task_t *task,
		       dns_loaddonefunc_t done, void *done_arg,
212
		       dns_loadctx_t **ctxp, isc_mem_t *mctx);
213

214 215 216 217 218 219 220 221 222 223 224 225
isc_result_t
dns_master_loadfileinc2(const char *master_file,
			dns_name_t *top,
			dns_name_t *origin,
			dns_rdataclass_t zclass,
			unsigned int options,
			dns_rdatacallbacks_t *callbacks,
			isc_task_t *task,
			dns_loaddonefunc_t done, void *done_arg,
			dns_loadctx_t **ctxp, isc_mem_t *mctx,
			dns_masterformat_t format);

226 227 228 229 230 231 232 233 234 235 236 237 238
isc_result_t
dns_master_loadfileinc3(const char *master_file,
			dns_name_t *top,
			dns_name_t *origin,
			dns_rdataclass_t zclass,
			unsigned int options,
			isc_uint32_t resign,
			dns_rdatacallbacks_t *callbacks,
			isc_task_t *task,
			dns_loaddonefunc_t done, void *done_arg,
			dns_loadctx_t **ctxp, isc_mem_t *mctx,
			dns_masterformat_t format);

239 240 241 242 243 244 245 246 247 248 249 250 251 252
isc_result_t
dns_master_loadfileinc4(const char *master_file,
			dns_name_t *top,
			dns_name_t *origin,
			dns_rdataclass_t zclass,
			unsigned int options,
			isc_uint32_t resign,
			dns_rdatacallbacks_t *callbacks,
			isc_task_t *task,
			dns_loaddonefunc_t done, void *done_arg,
			dns_loadctx_t **ctxp,
			dns_masterincludecb_t include_cb, void *include_arg,
			isc_mem_t *mctx, dns_masterformat_t format);

Evan Hunt's avatar
Evan Hunt committed
253 254 255 256 257 258 259 260 261 262 263 264
isc_result_t
dns_master_loadfileinc5(const char *master_file,
			dns_name_t *top,
			dns_name_t *origin,
			dns_rdataclass_t zclass,
			unsigned int options,
			isc_uint32_t resign,
			dns_rdatacallbacks_t *callbacks,
			isc_task_t *task,
			dns_loaddonefunc_t done, void *done_arg,
			dns_loadctx_t **ctxp,
			dns_masterincludecb_t include_cb, void *include_arg,
Mark Andrews's avatar
Mark Andrews committed
265
			isc_mem_t *mctx, dns_masterformat_t format,
Evan Hunt's avatar
Evan Hunt committed
266 267
			isc_uint32_t maxttl);

268 269 270 271 272
isc_result_t
dns_master_loadstreaminc(FILE *stream,
			 dns_name_t *top,
			 dns_name_t *origin,
			 dns_rdataclass_t zclass,
273
			 unsigned int options,
274 275 276
			 dns_rdatacallbacks_t *callbacks,
			 isc_task_t *task,
			 dns_loaddonefunc_t done, void *done_arg,
277
			 dns_loadctx_t **ctxp, isc_mem_t *mctx);
278 279 280 281 282 283

isc_result_t
dns_master_loadbufferinc(isc_buffer_t *buffer,
			 dns_name_t *top,
			 dns_name_t *origin,
			 dns_rdataclass_t zclass,
284
			 unsigned int options,
285 286 287
			 dns_rdatacallbacks_t *callbacks,
			 isc_task_t *task,
			 dns_loaddonefunc_t done, void *done_arg,
288
			 dns_loadctx_t **ctxp, isc_mem_t *mctx);
289

290 291 292 293 294 295 296 297 298 299 300
isc_result_t
dns_master_loadlexerinc(isc_lex_t *lex,
			dns_name_t *top,
			dns_name_t *origin,
			dns_rdataclass_t zclass,
			unsigned int options,
			dns_rdatacallbacks_t *callbacks,
			isc_task_t *task,
			dns_loaddonefunc_t done, void *done_arg,
			dns_loadctx_t **ctxp, isc_mem_t *mctx);

301 302
/*%<
 * Loads a RFC1305 master file from a file, stream, buffer, or existing
303 304 305 306
 * lexer into rdatasets and then calls 'callbacks->commit' to commit the
 * rdatasets.  Rdata memory belongs to dns_master_load and will be
 * reused / released when the callback completes.  dns_load_master will
 * abort if callbacks->commit returns any value other than ISC_R_SUCCESS.
307
 *
308
 * If 'DNS_MASTER_AGETTL' is set and the master file contains one or more
309
 * $DATE directives, the TTLs of the data will be aged accordingly.
310
 *
311 312 313
 * 'callbacks->commit' is assumed to call 'callbacks->error' or
 * 'callbacks->warn' to generate any error messages required.
 *
314
 * 'done' is called with 'done_arg' and a result code when the loading
315 316
 * is completed or has failed.  If the initial setup fails 'done' is
 * not called.
317
 *
318 319 320
 * 'resign' the number of seconds before a RRSIG expires that it should
 * be re-signed.  0 is used if not provided.
 *
321
 * Requires:
322 323 324 325 326 327 328 329 330 331 332
 *\li	'master_file' points to a valid string.
 *\li	'lexer' points to a valid lexer.
 *\li	'top' points to a valid name.
 *\li	'origin' points to a valid name.
 *\li	'callbacks->commit' points to a valid function.
 *\li	'callbacks->error' points to a valid function.
 *\li	'callbacks->warn' points to a valid function.
 *\li	'mctx' points to a valid memory context.
 *\li	'task' and 'done' to be valid.
 *\li	'lmgr' to be valid.
 *\li	'ctxp != NULL && ctxp == NULL'.
333 334
 *
 * Returns:
335 336
 *\li	ISC_R_SUCCESS upon successfully loading the master file.
 *\li	ISC_R_SEENINCLUDE upon successfully loading the master file with
337
 *		a $INCLUDE statement.
338 339
 *\li	ISC_R_NOMEMORY out of memory.
 *\li	ISC_R_UNEXPECTEDEND expected to be able to read a input token and
340
 *		there was not one.
341 342 343 344 345 346 347
 *\li	ISC_R_UNEXPECTED
 *\li	DNS_R_NOOWNER failed to specify a ownername.
 *\li	DNS_R_NOTTL failed to specify a ttl.
 *\li	DNS_R_BADCLASS record class did not match zone class.
 *\li	DNS_R_CONTINUE load still in progress (dns_master_load*inc() only).
 *\li	Any dns_rdata_fromtext() error code.
 *\li	Any error code from callbacks->commit().
348 349
 */

350 351
void
dns_loadctx_detach(dns_loadctx_t **ctxp);
352
/*%<
353 354 355
 * Detach from the load context.
 *
 * Requires:
356
 *\li	'*ctxp' to be valid.
357 358
 *
 * Ensures:
359
 *\li	'*ctxp == NULL'
360 361 362 363
 */

void
dns_loadctx_attach(dns_loadctx_t *source, dns_loadctx_t **target);
364
/*%<
365 366 367
 * Attach to the load context.
 *
 * Requires:
368 369
 *\li	'source' to be valid.
 *\li	'target != NULL && *target == NULL'.
370 371 372 373
 */

void
dns_loadctx_cancel(dns_loadctx_t *ctx);
374
/*%<
375 376 377
 * Cancel loading the zone file associated with this load context.
 *
 * Requires:
378
 *\li	'ctx' to be valid
379 380
 */

381 382 383 384 385 386
void
dns_master_initrawheader(dns_masterrawheader_t *header);
/*%<
 * Initializes the header for a raw master file, setting all
 * values to zero.
 */
Bob Halley's avatar
Bob Halley committed
387 388
ISC_LANG_ENDDECLS

389
#endif /* DNS_MASTER_H */