grpc 1.73.0 → 1.75.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 +116 -53
- data/include/grpc/create_channel_from_endpoint.h +54 -0
- data/include/grpc/credentials.h +18 -6
- data/include/grpc/event_engine/event_engine.h +74 -17
- data/include/grpc/grpc_posix.h +20 -1
- data/include/grpc/impl/channel_arg_names.h +2 -4
- data/include/grpc/module.modulemap +1 -0
- data/include/grpc/support/json.h +24 -0
- data/src/core/call/client_call.cc +4 -4
- data/src/core/call/filter_fusion.h +1230 -0
- data/src/core/call/interception_chain.h +7 -11
- data/src/core/call/metadata.cc +22 -0
- data/src/core/call/metadata.h +24 -2
- data/src/core/channelz/channel_trace.cc +213 -115
- data/src/core/channelz/channel_trace.h +380 -86
- data/src/core/channelz/channelz.cc +274 -192
- data/src/core/channelz/channelz.h +224 -72
- data/src/core/channelz/channelz_registry.cc +2 -163
- data/src/core/channelz/channelz_registry.h +37 -6
- data/src/core/channelz/property_list.cc +353 -0
- data/src/core/channelz/property_list.h +204 -0
- 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/channelz/ztrace_collector.h +3 -2
- data/src/core/client_channel/backup_poller.cc +17 -2
- data/src/core/client_channel/client_channel.cc +17 -28
- data/src/core/client_channel/client_channel_filter.cc +24 -33
- 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/config_selector.h +8 -2
- data/src/core/client_channel/dynamic_filters.cc +5 -6
- data/src/core/client_channel/dynamic_filters.h +1 -1
- data/src/core/client_channel/global_subchannel_pool.cc +4 -1
- data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
- data/src/core/client_channel/retry_filter.cc +21 -27
- data/src/core/client_channel/retry_filter.h +10 -7
- data/src/core/client_channel/retry_filter_legacy_call_data.cc +5 -5
- data/src/core/client_channel/retry_filter_legacy_call_data.h +1 -1
- data/src/core/client_channel/retry_interceptor.cc +30 -44
- data/src/core/client_channel/retry_interceptor.h +18 -17
- data/src/core/client_channel/retry_throttle.cc +46 -61
- data/src/core/client_channel/retry_throttle.h +17 -39
- data/src/core/client_channel/subchannel.cc +57 -25
- data/src/core/client_channel/subchannel.h +10 -0
- data/src/core/config/config_vars.cc +2 -0
- data/src/core/config/core_configuration.cc +4 -1
- data/src/core/config/core_configuration.h +23 -0
- data/src/core/credentials/call/call_creds_registry.h +125 -0
- data/src/core/credentials/call/call_creds_registry_init.cc +91 -0
- data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.cc +6 -48
- data/src/core/credentials/call/jwt_token_file/jwt_token_file_call_credentials.cc +86 -0
- data/src/core/credentials/call/jwt_token_file/jwt_token_file_call_credentials.h +74 -0
- data/src/core/credentials/call/jwt_util.cc +70 -0
- data/src/core/credentials/call/jwt_util.h +32 -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 +4 -2
- data/src/core/credentials/transport/google_default/google_default_credentials.cc +72 -4
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -2
- 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/load_system_roots_supported.cc +1 -0
- 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/credentials/transport/xds/xds_credentials.cc +0 -3
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
- data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.cc +8 -8
- data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.h +16 -16
- data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
- data/src/core/ext/filters/http/client_authority_filter.cc +3 -6
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
- data/src/core/ext/filters/http/message_compress/compression_filter.h +25 -22
- data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
- data/src/core/ext/filters/http/server/http_server_filter.h +12 -11
- 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/client/chttp2_connector.cc +120 -35
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +6 -5
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +165 -117
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +0 -3
- data/src/core/ext/transport/chttp2/transport/decode_huff.cc +1239 -3514
- data/src/core/ext/transport/chttp2/transport/decode_huff.h +1008 -1486
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +23 -17
- data/src/core/ext/transport/chttp2/transport/frame.cc +99 -6
- data/src/core/ext/transport/chttp2/transport/frame.h +40 -2
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +7 -8
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +4 -5
- data/src/core/ext/transport/chttp2/transport/header_assembler.h +290 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +11 -5
- data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +12 -1
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +1233 -0
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +712 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +65 -51
- 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/{third_party/abseil-cpp/absl/strings/cord_buffer.cc → src/core/ext/transport/chttp2/transport/http2_stats_collector.cc} +14 -14
- data/src/core/ext/transport/chttp2/transport/http2_stats_collector.h +33 -0
- data/src/core/ext/transport/chttp2/transport/http2_status.h +6 -1
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +121 -0
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +76 -0
- data/src/core/ext/transport/chttp2/transport/http2_ztrace_collector.h +0 -29
- data/src/core/ext/transport/chttp2/transport/internal.h +18 -8
- data/src/core/ext/transport/chttp2/transport/keepalive.cc +105 -0
- data/src/core/ext/transport/chttp2/transport/keepalive.h +138 -0
- data/src/core/ext/transport/chttp2/transport/message_assembler.h +185 -0
- data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -5
- data/src/core/ext/transport/chttp2/transport/ping_callbacks.h +19 -0
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +152 -0
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +197 -0
- data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +5 -9
- data/src/core/ext/transport/chttp2/transport/ping_rate_policy.h +11 -0
- data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +39 -1
- data/src/core/ext/transport/chttp2/transport/transport_common.cc +19 -0
- data/src/core/ext/transport/chttp2/transport/transport_common.h +27 -0
- data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +41 -13
- 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/channelz.upb.h +571 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/channelz.upb_minitable.c +120 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/channelz.upb_minitable.h +36 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb.h +1272 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb_minitable.c +312 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb_minitable.h +50 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +1072 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +230 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +44 -0
- 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/promise.upbdefs.c +175 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/promise.upbdefs.h +82 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +133 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +67 -0
- data/src/core/filter/auth/auth_filters.h +2 -27
- data/src/core/filter/auth/client_auth_filter.cc +0 -118
- data/src/core/filter/filter_args.h +9 -23
- data/src/core/filter/fused_filters.cc +154 -0
- data/src/core/handshaker/handshaker.cc +23 -14
- data/src/core/handshaker/handshaker.h +3 -0
- data/src/core/handshaker/http_connect/http_connect_handshaker.cc +3 -1
- data/src/core/handshaker/security/legacy_secure_endpoint.cc +7 -6
- data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
- data/src/core/handshaker/security/secure_endpoint.cc +98 -38
- data/src/core/handshaker/security/secure_endpoint.h +8 -0
- data/src/core/handshaker/security/security_handshaker.cc +4 -1
- data/src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc +7 -1
- data/src/core/lib/channel/channel_args.cc +15 -0
- data/src/core/lib/channel/channel_args.h +3 -0
- data/src/core/lib/channel/channel_stack.cc +22 -23
- data/src/core/lib/channel/channel_stack.h +9 -7
- data/src/core/lib/channel/channel_stack_builder_impl.cc +1 -1
- data/src/core/lib/channel/channel_stack_builder_impl.h +2 -7
- data/src/core/lib/channel/promise_based_filter.cc +15 -25
- data/src/core/lib/channel/promise_based_filter.h +11 -10
- data/src/core/lib/debug/trace_impl.h +0 -1
- data/src/core/lib/event_engine/ares_resolver.cc +165 -46
- data/src/core/lib/event_engine/ares_resolver.h +51 -3
- data/src/core/lib/event_engine/cf_engine/cf_engine.cc +12 -6
- data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -4
- 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 +14 -6
- data/src/core/lib/event_engine/endpoint_channel_arg_wrapper.cc +40 -0
- data/src/core/lib/event_engine/endpoint_channel_arg_wrapper.h +60 -0
- data/src/core/lib/event_engine/event_engine.cc +7 -0
- data/src/core/lib/event_engine/extensions/channelz.h +10 -6
- data/src/core/lib/event_engine/grpc_polled_fd.h +5 -0
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +139 -169
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +17 -19
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +90 -131
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +13 -13
- data/src/core/lib/event_engine/posix_engine/event_poller.h +18 -23
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -23
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
- data/src/core/lib/event_engine/posix_engine/file_descriptor_collection.cc +124 -0
- data/src/core/lib/event_engine/posix_engine/file_descriptor_collection.h +243 -0
- data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +30 -19
- data/src/core/lib/event_engine/posix_engine/internal_errqueue.cc +6 -2
- data/src/core/lib/event_engine/posix_engine/internal_errqueue.h +6 -1
- 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 +147 -94
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +9 -19
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +435 -229
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +78 -50
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +46 -38
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.h +6 -4
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +32 -142
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.h +6 -5
- data/src/core/lib/event_engine/posix_engine/posix_interface.h +211 -0
- data/src/core/lib/event_engine/posix_engine/posix_interface_posix.cc +1083 -0
- data/src/core/lib/event_engine/posix_engine/posix_interface_windows.cc +281 -0
- data/src/core/lib/event_engine/posix_engine/posix_write_event_sink.cc +154 -0
- data/src/core/lib/event_engine/posix_engine/posix_write_event_sink.h +174 -0
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +3 -719
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +11 -171
- data/src/core/lib/event_engine/posix_engine/timer_manager.cc +33 -22
- data/src/core/lib/event_engine/posix_engine/timer_manager.h +13 -11
- data/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +117 -151
- data/src/core/lib/event_engine/posix_engine/traced_buffer_list.h +26 -94
- data/src/core/lib/event_engine/posix_engine/wakeup_fd_eventfd.cc +26 -25
- data/src/core/lib/event_engine/posix_engine/wakeup_fd_eventfd.h +6 -2
- data/src/core/lib/event_engine/posix_engine/wakeup_fd_pipe.cc +36 -62
- data/src/core/lib/event_engine/posix_engine/wakeup_fd_pipe.h +6 -2
- data/src/core/lib/event_engine/posix_engine/wakeup_fd_posix.h +7 -6
- data/src/core/lib/event_engine/posix_engine/wakeup_fd_posix_default.cc +12 -6
- data/src/core/lib/event_engine/posix_engine/wakeup_fd_posix_default.h +3 -1
- data/src/core/lib/event_engine/shim.cc +9 -0
- data/src/core/lib/event_engine/shim.h +3 -0
- data/src/core/lib/event_engine/thread_pool/thread_pool.h +7 -3
- data/src/core/lib/event_engine/thread_pool/thread_pool_factory.cc +0 -17
- data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +4 -2
- data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.h +3 -2
- data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +6 -1
- data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.h +4 -0
- data/src/core/lib/event_engine/windows/windows_endpoint.h +2 -6
- data/src/core/lib/event_engine/windows/windows_engine.cc +0 -1
- data/src/core/lib/event_engine/windows/windows_engine.h +1 -3
- data/src/core/lib/event_engine/windows/windows_listener.cc +14 -2
- data/src/core/lib/experiments/experiments.cc +165 -99
- data/src/core/lib/experiments/experiments.h +65 -52
- data/src/core/lib/iomgr/combiner.cc +1 -1
- data/src/core/lib/iomgr/endpoint.cc +4 -3
- data/src/core/lib/iomgr/endpoint.h +7 -4
- data/src/core/lib/iomgr/endpoint_cfstream.cc +3 -2
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +7 -2
- data/src/core/lib/iomgr/ev_poll_posix.cc +7 -2
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +4 -6
- 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 +15 -9
- data/src/core/lib/iomgr/tcp_windows.cc +3 -2
- data/src/core/lib/promise/activity.h +3 -2
- data/src/core/lib/promise/arena_promise.h +23 -7
- data/src/core/lib/promise/detail/promise_factory.h +10 -0
- data/src/core/lib/promise/detail/promise_like.h +118 -11
- data/src/core/lib/promise/detail/promise_variant.h +50 -0
- data/src/core/lib/promise/detail/seq_state.h +687 -548
- data/src/core/lib/promise/if.h +20 -0
- data/src/core/lib/promise/inter_activity_latch.h +147 -0
- data/src/core/lib/promise/inter_activity_mutex.h +547 -0
- data/src/core/lib/promise/loop.h +65 -3
- data/src/core/lib/promise/map.h +24 -0
- data/src/core/lib/promise/match_promise.h +103 -0
- data/src/core/lib/promise/mpsc.cc +425 -0
- data/src/core/lib/promise/mpsc.h +490 -0
- data/src/core/lib/promise/party.cc +55 -6
- data/src/core/lib/promise/party.h +68 -3
- data/src/core/lib/promise/poll.h +10 -0
- data/src/core/lib/promise/race.h +31 -0
- data/src/core/lib/promise/seq.h +4 -1
- data/src/core/lib/promise/status_flag.h +7 -0
- data/src/core/lib/promise/try_seq.h +4 -1
- data/src/core/lib/promise/wait_set.cc +28 -0
- data/src/core/lib/promise/wait_set.h +86 -0
- data/src/core/lib/resource_quota/arena.h +19 -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/slice/slice.h +5 -0
- data/src/core/lib/surface/call.cc +5 -5
- data/src/core/lib/surface/call.h +6 -5
- data/src/core/lib/surface/channel_create.cc +88 -13
- data/src/core/lib/surface/channel_create.h +4 -0
- data/src/core/lib/surface/channel_init.cc +164 -47
- data/src/core/lib/surface/channel_init.h +64 -1
- data/src/core/lib/surface/completion_queue.cc +2 -4
- data/src/core/lib/surface/filter_stack_call.cc +19 -10
- data/src/core/lib/surface/init.cc +6 -15
- data/src/core/lib/surface/legacy_channel.cc +3 -5
- data/src/core/lib/surface/legacy_channel.h +3 -1
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.cc +110 -0
- data/src/core/lib/transport/promise_endpoint.h +307 -0
- data/src/core/load_balancing/child_policy_handler.cc +2 -4
- data/src/core/load_balancing/delegating_helper.h +2 -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/health_check_client.cc +1 -5
- data/src/core/load_balancing/lb_policy.h +1 -3
- data/src/core/load_balancing/oob_backend_metric.cc +1 -5
- data/src/core/load_balancing/pick_first/pick_first.cc +15 -5
- data/src/core/load_balancing/xds/cds.cc +10 -1
- 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/plugin_registry/grpc_plugin_registry_extra.cc +2 -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_config.cc +6 -3
- data/src/core/resolver/xds/xds_config.h +9 -4
- data/src/core/resolver/xds/xds_dependency_manager.cc +22 -7
- data/src/core/resolver/xds/xds_dependency_manager.h +2 -1
- data/src/core/resolver/xds/xds_resolver.cc +31 -11
- data/src/core/server/server.cc +84 -13
- data/src/core/server/server.h +21 -2
- 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/server/xds_server_config_fetcher.cc +63 -25
- data/src/core/service_config/service_config.h +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/service_config/service_config_impl.h +1 -1
- data/src/core/telemetry/call_tracer.cc +20 -14
- data/src/core/telemetry/call_tracer.h +22 -17
- data/src/core/telemetry/context_list_entry.cc +38 -0
- data/src/core/telemetry/context_list_entry.h +42 -12
- data/src/core/telemetry/metrics.h +8 -8
- data/src/core/telemetry/stats_data.cc +369 -343
- data/src/core/telemetry/stats_data.h +341 -244
- data/src/core/telemetry/tcp_tracer.h +1 -1
- 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/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +11 -3
- data/src/core/tsi/fake_transport_security.cc +17 -0
- data/src/core/tsi/ssl_transport_security.cc +205 -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/tsi/transport_security_grpc.cc +8 -0
- data/src/core/tsi/transport_security_grpc.h +15 -0
- data/src/core/util/backoff.cc +1 -5
- data/src/core/util/backoff.h +1 -0
- data/src/core/util/down_cast.h +1 -1
- data/src/core/util/function_signature.h +15 -1
- data/src/core/util/http_client/httpcli.cc +12 -5
- data/src/core/util/http_client/httpcli.h +4 -1
- 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 +249 -189
- data/src/core/util/log.cc +4 -0
- data/src/core/util/memory_usage.h +268 -0
- data/src/core/util/per_cpu.cc +2 -0
- data/src/core/util/per_cpu.h +7 -0
- data/src/core/util/shared_bit_gen.h +20 -0
- data/src/core/util/single_set_ptr.h +7 -4
- data/src/core/util/upb_utils.h +42 -0
- data/src/core/util/uri.cc +3 -2
- data/src/core/util/useful.h +144 -2
- data/src/core/util/wait_for_single_owner.cc +31 -0
- data/src/core/util/wait_for_single_owner.h +24 -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_bootstrap_grpc.cc +2 -0
- data/src/core/xds/grpc/xds_bootstrap_grpc.h +5 -0
- data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
- data/src/core/xds/grpc/xds_client_grpc.cc +6 -2
- data/src/core/xds/grpc/xds_common_types_parser.cc +138 -50
- data/src/core/xds/grpc/xds_common_types_parser.h +12 -0
- data/src/core/xds/grpc/xds_http_filter.h +7 -0
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.cc +22 -0
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.h +3 -0
- data/src/core/xds/grpc/xds_route_config_parser.cc +15 -38
- data/src/core/xds/grpc/xds_server_grpc.cc +63 -13
- data/src/core/xds/grpc/xds_server_grpc.h +10 -2
- data/src/core/xds/grpc/xds_server_grpc_interface.h +4 -0
- data/src/core/xds/grpc/xds_transport_grpc.cc +18 -0
- data/src/core/xds/xds_client/xds_bootstrap.h +2 -0
- data/src/core/xds/xds_client/xds_client.cc +26 -5
- data/src/ruby/ext/grpc/extconf.rb +2 -0
- data/src/ruby/ext/grpc/rb_call.c +1 -8
- data/src/ruby/ext/grpc/rb_channel.c +70 -557
- data/src/ruby/ext/grpc/rb_channel.h +0 -3
- data/src/ruby/ext/grpc/rb_completion_queue.c +26 -14
- data/src/ruby/ext/grpc/rb_completion_queue.h +1 -7
- data/src/ruby/ext/grpc/rb_grpc.c +9 -5
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +2 -2
- data/src/ruby/ext/grpc/rb_loader.c +0 -4
- data/src/ruby/ext/grpc/rb_server.c +31 -50
- data/src/ruby/lib/grpc/generic/client_stub.rb +4 -4
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/core_spec.rb +22 -0
- data/src/ruby/spec/generic/active_call_spec.rb +1 -1
- data/third_party/abseil-cpp/absl/algorithm/container.h +2 -19
- data/third_party/abseil-cpp/absl/base/attributes.h +76 -7
- data/third_party/abseil-cpp/absl/base/call_once.h +11 -12
- data/third_party/abseil-cpp/absl/base/config.h +20 -129
- data/third_party/abseil-cpp/absl/base/{internal/fast_type_id.h → fast_type_id.h} +11 -16
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +0 -5
- data/third_party/abseil-cpp/absl/base/internal/cycleclock_config.h +7 -7
- data/third_party/abseil-cpp/absl/base/internal/endian.h +34 -38
- data/third_party/abseil-cpp/absl/base/internal/iterator_traits.h +71 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +6 -5
- data/third_party/abseil-cpp/absl/base/internal/{nullability_impl.h → nullability_deprecated.h} +45 -8
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +0 -9
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +3 -13
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +6 -6
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +8 -3
- data/third_party/abseil-cpp/absl/base/no_destructor.h +11 -32
- data/third_party/abseil-cpp/absl/base/nullability.h +84 -72
- data/third_party/abseil-cpp/absl/base/options.h +3 -80
- data/third_party/abseil-cpp/absl/base/policy_checks.h +7 -7
- data/third_party/abseil-cpp/absl/cleanup/cleanup.h +1 -3
- data/third_party/abseil-cpp/absl/cleanup/internal/cleanup.h +3 -4
- data/third_party/abseil-cpp/absl/container/btree_map.h +4 -2
- data/third_party/abseil-cpp/absl/container/btree_set.h +4 -2
- data/third_party/abseil-cpp/absl/container/fixed_array.h +7 -14
- data/third_party/abseil-cpp/absl/container/flat_hash_map.h +5 -0
- data/third_party/abseil-cpp/absl/container/flat_hash_set.h +6 -1
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +8 -5
- data/third_party/abseil-cpp/absl/container/internal/btree.h +132 -29
- data/third_party/abseil-cpp/absl/container/internal/btree_container.h +175 -71
- data/third_party/abseil-cpp/absl/container/internal/common.h +43 -0
- data/third_party/abseil-cpp/absl/container/internal/common_policy_traits.h +1 -2
- data/third_party/abseil-cpp/absl/container/internal/container_memory.h +9 -10
- data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +1 -8
- data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +0 -4
- data/third_party/abseil-cpp/absl/container/internal/hashtable_control_bytes.h +527 -0
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +20 -4
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +31 -12
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +2 -7
- data/third_party/abseil-cpp/absl/container/internal/layout.h +26 -42
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +199 -68
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +1354 -183
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +881 -1424
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set_resize_impl.h +80 -0
- data/third_party/abseil-cpp/absl/crc/crc32c.cc +0 -4
- data/third_party/abseil-cpp/absl/crc/crc32c.h +7 -5
- data/third_party/abseil-cpp/absl/crc/internal/crc32_x86_arm_combined_simd.h +0 -22
- data/third_party/abseil-cpp/absl/crc/internal/crc_x86_arm_combined.cc +45 -74
- data/third_party/abseil-cpp/absl/debugging/internal/addresses.h +57 -0
- data/third_party/abseil-cpp/absl/debugging/internal/decode_rust_punycode.cc +1 -1
- data/third_party/abseil-cpp/absl/debugging/internal/decode_rust_punycode.h +5 -5
- data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +8 -35
- data/third_party/abseil-cpp/absl/debugging/internal/demangle_rust.cc +16 -16
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +40 -37
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +16 -7
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_emscripten-inl.inc +14 -5
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +10 -4
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +27 -16
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_riscv-inl.inc +13 -4
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +4 -3
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +15 -28
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +19 -9
- data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +144 -27
- data/third_party/abseil-cpp/absl/debugging/stacktrace.h +73 -5
- data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +19 -9
- data/third_party/abseil-cpp/absl/debugging/symbolize_emscripten.inc +3 -2
- data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +25 -6
- data/third_party/abseil-cpp/absl/flags/commandlineflag.h +2 -2
- data/third_party/abseil-cpp/absl/flags/flag.h +4 -3
- data/third_party/abseil-cpp/absl/flags/internal/commandlineflag.h +2 -2
- data/third_party/abseil-cpp/absl/flags/internal/flag.cc +2 -1
- data/third_party/abseil-cpp/absl/flags/internal/flag.h +7 -6
- data/third_party/abseil-cpp/absl/flags/internal/registry.h +4 -3
- data/third_party/abseil-cpp/absl/flags/reflection.cc +2 -3
- data/third_party/abseil-cpp/absl/functional/any_invocable.h +8 -10
- data/third_party/abseil-cpp/absl/functional/function_ref.h +2 -9
- data/third_party/abseil-cpp/absl/functional/internal/any_invocable.h +110 -226
- data/third_party/abseil-cpp/absl/functional/internal/front_binder.h +10 -12
- data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +2 -5
- data/third_party/abseil-cpp/absl/hash/hash.h +18 -0
- data/third_party/abseil-cpp/absl/hash/internal/hash.cc +1 -5
- data/third_party/abseil-cpp/absl/hash/internal/hash.h +86 -61
- data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.cc +25 -68
- data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.h +2 -6
- data/third_party/abseil-cpp/absl/hash/internal/weakly_mixed_integer.h +38 -0
- data/third_party/abseil-cpp/absl/log/check.h +2 -1
- data/third_party/abseil-cpp/absl/log/globals.h +4 -5
- data/third_party/abseil-cpp/absl/log/internal/append_truncated.h +28 -0
- data/third_party/abseil-cpp/absl/log/internal/check_op.cc +22 -22
- data/third_party/abseil-cpp/absl/log/internal/check_op.h +65 -62
- data/third_party/abseil-cpp/absl/log/internal/conditions.cc +5 -3
- data/third_party/abseil-cpp/absl/log/internal/conditions.h +7 -2
- data/third_party/abseil-cpp/absl/log/internal/log_message.cc +85 -43
- data/third_party/abseil-cpp/absl/log/internal/log_message.h +84 -59
- data/third_party/abseil-cpp/absl/log/internal/nullstream.h +1 -0
- data/third_party/abseil-cpp/absl/log/internal/proto.cc +3 -2
- data/third_party/abseil-cpp/absl/log/internal/proto.h +3 -3
- data/third_party/abseil-cpp/absl/log/internal/strip.h +4 -12
- data/third_party/abseil-cpp/absl/log/internal/vlog_config.h +8 -6
- data/third_party/abseil-cpp/absl/log/internal/voidify.h +10 -4
- data/third_party/abseil-cpp/absl/log/log.h +48 -35
- data/third_party/abseil-cpp/absl/log/log_sink_registry.h +2 -2
- data/third_party/abseil-cpp/absl/meta/type_traits.h +46 -175
- data/third_party/abseil-cpp/absl/numeric/bits.h +68 -2
- data/third_party/abseil-cpp/absl/numeric/int128.cc +0 -52
- data/third_party/abseil-cpp/absl/numeric/internal/bits.h +7 -3
- data/third_party/abseil-cpp/absl/profiling/internal/exponential_biased.cc +1 -1
- data/third_party/abseil-cpp/absl/random/bit_gen_ref.h +10 -11
- data/third_party/abseil-cpp/absl/random/distributions.h +6 -8
- data/third_party/abseil-cpp/absl/random/gaussian_distribution.h +1 -1
- data/third_party/abseil-cpp/absl/random/internal/distribution_caller.h +5 -6
- data/third_party/abseil-cpp/absl/random/internal/{pool_urbg.cc → entropy_pool.cc} +22 -90
- data/third_party/abseil-cpp/absl/random/internal/entropy_pool.h +35 -0
- data/third_party/abseil-cpp/absl/random/internal/nonsecure_base.h +5 -6
- data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +1 -1
- data/third_party/abseil-cpp/absl/random/internal/seed_material.cc +20 -12
- data/third_party/abseil-cpp/absl/random/internal/seed_material.h +5 -5
- data/third_party/abseil-cpp/absl/random/random.h +88 -53
- data/third_party/abseil-cpp/absl/random/seed_sequences.cc +6 -2
- data/third_party/abseil-cpp/absl/status/internal/status_internal.cc +3 -4
- data/third_party/abseil-cpp/absl/status/internal/status_internal.h +3 -4
- data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +4 -3
- data/third_party/abseil-cpp/absl/status/status.cc +4 -8
- data/third_party/abseil-cpp/absl/status/status.h +8 -8
- data/third_party/abseil-cpp/absl/status/status_payload_printer.h +2 -2
- data/third_party/abseil-cpp/absl/status/statusor.cc +2 -2
- data/third_party/abseil-cpp/absl/status/statusor.h +6 -6
- data/third_party/abseil-cpp/absl/strings/ascii.cc +9 -9
- data/third_party/abseil-cpp/absl/strings/ascii.h +18 -18
- data/third_party/abseil-cpp/absl/strings/charconv.cc +21 -22
- data/third_party/abseil-cpp/absl/strings/charconv.h +5 -5
- data/third_party/abseil-cpp/absl/strings/cord.cc +54 -58
- data/third_party/abseil-cpp/absl/strings/cord.h +94 -83
- data/third_party/abseil-cpp/absl/strings/cord_analysis.cc +11 -11
- data/third_party/abseil-cpp/absl/strings/cord_analysis.h +3 -3
- data/third_party/abseil-cpp/absl/strings/escaping.cc +130 -149
- data/third_party/abseil-cpp/absl/strings/escaping.h +9 -10
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +6 -8
- data/third_party/abseil-cpp/absl/strings/internal/cord_rep_btree.cc +0 -4
- data/third_party/abseil-cpp/absl/strings/internal/cordz_info.cc +0 -4
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +7 -63
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +1 -11
- data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.cc +0 -22
- data/third_party/abseil-cpp/absl/strings/internal/str_format/output.cc +5 -3
- data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +4 -2
- data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +3 -3
- data/third_party/abseil-cpp/absl/strings/internal/string_constant.h +0 -5
- data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +96 -1
- data/third_party/abseil-cpp/absl/strings/internal/utf8.h +15 -1
- data/third_party/abseil-cpp/absl/strings/numbers.cc +53 -32
- data/third_party/abseil-cpp/absl/strings/numbers.h +87 -58
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +6 -7
- data/third_party/abseil-cpp/absl/strings/str_cat.h +32 -32
- data/third_party/abseil-cpp/absl/strings/str_format.h +18 -18
- data/third_party/abseil-cpp/absl/strings/str_replace.cc +3 -3
- data/third_party/abseil-cpp/absl/strings/str_replace.h +6 -6
- data/third_party/abseil-cpp/absl/strings/string_view.cc +4 -9
- data/third_party/abseil-cpp/absl/strings/string_view.h +27 -32
- data/third_party/abseil-cpp/absl/strings/strip.h +4 -4
- data/third_party/abseil-cpp/absl/strings/substitute.cc +5 -4
- data/third_party/abseil-cpp/absl/strings/substitute.h +66 -64
- data/third_party/abseil-cpp/absl/synchronization/internal/futex_waiter.cc +0 -4
- data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.cc +0 -5
- data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.cc +0 -4
- data/third_party/abseil-cpp/absl/synchronization/internal/sem_waiter.cc +0 -4
- data/third_party/abseil-cpp/absl/synchronization/internal/stdcpp_waiter.cc +0 -4
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter_base.cc +0 -4
- data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.cc +0 -4
- data/third_party/abseil-cpp/absl/synchronization/mutex.cc +1 -1
- data/third_party/abseil-cpp/absl/synchronization/mutex.h +97 -69
- data/third_party/abseil-cpp/absl/synchronization/notification.h +1 -1
- data/third_party/abseil-cpp/absl/time/civil_time.cc +1 -0
- data/third_party/abseil-cpp/absl/time/duration.cc +12 -7
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +1 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +90 -111
- data/third_party/abseil-cpp/absl/time/time.h +20 -15
- data/third_party/abseil-cpp/absl/types/optional.h +7 -747
- data/third_party/abseil-cpp/absl/types/span.h +13 -11
- data/third_party/abseil-cpp/absl/types/variant.h +5 -784
- data/third_party/abseil-cpp/absl/utility/utility.h +10 -185
- 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 +192 -68
- data/src/core/lib/event_engine/forkable.cc +0 -105
- data/src/core/lib/event_engine/forkable.h +0 -67
- data/src/core/lib/iomgr/python_util.h +0 -46
- data/src/core/util/ring_buffer.h +0 -122
- data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +0 -108
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +0 -241
- data/third_party/abseil-cpp/absl/log/log_entry.cc +0 -41
- data/third_party/abseil-cpp/absl/random/internal/pool_urbg.h +0 -131
- data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +0 -66
- data/third_party/abseil-cpp/absl/types/bad_optional_access.h +0 -78
- data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +0 -82
- data/third_party/abseil-cpp/absl/types/bad_variant_access.h +0 -82
- data/third_party/abseil-cpp/absl/types/internal/optional.h +0 -352
- data/third_party/abseil-cpp/absl/types/internal/variant.h +0 -1622
- 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,952 @@
|
|
1
|
+
/* MIT License
|
2
|
+
*
|
3
|
+
* Copyright (c) 2023 Brad House
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
11
|
+
*
|
12
|
+
* The above copyright notice and this permission notice (including the next
|
13
|
+
* paragraph) shall be included in all copies or substantial portions of the
|
14
|
+
* Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
* SOFTWARE.
|
23
|
+
*
|
24
|
+
* SPDX-License-Identifier: MIT
|
25
|
+
*/
|
26
|
+
#include "ares_private.h"
|
27
|
+
#ifdef HAVE_SYS_TYPES_H
|
28
|
+
# include <sys/types.h>
|
29
|
+
#endif
|
30
|
+
#ifdef HAVE_SYS_STAT_H
|
31
|
+
# include <sys/stat.h>
|
32
|
+
#endif
|
33
|
+
#ifdef HAVE_NETINET_IN_H
|
34
|
+
# include <netinet/in.h>
|
35
|
+
#endif
|
36
|
+
#ifdef HAVE_NETDB_H
|
37
|
+
# include <netdb.h>
|
38
|
+
#endif
|
39
|
+
#ifdef HAVE_ARPA_INET_H
|
40
|
+
# include <arpa/inet.h>
|
41
|
+
#endif
|
42
|
+
#include <time.h>
|
43
|
+
|
44
|
+
/* HOSTS FILE PROCESSING OVERVIEW
|
45
|
+
* ==============================
|
46
|
+
* The hosts file on the system contains static entries to be processed locally
|
47
|
+
* rather than querying the nameserver. Each row is an IP address followed by
|
48
|
+
* a list of space delimited hostnames that match the ip address. This is used
|
49
|
+
* for both forward and reverse lookups.
|
50
|
+
*
|
51
|
+
* We are caching the entire parsed hosts file for performance reasons. Some
|
52
|
+
* files may be quite sizable and as per Issue #458 can approach 1/2MB in size,
|
53
|
+
* and the parse overhead on a rapid succession of queries can be quite large.
|
54
|
+
* The entries are stored in forwards and backwards hashtables so we can get
|
55
|
+
* O(1) performance on lookup. The file is cached until the file modification
|
56
|
+
* timestamp changes.
|
57
|
+
*
|
58
|
+
* The hosts file processing is quite unique. It has to merge all related hosts
|
59
|
+
* and ips into a single entry due to file formatting requirements. For
|
60
|
+
* instance take the below:
|
61
|
+
*
|
62
|
+
* 127.0.0.1 localhost.localdomain localhost
|
63
|
+
* ::1 localhost.localdomain localhost
|
64
|
+
* 192.168.1.1 host.example.com host
|
65
|
+
* 192.168.1.5 host.example.com host
|
66
|
+
* 2620:1234::1 host.example.com host6.example.com host6 host
|
67
|
+
*
|
68
|
+
* This will yield 2 entries.
|
69
|
+
* 1) ips: 127.0.0.1,::1
|
70
|
+
* hosts: localhost.localdomain,localhost
|
71
|
+
* 2) ips: 192.168.1.1,192.168.1.5,2620:1234::1
|
72
|
+
* hosts: host.example.com,host,host6.example.com,host6
|
73
|
+
*
|
74
|
+
* It could be argued that if searching for 192.168.1.1 that the 'host6'
|
75
|
+
* hostnames should not be returned, but this implementation will return them
|
76
|
+
* since they are related. It is unlikely this will matter in the real world.
|
77
|
+
*/
|
78
|
+
|
79
|
+
struct ares_hosts_file {
|
80
|
+
time_t ts;
|
81
|
+
/*! cache the filename so we know if the filename changes it automatically
|
82
|
+
* invalidates the cache */
|
83
|
+
char *filename;
|
84
|
+
/*! iphash is the owner of the 'entry' object as there is only ever a single
|
85
|
+
* match to the object. */
|
86
|
+
ares_htable_strvp_t *iphash;
|
87
|
+
/*! hosthash does not own the entry so won't free on destruction */
|
88
|
+
ares_htable_strvp_t *hosthash;
|
89
|
+
};
|
90
|
+
|
91
|
+
struct ares_hosts_entry {
|
92
|
+
size_t refcnt; /*! If the entry is stored multiple times in the
|
93
|
+
* ip address hash, we have to reference count it */
|
94
|
+
ares_llist_t *ips;
|
95
|
+
ares_llist_t *hosts;
|
96
|
+
};
|
97
|
+
|
98
|
+
const void *ares_dns_pton(const char *ipaddr, struct ares_addr *addr,
|
99
|
+
size_t *out_len)
|
100
|
+
{
|
101
|
+
const void *ptr = NULL;
|
102
|
+
size_t ptr_len = 0;
|
103
|
+
|
104
|
+
if (ipaddr == NULL || addr == NULL || out_len == NULL) {
|
105
|
+
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
|
106
|
+
}
|
107
|
+
|
108
|
+
*out_len = 0;
|
109
|
+
|
110
|
+
if (addr->family == AF_INET &&
|
111
|
+
ares_inet_pton(AF_INET, ipaddr, &addr->addr.addr4) > 0) {
|
112
|
+
ptr = &addr->addr.addr4;
|
113
|
+
ptr_len = sizeof(addr->addr.addr4);
|
114
|
+
} else if (addr->family == AF_INET6 &&
|
115
|
+
ares_inet_pton(AF_INET6, ipaddr, &addr->addr.addr6) > 0) {
|
116
|
+
ptr = &addr->addr.addr6;
|
117
|
+
ptr_len = sizeof(addr->addr.addr6);
|
118
|
+
} else if (addr->family == AF_UNSPEC) {
|
119
|
+
if (ares_inet_pton(AF_INET, ipaddr, &addr->addr.addr4) > 0) {
|
120
|
+
addr->family = AF_INET;
|
121
|
+
ptr = &addr->addr.addr4;
|
122
|
+
ptr_len = sizeof(addr->addr.addr4);
|
123
|
+
} else if (ares_inet_pton(AF_INET6, ipaddr, &addr->addr.addr6) > 0) {
|
124
|
+
addr->family = AF_INET6;
|
125
|
+
ptr = &addr->addr.addr6;
|
126
|
+
ptr_len = sizeof(addr->addr.addr6);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
*out_len = ptr_len;
|
131
|
+
return ptr;
|
132
|
+
}
|
133
|
+
|
134
|
+
static ares_bool_t ares_normalize_ipaddr(const char *ipaddr, char *out,
|
135
|
+
size_t out_len)
|
136
|
+
{
|
137
|
+
struct ares_addr data;
|
138
|
+
const void *addr;
|
139
|
+
size_t addr_len = 0;
|
140
|
+
|
141
|
+
memset(&data, 0, sizeof(data));
|
142
|
+
data.family = AF_UNSPEC;
|
143
|
+
|
144
|
+
addr = ares_dns_pton(ipaddr, &data, &addr_len);
|
145
|
+
if (addr == NULL) {
|
146
|
+
return ARES_FALSE;
|
147
|
+
}
|
148
|
+
|
149
|
+
if (!ares_inet_ntop(data.family, addr, out, (ares_socklen_t)out_len)) {
|
150
|
+
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
|
151
|
+
}
|
152
|
+
|
153
|
+
return ARES_TRUE;
|
154
|
+
}
|
155
|
+
|
156
|
+
static void ares_hosts_entry_destroy(ares_hosts_entry_t *entry)
|
157
|
+
{
|
158
|
+
if (entry == NULL) {
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
|
162
|
+
/* Honor reference counting */
|
163
|
+
if (entry->refcnt != 0) {
|
164
|
+
entry->refcnt--;
|
165
|
+
}
|
166
|
+
|
167
|
+
if (entry->refcnt > 0) {
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
|
171
|
+
ares_llist_destroy(entry->hosts);
|
172
|
+
ares_llist_destroy(entry->ips);
|
173
|
+
ares_free(entry);
|
174
|
+
}
|
175
|
+
|
176
|
+
static void ares_hosts_entry_destroy_cb(void *entry)
|
177
|
+
{
|
178
|
+
ares_hosts_entry_destroy(entry);
|
179
|
+
}
|
180
|
+
|
181
|
+
void ares_hosts_file_destroy(ares_hosts_file_t *hf)
|
182
|
+
{
|
183
|
+
if (hf == NULL) {
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
|
187
|
+
ares_free(hf->filename);
|
188
|
+
ares_htable_strvp_destroy(hf->hosthash);
|
189
|
+
ares_htable_strvp_destroy(hf->iphash);
|
190
|
+
ares_free(hf);
|
191
|
+
}
|
192
|
+
|
193
|
+
static ares_hosts_file_t *ares_hosts_file_create(const char *filename)
|
194
|
+
{
|
195
|
+
ares_hosts_file_t *hf = ares_malloc_zero(sizeof(*hf));
|
196
|
+
if (hf == NULL) {
|
197
|
+
goto fail;
|
198
|
+
}
|
199
|
+
|
200
|
+
hf->ts = time(NULL);
|
201
|
+
|
202
|
+
hf->filename = ares_strdup(filename);
|
203
|
+
if (hf->filename == NULL) {
|
204
|
+
goto fail;
|
205
|
+
}
|
206
|
+
|
207
|
+
hf->iphash = ares_htable_strvp_create(ares_hosts_entry_destroy_cb);
|
208
|
+
if (hf->iphash == NULL) {
|
209
|
+
goto fail;
|
210
|
+
}
|
211
|
+
|
212
|
+
hf->hosthash = ares_htable_strvp_create(NULL);
|
213
|
+
if (hf->hosthash == NULL) {
|
214
|
+
goto fail;
|
215
|
+
}
|
216
|
+
|
217
|
+
return hf;
|
218
|
+
|
219
|
+
fail:
|
220
|
+
ares_hosts_file_destroy(hf);
|
221
|
+
return NULL;
|
222
|
+
}
|
223
|
+
|
224
|
+
typedef enum {
|
225
|
+
ARES_MATCH_NONE = 0,
|
226
|
+
ARES_MATCH_IPADDR = 1,
|
227
|
+
ARES_MATCH_HOST = 2
|
228
|
+
} ares_hosts_file_match_t;
|
229
|
+
|
230
|
+
static ares_status_t ares_hosts_file_merge_entry(
|
231
|
+
const ares_hosts_file_t *hf, ares_hosts_entry_t *existing,
|
232
|
+
ares_hosts_entry_t *entry, ares_hosts_file_match_t matchtype)
|
233
|
+
{
|
234
|
+
ares_llist_node_t *node;
|
235
|
+
|
236
|
+
/* If we matched on IP address, we know there can only be 1, so there's no
|
237
|
+
* reason to do anything */
|
238
|
+
if (matchtype != ARES_MATCH_IPADDR) {
|
239
|
+
while ((node = ares_llist_node_first(entry->ips)) != NULL) {
|
240
|
+
const char *ipaddr = ares_llist_node_val(node);
|
241
|
+
|
242
|
+
if (ares_htable_strvp_get_direct(hf->iphash, ipaddr) != NULL) {
|
243
|
+
ares_llist_node_destroy(node);
|
244
|
+
continue;
|
245
|
+
}
|
246
|
+
|
247
|
+
ares_llist_node_mvparent_last(node, existing->ips);
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
while ((node = ares_llist_node_first(entry->hosts)) != NULL) {
|
253
|
+
const char *hostname = ares_llist_node_val(node);
|
254
|
+
|
255
|
+
if (ares_htable_strvp_get_direct(hf->hosthash, hostname) != NULL) {
|
256
|
+
ares_llist_node_destroy(node);
|
257
|
+
continue;
|
258
|
+
}
|
259
|
+
|
260
|
+
ares_llist_node_mvparent_last(node, existing->hosts);
|
261
|
+
}
|
262
|
+
|
263
|
+
ares_hosts_entry_destroy(entry);
|
264
|
+
return ARES_SUCCESS;
|
265
|
+
}
|
266
|
+
|
267
|
+
static ares_hosts_file_match_t
|
268
|
+
ares_hosts_file_match(const ares_hosts_file_t *hf, ares_hosts_entry_t *entry,
|
269
|
+
ares_hosts_entry_t **match)
|
270
|
+
{
|
271
|
+
ares_llist_node_t *node;
|
272
|
+
*match = NULL;
|
273
|
+
|
274
|
+
for (node = ares_llist_node_first(entry->ips); node != NULL;
|
275
|
+
node = ares_llist_node_next(node)) {
|
276
|
+
const char *ipaddr = ares_llist_node_val(node);
|
277
|
+
*match = ares_htable_strvp_get_direct(hf->iphash, ipaddr);
|
278
|
+
if (*match != NULL) {
|
279
|
+
return ARES_MATCH_IPADDR;
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
for (node = ares_llist_node_first(entry->hosts); node != NULL;
|
284
|
+
node = ares_llist_node_next(node)) {
|
285
|
+
const char *host = ares_llist_node_val(node);
|
286
|
+
*match = ares_htable_strvp_get_direct(hf->hosthash, host);
|
287
|
+
if (*match != NULL) {
|
288
|
+
return ARES_MATCH_HOST;
|
289
|
+
}
|
290
|
+
}
|
291
|
+
|
292
|
+
return ARES_MATCH_NONE;
|
293
|
+
}
|
294
|
+
|
295
|
+
/*! entry is invalidated upon calling this function, always, even on error */
|
296
|
+
static ares_status_t ares_hosts_file_add(ares_hosts_file_t *hosts,
|
297
|
+
ares_hosts_entry_t *entry)
|
298
|
+
{
|
299
|
+
ares_hosts_entry_t *match = NULL;
|
300
|
+
ares_status_t status = ARES_SUCCESS;
|
301
|
+
ares_llist_node_t *node;
|
302
|
+
ares_hosts_file_match_t matchtype;
|
303
|
+
size_t num_hostnames;
|
304
|
+
|
305
|
+
/* Record the number of hostnames in this entry file. If we merge into an
|
306
|
+
* existing record, these will be *appended* to the entry, so we'll count
|
307
|
+
* backwards when adding to the hosts hashtable */
|
308
|
+
num_hostnames = ares_llist_len(entry->hosts);
|
309
|
+
|
310
|
+
matchtype = ares_hosts_file_match(hosts, entry, &match);
|
311
|
+
|
312
|
+
if (matchtype != ARES_MATCH_NONE) {
|
313
|
+
status = ares_hosts_file_merge_entry(hosts, match, entry, matchtype);
|
314
|
+
if (status != ARES_SUCCESS) {
|
315
|
+
ares_hosts_entry_destroy(entry); /* LCOV_EXCL_LINE: DefensiveCoding */
|
316
|
+
return status; /* LCOV_EXCL_LINE: DefensiveCoding */
|
317
|
+
}
|
318
|
+
/* entry was invalidated above by merging */
|
319
|
+
entry = match;
|
320
|
+
}
|
321
|
+
|
322
|
+
if (matchtype != ARES_MATCH_IPADDR) {
|
323
|
+
const char *ipaddr = ares_llist_last_val(entry->ips);
|
324
|
+
|
325
|
+
if (!ares_htable_strvp_get(hosts->iphash, ipaddr, NULL)) {
|
326
|
+
if (!ares_htable_strvp_insert(hosts->iphash, ipaddr, entry)) {
|
327
|
+
ares_hosts_entry_destroy(entry);
|
328
|
+
return ARES_ENOMEM;
|
329
|
+
}
|
330
|
+
entry->refcnt++;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
/* Go backwards, on a merge, hostnames are appended. Breakout once we've
|
335
|
+
* consumed all the hosts that we appended */
|
336
|
+
for (node = ares_llist_node_last(entry->hosts); node != NULL;
|
337
|
+
node = ares_llist_node_prev(node)) {
|
338
|
+
const char *val = ares_llist_node_val(node);
|
339
|
+
|
340
|
+
if (num_hostnames == 0) {
|
341
|
+
break;
|
342
|
+
}
|
343
|
+
|
344
|
+
num_hostnames--;
|
345
|
+
|
346
|
+
/* first hostname match wins. If we detect a duplicate hostname for another
|
347
|
+
* ip it will automatically be added to the same entry */
|
348
|
+
if (ares_htable_strvp_get(hosts->hosthash, val, NULL)) {
|
349
|
+
continue;
|
350
|
+
}
|
351
|
+
|
352
|
+
if (!ares_htable_strvp_insert(hosts->hosthash, val, entry)) {
|
353
|
+
return ARES_ENOMEM;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
return ARES_SUCCESS;
|
358
|
+
}
|
359
|
+
|
360
|
+
static ares_bool_t ares_hosts_entry_isdup(ares_hosts_entry_t *entry,
|
361
|
+
const char *host)
|
362
|
+
{
|
363
|
+
ares_llist_node_t *node;
|
364
|
+
|
365
|
+
for (node = ares_llist_node_first(entry->ips); node != NULL;
|
366
|
+
node = ares_llist_node_next(node)) {
|
367
|
+
const char *myhost = ares_llist_node_val(node);
|
368
|
+
if (ares_strcaseeq(myhost, host)) {
|
369
|
+
return ARES_TRUE;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
return ARES_FALSE;
|
374
|
+
}
|
375
|
+
|
376
|
+
static ares_status_t ares_parse_hosts_hostnames(ares_buf_t *buf,
|
377
|
+
ares_hosts_entry_t *entry)
|
378
|
+
{
|
379
|
+
entry->hosts = ares_llist_create(ares_free);
|
380
|
+
if (entry->hosts == NULL) {
|
381
|
+
return ARES_ENOMEM;
|
382
|
+
}
|
383
|
+
|
384
|
+
/* Parse hostnames and aliases */
|
385
|
+
while (ares_buf_len(buf)) {
|
386
|
+
char hostname[256];
|
387
|
+
char *temp;
|
388
|
+
ares_status_t status;
|
389
|
+
unsigned char comment = '#';
|
390
|
+
|
391
|
+
ares_buf_consume_whitespace(buf, ARES_FALSE);
|
392
|
+
|
393
|
+
if (ares_buf_len(buf) == 0) {
|
394
|
+
break;
|
395
|
+
}
|
396
|
+
|
397
|
+
/* See if it is a comment, if so stop processing */
|
398
|
+
if (ares_buf_begins_with(buf, &comment, 1)) {
|
399
|
+
break;
|
400
|
+
}
|
401
|
+
|
402
|
+
ares_buf_tag(buf);
|
403
|
+
|
404
|
+
/* Must be at end of line */
|
405
|
+
if (ares_buf_consume_nonwhitespace(buf) == 0) {
|
406
|
+
break;
|
407
|
+
}
|
408
|
+
|
409
|
+
status = ares_buf_tag_fetch_string(buf, hostname, sizeof(hostname));
|
410
|
+
if (status != ARES_SUCCESS) {
|
411
|
+
/* Bad entry, just ignore as long as its not the first. If its the first,
|
412
|
+
* it must be valid */
|
413
|
+
if (ares_llist_len(entry->hosts) == 0) {
|
414
|
+
return ARES_EBADSTR;
|
415
|
+
}
|
416
|
+
|
417
|
+
continue;
|
418
|
+
}
|
419
|
+
|
420
|
+
/* Validate it is a valid hostname characterset */
|
421
|
+
if (!ares_is_hostname(hostname)) {
|
422
|
+
continue;
|
423
|
+
}
|
424
|
+
|
425
|
+
/* Don't add a duplicate to the same entry */
|
426
|
+
if (ares_hosts_entry_isdup(entry, hostname)) {
|
427
|
+
continue;
|
428
|
+
}
|
429
|
+
|
430
|
+
/* Add to list */
|
431
|
+
temp = ares_strdup(hostname);
|
432
|
+
if (temp == NULL) {
|
433
|
+
return ARES_ENOMEM;
|
434
|
+
}
|
435
|
+
|
436
|
+
if (ares_llist_insert_last(entry->hosts, temp) == NULL) {
|
437
|
+
ares_free(temp);
|
438
|
+
return ARES_ENOMEM;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
/* Must have at least 1 entry */
|
443
|
+
if (ares_llist_len(entry->hosts) == 0) {
|
444
|
+
return ARES_EBADSTR;
|
445
|
+
}
|
446
|
+
|
447
|
+
return ARES_SUCCESS;
|
448
|
+
}
|
449
|
+
|
450
|
+
static ares_status_t ares_parse_hosts_ipaddr(ares_buf_t *buf,
|
451
|
+
ares_hosts_entry_t **entry_out)
|
452
|
+
{
|
453
|
+
char addr[INET6_ADDRSTRLEN];
|
454
|
+
char *temp;
|
455
|
+
ares_hosts_entry_t *entry = NULL;
|
456
|
+
ares_status_t status;
|
457
|
+
|
458
|
+
*entry_out = NULL;
|
459
|
+
|
460
|
+
ares_buf_tag(buf);
|
461
|
+
ares_buf_consume_nonwhitespace(buf);
|
462
|
+
status = ares_buf_tag_fetch_string(buf, addr, sizeof(addr));
|
463
|
+
if (status != ARES_SUCCESS) {
|
464
|
+
return status;
|
465
|
+
}
|
466
|
+
|
467
|
+
/* Validate and normalize the ip address format */
|
468
|
+
if (!ares_normalize_ipaddr(addr, addr, sizeof(addr))) {
|
469
|
+
return ARES_EBADSTR;
|
470
|
+
}
|
471
|
+
|
472
|
+
entry = ares_malloc_zero(sizeof(*entry));
|
473
|
+
if (entry == NULL) {
|
474
|
+
return ARES_ENOMEM;
|
475
|
+
}
|
476
|
+
|
477
|
+
entry->ips = ares_llist_create(ares_free);
|
478
|
+
if (entry->ips == NULL) {
|
479
|
+
ares_hosts_entry_destroy(entry);
|
480
|
+
return ARES_ENOMEM;
|
481
|
+
}
|
482
|
+
|
483
|
+
temp = ares_strdup(addr);
|
484
|
+
if (temp == NULL) {
|
485
|
+
ares_hosts_entry_destroy(entry);
|
486
|
+
return ARES_ENOMEM;
|
487
|
+
}
|
488
|
+
|
489
|
+
if (ares_llist_insert_first(entry->ips, temp) == NULL) {
|
490
|
+
ares_free(temp);
|
491
|
+
ares_hosts_entry_destroy(entry);
|
492
|
+
return ARES_ENOMEM;
|
493
|
+
}
|
494
|
+
|
495
|
+
*entry_out = entry;
|
496
|
+
|
497
|
+
return ARES_SUCCESS;
|
498
|
+
}
|
499
|
+
|
500
|
+
static ares_status_t ares_parse_hosts(const char *filename,
|
501
|
+
ares_hosts_file_t **out)
|
502
|
+
{
|
503
|
+
ares_buf_t *buf = NULL;
|
504
|
+
ares_status_t status = ARES_EBADRESP;
|
505
|
+
ares_hosts_file_t *hf = NULL;
|
506
|
+
ares_hosts_entry_t *entry = NULL;
|
507
|
+
|
508
|
+
*out = NULL;
|
509
|
+
|
510
|
+
buf = ares_buf_create();
|
511
|
+
if (buf == NULL) {
|
512
|
+
status = ARES_ENOMEM;
|
513
|
+
goto done;
|
514
|
+
}
|
515
|
+
|
516
|
+
status = ares_buf_load_file(filename, buf);
|
517
|
+
if (status != ARES_SUCCESS) {
|
518
|
+
goto done;
|
519
|
+
}
|
520
|
+
|
521
|
+
hf = ares_hosts_file_create(filename);
|
522
|
+
if (hf == NULL) {
|
523
|
+
status = ARES_ENOMEM;
|
524
|
+
goto done;
|
525
|
+
}
|
526
|
+
|
527
|
+
while (ares_buf_len(buf)) {
|
528
|
+
unsigned char comment = '#';
|
529
|
+
|
530
|
+
/* -- Start of new line here -- */
|
531
|
+
|
532
|
+
/* Consume any leading whitespace */
|
533
|
+
ares_buf_consume_whitespace(buf, ARES_FALSE);
|
534
|
+
|
535
|
+
if (ares_buf_len(buf) == 0) {
|
536
|
+
break;
|
537
|
+
}
|
538
|
+
|
539
|
+
/* See if it is a comment, if so, consume remaining line */
|
540
|
+
if (ares_buf_begins_with(buf, &comment, 1)) {
|
541
|
+
ares_buf_consume_line(buf, ARES_TRUE);
|
542
|
+
continue;
|
543
|
+
}
|
544
|
+
|
545
|
+
/* Pull off ip address */
|
546
|
+
status = ares_parse_hosts_ipaddr(buf, &entry);
|
547
|
+
if (status == ARES_ENOMEM) {
|
548
|
+
goto done;
|
549
|
+
}
|
550
|
+
if (status != ARES_SUCCESS) {
|
551
|
+
/* Bad line, consume and go onto next */
|
552
|
+
ares_buf_consume_line(buf, ARES_TRUE);
|
553
|
+
continue;
|
554
|
+
}
|
555
|
+
|
556
|
+
/* Parse of the hostnames */
|
557
|
+
status = ares_parse_hosts_hostnames(buf, entry);
|
558
|
+
if (status == ARES_ENOMEM) {
|
559
|
+
goto done;
|
560
|
+
} else if (status != ARES_SUCCESS) {
|
561
|
+
/* Bad line, consume and go onto next */
|
562
|
+
ares_hosts_entry_destroy(entry);
|
563
|
+
entry = NULL;
|
564
|
+
ares_buf_consume_line(buf, ARES_TRUE);
|
565
|
+
continue;
|
566
|
+
}
|
567
|
+
|
568
|
+
/* Append the successful entry to the hosts file */
|
569
|
+
status = ares_hosts_file_add(hf, entry);
|
570
|
+
entry = NULL; /* is always invalidated by this function, even on error */
|
571
|
+
if (status != ARES_SUCCESS) {
|
572
|
+
goto done;
|
573
|
+
}
|
574
|
+
|
575
|
+
/* Go to next line */
|
576
|
+
ares_buf_consume_line(buf, ARES_TRUE);
|
577
|
+
}
|
578
|
+
|
579
|
+
status = ARES_SUCCESS;
|
580
|
+
|
581
|
+
done:
|
582
|
+
ares_hosts_entry_destroy(entry);
|
583
|
+
ares_buf_destroy(buf);
|
584
|
+
if (status != ARES_SUCCESS) {
|
585
|
+
ares_hosts_file_destroy(hf);
|
586
|
+
} else {
|
587
|
+
*out = hf;
|
588
|
+
}
|
589
|
+
return status;
|
590
|
+
}
|
591
|
+
|
592
|
+
static ares_bool_t ares_hosts_expired(const char *filename,
|
593
|
+
const ares_hosts_file_t *hf)
|
594
|
+
{
|
595
|
+
time_t mod_ts = 0;
|
596
|
+
|
597
|
+
#ifdef HAVE_STAT
|
598
|
+
struct stat st;
|
599
|
+
if (stat(filename, &st) == 0) {
|
600
|
+
mod_ts = st.st_mtime;
|
601
|
+
}
|
602
|
+
#elif defined(_WIN32)
|
603
|
+
struct _stat st;
|
604
|
+
if (_stat(filename, &st) == 0) {
|
605
|
+
mod_ts = st.st_mtime;
|
606
|
+
}
|
607
|
+
#else
|
608
|
+
(void)filename;
|
609
|
+
#endif
|
610
|
+
|
611
|
+
if (hf == NULL) {
|
612
|
+
return ARES_TRUE;
|
613
|
+
}
|
614
|
+
|
615
|
+
/* Expire every 60s if we can't get a time */
|
616
|
+
if (mod_ts == 0) {
|
617
|
+
mod_ts =
|
618
|
+
time(NULL) - 60; /* LCOV_EXCL_LINE: only on systems without stat() */
|
619
|
+
}
|
620
|
+
|
621
|
+
/* If filenames are different, its expired */
|
622
|
+
if (!ares_strcaseeq(hf->filename, filename)) {
|
623
|
+
return ARES_TRUE;
|
624
|
+
}
|
625
|
+
|
626
|
+
if (hf->ts <= mod_ts) {
|
627
|
+
return ARES_TRUE;
|
628
|
+
}
|
629
|
+
|
630
|
+
return ARES_FALSE;
|
631
|
+
}
|
632
|
+
|
633
|
+
static ares_status_t ares_hosts_path(const ares_channel_t *channel,
|
634
|
+
ares_bool_t use_env, char **path)
|
635
|
+
{
|
636
|
+
char *path_hosts = NULL;
|
637
|
+
|
638
|
+
*path = NULL;
|
639
|
+
|
640
|
+
if (channel->hosts_path) {
|
641
|
+
path_hosts = ares_strdup(channel->hosts_path);
|
642
|
+
if (!path_hosts) {
|
643
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
644
|
+
}
|
645
|
+
}
|
646
|
+
|
647
|
+
if (use_env) {
|
648
|
+
if (path_hosts) {
|
649
|
+
ares_free(path_hosts);
|
650
|
+
}
|
651
|
+
|
652
|
+
path_hosts = ares_strdup(getenv("CARES_HOSTS"));
|
653
|
+
if (!path_hosts) {
|
654
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
655
|
+
}
|
656
|
+
}
|
657
|
+
|
658
|
+
if (!path_hosts) {
|
659
|
+
#if defined(USE_WINSOCK)
|
660
|
+
char PATH_HOSTS[MAX_PATH] = "";
|
661
|
+
char tmp[MAX_PATH];
|
662
|
+
HKEY hkeyHosts;
|
663
|
+
DWORD dwLength = sizeof(tmp);
|
664
|
+
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ,
|
665
|
+
&hkeyHosts) != ERROR_SUCCESS) {
|
666
|
+
return ARES_ENOTFOUND;
|
667
|
+
}
|
668
|
+
RegQueryValueExA(hkeyHosts, DATABASEPATH, NULL, NULL, (LPBYTE)tmp,
|
669
|
+
&dwLength);
|
670
|
+
ExpandEnvironmentStringsA(tmp, PATH_HOSTS, MAX_PATH);
|
671
|
+
RegCloseKey(hkeyHosts);
|
672
|
+
strcat(PATH_HOSTS, WIN_PATH_HOSTS);
|
673
|
+
#elif defined(WATT32)
|
674
|
+
const char *PATH_HOSTS = _w32_GetHostsFile();
|
675
|
+
|
676
|
+
if (!PATH_HOSTS) {
|
677
|
+
return ARES_ENOTFOUND;
|
678
|
+
}
|
679
|
+
#endif
|
680
|
+
path_hosts = ares_strdup(PATH_HOSTS);
|
681
|
+
if (!path_hosts) {
|
682
|
+
return ARES_ENOMEM;
|
683
|
+
}
|
684
|
+
}
|
685
|
+
|
686
|
+
*path = path_hosts;
|
687
|
+
return ARES_SUCCESS;
|
688
|
+
}
|
689
|
+
|
690
|
+
static ares_status_t ares_hosts_update(ares_channel_t *channel,
|
691
|
+
ares_bool_t use_env)
|
692
|
+
{
|
693
|
+
ares_status_t status;
|
694
|
+
char *filename = NULL;
|
695
|
+
|
696
|
+
status = ares_hosts_path(channel, use_env, &filename);
|
697
|
+
if (status != ARES_SUCCESS) {
|
698
|
+
return status;
|
699
|
+
}
|
700
|
+
|
701
|
+
if (!ares_hosts_expired(filename, channel->hf)) {
|
702
|
+
ares_free(filename);
|
703
|
+
return ARES_SUCCESS;
|
704
|
+
}
|
705
|
+
|
706
|
+
ares_hosts_file_destroy(channel->hf);
|
707
|
+
channel->hf = NULL;
|
708
|
+
|
709
|
+
status = ares_parse_hosts(filename, &channel->hf);
|
710
|
+
ares_free(filename);
|
711
|
+
return status;
|
712
|
+
}
|
713
|
+
|
714
|
+
ares_status_t ares_hosts_search_ipaddr(ares_channel_t *channel,
|
715
|
+
ares_bool_t use_env, const char *ipaddr,
|
716
|
+
const ares_hosts_entry_t **entry)
|
717
|
+
{
|
718
|
+
ares_status_t status;
|
719
|
+
char addr[INET6_ADDRSTRLEN];
|
720
|
+
|
721
|
+
*entry = NULL;
|
722
|
+
|
723
|
+
status = ares_hosts_update(channel, use_env);
|
724
|
+
if (status != ARES_SUCCESS) {
|
725
|
+
return status;
|
726
|
+
}
|
727
|
+
|
728
|
+
if (channel->hf == NULL) {
|
729
|
+
return ARES_ENOTFOUND; /* LCOV_EXCL_LINE: DefensiveCoding */
|
730
|
+
}
|
731
|
+
|
732
|
+
if (!ares_normalize_ipaddr(ipaddr, addr, sizeof(addr))) {
|
733
|
+
return ARES_EBADNAME;
|
734
|
+
}
|
735
|
+
|
736
|
+
*entry = ares_htable_strvp_get_direct(channel->hf->iphash, addr);
|
737
|
+
if (*entry == NULL) {
|
738
|
+
return ARES_ENOTFOUND;
|
739
|
+
}
|
740
|
+
|
741
|
+
return ARES_SUCCESS;
|
742
|
+
}
|
743
|
+
|
744
|
+
ares_status_t ares_hosts_search_host(ares_channel_t *channel,
|
745
|
+
ares_bool_t use_env, const char *host,
|
746
|
+
const ares_hosts_entry_t **entry)
|
747
|
+
{
|
748
|
+
ares_status_t status;
|
749
|
+
|
750
|
+
*entry = NULL;
|
751
|
+
|
752
|
+
status = ares_hosts_update(channel, use_env);
|
753
|
+
if (status != ARES_SUCCESS) {
|
754
|
+
return status;
|
755
|
+
}
|
756
|
+
|
757
|
+
if (channel->hf == NULL) {
|
758
|
+
return ARES_ENOTFOUND; /* LCOV_EXCL_LINE: DefensiveCoding */
|
759
|
+
}
|
760
|
+
|
761
|
+
*entry = ares_htable_strvp_get_direct(channel->hf->hosthash, host);
|
762
|
+
if (*entry == NULL) {
|
763
|
+
return ARES_ENOTFOUND;
|
764
|
+
}
|
765
|
+
|
766
|
+
return ARES_SUCCESS;
|
767
|
+
}
|
768
|
+
|
769
|
+
static ares_status_t
|
770
|
+
ares_hosts_ai_append_cnames(const ares_hosts_entry_t *entry,
|
771
|
+
struct ares_addrinfo_cname **cnames_out)
|
772
|
+
{
|
773
|
+
struct ares_addrinfo_cname *cname = NULL;
|
774
|
+
struct ares_addrinfo_cname *cnames = NULL;
|
775
|
+
const char *primaryhost;
|
776
|
+
ares_llist_node_t *node;
|
777
|
+
ares_status_t status;
|
778
|
+
size_t cnt = 0;
|
779
|
+
|
780
|
+
node = ares_llist_node_first(entry->hosts);
|
781
|
+
primaryhost = ares_llist_node_val(node);
|
782
|
+
/* Skip to next node to start with aliases */
|
783
|
+
node = ares_llist_node_next(node);
|
784
|
+
|
785
|
+
while (node != NULL) {
|
786
|
+
const char *host = ares_llist_node_val(node);
|
787
|
+
|
788
|
+
/* Cap at 100 entries. , some people use
|
789
|
+
* https://github.com/StevenBlack/hosts and we don't need 200k+ aliases */
|
790
|
+
cnt++;
|
791
|
+
if (cnt > 100) {
|
792
|
+
break; /* LCOV_EXCL_LINE: DefensiveCoding */
|
793
|
+
}
|
794
|
+
|
795
|
+
cname = ares_append_addrinfo_cname(&cnames);
|
796
|
+
if (cname == NULL) {
|
797
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
798
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
799
|
+
}
|
800
|
+
|
801
|
+
cname->alias = ares_strdup(host);
|
802
|
+
if (cname->alias == NULL) {
|
803
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
804
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
805
|
+
}
|
806
|
+
|
807
|
+
cname->name = ares_strdup(primaryhost);
|
808
|
+
if (cname->name == NULL) {
|
809
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
810
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
811
|
+
}
|
812
|
+
|
813
|
+
node = ares_llist_node_next(node);
|
814
|
+
}
|
815
|
+
|
816
|
+
/* No entries, add only primary */
|
817
|
+
if (cnames == NULL) {
|
818
|
+
cname = ares_append_addrinfo_cname(&cnames);
|
819
|
+
if (cname == NULL) {
|
820
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
821
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
822
|
+
}
|
823
|
+
|
824
|
+
cname->name = ares_strdup(primaryhost);
|
825
|
+
if (cname->name == NULL) {
|
826
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
827
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
828
|
+
}
|
829
|
+
}
|
830
|
+
status = ARES_SUCCESS;
|
831
|
+
|
832
|
+
done:
|
833
|
+
if (status != ARES_SUCCESS) {
|
834
|
+
ares_freeaddrinfo_cnames(cnames); /* LCOV_EXCL_LINE: DefensiveCoding */
|
835
|
+
return status; /* LCOV_EXCL_LINE: DefensiveCoding */
|
836
|
+
}
|
837
|
+
|
838
|
+
*cnames_out = cnames;
|
839
|
+
return ARES_SUCCESS;
|
840
|
+
}
|
841
|
+
|
842
|
+
ares_status_t ares_hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry,
|
843
|
+
const char *name, int family,
|
844
|
+
unsigned short port,
|
845
|
+
ares_bool_t want_cnames,
|
846
|
+
struct ares_addrinfo *ai)
|
847
|
+
{
|
848
|
+
ares_status_t status = ARES_ENOTFOUND;
|
849
|
+
struct ares_addrinfo_cname *cnames = NULL;
|
850
|
+
struct ares_addrinfo_node *ainodes = NULL;
|
851
|
+
ares_llist_node_t *node;
|
852
|
+
|
853
|
+
switch (family) {
|
854
|
+
case AF_INET:
|
855
|
+
case AF_INET6:
|
856
|
+
case AF_UNSPEC:
|
857
|
+
break;
|
858
|
+
default: /* LCOV_EXCL_LINE: DefensiveCoding */
|
859
|
+
return ARES_EBADFAMILY; /* LCOV_EXCL_LINE: DefensiveCoding */
|
860
|
+
}
|
861
|
+
|
862
|
+
if (name != NULL) {
|
863
|
+
ares_free(ai->name);
|
864
|
+
ai->name = ares_strdup(name);
|
865
|
+
if (ai->name == NULL) {
|
866
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
867
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
868
|
+
}
|
869
|
+
}
|
870
|
+
|
871
|
+
for (node = ares_llist_node_first(entry->ips); node != NULL;
|
872
|
+
node = ares_llist_node_next(node)) {
|
873
|
+
struct ares_addr addr;
|
874
|
+
const void *ptr = NULL;
|
875
|
+
size_t ptr_len = 0;
|
876
|
+
const char *ipaddr = ares_llist_node_val(node);
|
877
|
+
|
878
|
+
memset(&addr, 0, sizeof(addr));
|
879
|
+
addr.family = family;
|
880
|
+
ptr = ares_dns_pton(ipaddr, &addr, &ptr_len);
|
881
|
+
|
882
|
+
if (ptr == NULL) {
|
883
|
+
continue;
|
884
|
+
}
|
885
|
+
|
886
|
+
status = ares_append_ai_node(addr.family, port, 0, ptr, &ainodes);
|
887
|
+
if (status != ARES_SUCCESS) {
|
888
|
+
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
|
889
|
+
}
|
890
|
+
}
|
891
|
+
|
892
|
+
/* Might be ARES_ENOTFOUND here if no ips matched requested address family */
|
893
|
+
if (status != ARES_SUCCESS) {
|
894
|
+
goto done;
|
895
|
+
}
|
896
|
+
|
897
|
+
if (want_cnames) {
|
898
|
+
status = ares_hosts_ai_append_cnames(entry, &cnames);
|
899
|
+
if (status != ARES_SUCCESS) {
|
900
|
+
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
|
901
|
+
}
|
902
|
+
}
|
903
|
+
|
904
|
+
status = ARES_SUCCESS;
|
905
|
+
|
906
|
+
done:
|
907
|
+
if (status != ARES_SUCCESS) {
|
908
|
+
/* LCOV_EXCL_START: defensive coding */
|
909
|
+
ares_freeaddrinfo_cnames(cnames);
|
910
|
+
ares_freeaddrinfo_nodes(ainodes);
|
911
|
+
ares_free(ai->name);
|
912
|
+
ai->name = NULL;
|
913
|
+
return status;
|
914
|
+
/* LCOV_EXCL_STOP */
|
915
|
+
}
|
916
|
+
ares_addrinfo_cat_cnames(&ai->cnames, cnames);
|
917
|
+
ares_addrinfo_cat_nodes(&ai->nodes, ainodes);
|
918
|
+
|
919
|
+
return status;
|
920
|
+
}
|
921
|
+
|
922
|
+
ares_status_t ares_hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
|
923
|
+
int family, struct hostent **hostent)
|
924
|
+
{
|
925
|
+
ares_status_t status;
|
926
|
+
struct ares_addrinfo *ai = ares_malloc_zero(sizeof(*ai));
|
927
|
+
|
928
|
+
*hostent = NULL;
|
929
|
+
|
930
|
+
if (ai == NULL) {
|
931
|
+
return ARES_ENOMEM;
|
932
|
+
}
|
933
|
+
|
934
|
+
status = ares_hosts_entry_to_addrinfo(entry, NULL, family, 0, ARES_TRUE, ai);
|
935
|
+
if (status != ARES_SUCCESS) {
|
936
|
+
goto done;
|
937
|
+
}
|
938
|
+
|
939
|
+
status = ares_addrinfo2hostent(ai, family, hostent);
|
940
|
+
if (status != ARES_SUCCESS) {
|
941
|
+
goto done;
|
942
|
+
}
|
943
|
+
|
944
|
+
done:
|
945
|
+
ares_freeaddrinfo(ai);
|
946
|
+
if (status != ARES_SUCCESS) {
|
947
|
+
ares_free_hostent(*hostent);
|
948
|
+
*hostent = NULL;
|
949
|
+
}
|
950
|
+
|
951
|
+
return status;
|
952
|
+
}
|