peer.c revision 08c90261660649ca7d92065f6f13a61ec5a9a86d
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/*
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Permission to use, copy, modify, and distribute this software for any
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * purpose with or without fee is hereby granted, provided that the above
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * copyright notice and this permission notice appear in all copies.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * PERFORMANCE OF THIS SOFTWARE.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/* $Id: peer.c,v 1.24 2006/01/05 00:01:46 marka Exp $ */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/*! \file */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <config.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <isc/mem.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <isc/string.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <isc/util.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <isc/sockaddr.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <dns/bit.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <dns/fixedname.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <dns/name.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <dns/peer.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/*%
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Bit positions in the dns_peer_t structure flags field
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define BOGUS_BIT 0
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define SERVER_TRANSFER_FORMAT_BIT 1
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define TRANSFERS_BIT 2
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define PROVIDE_IXFR_BIT 3
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define REQUEST_IXFR_BIT 4
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define SUPPORT_EDNS_BIT 5
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define SERVER_UDPSIZE_BIT 6
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define SERVER_MAXUDP_BIT 7
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic void
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleypeerlist_delete(dns_peerlist_t **list);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic void
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleypeer_delete(dns_peer_t **peer);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleyisc_result_t
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley dns_peerlist_t *l;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(list != NULL);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley l = isc_mem_get(mem, sizeof(*l));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (l == NULL)
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley return (ISC_R_NOMEMORY);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ISC_LIST_INIT(l->elements);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley l->mem = mem;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley l->refs = 1;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley l->magic = DNS_PEERLIST_MAGIC;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *list = l;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley return (ISC_R_SUCCESS);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleyvoid
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(DNS_PEERLIST_VALID(source));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(target != NULL);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(*target == NULL);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley source->refs++;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ENSURE(source->refs != 0xffffffffU);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *target = source;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleyvoid
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_peerlist_detach(dns_peerlist_t **list) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley dns_peerlist_t *plist;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(list != NULL);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(*list != NULL);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(DNS_PEERLIST_VALID(*list));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley plist = *list;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *list = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(plist->refs > 0);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley plist->refs--;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (plist->refs == 0)
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley peerlist_delete(&plist);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley}
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleystatic void
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleypeerlist_delete(dns_peerlist_t **list) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley dns_peerlist_t *l;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley dns_peer_t *server, *stmp;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(list != NULL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEERLIST_VALID(*list));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley l = *list;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(l->refs == 0);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley server = ISC_LIST_HEAD(l->elements);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley while (server != NULL) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley stmp = ISC_LIST_NEXT(server, next);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ISC_LIST_UNLINK(l->elements, server, next);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley dns_peer_detach(&server);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley server = stmp;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley }
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley l->magic = 0;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley isc_mem_put(l->mem, l, sizeof(*l));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *list = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halleyvoid
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleydns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley dns_peer_t *p = NULL;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley dns_peer_attach(peer, &p);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley /*
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley * More specifics to front of list.
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley */
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley for (p = ISC_LIST_HEAD(peers->elements);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley p != NULL;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley p = ISC_LIST_NEXT(p, next))
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley if (p->prefixlen < peer->prefixlen)
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley break;
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley if (p != NULL)
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley else
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley ISC_LIST_APPEND(peers->elements, peer, next);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley}
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleyisc_result_t
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleydns_peerlist_peerbyaddr(dns_peerlist_t *servers,
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley isc_netaddr_t *addr, dns_peer_t **retval)
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley{
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley dns_peer_t *server;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley isc_result_t res;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley REQUIRE(retval != NULL);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley REQUIRE(DNS_PEERLIST_VALID(servers));
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley server = ISC_LIST_HEAD(servers->elements);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley while (server != NULL) {
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley if (isc_netaddr_eqprefix(addr, &server->address,
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley server->prefixlen))
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley break;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley server = ISC_LIST_NEXT(server, next);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley }
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (server != NULL) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *retval = server;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley res = ISC_R_SUCCESS;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley } else {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley res = ISC_R_NOTFOUND;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley }
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley return (res);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley}
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleyisc_result_t
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleydns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley dns_peer_t *p = NULL;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley p = ISC_LIST_TAIL(peers->elements);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley dns_peer_attach(p, retval);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley return (ISC_R_SUCCESS);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley}
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleyisc_result_t
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleydns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley unsigned int prefixlen = 0;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley REQUIRE(peerptr != NULL);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley switch(addr->family) {
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley case AF_INET:
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley prefixlen = 32;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley break;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley case AF_INET6:
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley prefixlen = 128;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley break;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley default:
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley INSIST(0);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley }
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley return (dns_peer_newprefix(mem, addr, prefixlen, peerptr));
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley}
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleyisc_result_t
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleydns_peer_newprefix(isc_mem_t *mem, isc_netaddr_t *addr, unsigned int prefixlen,
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley dns_peer_t **peerptr)
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley{
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley dns_peer_t *peer;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley REQUIRE(peerptr != NULL);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley peer = isc_mem_get(mem, sizeof(*peer));
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley if (peer == NULL)
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley return (ISC_R_NOMEMORY);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->magic = DNS_PEER_MAGIC;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley peer->address = *addr;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->prefixlen = prefixlen;
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley peer->mem = mem;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->bogus = ISC_FALSE;
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley peer->transfer_format = dns_one_answer;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->transfers = 0;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->request_ixfr = ISC_FALSE;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->provide_ixfr = ISC_FALSE;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->key = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->refs = 1;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley peer->transfer_source = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley memset(&peer->bitflags, 0x0, sizeof(peer->bitflags));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ISC_LINK_INIT(peer, next);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *peerptr = peer;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley return (ISC_R_SUCCESS);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halleyvoid
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley REQUIRE(DNS_PEER_VALID(source));
08af8bf5ade4131fe44926ad04fd489e64a620bbBob Halley REQUIRE(target != NULL);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley REQUIRE(*target == NULL);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley source->refs++;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ENSURE(source->refs != 0xffffffffU);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley *target = source;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleyvoid
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleydns_peer_detach(dns_peer_t **peer) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley dns_peer_t *p;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(peer != NULL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(*peer != NULL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(*peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley p = *peer;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(p->refs > 0);
569d094440399b000e059d4cb3434391c2c4d330Michael Graff
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *peer = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley p->refs--;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley if (p->refs == 0)
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley peer_delete(&p);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleystatic void
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleypeer_delete(dns_peer_t **peer) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley dns_peer_t *p;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley isc_mem_t *mem;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(peer != NULL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(*peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley p = *peer;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(p->refs == 0);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley mem = p->mem;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley p->mem = NULL;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley p->magic = 0;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley if (p->key != NULL) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley dns_name_free(p->key, mem);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_mem_put(mem, p->key, sizeof(dns_name_t));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley }
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley if (p->transfer_source != NULL) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_mem_put(mem, p->transfer_source,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley sizeof(*p->transfer_source));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley }
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_mem_put(mem, p, sizeof(*p));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley *peer = NULL;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleyisc_result_t
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleydns_peer_setbogus(dns_peer_t *peer, isc_boolean_t newval) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_boolean_t existed;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley peer->bogus = newval;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleyisc_result_t
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleydns_peer_getbogus(dns_peer_t *peer, isc_boolean_t *retval) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(retval != NULL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley *retval = peer->bogus;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (ISC_R_SUCCESS);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley } else
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (ISC_R_NOTFOUND);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleyisc_result_t
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleydns_peer_setprovideixfr(dns_peer_t *peer, isc_boolean_t newval) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_boolean_t existed;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley peer->provide_ixfr = newval;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleyisc_result_t
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleydns_peer_getprovideixfr(dns_peer_t *peer, isc_boolean_t *retval) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(retval != NULL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley *retval = peer->provide_ixfr;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (ISC_R_SUCCESS);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley } else {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (ISC_R_NOTFOUND);
c866769e664ba0a6a5e6f9375245f5ccca393009David Lawrence }
c866769e664ba0a6a5e6f9375245f5ccca393009David Lawrence}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
c866769e664ba0a6a5e6f9375245f5ccca393009David Lawrenceisc_result_t
c866769e664ba0a6a5e6f9375245f5ccca393009David Lawrencedns_peer_setrequestixfr(dns_peer_t *peer, isc_boolean_t newval) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_boolean_t existed;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley peer->request_ixfr = newval;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley}
c866769e664ba0a6a5e6f9375245f5ccca393009David Lawrence
c866769e664ba0a6a5e6f9375245f5ccca393009David Lawrenceisc_result_t
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleydns_peer_getrequestixfr(dns_peer_t *peer, isc_boolean_t *retval) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(DNS_PEER_VALID(peer));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley REQUIRE(retval != NULL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley 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_setsupportedns(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags);
peer->support_edns = newval;
DNS_BIT_SET(SUPPORT_EDNS_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getsupportedns(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) {
*retval = peer->support_edns;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_settransfers(dns_peer_t *peer, isc_uint32_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_uint32_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);
}
isc_result_t
dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) {
isc_buffer_t b;
dns_fixedname_t fname;
dns_name_t *name;
isc_result_t result;
dns_fixedname_init(&fname);
isc_buffer_init(&b, keyval, strlen(keyval));
isc_buffer_add(&b, strlen(keyval));
result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
dns_rootname, ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS)
return (result);
name = isc_mem_get(peer->mem, sizeof(dns_name_t));
if (name == NULL)
return (ISC_R_NOMEMORY);
dns_name_init(name, NULL);
result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name);
if (result != ISC_R_SUCCESS) {
isc_mem_put(peer->mem, name, sizeof(dns_name_t));
return (result);
}
result = dns_peer_setkey(peer, &name);
if (result != ISC_R_SUCCESS)
isc_mem_put(peer->mem, name, sizeof(dns_name_t));
return (result);
}
isc_result_t
dns_peer_settransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
REQUIRE(DNS_PEER_VALID(peer));
if (peer->transfer_source != NULL) {
isc_mem_put(peer->mem, peer->transfer_source,
sizeof(*peer->transfer_source));
peer->transfer_source = NULL;
}
if (transfer_source != NULL) {
peer->transfer_source = isc_mem_get(peer->mem,
sizeof(*peer->transfer_source));
if (peer->transfer_source == NULL)
return (ISC_R_NOMEMORY);
*peer->transfer_source = *transfer_source;
}
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(transfer_source != NULL);
if (peer->transfer_source == NULL)
return (ISC_R_NOTFOUND);
*transfer_source = *peer->transfer_source;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setudpsize(dns_peer_t *peer, isc_uint16_t udpsize) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags);
peer->udpsize = udpsize;
DNS_BIT_SET(SERVER_UDPSIZE_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getudpsize(dns_peer_t *peer, isc_uint16_t *udpsize) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(udpsize != NULL);
if (DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags)) {
*udpsize = peer->udpsize;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_setmaxudp(dns_peer_t *peer, isc_uint16_t maxudp) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags);
peer->maxudp = maxudp;
DNS_BIT_SET(SERVER_MAXUDP_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getmaxudp(dns_peer_t *peer, isc_uint16_t *maxudp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(maxudp != NULL);
if (DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags)) {
*maxudp = peer->maxudp;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}