grpc 1.74.1 → 1.75.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +83 -41
  3. data/include/grpc/credentials.h +7 -1
  4. data/src/core/call/client_call.cc +4 -4
  5. data/src/core/call/filter_fusion.h +1230 -0
  6. data/src/core/call/metadata.cc +22 -0
  7. data/src/core/call/metadata.h +24 -2
  8. data/src/core/channelz/channelz.cc +10 -17
  9. data/src/core/channelz/channelz.h +58 -19
  10. data/src/core/channelz/channelz_registry.cc +0 -162
  11. data/src/core/channelz/channelz_registry.h +14 -7
  12. data/src/core/channelz/property_list.cc +19 -23
  13. data/src/core/channelz/property_list.h +3 -1
  14. data/src/core/channelz/v2tov1/convert.cc +683 -0
  15. data/src/core/channelz/v2tov1/convert.h +58 -0
  16. data/src/core/channelz/v2tov1/legacy_api.cc +425 -0
  17. data/src/core/channelz/v2tov1/legacy_api.h +32 -0
  18. data/src/core/channelz/v2tov1/property_list.cc +118 -0
  19. data/src/core/channelz/v2tov1/property_list.h +52 -0
  20. data/src/core/client_channel/client_channel_filter.cc +5 -4
  21. data/src/core/client_channel/client_channel_filter.h +2 -2
  22. data/src/core/client_channel/client_channel_internal.h +2 -1
  23. data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
  24. data/src/core/client_channel/subchannel.cc +14 -6
  25. data/src/core/client_channel/subchannel.h +2 -0
  26. data/src/core/config/core_configuration.cc +3 -1
  27. data/src/core/config/core_configuration.h +12 -0
  28. data/src/core/credentials/transport/alts/alts_credentials.cc +5 -0
  29. data/src/core/credentials/transport/alts/check_gcp_environment_windows.cc +2 -0
  30. data/src/core/credentials/transport/channel_creds_registry_init.cc +3 -1
  31. data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -1
  32. data/src/core/credentials/transport/ssl/ssl_security_connector.cc +8 -3
  33. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -24
  34. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +19 -8
  35. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +96 -54
  36. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +15 -2
  37. data/src/core/credentials/transport/tls/spiffe_utils.cc +371 -0
  38. data/src/core/credentials/transport/tls/spiffe_utils.h +171 -0
  39. data/src/core/credentials/transport/tls/ssl_utils.cc +11 -10
  40. data/src/core/credentials/transport/tls/ssl_utils.h +4 -2
  41. data/src/core/credentials/transport/tls/tls_credentials.cc +2 -0
  42. data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -26
  43. data/src/core/credentials/transport/tls/tls_security_connector.h +12 -12
  44. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
  45. data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
  46. data/src/core/ext/filters/http/client_authority_filter.cc +1 -2
  47. data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
  48. data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
  49. data/src/core/ext/filters/message_size/message_size_filter.cc +4 -4
  50. data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
  51. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -5
  52. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +3 -2
  53. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
  55. data/src/core/ext/transport/chttp2/transport/frame.cc +89 -6
  56. data/src/core/ext/transport/chttp2/transport/frame.h +38 -0
  57. data/src/core/ext/transport/chttp2/transport/header_assembler.h +5 -14
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
  59. data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +294 -78
  60. data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +128 -9
  61. data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
  62. data/src/core/ext/transport/chttp2/transport/http2_settings.h +52 -35
  63. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +61 -0
  64. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +142 -0
  65. data/src/core/ext/transport/chttp2/transport/http2_transport.cc +81 -3
  66. data/src/core/ext/transport/chttp2/transport/http2_transport.h +12 -1
  67. data/src/core/ext/transport/chttp2/transport/message_assembler.h +2 -2
  68. data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
  69. data/src/core/ext/transport/chttp2/transport/ping_promise.cc +2 -1
  70. data/src/core/ext/transport/chttp2/transport/ping_promise.h +22 -5
  71. data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
  72. data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
  73. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -4
  74. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb.h +4959 -0
  75. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.c +1111 -0
  76. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.h +108 -0
  77. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +142 -54
  78. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +18 -14
  79. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +2 -2
  80. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +716 -0
  81. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.h +227 -0
  82. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +86 -88
  83. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +2 -2
  84. data/src/core/filter/auth/auth_filters.h +2 -2
  85. data/src/core/filter/fused_filters.cc +154 -0
  86. data/src/core/handshaker/security/legacy_secure_endpoint.cc +1 -1
  87. data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
  88. data/src/core/handshaker/security/secure_endpoint.cc +28 -13
  89. data/src/core/handshaker/security/secure_endpoint.h +8 -0
  90. data/src/core/lib/channel/promise_based_filter.cc +15 -25
  91. data/src/core/lib/channel/promise_based_filter.h +6 -5
  92. data/src/core/lib/event_engine/ares_resolver.h +3 -1
  93. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -5
  94. data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -1
  95. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +263 -0
  96. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.h +107 -0
  97. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +31 -3
  98. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +12 -0
  99. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +12 -10
  100. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +6 -4
  101. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +15 -14
  102. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +7 -5
  103. data/src/core/lib/event_engine/posix_engine/event_poller.h +0 -8
  104. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -5
  105. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
  106. data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +1 -0
  107. data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +4 -4
  108. data/src/core/lib/event_engine/posix_engine/lockfree_event.h +3 -4
  109. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +2 -2
  110. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +188 -199
  111. data/src/core/lib/event_engine/posix_engine/posix_engine.h +30 -45
  112. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -1
  113. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +1 -1
  114. data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +2 -1
  115. data/src/core/lib/experiments/experiments.cc +120 -6
  116. data/src/core/lib/experiments/experiments.h +46 -3
  117. data/src/core/lib/iomgr/combiner.cc +1 -1
  118. data/src/core/lib/iomgr/exec_ctx.h +3 -9
  119. data/src/core/lib/iomgr/socket_mutator.cc +1 -1
  120. data/src/core/lib/iomgr/socket_utils_posix.cc +1 -1
  121. data/src/core/lib/iomgr/socket_utils_posix.h +1 -1
  122. data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
  123. data/src/core/lib/iomgr/tcp_posix.cc +3 -3
  124. data/src/core/lib/promise/activity.h +2 -2
  125. data/src/core/lib/promise/mpsc.cc +8 -8
  126. data/src/core/lib/promise/party.cc +7 -7
  127. data/src/core/lib/promise/party.h +4 -4
  128. data/src/core/lib/promise/poll.h +10 -0
  129. data/src/core/lib/resource_quota/memory_quota.cc +90 -3
  130. data/src/core/lib/resource_quota/memory_quota.h +20 -9
  131. data/src/core/lib/resource_quota/periodic_update.cc +14 -0
  132. data/src/core/lib/resource_quota/periodic_update.h +8 -0
  133. data/src/core/lib/resource_quota/resource_quota.cc +15 -4
  134. data/src/core/lib/resource_quota/resource_quota.h +3 -0
  135. data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -2
  136. data/src/core/lib/surface/call.cc +5 -5
  137. data/src/core/lib/surface/call.h +6 -5
  138. data/src/core/lib/surface/completion_queue.cc +2 -4
  139. data/src/core/lib/surface/filter_stack_call.cc +1 -1
  140. data/src/core/lib/surface/version.cc +2 -2
  141. data/src/core/lib/transport/promise_endpoint.cc +2 -2
  142. data/src/core/lib/transport/promise_endpoint.h +3 -3
  143. data/src/core/load_balancing/endpoint_list.cc +29 -2
  144. data/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +3 -3
  145. data/src/core/load_balancing/grpclb/client_load_reporting_filter.h +1 -1
  146. data/src/core/load_balancing/pick_first/pick_first.cc +12 -5
  147. data/src/core/load_balancing/xds/xds_cluster_impl.cc +5 -3
  148. data/src/core/net/socket_mutator.cc +19 -0
  149. data/src/core/net/socket_mutator.h +25 -0
  150. data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
  151. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +6 -1
  152. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -1
  153. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +8 -5
  154. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  155. data/src/core/resolver/xds/xds_dependency_manager.cc +1 -1
  156. data/src/core/server/server.cc +1 -1
  157. data/src/core/server/server_call_tracer_filter.cc +0 -66
  158. data/src/core/server/server_call_tracer_filter.h +64 -0
  159. data/src/core/server/server_config_selector_filter.cc +1 -1
  160. data/src/core/service_config/service_config_channel_arg_filter.cc +3 -60
  161. data/src/core/service_config/service_config_channel_arg_filter.h +82 -0
  162. data/src/core/telemetry/call_tracer.cc +20 -14
  163. data/src/core/telemetry/call_tracer.h +22 -17
  164. data/src/core/telemetry/metrics.h +8 -8
  165. data/src/core/telemetry/stats_data.cc +151 -151
  166. data/src/core/telemetry/stats_data.h +87 -87
  167. data/src/core/transport/auth_context.cc +20 -0
  168. data/src/core/transport/auth_context.h +4 -0
  169. data/src/core/transport/auth_context_comparator_registry.h +69 -0
  170. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -3
  171. data/src/core/tsi/ssl_transport_security.cc +202 -32
  172. data/src/core/tsi/ssl_transport_security.h +19 -10
  173. data/src/core/tsi/ssl_transport_security_utils.cc +21 -0
  174. data/src/core/tsi/ssl_transport_security_utils.h +4 -0
  175. data/src/core/util/http_client/httpcli_security_connector.cc +3 -1
  176. data/src/core/util/latent_see.cc +178 -146
  177. data/src/core/util/latent_see.h +245 -188
  178. data/src/core/util/single_set_ptr.h +5 -2
  179. data/src/core/util/useful.h +91 -0
  180. data/src/core/util/windows/directory_reader.cc +1 -0
  181. data/src/core/util/windows/thd.cc +1 -3
  182. data/src/core/util/work_serializer.cc +1 -1
  183. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +32 -5
  184. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +5 -0
  185. data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
  186. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  187. data/src/ruby/lib/grpc/version.rb +1 -1
  188. data/third_party/cares/cares/include/ares.h +925 -460
  189. data/third_party/cares/cares/include/ares_dns.h +86 -71
  190. data/third_party/cares/cares/include/ares_dns_record.h +1118 -0
  191. data/third_party/cares/cares/include/ares_nameser.h +215 -189
  192. data/third_party/cares/cares/include/ares_version.h +37 -14
  193. data/third_party/cares/cares/src/lib/ares_addrinfo2hostent.c +305 -0
  194. data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +245 -0
  195. data/third_party/cares/cares/src/lib/ares_android.c +216 -164
  196. data/third_party/cares/cares/src/lib/ares_android.h +25 -14
  197. data/third_party/cares/cares/src/lib/ares_cancel.c +68 -44
  198. data/third_party/cares/cares/src/lib/ares_close_sockets.c +137 -0
  199. data/third_party/cares/cares/src/lib/ares_conn.c +511 -0
  200. data/third_party/cares/cares/src/lib/ares_conn.h +196 -0
  201. data/third_party/cares/cares/src/lib/ares_cookie.c +461 -0
  202. data/third_party/cares/cares/src/lib/ares_data.c +93 -181
  203. data/third_party/cares/cares/src/lib/ares_data.h +50 -39
  204. data/third_party/cares/cares/src/lib/ares_destroy.c +127 -89
  205. data/third_party/cares/cares/src/lib/ares_free_hostent.c +35 -24
  206. data/third_party/cares/cares/src/lib/ares_free_string.c +24 -16
  207. data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +45 -38
  208. data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +549 -663
  209. data/third_party/cares/cares/src/lib/ares_getenv.c +25 -15
  210. data/third_party/cares/cares/src/lib/ares_getenv.h +26 -18
  211. data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +163 -221
  212. data/third_party/cares/cares/src/lib/ares_gethostbyname.c +222 -223
  213. data/third_party/cares/cares/src/lib/ares_getnameinfo.c +328 -338
  214. data/third_party/cares/cares/src/lib/ares_hosts_file.c +952 -0
  215. data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +25 -19
  216. data/third_party/cares/cares/src/lib/ares_init.c +425 -2091
  217. data/third_party/cares/cares/src/lib/ares_ipv6.h +63 -33
  218. data/third_party/cares/cares/src/lib/ares_library_init.c +110 -54
  219. data/third_party/cares/cares/src/lib/ares_metrics.c +261 -0
  220. data/third_party/cares/cares/src/lib/ares_options.c +418 -332
  221. data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +179 -0
  222. data/third_party/cares/cares/src/lib/ares_private.h +558 -356
  223. data/third_party/cares/cares/src/lib/ares_process.c +1224 -1369
  224. data/third_party/cares/cares/src/lib/ares_qcache.c +430 -0
  225. data/third_party/cares/cares/src/lib/ares_query.c +126 -121
  226. data/third_party/cares/cares/src/lib/ares_search.c +564 -262
  227. data/third_party/cares/cares/src/lib/ares_send.c +264 -93
  228. data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +588 -0
  229. data/third_party/cares/cares/src/lib/ares_setup.h +115 -111
  230. data/third_party/cares/cares/src/lib/ares_socket.c +425 -0
  231. data/third_party/cares/cares/src/lib/ares_socket.h +163 -0
  232. data/third_party/cares/cares/src/lib/ares_sortaddrinfo.c +447 -0
  233. data/third_party/cares/cares/src/lib/ares_strerror.c +83 -48
  234. data/third_party/cares/cares/src/lib/ares_sysconfig.c +639 -0
  235. data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +839 -0
  236. data/third_party/cares/cares/src/lib/ares_sysconfig_mac.c +373 -0
  237. data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +621 -0
  238. data/third_party/cares/cares/src/lib/ares_timeout.c +136 -73
  239. data/third_party/cares/cares/src/lib/ares_update_servers.c +1362 -0
  240. data/third_party/cares/cares/src/lib/ares_version.c +29 -4
  241. data/third_party/cares/cares/src/lib/config-dos.h +88 -89
  242. data/third_party/cares/cares/src/lib/config-win32.h +122 -77
  243. data/third_party/cares/cares/src/lib/dsa/ares_array.c +394 -0
  244. data/third_party/cares/cares/src/lib/dsa/ares_htable.c +447 -0
  245. data/third_party/cares/cares/src/lib/dsa/ares_htable.h +174 -0
  246. data/third_party/cares/cares/src/lib/dsa/ares_htable_asvp.c +224 -0
  247. data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +228 -0
  248. data/third_party/cares/cares/src/lib/dsa/ares_htable_strvp.c +210 -0
  249. data/third_party/cares/cares/src/lib/dsa/ares_htable_szvp.c +188 -0
  250. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  251. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  252. data/third_party/cares/cares/src/lib/dsa/ares_llist.c +382 -0
  253. data/third_party/cares/cares/src/lib/dsa/ares_slist.c +479 -0
  254. data/third_party/cares/cares/src/lib/dsa/ares_slist.h +207 -0
  255. data/third_party/cares/cares/src/lib/event/ares_event.h +191 -0
  256. data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +743 -0
  257. data/third_party/cares/cares/src/lib/event/ares_event_epoll.c +192 -0
  258. data/third_party/cares/cares/src/lib/event/ares_event_kqueue.c +248 -0
  259. data/third_party/cares/cares/src/lib/event/ares_event_poll.c +140 -0
  260. data/third_party/cares/cares/src/lib/event/ares_event_select.c +159 -0
  261. data/third_party/cares/cares/src/lib/event/ares_event_thread.c +567 -0
  262. data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +166 -0
  263. data/third_party/cares/cares/src/lib/event/ares_event_win32.c +978 -0
  264. data/third_party/cares/cares/src/lib/event/ares_event_win32.h +161 -0
  265. data/third_party/cares/cares/src/lib/include/ares_array.h +276 -0
  266. data/third_party/cares/cares/src/lib/include/ares_buf.h +732 -0
  267. data/third_party/cares/cares/src/lib/include/ares_htable_asvp.h +130 -0
  268. data/third_party/cares/cares/src/lib/include/ares_htable_dict.h +123 -0
  269. data/third_party/cares/cares/src/lib/include/ares_htable_strvp.h +130 -0
  270. data/third_party/cares/cares/src/lib/include/ares_htable_szvp.h +118 -0
  271. data/third_party/cares/cares/src/lib/include/ares_htable_vpstr.h +111 -0
  272. data/third_party/cares/cares/src/lib/include/ares_htable_vpvp.h +128 -0
  273. data/third_party/cares/cares/src/lib/include/ares_llist.h +239 -0
  274. data/third_party/cares/cares/src/lib/include/ares_mem.h +38 -0
  275. data/third_party/cares/cares/src/lib/include/ares_str.h +244 -0
  276. data/third_party/cares/cares/src/lib/inet_net_pton.c +202 -157
  277. data/third_party/cares/cares/src/lib/inet_ntop.c +87 -69
  278. data/third_party/cares/cares/src/lib/legacy/ares_create_query.c +78 -0
  279. data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +99 -0
  280. data/third_party/cares/cares/src/lib/legacy/ares_expand_string.c +107 -0
  281. data/third_party/cares/cares/src/lib/legacy/ares_fds.c +80 -0
  282. data/third_party/cares/cares/src/lib/legacy/ares_getsock.c +85 -0
  283. data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  284. data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  285. data/third_party/cares/cares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  286. data/third_party/cares/cares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  287. data/third_party/cares/cares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  288. data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  289. data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  290. data/third_party/cares/cares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  291. data/third_party/cares/cares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  292. data/third_party/cares/cares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  293. data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  294. data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +982 -0
  295. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +307 -0
  296. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.h +72 -0
  297. data/third_party/cares/cares/src/lib/record/ares_dns_name.c +673 -0
  298. data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +1329 -0
  299. data/third_party/cares/cares/src/lib/record/ares_dns_private.h +273 -0
  300. data/third_party/cares/cares/src/lib/record/ares_dns_record.c +1661 -0
  301. data/third_party/cares/cares/src/lib/record/ares_dns_write.c +1229 -0
  302. data/third_party/cares/cares/src/lib/str/ares_buf.c +1498 -0
  303. data/third_party/cares/cares/src/lib/str/ares_str.c +508 -0
  304. data/third_party/cares/cares/src/lib/str/ares_strsplit.c +90 -0
  305. data/third_party/cares/cares/src/lib/str/ares_strsplit.h +51 -0
  306. data/third_party/cares/cares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  307. data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +628 -0
  308. data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +139 -0
  309. data/third_party/cares/cares/src/lib/util/ares_math.c +158 -0
  310. data/third_party/cares/cares/src/lib/util/ares_math.h +45 -0
  311. data/third_party/cares/cares/src/lib/util/ares_rand.c +389 -0
  312. data/third_party/cares/cares/src/lib/util/ares_rand.h +36 -0
  313. data/third_party/cares/cares/src/lib/util/ares_threads.c +614 -0
  314. data/third_party/cares/cares/src/lib/util/ares_threads.h +60 -0
  315. data/third_party/cares/cares/src/lib/util/ares_time.h +48 -0
  316. data/third_party/cares/cares/src/lib/util/ares_timeval.c +95 -0
  317. data/third_party/cares/cares/src/lib/util/ares_uri.c +1626 -0
  318. data/third_party/cares/cares/src/lib/util/ares_uri.h +252 -0
  319. data/third_party/cares/cares/src/lib/windows_port.c +16 -9
  320. metadata +121 -49
  321. data/src/core/util/ring_buffer.h +0 -122
  322. data/third_party/cares/cares/include/ares_rules.h +0 -125
  323. data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +0 -266
  324. data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +0 -240
  325. data/third_party/cares/cares/src/lib/ares__close_sockets.c +0 -61
  326. data/third_party/cares/cares/src/lib/ares__get_hostent.c +0 -260
  327. data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +0 -229
  328. data/third_party/cares/cares/src/lib/ares__read_line.c +0 -73
  329. data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +0 -258
  330. data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +0 -507
  331. data/third_party/cares/cares/src/lib/ares__timeval.c +0 -111
  332. data/third_party/cares/cares/src/lib/ares_create_query.c +0 -197
  333. data/third_party/cares/cares/src/lib/ares_expand_name.c +0 -311
  334. data/third_party/cares/cares/src/lib/ares_expand_string.c +0 -67
  335. data/third_party/cares/cares/src/lib/ares_fds.c +0 -59
  336. data/third_party/cares/cares/src/lib/ares_getsock.c +0 -66
  337. data/third_party/cares/cares/src/lib/ares_iphlpapi.h +0 -221
  338. data/third_party/cares/cares/src/lib/ares_llist.c +0 -63
  339. data/third_party/cares/cares/src/lib/ares_llist.h +0 -39
  340. data/third_party/cares/cares/src/lib/ares_mkquery.c +0 -24
  341. data/third_party/cares/cares/src/lib/ares_nowarn.c +0 -260
  342. data/third_party/cares/cares/src/lib/ares_nowarn.h +0 -61
  343. data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +0 -90
  344. data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +0 -92
  345. data/third_party/cares/cares/src/lib/ares_parse_caa_reply.c +0 -199
  346. data/third_party/cares/cares/src/lib/ares_parse_mx_reply.c +0 -164
  347. data/third_party/cares/cares/src/lib/ares_parse_naptr_reply.c +0 -183
  348. data/third_party/cares/cares/src/lib/ares_parse_ns_reply.c +0 -177
  349. data/third_party/cares/cares/src/lib/ares_parse_ptr_reply.c +0 -228
  350. data/third_party/cares/cares/src/lib/ares_parse_soa_reply.c +0 -179
  351. data/third_party/cares/cares/src/lib/ares_parse_srv_reply.c +0 -168
  352. data/third_party/cares/cares/src/lib/ares_parse_txt_reply.c +0 -214
  353. data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +0 -184
  354. data/third_party/cares/cares/src/lib/ares_platform.c +0 -11042
  355. data/third_party/cares/cares/src/lib/ares_platform.h +0 -43
  356. data/third_party/cares/cares/src/lib/ares_rand.c +0 -279
  357. data/third_party/cares/cares/src/lib/ares_strcasecmp.c +0 -66
  358. data/third_party/cares/cares/src/lib/ares_strcasecmp.h +0 -30
  359. data/third_party/cares/cares/src/lib/ares_strdup.c +0 -42
  360. data/third_party/cares/cares/src/lib/ares_strdup.h +0 -24
  361. data/third_party/cares/cares/src/lib/ares_strsplit.c +0 -94
  362. data/third_party/cares/cares/src/lib/ares_strsplit.h +0 -42
  363. data/third_party/cares/cares/src/lib/ares_writev.c +0 -79
  364. data/third_party/cares/cares/src/lib/ares_writev.h +0 -36
  365. data/third_party/cares/cares/src/lib/bitncmp.c +0 -59
  366. data/third_party/cares/cares/src/lib/bitncmp.h +0 -26
  367. data/third_party/cares/cares/src/lib/setup_once.h +0 -554
  368. data/third_party/cares/cares/src/tools/ares_getopt.h +0 -53
