2 * Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
24 #include <dns/fixedname.h>
25 #include <dns/rdata.h>
26 #include <dns/types.h>
30 #define DNS_RPZ_IP_ZONE "rpz-ip"
31 #define DNS_RPZ_NSIP_ZONE "rpz-nsip"
32 #define DNS_RPZ_NSDNAME_ZONE "rpz-nsdname"
34 typedef isc_uint8_t dns_rpz_cidr_bits_t;
45 * Require DNS_RPZ_POLICY_PASSTHRU < DNS_RPZ_POLICY_NXDOMAIN <
46 * DNS_RPZ_POLICY_NODATA < DNS_RPZ_POLICY_CNAME to choose among competing
50 DNS_RPZ_POLICY_GIVEN = 0, /* 'given': what policy record says */
51 DNS_RPZ_POLICY_DISABLED = 1, /* 'cname x': answer with x's rrsets */
52 DNS_RPZ_POLICY_PASSTHRU = 2, /* 'passthru': do not rewrite */
53 DNS_RPZ_POLICY_NXDOMAIN = 3, /* 'nxdomain': answer with NXDOMAIN */
54 DNS_RPZ_POLICY_NODATA = 4, /* 'nodata': answer with ANCOUNT=0 */
55 DNS_RPZ_POLICY_CNAME = 5, /* 'cname x': answer with x's rrsets */
56 DNS_RPZ_POLICY_RECORD,
57 DNS_RPZ_POLICY_WILDCNAME,
63 * Specify a response policy zone.
65 typedef struct dns_rpz_zone dns_rpz_zone_t;
68 ISC_LINK(dns_rpz_zone_t) link;
70 dns_name_t origin; /* Policy zone name */
71 dns_name_t nsdname; /* DNS_RPZ_NSDNAME_ZONE.origin */
72 dns_rpz_policy_t policy; /* DNS_RPZ_POLICY_GIVEN or override */
73 dns_name_t cname; /* override value for ..._CNAME */
77 * Radix trees for response policy IP addresses.
79 typedef struct dns_rpz_cidr dns_rpz_cidr_t;
82 * context for finding the best policy
86 # define DNS_RPZ_REWRITTEN 0x0001
87 # define DNS_RPZ_DONE_QNAME 0x0002 /* qname checked */
88 # define DNS_RPZ_DONE_QNAME_IP 0x0004 /* IP addresses of qname checked */
89 # define DNS_RPZ_DONE_NSDNAME 0x0008 /* NS name missed; checking addresses */
90 # define DNS_RPZ_DONE_IPv4 0x0010
91 # define DNS_RPZ_RECURSING 0x0020
92 # define DNS_RPZ_HAVE_IP 0x0040 /* a policy zone has IP addresses */
93 # define DNS_RPZ_HAVE_NSIPv4 0x0080 /* IPv4 NISP addresses */
94 # define DNS_RPZ_HAVE_NSIPv6 0x0100 /* IPv6 NISP addresses */
95 # define DNS_RPZ_HAVE_NSDNAME 0x0200 /* NS names */
102 dns_rpz_cidr_bits_t prefix;
103 dns_rpz_policy_t policy;
108 dns_dbversion_t *version;
110 dns_rdataset_t *rdataset;
113 * State for chasing IP addresses and NS names including recursion.
118 dns_rdataset_t *ns_rdataset;
119 dns_rdatatype_t r_type;
120 isc_result_t r_result;
121 dns_rdataset_t *r_rdataset;
124 * State of real query while recursing for NSIP or NSDNAME.
128 isc_boolean_t is_zone;
129 isc_boolean_t authoritative;
133 dns_rdataset_t *rdataset;
134 dns_rdataset_t *sigrdataset;
135 dns_rdatatype_t qtype;
140 dns_fixedname_t _qnamef;
141 dns_fixedname_t _r_namef;
142 dns_fixedname_t _fnamef;
145 #define DNS_RPZ_TTL_DEFAULT 5
148 * So various response policy zone messages can be turned up or down.
150 #define DNS_RPZ_ERROR_LEVEL ISC_LOG_WARNING
151 #define DNS_RPZ_INFO_LEVEL ISC_LOG_INFO
152 #define DNS_RPZ_DEBUG_LEVEL1 ISC_LOG_DEBUG(1)
153 #define DNS_RPZ_DEBUG_LEVEL2 ISC_LOG_DEBUG(2)
154 #define DNS_RPZ_DEBUG_LEVEL3 ISC_LOG_DEBUG(3)
157 dns_rpz_type2str(dns_rpz_type_t type);
160 dns_rpz_str2policy(const char *str);
163 dns_rpz_policy2str(dns_rpz_policy_t policy);
166 dns_rpz_set_need(isc_boolean_t need);
169 dns_rpz_needed(void);
172 dns_rpz_cidr_free(dns_rpz_cidr_t **cidr);
175 dns_rpz_view_destroy(dns_view_t *view);
178 dns_rpz_new_cidr(isc_mem_t *mctx, dns_name_t *origin,
179 dns_rpz_cidr_t **rbtdb_cidr);
181 dns_rpz_enabled(dns_rpz_cidr_t *cidr, dns_rpz_st_t *st);
184 dns_rpz_cidr_deleteip(dns_rpz_cidr_t *cidr, dns_name_t *name);
187 dns_rpz_cidr_addip(dns_rpz_cidr_t *cidr, dns_name_t *name);
190 dns_rpz_cidr_find(dns_rpz_cidr_t *cidr, const isc_netaddr_t *netaddr,
191 dns_rpz_type_t type, dns_name_t *canon_name,
192 dns_name_t *search_name, dns_rpz_cidr_bits_t *prefix);
195 dns_rpz_decode_cname(dns_rdataset_t *, dns_name_t *selfname);
199 #endif /* DNS_RPZ_H */