portlist.c revision 12040a4f5c29f430cc3e0ced6b912b8cf7f5d301
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater * Copyright (C) 2003 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews/* $Id: portlist.c,v 1.4 2003/10/01 00:58:07 marka Exp $ */
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews#define DNS_PORTLIST_MAGIC ISC_MAGIC('P','L','S','T')
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define DNS_VALID_PORTLIST(p) ISC_MAGIC_VALID(p, DNS_PORTLIST_MAGIC)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleytypedef struct dns_element {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley unsigned int magic;
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley unsigned int allocated;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley unsigned int active;
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews const dns_element_t *e1 = (const dns_element_t *)arg1;
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley const dns_element_t *e2 = (const dns_element_t *)arg2;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley return (-1);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleydns_portlist_create(isc_mem_t *mctx, dns_portlist_t **portlistp) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(portlistp != NULL && *portlistp == NULL);
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews "isc_mutex_init() failed: %s",
0180ccf72c79b98eb8ee5abbb7331aec6951dd9fBob Halleyfind_port(dns_element_t *list, unsigned int len, in_port_t port) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley unsigned int min = 0;
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halleydns_portlist_add(dns_portlist_t *portlist, int af, in_port_t port) {
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson el = find_port(portlist->list, portlist->active, port);
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson if (portlist->allocated <= portlist->active) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley allocated = portlist->allocated + DNS_PL_ALLOCATE;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley el = isc_mem_get(portlist->mctx, sizeof(*el) * allocated);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley portlist->list[portlist->active].flags = DNS_PL_INET;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley portlist->list[portlist->active].flags = DNS_PL_INET6;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley qsort(portlist->list, portlist->active, sizeof(*el), compare);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉dns_portlist_remove(dns_portlist_t *portlist, int af, in_port_t port) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley el = find_port(portlist->list, portlist->active, port);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halleydns_portlist_match(dns_portlist_t *portlist, int af, in_port_t port) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley el = find_port(portlist->list, portlist->active, port);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley if (af == AF_INET && (el->flags & DNS_PL_INET) != 0)
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley if (af == AF_INET6 && (el->flags & DNS_PL_INET6) != 0)
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halleydns_portlist_attach(dns_portlist_t *portlist, dns_portlist_t **portlistp) {
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley REQUIRE(portlistp != NULL && *portlistp == NULL);
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley isc_refcount_increment(&portlist->refcount, NULL);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley unsigned int count;