Import bind 9.5.2 vendor sources.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / include / dns / acl.h
blobe72be3e72a4d18920754569768bca503e7366fbe
1 /*
2 * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: acl.h,v 1.31.2.2 2009/01/19 23:47:03 tbox Exp $ */
20 #ifndef DNS_ACL_H
21 #define DNS_ACL_H 1
23 /*****
24 ***** Module Info
25 *****/
27 /*! \file dns/acl.h
28 * \brief
29 * Address match list handling.
32 /***
33 *** Imports
34 ***/
36 #include <isc/lang.h>
37 #include <isc/magic.h>
38 #include <isc/netaddr.h>
39 #include <isc/refcount.h>
41 #include <dns/name.h>
42 #include <dns/types.h>
43 #include <dns/iptable.h>
45 /***
46 *** Types
47 ***/
49 typedef enum {
50 dns_aclelementtype_ipprefix,
51 dns_aclelementtype_keyname,
52 dns_aclelementtype_nestedacl,
53 dns_aclelementtype_localhost,
54 dns_aclelementtype_localnets,
55 dns_aclelementtype_any
56 } dns_aclelemettype_t;
58 typedef struct dns_aclipprefix dns_aclipprefix_t;
60 struct dns_aclipprefix {
61 isc_netaddr_t address; /* IP4/IP6 */
62 unsigned int prefixlen;
65 struct dns_aclelement {
66 dns_aclelemettype_t type;
67 isc_boolean_t negative;
68 dns_name_t keyname;
69 dns_acl_t *nestedacl;
70 int node_num;
73 struct dns_acl {
74 unsigned int magic;
75 isc_mem_t *mctx;
76 isc_refcount_t refcount;
77 dns_iptable_t *iptable;
78 #define node_count iptable->radix->num_added_node
79 dns_aclelement_t *elements;
80 isc_boolean_t has_negatives;
81 unsigned int alloc; /*%< Elements allocated */
82 unsigned int length; /*%< Elements initialized */
83 char *name; /*%< Temporary use only */
84 ISC_LINK(dns_acl_t) nextincache; /*%< Ditto */
87 struct dns_aclenv {
88 dns_acl_t *localhost;
89 dns_acl_t *localnets;
90 isc_boolean_t match_mapped;
93 #define DNS_ACL_MAGIC ISC_MAGIC('D','a','c','l')
94 #define DNS_ACL_VALID(a) ISC_MAGIC_VALID(a, DNS_ACL_MAGIC)
96 /***
97 *** Functions
98 ***/
100 ISC_LANG_BEGINDECLS
102 isc_result_t
103 dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target);
104 /*%<
105 * Create a new ACL, including an IP table and an array with room
106 * for 'n' ACL elements. The elements are uninitialized and the
107 * length is 0.
110 isc_result_t
111 dns_acl_any(isc_mem_t *mctx, dns_acl_t **target);
112 /*%<
113 * Create a new ACL that matches everything.
116 isc_result_t
117 dns_acl_none(isc_mem_t *mctx, dns_acl_t **target);
118 /*%<
119 * Create a new ACL that matches nothing.
122 isc_boolean_t
123 dns_acl_isany(dns_acl_t *acl);
124 /*%<
125 * Test whether ACL is set to "{ any; }"
128 isc_boolean_t
129 dns_acl_isnone(dns_acl_t *acl);
130 /*%<
131 * Test whether ACL is set to "{ none; }"
134 isc_result_t
135 dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, isc_boolean_t pos);
136 /*%<
137 * Merge the contents of one ACL into another. Call dns_iptable_merge()
138 * for the IP tables, then concatenate the element arrays.
140 * If pos is set to false, then the nested ACL is to be negated. This
141 * means reverse the sense of each *positive* element or IP table node,
142 * but leave negatives alone, so as to prevent a double-negative causing
143 * an unexpected positive match in the parent ACL.
146 void
147 dns_acl_attach(dns_acl_t *source, dns_acl_t **target);
149 void
150 dns_acl_detach(dns_acl_t **aclp);
152 isc_boolean_t
153 dns_acl_isinsecure(const dns_acl_t *a);
154 /*%<
155 * Return #ISC_TRUE iff the acl 'a' is considered insecure, that is,
156 * if it contains IP addresses other than those of the local host.
157 * This is intended for applications such as printing warning
158 * messages for suspect ACLs; it is not intended for making access
159 * control decisions. We make no guarantee that an ACL for which
160 * this function returns #ISC_FALSE is safe.
163 isc_result_t
164 dns_aclenv_init(isc_mem_t *mctx, dns_aclenv_t *env);
165 /*%<
166 * Initialize ACL environment, setting up localhost and localnets ACLs
169 void
170 dns_aclenv_copy(dns_aclenv_t *t, dns_aclenv_t *s);
172 void
173 dns_aclenv_destroy(dns_aclenv_t *env);
175 isc_result_t
176 dns_acl_match(const isc_netaddr_t *reqaddr,
177 const dns_name_t *reqsigner,
178 const dns_acl_t *acl,
179 const dns_aclenv_t *env,
180 int *match,
181 const dns_aclelement_t **matchelt);
182 /*%<
183 * General, low-level ACL matching. This is expected to
184 * be useful even for weird stuff like the topology and sortlist statements.
186 * Match the address 'reqaddr', and optionally the key name 'reqsigner',
187 * against 'acl'. 'reqsigner' may be NULL.
189 * If there is a match, '*match' will be set to an integer whose absolute
190 * value corresponds to the order in which the matching value was inserted
191 * into the ACL. For a positive match, this value will be positive; for a
192 * negative match, it will be negative.
194 * If there is no match, *match will be set to zero.
196 * If there is a match in the element list (either positive or negative)
197 * and 'matchelt' is non-NULL, *matchelt will be pointed to the matching
198 * element.
200 * Returns:
201 *\li #ISC_R_SUCCESS Always succeeds.
204 isc_boolean_t
205 dns_aclelement_match(const isc_netaddr_t *reqaddr,
206 const dns_name_t *reqsigner,
207 const dns_aclelement_t *e,
208 const dns_aclenv_t *env,
209 const dns_aclelement_t **matchelt);
210 /*%<
211 * Like dns_acl_match, but matches against the single ACL element 'e'
212 * rather than a complete ACL, and returns ISC_TRUE iff it matched.
214 * To determine whether the match was positive or negative, the
215 * caller should examine e->negative. Since the element 'e' may be
216 * a reference to a named ACL or a nested ACL, a matching element
217 * returned through 'matchelt' is not necessarily 'e' itself.
220 ISC_LANG_ENDDECLS
222 #endif /* DNS_ACL_H */