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,19 +1,31 @@
1
- /* Copyright 1998, 2011, 2013 by the Massachusetts Institute of Technology.
1
+ /* MIT License
2
2
  *
3
- * Permission to use, copy, modify, and distribute this
4
- * software and its documentation for any purpose and without
5
- * fee is hereby granted, provided that the above copyright
6
- * notice appear in all copies and that both that copyright
7
- * notice and this permission notice appear in supporting
8
- * documentation, and that the name of M.I.T. not be used in
9
- * advertising or publicity pertaining to distribution of the
10
- * software without specific, written prior permission.
11
- * M.I.T. makes no representations about the suitability of
12
- * this software for any purpose. It is provided "as is"
13
- * without express or implied warranty.
3
+ * Copyright (c) 1998, 2011, 2013 Massachusetts Institute of Technology
4
+ * Copyright (c) The c-ares project and its contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice (including the next
14
+ * paragraph) shall be included in all copies or substantial portions of the
15
+ * Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ *
25
+ * SPDX-License-Identifier: MIT
14
26
  */
15
27
 
16
- #include "ares_setup.h"
28
+ #include "ares_private.h"
17
29
 
18
30
  #ifdef HAVE_NETINET_IN_H
19
31
  # include <netinet/in.h>
@@ -28,60 +40,54 @@
28
40
  #include "ares_nameser.h"
29
41
 
30
42
  #ifdef HAVE_STRINGS_H
31
- #include <strings.h>
43
+ # include <strings.h>
32
44
  #endif
33
45
 
34
- #include "ares.h"
35
46
  #include "ares_inet_net_pton.h"
36
- #include "bitncmp.h"
37
- #include "ares_platform.h"
38
- #include "ares_nowarn.h"
39
- #include "ares_private.h"
40
47
 
41
- static void sort_addresses(struct hostent *host,
42
- const struct apattern *sortlist, int nsort);
43
- static void sort6_addresses(struct hostent *host,
44
- const struct apattern *sortlist, int nsort);
45
- static int get_address_index(const struct in_addr *addr,
46
- const struct apattern *sortlist, int nsort);
47
- static int get6_address_index(const struct ares_in6_addr *addr,
48
- const struct apattern *sortlist, int nsort);
48
+ static void sort_addresses(const struct hostent *host,
49
+ const struct apattern *sortlist, size_t nsort);
50
+ static void sort6_addresses(const struct hostent *host,
51
+ const struct apattern *sortlist, size_t nsort);
52
+ static size_t get_address_index(const struct in_addr *addr,
53
+ const struct apattern *sortlist, size_t nsort);
54
+ static size_t get6_address_index(const struct ares_in6_addr *addr,
55
+ const struct apattern *sortlist, size_t nsort);
49
56
 
50
57
  struct host_query {
51
58
  ares_host_callback callback;
52
- void *arg;
53
- ares_channel channel;
59
+ void *arg;
60
+ ares_channel_t *channel;
54
61
  };
55
62
 
56
63
  static void ares_gethostbyname_callback(void *arg, int status, int timeouts,
57
64
  struct ares_addrinfo *result)
58
65
  {
59
- struct hostent *hostent = NULL;
66
+ struct hostent *hostent = NULL;
60
67
  struct host_query *ghbn_arg = arg;
61
68
 
62
- if (status == ARES_SUCCESS)
63
- {
64
- status = ares__addrinfo2hostent(result, AF_UNSPEC, &hostent);
65
- }
69
+ if (status == ARES_SUCCESS) {
70
+ status = (int)ares_addrinfo2hostent(result, AF_UNSPEC, &hostent);
71
+ }
66
72
 
67
73
  /* addrinfo2hostent will only return ENODATA if there are no addresses _and_
68
74
  * no cname/aliases. However, gethostbyname will return ENODATA even if there
69
75
  * is cname/alias data */
70
76
  if (status == ARES_SUCCESS && hostent &&
71
- (!hostent->h_addr_list || !hostent->h_addr_list[0]))
72
- {
73
- status = ARES_ENODATA;
74
- }
77
+ (!hostent->h_addr_list || !hostent->h_addr_list[0])) {
78
+ status = ARES_ENODATA;
79
+ }
75
80
 
