peer.c revision 67adc03ef81fb610f8df093b17f55275ee816754
1b06367c345e972a0c719a6e821db3e875f20c3bMark Andrews * Copyright (C) 2004-2009, 2012 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * Permission to use, copy, modify, and/or distribute this software for any
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
a45a6ea2b03448751d7c44931e8ac7666e7cc2ceMark Andrews/* $Id: peer.c,v 1.33 2009/09/02 23:48:02 tbox Exp $ */
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Bit positions in the dns_peer_t structure flags field
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssondns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_detach(dns_peerlist_t **list) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ISC_LIST_UNLINK(l->elements, server, next);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * More specifics to front of list.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington ISC_LIST_APPEND(peers->elements, peer, next);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_peerbyaddr(dns_peerlist_t *servers,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (isc_netaddr_eqprefix(addr, &server->address,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington unsigned int prefixlen = 0;
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews return (dns_peer_newprefix(mem, addr, prefixlen, peerptr));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_newprefix(isc_mem_t *mem, isc_netaddr_t *addr, unsigned int prefixlen,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington memset(&peer->bitflags, 0x0, sizeof(peer->bitflags));
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewsdns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson isc_mem_put(mem, p->key, sizeof(dns_name_t));
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsdns_peer_setbogus(dns_peer_t *peer, isc_boolean_t newval) {
1cf54d1966b3de8f6593e9e80eae9a80a1c011adMark Andrews existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_peer_getbogus(dns_peer_t *peer, isc_boolean_t *retval) {
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafssondns_peer_setprovideixfr(dns_peer_t *peer, isc_boolean_t newval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
87f4715d6c0a22f3449eb3291c91aa45ba86c955Mark Andrews DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
476386968b1f287a695f73c48862e961011af99bMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdns_peer_getprovideixfr(dns_peer_t *peer, isc_boolean_t *retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setrequestixfr(dns_peer_t *peer, isc_boolean_t newval) {
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_getrequestixfr(dns_peer_t *peer, isc_boolean_t *retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_peer_setsupportedns(dns_peer_t *peer, isc_boolean_t newval) {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews existed = DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews DNS_BIT_SET(SUPPORT_EDNS_BIT, &peer->bitflags);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrewsdns_peer_getsupportedns(dns_peer_t *peer, isc_boolean_t *retval) {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setrequestnsid(dns_peer_t *peer, isc_boolean_t newval) {
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews existed = DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags);
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews DNS_BIT_SET(REQUEST_NSID_BIT, &peer->bitflags);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdns_peer_getrequestnsid(dns_peer_t *peer, isc_boolean_t *retval) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson if (DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_settransfers(dns_peer_t *peer, isc_uint32_t newval) {
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_gettransfers(dns_peer_t *peer, isc_uint32_t *retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_settransferformat(dns_peer_t *peer, dns_transfer_format_t newval) {
dcd12febbd47f5846d6c75f6a4dcba8a873bc153Andreas Gustafsson existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
a3a11c4f3fc9ba972802b811c4d95a9884d6ff4aMichael Sawyer return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssondns_peer_gettransferformat(dns_peer_t *peer, dns_transfer_format_t *retval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags)) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_getkey(dns_peer_t *peer, dns_name_t **retval) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson return (peer->key == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setkey(dns_peer_t *peer, dns_name_t **keyval) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_mem_put(peer->mem, peer->key, sizeof(dns_name_t));
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) {
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson isc_buffer_constinit(&b, keyval, strlen(keyval));
dfd7798d8b870abf03795d8095297a4b982ab6e9Mark Andrews result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson name = isc_mem_get(peer->mem, sizeof(dns_name_t));
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson isc_mem_put(peer->mem, name, sizeof(dns_name_t));
cc0a5f714231709409b9e1b85f0f97ae50854451Mark Andrews isc_mem_put(peer->mem, name, sizeof(dns_name_t));
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafssondns_peer_settransfersource(dns_peer_t *peer,
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson isc_mem_put(peer->mem, peer->transfer_source,
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson peer->transfer_source = isc_mem_get(peer->mem,
687b7ef9989c9ab9040f4ccb5f1816b96fa4e43fAndreas Gustafsson *peer->transfer_source = *transfer_source;
1672cff96d0b02badab6f94524e10285dde851fcMark Andrewsdns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrewsdns_peer_getnotifysource(dns_peer_t *peer, isc_sockaddr_t *notify_source) {
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafssondns_peer_setquerysource(dns_peer_t *peer, const isc_sockaddr_t *query_source) {
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson peer->query_source = isc_mem_get(peer->mem,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_peer_getquerysource(dns_peer_t *peer, isc_sockaddr_t *query_source) {
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellingtondns_peer_setudpsize(dns_peer_t *peer, isc_uint16_t udpsize) {
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington existed = DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags);
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews DNS_BIT_SET(SERVER_UDPSIZE_BIT, &peer->bitflags);
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_getudpsize(dns_peer_t *peer, isc_uint16_t *udpsize) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags)) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_setmaxudp(dns_peer_t *peer, isc_uint16_t maxudp) {
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews existed = DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews DNS_BIT_SET(SERVER_MAXUDP_BIT, &peer->bitflags);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrewsdns_peer_getmaxudp(dns_peer_t *peer, isc_uint16_t *maxudp) {
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrews if (DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags)) {
dc6da18ccbb808d21f123cc6bda399b44ad11445Mark Andrewsdns_peer_setnotifydscp(dns_peer_t *peer, isc_dscp_t dscp) {
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrewsdns_peer_getnotifydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_settransferdscp(dns_peer_t *peer, isc_dscp_t dscp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_gettransferdscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsdns_peer_setquerydscp(dns_peer_t *peer, isc_dscp_t dscp) {