Log DNS resolved answers

Introduce a thread-safe queue, DnsQueryLog, to log the DNS resolved answers
which are not found in the cache. The sensitive data is masked in order
not to reveal privacy information. The log can be shown only by
"dumpsys dnsresolver querylog", and it can show only the most-recent-one-hour
queries.

Example output:
DNS query log (last 60 minutes):
  time=17:27:09.262 netId=100 uid=10107 pid=3322 hostname=w*** answer=[2404:***, 216.***] (33ms)
  time=17:27:14.303 netId=100 uid=10097 pid=3363 hostname=w*** answer=[13.***] (21ms)

Bug: 139040977
Test: cd packages/modules/DnsResolver && atest
Test: "adb shell dumpsys dnsresolver querylog" passed
Change-Id: I8d063f4ac920f41c4fbc77e60a3e3a919d9daa62
6 files changed
tree: 4ff8fcdfff1094edc150c0f5b7cb93d3a252ea25
  1. aidl_api/
  2. apex/
  3. binder/
  4. include/
  5. tests/
  6. .editorconfig
  7. Android.bp
  8. Dns64Configuration.cpp
  9. Dns64Configuration.h
  10. DnsProxyListener.cpp
  11. DnsProxyListener.h
  12. DnsQueryLog.cpp
  13. DnsQueryLog.h
  14. DnsResolver.cpp
  15. DnsResolver.h
  16. DnsResolverService.cpp
  17. DnsResolverService.h
  18. DnsStats.cpp
  19. DnsStats.h
  20. DnsStatsTest.cpp
  21. DnsTlsDispatcher.cpp
  22. DnsTlsDispatcher.h
  23. DnsTlsQueryMap.cpp
  24. DnsTlsQueryMap.h
  25. DnsTlsServer.cpp
  26. DnsTlsServer.h
  27. DnsTlsSessionCache.cpp
  28. DnsTlsSessionCache.h
  29. DnsTlsSocket.cpp
  30. DnsTlsSocket.h
  31. DnsTlsSocketFactory.h
  32. DnsTlsTransport.cpp
  33. DnsTlsTransport.h
  34. getaddrinfo.cpp
  35. getaddrinfo.h
  36. gethnamaddr.cpp
  37. gethnamaddr.h
  38. hostent.h
  39. IDnsTlsSocket.h
  40. IDnsTlsSocketFactory.h
  41. IDnsTlsSocketObserver.h
  42. libnetd_resolv.map.txt
  43. LockedQueue.h
  44. NOTICE
  45. OWNERS
  46. params.h
  47. PREUPLOAD.cfg
  48. PrivateDnsConfiguration.cpp
  49. PrivateDnsConfiguration.h
  50. README-DoT.md
  51. README.md
  52. res_cache.cpp
  53. res_comp.cpp
  54. res_debug.cpp
  55. res_debug.h
  56. res_init.cpp
  57. res_init.h
  58. res_mkquery.cpp
  59. res_query.cpp
  60. res_send.cpp
  61. res_send.h
  62. res_stats.cpp
  63. resolv_cache.h
  64. resolv_cache_unit_test.cpp
  65. resolv_callback_unit_test.cpp
  66. resolv_private.h
  67. resolv_tls_unit_test.cpp
  68. resolv_unit_test.cpp
  69. ResolverController.cpp
  70. ResolverController.h
  71. ResolverEventReporter.cpp
  72. ResolverEventReporter.h
  73. ResolverStats.h
  74. sethostent.cpp
  75. stats.h
  76. stats.proto
  77. TEST_MAPPING
  78. util.cpp
  79. 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.