Commit graph

39 commits

Author SHA1 Message Date
Elliott Hughes
d0bbfa8327 Make res_init() work again.
Change 75830fb836 to fix _nres
initialization to be thread safe accidentally introduced a behavior
change whereby res_init() became a no-op. It also failed to remove all
direct accesses to _nres.

Move the file over to C++ so we can let RAII ensure we're always holding
a lock while using the global state, make all callers access the global
state via this class, and restore the previous behavior of res_init().

Test: atest DnsResolverTest
Bug: 166235340
Change-Id: Ib390a7eac063bc0ff5eeba755e8c74ef1383004e
2021-04-08 12:04:05 -07:00
Luke Huang
e3ed892faa Replace android_open_proxy with dns_open_proxy
remove android_open_proxy and use dns_open_proxy instead of it.
dns_open_proxy is in libnetd_client and
it does the same thing as android_open_proxy except return value.
It returns fd directly now.

Test: build, dns works fine
Change-Id: I984743fb50b23eeb9a7d24e9fc347832acfe2afe
2018-11-19 18:00:37 +08:00
Bernie Innocenti
58d13622a5 Make the resolver retry timeout configurable via __res_params
The primary motivation is speeding up tests for non-responsive
nameservers. It's also base infrastructure for future work to compute
retry timeouts dynamically.

Using default timeouts (RES_TIMEOUT = 5 seconds):
  ResolverTest.GetAddrInfoV6_nonresponsive (45141 ms)

With base_timeout_msec=100:
  ResolverTest.GetAddrInfoV6_nonresponsive (1264 ms)

Test: executed unsubmitted test from aosp/713993
Change-Id: Id902089ca69ca8d28032180ba51e8937262ef490
2018-08-08 15:45:19 +09:00
Ben Schwartz
27dd915147 Pad queries when EDNS0 is enabled.
Behavior is compliant with
https://tools.ietf.org/html/draft-ietf-dprive-padding-policy-04

EDNS0 is only enabled when the netcontext requests it, i.e. in DNS-over-TLS
mode.

Bug: 69623036
Bug: 64133961
Test: Wireshark verified. Integration tests echo padding and pass.
Change-Id: I5ef600e02a572d281441e890cc981614f150629b
2018-04-02 05:28:16 +00:00
Erik Kline
391143e51b Add flags field to struct android_net_context
This is for passing additional instructions through stages of the
DNS resolution pipeling.

Test: as follows
    - builds, flashes, boots
    - system/netd/tests/runtests.sh passes
Bug: 34953048
Bug: 70694619
Bug: 72345192
Change-Id: I5a86cc5192e6cfa09c375ac9f5810102da3aba20
2018-03-12 16:34:56 +09:00
Ben Schwartz
90a83beb4d Make use of the DNS query hook in the netcontext
This will allow netd to run queries over TLS:
https://android-review.googlesource.com/#/c/391513/
https://android-review.googlesource.com/#/c/380593/

Bug: 34953048
Test: Device tests pass.  No issues during manual testing.
Change-Id: I8d613322307fc40cdba59b82599eda753697278f
2017-05-22 18:37:25 -04:00
Ben Schwartz
dd878fe129 Add a netcontext variant of gethostbyname
Bug: 34953048
Test: Integration tests pass
Change-Id: I670427d67fde09d8e76ea6a920c90a1969230c4f
2017-05-22 10:19:25 -04:00
Ben Schwartz
50178056f7 Add a netcontext variant of gethostbyaddr
Bug: 34953048
Test: Integration tests pass
Change-Id: Id04830345be56cd7a077981c6e2acfb5568e7a88
2017-05-18 14:32:21 -04:00
Stephen Hines
9935e0fcee Don't mark __res_params or android_net_context as packed.
Bug: http://b/31532493

These internal API structures are never actually used anywhere that
would change behavior because it is "packed", so it is safe to remove.

Test: Builds correctly with the latest toolchain.
Change-Id: I5431992d840777605be75ab91dc21158d6d22c26
2017-01-25 00:42:45 -08:00
Elliott Hughes
7b737e43f8 Remove #pragma GCC visibility.
We have better control over visibility now.

Bug: http://b/24767418
Change-Id: Ifa9a1e5af4bd4217db08422050908770247b3b69
2016-07-25 15:57:02 -07:00
Elliott Hughes
f47514dd99 Remove __LIBC_ABI_PUBLIC__.
We have much better control over visibility now, so we don't need to
pollute the headers with cruft.

