grpc 1.83.1 → 1.84.0
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 +21 -17
- data/include/grpc/credentials.h +10 -0
- data/include/grpc/grpc_security_constants.h +2 -0
- data/include/grpc/impl/channel_arg_names.h +9 -0
- data/src/core/call/call_filters.h +4 -2
- data/src/core/call/client_call.cc +20 -8
- data/src/core/call/client_call.h +4 -0
- data/src/core/call/interception_chain.cc +2 -0
- data/src/core/call/interception_chain.h +14 -1
- data/src/core/call/metadata.cc +1 -3
- data/src/core/call/metadata_batch.h +13 -5
- data/src/core/call/server_call.cc +31 -14
- data/src/core/call/server_call.h +4 -0
- data/src/core/channelz/text_encode.cc +9 -4
- data/src/core/channelz/v2tov1/convert.cc +2 -2
- data/src/core/client_channel/backup_poller.cc +1 -2
- data/src/core/client_channel/client_channel.cc +6 -33
- data/src/core/client_channel/client_channel_filter.cc +22 -55
- data/src/core/client_channel/client_channel_filter.h +2 -2
- data/src/core/client_channel/client_channel_service_config.cc +3 -19
- data/src/core/client_channel/direct_channel.cc +7 -1
- data/src/core/client_channel/direct_channel.h +2 -2
- data/src/core/client_channel/load_balanced_call_destination.cc +5 -3
- data/src/core/client_channel/retry_filter_legacy_call_data.cc +5 -12
- data/src/core/client_channel/subchannel.cc +310 -1058
- data/src/core/client_channel/subchannel.h +44 -329
- data/src/core/client_channel/subchannel_metrics.cc +48 -0
- data/src/core/client_channel/subchannel_metrics.h +60 -0
- data/src/core/credentials/call/external/file_external_account_credentials.cc +1 -1
- data/src/core/credentials/call/external/url_external_account_credentials.cc +2 -3
- data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.cc +8 -24
- data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.h +3 -6
- data/src/core/credentials/call/gdch_service_account/gdch_service_account_credentials.cc +525 -0
- data/src/core/credentials/call/gdch_service_account/gdch_service_account_credentials.h +138 -0
- data/src/core/credentials/call/json_util.h +1 -0
- data/src/core/credentials/call/jwt/json_token.cc +10 -2
- data/src/core/credentials/call/jwt/jwt_verifier.cc +15 -1
- data/src/core/credentials/call/jwt_token_file/jwt_token_file_call_credentials.cc +1 -1
- data/src/core/credentials/call/oauth2/oauth2_credentials.cc +42 -79
- data/src/core/credentials/call/oauth2/oauth2_credentials.h +2 -5
- data/src/core/credentials/call/token_fetcher/token_fetcher_credentials.cc +52 -31
- data/src/core/credentials/call/token_fetcher/token_fetcher_credentials.h +21 -8
- data/src/core/credentials/transport/google_default/google_default_credentials.cc +3 -4
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +59 -72
- data/src/core/credentials/transport/ssl/ssl_credentials.h +9 -8
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +12 -6
- data/src/core/credentials/transport/ssl/ssl_security_connector.h +4 -4
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -18
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +9 -6
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +45 -56
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +5 -4
- data/src/core/credentials/transport/tls/grpc_tls_certificate_selector.h +26 -0
- data/src/core/credentials/transport/tls/grpc_tls_crl_provider.cc +1 -1
- data/src/core/credentials/transport/tls/load_system_roots.h +2 -6
- data/src/core/credentials/transport/tls/load_system_roots_fallback.cc +2 -4
- data/src/core/credentials/transport/tls/load_system_roots_supported.cc +13 -15
- data/src/core/credentials/transport/tls/load_system_roots_supported.h +3 -2
- data/src/core/credentials/transport/tls/load_system_roots_windows.cc +5 -8
- data/src/core/credentials/transport/tls/spiffe_utils.cc +1 -1
- data/src/core/credentials/transport/tls/ssl_utils.cc +39 -28
- data/src/core/credentials/transport/tls/ssl_utils.h +12 -49
- data/src/core/credentials/transport/tls/tls_security_connector.cc +48 -33
- data/src/core/credentials/transport/tls/tls_security_connector.h +31 -10
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +15 -11
- data/src/core/ext/filters/http/http_filters_plugin.cc +20 -9
- data/src/core/ext/filters/rbac/rbac_filter.cc +43 -21
- data/src/core/ext/filters/rbac/rbac_filter.h +21 -3
- data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +2 -2
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +6 -20
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +32 -67
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +78 -4
- data/src/core/ext/transport/chttp2/transport/frame.h +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +3 -4
- data/src/core/ext/transport/chttp2/transport/goaway.h +7 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +5 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -1
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +141 -130
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +22 -22
- data/src/core/ext/transport/chttp2/transport/http2_server_transport.cc +402 -269
- data/src/core/ext/transport/chttp2/transport/http2_server_transport.h +80 -49
- data/src/core/ext/transport/chttp2/transport/http2_settings_promises.h +1 -2
- data/src/core/ext/transport/chttp2/transport/http2_status.h +38 -37
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +178 -5
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +345 -5
- data/src/core/ext/transport/chttp2/transport/parsing.cc +5 -5
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +25 -5
- data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +3 -4
- data/src/core/ext/transport/chttp2/transport/read_context.h +30 -3
- data/src/core/ext/transport/chttp2/transport/stream.h +65 -23
- data/src/core/ext/transport/chttp2/transport/writing.cc +0 -3
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -5
- data/src/core/ext/transport/inproc/legacy_inproc_transport.cc +4 -17
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb.h +1912 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb_minitable.c +300 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb_minitable.h +37 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb.h +187 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb_minitable.c +64 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb_minitable.h +31 -0
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb.h +2362 -0
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.c +556 -0
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.h +47 -0
- data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb_minitable.c +3 -3
- data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb_minitable.h +5 -5
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upbdefs.c +453 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upbdefs.h +67 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upbdefs.c +142 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upbdefs.h +37 -0
- data/src/core/ext/upbdefs-gen/grpc/channelz/v1/channelz.upbdefs.c +715 -0
- data/src/core/ext/upbdefs-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upbdefs.h +44 -44
- data/src/core/filter/auth/server_auth_filter.cc +2 -3
- data/src/core/filter/composite/composite_filter.cc +45 -33
- data/src/core/filter/composite/composite_filter.h +5 -4
- data/src/core/filter/ext_proc/ext_proc_filter.cc +224 -0
- data/src/core/filter/ext_proc/ext_proc_filter.h +155 -0
- data/src/core/filter/ext_proc/ext_proc_messages.cc +701 -0
- data/src/core/filter/ext_proc/ext_proc_messages.h +297 -0
- data/src/core/filter/filter_args.h +13 -2
- data/src/core/handshaker/http_connect/http_proxy_mapper.cc +30 -3
- data/src/core/handshaker/security/security_handshaker.cc +9 -6
- data/src/core/lib/channel/channel_stack.cc +3 -0
- data/src/core/lib/channel/channel_stack.h +2 -0
- data/src/core/lib/channel/channel_stack_builder_impl.cc +1 -2
- data/src/core/lib/channel/promise_based_filter.cc +132 -20
- data/src/core/lib/channel/promise_based_filter.h +42 -12
- data/src/core/lib/compression/compression_internal.cc +4 -5
- data/src/core/lib/debug/trace_flags.cc +8 -0
- data/src/core/lib/debug/trace_flags.h +3 -0
- data/src/core/lib/event_engine/ares_resolver.cc +54 -50
- data/src/core/lib/event_engine/ares_resolver.h +3 -2
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +3 -3
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +4 -10
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +74 -33
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +4 -4
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +6 -2
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +3 -0
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +3 -0
- data/src/core/lib/event_engine/windows/windows_endpoint.cc +1 -3
- data/src/core/lib/experiments/experiments.cc +60 -96
- data/src/core/lib/experiments/experiments.h +34 -50
- data/src/core/lib/iomgr/cfstream_handle.cc +2 -6
- data/src/core/lib/iomgr/endpoint_cfstream.cc +3 -10
- data/src/core/lib/iomgr/error.cc +2 -6
- data/src/core/lib/iomgr/error_cfstream.cc +1 -1
- data/src/core/lib/iomgr/ev_poll_posix.cc +5 -9
- data/src/core/lib/iomgr/event_engine_shims/closure.cc +1 -1
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +1 -2
- data/src/core/lib/iomgr/event_engine_shims/tcp_client.cc +1 -2
- data/src/core/lib/iomgr/iomgr_posix.cc +0 -4
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +0 -4
- data/src/core/lib/iomgr/iomgr_windows.cc +0 -4
- data/src/core/lib/iomgr/socket_factory_posix.h +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.cc +3 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
- data/src/core/lib/iomgr/systemd_utils.cc +0 -1
- data/src/core/lib/iomgr/tcp_client.h +1 -1
- data/src/core/lib/iomgr/tcp_posix.cc +23 -15
- data/src/core/lib/iomgr/tcp_server.h +1 -1
- data/src/core/lib/iomgr/tcp_server_posix.cc +2 -3
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +0 -1
- data/src/core/lib/iomgr/tcp_server_windows.cc +0 -1
- data/src/core/lib/iomgr/tcp_windows.cc +5 -10
- data/src/core/lib/iomgr/unix_sockets_posix.cc +2 -4
- data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
- data/src/core/lib/iomgr/vsock.h +3 -1
- data/src/core/lib/resource_quota/memory_quota.cc +1 -1
- data/src/core/lib/security/authorization/rbac_policy.cc +139 -56
- data/src/core/lib/security/authorization/rbac_policy.h +21 -3
- data/src/core/lib/surface/call.cc +3 -9
- data/src/core/lib/surface/call_utils.h +113 -0
- data/src/core/lib/surface/channel_create.cc +1 -1
- data/src/core/lib/surface/channel_create.h +0 -2
- data/src/core/lib/surface/channel_init.cc +77 -38
- data/src/core/lib/surface/channel_init.h +30 -16
- data/src/core/lib/surface/filter_stack_call.cc +5 -10
- data/src/core/lib/surface/init.cc +13 -27
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/error_utils.cc +0 -27
- data/src/core/lib/transport/error_utils.h +0 -16
- data/src/core/lib/transport/transport.h +7 -5
- data/src/core/load_balancing/pick_first/pick_first.cc +2 -0
- data/src/core/load_balancing/rls/rls.cc +28 -11
- data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +33 -42
- data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.h +0 -2
- data/src/core/load_balancing/xds/cds.cc +3 -1
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +0 -1
- data/src/core/mitigation_engine/mitigation.h +14 -5
- data/src/core/mitigation_engine/mitigation_engine.h +7 -3
- data/src/core/mitigation_engine/mitigation_provider.h +2 -1
- data/src/core/plugin_registry/grpc_plugin_registry.cc +39 -8
- data/src/core/resolver/dns/{event_engine/event_engine_client_channel_resolver.cc → dns_resolver.cc} +42 -41
- data/src/core/resolver/dns/{event_engine/event_engine_client_channel_resolver.h → dns_resolver.h} +8 -5
- data/src/core/resolver/dns/{event_engine/service_config_helper.cc → service_config_helper.cc} +1 -1
- data/src/core/resolver/dns/{event_engine/service_config_helper.h → service_config_helper.h} +3 -3
- data/src/core/resolver/endpoint_addresses.h +3 -0
- data/src/core/resolver/google_c2p/google_c2p_resolver.cc +2 -1
- data/src/core/resolver/xds/xds_resolver.cc +35 -9
- data/src/core/server/server.cc +2 -6
- data/src/core/server/server_config_selector.h +18 -3
- data/src/core/server/server_config_selector_filter.cc +178 -91
- data/src/core/server/server_config_selector_filter.h +58 -3
- data/src/core/server/xds_server_config_fetcher.cc +196 -129
- data/src/core/server/xds_server_config_fetcher.h +49 -0
- data/src/core/server/xds_server_config_fetcher_legacy.cc +41 -37
- data/src/core/telemetry/histogram.h +94 -14
- data/src/core/telemetry/instrument.cc +179 -74
- data/src/core/telemetry/instrument.h +78 -30
- data/src/core/telemetry/metrics.h +5 -0
- data/src/core/{resolver/dns/dns_resolver_plugin.h → telemetry/telemetry_label.h} +12 -8
- data/src/core/tsi/alts/crypt/aes_gcm.cc +10 -13
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +3 -1
- data/src/core/tsi/ssl_telemetry_utils.cc +216 -259
- data/src/core/tsi/ssl_telemetry_utils.h +12 -2
- data/src/core/tsi/ssl_transport_security.cc +238 -80
- data/src/core/tsi/ssl_transport_security.h +63 -33
- data/src/core/tsi/tls_telemetry.cc +31 -0
- data/src/core/tsi/tls_telemetry.h +47 -0
- data/src/core/tsi/transport_security.cc +2 -2
- data/src/core/tsi/transport_security.h +1 -1
- data/src/core/tsi/transport_security_interface.h +1 -1
- data/src/core/{resolver/dns/native/dns_resolver.h → util/address_sorting_init.cc} +21 -8
- data/src/core/{resolver/dns/c_ares/grpc_ares_wrapper_posix.cc → util/address_sorting_init.h} +7 -8
- data/src/core/util/http_client/httpcli.cc +16 -53
- data/src/core/util/http_client/httpcli.h +0 -7
- data/src/core/util/http_client/httpcli_security_connector.cc +13 -8
- data/src/core/util/linux/cpu.cc +1 -1
- data/src/core/util/load_file.cc +3 -9
- data/src/core/util/load_file.h +3 -4
- data/src/core/util/matchers.h +8 -0
- data/src/core/util/posix/cpu.cc +1 -1
- data/src/core/util/status_helper.cc +0 -20
- data/src/core/util/status_helper.h +3 -14
- data/src/core/xds/grpc/xds_audit_logger_registry.cc +51 -31
- data/src/core/xds/grpc/xds_audit_logger_registry.h +17 -3
- data/src/core/xds/grpc/xds_bootstrap_grpc.cc +2 -10
- data/src/core/xds/grpc/xds_bootstrap_grpc.h +8 -6
- data/src/core/xds/grpc/xds_bootstrap_grpc_builder.cc +488 -0
- data/src/core/xds/grpc/xds_bootstrap_grpc_builder.h +97 -0
- data/src/core/xds/grpc/xds_certificate_provider.cc +7 -7
- data/src/core/xds/grpc/xds_client_grpc.cc +4 -8
- data/src/core/xds/grpc/xds_client_grpc.h +0 -4
- data/src/core/xds/grpc/xds_cluster.h +1 -0
- data/src/core/xds/grpc/xds_cluster_parser.cc +1 -5
- data/src/core/xds/grpc/xds_cluster_parser.h +0 -2
- data/src/core/xds/grpc/xds_cluster_specifier_plugin.cc +0 -2
- data/src/core/xds/grpc/xds_cluster_specifier_plugin.h +0 -2
- data/src/core/xds/grpc/xds_common_types.cc +0 -91
- data/src/core/xds/grpc/xds_common_types.h +1 -47
- data/src/core/xds/grpc/xds_common_types_parser.cc +84 -378
- data/src/core/xds/grpc/xds_common_types_parser.h +9 -11
- data/src/core/xds/grpc/xds_endpoint_parser.cc +0 -2
- data/src/core/xds/grpc/xds_grpc_service_parser.cc +177 -0
- data/src/core/{resolver/dns/c_ares/dns_resolver_ares.h → xds/grpc/xds_grpc_service_parser.h} +14 -9
- data/src/core/xds/grpc/xds_http_composite_filter.cc +26 -21
- data/src/core/xds/grpc/xds_http_composite_filter.h +4 -3
- data/src/core/xds/grpc/xds_http_ext_proc_filter.cc +418 -0
- data/src/core/xds/grpc/xds_http_ext_proc_filter.h +89 -0
- data/src/core/xds/grpc/xds_http_fault_filter.cc +9 -12
- data/src/core/xds/grpc/xds_http_fault_filter.h +1 -4
- data/src/core/xds/grpc/xds_http_filter.cc +2 -1
- data/src/core/xds/grpc/xds_http_filter.h +6 -5
- data/src/core/xds/grpc/xds_http_filter_registry.cc +10 -127
- data/src/core/xds/grpc/xds_http_filter_registry.h +7 -59
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.cc +13 -14
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.h +3 -2
- data/src/core/xds/grpc/xds_http_rbac_filter.cc +403 -25
- data/src/core/xds/grpc/xds_http_rbac_filter.h +1 -3
- data/src/core/xds/grpc/xds_http_stateful_session_filter.cc +8 -13
- data/src/core/xds/grpc/xds_http_stateful_session_filter.h +1 -4
- data/src/core/xds/grpc/xds_lb_policy_registry.cc +0 -292
- data/src/core/xds/grpc/xds_lb_policy_registry.h +7 -3
- data/src/core/xds/grpc/xds_listener.cc +2 -0
- data/src/core/xds/grpc/xds_listener.h +5 -0
- data/src/core/xds/grpc/xds_listener_parser.cc +16 -11
- data/src/core/xds/grpc/xds_matcher_parse.h +3 -1
- data/src/core/xds/grpc/xds_metadata_parser.cc +6 -1
- data/src/core/xds/grpc/xds_metadata_parser.h +2 -0
- data/src/core/xds/grpc/xds_route_config.cc +2 -0
- data/src/core/xds/grpc/xds_route_config.h +3 -1
- data/src/core/xds/grpc/xds_route_config_parser.cc +13 -79
- data/src/core/xds/grpc/xds_route_config_parser.h +0 -3
- data/src/core/xds/grpc/xds_routing.cc +116 -69
- data/src/core/xds/grpc/xds_routing.h +19 -8
- data/src/core/xds/grpc/xds_tls_context.cc +117 -0
- data/src/core/xds/grpc/xds_tls_context.h +76 -0
- data/src/core/xds/grpc/xds_tls_context_parser.cc +275 -0
- data/src/core/xds/grpc/xds_tls_context_parser.h +35 -0
- data/src/core/xds/grpc/xds_transport_grpc.cc +41 -38
- data/src/core/xds/grpc/xds_transport_grpc.h +4 -2
- data/src/ruby/ext/grpc/rb_call.c +26 -15
- data/src/ruby/ext/grpc/rb_completion_queue.c +6 -5
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/test/client.rb +5 -4
- data/src/ruby/spec/call_spec.rb +14 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +3 -6
- metadata +50 -35
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +0 -716
- data/src/core/lib/iomgr/resolve_address.cc +0 -59
- data/src/core/lib/iomgr/resolve_address.h +0 -125
- data/src/core/lib/iomgr/resolve_address_impl.h +0 -58
- data/src/core/lib/iomgr/resolve_address_posix.cc +0 -184
- data/src/core/lib/iomgr/resolve_address_posix.h +0 -78
- data/src/core/lib/iomgr/resolve_address_windows.cc +0 -169
- data/src/core/lib/iomgr/resolve_address_windows.h +0 -76
- data/src/core/resolver/dns/c_ares/dns_resolver_ares.cc +0 -781
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +0 -93
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +0 -203
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -838
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +0 -1237
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +0 -130
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -35
- data/src/core/resolver/dns/dns_resolver_plugin.cc +0 -64
- data/src/core/resolver/dns/native/dns_resolver.cc +0 -173
- data/src/core/util/json/json_util.cc +0 -101
- data/src/core/util/json/json_util.h +0 -163
|
@@ -1,1237 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2016 gRPC authors.
|
|
4
|
-
//
|
|
5
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
// you may not use this file except in compliance with the License.
|
|
7
|
-
// You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
// See the License for the specific language governing permissions and
|
|
15
|
-
// limitations under the License.
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
#include <grpc/impl/channel_arg_names.h>
|
|
20
|
-
#include <grpc/support/port_platform.h>
|
|
21
|
-
|
|
22
|
-
#include <algorithm>
|
|
23
|
-
#include <vector>
|
|
24
|
-
|
|
25
|
-
#include "src/core/lib/iomgr/sockaddr.h"
|
|
26
|
-
#include "src/core/util/status_helper.h"
|
|
27
|
-
#include "absl/strings/string_view.h"
|
|
28
|
-
|
|
29
|
-
// IWYU pragma: no_include <arpa/inet.h>
|
|
30
|
-
// IWYU pragma: no_include <arpa/nameser.h>
|
|
31
|
-
// IWYU pragma: no_include <inttypes.h>
|
|
32
|
-
// IWYU pragma: no_include <netdb.h>
|
|
33
|
-
// IWYU pragma: no_include <netinet/in.h>
|
|
34
|
-
// IWYU pragma: no_include <stdlib.h>
|
|
35
|
-
// IWYU pragma: no_include <sys/socket.h>
|
|
36
|
-
|
|
37
|
-
#if GRPC_ARES == 1
|
|
38
|
-
|
|
39
|
-
#include <address_sorting/address_sorting.h>
|
|
40
|
-
#include <ares.h>
|
|
41
|
-
#include <grpc/support/alloc.h>
|
|
42
|
-
#include <grpc/support/string_util.h>
|
|
43
|
-
#include <grpc/support/sync.h>
|
|
44
|
-
#include <string.h>
|
|
45
|
-
#include <sys/types.h> // IWYU pragma: keep
|
|
46
|
-
|
|
47
|
-
#include <string>
|
|
48
|
-
#include <utility>
|
|
49
|
-
|
|
50
|
-
#include "src/core/lib/address_utils/parse_address.h"
|
|
51
|
-
#include "src/core/lib/address_utils/sockaddr_utils.h"
|
|
52
|
-
#include "src/core/lib/channel/channel_args.h"
|
|
53
|
-
#include "src/core/lib/iomgr/error.h"
|
|
54
|
-
#include "src/core/lib/iomgr/exec_ctx.h"
|
|
55
|
-
#include "src/core/lib/iomgr/nameser.h" // IWYU pragma: keep
|
|
56
|
-
#include "src/core/lib/iomgr/resolved_address.h"
|
|
57
|
-
#include "src/core/lib/iomgr/timer.h"
|
|
58
|
-
#include "src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
|
59
|
-
#include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
|
60
|
-
#include "src/core/util/debug_location.h"
|
|
61
|
-
#include "src/core/util/grpc_check.h"
|
|
62
|
-
#include "src/core/util/host_port.h"
|
|
63
|
-
#include "src/core/util/string.h"
|
|
64
|
-
#include "src/core/util/time.h"
|
|
65
|
-
#include "absl/log/log.h"
|
|
66
|
-
#include "absl/status/status.h"
|
|
67
|
-
#include "absl/status/statusor.h"
|
|
68
|
-
#include "absl/strings/str_cat.h"
|
|
69
|
-
#include "absl/strings/str_format.h"
|
|
70
|
-
|
|
71
|
-
using grpc_core::EndpointAddresses;
|
|
72
|
-
using grpc_core::EndpointAddressesList;
|
|
73
|
-
|
|
74
|
-
typedef struct fd_node {
|
|
75
|
-
// default constructor exists only for linked list manipulation
|
|
76
|
-
fd_node() : ev_driver(nullptr) {}
|
|
77
|
-
|
|
78
|
-
explicit fd_node(grpc_ares_ev_driver* ev_driver) : ev_driver(ev_driver) {}
|
|
79
|
-
|
|
80
|
-
/// the owner of this fd node
|
|
81
|
-
grpc_ares_ev_driver* const ev_driver;
|
|
82
|
-
/// a closure wrapping on_readable_locked, which should be
|
|
83
|
-
/// invoked when the grpc_fd in this node becomes readable.
|
|
84
|
-
grpc_closure read_closure ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
85
|
-
/// a closure wrapping on_writable_locked, which should be
|
|
86
|
-
/// invoked when the grpc_fd in this node becomes writable.
|
|
87
|
-
grpc_closure write_closure ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
88
|
-
/// next fd node in the list
|
|
89
|
-
struct fd_node* next ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
90
|
-
|
|
91
|
-
/// wrapped fd that's polled by grpc's poller for the current platform
|
|
92
|
-
grpc_core::GrpcPolledFd* grpc_polled_fd
|
|
93
|
-
ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
94
|
-
/// if the readable closure has been registered
|
|
95
|
-
bool readable_registered ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
96
|
-
/// if the writable closure has been registered
|
|
97
|
-
bool writable_registered ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
98
|
-
/// if the fd has been shutdown yet from grpc iomgr perspective
|
|
99
|
-
bool already_shutdown ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
100
|
-
} fd_node;
|
|
101
|
-
|
|
102
|
-
struct grpc_ares_ev_driver {
|
|
103
|
-
explicit grpc_ares_ev_driver(grpc_ares_request* request) : request(request) {}
|
|
104
|
-
|
|
105
|
-
/// the ares_channel owned by this event driver
|
|
106
|
-
ares_channel channel ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
107
|
-
/// pollset set for driving the IO events of the channel
|
|
108
|
-
grpc_pollset_set* pollset_set ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
109
|
-
/// refcount of the event driver
|
|
110
|
-
gpr_refcount refs;
|
|
111
|
-
|
|
112
|
-
/// a list of grpc_fd that this event driver is currently using.
|
|
113
|
-
fd_node* fds ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
114
|
-
/// is this event driver being shut down
|
|
115
|
-
bool shutting_down ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
116
|
-
/// request object that's using this ev driver
|
|
117
|
-
grpc_ares_request* const request;
|
|
118
|
-
/// Owned by the ev_driver. Creates new GrpcPolledFd's
|
|
119
|
-
std::unique_ptr<grpc_core::GrpcPolledFdFactory> polled_fd_factory
|
|
120
|
-
ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
121
|
-
/// query timeout in milliseconds
|
|
122
|
-
int query_timeout_ms ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
123
|
-
/// alarm to cancel active queries
|
|
124
|
-
grpc_timer query_timeout ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
125
|
-
/// cancels queries on a timeout
|
|
126
|
-
grpc_closure on_timeout_locked ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
127
|
-
/// alarm to poll ares_process on in case fd events don't happen
|
|
128
|
-
grpc_timer ares_backup_poll_alarm ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
129
|
-
/// polls ares_process on a periodic timer
|
|
130
|
-
grpc_closure on_ares_backup_poll_alarm_locked
|
|
131
|
-
ABSL_GUARDED_BY(&grpc_ares_request::mu);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// TODO(apolcyn): make grpc_ares_hostbyname_request a sub-class
|
|
135
|
-
// of GrpcAresQuery.
|
|
136
|
-
typedef struct grpc_ares_hostbyname_request {
|
|
137
|
-
/// following members are set in create_hostbyname_request_locked
|
|
138
|
-
///
|
|
139
|
-
/// the top-level request instance
|
|
140
|
-
grpc_ares_request* parent_request;
|
|
141
|
-
/// host to resolve, parsed from the name to resolve
|
|
142
|
-
char* host;
|
|
143
|
-
/// port to fill in sockaddr_in, parsed from the name to resolve
|
|
144
|
-
uint16_t port;
|
|
145
|
-
/// is it a grpclb address
|
|
146
|
-
bool is_balancer;
|
|
147
|
-
/// for logging and errors: the query type ("A" or "AAAA")
|
|
148
|
-
const char* qtype;
|
|
149
|
-
} grpc_ares_hostbyname_request;
|
|
150
|
-
|
|
151
|
-
static void grpc_ares_request_ref_locked(grpc_ares_request* r)
|
|
152
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu);
|
|
153
|
-
static void grpc_ares_request_unref_locked(grpc_ares_request* r)
|
|
154
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu);
|
|
155
|
-
|
|
156
|
-
// TODO(apolcyn): as a part of C++-ification, find a way to
|
|
157
|
-
// organize per-query and per-resolution information in such a way
|
|
158
|
-
// that doesn't involve allocating a number of different data
|
|
159
|
-
// structures.
|
|
160
|
-
class GrpcAresQuery final {
|
|
161
|
-
public:
|
|
162
|
-
explicit GrpcAresQuery(grpc_ares_request* r, const std::string& name)
|
|
163
|
-
: r_(r), name_(name) {
|
|
164
|
-
grpc_ares_request_ref_locked(r_);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
~GrpcAresQuery() { grpc_ares_request_unref_locked(r_); }
|
|
168
|
-
|
|
169
|
-
grpc_ares_request* parent_request() { return r_; }
|
|
170
|
-
|
|
171
|
-
const std::string& name() { return name_; }
|
|
172
|
-
|
|
173
|
-
private:
|
|
174
|
-
// the top level request instance
|
|
175
|
-
grpc_ares_request* r_;
|
|
176
|
-
/// for logging and errors
|
|
177
|
-
const std::string name_;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
static absl::Status AresStatusToAbslStatus(int status,
|
|
181
|
-
absl::string_view error_msg) {
|
|
182
|
-
switch (status) {
|
|
183
|
-
case ARES_ECANCELLED:
|
|
184
|
-
return absl::CancelledError(error_msg);
|
|
185
|
-
case ARES_ENOTIMP:
|
|
186
|
-
return absl::UnimplementedError(error_msg);
|
|
187
|
-
case ARES_ENOTFOUND:
|
|
188
|
-
return absl::NotFoundError(error_msg);
|
|
189
|
-
case ARES_ECONNREFUSED:
|
|
190
|
-
return absl::UnavailableError(error_msg);
|
|
191
|
-
default:
|
|
192
|
-
return absl::UnknownError(error_msg);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
static grpc_ares_ev_driver* grpc_ares_ev_driver_ref(
|
|
197
|
-
grpc_ares_ev_driver* ev_driver)
|
|
198
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
199
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
200
|
-
<< "(c-ares resolver) request:" << ev_driver->request << " Ref ev_driver "
|
|
201
|
-
<< ev_driver;
|
|
202
|
-
gpr_ref(&ev_driver->refs);
|
|
203
|
-
return ev_driver;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
static void grpc_ares_complete_request_locked(grpc_ares_request* r)
|
|
207
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu);
|
|
208
|
-
|
|
209
|
-
static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver)
|
|
210
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
211
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
212
|
-
<< "(c-ares resolver) request:" << ev_driver->request
|
|
213
|
-
<< " Unref ev_driver " << ev_driver;
|
|
214
|
-
if (gpr_unref(&ev_driver->refs)) {
|
|
215
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
216
|
-
<< "(c-ares resolver) request:" << ev_driver->request
|
|
217
|
-
<< " destroy ev_driver " << ev_driver;
|
|
218
|
-
GRPC_CHECK_EQ(ev_driver->fds, nullptr);
|
|
219
|
-
ares_destroy(ev_driver->channel);
|
|
220
|
-
grpc_ares_complete_request_locked(ev_driver->request);
|
|
221
|
-
delete ev_driver;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
static void fd_node_destroy_locked(fd_node* fdn)
|
|
226
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
227
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
228
|
-
<< "(c-ares resolver) request:" << fdn->ev_driver->request
|
|
229
|
-
<< " delete fd: " << fdn->grpc_polled_fd->GetName();
|
|
230
|
-
GRPC_CHECK(!fdn->readable_registered);
|
|
231
|
-
GRPC_CHECK(!fdn->writable_registered);
|
|
232
|
-
GRPC_CHECK(fdn->already_shutdown);
|
|
233
|
-
delete fdn->grpc_polled_fd;
|
|
234
|
-
delete fdn;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
static void fd_node_shutdown_locked(fd_node* fdn, const char* reason)
|
|
238
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
239
|
-
if (!fdn->already_shutdown) {
|
|
240
|
-
fdn->already_shutdown = true;
|
|
241
|
-
fdn->grpc_polled_fd->ShutdownLocked(GRPC_ERROR_CREATE(reason));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
void grpc_ares_ev_driver_on_queries_complete_locked(
|
|
246
|
-
grpc_ares_ev_driver* ev_driver)
|
|
247
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
248
|
-
// We mark the event driver as being shut down.
|
|
249
|
-
// grpc_ares_notify_on_event_locked will shut down any remaining
|
|
250
|
-
// fds.
|
|
251
|
-
ev_driver->shutting_down = true;
|
|
252
|
-
grpc_timer_cancel(&ev_driver->query_timeout);
|
|
253
|
-
grpc_timer_cancel(&ev_driver->ares_backup_poll_alarm);
|
|
254
|
-
grpc_ares_ev_driver_unref(ev_driver);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
void grpc_ares_ev_driver_shutdown_locked(grpc_ares_ev_driver* ev_driver)
|
|
258
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
259
|
-
ev_driver->shutting_down = true;
|
|
260
|
-
fd_node* fn = ev_driver->fds;
|
|
261
|
-
while (fn != nullptr) {
|
|
262
|
-
fd_node_shutdown_locked(fn, "grpc_ares_ev_driver_shutdown");
|
|
263
|
-
fn = fn->next;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Search fd in the fd_node list head. This is an O(n) search, the max possible
|
|
268
|
-
// value of n is ARES_GETSOCK_MAXNUM (16). n is typically 1 - 2 in our tests.
|
|
269
|
-
static fd_node* pop_fd_node_locked(fd_node** head, ares_socket_t as)
|
|
270
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
271
|
-
fd_node phony_head;
|
|
272
|
-
phony_head.next = *head;
|
|
273
|
-
fd_node* node = &phony_head;
|
|
274
|
-
while (node->next != nullptr) {
|
|
275
|
-
if (node->next->grpc_polled_fd->GetWrappedAresSocketLocked() == as) {
|
|
276
|
-
fd_node* ret = node->next;
|
|
277
|
-
node->next = node->next->next;
|
|
278
|
-
*head = phony_head.next;
|
|
279
|
-
return ret;
|
|
280
|
-
}
|
|
281
|
-
node = node->next;
|
|
282
|
-
}
|
|
283
|
-
return nullptr;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
static grpc_core::Timestamp calculate_next_ares_backup_poll_alarm(
|
|
287
|
-
grpc_ares_ev_driver* driver)
|
|
288
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
289
|
-
// An alternative here could be to use ares_timeout to try to be more
|
|
290
|
-
// accurate, but that would require using "struct timeval"'s, which just makes
|
|
291
|
-
// things a bit more complicated. So just poll every second, as suggested
|
|
292
|
-
// by the c-ares code comments.
|
|
293
|
-
grpc_core::Duration until_next_ares_backup_poll_alarm =
|
|
294
|
-
grpc_core::Duration::Seconds(1);
|
|
295
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
296
|
-
<< "(c-ares resolver) request:" << driver->request
|
|
297
|
-
<< " ev_driver=" << driver << ". next ares process poll time in "
|
|
298
|
-
<< until_next_ares_backup_poll_alarm.millis() << " ms";
|
|
299
|
-
return grpc_core::Timestamp::Now() + until_next_ares_backup_poll_alarm;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
static void on_timeout(void* arg, grpc_error_handle error) {
|
|
303
|
-
grpc_ares_ev_driver* driver = static_cast<grpc_ares_ev_driver*>(arg);
|
|
304
|
-
grpc_core::MutexLock lock(&driver->request->mu);
|
|
305
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
306
|
-
<< "(c-ares resolver) request:" << driver->request
|
|
307
|
-
<< " ev_driver=" << driver
|
|
308
|
-
<< " on_timeout_locked. driver->shutting_down=" << driver->shutting_down
|
|
309
|
-
<< ". err=" << grpc_core::StatusToString(error);
|
|
310
|
-
if (!driver->shutting_down && error.ok()) {
|
|
311
|
-
grpc_ares_ev_driver_shutdown_locked(driver);
|
|
312
|
-
}
|
|
313
|
-
grpc_ares_ev_driver_unref(driver);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver)
|
|
317
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu);
|
|
318
|
-
|
|
319
|
-
// In case of non-responsive DNS servers, dropped packets, etc., c-ares has
|
|
320
|
-
// intelligent timeout and retry logic, which we can take advantage of by
|
|
321
|
-
// polling ares_process_fd on time intervals. Overall, the c-ares library is
|
|
322
|
-
// meant to be called into and given a chance to proceed name resolution:
|
|
323
|
-
// a) when fd events happen
|
|
324
|
-
// b) when some time has passed without fd events having happened
|
|
325
|
-
// For the latter, we use this backup poller. Also see
|
|
326
|
-
// https://github.com/grpc/grpc/pull/17688 description for more details.
|
|
327
|
-
static void on_ares_backup_poll_alarm(void* arg, grpc_error_handle error) {
|
|
328
|
-
grpc_ares_ev_driver* driver = static_cast<grpc_ares_ev_driver*>(arg);
|
|
329
|
-
grpc_core::MutexLock lock(&driver->request->mu);
|
|
330
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
331
|
-
<< "(c-ares resolver) request:" << driver->request
|
|
332
|
-
<< " ev_driver=" << driver
|
|
333
|
-
<< " on_ares_backup_poll_alarm_locked. driver->shutting_down="
|
|
334
|
-
<< driver->shutting_down << ". err=" << grpc_core::StatusToString(error);
|
|
335
|
-
if (!driver->shutting_down && error.ok()) {
|
|
336
|
-
fd_node* fdn = driver->fds;
|
|
337
|
-
while (fdn != nullptr) {
|
|
338
|
-
if (!fdn->already_shutdown) {
|
|
339
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
340
|
-
<< "(c-ares resolver) request:" << driver->request
|
|
341
|
-
<< " ev_driver=" << driver
|
|
342
|
-
<< " on_ares_backup_poll_alarm_locked; ares_process_fd. fd="
|
|
343
|
-
<< fdn->grpc_polled_fd->GetName();
|
|
344
|
-
ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked();
|
|
345
|
-
ares_process_fd(driver->channel, as, as);
|
|
346
|
-
}
|
|
347
|
-
fdn = fdn->next;
|
|
348
|
-
}
|
|
349
|
-
if (!driver->shutting_down) {
|
|
350
|
-
// InvalidateNow to avoid getting stuck re-initializing this timer
|
|
351
|
-
// in a loop while draining the currently-held WorkSerializer.
|
|
352
|
-
// Also see https://github.com/grpc/grpc/issues/26079.
|
|
353
|
-
grpc_core::ExecCtx::Get()->InvalidateNow();
|
|
354
|
-
grpc_core::Timestamp next_ares_backup_poll_alarm =
|
|
355
|
-
calculate_next_ares_backup_poll_alarm(driver);
|
|
356
|
-
grpc_ares_ev_driver_ref(driver);
|
|
357
|
-
GRPC_CLOSURE_INIT(&driver->on_ares_backup_poll_alarm_locked,
|
|
358
|
-
on_ares_backup_poll_alarm, driver,
|
|
359
|
-
grpc_schedule_on_exec_ctx);
|
|
360
|
-
grpc_timer_init(&driver->ares_backup_poll_alarm,
|
|
361
|
-
next_ares_backup_poll_alarm,
|
|
362
|
-
&driver->on_ares_backup_poll_alarm_locked);
|
|
363
|
-
}
|
|
364
|
-
grpc_ares_notify_on_event_locked(driver);
|
|
365
|
-
}
|
|
366
|
-
grpc_ares_ev_driver_unref(driver);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
static void on_readable(void* arg, grpc_error_handle error) {
|
|
370
|
-
fd_node* fdn = static_cast<fd_node*>(arg);
|
|
371
|
-
grpc_core::MutexLock lock(&fdn->ev_driver->request->mu);
|
|
372
|
-
GRPC_CHECK(fdn->readable_registered);
|
|
373
|
-
grpc_ares_ev_driver* ev_driver = fdn->ev_driver;
|
|
374
|
-
const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked();
|
|
375
|
-
fdn->readable_registered = false;
|
|
376
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
377
|
-
<< "(c-ares resolver) request:" << fdn->ev_driver->request
|
|
378
|
-
<< " readable on " << fdn->grpc_polled_fd->GetName();
|
|
379
|
-
if (error.ok() && !ev_driver->shutting_down) {
|
|
380
|
-
ares_process_fd(ev_driver->channel, as, ARES_SOCKET_BAD);
|
|
381
|
-
} else {
|
|
382
|
-
// If error is not absl::OkStatus() or the resolution was cancelled, it
|
|
383
|
-
// means the fd has been shutdown or timed out. The pending lookups made on
|
|
384
|
-
// this ev_driver will be cancelled by the following ares_cancel() and the
|
|
385
|
-
// on_done callbacks will be invoked with a status of ARES_ECANCELLED. The
|
|
386
|
-
// remaining file descriptors in this ev_driver will be cleaned up in the
|
|
387
|
-
// following grpc_ares_notify_on_event_locked().
|
|
388
|
-
ares_cancel(ev_driver->channel);
|
|
389
|
-
}
|
|
390
|
-
grpc_ares_notify_on_event_locked(ev_driver);
|
|
391
|
-
grpc_ares_ev_driver_unref(ev_driver);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
static void on_writable(void* arg, grpc_error_handle error) {
|
|
395
|
-
fd_node* fdn = static_cast<fd_node*>(arg);
|
|
396
|
-
grpc_core::MutexLock lock(&fdn->ev_driver->request->mu);
|
|
397
|
-
GRPC_CHECK(fdn->writable_registered);
|
|
398
|
-
grpc_ares_ev_driver* ev_driver = fdn->ev_driver;
|
|
399
|
-
const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked();
|
|
400
|
-
fdn->writable_registered = false;
|
|
401
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
402
|
-
<< "(c-ares resolver) request:" << ev_driver->request << " writable on "
|
|
403
|
-
<< fdn->grpc_polled_fd->GetName();
|
|
404
|
-
if (error.ok() && !ev_driver->shutting_down) {
|
|
405
|
-
ares_process_fd(ev_driver->channel, ARES_SOCKET_BAD, as);
|
|
406
|
-
} else {
|
|
407
|
-
// If error is not absl::OkStatus() or the resolution was cancelled, it
|
|
408
|
-
// means the fd has been shutdown or timed out. The pending lookups made on
|
|
409
|
-
// this ev_driver will be cancelled by the following ares_cancel() and the
|
|
410
|
-
// on_done callbacks will be invoked with a status of ARES_ECANCELLED. The
|
|
411
|
-
// remaining file descriptors in this ev_driver will be cleaned up in the
|
|
412
|
-
// following grpc_ares_notify_on_event_locked().
|
|
413
|
-
ares_cancel(ev_driver->channel);
|
|
414
|
-
}
|
|
415
|
-
grpc_ares_notify_on_event_locked(ev_driver);
|
|
416
|
-
grpc_ares_ev_driver_unref(ev_driver);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// Get the file descriptors used by the ev_driver's ares channel, register
|
|
420
|
-
// driver_closure with these filedescriptors.
|
|
421
|
-
static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver)
|
|
422
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
423
|
-
fd_node* new_list = nullptr;
|
|
424
|
-
if (!ev_driver->shutting_down) {
|
|
425
|
-
ares_socket_t socks[ARES_GETSOCK_MAXNUM];
|
|
426
|
-
int socks_bitmask =
|
|
427
|
-
ares_getsock(ev_driver->channel, socks, ARES_GETSOCK_MAXNUM);
|
|
428
|
-
for (size_t i = 0; i < ARES_GETSOCK_MAXNUM; i++) {
|
|
429
|
-
if (ARES_GETSOCK_READABLE(socks_bitmask, i) ||
|
|
430
|
-
ARES_GETSOCK_WRITABLE(socks_bitmask, i)) {
|
|
431
|
-
fd_node* fdn = pop_fd_node_locked(&ev_driver->fds, socks[i]);
|
|
432
|
-
// Create a new fd_node if sock[i] is not in the fd_node list.
|
|
433
|
-
if (fdn == nullptr) {
|
|
434
|
-
fdn = new fd_node(ev_driver);
|
|
435
|
-
fdn->grpc_polled_fd =
|
|
436
|
-
ev_driver->polled_fd_factory->NewGrpcPolledFdLocked(
|
|
437
|
-
socks[i], ev_driver->pollset_set);
|
|
438
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
439
|
-
<< "(c-ares resolver) request:" << ev_driver->request
|
|
440
|
-
<< " new fd: " << fdn->grpc_polled_fd->GetName();
|
|
441
|
-
fdn->readable_registered = false;
|
|
442
|
-
fdn->writable_registered = false;
|
|
443
|
-
fdn->already_shutdown = false;
|
|
444
|
-
}
|
|
445
|
-
fdn->next = new_list;
|
|
446
|
-
new_list = fdn;
|
|
447
|
-
// Register read_closure if the socket is readable and read_closure has
|
|
448
|
-
// not been registered with this socket.
|
|
449
|
-
if (ARES_GETSOCK_READABLE(socks_bitmask, i) &&
|
|
450
|
-
!fdn->readable_registered) {
|
|
451
|
-
grpc_ares_ev_driver_ref(ev_driver);
|
|
452
|
-
GRPC_CLOSURE_INIT(&fdn->read_closure, on_readable, fdn,
|
|
453
|
-
grpc_schedule_on_exec_ctx);
|
|
454
|
-
if (fdn->grpc_polled_fd->IsFdStillReadableLocked()) {
|
|
455
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
456
|
-
<< "(c-ares resolver) request:" << ev_driver->request
|
|
457
|
-
<< " schedule direct read on: "
|
|
458
|
-
<< fdn->grpc_polled_fd->GetName();
|
|
459
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, &fdn->read_closure,
|
|
460
|
-
absl::OkStatus());
|
|
461
|
-
} else {
|
|
462
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
463
|
-
<< "(c-ares resolver) request:" << ev_driver->request
|
|
464
|
-
<< " notify read on: " << fdn->grpc_polled_fd->GetName();
|
|
465
|
-
fdn->grpc_polled_fd->RegisterForOnReadableLocked(
|
|
466
|
-
&fdn->read_closure);
|
|
467
|
-
}
|
|
468
|
-
fdn->readable_registered = true;
|
|
469
|
-
}
|
|
470
|
-
// Register write_closure if the socket is writable and write_closure
|
|
471
|
-
// has not been registered with this socket.
|
|
472
|
-
if (ARES_GETSOCK_WRITABLE(socks_bitmask, i) &&
|
|
473
|
-
!fdn->writable_registered) {
|
|
474
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
475
|
-
<< "(c-ares resolver) request:" << ev_driver->request
|
|
476
|
-
<< " notify write on: " << fdn->grpc_polled_fd->GetName();
|
|
477
|
-
grpc_ares_ev_driver_ref(ev_driver);
|
|
478
|
-
GRPC_CLOSURE_INIT(&fdn->write_closure, on_writable, fdn,
|
|
479
|
-
grpc_schedule_on_exec_ctx);
|
|
480
|
-
fdn->grpc_polled_fd->RegisterForOnWriteableLocked(
|
|
481
|
-
&fdn->write_closure);
|
|
482
|
-
fdn->writable_registered = true;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
// We may be shutting down to completion of all requests, or due to a timeout
|
|
488
|
-
// or explicit caller-triggered cancellation. In any of these cases, shut
|
|
489
|
-
// down and destroy any remaining fds.
|
|
490
|
-
while (ev_driver->fds != nullptr) {
|
|
491
|
-
fd_node* cur = ev_driver->fds;
|
|
492
|
-
ev_driver->fds = ev_driver->fds->next;
|
|
493
|
-
if (ev_driver->shutting_down) {
|
|
494
|
-
fd_node_shutdown_locked(cur, "grpc_ares_notify_on_event_locked");
|
|
495
|
-
}
|
|
496
|
-
if (cur->already_shutdown && !cur->readable_registered &&
|
|
497
|
-
!cur->writable_registered) {
|
|
498
|
-
fd_node_destroy_locked(cur);
|
|
499
|
-
} else {
|
|
500
|
-
cur->next = new_list;
|
|
501
|
-
new_list = cur;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
ev_driver->fds = new_list;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
void grpc_ares_ev_driver_start_locked(grpc_ares_ev_driver* ev_driver)
|
|
508
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
|
|
509
|
-
grpc_ares_notify_on_event_locked(ev_driver);
|
|
510
|
-
// Initialize overall DNS resolution timeout alarm
|
|
511
|
-
grpc_core::Duration timeout =
|
|
512
|
-
ev_driver->query_timeout_ms == 0
|
|
513
|
-
? grpc_core::Duration::Infinity()
|
|
514
|
-
: grpc_core::Duration::Milliseconds(ev_driver->query_timeout_ms);
|
|
515
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
516
|
-
<< "(c-ares resolver) request:" << ev_driver->request
|
|
517
|
-
<< " ev_driver=" << ev_driver
|
|
518
|
-
<< " grpc_ares_ev_driver_start_locked. timeout in " << timeout.millis()
|
|
519
|
-
<< " ms";
|
|
520
|
-
grpc_ares_ev_driver_ref(ev_driver);
|
|
521
|
-
GRPC_CLOSURE_INIT(&ev_driver->on_timeout_locked, on_timeout, ev_driver,
|
|
522
|
-
grpc_schedule_on_exec_ctx);
|
|
523
|
-
grpc_timer_init(&ev_driver->query_timeout,
|
|
524
|
-
grpc_core::Timestamp::Now() + timeout,
|
|
525
|
-
&ev_driver->on_timeout_locked);
|
|
526
|
-
// Initialize the backup poll alarm
|
|
527
|
-
grpc_core::Timestamp next_ares_backup_poll_alarm =
|
|
528
|
-
calculate_next_ares_backup_poll_alarm(ev_driver);
|
|
529
|
-
grpc_ares_ev_driver_ref(ev_driver);
|
|
530
|
-
GRPC_CLOSURE_INIT(&ev_driver->on_ares_backup_poll_alarm_locked,
|
|
531
|
-
on_ares_backup_poll_alarm, ev_driver,
|
|
532
|
-
grpc_schedule_on_exec_ctx);
|
|
533
|
-
grpc_timer_init(&ev_driver->ares_backup_poll_alarm,
|
|
534
|
-
next_ares_backup_poll_alarm,
|
|
535
|
-
&ev_driver->on_ares_backup_poll_alarm_locked);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
static void noop_inject_channel_config(ares_channel* /*channel*/) {}
|
|
539
|
-
|
|
540
|
-
void (*grpc_ares_test_only_inject_config)(ares_channel* channel) =
|
|
541
|
-
noop_inject_channel_config;
|
|
542
|
-
|
|
543
|
-
bool g_grpc_ares_test_only_force_tcp = false;
|
|
544
|
-
|
|
545
|
-
grpc_error_handle grpc_ares_ev_driver_create_locked(
|
|
546
|
-
grpc_ares_ev_driver** ev_driver, grpc_pollset_set* pollset_set,
|
|
547
|
-
int query_timeout_ms, grpc_ares_request* request)
|
|
548
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(request->mu) {
|
|
549
|
-
*ev_driver = new grpc_ares_ev_driver(request);
|
|
550
|
-
ares_options opts;
|
|
551
|
-
memset(&opts, 0, sizeof(opts));
|
|
552
|
-
opts.flags |= ARES_FLAG_STAYOPEN;
|
|
553
|
-
if (g_grpc_ares_test_only_force_tcp) {
|
|
554
|
-
opts.flags |= ARES_FLAG_USEVC;
|
|
555
|
-
}
|
|
556
|
-
int status = ares_init_options(&(*ev_driver)->channel, &opts, ARES_OPT_FLAGS);
|
|
557
|
-
grpc_ares_test_only_inject_config(&(*ev_driver)->channel);
|
|
558
|
-
GRPC_TRACE_VLOG(cares_resolver, 2) << "(c-ares resolver) request:" << request
|
|
559
|
-
<< " grpc_ares_ev_driver_create_locked";
|
|
560
|
-
if (status != ARES_SUCCESS) {
|
|
561
|
-
grpc_error_handle err = GRPC_ERROR_CREATE(absl::StrCat(
|
|
562
|
-
"Failed to init ares channel. C-ares error: ", ares_strerror(status)));
|
|
563
|
-
delete *ev_driver;
|
|
564
|
-
return err;
|
|
565
|
-
}
|
|
566
|
-
gpr_ref_init(&(*ev_driver)->refs, 1);
|
|
567
|
-
(*ev_driver)->pollset_set = pollset_set;
|
|
568
|
-
(*ev_driver)->fds = nullptr;
|
|
569
|
-
(*ev_driver)->shutting_down = false;
|
|
570
|
-
(*ev_driver)->polled_fd_factory =
|
|
571
|
-
grpc_core::NewGrpcPolledFdFactory(&(*ev_driver)->request->mu);
|
|
572
|
-
(*ev_driver)
|
|
573
|
-
->polled_fd_factory->ConfigureAresChannelLocked((*ev_driver)->channel);
|
|
574
|
-
(*ev_driver)->query_timeout_ms = query_timeout_ms;
|
|
575
|
-
return absl::OkStatus();
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
static void log_address_sorting_list(const grpc_ares_request* r,
|
|
579
|
-
const EndpointAddressesList& addresses,
|
|
580
|
-
const char* input_output_str) {
|
|
581
|
-
for (size_t i = 0; i < addresses.size(); i++) {
|
|
582
|
-
auto addr_str = grpc_sockaddr_to_string(&addresses[i].address(), true);
|
|
583
|
-
LOG(INFO) << "(c-ares resolver) request:" << r
|
|
584
|
-
<< " c-ares address sorting: " << input_output_str << "[" << i
|
|
585
|
-
<< "]="
|
|
586
|
-
<< (addr_str.ok() ? addr_str->c_str()
|
|
587
|
-
: addr_str.status().ToString().c_str());
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
void grpc_cares_wrapper_address_sorting_sort(const grpc_ares_request* r,
|
|
592
|
-
EndpointAddressesList* addresses) {
|
|
593
|
-
if (GRPC_TRACE_FLAG_ENABLED(cares_address_sorting)) {
|
|
594
|
-
log_address_sorting_list(r, *addresses, "input");
|
|
595
|
-
}
|
|
596
|
-
address_sorting_sortable* sortables = static_cast<address_sorting_sortable*>(
|
|
597
|
-
gpr_zalloc(sizeof(address_sorting_sortable) * addresses->size()));
|
|
598
|
-
for (size_t i = 0; i < addresses->size(); ++i) {
|
|
599
|
-
sortables[i].user_data = &(*addresses)[i];
|
|
600
|
-
memcpy(&sortables[i].dest_addr.addr, &(*addresses)[i].address().addr,
|
|
601
|
-
(*addresses)[i].address().len);
|
|
602
|
-
sortables[i].dest_addr.len = (*addresses)[i].address().len;
|
|
603
|
-
}
|
|
604
|
-
address_sorting_rfc_6724_sort(sortables, addresses->size());
|
|
605
|
-
EndpointAddressesList sorted;
|
|
606
|
-
sorted.reserve(addresses->size());
|
|
607
|
-
for (size_t i = 0; i < addresses->size(); ++i) {
|
|
608
|
-
sorted.emplace_back(
|
|
609
|
-
*static_cast<EndpointAddresses*>(sortables[i].user_data));
|
|
610
|
-
}
|
|
611
|
-
gpr_free(sortables);
|
|
612
|
-
*addresses = std::move(sorted);
|
|
613
|
-
if (GRPC_TRACE_FLAG_ENABLED(cares_address_sorting)) {
|
|
614
|
-
log_address_sorting_list(r, *addresses, "output");
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
static void grpc_ares_request_ref_locked(grpc_ares_request* r)
|
|
619
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu) {
|
|
620
|
-
r->pending_queries++;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
static void grpc_ares_request_unref_locked(grpc_ares_request* r)
|
|
624
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu) {
|
|
625
|
-
r->pending_queries--;
|
|
626
|
-
if (r->pending_queries == 0u) {
|
|
627
|
-
grpc_ares_ev_driver_on_queries_complete_locked(r->ev_driver);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
void grpc_ares_complete_request_locked(grpc_ares_request* r)
|
|
632
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu) {
|
|
633
|
-
// Invoke on_done callback and destroy the request
|
|
634
|
-
r->ev_driver = nullptr;
|
|
635
|
-
if (r->addresses_out != nullptr && *r->addresses_out != nullptr) {
|
|
636
|
-
grpc_cares_wrapper_address_sorting_sort(r, r->addresses_out->get());
|
|
637
|
-
r->error = absl::OkStatus();
|
|
638
|
-
// TODO(apolcyn): allow c-ares to return a service config
|
|
639
|
-
// with no addresses along side it
|
|
640
|
-
}
|
|
641
|
-
if (r->balancer_addresses_out != nullptr) {
|
|
642
|
-
EndpointAddressesList* balancer_addresses =
|
|
643
|
-
r->balancer_addresses_out->get();
|
|
644
|
-
if (balancer_addresses != nullptr) {
|
|
645
|
-
grpc_cares_wrapper_address_sorting_sort(r, balancer_addresses);
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, r->error);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
// Note that the returned object takes a reference to qtype, so
|
|
652
|
-
// qtype must outlive it.
|
|
653
|
-
static grpc_ares_hostbyname_request* create_hostbyname_request_locked(
|
|
654
|
-
grpc_ares_request* parent_request, const char* host, uint16_t port,
|
|
655
|
-
bool is_balancer, const char* qtype)
|
|
656
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(parent_request->mu) {
|
|
657
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
658
|
-
<< "(c-ares resolver) request:" << parent_request
|
|
659
|
-
<< " create_hostbyname_request_locked host:" << host << " port:" << port
|
|
660
|
-
<< " is_balancer:" << is_balancer << " qtype:" << qtype;
|
|
661
|
-
grpc_ares_hostbyname_request* hr = new grpc_ares_hostbyname_request();
|
|
662
|
-
hr->parent_request = parent_request;
|
|
663
|
-
hr->host = gpr_strdup(host);
|
|
664
|
-
hr->port = port;
|
|
665
|
-
hr->is_balancer = is_balancer;
|
|
666
|
-
hr->qtype = qtype;
|
|
667
|
-
grpc_ares_request_ref_locked(parent_request);
|
|
668
|
-
return hr;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
static void destroy_hostbyname_request_locked(grpc_ares_hostbyname_request* hr)
|
|
672
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(hr->parent_request->mu) {
|
|
673
|
-
grpc_ares_request_unref_locked(hr->parent_request);
|
|
674
|
-
gpr_free(hr->host);
|
|
675
|
-
delete hr;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/,
|
|
679
|
-
struct hostent* hostent)
|
|
680
|
-
ABSL_NO_THREAD_SAFETY_ANALYSIS {
|
|
681
|
-
// This callback is invoked from the c-ares library, so disable thread safety
|
|
682
|
-
// analysis. Note that we are guaranteed to be holding r->mu, though.
|
|
683
|
-
grpc_ares_hostbyname_request* hr =
|
|
684
|
-
static_cast<grpc_ares_hostbyname_request*>(arg);
|
|
685
|
-
grpc_ares_request* r = hr->parent_request;
|
|
686
|
-
if (status == ARES_SUCCESS) {
|
|
687
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
688
|
-
<< "(c-ares resolver) request:" << r
|
|
689
|
-
<< " on_hostbyname_done_locked qtype=" << hr->qtype
|
|
690
|
-
<< " host=" << hr->host << " ARES_SUCCESS";
|
|
691
|
-
std::unique_ptr<EndpointAddressesList>* address_list_ptr =
|
|
692
|
-
hr->is_balancer ? r->balancer_addresses_out : r->addresses_out;
|
|
693
|
-
if (*address_list_ptr == nullptr) {
|
|
694
|
-
*address_list_ptr = std::make_unique<EndpointAddressesList>();
|
|
695
|
-
}
|
|
696
|
-
EndpointAddressesList& addresses = **address_list_ptr;
|
|
697
|
-
for (size_t i = 0; hostent->h_addr_list[i] != nullptr; ++i) {
|
|
698
|
-
grpc_core::ChannelArgs args;
|
|
699
|
-
if (hr->is_balancer) {
|
|
700
|
-
args = args.Set(GRPC_ARG_DEFAULT_AUTHORITY, hr->host);
|
|
701
|
-
}
|
|
702
|
-
grpc_resolved_address address;
|
|
703
|
-
memset(&address, 0, sizeof(address));
|
|
704
|
-
switch (hostent->h_addrtype) {
|
|
705
|
-
case AF_INET6: {
|
|
706
|
-
address.len = sizeof(struct sockaddr_in6);
|
|
707
|
-
auto* addr = reinterpret_cast<struct sockaddr_in6*>(&address.addr);
|
|
708
|
-
memcpy(&addr->sin6_addr, hostent->h_addr_list[i],
|
|
709
|
-
sizeof(struct in6_addr));
|
|
710
|
-
addr->sin6_family = static_cast<unsigned char>(hostent->h_addrtype);
|
|
711
|
-
addr->sin6_port = hr->port;
|
|
712
|
-
char output[INET6_ADDRSTRLEN];
|
|
713
|
-
ares_inet_ntop(AF_INET6, &addr->sin6_addr, output, INET6_ADDRSTRLEN);
|
|
714
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
715
|
-
<< "(c-ares resolver) request:" << r
|
|
716
|
-
<< " c-ares resolver gets a AF_INET6 result: \n"
|
|
717
|
-
<< " addr: " << output << "\n port: " << ntohs(hr->port)
|
|
718
|
-
<< "\n sin6_scope_id: " << addr->sin6_scope_id << "\n";
|
|
719
|
-
break;
|
|
720
|
-
}
|
|
721
|
-
case AF_INET: {
|
|
722
|
-
address.len = sizeof(struct sockaddr_in);
|
|
723
|
-
auto* addr = reinterpret_cast<struct sockaddr_in*>(&address.addr);
|
|
724
|
-
memcpy(&addr->sin_addr, hostent->h_addr_list[i],
|
|
725
|
-
sizeof(struct in_addr));
|
|
726
|
-
addr->sin_family = static_cast<unsigned char>(hostent->h_addrtype);
|
|
727
|
-
addr->sin_port = hr->port;
|
|
728
|
-
char output[INET_ADDRSTRLEN];
|
|
729
|
-
ares_inet_ntop(AF_INET, &addr->sin_addr, output, INET_ADDRSTRLEN);
|
|
730
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
731
|
-
<< "(c-ares resolver) request:" << r
|
|
732
|
-
<< " c-ares resolver gets a AF_INET result: \n addr: " << output
|
|
733
|
-
<< "\n port: " << ntohs(hr->port) << "\n";
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
addresses.emplace_back(address, args);
|
|
738
|
-
}
|
|
739
|
-
} else {
|
|
740
|
-
std::string error_msg = absl::StrFormat(
|
|
741
|
-
"C-ares status is not ARES_SUCCESS qtype=%s name=%s is_balancer=%d: %s",
|
|
742
|
-
hr->qtype, hr->host, hr->is_balancer, ares_strerror(status));
|
|
743
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
744
|
-
<< "(c-ares resolver) request:" << r
|
|
745
|
-
<< " on_hostbyname_done_locked: " << error_msg;
|
|
746
|
-
r->error = grpc_error_add_child(AresStatusToAbslStatus(status, error_msg),
|
|
747
|
-
r->error);
|
|
748
|
-
}
|
|
749
|
-
destroy_hostbyname_request_locked(hr);
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
static void on_srv_query_done_locked(void* arg, int status, int /*timeouts*/,
|
|
753
|
-
unsigned char* abuf,
|
|
754
|
-
int alen) ABSL_NO_THREAD_SAFETY_ANALYSIS {
|
|
755
|
-
// This callback is invoked from the c-ares library, so disable thread safety
|
|
756
|
-
// analysis. Note that we are guaranteed to be holding r->mu, though.
|
|
757
|
-
GrpcAresQuery* q = static_cast<GrpcAresQuery*>(arg);
|
|
758
|
-
grpc_ares_request* r = q->parent_request();
|
|
759
|
-
if (status == ARES_SUCCESS) {
|
|
760
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
761
|
-
<< "(c-ares resolver) request:" << r
|
|
762
|
-
<< " on_srv_query_done_locked name=" << q->name() << " ARES_SUCCESS";
|
|
763
|
-
struct ares_srv_reply* reply;
|
|
764
|
-
const int parse_status = ares_parse_srv_reply(abuf, alen, &reply);
|
|
765
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
766
|
-
<< "(c-ares resolver) request:" << r
|
|
767
|
-
<< " ares_parse_srv_reply: " << parse_status;
|
|
768
|
-
if (parse_status == ARES_SUCCESS) {
|
|
769
|
-
for (struct ares_srv_reply* srv_it = reply; srv_it != nullptr;
|
|
770
|
-
srv_it = srv_it->next) {
|
|
771
|
-
if (grpc_ares_query_ipv6()) {
|
|
772
|
-
grpc_ares_hostbyname_request* hr = create_hostbyname_request_locked(
|
|
773
|
-
r, srv_it->host, htons(srv_it->port), true /* is_balancer */,
|
|
774
|
-
"AAAA");
|
|
775
|
-
ares_gethostbyname(r->ev_driver->channel, hr->host, AF_INET6,
|
|
776
|
-
on_hostbyname_done_locked, hr);
|
|
777
|
-
}
|
|
778
|
-
grpc_ares_hostbyname_request* hr = create_hostbyname_request_locked(
|
|
779
|
-
r, srv_it->host, htons(srv_it->port), true /* is_balancer */, "A");
|
|
780
|
-
ares_gethostbyname(r->ev_driver->channel, hr->host, AF_INET,
|
|
781
|
-
on_hostbyname_done_locked, hr);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
if (reply != nullptr) {
|
|
785
|
-
ares_free_data(reply);
|
|
786
|
-
}
|
|
787
|
-
} else {
|
|
788
|
-
std::string error_msg = absl::StrFormat(
|
|
789
|
-
"C-ares status is not ARES_SUCCESS qtype=SRV name=%s: %s", q->name(),
|
|
790
|
-
ares_strerror(status));
|
|
791
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
792
|
-
<< "(c-ares resolver) request:" << r
|
|
793
|
-
<< " on_srv_query_done_locked: " << error_msg;
|
|
794
|
-
r->error = grpc_error_add_child(AresStatusToAbslStatus(status, error_msg),
|
|
795
|
-
r->error);
|
|
796
|
-
}
|
|
797
|
-
delete q;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
static const char g_service_config_attribute_prefix[] = "grpc_config=";
|
|
801
|
-
|
|
802
|
-
static void on_txt_done_locked(void* arg, int status, int /*timeouts*/,
|
|
803
|
-
unsigned char* buf,
|
|
804
|
-
int len) ABSL_NO_THREAD_SAFETY_ANALYSIS {
|
|
805
|
-
// This callback is invoked from the c-ares library, so disable thread safety
|
|
806
|
-
// analysis. Note that we are guaranteed to be holding r->mu, though.
|
|
807
|
-
GrpcAresQuery* q = static_cast<GrpcAresQuery*>(arg);
|
|
808
|
-
std::unique_ptr<GrpcAresQuery> query_deleter(q);
|
|
809
|
-
grpc_ares_request* r = q->parent_request();
|
|
810
|
-
const size_t prefix_len = sizeof(g_service_config_attribute_prefix) - 1;
|
|
811
|
-
struct ares_txt_ext* result = nullptr;
|
|
812
|
-
struct ares_txt_ext* reply = nullptr;
|
|
813
|
-
if (status != ARES_SUCCESS) goto fail;
|
|
814
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
815
|
-
<< "(c-ares resolver) request:" << r
|
|
816
|
-
<< " on_txt_done_locked name=" << q->name() << " ARES_SUCCESS";
|
|
817
|
-
status = ares_parse_txt_reply_ext(buf, len, &reply);
|
|
818
|
-
if (status != ARES_SUCCESS) goto fail;
|
|
819
|
-
// Find service config in TXT record.
|
|
820
|
-
for (result = reply; result != nullptr; result = result->next) {
|
|
821
|
-
if (result->record_start && result->length >= prefix_len &&
|
|
822
|
-
memcmp(result->txt, g_service_config_attribute_prefix, prefix_len) ==
|
|
823
|
-
0) {
|
|
824
|
-
break;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
// Found a service config record.
|
|
828
|
-
if (result != nullptr) {
|
|
829
|
-
size_t service_config_len = result->length - prefix_len;
|
|
830
|
-
*r->service_config_json_out =
|
|
831
|
-
static_cast<char*>(gpr_malloc(service_config_len + 1));
|
|
832
|
-
memcpy(*r->service_config_json_out, result->txt + prefix_len,
|
|
833
|
-
service_config_len);
|
|
834
|
-
for (result = result->next; result != nullptr && !result->record_start;
|
|
835
|
-
result = result->next) {
|
|
836
|
-
*r->service_config_json_out = static_cast<char*>(
|
|
837
|
-
gpr_realloc(*r->service_config_json_out,
|
|
838
|
-
service_config_len + result->length + 1));
|
|
839
|
-
memcpy(*r->service_config_json_out + service_config_len, result->txt,
|
|
840
|
-
result->length);
|
|
841
|
-
service_config_len += result->length;
|
|
842
|
-
}
|
|
843
|
-
(*r->service_config_json_out)[service_config_len] = '\0';
|
|
844
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
845
|
-
<< "(c-ares resolver) request:" << r
|
|
846
|
-
<< " found service config: " << *r->service_config_json_out;
|
|
847
|
-
}
|
|
848
|
-
// Clean up.
|
|
849
|
-
ares_free_data(reply);
|
|
850
|
-
grpc_ares_request_unref_locked(r);
|
|
851
|
-
return;
|
|
852
|
-
fail:
|
|
853
|
-
std::string error_msg =
|
|
854
|
-
absl::StrFormat("C-ares status is not ARES_SUCCESS qtype=TXT name=%s: %s",
|
|
855
|
-
q->name(), ares_strerror(status));
|
|
856
|
-
GRPC_TRACE_VLOG(cares_resolver, 2) << "(c-ares resolver) request:" << r
|
|
857
|
-
<< " on_txt_done_locked " << error_msg;
|
|
858
|
-
r->error =
|
|
859
|
-
grpc_error_add_child(AresStatusToAbslStatus(status, error_msg), r->error);
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
grpc_error_handle set_request_dns_server(grpc_ares_request* r,
|
|
863
|
-
absl::string_view dns_server)
|
|
864
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu) {
|
|
865
|
-
if (!dns_server.empty()) {
|
|
866
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
867
|
-
<< "(c-ares resolver) request:" << r << " Using DNS server "
|
|
868
|
-
<< dns_server.data();
|
|
869
|
-
grpc_resolved_address addr;
|
|
870
|
-
if (grpc_parse_ipv4_hostport(dns_server, &addr, /*log_errors=*/false)) {
|
|
871
|
-
r->dns_server_addr.family = AF_INET;
|
|
872
|
-
struct sockaddr_in* in = reinterpret_cast<struct sockaddr_in*>(addr.addr);
|
|
873
|
-
memcpy(&r->dns_server_addr.addr.addr4, &in->sin_addr,
|
|
874
|
-
sizeof(struct in_addr));
|
|
875
|
-
r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr);
|
|
876
|
-
r->dns_server_addr.udp_port = grpc_sockaddr_get_port(&addr);
|
|
877
|
-
} else if (grpc_parse_ipv6_hostport(dns_server, &addr,
|
|
878
|
-
/*log_errors=*/false)) {
|
|
879
|
-
r->dns_server_addr.family = AF_INET6;
|
|
880
|
-
struct sockaddr_in6* in6 =
|
|
881
|
-
reinterpret_cast<struct sockaddr_in6*>(addr.addr);
|
|
882
|
-
memcpy(&r->dns_server_addr.addr.addr6, &in6->sin6_addr,
|
|
883
|
-
sizeof(struct in6_addr));
|
|
884
|
-
r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr);
|
|
885
|
-
r->dns_server_addr.udp_port = grpc_sockaddr_get_port(&addr);
|
|
886
|
-
} else {
|
|
887
|
-
return GRPC_ERROR_CREATE(
|
|
888
|
-
absl::StrCat("cannot parse authority ", dns_server));
|
|
889
|
-
}
|
|
890
|
-
int status =
|
|
891
|
-
ares_set_servers_ports(r->ev_driver->channel, &r->dns_server_addr);
|
|
892
|
-
if (status != ARES_SUCCESS) {
|
|
893
|
-
return GRPC_ERROR_CREATE(absl::StrCat(
|
|
894
|
-
"C-ares status is not ARES_SUCCESS: ", ares_strerror(status)));
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
return absl::OkStatus();
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// Common logic for all lookup methods.
|
|
901
|
-
// If an error occurs, callers must run the client callback.
|
|
902
|
-
grpc_error_handle grpc_dns_lookup_ares_continued(
|
|
903
|
-
grpc_ares_request* r, const char* dns_server, const char* name,
|
|
904
|
-
const char* default_port, grpc_pollset_set* interested_parties,
|
|
905
|
-
int query_timeout_ms, std::string* host, std::string* port, bool check_port)
|
|
906
|
-
ABSL_EXCLUSIVE_LOCKS_REQUIRED(r->mu) {
|
|
907
|
-
grpc_error_handle error;
|
|
908
|
-
// parse name, splitting it into host and port parts
|
|
909
|
-
grpc_core::SplitHostPort(name, host, port);
|
|
910
|
-
if (host->empty()) {
|
|
911
|
-
error =
|
|
912
|
-
GRPC_ERROR_CREATE(absl::StrCat("unparsable host:port \"", name, "\""));
|
|
913
|
-
return error;
|
|
914
|
-
} else if (check_port && port->empty()) {
|
|
915
|
-
if (default_port == nullptr || strlen(default_port) == 0) {
|
|
916
|
-
error = GRPC_ERROR_CREATE(absl::StrCat("no port in name \"", name, "\""));
|
|
917
|
-
return error;
|
|
918
|
-
}
|
|
919
|
-
*port = default_port;
|
|
920
|
-
}
|
|
921
|
-
error = grpc_ares_ev_driver_create_locked(&r->ev_driver, interested_parties,
|
|
922
|
-
query_timeout_ms, r);
|
|
923
|
-
if (!error.ok()) return error;
|
|
924
|
-
// If dns_server is specified, use it.
|
|
925
|
-
error = set_request_dns_server(r, dns_server);
|
|
926
|
-
return error;
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
static bool inner_resolve_as_ip_literal_locked(
|
|
930
|
-
const char* name, const char* default_port,
|
|
931
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* addrs, std::string* host,
|
|
932
|
-
std::string* port, std::string* hostport) {
|
|
933
|
-
if (!grpc_core::SplitHostPort(name, host, port)) {
|
|
934
|
-
LOG(ERROR) << "Failed to parse " << name
|
|
935
|
-
<< " to host:port while attempting to resolve as ip literal.";
|
|
936
|
-
return false;
|
|
937
|
-
}
|
|
938
|
-
if (port->empty()) {
|
|
939
|
-
if (default_port == nullptr || strlen(default_port) == 0) {
|
|
940
|
-
LOG(ERROR) << "No port or default port for " << name
|
|
941
|
-
<< " while attempting to resolve as ip literal.";
|
|
942
|
-
return false;
|
|
943
|
-
}
|
|
944
|
-
*port = default_port;
|
|
945
|
-
}
|
|
946
|
-
grpc_resolved_address addr;
|
|
947
|
-
*hostport = grpc_core::JoinHostPort(*host, atoi(port->c_str()));
|
|
948
|
-
if (grpc_parse_ipv4_hostport(hostport->c_str(), &addr,
|
|
949
|
-
false /* log errors */) ||
|
|
950
|
-
grpc_parse_ipv6_hostport(hostport->c_str(), &addr,
|
|
951
|
-
false /* log errors */)) {
|
|
952
|
-
GRPC_CHECK(*addrs == nullptr);
|
|
953
|
-
*addrs = std::make_unique<EndpointAddressesList>();
|
|
954
|
-
(*addrs)->emplace_back(addr, grpc_core::ChannelArgs());
|
|
955
|
-
return true;
|
|
956
|
-
}
|
|
957
|
-
return false;
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
static bool resolve_as_ip_literal_locked(
|
|
961
|
-
const char* name, const char* default_port,
|
|
962
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* addrs) {
|
|
963
|
-
std::string host;
|
|
964
|
-
std::string port;
|
|
965
|
-
std::string hostport;
|
|
966
|
-
bool out = inner_resolve_as_ip_literal_locked(name, default_port, addrs,
|
|
967
|
-
&host, &port, &hostport);
|
|
968
|
-
return out;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
static bool target_matches_localhost_inner(const char* name, std::string* host,
|
|
972
|
-
std::string* port) {
|
|
973
|
-
if (!grpc_core::SplitHostPort(name, host, port)) {
|
|
974
|
-
LOG(ERROR) << "Unable to split host and port for name: " << name;
|
|
975
|
-
return false;
|
|
976
|
-
}
|
|
977
|
-
return gpr_stricmp(host->c_str(), "localhost") == 0;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
static bool target_matches_localhost(const char* name) {
|
|
981
|
-
std::string host;
|
|
982
|
-
std::string port;
|
|
983
|
-
return target_matches_localhost_inner(name, &host, &port);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
#ifdef GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY
|
|
987
|
-
static bool inner_maybe_resolve_localhost_manually_locked(
|
|
988
|
-
const grpc_ares_request* r, const char* name, const char* default_port,
|
|
989
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* addrs, std::string* host,
|
|
990
|
-
std::string* port) {
|
|
991
|
-
grpc_core::SplitHostPort(name, host, port);
|
|
992
|
-
if (host->empty()) {
|
|
993
|
-
LOG(ERROR) << "Failed to parse " << name
|
|
994
|
-
<< " into host:port during manual localhost resolution check.";
|
|
995
|
-
return false;
|
|
996
|
-
}
|
|
997
|
-
if (port->empty()) {
|
|
998
|
-
if (default_port == nullptr || strlen(default_port) == 0) {
|
|
999
|
-
LOG(ERROR) << "No port or default port for " << name
|
|
1000
|
-
<< " during manual localhost resolution check.";
|
|
1001
|
-
return false;
|
|
1002
|
-
}
|
|
1003
|
-
*port = default_port;
|
|
1004
|
-
}
|
|
1005
|
-
if (gpr_stricmp(host->c_str(), "localhost") == 0) {
|
|
1006
|
-
GRPC_CHECK(*addrs == nullptr);
|
|
1007
|
-
*addrs = std::make_unique<grpc_core::EndpointAddressesList>();
|
|
1008
|
-
uint16_t numeric_port = grpc_strhtons(port->c_str());
|
|
1009
|
-
grpc_resolved_address address;
|
|
1010
|
-
// Append the ipv6 loopback address.
|
|
1011
|
-
memset(&address, 0, sizeof(address));
|
|
1012
|
-
auto* ipv6_loopback_addr =
|
|
1013
|
-
reinterpret_cast<struct sockaddr_in6*>(&address.addr);
|
|
1014
|
-
((char*)&ipv6_loopback_addr->sin6_addr)[15] = 1;
|
|
1015
|
-
ipv6_loopback_addr->sin6_family = AF_INET6;
|
|
1016
|
-
ipv6_loopback_addr->sin6_port = numeric_port;
|
|
1017
|
-
address.len = sizeof(struct sockaddr_in6);
|
|
1018
|
-
(*addrs)->emplace_back(address, grpc_core::ChannelArgs());
|
|
1019
|
-
// Append the ipv4 loopback address.
|
|
1020
|
-
memset(&address, 0, sizeof(address));
|
|
1021
|
-
auto* ipv4_loopback_addr =
|
|
1022
|
-
reinterpret_cast<struct sockaddr_in*>(&address.addr);
|
|
1023
|
-
((char*)&ipv4_loopback_addr->sin_addr)[0] = 0x7f;
|
|
1024
|
-
((char*)&ipv4_loopback_addr->sin_addr)[3] = 0x01;
|
|
1025
|
-
ipv4_loopback_addr->sin_family = AF_INET;
|
|
1026
|
-
ipv4_loopback_addr->sin_port = numeric_port;
|
|
1027
|
-
address.len = sizeof(struct sockaddr_in);
|
|
1028
|
-
(*addrs)->emplace_back(address, grpc_core::ChannelArgs());
|
|
1029
|
-
// Let the address sorter figure out which one should be tried first.
|
|
1030
|
-
grpc_cares_wrapper_address_sorting_sort(r, addrs->get());
|
|
1031
|
-
return true;
|
|
1032
|
-
}
|
|
1033
|
-
return false;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
static bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
|
1037
|
-
const grpc_ares_request* r, const char* name, const char* default_port,
|
|
1038
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* addrs) {
|
|
1039
|
-
std::string host;
|
|
1040
|
-
std::string port;
|
|
1041
|
-
return inner_maybe_resolve_localhost_manually_locked(r, name, default_port,
|
|
1042
|
-
addrs, &host, &port);
|
|
1043
|
-
}
|
|
1044
|
-
#else // GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY
|
|
1045
|
-
static bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
|
1046
|
-
const grpc_ares_request* /*r*/, const char* /*name*/,
|
|
1047
|
-
const char* /*default_port*/,
|
|
1048
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* /*addrs*/) {
|
|
1049
|
-
return false;
|
|
1050
|
-
}
|
|
1051
|
-
#endif // GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY
|
|
1052
|
-
|
|
1053
|
-
static grpc_ares_request* grpc_dns_lookup_hostname_ares_impl(
|
|
1054
|
-
const char* dns_server, const char* name, const char* default_port,
|
|
1055
|
-
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
|
1056
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* addrs,
|
|
1057
|
-
int query_timeout_ms) {
|
|
1058
|
-
grpc_ares_request* r = new grpc_ares_request();
|
|
1059
|
-
grpc_core::MutexLock lock(&r->mu);
|
|
1060
|
-
r->ev_driver = nullptr;
|
|
1061
|
-
r->on_done = on_done;
|
|
1062
|
-
r->addresses_out = addrs;
|
|
1063
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
1064
|
-
<< "(c-ares resolver) request:" << r
|
|
1065
|
-
<< " c-ares grpc_dns_lookup_hostname_ares_impl name=" << name
|
|
1066
|
-
<< ", default_port=" << default_port;
|
|
1067
|
-
// Early out if the target is an ipv4 or ipv6 literal.
|
|
1068
|
-
if (resolve_as_ip_literal_locked(name, default_port, addrs)) {
|
|
1069
|
-
grpc_ares_complete_request_locked(r);
|
|
1070
|
-
return r;
|
|
1071
|
-
}
|
|
1072
|
-
// Early out if the target is localhost and we're on Windows.
|
|
1073
|
-
if (grpc_ares_maybe_resolve_localhost_manually_locked(r, name, default_port,
|
|
1074
|
-
addrs)) {
|
|
1075
|
-
grpc_ares_complete_request_locked(r);
|
|
1076
|
-
return r;
|
|
1077
|
-
}
|
|
1078
|
-
// Look up name using c-ares lib.
|
|
1079
|
-
std::string host;
|
|
1080
|
-
std::string port;
|
|
1081
|
-
grpc_error_handle error = grpc_dns_lookup_ares_continued(
|
|
1082
|
-
r, dns_server, name, default_port, interested_parties, query_timeout_ms,
|
|
1083
|
-
&host, &port, true);
|
|
1084
|
-
if (!error.ok()) {
|
|
1085
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, error);
|
|
1086
|
-
return r;
|
|
1087
|
-
}
|
|
1088
|
-
r->pending_queries = 1;
|
|
1089
|
-
grpc_ares_hostbyname_request* hr = nullptr;
|
|
1090
|
-
if (grpc_ares_query_ipv6()) {
|
|
1091
|
-
hr = create_hostbyname_request_locked(r, host.c_str(),
|
|
1092
|
-
grpc_strhtons(port.c_str()),
|
|
1093
|
-
/*is_balancer=*/false, "AAAA");
|
|
1094
|
-
ares_gethostbyname(r->ev_driver->channel, hr->host, AF_INET6,
|
|
1095
|
-
on_hostbyname_done_locked, hr);
|
|
1096
|
-
}
|
|
1097
|
-
hr = create_hostbyname_request_locked(r, host.c_str(),
|
|
1098
|
-
grpc_strhtons(port.c_str()),
|
|
1099
|
-
/*is_balancer=*/false, "A");
|
|
1100
|
-
ares_gethostbyname(r->ev_driver->channel, hr->host, AF_INET,
|
|
1101
|
-
on_hostbyname_done_locked, hr);
|
|
1102
|
-
grpc_ares_ev_driver_start_locked(r->ev_driver);
|
|
1103
|
-
grpc_ares_request_unref_locked(r);
|
|
1104
|
-
return r;
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
grpc_ares_request* grpc_dns_lookup_srv_ares_impl(
|
|
1108
|
-
const char* dns_server, const char* name,
|
|
1109
|
-
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
|
1110
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* balancer_addresses,
|
|
1111
|
-
int query_timeout_ms) {
|
|
1112
|
-
grpc_ares_request* r = new grpc_ares_request();
|
|
1113
|
-
grpc_core::MutexLock lock(&r->mu);
|
|
1114
|
-
r->ev_driver = nullptr;
|
|
1115
|
-
r->on_done = on_done;
|
|
1116
|
-
r->balancer_addresses_out = balancer_addresses;
|
|
1117
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
1118
|
-
<< "(c-ares resolver) request:" << r
|
|
1119
|
-
<< " c-ares grpc_dns_lookup_srv_ares_impl name=" << name;
|
|
1120
|
-
grpc_error_handle error;
|
|
1121
|
-
// Don't query for SRV records if the target is "localhost"
|
|
1122
|
-
if (target_matches_localhost(name)) {
|
|
1123
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, error);
|
|
1124
|
-
return r;
|
|
1125
|
-
}
|
|
1126
|
-
// Look up name using c-ares lib.
|
|
1127
|
-
std::string host;
|
|
1128
|
-
std::string port;
|
|
1129
|
-
error = grpc_dns_lookup_ares_continued(r, dns_server, name, nullptr,
|
|
1130
|
-
interested_parties, query_timeout_ms,
|
|
1131
|
-
&host, &port, false);
|
|
1132
|
-
if (!error.ok()) {
|
|
1133
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, error);
|
|
1134
|
-
return r;
|
|
1135
|
-
}
|
|
1136
|
-
r->pending_queries = 1;
|
|
1137
|
-
// Query the SRV record
|
|
1138
|
-
std::string service_name = absl::StrCat("_grpclb._tcp.", host);
|
|
1139
|
-
GrpcAresQuery* srv_query = new GrpcAresQuery(r, service_name);
|
|
1140
|
-
ares_query(r->ev_driver->channel, service_name.c_str(), ns_c_in, ns_t_srv,
|
|
1141
|
-
on_srv_query_done_locked, srv_query);
|
|
1142
|
-
grpc_ares_ev_driver_start_locked(r->ev_driver);
|
|
1143
|
-
grpc_ares_request_unref_locked(r);
|
|
1144
|
-
return r;
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
grpc_ares_request* grpc_dns_lookup_txt_ares_impl(
|
|
1148
|
-
const char* dns_server, const char* name,
|
|
1149
|
-
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
|
1150
|
-
char** service_config_json, int query_timeout_ms) {
|
|
1151
|
-
grpc_ares_request* r = new grpc_ares_request();
|
|
1152
|
-
grpc_core::MutexLock lock(&r->mu);
|
|
1153
|
-
r->ev_driver = nullptr;
|
|
1154
|
-
r->on_done = on_done;
|
|
1155
|
-
r->service_config_json_out = service_config_json;
|
|
1156
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
1157
|
-
<< "(c-ares resolver) request:" << r
|
|
1158
|
-
<< " c-ares grpc_dns_lookup_txt_ares_impl name=" << name;
|
|
1159
|
-
grpc_error_handle error;
|
|
1160
|
-
// Don't query for TXT records if the target is "localhost"
|
|
1161
|
-
if (target_matches_localhost(name)) {
|
|
1162
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, error);
|
|
1163
|
-
return r;
|
|
1164
|
-
}
|
|
1165
|
-
// Look up name using c-ares lib.
|
|
1166
|
-
std::string host;
|
|
1167
|
-
std::string port;
|
|
1168
|
-
error = grpc_dns_lookup_ares_continued(r, dns_server, name, nullptr,
|
|
1169
|
-
interested_parties, query_timeout_ms,
|
|
1170
|
-
&host, &port, false);
|
|
1171
|
-
if (!error.ok()) {
|
|
1172
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, error);
|
|
1173
|
-
return r;
|
|
1174
|
-
}
|
|
1175
|
-
r->pending_queries = 1;
|
|
1176
|
-
// Query the TXT record
|
|
1177
|
-
std::string config_name = absl::StrCat("_grpc_config.", host);
|
|
1178
|
-
GrpcAresQuery* txt_query = new GrpcAresQuery(r, config_name);
|
|
1179
|
-
ares_search(r->ev_driver->channel, config_name.c_str(), ns_c_in, ns_t_txt,
|
|
1180
|
-
on_txt_done_locked, txt_query);
|
|
1181
|
-
grpc_ares_ev_driver_start_locked(r->ev_driver);
|
|
1182
|
-
grpc_ares_request_unref_locked(r);
|
|
1183
|
-
return r;
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
grpc_ares_request* (*grpc_dns_lookup_hostname_ares)(
|
|
1187
|
-
const char* dns_server, const char* name, const char* default_port,
|
|
1188
|
-
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
|
1189
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* addrs,
|
|
1190
|
-
int query_timeout_ms) = grpc_dns_lookup_hostname_ares_impl;
|
|
1191
|
-
|
|
1192
|
-
grpc_ares_request* (*grpc_dns_lookup_srv_ares)(
|
|
1193
|
-
const char* dns_server, const char* name,
|
|
1194
|
-
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
|
1195
|
-
std::unique_ptr<grpc_core::EndpointAddressesList>* balancer_addresses,
|
|
1196
|
-
int query_timeout_ms) = grpc_dns_lookup_srv_ares_impl;
|
|
1197
|
-
|
|
1198
|
-
grpc_ares_request* (*grpc_dns_lookup_txt_ares)(
|
|
1199
|
-
const char* dns_server, const char* name,
|
|
1200
|
-
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
|
1201
|
-
char** service_config_json,
|
|
1202
|
-
int query_timeout_ms) = grpc_dns_lookup_txt_ares_impl;
|
|
1203
|
-
|
|
1204
|
-
static void grpc_cancel_ares_request_impl(grpc_ares_request* r) {
|
|
1205
|
-
GRPC_CHECK_NE(r, nullptr);
|
|
1206
|
-
grpc_core::MutexLock lock(&r->mu);
|
|
1207
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
1208
|
-
<< "(c-ares resolver) request:" << r
|
|
1209
|
-
<< " grpc_cancel_ares_request ev_driver:" << r->ev_driver;
|
|
1210
|
-
if (r->ev_driver != nullptr) {
|
|
1211
|
-
grpc_ares_ev_driver_shutdown_locked(r->ev_driver);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
void (*grpc_cancel_ares_request)(grpc_ares_request* r) =
|
|
1216
|
-
grpc_cancel_ares_request_impl;
|
|
1217
|
-
|
|
1218
|
-
// ares_library_init and ares_library_cleanup are currently no-op except under
|
|
1219
|
-
// Windows. Calling them may cause race conditions when other parts of the
|
|
1220
|
-
// binary calls these functions concurrently.
|
|
1221
|
-
#ifdef GPR_WINDOWS
|
|
1222
|
-
grpc_error_handle grpc_ares_init(void) {
|
|
1223
|
-
int status = ares_library_init(ARES_LIB_INIT_ALL);
|
|
1224
|
-
if (status != ARES_SUCCESS) {
|
|
1225
|
-
return GRPC_ERROR_CREATE(
|
|
1226
|
-
absl::StrCat("ares_library_init failed: ", ares_strerror(status)));
|
|
1227
|
-
}
|
|
1228
|
-
return absl::OkStatus();
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
void grpc_ares_cleanup(void) { ares_library_cleanup(); }
|
|
1232
|
-
#else
|
|
1233
|
-
grpc_error_handle grpc_ares_init(void) { return absl::OkStatus(); }
|
|
1234
|
-
void grpc_ares_cleanup(void) {}
|
|
1235
|
-
#endif // GPR_WINDOWS
|
|
1236
|
-
|
|
1237
|
-
#endif // GRPC_ARES == 1
|