2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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: listenlist.c,v 1.9.208.1 2004/03/06 10:21:18 marka Exp $ */
27 #include <named/listenlist.h>
30 destroy(ns_listenlist_t *list);
33 ns_listenelt_create(isc_mem_t *mctx, in_port_t port,
34 dns_acl_t *acl, ns_listenelt_t **target)
36 ns_listenelt_t *elt = NULL;
37 REQUIRE(target != NULL && *target == NULL);
38 elt = isc_mem_get(mctx, sizeof(*elt));
40 return (ISC_R_NOMEMORY);
42 ISC_LINK_INIT(elt, link);
46 return (ISC_R_SUCCESS);
50 ns_listenelt_destroy(ns_listenelt_t *elt) {
52 dns_acl_detach(&elt->acl);
53 isc_mem_put(elt->mctx, elt, sizeof(*elt));
57 ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target) {
58 ns_listenlist_t *list = NULL;
59 REQUIRE(target != NULL && *target == NULL);
60 list = isc_mem_get(mctx, sizeof(*list));
62 return (ISC_R_NOMEMORY);
65 ISC_LIST_INIT(list->elts);
67 return (ISC_R_SUCCESS);
71 destroy(ns_listenlist_t *list) {
72 ns_listenelt_t *elt, *next;
73 for (elt = ISC_LIST_HEAD(list->elts);
77 next = ISC_LIST_NEXT(elt, link);
78 ns_listenelt_destroy(elt);
80 isc_mem_put(list->mctx, list, sizeof(*list));
84 ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target) {
85 INSIST(source->refcount > 0);
91 ns_listenlist_detach(ns_listenlist_t **listp) {
92 ns_listenlist_t *list = *listp;
93 INSIST(list->refcount > 0);
95 if (list->refcount == 0)
101 ns_listenlist_default(isc_mem_t *mctx, in_port_t port,
102 isc_boolean_t enabled, ns_listenlist_t **target)
105 dns_acl_t *acl = NULL;
106 ns_listenelt_t *elt = NULL;
107 ns_listenlist_t *list = NULL;
109 REQUIRE(target != NULL && *target == NULL);
111 result = dns_acl_any(mctx, &acl);
113 result = dns_acl_none(mctx, &acl);
114 if (result != ISC_R_SUCCESS)
117 result = ns_listenelt_create(mctx, port, acl, &elt);
118 if (result != ISC_R_SUCCESS)
121 result = ns_listenlist_create(mctx, &list);
122 if (result != ISC_R_SUCCESS)
123 goto cleanup_listenelt;
125 ISC_LIST_APPEND(list->elts, elt, link);
128 return (ISC_R_SUCCESS);
131 ns_listenelt_destroy(elt);
133 dns_acl_detach(&acl);