@@ -1,27 +1,37 @@
1
-
2
- /* Copyright 1998, 2011, 2013 by the Massachusetts Institute of Technology.
3
- * Copyright (C) 2017 - 2018 by Christian Ammer
4
- * Copyright (C) 2019 by Andrew Selivanov
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998, 2011, 2013 Massachusetts Institute of Technology
4
+ * Copyright (c) 2017 Christian Ammer
5
+ * Copyright (c) 2019 Andrew Selivanov
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice (including the next
15
+ * paragraph) shall be included in all copies or substantial portions of the
16
+ * Software.
5
17
  *
6
- * Permission to use, copy, modify, and distribute this
7
- * software and its documentation for any purpose and without
8
- * fee is hereby granted, provided that the above copyright
9
- * notice appear in all copies and that both that copyright
10
- * notice and this permission notice appear in supporting
11
- * documentation, and that the name of M.I.T. not be used in
12
- * advertising or publicity pertaining to distribution of the
13
- * software without specific, written prior permission.
14
- * M.I.T. makes no representations about the suitability of
15
- * this software for any purpose. It is provided "as is"
16
- * without express or implied warranty.
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * SPDX-License-Identifier: MIT
17
27
  */
18
28
 
19
- #include "ares_setup.h"
29
+ #include "ares_private.h"
20
30
 