76
- if (status == ARES_SUCCESS && ghbn_arg->channel->nsort && hostent)
77
- {
78
- if (hostent->h_addrtype == AF_INET6)
79
- sort6_addresses(hostent, ghbn_arg->channel->sortlist,
80
- ghbn_arg->channel->nsort);
81
- if (hostent->h_addrtype == AF_INET)
82
- sort_addresses(hostent, ghbn_arg->channel->sortlist,
83
- ghbn_arg->channel->nsort);
81
+ if (status == ARES_SUCCESS && ghbn_arg->channel->nsort && hostent) {
82
+ if (hostent->h_addrtype == AF_INET6) {
83
+ sort6_addresses(hostent, ghbn_arg->channel->sortlist,
84
+ ghbn_arg->channel->nsort);
84
85
  }
86
+ if (hostent->h_addrtype == AF_INET) {
87
+ sort_addresses(hostent, ghbn_arg->channel->sortlist,
88
+ ghbn_arg->channel->nsort);
89
+ }
90
+ }
85
91
 
86
92
  ghbn_arg->callback(ghbn_arg->arg, status, timeouts, hostent);
87
93
 
@@ -90,249 +96,242 @@ static void ares_gethostbyname_callback(void *arg, int status, int timeouts,
90
96
  ares_free_hostent(hostent);
91
97
  }
92
98
 
93
- void ares_gethostbyname(ares_channel channel, const char *name, int family,
99
+ void ares_gethostbyname(ares_channel_t *channel, const char *name, int family,
94
100
  ares_host_callback callback, void *arg)
95
101
  {
96
- const struct ares_addrinfo_hints hints = { ARES_AI_CANONNAME, family, 0, 0 };
97
- struct host_query *ghbn_arg;
102
+ struct ares_addrinfo_hints hints;
103
+ struct host_query *ghbn_arg;
98
104
 
99
- if (!callback)
105
+ if (!callback) {
100
106
  return;
107
+ }
108
+
109
+ memset(&hints, 0, sizeof(hints));
110
+ hints.ai_flags = ARES_AI_CANONNAME;
111
+ hints.ai_family = family;
101
112
 
102
113
  ghbn_arg = ares_malloc(sizeof(*ghbn_arg));
103
- if (!ghbn_arg)
104
- {
105
- callback(arg, ARES_ENOMEM, 0, NULL);
106
- return;
107
- }
114
+ if (!ghbn_arg) {
115
+ callback(arg, ARES_ENOMEM, 0, NULL);
116
+ return;
117
+ }
108
118
 
109
- ghbn_arg->callback=callback;
110
- ghbn_arg->arg=arg;
111
- ghbn_arg->channel=channel;
119
+ ghbn_arg->callback = callback;
120
+ ghbn_arg->arg = arg;
121
+ ghbn_arg->channel = channel;
112
122
 
123
+ /* NOTE: ares_getaddrinfo() locks the channel, we don't use the channel
124
+ * outside so no need to lock */
113
125
  ares_getaddrinfo(channel, name, NULL, &hints, ares_gethostbyname_callback,
114
126
  ghbn_arg);
115
127
  }
116
128
 
117
-
118
- static void sort_addresses(struct hostent *host,
119
- const struct apattern *sortlist, int nsort)
129
+ static void sort_addresses(const struct hostent *host,
130
+ const struct apattern *sortlist, size_t nsort)
120
131
  {
121
- struct in_addr a1, a2;
122
- int i1, i2, ind1, ind2;
132
+ struct in_addr a1;
133
+ struct in_addr a2;
134
+ int i1;
135
+ int i2;
136
+ size_t ind1;
137
+ size_t ind2;
123
138
 
124
139
  /* This is a simple insertion sort, not optimized at all. i1 walks
125
140
  * through the address list, with the loop invariant that everything
126
141
  * to the left of i1 is sorted. In the loop body, the value at i1 is moved
127
142
  * back through the list (via i2) until it is in sorted order.
128
143
  */
129
- for (i1 = 0; host->h_addr_list[i1]; i1++)
130
- {
131
- memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr));
132
- ind1 = get_address_index(&a1, sortlist, nsort);
133
- for (i2 = i1 - 1; i2 >= 0; i2--)
134
- {
135
- memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
136
- ind2 = get_address_index(&a2, sortlist, nsort);
137
- if (ind2 <= ind1)
138
- break;
139
- memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
140
- }
141
- memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct in_addr));
144
+ for (i1 = 0; host->h_addr_list[i1]; i1++) {
145
+ memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr));
146
+ ind1 = get_address_index(&a1, sortlist, nsort);
147
+ for (i2 = i1 - 1; i2 >= 0; i2--) {
148
+ memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
149
+ ind2 = get_address_index(&a2, sortlist, nsort);
150
+ if (ind2 <= ind1) {
151
+ break;
152
+ }
153
+ memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
142
154
  }
