2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2003-2009, 2012-2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister */
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
d7201de09b85929a86b157f4b2d91667c68c6b52Automatic Updater/* $Id: peer.c,v 1.33 2009/09/02 23:48:02 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
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>
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉#include <isc/sockaddr.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
b3e77535185043f089b346166440402d092030c3David Lawrence#include <dns/bit.h>
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington#include <dns/fixedname.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <dns/name.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister#include <dns/peer.h>
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister * Bit positions in the dns_peer_t structure flags field
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister */
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define BOGUS_BIT 0
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define SERVER_TRANSFER_FORMAT_BIT 1
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define TRANSFERS_BIT 2
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define PROVIDE_IXFR_BIT 3
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define REQUEST_IXFR_BIT 4
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define SUPPORT_EDNS_BIT 5
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define SERVER_UDPSIZE_BIT 6
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define SERVER_MAXUDP_BIT 7
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define REQUEST_NSID_BIT 8
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews#define SEND_COOKIE_BIT 9
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define NOTIFY_DSCP_BIT 10
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define TRANSFER_DSCP_BIT 11
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews#define QUERY_DSCP_BIT 12
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews#define REQUEST_EXPIRE_BIT 13
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews#define EDNS_VERSION_BIT 14
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont#define FORCE_TCP_BIT 15
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonstatic void
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonpeerlist_delete(dns_peerlist_t **list);
b3e77535185043f089b346166440402d092030c3David Lawrence
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonstatic void
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonpeer_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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(list != NULL);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson l = isc_mem_get(mem, sizeof(*l));
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson if (l == NULL)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_NOMEMORY);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ISC_LIST_INIT(l->elements);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->mem = mem;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->refs = 1;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->magic = DNS_PEERLIST_MAGIC;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *list = l;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
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++;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson if (plist->refs == 0)
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson peerlist_delete(&plist);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonstatic void
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonpeerlist_delete(dns_peerlist_t **list) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peerlist_t *l;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *server, *stmp;
b3e77535185043f089b346166440402d092030c3David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(list != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEERLIST_VALID(*list));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l = *list;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(l->refs == 0);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson dns_peer_detach(&server);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister server = stmp;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister l->magic = 0;
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson isc_mem_put(l->mem, l, sizeof(*l));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *list = NULL;
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);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews /*
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews * More specifics to front of list.
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews */
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews for (p = ISC_LIST_HEAD(peers->elements);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews p != NULL;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews p = ISC_LIST_NEXT(p, next))
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews if (p->prefixlen < peer->prefixlen)
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews break;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews if (p != NULL)
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews else
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews ISC_LIST_APPEND(peers->elements, peer, next);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(retval != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEERLIST_VALID(servers));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister server = ISC_LIST_HEAD(servers->elements);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister while (server != NULL) {
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews if (isc_netaddr_eqprefix(addr, &server->address,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews server->prefixlen))
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister break;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister server = ISC_LIST_NEXT(server, next);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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 }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews unsigned int prefixlen = 0;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews REQUIRE(peerptr != NULL);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews switch(addr->family) {
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews case AF_INET:
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews prefixlen = 32;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews break;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews case AF_INET6:
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews prefixlen = 128;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews break;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews default:
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews INSIST(0);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews }
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews return (dns_peer_newprefix(mem, addr, prefixlen, peerptr));
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews}
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsisc_result_t
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsdns_peer_newprefix(isc_mem_t *mem, isc_netaddr_t *addr, unsigned int prefixlen,
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews dns_peer_t **peerptr)
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews{
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *peer;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(peerptr != NULL);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson peer = isc_mem_get(mem, sizeof(*peer));
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson if (peer == NULL)
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_NOMEMORY);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->magic = DNS_PEER_MAGIC;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->address = *addr;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews peer->prefixlen = prefixlen;
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;
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 peer->transfer_source = NULL;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews peer->notify_source = NULL;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews peer->query_source = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson memset(&peer->bitflags, 0x0, sizeof(peer->bitflags));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ISC_LINK_INIT(peer, next);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *peerptr = peer;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonvoid
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++;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister ENSURE(source->refs != 0xffffffffU);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *target = source;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonvoid
b3e77535185043f089b346166440402d092030c3David Lawrencedns_peer_detach(dns_peer_t **peer) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *p;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson if (p->refs == 0)
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson peer_delete(&p);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonstatic void
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafssonpeer_delete(dns_peer_t **peer) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister dns_peer_t *p;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_mem_t *mem;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(peer != NULL);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(*peer));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p = *peer;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(p->refs == 0);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister mem = p->mem;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p->mem = NULL;
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister p->magic = 0;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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 }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
75d747e1c5a30d6ef6c6238c6e27baa11d6f3bf6Mark Andrews if (p->query_source != NULL)
75d747e1c5a30d6ef6c6238c6e27baa11d6f3bf6Mark Andrews isc_mem_put(mem, p->query_source, sizeof(*p->query_source));
75d747e1c5a30d6ef6c6238c6e27baa11d6f3bf6Mark Andrews
75d747e1c5a30d6ef6c6238c6e27baa11d6f3bf6Mark Andrews if (p->notify_source != NULL)
75d747e1c5a30d6ef6c6238c6e27baa11d6f3bf6Mark Andrews isc_mem_put(mem, p->notify_source, sizeof(*p->notify_source));
75d747e1c5a30d6ef6c6238c6e27baa11d6f3bf6Mark Andrews
75d747e1c5a30d6ef6c6238c6e27baa11d6f3bf6Mark Andrews if (p->transfer_source != NULL)
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 isc_mem_put(mem, p->transfer_source,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 sizeof(*p->transfer_source));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson isc_mem_put(mem, p, sizeof(*p));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister *peer = NULL;
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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->bogus = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(DNS_PEER_VALID(peer));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister peer->provide_ixfr = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister REQUIRE(DNS_PEER_VALID(peer));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5475a2d296215b7a93bd89804dc33c36a6de7cb5James Brister peer->request_ixfr = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonisc_result_t
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtondns_peer_setsupportedns(dns_peer_t *peer, isc_boolean_t newval) {
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington isc_boolean_t existed;
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington existed = DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington peer->support_edns = newval;
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington DNS_BIT_SET(SUPPORT_EDNS_BIT, &peer->bitflags);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington}
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtonisc_result_t
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellingtondns_peer_getsupportedns(dns_peer_t *peer, isc_boolean_t *retval) {
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington REQUIRE(DNS_PEER_VALID(peer));
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington REQUIRE(retval != NULL);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) {
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington *retval = peer->support_edns;
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington return (ISC_R_SUCCESS);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington } else
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington return (ISC_R_NOTFOUND);
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington}
d25dd5b0567f67ecf40b7ed1cb20e0dce7b41c49Brian Wellington
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsisc_result_t
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsdns_peer_setrequestnsid(dns_peer_t *peer, isc_boolean_t newval) {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews isc_boolean_t existed;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews existed = DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews peer->request_nsid = newval;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews DNS_BIT_SET(REQUEST_NSID_BIT, &peer->bitflags);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews}
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsisc_result_t
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrewsdns_peer_getrequestnsid(dns_peer_t *peer, isc_boolean_t *retval) {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews REQUIRE(retval != NULL);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews if (DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags)) {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews *retval = peer->request_nsid;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (ISC_R_SUCCESS);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews } else
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (ISC_R_NOTFOUND);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews}
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrewsisc_result_t
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrewsdns_peer_setsendcookie(dns_peer_t *peer, isc_boolean_t newval) {
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews isc_boolean_t existed;
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews existed = DNS_BIT_CHECK(SEND_COOKIE_BIT, &peer->bitflags);
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews peer->send_cookie = newval;
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews DNS_BIT_SET(SEND_COOKIE_BIT, &peer->bitflags);
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews}
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrewsisc_result_t
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrewsdns_peer_getsendcookie(dns_peer_t *peer, isc_boolean_t *retval) {
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews REQUIRE(retval != NULL);
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews if (DNS_BIT_CHECK(SEND_COOKIE_BIT, &peer->bitflags)) {
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews *retval = peer->send_cookie;
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews return (ISC_R_SUCCESS);
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews } else
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews return (ISC_R_NOTFOUND);
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews}
b5f6271f4daf1e54501af2cb7dd278d7e8003d65Mark Andrews
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrewsisc_result_t
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrewsdns_peer_setrequestexpire(dns_peer_t *peer, isc_boolean_t newval) {
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews isc_boolean_t existed;
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews existed = DNS_BIT_CHECK(REQUEST_EXPIRE_BIT, &peer->bitflags);
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews peer->request_expire = newval;
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews DNS_BIT_SET(REQUEST_EXPIRE_BIT, &peer->bitflags);
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews}
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrewsisc_result_t
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrewsdns_peer_getrequestexpire(dns_peer_t *peer, isc_boolean_t *retval) {
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews REQUIRE(retval != NULL);
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews if (DNS_BIT_CHECK(REQUEST_EXPIRE_BIT, &peer->bitflags)) {
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews *retval = peer->request_expire;
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews return (ISC_R_SUCCESS);
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews } else
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews return (ISC_R_NOTFOUND);
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews}
43b9737b11f4f14b2d378746d0cd5561b1dc24a0Mark Andrews
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupontisc_result_t
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupontdns_peer_setforcetcp(dns_peer_t *peer, isc_boolean_t newval) {
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont isc_boolean_t existed;
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont REQUIRE(DNS_PEER_VALID(peer));
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont existed = DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags);
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont peer->force_tcp = newval;
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont DNS_BIT_SET(FORCE_TCP_BIT, &peer->bitflags);
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont}
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupontisc_result_t
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupontdns_peer_getforcetcp(dns_peer_t *peer, isc_boolean_t *retval) {
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont REQUIRE(DNS_PEER_VALID(peer));
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont REQUIRE(retval != NULL);
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont if (DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags)) {
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont *retval = peer->force_tcp;
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont return (ISC_R_SUCCESS);
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont } else
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont return (ISC_R_NOTFOUND);
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont}
5c5c6d289db78e41f714007426a387498e15963cFrancis Dupont
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
3e42bdfdc901b6b921b02028bd51ca2af8e84adcMark Andrewsdns_peer_settransfers(dns_peer_t *peer, isc_uint32_t newval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister isc_boolean_t existed;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->transfers = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister
2cde028c51055c9fd4837337116cd4fdfe8ff623James Bristerisc_result_t
3e42bdfdc901b6b921b02028bd51ca2af8e84adcMark Andrewsdns_peer_gettransfers(dns_peer_t *peer, isc_uint32_t *retval) {
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(retval != NULL);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister REQUIRE(DNS_PEER_VALID(peer));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b3e77535185043f089b346166440402d092030c3David Lawrence existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister peer->transfer_format = newval;
b3e77535185043f089b346166440402d092030c3David Lawrence DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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 }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
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;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
2cde028c51055c9fd4837337116cd4fdfe8ff623James Brister}
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellingtonisc_result_t
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellingtondns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) {
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington isc_buffer_t b;
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_fixedname_t fname;
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_name_t *name;
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington isc_result_t result;
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
15c5b240a6122795212c1aff03634e7156951e91Brian Wellington dns_fixedname_init(&fname);
6f7abb89ec22aef5eda40ed60fcf605a42b78d4dMark Andrews isc_buffer_constinit(&b, keyval, strlen(keyval));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington isc_buffer_add(&b, strlen(keyval));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 dns_rootname, 0, NULL);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington if (result != ISC_R_SUCCESS)
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington return (result);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington name = isc_mem_get(peer->mem, sizeof(dns_name_t));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington if (name == NULL)
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington return (ISC_R_NOMEMORY);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington dns_name_init(name, NULL);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington if (result != ISC_R_SUCCESS) {
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington isc_mem_put(peer->mem, name, sizeof(dns_name_t));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington return (result);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington }
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington result = dns_peer_setkey(peer, &name);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington if (result != ISC_R_SUCCESS)
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington isc_mem_put(peer->mem, name, sizeof(dns_name_t));
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington return (result);
590f840d3484114576d9f8a7f7d73fbe31228888Brian Wellington}
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉isc_result_t
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsdns_peer_settransfersource(dns_peer_t *peer,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews const isc_sockaddr_t *transfer_source)
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews{
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 REQUIRE(DNS_PEER_VALID(peer));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 if (peer->transfer_source != NULL) {
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 isc_mem_put(peer->mem, peer->transfer_source,
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 sizeof(*peer->transfer_source));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 peer->transfer_source = NULL;
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 }
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 if (transfer_source != NULL) {
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 peer->transfer_source = isc_mem_get(peer->mem,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews sizeof(*peer->transfer_source));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 if (peer->transfer_source == NULL)
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 return (ISC_R_NOMEMORY);
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 *peer->transfer_source = *transfer_source;
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 }
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉}
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉isc_result_t
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉dns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 REQUIRE(DNS_PEER_VALID(peer));
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 REQUIRE(transfer_source != NULL);
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 if (peer->transfer_source == NULL)
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 return (ISC_R_NOTFOUND);
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 *transfer_source = *peer->transfer_source;
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
600cbd1fcea3c9cc9706dc1ff8fc0d0034ebdeacTatuya JINMEI 神明達哉}
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsisc_result_t
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsdns_peer_setnotifysource(dns_peer_t *peer,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews const isc_sockaddr_t *notify_source)
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews{
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (peer->notify_source != NULL) {
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews isc_mem_put(peer->mem, peer->notify_source,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews sizeof(*peer->notify_source));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews peer->notify_source = NULL;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews }
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (notify_source != NULL) {
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews peer->notify_source = isc_mem_get(peer->mem,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews sizeof(*peer->notify_source));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (peer->notify_source == NULL)
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_NOMEMORY);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews *peer->notify_source = *notify_source;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews }
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_SUCCESS);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews}
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsisc_result_t
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsdns_peer_getnotifysource(dns_peer_t *peer, isc_sockaddr_t *notify_source) {
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews REQUIRE(notify_source != NULL);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (peer->notify_source == NULL)
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_NOTFOUND);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews *notify_source = *peer->notify_source;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_SUCCESS);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews}
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsisc_result_t
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsdns_peer_setquerysource(dns_peer_t *peer, const isc_sockaddr_t *query_source) {
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (peer->query_source != NULL) {
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews isc_mem_put(peer->mem, peer->query_source,
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews sizeof(*peer->query_source));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews peer->query_source = NULL;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews }
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (query_source != NULL) {
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews peer->query_source = isc_mem_get(peer->mem,
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews sizeof(*peer->query_source));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (peer->query_source == NULL)
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_NOMEMORY);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews *peer->query_source = *query_source;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews }
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_SUCCESS);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews}
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsisc_result_t
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrewsdns_peer_getquerysource(dns_peer_t *peer, isc_sockaddr_t *query_source) {
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews REQUIRE(query_source != NULL);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews if (peer->query_source == NULL)
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_NOTFOUND);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews *query_source = *peer->query_source;
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews return (ISC_R_SUCCESS);
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews}
7d4a465de03b26bf9f5ef131d03253b8f6afc169Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrewsisc_result_t
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrewsdns_peer_setudpsize(dns_peer_t *peer, isc_uint16_t udpsize) {
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews isc_boolean_t existed;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews existed = DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags);
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews peer->udpsize = udpsize;
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews DNS_BIT_SET(SERVER_UDPSIZE_BIT, &peer->bitflags);
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews}
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrewsisc_result_t
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrewsdns_peer_getudpsize(dns_peer_t *peer, isc_uint16_t *udpsize) {
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews REQUIRE(udpsize != NULL);
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews if (DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags)) {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews *udpsize = peer->udpsize;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (ISC_R_SUCCESS);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews } else {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (ISC_R_NOTFOUND);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews }
1c153afce556ff3c687986fb7c4a0b0a7f5e7cd8Mark Andrews}
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrewsisc_result_t
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrewsdns_peer_setmaxudp(dns_peer_t *peer, isc_uint16_t maxudp) {
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews isc_boolean_t existed;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews REQUIRE(DNS_PEER_VALID(peer));
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews existed = DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews peer->maxudp = maxudp;
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews DNS_BIT_SET(SERVER_MAXUDP_BIT, &peer->bitflags);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews}
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrewsisc_result_t
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrewsdns_peer_getmaxudp(dns_peer_t *peer, isc_uint16_t *maxudp) {
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews REQUIRE(DNS_PEER_VALID(peer));
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews REQUIRE(maxudp != NULL);
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews if (DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags)) {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews *maxudp = peer->maxudp;
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (ISC_R_SUCCESS);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews } else {
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (ISC_R_NOTFOUND);
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews }
08c90261660649ca7d92065f6f13a61ec5a9a86dMark Andrews}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_result_t
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntdns_peer_setnotifydscp(dns_peer_t *peer, isc_dscp_t dscp) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(DNS_PEER_VALID(peer));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(dscp < 64);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt peer->notify_dscp = dscp;
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews DNS_BIT_SET(NOTIFY_DSCP_BIT, &peer->bitflags);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (ISC_R_SUCCESS);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_result_t
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntdns_peer_getnotifydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(DNS_PEER_VALID(peer));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(dscpp != NULL);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews if (DNS_BIT_CHECK(NOTIFY_DSCP_BIT, &peer->bitflags)) {
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews *dscpp = peer->notify_dscp;
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews return (ISC_R_SUCCESS);
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews }
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews return (ISC_R_NOTFOUND);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_result_t
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntdns_peer_settransferdscp(dns_peer_t *peer, isc_dscp_t dscp) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(DNS_PEER_VALID(peer));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(dscp < 64);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt peer->transfer_dscp = dscp;
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews DNS_BIT_SET(TRANSFER_DSCP_BIT, &peer->bitflags);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (ISC_R_SUCCESS);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_result_t
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntdns_peer_gettransferdscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(DNS_PEER_VALID(peer));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(dscpp != NULL);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews if (DNS_BIT_CHECK(TRANSFER_DSCP_BIT, &peer->bitflags)) {
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews *dscpp = peer->transfer_dscp;
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews return (ISC_R_SUCCESS);
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews }
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews return (ISC_R_NOTFOUND);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_result_t
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntdns_peer_setquerydscp(dns_peer_t *peer, isc_dscp_t dscp) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(DNS_PEER_VALID(peer));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(dscp < 64);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt peer->query_dscp = dscp;
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews DNS_BIT_SET(QUERY_DSCP_BIT, &peer->bitflags);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (ISC_R_SUCCESS);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_result_t
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntdns_peer_getquerydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(DNS_PEER_VALID(peer));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt REQUIRE(dscpp != NULL);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews if (DNS_BIT_CHECK(QUERY_DSCP_BIT, &peer->bitflags)) {
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews *dscpp = peer->query_dscp;
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews return (ISC_R_SUCCESS);
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews }
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews return (ISC_R_NOTFOUND);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrewsisc_result_t
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrewsdns_peer_setednsversion(dns_peer_t *peer, isc_uint8_t ednsversion) {
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews peer->ednsversion = ednsversion;
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews DNS_BIT_SET(EDNS_VERSION_BIT, &peer->bitflags);
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews return (ISC_R_SUCCESS);
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews}
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrewsisc_result_t
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrewsdns_peer_getednsversion(dns_peer_t *peer, isc_uint8_t *ednsversion) {
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews REQUIRE(DNS_PEER_VALID(peer));
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews REQUIRE(ednsversion != NULL);
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews if (DNS_BIT_CHECK(EDNS_VERSION_BIT, &peer->bitflags)) {
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews *ednsversion = peer->ednsversion;
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews return (ISC_R_SUCCESS);
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews } else
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews return (ISC_R_NOTFOUND);
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews}