The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Sasha Levitskiy | fbae9f3 | 2013-02-27 15:48:55 -0800 | [diff] [blame] | 31 | #include <stddef.h> |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 32 | #include <sys/cdefs.h> |
Sasha Levitskiy | fbae9f3 | 2013-02-27 15:48:55 -0800 | [diff] [blame] | 33 | |
Mattias Falk | c63e590 | 2011-08-23 14:34:14 +0200 | [diff] [blame] | 34 | struct __res_state; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | struct resolv_cache; /* forward */ |
| 36 | |
Mattias Falk | c63e590 | 2011-08-23 14:34:14 +0200 | [diff] [blame] | 37 | /* gets the cache for an interface. Set ifname argument to NULL or |
| 38 | * empty buffer ('\0') to get cache for default interface. |
| 39 | * returned cache might be NULL*/ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 40 | __LIBC_HIDDEN__ |
Mattias Falk | c63e590 | 2011-08-23 14:34:14 +0200 | [diff] [blame] | 41 | extern struct resolv_cache* __get_res_cache(const char* ifname); |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 42 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 43 | /* this gets called everytime we detect some changes in the DNS configuration |
| 44 | * and will flush the cache */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 45 | __LIBC_HIDDEN__ |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 46 | extern void _resolv_cache_reset( unsigned generation ); |
| 47 | |
| 48 | /* Gets the address of the n:th name server for the default interface |
| 49 | * Return length of address on success else 0. |
| 50 | * Note: The first name server is at n = 1 */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 51 | __LIBC_HIDDEN__ |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 52 | extern int _resolv_cache_get_nameserver(int n, char* addr, int addrLen); |
| 53 | |
| 54 | /* Gets the address of the n:th name server for a certain interface |
| 55 | * Return length of address on success else 0. |
| 56 | * Note: The first name server is at n = 1 */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 57 | __LIBC_HIDDEN__ |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 58 | extern int _resolv_cache_get_nameserver_for_iface(const char* ifname, int n, |
| 59 | char* addr, int addrLen); |
| 60 | |
| 61 | /* Gets addrinfo of the n:th name server associated with an interface. |
| 62 | * NULL is returned if no address if found. |
| 63 | * Note: The first name server is at n = 1. */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 64 | __LIBC_HIDDEN__ |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 65 | extern struct addrinfo* _resolv_cache_get_nameserver_addr_for_iface(const char* ifname, int n); |
| 66 | |
| 67 | /* Gets addrinfo of the n:th name server associated with the default interface |
| 68 | * NULL is returned if no address if found. |
| 69 | * Note: The first name server is at n = 1. */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 70 | __LIBC_HIDDEN__ |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 71 | extern struct addrinfo* _resolv_cache_get_nameserver_addr(int n); |
| 72 | |
| 73 | /* gets the address associated with the default interface */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 74 | __LIBC_HIDDEN__ |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 75 | extern struct in_addr* _resolv_get_addr_of_default_iface(); |
| 76 | |
| 77 | /* gets the address associated with the specified interface */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 78 | __LIBC_HIDDEN__ |
Mattias Falk | 23d3e6b | 2011-04-04 16:12:35 +0200 | [diff] [blame] | 79 | extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname); |
| 80 | |
Sasha Levitskiy | fbae9f3 | 2013-02-27 15:48:55 -0800 | [diff] [blame] | 81 | /* Copy the name of the default interface to the provided buffer. |
| 82 | * Returns the string length of the default interface, |
| 83 | * be that less or more than the buffLen, or 0 if nothing had been written */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 84 | __LIBC_HIDDEN__ |
Sasha Levitskiy | fbae9f3 | 2013-02-27 15:48:55 -0800 | [diff] [blame] | 85 | extern size_t _resolv_get_default_iface(char* buff, size_t buffLen); |
Mattias Falk | c63e590 | 2011-08-23 14:34:14 +0200 | [diff] [blame] | 86 | |
| 87 | /* sets the name server addresses to the provided res_state structure. The |
| 88 | * name servers are retrieved from the cache which is associated |
| 89 | * with the interface to which the res_state structure is associated */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 90 | __LIBC_HIDDEN__ |
Sasha Levitskiy | fbae9f3 | 2013-02-27 15:48:55 -0800 | [diff] [blame] | 91 | extern void _resolv_populate_res_for_iface(struct __res_state* statp); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 | |
| 93 | typedef enum { |
| 94 | RESOLV_CACHE_UNSUPPORTED, /* the cache can't handle that kind of queries */ |
| 95 | /* or the answer buffer is too small */ |
| 96 | RESOLV_CACHE_NOTFOUND, /* the cache doesn't know about this query */ |
| 97 | RESOLV_CACHE_FOUND /* the cache found the answer */ |
| 98 | } ResolvCacheStatus; |
| 99 | |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 100 | __LIBC_HIDDEN__ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | extern ResolvCacheStatus |
| 102 | _resolv_cache_lookup( struct resolv_cache* cache, |
| 103 | const void* query, |
| 104 | int querylen, |
| 105 | void* answer, |
| 106 | int answersize, |
| 107 | int *answerlen ); |
| 108 | |
| 109 | /* add a (query,answer) to the cache, only call if _resolv_cache_lookup |
| 110 | * did return RESOLV_CACHE_NOTFOUND |
| 111 | */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 112 | __LIBC_HIDDEN__ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 113 | extern void |
| 114 | _resolv_cache_add( struct resolv_cache* cache, |
| 115 | const void* query, |
| 116 | int querylen, |
| 117 | const void* answer, |
| 118 | int answerlen ); |
| 119 | |
Mattias Falk | a59cfcf | 2011-09-06 15:15:06 +0200 | [diff] [blame] | 120 | /* Notify the cache a request failed */ |
Nick Kralevich | c01274c | 2013-03-29 13:56:05 -0700 | [diff] [blame] | 121 | __LIBC_HIDDEN__ |
Mattias Falk | a59cfcf | 2011-09-06 15:15:06 +0200 | [diff] [blame] | 122 | extern void |
| 123 | _resolv_cache_query_failed( struct resolv_cache* cache, |
| 124 | const void* query, |
| 125 | int querylen); |
| 126 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 127 | #endif /* _RESOLV_CACHE_H_ */ |