Commit graph

101 commits

Author SHA1 Message Date
Elliott Hughes
0ffd7a5fb1 Check for bad packets in getaddrinfo.c's getanswer. am: 87c0dba7b1 am: dc0492ac4f am: f277bb86c6
am: 389e3e92e2

Change-Id: Ie935c8491aa18867a5087ca4cf707eec318b85f6
2016-12-08 21:07:17 +00:00
Elliott Hughes
87c0dba7b1 Check for bad packets in getaddrinfo.c's getanswer.
The near duplicate in gethnamaddr.c was already doing so (this fix
is basically copy and pasted from there, but with both copies modified
to avoid skirting undefined behavior).

Bug: http://b/32322088
Test: browser still works
Change-Id: Ied6662be567fb1bddc7ceb138cae1da77fb57976
(cherry picked from commit 27a4459d94)
2016-11-15 20:19:41 +00:00
Pierre Imai
b0cfefac91 Always update search domain paths.
_resolv_set_nameservers_for_net() so far did not update the search
paths, unless the servers changed as well.

BUG: 28437641
Change-Id: Id31f2d97c173e00357fb2ba95908afb4572c0fc1
(cherry picked from commit 06e2202a4c)
2016-05-12 11:56:42 +09:00
Pierre Imai
0b1a71f9a4 Record the resolution start time on errors.
Also only record samples on the first try for a server.

BUG: 25731675

Change-Id: I10a68813c6636874e63aca1db661e63e1af72a2d
(cherry picked from commit 8b8611a0e6)
2016-05-02 17:46:16 +09:00
Pierre Imai
75746069ea DO NOT MERGE Fix DNS search path info.
Fix the resolver information returned by
android_net_res_stats_get_info_for_net,
erroneously included MAXDNSRCH empty results if no search path was set.

BUG: 25731675
Change-Id: I97ef5d2d47dc62ca403a3323c7f14902e47b29b6
(cherry picked from commit 1b069a990a)
2016-04-27 13:41:42 +09:00
Pierre Imai
21bf063727 DO NOT MERGE 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 14:25:10 +09:00
Pierre Imai
589afca92c DO NOT MERGE 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
(cherry picked from commit fff356786f)
2016-04-21 14:16:01 +09:00
Pierre Imai
e4e4e9da72 DO NOT MERGE: Reduce the amount of logging in Bionic's resolver.
Change-Id: I3b7b5ef5a5ee6ba3ad8654f792400d42d5ecd4b9
2016-04-06 11:30:02 +09:00
Pierre Imai
8b50d08e82 DO NOT MERGE: Fix off-by-one error in res_cache.c
(cherry picked from commit 03844d8cdb)

Change-Id: Ib5fff46ac9211716a1577ee25bb22461c489ea9f
2016-04-06 10:44:00 +09:00
Pierre Imai
4d8e740b08 DO NOT MERGE: 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

(cherry picked from commit 6b3f0d65f2)

Change-Id: Id989404b14fd885fb31a5a4de36a4186be1c9ad1
2016-04-06 10:41:07 +09:00
Pierre Imai
9db1f3efa8 Copy the entire zero-separated DNS seach domain string.
The DNS search string contains zeros as domain separator. The resolver
code erroneously used strlcpy(), which resulted in only the first domain
to be copied. The code uses pointers into this string to access the
individual domains. Since the structure is zero-initialized, this bug only
resulted in zero-length domains instead of accessing unitialized memory.

BUG: 27312811
Change-Id: Ia9d066c405dfcc5e82d6766d93ead2ce574e7b0d
(cherry picked from commit 0967fc7e59)
2016-03-29 12:29:24 +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
Elliott Hughes
dbb17b2831 Fix alignment after variable-length data.
In the serialized output from netd, the strings come first. Some code
assumes -- reasonably enough -- that it can do unaligned reads of pointers,
so we need to ensure alignment after all the strings.

(cherrypick of 65dd858239c4e32a5a1afbc14ac30dbcdd2a50a3.)

Bug: http://b/21192318
Change-Id: I456639127db9a2583f7f738e6b8103375d9387fd
2015-07-06 14:43:28 -07:00
Elliott Hughes
65dd858239 Fix alignment after variable-length data.
In the serialized output from netd, the strings come first. Some code
assumes -- reasonably enough -- that it can do unaligned reads of pointers,
so we need to ensure alignment after all the strings.

Bug: http://b/21192318
Change-Id: I456639127db9a2583f7f738e6b8103375d9387fd
2015-07-06 14:37:46 -07:00
Erik Kline
754f669076 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
(cherry picked from commit 01e37c9665)
2015-06-30 12:12:08 +09: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
Elliott Hughes
6170693e28 Make ThreadLocalBuffer a class rather than a macro.
Bug: 19995392
Change-Id: I497c512648fbe66257da3fb3bcd5c9911f983705
2015-03-31 10:56:58 -07:00
Yabin Cui
9ecb7f40d0 am c3307dc4: Merge "Better control of pthread keys used in bionic."
* commit 'c3307dc43b2526c4031837738b139d22831c5d09':
  Better control of pthread keys used in bionic.
