0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2003-2007, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: portlist.c,v 1.13 2007/06/19 23:47:16 tbox Exp $ */
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews#define DNS_PORTLIST_MAGIC ISC_MAGIC('P','L','S','T')
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews#define DNS_VALID_PORTLIST(p) ISC_MAGIC_VALID(p, DNS_PORTLIST_MAGIC)
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews const dns_element_t *e1 = (const dns_element_t *)arg1;
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews const dns_element_t *e2 = (const dns_element_t *)arg2;
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews return (-1);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsdns_portlist_create(isc_mem_t *mctx, dns_portlist_t **portlistp) {
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews REQUIRE(portlistp != NULL && *portlistp == NULL);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews portlist = isc_mem_get(mctx, sizeof(*portlist));
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews isc_mem_put(mctx, portlist, sizeof(*portlist));
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews result = isc_refcount_init(&portlist->refcount, 1);
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews isc_mem_put(mctx, portlist, sizeof(*portlist));
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsfind_port(dns_element_t *list, unsigned int len, in_port_t port) {
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsdns_portlist_add(dns_portlist_t *portlist, int af, in_port_t port) {
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews el = find_port(portlist->list, portlist->active, port);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews allocated = portlist->allocated + DNS_PL_ALLOCATE;
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews el = isc_mem_get(portlist->mctx, sizeof(*el) * allocated);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews portlist->list[portlist->active].flags = DNS_PL_INET;
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews portlist->list[portlist->active].flags = DNS_PL_INET6;
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews qsort(portlist->list, portlist->active, sizeof(*el), compare);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsdns_portlist_remove(dns_portlist_t *portlist, int af, in_port_t port) {
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews el = find_port(portlist->list, portlist->active, port);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsdns_portlist_match(dns_portlist_t *portlist, int af, in_port_t port) {
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews el = find_port(portlist->list, portlist->active, port);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews if (af == AF_INET && (el->flags & DNS_PL_INET) != 0)
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews if (af == AF_INET6 && (el->flags & DNS_PL_INET6) != 0)
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsdns_portlist_attach(dns_portlist_t *portlist, dns_portlist_t **portlistp) {
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews REQUIRE(portlistp != NULL && *portlistp == NULL);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews isc_refcount_increment(&portlist->refcount, NULL);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsdns_portlist_detach(dns_portlist_t **portlistp) {
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews isc_refcount_decrement(&portlist->refcount, &count);