155
+ memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct in_addr));
156
+ }
143
157
  }
144
158
 
145
159
  /* Find the first entry in sortlist which matches addr. Return nsort
146
160
  * if none of them match.
147
161
  */
148
- static int get_address_index(const struct in_addr *addr,
149
- const struct apattern *sortlist,
150
- int nsort)
162
+ static size_t get_address_index(const struct in_addr *addr,
163
+ const struct apattern *sortlist, size_t nsort)
151
164
  {
152
- int i;
153
-
154
- for (i = 0; i < nsort; i++)
155
- {
156
- if (sortlist[i].family != AF_INET)
157
- continue;
158
- if (sortlist[i].type == PATTERN_MASK)
159
- {
160
- if ((addr->s_addr & sortlist[i].mask.addr4.s_addr)
161
- == sortlist[i].addrV4.s_addr)
162
- break;
163
- }
164
- else
165
- {
166
- if (!ares__bitncmp(&addr->s_addr, &sortlist[i].addrV4.s_addr,
167
- sortlist[i].mask.bits))
168
- break;
169
- }
165
+ size_t i;
166
+ struct ares_addr aaddr;
167
+
168
+ memset(&aaddr, 0, sizeof(aaddr));
169
+ aaddr.family = AF_INET;
170
+ memcpy(&aaddr.addr.addr4, addr, 4);
171
+
172
+ for (i = 0; i < nsort; i++) {
173
+ if (sortlist[i].addr.family != AF_INET) {
174
+ continue;
175
+ }
176
+
177
+ if (ares_subnet_match(&aaddr, &sortlist[i].addr, sortlist[i].mask)) {
178
+ break;
170
179
  }
180
+ }
181
+
171
182
  return i;
172
183
  }
173
184
 
174
- static void sort6_addresses(struct hostent *host,
175
- const struct apattern *sortlist, int nsort)
185
+ static void sort6_addresses(const struct hostent *host,
186
+ const struct apattern *sortlist, size_t nsort)
176
187
  {
177
- struct ares_in6_addr a1, a2;
178
- int i1, i2, ind1, ind2;
188
+ struct ares_in6_addr a1;
189
+ struct ares_in6_addr a2;
190
+ int i1;
191
+ int i2;
192
+ size_t ind1;
193
+ size_t ind2;
179
194
 
180
195
  /* This is a simple insertion sort, not optimized at all. i1 walks
181
196
  * through the address list, with the loop invariant that everything
182
197
  * to the left of i1 is sorted. In the loop body, the value at i1 is moved
183
198
  * back through the list (via i2) until it is in sorted order.
184
199
  */
185
- for (i1 = 0; host->h_addr_list[i1]; i1++)
186
- {
187
- memcpy(&a1, host->h_addr_list[i1], sizeof(struct ares_in6_addr));
188
- ind1 = get6_address_index(&a1, sortlist, nsort);
189
- for (i2 = i1 - 1; i2 >= 0; i2--)
190
- {
191
- memcpy(&a2, host->h_addr_list[i2], sizeof(struct ares_in6_addr));
192
- ind2 = get6_address_index(&a2, sortlist, nsort);
193
- if (ind2 <= ind1)
194
- break;
195
- memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct ares_in6_addr));
196
- }
197
- memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct ares_in6_addr));
200
+ for (i1 = 0; host->h_addr_list[i1]; i1++) {
201
+ memcpy(&a1, host->h_addr_list[i1], sizeof(struct ares_in6_addr));
202
+ ind1 = get6_address_index(&a1, sortlist, nsort);
203
+ for (i2 = i1 - 1; i2 >= 0; i2--) {
204
+ memcpy(&a2, host->h_addr_list[i2], sizeof(struct ares_in6_addr));
205
+ ind2 = get6_address_index(&a2, sortlist, nsort);
206
+ if (ind2 <= ind1) {
207
+ break;
208
+ }
209
+ memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct ares_in6_addr));
198
210
  }
