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
@@ -0,0 +1,447 @@
|
|
1
|
+
/*
|
2
|
+
* Original file name getaddrinfo.c
|
3
|
+
* Lifted from the 'Android Bionic' project with the BSD license.
|
4
|
+
*/
|
5
|
+
|
6
|
+
/*
|
7
|
+
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
8
|
+
* Copyright (C) 2018 The Android Open Source Project
|
9
|
+
* Copyright (C) 2019 Andrew Selivanov
|
10
|
+
* All rights reserved.
|
11
|
+
*
|
12
|
+
* Redistribution and use in source and binary forms, with or without
|
13
|
+
* modification, are permitted provided that the following conditions
|
14
|
+
* are met:
|
15
|
+
* 1. Redistributions of source code must retain the above copyright
|
16
|
+
* notice, this list of conditions and the following disclaimer.
|
17
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
18
|
+
* notice, this list of conditions and the following disclaimer in the
|
19
|
+
* documentation and/or other materials provided with the distribution.
|
20
|
+
* 3. Neither the name of the project nor the names of its contributors
|
21
|
+
* may be used to endorse or promote products derived from this software
|
22
|
+
* without specific prior written permission.
|
23
|
+
*
|
24
|
+
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
25
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
27
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
28
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
29
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
30
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
31
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
32
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
34
|
+
* SUCH DAMAGE.
|
35
|
+
*
|
36
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
37
|
+
*/
|
38
|
+
|
39
|
+
#include "ares_private.h"
|
40
|
+
|
41
|
+
#ifdef HAVE_NETINET_IN_H
|
42
|
+
# include <netinet/in.h>
|
43
|
+
#endif
|
44
|
+
#ifdef HAVE_NETDB_H
|
45
|
+
# include <netdb.h>
|
46
|
+
#endif
|
47
|
+
#ifdef HAVE_STRINGS_H
|
48
|
+
# include <strings.h>
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#include <assert.h>
|
52
|
+
#include <limits.h>
|
53
|
+
|
54
|
+
struct addrinfo_sort_elem {
|
55
|
+
struct ares_addrinfo_node *ai;
|
56
|
+
ares_bool_t has_src_addr;
|
57
|
+
ares_sockaddr src_addr;
|
58
|
+
size_t original_order;
|
59
|
+
};
|
60
|
+
|
61
|
+
#define ARES_IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
|
62
|
+
|
63
|
+
#define ARES_IPV6_ADDR_SCOPE_NODELOCAL 0x01
|
64
|
+
#define ARES_IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
|
65
|
+
#define ARES_IPV6_ADDR_SCOPE_LINKLOCAL 0x02
|
66
|
+
#define ARES_IPV6_ADDR_SCOPE_SITELOCAL 0x05
|
67
|
+
#define ARES_IPV6_ADDR_SCOPE_ORGLOCAL 0x08
|
68
|
+
#define ARES_IPV6_ADDR_SCOPE_GLOBAL 0x0e
|
69
|
+
|
70
|
+
#define ARES_IN_LOOPBACK(a) \
|
71
|
+
((((long unsigned int)(a)) & 0xff000000) == 0x7f000000)
|
72
|
+
|
73
|
+
/* RFC 4193. */
|
74
|
+
#define ARES_IN6_IS_ADDR_ULA(a) (((a)->s6_addr[0] & 0xfe) == 0xfc)
|
75
|
+
|
76
|
+
/* These macros are modelled after the ones in <netinet/in6.h>. */
|
77
|
+
/* RFC 4380, section 2.6 */
|
78
|
+
#define ARES_IN6_IS_ADDR_TEREDO(a) \
|
79
|
+
((*(const unsigned int *)(const void *)(&(a)->s6_addr[0]) == \
|
80
|
+
ntohl(0x20010000)))
|
81
|
+
/* RFC 3056, section 2. */
|
82
|
+
#define ARES_IN6_IS_ADDR_6TO4(a) \
|
83
|
+
(((a)->s6_addr[0] == 0x20) && ((a)->s6_addr[1] == 0x02))
|
84
|
+
/* 6bone testing address area (3ffe::/16), deprecated in RFC 3701. */
|
85
|
+
#define ARES_IN6_IS_ADDR_6BONE(a) \
|
86
|
+
(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))
|
87
|
+
|
88
|
+
static int get_scope(const struct sockaddr *addr)
|
89
|
+
{
|
90
|
+
if (addr->sa_family == AF_INET6) {
|
91
|
+
const struct sockaddr_in6 *addr6 =
|
92
|
+
CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
93
|
+
if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr)) {
|
94
|
+
return ARES_IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
|
95
|
+
} else if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr) ||
|
96
|
+
IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
|
97
|
+
/*
|
98
|
+
* RFC 4291 section 2.5.3 says loopback is to be treated as having
|
99
|
+
* link-local scope.
|
100
|
+
*/
|
101
|
+
return ARES_IPV6_ADDR_SCOPE_LINKLOCAL;
|
102
|
+
} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
|
103
|
+
return ARES_IPV6_ADDR_SCOPE_SITELOCAL;
|
104
|
+
} else {
|
105
|
+
return ARES_IPV6_ADDR_SCOPE_GLOBAL;
|
106
|
+
}
|
107
|
+
} else if (addr->sa_family == AF_INET) {
|
108
|
+
const struct sockaddr_in *addr4 =
|
109
|
+
CARES_INADDR_CAST(const struct sockaddr_in *, addr);
|
110
|
+
unsigned long int na = ntohl(addr4->sin_addr.s_addr);
|
111
|
+
if (ARES_IN_LOOPBACK(na) || /* 127.0.0.0/8 */
|
112
|
+
(na & 0xffff0000) == 0xa9fe0000) /* 169.254.0.0/16 */
|
113
|
+
{
|
114
|
+
return ARES_IPV6_ADDR_SCOPE_LINKLOCAL;
|
115
|
+
} else {
|
116
|
+
/*
|
117
|
+
* RFC 6724 section 3.2. Other IPv4 addresses, including private
|
118
|
+
* addresses and shared addresses (100.64.0.0/10), are assigned global
|
119
|
+
* scope.
|
120
|
+
*/
|
121
|
+
return ARES_IPV6_ADDR_SCOPE_GLOBAL;
|
122
|
+
}
|
123
|
+
} else {
|
124
|
+
/*
|
125
|
+
* This should never happen.
|
126
|
+
* Return a scope with low priority as a last resort.
|
127
|
+
*/
|
128
|
+
return ARES_IPV6_ADDR_SCOPE_NODELOCAL;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
static int get_label(const struct sockaddr *addr)
|
133
|
+
{
|
134
|
+
if (addr->sa_family == AF_INET) {
|
135
|
+
return 4;
|
136
|
+
} else if (addr->sa_family == AF_INET6) {
|
137
|
+
const struct sockaddr_in6 *addr6 =
|
138
|
+
CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
139
|
+
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
|
140
|
+
return 0;
|
141
|
+
} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
|
142
|
+
return 4;
|
143
|
+
} else if (ARES_IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
|
144
|
+
return 2;
|
145
|
+
} else if (ARES_IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
|
146
|
+
return 5;
|
147
|
+
} else if (ARES_IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
|
148
|
+
return 13;
|
149
|
+
} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr)) {
|
150
|
+
return 3;
|
151
|
+
} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
|
152
|
+
return 11;
|
153
|
+
} else if (ARES_IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
|
154
|
+
return 12;
|
155
|
+
} else {
|
156
|
+
/* All other IPv6 addresses, including global unicast addresses. */
|
157
|
+
return 1;
|
158
|
+
}
|
159
|
+
} else {
|
160
|
+
/*
|
161
|
+
* This should never happen.
|
162
|
+
* Return a semi-random label as a last resort.
|
163
|
+
*/
|
164
|
+
return 1;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Get the precedence for a given IPv4/IPv6 address.
|
170
|
+
* RFC 6724, section 2.1.
|
171
|
+
*/
|
172
|
+
static int get_precedence(const struct sockaddr *addr)
|
173
|
+
{
|
174
|
+
if (addr->sa_family == AF_INET) {
|
175
|
+
return 35;
|
176
|
+
} else if (addr->sa_family == AF_INET6) {
|
177
|
+
const struct sockaddr_in6 *addr6 =
|
178
|
+
CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
179
|
+
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
|
180
|
+
return 50;
|
181
|
+
} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
|
182
|
+
return 35;
|
183
|
+
} else if (ARES_IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
|
184
|
+
return 30;
|
185
|
+
} else if (ARES_IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
|
186
|
+
return 5;
|
187
|
+
} else if (ARES_IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
|
188
|
+
return 3;
|
189
|
+
} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr) ||
|
190
|
+
IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr) ||
|
191
|
+
ARES_IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
|
192
|
+
return 1;
|
193
|
+
} else {
|
194
|
+
/* All other IPv6 addresses, including global unicast addresses. */
|
195
|
+
return 40;
|
196
|
+
}
|
197
|
+
} else {
|
198
|
+
return 1;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
/*
|
203
|
+
* Find number of matching initial bits between the two addresses a1 and a2.
|
204
|
+
*/
|
205
|
+
static size_t common_prefix_len(const struct in6_addr *a1,
|
206
|
+
const struct in6_addr *a2)
|
207
|
+
{
|
208
|
+
const unsigned char *p1 = (const unsigned char *)a1;
|
209
|
+
const unsigned char *p2 = (const unsigned char *)a2;
|
210
|
+
size_t i;
|
211
|
+
for (i = 0; i < sizeof(*a1); ++i) {
|
212
|
+
unsigned char x;
|
213
|
+
size_t j;
|
214
|
+
if (p1[i] == p2[i]) {
|
215
|
+
continue;
|
216
|
+
}
|
217
|
+
x = p1[i] ^ p2[i];
|
218
|
+
for (j = 0; j < CHAR_BIT; ++j) {
|
219
|
+
if (x & (1 << (CHAR_BIT - 1))) {
|
220
|
+
return i * CHAR_BIT + j;
|
221
|
+
}
|
222
|
+
x <<= 1;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
return sizeof(*a1) * CHAR_BIT;
|
226
|
+
}
|
227
|
+
|
228
|
+
/*
|
229
|
+
* Compare two source/destination address pairs.
|
230
|
+
* RFC 6724, section 6.
|
231
|
+
*/
|
232
|
+
static int rfc6724_compare(const void *ptr1, const void *ptr2)
|
233
|
+
{
|
234
|
+
const struct addrinfo_sort_elem *a1 = (const struct addrinfo_sort_elem *)ptr1;
|
235
|
+
const struct addrinfo_sort_elem *a2 = (const struct addrinfo_sort_elem *)ptr2;
|
236
|
+
int scope_src1;
|
237
|
+
int scope_dst1;
|
238
|
+
int scope_match1;
|
239
|
+
int scope_src2;
|
240
|
+
int scope_dst2;
|
241
|
+
int scope_match2;
|
242
|
+
int label_src1;
|
243
|
+
int label_dst1;
|
244
|
+
int label_match1;
|
245
|
+
int label_src2;
|
246
|
+
int label_dst2;
|
247
|
+
int label_match2;
|
248
|
+
int precedence1;
|
249
|
+
int precedence2;
|
250
|
+
size_t prefixlen1;
|
251
|
+
size_t prefixlen2;
|
252
|
+
|
253
|
+
/* Rule 1: Avoid unusable destinations. */
|
254
|
+
if (a1->has_src_addr != a2->has_src_addr) {
|
255
|
+
return ((int)a2->has_src_addr) - ((int)a1->has_src_addr);
|
256
|
+
}
|
257
|
+
|
258
|
+
/* Rule 2: Prefer matching scope. */
|
259
|
+
scope_src1 = ARES_IPV6_ADDR_SCOPE_NODELOCAL;
|
260
|
+
if (a1->has_src_addr) {
|
261
|
+
scope_src1 = get_scope(&a1->src_addr.sa);
|
262
|
+
}
|
263
|
+
scope_dst1 = get_scope(a1->ai->ai_addr);
|
264
|
+
scope_match1 = (scope_src1 == scope_dst1);
|
265
|
+
|
266
|
+
scope_src2 = ARES_IPV6_ADDR_SCOPE_NODELOCAL;
|
267
|
+
if (a2->has_src_addr) {
|
268
|
+
scope_src2 = get_scope(&a2->src_addr.sa);
|
269
|
+
}
|
270
|
+
scope_dst2 = get_scope(a2->ai->ai_addr);
|
271
|
+
scope_match2 = (scope_src2 == scope_dst2);
|
272
|
+
|
273
|
+
if (scope_match1 != scope_match2) {
|
274
|
+
return scope_match2 - scope_match1;
|
275
|
+
}
|
276
|
+
|
277
|
+
/* Rule 3: Avoid deprecated addresses. */
|
278
|
+
|
279
|
+
/* Rule 4: Prefer home addresses. */
|
280
|
+
|
281
|
+
/* Rule 5: Prefer matching label. */
|
282
|
+
label_src1 = 1;
|
283
|
+
if (a1->has_src_addr) {
|
284
|
+
label_src1 = get_label(&a1->src_addr.sa);
|
285
|
+
}
|
286
|
+
label_dst1 = get_label(a1->ai->ai_addr);
|
287
|
+
label_match1 = (label_src1 == label_dst1);
|
288
|
+
|
289
|
+
label_src2 = 1;
|
290
|
+
if (a2->has_src_addr) {
|
291
|
+
label_src2 = get_label(&a2->src_addr.sa);
|
292
|
+
}
|
293
|
+
label_dst2 = get_label(a2->ai->ai_addr);
|
294
|
+
label_match2 = (label_src2 == label_dst2);
|
295
|
+
|
296
|
+
if (label_match1 != label_match2) {
|
297
|
+
return label_match2 - label_match1;
|
298
|
+
}
|
299
|
+
|
300
|
+
/* Rule 6: Prefer higher precedence. */
|
301
|
+
precedence1 = get_precedence(a1->ai->ai_addr);
|
302
|
+
precedence2 = get_precedence(a2->ai->ai_addr);
|
303
|
+
if (precedence1 != precedence2) {
|
304
|
+
return precedence2 - precedence1;
|
305
|
+
}
|
306
|
+
|
307
|
+
/* Rule 7: Prefer native transport. */
|
308
|
+
|
309
|
+
/* Rule 8: Prefer smaller scope. */
|
310
|
+
if (scope_dst1 != scope_dst2) {
|
311
|
+
return scope_dst1 - scope_dst2;
|
312
|
+
}
|
313
|
+
|
314
|
+
/* Rule 9: Use longest matching prefix. */
|
315
|
+
if (a1->has_src_addr && a1->ai->ai_addr->sa_family == AF_INET6 &&
|
316
|
+
a2->has_src_addr && a2->ai->ai_addr->sa_family == AF_INET6) {
|
317
|
+
const struct sockaddr_in6 *a1_src = &a1->src_addr.sa6;
|
318
|
+
const struct sockaddr_in6 *a1_dst =
|
319
|
+
CARES_INADDR_CAST(const struct sockaddr_in6 *, a1->ai->ai_addr);
|
320
|
+
const struct sockaddr_in6 *a2_src = &a2->src_addr.sa6;
|
321
|
+
const struct sockaddr_in6 *a2_dst =
|
322
|
+
CARES_INADDR_CAST(const struct sockaddr_in6 *, a2->ai->ai_addr);
|
323
|
+
prefixlen1 = common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
|
324
|
+
prefixlen2 = common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
|
325
|
+
if (prefixlen1 != prefixlen2) {
|
326
|
+
return (int)prefixlen2 - (int)prefixlen1;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
/*
|
331
|
+
* Rule 10: Leave the order unchanged.
|
332
|
+
* We need this since qsort() is not necessarily stable.
|
333
|
+
*/
|
334
|
+
return ((int)a1->original_order) - ((int)a2->original_order);
|
335
|
+
}
|
336
|
+
|
337
|
+
/*
|
338
|
+
* Find the source address that will be used if trying to connect to the given
|
339
|
+
* address.
|
340
|
+
*
|
341
|
+
* Returns 1 if a source address was found, 0 if the address is unreachable
|
342
|
+
* and -1 if a fatal error occurred. If 0 or 1, the contents of src_addr are
|
343
|
+
* undefined.
|
344
|
+
*/
|
345
|
+
static int find_src_addr(ares_channel_t *channel, const struct sockaddr *addr,
|
346
|
+
struct sockaddr *src_addr)
|
347
|
+
{
|
348
|
+
ares_socket_t sock;
|
349
|
+
ares_socklen_t len;
|
350
|
+
ares_conn_err_t err;
|
351
|
+
|
352
|
+
switch (addr->sa_family) {
|
353
|
+
case AF_INET:
|
354
|
+
len = sizeof(struct sockaddr_in);
|
355
|
+
break;
|
356
|
+
case AF_INET6:
|
357
|
+
len = sizeof(struct sockaddr_in6);
|
358
|
+
break;
|
359
|
+
default:
|
360
|
+
/* No known usable source address for non-INET families. */
|
361
|
+
return 0;
|
362
|
+
}
|
363
|
+
|
364
|
+
err =
|
365
|
+
ares_socket_open(&sock, channel, addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
|
366
|
+
if (err == ARES_CONN_ERR_AFNOSUPPORT) {
|
367
|
+
return 0;
|
368
|
+
} else if (err != ARES_CONN_ERR_SUCCESS) {
|
369
|
+
return -1;
|
370
|
+
}
|
371
|
+
|
372
|
+
err = ares_socket_connect(channel, sock, ARES_FALSE, addr, len);
|
373
|
+
if (err != ARES_CONN_ERR_SUCCESS && err != ARES_CONN_ERR_WOULDBLOCK) {
|
374
|
+
ares_socket_close(channel, sock);
|
375
|
+
return 0;
|
376
|
+
}
|
377
|
+
|
378
|
+
if (channel->sock_funcs.agetsockname == NULL ||
|
379
|
+
channel->sock_funcs.agetsockname(sock, src_addr, &len,
|
380
|
+
channel->sock_func_cb_data) != 0) {
|
381
|
+
ares_socket_close(channel, sock);
|
382
|
+
return -1;
|
383
|
+
}
|
384
|
+
ares_socket_close(channel, sock);
|
385
|
+
return 1;
|
386
|
+
}
|
387
|
+
|
388
|
+
/*
|
389
|
+
* Sort the linked list starting at sentinel->ai_next in RFC6724 order.
|
390
|
+
* Will leave the list unchanged if an error occurs.
|
391
|
+
*/
|
392
|
+
ares_status_t ares_sortaddrinfo(ares_channel_t *channel,
|
393
|
+
struct ares_addrinfo_node *list_sentinel)
|
394
|
+
{
|
395
|
+
struct ares_addrinfo_node *cur;
|
396
|
+
size_t nelem = 0;
|
397
|
+
size_t i;
|
398
|
+
int has_src_addr;
|
399
|
+
struct addrinfo_sort_elem *elems;
|
400
|
+
|
401
|
+
cur = list_sentinel->ai_next;
|
402
|
+
while (cur) {
|
403
|
+
++nelem;
|
404
|
+
cur = cur->ai_next;
|
405
|
+
}
|
406
|
+
|
407
|
+
if (!nelem) {
|
408
|
+
return ARES_ENODATA;
|
409
|
+
}
|
410
|
+
|
411
|
+
elems = (struct addrinfo_sort_elem *)ares_malloc(
|
412
|
+
nelem * sizeof(struct addrinfo_sort_elem));
|
413
|
+
if (!elems) {
|
414
|
+
return ARES_ENOMEM;
|
415
|
+
}
|
416
|
+
|
417
|
+
/*
|
418
|
+
* Convert the linked list to an array that also contains the candidate
|
419
|
+
* source address for each destination address.
|
420
|
+
*/
|
421
|
+
for (i = 0, cur = list_sentinel->ai_next; i < nelem;
|
422
|
+
++i, cur = cur->ai_next) {
|
423
|
+
assert(cur != NULL);
|
424
|
+
elems[i].ai = cur;
|
425
|
+
elems[i].original_order = i;
|
426
|
+
has_src_addr = find_src_addr(channel, cur->ai_addr, &elems[i].src_addr.sa);
|
427
|
+
if (has_src_addr == -1) {
|
428
|
+
ares_free(elems);
|
429
|
+
return ARES_ENOTFOUND;
|
430
|
+
}
|
431
|
+
elems[i].has_src_addr = (has_src_addr == 1) ? ARES_TRUE : ARES_FALSE;
|
432
|
+
}
|
433
|
+
|
434
|
+
/* Sort the addresses, and rearrange the linked list so it matches the sorted
|
435
|
+
* order. */
|
436
|
+
qsort((void *)elems, nelem, sizeof(struct addrinfo_sort_elem),
|
437
|
+
rfc6724_compare);
|
438
|
+
|
439
|
+
list_sentinel->ai_next = elems[0].ai;
|
440
|
+
for (i = 0; i < nelem - 1; ++i) {
|
441
|
+
elems[i].ai->ai_next = elems[i + 1].ai;
|
442
|
+
}
|
443
|
+
elems[nelem - 1].ai->ai_next = NULL;
|
444
|
+
|
445
|
+
ares_free(elems);
|
446
|
+
return ARES_SUCCESS;
|
447
|
+
}
|
@@ -1,56 +1,91 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
/* MIT License
|
2
|
+
*
|
3
|
+
* Copyright (c) 1998 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.
|
3
24
|
*
|
4
|
-
*
|
5
|
-
* software and its documentation for any purpose and without
|
6
|
-
* fee is hereby granted, provided that the above copyright
|
7
|
-
* notice appear in all copies and that both that copyright
|
8
|
-
* notice and this permission notice appear in supporting
|
9
|
-
* documentation, and that the name of M.I.T. not be used in
|
10
|
-
* advertising or publicity pertaining to distribution of the
|
11
|
-
* software without specific, written prior permission.
|
12
|
-
* M.I.T. makes no representations about the suitability of
|
13
|
-
* this software for any purpose. It is provided "as is"
|
14
|
-
* without express or implied warranty.
|
25
|
+
* SPDX-License-Identifier: MIT
|
15
26
|
*/
|
16
27
|
|
17
|
-
#include "
|
18
|
-
#include <assert.h>
|
19
|
-
#include "ares.h"
|
28
|
+
#include "ares_private.h"
|
20
29
|
|
21
30
|
const char *ares_strerror(int code)
|
22
31
|
{
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
32
|
+
ares_status_t status = (ares_status_t)code;
|
33
|
+
switch (status) {
|
34
|
+
case ARES_SUCCESS:
|
35
|
+
return "Successful completion";
|
36
|
+
case ARES_ENODATA:
|
37
|
+
return "DNS server returned answer with no data";
|
38
|
+
case ARES_EFORMERR:
|
39
|
+
return "DNS server claims query was misformatted";
|
40
|
+
case ARES_ESERVFAIL:
|
41
|
+
return "DNS server returned general failure";
|
42
|
+
case ARES_ENOTFOUND:
|
43
|
+
return "Domain name not found";
|
44
|
+
case ARES_ENOTIMP:
|
45
|
+
return "DNS server does not implement requested operation";
|
46
|
+
case ARES_EREFUSED:
|
47
|
+
return "DNS server refused query";
|
48
|
+
case ARES_EBADQUERY:
|
49
|
+
return "Misformatted DNS query";
|
50
|
+
case ARES_EBADNAME:
|
51
|
+
return "Misformatted domain name";
|
52
|
+
case ARES_EBADFAMILY:
|
53
|
+
return "Unsupported address family";
|
54
|
+
case ARES_EBADRESP:
|
55
|
+
return "Misformatted DNS reply";
|
56
|
+
case ARES_ECONNREFUSED:
|
57
|
+
return "Could not contact DNS servers";
|
58
|
+
case ARES_ETIMEOUT:
|
59
|
+
return "Timeout while contacting DNS servers";
|
60
|
+
case ARES_EOF:
|
61
|
+
return "End of file";
|
62
|
+
case ARES_EFILE:
|
63
|
+
return "Error reading file";
|
64
|
+
case ARES_ENOMEM:
|
65
|
+
return "Out of memory";
|
66
|
+
case ARES_EDESTRUCTION:
|
67
|
+
return "Channel is being destroyed";
|
68
|
+
case ARES_EBADSTR:
|
69
|
+
return "Misformatted string";
|
70
|
+
case ARES_EBADFLAGS:
|
71
|
+
return "Illegal flags specified";
|
72
|
+
case ARES_ENONAME:
|
73
|
+
return "Given hostname is not numeric";
|
74
|
+
case ARES_EBADHINTS:
|
75
|
+
return "Illegal hints flags specified";
|
76
|
+
case ARES_ENOTINITIALIZED:
|
77
|
+
return "c-ares library initialization not yet performed";
|
78
|
+
case ARES_ELOADIPHLPAPI:
|
79
|
+
return "Error loading iphlpapi.dll";
|
80
|
+
case ARES_EADDRGETNETWORKPARAMS:
|
81
|
+
return "Could not find GetNetworkParams function";
|
82
|
+
case ARES_ECANCELLED:
|
83
|
+
return "DNS query cancelled";
|
84
|
+
case ARES_ESERVICE:
|
85
|
+
return "Invalid service name or number";
|
86
|
+
case ARES_ENOSERVER:
|
87
|
+
return "No DNS servers were configured";
|
88
|
+
}
|
51
89
|
|
52
|
-
|
53
|
-
return errtext[code];
|
54
|
-
else
|
55
|
-
return "unknown";
|
90
|
+
return "unknown";
|
56
91
|
}
|