"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/peer.c" (7 Sep 2020, 19393 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "peer.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /* $Id: peer.c,v 1.33 2009/09/02 23:48:02 tbox Exp $ */
   13 
   14 /*! \file */
   15 
   16 #include <config.h>
   17 
   18 #include <inttypes.h>
   19 #include <stdbool.h>
   20 
   21 #include <isc/mem.h>
   22 #include <isc/string.h>
   23 #include <isc/util.h>
   24 #include <isc/sockaddr.h>
   25 
   26 #include <dns/bit.h>
   27 #include <dns/fixedname.h>
   28 #include <dns/name.h>
   29 #include <dns/peer.h>
   30 
   31 /*%
   32  * Bit positions in the dns_peer_t structure flags field
   33  */
   34 #define BOGUS_BIT            0
   35 #define SERVER_TRANSFER_FORMAT_BIT   1
   36 #define TRANSFERS_BIT            2
   37 #define PROVIDE_IXFR_BIT         3
   38 #define REQUEST_IXFR_BIT         4
   39 #define SUPPORT_EDNS_BIT         5
   40 #define SERVER_UDPSIZE_BIT       6
   41 #define SERVER_MAXUDP_BIT        7
   42 #define REQUEST_NSID_BIT                 8
   43 #define SEND_COOKIE_BIT                  9
   44 #define NOTIFY_DSCP_BIT                 10
   45 #define TRANSFER_DSCP_BIT               11
   46 #define QUERY_DSCP_BIT                  12
   47 #define REQUEST_EXPIRE_BIT              13
   48 #define EDNS_VERSION_BIT            14
   49 #define FORCE_TCP_BIT           15
   50 
   51 static void
   52 peerlist_delete(dns_peerlist_t **list);
   53 
   54 static void
   55 peer_delete(dns_peer_t **peer);
   56 
   57 isc_result_t
   58 dns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
   59     dns_peerlist_t *l;
   60 
   61     REQUIRE(list != NULL);
   62 
   63     l = isc_mem_get(mem, sizeof(*l));
   64     if (l == NULL)
   65         return (ISC_R_NOMEMORY);
   66 
   67     ISC_LIST_INIT(l->elements);
   68     l->mem = mem;
   69     l->refs = 1;
   70     l->magic = DNS_PEERLIST_MAGIC;
   71 
   72     *list = l;
   73 
   74     return (ISC_R_SUCCESS);
   75 }
   76 
   77 void
   78 dns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
   79     REQUIRE(DNS_PEERLIST_VALID(source));
   80     REQUIRE(target != NULL);
   81     REQUIRE(*target == NULL);
   82 
   83     source->refs++;
   84 
   85     ENSURE(source->refs != 0xffffffffU);
   86 
   87     *target = source;
   88 }
   89 
   90 void
   91 dns_peerlist_detach(dns_peerlist_t **list) {
   92     dns_peerlist_t *plist;
   93 
   94     REQUIRE(list != NULL);
   95     REQUIRE(*list != NULL);
   96     REQUIRE(DNS_PEERLIST_VALID(*list));
   97 
   98     plist = *list;
   99     *list = NULL;
  100 
  101     REQUIRE(plist->refs > 0);
  102 
  103     plist->refs--;
  104 
  105     if (plist->refs == 0)
  106         peerlist_delete(&plist);
  107 }
  108 
  109 static void
  110 peerlist_delete(dns_peerlist_t **list) {
  111     dns_peerlist_t *l;
  112     dns_peer_t *server, *stmp;
  113 
  114     REQUIRE(list != NULL);
  115     REQUIRE(DNS_PEERLIST_VALID(*list));
  116 
  117     l = *list;
  118 
  119     REQUIRE(l->refs == 0);
  120 
  121     server = ISC_LIST_HEAD(l->elements);
  122     while (server != NULL) {
  123         stmp = ISC_LIST_NEXT(server, next);
  124         ISC_LIST_UNLINK(l->elements, server, next);
  125         dns_peer_detach(&server);
  126         server = stmp;
  127     }
  128 
  129     l->magic = 0;
  130     isc_mem_put(l->mem, l, sizeof(*l));
  131 
  132     *list = NULL;
  133 }
  134 
  135 void
  136 dns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
  137     dns_peer_t *p = NULL;
  138 
  139     dns_peer_attach(peer, &p);
  140 
  141     /*
  142      * More specifics to front of list.
  143      */
  144     for (p = ISC_LIST_HEAD(peers->elements);
  145          p != NULL;
  146          p = ISC_LIST_NEXT(p, next))
  147         if (p->prefixlen < peer->prefixlen)
  148             break;
  149 
  150     if (p != NULL)
  151         ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next);
  152     else
  153         ISC_LIST_APPEND(peers->elements, peer, next);
  154 
  155 }
  156 
  157 isc_result_t
  158 dns_peerlist_peerbyaddr(dns_peerlist_t *servers,
  159             isc_netaddr_t *addr, dns_peer_t **retval)
  160 {
  161     dns_peer_t *server;
  162     isc_result_t res;
  163 
  164     REQUIRE(retval != NULL);
  165     REQUIRE(DNS_PEERLIST_VALID(servers));
  166 
  167     server = ISC_LIST_HEAD(servers->elements);
  168     while (server != NULL) {
  169         if (isc_netaddr_eqprefix(addr, &server->address,
  170                      server->prefixlen))
  171             break;
  172 
  173         server = ISC_LIST_NEXT(server, next);
  174     }
  175 
  176     if (server != NULL) {
  177         *retval = server;
  178         res = ISC_R_SUCCESS;
  179     } else {
  180         res = ISC_R_NOTFOUND;
  181     }
  182 
  183     return (res);
  184 }
  185 
  186 
  187 
  188 isc_result_t
  189 dns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
  190     dns_peer_t *p = NULL;
  191 
  192     p = ISC_LIST_TAIL(peers->elements);
  193 
  194     dns_peer_attach(p, retval);
  195 
  196     return (ISC_R_SUCCESS);
  197 }
  198 
  199 isc_result_t
  200 dns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
  201     unsigned int prefixlen = 0;
  202 
  203     REQUIRE(peerptr != NULL);
  204     switch(addr->family) {
  205     case AF_INET:
  206         prefixlen = 32;
  207         break;
  208     case AF_INET6:
  209         prefixlen = 128;
  210         break;
  211     default:
  212         INSIST(0);
  213         ISC_UNREACHABLE();
  214     }
  215 
  216     return (dns_peer_newprefix(mem, addr, prefixlen, peerptr));
  217 }
  218 
  219 isc_result_t
  220 dns_peer_newprefix(isc_mem_t *mem, isc_netaddr_t *addr, unsigned int prefixlen,
  221            dns_peer_t **peerptr)
  222 {
  223     dns_peer_t *peer;
  224 
  225     REQUIRE(peerptr != NULL);
  226 
  227     peer = isc_mem_get(mem, sizeof(*peer));
  228     if (peer == NULL)
  229         return (ISC_R_NOMEMORY);
  230 
  231     peer->magic = DNS_PEER_MAGIC;
  232     peer->address = *addr;
  233     peer->prefixlen = prefixlen;
  234     peer->mem = mem;
  235     peer->bogus = false;
  236     peer->transfer_format = dns_one_answer;
  237     peer->transfers = 0;
  238     peer->request_ixfr = false;
  239     peer->provide_ixfr = false;
  240     peer->key = NULL;
  241     peer->refs = 1;
  242     peer->transfer_source = NULL;
  243     peer->notify_source = NULL;
  244     peer->query_source = NULL;
  245 
  246     memset(&peer->bitflags, 0x0, sizeof(peer->bitflags));
  247 
  248     ISC_LINK_INIT(peer, next);
  249 
  250     *peerptr = peer;
  251 
  252     return (ISC_R_SUCCESS);
  253 }
  254 
  255 void
  256 dns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
  257     REQUIRE(DNS_PEER_VALID(source));
  258     REQUIRE(target != NULL);
  259     REQUIRE(*target == NULL);
  260 
  261     source->refs++;
  262 
  263     ENSURE(source->refs != 0xffffffffU);
  264 
  265     *target = source;
  266 }
  267 
  268 void
  269 dns_peer_detach(dns_peer_t **peer) {
  270     dns_peer_t *p;
  271 
  272     REQUIRE(peer != NULL);
  273     REQUIRE(*peer != NULL);
  274     REQUIRE(DNS_PEER_VALID(*peer));
  275 
  276     p = *peer;
  277 
  278     REQUIRE(p->refs > 0);
  279 
  280     *peer = NULL;
  281     p->refs--;
  282 
  283     if (p->refs == 0)
  284         peer_delete(&p);
  285 }
  286 
  287 static void
  288 peer_delete(dns_peer_t **peer) {
  289     dns_peer_t *p;
  290     isc_mem_t *mem;
  291 
  292     REQUIRE(peer != NULL);
  293     REQUIRE(DNS_PEER_VALID(*peer));
  294 
  295     p = *peer;
  296 
  297     REQUIRE(p->refs == 0);
  298 
  299     mem = p->mem;
  300     p->mem = NULL;
  301     p->magic = 0;
  302 
  303     if (p->key != NULL) {
  304         dns_name_free(p->key, mem);
  305         isc_mem_put(mem, p->key, sizeof(dns_name_t));
  306     }
  307 
  308     if (p->query_source != NULL)
  309         isc_mem_put(mem, p->query_source, sizeof(*p->query_source));
  310 
  311     if (p->notify_source != NULL)
  312         isc_mem_put(mem, p->notify_source, sizeof(*p->notify_source));
  313 
  314     if (p->transfer_source != NULL)
  315         isc_mem_put(mem, p->transfer_source,
  316                 sizeof(*p->transfer_source));
  317 
  318     isc_mem_put(mem, p, sizeof(*p));
  319 
  320     *peer = NULL;
  321 }
  322 
  323 isc_result_t
  324 dns_peer_setbogus(dns_peer_t *peer, bool newval) {
  325     bool existed;
  326 
  327     REQUIRE(DNS_PEER_VALID(peer));
  328 
  329     existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
  330 
  331     peer->bogus = newval;
  332     DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
  333 
  334     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  335 }
  336 
  337 isc_result_t
  338 dns_peer_getbogus(dns_peer_t *peer, bool *retval) {
  339     REQUIRE(DNS_PEER_VALID(peer));
  340     REQUIRE(retval != NULL);
  341 
  342     if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
  343         *retval = peer->bogus;
  344         return (ISC_R_SUCCESS);
  345     } else
  346         return (ISC_R_NOTFOUND);
  347 }
  348 
  349 
  350 isc_result_t
  351 dns_peer_setprovideixfr(dns_peer_t *peer, bool newval) {
  352     bool existed;
  353 
  354     REQUIRE(DNS_PEER_VALID(peer));
  355 
  356     existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
  357 
  358     peer->provide_ixfr = newval;
  359     DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
  360 
  361     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  362 }
  363 
  364 isc_result_t
  365 dns_peer_getprovideixfr(dns_peer_t *peer, bool *retval) {
  366     REQUIRE(DNS_PEER_VALID(peer));
  367     REQUIRE(retval != NULL);
  368 
  369     if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
  370         *retval = peer->provide_ixfr;
  371         return (ISC_R_SUCCESS);
  372     } else {
  373         return (ISC_R_NOTFOUND);
  374     }
  375 }
  376 
  377 isc_result_t
  378 dns_peer_setrequestixfr(dns_peer_t *peer, bool newval) {
  379     bool existed;
  380 
  381     REQUIRE(DNS_PEER_VALID(peer));
  382 
  383     existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
  384 
  385     peer->request_ixfr = newval;
  386     DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
  387 
  388     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  389 }
  390 
  391 isc_result_t
  392 dns_peer_getrequestixfr(dns_peer_t *peer, bool *retval) {
  393     REQUIRE(DNS_PEER_VALID(peer));
  394     REQUIRE(retval != NULL);
  395 
  396     if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) {
  397         *retval = peer->request_ixfr;
  398         return (ISC_R_SUCCESS);
  399     } else
  400         return (ISC_R_NOTFOUND);
  401 }
  402 
  403 isc_result_t
  404 dns_peer_setsupportedns(dns_peer_t *peer, bool newval) {
  405     bool existed;
  406 
  407     REQUIRE(DNS_PEER_VALID(peer));
  408 
  409     existed = DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags);
  410 
  411     peer->support_edns = newval;
  412     DNS_BIT_SET(SUPPORT_EDNS_BIT, &peer->bitflags);
  413 
  414     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  415 }
  416 
  417 isc_result_t
  418 dns_peer_getsupportedns(dns_peer_t *peer, bool *retval) {
  419     REQUIRE(DNS_PEER_VALID(peer));
  420     REQUIRE(retval != NULL);
  421 
  422     if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) {
  423         *retval = peer->support_edns;
  424         return (ISC_R_SUCCESS);
  425     } else
  426         return (ISC_R_NOTFOUND);
  427 }
  428 
  429 isc_result_t
  430 dns_peer_setrequestnsid(dns_peer_t *peer, bool newval) {
  431     bool existed;
  432 
  433     REQUIRE(DNS_PEER_VALID(peer));
  434 
  435     existed = DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags);
  436 
  437     peer->request_nsid = newval;
  438     DNS_BIT_SET(REQUEST_NSID_BIT, &peer->bitflags);
  439 
  440     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  441 }
  442 
  443 isc_result_t
  444 dns_peer_getrequestnsid(dns_peer_t *peer, bool *retval) {
  445     REQUIRE(DNS_PEER_VALID(peer));
  446     REQUIRE(retval != NULL);
  447 
  448     if (DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags)) {
  449         *retval = peer->request_nsid;
  450         return (ISC_R_SUCCESS);
  451     } else
  452         return (ISC_R_NOTFOUND);
  453 }
  454 
  455 isc_result_t
  456 dns_peer_setsendcookie(dns_peer_t *peer, bool newval) {
  457     bool existed;
  458 
  459     REQUIRE(DNS_PEER_VALID(peer));
  460 
  461     existed = DNS_BIT_CHECK(SEND_COOKIE_BIT, &peer->bitflags);
  462 
  463     peer->send_cookie = newval;
  464     DNS_BIT_SET(SEND_COOKIE_BIT, &peer->bitflags);
  465 
  466     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  467 }
  468 
  469 isc_result_t
  470 dns_peer_getsendcookie(dns_peer_t *peer, bool *retval) {
  471     REQUIRE(DNS_PEER_VALID(peer));
  472     REQUIRE(retval != NULL);
  473 
  474     if (DNS_BIT_CHECK(SEND_COOKIE_BIT, &peer->bitflags)) {
  475         *retval = peer->send_cookie;
  476         return (ISC_R_SUCCESS);
  477     } else
  478         return (ISC_R_NOTFOUND);
  479 }
  480 
  481 isc_result_t
  482 dns_peer_setrequestexpire(dns_peer_t *peer, bool newval) {
  483     bool existed;
  484 
  485     REQUIRE(DNS_PEER_VALID(peer));
  486 
  487     existed = DNS_BIT_CHECK(REQUEST_EXPIRE_BIT, &peer->bitflags);
  488 
  489     peer->request_expire = newval;
  490     DNS_BIT_SET(REQUEST_EXPIRE_BIT, &peer->bitflags);
  491 
  492     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  493 }
  494 
  495 isc_result_t
  496 dns_peer_getrequestexpire(dns_peer_t *peer, bool *retval) {
  497     REQUIRE(DNS_PEER_VALID(peer));
  498     REQUIRE(retval != NULL);
  499 
  500     if (DNS_BIT_CHECK(REQUEST_EXPIRE_BIT, &peer->bitflags)) {
  501         *retval = peer->request_expire;
  502         return (ISC_R_SUCCESS);
  503     } else
  504         return (ISC_R_NOTFOUND);
  505 }
  506 
  507 isc_result_t
  508 dns_peer_setforcetcp(dns_peer_t *peer, bool newval) {
  509     bool existed;
  510 
  511     REQUIRE(DNS_PEER_VALID(peer));
  512 
  513     existed = DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags);
  514 
  515     peer->force_tcp = newval;
  516     DNS_BIT_SET(FORCE_TCP_BIT, &peer->bitflags);
  517 
  518     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  519 }
  520 
  521 isc_result_t
  522 dns_peer_getforcetcp(dns_peer_t *peer, bool *retval) {
  523     REQUIRE(DNS_PEER_VALID(peer));
  524     REQUIRE(retval != NULL);
  525 
  526     if (DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags)) {
  527         *retval = peer->force_tcp;
  528         return (ISC_R_SUCCESS);
  529     } else
  530         return (ISC_R_NOTFOUND);
  531 }
  532 
  533 isc_result_t
  534 dns_peer_settransfers(dns_peer_t *peer, uint32_t newval) {
  535     bool existed;
  536 
  537     REQUIRE(DNS_PEER_VALID(peer));
  538 
  539     existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
  540 
  541     peer->transfers = newval;
  542     DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
  543 
  544     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  545 }
  546 
  547 isc_result_t
  548 dns_peer_gettransfers(dns_peer_t *peer, uint32_t *retval) {
  549     REQUIRE(DNS_PEER_VALID(peer));
  550     REQUIRE(retval != NULL);
  551 
  552     if (DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags)) {
  553         *retval = peer->transfers;
  554         return (ISC_R_SUCCESS);
  555     } else {
  556         return (ISC_R_NOTFOUND);
  557     }
  558 }
  559 
  560 isc_result_t
  561 dns_peer_settransferformat(dns_peer_t *peer, dns_transfer_format_t newval) {
  562     bool existed;
  563 
  564     REQUIRE(DNS_PEER_VALID(peer));
  565 
  566     existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
  567                  &peer->bitflags);
  568 
  569     peer->transfer_format = newval;
  570     DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
  571 
  572     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  573 }
  574 
  575 isc_result_t
  576 dns_peer_gettransferformat(dns_peer_t *peer, dns_transfer_format_t *retval) {
  577     REQUIRE(DNS_PEER_VALID(peer));
  578     REQUIRE(retval != NULL);
  579 
  580     if (DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags)) {
  581         *retval = peer->transfer_format;
  582         return (ISC_R_SUCCESS);
  583     } else {
  584         return (ISC_R_NOTFOUND);
  585     }
  586 }
  587 
  588 isc_result_t
  589 dns_peer_getkey(dns_peer_t *peer, dns_name_t **retval) {
  590     REQUIRE(DNS_PEER_VALID(peer));
  591     REQUIRE(retval != NULL);
  592 
  593     if (peer->key != NULL) {
  594         *retval = peer->key;
  595     }
  596 
  597     return (peer->key == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS);
  598 }
  599 
  600 isc_result_t
  601 dns_peer_setkey(dns_peer_t *peer, dns_name_t **keyval) {
  602     bool exists = false;
  603 
  604     if (peer->key != NULL) {
  605         dns_name_free(peer->key, peer->mem);
  606         isc_mem_put(peer->mem, peer->key, sizeof(dns_name_t));
  607         exists = true;
  608     }
  609 
  610     peer->key = *keyval;
  611     *keyval = NULL;
  612 
  613     return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
  614 }
  615 
  616 isc_result_t
  617 dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) {
  618     isc_buffer_t b;
  619     dns_fixedname_t fname;
  620     dns_name_t *name;
  621     isc_result_t result;
  622 
  623     dns_fixedname_init(&fname);
  624     isc_buffer_constinit(&b, keyval, strlen(keyval));
  625     isc_buffer_add(&b, strlen(keyval));
  626     result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
  627                    dns_rootname, 0, NULL);
  628     if (result != ISC_R_SUCCESS)
  629         return (result);
  630 
  631     name = isc_mem_get(peer->mem, sizeof(dns_name_t));
  632     if (name == NULL)
  633         return (ISC_R_NOMEMORY);
  634 
  635     dns_name_init(name, NULL);
  636     result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name);
  637     if (result != ISC_R_SUCCESS) {
  638         isc_mem_put(peer->mem, name, sizeof(dns_name_t));
  639         return (result);
  640     }
  641 
  642     result = dns_peer_setkey(peer, &name);
  643     if (result != ISC_R_SUCCESS)
  644         isc_mem_put(peer->mem, name, sizeof(dns_name_t));
  645 
  646     return (result);
  647 }
  648 
  649 isc_result_t
  650 dns_peer_settransfersource(dns_peer_t *peer,
  651                const isc_sockaddr_t *transfer_source)
  652 {
  653     REQUIRE(DNS_PEER_VALID(peer));
  654 
  655     if (peer->transfer_source != NULL) {
  656         isc_mem_put(peer->mem, peer->transfer_source,
  657                 sizeof(*peer->transfer_source));
  658         peer->transfer_source = NULL;
  659     }
  660     if (transfer_source != NULL) {
  661         peer->transfer_source = isc_mem_get(peer->mem,
  662                         sizeof(*peer->transfer_source));
  663         if (peer->transfer_source == NULL)
  664             return (ISC_R_NOMEMORY);
  665 
  666         *peer->transfer_source = *transfer_source;
  667     }
  668     return (ISC_R_SUCCESS);
  669 }
  670 
  671 isc_result_t
  672 dns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
  673     REQUIRE(DNS_PEER_VALID(peer));
  674     REQUIRE(transfer_source != NULL);
  675 
  676     if (peer->transfer_source == NULL)
  677         return (ISC_R_NOTFOUND);
  678     *transfer_source = *peer->transfer_source;
  679     return (ISC_R_SUCCESS);
  680 }
  681 
  682 isc_result_t
  683 dns_peer_setnotifysource(dns_peer_t *peer,
  684              const isc_sockaddr_t *notify_source)
  685 {
  686     REQUIRE(DNS_PEER_VALID(peer));
  687 
  688     if (peer->notify_source != NULL) {
  689         isc_mem_put(peer->mem, peer->notify_source,
  690                 sizeof(*peer->notify_source));
  691         peer->notify_source = NULL;
  692     }
  693     if (notify_source != NULL) {
  694         peer->notify_source = isc_mem_get(peer->mem,
  695                         sizeof(*peer->notify_source));
  696         if (peer->notify_source == NULL)
  697             return (ISC_R_NOMEMORY);
  698 
  699         *peer->notify_source = *notify_source;
  700     }
  701     return (ISC_R_SUCCESS);
  702 }
  703 
  704 isc_result_t
  705 dns_peer_getnotifysource(dns_peer_t *peer, isc_sockaddr_t *notify_source) {
  706     REQUIRE(DNS_PEER_VALID(peer));
  707     REQUIRE(notify_source != NULL);
  708 
  709     if (peer->notify_source == NULL)
  710         return (ISC_R_NOTFOUND);
  711     *notify_source = *peer->notify_source;
  712     return (ISC_R_SUCCESS);
  713 }
  714 
  715 isc_result_t
  716 dns_peer_setquerysource(dns_peer_t *peer, const isc_sockaddr_t *query_source) {
  717     REQUIRE(DNS_PEER_VALID(peer));
  718 
  719     if (peer->query_source != NULL) {
  720         isc_mem_put(peer->mem, peer->query_source,
  721                 sizeof(*peer->query_source));
  722         peer->query_source = NULL;
  723     }
  724     if (query_source != NULL) {
  725         peer->query_source = isc_mem_get(peer->mem,
  726                         sizeof(*peer->query_source));
  727         if (peer->query_source == NULL)
  728             return (ISC_R_NOMEMORY);
  729 
  730         *peer->query_source = *query_source;
  731     }
  732     return (ISC_R_SUCCESS);
  733 }
  734 
  735 isc_result_t
  736 dns_peer_getquerysource(dns_peer_t *peer, isc_sockaddr_t *query_source) {
  737     REQUIRE(DNS_PEER_VALID(peer));
  738     REQUIRE(query_source != NULL);
  739 
  740     if (peer->query_source == NULL)
  741         return (ISC_R_NOTFOUND);
  742     *query_source = *peer->query_source;
  743     return (ISC_R_SUCCESS);
  744 }
  745 
  746 isc_result_t
  747 dns_peer_setudpsize(dns_peer_t *peer, uint16_t udpsize) {
  748     bool existed;
  749 
  750     REQUIRE(DNS_PEER_VALID(peer));
  751 
  752     existed = DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags);
  753 
  754     peer->udpsize = udpsize;
  755     DNS_BIT_SET(SERVER_UDPSIZE_BIT, &peer->bitflags);
  756 
  757     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  758 }
  759 
  760 isc_result_t
  761 dns_peer_getudpsize(dns_peer_t *peer, uint16_t *udpsize) {
  762 
  763     REQUIRE(DNS_PEER_VALID(peer));
  764     REQUIRE(udpsize != NULL);
  765 
  766     if (DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags)) {
  767         *udpsize = peer->udpsize;
  768         return (ISC_R_SUCCESS);
  769     } else {
  770         return (ISC_R_NOTFOUND);
  771     }
  772 }
  773 
  774 isc_result_t
  775 dns_peer_setmaxudp(dns_peer_t *peer, uint16_t maxudp) {
  776     bool existed;
  777 
  778     REQUIRE(DNS_PEER_VALID(peer));
  779 
  780     existed = DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags);
  781 
  782     peer->maxudp = maxudp;
  783     DNS_BIT_SET(SERVER_MAXUDP_BIT, &peer->bitflags);
  784 
  785     return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
  786 }
  787 
  788 isc_result_t
  789 dns_peer_getmaxudp(dns_peer_t *peer, uint16_t *maxudp) {
  790 
  791     REQUIRE(DNS_PEER_VALID(peer));
  792     REQUIRE(maxudp != NULL);
  793 
  794     if (DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags)) {
  795         *maxudp = peer->maxudp;
  796         return (ISC_R_SUCCESS);
  797     } else {
  798         return (ISC_R_NOTFOUND);
  799     }
  800 }
  801 
  802 isc_result_t
  803 dns_peer_setnotifydscp(dns_peer_t *peer, isc_dscp_t dscp) {
  804     REQUIRE(DNS_PEER_VALID(peer));
  805     REQUIRE(dscp < 64);
  806 
  807     peer->notify_dscp = dscp;
  808     DNS_BIT_SET(NOTIFY_DSCP_BIT, &peer->bitflags);
  809     return (ISC_R_SUCCESS);
  810 }
  811 
  812 isc_result_t
  813 dns_peer_getnotifydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
  814     REQUIRE(DNS_PEER_VALID(peer));
  815     REQUIRE(dscpp != NULL);
  816 
  817     if (DNS_BIT_CHECK(NOTIFY_DSCP_BIT, &peer->bitflags)) {
  818         *dscpp = peer->notify_dscp;
  819         return (ISC_R_SUCCESS);
  820     }
  821     return (ISC_R_NOTFOUND);
  822 }
  823 
  824 isc_result_t
  825 dns_peer_settransferdscp(dns_peer_t *peer, isc_dscp_t dscp) {
  826     REQUIRE(DNS_PEER_VALID(peer));
  827     REQUIRE(dscp < 64);
  828 
  829     peer->transfer_dscp = dscp;
  830     DNS_BIT_SET(TRANSFER_DSCP_BIT, &peer->bitflags);
  831     return (ISC_R_SUCCESS);
  832 }
  833 
  834 isc_result_t
  835 dns_peer_gettransferdscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
  836     REQUIRE(DNS_PEER_VALID(peer));
  837     REQUIRE(dscpp != NULL);
  838 
  839     if (DNS_BIT_CHECK(TRANSFER_DSCP_BIT, &peer->bitflags)) {
  840         *dscpp = peer->transfer_dscp;
  841         return (ISC_R_SUCCESS);
  842     }
  843     return (ISC_R_NOTFOUND);
  844 }
  845 
  846 isc_result_t
  847 dns_peer_setquerydscp(dns_peer_t *peer, isc_dscp_t dscp) {
  848     REQUIRE(DNS_PEER_VALID(peer));
  849     REQUIRE(dscp < 64);
  850 
  851     peer->query_dscp = dscp;
  852     DNS_BIT_SET(QUERY_DSCP_BIT, &peer->bitflags);
  853     return (ISC_R_SUCCESS);
  854 }
  855 
  856 isc_result_t
  857 dns_peer_getquerydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
  858     REQUIRE(DNS_PEER_VALID(peer));
  859     REQUIRE(dscpp != NULL);
  860 
  861     if (DNS_BIT_CHECK(QUERY_DSCP_BIT, &peer->bitflags)) {
  862         *dscpp = peer->query_dscp;
  863         return (ISC_R_SUCCESS);
  864     }
  865     return (ISC_R_NOTFOUND);
  866 }
  867 
  868 isc_result_t
  869 dns_peer_setednsversion(dns_peer_t *peer, uint8_t ednsversion) {
  870     REQUIRE(DNS_PEER_VALID(peer));
  871 
  872     peer->ednsversion = ednsversion;
  873     DNS_BIT_SET(EDNS_VERSION_BIT, &peer->bitflags);
  874 
  875     return (ISC_R_SUCCESS);
  876 }
  877 
  878 isc_result_t
  879 dns_peer_getednsversion(dns_peer_t *peer, uint8_t *ednsversion) {
  880     REQUIRE(DNS_PEER_VALID(peer));
  881     REQUIRE(ednsversion != NULL);
  882 
  883     if (DNS_BIT_CHECK(EDNS_VERSION_BIT, &peer->bitflags)) {
  884         *ednsversion = peer->ednsversion;
  885         return (ISC_R_SUCCESS);
  886     } else
  887         return (ISC_R_NOTFOUND);
  888 }