bionic: Replace iface with opaque netid in resolver.
Replace iface cache key with netid.
Replace _mark with netid.
Mark sockets used to test IPv4/IPv6 support as well as sockets
used to determine source address for rfc6724 sort.
Remove pid/uid mappings (functionality moved to system/netd).
Do not create resolv_cache when it does not exist, but rather only
when DNS configuration is supplied.
Clean up unused functions.
Change-Id: I9ccfda2902cc0943e87c9bc346ad9a2578accdab
diff --git a/libc/dns/include/resolv_cache.h b/libc/dns/include/resolv_cache.h
index 68a1180..16f3e43 100644
--- a/libc/dns/include/resolv_cache.h
+++ b/libc/dns/include/resolv_cache.h
@@ -34,61 +34,15 @@
struct __res_state;
struct resolv_cache; /* forward */
-/* gets the cache for an interface. Set ifname argument to NULL or
- * empty buffer ('\0') to get cache for default interface.
- * returned cache might be NULL*/
+/* Gets the cache for a network. Returned cache might be NULL. */
__LIBC_HIDDEN__
-extern struct resolv_cache* __get_res_cache(const char* ifname);
-
-/* this gets called everytime we detect some changes in the DNS configuration
- * and will flush the cache */
-__LIBC_HIDDEN__
-extern void _resolv_cache_reset( unsigned generation );
-
-/* Gets the address of the n:th name server for the default interface
- * Return length of address on success else 0.
- * Note: The first name server is at n = 1 */
-__LIBC_HIDDEN__
-extern int _resolv_cache_get_nameserver(int n, char* addr, int addrLen);
-
-/* Gets the address of the n:th name server for a certain interface
- * Return length of address on success else 0.
- * Note: The first name server is at n = 1 */
-__LIBC_HIDDEN__
-extern int _resolv_cache_get_nameserver_for_iface(const char* ifname, int n,
- char* addr, int addrLen);
-
-/* Gets addrinfo of the n:th name server associated with an interface.
- * NULL is returned if no address if found.
- * Note: The first name server is at n = 1. */
-__LIBC_HIDDEN__
-extern struct addrinfo* _resolv_cache_get_nameserver_addr_for_iface(const char* ifname, int n);
-
-/* Gets addrinfo of the n:th name server associated with the default interface
- * NULL is returned if no address if found.
- * Note: The first name server is at n = 1. */
-__LIBC_HIDDEN__
-extern struct addrinfo* _resolv_cache_get_nameserver_addr(int n);
-
-/* gets the address associated with the default interface */
-__LIBC_HIDDEN__
-extern struct in_addr* _resolv_get_addr_of_default_iface();
-
-/* gets the address associated with the specified interface */
-__LIBC_HIDDEN__
-extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname);
-
-/* Copy the name of the default interface to the provided buffer.
- * Returns the string length of the default interface,
- * be that less or more than the buffLen, or 0 if nothing had been written */
-__LIBC_HIDDEN__
- extern size_t _resolv_get_default_iface(char* buff, size_t buffLen);
+extern struct resolv_cache* __get_res_cache(unsigned netid);
/* sets the name server addresses to the provided res_state structure. The
* name servers are retrieved from the cache which is associated
- * with the interface to which the res_state structure is associated */
+ * with the network to which the res_state structure is associated */
__LIBC_HIDDEN__
-extern void _resolv_populate_res_for_iface(struct __res_state* statp);
+extern void _resolv_populate_res_for_net(struct __res_state* statp);
typedef enum {
RESOLV_CACHE_UNSUPPORTED, /* the cache can't handle that kind of queries */
diff --git a/libc/dns/include/resolv_iface.h b/libc/dns/include/resolv_iface.h
deleted file mode 100644
index ad42793..0000000
--- a/libc/dns/include/resolv_iface.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#ifndef _RESOLV_IFACE_H
-#define _RESOLV_IFACE_H
-
-/* This header contains declarations related to per-interface DNS
- * server selection. They are used by system/netd/ and should not be
- * exposed by the C library's public NDK headers.
- *
- * NOTE: <resolv.h> contains the same declarations, this will be removed
- * when we change system/netd to use this header instead.
- */
-#include <sys/cdefs.h>
-#include <netinet/in.h>
-
-__BEGIN_DECLS
-
-/* Use a guard macro until we remove the same definitions from <resolv.h> */
-#ifndef _BIONIC_RESOLV_IFACE_FUNCTIONS_DECLARED
-#define _BIONIC_RESOLV_IFACE_FUNCTIONS_DECLARED
-
-/* Set name of default interface */
-extern void _resolv_set_default_iface(const char* ifname);
-
-/* set name servers for an interface */
-extern void _resolv_set_nameservers_for_iface(const char* ifname, const char** servers, int numservers,
- const char *domains);
-
-/* tell resolver of the address of an interface */
-extern void _resolv_set_addr_of_iface(const char* ifname, struct in_addr* addr);
-
-/* flush the cache associated with the default interface */
-extern void _resolv_flush_cache_for_default_iface();
-
-/* flush the cache associated with a certain interface */
-extern void _resolv_flush_cache_for_iface(const char* ifname);
-
-/* set a pid to use the name servers of the specified interface */
-extern void _resolv_set_iface_for_pid(const char* ifname, int pid);
-
-/* clear pid from being associated with an interface */
-extern void _resolv_clear_iface_for_pid(int pid);
-
-/* clear the entire mapping of pids to interfaces. */
-extern void _resolv_clear_iface_pid_mapping();
-
-/** Gets the name of the interface to which the pid is attached.
- * On error, -1 is returned.
- * If no interface is found, 0 is returned and buff is set to empty ('\0').
- * If an interface is found, the name is copied to buff and the length of the name is returned.
- * Arguments: pid The pid to find an interface for
- * buff A buffer to copy the result to
- * buffLen Length of buff. An interface is at most IF_NAMESIZE in length */
-extern int _resolv_get_pids_associated_interface(int pid, char* buff, int buffLen);
-
-
-/** set a uid range to use the name servers of the specified interface
- * If [low,high] overlaps with an already existing rule -1 is returned */
-extern int _resolv_set_iface_for_uid_range(const char* ifname, int uid_start, int uid_end);
-
-/* clear a uid range from being associated with an interface
- * If the range given is not mapped -1 is returned. */
-extern int _resolv_clear_iface_for_uid_range(int uid_start, int uid_end);
-
-/* clear the entire mapping of uid ranges to interfaces. */
-extern void _resolv_clear_iface_uid_range_mapping();
-
-/** Gets the name of the interface to which the uid is attached.
- * On error, -1 is returned.
- * If no interface is found, 0 is returned and buff is set to empty ('\0').
- * If an interface is found, the name is copied to buff and the length of the name is returned.
- * Arguments: uid The uid to find an interface for
- * buff A buffer to copy the result to
- * buffLen Length of buff. An interface is at most IF_NAMESIZE in length */
-extern int _resolv_get_uids_associated_interface(int uid, char* buff, int buffLen);
-
-#endif /* _BIONIC_RESOLV_IFACE_FUNCTIONS_DECLARED */
-
-__END_DECLS
-
-#endif /* _RESOLV_IFACE_H */
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
new file mode 100644
index 0000000..991a0bf
--- /dev/null
+++ b/libc/dns/include/resolv_netid.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef _RESOLV_NETID_H
+#define _RESOLV_NETID_H
+
+/* This header contains declarations related to per-network DNS
+ * server selection. They are used by system/netd/ and should not be
+ * exposed by the C library's public NDK headers.
+ */
+#include <sys/cdefs.h>
+#include <netinet/in.h>
+
+/*
+ * Passing NETID_UNSET as the netId causes system/netd/DnsProxyListener.cpp to
+ * fill in the appropriate default netId for the query.
+ */
+#define NETID_UNSET 0u
+
+/*
+ * MARK_UNSET represents the default (i.e. unset) value for a socket mark.
+ */
+#define MARK_UNSET 0u
+
+__BEGIN_DECLS
+
+struct addrinfo;
+
+struct hostent *android_gethostbyaddrfornet(const void *, socklen_t, int, unsigned, unsigned);
+struct hostent *android_gethostbyaddrfornet_proxy(const void *, socklen_t, int , unsigned);
+struct hostent *android_gethostbynamefornet(const char *, int, unsigned, unsigned);
+int android_getaddrinfofornet(const char *, const char *, const struct addrinfo *, unsigned,
+ unsigned, struct addrinfo **);
+int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t,
+ int, unsigned, unsigned);
+
+/* set name servers for a network */
+extern void _resolv_set_nameservers_for_net(unsigned netid,
+ const char** servers, int numservers, const char *domains);
+
+/* flush the cache associated with a certain network */
+extern void _resolv_flush_cache_for_net(unsigned netid);
+
+__END_DECLS
+
+#endif /* _RESOLV_NETID_H */
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index c7bcb89..8914fae 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -142,7 +142,7 @@
struct __res_state_ext;
struct __res_state {
- char iface[IF_NAMESIZE+1];
+ unsigned netid; /* NetId: cache key and socket mark */
int retrans; /* retransmission time interval */
int retry; /* number of times to retransmit */
#ifdef sun
@@ -175,7 +175,7 @@
res_send_qhook qhook; /* query hook */
res_send_rhook rhook; /* response hook */
int res_h_errno; /* last one set for this context */
- int _mark; /* If non-0 SET_MARK to _mark on all request sockets */
+ unsigned _mark; /* If non-0 SET_MARK to _mark on all request sockets */
int _vcsock; /* PRIVATE: for res_send VC i/o */
u_int _flags; /* PRIVATE: see below */
u_int _pad; /* make _u 64 bit aligned */
@@ -490,8 +490,8 @@
int res_getservers(res_state,
union res_sockaddr_union *, int);
-void res_setiface();
-void res_setmark();
+void res_setnetid(res_state, unsigned);
+void res_setmark(res_state, unsigned);
u_int res_randomid(void);
__END_DECLS