162ac0c33Sjakob /*
262ac0c33Sjakob * options.h -- nsd.conf options definitions and prototypes
362ac0c33Sjakob *
4d3fecca9Ssthen * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
562ac0c33Sjakob *
662ac0c33Sjakob * See LICENSE for the license.
762ac0c33Sjakob *
862ac0c33Sjakob */
962ac0c33Sjakob
1062ac0c33Sjakob #ifndef OPTIONS_H
1162ac0c33Sjakob #define OPTIONS_H
1262ac0c33Sjakob
1362ac0c33Sjakob #include <stdarg.h>
1462ac0c33Sjakob #include "region-allocator.h"
1562ac0c33Sjakob #include "rbtree.h"
1662ac0c33Sjakob struct query;
1762ac0c33Sjakob struct dname;
1862ac0c33Sjakob struct tsig_key;
19d3fecca9Ssthen struct buffer;
20cdb6bbddSbrad struct nsd;
21b71395eaSflorian struct proxy_protocol_port_list;
2262ac0c33Sjakob
23*bf87c3c0Sflorian
24fe5fe5f6Sflorian typedef struct nsd_options nsd_options_type;
25fe5fe5f6Sflorian typedef struct pattern_options pattern_options_type;
26fe5fe5f6Sflorian typedef struct zone_options zone_options_type;
27308d2509Sflorian typedef struct range_option range_option_type;
28fe5fe5f6Sflorian typedef struct ip_address_option ip_address_option_type;
29308d2509Sflorian typedef struct cpu_option cpu_option_type;
30308d2509Sflorian typedef struct cpu_map_option cpu_map_option_type;
31fe5fe5f6Sflorian typedef struct acl_options acl_options_type;
32fe5fe5f6Sflorian typedef struct key_options key_options_type;
33063644e9Sflorian typedef struct tls_auth_options tls_auth_options_type;
34fe5fe5f6Sflorian typedef struct config_parser_state config_parser_state_type;
35308d2509Sflorian
363f21e8ccSflorian #define VERIFY_ZONE_INHERIT (2)
373f21e8ccSflorian #define VERIFIER_FEED_ZONE_INHERIT (2)
383f21e8ccSflorian #define VERIFIER_TIMEOUT_INHERIT (-1)
39*bf87c3c0Sflorian #define CATALOG_ROLE_INHERIT (0)
40*bf87c3c0Sflorian #define CATALOG_ROLE_CONSUMER (1)
41*bf87c3c0Sflorian #define CATALOG_ROLE_PRODUCER (2)
423f21e8ccSflorian
4362ac0c33Sjakob /*
4462ac0c33Sjakob * Options global for nsd.
4562ac0c33Sjakob */
4662ac0c33Sjakob struct nsd_options {
47d3fecca9Ssthen /* config file name */
48d3fecca9Ssthen char* configfile;
49fe5fe5f6Sflorian /* options for zones, by apex, contains zone_options */
50fe5fe5f6Sflorian rbtree_type* zone_options;
51fe5fe5f6Sflorian /* patterns, by name, contains pattern_options */
52fe5fe5f6Sflorian rbtree_type* patterns;
5362ac0c33Sjakob
54d3fecca9Ssthen /* free space in zonelist file, contains zonelist_bucket */
55fe5fe5f6Sflorian rbtree_type* zonefree;
56d3fecca9Ssthen /* number of free space lines in zonelist file */
57d3fecca9Ssthen size_t zonefree_number;
58d3fecca9Ssthen /* zonelist file if open */
59d3fecca9Ssthen FILE* zonelist;
60d3fecca9Ssthen /* last offset in file (or 0 if none) */
61d3fecca9Ssthen off_t zonelist_off;
62d3fecca9Ssthen
639e506f0aSbrad /* tree of zonestat names and their id values, entries are struct
649e506f0aSbrad * zonestatname with malloced key=stringname. The number of items
659e506f0aSbrad * is the max statnameid, no items are freed from this.
669e506f0aSbrad * kept correct in the xfrd process, and on startup. */
67fe5fe5f6Sflorian rbtree_type* zonestatnames;
689e506f0aSbrad
69d3fecca9Ssthen /* rbtree of keys defined, by name */
70fe5fe5f6Sflorian rbtree_type* keys;
7162ac0c33Sjakob
72063644e9Sflorian /* rbtree of tls_auth defined, by name */
73063644e9Sflorian rbtree_type* tls_auths;
74063644e9Sflorian
752fd875a4Ssthen /* list of ip addresses to bind to (or NULL for all) */
76fe5fe5f6Sflorian struct ip_address_option* ip_addresses;
7762ac0c33Sjakob
7812455795Ssthen int ip_transparent;
79275a8d89Sflorian int ip_freebind;
80eab1363eSsthen int send_buffer_size;
81eab1363eSsthen int receive_buffer_size;
8262ac0c33Sjakob int debug_mode;
8362ac0c33Sjakob int verbosity;
8462ac0c33Sjakob int hide_version;
85eab1363eSsthen int hide_identity;
86308d2509Sflorian int drop_updates;
87d3fecca9Ssthen int do_ip4;
88d3fecca9Ssthen int do_ip6;
8962ac0c33Sjakob const char* identity;
903126abd5Ssthen const char* version;
9162ac0c33Sjakob const char* logfile;
92ac5517e4Sflorian int log_only_syslog;
9362ac0c33Sjakob int server_count;
94308d2509Sflorian struct cpu_option* cpu_affinity;
95308d2509Sflorian struct cpu_map_option* service_cpu_affinity;
9662ac0c33Sjakob int tcp_count;
97eab1363eSsthen int tcp_reject_overflow;
985435475dSsthen int confine_to_zone;
9962ac0c33Sjakob int tcp_query_count;
10062ac0c33Sjakob int tcp_timeout;
101275a8d89Sflorian int tcp_mss;
102275a8d89Sflorian int outgoing_tcp_mss;
10362ac0c33Sjakob size_t ipv4_edns_size;
10462ac0c33Sjakob size_t ipv6_edns_size;
10562ac0c33Sjakob const char* pidfile;
10662ac0c33Sjakob const char* port;
10762ac0c33Sjakob int statistics;
10862ac0c33Sjakob const char* chroot;
10962ac0c33Sjakob const char* username;
11062ac0c33Sjakob const char* zonesdir;
11162ac0c33Sjakob const char* xfrdfile;
112d3fecca9Ssthen const char* xfrdir;
113d3fecca9Ssthen const char* zonelistfile;
114a8b34139Sjakob const char* nsid;
11562ac0c33Sjakob int xfrd_reload_timeout;
116d3fecca9Ssthen int zonefiles_check;
11715ed76cbSbrad int zonefiles_write;
11815ed76cbSbrad int log_time_ascii;
11915ed76cbSbrad int round_robin;
120db7d0d02Sflorian int minimal_responses;
121bfd0b123Sflorian int refuse_any;
122a65f413bSsthen int reuseport;
123bc6311d7Sflorian /* max number of xfrd tcp sockets */
124bc6311d7Sflorian int xfrd_tcp_max;
125bc6311d7Sflorian /* max number of simultaneous requests on xfrd tcp socket */
126bc6311d7Sflorian int xfrd_tcp_pipeline;
127d3fecca9Ssthen
128eab1363eSsthen /* private key file for TLS */
129eab1363eSsthen char* tls_service_key;
130eab1363eSsthen /* ocsp stapling file for TLS */
131eab1363eSsthen char* tls_service_ocsp;
132eab1363eSsthen /* certificate file for TLS */
133eab1363eSsthen char* tls_service_pem;
134eab1363eSsthen /* TLS dedicated port */
135eab1363eSsthen const char* tls_port;
136063644e9Sflorian /* TLS certificate bundle */
137063644e9Sflorian const char* tls_cert_bundle;
138eab1363eSsthen
139b71395eaSflorian /* proxy protocol port list */
140b71395eaSflorian struct proxy_protocol_port_list* proxy_protocol_port;
141b71395eaSflorian
142d3fecca9Ssthen /** remote control section. enable toggle. */
143d3fecca9Ssthen int control_enable;
144d3fecca9Ssthen /** the interfaces the remote control should listen on */
145fe5fe5f6Sflorian struct ip_address_option* control_interface;
146d3fecca9Ssthen /** port number for the control port */
147d3fecca9Ssthen int control_port;
148d3fecca9Ssthen /** private key file for server */
149d3fecca9Ssthen char* server_key_file;
150d3fecca9Ssthen /** certificate file for server */
151d3fecca9Ssthen char* server_cert_file;
152d3fecca9Ssthen /** private key file for nsd-control */
153d3fecca9Ssthen char* control_key_file;
154d3fecca9Ssthen /** certificate file for nsd-control */
155d3fecca9Ssthen char* control_cert_file;
15662ac0c33Sjakob
1572c1ae072Ssthen #ifdef RATELIMIT
1582c1ae072Ssthen /** number of buckets in rrl hashtable */
1592c1ae072Ssthen size_t rrl_size;
1602c1ae072Ssthen /** max qps for queries, 0 is nolimit */
1612c1ae072Ssthen size_t rrl_ratelimit;
16212455795Ssthen /** ratio of slipped responses, 0 is noslip */
16312455795Ssthen size_t rrl_slip;
16412455795Ssthen /** ip prefix length */
16512455795Ssthen size_t rrl_ipv4_prefix_length;
16612455795Ssthen size_t rrl_ipv6_prefix_length;
1672c1ae072Ssthen /** max qps for whitelisted queries, 0 is nolimit */
1682c1ae072Ssthen size_t rrl_whitelist_ratelimit;
1692c1ae072Ssthen #endif
170e02bc0dfSflorian /** if dnstap is enabled */
171e02bc0dfSflorian int dnstap_enable;
172e02bc0dfSflorian /** dnstap socket path */
173e02bc0dfSflorian char* dnstap_socket_path;
1743efee2e1Sflorian /** dnstap IP, if "", it uses socket path. */
1753efee2e1Sflorian char* dnstap_ip;
1763efee2e1Sflorian /** dnstap TLS enable */
1773efee2e1Sflorian int dnstap_tls;
1783efee2e1Sflorian /** dnstap tls server authentication name */
1793efee2e1Sflorian char* dnstap_tls_server_name;
1803efee2e1Sflorian /** dnstap server cert bundle */
1813efee2e1Sflorian char* dnstap_tls_cert_bundle;
1823efee2e1Sflorian /** dnstap client key for client authentication */
1833efee2e1Sflorian char* dnstap_tls_client_key_file;
1843efee2e1Sflorian /** dnstap client cert for client authentication */
1853efee2e1Sflorian char* dnstap_tls_client_cert_file;
186e02bc0dfSflorian /** true to send "identity" via dnstap */
187e02bc0dfSflorian int dnstap_send_identity;
188e02bc0dfSflorian /** true to send "version" via dnstap */
189e02bc0dfSflorian int dnstap_send_version;
190e02bc0dfSflorian /** dnstap "identity", hostname is used if "". */
191e02bc0dfSflorian char* dnstap_identity;
192e02bc0dfSflorian /** dnstap "version", package version is used if "". */
193e02bc0dfSflorian char* dnstap_version;
194e02bc0dfSflorian /** true to log dnstap AUTH_QUERY message events */
195e02bc0dfSflorian int dnstap_log_auth_query_messages;
196e02bc0dfSflorian /** true to log dnstap AUTH_RESPONSE message events */
197e02bc0dfSflorian int dnstap_log_auth_response_messages;
1982c1ae072Ssthen
199063644e9Sflorian /** do answer with server cookie when request contained cookie option */
200063644e9Sflorian int answer_cookie;
201063644e9Sflorian /** cookie secret */
202063644e9Sflorian char *cookie_secret;
203063644e9Sflorian /** path to cookie secret store */
204063644e9Sflorian char const* cookie_secret_file;
2053f21e8ccSflorian /** enable verify */
2063f21e8ccSflorian int verify_enable;
2073f21e8ccSflorian /** list of ip addresses used to serve zones for verification */
2083f21e8ccSflorian struct ip_address_option* verify_ip_addresses;
2093f21e8ccSflorian /** default port 5347 */
2103f21e8ccSflorian char *verify_port;
2113f21e8ccSflorian /** verify zones by default */
2123f21e8ccSflorian int verify_zones;
2133f21e8ccSflorian /** default command to verify zones with */
2143f21e8ccSflorian char **verifier;
2153f21e8ccSflorian /** maximum number of verifiers that may run simultaneously */
2163f21e8ccSflorian int verifier_count;
2173f21e8ccSflorian /** whether or not to feed the zone to the verifier over stdin */
2183f21e8ccSflorian uint8_t verifier_feed_zone;
2193f21e8ccSflorian /** maximum number of seconds that a verifier may take */
2203f21e8ccSflorian uint32_t verifier_timeout;
221063644e9Sflorian
22262ac0c33Sjakob region_type* region;
22362ac0c33Sjakob };
22462ac0c33Sjakob
225308d2509Sflorian struct range_option {
226308d2509Sflorian struct range_option* next;
227308d2509Sflorian int first;
228308d2509Sflorian int last;
229308d2509Sflorian };
230308d2509Sflorian
231fe5fe5f6Sflorian struct ip_address_option {
232fe5fe5f6Sflorian struct ip_address_option* next;
23362ac0c33Sjakob char* address;
234308d2509Sflorian struct range_option* servers;
235308d2509Sflorian int dev;
236308d2509Sflorian int fib;
237308d2509Sflorian };
238308d2509Sflorian
239308d2509Sflorian struct cpu_option {
240308d2509Sflorian struct cpu_option* next;
241308d2509Sflorian int cpu;
242308d2509Sflorian };
243308d2509Sflorian
244308d2509Sflorian struct cpu_map_option {
245308d2509Sflorian struct cpu_map_option* next;
246308d2509Sflorian int service;
247308d2509Sflorian int cpu;
24862ac0c33Sjakob };
24962ac0c33Sjakob
25062ac0c33Sjakob /*
251ac5517e4Sflorian * Defines for min_expire_time_expr value
252ac5517e4Sflorian */
253ac5517e4Sflorian #define EXPIRE_TIME_HAS_VALUE 0
254ac5517e4Sflorian #define EXPIRE_TIME_IS_DEFAULT 1
255ac5517e4Sflorian #define REFRESHPLUSRETRYPLUS1 2
256ac5517e4Sflorian #define REFRESHPLUSRETRYPLUS1_STR "refresh+retry+1"
257ac5517e4Sflorian #define expire_time_is_default(x) (!( (x) == REFRESHPLUSRETRYPLUS1 \
258ac5517e4Sflorian || (x) == EXPIRE_TIME_HAS_VALUE ))
259ac5517e4Sflorian
260ac5517e4Sflorian
261ac5517e4Sflorian /*
262d3fecca9Ssthen * Pattern of zone options, used to contain options for zone(s).
26362ac0c33Sjakob */
264d3fecca9Ssthen struct pattern_options {
265fe5fe5f6Sflorian rbnode_type node;
266d3fecca9Ssthen const char* pname; /* name of the pattern, key of rbtree */
26762ac0c33Sjakob const char* zonefile;
268fe5fe5f6Sflorian struct acl_options* allow_notify;
269fe5fe5f6Sflorian struct acl_options* request_xfr;
270fe5fe5f6Sflorian struct acl_options* notify;
271fe5fe5f6Sflorian struct acl_options* provide_xfr;
2728d298c9fSsthen struct acl_options* allow_query;
273fe5fe5f6Sflorian struct acl_options* outgoing_interface;
2749e506f0aSbrad const char* zonestats;
2752c1ae072Ssthen #ifdef RATELIMIT
2762c1ae072Ssthen uint16_t rrl_whitelist; /* bitmap with rrl types */
2772c1ae072Ssthen #endif
27862ac0c33Sjakob uint8_t allow_axfr_fallback;
279d3fecca9Ssthen uint8_t allow_axfr_fallback_is_default;
28062ac0c33Sjakob uint8_t notify_retry;
281d3fecca9Ssthen uint8_t notify_retry_is_default;
282d3fecca9Ssthen uint8_t implicit; /* pattern is implicit, part_of_config zone used */
283d3fecca9Ssthen uint8_t xfrd_flags;
2846e9bf1eeSflorian uint32_t max_refresh_time;
2856e9bf1eeSflorian uint8_t max_refresh_time_is_default;
2866e9bf1eeSflorian uint32_t min_refresh_time;
2876e9bf1eeSflorian uint8_t min_refresh_time_is_default;
2886e9bf1eeSflorian uint32_t max_retry_time;
2896e9bf1eeSflorian uint8_t max_retry_time_is_default;
2906e9bf1eeSflorian uint32_t min_retry_time;
2916e9bf1eeSflorian uint8_t min_retry_time_is_default;
292ac5517e4Sflorian uint32_t min_expire_time;
293ac5517e4Sflorian /* min_expir_time_expr is either a known value (REFRESHPLUSRETRYPLUS1
294ac5517e4Sflorian * or EXPIRE_EXPR_HAS_VALUE) or else min_expire_time is the default.
295ac5517e4Sflorian * This can be tested with expire_time_is_default(x) define.
296ac5517e4Sflorian */
297ac5517e4Sflorian uint8_t min_expire_time_expr;
2986e9bf1eeSflorian uint64_t size_limit_xfr;
299*bf87c3c0Sflorian uint8_t multi_primary_check;
3004564029fSflorian uint8_t store_ixfr;
3014564029fSflorian uint8_t store_ixfr_is_default;
3024564029fSflorian uint64_t ixfr_size;
3034564029fSflorian uint8_t ixfr_size_is_default;
3044564029fSflorian uint32_t ixfr_number;
3054564029fSflorian uint8_t ixfr_number_is_default;
3064564029fSflorian uint8_t create_ixfr;
3074564029fSflorian uint8_t create_ixfr_is_default;
3083f21e8ccSflorian uint8_t verify_zone;
3093f21e8ccSflorian uint8_t verify_zone_is_default;
3103f21e8ccSflorian char **verifier;
3113f21e8ccSflorian uint8_t verifier_feed_zone;
3123f21e8ccSflorian uint8_t verifier_feed_zone_is_default;
3133f21e8ccSflorian int32_t verifier_timeout;
3143f21e8ccSflorian uint8_t verifier_timeout_is_default;
315*bf87c3c0Sflorian uint8_t catalog_role;
316*bf87c3c0Sflorian uint8_t catalog_role_is_default;
317*bf87c3c0Sflorian const char* catalog_member_pattern;
318*bf87c3c0Sflorian const char* catalog_producer_zone;
319ee5153b7Sflorian } ATTR_PACKED;
320d3fecca9Ssthen
321d3fecca9Ssthen #define PATTERN_IMPLICIT_MARKER "_implicit_"
322d3fecca9Ssthen
323d3fecca9Ssthen /*
324d3fecca9Ssthen * Options for a zone
325d3fecca9Ssthen */
326d3fecca9Ssthen struct zone_options {
327d3fecca9Ssthen /* key is dname of apex */
328fe5fe5f6Sflorian rbnode_type node;
329d3fecca9Ssthen
330d3fecca9Ssthen /* is apex of the zone */
331d3fecca9Ssthen const char* name;
332d3fecca9Ssthen /* if not part of config, the offset and linesize of zonelist entry */
333d3fecca9Ssthen off_t off;
334d3fecca9Ssthen int linesize;
335d3fecca9Ssthen /* pattern for the zone options, if zone is part_of_config, this is
336d3fecca9Ssthen * a anonymous pattern created in-place */
337fe5fe5f6Sflorian struct pattern_options* pattern;
338d3fecca9Ssthen /* zone is fixed into the main config, not in zonelist, cannot delete */
339*bf87c3c0Sflorian unsigned part_of_config : 1;
340*bf87c3c0Sflorian unsigned is_catalog_member_zone: 1;
341ee5153b7Sflorian } ATTR_PACKED;
34262ac0c33Sjakob
343*bf87c3c0Sflorian /*
344*bf87c3c0Sflorian * Options for catalog member zones
345*bf87c3c0Sflorian * assert(options->is_catalog_member_zone == 1)
346*bf87c3c0Sflorian * when options->pattern->catalog_producer_zone is set, this is a
347*bf87c3c0Sflorian * producer member zone, otherwise a consumer member zone.
348*bf87c3c0Sflorian * A catalog member zone is either a member zone of a catalog producer zone
349*bf87c3c0Sflorian * or a catalog consumer zone. They are mutually exclusive.
350*bf87c3c0Sflorian */
351*bf87c3c0Sflorian struct catalog_member_zone {
352*bf87c3c0Sflorian struct zone_options options;
353*bf87c3c0Sflorian const struct dname* member_id;
354*bf87c3c0Sflorian /* node in the associated catalog consumer or producer zone */
355*bf87c3c0Sflorian rbnode_type node;
356*bf87c3c0Sflorian } ATTR_PACKED;
357*bf87c3c0Sflorian
358*bf87c3c0Sflorian typedef void (*new_member_id_type)(struct catalog_member_zone* zone);
359*bf87c3c0Sflorian
36062ac0c33Sjakob union acl_addr_storage {
36162ac0c33Sjakob #ifdef INET6
36262ac0c33Sjakob struct in_addr addr;
36362ac0c33Sjakob struct in6_addr addr6;
36462ac0c33Sjakob #else
36562ac0c33Sjakob struct in_addr addr;
36662ac0c33Sjakob #endif
36762ac0c33Sjakob };
36862ac0c33Sjakob
36962ac0c33Sjakob /*
37062ac0c33Sjakob * Access control list element
37162ac0c33Sjakob */
37262ac0c33Sjakob struct acl_options {
373fe5fe5f6Sflorian struct acl_options* next;
37462ac0c33Sjakob
37562ac0c33Sjakob /* options */
37662ac0c33Sjakob time_t ixfr_disabled;
37712455795Ssthen int bad_xfr_count;
378d3fecca9Ssthen uint8_t use_axfr_only;
379d3fecca9Ssthen uint8_t allow_udp;
38062ac0c33Sjakob
38162ac0c33Sjakob /* ip address range */
38262ac0c33Sjakob const char* ip_address_spec;
38362ac0c33Sjakob uint8_t is_ipv6;
38462ac0c33Sjakob unsigned int port; /* is 0(no port) or suffix @port value */
38562ac0c33Sjakob union acl_addr_storage addr;
38662ac0c33Sjakob union acl_addr_storage range_mask;
38762ac0c33Sjakob enum {
3882fd875a4Ssthen acl_range_single = 0, /* single address */
38962ac0c33Sjakob acl_range_mask = 1, /* 10.20.30.40&255.255.255.0 */
39062ac0c33Sjakob acl_range_subnet = 2, /* 10.20.30.40/28 */
39162ac0c33Sjakob acl_range_minmax = 3 /* 10.20.30.40-10.20.30.60 (mask=max) */
39262ac0c33Sjakob } rangetype;
39362ac0c33Sjakob
39462ac0c33Sjakob /* key */
39562ac0c33Sjakob uint8_t nokey;
39662ac0c33Sjakob uint8_t blocked;
39762ac0c33Sjakob const char* key_name;
398fe5fe5f6Sflorian struct key_options* key_options;
399063644e9Sflorian
400063644e9Sflorian /* tls_auth for XoT */
401063644e9Sflorian const char* tls_auth_name;
402063644e9Sflorian struct tls_auth_options* tls_auth_options;
403ee5153b7Sflorian } ATTR_PACKED;
40462ac0c33Sjakob
40562ac0c33Sjakob /*
40662ac0c33Sjakob * Key definition
40762ac0c33Sjakob */
40862ac0c33Sjakob struct key_options {
409fe5fe5f6Sflorian rbnode_type node; /* key of tree is name */
410d3fecca9Ssthen char* name;
411d3fecca9Ssthen char* algorithm;
412d3fecca9Ssthen char* secret;
41362ac0c33Sjakob struct tsig_key* tsig_key;
414ee5153b7Sflorian } ATTR_PACKED;
41562ac0c33Sjakob
416063644e9Sflorian /*
417063644e9Sflorian * TLS Auth definition for XoT
418063644e9Sflorian */
419063644e9Sflorian struct tls_auth_options {
420063644e9Sflorian rbnode_type node; /* key of tree is name */
421063644e9Sflorian char* name;
422063644e9Sflorian char* auth_domain_name;
423a904e103Sflorian char* client_cert;
424a904e103Sflorian char* client_key;
425a904e103Sflorian char* client_key_pw;
426063644e9Sflorian };
427063644e9Sflorian
428b71395eaSflorian /* proxy protocol port option list */
429b71395eaSflorian struct proxy_protocol_port_list {
430b71395eaSflorian struct proxy_protocol_port_list* next;
431b71395eaSflorian int port;
432b71395eaSflorian };
433b71395eaSflorian
434d3fecca9Ssthen /** zone list free space */
435d3fecca9Ssthen struct zonelist_free {
436d3fecca9Ssthen struct zonelist_free* next;
437d3fecca9Ssthen off_t off;
438d3fecca9Ssthen };
439d3fecca9Ssthen /** zonelist free bucket for a particular line length */
440d3fecca9Ssthen struct zonelist_bucket {
441fe5fe5f6Sflorian rbnode_type node; /* key is ptr to linesize */
442d3fecca9Ssthen int linesize;
443d3fecca9Ssthen struct zonelist_free* list;
444d3fecca9Ssthen };
445d3fecca9Ssthen
44615ed76cbSbrad /* default zonefile write interval if database is "", in seconds */
44715ed76cbSbrad #define ZONEFILES_WRITE_INTERVAL 3600
44815ed76cbSbrad
4499e506f0aSbrad struct zonestatname {
450fe5fe5f6Sflorian rbnode_type node; /* key is malloced string with cooked zonestat name */
4519e506f0aSbrad unsigned id; /* index in nsd.zonestat array */
4529e506f0aSbrad };
4539e506f0aSbrad
45462ac0c33Sjakob /*
45562ac0c33Sjakob * Used during options parsing
45662ac0c33Sjakob */
45762ac0c33Sjakob struct config_parser_state {
45815ed76cbSbrad char* filename;
459d3fecca9Ssthen const char* chroot;
46062ac0c33Sjakob int line;
46162ac0c33Sjakob int errors;
462fe5fe5f6Sflorian struct nsd_options* opt;
4635435475dSsthen struct pattern_options *pattern;
4645435475dSsthen struct zone_options *zone;
4655435475dSsthen struct key_options *key;
466063644e9Sflorian struct tls_auth_options *tls_auth;
467308d2509Sflorian struct ip_address_option *ip;
468d3fecca9Ssthen void (*err)(void*,const char*);
469d3fecca9Ssthen void* err_arg;
47062ac0c33Sjakob };
47162ac0c33Sjakob
472fe5fe5f6Sflorian extern config_parser_state_type* cfg_parser;
47362ac0c33Sjakob
47462ac0c33Sjakob /* region will be put in nsd_options struct. Returns empty options struct. */
475fe5fe5f6Sflorian struct nsd_options* nsd_options_create(region_type* region);
47662ac0c33Sjakob /* the number of zones that are configured */
nsd_options_num_zones(struct nsd_options * opt)477fe5fe5f6Sflorian static inline size_t nsd_options_num_zones(struct nsd_options* opt)
47862ac0c33Sjakob { return opt->zone_options->count; }
47962ac0c33Sjakob /* insert a zone into the main options tree, returns 0 on error */
480fe5fe5f6Sflorian int nsd_options_insert_zone(struct nsd_options* opt, struct zone_options* zone);
481d3fecca9Ssthen /* insert a pattern into the main options tree, returns 0 on error */
482fe5fe5f6Sflorian int nsd_options_insert_pattern(struct nsd_options* opt,
483fe5fe5f6Sflorian struct pattern_options* pat);
48462ac0c33Sjakob
485d3fecca9Ssthen /* parses options file. Returns false on failure. callback, if nonNULL,
486d3fecca9Ssthen * gets called with error strings, default prints. */
487fe5fe5f6Sflorian int parse_options_file(struct nsd_options* opt, const char* file,
488*bf87c3c0Sflorian void (*err)(void*,const char*), void* err_arg,
489*bf87c3c0Sflorian struct nsd_options* old_opts);
490fe5fe5f6Sflorian struct zone_options* zone_options_create(region_type* region);
491fe5fe5f6Sflorian void zone_options_delete(struct nsd_options* opt, struct zone_options* zone);
492*bf87c3c0Sflorian struct catalog_member_zone* catalog_member_zone_create(region_type* region);
as_catalog_member_zone(struct zone_options * zopt)493*bf87c3c0Sflorian static inline struct catalog_member_zone* as_catalog_member_zone(struct zone_options* zopt)
494*bf87c3c0Sflorian { return zopt && zopt->is_catalog_member_zone ? (struct catalog_member_zone*)zopt : NULL; }
49562ac0c33Sjakob /* find a zone by apex domain name, or NULL if not found. */
496fe5fe5f6Sflorian struct zone_options* zone_options_find(struct nsd_options* opt,
497fe5fe5f6Sflorian const struct dname* apex);
498fe5fe5f6Sflorian struct pattern_options* pattern_options_create(region_type* region);
499fe5fe5f6Sflorian struct pattern_options* pattern_options_find(struct nsd_options* opt, const char* name);
500fe5fe5f6Sflorian int pattern_options_equal(struct pattern_options* p, struct pattern_options* q);
501fe5fe5f6Sflorian void pattern_options_remove(struct nsd_options* opt, const char* name);
502fe5fe5f6Sflorian void pattern_options_add_modify(struct nsd_options* opt,
503fe5fe5f6Sflorian struct pattern_options* p);
504fe5fe5f6Sflorian void pattern_options_marshal(struct buffer* buffer, struct pattern_options* p);
505fe5fe5f6Sflorian struct pattern_options* pattern_options_unmarshal(region_type* r,
506fe5fe5f6Sflorian struct buffer* b);
507fe5fe5f6Sflorian struct key_options* key_options_create(region_type* region);
508fe5fe5f6Sflorian void key_options_insert(struct nsd_options* opt, struct key_options* key);
509fe5fe5f6Sflorian struct key_options* key_options_find(struct nsd_options* opt, const char* name);
510fe5fe5f6Sflorian void key_options_remove(struct nsd_options* opt, const char* name);
511fe5fe5f6Sflorian int key_options_equal(struct key_options* p, struct key_options* q);
512fe5fe5f6Sflorian void key_options_add_modify(struct nsd_options* opt, struct key_options* key);
513a1bac035Sflorian void key_options_setup(region_type* region, struct key_options* key);
514a1bac035Sflorian void key_options_desetup(region_type* region, struct key_options* key);
515063644e9Sflorian /* TLS auth */
516063644e9Sflorian struct tls_auth_options* tls_auth_options_create(region_type* region);
517063644e9Sflorian void tls_auth_options_insert(struct nsd_options* opt, struct tls_auth_options* auth);
518063644e9Sflorian struct tls_auth_options* tls_auth_options_find(struct nsd_options* opt, const char* name);
519d3fecca9Ssthen /* read in zone list file. Returns false on failure */
520fe5fe5f6Sflorian int parse_zone_list_file(struct nsd_options* opt);
521*bf87c3c0Sflorian /* create (potential) catalog producer member entry and add to the zonelist */
522*bf87c3c0Sflorian struct zone_options* zone_list_add_or_cat(struct nsd_options* opt,
523*bf87c3c0Sflorian const char* zname, const char* pname, new_member_id_type new_member_id);
524d3fecca9Ssthen /* create zone entry and add to the zonelist file */
zone_list_add(struct nsd_options * opt,const char * zname,const char * pname)525*bf87c3c0Sflorian static inline struct zone_options* zone_list_add(struct nsd_options* opt,
526*bf87c3c0Sflorian const char* zname, const char* pname)
527*bf87c3c0Sflorian { return zone_list_add_or_cat(opt, zname, pname, NULL); }
528d3fecca9Ssthen /* create zonelist entry, do not insert in file (called by _add) */
529fe5fe5f6Sflorian struct zone_options* zone_list_zone_insert(struct nsd_options* opt,
530*bf87c3c0Sflorian const char* nm, const char* patnm);
531fe5fe5f6Sflorian void zone_list_del(struct nsd_options* opt, struct zone_options* zone);
532fe5fe5f6Sflorian void zone_list_compact(struct nsd_options* opt);
533fe5fe5f6Sflorian void zone_list_close(struct nsd_options* opt);
534d65f3523Sjakob
5359e506f0aSbrad /* create zonestat name tree , for initially created zones */
536fe5fe5f6Sflorian void options_zonestatnames_create(struct nsd_options* opt);
5379e506f0aSbrad /* Get zonestat id for zone options, add new entry if necessary.
5389e506f0aSbrad * instantiates the pattern's zonestat string */
539fe5fe5f6Sflorian unsigned getzonestatid(struct nsd_options* opt, struct zone_options* zopt);
5409e506f0aSbrad /* create string, same options as zonefile but no chroot changes */
541fe5fe5f6Sflorian const char* config_cook_string(struct zone_options* zone, const char* input);
5429e506f0aSbrad
54318e77612Sflorian /** check if config for remote control turns on IP-address interface
54418e77612Sflorian * with certificates or a named pipe without certificates. */
54518e77612Sflorian int options_remote_is_address(struct nsd_options* cfg);
54618e77612Sflorian
547d65f3523Sjakob #if defined(HAVE_SSL)
54862ac0c33Sjakob /* tsig must be inited, adds all keys in options to tsig. */
549fe5fe5f6Sflorian void key_options_tsig_add(struct nsd_options* opt);
550d65f3523Sjakob #endif
55162ac0c33Sjakob
55262ac0c33Sjakob /* check acl list, acl number that matches if passed(0..),
55362ac0c33Sjakob * or failure (-1) if dropped */
55462ac0c33Sjakob /* the reason why (the acl) is returned too (or NULL) */
555fe5fe5f6Sflorian int acl_check_incoming(struct acl_options* acl, struct query* q,
556fe5fe5f6Sflorian struct acl_options** reason);
557fe5fe5f6Sflorian int acl_addr_matches_host(struct acl_options* acl, struct acl_options* host);
558fe5fe5f6Sflorian int acl_addr_matches(struct acl_options* acl, struct query* q);
559b71395eaSflorian int acl_addr_matches_proxy(struct acl_options* acl, struct query* q);
560fe5fe5f6Sflorian int acl_key_matches(struct acl_options* acl, struct query* q);
56162ac0c33Sjakob int acl_addr_match_mask(uint32_t* a, uint32_t* b, uint32_t* mask, size_t sz);
562308d2509Sflorian int acl_addr_match_range_v6(uint32_t* minval, uint32_t* x, uint32_t* maxval, size_t sz);
563308d2509Sflorian int acl_addr_match_range_v4(uint32_t* minval, uint32_t* x, uint32_t* maxval, size_t sz);
56462ac0c33Sjakob
565b71395eaSflorian /* check acl list for blocks on address, return 0 if none, -1 if blocked. */
566b71395eaSflorian int acl_check_incoming_block_proxy(struct acl_options* acl, struct query* q,
567b71395eaSflorian struct acl_options** reason);
568b71395eaSflorian
56962ac0c33Sjakob /* returns true if acls are both from the same host */
570fe5fe5f6Sflorian int acl_same_host(struct acl_options* a, struct acl_options* b);
57162ac0c33Sjakob /* find acl by number in the list */
572fe5fe5f6Sflorian struct acl_options* acl_find_num(struct acl_options* acl, int num);
57362ac0c33Sjakob
574d3fecca9Ssthen /* see if two acl lists are the same (same elements in same order, or empty) */
575fe5fe5f6Sflorian int acl_list_equal(struct acl_options* p, struct acl_options* q);
576d3fecca9Ssthen /* see if two acl are the same */
577fe5fe5f6Sflorian int acl_equal(struct acl_options* p, struct acl_options* q);
578d3fecca9Ssthen
57962ac0c33Sjakob /* see if a zone is a slave or a master zone */
580fe5fe5f6Sflorian int zone_is_slave(struct zone_options* opt);
581*bf87c3c0Sflorian /* see if a zone is a catalog consumer */
zone_is_catalog_consumer(struct zone_options * opt)582*bf87c3c0Sflorian static inline int zone_is_catalog_consumer(struct zone_options* opt)
583*bf87c3c0Sflorian { return opt && opt->pattern
584*bf87c3c0Sflorian && opt->pattern->catalog_role == CATALOG_ROLE_CONSUMER; }
zone_is_catalog_producer(struct zone_options * opt)585*bf87c3c0Sflorian static inline int zone_is_catalog_producer(struct zone_options* opt)
586*bf87c3c0Sflorian { return opt && opt->pattern
587*bf87c3c0Sflorian && opt->pattern->catalog_role == CATALOG_ROLE_PRODUCER; }
zone_is_catalog_member(struct zone_options * opt)588*bf87c3c0Sflorian static inline int zone_is_catalog_member(struct zone_options* opt)
589*bf87c3c0Sflorian { return opt && opt->is_catalog_member_zone; }
zone_is_catalog_producer_member(struct zone_options * opt)590*bf87c3c0Sflorian static inline const char* zone_is_catalog_producer_member(struct zone_options* opt)
591*bf87c3c0Sflorian { return opt && opt->pattern && opt->pattern->catalog_producer_zone
592*bf87c3c0Sflorian ? opt->pattern->catalog_producer_zone : NULL; }
zone_is_catalog_consumer_member(struct zone_options * opt)593*bf87c3c0Sflorian static inline int zone_is_catalog_consumer_member(struct zone_options* opt)
594*bf87c3c0Sflorian { return zone_is_catalog_member(opt) && !zone_is_catalog_producer_member(opt); }
595d3fecca9Ssthen /* create zonefile name, returns static pointer (perhaps to options data) */
596fe5fe5f6Sflorian const char* config_make_zonefile(struct zone_options* zone, struct nsd* nsd);
597d3fecca9Ssthen
598d3fecca9Ssthen #define ZONEC_PCT_TIME 5 /* seconds, then it starts to print pcts */
599d3fecca9Ssthen #define ZONEC_PCT_COUNT 100000 /* elements before pct check is done */
60062ac0c33Sjakob
60162ac0c33Sjakob /* parsing helpers */
6025435475dSsthen void c_error(const char* msg, ...) ATTR_FORMAT(printf, 1,2);
6035435475dSsthen int c_wrap(void);
604fe5fe5f6Sflorian struct acl_options* parse_acl_info(region_type* region, char* ip,
605fe5fe5f6Sflorian const char* key);
60662ac0c33Sjakob /* true if ipv6 address, false if ipv4 */
60762ac0c33Sjakob int parse_acl_is_ipv6(const char* p);
60862ac0c33Sjakob /* returns range type. mask is the 2nd part of the range */
60962ac0c33Sjakob int parse_acl_range_type(char* ip, char** mask);
61062ac0c33Sjakob /* parses subnet mask, fills 0 mask as well */
61162ac0c33Sjakob void parse_acl_range_subnet(char* p, void* addr, int maxbits);
61262ac0c33Sjakob /* clean up options */
613fe5fe5f6Sflorian void nsd_options_destroy(struct nsd_options* opt);
614d3fecca9Ssthen /* replace occurrences of one with two in buf, pass length of buffer */
615d3fecca9Ssthen void replace_str(char* buf, size_t len, const char* one, const char* two);
616d3fecca9Ssthen /* apply pattern to the existing pattern in the parser */
6175435475dSsthen void config_apply_pattern(struct pattern_options *dest, const char* name);
6183b24e79eSsthen /* if the file is a directory, print a warning, because flex just exit()s
6193b24e79eSsthen * when a fileread fails because it is a directory, helps the user figure
6203b24e79eSsthen * out what just happened */
6213b24e79eSsthen void warn_if_directory(const char* filetype, FILE* f, const char* fname);
6228d298c9fSsthen /* resolve interface names in the options "ip-address:" (or "interface:")
6238d298c9fSsthen * and "control-interface:" into the ip-addresses associated with those
6248d298c9fSsthen * names. */
6258d298c9fSsthen void resolve_interface_names(struct nsd_options* options);
62662ac0c33Sjakob
627b71395eaSflorian /* See if the sockaddr port number is listed in the proxy protocol ports. */
628b71395eaSflorian int sockaddr_uses_proxy_protocol_port(struct nsd_options* options,
629b71395eaSflorian struct sockaddr* addr);
630b71395eaSflorian
63162ac0c33Sjakob #endif /* OPTIONS_H */
632