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.206.2 2009/01/18 23:47:41 tbox Exp $ */
29 * Address match list handling.
37 #include <isc/magic.h>
38 #include <isc/netaddr.h>
39 #include <isc/refcount.h>
42 #include <dns/types.h>
43 #include <dns/iptable.h>
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;
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 */
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)
103 dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target);
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
111 dns_acl_any(isc_mem_t *mctx, dns_acl_t **target);
113 * Create a new ACL that matches everything.
117 dns_acl_none(isc_mem_t *mctx, dns_acl_t **target);
119 * Create a new ACL that matches nothing.
123 dns_acl_isany(dns_acl_t *acl);
125 * Test whether ACL is set to "{ any; }"
129 dns_acl_isnone(dns_acl_t *acl);
131 * Test whether ACL is set to "{ none; }"
135 dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, isc_boolean_t pos);
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.
147 dns_acl_attach(dns_acl_t *source, dns_acl_t **target);
150 dns_acl_detach(dns_acl_t **aclp);
153 dns_acl_isinsecure(const dns_acl_t *a);
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.
164 dns_aclenv_init(isc_mem_t *mctx, dns_aclenv_t *env);
166 * Initialize ACL environment, setting up localhost and localnets ACLs
170 dns_aclenv_copy(dns_aclenv_t *t, dns_aclenv_t *s);
173 dns_aclenv_destroy(dns_aclenv_t *env);
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,
181 const dns_aclelement_t **matchelt);
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
201 *\li #ISC_R_SUCCESS Always succeeds.
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);
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.
222 #endif /* DNS_ACL_H */