2015-03-05 18:33:31 +00:00
Yabin Cui
4a2891d8c8 Better control of pthread keys used in bionic.
Change-Id: I1e1bc77c0e7879baead6c3417282ce549a1153b5
2015-03-04 16:53:23 -08:00
Yabin Cui
8dc24ee55e am 3a31e697: am ee17e880: Merge "Define MAXHOSTNAMELEN explicitly in source files."
* commit '3a31e697ca3c1207bfec64b555bcff7b129348a3':
  Define MAXHOSTNAMELEN explicitly in source files.
2015-02-10 18:09:57 +00: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
Elliott Hughes
0772f933a4 am 6cf2cf8b: am 542b94d9: Merge "Remove unused CONFIG_SECONDS."
* commit '6cf2cf8bf26b99b7318791c75cbccfd95893b04e':
  Remove unused CONFIG_SECONDS.
2015-01-30 21:16:34 +00:00
Elliott Hughes
4dcfccff8d Remove unused CONFIG_SECONDS.
Bug: https://code.google.com/p/android/issues/detail?id=65951
Change-Id: I8ae7057c68e16618de6dd06cf052426c6cad8a3d
2015-01-29 21:47:37 -08:00
Elliott Hughes
dbfcf000c0 am e40b4eb3: am 7f17aea2: Merge "Add missing includes."
* commit 'e40b4eb35a6f8ae5c286f53abb920b452b7b6792':
  Add missing includes.
2015-01-29 03:33:42 +00:00
Elliott Hughes
05fc1d7050 Add missing includes.
Change-Id: Ibf549266a19a67eb9158d341a69dddfb654be669
2015-01-28 19:23:11 -08:00
Elliott Hughes
5bf4a1729a am dedacf10: am 5c7964c5: Merge "Clean up <stdlib.h> slightly."
* commit 'dedacf109b35e74d76594c29560a09f4ef3eb94d':
  Clean up <stdlib.h> slightly.
2015-01-27 05:00:11 +00:00
Elliott Hughes
5c7964c5f1 Merge "Clean up <stdlib.h> slightly." 2015-01-27 04:49:07 +00:00
Lorenzo Colitti
ecbeee61ed am 329db346: am f2d02c38: Merge "Make bionic compile even if resolver debugging is enabled."
* commit '329db346f54c629e0c9fcc98c21c19619a573e9b':
  Make bionic compile even if resolver debugging is enabled.
2015-01-27 04:14:09 +00:00
Elliott Hughes
76f8916b90 Clean up <stdlib.h> slightly.
Interestingly, this mostly involves cleaning up our implementation of
various <string.h> functions.

Change-Id: Ifaef49b5cb997134f7bc0cc31bdac844bdb9e089
2015-01-26 14:28:41 -08:00
Lorenzo Colitti
616344d169 Make bionic compile even if resolver debugging is enabled.
The code now compiles with all combinations of DEBUG and
DEBUG_DATA except DEBUG_DATA=1, DEBUG=0, which is unsupported.

Change-Id: I9035a65c649df73092f1fc0864ae1cdd9a14aa3b
2015-01-26 16:05:27 +09:00
Elliott Hughes
6428c625e8 am 7d196768: am 927d8be7: Merge "Fix build error when XLOG is enabled"
* commit '7d196768029f36b0e3fa57ba747ce58ef2b1c9d6':
  Fix build error when XLOG is enabled
2015-01-21 02:21:57 +00:00
Patrick Tjin
a6a0949b1d Fix build error when XLOG is enabled
(cherrypick of 79a49c9857f3949fc13373eeb179f27b6ecdca81.)

Change-Id: I7bb44fd1fe3ef2ddfc115247f328eccfceeb5352
Signed-off-by: Patrick Tjin <pattjin@google.com>
2015-01-20 16:12:45 -08:00
Elliott Hughes
857e112443 am e6594658: am 8623dc75: Merge "Fix freeaddrinfo(NULL)."
* commit 'e6594658f7d36172007a2573e345d6ae0d0ac58a':
  Fix freeaddrinfo(NULL).
2015-01-09 02:58:56 +00:00
Elliott Hughes
c62a4b5a7a Fix freeaddrinfo(NULL).
Bug: https://code.google.com/p/android/issues/detail?id=13228
Change-Id: I5e3b126d90d750a93ac0b8872198e50ba047e603
2015-01-08 17:28:46 -08:00
Yabin Cui
598f86661d am e4d3161a: am 4c30fedf: Merge "Move gethtnamaddr.c to net/ subdirectory."
* commit 'e4d3161a84c0373d35f43f981559212a9ae44397':
  Move gethtnamaddr.c to net/ subdirectory.
