namedconf.c revision 1.1.1.14 1 /* $NetBSD: namedconf.c,v 1.1.1.14 2024/09/22 00:06:15 christos Exp $ */
2
3 /*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16 /*! \file */
17
18 #include <inttypes.h>
19 #include <stdbool.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <isc/lex.h>
24 #include <isc/mem.h>
25 #include <isc/print.h>
26 #include <isc/result.h>
27 #include <isc/string.h>
28 #include <isc/util.h>
29
30 #include <dns/ttl.h>
31
32 #include <isccfg/cfg.h>
33 #include <isccfg/grammar.h>
34 #include <isccfg/log.h>
35 #include <isccfg/namedconf.h>
36
37 #define TOKEN_STRING(pctx) (pctx->token.value.as_textregion.base)
38
39 /*% Check a return value. */
40 #define CHECK(op) \
41 do { \
42 result = (op); \
43 if (result != ISC_R_SUCCESS) \
44 goto cleanup; \
45 } while (0)
46
47 /*% Clean up a configuration object if non-NULL. */
48 #define CLEANUP_OBJ(obj) \
49 do { \
50 if ((obj) != NULL) \
51 cfg_obj_destroy(pctx, &(obj)); \
52 } while (0)
53
54 /*%
55 * Forward declarations of static functions.
56 */
57
58 static isc_result_t
59 parse_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
60
61 static isc_result_t
62 parse_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type,
63 cfg_obj_t **ret);
64
65 static isc_result_t
66 parse_updatepolicy(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
67 static void
68 print_updatepolicy(cfg_printer_t *pctx, const cfg_obj_t *obj);
69
70 static void
71 doc_updatepolicy(cfg_printer_t *pctx, const cfg_type_t *type);
72
73 static void
74 print_keyvalue(cfg_printer_t *pctx, const cfg_obj_t *obj);
75
76 static void
77 doc_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);
78
79 static void
80 doc_optional_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);
81
82 static isc_result_t
83 cfg_parse_kv_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
84
85 static void
86 cfg_print_kv_tuple(cfg_printer_t *pctx, const cfg_obj_t *obj);
87
88 static void
89 cfg_doc_kv_tuple(cfg_printer_t *pctx, const cfg_type_t *type);
90
91 static cfg_type_t cfg_type_acl;
92 static cfg_type_t cfg_type_bracketed_dscpsockaddrlist;
93 static cfg_type_t cfg_type_bracketed_namesockaddrkeylist;
94 static cfg_type_t cfg_type_bracketed_netaddrlist;
95 static cfg_type_t cfg_type_bracketed_sockaddrnameportlist;
96 static cfg_type_t cfg_type_bracketed_http_endpoint_list;
97 static cfg_type_t cfg_type_controls;
98 static cfg_type_t cfg_type_controls_sockaddr;
99 static cfg_type_t cfg_type_destinationlist;
100 static cfg_type_t cfg_type_dialuptype;
101 static cfg_type_t cfg_type_dlz;
102 static cfg_type_t cfg_type_dnssecpolicy;
103 static cfg_type_t cfg_type_dnstap;
104 static cfg_type_t cfg_type_dnstapoutput;
105 static cfg_type_t cfg_type_dyndb;
106 static cfg_type_t cfg_type_http_description;
107 static cfg_type_t cfg_type_ixfrdifftype;
108 static cfg_type_t cfg_type_ixfrratio;
109 static cfg_type_t cfg_type_key;
110 static cfg_type_t cfg_type_logfile;
111 static cfg_type_t cfg_type_logging;
112 static cfg_type_t cfg_type_logseverity;
113 static cfg_type_t cfg_type_logsuffix;
114 static cfg_type_t cfg_type_logversions;
115 static cfg_type_t cfg_type_remoteselement;
116 static cfg_type_t cfg_type_maxduration;
117 static cfg_type_t cfg_type_minimal;
118 static cfg_type_t cfg_type_nameportiplist;
119 static cfg_type_t cfg_type_notifytype;
120 static cfg_type_t cfg_type_optional_allow;
121 static cfg_type_t cfg_type_optional_class;
122 static cfg_type_t cfg_type_optional_dscp;
123 static cfg_type_t cfg_type_optional_facility;
124 static cfg_type_t cfg_type_optional_keyref;
125 static cfg_type_t cfg_type_optional_port;
126 static cfg_type_t cfg_type_optional_uint32;
127 static cfg_type_t cfg_type_optional_tls;
128 static cfg_type_t cfg_type_options;
129 static cfg_type_t cfg_type_plugin;
130 static cfg_type_t cfg_type_portiplist;
131 static cfg_type_t cfg_type_printtime;
132 static cfg_type_t cfg_type_qminmethod;
133 static cfg_type_t cfg_type_querysource4;
134 static cfg_type_t cfg_type_querysource6;
135 static cfg_type_t cfg_type_querysource;
136 static cfg_type_t cfg_type_server;
137 static cfg_type_t cfg_type_server_key_kludge;
138 static cfg_type_t cfg_type_size;
139 static cfg_type_t cfg_type_sizenodefault;
140 static cfg_type_t cfg_type_sizeorpercent;
141 static cfg_type_t cfg_type_sizeval;
142 static cfg_type_t cfg_type_sockaddr4wild;
143 static cfg_type_t cfg_type_sockaddr6wild;
144 static cfg_type_t cfg_type_statschannels;
145 static cfg_type_t cfg_type_tlsconf;
146 static cfg_type_t cfg_type_view;
147 static cfg_type_t cfg_type_viewopts;
148 static cfg_type_t cfg_type_zone;
149
150 /*% tkey-dhkey */
151
152 static cfg_tuplefielddef_t tkey_dhkey_fields[] = {
153 { "name", &cfg_type_qstring, 0 },
154 { "keyid", &cfg_type_uint32, 0 },
155 { NULL, NULL, 0 }
156 };
157
158 static cfg_type_t cfg_type_tkey_dhkey = { "tkey-dhkey", cfg_parse_tuple,
159 cfg_print_tuple, cfg_doc_tuple,
160 &cfg_rep_tuple, tkey_dhkey_fields };
161
162 /*% listen-on */
163
164 static cfg_tuplefielddef_t listenon_tuple_fields[] = {
165 { "port", &cfg_type_optional_port, 0 },
166 { "dscp", &cfg_type_uint32,
167 CFG_CLAUSEFLAG_OBSOLETE | CFG_CLAUSEFLAG_NODOC },
168 { "tls", &cfg_type_astring, 0 },
169 #if HAVE_LIBNGHTTP2
170 { "http", &cfg_type_astring, 0 },
171 #else
172 { "http", &cfg_type_astring, CFG_CLAUSEFLAG_NOTCONFIGURED },
173 #endif
174 { NULL, NULL, 0 }
175 };
176 static cfg_type_t cfg_type_listen_tuple = {
177 "listenon tuple", cfg_parse_kv_tuple, cfg_print_kv_tuple,
178 cfg_doc_kv_tuple, &cfg_rep_tuple, listenon_tuple_fields
179 };
180
181 static cfg_tuplefielddef_t listenon_fields[] = {
182 { "tuple", &cfg_type_listen_tuple, 0 },
183 { "acl", &cfg_type_bracketed_aml, 0 },
184 { NULL, NULL, 0 }
185 };
186
187 static cfg_type_t cfg_type_listenon = { "listenon", cfg_parse_tuple,
188 cfg_print_tuple, cfg_doc_tuple,
189 &cfg_rep_tuple, listenon_fields };
190
191 /*% acl */
192
193 /*
194 * Encrypted transfer related definitions
195 */
196
197 static cfg_tuplefielddef_t cfg_transport_acl_tuple_fields[] = {
198 { "port", &cfg_type_optional_port, 0 },
199 { "transport", &cfg_type_astring, 0 },
200 { NULL, NULL, 0 }
201 };
202 static cfg_type_t cfg_transport_acl_tuple = {
203 "transport-acl tuple", cfg_parse_kv_tuple,
204 cfg_print_kv_tuple, cfg_doc_kv_tuple,
205 &cfg_rep_tuple, cfg_transport_acl_tuple_fields
206 };
207
208 static cfg_tuplefielddef_t cfg_transport_acl_fields[] = {
209 { "port-transport", &cfg_transport_acl_tuple, 0 },
210 { "aml", &cfg_type_bracketed_aml, 0 },
211 { NULL, NULL, 0 }
212 };
213
214 static cfg_type_t cfg_type_transport_acl = {
215 "transport-acl", cfg_parse_tuple, cfg_print_tuple,
216 cfg_doc_tuple, &cfg_rep_tuple, cfg_transport_acl_fields
217 };
218
219 /*
220 * NOTE: To enable syntax which allows specifying port and protocol,
221 * replace 'cfg_type_bracketed_aml' with
222 * 'cfg_type_transport_acl'.
223 *
224 * Example: acl port 853 protocol tls { ... };
225 */
226 static cfg_tuplefielddef_t acl_fields[] = { { "name", &cfg_type_astring, 0 },
227 { "value", &cfg_type_bracketed_aml,
228 0 },
229 { NULL, NULL, 0 } };
230
231 static cfg_type_t cfg_type_acl = { "acl", cfg_parse_tuple,
232 cfg_print_tuple, cfg_doc_tuple,
233 &cfg_rep_tuple, acl_fields };
234
235 /*% remote servers, used for primaries and parental agents */
236 static cfg_tuplefielddef_t remotes_fields[] = {
237 { "name", &cfg_type_astring, 0 },
238 { "port", &cfg_type_optional_port, 0 },
239 { "dscp", &cfg_type_optional_dscp, CFG_CLAUSEFLAG_OBSOLETE },
240 { "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 },
241 { NULL, NULL, 0 }
242 };
243
244 static cfg_type_t cfg_type_remoteservers = { "remote-servers", cfg_parse_tuple,
245 cfg_print_tuple, cfg_doc_tuple,
246 &cfg_rep_tuple, remotes_fields };
247
248 /*%
249 * "sockaddrkeylist", a list of socket addresses with optional keys
250 * and an optional default port, as used in the remote-servers option.
251 * E.g.,
252 * "port 1234 { myservers; 10.0.0.1 key foo; 1::2 port 69; }"
253 */
254
255 static cfg_tuplefielddef_t namesockaddrkey_fields[] = {
256 { "remoteselement", &cfg_type_remoteselement, 0 },
257 { "key", &cfg_type_optional_keyref, 0 },
258 { "tls", &cfg_type_optional_tls, 0 },
259 { NULL, NULL, 0 },
260 };
261
262 static cfg_type_t cfg_type_namesockaddrkey = {
263 "namesockaddrkey", cfg_parse_tuple, cfg_print_tuple,
264 cfg_doc_tuple, &cfg_rep_tuple, namesockaddrkey_fields
265 };
266
267 static cfg_type_t cfg_type_bracketed_namesockaddrkeylist = {
268 "bracketed_namesockaddrkeylist",
269 cfg_parse_bracketed_list,
270 cfg_print_bracketed_list,
271 cfg_doc_bracketed_list,
272 &cfg_rep_list,
273 &cfg_type_namesockaddrkey
274 };
275
276 static cfg_tuplefielddef_t namesockaddrkeylist_fields[] = {
277 { "port", &cfg_type_optional_port, 0 },
278 { "dscp", &cfg_type_optional_dscp, CFG_CLAUSEFLAG_OBSOLETE },
279 { "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 },
280 { NULL, NULL, 0 }
281 };
282 static cfg_type_t cfg_type_namesockaddrkeylist = {
283 "sockaddrkeylist", cfg_parse_tuple, cfg_print_tuple,
284 cfg_doc_tuple, &cfg_rep_tuple, namesockaddrkeylist_fields
285 };
286
287 /*%
288 * A list of socket addresses with an optional default port, as used
289 * in the 'listen-on' option. E.g., "{ 10.0.0.1; 1::2 port 69; }"
290 */
291 static cfg_tuplefielddef_t portiplist_fields[] = {
292 { "port", &cfg_type_optional_port, 0 },
293 { "dscp", &cfg_type_optional_dscp, CFG_CLAUSEFLAG_OBSOLETE },
294 { "addresses", &cfg_type_bracketed_dscpsockaddrlist, 0 },
295 { NULL, NULL, 0 }
296 };
297 static cfg_type_t cfg_type_portiplist = { "portiplist", cfg_parse_tuple,
298 cfg_print_tuple, cfg_doc_tuple,
299 &cfg_rep_tuple, portiplist_fields };
300
301 /*%
302 * A list of RR types, used in grant statements.
303 * Note that the old parser allows quotes around the RR type names.
304 */
305 static cfg_type_t cfg_type_rrtypelist = {
306 "rrtypelist", cfg_parse_spacelist, cfg_print_spacelist,
307 cfg_doc_terminal, &cfg_rep_list, &cfg_type_astring
308 };
309
310 static const char *mode_enums[] = { "deny", "grant", NULL };
311 static cfg_type_t cfg_type_mode = {
312 "mode", cfg_parse_enum, cfg_print_ustring,
313 cfg_doc_enum, &cfg_rep_string, &mode_enums
314 };
315
316 static isc_result_t
317 parse_matchtype(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
318 isc_result_t result;
319
320 CHECK(cfg_peektoken(pctx, 0));
321 if (pctx->token.type == isc_tokentype_string &&
322 strcasecmp(TOKEN_STRING(pctx), "zonesub") == 0)
323 {
324 pctx->flags |= CFG_PCTX_SKIP;
325 }
326 return (cfg_parse_enum(pctx, type, ret));
327
328 cleanup:
329 return (result);
330 }
331
332 static isc_result_t
333 parse_matchname(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
334 isc_result_t result;
335 cfg_obj_t *obj = NULL;
336
337 if ((pctx->flags & CFG_PCTX_SKIP) != 0) {
338 pctx->flags &= ~CFG_PCTX_SKIP;
339 CHECK(cfg_parse_void(pctx, NULL, &obj));
340 } else {
341 result = cfg_parse_astring(pctx, type, &obj);
342 }
343
344 *ret = obj;
345 cleanup:
346 return (result);
347 }
348
349 static void
350 doc_matchname(cfg_printer_t *pctx, const cfg_type_t *type) {
351 cfg_print_cstr(pctx, "[ ");
352 cfg_doc_obj(pctx, type->of);
353 cfg_print_cstr(pctx, " ]");
354 }
355
356 static const char *matchtype_enums[] = { "6to4-self",
357 "external",
358 "krb5-self",
359 "krb5-selfsub",
360 "krb5-subdomain",
361 "krb5-subdomain-self-rhs",
362 "ms-self",
363 "ms-selfsub",
364 "ms-subdomain",
365 "ms-subdomain-self-rhs",
366 "name",
367 "self",
368 "selfsub",
369 "selfwild",
370 "subdomain",
371 "tcp-self",
372 "wildcard",
373 "zonesub",
374 NULL };
375
376 static cfg_type_t cfg_type_matchtype = { "matchtype", parse_matchtype,
377 cfg_print_ustring, cfg_doc_enum,
378 &cfg_rep_string, &matchtype_enums };
379
380 static cfg_type_t cfg_type_matchname = {
381 "optional_matchname", parse_matchname, cfg_print_ustring,
382 doc_matchname, &cfg_rep_tuple, &cfg_type_ustring
383 };
384
385 /*%
386 * A grant statement, used in the update policy.
387 */
388 static cfg_tuplefielddef_t grant_fields[] = {
389 { "mode", &cfg_type_mode, 0 },
390 { "identity", &cfg_type_astring, 0 }, /* domain name */
391 { "matchtype", &cfg_type_matchtype, 0 },
392 { "name", &cfg_type_matchname, 0 }, /* domain name */
393 { "types", &cfg_type_rrtypelist, 0 },
394 { NULL, NULL, 0 }
395 };
396 static cfg_type_t cfg_type_grant = { "grant", cfg_parse_tuple,
397 cfg_print_tuple, cfg_doc_tuple,
398 &cfg_rep_tuple, grant_fields };
399
400 static cfg_type_t cfg_type_updatepolicy = {
401 "update_policy", parse_updatepolicy, print_updatepolicy,
402 doc_updatepolicy, &cfg_rep_list, &cfg_type_grant
403 };
404
405 static isc_result_t
406 parse_updatepolicy(cfg_parser_t *pctx, const cfg_type_t *type,
407 cfg_obj_t **ret) {
408 isc_result_t result;
409 CHECK(cfg_gettoken(pctx, 0));
410 if (pctx->token.type == isc_tokentype_special &&
411 pctx->token.value.as_char == '{')
412 {
413 cfg_ungettoken(pctx);
414 return (cfg_parse_bracketed_list(pctx, type, ret));
415 }
416
417 if (pctx->token.type == isc_tokentype_string &&
418 strcasecmp(TOKEN_STRING(pctx), "local") == 0)
419 {
420 cfg_obj_t *obj = NULL;
421 CHECK(cfg_create_obj(pctx, &cfg_type_ustring, &obj));
422 obj->value.string.length = strlen("local");
423 obj->value.string.base =
424 isc_mem_get(pctx->mctx, obj->value.string.length + 1);
425 memmove(obj->value.string.base, "local", 5);
426 obj->value.string.base[5] = '\0';
427 *ret = obj;
428 return (ISC_R_SUCCESS);
429 }
430
431 cfg_ungettoken(pctx);
432 return (ISC_R_UNEXPECTEDTOKEN);
433
434 cleanup:
435 return (result);
436 }
437
438 static void
439 print_updatepolicy(cfg_printer_t *pctx, const cfg_obj_t *obj) {
440 if (cfg_obj_isstring(obj)) {
441 cfg_print_ustring(pctx, obj);
442 } else {
443 cfg_print_bracketed_list(pctx, obj);
444 }
445 }
446
447 static void
448 doc_updatepolicy(cfg_printer_t *pctx, const cfg_type_t *type) {
449 cfg_print_cstr(pctx, "( local | { ");
450 cfg_doc_obj(pctx, type->of);
451 cfg_print_cstr(pctx, "; ... } )");
452 }
453
454 /*%
455 * A view statement.
456 */
457 static cfg_tuplefielddef_t view_fields[] = {
458 { "name", &cfg_type_astring, 0 },
459 { "class", &cfg_type_optional_class, 0 },
460 { "options", &cfg_type_viewopts, 0 },
461 { NULL, NULL, 0 }
462 };
463 static cfg_type_t cfg_type_view = { "view", cfg_parse_tuple,
464 cfg_print_tuple, cfg_doc_tuple,
465 &cfg_rep_tuple, view_fields };
466
467 /*%
468 * A zone statement.
469 */
470 static cfg_tuplefielddef_t zone_fields[] = {
471 { "name", &cfg_type_astring, 0 },
472 { "class", &cfg_type_optional_class, 0 },
473 { "options", &cfg_type_zoneopts, 0 },
474 { NULL, NULL, 0 }
475 };
476 static cfg_type_t cfg_type_zone = { "zone", cfg_parse_tuple,
477 cfg_print_tuple, cfg_doc_tuple,
478 &cfg_rep_tuple, zone_fields };
479
480 /*%
481 * A dnssec-policy statement.
482 */
483 static cfg_tuplefielddef_t dnssecpolicy_fields[] = {
484 { "name", &cfg_type_astring, 0 },
485 { "options", &cfg_type_dnssecpolicyopts, 0 },
486 { NULL, NULL, 0 }
487 };
488
489 static cfg_type_t cfg_type_dnssecpolicy = {
490 "dnssec-policy", cfg_parse_tuple, cfg_print_tuple,
491 cfg_doc_tuple, &cfg_rep_tuple, dnssecpolicy_fields
492 };
493
494 /*%
495 * A "category" clause in the "logging" statement.
496 */
497 static cfg_tuplefielddef_t category_fields[] = {
498 { "name", &cfg_type_astring, 0 },
499 { "destinations", &cfg_type_destinationlist, 0 },
500 { NULL, NULL, 0 }
501 };
502 static cfg_type_t cfg_type_category = { "category", cfg_parse_tuple,
503 cfg_print_tuple, cfg_doc_tuple,
504 &cfg_rep_tuple, category_fields };
505
506 static isc_result_t
507 parse_maxduration(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
508 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_duration, ret));
509 }
510
511 static void
512 doc_maxduration(cfg_printer_t *pctx, const cfg_type_t *type) {
513 cfg_doc_enum_or_other(pctx, type, &cfg_type_duration);
514 }
515
516 /*%
517 * A duration or "unlimited", but not "default".
518 */
519 static const char *maxduration_enums[] = { "unlimited", NULL };
520 static cfg_type_t cfg_type_maxduration = {
521 "maxduration_no_default", parse_maxduration, cfg_print_ustring,
522 doc_maxduration, &cfg_rep_duration, maxduration_enums
523 };
524
525 /*%
526 * A dnssec key, as used in the "trusted-keys" statement.
527 */
528 static cfg_tuplefielddef_t dnsseckey_fields[] = {
529 { "name", &cfg_type_astring, 0 },
530 { "anchortype", &cfg_type_void, 0 },
531 { "rdata1", &cfg_type_uint32, 0 },
532 { "rdata2", &cfg_type_uint32, 0 },
533 { "rdata3", &cfg_type_uint32, 0 },
534 { "data", &cfg_type_qstring, 0 },
535 { NULL, NULL, 0 }
536 };
537 static cfg_type_t cfg_type_dnsseckey = { "dnsseckey", cfg_parse_tuple,
538 cfg_print_tuple, cfg_doc_tuple,
539 &cfg_rep_tuple, dnsseckey_fields };
540
541 /*%
542 * Optional enums.
543 *
544 */
545 static isc_result_t
546 parse_optional_enum(cfg_parser_t *pctx, const cfg_type_t *type,
547 cfg_obj_t **ret) {
548 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_void, ret));
549 }
550
551 static void
552 doc_optional_enum(cfg_printer_t *pctx, const cfg_type_t *type) {
553 UNUSED(type);
554 cfg_print_cstr(pctx, "[ ");
555 cfg_doc_enum(pctx, type);
556 cfg_print_cstr(pctx, " ]");
557 }
558
559 /*%
560 * A key initialization specifier, as used in the
561 * "trust-anchors" (or synonymous "managed-keys") statement.
562 */
563 static const char *anchortype_enums[] = { "static-key", "initial-key",
564 "static-ds", "initial-ds", NULL };
565 static cfg_type_t cfg_type_anchortype = { "anchortype", cfg_parse_enum,
566 cfg_print_ustring, cfg_doc_enum,
567 &cfg_rep_string, anchortype_enums };
568 static cfg_tuplefielddef_t managedkey_fields[] = {
569 { "name", &cfg_type_astring, 0 },
570 { "anchortype", &cfg_type_anchortype, 0 },
571 { "rdata1", &cfg_type_uint32, 0 },
572 { "rdata2", &cfg_type_uint32, 0 },
573 { "rdata3", &cfg_type_uint32, 0 },
574 { "data", &cfg_type_qstring, 0 },
575 { NULL, NULL, 0 }
576 };
577 static cfg_type_t cfg_type_managedkey = { "managedkey", cfg_parse_tuple,
578 cfg_print_tuple, cfg_doc_tuple,
579 &cfg_rep_tuple, managedkey_fields };
580
581 /*%
582 * DNSSEC key roles.
583 */
584 static const char *dnsseckeyrole_enums[] = { "csk", "ksk", "zsk", NULL };
585 static cfg_type_t cfg_type_dnsseckeyrole = {
586 "dnssec-key-role", cfg_parse_enum, cfg_print_ustring,
587 cfg_doc_enum, &cfg_rep_string, &dnsseckeyrole_enums
588 };
589
590 /*%
591 * DNSSEC key storage types.
592 */
593 static const char *dnsseckeystore_enums[] = { "key-directory", NULL };
594 static cfg_type_t cfg_type_dnsseckeystore = {
595 "dnssec-key-storage", parse_optional_enum, cfg_print_ustring,
596 doc_optional_enum, &cfg_rep_string, dnsseckeystore_enums
597 };
598
599 /*%
600 * A dnssec key, as used in the "keys" statement in a "dnssec-policy".
601 */
602 static keyword_type_t algorithm_kw = { "algorithm", &cfg_type_ustring };
603 static cfg_type_t cfg_type_algorithm = { "algorithm", parse_keyvalue,
604 print_keyvalue, doc_keyvalue,
605 &cfg_rep_string, &algorithm_kw };
606
607 static keyword_type_t lifetime_kw = { "lifetime",
608 &cfg_type_duration_or_unlimited };
609 static cfg_type_t cfg_type_lifetime = { "lifetime", parse_keyvalue,
610 print_keyvalue, doc_keyvalue,
611 &cfg_rep_duration, &lifetime_kw };
612
613 static cfg_tuplefielddef_t kaspkey_fields[] = {
614 { "role", &cfg_type_dnsseckeyrole, 0 },
615 { "keystore-type", &cfg_type_dnsseckeystore, 0 },
616 { "lifetime", &cfg_type_lifetime, 0 },
617 { "algorithm", &cfg_type_algorithm, 0 },
618 { "length", &cfg_type_optional_uint32, 0 },
619 { NULL, NULL, 0 }
620 };
621 static cfg_type_t cfg_type_kaspkey = { "kaspkey", cfg_parse_tuple,
622 cfg_print_tuple, cfg_doc_tuple,
623 &cfg_rep_tuple, kaspkey_fields };
624
625 /*%
626 * NSEC3 parameters.
627 */
628 static keyword_type_t nsec3iter_kw = { "iterations", &cfg_type_uint32 };
629 static cfg_type_t cfg_type_nsec3iter = {
630 "iterations", parse_optional_keyvalue, print_keyvalue,
631 doc_optional_keyvalue, &cfg_rep_uint32, &nsec3iter_kw
632 };
633
634 static keyword_type_t nsec3optout_kw = { "optout", &cfg_type_boolean };
635 static cfg_type_t cfg_type_nsec3optout = {
636 "optout", parse_optional_keyvalue,
637 print_keyvalue, doc_optional_keyvalue,
638 &cfg_rep_boolean, &nsec3optout_kw
639 };
640
641 static keyword_type_t nsec3salt_kw = { "salt-length", &cfg_type_uint32 };
642 static cfg_type_t cfg_type_nsec3salt = {
643 "salt-length", parse_optional_keyvalue, print_keyvalue,
644 doc_optional_keyvalue, &cfg_rep_uint32, &nsec3salt_kw
645 };
646
647 static cfg_tuplefielddef_t nsec3param_fields[] = {
648 { "iterations", &cfg_type_nsec3iter, 0 },
649 { "optout", &cfg_type_nsec3optout, 0 },
650 { "salt-length", &cfg_type_nsec3salt, 0 },
651 { NULL, NULL, 0 }
652 };
653
654 static cfg_type_t cfg_type_nsec3 = { "nsec3param", cfg_parse_tuple,
655 cfg_print_tuple, cfg_doc_tuple,
656 &cfg_rep_tuple, nsec3param_fields };
657
658 /*%
659 * Wild class, type, name.
660 */
661 static keyword_type_t wild_class_kw = { "class", &cfg_type_ustring };
662
663 static cfg_type_t cfg_type_optional_wild_class = {
664 "optional_wild_class", parse_optional_keyvalue, print_keyvalue,
665 doc_optional_keyvalue, &cfg_rep_string, &wild_class_kw
666 };
667
668 static keyword_type_t wild_type_kw = { "type", &cfg_type_ustring };
669
670 static cfg_type_t cfg_type_optional_wild_type = {
671 "optional_wild_type", parse_optional_keyvalue, print_keyvalue,
672 doc_optional_keyvalue, &cfg_rep_string, &wild_type_kw
673 };
674
675 static keyword_type_t wild_name_kw = { "name", &cfg_type_qstring };
676
677 static cfg_type_t cfg_type_optional_wild_name = {
678 "optional_wild_name", parse_optional_keyvalue, print_keyvalue,
679 doc_optional_keyvalue, &cfg_rep_string, &wild_name_kw
680 };
681
682 /*%
683 * An rrset ordering element.
684 */
685 static cfg_tuplefielddef_t rrsetorderingelement_fields[] = {
686 { "class", &cfg_type_optional_wild_class, 0 },
687 { "type", &cfg_type_optional_wild_type, 0 },
688 { "name", &cfg_type_optional_wild_name, 0 },
689 { "order", &cfg_type_ustring, 0 }, /* must be literal "order" */
690 { "ordering", &cfg_type_ustring, 0 },
691 { NULL, NULL, 0 }
692 };
693 static cfg_type_t cfg_type_rrsetorderingelement = {
694 "rrsetorderingelement", cfg_parse_tuple, cfg_print_tuple,
695 cfg_doc_tuple, &cfg_rep_tuple, rrsetorderingelement_fields
696 };
697
698 /*%
699 * A global or view "check-names" option. Note that the zone
700 * "check-names" option has a different syntax.
701 */
702
703 static const char *checktype_enums[] = { "primary", "master", "secondary",
704 "slave", "response", NULL };
705 static cfg_type_t cfg_type_checktype = { "checktype", cfg_parse_enum,
706 cfg_print_ustring, cfg_doc_enum,
707 &cfg_rep_string, &checktype_enums };
708
709 static const char *checkmode_enums[] = { "fail", "warn", "ignore", NULL };
710 static cfg_type_t cfg_type_checkmode = { "checkmode", cfg_parse_enum,
711 cfg_print_ustring, cfg_doc_enum,
712 &cfg_rep_string, &checkmode_enums };
713
714 static const char *warn_enums[] = { "warn", "ignore", NULL };
715 static cfg_type_t cfg_type_warn = {
716 "warn", cfg_parse_enum, cfg_print_ustring,
717 cfg_doc_enum, &cfg_rep_string, &warn_enums
718 };
719
720 static cfg_tuplefielddef_t checknames_fields[] = {
721 { "type", &cfg_type_checktype, 0 },
722 { "mode", &cfg_type_checkmode, 0 },
723 { NULL, NULL, 0 }
724 };
725
726 static cfg_type_t cfg_type_checknames = { "checknames", cfg_parse_tuple,
727 cfg_print_tuple, cfg_doc_tuple,
728 &cfg_rep_tuple, checknames_fields };
729
730 static cfg_type_t cfg_type_bracketed_dscpsockaddrlist = {
731 "bracketed_sockaddrlist",
732 cfg_parse_bracketed_list,
733 cfg_print_bracketed_list,
734 cfg_doc_bracketed_list,
735 &cfg_rep_list,
736 &cfg_type_sockaddrdscp
737 };
738
739 static cfg_type_t cfg_type_bracketed_netaddrlist = { "bracketed_netaddrlist",
740 cfg_parse_bracketed_list,
741 cfg_print_bracketed_list,
742 cfg_doc_bracketed_list,
743 &cfg_rep_list,
744 &cfg_type_netaddr };
745
746 static const char *autodnssec_enums[] = { "allow", "maintain", "off", NULL };
747 static cfg_type_t cfg_type_autodnssec = {
748 "autodnssec", cfg_parse_enum, cfg_print_ustring,
749 cfg_doc_enum, &cfg_rep_string, &autodnssec_enums
750 };
751
752 static const char *dnssecupdatemode_enums[] = { "maintain", "no-resign", NULL };
753 static cfg_type_t cfg_type_dnssecupdatemode = {
754 "dnssecupdatemode", cfg_parse_enum, cfg_print_ustring,
755 cfg_doc_enum, &cfg_rep_string, &dnssecupdatemode_enums
756 };
757
758 static const char *updatemethods_enums[] = { "date", "increment", "unixtime",
759 NULL };
760 static cfg_type_t cfg_type_updatemethod = {
761 "updatemethod", cfg_parse_enum, cfg_print_ustring,
762 cfg_doc_enum, &cfg_rep_string, &updatemethods_enums
763 };
764
765 /*
766 * zone-statistics: full, terse, or none.
767 *
768 * for backward compatibility, we also support boolean values.
769 * yes represents "full", no represents "terse". in the future we
770 * may change no to mean "none".
771 */
772 static const char *zonestat_enums[] = { "full", "terse", "none", NULL };
773 static isc_result_t
774 parse_zonestat(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
775 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
776 }
777 static void
778 doc_zonestat(cfg_printer_t *pctx, const cfg_type_t *type) {
779 cfg_doc_enum_or_other(pctx, type, &cfg_type_boolean);
780 }
781 static cfg_type_t cfg_type_zonestat = { "zonestat", parse_zonestat,
782 cfg_print_ustring, doc_zonestat,
783 &cfg_rep_string, zonestat_enums };
784
785 static cfg_type_t cfg_type_rrsetorder = { "rrsetorder",
786 cfg_parse_bracketed_list,
787 cfg_print_bracketed_list,
788 cfg_doc_bracketed_list,
789 &cfg_rep_list,
790 &cfg_type_rrsetorderingelement };
791
792 static keyword_type_t dscp_kw = { "dscp", &cfg_type_uint32 };
793
794 static cfg_type_t cfg_type_optional_dscp = {
795 "optional_dscp", parse_optional_keyvalue, print_keyvalue,
796 cfg_doc_void, &cfg_rep_uint32, &dscp_kw
797 };
798
799 static keyword_type_t port_kw = { "port", &cfg_type_uint32 };
800
801 static cfg_type_t cfg_type_optional_port = {
802 "optional_port", parse_optional_keyvalue, print_keyvalue,
803 doc_optional_keyvalue, &cfg_rep_uint32, &port_kw
804 };
805
806 /*% A list of keys, as in the "key" clause of the controls statement. */
807 static cfg_type_t cfg_type_keylist = { "keylist",
808 cfg_parse_bracketed_list,
809 cfg_print_bracketed_list,
810 cfg_doc_bracketed_list,
811 &cfg_rep_list,
812 &cfg_type_astring };
813
814 /*% A list of dnssec keys, as in "trusted-keys". Deprecated. */
815 static cfg_type_t cfg_type_trustedkeys = { "trustedkeys",
816 cfg_parse_bracketed_list,
817 cfg_print_bracketed_list,
818 cfg_doc_bracketed_list,
819 &cfg_rep_list,
820 &cfg_type_dnsseckey };
821
822 /*%
823 * A list of managed trust anchors. Each entry contains a name, a keyword
824 * ("static-key", initial-key", "static-ds" or "initial-ds"), and the
825 * fields associated with either a DNSKEY or a DS record.
826 */
827 static cfg_type_t cfg_type_dnsseckeys = { "dnsseckeys",
828 cfg_parse_bracketed_list,
829 cfg_print_bracketed_list,
830 cfg_doc_bracketed_list,
831 &cfg_rep_list,
832 &cfg_type_managedkey };
833
834 /*%
835 * A list of key entries, used in a DNSSEC Key and Signing Policy.
836 */
837 static cfg_type_t cfg_type_kaspkeys = { "kaspkeys",
838 cfg_parse_bracketed_list,
839 cfg_print_bracketed_list,
840 cfg_doc_bracketed_list,
841 &cfg_rep_list,
842 &cfg_type_kaspkey };
843
844 static const char *forwardtype_enums[] = { "first", "only", NULL };
845 static cfg_type_t cfg_type_forwardtype = {
846 "forwardtype", cfg_parse_enum, cfg_print_ustring,
847 cfg_doc_enum, &cfg_rep_string, &forwardtype_enums
848 };
849
850 static const char *zonetype_enums[] = {
851 "primary", "master", "secondary", "slave",
852 "mirror", "delegation-only", "forward", "hint",
853 "redirect", "static-stub", "stub", NULL
854 };
855 static cfg_type_t cfg_type_zonetype = { "zonetype", cfg_parse_enum,
856 cfg_print_ustring, cfg_doc_enum,
857 &cfg_rep_string, &zonetype_enums };
858
859 static const char *loglevel_enums[] = { "critical", "error", "warning",
860 "notice", "info", "dynamic",
861 NULL };
862 static cfg_type_t cfg_type_loglevel = { "loglevel", cfg_parse_enum,
863 cfg_print_ustring, cfg_doc_enum,
864 &cfg_rep_string, &loglevel_enums };
865
866 static const char *transferformat_enums[] = { "many-answers", "one-answer",
867 NULL };
868 static cfg_type_t cfg_type_transferformat = {
869 "transferformat", cfg_parse_enum, cfg_print_ustring,
870 cfg_doc_enum, &cfg_rep_string, &transferformat_enums
871 };
872
873 /*%
874 * The special keyword "none", as used in the pid-file option.
875 */
876
877 static void
878 print_none(cfg_printer_t *pctx, const cfg_obj_t *obj) {
879 UNUSED(obj);
880 cfg_print_cstr(pctx, "none");
881 }
882
883 static cfg_type_t cfg_type_none = { "none", NULL, print_none,
884 NULL, &cfg_rep_void, NULL };
885
886 /*%
887 * A quoted string or the special keyword "none". Used in the pid-file option.
888 */
889 static isc_result_t
890 parse_qstringornone(cfg_parser_t *pctx, const cfg_type_t *type,
891 cfg_obj_t **ret) {
892 isc_result_t result;
893
894 CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
895 if (pctx->token.type == isc_tokentype_string &&
896 strcasecmp(TOKEN_STRING(pctx), "none") == 0)
897 {
898 return (cfg_create_obj(pctx, &cfg_type_none, ret));
899 }
900 cfg_ungettoken(pctx);
901 return (cfg_parse_qstring(pctx, type, ret));
902 cleanup:
903 return (result);
904 }
905
906 static void
907 doc_qstringornone(cfg_printer_t *pctx, const cfg_type_t *type) {
908 UNUSED(type);
909 cfg_print_cstr(pctx, "( <quoted_string> | none )");
910 }
911
912 static cfg_type_t cfg_type_qstringornone = { "qstringornone",
913 parse_qstringornone,
914 NULL,
915 doc_qstringornone,
916 NULL,
917 NULL };
918
919 /*%
920 * A boolean ("yes" or "no"), or the special keyword "auto".
921 * Used in the dnssec-validation option.
922 */
923 static void
924 print_auto(cfg_printer_t *pctx, const cfg_obj_t *obj) {
925 UNUSED(obj);
926 cfg_print_cstr(pctx, "auto");
927 }
928
929 static cfg_type_t cfg_type_auto = { "auto", NULL, print_auto,
930 NULL, &cfg_rep_void, NULL };
931
932 static isc_result_t
933 parse_boolorauto(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
934 isc_result_t result;
935
936 CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
937 if (pctx->token.type == isc_tokentype_string &&
938 strcasecmp(TOKEN_STRING(pctx), "auto") == 0)
939 {
940 return (cfg_create_obj(pctx, &cfg_type_auto, ret));
941 }
942 cfg_ungettoken(pctx);
943 return (cfg_parse_boolean(pctx, type, ret));
944 cleanup:
945 return (result);
946 }
947
948 static void
949 print_boolorauto(cfg_printer_t *pctx, const cfg_obj_t *obj) {
950 if (obj->type->rep == &cfg_rep_void) {
951 cfg_print_cstr(pctx, "auto");
952 } else if (obj->value.boolean) {
953 cfg_print_cstr(pctx, "yes");
954 } else {
955 cfg_print_cstr(pctx, "no");
956 }
957 }
958
959 static void
960 doc_boolorauto(cfg_printer_t *pctx, const cfg_type_t *type) {
961 UNUSED(type);
962 cfg_print_cstr(pctx, "( yes | no | auto )");
963 }
964
965 static cfg_type_t cfg_type_boolorauto = {
966 "boolorauto", parse_boolorauto, print_boolorauto, doc_boolorauto, NULL,
967 NULL
968 };
969
970 /*%
971 * keyword hostname
972 */
973 static void
974 print_hostname(cfg_printer_t *pctx, const cfg_obj_t *obj) {
975 UNUSED(obj);
976 cfg_print_cstr(pctx, "hostname");
977 }
978
979 static cfg_type_t cfg_type_hostname = { "hostname", NULL,
980 print_hostname, NULL,
981 &cfg_rep_boolean, NULL };
982
983 /*%
984 * "server-id" argument.
985 */
986
987 static isc_result_t
988 parse_serverid(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
989 isc_result_t result;
990 CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
991 if (pctx->token.type == isc_tokentype_string &&
992 strcasecmp(TOKEN_STRING(pctx), "none") == 0)
993 {
994 return (cfg_create_obj(pctx, &cfg_type_none, ret));
995 }
996 if (pctx->token.type == isc_tokentype_string &&
997 strcasecmp(TOKEN_STRING(pctx), "hostname") == 0)
998 {
999 result = cfg_create_obj(pctx, &cfg_type_hostname, ret);
1000 if (result == ISC_R_SUCCESS) {
1001 (*ret)->value.boolean = true;
1002 }
1003 return (result);
1004 }
1005 cfg_ungettoken(pctx);
1006 return (cfg_parse_qstring(pctx, type, ret));
1007 cleanup:
1008 return (result);
1009 }
1010
1011 static void
1012 doc_serverid(cfg_printer_t *pctx, const cfg_type_t *type) {
1013 UNUSED(type);
1014 cfg_print_cstr(pctx, "( <quoted_string> | none | hostname )");
1015 }
1016
1017 static cfg_type_t cfg_type_serverid = { "serverid", parse_serverid, NULL,
1018 doc_serverid, NULL, NULL };
1019
1020 /*%
1021 * Port list.
1022 */
1023 static void
1024 print_porttuple(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1025 cfg_print_cstr(pctx, "range ");
1026 cfg_print_tuple(pctx, obj);
1027 }
1028 static cfg_tuplefielddef_t porttuple_fields[] = {
1029 { "loport", &cfg_type_uint32, 0 },
1030 { "hiport", &cfg_type_uint32, 0 },
1031 { NULL, NULL, 0 }
1032 };
1033 static cfg_type_t cfg_type_porttuple = { "porttuple", cfg_parse_tuple,
1034 print_porttuple, cfg_doc_tuple,
1035 &cfg_rep_tuple, porttuple_fields };
1036
1037 static isc_result_t
1038 parse_port(cfg_parser_t *pctx, cfg_obj_t **ret) {
1039 isc_result_t result;
1040
1041 CHECK(cfg_parse_uint32(pctx, NULL, ret));
1042 if ((*ret)->value.uint32 > 0xffff) {
1043 cfg_parser_error(pctx, CFG_LOG_NEAR, "invalid port");
1044 cfg_obj_destroy(pctx, ret);
1045 result = ISC_R_RANGE;
1046 }
1047
1048 cleanup:
1049 return (result);
1050 }
1051
1052 static isc_result_t
1053 parse_portrange(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1054 isc_result_t result;
1055 cfg_obj_t *obj = NULL;
1056
1057 UNUSED(type);
1058
1059 CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
1060 if (pctx->token.type == isc_tokentype_number) {
1061 CHECK(parse_port(pctx, ret));
1062 } else {
1063 CHECK(cfg_gettoken(pctx, 0));
1064 if (pctx->token.type != isc_tokentype_string ||
1065 strcasecmp(TOKEN_STRING(pctx), "range") != 0)
1066 {
1067 cfg_parser_error(pctx, CFG_LOG_NEAR,
1068 "expected integer or 'range'");
1069 return (ISC_R_UNEXPECTEDTOKEN);
1070 }
1071 CHECK(cfg_create_tuple(pctx, &cfg_type_porttuple, &obj));
1072 CHECK(parse_port(pctx, &obj->value.tuple[0]));
1073 CHECK(parse_port(pctx, &obj->value.tuple[1]));
1074 if (obj->value.tuple[0]->value.uint32 >
1075 obj->value.tuple[1]->value.uint32)
1076 {
1077 cfg_parser_error(pctx, CFG_LOG_NOPREP,
1078 "low port '%u' must not be larger "
1079 "than high port",
1080 obj->value.tuple[0]->value.uint32);
1081 result = ISC_R_RANGE;
1082 goto cleanup;
1083 }
1084 *ret = obj;
1085 obj = NULL;
1086 }
1087
1088 cleanup:
1089 if (obj != NULL) {
1090 cfg_obj_destroy(pctx, &obj);
1091 }
1092 return (result);
1093 }
1094
1095 static cfg_type_t cfg_type_portrange = { "portrange", parse_portrange,
1096 NULL, cfg_doc_terminal,
1097 NULL, NULL };
1098
1099 static cfg_type_t cfg_type_bracketed_portlist = { "bracketed_sockaddrlist",
1100 cfg_parse_bracketed_list,
1101 cfg_print_bracketed_list,
1102 cfg_doc_bracketed_list,
1103 &cfg_rep_list,
1104 &cfg_type_portrange };
1105
1106 static const char *cookiealg_enums[] = { "aes", "siphash24", NULL };
1107 static cfg_type_t cfg_type_cookiealg = { "cookiealg", cfg_parse_enum,
1108 cfg_print_ustring, cfg_doc_enum,
1109 &cfg_rep_string, &cookiealg_enums };
1110
1111 /*%
1112 * fetch-quota-params
1113 */
1114
1115 static cfg_tuplefielddef_t fetchquota_fields[] = {
1116 { "frequency", &cfg_type_uint32, 0 },
1117 { "low", &cfg_type_fixedpoint, 0 },
1118 { "high", &cfg_type_fixedpoint, 0 },
1119 { "discount", &cfg_type_fixedpoint, 0 },
1120 { NULL, NULL, 0 }
1121 };
1122
1123 static cfg_type_t cfg_type_fetchquota = { "fetchquota", cfg_parse_tuple,
1124 cfg_print_tuple, cfg_doc_tuple,
1125 &cfg_rep_tuple, fetchquota_fields };
1126
1127 /*%
1128 * fetches-per-server or fetches-per-zone
1129 */
1130
1131 static const char *response_enums[] = { "drop", "fail", NULL };
1132
1133 static cfg_type_t cfg_type_responsetype = {
1134 "responsetype", parse_optional_enum, cfg_print_ustring,
1135 doc_optional_enum, &cfg_rep_string, response_enums
1136 };
1137
1138 static cfg_tuplefielddef_t fetchesper_fields[] = {
1139 { "fetches", &cfg_type_uint32, 0 },
1140 { "response", &cfg_type_responsetype, 0 },
1141 { NULL, NULL, 0 }
1142 };
1143
1144 static cfg_type_t cfg_type_fetchesper = { "fetchesper", cfg_parse_tuple,
1145 cfg_print_tuple, cfg_doc_tuple,
1146 &cfg_rep_tuple, fetchesper_fields };
1147
1148 /*%
1149 * Clauses that can be found within the top level of the named.conf
1150 * file only.
1151 */
1152 static cfg_clausedef_t namedconf_clauses[] = {
1153 { "acl", &cfg_type_acl, CFG_CLAUSEFLAG_MULTI },
1154 { "controls", &cfg_type_controls, CFG_CLAUSEFLAG_MULTI },
1155 { "dnssec-policy", &cfg_type_dnssecpolicy, CFG_CLAUSEFLAG_MULTI },
1156 #if HAVE_LIBNGHTTP2
1157 { "http", &cfg_type_http_description, CFG_CLAUSEFLAG_MULTI },
1158 #else
1159 { "http", &cfg_type_http_description,
1160 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_NOTCONFIGURED },
1161 #endif
1162 { "logging", &cfg_type_logging, 0 },
1163 { "lwres", NULL, CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_ANCIENT },
1164 { "masters", &cfg_type_remoteservers,
1165 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_NODOC },
1166 { "options", &cfg_type_options, 0 },
1167 { "parental-agents", &cfg_type_remoteservers, CFG_CLAUSEFLAG_MULTI },
1168 { "primaries", &cfg_type_remoteservers, CFG_CLAUSEFLAG_MULTI },
1169 { "statistics-channels", &cfg_type_statschannels,
1170 CFG_CLAUSEFLAG_MULTI },
1171 { "tls", &cfg_type_tlsconf, CFG_CLAUSEFLAG_MULTI },
1172 { "view", &cfg_type_view, CFG_CLAUSEFLAG_MULTI },
1173 { NULL, NULL, 0 }
1174 };
1175
1176 /*%
1177 * Clauses that can occur at the top level or in the view
1178 * statement, but not in the options block.
1179 */
1180 static cfg_clausedef_t namedconf_or_view_clauses[] = {
1181 { "dlz", &cfg_type_dlz, CFG_CLAUSEFLAG_MULTI },
1182 { "dyndb", &cfg_type_dyndb, CFG_CLAUSEFLAG_MULTI },
1183 { "key", &cfg_type_key, CFG_CLAUSEFLAG_MULTI },
1184 { "managed-keys", &cfg_type_dnsseckeys,
1185 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_DEPRECATED },
1186 { "plugin", &cfg_type_plugin, CFG_CLAUSEFLAG_MULTI },
1187 { "server", &cfg_type_server, CFG_CLAUSEFLAG_MULTI },
1188 { "trust-anchors", &cfg_type_dnsseckeys, CFG_CLAUSEFLAG_MULTI },
1189 { "trusted-keys", &cfg_type_trustedkeys,
1190 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_DEPRECATED },
1191 { "zone", &cfg_type_zone, CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_NODOC },
1192 { NULL, NULL, 0 }
1193 };
1194
1195 /*%
1196 * Clauses that can occur in the bind.keys file.
1197 */
1198 static cfg_clausedef_t bindkeys_clauses[] = {
1199 { "managed-keys", &cfg_type_dnsseckeys,
1200 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_DEPRECATED },
1201 { "trust-anchors", &cfg_type_dnsseckeys, CFG_CLAUSEFLAG_MULTI },
1202 { "trusted-keys", &cfg_type_trustedkeys,
1203 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_DEPRECATED },
1204 { NULL, NULL, 0 }
1205 };
1206
1207 static const char *fstrm_model_enums[] = { "mpsc", "spsc", NULL };
1208 static cfg_type_t cfg_type_fstrm_model = {
1209 "model", cfg_parse_enum, cfg_print_ustring,
1210 cfg_doc_enum, &cfg_rep_string, &fstrm_model_enums
1211 };
1212
1213 /*%
1214 * Clauses that can be found within the 'options' statement.
1215 */
1216 static cfg_clausedef_t options_clauses[] = {
1217 { "answer-cookie", &cfg_type_boolean, 0 },
1218 { "automatic-interface-scan", &cfg_type_boolean, 0 },
1219 { "avoid-v4-udp-ports", &cfg_type_bracketed_portlist,
1220 CFG_CLAUSEFLAG_DEPRECATED },
1221 { "avoid-v6-udp-ports", &cfg_type_bracketed_portlist,
1222 CFG_CLAUSEFLAG_DEPRECATED },
1223 { "bindkeys-file", &cfg_type_qstring, 0 },
1224 { "blackhole", &cfg_type_bracketed_aml, 0 },
1225 { "cookie-algorithm", &cfg_type_cookiealg, 0 },
1226 { "cookie-secret", &cfg_type_sstring, CFG_CLAUSEFLAG_MULTI },
1227 { "coresize", &cfg_type_size, CFG_CLAUSEFLAG_DEPRECATED },
1228 { "datasize", &cfg_type_size, CFG_CLAUSEFLAG_DEPRECATED },
1229 { "deallocate-on-exit", NULL, CFG_CLAUSEFLAG_ANCIENT },
1230 { "directory", &cfg_type_qstring, CFG_CLAUSEFLAG_CALLBACK },
1231 #ifdef HAVE_DNSTAP
1232 { "dnstap-output", &cfg_type_dnstapoutput, 0 },
1233 { "dnstap-identity", &cfg_type_serverid, 0 },
1234 { "dnstap-version", &cfg_type_qstringornone, 0 },
1235 #else /* ifdef HAVE_DNSTAP */
1236 { "dnstap-output", &cfg_type_dnstapoutput,
1237 CFG_CLAUSEFLAG_NOTCONFIGURED },
1238 { "dnstap-identity", &cfg_type_serverid, CFG_CLAUSEFLAG_NOTCONFIGURED },
1239 { "dnstap-version", &cfg_type_qstringornone,
1240 CFG_CLAUSEFLAG_NOTCONFIGURED },
1241 #endif /* ifdef HAVE_DNSTAP */
1242 { "dscp", &cfg_type_uint32, CFG_CLAUSEFLAG_OBSOLETE },
1243 { "dump-file", &cfg_type_qstring, 0 },
1244 { "fake-iquery", NULL, CFG_CLAUSEFLAG_ANCIENT },
1245 { "files", &cfg_type_size, CFG_CLAUSEFLAG_DEPRECATED },
1246 { "flush-zones-on-shutdown", &cfg_type_boolean, 0 },
1247 #ifdef HAVE_DNSTAP
1248 { "fstrm-set-buffer-hint", &cfg_type_uint32, 0 },
1249 { "fstrm-set-flush-timeout", &cfg_type_uint32, 0 },
1250 { "fstrm-set-input-queue-size", &cfg_type_uint32, 0 },
1251 { "fstrm-set-output-notify-threshold", &cfg_type_uint32, 0 },
1252 { "fstrm-set-output-queue-model", &cfg_type_fstrm_model, 0 },
1253 { "fstrm-set-output-queue-size", &cfg_type_uint32, 0 },
1254 { "fstrm-set-reopen-interval", &cfg_type_duration, 0 },
1255 #else /* ifdef HAVE_DNSTAP */
1256 { "fstrm-set-buffer-hint", &cfg_type_uint32,
1257 CFG_CLAUSEFLAG_NOTCONFIGURED },
1258 { "fstrm-set-flush-timeout", &cfg_type_uint32,
1259 CFG_CLAUSEFLAG_NOTCONFIGURED },
1260 { "fstrm-set-input-queue-size", &cfg_type_uint32,
1261 CFG_CLAUSEFLAG_NOTCONFIGURED },
1262 { "fstrm-set-output-notify-threshold", &cfg_type_uint32,
1263 CFG_CLAUSEFLAG_NOTCONFIGURED },
1264 { "fstrm-set-output-queue-model", &cfg_type_fstrm_model,
1265 CFG_CLAUSEFLAG_NOTCONFIGURED },
1266 { "fstrm-set-output-queue-size", &cfg_type_uint32,
1267 CFG_CLAUSEFLAG_NOTCONFIGURED },
1268 { "fstrm-set-reopen-interval", &cfg_type_duration,
1269 CFG_CLAUSEFLAG_NOTCONFIGURED },
1270 #endif /* HAVE_DNSTAP */
1271 #if defined(HAVE_GEOIP2)
1272 { "geoip-directory", &cfg_type_qstringornone, 0 },
1273 #else /* if defined(HAVE_GEOIP2) */
1274 { "geoip-directory", &cfg_type_qstringornone,
1275 CFG_CLAUSEFLAG_NOTCONFIGURED },
1276 #endif /* HAVE_GEOIP2 */
1277 { "geoip-use-ecs", NULL, CFG_CLAUSEFLAG_ANCIENT },
1278 { "has-old-clients", NULL, CFG_CLAUSEFLAG_ANCIENT },
1279 { "heartbeat-interval", &cfg_type_uint32, CFG_CLAUSEFLAG_DEPRECATED },
1280 { "host-statistics", NULL, CFG_CLAUSEFLAG_ANCIENT },
1281 { "host-statistics-max", NULL, CFG_CLAUSEFLAG_ANCIENT },
1282 { "hostname", &cfg_type_qstringornone, 0 },
1283 { "interface-interval", &cfg_type_duration, 0 },
1284 { "keep-response-order", &cfg_type_bracketed_aml, 0 },
1285 { "listen-on", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
1286 { "listen-on-v6", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
1287 { "lock-file", &cfg_type_qstringornone, 0 },
1288 { "managed-keys-directory", &cfg_type_qstring, 0 },
1289 { "match-mapped-addresses", &cfg_type_boolean, 0 },
1290 { "max-rsa-exponent-size", &cfg_type_uint32, 0 },
1291 { "memstatistics", &cfg_type_boolean, 0 },
1292 { "memstatistics-file", &cfg_type_qstring, 0 },
1293 { "multiple-cnames", NULL, CFG_CLAUSEFLAG_ANCIENT },
1294 { "named-xfer", NULL, CFG_CLAUSEFLAG_ANCIENT },
1295 { "notify-rate", &cfg_type_uint32, 0 },
1296 { "pid-file", &cfg_type_qstringornone, 0 },
1297 { "port", &cfg_type_uint32, 0 },
1298 { "tls-port", &cfg_type_uint32, 0 },
1299 #if HAVE_LIBNGHTTP2
1300 { "http-port", &cfg_type_uint32, 0 },
1301 { "http-listener-clients", &cfg_type_uint32, 0 },
1302 { "http-streams-per-connection", &cfg_type_uint32, 0 },
1303 { "https-port", &cfg_type_uint32, 0 },
1304 #else
1305 { "http-port", &cfg_type_uint32, CFG_CLAUSEFLAG_NOTCONFIGURED },
1306 { "http-listener-clients", &cfg_type_uint32,
1307 CFG_CLAUSEFLAG_NOTCONFIGURED },
1308 { "http-streams-per-connection", &cfg_type_uint32,
1309 CFG_CLAUSEFLAG_NOTCONFIGURED },
1310 { "https-port", &cfg_type_uint32, CFG_CLAUSEFLAG_NOTCONFIGURED },
1311 #endif
1312 { "querylog", &cfg_type_boolean, 0 },
1313 { "random-device", &cfg_type_qstringornone, CFG_CLAUSEFLAG_OBSOLETE },
1314 { "recursing-file", &cfg_type_qstring, 0 },
1315 { "recursive-clients", &cfg_type_uint32, 0 },
1316 { "reuseport", &cfg_type_boolean, 0 },
1317 { "reserved-sockets", &cfg_type_uint32, CFG_CLAUSEFLAG_DEPRECATED },
1318 { "secroots-file", &cfg_type_qstring, 0 },
1319 { "serial-queries", NULL, CFG_CLAUSEFLAG_ANCIENT },
1320 { "serial-query-rate", &cfg_type_uint32, 0 },
1321 { "server-id", &cfg_type_serverid, 0 },
1322 { "session-keyalg", &cfg_type_astring, 0 },
1323 { "session-keyfile", &cfg_type_qstringornone, 0 },
1324 { "session-keyname", &cfg_type_astring, 0 },
1325 { "sit-secret", NULL, CFG_CLAUSEFLAG_ANCIENT },
1326 { "stacksize", &cfg_type_size, CFG_CLAUSEFLAG_DEPRECATED },
1327 { "startup-notify-rate", &cfg_type_uint32, 0 },
1328 { "statistics-file", &cfg_type_qstring, 0 },
1329 { "statistics-interval", NULL, CFG_CLAUSEFLAG_ANCIENT },
1330 { "tcp-advertised-timeout", &cfg_type_uint32, 0 },
1331 { "tcp-clients", &cfg_type_uint32, 0 },
1332 { "tcp-idle-timeout", &cfg_type_uint32, 0 },
1333 { "tcp-initial-timeout", &cfg_type_uint32, 0 },
1334 { "tcp-keepalive-timeout", &cfg_type_uint32, 0 },
1335 { "tcp-listen-queue", &cfg_type_uint32, 0 },
1336 { "tcp-receive-buffer", &cfg_type_uint32, 0 },
1337 { "tcp-send-buffer", &cfg_type_uint32, 0 },
1338 { "tkey-dhkey", &cfg_type_tkey_dhkey, CFG_CLAUSEFLAG_DEPRECATED },
1339 { "tkey-domain", &cfg_type_qstring, 0 },
1340 { "tkey-gssapi-credential", &cfg_type_qstring, 0 },
1341 { "tkey-gssapi-keytab", &cfg_type_qstring, 0 },
1342 { "transfer-message-size", &cfg_type_uint32, 0 },
1343 { "transfers-in", &cfg_type_uint32, 0 },
1344 { "transfers-out", &cfg_type_uint32, 0 },
1345 { "transfers-per-ns", &cfg_type_uint32, 0 },
1346 { "treat-cr-as-space", NULL, CFG_CLAUSEFLAG_ANCIENT },
1347 { "udp-receive-buffer", &cfg_type_uint32, 0 },
1348 { "udp-send-buffer", &cfg_type_uint32, 0 },
1349 { "update-quota", &cfg_type_uint32, 0 },
1350 { "use-id-pool", NULL, CFG_CLAUSEFLAG_ANCIENT },
1351 { "use-ixfr", NULL, CFG_CLAUSEFLAG_ANCIENT },
1352 { "use-v4-udp-ports", &cfg_type_bracketed_portlist,
1353 CFG_CLAUSEFLAG_DEPRECATED },
1354 { "use-v6-udp-ports", &cfg_type_bracketed_portlist,
1355 CFG_CLAUSEFLAG_DEPRECATED },
1356 { "version", &cfg_type_qstringornone, 0 },
1357 { NULL, NULL, 0 }
1358 };
1359
1360 static cfg_type_t cfg_type_namelist = { "namelist",
1361 cfg_parse_bracketed_list,
1362 cfg_print_bracketed_list,
1363 cfg_doc_bracketed_list,
1364 &cfg_rep_list,
1365 &cfg_type_astring };
1366
1367 static keyword_type_t exclude_kw = { "exclude", &cfg_type_namelist };
1368
1369 static cfg_type_t cfg_type_optional_exclude = {
1370 "optional_exclude", parse_optional_keyvalue, print_keyvalue,
1371 doc_optional_keyvalue, &cfg_rep_list, &exclude_kw
1372 };
1373
1374 static keyword_type_t exceptionnames_kw = { "except-from", &cfg_type_namelist };
1375
1376 static cfg_type_t cfg_type_optional_exceptionnames = {
1377 "optional_allow", parse_optional_keyvalue, print_keyvalue,
1378 doc_optional_keyvalue, &cfg_rep_list, &exceptionnames_kw
1379 };
1380
1381 static cfg_tuplefielddef_t denyaddresses_fields[] = {
1382 { "acl", &cfg_type_bracketed_aml, 0 },
1383 { "except-from", &cfg_type_optional_exceptionnames, 0 },
1384 { NULL, NULL, 0 }
1385 };
1386
1387 static cfg_type_t cfg_type_denyaddresses = {
1388 "denyaddresses", cfg_parse_tuple, cfg_print_tuple,
1389 cfg_doc_tuple, &cfg_rep_tuple, denyaddresses_fields
1390 };
1391
1392 static cfg_tuplefielddef_t denyaliases_fields[] = {
1393 { "name", &cfg_type_namelist, 0 },
1394 { "except-from", &cfg_type_optional_exceptionnames, 0 },
1395 { NULL, NULL, 0 }
1396 };
1397
1398 static cfg_type_t cfg_type_denyaliases = {
1399 "denyaliases", cfg_parse_tuple, cfg_print_tuple,
1400 cfg_doc_tuple, &cfg_rep_tuple, denyaliases_fields
1401 };
1402
1403 static cfg_type_t cfg_type_algorithmlist = { "algorithmlist",
1404 cfg_parse_bracketed_list,
1405 cfg_print_bracketed_list,
1406 cfg_doc_bracketed_list,
1407 &cfg_rep_list,
1408 &cfg_type_astring };
1409
1410 static cfg_tuplefielddef_t disablealgorithm_fields[] = {
1411 { "name", &cfg_type_astring, 0 },
1412 { "algorithms", &cfg_type_algorithmlist, 0 },
1413 { NULL, NULL, 0 }
1414 };
1415
1416 static cfg_type_t cfg_type_disablealgorithm = {
1417 "disablealgorithm", cfg_parse_tuple, cfg_print_tuple,
1418 cfg_doc_tuple, &cfg_rep_tuple, disablealgorithm_fields
1419 };
1420
1421 static cfg_type_t cfg_type_dsdigestlist = { "dsdigestlist",
1422 cfg_parse_bracketed_list,
1423 cfg_print_bracketed_list,
1424 cfg_doc_bracketed_list,
1425 &cfg_rep_list,
1426 &cfg_type_astring };
1427
1428 static cfg_tuplefielddef_t disabledsdigest_fields[] = {
1429 { "name", &cfg_type_astring, 0 },
1430 { "digests", &cfg_type_dsdigestlist, 0 },
1431 { NULL, NULL, 0 }
1432 };
1433
1434 static cfg_type_t cfg_type_disabledsdigest = {
1435 "disabledsdigest", cfg_parse_tuple, cfg_print_tuple,
1436 cfg_doc_tuple, &cfg_rep_tuple, disabledsdigest_fields
1437 };
1438
1439 static cfg_tuplefielddef_t mustbesecure_fields[] = {
1440 { "name", &cfg_type_astring, 0 },
1441 { "value", &cfg_type_boolean, 0 },
1442 { NULL, NULL, 0 }
1443 };
1444
1445 static cfg_type_t cfg_type_mustbesecure = {
1446 "mustbesecure", cfg_parse_tuple, cfg_print_tuple,
1447 cfg_doc_tuple, &cfg_rep_tuple, mustbesecure_fields
1448 };
1449
1450 static const char *masterformat_enums[] = { "raw", "text", NULL };
1451 static cfg_type_t cfg_type_masterformat = {
1452 "masterformat", cfg_parse_enum, cfg_print_ustring,
1453 cfg_doc_enum, &cfg_rep_string, &masterformat_enums
1454 };
1455
1456 static const char *masterstyle_enums[] = { "full", "relative", NULL };
1457 static cfg_type_t cfg_type_masterstyle = {
1458 "masterstyle", cfg_parse_enum, cfg_print_ustring,
1459 cfg_doc_enum, &cfg_rep_string, &masterstyle_enums
1460 };
1461
1462 static keyword_type_t blocksize_kw = { "block-size", &cfg_type_uint32 };
1463
1464 static cfg_type_t cfg_type_blocksize = { "blocksize", parse_keyvalue,
1465 print_keyvalue, doc_keyvalue,
1466 &cfg_rep_uint32, &blocksize_kw };
1467
1468 static cfg_tuplefielddef_t resppadding_fields[] = {
1469 { "acl", &cfg_type_bracketed_aml, 0 },
1470 { "block-size", &cfg_type_blocksize, 0 },
1471 { NULL, NULL, 0 }
1472 };
1473
1474 static cfg_type_t cfg_type_resppadding = {
1475 "resppadding", cfg_parse_tuple, cfg_print_tuple,
1476 cfg_doc_tuple, &cfg_rep_tuple, resppadding_fields
1477 };
1478
1479 /*%
1480 * dnstap {
1481 * <message type> [query | response] ;
1482 * ...
1483 * }
1484 *
1485 * ... where message type is one of: client, resolver, auth, forwarder,
1486 * update, all
1487 */
1488 static const char *dnstap_types[] = { "all", "auth", "client",
1489 "forwarder", "resolver", "update",
1490 NULL };
1491
1492 static const char *dnstap_modes[] = { "query", "response", NULL };
1493
1494 static cfg_type_t cfg_type_dnstap_type = { "dnstap_type", cfg_parse_enum,
1495 cfg_print_ustring, cfg_doc_enum,
1496 &cfg_rep_string, dnstap_types };
1497
1498 static cfg_type_t cfg_type_dnstap_mode = {
1499 "dnstap_mode", parse_optional_enum, cfg_print_ustring,
1500 doc_optional_enum, &cfg_rep_string, dnstap_modes
1501 };
1502
1503 static cfg_tuplefielddef_t dnstap_fields[] = {
1504 { "type", &cfg_type_dnstap_type, 0 },
1505 { "mode", &cfg_type_dnstap_mode, 0 },
1506 { NULL, NULL, 0 }
1507 };
1508
1509 static cfg_type_t cfg_type_dnstap_entry = { "dnstap_value", cfg_parse_tuple,
1510 cfg_print_tuple, cfg_doc_tuple,
1511 &cfg_rep_tuple, dnstap_fields };
1512
1513 static cfg_type_t cfg_type_dnstap = { "dnstap",
1514 cfg_parse_bracketed_list,
1515 cfg_print_bracketed_list,
1516 cfg_doc_bracketed_list,
1517 &cfg_rep_list,
1518 &cfg_type_dnstap_entry };
1519
1520 /*%
1521 * dnstap-output
1522 */
1523 static isc_result_t
1524 parse_dtout(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1525 isc_result_t result;
1526 cfg_obj_t *obj = NULL;
1527 const cfg_tuplefielddef_t *fields = type->of;
1528
1529 CHECK(cfg_create_tuple(pctx, type, &obj));
1530
1531 /* Parse the mandatory "mode" and "path" fields */
1532 CHECK(cfg_parse_obj(pctx, fields[0].type, &obj->value.tuple[0]));
1533 CHECK(cfg_parse_obj(pctx, fields[1].type, &obj->value.tuple[1]));
1534
1535 /* Parse "versions" and "size" fields in any order. */
1536 for (;;) {
1537 CHECK(cfg_peektoken(pctx, 0));
1538 if (pctx->token.type == isc_tokentype_string) {
1539 CHECK(cfg_gettoken(pctx, 0));
1540 if (strcasecmp(TOKEN_STRING(pctx), "size") == 0 &&
1541 obj->value.tuple[2] == NULL)
1542 {
1543 CHECK(cfg_parse_obj(pctx, fields[2].type,
1544 &obj->value.tuple[2]));
1545 } else if (strcasecmp(TOKEN_STRING(pctx), "versions") ==
1546 0 &&
1547 obj->value.tuple[3] == NULL)
1548 {
1549 CHECK(cfg_parse_obj(pctx, fields[3].type,
1550 &obj->value.tuple[3]));
1551 } else if (strcasecmp(TOKEN_STRING(pctx), "suffix") ==
1552 0 &&
1553 obj->value.tuple[4] == NULL)
1554 {
1555 CHECK(cfg_parse_obj(pctx, fields[4].type,
1556 &obj->value.tuple[4]));
1557 } else {
1558 cfg_parser_error(pctx, CFG_LOG_NEAR,
1559 "unexpected token");
1560 result = ISC_R_UNEXPECTEDTOKEN;
1561 goto cleanup;
1562 }
1563 } else {
1564 break;
1565 }
1566 }
1567
1568 /* Create void objects for missing optional values. */
1569 if (obj->value.tuple[2] == NULL) {
1570 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[2]));
1571 }
1572 if (obj->value.tuple[3] == NULL) {
1573 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[3]));
1574 }
1575 if (obj->value.tuple[4] == NULL) {
1576 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[4]));
1577 }
1578
1579 *ret = obj;
1580 return (ISC_R_SUCCESS);
1581
1582 cleanup:
1583 CLEANUP_OBJ(obj);
1584 return (result);
1585 }
1586
1587 static void
1588 print_dtout(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1589 cfg_print_obj(pctx, obj->value.tuple[0]); /* mode */
1590 cfg_print_obj(pctx, obj->value.tuple[1]); /* file */
1591 if (obj->value.tuple[2]->type->print != cfg_print_void) {
1592 cfg_print_cstr(pctx, " size ");
1593 cfg_print_obj(pctx, obj->value.tuple[2]);
1594 }
1595 if (obj->value.tuple[3]->type->print != cfg_print_void) {
1596 cfg_print_cstr(pctx, " versions ");
1597 cfg_print_obj(pctx, obj->value.tuple[3]);
1598 }
1599 if (obj->value.tuple[4]->type->print != cfg_print_void) {
1600 cfg_print_cstr(pctx, " suffix ");
1601 cfg_print_obj(pctx, obj->value.tuple[4]);
1602 }
1603 }
1604
1605 static void
1606 doc_dtout(cfg_printer_t *pctx, const cfg_type_t *type) {
1607 UNUSED(type);
1608 cfg_print_cstr(pctx, "( file | unix ) <quoted_string>");
1609 cfg_print_cstr(pctx, " ");
1610 cfg_print_cstr(pctx, "[ size ( unlimited | <size> ) ]");
1611 cfg_print_cstr(pctx, " ");
1612 cfg_print_cstr(pctx, "[ versions ( unlimited | <integer> ) ]");
1613 cfg_print_cstr(pctx, " ");
1614 cfg_print_cstr(pctx, "[ suffix ( increment | timestamp ) ]");
1615 }
1616
1617 static const char *dtoutmode_enums[] = { "file", "unix", NULL };
1618 static cfg_type_t cfg_type_dtmode = { "dtmode", cfg_parse_enum,
1619 cfg_print_ustring, cfg_doc_enum,
1620 &cfg_rep_string, &dtoutmode_enums };
1621
1622 static cfg_tuplefielddef_t dtout_fields[] = {
1623 { "mode", &cfg_type_dtmode, 0 },
1624 { "path", &cfg_type_qstring, 0 },
1625 { "size", &cfg_type_sizenodefault, 0 },
1626 { "versions", &cfg_type_logversions, 0 },
1627 { "suffix", &cfg_type_logsuffix, 0 },
1628 { NULL, NULL, 0 }
1629 };
1630
1631 static cfg_type_t cfg_type_dnstapoutput = { "dnstapoutput", parse_dtout,
1632 print_dtout, doc_dtout,
1633 &cfg_rep_tuple, dtout_fields };
1634
1635 /*%
1636 * response-policy {
1637 * zone <string> [ policy (given|disabled|passthru|drop|tcp-only|
1638 * nxdomain|nodata|cname <domain> ) ]
1639 * [ recursive-only yes|no ] [ log yes|no ]
1640 * [ max-policy-ttl number ]
1641 * [ nsip-enable yes|no ] [ nsdname-enable yes|no ];
1642 * } [ recursive-only yes|no ] [ max-policy-ttl number ]
1643 * [ min-update-interval number ]
1644 * [ break-dnssec yes|no ] [ min-ns-dots number ]
1645 * [ qname-wait-recurse yes|no ]
1646 * [ nsip-enable yes|no ] [ nsdname-enable yes|no ]
1647 * [ dnsrps-enable yes|no ]
1648 * [ dnsrps-options { DNSRPS configuration string } ];
1649 */
1650
1651 static void
1652 doc_rpz_policy(cfg_printer_t *pctx, const cfg_type_t *type) {
1653 const char *const *p;
1654 /*
1655 * This is cfg_doc_enum() without the trailing " )".
1656 */
1657 cfg_print_cstr(pctx, "( ");
1658 for (p = type->of; *p != NULL; p++) {
1659 cfg_print_cstr(pctx, *p);
1660 if (p[1] != NULL) {
1661 cfg_print_cstr(pctx, " | ");
1662 }
1663 }
1664 }
1665
1666 static void
1667 doc_rpz_cname(cfg_printer_t *pctx, const cfg_type_t *type) {
1668 cfg_doc_terminal(pctx, type);
1669 cfg_print_cstr(pctx, " )");
1670 }
1671
1672 /*
1673 * Parse
1674 * given|disabled|passthru|drop|tcp-only|nxdomain|nodata|cname <domain>
1675 */
1676 static isc_result_t
1677 cfg_parse_rpz_policy(cfg_parser_t *pctx, const cfg_type_t *type,
1678 cfg_obj_t **ret) {
1679 isc_result_t result;
1680 cfg_obj_t *obj = NULL;
1681 const cfg_tuplefielddef_t *fields;
1682
1683 CHECK(cfg_create_tuple(pctx, type, &obj));
1684
1685 fields = type->of;
1686 CHECK(cfg_parse_obj(pctx, fields[0].type, &obj->value.tuple[0]));
1687 /*
1688 * parse cname domain only after "policy cname"
1689 */
1690 if (strcasecmp("cname", cfg_obj_asstring(obj->value.tuple[0])) != 0) {
1691 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[1]));
1692 } else {
1693 CHECK(cfg_parse_obj(pctx, fields[1].type,
1694 &obj->value.tuple[1]));
1695 }
1696
1697 *ret = obj;
1698 return (ISC_R_SUCCESS);
1699
1700 cleanup:
1701 CLEANUP_OBJ(obj);
1702 return (result);
1703 }
1704
1705 /*
1706 * Parse a tuple consisting of any kind of required field followed
1707 * by 2 or more optional keyvalues that can be in any order.
1708 */
1709 static isc_result_t
1710 cfg_parse_kv_tuple(cfg_parser_t *pctx, const cfg_type_t *type,
1711 cfg_obj_t **ret) {
1712 const cfg_tuplefielddef_t *fields, *f;
1713 cfg_obj_t *obj = NULL;
1714 int fn;
1715 isc_result_t result;
1716
1717 CHECK(cfg_create_tuple(pctx, type, &obj));
1718
1719 /*
1720 * The zone first field is required and always first.
1721 */
1722 fields = type->of;
1723 CHECK(cfg_parse_obj(pctx, fields[0].type, &obj->value.tuple[0]));
1724
1725 for (;;) {
1726 CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
1727 if (pctx->token.type != isc_tokentype_string) {
1728 break;
1729 }
1730
1731 for (fn = 1, f = &fields[1];; ++fn, ++f) {
1732 if (f->name == NULL) {
1733 cfg_parser_error(pctx, 0, "unexpected '%s'",
1734 TOKEN_STRING(pctx));
1735 result = ISC_R_UNEXPECTEDTOKEN;
1736 goto cleanup;
1737 }
1738 if (obj->value.tuple[fn] == NULL &&
1739 strcasecmp(f->name, TOKEN_STRING(pctx)) == 0)
1740 {
1741 break;
1742 }
1743 }
1744
1745 CHECK(cfg_gettoken(pctx, 0));
1746 CHECK(cfg_parse_obj(pctx, f->type, &obj->value.tuple[fn]));
1747 }
1748
1749 for (fn = 1, f = &fields[1]; f->name != NULL; ++fn, ++f) {
1750 if (obj->value.tuple[fn] == NULL) {
1751 CHECK(cfg_parse_void(pctx, NULL,
1752 &obj->value.tuple[fn]));
1753 }
1754 }
1755
1756 *ret = obj;
1757 return (ISC_R_SUCCESS);
1758
1759 cleanup:
1760 CLEANUP_OBJ(obj);
1761 return (result);
1762 }
1763
1764 static void
1765 cfg_print_kv_tuple(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1766 unsigned int i;
1767 const cfg_tuplefielddef_t *fields, *f;
1768 const cfg_obj_t *fieldobj;
1769
1770 fields = obj->type->of;
1771 for (f = fields, i = 0; f->name != NULL; f++, i++) {
1772 fieldobj = obj->value.tuple[i];
1773 if (fieldobj->type->print == cfg_print_void) {
1774 continue;
1775 }
1776 if (i != 0) {
1777 cfg_print_cstr(pctx, " ");
1778 cfg_print_cstr(pctx, f->name);
1779 cfg_print_cstr(pctx, " ");
1780 }
1781 cfg_print_obj(pctx, fieldobj);
1782 }
1783 }
1784
1785 static void
1786 cfg_doc_kv_tuple(cfg_printer_t *pctx, const cfg_type_t *type) {
1787 const cfg_tuplefielddef_t *fields, *f;
1788
1789 fields = type->of;
1790 for (f = fields; f->name != NULL; f++) {
1791 if ((f->flags & CFG_CLAUSEFLAG_NODOC) != 0) {
1792 continue;
1793 }
1794 if (f != fields) {
1795 cfg_print_cstr(pctx, " [ ");
1796 cfg_print_cstr(pctx, f->name);
1797 if (f->type->doc != cfg_doc_void) {
1798 cfg_print_cstr(pctx, " ");
1799 }
1800 }
1801 cfg_doc_obj(pctx, f->type);
1802 if (f != fields) {
1803 cfg_print_cstr(pctx, " ]");
1804 }
1805 }
1806 }
1807
1808 static keyword_type_t zone_kw = { "zone", &cfg_type_astring };
1809 static cfg_type_t cfg_type_rpz_zone = { "zone", parse_keyvalue,
1810 print_keyvalue, doc_keyvalue,
1811 &cfg_rep_string, &zone_kw };
1812 /*
1813 * "no-op" is an obsolete equivalent of "passthru".
1814 */
1815 static const char *rpz_policies[] = { "cname", "disabled", "drop",
1816 "given", "no-op", "nodata",
1817 "nxdomain", "passthru", "tcp-only",
1818 NULL };
1819 static cfg_type_t cfg_type_rpz_policy_name = {
1820 "policy name", cfg_parse_enum, cfg_print_ustring,
1821 doc_rpz_policy, &cfg_rep_string, &rpz_policies
1822 };
1823 static cfg_type_t cfg_type_rpz_cname = {
1824 "quoted_string", cfg_parse_astring, NULL,
1825 doc_rpz_cname, &cfg_rep_string, NULL
1826 };
1827 static cfg_tuplefielddef_t rpz_policy_fields[] = {
1828 { "policy name", &cfg_type_rpz_policy_name, 0 },
1829 { "cname", &cfg_type_rpz_cname, 0 },
1830 { NULL, NULL, 0 }
1831 };
1832 static cfg_type_t cfg_type_rpz_policy = { "policy tuple", cfg_parse_rpz_policy,
1833 cfg_print_tuple, cfg_doc_tuple,
1834 &cfg_rep_tuple, rpz_policy_fields };
1835 static cfg_tuplefielddef_t rpz_zone_fields[] = {
1836 { "zone name", &cfg_type_rpz_zone, 0 },
1837 { "add-soa", &cfg_type_boolean, 0 },
1838 { "log", &cfg_type_boolean, 0 },
1839 { "max-policy-ttl", &cfg_type_duration, 0 },
1840 { "min-update-interval", &cfg_type_duration, 0 },
1841 { "policy", &cfg_type_rpz_policy, 0 },
1842 { "recursive-only", &cfg_type_boolean, 0 },
1843 { "nsip-enable", &cfg_type_boolean, 0 },
1844 { "nsdname-enable", &cfg_type_boolean, 0 },
1845 { NULL, NULL, 0 }
1846 };
1847 static cfg_type_t cfg_type_rpz_tuple = { "rpz tuple", cfg_parse_kv_tuple,
1848 cfg_print_kv_tuple, cfg_doc_kv_tuple,
1849 &cfg_rep_tuple, rpz_zone_fields };
1850 static cfg_type_t cfg_type_rpz_list = { "zone list",
1851 cfg_parse_bracketed_list,
1852 cfg_print_bracketed_list,
1853 cfg_doc_bracketed_list,
1854 &cfg_rep_list,
1855 &cfg_type_rpz_tuple };
1856 static cfg_tuplefielddef_t rpz_fields[] = {
1857 { "zone list", &cfg_type_rpz_list, 0 },
1858 { "add-soa", &cfg_type_boolean, 0 },
1859 { "break-dnssec", &cfg_type_boolean, 0 },
1860 { "max-policy-ttl", &cfg_type_duration, 0 },
1861 { "min-update-interval", &cfg_type_duration, 0 },
1862 { "min-ns-dots", &cfg_type_uint32, 0 },
1863 { "nsip-wait-recurse", &cfg_type_boolean, 0 },
1864 { "nsdname-wait-recurse", &cfg_type_boolean, 0 },
1865 { "qname-wait-recurse", &cfg_type_boolean, 0 },
1866 { "recursive-only", &cfg_type_boolean, 0 },
1867 { "nsip-enable", &cfg_type_boolean, 0 },
1868 { "nsdname-enable", &cfg_type_boolean, 0 },
1869 #ifdef USE_DNSRPS
1870 { "dnsrps-enable", &cfg_type_boolean, 0 },
1871 { "dnsrps-options", &cfg_type_bracketed_text, 0 },
1872 #else /* ifdef USE_DNSRPS */
1873 { "dnsrps-enable", &cfg_type_boolean, CFG_CLAUSEFLAG_NOTCONFIGURED },
1874 { "dnsrps-options", &cfg_type_bracketed_text,
1875 CFG_CLAUSEFLAG_NOTCONFIGURED },
1876 #endif /* ifdef USE_DNSRPS */
1877 { NULL, NULL, 0 }
1878 };
1879 static cfg_type_t cfg_type_rpz = { "rpz",
1880 cfg_parse_kv_tuple,
1881 cfg_print_kv_tuple,
1882 cfg_doc_kv_tuple,
1883 &cfg_rep_tuple,
1884 rpz_fields };
1885
1886 /*
1887 * Catalog zones
1888 */
1889 static cfg_type_t cfg_type_catz_zone = { "zone", parse_keyvalue,
1890 print_keyvalue, doc_keyvalue,
1891 &cfg_rep_string, &zone_kw };
1892
1893 static cfg_tuplefielddef_t catz_zone_fields[] = {
1894 { "zone name", &cfg_type_catz_zone, 0 },
1895 { "default-masters", &cfg_type_namesockaddrkeylist,
1896 CFG_CLAUSEFLAG_NODOC },
1897 { "default-primaries", &cfg_type_namesockaddrkeylist, 0 },
1898 { "zone-directory", &cfg_type_qstring, 0 },
1899 { "in-memory", &cfg_type_boolean, 0 },
1900 { "min-update-interval", &cfg_type_duration, 0 },
1901 { NULL, NULL, 0 }
1902 };
1903 static cfg_type_t cfg_type_catz_tuple = {
1904 "catz tuple", cfg_parse_kv_tuple, cfg_print_kv_tuple,
1905 cfg_doc_kv_tuple, &cfg_rep_tuple, catz_zone_fields
1906 };
1907 static cfg_type_t cfg_type_catz_list = { "zone list",
1908 cfg_parse_bracketed_list,
1909 cfg_print_bracketed_list,
1910 cfg_doc_bracketed_list,
1911 &cfg_rep_list,
1912 &cfg_type_catz_tuple };
1913 static cfg_tuplefielddef_t catz_fields[] = {
1914 { "zone list", &cfg_type_catz_list, 0 }, { NULL, NULL, 0 }
1915 };
1916 static cfg_type_t cfg_type_catz = {
1917 "catz", cfg_parse_kv_tuple, cfg_print_kv_tuple,
1918 cfg_doc_kv_tuple, &cfg_rep_tuple, catz_fields
1919 };
1920
1921 /*
1922 * rate-limit
1923 */
1924 static cfg_clausedef_t rrl_clauses[] = {
1925 { "all-per-second", &cfg_type_uint32, 0 },
1926 { "errors-per-second", &cfg_type_uint32, 0 },
1927 { "exempt-clients", &cfg_type_bracketed_aml, 0 },
1928 { "ipv4-prefix-length", &cfg_type_uint32, 0 },
1929 { "ipv6-prefix-length", &cfg_type_uint32, 0 },
1930 { "log-only", &cfg_type_boolean, 0 },
1931 { "max-table-size", &cfg_type_uint32, 0 },
1932 { "min-table-size", &cfg_type_uint32, 0 },
1933 { "nodata-per-second", &cfg_type_uint32, 0 },
1934 { "nxdomains-per-second", &cfg_type_uint32, 0 },
1935 { "qps-scale", &cfg_type_uint32, 0 },
1936 { "referrals-per-second", &cfg_type_uint32, 0 },
1937 { "responses-per-second", &cfg_type_uint32, 0 },
1938 { "slip", &cfg_type_uint32, 0 },
1939 { "window", &cfg_type_uint32, 0 },
1940 { NULL, NULL, 0 }
1941 };
1942
1943 static cfg_clausedef_t *rrl_clausesets[] = { rrl_clauses, NULL };
1944
1945 static cfg_type_t cfg_type_rrl = { "rate-limit", cfg_parse_map, cfg_print_map,
1946 cfg_doc_map, &cfg_rep_map, rrl_clausesets };
1947
1948 static isc_result_t
1949 parse_optional_uint32(cfg_parser_t *pctx, const cfg_type_t *type,
1950 cfg_obj_t **ret) {
1951 isc_result_t result;
1952 UNUSED(type);
1953
1954 CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
1955 if (pctx->token.type == isc_tokentype_number) {
1956 CHECK(cfg_parse_obj(pctx, &cfg_type_uint32, ret));
1957 } else {
1958 CHECK(cfg_parse_obj(pctx, &cfg_type_void, ret));
1959 }
1960 cleanup:
1961 return (result);
1962 }
1963
1964 static void
1965 doc_optional_uint32(cfg_printer_t *pctx, const cfg_type_t *type) {
1966 UNUSED(type);
1967 cfg_print_cstr(pctx, "[ <integer> ]");
1968 }
1969
1970 static cfg_type_t cfg_type_optional_uint32 = { "optional_uint32",
1971 parse_optional_uint32,
1972 NULL,
1973 doc_optional_uint32,
1974 NULL,
1975 NULL };
1976
1977 static cfg_tuplefielddef_t prefetch_fields[] = {
1978 { "trigger", &cfg_type_uint32, 0 },
1979 { "eligible", &cfg_type_optional_uint32, 0 },
1980 { NULL, NULL, 0 }
1981 };
1982
1983 static cfg_type_t cfg_type_prefetch = { "prefetch", cfg_parse_tuple,
1984 cfg_print_tuple, cfg_doc_tuple,
1985 &cfg_rep_tuple, prefetch_fields };
1986 /*
1987 * DNS64.
1988 */
1989 static cfg_clausedef_t dns64_clauses[] = {
1990 { "break-dnssec", &cfg_type_boolean, 0 },
1991 { "clients", &cfg_type_bracketed_aml, 0 },
1992 { "exclude", &cfg_type_bracketed_aml, 0 },
1993 { "mapped", &cfg_type_bracketed_aml, 0 },
1994 { "recursive-only", &cfg_type_boolean, 0 },
1995 { "suffix", &cfg_type_netaddr6, 0 },
1996 { NULL, NULL, 0 },
1997 };
1998
1999 static cfg_clausedef_t *dns64_clausesets[] = { dns64_clauses, NULL };
2000
2001 static cfg_type_t cfg_type_dns64 = { "dns64", cfg_parse_netprefix_map,
2002 cfg_print_map, cfg_doc_map,
2003 &cfg_rep_map, dns64_clausesets };
2004
2005 static const char *staleanswerclienttimeout_enums[] = { "disabled", "off",
2006 NULL };
2007 static isc_result_t
2008 parse_staleanswerclienttimeout(cfg_parser_t *pctx, const cfg_type_t *type,
2009 cfg_obj_t **ret) {
2010 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_uint32, ret));
2011 }
2012
2013 static void
2014 doc_staleanswerclienttimeout(cfg_printer_t *pctx, const cfg_type_t *type) {
2015 cfg_doc_enum_or_other(pctx, type, &cfg_type_uint32);
2016 }
2017
2018 static cfg_type_t cfg_type_staleanswerclienttimeout = {
2019 "staleanswerclienttimeout",
2020 parse_staleanswerclienttimeout,
2021 cfg_print_ustring,
2022 doc_staleanswerclienttimeout,
2023 &cfg_rep_string,
2024 staleanswerclienttimeout_enums
2025 };
2026
2027 /*%
2028 * Clauses that can be found within the 'view' statement,
2029 * with defaults in the 'options' statement.
2030 */
2031
2032 static cfg_clausedef_t view_clauses[] = {
2033 { "acache-cleaning-interval", NULL, CFG_CLAUSEFLAG_ANCIENT },
2034 { "acache-enable", NULL, CFG_CLAUSEFLAG_ANCIENT },
2035 { "additional-from-auth", NULL, CFG_CLAUSEFLAG_ANCIENT },
2036 { "additional-from-cache", NULL, CFG_CLAUSEFLAG_ANCIENT },
2037 { "allow-new-zones", &cfg_type_boolean, 0 },
2038 { "allow-query-cache", &cfg_type_bracketed_aml, 0 },
2039 { "allow-query-cache-on", &cfg_type_bracketed_aml, 0 },
2040 { "allow-recursion", &cfg_type_bracketed_aml, 0 },
2041 { "allow-recursion-on", &cfg_type_bracketed_aml, 0 },
2042 { "allow-v6-synthesis", NULL, CFG_CLAUSEFLAG_ANCIENT },
2043 { "attach-cache", &cfg_type_astring, 0 },
2044 { "auth-nxdomain", &cfg_type_boolean, 0 },
2045 { "cache-file", &cfg_type_qstring, CFG_CLAUSEFLAG_ANCIENT },
2046 { "catalog-zones", &cfg_type_catz, 0 },
2047 { "check-names", &cfg_type_checknames, CFG_CLAUSEFLAG_MULTI },
2048 { "cleaning-interval", NULL, CFG_CLAUSEFLAG_ANCIENT },
2049 { "clients-per-query", &cfg_type_uint32, 0 },
2050 { "deny-answer-addresses", &cfg_type_denyaddresses, 0 },
2051 { "deny-answer-aliases", &cfg_type_denyaliases, 0 },
2052 { "disable-algorithms", &cfg_type_disablealgorithm,
2053 CFG_CLAUSEFLAG_MULTI },
2054 { "disable-ds-digests", &cfg_type_disabledsdigest,
2055 CFG_CLAUSEFLAG_MULTI },
2056 { "disable-empty-zone", &cfg_type_astring, CFG_CLAUSEFLAG_MULTI },
2057 { "dns64", &cfg_type_dns64, CFG_CLAUSEFLAG_MULTI },
2058 { "dns64-contact", &cfg_type_astring, 0 },
2059 { "dns64-server", &cfg_type_astring, 0 },
2060 #ifdef USE_DNSRPS
2061 { "dnsrps-enable", &cfg_type_boolean, 0 },
2062 { "dnsrps-options", &cfg_type_bracketed_text, 0 },
2063 #else /* ifdef USE_DNSRPS */
2064 { "dnsrps-enable", &cfg_type_boolean, CFG_CLAUSEFLAG_NOTCONFIGURED },
2065 { "dnsrps-options", &cfg_type_bracketed_text,
2066 CFG_CLAUSEFLAG_NOTCONFIGURED },
2067 #endif /* ifdef USE_DNSRPS */
2068 { "dnssec-accept-expired", &cfg_type_boolean, 0 },
2069 { "dnssec-enable", NULL, CFG_CLAUSEFLAG_ANCIENT },
2070 { "dnssec-lookaside", NULL,
2071 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_ANCIENT },
2072 { "dnssec-must-be-secure", &cfg_type_mustbesecure,
2073 CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_DEPRECATED },
2074 { "dnssec-validation", &cfg_type_boolorauto, 0 },
2075 #ifdef HAVE_DNSTAP
2076 { "dnstap", &cfg_type_dnstap, 0 },
2077 #else /* ifdef HAVE_DNSTAP */
2078 { "dnstap", &cfg_type_dnstap, CFG_CLAUSEFLAG_NOTCONFIGURED },
2079 #endif /* HAVE_DNSTAP */
2080 { "dual-stack-servers", &cfg_type_nameportiplist, 0 },
2081 { "edns-udp-size", &cfg_type_uint32, 0 },
2082 { "empty-contact", &cfg_type_astring, 0 },
2083 { "empty-server", &cfg_type_astring, 0 },
2084 { "empty-zones-enable", &cfg_type_boolean, 0 },
2085 { "fetch-glue", NULL, CFG_CLAUSEFLAG_ANCIENT },
2086 { "fetch-quota-params", &cfg_type_fetchquota, 0 },
2087 { "fetches-per-server", &cfg_type_fetchesper, 0 },
2088 { "fetches-per-zone", &cfg_type_fetchesper, 0 },
2089 { "filter-aaaa", &cfg_type_bracketed_aml, CFG_CLAUSEFLAG_ANCIENT },
2090 { "filter-aaaa-on-v4", &cfg_type_boolean, CFG_CLAUSEFLAG_ANCIENT },
2091 { "filter-aaaa-on-v6", &cfg_type_boolean, CFG_CLAUSEFLAG_ANCIENT },
2092 { "glue-cache", &cfg_type_boolean, CFG_CLAUSEFLAG_DEPRECATED },
2093 { "ipv4only-enable", &cfg_type_boolean, 0 },
2094 { "ipv4only-contact", &cfg_type_astring, 0 },
2095 { "ipv4only-server", &cfg_type_astring, 0 },
2096 { "ixfr-from-differences", &cfg_type_ixfrdifftype, 0 },
2097 { "lame-ttl", &cfg_type_duration, 0 },
2098 #ifdef HAVE_LMDB
2099 { "lmdb-mapsize", &cfg_type_sizeval, 0 },
2100 #else /* ifdef HAVE_LMDB */
2101 { "lmdb-mapsize", &cfg_type_sizeval, CFG_CLAUSEFLAG_NOTCONFIGURED },
2102 #endif /* ifdef HAVE_LMDB */
2103 { "max-acache-size", NULL, CFG_CLAUSEFLAG_ANCIENT },
2104 { "max-cache-size", &cfg_type_sizeorpercent, 0 },
2105 { "max-cache-ttl", &cfg_type_duration, 0 },
2106 { "max-clients-per-query", &cfg_type_uint32, 0 },
2107 { "max-ncache-ttl", &cfg_type_duration, 0 },
2108 { "max-recursion-depth", &cfg_type_uint32, 0 },
2109 { "max-recursion-queries", &cfg_type_uint32, 0 },
2110 { "max-query-restarts", &cfg_type_uint32, 0 },
2111 { "max-stale-ttl", &cfg_type_duration, 0 },
2112 { "max-udp-size", &cfg_type_uint32, 0 },
2113 { "message-compression", &cfg_type_boolean, 0 },
2114 { "min-cache-ttl", &cfg_type_duration, 0 },
2115 { "min-ncache-ttl", &cfg_type_duration, 0 },
2116 { "min-roots", NULL, CFG_CLAUSEFLAG_ANCIENT },
2117 { "minimal-any", &cfg_type_boolean, 0 },
2118 { "minimal-responses", &cfg_type_minimal, 0 },
2119 { "new-zones-directory", &cfg_type_qstring, 0 },
2120 { "no-case-compress", &cfg_type_bracketed_aml, 0 },
2121 { "nocookie-udp-size", &cfg_type_uint32, 0 },
2122 { "nosit-udp-size", NULL, CFG_CLAUSEFLAG_ANCIENT },
2123 { "nta-lifetime", &cfg_type_duration, 0 },
2124 { "nta-recheck", &cfg_type_duration, 0 },
2125 { "nxdomain-redirect", &cfg_type_astring, 0 },
2126 { "preferred-glue", &cfg_type_astring, 0 },
2127 { "prefetch", &cfg_type_prefetch, 0 },
2128 { "provide-ixfr", &cfg_type_boolean, 0 },
2129 { "qname-minimization", &cfg_type_qminmethod, 0 },
2130 /*
2131 * Note that the query-source option syntax is different
2132 * from the other -source options.
2133 */
2134 { "query-source", &cfg_type_querysource4, 0 },
2135 { "query-source-v6", &cfg_type_querysource6, 0 },
2136 { "queryport-pool-ports", NULL, CFG_CLAUSEFLAG_ANCIENT },
2137 { "queryport-pool-updateinterval", NULL, CFG_CLAUSEFLAG_ANCIENT },
2138 { "rate-limit", &cfg_type_rrl, 0 },
2139 { "recursion", &cfg_type_boolean, 0 },
2140 { "request-nsid", &cfg_type_boolean, 0 },
2141 { "request-sit", NULL, CFG_CLAUSEFLAG_ANCIENT },
2142 { "require-server-cookie", &cfg_type_boolean, 0 },
2143 { "resolver-nonbackoff-tries", &cfg_type_uint32,
2144 CFG_CLAUSEFLAG_DEPRECATED },
2145 { "resolver-query-timeout", &cfg_type_uint32, 0 },
2146 { "resolver-retry-interval", &cfg_type_uint32,
2147 CFG_CLAUSEFLAG_DEPRECATED },
2148 { "response-padding", &cfg_type_resppadding, 0 },
2149 { "response-policy", &cfg_type_rpz, 0 },
2150 { "rfc2308-type1", NULL, CFG_CLAUSEFLAG_ANCIENT },
2151 { "root-delegation-only", &cfg_type_optional_exclude,
2152 CFG_CLAUSEFLAG_DEPRECATED },
2153 { "root-key-sentinel", &cfg_type_boolean, 0 },
2154 { "rrset-order", &cfg_type_rrsetorder, 0 },
2155 { "send-cookie", &cfg_type_boolean, 0 },
2156 { "servfail-ttl", &cfg_type_duration, 0 },
2157 { "sortlist", &cfg_type_bracketed_aml, 0 },
2158 { "stale-answer-enable", &cfg_type_boolean, 0 },
2159 { "stale-answer-client-timeout", &cfg_type_staleanswerclienttimeout,
2160 0 },
2161 { "stale-answer-ttl", &cfg_type_duration, 0 },
2162 { "stale-cache-enable", &cfg_type_boolean, 0 },
2163 { "stale-refresh-time", &cfg_type_duration, 0 },
2164 { "suppress-initial-notify", &cfg_type_boolean,
2165 CFG_CLAUSEFLAG_OBSOLETE },
2166 { "synth-from-dnssec", &cfg_type_boolean, 0 },
2167 { "topology", NULL, CFG_CLAUSEFLAG_ANCIENT },
2168 { "transfer-format", &cfg_type_transferformat, 0 },
2169 { "trust-anchor-telemetry", &cfg_type_boolean, 0 },
2170 { "use-queryport-pool", NULL, CFG_CLAUSEFLAG_ANCIENT },
2171 { "validate-except", &cfg_type_namelist, 0 },
2172 { "v6-bias", &cfg_type_uint32, 0 },
2173 { "zero-no-soa-ttl-cache", &cfg_type_boolean, 0 },
2174 { NULL, NULL, 0 }
2175 };
2176
2177 /*%
2178 * Clauses that can be found within the 'view' statement only.
2179 */
2180 static cfg_clausedef_t view_only_clauses[] = {
2181 { "match-clients", &cfg_type_bracketed_aml, 0 },
2182 { "match-destinations", &cfg_type_bracketed_aml, 0 },
2183 { "match-recursive-only", &cfg_type_boolean, 0 },
2184 { NULL, NULL, 0 }
2185 };
2186
2187 /*%
2188 * Sig-validity-interval.
2189 */
2190
2191 static cfg_tuplefielddef_t validityinterval_fields[] = {
2192 { "validity", &cfg_type_uint32, 0 },
2193 { "re-sign", &cfg_type_optional_uint32, 0 },
2194 { NULL, NULL, 0 }
2195 };
2196
2197 static cfg_type_t cfg_type_validityinterval = {
2198 "validityinterval", cfg_parse_tuple, cfg_print_tuple,
2199 cfg_doc_tuple, &cfg_rep_tuple, validityinterval_fields
2200 };
2201
2202 /*%
2203 * Clauses that can be found in a 'dnssec-policy' statement.
2204 */
2205 static cfg_clausedef_t dnssecpolicy_clauses[] = {
2206 { "dnskey-ttl", &cfg_type_duration, 0 },
2207 { "keys", &cfg_type_kaspkeys, 0 },
2208 { "max-zone-ttl", &cfg_type_duration, 0 },
2209 { "nsec3param", &cfg_type_nsec3, 0 },
2210 { "parent-ds-ttl", &cfg_type_duration, 0 },
2211 { "parent-propagation-delay", &cfg_type_duration, 0 },
2212 { "parent-registration-delay", &cfg_type_duration,
2213 CFG_CLAUSEFLAG_OBSOLETE },
2214 { "publish-safety", &cfg_type_duration, 0 },
2215 { "purge-keys", &cfg_type_duration, 0 },
2216 { "retire-safety", &cfg_type_duration, 0 },
2217 { "signatures-jitter", &cfg_type_duration, 0 },
2218 { "signatures-refresh", &cfg_type_duration, 0 },
2219 { "signatures-validity", &cfg_type_duration, 0 },
2220 { "signatures-validity-dnskey", &cfg_type_duration, 0 },
2221 { "zone-propagation-delay", &cfg_type_duration, 0 },
2222 { NULL, NULL, 0 }
2223 };
2224
2225 /*%
2226 * Clauses that can be found in a 'zone' statement,
2227 * with defaults in the 'view' or 'options' statement.
2228 *
2229 * Note: CFG_ZONE_* options indicate in which zone types this clause is
2230 * legal.
2231 */
2232 /*
2233 * NOTE: To enable syntax which allows specifying port and protocol
2234 * within 'allow-*' clauses, replace 'cfg_type_bracketed_aml' with
2235 * 'cfg_type_transport_acl'.
2236 *
2237 * Example: allow-transfer port 853 protocol tls { ... };
2238 */
2239 static cfg_clausedef_t zone_clauses[] = {
2240 { "allow-notify", &cfg_type_bracketed_aml,
2241 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2242 { "allow-query", &cfg_type_bracketed_aml,
2243 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2244 CFG_ZONE_STUB | CFG_ZONE_REDIRECT | CFG_ZONE_STATICSTUB },
2245 { "allow-query-on", &cfg_type_bracketed_aml,
2246 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2247 CFG_ZONE_STUB | CFG_ZONE_REDIRECT | CFG_ZONE_STATICSTUB },
2248 { "allow-transfer", &cfg_type_transport_acl,
2249 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2250 { "allow-update", &cfg_type_bracketed_aml, CFG_ZONE_PRIMARY },
2251 { "allow-update-forwarding", &cfg_type_bracketed_aml,
2252 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2253 { "also-notify", &cfg_type_namesockaddrkeylist,
2254 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2255 { "alt-transfer-source", &cfg_type_sockaddr4wild,
2256 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2257 CFG_CLAUSEFLAG_DEPRECATED },
2258 { "alt-transfer-source-v6", &cfg_type_sockaddr6wild,
2259 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2260 CFG_CLAUSEFLAG_DEPRECATED },
2261 { "auto-dnssec", &cfg_type_autodnssec,
2262 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_CLAUSEFLAG_DEPRECATED },
2263 { "check-dup-records", &cfg_type_checkmode, CFG_ZONE_PRIMARY },
2264 { "check-integrity", &cfg_type_boolean, CFG_ZONE_PRIMARY },
2265 { "check-mx", &cfg_type_checkmode, CFG_ZONE_PRIMARY },
2266 { "check-mx-cname", &cfg_type_checkmode, CFG_ZONE_PRIMARY },
2267 { "check-sibling", &cfg_type_boolean, CFG_ZONE_PRIMARY },
2268 { "check-spf", &cfg_type_warn, CFG_ZONE_PRIMARY },
2269 { "check-srv-cname", &cfg_type_checkmode, CFG_ZONE_PRIMARY },
2270 { "check-wildcard", &cfg_type_boolean, CFG_ZONE_PRIMARY },
2271 { "dialup", &cfg_type_dialuptype,
2272 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_STUB |
2273 CFG_CLAUSEFLAG_DEPRECATED },
2274 { "dnssec-dnskey-kskonly", &cfg_type_boolean,
2275 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2276 { "dnssec-loadkeys-interval", &cfg_type_uint32,
2277 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2278 { "dnssec-policy", &cfg_type_astring,
2279 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2280 { "dnssec-secure-to-insecure", &cfg_type_boolean, CFG_ZONE_PRIMARY },
2281 { "dnssec-update-mode", &cfg_type_dnssecupdatemode,
2282 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2283 { "forward", &cfg_type_forwardtype,
2284 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_STUB |
2285 CFG_ZONE_STATICSTUB | CFG_ZONE_FORWARD },
2286 { "forwarders", &cfg_type_portiplist,
2287 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_STUB |
2288 CFG_ZONE_STATICSTUB | CFG_ZONE_FORWARD },
2289 { "key-directory", &cfg_type_qstring,
2290 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2291 { "maintain-ixfr-base", NULL, CFG_CLAUSEFLAG_ANCIENT },
2292 { "masterfile-format", &cfg_type_masterformat,
2293 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2294 CFG_ZONE_STUB | CFG_ZONE_REDIRECT },
2295 { "masterfile-style", &cfg_type_masterstyle,
2296 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2297 CFG_ZONE_STUB | CFG_ZONE_REDIRECT },
2298 { "max-ixfr-log-size", NULL, CFG_CLAUSEFLAG_ANCIENT },
2299 { "max-ixfr-ratio", &cfg_type_ixfrratio,
2300 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2301 { "max-journal-size", &cfg_type_size,
2302 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2303 { "max-records", &cfg_type_uint32,
2304 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2305 CFG_ZONE_STUB | CFG_ZONE_STATICSTUB | CFG_ZONE_REDIRECT },
2306 { "max-records-per-type", &cfg_type_uint32,
2307 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2308 CFG_ZONE_STUB | CFG_ZONE_STATICSTUB | CFG_ZONE_REDIRECT },
2309 { "max-types-per-name", &cfg_type_uint32,
2310 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2311 CFG_ZONE_STUB | CFG_ZONE_STATICSTUB | CFG_ZONE_REDIRECT },
2312 { "max-refresh-time", &cfg_type_uint32,
2313 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2314 { "max-retry-time", &cfg_type_uint32,
2315 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2316 { "max-transfer-idle-in", &cfg_type_uint32,
2317 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2318 { "max-transfer-idle-out", &cfg_type_uint32,
2319 CFG_ZONE_PRIMARY | CFG_ZONE_MIRROR | CFG_ZONE_SECONDARY },
2320 { "max-transfer-time-in", &cfg_type_uint32,
2321 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2322 { "max-transfer-time-out", &cfg_type_uint32,
2323 CFG_ZONE_PRIMARY | CFG_ZONE_MIRROR | CFG_ZONE_SECONDARY },
2324 { "max-zone-ttl", &cfg_type_maxduration,
2325 CFG_ZONE_PRIMARY | CFG_ZONE_REDIRECT },
2326 { "min-refresh-time", &cfg_type_uint32,
2327 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2328 { "min-retry-time", &cfg_type_uint32,
2329 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2330 { "multi-master", &cfg_type_boolean,
2331 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2332 { "notify", &cfg_type_notifytype,
2333 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2334 { "notify-delay", &cfg_type_uint32,
2335 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2336 { "notify-source", &cfg_type_sockaddr4wild,
2337 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2338 { "notify-source-v6", &cfg_type_sockaddr6wild,
2339 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2340 { "notify-to-soa", &cfg_type_boolean,
2341 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2342 { "nsec3-test-zone", &cfg_type_boolean,
2343 CFG_CLAUSEFLAG_TESTONLY | CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2344 { "parental-source", &cfg_type_sockaddr4wild,
2345 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2346 { "parental-source-v6", &cfg_type_sockaddr6wild,
2347 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2348 { "request-expire", &cfg_type_boolean,
2349 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2350 { "request-ixfr", &cfg_type_boolean,
2351 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2352 { "serial-update-method", &cfg_type_updatemethod, CFG_ZONE_PRIMARY },
2353 { "sig-signing-nodes", &cfg_type_uint32,
2354 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2355 { "sig-signing-signatures", &cfg_type_uint32,
2356 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2357 { "sig-signing-type", &cfg_type_uint32,
2358 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2359 { "sig-validity-interval", &cfg_type_validityinterval,
2360 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2361 { "dnskey-sig-validity", &cfg_type_uint32,
2362 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2363 { "transfer-source", &cfg_type_sockaddr4wild,
2364 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2365 { "transfer-source-v6", &cfg_type_sockaddr6wild,
2366 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB },
2367 { "try-tcp-refresh", &cfg_type_boolean,
2368 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2369 { "update-check-ksk", &cfg_type_boolean,
2370 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2371 { "use-alt-transfer-source", &cfg_type_boolean,
2372 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB |
2373 CFG_CLAUSEFLAG_DEPRECATED },
2374 { "zero-no-soa-ttl", &cfg_type_boolean,
2375 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2376 { "zone-statistics", &cfg_type_zonestat,
2377 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2378 CFG_ZONE_STUB | CFG_ZONE_STATICSTUB | CFG_ZONE_REDIRECT },
2379 { NULL, NULL, 0 }
2380 };
2381
2382 /*%
2383 * Clauses that can be found in a 'zone' statement only.
2384 *
2385 * Note: CFG_ZONE_* options indicate in which zone types this clause is
2386 * legal.
2387 */
2388 static cfg_clausedef_t zone_only_clauses[] = {
2389 /*
2390 * Note that the format of the check-names option is different between
2391 * the zone options and the global/view options. Ugh.
2392 */
2393 { "type", &cfg_type_zonetype,
2394 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2395 CFG_ZONE_STUB | CFG_ZONE_STATICSTUB | CFG_ZONE_DELEGATION |
2396 CFG_ZONE_HINT | CFG_ZONE_REDIRECT | CFG_ZONE_FORWARD },
2397 { "check-names", &cfg_type_checkmode,
2398 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2399 CFG_ZONE_HINT | CFG_ZONE_STUB },
2400 { "database", &cfg_type_astring,
2401 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2402 CFG_ZONE_STUB },
2403 { "delegation-only", &cfg_type_boolean,
2404 CFG_ZONE_HINT | CFG_ZONE_STUB | CFG_ZONE_FORWARD |
2405 CFG_CLAUSEFLAG_DEPRECATED },
2406 { "dlz", &cfg_type_astring,
2407 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_REDIRECT },
2408 { "file", &cfg_type_qstring,
2409 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR |
2410 CFG_ZONE_STUB | CFG_ZONE_HINT | CFG_ZONE_REDIRECT },
2411 { "in-view", &cfg_type_astring, CFG_ZONE_INVIEW },
2412 { "inline-signing", &cfg_type_boolean,
2413 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2414 { "ixfr-base", NULL, CFG_CLAUSEFLAG_ANCIENT },
2415 { "ixfr-from-differences", &cfg_type_boolean,
2416 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2417 { "ixfr-tmp-file", NULL, CFG_CLAUSEFLAG_ANCIENT },
2418 { "journal", &cfg_type_qstring,
2419 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR },
2420 { "masters", &cfg_type_namesockaddrkeylist,
2421 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB |
2422 CFG_ZONE_REDIRECT | CFG_CLAUSEFLAG_NODOC },
2423 { "parental-agents", &cfg_type_namesockaddrkeylist,
2424 CFG_ZONE_PRIMARY | CFG_ZONE_SECONDARY },
2425 { "primaries", &cfg_type_namesockaddrkeylist,
2426 CFG_ZONE_SECONDARY | CFG_ZONE_MIRROR | CFG_ZONE_STUB |
2427 CFG_ZONE_REDIRECT },
2428 { "pubkey", NULL, CFG_CLAUSEFLAG_ANCIENT },
2429 { "server-addresses", &cfg_type_bracketed_netaddrlist,
2430 CFG_ZONE_STATICSTUB },
2431 { "server-names", &cfg_type_namelist, CFG_ZONE_STATICSTUB },
2432 { "update-policy", &cfg_type_updatepolicy, CFG_ZONE_PRIMARY },
2433 { NULL, NULL, 0 }
2434 };
2435
2436 /*% The top-level named.conf syntax. */
2437
2438 static cfg_clausedef_t *namedconf_clausesets[] = { namedconf_clauses,
2439 namedconf_or_view_clauses,
2440 NULL };
2441 cfg_type_t cfg_type_namedconf = { "namedconf", cfg_parse_mapbody,
2442 cfg_print_mapbody, cfg_doc_mapbody,
2443 &cfg_rep_map, namedconf_clausesets };
2444
2445 /*% The bind.keys syntax (trust-anchors/managed-keys/trusted-keys only). */
2446 static cfg_clausedef_t *bindkeys_clausesets[] = { bindkeys_clauses, NULL };
2447 cfg_type_t cfg_type_bindkeys = { "bindkeys", cfg_parse_mapbody,
2448 cfg_print_mapbody, cfg_doc_mapbody,
2449 &cfg_rep_map, bindkeys_clausesets };
2450
2451 /*% The "options" statement syntax. */
2452
2453 static cfg_clausedef_t *options_clausesets[] = { options_clauses, view_clauses,
2454 zone_clauses, NULL };
2455 static cfg_type_t cfg_type_options = { "options", cfg_parse_map,
2456 cfg_print_map, cfg_doc_map,
2457 &cfg_rep_map, options_clausesets };
2458
2459 /*% The "view" statement syntax. */
2460
2461 static cfg_clausedef_t *view_clausesets[] = { view_only_clauses,
2462 namedconf_or_view_clauses,
2463 view_clauses, zone_clauses,
2464 NULL };
2465
2466 static cfg_type_t cfg_type_viewopts = { "view", cfg_parse_map,
2467 cfg_print_map, cfg_doc_map,
2468 &cfg_rep_map, view_clausesets };
2469
2470 /*% The "zone" statement syntax. */
2471
2472 static cfg_clausedef_t *zone_clausesets[] = { zone_only_clauses, zone_clauses,
2473 NULL };
2474 cfg_type_t cfg_type_zoneopts = { "zoneopts", cfg_parse_map, cfg_print_map,
2475 cfg_doc_map, &cfg_rep_map, zone_clausesets };
2476
2477 /*% The "dnssec-policy" statement syntax. */
2478 static cfg_clausedef_t *dnssecpolicy_clausesets[] = { dnssecpolicy_clauses,
2479 NULL };
2480 cfg_type_t cfg_type_dnssecpolicyopts = {
2481 "dnssecpolicyopts", cfg_parse_map, cfg_print_map,
2482 cfg_doc_map, &cfg_rep_map, dnssecpolicy_clausesets
2483 };
2484
2485 /*% The "dynamically loadable zones" statement syntax. */
2486
2487 static cfg_clausedef_t dlz_clauses[] = { { "database", &cfg_type_astring, 0 },
2488 { "search", &cfg_type_boolean, 0 },
2489 { NULL, NULL, 0 } };
2490 static cfg_clausedef_t *dlz_clausesets[] = { dlz_clauses, NULL };
2491 static cfg_type_t cfg_type_dlz = { "dlz", cfg_parse_named_map,
2492 cfg_print_map, cfg_doc_map,
2493 &cfg_rep_map, dlz_clausesets };
2494
2495 /*%
2496 * The "dyndb" statement syntax.
2497 */
2498
2499 static cfg_tuplefielddef_t dyndb_fields[] = {
2500 { "name", &cfg_type_astring, 0 },
2501 { "library", &cfg_type_qstring, 0 },
2502 { "parameters", &cfg_type_bracketed_text, 0 },
2503 { NULL, NULL, 0 }
2504 };
2505
2506 static cfg_type_t cfg_type_dyndb = { "dyndb", cfg_parse_tuple,
2507 cfg_print_tuple, cfg_doc_tuple,
2508 &cfg_rep_tuple, dyndb_fields };
2509
2510 /*%
2511 * The "plugin" statement syntax.
2512 * Currently only one plugin type is supported: query.
2513 */
2514
2515 static const char *plugin_enums[] = { "query", NULL };
2516 static cfg_type_t cfg_type_plugintype = { "plugintype", cfg_parse_enum,
2517 cfg_print_ustring, cfg_doc_enum,
2518 &cfg_rep_string, plugin_enums };
2519 static cfg_tuplefielddef_t plugin_fields[] = {
2520 { "type", &cfg_type_plugintype, 0 },
2521 { "library", &cfg_type_astring, 0 },
2522 { "parameters", &cfg_type_optional_bracketed_text, 0 },
2523 { NULL, NULL, 0 }
2524 };
2525 static cfg_type_t cfg_type_plugin = { "plugin", cfg_parse_tuple,
2526 cfg_print_tuple, cfg_doc_tuple,
2527 &cfg_rep_tuple, plugin_fields };
2528
2529 /*%
2530 * Clauses that can be found within the 'key' statement.
2531 */
2532 static cfg_clausedef_t key_clauses[] = { { "algorithm", &cfg_type_astring, 0 },
2533 { "secret", &cfg_type_sstring, 0 },
2534 { NULL, NULL, 0 } };
2535
2536 static cfg_clausedef_t *key_clausesets[] = { key_clauses, NULL };
2537 static cfg_type_t cfg_type_key = { "key", cfg_parse_named_map,
2538 cfg_print_map, cfg_doc_map,
2539 &cfg_rep_map, key_clausesets };
2540
2541 /*%
2542 * Clauses that can be found in a 'server' statement.
2543 *
2544 * Please update lib/bind9/check.c and
2545 * bin/tests/system/checkconf/good-server-christmas-tree.conf.in to
2546 * exercise the new clause when adding new clauses.
2547 */
2548 static cfg_clausedef_t server_clauses[] = {
2549 { "bogus", &cfg_type_boolean, 0 },
2550 { "edns", &cfg_type_boolean, 0 },
2551 { "edns-udp-size", &cfg_type_uint32, 0 },
2552 { "edns-version", &cfg_type_uint32, 0 },
2553 { "keys", &cfg_type_server_key_kludge, 0 },
2554 { "max-udp-size", &cfg_type_uint32, 0 },
2555 { "notify-source", &cfg_type_sockaddr4wild, 0 },
2556 { "notify-source-v6", &cfg_type_sockaddr6wild, 0 },
2557 { "padding", &cfg_type_uint32, 0 },
2558 { "provide-ixfr", &cfg_type_boolean, 0 },
2559 { "query-source", &cfg_type_querysource4, 0 },
2560 { "query-source-v6", &cfg_type_querysource6, 0 },
2561 { "request-expire", &cfg_type_boolean, 0 },
2562 { "request-ixfr", &cfg_type_boolean, 0 },
2563 { "request-nsid", &cfg_type_boolean, 0 },
2564 { "request-sit", NULL, CFG_CLAUSEFLAG_ANCIENT },
2565 { "send-cookie", &cfg_type_boolean, 0 },
2566 { "support-ixfr", NULL, CFG_CLAUSEFLAG_ANCIENT },
2567 { "tcp-keepalive", &cfg_type_boolean, 0 },
2568 { "tcp-only", &cfg_type_boolean, 0 },
2569 { "transfer-format", &cfg_type_transferformat, 0 },
2570 { "transfer-source", &cfg_type_sockaddr4wild, 0 },
2571 { "transfer-source-v6", &cfg_type_sockaddr6wild, 0 },
2572 { "transfers", &cfg_type_uint32, 0 },
2573 { NULL, NULL, 0 }
2574 };
2575 static cfg_clausedef_t *server_clausesets[] = { server_clauses, NULL };
2576 static cfg_type_t cfg_type_server = { "server", cfg_parse_netprefix_map,
2577 cfg_print_map, cfg_doc_map,
2578 &cfg_rep_map, server_clausesets };
2579
2580 /*%
2581 * Clauses that can be found in a 'channel' clause in the
2582 * 'logging' statement.
2583 *
2584 * These have some additional constraints that need to be
2585 * checked after parsing:
2586 * - There must exactly one of file/syslog/null/stderr
2587 */
2588
2589 static const char *printtime_enums[] = { "iso8601", "iso8601-utc", "local",
2590 NULL };
2591 static isc_result_t
2592 parse_printtime(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2593 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
2594 }
2595 static void
2596 doc_printtime(cfg_printer_t *pctx, const cfg_type_t *type) {
2597 cfg_doc_enum_or_other(pctx, type, &cfg_type_boolean);
2598 }
2599 static cfg_type_t cfg_type_printtime = { "printtime", parse_printtime,
2600 cfg_print_ustring, doc_printtime,
2601 &cfg_rep_string, printtime_enums };
2602
2603 static cfg_clausedef_t channel_clauses[] = {
2604 /* Destinations. We no longer require these to be first. */
2605 { "file", &cfg_type_logfile, 0 },
2606 { "syslog", &cfg_type_optional_facility, 0 },
2607 { "null", &cfg_type_void, 0 },
2608 { "stderr", &cfg_type_void, 0 },
2609 /* Options. We now accept these for the null channel, too. */
2610 { "severity", &cfg_type_logseverity, 0 },
2611 { "print-time", &cfg_type_printtime, 0 },
2612 { "print-severity", &cfg_type_boolean, 0 },
2613 { "print-category", &cfg_type_boolean, 0 },
2614 { "buffered", &cfg_type_boolean, 0 },
2615 { NULL, NULL, 0 }
2616 };
2617 static cfg_clausedef_t *channel_clausesets[] = { channel_clauses, NULL };
2618 static cfg_type_t cfg_type_channel = { "channel", cfg_parse_named_map,
2619 cfg_print_map, cfg_doc_map,
2620 &cfg_rep_map, channel_clausesets };
2621
2622 /*% A list of log destination, used in the "category" clause. */
2623 static cfg_type_t cfg_type_destinationlist = { "destinationlist",
2624 cfg_parse_bracketed_list,
2625 cfg_print_bracketed_list,
2626 cfg_doc_bracketed_list,
2627 &cfg_rep_list,
2628 &cfg_type_astring };
2629
2630 /*%
2631 * Clauses that can be found in a 'logging' statement.
2632 */
2633 static cfg_clausedef_t logging_clauses[] = {
2634 { "channel", &cfg_type_channel, CFG_CLAUSEFLAG_MULTI },
2635 { "category", &cfg_type_category, CFG_CLAUSEFLAG_MULTI },
2636 { NULL, NULL, 0 }
2637 };
2638 static cfg_clausedef_t *logging_clausesets[] = { logging_clauses, NULL };
2639 static cfg_type_t cfg_type_logging = { "logging", cfg_parse_map,
2640 cfg_print_map, cfg_doc_map,
2641 &cfg_rep_map, logging_clausesets };
2642
2643 /*%
2644 * For parsing an 'addzone' statement
2645 */
2646 static cfg_tuplefielddef_t addzone_fields[] = {
2647 { "name", &cfg_type_astring, 0 },
2648 { "class", &cfg_type_optional_class, 0 },
2649 { "view", &cfg_type_optional_class, 0 },
2650 { "options", &cfg_type_zoneopts, 0 },
2651 { NULL, NULL, 0 }
2652 };
2653 static cfg_type_t cfg_type_addzone = { "zone", cfg_parse_tuple,
2654 cfg_print_tuple, cfg_doc_tuple,
2655 &cfg_rep_tuple, addzone_fields };
2656
2657 static cfg_clausedef_t addzoneconf_clauses[] = {
2658 { "zone", &cfg_type_addzone, CFG_CLAUSEFLAG_MULTI }, { NULL, NULL, 0 }
2659 };
2660
2661 static cfg_clausedef_t *addzoneconf_clausesets[] = { addzoneconf_clauses,
2662 NULL };
2663
2664 cfg_type_t cfg_type_addzoneconf = { "addzoneconf", cfg_parse_mapbody,
2665 cfg_print_mapbody, cfg_doc_mapbody,
2666 &cfg_rep_map, addzoneconf_clausesets };
2667
2668 static isc_result_t
2669 parse_unitstring(char *str, isc_resourcevalue_t *valuep) {
2670 char *endp;
2671 unsigned int len;
2672 uint64_t value;
2673 uint64_t unit;
2674
2675 value = strtoull(str, &endp, 10);
2676 if (*endp == 0) {
2677 *valuep = value;
2678 return (ISC_R_SUCCESS);
2679 }
2680
2681 len = strlen(str);
2682 if (len < 2 || endp[1] != '\0') {
2683 return (ISC_R_FAILURE);
2684 }
2685
2686 switch (str[len - 1]) {
2687 case 'k':
2688 case 'K':
2689 unit = 1024;
2690 break;
2691 case 'm':
2692 case 'M':
2693 unit = 1024 * 1024;
2694 break;
2695 case 'g':
2696 case 'G':
2697 unit = 1024 * 1024 * 1024;
2698 break;
2699 default:
2700 return (ISC_R_FAILURE);
2701 }
2702 if (value > ((uint64_t)UINT64_MAX / unit)) {
2703 return (ISC_R_FAILURE);
2704 }
2705 *valuep = value * unit;
2706 return (ISC_R_SUCCESS);
2707 }
2708
2709 static isc_result_t
2710 parse_sizeval(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2711 isc_result_t result;
2712 cfg_obj_t *obj = NULL;
2713 uint64_t val;
2714
2715 UNUSED(type);
2716
2717 CHECK(cfg_gettoken(pctx, 0));
2718 if (pctx->token.type != isc_tokentype_string) {
2719 result = ISC_R_UNEXPECTEDTOKEN;
2720 goto cleanup;
2721 }
2722 CHECK(parse_unitstring(TOKEN_STRING(pctx), &val));
2723
2724 CHECK(cfg_create_obj(pctx, &cfg_type_uint64, &obj));
2725 obj->value.uint64 = val;
2726 *ret = obj;
2727 return (ISC_R_SUCCESS);
2728
2729 cleanup:
2730 cfg_parser_error(pctx, CFG_LOG_NEAR,
2731 "expected integer and optional unit");
2732 return (result);
2733 }
2734
2735 static isc_result_t
2736 parse_sizeval_percent(cfg_parser_t *pctx, const cfg_type_t *type,
2737 cfg_obj_t **ret) {
2738 char *endp;
2739 isc_result_t result;
2740 cfg_obj_t *obj = NULL;
2741 uint64_t val;
2742 uint64_t percent;
2743
2744 UNUSED(type);
2745
2746 CHECK(cfg_gettoken(pctx, 0));
2747 if (pctx->token.type != isc_tokentype_string) {
2748 result = ISC_R_UNEXPECTEDTOKEN;
2749 goto cleanup;
2750 }
2751
2752 percent = strtoull(TOKEN_STRING(pctx), &endp, 10);
2753
2754 if (*endp == '%' && *(endp + 1) == 0) {
2755 CHECK(cfg_create_obj(pctx, &cfg_type_percentage, &obj));
2756 obj->value.uint32 = (uint32_t)percent;
2757 *ret = obj;
2758 return (ISC_R_SUCCESS);
2759 } else {
2760 CHECK(parse_unitstring(TOKEN_STRING(pctx), &val));
2761 CHECK(cfg_create_obj(pctx, &cfg_type_uint64, &obj));
2762 obj->value.uint64 = val;
2763 *ret = obj;
2764 return (ISC_R_SUCCESS);
2765 }
2766
2767 cleanup:
2768 cfg_parser_error(pctx, CFG_LOG_NEAR,
2769 "expected integer and optional unit or percent");
2770 return (result);
2771 }
2772
2773 static void
2774 doc_sizeval_percent(cfg_printer_t *pctx, const cfg_type_t *type) {
2775 UNUSED(type);
2776
2777 cfg_print_cstr(pctx, "( ");
2778 cfg_doc_terminal(pctx, &cfg_type_size);
2779 cfg_print_cstr(pctx, " | ");
2780 cfg_doc_terminal(pctx, &cfg_type_percentage);
2781 cfg_print_cstr(pctx, " )");
2782 }
2783
2784 /*%
2785 * A size value (number + optional unit).
2786 */
2787 static cfg_type_t cfg_type_sizeval = { "sizeval", parse_sizeval,
2788 cfg_print_uint64, cfg_doc_terminal,
2789 &cfg_rep_uint64, NULL };
2790
2791 /*%
2792 * A size, "unlimited", or "default".
2793 */
2794
2795 static isc_result_t
2796 parse_size(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2797 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_sizeval, ret));
2798 }
2799
2800 static void
2801 doc_size(cfg_printer_t *pctx, const cfg_type_t *type) {
2802 cfg_doc_enum_or_other(pctx, type, &cfg_type_sizeval);
2803 }
2804
2805 static const char *size_enums[] = { "default", "unlimited", NULL };
2806 static cfg_type_t cfg_type_size = {
2807 "size", parse_size, cfg_print_ustring,
2808 doc_size, &cfg_rep_string, size_enums
2809 };
2810
2811 /*%
2812 * A size or "unlimited", but not "default".
2813 */
2814 static const char *sizenodefault_enums[] = { "unlimited", NULL };
2815 static cfg_type_t cfg_type_sizenodefault = {
2816 "size_no_default", parse_size, cfg_print_ustring,
2817 doc_size, &cfg_rep_string, sizenodefault_enums
2818 };
2819
2820 /*%
2821 * A size in absolute values or percents.
2822 */
2823 static cfg_type_t cfg_type_sizeval_percent = {
2824 "sizeval_percent", parse_sizeval_percent, cfg_print_ustring,
2825 doc_sizeval_percent, &cfg_rep_string, NULL
2826 };
2827
2828 /*%
2829 * A size in absolute values or percents, or "unlimited", or "default"
2830 */
2831
2832 static isc_result_t
2833 parse_size_or_percent(cfg_parser_t *pctx, const cfg_type_t *type,
2834 cfg_obj_t **ret) {
2835 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_sizeval_percent,
2836 ret));
2837 }
2838
2839 static void
2840 doc_parse_size_or_percent(cfg_printer_t *pctx, const cfg_type_t *type) {
2841 UNUSED(type);
2842 cfg_print_cstr(pctx, "( default | unlimited | ");
2843 cfg_doc_terminal(pctx, &cfg_type_sizeval);
2844 cfg_print_cstr(pctx, " | ");
2845 cfg_doc_terminal(pctx, &cfg_type_percentage);
2846 cfg_print_cstr(pctx, " )");
2847 }
2848
2849 static const char *sizeorpercent_enums[] = { "default", "unlimited", NULL };
2850 static cfg_type_t cfg_type_sizeorpercent = {
2851 "size_or_percent", parse_size_or_percent, cfg_print_ustring,
2852 doc_parse_size_or_percent, &cfg_rep_string, sizeorpercent_enums
2853 };
2854
2855 /*%
2856 * An IXFR size ratio: percentage, or "unlimited".
2857 */
2858
2859 static isc_result_t
2860 parse_ixfrratio(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2861 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_percentage, ret));
2862 }
2863
2864 static void
2865 doc_ixfrratio(cfg_printer_t *pctx, const cfg_type_t *type) {
2866 UNUSED(type);
2867 cfg_print_cstr(pctx, "( unlimited | ");
2868 cfg_doc_terminal(pctx, &cfg_type_percentage);
2869 cfg_print_cstr(pctx, " )");
2870 }
2871
2872 static const char *ixfrratio_enums[] = { "unlimited", NULL };
2873 static cfg_type_t cfg_type_ixfrratio = { "ixfr_ratio", parse_ixfrratio,
2874 NULL, doc_ixfrratio,
2875 NULL, ixfrratio_enums };
2876
2877 /*%
2878 * optional_keyvalue
2879 */
2880 static isc_result_t
2881 parse_maybe_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type,
2882 bool optional, cfg_obj_t **ret) {
2883 isc_result_t result;
2884 cfg_obj_t *obj = NULL;
2885 const keyword_type_t *kw = type->of;
2886
2887 CHECK(cfg_peektoken(pctx, 0));
2888 if (pctx->token.type == isc_tokentype_string &&
2889 strcasecmp(TOKEN_STRING(pctx), kw->name) == 0)
2890 {
2891 CHECK(cfg_gettoken(pctx, 0));
2892 CHECK(kw->type->parse(pctx, kw->type, &obj));
2893 obj->type = type; /* XXX kludge */
2894 } else {
2895 if (optional) {
2896 CHECK(cfg_parse_void(pctx, NULL, &obj));
2897 } else {
2898 cfg_parser_error(pctx, CFG_LOG_NEAR, "expected '%s'",
2899 kw->name);
2900 result = ISC_R_UNEXPECTEDTOKEN;
2901 goto cleanup;
2902 }
2903 }
2904 *ret = obj;
2905 cleanup:
2906 return (result);
2907 }
2908
2909 static isc_result_t
2910 parse_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2911 return (parse_maybe_optional_keyvalue(pctx, type, false, ret));
2912 }
2913
2914 static isc_result_t
2915 parse_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type,
2916 cfg_obj_t **ret) {
2917 return (parse_maybe_optional_keyvalue(pctx, type, true, ret));
2918 }
2919
2920 static void
2921 print_keyvalue(cfg_printer_t *pctx, const cfg_obj_t *obj) {
2922 const keyword_type_t *kw = obj->type->of;
2923 cfg_print_cstr(pctx, kw->name);
2924 cfg_print_cstr(pctx, " ");
2925 kw->type->print(pctx, obj);
2926 }
2927
2928 static void
2929 doc_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type) {
2930 const keyword_type_t *kw = type->of;
2931 cfg_print_cstr(pctx, kw->name);
2932 cfg_print_cstr(pctx, " ");
2933 cfg_doc_obj(pctx, kw->type);
2934 }
2935
2936 static void
2937 doc_optional_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type) {
2938 const keyword_type_t *kw = type->of;
2939 cfg_print_cstr(pctx, "[ ");
2940 cfg_print_cstr(pctx, kw->name);
2941 cfg_print_cstr(pctx, " ");
2942 cfg_doc_obj(pctx, kw->type);
2943 cfg_print_cstr(pctx, " ]");
2944 }
2945
2946 static const char *dialup_enums[] = { "notify", "notify-passive", "passive",
2947 "refresh", NULL };
2948 static isc_result_t
2949 parse_dialup_type(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2950 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
2951 }
2952 static void
2953 doc_dialup_type(cfg_printer_t *pctx, const cfg_type_t *type) {
2954 cfg_doc_enum_or_other(pctx, type, &cfg_type_boolean);
2955 }
2956 static cfg_type_t cfg_type_dialuptype = { "dialuptype", parse_dialup_type,
2957 cfg_print_ustring, doc_dialup_type,
2958 &cfg_rep_string, dialup_enums };
2959
2960 static const char *notify_enums[] = { "explicit", "master-only", "primary-only",
2961 NULL };
2962 static isc_result_t
2963 parse_notify_type(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2964 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
2965 }
2966 static void
2967 doc_notify_type(cfg_printer_t *pctx, const cfg_type_t *type) {
2968 cfg_doc_enum_or_other(pctx, type, &cfg_type_boolean);
2969 }
2970 static cfg_type_t cfg_type_notifytype = {
2971 "notifytype", parse_notify_type, cfg_print_ustring,
2972 doc_notify_type, &cfg_rep_string, notify_enums,
2973 };
2974
2975 static const char *minimal_enums[] = { "no-auth", "no-auth-recursive", NULL };
2976 static isc_result_t
2977 parse_minimal(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
2978 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
2979 }
2980 static void
2981 doc_minimal(cfg_printer_t *pctx, const cfg_type_t *type) {
2982 cfg_doc_enum_or_other(pctx, type, &cfg_type_boolean);
2983 }
2984 static cfg_type_t cfg_type_minimal = {
2985 "minimal", parse_minimal, cfg_print_ustring,
2986 doc_minimal, &cfg_rep_string, minimal_enums,
2987 };
2988
2989 static const char *ixfrdiff_enums[] = { "primary", "master", "secondary",
2990 "slave", NULL };
2991 static isc_result_t
2992 parse_ixfrdiff_type(cfg_parser_t *pctx, const cfg_type_t *type,
2993 cfg_obj_t **ret) {
2994 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
2995 }
2996 static void
2997 doc_ixfrdiff_type(cfg_printer_t *pctx, const cfg_type_t *type) {
2998 cfg_doc_enum_or_other(pctx, type, &cfg_type_boolean);
2999 }
3000 static cfg_type_t cfg_type_ixfrdifftype = {
3001 "ixfrdiff", parse_ixfrdiff_type, cfg_print_ustring,
3002 doc_ixfrdiff_type, &cfg_rep_string, ixfrdiff_enums,
3003 };
3004
3005 static keyword_type_t key_kw = { "key", &cfg_type_astring };
3006
3007 cfg_type_t cfg_type_keyref = { "keyref", parse_keyvalue, print_keyvalue,
3008 doc_keyvalue, &cfg_rep_string, &key_kw };
3009
3010 static cfg_type_t cfg_type_optional_keyref = {
3011 "optional_keyref", parse_optional_keyvalue, print_keyvalue,
3012 doc_optional_keyvalue, &cfg_rep_string, &key_kw
3013 };
3014
3015 static const char *qminmethod_enums[] = { "strict", "relaxed", "disabled",
3016 "off", NULL };
3017
3018 static cfg_type_t cfg_type_qminmethod = { "qminmethod", cfg_parse_enum,
3019 cfg_print_ustring, cfg_doc_enum,
3020 &cfg_rep_string, qminmethod_enums };
3021
3022 /*%
3023 * A "controls" statement is represented as a map with the multivalued
3024 * "inet" and "unix" clauses.
3025 */
3026
3027 static keyword_type_t controls_allow_kw = { "allow", &cfg_type_bracketed_aml };
3028
3029 static cfg_type_t cfg_type_controls_allow = {
3030 "controls_allow", parse_keyvalue, print_keyvalue,
3031 doc_keyvalue, &cfg_rep_list, &controls_allow_kw
3032 };
3033
3034 static keyword_type_t controls_keys_kw = { "keys", &cfg_type_keylist };
3035
3036 static cfg_type_t cfg_type_controls_keys = {
3037 "controls_keys", parse_optional_keyvalue, print_keyvalue,
3038 doc_optional_keyvalue, &cfg_rep_list, &controls_keys_kw
3039 };
3040
3041 static keyword_type_t controls_readonly_kw = { "read-only", &cfg_type_boolean };
3042
3043 static cfg_type_t cfg_type_controls_readonly = {
3044 "controls_readonly", parse_optional_keyvalue, print_keyvalue,
3045 doc_optional_keyvalue, &cfg_rep_boolean, &controls_readonly_kw
3046 };
3047
3048 static cfg_tuplefielddef_t inetcontrol_fields[] = {
3049 { "address", &cfg_type_controls_sockaddr, 0 },
3050 { "allow", &cfg_type_controls_allow, 0 },
3051 { "keys", &cfg_type_controls_keys, 0 },
3052 { "read-only", &cfg_type_controls_readonly, 0 },
3053 { NULL, NULL, 0 }
3054 };
3055
3056 static cfg_type_t cfg_type_inetcontrol = {
3057 "inetcontrol", cfg_parse_tuple, cfg_print_tuple,
3058 cfg_doc_tuple, &cfg_rep_tuple, inetcontrol_fields
3059 };
3060
3061 static keyword_type_t controls_perm_kw = { "perm", &cfg_type_uint32 };
3062
3063 static cfg_type_t cfg_type_controls_perm = {
3064 "controls_perm", parse_keyvalue, print_keyvalue,
3065 doc_keyvalue, &cfg_rep_uint32, &controls_perm_kw
3066 };
3067
3068 static keyword_type_t controls_owner_kw = { "owner", &cfg_type_uint32 };
3069
3070 static cfg_type_t cfg_type_controls_owner = {
3071 "controls_owner", parse_keyvalue, print_keyvalue,
3072 doc_keyvalue, &cfg_rep_uint32, &controls_owner_kw
3073 };
3074
3075 static keyword_type_t controls_group_kw = { "group", &cfg_type_uint32 };
3076
3077 static cfg_type_t cfg_type_controls_group = {
3078 "controls_allow", parse_keyvalue, print_keyvalue,
3079 doc_keyvalue, &cfg_rep_uint32, &controls_group_kw
3080 };
3081
3082 static cfg_tuplefielddef_t unixcontrol_fields[] = {
3083 { "path", &cfg_type_qstring, 0 },
3084 { "perm", &cfg_type_controls_perm, 0 },
3085 { "owner", &cfg_type_controls_owner, 0 },
3086 { "group", &cfg_type_controls_group, 0 },
3087 { "keys", &cfg_type_controls_keys, 0 },
3088 { "read-only", &cfg_type_controls_readonly, 0 },
3089 { NULL, NULL, 0 }
3090 };
3091
3092 static cfg_type_t cfg_type_unixcontrol = {
3093 "unixcontrol", cfg_parse_tuple, cfg_print_tuple,
3094 cfg_doc_tuple, &cfg_rep_tuple, unixcontrol_fields
3095 };
3096
3097 static cfg_clausedef_t controls_clauses[] = {
3098 { "inet", &cfg_type_inetcontrol, CFG_CLAUSEFLAG_MULTI },
3099 { "unix", &cfg_type_unixcontrol, CFG_CLAUSEFLAG_MULTI },
3100 { NULL, NULL, 0 }
3101 };
3102
3103 static cfg_clausedef_t *controls_clausesets[] = { controls_clauses, NULL };
3104 static cfg_type_t cfg_type_controls = { "controls", cfg_parse_map,
3105 cfg_print_map, cfg_doc_map,
3106 &cfg_rep_map, &controls_clausesets };
3107
3108 /*%
3109 * A "statistics-channels" statement is represented as a map with the
3110 * multivalued "inet" clauses.
3111 */
3112 static void
3113 doc_optional_bracketed_list(cfg_printer_t *pctx, const cfg_type_t *type) {
3114 const keyword_type_t *kw = type->of;
3115 cfg_print_cstr(pctx, "[ ");
3116 cfg_print_cstr(pctx, kw->name);
3117 cfg_print_cstr(pctx, " ");
3118 cfg_doc_obj(pctx, kw->type);
3119 cfg_print_cstr(pctx, " ]");
3120 }
3121
3122 static cfg_type_t cfg_type_optional_allow = {
3123 "optional_allow", parse_optional_keyvalue,
3124 print_keyvalue, doc_optional_bracketed_list,
3125 &cfg_rep_list, &controls_allow_kw
3126 };
3127
3128 static cfg_tuplefielddef_t statserver_fields[] = {
3129 { "address", &cfg_type_controls_sockaddr, 0 }, /* reuse controls def */
3130 { "allow", &cfg_type_optional_allow, 0 },
3131 { NULL, NULL, 0 }
3132 };
3133
3134 static cfg_type_t cfg_type_statschannel = {
3135 "statschannel", cfg_parse_tuple, cfg_print_tuple,
3136 cfg_doc_tuple, &cfg_rep_tuple, statserver_fields
3137 };
3138
3139 static cfg_clausedef_t statservers_clauses[] = {
3140 { "inet", &cfg_type_statschannel, CFG_CLAUSEFLAG_MULTI },
3141 { NULL, NULL, 0 }
3142 };
3143
3144 static cfg_clausedef_t *statservers_clausesets[] = { statservers_clauses,
3145 NULL };
3146
3147 static cfg_type_t cfg_type_statschannels = {
3148 "statistics-channels", cfg_parse_map, cfg_print_map,
3149 cfg_doc_map, &cfg_rep_map, &statservers_clausesets
3150 };
3151
3152 /*%
3153 * An optional class, as used in view and zone statements.
3154 */
3155 static isc_result_t
3156 parse_optional_class(cfg_parser_t *pctx, const cfg_type_t *type,
3157 cfg_obj_t **ret) {
3158 isc_result_t result;
3159 UNUSED(type);
3160 CHECK(cfg_peektoken(pctx, 0));
3161 if (pctx->token.type == isc_tokentype_string) {
3162 CHECK(cfg_parse_obj(pctx, &cfg_type_ustring, ret));
3163 } else {
3164 CHECK(cfg_parse_obj(pctx, &cfg_type_void, ret));
3165 }
3166 cleanup:
3167 return (result);
3168 }
3169
3170 static void
3171 doc_optional_class(cfg_printer_t *pctx, const cfg_type_t *type) {
3172 UNUSED(type);
3173 cfg_print_cstr(pctx, "[ <class> ]");
3174 }
3175
3176 static cfg_type_t cfg_type_optional_class = { "optional_class",
3177 parse_optional_class,
3178 NULL,
3179 doc_optional_class,
3180 NULL,
3181 NULL };
3182
3183 static isc_result_t
3184 parse_querysource(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
3185 isc_result_t result;
3186 cfg_obj_t *obj = NULL;
3187 isc_netaddr_t netaddr;
3188 in_port_t port = 0;
3189 unsigned int have_address = 0;
3190 unsigned int have_port = 0;
3191 unsigned int have_dscp = 0;
3192 const unsigned int *flagp = type->of;
3193 int dscp = -1;
3194
3195 if ((*flagp & CFG_ADDR_V4OK) != 0) {
3196 isc_netaddr_any(&netaddr);
3197 } else if ((*flagp & CFG_ADDR_V6OK) != 0) {
3198 isc_netaddr_any6(&netaddr);
3199 } else {
3200 UNREACHABLE();
3201 }
3202
3203 for (;;) {
3204 CHECK(cfg_peektoken(pctx, 0));
3205 if (pctx->token.type == isc_tokentype_string) {
3206 if (strcasecmp(TOKEN_STRING(pctx), "address") == 0) {
3207 /* read "address" */
3208 CHECK(cfg_gettoken(pctx, 0));
3209 CHECK(cfg_parse_rawaddr(pctx, *flagp,
3210 &netaddr));
3211 have_address++;
3212 } else if (strcasecmp(TOKEN_STRING(pctx), "port") == 0)
3213 {
3214 /* read "port" */
3215 if ((pctx->flags & CFG_PCTX_NODEPRECATED) == 0)
3216 {
3217 cfg_parser_warning(
3218 pctx, 0,
3219 "token 'port' is deprecated");
3220 }
3221 CHECK(cfg_gettoken(pctx, 0));
3222 CHECK(cfg_parse_rawport(pctx, CFG_ADDR_WILDOK,
3223 &port));
3224 have_port++;
3225 } else if (strcasecmp(TOKEN_STRING(pctx), "dscp") == 0)
3226 {
3227 /* read "dscp" */
3228 cfg_parser_warning(pctx, 0,
3229 "'dscp' is obsolete and "
3230 "should be removed");
3231 CHECK(cfg_gettoken(pctx, 0));
3232 CHECK(cfg_parse_uint32(pctx, NULL, &obj));
3233 dscp = cfg_obj_asuint32(obj);
3234 cfg_obj_destroy(pctx, &obj);
3235 have_dscp++;
3236 } else if (have_port == 0 && have_dscp == 0 &&
3237 have_address == 0)
3238 {
3239 return (cfg_parse_sockaddr(pctx, type, ret));
3240 } else {
3241 cfg_parser_error(pctx, CFG_LOG_NEAR,
3242 "expected 'address' "
3243 "or 'port'");
3244 return (ISC_R_UNEXPECTEDTOKEN);
3245 }
3246 } else {
3247 break;
3248 }
3249 }
3250 if (have_address > 1 || have_port > 1 || have_address + have_port == 0)
3251 {
3252 cfg_parser_error(pctx, 0, "expected one address and/or port");
3253 return (ISC_R_UNEXPECTEDTOKEN);
3254 }
3255
3256 if (have_dscp > 1) {
3257 cfg_parser_error(pctx, 0, "expected at most one dscp");
3258 return (ISC_R_UNEXPECTEDTOKEN);
3259 }
3260
3261 CHECK(cfg_create_obj(pctx, &cfg_type_querysource, &obj));
3262 isc_sockaddr_fromnetaddr(&obj->value.sockaddr, &netaddr, port);
3263 obj->value.sockaddrdscp.dscp = dscp;
3264 *ret = obj;
3265 return (ISC_R_SUCCESS);
3266
3267 cleanup:
3268 cfg_parser_error(pctx, CFG_LOG_NEAR, "invalid query source");
3269 CLEANUP_OBJ(obj);
3270 return (result);
3271 }
3272
3273 static void
3274 print_querysource(cfg_printer_t *pctx, const cfg_obj_t *obj) {
3275 isc_netaddr_t na;
3276 isc_netaddr_fromsockaddr(&na, &obj->value.sockaddr);
3277 cfg_print_cstr(pctx, "address ");
3278 cfg_print_rawaddr(pctx, &na);
3279 cfg_print_cstr(pctx, " port ");
3280 cfg_print_rawuint(pctx, isc_sockaddr_getport(&obj->value.sockaddr));
3281 if (obj->value.sockaddrdscp.dscp != -1) {
3282 cfg_print_cstr(pctx, " dscp ");
3283 cfg_print_rawuint(pctx, obj->value.sockaddrdscp.dscp);
3284 }
3285 }
3286
3287 static void
3288 doc_querysource(cfg_printer_t *pctx, const cfg_type_t *type) {
3289 const unsigned int *flagp = type->of;
3290
3291 cfg_print_cstr(pctx, "[ address ] ( ");
3292 if ((*flagp & CFG_ADDR_V4OK) != 0) {
3293 cfg_print_cstr(pctx, "<ipv4_address>");
3294 } else if ((*flagp & CFG_ADDR_V6OK) != 0) {
3295 cfg_print_cstr(pctx, "<ipv6_address>");
3296 } else {
3297 UNREACHABLE();
3298 }
3299 cfg_print_cstr(pctx, " | * )");
3300 }
3301
3302 static unsigned int sockaddr4wild_flags = CFG_ADDR_WILDOK | CFG_ADDR_V4OK |
3303 CFG_ADDR_DSCPOK;
3304 static unsigned int sockaddr6wild_flags = CFG_ADDR_WILDOK | CFG_ADDR_V6OK |
3305 CFG_ADDR_DSCPOK;
3306
3307 static cfg_type_t cfg_type_querysource4 = {
3308 "querysource4", parse_querysource, NULL, doc_querysource,
3309 NULL, &sockaddr4wild_flags
3310 };
3311
3312 static cfg_type_t cfg_type_querysource6 = {
3313 "querysource6", parse_querysource, NULL, doc_querysource,
3314 NULL, &sockaddr6wild_flags
3315 };
3316
3317 static cfg_type_t cfg_type_querysource = { "querysource", NULL,
3318 print_querysource, NULL,
3319 &cfg_rep_sockaddr, NULL };
3320
3321 /*%
3322 * The socket address syntax in the "controls" statement is silly.
3323 * It allows both socket address families, but also allows "*",
3324 * which is gratuitously interpreted as the IPv4 wildcard address.
3325 */
3326 static unsigned int controls_sockaddr_flags = CFG_ADDR_V4OK | CFG_ADDR_V6OK |
3327 CFG_ADDR_WILDOK | CFG_ADDR_PORTOK;
3328 static cfg_type_t cfg_type_controls_sockaddr = {
3329 "controls_sockaddr", cfg_parse_sockaddr, cfg_print_sockaddr,
3330 cfg_doc_sockaddr, &cfg_rep_sockaddr, &controls_sockaddr_flags
3331 };
3332
3333 /*%
3334 * Handle the special kludge syntax of the "keys" clause in the "server"
3335 * statement, which takes a single key with or without braces and semicolon.
3336 */
3337 static isc_result_t
3338 parse_server_key_kludge(cfg_parser_t *pctx, const cfg_type_t *type,
3339 cfg_obj_t **ret) {
3340 isc_result_t result;
3341 bool braces = false;
3342 UNUSED(type);
3343
3344 /* Allow opening brace. */
3345 CHECK(cfg_peektoken(pctx, 0));
3346 if (pctx->token.type == isc_tokentype_special &&
3347 pctx->token.value.as_char == '{')
3348 {
3349 CHECK(cfg_gettoken(pctx, 0));
3350 braces = true;
3351 }
3352
3353 CHECK(cfg_parse_obj(pctx, &cfg_type_astring, ret));
3354
3355 if (braces) {
3356 /* Skip semicolon if present. */
3357 CHECK(cfg_peektoken(pctx, 0));
3358 if (pctx->token.type == isc_tokentype_special &&
3359 pctx->token.value.as_char == ';')
3360 {
3361 CHECK(cfg_gettoken(pctx, 0));
3362 }
3363
3364 CHECK(cfg_parse_special(pctx, '}'));
3365 }
3366 cleanup:
3367 return (result);
3368 }
3369 static cfg_type_t cfg_type_server_key_kludge = {
3370 "server_key", parse_server_key_kludge, NULL, cfg_doc_terminal, NULL,
3371 NULL
3372 };
3373
3374 /*%
3375 * An optional logging facility.
3376 */
3377
3378 static isc_result_t
3379 parse_optional_facility(cfg_parser_t *pctx, const cfg_type_t *type,
3380 cfg_obj_t **ret) {
3381 isc_result_t result;
3382 UNUSED(type);
3383
3384 CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
3385 if (pctx->token.type == isc_tokentype_string ||
3386 pctx->token.type == isc_tokentype_qstring)
3387 {
3388 CHECK(cfg_parse_obj(pctx, &cfg_type_astring, ret));
3389 } else {
3390 CHECK(cfg_parse_obj(pctx, &cfg_type_void, ret));
3391 }
3392 cleanup:
3393 return (result);
3394 }
3395
3396 static void
3397 doc_optional_facility(cfg_printer_t *pctx, const cfg_type_t *type) {
3398 UNUSED(type);
3399 cfg_print_cstr(pctx, "[ <syslog_facility> ]");
3400 }
3401
3402 static cfg_type_t cfg_type_optional_facility = { "optional_facility",
3403 parse_optional_facility,
3404 NULL,
3405 doc_optional_facility,
3406 NULL,
3407 NULL };
3408
3409 /*%
3410 * A log severity. Return as a string, except "debug N",
3411 * which is returned as a keyword object.
3412 */
3413
3414 static keyword_type_t debug_kw = { "debug", &cfg_type_uint32 };
3415 static cfg_type_t cfg_type_debuglevel = { "debuglevel", parse_keyvalue,
3416 print_keyvalue, doc_keyvalue,
3417 &cfg_rep_uint32, &debug_kw };
3418
3419 static isc_result_t
3420 parse_logseverity(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
3421 isc_result_t result;
3422 UNUSED(type);
3423
3424 CHECK(cfg_peektoken(pctx, 0));
3425 if (pctx->token.type == isc_tokentype_string &&
3426 strcasecmp(TOKEN_STRING(pctx), "debug") == 0)
3427 {
3428 CHECK(cfg_gettoken(pctx, 0)); /* read "debug" */
3429 CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER));
3430 if (pctx->token.type == isc_tokentype_number) {
3431 CHECK(cfg_parse_uint32(pctx, NULL, ret));
3432 } else {
3433 /*
3434 * The debug level is optional and defaults to 1.
3435 * This makes little sense, but we support it for
3436 * compatibility with BIND 8.
3437 */
3438 CHECK(cfg_create_obj(pctx, &cfg_type_uint32, ret));
3439 (*ret)->value.uint32 = 1;
3440 }
3441 (*ret)->type = &cfg_type_debuglevel; /* XXX kludge */
3442 } else {
3443 CHECK(cfg_parse_obj(pctx, &cfg_type_loglevel, ret));
3444 }
3445 cleanup:
3446 return (result);
3447 }
3448
3449 static cfg_type_t cfg_type_logseverity = { "log_severity", parse_logseverity,
3450 NULL, cfg_doc_terminal,
3451 NULL, NULL };
3452
3453 /*%
3454 * The "file" clause of the "channel" statement.
3455 * This is yet another special case.
3456 */
3457
3458 static const char *logversions_enums[] = { "unlimited", NULL };
3459 static isc_result_t
3460 parse_logversions(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
3461 return (cfg_parse_enum_or_other(pctx, type, &cfg_type_uint32, ret));
3462 }
3463
3464 static void
3465 doc_logversions(cfg_printer_t *pctx, const cfg_type_t *type) {
3466 cfg_doc_enum_or_other(pctx, type, &cfg_type_uint32);
3467 }
3468
3469 static cfg_type_t cfg_type_logversions = {
3470 "logversions", parse_logversions, cfg_print_ustring,
3471 doc_logversions, &cfg_rep_string, logversions_enums
3472 };
3473
3474 static const char *logsuffix_enums[] = { "increment", "timestamp", NULL };
3475 static cfg_type_t cfg_type_logsuffix = { "logsuffix", cfg_parse_enum,
3476 cfg_print_ustring, cfg_doc_enum,
3477 &cfg_rep_string, &logsuffix_enums };
3478
3479 static cfg_tuplefielddef_t logfile_fields[] = {
3480 { "file", &cfg_type_qstring, 0 },
3481 { "versions", &cfg_type_logversions, 0 },
3482 { "size", &cfg_type_size, 0 },
3483 { "suffix", &cfg_type_logsuffix, 0 },
3484 { NULL, NULL, 0 }
3485 };
3486
3487 static isc_result_t
3488 parse_logfile(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
3489 isc_result_t result;
3490 cfg_obj_t *obj = NULL;
3491 const cfg_tuplefielddef_t *fields = type->of;
3492
3493 CHECK(cfg_create_tuple(pctx, type, &obj));
3494
3495 /* Parse the mandatory "file" field */
3496 CHECK(cfg_parse_obj(pctx, fields[0].type, &obj->value.tuple[0]));
3497
3498 /* Parse "versions" and "size" fields in any order. */
3499 for (;;) {
3500 CHECK(cfg_peektoken(pctx, 0));
3501 if (pctx->token.type == isc_tokentype_string) {
3502 CHECK(cfg_gettoken(pctx, 0));
3503 if (strcasecmp(TOKEN_STRING(pctx), "versions") == 0 &&
3504 obj->value.tuple[1] == NULL)
3505 {
3506 CHECK(cfg_parse_obj(pctx, fields[1].type,
3507 &obj->value.tuple[1]));
3508 } else if (strcasecmp(TOKEN_STRING(pctx), "size") ==
3509 0 &&
3510 obj->value.tuple[2] == NULL)
3511 {
3512 CHECK(cfg_parse_obj(pctx, fields[2].type,
3513 &obj->value.tuple[2]));
3514 } else if (strcasecmp(TOKEN_STRING(pctx), "suffix") ==
3515 0 &&
3516 obj->value.tuple[3] == NULL)
3517 {
3518 CHECK(cfg_parse_obj(pctx, fields[3].type,
3519 &obj->value.tuple[3]));
3520 } else {
3521 break;
3522 }
3523 } else {
3524 break;
3525 }
3526 }
3527
3528 /* Create void objects for missing optional values. */
3529 if (obj->value.tuple[1] == NULL) {
3530 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[1]));
3531 }
3532 if (obj->value.tuple[2] == NULL) {
3533 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[2]));
3534 }
3535 if (obj->value.tuple[3] == NULL) {
3536 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[3]));
3537 }
3538
3539 *ret = obj;
3540 return (ISC_R_SUCCESS);
3541
3542 cleanup:
3543 CLEANUP_OBJ(obj);
3544 return (result);
3545 }
3546
3547 static void
3548 print_logfile(cfg_printer_t *pctx, const cfg_obj_t *obj) {
3549 cfg_print_obj(pctx, obj->value.tuple[0]); /* file */
3550 if (obj->value.tuple[1]->type->print != cfg_print_void) {
3551 cfg_print_cstr(pctx, " versions ");
3552 cfg_print_obj(pctx, obj->value.tuple[1]);
3553 }
3554 if (obj->value.tuple[2]->type->print != cfg_print_void) {
3555 cfg_print_cstr(pctx, " size ");
3556 cfg_print_obj(pctx, obj->value.tuple[2]);
3557 }
3558 if (obj->value.tuple[3]->type->print != cfg_print_void) {
3559 cfg_print_cstr(pctx, " suffix ");
3560 cfg_print_obj(pctx, obj->value.tuple[3]);
3561 }
3562 }
3563
3564 static void
3565 doc_logfile(cfg_printer_t *pctx, const cfg_type_t *type) {
3566 UNUSED(type);
3567 cfg_print_cstr(pctx, "<quoted_string>");
3568 cfg_print_cstr(pctx, " ");
3569 cfg_print_cstr(pctx, "[ versions ( unlimited | <integer> ) ]");
3570 cfg_print_cstr(pctx, " ");
3571 cfg_print_cstr(pctx, "[ size <size> ]");
3572 cfg_print_cstr(pctx, " ");
3573 cfg_print_cstr(pctx, "[ suffix ( increment | timestamp ) ]");
3574 }
3575
3576 static cfg_type_t cfg_type_logfile = { "log_file", parse_logfile,
3577 print_logfile, doc_logfile,
3578 &cfg_rep_tuple, logfile_fields };
3579
3580 /*% An IPv4 address, "*" accepted as wildcard. */
3581 static cfg_type_t cfg_type_sockaddr4wild = {
3582 "sockaddr4wild", cfg_parse_sockaddr, cfg_print_sockaddr,
3583 cfg_doc_sockaddr, &cfg_rep_sockaddr, &sockaddr4wild_flags
3584 };
3585
3586 /*% An IPv6 address, "*" accepted as wildcard. */
3587 static cfg_type_t cfg_type_sockaddr6wild = {
3588 "v6addrportwild", cfg_parse_sockaddr, cfg_print_sockaddr,
3589 cfg_doc_sockaddr, &cfg_rep_sockaddr, &sockaddr6wild_flags
3590 };
3591
3592 /*%
3593 * rndc
3594 */
3595
3596 static cfg_clausedef_t rndcconf_options_clauses[] = {
3597 { "default-key", &cfg_type_astring, 0 },
3598 { "default-port", &cfg_type_uint32, 0 },
3599 { "default-server", &cfg_type_astring, 0 },
3600 { "default-source-address", &cfg_type_netaddr4wild, 0 },
3601 { "default-source-address-v6", &cfg_type_netaddr6wild, 0 },
3602 { NULL, NULL, 0 }
3603 };
3604
3605 static cfg_clausedef_t *rndcconf_options_clausesets[] = {
3606 rndcconf_options_clauses, NULL
3607 };
3608
3609 static cfg_type_t cfg_type_rndcconf_options = {
3610 "rndcconf_options", cfg_parse_map, cfg_print_map,
3611 cfg_doc_map, &cfg_rep_map, rndcconf_options_clausesets
3612 };
3613
3614 static cfg_clausedef_t rndcconf_server_clauses[] = {
3615 { "key", &cfg_type_astring, 0 },
3616 { "port", &cfg_type_uint32, 0 },
3617 { "source-address", &cfg_type_netaddr4wild, 0 },
3618 { "source-address-v6", &cfg_type_netaddr6wild, 0 },
3619 { "addresses", &cfg_type_bracketed_sockaddrnameportlist, 0 },
3620 { NULL, NULL, 0 }
3621 };
3622
3623 static cfg_clausedef_t *rndcconf_server_clausesets[] = {
3624 rndcconf_server_clauses, NULL
3625 };
3626
3627 static cfg_type_t cfg_type_rndcconf_server = {
3628 "rndcconf_server", cfg_parse_named_map, cfg_print_map,
3629 cfg_doc_map, &cfg_rep_map, rndcconf_server_clausesets
3630 };
3631
3632 static cfg_clausedef_t rndcconf_clauses[] = {
3633 { "key", &cfg_type_key, CFG_CLAUSEFLAG_MULTI },
3634 { "server", &cfg_type_rndcconf_server, CFG_CLAUSEFLAG_MULTI },
3635 { "options", &cfg_type_rndcconf_options, 0 },
3636 { NULL, NULL, 0 }
3637 };
3638
3639 static cfg_clausedef_t *rndcconf_clausesets[] = { rndcconf_clauses, NULL };
3640
3641 cfg_type_t cfg_type_rndcconf = { "rndcconf", cfg_parse_mapbody,
3642 cfg_print_mapbody, cfg_doc_mapbody,
3643 &cfg_rep_map, rndcconf_clausesets };
3644
3645 static cfg_clausedef_t rndckey_clauses[] = { { "key", &cfg_type_key, 0 },
3646 { NULL, NULL, 0 } };
3647
3648 static cfg_clausedef_t *rndckey_clausesets[] = { rndckey_clauses, NULL };
3649
3650 cfg_type_t cfg_type_rndckey = { "rndckey", cfg_parse_mapbody,
3651 cfg_print_mapbody, cfg_doc_mapbody,
3652 &cfg_rep_map, rndckey_clausesets };
3653
3654 /*
3655 * session.key has exactly the same syntax as rndc.key, but it's defined
3656 * separately for clarity (and so we can extend it someday, if needed).
3657 */
3658 cfg_type_t cfg_type_sessionkey = { "sessionkey", cfg_parse_mapbody,
3659 cfg_print_mapbody, cfg_doc_mapbody,
3660 &cfg_rep_map, rndckey_clausesets };
3661
3662 static cfg_tuplefielddef_t nameport_fields[] = {
3663 { "name", &cfg_type_astring, 0 },
3664 { "port", &cfg_type_optional_port, 0 },
3665 { "dscp", &cfg_type_optional_dscp, CFG_CLAUSEFLAG_OBSOLETE },
3666 { NULL, NULL, 0 }
3667 };
3668
3669 static cfg_type_t cfg_type_nameport = { "nameport", cfg_parse_tuple,
3670 cfg_print_tuple, cfg_doc_tuple,
3671 &cfg_rep_tuple, nameport_fields };
3672
3673 static void
3674 doc_sockaddrnameport(cfg_printer_t *pctx, const cfg_type_t *type) {
3675 UNUSED(type);
3676 cfg_print_cstr(pctx, "( ");
3677 cfg_print_cstr(pctx, "<quoted_string>");
3678 cfg_print_cstr(pctx, " ");
3679 cfg_print_cstr(pctx, "[ port <integer> ]");
3680 cfg_print_cstr(pctx, " | ");
3681 cfg_print_cstr(pctx, "<ipv4_address>");
3682 cfg_print_cstr(pctx, " ");
3683 cfg_print_cstr(pctx, "[ port <integer> ]");
3684 cfg_print_cstr(pctx, " | ");
3685 cfg_print_cstr(pctx, "<ipv6_address>");
3686 cfg_print_cstr(pctx, " ");
3687 cfg_print_cstr(pctx, "[ port <integer> ]");
3688 cfg_print_cstr(pctx, " )");
3689 }
3690
3691 static isc_result_t
3692 parse_sockaddrnameport(cfg_parser_t *pctx, const cfg_type_t *type,
3693 cfg_obj_t **ret) {
3694 isc_result_t result;
3695 cfg_obj_t *obj = NULL;
3696 UNUSED(type);
3697
3698 CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
3699 if (pctx->token.type == isc_tokentype_string ||
3700 pctx->token.type == isc_tokentype_qstring)
3701 {
3702 if (cfg_lookingat_netaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V6OK))
3703 {
3704 CHECK(cfg_parse_sockaddr(pctx, &cfg_type_sockaddr,
3705 ret));
3706 } else {
3707 const cfg_tuplefielddef_t *fields =
3708 cfg_type_nameport.of;
3709 CHECK(cfg_create_tuple(pctx, &cfg_type_nameport, &obj));
3710 CHECK(cfg_parse_obj(pctx, fields[0].type,
3711 &obj->value.tuple[0]));
3712 CHECK(cfg_parse_obj(pctx, fields[1].type,
3713 &obj->value.tuple[1]));
3714 CHECK(cfg_parse_obj(pctx, fields[2].type,
3715 &obj->value.tuple[2]));
3716 *ret = obj;
3717 obj = NULL;
3718 }
3719 } else {
3720 cfg_parser_error(pctx, CFG_LOG_NEAR,
3721 "expected IP address or hostname");
3722 return (ISC_R_UNEXPECTEDTOKEN);
3723 }
3724 cleanup:
3725 CLEANUP_OBJ(obj);
3726 return (result);
3727 }
3728
3729 static cfg_type_t cfg_type_sockaddrnameport = { "sockaddrnameport_element",
3730 parse_sockaddrnameport,
3731 NULL,
3732 doc_sockaddrnameport,
3733 NULL,
3734 NULL };
3735
3736 static cfg_type_t cfg_type_bracketed_sockaddrnameportlist = {
3737 "bracketed_sockaddrnameportlist",
3738 cfg_parse_bracketed_list,
3739 cfg_print_bracketed_list,
3740 cfg_doc_bracketed_list,
3741 &cfg_rep_list,
3742 &cfg_type_sockaddrnameport
3743 };
3744
3745 /*%
3746 * A list of socket addresses or name with an optional default port,
3747 * as used in the dual-stack-servers option. E.g.,
3748 * "port 1234 { dual-stack-servers.net; 10.0.0.1; 1::2 port 69; }"
3749 */
3750 static cfg_tuplefielddef_t nameportiplist_fields[] = {
3751 { "port", &cfg_type_optional_port, 0 },
3752 { "addresses", &cfg_type_bracketed_sockaddrnameportlist, 0 },
3753 { NULL, NULL, 0 }
3754 };
3755
3756 static cfg_type_t cfg_type_nameportiplist = {
3757 "nameportiplist", cfg_parse_tuple, cfg_print_tuple,
3758 cfg_doc_tuple, &cfg_rep_tuple, nameportiplist_fields
3759 };
3760
3761 /*%
3762 * remote servers element.
3763 */
3764
3765 static void
3766 doc_remoteselement(cfg_printer_t *pctx, const cfg_type_t *type) {
3767 UNUSED(type);
3768 cfg_print_cstr(pctx, "( ");
3769 cfg_print_cstr(pctx, "<remote-servers>");
3770 cfg_print_cstr(pctx, " | ");
3771 cfg_print_cstr(pctx, "<ipv4_address>");
3772 cfg_print_cstr(pctx, " ");
3773 cfg_print_cstr(pctx, "[ port <integer> ]");
3774 cfg_print_cstr(pctx, " | ");
3775 cfg_print_cstr(pctx, "<ipv6_address>");
3776 cfg_print_cstr(pctx, " ");
3777 cfg_print_cstr(pctx, "[ port <integer> ]");
3778 cfg_print_cstr(pctx, " )");
3779 }
3780
3781 static isc_result_t
3782 parse_remoteselement(cfg_parser_t *pctx, const cfg_type_t *type,
3783 cfg_obj_t **ret) {
3784 isc_result_t result;
3785 cfg_obj_t *obj = NULL;
3786 UNUSED(type);
3787
3788 CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
3789 if (pctx->token.type == isc_tokentype_string ||
3790 pctx->token.type == isc_tokentype_qstring)
3791 {
3792 if (cfg_lookingat_netaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V6OK))
3793 {
3794 CHECK(cfg_parse_sockaddr(pctx, &cfg_type_sockaddr,
3795 ret));
3796 } else {
3797 CHECK(cfg_parse_astring(pctx, &cfg_type_astring, ret));
3798 }
3799 } else {
3800 cfg_parser_error(pctx, CFG_LOG_NEAR,
3801 "expected IP address or remote servers list "
3802 "name");
3803 return (ISC_R_UNEXPECTEDTOKEN);
3804 }
3805 cleanup:
3806 CLEANUP_OBJ(obj);
3807 return (result);
3808 }
3809
3810 static cfg_type_t cfg_type_remoteselement = { "remotes_element",
3811 parse_remoteselement,
3812 NULL,
3813 doc_remoteselement,
3814 NULL,
3815 NULL };
3816
3817 static int
3818 cmp_clause(const void *ap, const void *bp) {
3819 const cfg_clausedef_t *a = (const cfg_clausedef_t *)ap;
3820 const cfg_clausedef_t *b = (const cfg_clausedef_t *)bp;
3821 return (strcmp(a->name, b->name));
3822 }
3823
3824 bool
3825 cfg_clause_validforzone(const char *name, unsigned int ztype) {
3826 const cfg_clausedef_t *clause;
3827 bool valid = false;
3828
3829 for (clause = zone_clauses; clause->name != NULL; clause++) {
3830 if ((clause->flags & ztype) == 0 ||
3831 strcmp(clause->name, name) != 0)
3832 {
3833 continue;
3834 }
3835 valid = true;
3836 }
3837 for (clause = zone_only_clauses; clause->name != NULL; clause++) {
3838 if ((clause->flags & ztype) == 0 ||
3839 strcmp(clause->name, name) != 0)
3840 {
3841 continue;
3842 }
3843 valid = true;
3844 }
3845
3846 return (valid);
3847 }
3848
3849 void
3850 cfg_print_zonegrammar(const unsigned int zonetype, unsigned int flags,
3851 void (*f)(void *closure, const char *text, int textlen),
3852 void *closure) {
3853 #define NCLAUSES \
3854 (((sizeof(zone_clauses) + sizeof(zone_only_clauses)) / \
3855 sizeof(clause[0])) - \
3856 1)
3857
3858 cfg_printer_t pctx;
3859 cfg_clausedef_t *clause = NULL;
3860 cfg_clausedef_t clauses[NCLAUSES];
3861
3862 pctx.f = f;
3863 pctx.closure = closure;
3864 pctx.indent = 0;
3865 pctx.flags = flags;
3866
3867 memmove(clauses, zone_clauses, sizeof(zone_clauses));
3868 memmove(clauses + sizeof(zone_clauses) / sizeof(zone_clauses[0]) - 1,
3869 zone_only_clauses, sizeof(zone_only_clauses));
3870 qsort(clauses, NCLAUSES - 1, sizeof(clause[0]), cmp_clause);
3871
3872 cfg_print_cstr(&pctx, "zone <string> [ <class> ] {\n");
3873 pctx.indent++;
3874
3875 switch (zonetype) {
3876 case CFG_ZONE_PRIMARY:
3877 cfg_print_indent(&pctx);
3878 cfg_print_cstr(&pctx, "type primary;\n");
3879 break;
3880 case CFG_ZONE_SECONDARY:
3881 cfg_print_indent(&pctx);
3882 cfg_print_cstr(&pctx, "type secondary;\n");
3883 break;
3884 case CFG_ZONE_MIRROR:
3885 cfg_print_indent(&pctx);
3886 cfg_print_cstr(&pctx, "type mirror;\n");
3887 break;
3888 case CFG_ZONE_STUB:
3889 cfg_print_indent(&pctx);
3890 cfg_print_cstr(&pctx, "type stub;\n");
3891 break;
3892 case CFG_ZONE_HINT:
3893 cfg_print_indent(&pctx);
3894 cfg_print_cstr(&pctx, "type hint;\n");
3895 break;
3896 case CFG_ZONE_FORWARD:
3897 cfg_print_indent(&pctx);
3898 cfg_print_cstr(&pctx, "type forward;\n");
3899 break;
3900 case CFG_ZONE_STATICSTUB:
3901 cfg_print_indent(&pctx);
3902 cfg_print_cstr(&pctx, "type static-stub;\n");
3903 break;
3904 case CFG_ZONE_REDIRECT:
3905 cfg_print_indent(&pctx);
3906 cfg_print_cstr(&pctx, "type redirect;\n");
3907 break;
3908 case CFG_ZONE_DELEGATION:
3909 cfg_print_indent(&pctx);
3910 cfg_print_cstr(&pctx, "type delegation-only;\n");
3911 break;
3912 case CFG_ZONE_INVIEW:
3913 /* no zone type is specified for these */
3914 break;
3915 default:
3916 UNREACHABLE();
3917 }
3918
3919 for (clause = clauses; clause->name != NULL; clause++) {
3920 if (((pctx.flags & CFG_PRINTER_ACTIVEONLY) != 0) &&
3921 (((clause->flags & CFG_CLAUSEFLAG_OBSOLETE) != 0) ||
3922 ((clause->flags & CFG_CLAUSEFLAG_TESTONLY) != 0)))
3923 {
3924 continue;
3925 }
3926 if ((clause->flags & CFG_CLAUSEFLAG_ANCIENT) != 0 ||
3927 (clause->flags & CFG_CLAUSEFLAG_NODOC) != 0)
3928 {
3929 continue;
3930 }
3931
3932 if ((clause->flags & zonetype) == 0 ||
3933 strcasecmp(clause->name, "type") == 0)
3934 {
3935 continue;
3936 }
3937 cfg_print_indent(&pctx);
3938 cfg_print_cstr(&pctx, clause->name);
3939 cfg_print_cstr(&pctx, " ");
3940 cfg_doc_obj(&pctx, clause->type);
3941 cfg_print_cstr(&pctx, ";");
3942 cfg_print_clauseflags(&pctx, clause->flags);
3943 cfg_print_cstr(&pctx, "\n");
3944 }
3945
3946 pctx.indent--;
3947 cfg_print_cstr(&pctx, "};\n");
3948 }
3949
3950 /*%
3951 * "tls" and related statement syntax.
3952 */
3953 static cfg_type_t cfg_type_tlsprotos = { "tls_protocols",
3954 cfg_parse_bracketed_list,
3955 cfg_print_bracketed_list,
3956 cfg_doc_bracketed_list,
3957 &cfg_rep_list,
3958 &cfg_type_astring };
3959
3960 static cfg_clausedef_t tls_clauses[] = {
3961 { "key-file", &cfg_type_qstring, 0 },
3962 { "cert-file", &cfg_type_qstring, 0 },
3963 { "ca-file", &cfg_type_qstring, 0 },
3964 { "remote-hostname", &cfg_type_qstring, 0 },
3965 { "dhparam-file", &cfg_type_qstring, 0 },
3966 { "protocols", &cfg_type_tlsprotos, 0 },
3967 { "ciphers", &cfg_type_astring, 0 },
3968 { "prefer-server-ciphers", &cfg_type_boolean, 0 },
3969 { "session-tickets", &cfg_type_boolean, 0 },
3970 { NULL, NULL, 0 }
3971 };
3972
3973 static cfg_clausedef_t *tls_clausesets[] = { tls_clauses, NULL };
3974 static cfg_type_t cfg_type_tlsconf = { "tlsconf", cfg_parse_named_map,
3975 cfg_print_map, cfg_doc_map,
3976 &cfg_rep_map, tls_clausesets };
3977
3978 static keyword_type_t tls_kw = { "tls", &cfg_type_astring };
3979 static cfg_type_t cfg_type_optional_tls = {
3980 "tlsoptional", parse_optional_keyvalue, print_keyvalue,
3981 doc_optional_keyvalue, &cfg_rep_string, &tls_kw
3982 };
3983
3984 /* http and https */
3985
3986 static cfg_type_t cfg_type_bracketed_http_endpoint_list = {
3987 "bracketed_http_endpoint_list",
3988 cfg_parse_bracketed_list,
3989 cfg_print_bracketed_list,
3990 cfg_doc_bracketed_list,
3991 &cfg_rep_list,
3992 &cfg_type_qstring
3993 };
3994
3995 static cfg_clausedef_t cfg_http_description_clauses[] = {
3996 { "endpoints", &cfg_type_bracketed_http_endpoint_list, 0 },
3997 { "listener-clients", &cfg_type_uint32, 0 },
3998 { "streams-per-connection", &cfg_type_uint32, 0 },
3999 { NULL, NULL, 0 }
4000 };
4001
4002 static cfg_clausedef_t *http_description_clausesets[] = {
4003 cfg_http_description_clauses, NULL
4004 };
4005
4006 static cfg_type_t cfg_type_http_description = {
4007 "http_desc", cfg_parse_named_map, cfg_print_map,
4008 cfg_doc_map, &cfg_rep_map, http_description_clausesets
4009 };
4010