2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 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: listenlist.c,v 1.14 2007/06/19 23:46:59 tbox Exp $ */
29 #include <named/listenlist.h>
32 destroy(ns_listenlist_t *list);
35 ns_listenelt_create(isc_mem_t *mctx, in_port_t port,
36 dns_acl_t *acl, ns_listenelt_t **target)
38 ns_listenelt_t *elt = NULL;
39 REQUIRE(target != NULL && *target == NULL);
40 elt = isc_mem_get(mctx, sizeof(*elt));
42 return (ISC_R_NOMEMORY);
44 ISC_LINK_INIT(elt, link);
48 return (ISC_R_SUCCESS);
52 ns_listenelt_destroy(ns_listenelt_t *elt) {
54 dns_acl_detach(&elt->acl);
55 isc_mem_put(elt->mctx, elt, sizeof(*elt));
59 ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target) {
60 ns_listenlist_t *list = NULL;
61 REQUIRE(target != NULL && *target == NULL);
62 list = isc_mem_get(mctx, sizeof(*list));
64 return (ISC_R_NOMEMORY);
67 ISC_LIST_INIT(list->elts);
69 return (ISC_R_SUCCESS);
73 destroy(ns_listenlist_t *list) {
74 ns_listenelt_t *elt, *next;
75 for (elt = ISC_LIST_HEAD(list->elts);
79 next = ISC_LIST_NEXT(elt, link);
80 ns_listenelt_destroy(elt);
82 isc_mem_put(list->mctx, list, sizeof(*list));
86 ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target) {
87 INSIST(source->refcount > 0);
93 ns_listenlist_detach(ns_listenlist_t **listp) {
94 ns_listenlist_t *list = *listp;
95 INSIST(list->refcount > 0);
97 if (list->refcount == 0)
103 ns_listenlist_default(isc_mem_t *mctx, in_port_t port,
104 isc_boolean_t enabled, ns_listenlist_t **target)
107 dns_acl_t *acl = NULL;
108 ns_listenelt_t *elt = NULL;
109 ns_listenlist_t *list = NULL;
111 REQUIRE(target != NULL && *target == NULL);
113 result = dns_acl_any(mctx, &acl);
115 result = dns_acl_none(mctx, &acl);
116 if (result != ISC_R_SUCCESS)
119 result = ns_listenelt_create(mctx, port, acl, &elt);
120 if (result != ISC_R_SUCCESS)
123 result = ns_listenlist_create(mctx, &list);
124 if (result != ISC_R_SUCCESS)
125 goto cleanup_listenelt;
127 ISC_LIST_APPEND(list->elts, elt, link);
130 return (ISC_R_SUCCESS);
133 ns_listenelt_destroy(elt);
135 dns_acl_detach(&acl);