Bug: http://b/24767418
Change-Id: I349f4c3bc30102477375ad9f80926e560c7c1d8b
2016-07-19 13:56:46 -07:00
Elliott Hughes
21788265da Remove a duplicate declaration, improve check-symbols-glibc.py.
Change-Id: I97a98dfc8acaa93172386b4475487a05a35a9337
2016-05-06 14:43:50 -07:00
Elliott Hughes
42d752754e Move nsswitch.h into libc/dns/include.
Not a public header file except in NetBSD, where it came from. Even
OpenBSD doesn't have it.

Bug: http://b/28519060
Change-Id: Id5feec4a4e8010a9f4433e73b1bfa6f935d884b9
2016-05-02 12:24:58 -07:00
Josh Gao
c194fd30c6 Delete declarations which don't exist.
Bug: http://b/28178111
Change-Id: I72d5d015d7927a8df24b3973bf8a052053a067fb
2016-04-27 16:50:54 -07:00
Pierre Imai
97c9d73a87 Add new info functions to resolver for use by Netd.
android_net_res_stats_get_info_for_net returns the current name servers, search
domains, parameters and stats for the given network ID.

android_net_res_stats_aggregate provides statistics such as errors counts from
the raw stats data reported by android_net_res_stats_get_info_for_net.

android_net_res_stats_get_usable_servers uses the data returned by
android_net_res_stats_aggregate to determine which of the servers are
considered valid or broken by the resolver.

BUG: 25731675

Change-Id: I6059b68e5e8b809027a4d3135f6081588bee8a7d
2016-04-21 10:07:26 +09:00
Pierre Imai
fff356786f Store DNS server count in resolv_cache.
Instead of keeping a sentinel after nameservers[], nsaddrinfo[] and
nstats[], store the server count in the structure, freeing up memory and
eliminating the need to enumerate the server count every time
_resolv_is_nameservers_equal_locked() is invoked.

Also increase MAXNS from 3 to 4.

BUG: 28153323
Change-Id: I11a7257af695157c9e32019cd00c67b535b63c75
2016-04-21 10:07:24 +09:00
Pierre Imai
03844d8cdb Fix off-by-one error in res_cache.c
Change-Id: I58264902c123b3bc0d392d17837aa537ca0a3ca2
2016-04-05 16:19:57 +09:00
Pierre Imai
6b3f0d65f2 Ignore unreliable DNS servers.
Collect statistics about DNS query success state and delay. Ignore
servers that have been tried at least five times and have a success rate
of < 0.25. Retry these servers once every 180s.

Bug: 25731675
Change-Id: I78e24f43e388dca82fb81835e1796f4c7dce8da3
2016-04-05 11:42:43 +09:00
Elliott Hughes
506c6deff7 Sync with upstream OpenBSD.
Also some minor build cleanup.

Change-Id: Ibd20602d7ea45685f0c47fceb00ffd6c7ae35954
2016-01-15 16:30:18 -08:00
Erik Kline
01e37c9665 Pass around struct android_net_context for better behaviour
Group network context elements in to a single struct and
add a version of android_getaddrinfofornet() that accepts it.

The introduction of UID-based routing means that the UID is an
integral part of the network context when evaluating connectivity,
sorting addresses, etc.

Also, introduce a distinction between DNS netids/marks and those
expected to be used by the application.  This can be important
when the network an application is using is not the same as the
network on which DNS queries will be issued.

Additionally, de-duplicate the UDP connect logic (collapse both
_test_connect() and _find_src_addr() into just the latter).

Bug: 19470192
Bug: 20733156
Bug: 21832279
Change-Id: If16c2f4744695f507993afdac078ca105eb5d3e4
2015-06-29 18:39:54 +09:00
Yabin Cui
2d8f9b5aea Define MAXHOSTNAMELEN explicitly in source files.
Bug: 19093777
Bug: 19092844
Change-Id: I0778507ca2d5c008abb9a6d6315d0909263a8817
2015-02-09 19:56:47 -08:00
Yabin Cui
58d33a51f3 Sync with upstream for gethnamaddr.c.
Bug: 18566967
Change-Id: I37e7410226b49eec67614e20b2c1d5e3e47817a5
2014-12-17 16:19:27 -08:00
Elliott Hughes
9773fa3ffd Clean up DNS proxying.
Remove code duplication and fall back to trying directly if the proxy
isn't available. With this, tests still work if netd is dead (perhaps
because you've run "adb shell stop", or because you're running on the host).

Bug: 18547878
Change-Id: Ia4a9aa18b1fc79e09735107246989fa7fc6c8455
2014-12-10 17:14:02 -08:00
Dan Albert
a2220ffb74 am 72d72d91: Merge "Replace uses of sprintf(3) with snprintf(3)."
* commit '72d72d91262fabe6bc169618ef3acb0721441cf0':
  Replace uses of sprintf(3) with snprintf(3).