2014-12-20 03:26:19 +00:00
Yabin Cui
a2177c6ccb Move gethtnamaddr.c to net/ subdirectory.
It may be the better place to stay.

Change-Id: I517cc2769f63e1873191768c4732907c14f2c60e
2014-12-19 17:29:04 -08:00
Yabin Cui
b695cb47c3 am be327941: am e28a1864: Merge "Support gethostbyname_r_ERANGE."
* commit 'be32794141e95ea5d65626bbf29be95b9d974d54':
  Support gethostbyname_r_ERANGE.
2014-12-19 23:02:51 +00:00
Yabin Cui
7069256495 Support gethostbyname_r_ERANGE.
Bug: 18802601
Change-Id: Iaa64921e96f91e330f1845c5399ee8aba39d9c10
2014-12-19 14:11:29 -08:00
Yabin Cui
858e239094 am 9a734138: am 370a3e57: Merge "Sync with upstream for gethnamaddr.c."
* commit '9a734138138fcde0a2f0935e86246b9d7ff0ccb1':
  Sync with upstream for gethnamaddr.c.
2014-12-18 21:49:52 +00:00
Yabin Cui
58d33a51f3 Sync with upstream for gethnamaddr.c.
Bug: 18566967
Change-Id: I37e7410226b49eec67614e20b2c1d5e3e47817a5
2014-12-17 16:19:27 -08:00
Yabin Cui
bb3579f878 am 96cd50f2: am 0e32e39d: Merge "Fix pthread key num calculation."
* commit '96cd50f2fc33b0d342f1733894b06fd59a725519':
  Fix pthread key num calculation.
2014-12-13 03:03:51 +00:00
Yabin Cui
6c238f2926 Fix pthread key num calculation.
Bug: 18723085
Change-Id: Iba2c834b350e4cdba0b2d771b221560a3e5df952
2014-12-12 17:00:08 -08:00
Elliott Hughes
a70d54786f am 1dff030e: am e7b8bc4e: Merge "Clean up DNS proxying."
* commit '1dff030e6eb527eeb4e7ed163cf19641fdb3872b':
  Clean up DNS proxying.
2014-12-11 18:55:55 +00: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
Lorenzo Colitti
8a94b864bf am e5477f83: Fail queries fast if no DNS servers are configured.
* commit 'e5477f83b0a639b86d8cbe710f25d9808a8f72af':
  Fail queries fast if no DNS servers are configured.
2014-12-02 07:00:47 +00:00
Lorenzo Colitti
e5477f83b0 Fail queries fast if no DNS servers are configured.
When no DNS servers are configured (and thus there is no chance
that the DNS query will suceed), res_nsend returns early, but
it does not tell the cache that the query has failed.
Therefore, if the caller retries the query, it will block for
PENDING_REQUEST_TIMEOUT (= 20 seconds) waiting for the "existing
query" (which isn't actually doing anything) to complete.

Bug: 18240188
Bug: 18327075
Change-Id: I0df13ff4a17ee65e640be96695a3af31b020963a
2014-12-01 20:03:25 +00:00
Robert Alm
3638a83657 Add error-check when mapping socket to fd
The call to fdopen can fail in several ways.
The fprintf on the next line will then dereference a
NULL-pointer FILE*.
Added a NULL-check, closed the socket, returned system error
and added a comment about it.

Change-Id: I7a6b26aa3c79452b1fdd76af12dfa75da88cbad7
2014-11-27 11:01:50 -08:00
Elliott Hughes
55293c1dad Don't receive structs containing pointers over sockets.
Fixes x86-64 netd.

Change-Id: Iee5ef802ebbf2e000b2593643de4eec46f296c04
2014-11-12 22:06:35 -08:00
Elliott Hughes
ac5df33e09 am 6c5694b6: Merge "Migrate system/extra getaddrinfo test, and fix a bug in getservbyname(3)."
* commit '6c5694b6c8343d740c36adbe904442cecd8030a6':
  Migrate system/extra getaddrinfo test, and fix a bug in getservbyname(3).
2014-10-28 04:33:09 +00:00
Derek Xue
ba811120ae Migrate system/extra getaddrinfo test, and fix a bug in getservbyname(3).
This change is to migrate the getaddrinfo tests defined in the old file
system/extras/tests/bionic/libc/common/test_getaddrinfo.c
to the new place bionic/tests/netdb_test.cpp.

The test here is more thorough, and catches a bug in getservbyname(3)
that was breaking getaddrinfo(3)'s ability to look up services by name
without a hint that would cause it to ask for a specific protocol.

Change-Id: Ief5ebd0869496d1bc6a97861dfefa04bdf24bab1
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2014-10-22 22:23:10 -07:00