Implement DoT revalidation

The revalidation starts from DnsTlsDispatcher which uses a counter
for counting the number of continuous network_error failures of a
DoT server. The mechanics works for private DNS opportunistic mode.

- Once the counter reaches dot_revalidation_threshold, DnsTlsDispatcher
  sends a revalidation request to PrivateDnsConfiguration to validate
  the DoT server.
- Once the counter reaches dot_xport_unusable_threshold, DnsTlsDispatcher
  marks the transport of the DoT server as unusable. The DoT server
  won't be used for at least 5 minutes.

DoT revalidation runs when the followings are met:
  [1] the private DNS setting is opportunistic mode
  [2] the requested DoT server is valid to be used on the network
  [3] the requested DoT server is currently marked as Validation::success

The above mechanics runs when the feature flag "dot_revalidation_threshold"
is a positive and zon-zero value, and is -1 when the mechanics is
disabled.

Bug: 79727473
Test: atest when all the flags off
        dot_revalidation_threshold: -1
        dot_async_handshake: 0
        dot_xport_unusable_threshold: -1
        dot_maxtries: 3
        parallel_lookup_sleep_time: 2
        dot_connect_timeout_ms: 127000
        parallel_lookup_release: 0
        sort_nameservers: 0
        keep_listening_udp: 0

Test: atest when all the flags on
        dot_revalidation_threshold: 10
        dot_async_handshake: 1
        dot_xport_unusable_threshold: 20
        dot_maxtries: 1
        parallel_lookup_sleep_time: 2
        dot_connect_timeout_ms: 10000
        parallel_lookup_release: 1
        sort_nameservers: 1
        keep_listening_udp: 1

Change-Id: Id442529468d63156a9aebf30ea5f142dfa689a97
7 files changed
tree: f356d3612e202044d1c5fb7d0080978e9f770c2c
  1. aidl_api/
  2. apex/
  3. binder/
  4. include/
  5. tests/
  6. .editorconfig
  7. Android.bp
  8. cbindgen.toml
  9. Dns64Configuration.cpp
  10. Dns64Configuration.h
  11. DnsProxyListener.cpp
  12. DnsProxyListener.h
  13. DnsQueryLog.cpp
  14. DnsQueryLog.h
  15. DnsQueryLogTest.cpp
  16. DnsResolver.cpp
  17. DnsResolver.h
  18. DnsResolverService.cpp
  19. DnsResolverService.h
  20. DnsStats.cpp
  21. DnsStats.h
  22. DnsStatsTest.cpp
  23. DnsTlsDispatcher.cpp
  24. DnsTlsDispatcher.h
  25. DnsTlsQueryMap.cpp
  26. DnsTlsQueryMap.h
  27. DnsTlsServer.cpp
  28. DnsTlsServer.h
  29. DnsTlsSessionCache.cpp
  30. DnsTlsSessionCache.h
  31. DnsTlsSocket.cpp
  32. DnsTlsSocket.h
  33. DnsTlsSocketFactory.h
  34. DnsTlsTransport.cpp
  35. DnsTlsTransport.h
  36. doh.h
  37. doh.rs
  38. doh_ffi_test.cpp
  39. Experiments.cpp
  40. Experiments.h
  41. ExperimentsTest.cpp
  42. getaddrinfo.cpp
  43. getaddrinfo.h
  44. gethnamaddr.cpp
  45. gethnamaddr.h
  46. hostent.h
  47. IDnsTlsSocket.h
  48. IDnsTlsSocketFactory.h
  49. IDnsTlsSocketObserver.h
  50. libnetd_resolv.map.txt
  51. LockedQueue.h
  52. NOTICE
  53. OperationLimiter.h
  54. OperationLimiterTest.cpp
  55. OWNERS
  56. params.h
  57. PREUPLOAD.cfg
  58. PrivateDnsCommon.h
  59. PrivateDnsConfiguration.cpp
  60. PrivateDnsConfiguration.h
  61. PrivateDnsConfigurationTest.cpp
  62. PrivateDnsValidationObserver.h
  63. README-DoT.md
  64. README.md
  65. res_cache.cpp
  66. res_comp.cpp
  67. res_comp.h
  68. res_debug.cpp
  69. res_debug.h
  70. res_mkquery.cpp
  71. res_query.cpp
  72. res_send.cpp
  73. res_send.h
  74. res_stats.cpp
  75. resolv_cache.h
  76. resolv_private.h
  77. resolv_rust_test_config_template.xml
  78. resolv_test_config_template.xml
  79. ResolverController.cpp
  80. ResolverController.h
  81. ResolverEventReporter.cpp
  82. ResolverEventReporter.h
  83. ResolverStats.h
  84. sethostent.cpp
  85. stats.h
  86. stats.proto
  87. TEST_MAPPING
  88. util.cpp
  89. util.h
README.md

Logging

This code uses LOG(X) for logging. Log levels are VERBOSE,DEBUG,INFO,WARNING and ERROR. The default setting is WARNING and logs relate to WARNING and ERROR will be shown. If you want to enable the DEBUG level logs, using following command. adb shell service call dnsresolver 10 i32 1 VERBOSE 0 DEBUG 1 INFO 2 WARNING 3 ERROR 4 Verbose resolver logs could contain PII -- do NOT enable in production builds.