21
31
  #ifdef HAVE_GETSERVBYNAME_R
22
- # if !defined(GETSERVBYNAME_R_ARGS) || \
23
- (GETSERVBYNAME_R_ARGS < 4) || (GETSERVBYNAME_R_ARGS > 6)
24
- # error "you MUST specifiy a valid number of arguments for getservbyname_r"
32
+ # if !defined(GETSERVBYNAME_R_ARGS) || (GETSERVBYNAME_R_ARGS < 4) || \
33
+ (GETSERVBYNAME_R_ARGS > 6)
34
+ # error "you MUST specify a valid number of arguments for getservbyname_r"
25
35
  # endif
26
36
  #endif
27
37
 
@@ -38,41 +48,42 @@
38
48
  #include "ares_nameser.h"
39
49
 
40
50
  #ifdef HAVE_STRINGS_H
41
- #include <strings.h>
51
+ # include <strings.h>
42
52
  #endif
43
53
  #include <assert.h>
44
54
 
45
55
  #ifdef HAVE_LIMITS_H
46
- #include <limits.h>
56
+ # include <limits.h>
47
57
  #endif
48
58
 
49
- #include "ares.h"
50
- #include "bitncmp.h"
51
- #include "ares_private.h"
59
+ #include "ares_dns.h"
52
60
 
