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.
- checksums.yaml +4 -4
- data/Makefile +83 -41
- data/include/grpc/credentials.h +7 -1
- data/src/core/call/client_call.cc +4 -4
- data/src/core/call/filter_fusion.h +1230 -0
- data/src/core/call/metadata.cc +22 -0
- data/src/core/call/metadata.h +24 -2
- data/src/core/channelz/channelz.cc +10 -17
- data/src/core/channelz/channelz.h +58 -19
- data/src/core/channelz/channelz_registry.cc +0 -162
- data/src/core/channelz/channelz_registry.h +14 -7
- data/src/core/channelz/property_list.cc +19 -23
- data/src/core/channelz/property_list.h +3 -1
- data/src/core/channelz/v2tov1/convert.cc +683 -0
- data/src/core/channelz/v2tov1/convert.h +58 -0
- data/src/core/channelz/v2tov1/legacy_api.cc +425 -0
- data/src/core/channelz/v2tov1/legacy_api.h +32 -0
- data/src/core/channelz/v2tov1/property_list.cc +118 -0
- data/src/core/channelz/v2tov1/property_list.h +52 -0
- data/src/core/client_channel/client_channel_filter.cc +5 -4
- data/src/core/client_channel/client_channel_filter.h +2 -2
- data/src/core/client_channel/client_channel_internal.h +2 -1
- data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
- data/src/core/client_channel/subchannel.cc +14 -6
- data/src/core/client_channel/subchannel.h +2 -0
- data/src/core/config/core_configuration.cc +3 -1
- data/src/core/config/core_configuration.h +12 -0
- data/src/core/credentials/transport/alts/alts_credentials.cc +5 -0
- data/src/core/credentials/transport/alts/check_gcp_environment_windows.cc +2 -0
- data/src/core/credentials/transport/channel_creds_registry_init.cc +3 -1
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -1
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +8 -3
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -24
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +19 -8
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +96 -54
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +15 -2
- data/src/core/credentials/transport/tls/spiffe_utils.cc +371 -0
- data/src/core/credentials/transport/tls/spiffe_utils.h +171 -0
- data/src/core/credentials/transport/tls/ssl_utils.cc +11 -10
- data/src/core/credentials/transport/tls/ssl_utils.h +4 -2
- data/src/core/credentials/transport/tls/tls_credentials.cc +2 -0
- data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -26
- data/src/core/credentials/transport/tls/tls_security_connector.h +12 -12
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -2
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
- data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
- data/src/core/ext/filters/message_size/message_size_filter.cc +4 -4
- data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -5
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
- data/src/core/ext/transport/chttp2/transport/frame.cc +89 -6
- data/src/core/ext/transport/chttp2/transport/frame.h +38 -0
- data/src/core/ext/transport/chttp2/transport/header_assembler.h +5 -14
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +294 -78
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +128 -9
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +52 -35
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +61 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +142 -0
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +81 -3
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +12 -1
- data/src/core/ext/transport/chttp2/transport/message_assembler.h +2 -2
- data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +22 -5
- data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
- data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +6 -4
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb.h +4959 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.c +1111 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.h +108 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +142 -54
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +18 -14
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +2 -2
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +716 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.h +227 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +86 -88
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +2 -2
- data/src/core/filter/auth/auth_filters.h +2 -2
- data/src/core/filter/fused_filters.cc +154 -0
- data/src/core/handshaker/security/legacy_secure_endpoint.cc +1 -1
- data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
- data/src/core/handshaker/security/secure_endpoint.cc +28 -13
- data/src/core/handshaker/security/secure_endpoint.h +8 -0
- data/src/core/lib/channel/promise_based_filter.cc +15 -25
- data/src/core/lib/channel/promise_based_filter.h +6 -5
- data/src/core/lib/event_engine/ares_resolver.h +3 -1
- data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -5
- data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -1
- data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +263 -0
- data/src/core/lib/event_engine/cf_engine/cfsocket_listener.h +107 -0
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +31 -3
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +12 -0
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +12 -10
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +6 -4
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +15 -14
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +7 -5
- data/src/core/lib/event_engine/posix_engine/event_poller.h +0 -8
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -5
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
- data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +1 -0
- data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +4 -4
- data/src/core/lib/event_engine/posix_engine/lockfree_event.h +3 -4
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +2 -2
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +188 -199
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +30 -45
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -1
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +1 -1
- data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +2 -1
- data/src/core/lib/experiments/experiments.cc +120 -6
- data/src/core/lib/experiments/experiments.h +46 -3
- data/src/core/lib/iomgr/combiner.cc +1 -1
- data/src/core/lib/iomgr/exec_ctx.h +3 -9
- data/src/core/lib/iomgr/socket_mutator.cc +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.cc +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.h +1 -1
- data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
- data/src/core/lib/iomgr/tcp_posix.cc +3 -3
- data/src/core/lib/promise/activity.h +2 -2
- data/src/core/lib/promise/mpsc.cc +8 -8
- data/src/core/lib/promise/party.cc +7 -7
- data/src/core/lib/promise/party.h +4 -4
- data/src/core/lib/promise/poll.h +10 -0
- data/src/core/lib/resource_quota/memory_quota.cc +90 -3
- data/src/core/lib/resource_quota/memory_quota.h +20 -9
- data/src/core/lib/resource_quota/periodic_update.cc +14 -0
- data/src/core/lib/resource_quota/periodic_update.h +8 -0
- data/src/core/lib/resource_quota/resource_quota.cc +15 -4
- data/src/core/lib/resource_quota/resource_quota.h +3 -0
- data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -2
- data/src/core/lib/surface/call.cc +5 -5
- data/src/core/lib/surface/call.h +6 -5
- data/src/core/lib/surface/completion_queue.cc +2 -4
- data/src/core/lib/surface/filter_stack_call.cc +1 -1
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.h +3 -3
- data/src/core/load_balancing/endpoint_list.cc +29 -2
- data/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +3 -3
- data/src/core/load_balancing/grpclb/client_load_reporting_filter.h +1 -1
- data/src/core/load_balancing/pick_first/pick_first.cc +12 -5
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +5 -3
- data/src/core/net/socket_mutator.cc +19 -0
- data/src/core/net/socket_mutator.h +25 -0
- data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +6 -1
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -1
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +8 -5
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/resolver/xds/xds_dependency_manager.cc +1 -1
- data/src/core/server/server.cc +1 -1
- data/src/core/server/server_call_tracer_filter.cc +0 -66
- data/src/core/server/server_call_tracer_filter.h +64 -0
- data/src/core/server/server_config_selector_filter.cc +1 -1
- data/src/core/service_config/service_config_channel_arg_filter.cc +3 -60
- data/src/core/service_config/service_config_channel_arg_filter.h +82 -0
- data/src/core/telemetry/call_tracer.cc +20 -14
- data/src/core/telemetry/call_tracer.h +22 -17
- data/src/core/telemetry/metrics.h +8 -8
- data/src/core/telemetry/stats_data.cc +151 -151
- data/src/core/telemetry/stats_data.h +87 -87
- data/src/core/transport/auth_context.cc +20 -0
- data/src/core/transport/auth_context.h +4 -0
- data/src/core/transport/auth_context_comparator_registry.h +69 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -3
- data/src/core/tsi/ssl_transport_security.cc +202 -32
- data/src/core/tsi/ssl_transport_security.h +19 -10
- data/src/core/tsi/ssl_transport_security_utils.cc +21 -0
- data/src/core/tsi/ssl_transport_security_utils.h +4 -0
- data/src/core/util/http_client/httpcli_security_connector.cc +3 -1
- data/src/core/util/latent_see.cc +178 -146
- data/src/core/util/latent_see.h +245 -188
- data/src/core/util/single_set_ptr.h +5 -2
- data/src/core/util/useful.h +91 -0
- data/src/core/util/windows/directory_reader.cc +1 -0
- data/src/core/util/windows/thd.cc +1 -3
- data/src/core/util/work_serializer.cc +1 -1
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +32 -5
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +5 -0
- data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/cares/cares/include/ares.h +925 -460
- data/third_party/cares/cares/include/ares_dns.h +86 -71
- data/third_party/cares/cares/include/ares_dns_record.h +1118 -0
- data/third_party/cares/cares/include/ares_nameser.h +215 -189
- data/third_party/cares/cares/include/ares_version.h +37 -14
- data/third_party/cares/cares/src/lib/ares_addrinfo2hostent.c +305 -0
- data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +245 -0
- data/third_party/cares/cares/src/lib/ares_android.c +216 -164
- data/third_party/cares/cares/src/lib/ares_android.h +25 -14
- data/third_party/cares/cares/src/lib/ares_cancel.c +68 -44
- data/third_party/cares/cares/src/lib/ares_close_sockets.c +137 -0
- data/third_party/cares/cares/src/lib/ares_conn.c +511 -0
- data/third_party/cares/cares/src/lib/ares_conn.h +196 -0
- data/third_party/cares/cares/src/lib/ares_cookie.c +461 -0
- data/third_party/cares/cares/src/lib/ares_data.c +93 -181
- data/third_party/cares/cares/src/lib/ares_data.h +50 -39
- data/third_party/cares/cares/src/lib/ares_destroy.c +127 -89
- data/third_party/cares/cares/src/lib/ares_free_hostent.c +35 -24
- data/third_party/cares/cares/src/lib/ares_free_string.c +24 -16
- data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +45 -38
- data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +549 -663
- data/third_party/cares/cares/src/lib/ares_getenv.c +25 -15
- data/third_party/cares/cares/src/lib/ares_getenv.h +26 -18
- data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +163 -221
- data/third_party/cares/cares/src/lib/ares_gethostbyname.c +222 -223
- data/third_party/cares/cares/src/lib/ares_getnameinfo.c +328 -338
- data/third_party/cares/cares/src/lib/ares_hosts_file.c +952 -0
- data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +25 -19
- data/third_party/cares/cares/src/lib/ares_init.c +425 -2091
- data/third_party/cares/cares/src/lib/ares_ipv6.h +63 -33
- data/third_party/cares/cares/src/lib/ares_library_init.c +110 -54
- data/third_party/cares/cares/src/lib/ares_metrics.c +261 -0
- data/third_party/cares/cares/src/lib/ares_options.c +418 -332
- data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +179 -0
- data/third_party/cares/cares/src/lib/ares_private.h +558 -356
- data/third_party/cares/cares/src/lib/ares_process.c +1224 -1369
- data/third_party/cares/cares/src/lib/ares_qcache.c +430 -0
- data/third_party/cares/cares/src/lib/ares_query.c +126 -121
- data/third_party/cares/cares/src/lib/ares_search.c +564 -262
- data/third_party/cares/cares/src/lib/ares_send.c +264 -93
- data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +588 -0
- data/third_party/cares/cares/src/lib/ares_setup.h +115 -111
- data/third_party/cares/cares/src/lib/ares_socket.c +425 -0
- data/third_party/cares/cares/src/lib/ares_socket.h +163 -0
- data/third_party/cares/cares/src/lib/ares_sortaddrinfo.c +447 -0
- data/third_party/cares/cares/src/lib/ares_strerror.c +83 -48
- data/third_party/cares/cares/src/lib/ares_sysconfig.c +639 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +839 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_mac.c +373 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +621 -0
- data/third_party/cares/cares/src/lib/ares_timeout.c +136 -73
- data/third_party/cares/cares/src/lib/ares_update_servers.c +1362 -0
- data/third_party/cares/cares/src/lib/ares_version.c +29 -4
- data/third_party/cares/cares/src/lib/config-dos.h +88 -89
- data/third_party/cares/cares/src/lib/config-win32.h +122 -77
- data/third_party/cares/cares/src/lib/dsa/ares_array.c +394 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable.c +447 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable.h +174 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_asvp.c +224 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +228 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_strvp.c +210 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_szvp.c +188 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- data/third_party/cares/cares/src/lib/dsa/ares_llist.c +382 -0
- data/third_party/cares/cares/src/lib/dsa/ares_slist.c +479 -0
- data/third_party/cares/cares/src/lib/dsa/ares_slist.h +207 -0
- data/third_party/cares/cares/src/lib/event/ares_event.h +191 -0
- data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +743 -0
- data/third_party/cares/cares/src/lib/event/ares_event_epoll.c +192 -0
- data/third_party/cares/cares/src/lib/event/ares_event_kqueue.c +248 -0
- data/third_party/cares/cares/src/lib/event/ares_event_poll.c +140 -0
- data/third_party/cares/cares/src/lib/event/ares_event_select.c +159 -0
- data/third_party/cares/cares/src/lib/event/ares_event_thread.c +567 -0
- data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +166 -0
- data/third_party/cares/cares/src/lib/event/ares_event_win32.c +978 -0
- data/third_party/cares/cares/src/lib/event/ares_event_win32.h +161 -0
- data/third_party/cares/cares/src/lib/include/ares_array.h +276 -0
- data/third_party/cares/cares/src/lib/include/ares_buf.h +732 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_asvp.h +130 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_dict.h +123 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_strvp.h +130 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_szvp.h +118 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_vpstr.h +111 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_vpvp.h +128 -0
- data/third_party/cares/cares/src/lib/include/ares_llist.h +239 -0
- data/third_party/cares/cares/src/lib/include/ares_mem.h +38 -0
- data/third_party/cares/cares/src/lib/include/ares_str.h +244 -0
- data/third_party/cares/cares/src/lib/inet_net_pton.c +202 -157
- data/third_party/cares/cares/src/lib/inet_ntop.c +87 -69
- data/third_party/cares/cares/src/lib/legacy/ares_create_query.c +78 -0
- data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +99 -0
- data/third_party/cares/cares/src/lib/legacy/ares_expand_string.c +107 -0
- data/third_party/cares/cares/src/lib/legacy/ares_fds.c +80 -0
- data/third_party/cares/cares/src/lib/legacy/ares_getsock.c +85 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +982 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +307 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_multistring.h +72 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_name.c +673 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +1329 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_private.h +273 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_record.c +1661 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_write.c +1229 -0
- data/third_party/cares/cares/src/lib/str/ares_buf.c +1498 -0
- data/third_party/cares/cares/src/lib/str/ares_str.c +508 -0
- data/third_party/cares/cares/src/lib/str/ares_strsplit.c +90 -0
- data/third_party/cares/cares/src/lib/str/ares_strsplit.h +51 -0
- data/third_party/cares/cares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +628 -0
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +139 -0
- data/third_party/cares/cares/src/lib/util/ares_math.c +158 -0
- data/third_party/cares/cares/src/lib/util/ares_math.h +45 -0
- data/third_party/cares/cares/src/lib/util/ares_rand.c +389 -0
- data/third_party/cares/cares/src/lib/util/ares_rand.h +36 -0
- data/third_party/cares/cares/src/lib/util/ares_threads.c +614 -0
- data/third_party/cares/cares/src/lib/util/ares_threads.h +60 -0
- data/third_party/cares/cares/src/lib/util/ares_time.h +48 -0
- data/third_party/cares/cares/src/lib/util/ares_timeval.c +95 -0
- data/third_party/cares/cares/src/lib/util/ares_uri.c +1626 -0
- data/third_party/cares/cares/src/lib/util/ares_uri.h +252 -0
- data/third_party/cares/cares/src/lib/windows_port.c +16 -9
- metadata +121 -49
- data/src/core/util/ring_buffer.h +0 -122
- data/third_party/cares/cares/include/ares_rules.h +0 -125
- data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +0 -266
- data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +0 -240
- data/third_party/cares/cares/src/lib/ares__close_sockets.c +0 -61
- data/third_party/cares/cares/src/lib/ares__get_hostent.c +0 -260
- data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +0 -229
- data/third_party/cares/cares/src/lib/ares__read_line.c +0 -73
- data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +0 -258
- data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +0 -507
- data/third_party/cares/cares/src/lib/ares__timeval.c +0 -111
- data/third_party/cares/cares/src/lib/ares_create_query.c +0 -197
- data/third_party/cares/cares/src/lib/ares_expand_name.c +0 -311
- data/third_party/cares/cares/src/lib/ares_expand_string.c +0 -67
- data/third_party/cares/cares/src/lib/ares_fds.c +0 -59
- data/third_party/cares/cares/src/lib/ares_getsock.c +0 -66
- data/third_party/cares/cares/src/lib/ares_iphlpapi.h +0 -221
- data/third_party/cares/cares/src/lib/ares_llist.c +0 -63
- data/third_party/cares/cares/src/lib/ares_llist.h +0 -39
- data/third_party/cares/cares/src/lib/ares_mkquery.c +0 -24
- data/third_party/cares/cares/src/lib/ares_nowarn.c +0 -260
- data/third_party/cares/cares/src/lib/ares_nowarn.h +0 -61
- data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +0 -90
- data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +0 -92
- data/third_party/cares/cares/src/lib/ares_parse_caa_reply.c +0 -199
- data/third_party/cares/cares/src/lib/ares_parse_mx_reply.c +0 -164
- data/third_party/cares/cares/src/lib/ares_parse_naptr_reply.c +0 -183
- data/third_party/cares/cares/src/lib/ares_parse_ns_reply.c +0 -177
- data/third_party/cares/cares/src/lib/ares_parse_ptr_reply.c +0 -228
- data/third_party/cares/cares/src/lib/ares_parse_soa_reply.c +0 -179
- data/third_party/cares/cares/src/lib/ares_parse_srv_reply.c +0 -168
- data/third_party/cares/cares/src/lib/ares_parse_txt_reply.c +0 -214
- data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +0 -184
- data/third_party/cares/cares/src/lib/ares_platform.c +0 -11042
- data/third_party/cares/cares/src/lib/ares_platform.h +0 -43
- data/third_party/cares/cares/src/lib/ares_rand.c +0 -279
- data/third_party/cares/cares/src/lib/ares_strcasecmp.c +0 -66
- data/third_party/cares/cares/src/lib/ares_strcasecmp.h +0 -30
- data/third_party/cares/cares/src/lib/ares_strdup.c +0 -42
- data/third_party/cares/cares/src/lib/ares_strdup.h +0 -24
- data/third_party/cares/cares/src/lib/ares_strsplit.c +0 -94
- data/third_party/cares/cares/src/lib/ares_strsplit.h +0 -42
- data/third_party/cares/cares/src/lib/ares_writev.c +0 -79
- data/third_party/cares/cares/src/lib/ares_writev.h +0 -36
- data/third_party/cares/cares/src/lib/bitncmp.c +0 -59
- data/third_party/cares/cares/src/lib/bitncmp.h +0 -26
- data/third_party/cares/cares/src/lib/setup_once.h +0 -554
- data/third_party/cares/cares/src/tools/ares_getopt.h +0 -53
@@ -1,27 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* Copyright (
|
4
|
-
* Copyright (
|
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
|
-
*
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
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 "
|
29
|
+
#include "ares_private.h"
|
20
30
|
|
21
31
|
#ifdef HAVE_GETSERVBYNAME_R
|
22
|
-
# if !defined(GETSERVBYNAME_R_ARGS) || \
|
23
|
-
|
24
|
-
# error "you MUST
|
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 "
|
50
|
-
#include "bitncmp.h"
|
51
|
-
#include "ares_private.h"
|
59
|
+
#include "ares_dns.h"
|
52
60
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
69
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
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 *
|
99
|
+
struct ares_addrinfo_cname *
|
100
|
+
ares_append_addrinfo_cname(struct ares_addrinfo_cname **head)
|
117
101
|
{
|
118
|
-
struct ares_addrinfo_cname *
|
119
|
-
|
120
|
-
return NULL;
|
102
|
+
struct ares_addrinfo_cname *tail = ares_malloc_zero(sizeof(*tail));
|
103
|
+
struct ares_addrinfo_cname *last = *head;
|
121
104
|
|
122
|
-
|
123
|
-
|
124
|
-
}
|
105
|
+
if (tail == NULL) {
|
106
|
+
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
|
107
|
+
}
|
125
108
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
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
|
146
|
-
|
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
|
-
|
152
|
-
|
153
|
-
}
|
126
|
+
if (!last) {
|
127
|
+
*head = tail;
|
128
|
+
return;
|
129
|
+
}
|
154
130
|
|
155
|
-
while (last->next)
|
156
|
-
|
157
|
-
|
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 *
|
139
|
+
struct ares_addrinfo_node *
|
140
|
+
ares_append_addrinfo_node(struct ares_addrinfo_node **head)
|
186
141
|
{
|
187
|
-
struct ares_addrinfo_node *tail =
|
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
|
-
|
196
|
-
|
197
|
-
|
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
|
205
|
-
|
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
|
-
|
211
|
-
|
212
|
-
}
|
166
|
+
if (!last) {
|
167
|
+
*head = tail;
|
168
|
+
return;
|
169
|
+
}
|
213
170
|
|
214
|
-
while (last->ai_next)
|
215
|
-
|
216
|
-
|
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
|
183
|
+
const char *proto;
|
228
184
|
struct servent *sep;
|
229
185
|
#ifdef HAVE_GETSERVBYNAME_R
|
230
186
|
struct servent se;
|
231
|
-
char
|
187
|
+
char tmpbuf[4096];
|
232
188
|
#endif
|
233
189
|
|
234
|
-
if (service)
|
235
|
-
{
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
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
|
-
|
246
|
-
|
247
|
-
|
248
|
-
#if GETSERVBYNAME_R_ARGS == 6
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
#elif GETSERVBYNAME_R_ARGS == 4
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
#
|
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
|
-
|
268
|
-
#
|
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
|
-
|
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
|
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
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
288
|
-
|
289
|
-
int
|
290
|
-
if (family == AF_INET || family == AF_INET6 || family == AF_UNSPEC)
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
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
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
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
|
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
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
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
|
318
|
+
return ARES_TRUE;
|
372
319
|
}
|
373
320
|
|
374
|
-
static void
|
321
|
+
static void hquery_free(struct host_query *hquery, ares_bool_t cleanup_ai)
|
375
322
|
{
|
376
|
-
|
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
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
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
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
366
|
+
if (name == NULL) {
|
367
|
+
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
|
368
|
+
}
|
414
369
|
|
415
|
-
if (
|
416
|
-
return
|
370
|
+
if (ares_strcaseeq(name, "localhost")) {
|
371
|
+
return ARES_TRUE;
|
372
|
+
}
|
417
373
|
|
418
|
-
len =
|
419
|
-
if (len < 10 /* strlen(".localhost") */)
|
420
|
-
return
|
374
|
+
len = ares_strlen(name);
|
375
|
+
if (len < 10 /* strlen(".localhost") */) {
|
376
|
+
return ARES_FALSE;
|
377
|
+
}
|
421
378
|
|
422
|
-
if (
|
423
|
-
|
379
|
+
if (ares_strcaseeq(name + (len - 10 /* strlen(".localhost") */),
|
380
|
+
".localhost")) {
|
381
|
+
return ARES_TRUE;
|
382
|
+
}
|
424
383
|
|
425
|
-
return
|
384
|
+
return ARES_FALSE;
|
426
385
|
}
|
427
386
|
|
428
|
-
static
|
387
|
+
static ares_status_t file_lookup(struct host_query *hquery)
|
429
388
|
{
|
430
|
-
|
431
|
-
|
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
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
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
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
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
|
-
|
480
|
-
|
481
|
-
|
402
|
+
if (status != ARES_SUCCESS) {
|
403
|
+
goto done;
|
404
|
+
}
|
482
405
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
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
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
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,
|
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
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
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,
|
567
|
-
|
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
|
570
|
-
|
571
|
-
hquery->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 =
|
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
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
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
|
624
|
-
|
625
|
-
|
626
|
-
|
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
|
629
|
-
unsigned short
|
630
|
-
int
|
583
|
+
struct host_query *hquery;
|
584
|
+
unsigned short port = 0;
|
585
|
+
int family;
|
631
586
|
struct ares_addrinfo *ai;
|
632
|
-
|
633
|
-
int status;
|
587
|
+
ares_status_t status;
|
634
588
|
|
635
|
-
if (!hints)
|
636
|
-
|
637
|
-
|
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
|
-
|
646
|
-
|
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
|
-
|
659
|
-
|
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 (
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
if (
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
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 =
|
704
|
-
if (!ai)
|
705
|
-
|
706
|
-
|
707
|
-
|
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
|
-
|
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 =
|
719
|
-
if (!hquery)
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
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
|
738
|
-
hquery->channel
|
739
|
-
hquery->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
|
742
|
-
hquery->arg
|
743
|
-
hquery->
|
744
|
-
hquery->
|
745
|
-
hquery->
|
746
|
-
|
747
|
-
|
748
|
-
|
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
|
-
|
751
|
-
|
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
|
-
|
771
|
-
if (
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
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
|
699
|
+
static ares_bool_t next_dns_lookup(struct host_query *hquery)
|
844
700
|
{
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
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
|
+
}
|