peer.c revision 15a44745412679c30a6d022733925af70a38b715
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000 Internet Software Consortium.
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews *
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews */
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews/* $Id: peer.c,v 1.9 2000/07/27 09:46:20 tale Exp $ */
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#include <config.h>
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#include <isc/mem.h>
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#include <isc/string.h>
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#include <isc/util.h>
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#include <dns/bit.h>
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#include <dns/name.h>
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#include <dns/peer.h>
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews/*
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews * Bit positions in the dns_peer_t structure flags field
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews */
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#define BOGUS_BIT 0
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#define SERVER_TRANSFER_FORMAT_BIT 1
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#define TRANSFERS_BIT 2
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#define PROVIDE_IXFR_BIT 3
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews#define REQUEST_IXFR_BIT 4
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peerlist_delete(dns_peerlist_t **list);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peer_delete(dns_peer_t **peer);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsisc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peerlist_t *l;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(list != NULL);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews l = isc_mem_get(mem, sizeof *l);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews if (l == NULL) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews return (ISC_R_NOMEMORY);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews }
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews ISC_LIST_INIT(l->elements);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews l->mem = mem;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews l->refs = 1;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews l->magic = DNS_PEERLIST_MAGIC;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews *list = l;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews return (ISC_R_SUCCESS);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews}
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsvoid
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(DNS_PEERLIST_VALID(source));
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(target != NULL);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(*target == NULL);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews source->refs++;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews ENSURE(source->refs != 0xffffffffU);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews *target = source;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews}
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsvoid
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peerlist_detach(dns_peerlist_t **list) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peerlist_t *plist;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(list != NULL);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(*list != NULL);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(DNS_PEERLIST_VALID(*list));
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews plist = *list;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews *list = NULL;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(plist->refs > 0);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews plist->refs--;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews if (plist->refs == 0) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peerlist_delete(&plist);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews }
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews}
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peerlist_delete(dns_peerlist_t **list) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peerlist_t *l;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peer_t *server, *stmp;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews isc_result_t r;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(list != NULL);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(DNS_PEERLIST_VALID(*list));
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews l = *list;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(l->refs == 0);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews server = ISC_LIST_HEAD(l->elements);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews while (server != NULL) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews stmp = ISC_LIST_NEXT(server, next);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews ISC_LIST_UNLINK(l->elements, server, next);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews r = dns_peer_detach(&server);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews if (r != ISC_R_SUCCESS) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews return (r);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews }
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews server = stmp;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews }
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews l->magic = 0;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews isc_mem_put(l->mem, l, sizeof *l);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews *list = NULL;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews return (ISC_R_SUCCESS);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews}
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsvoid
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peer_t *p = NULL;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peer_attach(peer, &p);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews ISC_LIST_APPEND(peers->elements, peer, next);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews}
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsisc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsdns_peerlist_peerbyaddr(dns_peerlist_t *servers,
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews isc_netaddr_t *addr, dns_peer_t **retval)
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews{
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews dns_peer_t *server;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews isc_result_t res;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(retval != NULL);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews REQUIRE(DNS_PEERLIST_VALID(servers));
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews server = ISC_LIST_HEAD(servers->elements);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews while (server != NULL) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews if (isc_netaddr_equal(addr, &server->address)) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews break;
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews }
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews server = ISC_LIST_NEXT(server, next);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews }
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews if (server != NULL) {
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews *retval = server;
res = ISC_R_SUCCESS;
} else {
res = ISC_R_NOTFOUND;
}
return (res);
}
isc_result_t
dns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
dns_peer_t *p = NULL;
p = ISC_LIST_TAIL(peers->elements);
dns_peer_attach(p, retval);
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
dns_peer_t *peer;
REQUIRE(peerptr != NULL);
peer = isc_mem_get(mem, sizeof *peer);
if (peer == NULL) {
return (ISC_R_NOMEMORY);
}
peer->magic = DNS_PEER_MAGIC;
peer->address = *addr;
peer->mem = mem;
peer->bogus = ISC_FALSE;
peer->transfer_format = dns_one_answer;
peer->transfers = 0;
peer->request_ixfr = ISC_FALSE;
peer->provide_ixfr = ISC_FALSE;
peer->key = NULL;
peer->refs = 1;
memset(&peer->bitflags, 0x0, sizeof peer->bitflags);
ISC_LINK_INIT(peer, next);
*peerptr = peer;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
REQUIRE(DNS_PEER_VALID(source));
REQUIRE(target != NULL);
REQUIRE(*target == NULL);
source->refs++;
ENSURE(source->refs != 0xffffffffU);
*target = source;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_detach(dns_peer_t **peer) {
dns_peer_t *p;
REQUIRE(peer != NULL);
REQUIRE(*peer != NULL);
REQUIRE(DNS_PEER_VALID(*peer));
p = *peer;
REQUIRE(p->refs > 0);
*peer = NULL;
p->refs--;
if (p->refs == 0) {
dns_peer_delete(&p);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
dns_peer_delete(dns_peer_t **peer) {
dns_peer_t *p;
isc_mem_t *mem;
REQUIRE(peer != NULL);
REQUIRE(DNS_PEER_VALID(*peer));
p = *peer;
REQUIRE(p->refs == 0);
mem = p->mem;
p->mem = NULL;
p->magic = 0;
if (p->key != NULL) {
dns_name_free(p->key, mem);
isc_mem_put(mem, p->key, sizeof(dns_name_t));
}
isc_mem_put(mem, p, sizeof *p);
*peer = NULL;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setbogus(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
peer->bogus = newval;
DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getbogus(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
*retval = peer->bogus;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_setprovideixfr(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
peer->provide_ixfr = newval;
DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getprovideixfr(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
*retval = peer->provide_ixfr;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_setrequestixfr(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
peer->request_ixfr = newval;
DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getrequestixfr(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) {
*retval = peer->request_ixfr;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_settransfers(dns_peer_t *peer, isc_int32_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
peer->transfers = newval;
DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_gettransfers(dns_peer_t *peer, isc_int32_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags)) {
*retval = peer->transfers;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_settransferformat(dns_peer_t *peer, dns_transfer_format_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
&peer->bitflags);
peer->transfer_format = newval;
DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_gettransferformat(dns_peer_t *peer, dns_transfer_format_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags)) {
*retval = peer->transfer_format;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_getkey(dns_peer_t *peer, dns_name_t **retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (peer->key != NULL) {
*retval = peer->key;
}
return (peer->key == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setkey(dns_peer_t *peer, dns_name_t **keyval) {
isc_boolean_t exists = ISC_FALSE;
if (peer->key != NULL) {
dns_name_free(peer->key, peer->mem);
isc_mem_put(peer->mem, peer->key, sizeof(dns_name_t));
exists = ISC_TRUE;
}
peer->key = *keyval;
*keyval = NULL;
return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
}