2014-10-09 00:13:06 +00:00
Dan Albert
cfd8c45725 Replace uses of sprintf(3) with snprintf(3).
At -00, the compiler warns about sprintf(3), and it is promoted to an
error by -Werror.

Change-Id: Ibb380d27d7eb09dda8ac785be2478d656b379190
2014-10-08 16:12:27 -07:00
Paul Jensen
1544eae56e Revert most of "Cleanup: Delete dead code."
This reverts most of commit 2582f02a01.
The DNS cache flushing code needs to be called when routes change.

Change-Id: I5b04121bc428cc6a2e136b6c3269c395bfb4981f
bug:16549455
2014-08-06 13:38:16 -04:00
Sreeram Ramachandran
2582f02a01 Cleanup: Delete dead code.
Bug: 15413389
Change-Id: I315468832ef18ffc84174e54774ab63b86d284dc
2014-07-22 11:24:17 -07:00
Elliott Hughes
dd9efcbab6 am c5f1504e: am 6cdab387: Merge "Restore <nsswitch.h> which is BSD API, not private."
* commit 'c5f1504e3db3a39bb951bf01e2d0d758ca93cc44':
  Restore <nsswitch.h> which is BSD API, not private.
2014-06-30 23:16:01 +00:00
Elliott Hughes
a311704103 Restore <nsswitch.h> which is BSD API, not private.
Also make nsdispatch non-hidden. Firefox uses it.

Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1030899
Change-Id: Iaccc1ec813d196ec91ac475fcc4ae9dca756861d
2014-06-30 14:15:34 -07:00
Elliott Hughes
1f29fd72c8 am 7e6f6965: am 1e7ae47d: Merge "Bring our "libresolv" stuff in line with glibc."
* commit '7e6f6965982183ebae357e61e7bad55b91e97cc9':
  Bring our "libresolv" stuff in line with glibc.
2014-06-13 21:50:45 +00:00
Elliott Hughes
62e50ea8de am 294cae0f: am 1aaed87f: Merge "Somewhere, the declaration of _resolv_delete_cache_for_net went missing."
* commit '294cae0f18ceae96e1a5f8b42ae9fd8064b98746':
  Somewhere, the declaration of _resolv_delete_cache_for_net went missing.
2014-06-13 01:51:30 +00:00
Elliott Hughes
b38018f786 am c189362d: am 564222e3: Merge "Use default hidden visibility to build libc_dns."
* commit 'c189362d879520243cc9e1ba65b9828165efa159':
  Use default hidden visibility to build libc_dns.
2014-06-13 00:48:44 +00:00
Elliott Hughes
8563802b04 Use default hidden visibility to build libc_dns.
Bug: 11156955
Change-Id: Ia443705f5fbee0681039d4480abc89850968f475
2014-06-12 13:35:41 -07:00
Elliott Hughes
e8e453439f Bring our "libresolv" stuff in line with glibc.
Despite the name, most of resolv_private.h is actually in glibc; it's just
that there it's tucked away in libresolv whereas we have it in libc.

Change-Id: Ibcf6603f1141ffd2661cee0bffa83052d4f9e549
2014-06-13 11:50:07 -07:00
Elliott Hughes
7f2d4c21cc Somewhere, the declaration of _resolv_delete_cache_for_net went missing.
I couldn't work out where this went missing from "git log", but it became
important with the switch to hidden visibility.

Change-Id: I921f81e36642a2c65c3ec85dc9b5b87c5d977a5b
2014-06-12 18:40:06 -07:00
Paul Jensen
31ad03761d Make host resolver call __connect() rather than connect() so mark isn't cleared.
Calling connect() will erase the mark set by the host resolver code because the
explicitlySelected bit of the Fwmark isn't set.  It's by design that the
explicitlySelected bit isn't set as this facilitates falling through to other
routing rules if the selected network doesn't provide a route to the DNS server
as may be the case with VPNs.

Change-Id: I60ba7c754194ead97df3ac6a6c5b3db1f446dac8
2014-05-30 08:02:52 -04:00
Paul Jensen
41d9a50371 Add support for deleting per-network DNS resolver caches.
This is required when the possible range of NetIds is large to
prevent netd consuming excessive amounts of memory.
This required replacing the per-cache locks in favor of a single
global lock to prevent accesses to deleted caches.

Change-Id: I99d058bafea5de743e56075dbed74031da4df63f
2014-05-14 04:16:18 -07:00
Szymon Jakubczak
ea9bf67881 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
2014-04-01 16:25:49 -04:00
Calin Juravle
cecc036970 Moved private dns header to their own dir.
Bug: 13219633
Change-Id: I3435ef7564b9ad3c7b54188a0809440993b36c9e
2014-03-03 20:40:41 +00:00