peer.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2009, 2012-2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 2001, 2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: peer.c,v 1.33 2009/09/02 23:48:02 tbox Exp $ */
00019 
00020 /*! \file */
00021 
00022 #include <config.h>
00023 
00024 #include <isc/mem.h>
00025 #include <isc/string.h>
00026 #include <isc/util.h>
00027 #include <isc/sockaddr.h>
00028 
00029 #include <dns/bit.h>
00030 #include <dns/fixedname.h>
00031 #include <dns/name.h>
00032 #include <dns/peer.h>
00033 
00034 /*%
00035  * Bit positions in the dns_peer_t structure flags field
00036  */
00037 #define BOGUS_BIT                        0
00038 #define SERVER_TRANSFER_FORMAT_BIT       1
00039 #define TRANSFERS_BIT                    2
00040 #define PROVIDE_IXFR_BIT                 3
00041 #define REQUEST_IXFR_BIT                 4
00042 #define SUPPORT_EDNS_BIT                 5
00043 #define SERVER_UDPSIZE_BIT               6
00044 #define SERVER_MAXUDP_BIT                7
00045 #define REQUEST_NSID_BIT                 8
00046 #define REQUEST_SIT_BIT                  9
00047 #define NOTIFY_DSCP_BIT                 10
00048 #define TRANSFER_DSCP_BIT               11
00049 #define QUERY_DSCP_BIT                  12
00050 #define REQUEST_EXPIRE_BIT              13
00051 #define EDNS_VERSION_BIT                14
00052 #define FORCE_TCP_BIT                   15
00053 
00054 static void
00055 peerlist_delete(dns_peerlist_t **list);
00056 
00057 static void
00058 peer_delete(dns_peer_t **peer);
00059 
00060 isc_result_t
00061 dns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
00062         dns_peerlist_t *l;
00063 
00064         REQUIRE(list != NULL);
00065 
00066         l = isc_mem_get(mem, sizeof(*l));
00067         if (l == NULL)
00068                 return (ISC_R_NOMEMORY);
00069 
00070         ISC_LIST_INIT(l->elements);
00071         l->mem = mem;
00072         l->refs = 1;
00073         l->magic = DNS_PEERLIST_MAGIC;
00074 
00075         *list = l;
00076 
00077         return (ISC_R_SUCCESS);
00078 }
00079 
00080 void
00081 dns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
00082         REQUIRE(DNS_PEERLIST_VALID(source));
00083         REQUIRE(target != NULL);
00084         REQUIRE(*target == NULL);
00085 
00086         source->refs++;
00087 
00088         ENSURE(source->refs != 0xffffffffU);
00089 
00090         *target = source;
00091 }
00092 
00093 void
00094 dns_peerlist_detach(dns_peerlist_t **list) {
00095         dns_peerlist_t *plist;
00096 
00097         REQUIRE(list != NULL);
00098         REQUIRE(*list != NULL);
00099         REQUIRE(DNS_PEERLIST_VALID(*list));
00100 
00101         plist = *list;
00102         *list = NULL;
00103 
00104         REQUIRE(plist->refs > 0);
00105 
00106         plist->refs--;
00107 
00108         if (plist->refs == 0)
00109                 peerlist_delete(&plist);
00110 }
00111 
00112 static void
00113 peerlist_delete(dns_peerlist_t **list) {
00114         dns_peerlist_t *l;
00115         dns_peer_t *server, *stmp;
00116 
00117         REQUIRE(list != NULL);
00118         REQUIRE(DNS_PEERLIST_VALID(*list));
00119 
00120         l = *list;
00121 
00122         REQUIRE(l->refs == 0);
00123 
00124         server = ISC_LIST_HEAD(l->elements);
00125         while (server != NULL) {
00126                 stmp = ISC_LIST_NEXT(server, next);
00127                 ISC_LIST_UNLINK(l->elements, server, next);
00128                 dns_peer_detach(&server);
00129                 server = stmp;
00130         }
00131 
00132         l->magic = 0;
00133         isc_mem_put(l->mem, l, sizeof(*l));
00134 
00135         *list = NULL;
00136 }
00137 
00138 void
00139 dns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
00140         dns_peer_t *p = NULL;
00141 
00142         dns_peer_attach(peer, &p);
00143 
00144         /*
00145          * More specifics to front of list.
00146          */
00147         for (p = ISC_LIST_HEAD(peers->elements);
00148              p != NULL;
00149              p = ISC_LIST_NEXT(p, next))
00150                 if (p->prefixlen < peer->prefixlen)
00151                         break;
00152 
00153         if (p != NULL)
00154                 ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next);
00155         else
00156                 ISC_LIST_APPEND(peers->elements, peer, next);
00157 
00158 }
00159 
00160 isc_result_t
00161 dns_peerlist_peerbyaddr(dns_peerlist_t *servers,
00162                         isc_netaddr_t *addr, dns_peer_t **retval)
00163 {
00164         dns_peer_t *server;
00165         isc_result_t res;
00166 
00167         REQUIRE(retval != NULL);
00168         REQUIRE(DNS_PEERLIST_VALID(servers));
00169 
00170         server = ISC_LIST_HEAD(servers->elements);
00171         while (server != NULL) {
00172                 if (isc_netaddr_eqprefix(addr, &server->address,
00173                                          server->prefixlen))
00174                         break;
00175 
00176                 server = ISC_LIST_NEXT(server, next);
00177         }
00178 
00179         if (server != NULL) {
00180                 *retval = server;
00181                 res = ISC_R_SUCCESS;
00182         } else {
00183                 res = ISC_R_NOTFOUND;
00184         }
00185 
00186         return (res);
00187 }
00188 
00189 
00190 
00191 isc_result_t
00192 dns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
00193         dns_peer_t *p = NULL;
00194 
00195         p = ISC_LIST_TAIL(peers->elements);
00196 
00197         dns_peer_attach(p, retval);
00198 
00199         return (ISC_R_SUCCESS);
00200 }
00201 
00202 isc_result_t
00203 dns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
00204         unsigned int prefixlen = 0;
00205 
00206         REQUIRE(peerptr != NULL);
00207         switch(addr->family) {
00208         case AF_INET:
00209                 prefixlen = 32;
00210                 break;
00211         case AF_INET6:
00212                  prefixlen = 128;
00213                 break;
00214         default:
00215                 INSIST(0);
00216         }
00217 
00218         return (dns_peer_newprefix(mem, addr, prefixlen, peerptr));
00219 }
00220 
00221 isc_result_t
00222 dns_peer_newprefix(isc_mem_t *mem, isc_netaddr_t *addr, unsigned int prefixlen,
00223                    dns_peer_t **peerptr)
00224 {
00225         dns_peer_t *peer;
00226 
00227         REQUIRE(peerptr != NULL);
00228 
00229         peer = isc_mem_get(mem, sizeof(*peer));
00230         if (peer == NULL)
00231                 return (ISC_R_NOMEMORY);
00232 
00233         peer->magic = DNS_PEER_MAGIC;
00234         peer->address = *addr;
00235         peer->prefixlen = prefixlen;
00236         peer->mem = mem;
00237         peer->bogus = ISC_FALSE;
00238         peer->transfer_format = dns_one_answer;
00239         peer->transfers = 0;
00240         peer->request_ixfr = ISC_FALSE;
00241         peer->provide_ixfr = ISC_FALSE;
00242         peer->key = NULL;
00243         peer->refs = 1;
00244         peer->transfer_source = NULL;
00245         peer->notify_source = NULL;
00246         peer->query_source = NULL;
00247 
00248         memset(&peer->bitflags, 0x0, sizeof(peer->bitflags));
00249 
00250         ISC_LINK_INIT(peer, next);
00251 
00252         *peerptr = peer;
00253 
00254         return (ISC_R_SUCCESS);
00255 }
00256 
00257 void
00258 dns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
00259         REQUIRE(DNS_PEER_VALID(source));
00260         REQUIRE(target != NULL);
00261         REQUIRE(*target == NULL);
00262 
00263         source->refs++;
00264 
00265         ENSURE(source->refs != 0xffffffffU);
00266 
00267         *target = source;
00268 }
00269 
00270 void
00271 dns_peer_detach(dns_peer_t **peer) {
00272         dns_peer_t *p;
00273 
00274         REQUIRE(peer != NULL);
00275         REQUIRE(*peer != NULL);
00276         REQUIRE(DNS_PEER_VALID(*peer));
00277 
00278         p = *peer;
00279 
00280         REQUIRE(p->refs > 0);
00281 
00282         *peer = NULL;
00283         p->refs--;
00284 
00285         if (p->refs == 0)
00286                 peer_delete(&p);
00287 }
00288 
00289 static void
00290 peer_delete(dns_peer_t **peer) {
00291         dns_peer_t *p;
00292         isc_mem_t *mem;
00293 
00294         REQUIRE(peer != NULL);
00295         REQUIRE(DNS_PEER_VALID(*peer));
00296 
00297         p = *peer;
00298 
00299         REQUIRE(p->refs == 0);
00300 
00301         mem = p->mem;
00302         p->mem = NULL;
00303         p->magic = 0;
00304 
00305         if (p->key != NULL) {
00306                 dns_name_free(p->key, mem);
00307                 isc_mem_put(mem, p->key, sizeof(dns_name_t));
00308         }
00309 
00310         if (p->query_source != NULL)
00311                 isc_mem_put(mem, p->query_source, sizeof(*p->query_source));
00312 
00313         if (p->notify_source != NULL)
00314                 isc_mem_put(mem, p->notify_source, sizeof(*p->notify_source));
00315 
00316         if (p->transfer_source != NULL)
00317                 isc_mem_put(mem, p->transfer_source,
00318                             sizeof(*p->transfer_source));
00319 
00320         isc_mem_put(mem, p, sizeof(*p));
00321 
00322         *peer = NULL;
00323 }
00324 
00325 isc_result_t
00326 dns_peer_setbogus(dns_peer_t *peer, isc_boolean_t newval) {
00327         isc_boolean_t existed;
00328 
00329         REQUIRE(DNS_PEER_VALID(peer));
00330 
00331         existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
00332 
00333         peer->bogus = newval;
00334         DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
00335 
00336         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00337 }
00338 
00339 isc_result_t
00340 dns_peer_getbogus(dns_peer_t *peer, isc_boolean_t *retval) {
00341         REQUIRE(DNS_PEER_VALID(peer));
00342         REQUIRE(retval != NULL);
00343 
00344         if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
00345                 *retval = peer->bogus;
00346                 return (ISC_R_SUCCESS);
00347         } else
00348                 return (ISC_R_NOTFOUND);
00349 }
00350 
00351 
00352 isc_result_t
00353 dns_peer_setprovideixfr(dns_peer_t *peer, isc_boolean_t newval) {
00354         isc_boolean_t existed;
00355 
00356         REQUIRE(DNS_PEER_VALID(peer));
00357 
00358         existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
00359 
00360         peer->provide_ixfr = newval;
00361         DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
00362 
00363         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00364 }
00365 
00366 isc_result_t
00367 dns_peer_getprovideixfr(dns_peer_t *peer, isc_boolean_t *retval) {
00368         REQUIRE(DNS_PEER_VALID(peer));
00369         REQUIRE(retval != NULL);
00370 
00371         if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
00372                 *retval = peer->provide_ixfr;
00373                 return (ISC_R_SUCCESS);
00374         } else {
00375                 return (ISC_R_NOTFOUND);
00376         }
00377 }
00378 
00379 isc_result_t
00380 dns_peer_setrequestixfr(dns_peer_t *peer, isc_boolean_t newval) {
00381         isc_boolean_t existed;
00382 
00383         REQUIRE(DNS_PEER_VALID(peer));
00384 
00385         existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
00386 
00387         peer->request_ixfr = newval;
00388         DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
00389 
00390         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00391 }
00392 
00393 isc_result_t
00394 dns_peer_getrequestixfr(dns_peer_t *peer, isc_boolean_t *retval) {
00395         REQUIRE(DNS_PEER_VALID(peer));
00396         REQUIRE(retval != NULL);
00397 
00398         if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) {
00399                 *retval = peer->request_ixfr;
00400                 return (ISC_R_SUCCESS);
00401         } else
00402                 return (ISC_R_NOTFOUND);
00403 }
00404 
00405 isc_result_t
00406 dns_peer_setsupportedns(dns_peer_t *peer, isc_boolean_t newval) {
00407         isc_boolean_t existed;
00408 
00409         REQUIRE(DNS_PEER_VALID(peer));
00410 
00411         existed = DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags);
00412 
00413         peer->support_edns = newval;
00414         DNS_BIT_SET(SUPPORT_EDNS_BIT, &peer->bitflags);
00415 
00416         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00417 }
00418 
00419 isc_result_t
00420 dns_peer_getsupportedns(dns_peer_t *peer, isc_boolean_t *retval) {
00421         REQUIRE(DNS_PEER_VALID(peer));
00422         REQUIRE(retval != NULL);
00423 
00424         if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) {
00425                 *retval = peer->support_edns;
00426                 return (ISC_R_SUCCESS);
00427         } else
00428                 return (ISC_R_NOTFOUND);
00429 }
00430 
00431 isc_result_t
00432 dns_peer_setrequestnsid(dns_peer_t *peer, isc_boolean_t newval) {
00433         isc_boolean_t existed;
00434 
00435         REQUIRE(DNS_PEER_VALID(peer));
00436 
00437         existed = DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags);
00438 
00439         peer->request_nsid = newval;
00440         DNS_BIT_SET(REQUEST_NSID_BIT, &peer->bitflags);
00441 
00442         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00443 }
00444 
00445 isc_result_t
00446 dns_peer_getrequestnsid(dns_peer_t *peer, isc_boolean_t *retval) {
00447         REQUIRE(DNS_PEER_VALID(peer));
00448         REQUIRE(retval != NULL);
00449 
00450         if (DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags)) {
00451                 *retval = peer->request_nsid;
00452                 return (ISC_R_SUCCESS);
00453         } else
00454                 return (ISC_R_NOTFOUND);
00455 }
00456 
00457 isc_result_t
00458 dns_peer_setrequestsit(dns_peer_t *peer, isc_boolean_t newval) {
00459         isc_boolean_t existed;
00460 
00461         REQUIRE(DNS_PEER_VALID(peer));
00462 
00463         existed = DNS_BIT_CHECK(REQUEST_SIT_BIT, &peer->bitflags);
00464 
00465         peer->request_sit = newval;
00466         DNS_BIT_SET(REQUEST_SIT_BIT, &peer->bitflags);
00467 
00468         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00469 }
00470 
00471 isc_result_t
00472 dns_peer_getrequestsit(dns_peer_t *peer, isc_boolean_t *retval) {
00473         REQUIRE(DNS_PEER_VALID(peer));
00474         REQUIRE(retval != NULL);
00475 
00476         if (DNS_BIT_CHECK(REQUEST_SIT_BIT, &peer->bitflags)) {
00477                 *retval = peer->request_sit;
00478                 return (ISC_R_SUCCESS);
00479         } else
00480                 return (ISC_R_NOTFOUND);
00481 }
00482 
00483 isc_result_t
00484 dns_peer_setrequestexpire(dns_peer_t *peer, isc_boolean_t newval) {
00485         isc_boolean_t existed;
00486 
00487         REQUIRE(DNS_PEER_VALID(peer));
00488 
00489         existed = DNS_BIT_CHECK(REQUEST_EXPIRE_BIT, &peer->bitflags);
00490 
00491         peer->request_expire = newval;
00492         DNS_BIT_SET(REQUEST_EXPIRE_BIT, &peer->bitflags);
00493 
00494         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00495 }
00496 
00497 isc_result_t
00498 dns_peer_getrequestexpire(dns_peer_t *peer, isc_boolean_t *retval) {
00499         REQUIRE(DNS_PEER_VALID(peer));
00500         REQUIRE(retval != NULL);
00501 
00502         if (DNS_BIT_CHECK(REQUEST_EXPIRE_BIT, &peer->bitflags)) {
00503                 *retval = peer->request_expire;
00504                 return (ISC_R_SUCCESS);
00505         } else
00506                 return (ISC_R_NOTFOUND);
00507 }
00508 
00509 isc_result_t
00510 dns_peer_setforcetcp(dns_peer_t *peer, isc_boolean_t newval) {
00511         isc_boolean_t existed;
00512 
00513         REQUIRE(DNS_PEER_VALID(peer));
00514 
00515         existed = DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags);
00516 
00517         peer->force_tcp = newval;
00518         DNS_BIT_SET(FORCE_TCP_BIT, &peer->bitflags);
00519 
00520         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00521 }
00522 
00523 isc_result_t
00524 dns_peer_getforcetcp(dns_peer_t *peer, isc_boolean_t *retval) {
00525         REQUIRE(DNS_PEER_VALID(peer));
00526         REQUIRE(retval != NULL);
00527 
00528         if (DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags)) {
00529                 *retval = peer->force_tcp;
00530                 return (ISC_R_SUCCESS);
00531         } else
00532                 return (ISC_R_NOTFOUND);
00533 }
00534 
00535 isc_result_t
00536 dns_peer_settransfers(dns_peer_t *peer, isc_uint32_t newval) {
00537         isc_boolean_t existed;
00538 
00539         REQUIRE(DNS_PEER_VALID(peer));
00540 
00541         existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
00542 
00543         peer->transfers = newval;
00544         DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
00545 
00546         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00547 }
00548 
00549 isc_result_t
00550 dns_peer_gettransfers(dns_peer_t *peer, isc_uint32_t *retval) {
00551         REQUIRE(DNS_PEER_VALID(peer));
00552         REQUIRE(retval != NULL);
00553 
00554         if (DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags)) {
00555                 *retval = peer->transfers;
00556                 return (ISC_R_SUCCESS);
00557         } else {
00558                 return (ISC_R_NOTFOUND);
00559         }
00560 }
00561 
00562 isc_result_t
00563 dns_peer_settransferformat(dns_peer_t *peer, dns_transfer_format_t newval) {
00564         isc_boolean_t existed;
00565 
00566         REQUIRE(DNS_PEER_VALID(peer));
00567 
00568         existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
00569                                  &peer->bitflags);
00570 
00571         peer->transfer_format = newval;
00572         DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
00573 
00574         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00575 }
00576 
00577 isc_result_t
00578 dns_peer_gettransferformat(dns_peer_t *peer, dns_transfer_format_t *retval) {
00579         REQUIRE(DNS_PEER_VALID(peer));
00580         REQUIRE(retval != NULL);
00581 
00582         if (DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags)) {
00583                 *retval = peer->transfer_format;
00584                 return (ISC_R_SUCCESS);
00585         } else {
00586                 return (ISC_R_NOTFOUND);
00587         }
00588 }
00589 
00590 isc_result_t
00591 dns_peer_getkey(dns_peer_t *peer, dns_name_t **retval) {
00592         REQUIRE(DNS_PEER_VALID(peer));
00593         REQUIRE(retval != NULL);
00594 
00595         if (peer->key != NULL) {
00596                 *retval = peer->key;
00597         }
00598 
00599         return (peer->key == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS);
00600 }
00601 
00602 isc_result_t
00603 dns_peer_setkey(dns_peer_t *peer, dns_name_t **keyval) {
00604         isc_boolean_t exists = ISC_FALSE;
00605 
00606         if (peer->key != NULL) {
00607                 dns_name_free(peer->key, peer->mem);
00608                 isc_mem_put(peer->mem, peer->key, sizeof(dns_name_t));
00609                 exists = ISC_TRUE;
00610         }
00611 
00612         peer->key = *keyval;
00613         *keyval = NULL;
00614 
00615         return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
00616 }
00617 
00618 isc_result_t
00619 dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) {
00620         isc_buffer_t b;
00621         dns_fixedname_t fname;
00622         dns_name_t *name;
00623         isc_result_t result;
00624 
00625         dns_fixedname_init(&fname);
00626         isc_buffer_constinit(&b, keyval, strlen(keyval));
00627         isc_buffer_add(&b, strlen(keyval));
00628         result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
00629                                    dns_rootname, 0, NULL);
00630         if (result != ISC_R_SUCCESS)
00631                 return (result);
00632 
00633         name = isc_mem_get(peer->mem, sizeof(dns_name_t));
00634         if (name == NULL)
00635                 return (ISC_R_NOMEMORY);
00636 
00637         dns_name_init(name, NULL);
00638         result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name);
00639         if (result != ISC_R_SUCCESS) {
00640                 isc_mem_put(peer->mem, name, sizeof(dns_name_t));
00641                 return (result);
00642         }
00643 
00644         result = dns_peer_setkey(peer, &name);
00645         if (result != ISC_R_SUCCESS)
00646                 isc_mem_put(peer->mem, name, sizeof(dns_name_t));
00647 
00648         return (result);
00649 }
00650 
00651 isc_result_t
00652 dns_peer_settransfersource(dns_peer_t *peer,
00653                            const isc_sockaddr_t *transfer_source)
00654 {
00655         REQUIRE(DNS_PEER_VALID(peer));
00656 
00657         if (peer->transfer_source != NULL) {
00658                 isc_mem_put(peer->mem, peer->transfer_source,
00659                             sizeof(*peer->transfer_source));
00660                 peer->transfer_source = NULL;
00661         }
00662         if (transfer_source != NULL) {
00663                 peer->transfer_source = isc_mem_get(peer->mem,
00664                                                 sizeof(*peer->transfer_source));
00665                 if (peer->transfer_source == NULL)
00666                         return (ISC_R_NOMEMORY);
00667 
00668                 *peer->transfer_source = *transfer_source;
00669         }
00670         return (ISC_R_SUCCESS);
00671 }
00672 
00673 isc_result_t
00674 dns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
00675         REQUIRE(DNS_PEER_VALID(peer));
00676         REQUIRE(transfer_source != NULL);
00677 
00678         if (peer->transfer_source == NULL)
00679                 return (ISC_R_NOTFOUND);
00680         *transfer_source = *peer->transfer_source;
00681         return (ISC_R_SUCCESS);
00682 }
00683 
00684 isc_result_t
00685 dns_peer_setnotifysource(dns_peer_t *peer,
00686                          const isc_sockaddr_t *notify_source)
00687 {
00688         REQUIRE(DNS_PEER_VALID(peer));
00689 
00690         if (peer->notify_source != NULL) {
00691                 isc_mem_put(peer->mem, peer->notify_source,
00692                             sizeof(*peer->notify_source));
00693                 peer->notify_source = NULL;
00694         }
00695         if (notify_source != NULL) {
00696                 peer->notify_source = isc_mem_get(peer->mem,
00697                                                 sizeof(*peer->notify_source));
00698                 if (peer->notify_source == NULL)
00699                         return (ISC_R_NOMEMORY);
00700 
00701                 *peer->notify_source = *notify_source;
00702         }
00703         return (ISC_R_SUCCESS);
00704 }
00705 
00706 isc_result_t
00707 dns_peer_getnotifysource(dns_peer_t *peer, isc_sockaddr_t *notify_source) {
00708         REQUIRE(DNS_PEER_VALID(peer));
00709         REQUIRE(notify_source != NULL);
00710 
00711         if (peer->notify_source == NULL)
00712                 return (ISC_R_NOTFOUND);
00713         *notify_source = *peer->notify_source;
00714         return (ISC_R_SUCCESS);
00715 }
00716 
00717 isc_result_t
00718 dns_peer_setquerysource(dns_peer_t *peer, const isc_sockaddr_t *query_source) {
00719         REQUIRE(DNS_PEER_VALID(peer));
00720 
00721         if (peer->query_source != NULL) {
00722                 isc_mem_put(peer->mem, peer->query_source,
00723                             sizeof(*peer->query_source));
00724                 peer->query_source = NULL;
00725         }
00726         if (query_source != NULL) {
00727                 peer->query_source = isc_mem_get(peer->mem,
00728                                                 sizeof(*peer->query_source));
00729                 if (peer->query_source == NULL)
00730                         return (ISC_R_NOMEMORY);
00731 
00732                 *peer->query_source = *query_source;
00733         }
00734         return (ISC_R_SUCCESS);
00735 }
00736 
00737 isc_result_t
00738 dns_peer_getquerysource(dns_peer_t *peer, isc_sockaddr_t *query_source) {
00739         REQUIRE(DNS_PEER_VALID(peer));
00740         REQUIRE(query_source != NULL);
00741 
00742         if (peer->query_source == NULL)
00743                 return (ISC_R_NOTFOUND);
00744         *query_source = *peer->query_source;
00745         return (ISC_R_SUCCESS);
00746 }
00747 
00748 isc_result_t
00749 dns_peer_setudpsize(dns_peer_t *peer, isc_uint16_t udpsize) {
00750         isc_boolean_t existed;
00751 
00752         REQUIRE(DNS_PEER_VALID(peer));
00753 
00754         existed = DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags);
00755 
00756         peer->udpsize = udpsize;
00757         DNS_BIT_SET(SERVER_UDPSIZE_BIT, &peer->bitflags);
00758 
00759         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00760 }
00761 
00762 isc_result_t
00763 dns_peer_getudpsize(dns_peer_t *peer, isc_uint16_t *udpsize) {
00764 
00765         REQUIRE(DNS_PEER_VALID(peer));
00766         REQUIRE(udpsize != NULL);
00767 
00768         if (DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags)) {
00769                 *udpsize = peer->udpsize;
00770                 return (ISC_R_SUCCESS);
00771         } else {
00772                 return (ISC_R_NOTFOUND);
00773         }
00774 }
00775 
00776 isc_result_t
00777 dns_peer_setmaxudp(dns_peer_t *peer, isc_uint16_t maxudp) {
00778         isc_boolean_t existed;
00779 
00780         REQUIRE(DNS_PEER_VALID(peer));
00781 
00782         existed = DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags);
00783 
00784         peer->maxudp = maxudp;
00785         DNS_BIT_SET(SERVER_MAXUDP_BIT, &peer->bitflags);
00786 
00787         return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
00788 }
00789 
00790 isc_result_t
00791 dns_peer_getmaxudp(dns_peer_t *peer, isc_uint16_t *maxudp) {
00792 
00793         REQUIRE(DNS_PEER_VALID(peer));
00794         REQUIRE(maxudp != NULL);
00795 
00796         if (DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags)) {
00797                 *maxudp = peer->maxudp;
00798                 return (ISC_R_SUCCESS);
00799         } else {
00800                 return (ISC_R_NOTFOUND);
00801         }
00802 }
00803 
00804 isc_result_t
00805 dns_peer_setnotifydscp(dns_peer_t *peer, isc_dscp_t dscp) {
00806         REQUIRE(DNS_PEER_VALID(peer));
00807         REQUIRE(dscp < 64);
00808 
00809         peer->notify_dscp = dscp;
00810         DNS_BIT_SET(NOTIFY_DSCP_BIT, &peer->bitflags);
00811         return (ISC_R_SUCCESS);
00812 }
00813 
00814 isc_result_t
00815 dns_peer_getnotifydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
00816         REQUIRE(DNS_PEER_VALID(peer));
00817         REQUIRE(dscpp != NULL);
00818 
00819         if (DNS_BIT_CHECK(NOTIFY_DSCP_BIT, &peer->bitflags)) {
00820                 *dscpp = peer->notify_dscp;
00821                 return (ISC_R_SUCCESS);
00822         }
00823         return (ISC_R_NOTFOUND);
00824 }
00825 
00826 isc_result_t
00827 dns_peer_settransferdscp(dns_peer_t *peer, isc_dscp_t dscp) {
00828         REQUIRE(DNS_PEER_VALID(peer));
00829         REQUIRE(dscp < 64);
00830 
00831         peer->transfer_dscp = dscp;
00832         DNS_BIT_SET(TRANSFER_DSCP_BIT, &peer->bitflags);
00833         return (ISC_R_SUCCESS);
00834 }
00835 
00836 isc_result_t
00837 dns_peer_gettransferdscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
00838         REQUIRE(DNS_PEER_VALID(peer));
00839         REQUIRE(dscpp != NULL);
00840 
00841         if (DNS_BIT_CHECK(TRANSFER_DSCP_BIT, &peer->bitflags)) {
00842                 *dscpp = peer->transfer_dscp;
00843                 return (ISC_R_SUCCESS);
00844         }
00845         return (ISC_R_NOTFOUND);
00846 }
00847 
00848 isc_result_t
00849 dns_peer_setquerydscp(dns_peer_t *peer, isc_dscp_t dscp) {
00850         REQUIRE(DNS_PEER_VALID(peer));
00851         REQUIRE(dscp < 64);
00852 
00853         peer->query_dscp = dscp;
00854         DNS_BIT_SET(QUERY_DSCP_BIT, &peer->bitflags);
00855         return (ISC_R_SUCCESS);
00856 }
00857 
00858 isc_result_t
00859 dns_peer_getquerydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
00860         REQUIRE(DNS_PEER_VALID(peer));
00861         REQUIRE(dscpp != NULL);
00862 
00863         if (DNS_BIT_CHECK(QUERY_DSCP_BIT, &peer->bitflags)) {
00864                 *dscpp = peer->query_dscp;
00865                 return (ISC_R_SUCCESS);
00866         }
00867         return (ISC_R_NOTFOUND);
00868 }
00869 
00870 isc_result_t
00871 dns_peer_setednsversion(dns_peer_t *peer, isc_uint8_t ednsversion) {
00872         REQUIRE(DNS_PEER_VALID(peer));
00873 
00874         peer->ednsversion = ednsversion;
00875         DNS_BIT_SET(EDNS_VERSION_BIT, &peer->bitflags);
00876 
00877         return (ISC_R_SUCCESS);
00878 }
00879 
00880 isc_result_t
00881 dns_peer_getednsversion(dns_peer_t *peer, isc_uint8_t *ednsversion) {
00882         REQUIRE(DNS_PEER_VALID(peer));
00883         REQUIRE(ednsversion != NULL);
00884 
00885         if (DNS_BIT_CHECK(EDNS_VERSION_BIT, &peer->bitflags)) {
00886                 *ednsversion = peer->ednsversion;
00887                 return (ISC_R_SUCCESS);
00888         } else
00889                 return (ISC_R_NOTFOUND);
00890 }

Generated on Tue Apr 28 17:40:58 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha