1135446Strhodes/* 2254897Serwin * Copyright (C) 2004-2008, 2011, 2013 Internet Systems Consortium, Inc. ("ISC") 3135446Strhodes * Copyright (C) 1999-2003 Internet Software Consortium. 4135446Strhodes * 5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any 6135446Strhodes * purpose with or without fee is hereby granted, provided that the above 7135446Strhodes * copyright notice and this permission notice appear in all copies. 8135446Strhodes * 9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11135446Strhodes * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15135446Strhodes * PERFORMANCE OF THIS SOFTWARE. 16135446Strhodes */ 17135446Strhodes 18254897Serwin/* $Id: adb.h,v 1.88 2011/12/05 17:10:51 each Exp $ */ 19135446Strhodes 20135446Strhodes#ifndef DNS_ADB_H 21135446Strhodes#define DNS_ADB_H 1 22135446Strhodes 23135446Strhodes/***** 24135446Strhodes ***** Module Info 25135446Strhodes *****/ 26135446Strhodes 27193149Sdougb/*! \file dns/adb.h 28170222Sdougb *\brief 29135446Strhodes * DNS Address Database 30135446Strhodes * 31135446Strhodes * This module implements an address database (ADB) for mapping a name 32135446Strhodes * to an isc_sockaddr_t. It also provides statistical information on 33135446Strhodes * how good that address might be. 34135446Strhodes * 35135446Strhodes * A client will pass in a dns_name_t, and the ADB will walk through 36135446Strhodes * the rdataset looking up addresses associated with the name. If it 37135446Strhodes * is found on the internal lists, a structure is filled in with the 38135446Strhodes * address information and stats for found addresses. 39135446Strhodes * 40135446Strhodes * If the name cannot be found on the internal lists, a new entry will 41135446Strhodes * be created for a name if all the information needed can be found 42135446Strhodes * in the zone table or cache. This new address will then be returned. 43135446Strhodes * 44135446Strhodes * If a request must be made to remote servers to satisfy a name lookup, 45135446Strhodes * this module will start fetches to try to complete these addresses. When 46135446Strhodes * at least one more completes, an event is sent to the caller. If none of 47135446Strhodes * them resolve before the fetch times out, an event indicating this is 48135446Strhodes * sent instead. 49135446Strhodes * 50135446Strhodes * Records are stored internally until a timer expires. The timer is the 51135446Strhodes * smaller of the TTL or signature validity period. 52135446Strhodes * 53170222Sdougb * Lameness is stored per <qname,qtype> tuple, and this data hangs off each 54170222Sdougb * address field. When an address is marked lame for a given tuple the address 55170222Sdougb * will not be returned to a caller. 56135446Strhodes * 57135446Strhodes * 58135446Strhodes * MP: 59135446Strhodes * 60170222Sdougb *\li The ADB takes care of all necessary locking. 61135446Strhodes * 62170222Sdougb *\li Only the task which initiated the name lookup can cancel the lookup. 63135446Strhodes * 64135446Strhodes * 65135446Strhodes * Security: 66135446Strhodes * 67170222Sdougb *\li None, since all data stored is required to be pre-filtered. 68135446Strhodes * (Cache needs to be sane, fetches return bounds-checked and sanity- 69135446Strhodes * checked data, caller passes a good dns_name_t for the zone, etc) 70135446Strhodes */ 71135446Strhodes 72135446Strhodes/*** 73135446Strhodes *** Imports 74135446Strhodes ***/ 75135446Strhodes 76135446Strhodes#include <isc/lang.h> 77135446Strhodes#include <isc/magic.h> 78135446Strhodes#include <isc/mem.h> 79135446Strhodes#include <isc/sockaddr.h> 80135446Strhodes 81135446Strhodes#include <dns/types.h> 82135446Strhodes#include <dns/view.h> 83135446Strhodes 84135446StrhodesISC_LANG_BEGINDECLS 85135446Strhodes 86135446Strhodes/*** 87135446Strhodes *** Magic number checks 88135446Strhodes ***/ 89135446Strhodes 90135446Strhodes#define DNS_ADBFIND_MAGIC ISC_MAGIC('a','d','b','H') 91135446Strhodes#define DNS_ADBFIND_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBFIND_MAGIC) 92135446Strhodes#define DNS_ADBADDRINFO_MAGIC ISC_MAGIC('a','d','A','I') 93135446Strhodes#define DNS_ADBADDRINFO_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBADDRINFO_MAGIC) 94135446Strhodes 95135446Strhodes 96135446Strhodes/*** 97135446Strhodes *** TYPES 98135446Strhodes ***/ 99135446Strhodes 100135446Strhodestypedef struct dns_adbname dns_adbname_t; 101135446Strhodes 102193149Sdougb/*! 103170222Sdougb *\brief 104135446Strhodes * Represents a lookup for a single name. 105135446Strhodes * 106135446Strhodes * On return, the client can safely use "list", and can reorder the list. 107135446Strhodes * Items may not be _deleted_ from this list, however, or added to it 108135446Strhodes * other than by using the dns_adb_*() API. 109135446Strhodes */ 110135446Strhodesstruct dns_adbfind { 111135446Strhodes /* Public */ 112170222Sdougb unsigned int magic; /*%< RO: magic */ 113170222Sdougb dns_adbaddrinfolist_t list; /*%< RO: list of addrs */ 114170222Sdougb unsigned int query_pending; /*%< RO: partial list */ 115170222Sdougb unsigned int partial_result; /*%< RO: addrs missing */ 116170222Sdougb unsigned int options; /*%< RO: options */ 117170222Sdougb isc_result_t result_v4; /*%< RO: v4 result */ 118170222Sdougb isc_result_t result_v6; /*%< RO: v6 result */ 119170222Sdougb ISC_LINK(dns_adbfind_t) publink; /*%< RW: client use */ 120135446Strhodes 121275672Sdelphij isc_uint32_t qtotal; 122275672Sdelphij 123135446Strhodes /* Private */ 124135446Strhodes isc_mutex_t lock; /* locks all below */ 125135446Strhodes in_port_t port; 126135446Strhodes int name_bucket; 127135446Strhodes unsigned int flags; 128135446Strhodes dns_adbname_t *adbname; 129135446Strhodes dns_adb_t *adb; 130135446Strhodes isc_event_t event; 131135446Strhodes ISC_LINK(dns_adbfind_t) plink; 132135446Strhodes}; 133135446Strhodes 134135446Strhodes/* 135135446Strhodes * _INET: 136135446Strhodes * _INET6: 137135446Strhodes * return addresses of that type. 138135446Strhodes * 139135446Strhodes * _EMPTYEVENT: 140135446Strhodes * Only schedule an event if no addresses are known. 141135446Strhodes * Must set _WANTEVENT for this to be meaningful. 142135446Strhodes * 143135446Strhodes * _WANTEVENT: 144135446Strhodes * An event is desired. Check this bit in the returned find to see 145135446Strhodes * if one will actually be generated. 146135446Strhodes * 147135446Strhodes * _AVOIDFETCHES: 148135446Strhodes * If set, fetches will not be generated unless no addresses are 149135446Strhodes * available in any of the address families requested. 150135446Strhodes * 151135446Strhodes * _STARTATZONE: 152135446Strhodes * Fetches will start using the closest zone data or use the root servers. 153135446Strhodes * This is useful for reestablishing glue that has expired. 154135446Strhodes * 155135446Strhodes * _GLUEOK: 156135446Strhodes * _HINTOK: 157135446Strhodes * Glue or hints are ok. These are used when matching names already 158135446Strhodes * in the adb, and when dns databases are searched. 159135446Strhodes * 160135446Strhodes * _RETURNLAME: 161135446Strhodes * Return lame servers in a find, so that all addresses are returned. 162135446Strhodes * 163135446Strhodes * _LAMEPRUNED: 164135446Strhodes * At least one address was omitted from the list because it was lame. 165135446Strhodes * This bit will NEVER be set if _RETURNLAME is set in the createfind(). 166135446Strhodes */ 167170222Sdougb/*% Return addresses of type INET. */ 168135446Strhodes#define DNS_ADBFIND_INET 0x00000001 169170222Sdougb/*% Return addresses of type INET6. */ 170135446Strhodes#define DNS_ADBFIND_INET6 0x00000002 171135446Strhodes#define DNS_ADBFIND_ADDRESSMASK 0x00000003 172170222Sdougb/*% 173170222Sdougb * Only schedule an event if no addresses are known. 174170222Sdougb * Must set _WANTEVENT for this to be meaningful. 175170222Sdougb */ 176135446Strhodes#define DNS_ADBFIND_EMPTYEVENT 0x00000004 177170222Sdougb/*% 178170222Sdougb * An event is desired. Check this bit in the returned find to see 179170222Sdougb * if one will actually be generated. 180170222Sdougb */ 181135446Strhodes#define DNS_ADBFIND_WANTEVENT 0x00000008 182170222Sdougb/*% 183170222Sdougb * If set, fetches will not be generated unless no addresses are 184170222Sdougb * available in any of the address families requested. 185170222Sdougb */ 186135446Strhodes#define DNS_ADBFIND_AVOIDFETCHES 0x00000010 187170222Sdougb/*% 188170222Sdougb * Fetches will start using the closest zone data or use the root servers. 189170222Sdougb * This is useful for reestablishing glue that has expired. 190170222Sdougb */ 191135446Strhodes#define DNS_ADBFIND_STARTATZONE 0x00000020 192170222Sdougb/*% 193170222Sdougb * Glue or hints are ok. These are used when matching names already 194170222Sdougb * in the adb, and when dns databases are searched. 195170222Sdougb */ 196135446Strhodes#define DNS_ADBFIND_GLUEOK 0x00000040 197170222Sdougb/*% 198170222Sdougb * Glue or hints are ok. These are used when matching names already 199170222Sdougb * in the adb, and when dns databases are searched. 200170222Sdougb */ 201135446Strhodes#define DNS_ADBFIND_HINTOK 0x00000080 202170222Sdougb/*% 203170222Sdougb * Return lame servers in a find, so that all addresses are returned. 204170222Sdougb */ 205135446Strhodes#define DNS_ADBFIND_RETURNLAME 0x00000100 206170222Sdougb/*% 207170222Sdougb * Only schedule an event if no addresses are known. 208170222Sdougb * Must set _WANTEVENT for this to be meaningful. 209170222Sdougb */ 210135446Strhodes#define DNS_ADBFIND_LAMEPRUNED 0x00000200 211135446Strhodes 212170222Sdougb/*% 213135446Strhodes * The answers to queries come back as a list of these. 214135446Strhodes */ 215135446Strhodesstruct dns_adbaddrinfo { 216170222Sdougb unsigned int magic; /*%< private */ 217135446Strhodes 218170222Sdougb isc_sockaddr_t sockaddr; /*%< [rw] */ 219170222Sdougb unsigned int srtt; /*%< [rw] microseconds */ 220170222Sdougb unsigned int flags; /*%< [rw] */ 221170222Sdougb dns_adbentry_t *entry; /*%< private */ 222135446Strhodes ISC_LINK(dns_adbaddrinfo_t) publink; 223135446Strhodes}; 224135446Strhodes 225193149Sdougb/*!< 226135446Strhodes * The event sent to the caller task is just a plain old isc_event_t. It 227135446Strhodes * contains no data other than a simple status, passed in the "type" field 228135446Strhodes * to indicate that another address resolved, or all partially resolved 229135446Strhodes * addresses have failed to resolve. 230135446Strhodes * 231135446Strhodes * "sender" is the dns_adbfind_t used to issue this query. 232135446Strhodes * 233135446Strhodes * This is simply a standard event, with the "type" set to: 234135446Strhodes * 235170222Sdougb *\li #DNS_EVENT_ADBMOREADDRESSES -- another address resolved. 236170222Sdougb *\li #DNS_EVENT_ADBNOMOREADDRESSES -- all pending addresses failed, 237135446Strhodes * were canceled, or otherwise will 238135446Strhodes * not be usable. 239170222Sdougb *\li #DNS_EVENT_ADBCANCELED -- The request was canceled by a 240135446Strhodes * 3rd party. 241170222Sdougb *\li #DNS_EVENT_ADBNAMEDELETED -- The name was deleted, so this request 242135446Strhodes * was canceled. 243135446Strhodes * 244135446Strhodes * In each of these cases, the addresses returned by the initial call 245135446Strhodes * to dns_adb_createfind() can still be used until they are no longer needed. 246135446Strhodes */ 247135446Strhodes 248135446Strhodes/**** 249135446Strhodes **** FUNCTIONS 250135446Strhodes ****/ 251135446Strhodes 252135446Strhodes 253135446Strhodesisc_result_t 254135446Strhodesdns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *tmgr, 255135446Strhodes isc_taskmgr_t *taskmgr, dns_adb_t **newadb); 256170222Sdougb/*%< 257135446Strhodes * Create a new ADB. 258135446Strhodes * 259135446Strhodes * Notes: 260135446Strhodes * 261170222Sdougb *\li Generally, applications should not create an ADB directly, but 262135446Strhodes * should instead call dns_view_createresolver(). 263135446Strhodes * 264135446Strhodes * Requires: 265135446Strhodes * 266170222Sdougb *\li 'mem' must be a valid memory context. 267135446Strhodes * 268170222Sdougb *\li 'view' be a pointer to a valid view. 269135446Strhodes * 270170222Sdougb *\li 'tmgr' be a pointer to a valid timer manager. 271135446Strhodes * 272170222Sdougb *\li 'taskmgr' be a pointer to a valid task manager. 273135446Strhodes * 274170222Sdougb *\li 'newadb' != NULL && '*newadb' == NULL. 275135446Strhodes * 276135446Strhodes * Returns: 277135446Strhodes * 278170222Sdougb *\li #ISC_R_SUCCESS after happiness. 279170222Sdougb *\li #ISC_R_NOMEMORY after resource allocation failure. 280135446Strhodes */ 281135446Strhodes 282135446Strhodesvoid 283135446Strhodesdns_adb_attach(dns_adb_t *adb, dns_adb_t **adbp); 284170222Sdougb/*% 285135446Strhodes * Attach to an 'adb' to 'adbp'. 286135446Strhodes * 287135446Strhodes * Requires: 288170222Sdougb *\li 'adb' to be a valid dns_adb_t, created via dns_adb_create(). 289170222Sdougb *\li 'adbp' to be a valid pointer to a *dns_adb_t which is initialized 290135446Strhodes * to NULL. 291135446Strhodes */ 292135446Strhodes 293135446Strhodesvoid 294135446Strhodesdns_adb_detach(dns_adb_t **adb); 295170222Sdougb/*% 296135446Strhodes * Delete the ADB. Sets *ADB to NULL. Cancels any outstanding requests. 297135446Strhodes * 298135446Strhodes * Requires: 299135446Strhodes * 300170222Sdougb *\li 'adb' be non-NULL and '*adb' be a valid dns_adb_t, created via 301135446Strhodes * dns_adb_create(). 302135446Strhodes */ 303135446Strhodes 304135446Strhodesvoid 305135446Strhodesdns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp); 306170222Sdougb/*% 307135446Strhodes * Send '*eventp' to 'task' when 'adb' has shutdown. 308135446Strhodes * 309135446Strhodes * Requires: 310135446Strhodes * 311170222Sdougb *\li '*adb' is a valid dns_adb_t. 312135446Strhodes * 313170222Sdougb *\li eventp != NULL && *eventp is a valid event. 314135446Strhodes * 315135446Strhodes * Ensures: 316135446Strhodes * 317170222Sdougb *\li *eventp == NULL 318135446Strhodes * 319170222Sdougb *\li The event's sender field is set to the value of adb when the event 320135446Strhodes * is sent. 321135446Strhodes */ 322135446Strhodes 323135446Strhodesvoid 324135446Strhodesdns_adb_shutdown(dns_adb_t *adb); 325170222Sdougb/*%< 326135446Strhodes * Shutdown 'adb'. 327135446Strhodes * 328135446Strhodes * Requires: 329135446Strhodes * 330170222Sdougb * \li '*adb' is a valid dns_adb_t. 331135446Strhodes */ 332135446Strhodes 333135446Strhodesisc_result_t 334135446Strhodesdns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action, 335170222Sdougb void *arg, dns_name_t *name, dns_name_t *qname, 336170222Sdougb dns_rdatatype_t qtype, unsigned int options, 337170222Sdougb isc_stdtime_t now, dns_name_t *target, 338135446Strhodes in_port_t port, dns_adbfind_t **find); 339275672Sdelphijisc_result_t 340275672Sdelphijdns_adb_createfind2(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action, 341275672Sdelphij void *arg, dns_name_t *name, dns_name_t *qname, 342275672Sdelphij dns_rdatatype_t qtype, unsigned int options, 343275672Sdelphij isc_stdtime_t now, dns_name_t *target, in_port_t port, 344275672Sdelphij unsigned int depth, dns_adbfind_t **find); 345170222Sdougb/*%< 346135446Strhodes * Main interface for clients. The adb will look up the name given in 347135446Strhodes * "name" and will build up a list of found addresses, and perhaps start 348135446Strhodes * internal fetches to resolve names that are unknown currently. 349135446Strhodes * 350135446Strhodes * If other addresses resolve after this call completes, an event will 351135446Strhodes * be sent to the <task, taskaction, arg> with the sender of that event 352135446Strhodes * set to a pointer to the dns_adbfind_t returned by this function. 353135446Strhodes * 354135446Strhodes * If no events will be generated, the *find->result_v4 and/or result_v6 355170222Sdougb * members may be examined for address lookup status. The usual #ISC_R_SUCCESS, 356193149Sdougb * #ISC_R_FAILURE, #DNS_R_NXDOMAIN, and #DNS_R_NXRRSET are returned, along with 357170222Sdougb * #ISC_R_NOTFOUND meaning the ADB has not _yet_ found the values. In this 358135446Strhodes * latter case, retrying may produce more addresses. 359135446Strhodes * 360135446Strhodes * If events will be returned, the result_v[46] members are only valid 361135446Strhodes * when that event is actually returned. 362135446Strhodes * 363135446Strhodes * The list of addresses returned is unordered. The caller must impose 364135446Strhodes * any ordering required. The list will not contain "known bad" addresses, 365135446Strhodes * however. For instance, it will not return hosts that are known to be 366135446Strhodes * lame for the zone in question. 367135446Strhodes * 368135446Strhodes * The caller cannot (directly) modify the contents of the address list's 369135446Strhodes * fields other than the "link" field. All values can be read at any 370135446Strhodes * time, however. 371135446Strhodes * 372135446Strhodes * The "now" parameter is used only for determining which entries that 373135446Strhodes * have a specific time to live or expire time should be removed from 374135446Strhodes * the running database. If specified as zero, the current time will 375135446Strhodes * be retrieved and used. 376135446Strhodes * 377135446Strhodes * If 'target' is not NULL and 'name' is an alias (i.e. the name is 378135446Strhodes * CNAME'd or DNAME'd to another name), then 'target' will be updated with 379135446Strhodes * the domain name that 'name' is aliased to. 380135446Strhodes * 381135446Strhodes * All addresses returned will have the sockaddr's port set to 'port.' 382135446Strhodes * The caller may change them directly in the dns_adbaddrinfo_t since 383135446Strhodes * they are copies of the internal address only. 384135446Strhodes * 385135446Strhodes * XXXMLG Document options, especially the flags which control how 386135446Strhodes * events are sent. 387135446Strhodes * 388135446Strhodes * Requires: 389135446Strhodes * 390170222Sdougb *\li *adb be a valid isc_adb_t object. 391135446Strhodes * 392170222Sdougb *\li If events are to be sent, *task be a valid task, 393135446Strhodes * and isc_taskaction_t != NULL. 394135446Strhodes * 395170222Sdougb *\li *name is a valid dns_name_t. 396135446Strhodes * 397170222Sdougb *\li qname != NULL and *qname be a valid dns_name_t. 398135446Strhodes * 399170222Sdougb *\li target == NULL or target is a valid name with a buffer. 400135446Strhodes * 401170222Sdougb *\li find != NULL && *find == NULL. 402135446Strhodes * 403135446Strhodes * Returns: 404135446Strhodes * 405170222Sdougb *\li #ISC_R_SUCCESS Addresses might have been returned, and events will be 406135446Strhodes * delivered for unresolved addresses. 407170222Sdougb *\li #ISC_R_NOMORE Addresses might have been returned, but no events 408135446Strhodes * will ever be posted for this context. This is only 409135446Strhodes * returned if task != NULL. 410170222Sdougb *\li #ISC_R_NOMEMORY insufficient resources 411170222Sdougb *\li #DNS_R_ALIAS 'name' is an alias for another name. 412135446Strhodes * 413135446Strhodes * Calls, and returns error codes from: 414135446Strhodes * 415170222Sdougb *\li isc_stdtime_get() 416135446Strhodes * 417135446Strhodes * Notes: 418135446Strhodes * 419170222Sdougb *\li No internal reference to "name" exists after this function 420135446Strhodes * returns. 421135446Strhodes */ 422135446Strhodes 423135446Strhodesvoid 424135446Strhodesdns_adb_cancelfind(dns_adbfind_t *find); 425170222Sdougb/*%< 426135446Strhodes * Cancels the find, and sends the event off to the caller. 427135446Strhodes * 428135446Strhodes * It is an error to call dns_adb_cancelfind() on a find where 429135446Strhodes * no event is wanted, or will ever be sent. 430135446Strhodes * 431135446Strhodes * Note: 432135446Strhodes * 433170222Sdougb *\li It is possible that the real completion event was posted just 434135446Strhodes * before the dns_adb_cancelfind() call was made. In this case, 435135446Strhodes * dns_adb_cancelfind() will do nothing. The event callback needs 436135446Strhodes * to be prepared to find this situation (i.e. result is valid but 437135446Strhodes * the caller expects it to be canceled). 438135446Strhodes * 439135446Strhodes * Requires: 440135446Strhodes * 441170222Sdougb *\li 'find' be a valid dns_adbfind_t pointer. 442135446Strhodes * 443170222Sdougb *\li events would have been posted to the task. This can be checked 444135446Strhodes * with (find->options & DNS_ADBFIND_WANTEVENT). 445135446Strhodes * 446135446Strhodes * Ensures: 447135446Strhodes * 448170222Sdougb *\li The event was posted to the task. 449135446Strhodes */ 450135446Strhodes 451135446Strhodesvoid 452135446Strhodesdns_adb_destroyfind(dns_adbfind_t **find); 453170222Sdougb/*%< 454135446Strhodes * Destroys the find reference. 455135446Strhodes * 456135446Strhodes * Note: 457135446Strhodes * 458170222Sdougb *\li This can only be called after the event was delivered for a 459135446Strhodes * find. Additionally, the event MUST have been freed via 460135446Strhodes * isc_event_free() BEFORE this function is called. 461135446Strhodes * 462135446Strhodes * Requires: 463135446Strhodes * 464170222Sdougb *\li 'find' != NULL and *find be valid dns_adbfind_t pointer. 465135446Strhodes * 466135446Strhodes * Ensures: 467135446Strhodes * 468170222Sdougb *\li No "address found" events will be posted to the originating task 469135446Strhodes * after this function returns. 470135446Strhodes */ 471135446Strhodes 472135446Strhodesvoid 473135446Strhodesdns_adb_dump(dns_adb_t *adb, FILE *f); 474170222Sdougb/*%< 475135446Strhodes * This function is only used for debugging. It will dump as much of the 476135446Strhodes * state of the running system as possible. 477135446Strhodes * 478135446Strhodes * Requires: 479135446Strhodes * 480170222Sdougb *\li adb be valid. 481135446Strhodes * 482170222Sdougb *\li f != NULL, and is a file open for writing. 483135446Strhodes */ 484135446Strhodes 485135446Strhodesvoid 486135446Strhodesdns_adb_dumpfind(dns_adbfind_t *find, FILE *f); 487170222Sdougb/*%< 488135446Strhodes * This function is only used for debugging. Dump the data associated 489135446Strhodes * with a find. 490135446Strhodes * 491135446Strhodes * Requires: 492135446Strhodes * 493170222Sdougb *\li find is valid. 494135446Strhodes * 495170222Sdougb * \li f != NULL, and is a file open for writing. 496135446Strhodes */ 497135446Strhodes 498135446Strhodesisc_result_t 499170222Sdougbdns_adb_marklame(dns_adb_t *adb, dns_adbaddrinfo_t *addr, dns_name_t *qname, 500170222Sdougb dns_rdatatype_t type, isc_stdtime_t expire_time); 501170222Sdougb/*%< 502170222Sdougb * Mark the given address as lame for the <qname,qtype>. expire_time should 503135446Strhodes * be set to the time when the entry should expire. That is, if it is to 504135446Strhodes * expire 10 minutes in the future, it should set it to (now + 10 * 60). 505135446Strhodes * 506135446Strhodes * Requires: 507135446Strhodes * 508170222Sdougb *\li adb be valid. 509135446Strhodes * 510170222Sdougb *\li addr be valid. 511135446Strhodes * 512170222Sdougb *\li qname be the qname used in the dns_adb_createfind() call. 513135446Strhodes * 514135446Strhodes * Returns: 515135446Strhodes * 516170222Sdougb *\li #ISC_R_SUCCESS -- all is well. 517170222Sdougb *\li #ISC_R_NOMEMORY -- could not mark address as lame. 518135446Strhodes */ 519135446Strhodes 520135446Strhodes/* 521135446Strhodes * A reasonable default for RTT adjustments 522135446Strhodes */ 523170222Sdougb#define DNS_ADB_RTTADJDEFAULT 7 /*%< default scale */ 524170222Sdougb#define DNS_ADB_RTTADJREPLACE 0 /*%< replace with our rtt */ 525170222Sdougb#define DNS_ADB_RTTADJAGE 10 /*%< age this rtt */ 526135446Strhodes 527135446Strhodesvoid 528135446Strhodesdns_adb_adjustsrtt(dns_adb_t *adb, dns_adbaddrinfo_t *addr, 529135446Strhodes unsigned int rtt, unsigned int factor); 530170222Sdougb/*%< 531193149Sdougb * Mix the round trip time into the existing smoothed rtt. 532170222Sdougb 533170222Sdougb * The formula used 534135446Strhodes * (where srtt is the existing rtt value, and rtt and factor are arguments to 535135446Strhodes * this function): 536135446Strhodes * 537170222Sdougb *\code 538135446Strhodes * new_srtt = (old_srtt / 10 * factor) + (rtt / 10 * (10 - factor)); 539170222Sdougb *\endcode 540135446Strhodes * 541135446Strhodes * XXXRTH Do we want to publish the formula? What if we want to change how 542135446Strhodes * this works later on? Recommend/require that the units are 543135446Strhodes * microseconds? 544135446Strhodes * 545135446Strhodes * Requires: 546135446Strhodes * 547170222Sdougb *\li adb be valid. 548135446Strhodes * 549170222Sdougb *\li addr be valid. 550135446Strhodes * 551170222Sdougb *\li 0 <= factor <= 10 552135446Strhodes * 553135446Strhodes * Note: 554135446Strhodes * 555170222Sdougb *\li The srtt in addr will be updated to reflect the new global 556135446Strhodes * srtt value. This may include changes made by others. 557135446Strhodes */ 558135446Strhodes 559135446Strhodesvoid 560135446Strhodesdns_adb_changeflags(dns_adb_t *adb, dns_adbaddrinfo_t *addr, 561135446Strhodes unsigned int bits, unsigned int mask); 562170222Sdougb/*% 563170222Sdougb * Change Flags. 564170222Sdougb * 565135446Strhodes * Set the flags as given by: 566135446Strhodes * 567170222Sdougb *\li newflags = (oldflags & ~mask) | (bits & mask); 568135446Strhodes * 569135446Strhodes * Requires: 570135446Strhodes * 571170222Sdougb *\li adb be valid. 572135446Strhodes * 573170222Sdougb *\li addr be valid. 574135446Strhodes */ 575135446Strhodes 576135446Strhodesisc_result_t 577135446Strhodesdns_adb_findaddrinfo(dns_adb_t *adb, isc_sockaddr_t *sa, 578135446Strhodes dns_adbaddrinfo_t **addrp, isc_stdtime_t now); 579170222Sdougb/*%< 580135446Strhodes * Return a dns_adbaddrinfo_t that is associated with address 'sa'. 581135446Strhodes * 582135446Strhodes * Requires: 583135446Strhodes * 584170222Sdougb *\li adb is valid. 585135446Strhodes * 586170222Sdougb *\li sa is valid. 587135446Strhodes * 588170222Sdougb *\li addrp != NULL && *addrp == NULL 589135446Strhodes * 590135446Strhodes * Returns: 591170222Sdougb *\li #ISC_R_SUCCESS 592170222Sdougb *\li #ISC_R_NOMEMORY 593170222Sdougb *\li #ISC_R_SHUTTINGDOWN 594135446Strhodes */ 595135446Strhodes 596135446Strhodesvoid 597135446Strhodesdns_adb_freeaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **addrp); 598170222Sdougb/*%< 599135446Strhodes * Free a dns_adbaddrinfo_t allocated by dns_adb_findaddrinfo(). 600135446Strhodes * 601135446Strhodes * Requires: 602135446Strhodes * 603170222Sdougb *\li adb is valid. 604135446Strhodes * 605170222Sdougb *\li *addrp is a valid dns_adbaddrinfo_t *. 606135446Strhodes */ 607135446Strhodes 608135446Strhodesvoid 609135446Strhodesdns_adb_flush(dns_adb_t *adb); 610170222Sdougb/*%< 611135446Strhodes * Flushes all cached data from the adb. 612135446Strhodes * 613135446Strhodes * Requires: 614170222Sdougb *\li adb is valid. 615135446Strhodes */ 616135446Strhodes 617135446Strhodesvoid 618254897Serwindns_adb_setadbsize(dns_adb_t *adb, size_t size); 619170222Sdougb/*%< 620135446Strhodes * Set a target memory size. If memory usage exceeds the target 621135446Strhodes * size entries will be removed before they would have expired on 622135446Strhodes * a random basis. 623135446Strhodes * 624135446Strhodes * If 'size' is 0 then memory usage is unlimited. 625135446Strhodes * 626135446Strhodes * Requires: 627170222Sdougb *\li 'adb' is valid. 628135446Strhodes */ 629135446Strhodes 630135446Strhodesvoid 631135446Strhodesdns_adb_flushname(dns_adb_t *adb, dns_name_t *name); 632170222Sdougb/*%< 633135446Strhodes * Flush 'name' from the adb cache. 634193149Sdougb * 635135446Strhodes * Requires: 636170222Sdougb *\li 'adb' is valid. 637170222Sdougb *\li 'name' is valid. 638135446Strhodes */ 639135446Strhodes 640135446StrhodesISC_LANG_ENDDECLS 641135446Strhodes 642135446Strhodes#endif /* DNS_ADB_H */ 643