peer.c revision 9c3531d72aeaad6c5f01efe6a1c82023e1379e4d
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister/*
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley * Copyright (C) 2000 Internet Software Consortium.
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * Permission to use, copy, modify, and distribute this software for any
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * purpose with or without fee is hereby granted, provided that the above
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * copyright notice and this permission notice appear in all copies.
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * SOFTWARE.
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister */
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence/* $Id: peer.c,v 1.8 2000/06/22 21:54:35 tale Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <config.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/mem.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/string.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <isc/util.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence#include <dns/bit.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <dns/name.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <dns/peer.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister/*
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * Bit positions in the dns_peer_t structure flags field
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister */
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#define BOGUS_BIT 0
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#define SERVER_TRANSFER_FORMAT_BIT 1
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#define TRANSFERS_BIT 2
72166c5cf59db011cce11e98abe377f5aa6f7052Andreas Gustafsson#define PROVIDE_IXFR_BIT 3
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister#define REQUEST_IXFR_BIT 4
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrencestatic isc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peerlist_delete(dns_peerlist_t **list);
b3e77535185043f089b346166440402d092030c3David Lawrence
b3e77535185043f089b346166440402d092030c3David Lawrencestatic isc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_delete(dns_peer_t **peer);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peerlist_t *l;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(list != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l = isc_mem_get(mem, sizeof *l);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (l == NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_NOMEMORY);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ISC_LIST_INIT(l->elements);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->mem = mem;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->refs = 1;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->magic = DNS_PEERLIST_MAGIC;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *list = l;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristervoid
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEERLIST_VALID(source));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(target != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(*target == NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister source->refs++;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ENSURE(source->refs != 0xffffffffU);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *target = source;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristervoid
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peerlist_detach(dns_peerlist_t **list) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peerlist_t *plist;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(list != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(*list != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEERLIST_VALID(*list));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister plist = *list;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *list = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(plist->refs > 0);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister plist->refs--;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (plist->refs == 0) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peerlist_delete(&plist);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peerlist_delete(dns_peerlist_t **list) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peerlist_t *l;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *server, *stmp;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_result_t r;
b3e77535185043f089b346166440402d092030c3David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(list != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEERLIST_VALID(*list));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l = *list;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(l->refs == 0);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister server = ISC_LIST_HEAD(l->elements);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister while (server != NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister stmp = ISC_LIST_NEXT(server, next);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ISC_LIST_UNLINK(l->elements, server, next);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister r = dns_peer_detach(&server);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (r != ISC_R_SUCCESS) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (r);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister server = stmp;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->magic = 0;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_mem_put(l->mem, l, sizeof *l);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *list = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristervoid
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *p = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_attach(peer, &p);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ISC_LIST_APPEND(peers->elements, peer, next);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerdns_peerlist_peerbyaddr(dns_peerlist_t *servers,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_netaddr_t *addr, dns_peer_t **retval)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister{
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *server;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_result_t res;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(retval != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEERLIST_VALID(servers));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister server = ISC_LIST_HEAD(servers->elements);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister while (server != NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (isc_netaddr_equal(addr, &server->address)) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister break;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister server = ISC_LIST_NEXT(server, next);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (server != NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *retval = server;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister res = ISC_R_SUCCESS;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister } else {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister res = ISC_R_NOTFOUND;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (res);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *p = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p = ISC_LIST_TAIL(peers->elements);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_attach(p, retval);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *peer;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(peerptr != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer = isc_mem_get(mem, sizeof *peer);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (peer == NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_NOMEMORY);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->magic = DNS_PEER_MAGIC;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->address = *addr;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->mem = mem;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->bogus = ISC_FALSE;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->transfer_format = dns_one_answer;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->transfers = 0;
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister peer->request_ixfr = ISC_FALSE;
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister peer->provide_ixfr = ISC_FALSE;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->key = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->refs = 1;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister memset(&peer->bitflags, 0x0, sizeof peer->bitflags);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ISC_LINK_INIT(peer, next);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *peerptr = peer;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(source));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(target != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(*target == NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister source->refs++;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ENSURE(source->refs != 0xffffffffU);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *target = source;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_detach(dns_peer_t **peer) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *p;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(peer != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(*peer != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(*peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p = *peer;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(p->refs > 0);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *peer = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p->refs--;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (p->refs == 0) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_delete(&p);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerstatic isc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_delete(dns_peer_t **peer) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *p;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_mem_t *mem;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(peer != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(*peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p = *peer;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(p->refs == 0);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister mem = p->mem;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p->mem = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p->magic = 0;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (p->key != NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_name_free(p->key, mem);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_mem_put(mem, p->key, sizeof(dns_name_t));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_mem_put(mem, p, sizeof *p);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *peer = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_setbogus(dns_peer_t *peer, isc_boolean_t newval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_boolean_t existed;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->bogus = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_getbogus(dns_peer_t *peer, isc_boolean_t *retval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(retval != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *retval = peer->bogus;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
b3e77535185043f089b346166440402d092030c3David Lawrence } else
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_NOTFOUND);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_setprovideixfr(dns_peer_t *peer, isc_boolean_t newval) {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister isc_boolean_t existed;
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(DNS_PEER_VALID(peer));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister peer->provide_ixfr = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister}
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_getprovideixfr(dns_peer_t *peer, isc_boolean_t *retval) {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(DNS_PEER_VALID(peer));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(retval != NULL);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister *retval = peer->provide_ixfr;
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister return (ISC_R_SUCCESS);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister } else {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister return (ISC_R_NOTFOUND);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister }
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister}
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_setrequestixfr(dns_peer_t *peer, isc_boolean_t newval) {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister isc_boolean_t existed;
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(DNS_PEER_VALID(peer));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister peer->request_ixfr = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister}
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_getrequestixfr(dns_peer_t *peer, isc_boolean_t *retval) {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(DNS_PEER_VALID(peer));
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(retval != NULL);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) {
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister *retval = peer->request_ixfr;
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister return (ISC_R_SUCCESS);
b3e77535185043f089b346166440402d092030c3David Lawrence } else
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister return (ISC_R_NOTFOUND);
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister}
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_settransfers(dns_peer_t *peer, isc_int32_t newval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_boolean_t existed;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->transfers = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_gettransfers(dns_peer_t *peer, isc_int32_t *retval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(retval != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence if (DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags)) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *retval = peer->transfers;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister } else {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_NOTFOUND);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_settransferformat(dns_peer_t *peer, dns_transfer_format_t newval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_boolean_t existed;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister &peer->bitflags);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->transfer_format = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_gettransferformat(dns_peer_t *peer, dns_transfer_format_t *retval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(retval != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence if (DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags)) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *retval = peer->transfer_format;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister } else {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_NOTFOUND);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_getkey(dns_peer_t *peer, dns_name_t **retval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(retval != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (peer->key != NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *retval = peer->key;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (peer->key == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_setkey(dns_peer_t *peer, dns_name_t **keyval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_boolean_t exists = ISC_FALSE;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister if (peer->key != NULL) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_name_free(peer->key, peer->mem);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_mem_put(peer->mem, peer->key, sizeof(dns_name_t));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister exists = ISC_TRUE;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->key = *keyval;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *keyval = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}