Lines Matching defs:portlist

9 /* $Id: portlist.c,v 1.13 2007/06/19 23:47:16 tbox Exp $ */
28 #include <dns/portlist.h>
66 dns_portlist_t *portlist;
71 portlist = isc_mem_get(mctx, sizeof(*portlist));
72 if (portlist == NULL)
74 result = isc_mutex_init(&portlist->lock);
76 isc_mem_put(mctx, portlist, sizeof(*portlist));
79 result = isc_refcount_init(&portlist->refcount, 1);
81 DESTROYLOCK(&portlist->lock);
82 isc_mem_put(mctx, portlist, sizeof(*portlist));
85 portlist->list = NULL;
86 portlist->allocated = 0;
87 portlist->active = 0;
88 portlist->mctx = NULL;
89 isc_mem_attach(mctx, &portlist->mctx);
90 portlist->magic = DNS_PORTLIST_MAGIC;
91 *portlistp = portlist;
129 dns_portlist_add(dns_portlist_t *portlist, int af, in_port_t port) {
133 REQUIRE(DNS_VALID_PORTLIST(portlist));
136 LOCK(&portlist->lock);
137 if (portlist->active != 0) {
138 el = find_port(portlist->list, portlist->active, port);
149 if (portlist->allocated <= portlist->active) {
151 allocated = portlist->allocated + DNS_PL_ALLOCATE;
152 el = isc_mem_get(portlist->mctx, sizeof(*el) * allocated);
157 if (portlist->list != NULL) {
158 memmove(el, portlist->list,
159 portlist->allocated * sizeof(*el));
160 isc_mem_put(portlist->mctx, portlist->list,
161 portlist->allocated * sizeof(*el));
163 portlist->list = el;
164 portlist->allocated = allocated;
166 portlist->list[portlist->active].port = port;
168 portlist->list[portlist->active].flags = DNS_PL_INET;
170 portlist->list[portlist->active].flags = DNS_PL_INET6;
171 portlist->active++;
172 qsort(portlist->list, portlist->active, sizeof(*el), compare);
175 UNLOCK(&portlist->lock);
180 dns_portlist_remove(dns_portlist_t *portlist, int af, in_port_t port) {
183 REQUIRE(DNS_VALID_PORTLIST(portlist));
186 LOCK(&portlist->lock);
187 if (portlist->active != 0) {
188 el = find_port(portlist->list, portlist->active, port);
195 *el = portlist->list[portlist->active];
196 portlist->active--;
197 qsort(portlist->list, portlist->active,
202 UNLOCK(&portlist->lock);
206 dns_portlist_match(dns_portlist_t *portlist, int af, in_port_t port) {
210 REQUIRE(DNS_VALID_PORTLIST(portlist));
212 LOCK(&portlist->lock);
213 if (portlist->active != 0) {
214 el = find_port(portlist->list, portlist->active, port);
222 UNLOCK(&portlist->lock);
227 dns_portlist_attach(dns_portlist_t *portlist, dns_portlist_t **portlistp) {
229 REQUIRE(DNS_VALID_PORTLIST(portlist));
232 isc_refcount_increment(&portlist->refcount, NULL);
233 *portlistp = portlist;
238 dns_portlist_t *portlist;
242 portlist = *portlistp;
243 REQUIRE(DNS_VALID_PORTLIST(portlist));
245 isc_refcount_decrement(&portlist->refcount, &count);
247 portlist->magic = 0;
248 isc_refcount_destroy(&portlist->refcount);
249 if (portlist->list != NULL)
250 isc_mem_put(portlist->mctx, portlist->list,
251 portlist->allocated *
252 sizeof(*portlist->list));
253 DESTROYLOCK(&portlist->lock);
254 isc_mem_putanddetach(&portlist->mctx, portlist,
255 sizeof(*portlist));