1 /* $NetBSD: master.h,v 1.6 2014/12/10 04:37:58 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2009, 2011-2014 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 1999-2002 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* Id: master.h,v 1.57.8.1 2012/02/07 00:44:16 each Exp */ 21 22 #ifndef DNS_MASTER_H 23 #define DNS_MASTER_H 1 24 25 /*! \file dns/master.h */ 26 27 /*** 28 *** Imports 29 ***/ 30 31 #include <stdio.h> 32 33 #include <isc/lang.h> 34 35 #include <dns/types.h> 36 37 /* 38 * Flags to be passed in the 'options' argument in the functions below. 39 */ 40 #define DNS_MASTER_AGETTL 0x00000001 /*%< Age the ttl based on $DATE. */ 41 #define DNS_MASTER_MANYERRORS 0x00000002 /*%< Continue processing on errors. */ 42 #define DNS_MASTER_NOINCLUDE 0x00000004 /*%< Disallow $INCLUDE directives. */ 43 #define DNS_MASTER_ZONE 0x00000008 /*%< Loading a zone master file. */ 44 #define DNS_MASTER_HINT 0x00000010 /*%< Loading a hint master file. */ 45 #define DNS_MASTER_SLAVE 0x00000020 /*%< Loading a slave master file. */ 46 #define DNS_MASTER_CHECKNS 0x00000040 /*%< 47 * Check NS records to see 48 * if they are an address 49 */ 50 #define DNS_MASTER_FATALNS 0x00000080 /*%< 51 * Treat DNS_MASTER_CHECKNS 52 * matches as fatal 53 */ 54 #define DNS_MASTER_CHECKNAMES 0x00000100 55 #define DNS_MASTER_CHECKNAMESFAIL 0x00000200 56 #define DNS_MASTER_CHECKWILDCARD 0x00000400 /* Check for internal wildcards. */ 57 #define DNS_MASTER_CHECKMX 0x00000800 58 #define DNS_MASTER_CHECKMXFAIL 0x00001000 59 60 #define DNS_MASTER_RESIGN 0x00002000 61 #define DNS_MASTER_KEY 0x00004000 /*%< Loading a key zone master file. */ 62 #define DNS_MASTER_NOTTL 0x00008000 /*%< Don't require ttl. */ 63 #define DNS_MASTER_CHECKTTL 0x00010000 /*%< Check max-zone-ttl */ 64 65 ISC_LANG_BEGINDECLS 66 67 /* 68 * Structures that implement the "raw" format for master dump. 69 * These are provided for a reference purpose only; in the actual 70 * encoding, we directly read/write each field so that the encoded data 71 * is always "packed", regardless of the hardware architecture. 72 */ 73 #define DNS_RAWFORMAT_VERSION 1 74 75 /* 76 * Flags to indicate the status of the data in the raw file header 77 */ 78 #define DNS_MASTERRAW_COMPAT 0x01 79 #define DNS_MASTERRAW_SOURCESERIALSET 0x02 80 #define DNS_MASTERRAW_LASTXFRINSET 0x04 81 82 /* Common header */ 83 struct dns_masterrawheader { 84 isc_uint32_t format; /* must be 85 * dns_masterformat_raw 86 * or 87 * dns_masterformat_map */ 88 isc_uint32_t version; /* compatibility for future 89 * extensions */ 90 isc_uint32_t dumptime; /* timestamp on creation 91 * (currently unused) */ 92 isc_uint32_t flags; /* Flags */ 93 isc_uint32_t sourceserial; /* Source serial number (used 94 * by inline-signing zones) */ 95 isc_uint32_t lastxfrin; /* timestamp of last transfer 96 * (used by slave zones) */ 97 }; 98 99 /* The structure for each RRset */ 100 typedef struct { 101 isc_uint32_t totallen; /* length of the data for this 102 * RRset, including the 103 * "header" part */ 104 dns_rdataclass_t rdclass; /* 16-bit class */ 105 dns_rdatatype_t type; /* 16-bit type */ 106 dns_rdatatype_t covers; /* same as type */ 107 dns_ttl_t ttl; /* 32-bit TTL */ 108 isc_uint32_t nrdata; /* number of RRs in this set */ 109 /* followed by encoded owner name, and then rdata */ 110 } dns_masterrawrdataset_t; 111 112 /* 113 * Method prototype: a callback to register each include file as 114 * it is encountered. 115 */ 116 typedef void 117 (*dns_masterincludecb_t)(const char *file, void *arg); 118 119 /*** 120 *** Function 121 ***/ 122 123 isc_result_t 124 dns_master_loadfile(const char *master_file, 125 dns_name_t *top, 126 dns_name_t *origin, 127 dns_rdataclass_t zclass, 128 unsigned int options, 129 dns_rdatacallbacks_t *callbacks, 130 isc_mem_t *mctx); 131 132 isc_result_t 133 dns_master_loadfile2(const char *master_file, 134 dns_name_t *top, 135 dns_name_t *origin, 136 dns_rdataclass_t zclass, 137 unsigned int options, 138 dns_rdatacallbacks_t *callbacks, 139 isc_mem_t *mctx, 140 dns_masterformat_t format); 141 142 isc_result_t 143 dns_master_loadfile3(const char *master_file, 144 dns_name_t *top, 145 dns_name_t *origin, 146 dns_rdataclass_t zclass, 147 unsigned int options, 148 isc_uint32_t resign, 149 dns_rdatacallbacks_t *callbacks, 150 isc_mem_t *mctx, 151 dns_masterformat_t format); 152 153 isc_result_t 154 dns_master_loadfile4(const char *master_file, 155 dns_name_t *top, 156 dns_name_t *origin, 157 dns_rdataclass_t zclass, 158 unsigned int options, 159 isc_uint32_t resign, 160 dns_rdatacallbacks_t *callbacks, 161 dns_masterincludecb_t include_cb, 162 void *include_arg, isc_mem_t *mctx, 163 dns_masterformat_t format); 164 165 isc_result_t 166 dns_master_loadfile5(const char *master_file, 167 dns_name_t *top, 168 dns_name_t *origin, 169 dns_rdataclass_t zclass, 170 unsigned int options, 171 isc_uint32_t resign, 172 dns_rdatacallbacks_t *callbacks, 173 dns_masterincludecb_t include_cb, 174 void *include_arg, isc_mem_t *mctx, 175 dns_masterformat_t format, 176 dns_ttl_t maxttl); 177 178 isc_result_t 179 dns_master_loadstream(FILE *stream, 180 dns_name_t *top, 181 dns_name_t *origin, 182 dns_rdataclass_t zclass, 183 unsigned int options, 184 dns_rdatacallbacks_t *callbacks, 185 isc_mem_t *mctx); 186 187 isc_result_t 188 dns_master_loadbuffer(isc_buffer_t *buffer, 189 dns_name_t *top, 190 dns_name_t *origin, 191 dns_rdataclass_t zclass, 192 unsigned int options, 193 dns_rdatacallbacks_t *callbacks, 194 isc_mem_t *mctx); 195 196 isc_result_t 197 dns_master_loadlexer(isc_lex_t *lex, 198 dns_name_t *top, 199 dns_name_t *origin, 200 dns_rdataclass_t zclass, 201 unsigned int options, 202 dns_rdatacallbacks_t *callbacks, 203 isc_mem_t *mctx); 204 205 isc_result_t 206 dns_master_loadfileinc(const char *master_file, 207 dns_name_t *top, 208 dns_name_t *origin, 209 dns_rdataclass_t zclass, 210 unsigned int options, 211 dns_rdatacallbacks_t *callbacks, 212 isc_task_t *task, 213 dns_loaddonefunc_t done, void *done_arg, 214 dns_loadctx_t **ctxp, isc_mem_t *mctx); 215 216 isc_result_t 217 dns_master_loadfileinc2(const char *master_file, 218 dns_name_t *top, 219 dns_name_t *origin, 220 dns_rdataclass_t zclass, 221 unsigned int options, 222 dns_rdatacallbacks_t *callbacks, 223 isc_task_t *task, 224 dns_loaddonefunc_t done, void *done_arg, 225 dns_loadctx_t **ctxp, isc_mem_t *mctx, 226 dns_masterformat_t format); 227 228 isc_result_t 229 dns_master_loadfileinc3(const char *master_file, 230 dns_name_t *top, 231 dns_name_t *origin, 232 dns_rdataclass_t zclass, 233 unsigned int options, 234 isc_uint32_t resign, 235 dns_rdatacallbacks_t *callbacks, 236 isc_task_t *task, 237 dns_loaddonefunc_t done, void *done_arg, 238 dns_loadctx_t **ctxp, isc_mem_t *mctx, 239 dns_masterformat_t format); 240 241 isc_result_t 242 dns_master_loadfileinc4(const char *master_file, 243 dns_name_t *top, 244 dns_name_t *origin, 245 dns_rdataclass_t zclass, 246 unsigned int options, 247 isc_uint32_t resign, 248 dns_rdatacallbacks_t *callbacks, 249 isc_task_t *task, 250 dns_loaddonefunc_t done, void *done_arg, 251 dns_loadctx_t **ctxp, 252 dns_masterincludecb_t include_cb, void *include_arg, 253 isc_mem_t *mctx, dns_masterformat_t format); 254 255 isc_result_t 256 dns_master_loadfileinc5(const char *master_file, 257 dns_name_t *top, 258 dns_name_t *origin, 259 dns_rdataclass_t zclass, 260 unsigned int options, 261 isc_uint32_t resign, 262 dns_rdatacallbacks_t *callbacks, 263 isc_task_t *task, 264 dns_loaddonefunc_t done, void *done_arg, 265 dns_loadctx_t **ctxp, 266 dns_masterincludecb_t include_cb, void *include_arg, 267 isc_mem_t *mctx, dns_masterformat_t format, 268 isc_uint32_t maxttl); 269 270 isc_result_t 271 dns_master_loadstreaminc(FILE *stream, 272 dns_name_t *top, 273 dns_name_t *origin, 274 dns_rdataclass_t zclass, 275 unsigned int options, 276 dns_rdatacallbacks_t *callbacks, 277 isc_task_t *task, 278 dns_loaddonefunc_t done, void *done_arg, 279 dns_loadctx_t **ctxp, isc_mem_t *mctx); 280 281 isc_result_t 282 dns_master_loadbufferinc(isc_buffer_t *buffer, 283 dns_name_t *top, 284 dns_name_t *origin, 285 dns_rdataclass_t zclass, 286 unsigned int options, 287 dns_rdatacallbacks_t *callbacks, 288 isc_task_t *task, 289 dns_loaddonefunc_t done, void *done_arg, 290 dns_loadctx_t **ctxp, isc_mem_t *mctx); 291 292 isc_result_t 293 dns_master_loadlexerinc(isc_lex_t *lex, 294 dns_name_t *top, 295 dns_name_t *origin, 296 dns_rdataclass_t zclass, 297 unsigned int options, 298 dns_rdatacallbacks_t *callbacks, 299 isc_task_t *task, 300 dns_loaddonefunc_t done, void *done_arg, 301 dns_loadctx_t **ctxp, isc_mem_t *mctx); 302 303 /*%< 304 * Loads a RFC1305 master file from a file, stream, buffer, or existing 305 * lexer into rdatasets and then calls 'callbacks->commit' to commit the 306 * rdatasets. Rdata memory belongs to dns_master_load and will be 307 * reused / released when the callback completes. dns_load_master will 308 * abort if callbacks->commit returns any value other than ISC_R_SUCCESS. 309 * 310 * If 'DNS_MASTER_AGETTL' is set and the master file contains one or more 311 * $DATE directives, the TTLs of the data will be aged accordingly. 312 * 313 * 'callbacks->commit' is assumed to call 'callbacks->error' or 314 * 'callbacks->warn' to generate any error messages required. 315 * 316 * 'done' is called with 'done_arg' and a result code when the loading 317 * is completed or has failed. If the initial setup fails 'done' is 318 * not called. 319 * 320 * 'resign' the number of seconds before a RRSIG expires that it should 321 * be re-signed. 0 is used if not provided. 322 * 323 * Requires: 324 *\li 'master_file' points to a valid string. 325 *\li 'lexer' points to a valid lexer. 326 *\li 'top' points to a valid name. 327 *\li 'origin' points to a valid name. 328 *\li 'callbacks->commit' points to a valid function. 329 *\li 'callbacks->error' points to a valid function. 330 *\li 'callbacks->warn' points to a valid function. 331 *\li 'mctx' points to a valid memory context. 332 *\li 'task' and 'done' to be valid. 333 *\li 'lmgr' to be valid. 334 *\li 'ctxp != NULL && ctxp == NULL'. 335 * 336 * Returns: 337 *\li ISC_R_SUCCESS upon successfully loading the master file. 338 *\li ISC_R_SEENINCLUDE upon successfully loading the master file with 339 * a $INCLUDE statement. 340 *\li ISC_R_NOMEMORY out of memory. 341 *\li ISC_R_UNEXPECTEDEND expected to be able to read a input token and 342 * there was not one. 343 *\li ISC_R_UNEXPECTED 344 *\li DNS_R_NOOWNER failed to specify a ownername. 345 *\li DNS_R_NOTTL failed to specify a ttl. 346 *\li DNS_R_BADCLASS record class did not match zone class. 347 *\li DNS_R_CONTINUE load still in progress (dns_master_load*inc() only). 348 *\li Any dns_rdata_fromtext() error code. 349 *\li Any error code from callbacks->commit(). 350 */ 351 352 void 353 dns_loadctx_detach(dns_loadctx_t **ctxp); 354 /*%< 355 * Detach from the load context. 356 * 357 * Requires: 358 *\li '*ctxp' to be valid. 359 * 360 * Ensures: 361 *\li '*ctxp == NULL' 362 */ 363 364 void 365 dns_loadctx_attach(dns_loadctx_t *source, dns_loadctx_t **target); 366 /*%< 367 * Attach to the load context. 368 * 369 * Requires: 370 *\li 'source' to be valid. 371 *\li 'target != NULL && *target == NULL'. 372 */ 373 374 void 375 dns_loadctx_cancel(dns_loadctx_t *ctx); 376 /*%< 377 * Cancel loading the zone file associated with this load context. 378 * 379 * Requires: 380 *\li 'ctx' to be valid 381 */ 382 383 void 384 dns_master_initrawheader(dns_masterrawheader_t *header); 385 /*%< 386 * Initializes the header for a raw master file, setting all 387 * values to zero. 388 */ 389 ISC_LANG_ENDDECLS 390 391 #endif /* DNS_MASTER_H */ 392