peer.c revision 67adc03ef81fb610f8df093b17f55275ee816754
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson/*
1b06367c345e972a0c719a6e821db3e875f20c3bMark Andrews * Copyright (C) 2004-2009, 2012 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * Permission to use, copy, modify, and/or distribute this software for any
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson */
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
a45a6ea2b03448751d7c44931e8ac7666e7cc2ceMark Andrews/* $Id: peer.c,v 1.33 2009/09/02 23:48:02 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson#include <config.h>
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington#include <isc/mem.h>
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington#include <isc/string.h>
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson#include <isc/util.h>
cc0a5f714231709409b9e1b85f0f97ae50854451Mark Andrews#include <isc/sockaddr.h>
6028d1ce0380d0ba7f6c6ecd1ad20b31ddd1becbDavid Lawrence
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <dns/bit.h>
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson#include <dns/fixedname.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/name.h>
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington#include <dns/peer.h>
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington/*%
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Bit positions in the dns_peer_t structure flags field
5afa531442369eed0e93a8af14422b30f400bd89Mark Andrews */
476386968b1f287a695f73c48862e961011af99bMark Andrews#define BOGUS_BIT 0
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson#define SERVER_TRANSFER_FORMAT_BIT 1
9259fed3d8ac5d1efa9b5a647969e40c9c934484Andreas Gustafsson#define TRANSFERS_BIT 2
3aca8e5bf3740bbcc3bb13dde242d7cc369abb27Mark Andrews#define PROVIDE_IXFR_BIT 3
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington#define REQUEST_IXFR_BIT 4
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson#define SUPPORT_EDNS_BIT 5
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson#define SERVER_UDPSIZE_BIT 6
62700b67eb8abb7d13f9c3c1bc4b60a1477d35d8Mark Andrews#define SERVER_MAXUDP_BIT 7
9259fed3d8ac5d1efa9b5a647969e40c9c934484Andreas Gustafsson#define REQUEST_NSID_BIT 8
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic void
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssonpeerlist_delete(dns_peerlist_t **list);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssonstatic void
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssonpeer_delete(dns_peer_t **peer);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssonisc_result_t
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssondns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson dns_peerlist_t *l;
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein REQUIRE(list != NULL);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson l = isc_mem_get(mem, sizeof(*l));
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson if (l == NULL)
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews return (ISC_R_NOMEMORY);
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews ISC_LIST_INIT(l->elements);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson l->mem = mem;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson l->refs = 1;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson l->magic = DNS_PEERLIST_MAGIC;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
7b68fa6229f1edadac44c7ec459c9ed77a8368c8Mark Andrews *list = l;
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_SUCCESS);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonvoid
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEERLIST_VALID(source));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(target != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(*target == NULL);
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington source->refs++;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ENSURE(source->refs != 0xffffffffU);
3eef7eaba00e9bd468d8036c709a296a0e5b76f1Andreas Gustafsson
7b68fa6229f1edadac44c7ec459c9ed77a8368c8Mark Andrews *target = source;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonvoid
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_detach(dns_peerlist_t **list) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson dns_peerlist_t *plist;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson REQUIRE(list != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(*list != NULL);
ad5bc22a819190839bdcc4d102d023782dc23660Mark Andrews REQUIRE(DNS_PEERLIST_VALID(*list));
ad5bc22a819190839bdcc4d102d023782dc23660Mark Andrews
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington plist = *list;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington *list = NULL;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(plist->refs > 0);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson plist->refs--;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (plist->refs == 0)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peerlist_delete(&plist);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsstatic void
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewspeerlist_delete(dns_peerlist_t **list) {
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews dns_peerlist_t *l;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_peer_t *server, *stmp;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(list != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEERLIST_VALID(*list));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
a687a0592bbe3a582860eb5f03725bf80d7ac1d8Mark Andrews l = *list;
a687a0592bbe3a582860eb5f03725bf80d7ac1d8Mark Andrews
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(l->refs == 0);
a687a0592bbe3a582860eb5f03725bf80d7ac1d8Mark Andrews
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington server = ISC_LIST_HEAD(l->elements);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington while (server != NULL) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington stmp = ISC_LIST_NEXT(server, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ISC_LIST_UNLINK(l->elements, server, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_peer_detach(&server);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington server = stmp;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington l->magic = 0;
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews isc_mem_put(l->mem, l, sizeof(*l));
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews *list = NULL;
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews}
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsvoid
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
0015ab097438e041197b19b9de2ba48f6bfd1c6cDavid Lawrence dns_peer_t *p = NULL;
0015ab097438e041197b19b9de2ba48f6bfd1c6cDavid Lawrence
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_peer_attach(peer, &p);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington /*
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * More specifics to front of list.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington */
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington for (p = ISC_LIST_HEAD(peers->elements);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington p != NULL;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington p = ISC_LIST_NEXT(p, next))
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (p->prefixlen < peer->prefixlen)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington break;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (p != NULL)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington else
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ISC_LIST_APPEND(peers->elements, peer, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_peerbyaddr(dns_peerlist_t *servers,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_netaddr_t *addr, dns_peer_t **retval)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington{
6e373c502584f9292e964378411d296c8259026bMark Andrews dns_peer_t *server;
6e373c502584f9292e964378411d296c8259026bMark Andrews isc_result_t res;
6e373c502584f9292e964378411d296c8259026bMark Andrews
6e373c502584f9292e964378411d296c8259026bMark Andrews REQUIRE(retval != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEERLIST_VALID(servers));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington server = ISC_LIST_HEAD(servers->elements);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington while (server != NULL) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (isc_netaddr_eqprefix(addr, &server->address,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington server->prefixlen))
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington break;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington server = ISC_LIST_NEXT(server, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (server != NULL) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington *retval = server;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington res = ISC_R_SUCCESS;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington } else {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington res = ISC_R_NOTFOUND;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (res);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_peer_t *p = NULL;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington p = ISC_LIST_TAIL(peers->elements);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_peer_attach(p, retval);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington unsigned int prefixlen = 0;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(peerptr != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington switch(addr->family) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington case AF_INET:
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington prefixlen = 32;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington break;
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews case AF_INET6:
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington prefixlen = 128;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington break;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington default:
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington INSIST(0);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews return (dns_peer_newprefix(mem, addr, prefixlen, peerptr));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_newprefix(isc_mem_t *mem, isc_netaddr_t *addr, unsigned int prefixlen,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_peer_t **peerptr)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington{
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_peer_t *peer;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(peerptr != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer = isc_mem_get(mem, sizeof(*peer));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (peer == NULL)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_NOMEMORY);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->magic = DNS_PEER_MAGIC;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->address = *addr;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->prefixlen = prefixlen;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->mem = mem;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->bogus = ISC_FALSE;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->transfer_format = dns_one_answer;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->transfers = 0;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->request_ixfr = ISC_FALSE;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->provide_ixfr = ISC_FALSE;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->key = NULL;
6889d57aabc5f48eaee78894e20054215319b461Andreas Gustafsson peer->refs = 1;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->transfer_source = NULL;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->notify_source = NULL;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->query_source = NULL;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington memset(&peer->bitflags, 0x0, sizeof(peer->bitflags));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ISC_LINK_INIT(peer, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington *peerptr = peer;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsvoid
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsdns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEER_VALID(source));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(target != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(*target == NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington source->refs++;
6889d57aabc5f48eaee78894e20054215319b461Andreas Gustafsson
6889d57aabc5f48eaee78894e20054215319b461Andreas Gustafsson ENSURE(source->refs != 0xffffffffU);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson *target = source;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson}
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
d5e72d5dba7b77ae0036c53578bcabcf3af1f4b7Andreas Gustafssonvoid
d5e72d5dba7b77ae0036c53578bcabcf3af1f4b7Andreas Gustafssondns_peer_detach(dns_peer_t **peer) {
d5e72d5dba7b77ae0036c53578bcabcf3af1f4b7Andreas Gustafsson dns_peer_t *p;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(peer != NULL);
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(*peer != NULL);
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(DNS_PEER_VALID(*peer));
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson p = *peer;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(p->refs > 0);
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson *peer = NULL;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson p->refs--;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson if (p->refs == 0)
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson peer_delete(&p);
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson}
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafssonstatic void
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafssonpeer_delete(dns_peer_t **peer) {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson dns_peer_t *p;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson isc_mem_t *mem;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(peer != NULL);
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(DNS_PEER_VALID(*peer));
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson p = *peer;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(p->refs == 0);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson mem = p->mem;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson p->mem = NULL;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson p->magic = 0;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson if (p->key != NULL) {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson dns_name_free(p->key, mem);
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson isc_mem_put(mem, p->key, sizeof(dns_name_t));
d5e72d5dba7b77ae0036c53578bcabcf3af1f4b7Andreas Gustafsson }
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson if (p->transfer_source != NULL) {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson isc_mem_put(mem, p->transfer_source,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews sizeof(*p->transfer_source));
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews }
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews isc_mem_put(mem, p, sizeof(*p));
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
1cf54d1966b3de8f6593e9e80eae9a80a1c011adMark Andrews *peer = NULL;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsisc_result_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsdns_peer_setbogus(dns_peer_t *peer, isc_boolean_t newval) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews isc_boolean_t existed;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
1cf54d1966b3de8f6593e9e80eae9a80a1c011adMark Andrews
1cf54d1966b3de8f6593e9e80eae9a80a1c011adMark Andrews existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews peer->bogus = newval;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews}
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssonisc_result_t
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_peer_getbogus(dns_peer_t *peer, isc_boolean_t *retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews REQUIRE(retval != NULL);
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews *retval = peer->bogus;
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews return (ISC_R_SUCCESS);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson } else
0015ab097438e041197b19b9de2ba48f6bfd1c6cDavid Lawrence return (ISC_R_NOTFOUND);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafssonisc_result_t
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafssondns_peer_setprovideixfr(dns_peer_t *peer, isc_boolean_t newval) {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson isc_boolean_t existed;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson REQUIRE(DNS_PEER_VALID(peer));
8dd4cf7fc6c025c547a473de5df7a72939d0cb2aDavid Lawrence
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
cc0a5f714231709409b9e1b85f0f97ae50854451Mark Andrews peer->provide_ixfr = newval;
87f4715d6c0a22f3449eb3291c91aa45ba86c955Mark Andrews DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
476386968b1f287a695f73c48862e961011af99bMark Andrews
476386968b1f287a695f73c48862e961011af99bMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
1672cff96d0b02badab6f94524e10285dde851fcMark Andrewsisc_result_t
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdns_peer_getprovideixfr(dns_peer_t *peer, isc_boolean_t *retval) {
b4dfb4747498ab22831a30c44607e81082fef962Michael Graff REQUIRE(DNS_PEER_VALID(peer));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(retval != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington *retval = peer->provide_ixfr;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington } else {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_NOTFOUND);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setrequestixfr(dns_peer_t *peer, isc_boolean_t newval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_boolean_t existed;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews peer->request_ixfr = newval;
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson}
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_getrequestixfr(dns_peer_t *peer, isc_boolean_t *retval) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson REQUIRE(DNS_PEER_VALID(peer));
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews REQUIRE(retval != NULL);
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson *retval = peer->request_ixfr;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington } else
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_NOTFOUND);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_peer_setsupportedns(dns_peer_t *peer, isc_boolean_t newval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_boolean_t existed;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews REQUIRE(DNS_PEER_VALID(peer));
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews existed = DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews peer->support_edns = newval;
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews DNS_BIT_SET(SUPPORT_EDNS_BIT, &peer->bitflags);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews}
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrewsisc_result_t
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrewsdns_peer_getsupportedns(dns_peer_t *peer, isc_boolean_t *retval) {
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrews REQUIRE(retval != NULL);
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrews
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson *retval = peer->support_edns;
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews return (ISC_R_SUCCESS);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews } else
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews return (ISC_R_NOTFOUND);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews}
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setrequestnsid(dns_peer_t *peer, isc_boolean_t newval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_boolean_t existed;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews REQUIRE(DNS_PEER_VALID(peer));
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews existed = DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews peer->request_nsid = newval;
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews DNS_BIT_SET(REQUEST_NSID_BIT, &peer->bitflags);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews}
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsisc_result_t
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdns_peer_getrequestnsid(dns_peer_t *peer, isc_boolean_t *retval) {
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews REQUIRE(DNS_PEER_VALID(peer));
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews REQUIRE(retval != NULL);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson if (DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags)) {
207f0a15bb486d8dc27cf5ff963fac6068ee2972Mark Andrews *retval = peer->request_nsid;
207f0a15bb486d8dc27cf5ff963fac6068ee2972Mark Andrews return (ISC_R_SUCCESS);
207f0a15bb486d8dc27cf5ff963fac6068ee2972Mark Andrews } else
207f0a15bb486d8dc27cf5ff963fac6068ee2972Mark Andrews return (ISC_R_NOTFOUND);
207f0a15bb486d8dc27cf5ff963fac6068ee2972Mark Andrews}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_settransfers(dns_peer_t *peer, isc_uint32_t newval) {
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrews isc_boolean_t existed;
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrews
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson REQUIRE(DNS_PEER_VALID(peer));
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->transfers = newval;
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_gettransfers(dns_peer_t *peer, isc_uint32_t *retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(retval != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington *retval = peer->transfers;
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews return (ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington } else {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_NOTFOUND);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_settransferformat(dns_peer_t *peer, dns_transfer_format_t newval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_boolean_t existed;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
dcd12febbd47f5846d6c75f6a4dcba8a873bc153Andreas Gustafsson existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson &peer->bitflags);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington peer->transfer_format = newval;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
a3a11c4f3fc9ba972802b811c4d95a9884d6ff4aMichael Sawyer return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson}
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssonisc_result_t
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssondns_peer_gettransferformat(dns_peer_t *peer, dns_transfer_format_t *retval) {
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson REQUIRE(DNS_PEER_VALID(peer));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(retval != NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington *retval = peer->transfer_format;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington } else {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (ISC_R_NOTFOUND);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_getkey(dns_peer_t *peer, dns_name_t **retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
3b1fce680f1dbe9467cd3b0ab3138ea52d5a976fMark Andrews REQUIRE(retval != NULL);
3b1fce680f1dbe9467cd3b0ab3138ea52d5a976fMark Andrews
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (peer->key != NULL) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington *retval = peer->key;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
ef653fbdb122e9e251bdfbdd4609d03a208bb79dMichael Graff
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson return (peer->key == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
7e0d7323d73f31ceb678879ad3aca873dc382483Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setkey(dns_peer_t *peer, dns_name_t **keyval) {
023dd2cfe0029002f5e5066ce0cc586b7b703376Mark Andrews isc_boolean_t exists = ISC_FALSE;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (peer->key != NULL) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_name_free(peer->key, peer->mem);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_mem_put(peer->mem, peer->key, sizeof(dns_name_t));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington exists = ISC_TRUE;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
023dd2cfe0029002f5e5066ce0cc586b7b703376Mark Andrews
7e0d7323d73f31ceb678879ad3aca873dc382483Brian Wellington peer->key = *keyval;
7e0d7323d73f31ceb678879ad3aca873dc382483Brian Wellington *keyval = NULL;
7e0d7323d73f31ceb678879ad3aca873dc382483Brian Wellington
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) {
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson isc_buffer_t b;
62700b67eb8abb7d13f9c3c1bc4b60a1477d35d8Mark Andrews dns_fixedname_t fname;
dfd7798d8b870abf03795d8095297a4b982ab6e9Mark Andrews dns_name_t *name;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_result_t result;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_fixedname_init(&fname);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson isc_buffer_constinit(&b, keyval, strlen(keyval));
62700b67eb8abb7d13f9c3c1bc4b60a1477d35d8Mark Andrews isc_buffer_add(&b, strlen(keyval));
dfd7798d8b870abf03795d8095297a4b982ab6e9Mark Andrews result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
3aca8e5bf3740bbcc3bb13dde242d7cc369abb27Mark Andrews dns_rootname, 0, NULL);
3aca8e5bf3740bbcc3bb13dde242d7cc369abb27Mark Andrews if (result != ISC_R_SUCCESS)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (result);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson name = isc_mem_get(peer->mem, sizeof(dns_name_t));
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson if (name == NULL)
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson return (ISC_R_NOMEMORY);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington dns_name_init(name, NULL);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name);
17dba29ba5db791976e505114baee53a1dde88aaBrian Wellington if (result != ISC_R_SUCCESS) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson isc_mem_put(peer->mem, name, sizeof(dns_name_t));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington return (result);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
17dba29ba5db791976e505114baee53a1dde88aaBrian Wellington result = dns_peer_setkey(peer, &name);
cc0a5f714231709409b9e1b85f0f97ae50854451Mark Andrews if (result != ISC_R_SUCCESS)
cc0a5f714231709409b9e1b85f0f97ae50854451Mark Andrews isc_mem_put(peer->mem, name, sizeof(dns_name_t));
cb8fd52bbeaf40c9166a0144541c4ff2bafc2dd6Andreas Gustafsson
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson return (result);
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson}
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafssonisc_result_t
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafssondns_peer_settransfersource(dns_peer_t *peer,
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson const isc_sockaddr_t *transfer_source)
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson{
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson REQUIRE(DNS_PEER_VALID(peer));
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson if (peer->transfer_source != NULL) {
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson isc_mem_put(peer->mem, peer->transfer_source,
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson sizeof(*peer->transfer_source));
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson peer->transfer_source = NULL;
76d9120dd696209fa1186ea289ea01cd4677782fAndreas Gustafsson }
76d9120dd696209fa1186ea289ea01cd4677782fAndreas Gustafsson if (transfer_source != NULL) {
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson peer->transfer_source = isc_mem_get(peer->mem,
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson sizeof(*peer->transfer_source));
cc0a5f714231709409b9e1b85f0f97ae50854451Mark Andrews if (peer->transfer_source == NULL)
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson return (ISC_R_NOMEMORY);
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson *peer->transfer_source = *transfer_source;
8cccaeaee13993c49009d3915806c1d0bd03743bAndreas Gustafsson }
8cccaeaee13993c49009d3915806c1d0bd03743bAndreas Gustafsson return (ISC_R_SUCCESS);
8cccaeaee13993c49009d3915806c1d0bd03743bAndreas Gustafsson}
8cccaeaee13993c49009d3915806c1d0bd03743bAndreas Gustafsson
1672cff96d0b02badab6f94524e10285dde851fcMark Andrewsisc_result_t
1672cff96d0b02badab6f94524e10285dde851fcMark Andrewsdns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews REQUIRE(DNS_PEER_VALID(peer));
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews REQUIRE(transfer_source != NULL);
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews if (peer->transfer_source == NULL)
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews return (ISC_R_NOTFOUND);
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews *transfer_source = *peer->transfer_source;
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews return (ISC_R_SUCCESS);
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews}
1672cff96d0b02badab6f94524e10285dde851fcMark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsisc_result_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsdns_peer_setnotifysource(dns_peer_t *peer,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews const isc_sockaddr_t *notify_source)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews{
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (peer->notify_source != NULL) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews isc_mem_put(peer->mem, peer->notify_source,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews sizeof(*peer->notify_source));
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews peer->notify_source = NULL;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews }
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (notify_source != NULL) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews peer->notify_source = isc_mem_get(peer->mem,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews sizeof(*peer->notify_source));
48f929d315bafeeffe0a37082ab4c9661a928c39Mark Andrews if (peer->notify_source == NULL)
48f929d315bafeeffe0a37082ab4c9661a928c39Mark Andrews return (ISC_R_NOMEMORY);
48f929d315bafeeffe0a37082ab4c9661a928c39Mark Andrews
48f929d315bafeeffe0a37082ab4c9661a928c39Mark Andrews *peer->notify_source = *notify_source;
48f929d315bafeeffe0a37082ab4c9661a928c39Mark Andrews }
48f929d315bafeeffe0a37082ab4c9661a928c39Mark Andrews return (ISC_R_SUCCESS);
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews}
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrewsisc_result_t
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrewsdns_peer_getnotifysource(dns_peer_t *peer, isc_sockaddr_t *notify_source) {
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
a1bc94109313bf4ebb6e6ff655d71d45582d2e43Mark Andrews REQUIRE(notify_source != NULL);
a1bc94109313bf4ebb6e6ff655d71d45582d2e43Mark Andrews
a1bc94109313bf4ebb6e6ff655d71d45582d2e43Mark Andrews if (peer->notify_source == NULL)
a1bc94109313bf4ebb6e6ff655d71d45582d2e43Mark Andrews return (ISC_R_NOTFOUND);
a1bc94109313bf4ebb6e6ff655d71d45582d2e43Mark Andrews *notify_source = *peer->notify_source;
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson return (ISC_R_SUCCESS);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson}
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssonisc_result_t
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssondns_peer_setquerysource(dns_peer_t *peer, const isc_sockaddr_t *query_source) {
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson REQUIRE(DNS_PEER_VALID(peer));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson if (peer->query_source != NULL) {
80dd46d7aab16c42a8c1acf6156c95406a9f20a4Mark Andrews isc_mem_put(peer->mem, peer->query_source,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington sizeof(*peer->query_source));
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson peer->query_source = NULL;
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson }
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson if (query_source != NULL) {
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson peer->query_source = isc_mem_get(peer->mem,
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson sizeof(*peer->query_source));
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson if (peer->query_source == NULL)
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson return (ISC_R_NOMEMORY);
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson *peer->query_source = *query_source;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington }
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson return (ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington}
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonisc_result_t
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_getquerysource(dns_peer_t *peer, isc_sockaddr_t *query_source) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
17dba29ba5db791976e505114baee53a1dde88aaBrian Wellington REQUIRE(query_source != NULL);
17dba29ba5db791976e505114baee53a1dde88aaBrian Wellington
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington if (peer->query_source == NULL)
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington return (ISC_R_NOTFOUND);
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington *query_source = *peer->query_source;
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington return (ISC_R_SUCCESS);
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington}
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellingtonisc_result_t
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellingtondns_peer_setudpsize(dns_peer_t *peer, isc_uint16_t udpsize) {
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington isc_boolean_t existed;
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington existed = DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews peer->udpsize = udpsize;
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews DNS_BIT_SET(SERVER_UDPSIZE_BIT, &peer->bitflags);
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews}
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews
508f61f8d699c46f962b682f388e54b446a7194dMark Andrewsisc_result_t
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_getudpsize(dns_peer_t *peer, isc_uint16_t *udpsize) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(udpsize != NULL);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags)) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews *udpsize = peer->udpsize;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return (ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews } else {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return (ISC_R_NOTFOUND);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews }
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsisc_result_t
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_setmaxudp(dns_peer_t *peer, isc_uint16_t maxudp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews isc_boolean_t existed;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews existed = DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews peer->maxudp = maxudp;
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews DNS_BIT_SET(SERVER_MAXUDP_BIT, &peer->bitflags);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews}
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrewsisc_result_t
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrewsdns_peer_getmaxudp(dns_peer_t *peer, isc_uint16_t *maxudp) {
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews REQUIRE(maxudp != NULL);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews if (DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags)) {
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews *maxudp = peer->maxudp;
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews return (ISC_R_SUCCESS);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews } else {
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews return (ISC_R_NOTFOUND);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews }
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews}
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrewsisc_result_t
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrewsdns_peer_setnotifydscp(dns_peer_t *peer, isc_dscp_t dscp) {
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews REQUIRE(dscp < 64);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews peer->notify_dscp = dscp;
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews return (ISC_R_SUCCESS);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews}
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrewsisc_result_t
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrewsdns_peer_getnotifydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrews REQUIRE(dscpp != NULL);
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrews
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrews *dscpp = peer->notify_dscp;
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrews return (ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsisc_result_t
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_settransferdscp(dns_peer_t *peer, isc_dscp_t dscp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(dscp < 64);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews peer->transfer_dscp = dscp;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return (ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsisc_result_t
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_gettransferdscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(dscpp != NULL);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews *dscpp = peer->transfer_dscp;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return (ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsisc_result_t
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_setquerydscp(dns_peer_t *peer, isc_dscp_t dscp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(dscp < 64);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews peer->query_dscp = dscp;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return (ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsisc_result_t
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_getquerydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews REQUIRE(dscpp != NULL);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews *dscpp = peer->query_dscp;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return (ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews