Lines Matching refs:portlist
18 /* $Id: portlist.c,v 1.13 2007/06/19 23:47:16 tbox Exp $ */
37 #include <dns/portlist.h>
75 dns_portlist_t *portlist;
80 portlist = isc_mem_get(mctx, sizeof(*portlist));
81 if (portlist == NULL)
83 result = isc_mutex_init(&portlist->lock);
85 isc_mem_put(mctx, portlist, sizeof(*portlist));
88 result = isc_refcount_init(&portlist->refcount, 1);
90 DESTROYLOCK(&portlist->lock);
91 isc_mem_put(mctx, portlist, sizeof(*portlist));
94 portlist->list = NULL;
95 portlist->allocated = 0;
96 portlist->active = 0;
97 portlist->mctx = NULL;
98 isc_mem_attach(mctx, &portlist->mctx);
99 portlist->magic = DNS_PORTLIST_MAGIC;
100 *portlistp = portlist;
138 dns_portlist_add(dns_portlist_t *portlist, int af, in_port_t port) {
142 REQUIRE(DNS_VALID_PORTLIST(portlist));
145 LOCK(&portlist->lock);
146 if (portlist->active != 0) {
147 el = find_port(portlist->list, portlist->active, port);
158 if (portlist->allocated <= portlist->active) {
160 allocated = portlist->allocated + DNS_PL_ALLOCATE;
161 el = isc_mem_get(portlist->mctx, sizeof(*el) * allocated);
166 if (portlist->list != NULL) {
167 memmove(el, portlist->list,
168 portlist->allocated * sizeof(*el));
169 isc_mem_put(portlist->mctx, portlist->list,
170 portlist->allocated * sizeof(*el));
172 portlist->list = el;
173 portlist->allocated = allocated;
175 portlist->list[portlist->active].port = port;
177 portlist->list[portlist->active].flags = DNS_PL_INET;
179 portlist->list[portlist->active].flags = DNS_PL_INET6;
180 portlist->active++;
181 qsort(portlist->list, portlist->active, sizeof(*el), compare);
184 UNLOCK(&portlist->lock);
189 dns_portlist_remove(dns_portlist_t *portlist, int af, in_port_t port) {
192 REQUIRE(DNS_VALID_PORTLIST(portlist));
195 LOCK(&portlist->lock);
196 if (portlist->active != 0) {
197 el = find_port(portlist->list, portlist->active, port);
204 *el = portlist->list[portlist->active];
205 portlist->active--;
206 qsort(portlist->list, portlist->active,
211 UNLOCK(&portlist->lock);
215 dns_portlist_match(dns_portlist_t *portlist, int af, in_port_t port) {
219 REQUIRE(DNS_VALID_PORTLIST(portlist));
221 LOCK(&portlist->lock);
222 if (portlist->active != 0) {
223 el = find_port(portlist->list, portlist->active, port);
231 UNLOCK(&portlist->lock);
236 dns_portlist_attach(dns_portlist_t *portlist, dns_portlist_t **portlistp) {
238 REQUIRE(DNS_VALID_PORTLIST(portlist));
241 isc_refcount_increment(&portlist->refcount, NULL);
242 *portlistp = portlist;
247 dns_portlist_t *portlist;
251 portlist = *portlistp;
252 REQUIRE(DNS_VALID_PORTLIST(portlist));
254 isc_refcount_decrement(&portlist->refcount, &count);
256 portlist->magic = 0;
257 isc_refcount_destroy(&portlist->refcount);
258 if (portlist->list != NULL)
259 isc_mem_put(portlist->mctx, portlist->list,
260 portlist->allocated *
261 sizeof(*portlist->list));
262 DESTROYLOCK(&portlist->lock);
263 isc_mem_putanddetach(&portlist->mctx, portlist,
264 sizeof(*portlist));