2 * Copyright (C) 2011 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.
17 /* $Id: rpz.h,v 1.3 2011-01-13 04:59:26 tbox Exp $ */
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_NO_OP < DNS_RPZ_POLICY_NXDOMAIN <
46 * DNS_RPZ_POLICY_NODATA < DNS_RPZ_POLICY_CNAME.
49 DNS_RPZ_POLICY_GIVEN = 0, /* 'given': what something else says */
50 DNS_RPZ_POLICY_NO_OP = 1, /* 'no-op': do not rewrite */
51 DNS_RPZ_POLICY_NXDOMAIN = 2, /* 'nxdomain': answer with NXDOMAIN */
52 DNS_RPZ_POLICY_NODATA = 3, /* 'nodata': answer with ANCOUNT=0 */
53 DNS_RPZ_POLICY_CNAME = 4, /* 'cname x': answer with x's rrsets */
54 DNS_RPZ_POLICY_RECORD = 5,
60 * Specify a response policy zone.
62 typedef struct dns_rpz_zone dns_rpz_zone_t;
65 ISC_LINK(dns_rpz_zone_t) link;
67 dns_name_t origin; /* Policy zone name */
68 dns_name_t nsdname; /* RPZ_NSDNAME_ZONE.origin */
69 dns_rpz_policy_t policy; /* RPZ_POLICY_GIVEN or override */
70 dns_name_t cname; /* override name for
75 * Radix trees for response policy IP addresses.
77 typedef struct dns_rpz_cidr dns_rpz_cidr_t;
80 * context for finding the best policy
84 # define DNS_RPZ_REWRITTEN 0x0001
85 # define DNS_RPZ_DONE_QNAME 0x0002
86 # define DNS_RPZ_DONE_A 0x0004
87 # define DNS_RPZ_RECURSING 0x0008
88 # define DNS_RPZ_HAVE_IP 0x0010
89 # define DNS_RPZ_HAVE_NSIPv4 0x0020
90 # define DNS_RPZ_HAVE_NSIPv6 0x0040
91 # define DNS_RPZ_HAD_NSDNAME 0x0080
98 dns_rpz_cidr_bits_t prefix;
99 dns_rpz_policy_t policy;
105 dns_rdataset_t *rdataset;
108 * State for chasing NS names and addresses including recursion.
113 dns_rdataset_t *ns_rdataset;
114 dns_rdatatype_t r_type;
115 isc_result_t r_result;
116 dns_rdataset_t *r_rdataset;
119 * State of real query while recursing for NSIP or NSDNAME.
123 isc_boolean_t is_zone;
124 isc_boolean_t authoritative;
128 dns_rdataset_t *rdataset;
129 dns_rdataset_t *sigrdataset;
130 dns_rdatatype_t qtype;
135 dns_fixedname_t _qnamef;
136 dns_fixedname_t _r_namef;
137 dns_fixedname_t _fnamef;
140 #define DNS_RPZ_TTL_DEFAULT 5
143 * So various response policy zone messages can be turned up or down.
145 #define DNS_RPZ_ERROR_LEVEL ISC_LOG_WARNING
146 #define DNS_RPZ_INFO_LEVEL ISC_LOG_INFO
147 #define DNS_RPZ_DEBUG_LEVEL1 ISC_LOG_DEBUG(1)
148 #define DNS_RPZ_DEBUG_LEVEL2 ISC_LOG_DEBUG(2)
151 dns_rpz_type2str(dns_rpz_type_t type);
154 dns_rpz_str2policy(const char *str);
157 dns_rpz_set_need(isc_boolean_t need);
160 dns_rpz_needed(void);
163 dns_rpz_cidr_free(dns_rpz_cidr_t **cidr);
166 dns_rpz_view_destroy(dns_view_t *view);
169 dns_rpz_new_cidr(isc_mem_t *mctx, dns_name_t *origin,
170 dns_rpz_cidr_t **rbtdb_cidr);
172 dns_rpz_enabled(dns_rpz_cidr_t *cidr, dns_rpz_st_t *st);
175 dns_rpz_cidr_deleteip(dns_rpz_cidr_t *cidr, dns_name_t *name);
178 dns_rpz_cidr_addip(dns_rpz_cidr_t *cidr, dns_name_t *name);
181 dns_rpz_cidr_find(dns_rpz_cidr_t *cidr, const isc_netaddr_t *netaddr,
182 dns_rpz_type_t type, dns_name_t *canon_name,
183 dns_name_t *search_name, dns_rpz_cidr_bits_t *prefix);
186 dns_rpz_decode_cname(dns_rdataset_t *, dns_name_t *selfname);
188 #endif /* DNS_RPZ_H */