/contrib/bind9/lib/dns/include/dns/rpz.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 200 lines · 128 code · 30 blank · 42 comment · 0 complexity · 6fdac566044be1f71cd3834bbbe4f4c4 MD5 · raw file

  1. /*
  2. * Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
  3. *
  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.
  7. *
  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.
  15. */
  16. /* $Id$ */
  17. #ifndef DNS_RPZ_H
  18. #define DNS_RPZ_H 1
  19. #include <isc/lang.h>
  20. #include <dns/fixedname.h>
  21. #include <dns/rdata.h>
  22. #include <dns/types.h>
  23. ISC_LANG_BEGINDECLS
  24. #define DNS_RPZ_IP_ZONE "rpz-ip"
  25. #define DNS_RPZ_NSIP_ZONE "rpz-nsip"
  26. #define DNS_RPZ_NSDNAME_ZONE "rpz-nsdname"
  27. typedef isc_uint8_t dns_rpz_cidr_bits_t;
  28. typedef enum {
  29. DNS_RPZ_TYPE_BAD,
  30. DNS_RPZ_TYPE_QNAME,
  31. DNS_RPZ_TYPE_IP,
  32. DNS_RPZ_TYPE_NSDNAME,
  33. DNS_RPZ_TYPE_NSIP
  34. } dns_rpz_type_t;
  35. /*
  36. * Require DNS_RPZ_POLICY_PASSTHRU < DNS_RPZ_POLICY_NXDOMAIN <
  37. * DNS_RPZ_POLICY_NODATA < DNS_RPZ_POLICY_CNAME to choose among competing
  38. * policies.
  39. */
  40. typedef enum {
  41. DNS_RPZ_POLICY_GIVEN = 0, /* 'given': what policy record says */
  42. DNS_RPZ_POLICY_DISABLED = 1, /* 'cname x': answer with x's rrsets */
  43. DNS_RPZ_POLICY_PASSTHRU = 2, /* 'passthru': do not rewrite */
  44. DNS_RPZ_POLICY_NXDOMAIN = 3, /* 'nxdomain': answer with NXDOMAIN */
  45. DNS_RPZ_POLICY_NODATA = 4, /* 'nodata': answer with ANCOUNT=0 */
  46. DNS_RPZ_POLICY_CNAME = 5, /* 'cname x': answer with x's rrsets */
  47. DNS_RPZ_POLICY_RECORD,
  48. DNS_RPZ_POLICY_WILDCNAME,
  49. DNS_RPZ_POLICY_MISS,
  50. DNS_RPZ_POLICY_ERROR
  51. } dns_rpz_policy_t;
  52. /*
  53. * Specify a response policy zone.
  54. */
  55. typedef struct dns_rpz_zone dns_rpz_zone_t;
  56. struct dns_rpz_zone {
  57. ISC_LINK(dns_rpz_zone_t) link;
  58. int num;
  59. dns_name_t origin; /* Policy zone name */
  60. dns_name_t nsdname; /* DNS_RPZ_NSDNAME_ZONE.origin */
  61. dns_rpz_policy_t policy; /* DNS_RPZ_POLICY_GIVEN or override */
  62. dns_name_t cname; /* override value for ..._CNAME */
  63. };
  64. /*
  65. * Radix trees for response policy IP addresses.
  66. */
  67. typedef struct dns_rpz_cidr dns_rpz_cidr_t;
  68. /*
  69. * context for finding the best policy
  70. */
  71. typedef struct {
  72. unsigned int state;
  73. # define DNS_RPZ_REWRITTEN 0x0001
  74. # define DNS_RPZ_DONE_QNAME 0x0002 /* qname checked */
  75. # define DNS_RPZ_DONE_QNAME_IP 0x0004 /* IP addresses of qname checked */
  76. # define DNS_RPZ_DONE_NSDNAME 0x0008 /* NS name missed; checking addresses */
  77. # define DNS_RPZ_DONE_IPv4 0x0010
  78. # define DNS_RPZ_RECURSING 0x0020
  79. # define DNS_RPZ_HAVE_IP 0x0040 /* a policy zone has IP addresses */
  80. # define DNS_RPZ_HAVE_NSIPv4 0x0080 /* IPv4 NISP addresses */
  81. # define DNS_RPZ_HAVE_NSIPv6 0x0100 /* IPv6 NISP addresses */
  82. # define DNS_RPZ_HAVE_NSDNAME 0x0200 /* NS names */
  83. /*
  84. * Best match so far.
  85. */
  86. struct {
  87. dns_rpz_type_t type;
  88. dns_rpz_zone_t *rpz;
  89. dns_rpz_cidr_bits_t prefix;
  90. dns_rpz_policy_t policy;
  91. dns_ttl_t ttl;
  92. isc_result_t result;
  93. dns_zone_t *zone;
  94. dns_db_t *db;
  95. dns_dbversion_t *version;
  96. dns_dbnode_t *node;
  97. dns_rdataset_t *rdataset;
  98. } m;
  99. /*
  100. * State for chasing IP addresses and NS names including recursion.
  101. */
  102. struct {
  103. unsigned int label;
  104. dns_db_t *db;
  105. dns_rdataset_t *ns_rdataset;
  106. dns_rdatatype_t r_type;
  107. isc_result_t r_result;
  108. dns_rdataset_t *r_rdataset;
  109. } r;
  110. /*
  111. * State of real query while recursing for NSIP or NSDNAME.
  112. */
  113. struct {
  114. isc_result_t result;
  115. isc_boolean_t is_zone;
  116. isc_boolean_t authoritative;
  117. dns_zone_t *zone;
  118. dns_db_t *db;
  119. dns_dbnode_t *node;
  120. dns_rdataset_t *rdataset;
  121. dns_rdataset_t *sigrdataset;
  122. dns_rdatatype_t qtype;
  123. } q;
  124. dns_name_t *qname;
  125. dns_name_t *r_name;
  126. dns_name_t *fname;
  127. dns_fixedname_t _qnamef;
  128. dns_fixedname_t _r_namef;
  129. dns_fixedname_t _fnamef;
  130. } dns_rpz_st_t;
  131. #define DNS_RPZ_TTL_DEFAULT 5
  132. /*
  133. * So various response policy zone messages can be turned up or down.
  134. */
  135. #define DNS_RPZ_ERROR_LEVEL ISC_LOG_WARNING
  136. #define DNS_RPZ_INFO_LEVEL ISC_LOG_INFO
  137. #define DNS_RPZ_DEBUG_LEVEL1 ISC_LOG_DEBUG(1)
  138. #define DNS_RPZ_DEBUG_LEVEL2 ISC_LOG_DEBUG(2)
  139. #define DNS_RPZ_DEBUG_LEVEL3 ISC_LOG_DEBUG(3)
  140. const char *
  141. dns_rpz_type2str(dns_rpz_type_t type);
  142. dns_rpz_policy_t
  143. dns_rpz_str2policy(const char *str);
  144. const char *
  145. dns_rpz_policy2str(dns_rpz_policy_t policy);
  146. void
  147. dns_rpz_set_need(isc_boolean_t need);
  148. isc_boolean_t
  149. dns_rpz_needed(void);
  150. void
  151. dns_rpz_cidr_free(dns_rpz_cidr_t **cidr);
  152. void
  153. dns_rpz_view_destroy(dns_view_t *view);
  154. isc_result_t
  155. dns_rpz_new_cidr(isc_mem_t *mctx, dns_name_t *origin,
  156. dns_rpz_cidr_t **rbtdb_cidr);
  157. void
  158. dns_rpz_enabled(dns_rpz_cidr_t *cidr, dns_rpz_st_t *st);
  159. void
  160. dns_rpz_cidr_deleteip(dns_rpz_cidr_t *cidr, dns_name_t *name);
  161. void
  162. dns_rpz_cidr_addip(dns_rpz_cidr_t *cidr, dns_name_t *name);
  163. isc_result_t
  164. dns_rpz_cidr_find(dns_rpz_cidr_t *cidr, const isc_netaddr_t *netaddr,
  165. dns_rpz_type_t type, dns_name_t *canon_name,
  166. dns_name_t *search_name, dns_rpz_cidr_bits_t *prefix);
  167. dns_rpz_policy_t
  168. dns_rpz_decode_cname(dns_rdataset_t *, dns_name_t *selfname);
  169. ISC_LANG_ENDDECLS
  170. #endif /* DNS_RPZ_H */