blob: d70857de2ca45430fbae36a20bd9efe92a4cfc79 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#ifndef _RESOLV_CACHE_H_
29#define _RESOLV_CACHE_H_
30
Nick Kralevichc01274c2013-03-29 13:56:05 -070031#include <sys/cdefs.h>
32
Mattias Falkc63e5902011-08-23 14:34:14 +020033struct __res_state;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034struct resolv_cache; /* forward */
35
Mattias Falkc63e5902011-08-23 14:34:14 +020036/* gets the cache for an interface. Set ifname argument to NULL or
37 * empty buffer ('\0') to get cache for default interface.
38 * returned cache might be NULL*/
Nick Kralevichc01274c2013-03-29 13:56:05 -070039__LIBC_HIDDEN__
Mattias Falkc63e5902011-08-23 14:34:14 +020040extern struct resolv_cache* __get_res_cache(const char* ifname);
Mattias Falk23d3e6b2011-04-04 16:12:35 +020041
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042/* this gets called everytime we detect some changes in the DNS configuration
43 * and will flush the cache */
Nick Kralevichc01274c2013-03-29 13:56:05 -070044__LIBC_HIDDEN__
Mattias Falk23d3e6b2011-04-04 16:12:35 +020045extern void _resolv_cache_reset( unsigned generation );
46
47/* Gets the address of the n:th name server for the default interface
48 * Return length of address on success else 0.
49 * Note: The first name server is at n = 1 */
Nick Kralevichc01274c2013-03-29 13:56:05 -070050__LIBC_HIDDEN__
Mattias Falk23d3e6b2011-04-04 16:12:35 +020051extern int _resolv_cache_get_nameserver(int n, char* addr, int addrLen);
52
53/* Gets the address of the n:th name server for a certain interface
54 * Return length of address on success else 0.
55 * Note: The first name server is at n = 1 */
Nick Kralevichc01274c2013-03-29 13:56:05 -070056__LIBC_HIDDEN__
Mattias Falk23d3e6b2011-04-04 16:12:35 +020057extern int _resolv_cache_get_nameserver_for_iface(const char* ifname, int n,
58 char* addr, int addrLen);
59
60/* Gets addrinfo of the n:th name server associated with an interface.
61 * NULL is returned if no address if found.
62 * Note: The first name server is at n = 1. */
Nick Kralevichc01274c2013-03-29 13:56:05 -070063__LIBC_HIDDEN__
Mattias Falk23d3e6b2011-04-04 16:12:35 +020064extern struct addrinfo* _resolv_cache_get_nameserver_addr_for_iface(const char* ifname, int n);
65
66/* Gets addrinfo of the n:th name server associated with the default interface
67 * NULL is returned if no address if found.
68 * Note: The first name server is at n = 1. */
Nick Kralevichc01274c2013-03-29 13:56:05 -070069__LIBC_HIDDEN__
Mattias Falk23d3e6b2011-04-04 16:12:35 +020070extern struct addrinfo* _resolv_cache_get_nameserver_addr(int n);
71
72/* gets the address associated with the default interface */
Nick Kralevichc01274c2013-03-29 13:56:05 -070073__LIBC_HIDDEN__
Mattias Falk23d3e6b2011-04-04 16:12:35 +020074extern struct in_addr* _resolv_get_addr_of_default_iface();
75
76/* gets the address associated with the specified interface */
Nick Kralevichc01274c2013-03-29 13:56:05 -070077__LIBC_HIDDEN__
Mattias Falk23d3e6b2011-04-04 16:12:35 +020078extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname);
79
Mattias Falkc63e5902011-08-23 14:34:14 +020080/* Copy the name of the default interface to provided buffer.
81 * Return length of buffer on success on failure -1 is returned */
Nick Kralevichc01274c2013-03-29 13:56:05 -070082__LIBC_HIDDEN__
Mattias Falkc63e5902011-08-23 14:34:14 +020083extern int _resolv_get_default_iface(char* buff, int buffLen);
84
85/* sets the name server addresses to the provided res_state structure. The
86 * name servers are retrieved from the cache which is associated
87 * with the interface to which the res_state structure is associated */
Nick Kralevichc01274c2013-03-29 13:56:05 -070088__LIBC_HIDDEN__
Mattias Falkc63e5902011-08-23 14:34:14 +020089extern int _resolv_populate_res_for_iface(struct __res_state* statp);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080090
91typedef enum {
92 RESOLV_CACHE_UNSUPPORTED, /* the cache can't handle that kind of queries */
93 /* or the answer buffer is too small */
94 RESOLV_CACHE_NOTFOUND, /* the cache doesn't know about this query */
95 RESOLV_CACHE_FOUND /* the cache found the answer */
96} ResolvCacheStatus;
97
Nick Kralevichc01274c2013-03-29 13:56:05 -070098__LIBC_HIDDEN__
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080099extern ResolvCacheStatus
100_resolv_cache_lookup( struct resolv_cache* cache,
101 const void* query,
102 int querylen,
103 void* answer,
104 int answersize,
105 int *answerlen );
106
107/* add a (query,answer) to the cache, only call if _resolv_cache_lookup
108 * did return RESOLV_CACHE_NOTFOUND
109 */
Nick Kralevichc01274c2013-03-29 13:56:05 -0700110__LIBC_HIDDEN__
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800111extern void
112_resolv_cache_add( struct resolv_cache* cache,
113 const void* query,
114 int querylen,
115 const void* answer,
116 int answerlen );
117
Mattias Falka59cfcf2011-09-06 15:15:06 +0200118/* Notify the cache a request failed */
Nick Kralevichc01274c2013-03-29 13:56:05 -0700119__LIBC_HIDDEN__
Mattias Falka59cfcf2011-09-06 15:15:06 +0200120extern void
121_resolv_cache_query_failed( struct resolv_cache* cache,
122 const void* query,
123 int querylen);
124
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800125#endif /* _RESOLV_CACHE_H_ */