00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef DNS_RPZ_H
00021 #define DNS_RPZ_H 1
00022
00023 #include <isc/lang.h>
00024
00025 #include <dns/fixedname.h>
00026 #include <dns/rdata.h>
00027 #include <dns/types.h>
00028 #include <isc/refcount.h>
00029
00030 ISC_LANG_BEGINDECLS
00031
00032 #define DNS_RPZ_PREFIX "rpz-"
00033
00034
00035
00036 #define DNS_RPZ_CLIENT_IP_ZONE DNS_RPZ_PREFIX"client-ip"
00037 #define DNS_RPZ_IP_ZONE DNS_RPZ_PREFIX"ip"
00038 #define DNS_RPZ_NSIP_ZONE DNS_RPZ_PREFIX"nsip"
00039 #define DNS_RPZ_NSDNAME_ZONE DNS_RPZ_PREFIX"nsdname"
00040
00041
00042
00043 #define DNS_RPZ_PASSTHRU_NAME DNS_RPZ_PREFIX"passthru"
00044 #define DNS_RPZ_DROP_NAME DNS_RPZ_PREFIX"drop"
00045 #define DNS_RPZ_TCP_ONLY_NAME DNS_RPZ_PREFIX"tcp-only"
00046
00047
00048 typedef isc_uint8_t dns_rpz_prefix_t;
00049
00050 typedef enum {
00051 DNS_RPZ_TYPE_BAD,
00052 DNS_RPZ_TYPE_CLIENT_IP,
00053 DNS_RPZ_TYPE_QNAME,
00054 DNS_RPZ_TYPE_IP,
00055 DNS_RPZ_TYPE_NSDNAME,
00056 DNS_RPZ_TYPE_NSIP
00057 } dns_rpz_type_t;
00058
00059
00060
00061
00062
00063
00064 typedef enum {
00065 DNS_RPZ_POLICY_GIVEN = 0,
00066 DNS_RPZ_POLICY_DISABLED = 1,
00067 DNS_RPZ_POLICY_PASSTHRU = 2,
00068 DNS_RPZ_POLICY_DROP = 3,
00069 DNS_RPZ_POLICY_TCP_ONLY = 4,
00070 DNS_RPZ_POLICY_NXDOMAIN = 5,
00071 DNS_RPZ_POLICY_NODATA = 6,
00072 DNS_RPZ_POLICY_CNAME = 7,
00073 DNS_RPZ_POLICY_RECORD,
00074 DNS_RPZ_POLICY_WILDCNAME,
00075 DNS_RPZ_POLICY_MISS,
00076 DNS_RPZ_POLICY_ERROR
00077 } dns_rpz_policy_t;
00078
00079 typedef isc_uint8_t dns_rpz_num_t;
00080
00081 #define DNS_RPZ_MAX_ZONES 32
00082 #if DNS_RPZ_MAX_ZONES > 32
00083 # if DNS_RPZ_MAX_ZONES > 64
00084 # error "rpz zone bit masks must fit in a word"
00085 # endif
00086 typedef isc_uint64_t dns_rpz_zbits_t;
00087 #else
00088 typedef isc_uint32_t dns_rpz_zbits_t;
00089 #endif
00090
00091 #define DNS_RPZ_ALL_ZBITS ((dns_rpz_zbits_t)-1)
00092
00093 #define DNS_RPZ_INVALID_NUM DNS_RPZ_MAX_ZONES
00094
00095 #define DNS_RPZ_ZBIT(n) (((dns_rpz_zbits_t)1) << (dns_rpz_num_t)(n))
00096
00097
00098
00099
00100
00101 #define DNS_RPZ_ZMASK(n) ((dns_rpz_zbits_t)((((n) >= DNS_RPZ_MAX_ZONES-1) ? \
00102 0 : (1<<((n)+1))) -1))
00103
00104
00105
00106
00107 typedef struct dns_rpz_triggers dns_rpz_triggers_t;
00108 struct dns_rpz_triggers {
00109 int client_ipv4;
00110 int client_ipv6;
00111 int qname;
00112 int ipv4;
00113 int ipv6;
00114 int nsdname;
00115 int nsipv4;
00116 int nsipv6;
00117 };
00118
00119
00120
00121 typedef struct dns_rpz_zone dns_rpz_zone_t;
00122 struct dns_rpz_zone {
00123 isc_refcount_t refs;
00124 dns_rpz_num_t num;
00125 dns_name_t origin;
00126 dns_name_t client_ip;
00127 dns_name_t ip;
00128 dns_name_t nsdname;
00129 dns_name_t nsip;
00130 dns_name_t passthru;
00131 dns_name_t drop;
00132 dns_name_t tcp_only;
00133 dns_name_t cname;
00134 dns_ttl_t max_policy_ttl;
00135 dns_rpz_policy_t policy;
00136 };
00137
00138
00139
00140
00141 typedef struct dns_rpz_cidr_node dns_rpz_cidr_node_t;
00142
00143
00144
00145
00146 typedef struct dns_rpz_zones dns_rpz_zones_t;
00147 struct dns_rpz_zones {
00148 struct {
00149 dns_rpz_zbits_t no_rd_ok;
00150 isc_boolean_t break_dnssec;
00151 isc_boolean_t qname_wait_recurse;
00152 unsigned int min_ns_labels;
00153 dns_rpz_num_t num_zones;
00154 } p;
00155 dns_rpz_zone_t *zones[DNS_RPZ_MAX_ZONES];
00156 dns_rpz_triggers_t triggers[DNS_RPZ_MAX_ZONES];
00157
00158 dns_rpz_zbits_t defined;
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 dns_rpz_zbits_t load_begun;
00174 struct {
00175 dns_rpz_zbits_t client_ipv4;
00176 dns_rpz_zbits_t client_ipv6;
00177 dns_rpz_zbits_t client_ip;
00178 dns_rpz_zbits_t qname;
00179 dns_rpz_zbits_t ipv4;
00180 dns_rpz_zbits_t ipv6;
00181 dns_rpz_zbits_t ip;
00182 dns_rpz_zbits_t nsdname;
00183 dns_rpz_zbits_t nsipv4;
00184 dns_rpz_zbits_t nsipv6;
00185 dns_rpz_zbits_t nsip;
00186 dns_rpz_zbits_t qname_skip_recurse;
00187 } have;
00188 dns_rpz_triggers_t total_triggers;
00189
00190 isc_mem_t *mctx;
00191 isc_refcount_t refs;
00192
00193
00194
00195
00196
00197
00198 isc_mutex_t search_lock;
00199 isc_mutex_t maint_lock;
00200
00201 dns_rpz_cidr_node_t *cidr;
00202 dns_rbt_t *rbt;
00203 };
00204
00205
00206
00207
00208
00209 typedef struct {
00210 unsigned int state;
00211 # define DNS_RPZ_REWRITTEN 0x0001
00212 # define DNS_RPZ_DONE_CLIENT_IP 0x0002
00213 # define DNS_RPZ_DONE_QNAME 0x0004
00214 # define DNS_RPZ_DONE_QNAME_IP 0x0008
00215 # define DNS_RPZ_DONE_NSDNAME 0x0010
00216 # define DNS_RPZ_DONE_IPv4 0x0020
00217 # define DNS_RPZ_RECURSING 0x0040
00218
00219
00220
00221 struct {
00222 dns_rpz_type_t type;
00223 dns_rpz_zone_t *rpz;
00224 dns_rpz_prefix_t prefix;
00225 dns_rpz_policy_t policy;
00226 dns_ttl_t ttl;
00227 isc_result_t result;
00228 dns_zone_t *zone;
00229 dns_db_t *db;
00230 dns_dbversion_t *version;
00231 dns_dbnode_t *node;
00232 dns_rdataset_t *rdataset;
00233 } m;
00234
00235
00236
00237 struct {
00238 unsigned int label;
00239 dns_db_t *db;
00240 dns_rdataset_t *ns_rdataset;
00241 dns_rdatatype_t r_type;
00242 isc_result_t r_result;
00243 dns_rdataset_t *r_rdataset;
00244 } r;
00245
00246
00247
00248 struct {
00249 isc_result_t result;
00250 isc_boolean_t is_zone;
00251 isc_boolean_t authoritative;
00252 dns_zone_t *zone;
00253 dns_db_t *db;
00254 dns_dbnode_t *node;
00255 dns_rdataset_t *rdataset;
00256 dns_rdataset_t *sigrdataset;
00257 dns_rdatatype_t qtype;
00258 } q;
00259
00260
00261
00262
00263
00264 dns_name_t *p_name;
00265 dns_name_t *r_name;
00266 dns_name_t *fname;
00267 dns_fixedname_t _p_namef;
00268 dns_fixedname_t _r_namef;
00269 dns_fixedname_t _fnamef;
00270 } dns_rpz_st_t;
00271
00272 #define DNS_RPZ_TTL_DEFAULT 5
00273 #define DNS_RPZ_MAX_TTL_DEFAULT DNS_RPZ_TTL_DEFAULT
00274
00275
00276
00277
00278 #define DNS_RPZ_ERROR_LEVEL ISC_LOG_WARNING
00279 #define DNS_RPZ_INFO_LEVEL ISC_LOG_INFO
00280 #define DNS_RPZ_DEBUG_LEVEL1 ISC_LOG_DEBUG(1)
00281 #define DNS_RPZ_DEBUG_LEVEL2 ISC_LOG_DEBUG(2)
00282 #define DNS_RPZ_DEBUG_LEVEL3 ISC_LOG_DEBUG(3)
00283 #define DNS_RPZ_DEBUG_QUIET (DNS_RPZ_DEBUG_LEVEL3+1)
00284
00285 const char *
00286 dns_rpz_type2str(dns_rpz_type_t type);
00287
00288 dns_rpz_policy_t
00289 dns_rpz_str2policy(const char *str);
00290
00291 const char *
00292 dns_rpz_policy2str(dns_rpz_policy_t policy);
00293
00294 dns_rpz_policy_t
00295 dns_rpz_decode_cname(dns_rpz_zone_t *rpz, dns_rdataset_t *rdataset,
00296 dns_name_t *selfname);
00297
00298 isc_result_t
00299 dns_rpz_new_zones(dns_rpz_zones_t **rpzsp, isc_mem_t *mctx);
00300
00301 void
00302 dns_rpz_attach_rpzs(dns_rpz_zones_t *source, dns_rpz_zones_t **target);
00303
00304 void
00305 dns_rpz_detach_rpzs(dns_rpz_zones_t **rpzsp);
00306
00307 isc_result_t
00308 dns_rpz_beginload(dns_rpz_zones_t **load_rpzsp,
00309 dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num);
00310
00311 isc_result_t
00312 dns_rpz_ready(dns_rpz_zones_t *rpzs,
00313 dns_rpz_zones_t **load_rpzsp, dns_rpz_num_t rpz_num);
00314
00315 isc_result_t
00316 dns_rpz_add(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_name_t *name);
00317
00318 void
00319 dns_rpz_delete(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_name_t *name);
00320
00321 dns_rpz_num_t
00322 dns_rpz_find_ip(dns_rpz_zones_t *rpzs, dns_rpz_type_t rpz_type,
00323 dns_rpz_zbits_t zbits, const isc_netaddr_t *netaddr,
00324 dns_name_t *ip_name, dns_rpz_prefix_t *prefixp);
00325
00326 dns_rpz_zbits_t
00327 dns_rpz_find_name(dns_rpz_zones_t *rpzs, dns_rpz_type_t rpz_type,
00328 dns_rpz_zbits_t zbits, dns_name_t *trig_name);
00329
00330 ISC_LANG_ENDDECLS
00331
00332 #endif
00333