211
+ memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct ares_in6_addr));
212
+ }
199
213
  }
200
214
 
201
215
  /* Find the first entry in sortlist which matches addr. Return nsort
202
216
  * if none of them match.
203
217
  */
204
- static int get6_address_index(const struct ares_in6_addr *addr,
205
- const struct apattern *sortlist,
206
- int nsort)
218
+ static size_t get6_address_index(const struct ares_in6_addr *addr,
219
+ const struct apattern *sortlist, size_t nsort)
207
220
  {
208
- int i;
221
+ size_t i;
222
+ struct ares_addr aaddr;
209
223
 
210
- for (i = 0; i < nsort; i++)
211
- {
212
- if (sortlist[i].family != AF_INET6)
213
- continue;
214
- if (!ares__bitncmp(addr, &sortlist[i].addrV6, sortlist[i].mask.bits))
215
- break;
224
+ memset(&aaddr, 0, sizeof(aaddr));
225
+ aaddr.family = AF_INET6;
226
+ memcpy(&aaddr.addr.addr6, addr, 16);
227
+
228
+ for (i = 0; i < nsort; i++) {
229
+ if (sortlist[i].addr.family != AF_INET6) {
230
+ continue;
216
231
  }
232
+
233
+ if (ares_subnet_match(&aaddr, &sortlist[i].addr, sortlist[i].mask)) {
234
+ break;
235
+ }
236
+ }
217
237
  return i;
218
238
  }
219
239
 
240
+ static ares_status_t ares_hostent_localhost(const char *name, int family,
241
+ struct hostent **host_out)
242
+ {
243
+ ares_status_t status;
244
+ struct ares_addrinfo *ai = NULL;
245
+ struct ares_addrinfo_hints hints;
246
+
247
+ memset(&hints, 0, sizeof(hints));
248
+ hints.ai_family = family;
220
249
 
250
+ ai = ares_malloc_zero(sizeof(*ai));
251
+ if (ai == NULL) {
252
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
253
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
254
+ }
221
255
 
222
- static int file_lookup(const char *name, int family, struct hostent **host);
256
+ status = ares_addrinfo_localhost(name, 0, &hints, ai);
257
+ if (status != ARES_SUCCESS) {
258
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
259
+ }
260
+
261
+ status = ares_addrinfo2hostent(ai, family, host_out);
262
+ if (status != ARES_SUCCESS) {
263
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
264
+ }
265
+
266
+ done:
267
+ ares_freeaddrinfo(ai);
268
+ return status;
269
+ }
223
270
 
224
271
  /* I really have no idea why this is exposed as a public function, but since
225
272
  * it is, we can't kill this legacy function. */
226
- int ares_gethostbyname_file(ares_channel channel, const char *name,
227
- int family, struct hostent **host)
273
+ static ares_status_t ares_gethostbyname_file_int(ares_channel_t *channel,
274
+ const char *name, int family,
275
+ struct hostent **host)
228
276
  {
229
- int result;
277
+ const ares_hosts_entry_t *entry;
278
+ ares_status_t status;
230
279
 
231
280
  /* We only take the channel to ensure that ares_init() been called. */
232
- if(channel == NULL)
233
- {
234
- /* Anything will do, really. This seems fine, and is consistent with
235
- other error cases. */
236
- *host = NULL;
237
- return ARES_ENOTFOUND;
238
- }
239
-
240
- /* Just chain to the internal implementation we use here; it's exactly
241
- * what we want.
242
- */
243
- result = file_lookup(name, family, host);
244
- if(result != ARES_SUCCESS)
245
- {
246
- /* We guarantee a NULL hostent on failure. */
281
+ if (channel == NULL || name == NULL || host == NULL) {
282
+ /* Anything will do, really. This seems fine, and is consistent with
283
+ other error cases. */
284
+ if (host != NULL) {
247
285
  *host = NULL;
248
286
  }
249
- return result;
250
- }
251
-
252
- static int file_lookup(const char *name, int family, struct hostent **host)
253
- {
254
- FILE *fp;
255
- char **alias;
256
- int status;
257
- int error;
258
-
259
- #ifdef WIN32
260
- char PATH_HOSTS[MAX_PATH];
261
- win_platform platform;
262
-
263
- PATH_HOSTS[0] = '\0';
264
-
265
- platform = ares__getplatform();
266
-
267
- if (platform == WIN_NT) {
268
- char tmp[MAX_PATH];
269
- HKEY hkeyHosts;
270
-
271
- if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ,
272
- &hkeyHosts) == ERROR_SUCCESS)
273
- {
274
- DWORD dwLength = MAX_PATH;
275
- RegQueryValueExA(hkeyHosts, DATABASEPATH, NULL, NULL, (LPBYTE)tmp,
276
- &dwLength);
277
- ExpandEnvironmentStringsA(tmp, PATH_HOSTS, MAX_PATH);
278
- RegCloseKey(hkeyHosts);
279
- }
280
- }
281
- else if (platform == WIN_9X)
282
- GetWindowsDirectoryA(PATH_HOSTS, MAX_PATH);
283
- else
284
287
  return ARES_ENOTFOUND;
288
+ }
285
289
 
286
- strcat(PATH_HOSTS, WIN_PATH_HOSTS);
287
-
288
- #elif defined(WATT32)
289
- const char *PATH_HOSTS = _w32_GetHostsFile();
290
-
291
- if (!PATH_HOSTS)
292
- return ARES_ENOTFOUND;
293
- #endif
290
+ *host = NULL;
294
291
 
295
292
  /* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
296
- if (ares__is_onion_domain(name))
293
+ if (ares_is_onion_domain(name)) {
297
294
  return ARES_ENOTFOUND;
295
+ }
298
296
 
297
+ status = ares_hosts_search_host(channel, ARES_FALSE, name, &entry);
298
+ if (status != ARES_SUCCESS) {
299
+ goto done;
300
+ }
301
+
302
+ status = ares_hosts_entry_to_hostent(entry, family, host);
303
+ if (status != ARES_SUCCESS) {
304
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
305
+ }
306
+
307
+ done:
308
+ /* RFC6761 section 6.3 #3 states that "Name resolution APIs and libraries
309
+ * SHOULD recognize localhost names as special and SHOULD always return the
310
+ * IP loopback address for address queries".
311
+ * We will also ignore ALL errors when trying to resolve localhost, such
312
+ * as permissions errors reading /etc/hosts or a malformed /etc/hosts.
313
+ *
314
+ * Also, just because the query itself returned success from /etc/hosts
315
+ * lookup doesn't mean it returned everything it needed to for all requested
316
+ * address families. As long as we're not on a critical out of memory
317
+ * condition pass it through to fill in any other address classes. */
318
+ if (status != ARES_ENOMEM && ares_is_localhost(name)) {
319
+ return ares_hostent_localhost(name, family, host);
320
+ }
299
321
 
300
- fp = fopen(PATH_HOSTS, "r");
301
- if (!fp)
302
- {
303
- error = ERRNO;
304
- switch(error)
305
- {
306
- case ENOENT:
307
- case ESRCH:
308
- return ARES_ENOTFOUND;
309
- default:
310
- DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
311
- error, strerror(error)));
312
- DEBUGF(fprintf(stderr, "Error opening file: %s\n",
313
- PATH_HOSTS));
314
- *host = NULL;
315
- return ARES_EFILE;
316
- }
317
- }
318
- while ((status = ares__get_hostent(fp, family, host)) == ARES_SUCCESS)
319
- {
320
- if (strcasecmp((*host)->h_name, name) == 0)
321
- break;
322
- for (alias = (*host)->h_aliases; *alias; alias++)
323
- {
324
- if (strcasecmp(*alias, name) == 0)
325
- break;
326
- }
327
- if (*alias)
328
- break;
329
- ares_free_hostent(*host);
330
- }
331
- fclose(fp);
332
- if (status == ARES_EOF)
333
- status = ARES_ENOTFOUND;
334
- if (status != ARES_SUCCESS)
335
- *host = NULL;
336
322
  return status;
337
323
  }
338
324
 
325
+ int ares_gethostbyname_file(ares_channel_t *channel, const char *name,
326
+ int family, struct hostent **host)
327
+ {
328
+ ares_status_t status;
329
+ if (channel == NULL) {
330
+ return ARES_ENOTFOUND;
331
+ }
332
+
333
+ ares_channel_lock(channel);
334
+ status = ares_gethostbyname_file_int(channel, name, family, host);
335
+ ares_channel_unlock(channel);
336
+ return (int)status;
337
+ }