53
- #ifdef WATT32
54
- #undef WIN32
55
- #endif
56
- #ifdef WIN32
57
- # include "ares_platform.h"
58
- #endif
59
-
60
- struct host_query
61
- {
62
- ares_channel channel;
63
- char *name;
64
- unsigned short port; /* in host order */
65
- ares_addrinfo_callback callback;
66
- void *arg;
61
+ struct host_query {
62
+ ares_channel_t *channel;
63
+ char *name;
64
+ unsigned short port; /* in host order */
65
+ ares_addrinfo_callback callback;
66
+ void *arg;
67
67
  struct ares_addrinfo_hints hints;
68
- int sent_family; /* this family is what was is being used */
69
- int timeouts; /* number of timeouts we saw for this request */
68
+ int sent_family; /* this family is what was is being used */
69
+ size_t timeouts; /* number of timeouts we saw for this request */
70
+ char *lookups; /* Duplicate memory from channel because of ares_reinit() */
70
71
  const char *remaining_lookups; /* types of lookup we need to perform ("fb" by
71
72
  default, file and dns respectively) */
72
- struct ares_addrinfo *ai; /* store results between lookups */
73
- int remaining; /* number of DNS answers waiting for */
74
- int next_domain; /* next search domain to try */
75
- int nodata_cnt; /* Track nodata responses to possibly override final result */
73
+
74
+ /* Search order for names */
75
+ char **names;
76
+ size_t names_cnt;
77
+ size_t next_name_idx; /* next name index being attempted */
78
+
79
+ struct ares_addrinfo *ai; /* store results between lookups */
80
+ unsigned short qid_a; /* qid for A request */
81
+ unsigned short qid_aaaa; /* qid for AAAA request */
82
+
83
+ size_t remaining; /* number of DNS answers waiting for */
84
+
85
+ /* Track nodata responses to possibly override final result */
86
+ size_t nodata_cnt;
76
87
  };
77
88
 
78
89
  static const struct ares_addrinfo_hints default_hints = {
@@ -82,139 +93,84 @@ static const struct ares_addrinfo_hints default_hints = {
82
93
  0, /* ai_protocol */
83
94
  };
84
95
 
85
- static const struct ares_addrinfo_cname empty_addrinfo_cname = {
86
- INT_MAX, /* ttl */
87
- NULL, /* alias */
88
- NULL, /* name */
89
- NULL, /* next */
90
- };
91
-
92
- static const struct ares_addrinfo_node empty_addrinfo_node = {
93
- 0, /* ai_ttl */
94
- 0, /* ai_flags */
95
- 0, /* ai_family */
96
- 0, /* ai_socktype */
97
- 0, /* ai_protocol */
98
- 0, /* ai_addrlen */
99
- NULL, /* ai_addr */
100
- NULL /* ai_next */
101
- };
102
-
103
- static const struct ares_addrinfo empty_addrinfo = {
104
- NULL, /* cnames */
105
- NULL, /* nodes */
106
- NULL /* name */
107
- };
108
-
109
96
  /* forward declarations */
110
- static void host_callback(void *arg, int status, int timeouts,
111
- unsigned char *abuf, int alen);
112
- static int as_is_first(const struct host_query *hquery);
113
- static int as_is_only(const struct host_query* hquery);
114
- static int next_dns_lookup(struct host_query *hquery);
97
+ static ares_bool_t next_dns_lookup(struct host_query *hquery);
115
98
 
116
- struct ares_addrinfo_cname *ares__malloc_addrinfo_cname()
99
+ struct ares_addrinfo_cname *
100
+ ares_append_addrinfo_cname(struct ares_addrinfo_cname **head)
117
101
  {
118
- struct ares_addrinfo_cname *cname = ares_malloc(sizeof(struct ares_addrinfo_cname));
119
- if (!cname)
120
- return NULL;
102
+ struct ares_addrinfo_cname *tail = ares_malloc_zero(sizeof(*tail));
103
+ struct ares_addrinfo_cname *last = *head;
121
104
 
122
- *cname = empty_addrinfo_cname;
123
- return cname;
124
- }
105
+ if (tail == NULL) {
106
+ return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
107
+ }
125
108
 
126
- struct ares_addrinfo_cname *ares__append_addrinfo_cname(struct ares_addrinfo_cname **head)
127
- {
128
- struct ares_addrinfo_cname *tail = ares__malloc_addrinfo_cname();
129
- struct ares_addrinfo_cname *last = *head;
130
- if (!last)
131
- {
132
- *head = tail;
133
- return tail;
134
- }
109
+ if (!last) {
110
+ *head = tail;
111
+ return tail;
112
+ }
135
113
 
136
- while (last->next)
137
- {
138
- last = last->next;
139
- }
114
+ while (last->next) {
115
+ last = last->next;
116
+ }
140
117
 
141
118
  last->next = tail;
142
119
  return tail;
143
120
  }
144
121
 
145
- void ares__addrinfo_cat_cnames(struct ares_addrinfo_cname **head,
146
- struct ares_addrinfo_cname *tail)
122
+ void ares_addrinfo_cat_cnames(struct ares_addrinfo_cname **head,
123
+ struct ares_addrinfo_cname *tail)
147
124
  {
148
125
  struct ares_addrinfo_cname *last = *head;
149
- if (!last)
150
- {
151
- *head = tail;
152
- return;
153
- }
126
+ if (!last) {
127
+ *head = tail;
128
+ return;
129
+ }
154
130
 
155
- while (last->next)
156
- {
157
- last = last->next;
158
- }
131
+ while (last->next) {
132
+ last = last->next;
133
+ }
159
134
 
160
135
  last->next = tail;
161
136
  }
162
137
 
163
- struct ares_addrinfo *ares__malloc_addrinfo()
164
- {
165
- struct ares_addrinfo *ai = ares_malloc(sizeof(struct ares_addrinfo));
166
- if (!ai)
167
- return NULL;
168
-
169
- *ai = empty_addrinfo;
170
- return ai;
171
- }
172
-
173
- struct ares_addrinfo_node *ares__malloc_addrinfo_node()
174
- {
175
- struct ares_addrinfo_node *node =
176
- ares_malloc(sizeof(struct ares_addrinfo_node));
177
- if (!node)
178
- return NULL;
179
-
180
- *node = empty_addrinfo_node;
181
- return node;
182
- }
183
-
184
138
  /* Allocate new addrinfo and append to the tail. */
185
- struct ares_addrinfo_node *ares__append_addrinfo_node(struct ares_addrinfo_node **head)
139
+ struct ares_addrinfo_node *
140
+ ares_append_addrinfo_node(struct ares_addrinfo_node **head)
186
141
  {
187
- struct ares_addrinfo_node *tail = ares__malloc_addrinfo_node();
142
+ struct ares_addrinfo_node *tail = ares_malloc_zero(sizeof(*tail));
188
143
  struct ares_addrinfo_node *last = *head;
189
- if (!last)
190
- {
191
- *head = tail;
192
- return tail;
193
- }
194
144
 
195
- while (last->ai_next)
196
- {
197
- last = last->ai_next;
198
- }
145
+ if (tail == NULL) {
146
+ return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
147
+ }
148
+
149
+ if (!last) {
150
+ *head = tail;
151
+ return tail;
152
+ }
153
+
154
+ while (last->ai_next) {
155
+ last = last->ai_next;
156
+ }
199
157
 
200
158
  last->ai_next = tail;
201
159
  return tail;
202
160
  }
203
161
 
204
- void ares__addrinfo_cat_nodes(struct ares_addrinfo_node **head,
205
- struct ares_addrinfo_node *tail)
162
+ void ares_addrinfo_cat_nodes(struct ares_addrinfo_node **head,
163
+ struct ares_addrinfo_node *tail)
206
164
  {
207
165
  struct ares_addrinfo_node *last = *head;
208
- if (!last)
209
- {
210
- *head = tail;
211
- return;
212
- }
166
+ if (!last) {
167
+ *head = tail;
168
+ return;
169
+ }
213
170
 
214
- while (last->ai_next)
215
- {
216
- last = last->ai_next;
217
- }
171
+ while (last->ai_next) {
172
+ last = last->ai_next;
173
+ }
218
174
 
219
175
  last->ai_next = tail;
220
176
  }
@@ -224,627 +180,557 @@ void ares__addrinfo_cat_nodes(struct ares_addrinfo_node **head,
224
180
  */
225
181
  static unsigned short lookup_service(const char *service, int flags)
226
182
  {
227
- const char *proto;
183
+ const char *proto;
228
184
  struct servent *sep;
229
185
  #ifdef HAVE_GETSERVBYNAME_R
230
186
  struct servent se;
231
- char tmpbuf[4096];
187
+ char tmpbuf[4096];
232
188
  #endif
233
189
 
234
- if (service)
235
- {
236
- if (flags & ARES_NI_UDP)
237
- proto = "udp";
238
- else if (flags & ARES_NI_SCTP)
239
- proto = "sctp";
240
- else if (flags & ARES_NI_DCCP)
241
- proto = "dccp";
242
- else
243
- proto = "tcp";
190
+ if (service) {
191
+ if (flags & ARES_NI_UDP) {
192
+ proto = "udp";
193
+ } else if (flags & ARES_NI_SCTP) {
194
+ proto = "sctp";
195
+ } else if (flags & ARES_NI_DCCP) {
196
+ proto = "dccp";
197
+ } else {
198
+ proto = "tcp";
199
+ }
244
200
  #ifdef HAVE_GETSERVBYNAME_R
245
- memset(&se, 0, sizeof(se));
246
- sep = &se;
247
- memset(tmpbuf, 0, sizeof(tmpbuf));
248
- #if GETSERVBYNAME_R_ARGS == 6
249
- if (getservbyname_r(service, proto, &se, (void *)tmpbuf, sizeof(tmpbuf),
250
- &sep) != 0)
251
- sep = NULL; /* LCOV_EXCL_LINE: buffer large so this never fails */
252
- #elif GETSERVBYNAME_R_ARGS == 5
253
- sep =
254
- getservbyname_r(service, proto, &se, (void *)tmpbuf, sizeof(tmpbuf));
255
- #elif GETSERVBYNAME_R_ARGS == 4
256
- if (getservbyname_r(service, proto, &se, (void *)tmpbuf) != 0)
257
- sep = NULL;
258
- #else
259
- /* Lets just hope the OS uses TLS! */
260
- sep = getservbyname(service, proto);
261
- #endif
262
- #else
263
- /* Lets just hope the OS uses TLS! */
264
- #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
265
- sep = getservbyname(service, (char *)proto);
201
+ memset(&se, 0, sizeof(se));
202
+ sep = &se;
203
+ memset(tmpbuf, 0, sizeof(tmpbuf));
204
+ # if GETSERVBYNAME_R_ARGS == 6
205
+ if (getservbyname_r(service, proto, &se, (void *)tmpbuf, sizeof(tmpbuf),
206
+ &sep) != 0) {
207
+ sep = NULL; /* LCOV_EXCL_LINE: buffer large so this never fails */
208
+ }
209
+ # elif GETSERVBYNAME_R_ARGS == 5
210
+ sep = getservbyname_r(service, proto, &se, (void *)tmpbuf, sizeof(tmpbuf));
211
+ # elif GETSERVBYNAME_R_ARGS == 4
212
+ if (getservbyname_r(service, proto, &se, (void *)tmpbuf) != 0) {
213
+ sep = NULL;
214
+ }
215
+ # else
216
+ /* Lets just hope the OS uses TLS! */
217
+ sep = getservbyname(service, proto);
218
+ # endif
266
219
  #else
267
- sep = getservbyname(service, proto);
268
- #endif
220
+ /* Lets just hope the OS uses TLS! */
221
+ # if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
222
+ sep = getservbyname(service, (char *)proto);
223
+ # else
224
+ sep = getservbyname(service, proto);
225
+ # endif
269
226
  #endif
270
- return (sep ? ntohs((unsigned short)sep->s_port) : 0);
271
- }
227
+ return (sep ? ntohs((unsigned short)sep->s_port) : 0);
228
+ }
272
229
  return 0;
273
230
  }
274
231
 
275
- /* If the name looks like an IP address or an error occured,
232
+ /* If the name looks like an IP address or an error occurred,
276
233
  * fake up a host entry, end the query immediately, and return true.
277
234
  * Otherwise return false.
278
235
  */
279
- static int fake_addrinfo(const char *name,
280
- unsigned short port,
281
- const struct ares_addrinfo_hints *hints,
282
- struct ares_addrinfo *ai,
283
- ares_addrinfo_callback callback,
284
- void *arg)
236
+ static ares_bool_t fake_addrinfo(const char *name, unsigned short port,
237
+ const struct ares_addrinfo_hints *hints,
238
+ struct ares_addrinfo *ai,
239
+ ares_addrinfo_callback callback, void *arg)
285
240
  {
286
241
  struct ares_addrinfo_cname *cname;
287
- int status = ARES_SUCCESS;
288
- int result = 0;
289
- int family = hints->ai_family;
290
- if (family == AF_INET || family == AF_INET6 || family == AF_UNSPEC)
291
- {
292
- /* It only looks like an IP address if it's all numbers and dots. */
293
- int numdots = 0, valid = 1;
294
- const char *p;
295
- for (p = name; *p; p++)
296
- {
297
- if (!ISDIGIT(*p) && *p != '.')
298
- {
299
- valid = 0;
300
- break;
301
- }
302
- else if (*p == '.')
303
- {
304
- numdots++;
305
- }
306
- }
242
+ ares_status_t status = ARES_SUCCESS;
243
+ ares_bool_t result = ARES_FALSE;
244
+ int family = hints->ai_family;
245
+ if (family == AF_INET || family == AF_INET6 || family == AF_UNSPEC) {
246
+ /* It only looks like an IP address if it's all numbers and dots. */
247
+ size_t numdots = 0;
248
+ ares_bool_t valid = ARES_TRUE;
249
+ const char *p;
250
+ for (p = name; *p; p++) {
251
+ if (!ares_isdigit(*p) && *p != '.') {
252
+ valid = ARES_FALSE;
253
+ break;
254
+ } else if (*p == '.') {
255
+ numdots++;
256
+ }
257
+ }
307
258
 
308
- /* if we don't have 3 dots, it is illegal
309
- * (although inet_pton doesn't think so).
310
- */
311
- if (numdots != 3 || !valid)
312
- result = 0;
313
- else
314
- {
315
- struct in_addr addr4;
316
- result = ares_inet_pton(AF_INET, name, &addr4) < 1 ? 0 : 1;
317
- if (result)
318
- {
319
- status = ares_append_ai_node(AF_INET, port, 0, &addr4, &ai->nodes);
320
- if (status != ARES_SUCCESS)
321
- {
322
- callback(arg, status, 0, NULL);
323
- return 1;
324
- }
325
- }
259
+ /* if we don't have 3 dots, it is illegal
260
+ * (although inet_pton doesn't think so).
261
+ */
262
+ if (numdots != 3 || !valid) {
263
+ result = ARES_FALSE;
264
+ } else {
265
+ struct in_addr addr4;
266
+ result =
267
+ ares_inet_pton(AF_INET, name, &addr4) < 1 ? ARES_FALSE : ARES_TRUE;
268
+ if (result) {
269
+ status = ares_append_ai_node(AF_INET, port, 0, &addr4, &ai->nodes);
270
+ if (status != ARES_SUCCESS) {
271
+ callback(arg, (int)status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */
272
+ return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */
326
273
  }
274
+ }
327
275
  }
276
+ }
328
277
 
329
- if (!result && (family == AF_INET6 || family == AF_UNSPEC))
330
- {
331
- struct ares_in6_addr addr6;
332
- result = ares_inet_pton(AF_INET6, name, &addr6) < 1 ? 0 : 1;
333
- if (result)
334
- {
335
- status = ares_append_ai_node(AF_INET6, port, 0, &addr6, &ai->nodes);
336
- if (status != ARES_SUCCESS)
337
- {
338
- callback(arg, status, 0, NULL);
339
- return 1;
340
- }
341
- }
278
+ if (!result && (family == AF_INET6 || family == AF_UNSPEC)) {
279
+ struct ares_in6_addr addr6;
280
+ result =
281
+ ares_inet_pton(AF_INET6, name, &addr6) < 1 ? ARES_FALSE : ARES_TRUE;
282
+ if (result) {
283
+ status = ares_append_ai_node(AF_INET6, port, 0, &addr6, &ai->nodes);
284
+ if (status != ARES_SUCCESS) {
285
+ callback(arg, (int)status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */
286
+ return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */
287
+ }
342
288
  }
289
+ }
343
290
 
344
- if (!result)
345
- return 0;
346
-
347
- if (hints->ai_flags & ARES_AI_CANONNAME)
348
- {
349
- cname = ares__append_addrinfo_cname(&ai->cnames);
350
- if (!cname)
351
- {
352
- ares_freeaddrinfo(ai);
353
- callback(arg, ARES_ENOMEM, 0, NULL);
354
- return 1;
355
- }
291
+ if (!result) {
292
+ return ARES_FALSE;
293
+ }
356
294
 
357
- /* Duplicate the name, to avoid a constness violation. */
358
- cname->name = ares_strdup(name);
359
- if (!cname->name)
360
- {
361
- ares_freeaddrinfo(ai);
362
- callback(arg, ARES_ENOMEM, 0, NULL);
363
- return 1;
364
- }
295
+ if (hints->ai_flags & ARES_AI_CANONNAME) {
296
+ cname = ares_append_addrinfo_cname(&ai->cnames);
297
+ if (!cname) {
298
+ /* LCOV_EXCL_START: OutOfMemory */
299
+ ares_freeaddrinfo(ai);
300
+ callback(arg, ARES_ENOMEM, 0, NULL);
301
+ return ARES_TRUE;
302
+ /* LCOV_EXCL_STOP */
365
303
  }
366
304
 
305
+ /* Duplicate the name, to avoid a constness violation. */
306
+ cname->name = ares_strdup(name);
307
+ if (!cname->name) {
308
+ ares_freeaddrinfo(ai);
309
+ callback(arg, ARES_ENOMEM, 0, NULL);
310
+ return ARES_TRUE;
311
+ }
312
+ }
313
+
367
314
  ai->nodes->ai_socktype = hints->ai_socktype;
368
315
  ai->nodes->ai_protocol = hints->ai_protocol;
369
316
 
370
317
  callback(arg, ARES_SUCCESS, 0, ai);
371
- return 1;
318
+ return ARES_TRUE;
372
319
  }
373
320
 
374
- static void end_hquery(struct host_query *hquery, int status)
321
+ static void hquery_free(struct host_query *hquery, ares_bool_t cleanup_ai)
375
322
  {
376
- struct ares_addrinfo_node sentinel;
323
+ if (cleanup_ai) {
324
+ ares_freeaddrinfo(hquery->ai);
325
+ }
326
+ ares_strsplit_free(hquery->names, hquery->names_cnt);
327
+ ares_free(hquery->name);
328
+ ares_free(hquery->lookups);
329
+ ares_free(hquery);
330
+ }
331
+
332
+ static void end_hquery(struct host_query *hquery, ares_status_t status)
333
+ {
334
+ struct ares_addrinfo_node sentinel;
377
335
  struct ares_addrinfo_node *next;
378
- if (status == ARES_SUCCESS)
379
- {
380
- if (!(hquery->hints.ai_flags & ARES_AI_NOSORT) && hquery->ai->nodes)
381
- {
382
- sentinel.ai_next = hquery->ai->nodes;
383
- ares__sortaddrinfo(hquery->channel, &sentinel);
384
- hquery->ai->nodes = sentinel.ai_next;
385
- }
386
- next = hquery->ai->nodes;
387
336
 
388
- while (next)
389
- {
390
- next->ai_socktype = hquery->hints.ai_socktype;
391
- next->ai_protocol = hquery->hints.ai_protocol;
392
- next = next->ai_next;
393
- }
337
+ if (status == ARES_SUCCESS) {
338
+ if (!(hquery->hints.ai_flags & ARES_AI_NOSORT) && hquery->ai->nodes) {
339
+ sentinel.ai_next = hquery->ai->nodes;
340
+ ares_sortaddrinfo(hquery->channel, &sentinel);
341
+ hquery->ai->nodes = sentinel.ai_next;
394
342
  }
395
- else
396
- {
397
- /* Clean up what we have collected by so far. */
398
- ares_freeaddrinfo(hquery->ai);
399
- hquery->ai = NULL;
343
+ next = hquery->ai->nodes;
344
+
345
+ while (next) {
346
+ next->ai_socktype = hquery->hints.ai_socktype;
347
+ next->ai_protocol = hquery->hints.ai_protocol;
348
+ next = next->ai_next;
400
349
  }
350
+ } else {
351
+ /* Clean up what we have collected by so far. */
352
+ ares_freeaddrinfo(hquery->ai);
353
+ hquery->ai = NULL;
354
+ }
401
355
 
402
- hquery->callback(hquery->arg, status, hquery->timeouts, hquery->ai);
403
- ares_free(hquery->name);
404
- ares_free(hquery);
356
+ hquery->callback(hquery->arg, (int)status, (int)hquery->timeouts, hquery->ai);
357
+ hquery_free(hquery, ARES_FALSE);
405
358
  }
406
359
 
407
- static int is_localhost(const char *name)
360
+ ares_bool_t ares_is_localhost(const char *name)
408
361
  {
409
- /* RFC6761 6.3 says : The domain "localhost." and any names falling within ".localhost." */
362
+ /* RFC6761 6.3 says : The domain "localhost." and any names falling within
363
+ * ".localhost." */
410
364
  size_t len;
411
365
 
412
- if (name == NULL)
413
- return 0;
366
+ if (name == NULL) {
367
+ return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
368
+ }
414
369
 
415
- if (strcmp(name, "localhost") == 0)
416
- return 1;
370
+ if (ares_strcaseeq(name, "localhost")) {
371
+ return ARES_TRUE;
372
+ }
417
373
 
418
- len = strlen(name);
419
- if (len < 10 /* strlen(".localhost") */)
420
- return 0;
374
+ len = ares_strlen(name);
375
+ if (len < 10 /* strlen(".localhost") */) {
376
+ return ARES_FALSE;
377
+ }
421
378
 
422
- if (strcmp(name + (len - 10 /* strlen(".localhost") */), ".localhost") == 0)
423
- return 1;
379
+ if (ares_strcaseeq(name + (len - 10 /* strlen(".localhost") */),
380
+ ".localhost")) {
381
+ return ARES_TRUE;
382
+ }
424
383
 
425
- return 0;
384
+ return ARES_FALSE;
426
385
  }
427
386
 
428
- static int file_lookup(struct host_query *hquery)
387
+ static ares_status_t file_lookup(struct host_query *hquery)
429
388
  {
430
- FILE *fp;
431
- int error;
432
- int status;
433
- char *path_hosts = NULL;
434
-
435
- if (hquery->hints.ai_flags & ARES_AI_ENVHOSTS)
436
- {
437
- path_hosts = ares_strdup(getenv("CARES_HOSTS"));
438
- if (!path_hosts)
439
- return ARES_ENOMEM;
440
- }
389
+ const ares_hosts_entry_t *entry;
390
+ ares_status_t status;
441
391
 
442
- if (hquery->channel->hosts_path)
443
- {
444
- path_hosts = ares_strdup(hquery->channel->hosts_path);
445
- if (!path_hosts)
446
- return ARES_ENOMEM;
447
- }
392
+ /* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
393
+ if (ares_is_onion_domain(hquery->name)) {
394
+ return ARES_ENOTFOUND;
395
+ }
448
396
 
449
- if (!path_hosts)
450
- {
451
- #ifdef WIN32
452
- char PATH_HOSTS[MAX_PATH];
453
- win_platform platform;
454
-
455
- PATH_HOSTS[0] = '\0';
456
-
457
- platform = ares__getplatform();
458
-
459
- if (platform == WIN_NT)
460
- {
461
- char tmp[MAX_PATH];
462
- HKEY hkeyHosts;
463
-
464
- if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ,
465
- &hkeyHosts) == ERROR_SUCCESS)
466
- {
467
- DWORD dwLength = MAX_PATH;
468
- RegQueryValueExA(hkeyHosts, DATABASEPATH, NULL, NULL, (LPBYTE)tmp,
469
- &dwLength);
470
- ExpandEnvironmentStringsA(tmp, PATH_HOSTS, MAX_PATH);
471
- RegCloseKey(hkeyHosts);
472
- }
473
- }
474
- else if (platform == WIN_9X)
475
- GetWindowsDirectoryA(PATH_HOSTS, MAX_PATH);
476
- else
477
- return ARES_ENOTFOUND;
397
+ status = ares_hosts_search_host(
398
+ hquery->channel,
399
+ (hquery->hints.ai_flags & ARES_AI_ENVHOSTS) ? ARES_TRUE : ARES_FALSE,
400
+ hquery->name, &entry);
478
401
 
479
- strcat(PATH_HOSTS, WIN_PATH_HOSTS);
480
- #elif defined(WATT32)
481
- const char *PATH_HOSTS = _w32_GetHostsFile();
402
+ if (status != ARES_SUCCESS) {
403
+ goto done;
404
+ }
482
405
 
483
- if (!PATH_HOSTS)
484
- return ARES_ENOTFOUND;
485
- #endif
486
- path_hosts = ares_strdup(PATH_HOSTS);
487
- if (!path_hosts)
488
- return ARES_ENOMEM;
489
- }
406
+ status = ares_hosts_entry_to_addrinfo(
407
+ entry, hquery->name, hquery->hints.ai_family, hquery->port,
408
+ (hquery->hints.ai_flags & ARES_AI_CANONNAME) ? ARES_TRUE : ARES_FALSE,
409
+ hquery->ai);
410
+
411
+ if (status != ARES_SUCCESS) {
412
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
413
+ }
490
414
 
491
- fp = fopen(path_hosts, "r");
492
- if (!fp)
493
- {
494
- error = ERRNO;
495
- switch (error)
496
- {
497
- case ENOENT:
498
- case ESRCH:
499
- status = ARES_ENOTFOUND;
500
- break;
501
- default:
502
- DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", error,
503
- strerror(error)));
504
- DEBUGF(fprintf(stderr, "Error opening file: %s\n", path_hosts));
505
- status = ARES_EFILE;
506
- break;
507
- }
508
- }
509
- else
510
- {
511
- status = ares__readaddrinfo(fp, hquery->name, hquery->port, &hquery->hints, hquery->ai);
512
- fclose(fp);
513
- }
514
- ares_free(path_hosts);
515
415
 
416
+ done:
516
417
  /* RFC6761 section 6.3 #3 states that "Name resolution APIs and libraries
517
418
  * SHOULD recognize localhost names as special and SHOULD always return the
518
419
  * IP loopback address for address queries".
519
420
  * We will also ignore ALL errors when trying to resolve localhost, such
520
- * as permissions errors reading /etc/hosts or a malformed /etc/hosts */
521
- if (status != ARES_SUCCESS && is_localhost(hquery->name))
522
- {
523
- return ares__addrinfo_localhost(hquery->name, hquery->port,
524
- &hquery->hints, hquery->ai);
525
- }
421
+ * as permissions errors reading /etc/hosts or a malformed /etc/hosts.
422
+ *
423
+ * Also, just because the query itself returned success from /etc/hosts
424
+ * lookup doesn't mean it returned everything it needed to for all requested
425
+ * address families. As long as we're not on a critical out of memory
426
+ * condition pass it through to fill in any other address classes. */
427
+ if (status != ARES_ENOMEM && ares_is_localhost(hquery->name)) {
428
+ return ares_addrinfo_localhost(hquery->name, hquery->port, &hquery->hints,
429
+ hquery->ai);
430
+ }
526
431
 
527
432
  return status;
528
433
  }
529
434
 
530
- static void next_lookup(struct host_query *hquery, int status)
435
+ static void next_lookup(struct host_query *hquery, ares_status_t status)
436
+ {
437
+ switch (*hquery->remaining_lookups) {
438
+ case 'b':
439
+ /* RFC6761 section 6.3 #3 says "Name resolution APIs SHOULD NOT send
440
+ * queries for localhost names to their configured caching DNS
441
+ * server(s)."
442
+ * Otherwise, DNS lookup. */
443
+ if (!ares_is_localhost(hquery->name) && next_dns_lookup(hquery)) {
444
+ break;
445
+ }
446
+
447
+ hquery->remaining_lookups++;
448
+ next_lookup(hquery, status);
449
+ break;
450
+
451
+ case 'f':
452
+ /* Host file lookup */
453
+ if (file_lookup(hquery) == ARES_SUCCESS) {
454
+ end_hquery(hquery, ARES_SUCCESS);
455
+ break;
456
+ }
457
+ hquery->remaining_lookups++;
458
+ next_lookup(hquery, status);
459
+ break;
460
+ default:
461
+ /* No lookup left */
462
+ end_hquery(hquery, status);
463
+ break;
464
+ }
465
+ }
466
+
467
+ static void terminate_retries(const struct host_query *hquery,
468
+ unsigned short qid)
469
+ {
470
+ unsigned short term_qid =
471
+ (qid == hquery->qid_a) ? hquery->qid_aaaa : hquery->qid_a;
472
+ const ares_channel_t *channel = hquery->channel;
473
+ ares_query_t *query = NULL;
474
+
475
+ /* No other outstanding queries, nothing to do */
476
+ if (!hquery->remaining) {
477
+ return;
478
+ }
479
+
480
+ query = ares_htable_szvp_get_direct(channel->queries_by_qid, term_qid);
481
+ if (query == NULL) {
482
+ return;
483
+ }
484
+
485
+ query->no_retries = ARES_TRUE;
486
+ }
487
+
488
+ static ares_bool_t ai_has_ipv4(struct ares_addrinfo *ai)
531
489
  {
532
- switch (*hquery->remaining_lookups)
533
- {
534
- case 'b':
535
- /* RFC6761 section 6.3 #3 says "Name resolution APIs SHOULD NOT send
536
- * queries for localhost names to their configured caching DNS
537
- * server(s)." */
538
- if (!is_localhost(hquery->name))
539
- {
540
- /* DNS lookup */
541
- if (next_dns_lookup(hquery))
542
- break;
543
- }
544
-
545
- hquery->remaining_lookups++;
546
- next_lookup(hquery, status);
547
- break;
548
-
549
- case 'f':
550
- /* Host file lookup */
551
- if (file_lookup(hquery) == ARES_SUCCESS)
552
- {
553
- end_hquery(hquery, ARES_SUCCESS);
554
- break;
555
- }
556
- hquery->remaining_lookups++;
557
- next_lookup(hquery, status);
558
- break;
559
- default:
560
- /* No lookup left */
561
- end_hquery(hquery, status);
562
- break;
490
+ struct ares_addrinfo_node *node;
491
+
492
+ for (node = ai->nodes; node != NULL; node = node->ai_next) {
493
+ if (node->ai_family == AF_INET) {
494
+ return ARES_TRUE;
563
495
  }
496
+ }
497
+ return ARES_FALSE;
564
498
  }
565
499
 
566
- static void host_callback(void *arg, int status, int timeouts,
567
- unsigned char *abuf, int alen)
500
+ static void host_callback(void *arg, ares_status_t status, size_t timeouts,
501
+ const ares_dns_record_t *dnsrec)
568
502
  {
569
- struct host_query *hquery = (struct host_query*)arg;
570
- int addinfostatus = ARES_SUCCESS;
571
- hquery->timeouts += timeouts;
503
+ struct host_query *hquery = (struct host_query *)arg;
504
+ ares_status_t addinfostatus = ARES_SUCCESS;
505
+ hquery->timeouts += timeouts;
572
506
  hquery->remaining--;
573
507
 
574
- if (status == ARES_SUCCESS)
575
- {
576
- addinfostatus = ares__parse_into_addrinfo(abuf, alen, 1, hquery->port, hquery->ai);
508
+ if (status == ARES_SUCCESS) {
509
+ if (dnsrec == NULL) {
510
+ addinfostatus = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
511
+ } else {
512
+ addinfostatus =
513
+ ares_parse_into_addrinfo(dnsrec, ARES_TRUE, hquery->port, hquery->ai);
514
+ }
515
+
516
+ /* We sent out ipv4 and ipv6 requests simultaneously. If we got a
517
+ * successful ipv4 response, we want to go ahead and tell the ipv6 request
518
+ * that if it fails or times out to not try again since we have the data
519
+ * we need.
520
+ *
521
+ * Our initial implementation of this would terminate retries if we got any
522
+ * successful response (ipv4 _or_ ipv6). But we did get some user-reported
523
+ * issues with this that had bad system configs and odd behavior:
524
+ * https://github.com/alpinelinux/docker-alpine/issues/366
525
+ *
526
+ * Essentially the ipv6 query succeeded but the ipv4 query failed or timed
527
+ * out, and so we only returned the ipv6 address, but the host couldn't
528
+ * use ipv6. If we continued to allow ipv4 retries it would have found a
529
+ * server that worked and returned both address classes (this is clearly
530
+ * unexpected behavior).
531
+ *
532
+ * At some point down the road if ipv6 actually becomes required and
533
+ * reliable we can drop this ipv4 check.
534
+ */
535
+ if (addinfostatus == ARES_SUCCESS && ai_has_ipv4(hquery->ai)) {
536
+ terminate_retries(hquery, ares_dns_record_get_id(dnsrec));
577
537
  }
538
+ }
578
539
 
579
- if (!hquery->remaining)
580
- {
581
- if (addinfostatus != ARES_SUCCESS && addinfostatus != ARES_ENODATA)
582
- {
583
- /* error in parsing result e.g. no memory */
584
- if (addinfostatus == ARES_EBADRESP && hquery->ai->nodes)
585
- {
586
- /* We got a bad response from server, but at least one query
587
- * ended with ARES_SUCCESS */
588
- end_hquery(hquery, ARES_SUCCESS);
589
- }
590
- else
591
- {
592
- end_hquery(hquery, addinfostatus);
593
- }
594
- }
595
- else if (hquery->ai->nodes)
596
- {
597
- /* at least one query ended with ARES_SUCCESS */
598
- end_hquery(hquery, ARES_SUCCESS);
599
- }
600
- else if (status == ARES_ENOTFOUND || status == ARES_ENODATA ||
601
- addinfostatus == ARES_ENODATA)
602
- {
603
- if (status == ARES_ENODATA || addinfostatus == ARES_ENODATA)
604
- hquery->nodata_cnt++;
605
- next_lookup(hquery, hquery->nodata_cnt?ARES_ENODATA:status);
606
- }
607
- else if (status == ARES_EDESTRUCTION)
608
- {
609
- /* NOTE: Could also be ARES_EDESTRUCTION. We need to only call this
610
- * once all queries (there can be multiple for getaddrinfo) are
611
- * terminated. */
612
- end_hquery(hquery, status);
613
- }
614
- else
615
- {
616
- end_hquery(hquery, status);
617
- }
540
+ if (!hquery->remaining) {
541
+ if (status == ARES_EDESTRUCTION || status == ARES_ECANCELLED) {
542
+ /* must make sure we don't do next_lookup() on destroy or cancel,
543
+ * and return the appropriate status. We won't return a partial
544
+ * result in this case. */
545
+ end_hquery(hquery, status);
546
+ } else if (addinfostatus != ARES_SUCCESS && addinfostatus != ARES_ENODATA) {
547
+ /* error in parsing result e.g. no memory */
548
+ if (addinfostatus == ARES_EBADRESP && hquery->ai->nodes) {
549
+ /* We got a bad response from server, but at least one query
550
+ * ended with ARES_SUCCESS */
551
+ end_hquery(hquery, ARES_SUCCESS);
552
+ } else {
553
+ end_hquery(hquery, addinfostatus);
554
+ }
555
+ } else if (hquery->ai->nodes) {
556
+ /* at least one query ended with ARES_SUCCESS */
557
+ end_hquery(hquery, ARES_SUCCESS);
558
+ } else if (status == ARES_ENOTFOUND || status == ARES_ENODATA ||
559
+ addinfostatus == ARES_ENODATA) {
560
+ if (status == ARES_ENODATA || addinfostatus == ARES_ENODATA) {
561
+ hquery->nodata_cnt++;
562
+ }
563
+ next_lookup(hquery, hquery->nodata_cnt ? ARES_ENODATA : status);
564
+ } else if ((status == ARES_ESERVFAIL || status == ARES_EREFUSED) &&
565
+ ares_name_label_cnt(hquery->names[hquery->next_name_idx - 1]) ==
566
+ 1) {
567
+ /* Issue #852, systemd-resolved may return SERVFAIL or REFUSED on a
568
+ * single label domain name. */
569
+ next_lookup(hquery, hquery->nodata_cnt ? ARES_ENODATA : status);
570
+ } else {
571
+ end_hquery(hquery, status);
618
572
  }
573
+ }
619
574
 
620
575
  /* at this point we keep on waiting for the next query to finish */
621
576
  }
622
577
 
623
- void ares_getaddrinfo(ares_channel channel,
624
- const char* name, const char* service,
625
- const struct ares_addrinfo_hints* hints,
626
- ares_addrinfo_callback callback, void* arg)
578
+ static void ares_getaddrinfo_int(ares_channel_t *channel, const char *name,
579
+ const char *service,
580
+ const struct ares_addrinfo_hints *hints,
581
+ ares_addrinfo_callback callback, void *arg)
627
582
  {
628
- struct host_query *hquery;
629
- unsigned short port = 0;
630
- int family;
583
+ struct host_query *hquery;
584
+ unsigned short port = 0;
585
+ int family;
631
586
  struct ares_addrinfo *ai;
632
- char *alias_name = NULL;
633
- int status;
587
+ ares_status_t status;
634
588
 
635
- if (!hints)
636
- {
637
- hints = &default_hints;
638
- }
589
+ if (!hints) {
590
+ hints = &default_hints;
591
+ }
639
592
 
640
593
  family = hints->ai_family;
641
594
 
642
595
  /* Right now we only know how to look up Internet addresses
643
596
  and unspec means try both basically. */
644
- if (family != AF_INET &&
645
- family != AF_INET6 &&
646
- family != AF_UNSPEC)
647
- {
648
- callback(arg, ARES_ENOTIMP, 0, NULL);
649
- return;
650
- }
651
-
652
- if (ares__is_onion_domain(name))
653
- {
654
- callback(arg, ARES_ENOTFOUND, 0, NULL);
655
- return;
656
- }
597
+ if (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC) {
598
+ callback(arg, ARES_ENOTIMP, 0, NULL);
599
+ return;
600
+ }
657
601
 
658
- /* perform HOSTALIAS resolution (technically this function does some other
659
- * things we are going to ignore) */
660
- status = ares__single_domain(channel, name, &alias_name);
661
- if (status != ARES_SUCCESS) {
662
- callback(arg, status, 0, NULL);
602
+ if (ares_is_onion_domain(name)) {
603
+ callback(arg, ARES_ENOTFOUND, 0, NULL);
663
604
  return;
664
605
  }
665
606
 
666
- if (alias_name)
667
- name = alias_name;
668
-
669
- if (service)
670
- {
671
- if (hints->ai_flags & ARES_AI_NUMERICSERV)
672
- {
673
- unsigned long val;
674
- errno = 0;
675
- val = strtoul(service, NULL, 0);
676
- if ((val == 0 && errno != 0) || val > 65535)
677
- {
678
- ares_free(alias_name);
679
- callback(arg, ARES_ESERVICE, 0, NULL);
680
- return;
681
- }
682
- port = (unsigned short)val;
683
- }
684
- else
685
- {
686
- port = lookup_service(service, 0);
687
- if (!port)
688
- {
689
- unsigned long val;
690
- errno = 0;
691
- val = strtoul(service, NULL, 0);
692
- if ((val == 0 && errno != 0) || val > 65535)
693
- {
694
- ares_free(alias_name);
695
- callback(arg, ARES_ESERVICE, 0, NULL);
696
- return;
697
- }
698
- port = (unsigned short)val;
699
- }
607
+ if (service) {
608
+ if (hints->ai_flags & ARES_AI_NUMERICSERV) {
609
+ unsigned long val;
610
+ errno = 0;
611
+ val = strtoul(service, NULL, 0);
612
+ if ((val == 0 && errno != 0) || val > 65535) {
613
+ callback(arg, ARES_ESERVICE, 0, NULL);
614
+ return;
615
+ }
616
+ port = (unsigned short)val;
617
+ } else {
618
+ port = lookup_service(service, 0);
619
+ if (!port) {
620
+ unsigned long val;
621
+ errno = 0;
622
+ val = strtoul(service, NULL, 0);
623
+ if ((val == 0 && errno != 0) || val > 65535) {
624
+ callback(arg, ARES_ESERVICE, 0, NULL);
625
+ return;
700
626
  }
627
+ port = (unsigned short)val;
628
+ }
701
629
  }
630
+ }
702
631
 
703
- ai = ares__malloc_addrinfo();
704
- if (!ai)
705
- {
706
- ares_free(alias_name);
707
- callback(arg, ARES_ENOMEM, 0, NULL);
708
- return;
709
- }
632
+ ai = ares_malloc_zero(sizeof(*ai));
633
+ if (!ai) {
634
+ callback(arg, ARES_ENOMEM, 0, NULL);
635
+ return;
636
+ }
710
637
 
711
- if (fake_addrinfo(name, port, hints, ai, callback, arg))
712
- {
713
- ares_free(alias_name);
714
- return;
715
- }
638
+ if (fake_addrinfo(name, port, hints, ai, callback, arg)) {
639
+ return;
640
+ }
716
641
 
717
642
  /* Allocate and fill in the host query structure. */
718
- hquery = ares_malloc(sizeof(struct host_query));
719
- if (!hquery)
720
- {
721
- ares_free(alias_name);
722
- ares_freeaddrinfo(ai);
723
- callback(arg, ARES_ENOMEM, 0, NULL);
724
- return;
725
- }
726
-
727
- hquery->name = ares_strdup(name);
728
- ares_free(alias_name);
729
- if (!hquery->name)
730
- {
731
- ares_free(hquery);
732
- ares_freeaddrinfo(ai);
733
- callback(arg, ARES_ENOMEM, 0, NULL);
734
- return;
735
- }
643
+ hquery = ares_malloc_zero(sizeof(*hquery));
644
+ if (!hquery) {
645
+ ares_freeaddrinfo(ai);
646
+ callback(arg, ARES_ENOMEM, 0, NULL);
647
+ return;
648
+ }
736
649
 
737
- hquery->port = port;
738
- hquery->channel = channel;
739
- hquery->hints = *hints;
650
+ hquery->port = port;
651
+ hquery->channel = channel;
652
+ hquery->hints = *hints;
740
653
  hquery->sent_family = -1; /* nothing is sent yet */
741
- hquery->callback = callback;
742
- hquery->arg = arg;
743
- hquery->remaining_lookups = channel->lookups;
744
- hquery->timeouts = 0;
745
- hquery->ai = ai;
746
- hquery->next_domain = -1;
747
- hquery->remaining = 0;
748
- hquery->nodata_cnt = 0;
654
+ hquery->callback = callback;
655
+ hquery->arg = arg;
656
+ hquery->ai = ai;
657
+ hquery->name = ares_strdup(name);
658
+ if (hquery->name == NULL) {
659
+ hquery_free(hquery, ARES_TRUE);
660
+ callback(arg, ARES_ENOMEM, 0, NULL);
661
+ return;
662
+ }
749
663
 
750
- /* Start performing lookups according to channel->lookups. */
751
- next_lookup(hquery, ARES_ECONNREFUSED /* initial error code */);
752
- }
664
+ status =
665
+ ares_search_name_list(channel, name, &hquery->names, &hquery->names_cnt);
666
+ if (status != ARES_SUCCESS) {
667
+ hquery_free(hquery, ARES_TRUE);
668
+ callback(arg, (int)status, 0, NULL);
669
+ return;
670
+ }
671
+ hquery->next_name_idx = 0;
753
672
 
754
- static int next_dns_lookup(struct host_query *hquery)
755
- {
756
- char *s = NULL;
757
- int is_s_allocated = 0;
758
- int status;
759
-
760
- /* if next_domain == -1 and as_is_first is true, try hquery->name */
761
- if (hquery->next_domain == -1)
762
- {
763
- if (as_is_first(hquery))
764
- {
765
- s = hquery->name;
766
- }
767
- hquery->next_domain = 0;
768
- }
769
673
 
770
- /* if as_is_first is false, try hquery->name at last */
771
- if (!s && hquery->next_domain == hquery->channel->ndomains) {
772
- if (!as_is_first(hquery))
773
- {
774
- s = hquery->name;
775
- }
776
- hquery->next_domain++;
777
- }
778
-
779
- if (!s && hquery->next_domain < hquery->channel->ndomains && !as_is_only(hquery))
780
- {
781
- status = ares__cat_domain(
782
- hquery->name,
783
- hquery->channel->domains[hquery->next_domain++],
784
- &s);
785
- if (status == ARES_SUCCESS)
786
- {
787
- is_s_allocated = 1;
788
- }
789
- }
674
+ hquery->lookups = ares_strdup(channel->lookups);
675
+ if (hquery->lookups == NULL) {
676
+ hquery_free(hquery, ARES_TRUE);
677
+ callback(arg, ARES_ENOMEM, 0, NULL);
678
+ return;
679
+ }
680
+ hquery->remaining_lookups = hquery->lookups;
790
681
 
791
- if (s)
792
- {
793
- switch (hquery->hints.ai_family)
794
- {
795
- case AF_INET:
796
- hquery->remaining += 1;
797
- ares_query(hquery->channel, s, C_IN, T_A, host_callback, hquery);
798
- break;
799
- case AF_INET6:
800
- hquery->remaining += 1;
801
- ares_query(hquery->channel, s, C_IN, T_AAAA, host_callback, hquery);
802
- break;
803
- case AF_UNSPEC:
804
- hquery->remaining += 2;
805
- ares_query(hquery->channel, s, C_IN, T_A, host_callback, hquery);
806
- ares_query(hquery->channel, s, C_IN, T_AAAA, host_callback, hquery);
807
- break;
808
- default: break;
809
- }
810
- if (is_s_allocated)
811
- {
812
- ares_free(s);
813
- }
814
- return 1;
815
- }
816
- else
817
- {
818
- assert(!hquery->ai->nodes);
819
- return 0;
820
- }
682
+ /* Start performing lookups according to channel->lookups. */
683
+ next_lookup(hquery, ARES_ECONNREFUSED /* initial error code */);
821
684
  }
822
685
 
823
- static int as_is_first(const struct host_query* hquery)
686
+ void ares_getaddrinfo(ares_channel_t *channel, const char *name,
687
+ const char *service,
688
+ const struct ares_addrinfo_hints *hints,
689
+ ares_addrinfo_callback callback, void *arg)
824
690
  {
825
- char* p;
826
- int ndots = 0;
827
- size_t nname = hquery->name?strlen(hquery->name):0;
828
- for (p = hquery->name; *p; p++)
829
- {
830
- if (*p == '.')
831
- {
832
- ndots++;
833
- }
834
- }
835
- if (nname && hquery->name[nname-1] == '.')
836
- {
837
- /* prevent ARES_EBADNAME for valid FQDN, where ndots < channel->ndots */
838
- return 1;
839
- }
840
- return ndots >= hquery->channel->ndots;
691
+ if (channel == NULL) {
692
+ return;
693
+ }
694
+ ares_channel_lock(channel);
695
+ ares_getaddrinfo_int(channel, name, service, hints, callback, arg);
696
+ ares_channel_unlock(channel);
841
697
  }
842
698
 
843
- static int as_is_only(const struct host_query* hquery)
699
+ static ares_bool_t next_dns_lookup(struct host_query *hquery)
844
700
  {
845
- size_t nname = hquery->name?strlen(hquery->name):0;
846
- if (nname && hquery->name[nname-1] == '.')
847
- return 1;
848
- return 0;
849
- }
701
+ const char *name = NULL;
702
+
703
+ if (hquery->next_name_idx >= hquery->names_cnt) {
704
+ return ARES_FALSE;
705
+ }
850
706
 
707
+ name = hquery->names[hquery->next_name_idx++];
708
+
709
+ /* NOTE: hquery may be invalidated during the call to ares_query_qid(),
710
+ * so should not be referenced after this point */
711
+ switch (hquery->hints.ai_family) {
712
+ case AF_INET:
713
+ hquery->remaining += 1;
714
+ ares_query_nolock(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_A,
715
+ host_callback, hquery, &hquery->qid_a);
716
+ break;
717
+ case AF_INET6:
718
+ hquery->remaining += 1;
719
+ ares_query_nolock(hquery->channel, name, ARES_CLASS_IN,
720
+ ARES_REC_TYPE_AAAA, host_callback, hquery,
721
+ &hquery->qid_aaaa);
722
+ break;
723
+ case AF_UNSPEC:
724
+ hquery->remaining += 2;
725
+ ares_query_nolock(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_A,
726
+ host_callback, hquery, &hquery->qid_a);
727
+ ares_query_nolock(hquery->channel, name, ARES_CLASS_IN,
728
+ ARES_REC_TYPE_AAAA, host_callback, hquery,
729
+ &hquery->qid_aaaa);
730
+ break;
731
+ default:
732
+ break;
733
+ }
734
+
735
+ return ARES_TRUE;
736
+ }