grpc 1.74.1 → 1.75.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +83 -41
- data/include/grpc/credentials.h +7 -1
- data/src/core/call/client_call.cc +4 -4
- data/src/core/call/filter_fusion.h +1230 -0
- data/src/core/call/metadata.cc +22 -0
- data/src/core/call/metadata.h +24 -2
- data/src/core/channelz/channelz.cc +10 -17
- data/src/core/channelz/channelz.h +58 -19
- data/src/core/channelz/channelz_registry.cc +0 -162
- data/src/core/channelz/channelz_registry.h +14 -7
- data/src/core/channelz/property_list.cc +19 -23
- data/src/core/channelz/property_list.h +3 -1
- data/src/core/channelz/v2tov1/convert.cc +683 -0
- data/src/core/channelz/v2tov1/convert.h +58 -0
- data/src/core/channelz/v2tov1/legacy_api.cc +425 -0
- data/src/core/channelz/v2tov1/legacy_api.h +32 -0
- data/src/core/channelz/v2tov1/property_list.cc +118 -0
- data/src/core/channelz/v2tov1/property_list.h +52 -0
- data/src/core/client_channel/client_channel_filter.cc +5 -4
- data/src/core/client_channel/client_channel_filter.h +2 -2
- data/src/core/client_channel/client_channel_internal.h +2 -1
- data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
- data/src/core/client_channel/subchannel.cc +14 -6
- data/src/core/client_channel/subchannel.h +2 -0
- data/src/core/config/core_configuration.cc +3 -1
- data/src/core/config/core_configuration.h +12 -0
- data/src/core/credentials/transport/alts/alts_credentials.cc +5 -0
- data/src/core/credentials/transport/alts/check_gcp_environment_windows.cc +2 -0
- data/src/core/credentials/transport/channel_creds_registry_init.cc +3 -1
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -1
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +8 -3
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -24
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +19 -8
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +96 -54
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +15 -2
- data/src/core/credentials/transport/tls/spiffe_utils.cc +371 -0
- data/src/core/credentials/transport/tls/spiffe_utils.h +171 -0
- data/src/core/credentials/transport/tls/ssl_utils.cc +11 -10
- data/src/core/credentials/transport/tls/ssl_utils.h +4 -2
- data/src/core/credentials/transport/tls/tls_credentials.cc +2 -0
- data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -26
- data/src/core/credentials/transport/tls/tls_security_connector.h +12 -12
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -2
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
- data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
- data/src/core/ext/filters/message_size/message_size_filter.cc +4 -4
- data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -5
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
- data/src/core/ext/transport/chttp2/transport/frame.cc +89 -6
- data/src/core/ext/transport/chttp2/transport/frame.h +38 -0
- data/src/core/ext/transport/chttp2/transport/header_assembler.h +5 -14
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +294 -78
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +128 -9
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +52 -35
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +61 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +142 -0
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +81 -3
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +12 -1
- data/src/core/ext/transport/chttp2/transport/message_assembler.h +2 -2
- data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +22 -5
- data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
- data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +6 -4
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb.h +4959 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.c +1111 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.h +108 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +142 -54
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +18 -14
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +2 -2
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +716 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.h +227 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +86 -88
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +2 -2
- data/src/core/filter/auth/auth_filters.h +2 -2
- data/src/core/filter/fused_filters.cc +154 -0
- data/src/core/handshaker/security/legacy_secure_endpoint.cc +1 -1
- data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
- data/src/core/handshaker/security/secure_endpoint.cc +28 -13
- data/src/core/handshaker/security/secure_endpoint.h +8 -0
- data/src/core/lib/channel/promise_based_filter.cc +15 -25
- data/src/core/lib/channel/promise_based_filter.h +6 -5
- data/src/core/lib/event_engine/ares_resolver.h +3 -1
- data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -5
- data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -1
- data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +263 -0
- data/src/core/lib/event_engine/cf_engine/cfsocket_listener.h +107 -0
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +31 -3
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +12 -0
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +12 -10
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +6 -4
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +15 -14
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +7 -5
- data/src/core/lib/event_engine/posix_engine/event_poller.h +0 -8
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -5
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
- data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +1 -0
- data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +4 -4
- data/src/core/lib/event_engine/posix_engine/lockfree_event.h +3 -4
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +2 -2
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +188 -199
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +30 -45
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -1
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +1 -1
- data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +2 -1
- data/src/core/lib/experiments/experiments.cc +120 -6
- data/src/core/lib/experiments/experiments.h +46 -3
- data/src/core/lib/iomgr/combiner.cc +1 -1
- data/src/core/lib/iomgr/exec_ctx.h +3 -9
- data/src/core/lib/iomgr/socket_mutator.cc +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.cc +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.h +1 -1
- data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
- data/src/core/lib/iomgr/tcp_posix.cc +3 -3
- data/src/core/lib/promise/activity.h +2 -2
- data/src/core/lib/promise/mpsc.cc +8 -8
- data/src/core/lib/promise/party.cc +7 -7
- data/src/core/lib/promise/party.h +4 -4
- data/src/core/lib/promise/poll.h +10 -0
- data/src/core/lib/resource_quota/memory_quota.cc +90 -3
- data/src/core/lib/resource_quota/memory_quota.h +20 -9
- data/src/core/lib/resource_quota/periodic_update.cc +14 -0
- data/src/core/lib/resource_quota/periodic_update.h +8 -0
- data/src/core/lib/resource_quota/resource_quota.cc +15 -4
- data/src/core/lib/resource_quota/resource_quota.h +3 -0
- data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -2
- data/src/core/lib/surface/call.cc +5 -5
- data/src/core/lib/surface/call.h +6 -5
- data/src/core/lib/surface/completion_queue.cc +2 -4
- data/src/core/lib/surface/filter_stack_call.cc +1 -1
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.h +3 -3
- data/src/core/load_balancing/endpoint_list.cc +29 -2
- data/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +3 -3
- data/src/core/load_balancing/grpclb/client_load_reporting_filter.h +1 -1
- data/src/core/load_balancing/pick_first/pick_first.cc +12 -5
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +5 -3
- data/src/core/net/socket_mutator.cc +19 -0
- data/src/core/net/socket_mutator.h +25 -0
- data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +6 -1
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -1
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +8 -5
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/resolver/xds/xds_dependency_manager.cc +1 -1
- data/src/core/server/server.cc +1 -1
- data/src/core/server/server_call_tracer_filter.cc +0 -66
- data/src/core/server/server_call_tracer_filter.h +64 -0
- data/src/core/server/server_config_selector_filter.cc +1 -1
- data/src/core/service_config/service_config_channel_arg_filter.cc +3 -60
- data/src/core/service_config/service_config_channel_arg_filter.h +82 -0
- data/src/core/telemetry/call_tracer.cc +20 -14
- data/src/core/telemetry/call_tracer.h +22 -17
- data/src/core/telemetry/metrics.h +8 -8
- data/src/core/telemetry/stats_data.cc +151 -151
- data/src/core/telemetry/stats_data.h +87 -87
- data/src/core/transport/auth_context.cc +20 -0
- data/src/core/transport/auth_context.h +4 -0
- data/src/core/transport/auth_context_comparator_registry.h +69 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -3
- data/src/core/tsi/ssl_transport_security.cc +202 -32
- data/src/core/tsi/ssl_transport_security.h +19 -10
- data/src/core/tsi/ssl_transport_security_utils.cc +21 -0
- data/src/core/tsi/ssl_transport_security_utils.h +4 -0
- data/src/core/util/http_client/httpcli_security_connector.cc +3 -1
- data/src/core/util/latent_see.cc +178 -146
- data/src/core/util/latent_see.h +245 -188
- data/src/core/util/single_set_ptr.h +5 -2
- data/src/core/util/useful.h +91 -0
- data/src/core/util/windows/directory_reader.cc +1 -0
- data/src/core/util/windows/thd.cc +1 -3
- data/src/core/util/work_serializer.cc +1 -1
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +32 -5
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +5 -0
- data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/cares/cares/include/ares.h +925 -460
- data/third_party/cares/cares/include/ares_dns.h +86 -71
- data/third_party/cares/cares/include/ares_dns_record.h +1118 -0
- data/third_party/cares/cares/include/ares_nameser.h +215 -189
- data/third_party/cares/cares/include/ares_version.h +37 -14
- data/third_party/cares/cares/src/lib/ares_addrinfo2hostent.c +305 -0
- data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +245 -0
- data/third_party/cares/cares/src/lib/ares_android.c +216 -164
- data/third_party/cares/cares/src/lib/ares_android.h +25 -14
- data/third_party/cares/cares/src/lib/ares_cancel.c +68 -44
- data/third_party/cares/cares/src/lib/ares_close_sockets.c +137 -0
- data/third_party/cares/cares/src/lib/ares_conn.c +511 -0
- data/third_party/cares/cares/src/lib/ares_conn.h +196 -0
- data/third_party/cares/cares/src/lib/ares_cookie.c +461 -0
- data/third_party/cares/cares/src/lib/ares_data.c +93 -181
- data/third_party/cares/cares/src/lib/ares_data.h +50 -39
- data/third_party/cares/cares/src/lib/ares_destroy.c +127 -89
- data/third_party/cares/cares/src/lib/ares_free_hostent.c +35 -24
- data/third_party/cares/cares/src/lib/ares_free_string.c +24 -16
- data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +45 -38
- data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +549 -663
- data/third_party/cares/cares/src/lib/ares_getenv.c +25 -15
- data/third_party/cares/cares/src/lib/ares_getenv.h +26 -18
- data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +163 -221
- data/third_party/cares/cares/src/lib/ares_gethostbyname.c +222 -223
- data/third_party/cares/cares/src/lib/ares_getnameinfo.c +328 -338
- data/third_party/cares/cares/src/lib/ares_hosts_file.c +952 -0
- data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +25 -19
- data/third_party/cares/cares/src/lib/ares_init.c +425 -2091
- data/third_party/cares/cares/src/lib/ares_ipv6.h +63 -33
- data/third_party/cares/cares/src/lib/ares_library_init.c +110 -54
- data/third_party/cares/cares/src/lib/ares_metrics.c +261 -0
- data/third_party/cares/cares/src/lib/ares_options.c +418 -332
- data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +179 -0
- data/third_party/cares/cares/src/lib/ares_private.h +558 -356
- data/third_party/cares/cares/src/lib/ares_process.c +1224 -1369
- data/third_party/cares/cares/src/lib/ares_qcache.c +430 -0
- data/third_party/cares/cares/src/lib/ares_query.c +126 -121
- data/third_party/cares/cares/src/lib/ares_search.c +564 -262
- data/third_party/cares/cares/src/lib/ares_send.c +264 -93
- data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +588 -0
- data/third_party/cares/cares/src/lib/ares_setup.h +115 -111
- data/third_party/cares/cares/src/lib/ares_socket.c +425 -0
- data/third_party/cares/cares/src/lib/ares_socket.h +163 -0
- data/third_party/cares/cares/src/lib/ares_sortaddrinfo.c +447 -0
- data/third_party/cares/cares/src/lib/ares_strerror.c +83 -48
- data/third_party/cares/cares/src/lib/ares_sysconfig.c +639 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +839 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_mac.c +373 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +621 -0
- data/third_party/cares/cares/src/lib/ares_timeout.c +136 -73
- data/third_party/cares/cares/src/lib/ares_update_servers.c +1362 -0
- data/third_party/cares/cares/src/lib/ares_version.c +29 -4
- data/third_party/cares/cares/src/lib/config-dos.h +88 -89
- data/third_party/cares/cares/src/lib/config-win32.h +122 -77
- data/third_party/cares/cares/src/lib/dsa/ares_array.c +394 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable.c +447 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable.h +174 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_asvp.c +224 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +228 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_strvp.c +210 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_szvp.c +188 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- data/third_party/cares/cares/src/lib/dsa/ares_llist.c +382 -0
- data/third_party/cares/cares/src/lib/dsa/ares_slist.c +479 -0
- data/third_party/cares/cares/src/lib/dsa/ares_slist.h +207 -0
- data/third_party/cares/cares/src/lib/event/ares_event.h +191 -0
- data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +743 -0
- data/third_party/cares/cares/src/lib/event/ares_event_epoll.c +192 -0
- data/third_party/cares/cares/src/lib/event/ares_event_kqueue.c +248 -0
- data/third_party/cares/cares/src/lib/event/ares_event_poll.c +140 -0
- data/third_party/cares/cares/src/lib/event/ares_event_select.c +159 -0
- data/third_party/cares/cares/src/lib/event/ares_event_thread.c +567 -0
- data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +166 -0
- data/third_party/cares/cares/src/lib/event/ares_event_win32.c +978 -0
- data/third_party/cares/cares/src/lib/event/ares_event_win32.h +161 -0
- data/third_party/cares/cares/src/lib/include/ares_array.h +276 -0
- data/third_party/cares/cares/src/lib/include/ares_buf.h +732 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_asvp.h +130 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_dict.h +123 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_strvp.h +130 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_szvp.h +118 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_vpstr.h +111 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_vpvp.h +128 -0
- data/third_party/cares/cares/src/lib/include/ares_llist.h +239 -0
- data/third_party/cares/cares/src/lib/include/ares_mem.h +38 -0
- data/third_party/cares/cares/src/lib/include/ares_str.h +244 -0
- data/third_party/cares/cares/src/lib/inet_net_pton.c +202 -157
- data/third_party/cares/cares/src/lib/inet_ntop.c +87 -69
- data/third_party/cares/cares/src/lib/legacy/ares_create_query.c +78 -0
- data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +99 -0
- data/third_party/cares/cares/src/lib/legacy/ares_expand_string.c +107 -0
- data/third_party/cares/cares/src/lib/legacy/ares_fds.c +80 -0
- data/third_party/cares/cares/src/lib/legacy/ares_getsock.c +85 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +982 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +307 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_multistring.h +72 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_name.c +673 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +1329 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_private.h +273 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_record.c +1661 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_write.c +1229 -0
- data/third_party/cares/cares/src/lib/str/ares_buf.c +1498 -0
- data/third_party/cares/cares/src/lib/str/ares_str.c +508 -0
- data/third_party/cares/cares/src/lib/str/ares_strsplit.c +90 -0
- data/third_party/cares/cares/src/lib/str/ares_strsplit.h +51 -0
- data/third_party/cares/cares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +628 -0
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +139 -0
- data/third_party/cares/cares/src/lib/util/ares_math.c +158 -0
- data/third_party/cares/cares/src/lib/util/ares_math.h +45 -0
- data/third_party/cares/cares/src/lib/util/ares_rand.c +389 -0
- data/third_party/cares/cares/src/lib/util/ares_rand.h +36 -0
- data/third_party/cares/cares/src/lib/util/ares_threads.c +614 -0
- data/third_party/cares/cares/src/lib/util/ares_threads.h +60 -0
- data/third_party/cares/cares/src/lib/util/ares_time.h +48 -0
- data/third_party/cares/cares/src/lib/util/ares_timeval.c +95 -0
- data/third_party/cares/cares/src/lib/util/ares_uri.c +1626 -0
- data/third_party/cares/cares/src/lib/util/ares_uri.h +252 -0
- data/third_party/cares/cares/src/lib/windows_port.c +16 -9
- metadata +121 -49
- data/src/core/util/ring_buffer.h +0 -122
- data/third_party/cares/cares/include/ares_rules.h +0 -125
- data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +0 -266
- data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +0 -240
- data/third_party/cares/cares/src/lib/ares__close_sockets.c +0 -61
- data/third_party/cares/cares/src/lib/ares__get_hostent.c +0 -260
- data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +0 -229
- data/third_party/cares/cares/src/lib/ares__read_line.c +0 -73
- data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +0 -258
- data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +0 -507
- data/third_party/cares/cares/src/lib/ares__timeval.c +0 -111
- data/third_party/cares/cares/src/lib/ares_create_query.c +0 -197
- data/third_party/cares/cares/src/lib/ares_expand_name.c +0 -311
- data/third_party/cares/cares/src/lib/ares_expand_string.c +0 -67
- data/third_party/cares/cares/src/lib/ares_fds.c +0 -59
- data/third_party/cares/cares/src/lib/ares_getsock.c +0 -66
- data/third_party/cares/cares/src/lib/ares_iphlpapi.h +0 -221
- data/third_party/cares/cares/src/lib/ares_llist.c +0 -63
- data/third_party/cares/cares/src/lib/ares_llist.h +0 -39
- data/third_party/cares/cares/src/lib/ares_mkquery.c +0 -24
- data/third_party/cares/cares/src/lib/ares_nowarn.c +0 -260
- data/third_party/cares/cares/src/lib/ares_nowarn.h +0 -61
- data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +0 -90
- data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +0 -92
- data/third_party/cares/cares/src/lib/ares_parse_caa_reply.c +0 -199
- data/third_party/cares/cares/src/lib/ares_parse_mx_reply.c +0 -164
- data/third_party/cares/cares/src/lib/ares_parse_naptr_reply.c +0 -183
- data/third_party/cares/cares/src/lib/ares_parse_ns_reply.c +0 -177
- data/third_party/cares/cares/src/lib/ares_parse_ptr_reply.c +0 -228
- data/third_party/cares/cares/src/lib/ares_parse_soa_reply.c +0 -179
- data/third_party/cares/cares/src/lib/ares_parse_srv_reply.c +0 -168
- data/third_party/cares/cares/src/lib/ares_parse_txt_reply.c +0 -214
- data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +0 -184
- data/third_party/cares/cares/src/lib/ares_platform.c +0 -11042
- data/third_party/cares/cares/src/lib/ares_platform.h +0 -43
- data/third_party/cares/cares/src/lib/ares_rand.c +0 -279
- data/third_party/cares/cares/src/lib/ares_strcasecmp.c +0 -66
- data/third_party/cares/cares/src/lib/ares_strcasecmp.h +0 -30
- data/third_party/cares/cares/src/lib/ares_strdup.c +0 -42
- data/third_party/cares/cares/src/lib/ares_strdup.h +0 -24
- data/third_party/cares/cares/src/lib/ares_strsplit.c +0 -94
- data/third_party/cares/cares/src/lib/ares_strsplit.h +0 -42
- data/third_party/cares/cares/src/lib/ares_writev.c +0 -79
- data/third_party/cares/cares/src/lib/ares_writev.h +0 -36
- data/third_party/cares/cares/src/lib/bitncmp.c +0 -59
- data/third_party/cares/cares/src/lib/bitncmp.h +0 -26
- data/third_party/cares/cares/src/lib/setup_once.h +0 -554
- data/third_party/cares/cares/src/tools/ares_getopt.h +0 -53
@@ -0,0 +1,673 @@
|
|
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
|
+
|
28
|
+
typedef struct {
|
29
|
+
char *name;
|
30
|
+
size_t name_len;
|
31
|
+
size_t idx;
|
32
|
+
} ares_nameoffset_t;
|
33
|
+
|
34
|
+
static void ares_nameoffset_free(void *arg)
|
35
|
+
{
|
36
|
+
ares_nameoffset_t *off = arg;
|
37
|
+
if (off == NULL) {
|
38
|
+
return; /* LCOV_EXCL_LINE: DefensiveCoding */
|
39
|
+
}
|
40
|
+
ares_free(off->name);
|
41
|
+
ares_free(off);
|
42
|
+
}
|
43
|
+
|
44
|
+
static ares_status_t ares_nameoffset_create(ares_llist_t **list,
|
45
|
+
const char *name, size_t idx)
|
46
|
+
{
|
47
|
+
ares_status_t status;
|
48
|
+
ares_nameoffset_t *off = NULL;
|
49
|
+
|
50
|
+
if (list == NULL || name == NULL || ares_strlen(name) == 0 ||
|
51
|
+
ares_strlen(name) > 255) {
|
52
|
+
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
|
53
|
+
}
|
54
|
+
|
55
|
+
if (*list == NULL) {
|
56
|
+
*list = ares_llist_create(ares_nameoffset_free);
|
57
|
+
}
|
58
|
+
if (*list == NULL) {
|
59
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
60
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
61
|
+
}
|
62
|
+
|
63
|
+
off = ares_malloc_zero(sizeof(*off));
|
64
|
+
if (off == NULL) {
|
65
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
66
|
+
}
|
67
|
+
|
68
|
+
off->name = ares_strdup(name);
|
69
|
+
off->name_len = ares_strlen(off->name);
|
70
|
+
off->idx = idx;
|
71
|
+
|
72
|
+
if (ares_llist_insert_last(*list, off) == NULL) {
|
73
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
74
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
75
|
+
}
|
76
|
+
|
77
|
+
return ARES_SUCCESS;
|
78
|
+
|
79
|
+
/* LCOV_EXCL_START: OutOfMemory */
|
80
|
+
fail:
|
81
|
+
ares_nameoffset_free(off);
|
82
|
+
return status;
|
83
|
+
/* LCOV_EXCL_STOP */
|
84
|
+
}
|
85
|
+
|
86
|
+
static const ares_nameoffset_t *ares_nameoffset_find(ares_llist_t *list,
|
87
|
+
const char *name)
|
88
|
+
{
|
89
|
+
size_t name_len = ares_strlen(name);
|
90
|
+
ares_llist_node_t *node;
|
91
|
+
const ares_nameoffset_t *longest_match = NULL;
|
92
|
+
|
93
|
+
if (list == NULL || name == NULL || name_len == 0) {
|
94
|
+
return NULL;
|
95
|
+
}
|
96
|
+
|
97
|
+
for (node = ares_llist_node_first(list); node != NULL;
|
98
|
+
node = ares_llist_node_next(node)) {
|
99
|
+
const ares_nameoffset_t *val = ares_llist_node_val(node);
|
100
|
+
size_t prefix_len;
|
101
|
+
|
102
|
+
/* Can't be a match if the stored name is longer */
|
103
|
+
if (val->name_len > name_len) {
|
104
|
+
continue;
|
105
|
+
}
|
106
|
+
|
107
|
+
/* Can't be the longest match if our existing longest match is longer */
|
108
|
+
if (longest_match != NULL && longest_match->name_len > val->name_len) {
|
109
|
+
continue;
|
110
|
+
}
|
111
|
+
|
112
|
+
prefix_len = name_len - val->name_len;
|
113
|
+
|
114
|
+
/* Due to DNS 0x20, lets not inadvertently mangle things, use case-sensitive
|
115
|
+
* matching instead of case-insensitive. This may result in slightly
|
116
|
+
* larger DNS queries overall. */
|
117
|
+
if (!ares_streq(val->name, name + prefix_len)) {
|
118
|
+
continue;
|
119
|
+
}
|
120
|
+
|
121
|
+
/* We need to make sure if `val->name` is "example.com" that name is
|
122
|
+
* is separated by a label, e.g. "myexample.com" is not ok, however
|
123
|
+
* "my.example.com" is, so we look for the preceding "." */
|
124
|
+
if (prefix_len != 0 && name[prefix_len - 1] != '.') {
|
125
|
+
continue;
|
126
|
+
}
|
127
|
+
|
128
|
+
longest_match = val;
|
129
|
+
}
|
130
|
+
|
131
|
+
return longest_match;
|
132
|
+
}
|
133
|
+
|
134
|
+
static void ares_dns_labels_free_cb(void *arg)
|
135
|
+
{
|
136
|
+
ares_buf_t **buf = arg;
|
137
|
+
if (buf == NULL) {
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
|
141
|
+
ares_buf_destroy(*buf);
|
142
|
+
}
|
143
|
+
|
144
|
+
static ares_buf_t *ares_dns_labels_add(ares_array_t *labels)
|
145
|
+
{
|
146
|
+
ares_buf_t **buf;
|
147
|
+
|
148
|
+
if (labels == NULL) {
|
149
|
+
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
|
150
|
+
}
|
151
|
+
|
152
|
+
if (ares_array_insert_last((void **)&buf, labels) != ARES_SUCCESS) {
|
153
|
+
return NULL;
|
154
|
+
}
|
155
|
+
|
156
|
+
*buf = ares_buf_create();
|
157
|
+
if (*buf == NULL) {
|
158
|
+
ares_array_remove_last(labels);
|
159
|
+
return NULL;
|
160
|
+
}
|
161
|
+
|
162
|
+
return *buf;
|
163
|
+
}
|
164
|
+
|
165
|
+
static ares_buf_t *ares_dns_labels_get_last(ares_array_t *labels)
|
166
|
+
{
|
167
|
+
ares_buf_t **buf = ares_array_last(labels);
|
168
|
+
|
169
|
+
if (buf == NULL) {
|
170
|
+
return NULL;
|
171
|
+
}
|
172
|
+
|
173
|
+
return *buf;
|
174
|
+
}
|
175
|
+
|
176
|
+
static ares_buf_t *ares_dns_labels_get_at(ares_array_t *labels, size_t idx)
|
177
|
+
{
|
178
|
+
ares_buf_t **buf = ares_array_at(labels, idx);
|
179
|
+
|
180
|
+
if (buf == NULL) {
|
181
|
+
return NULL;
|
182
|
+
}
|
183
|
+
|
184
|
+
return *buf;
|
185
|
+
}
|
186
|
+
|
187
|
+
static void ares_dns_name_labels_del_last(ares_array_t *labels)
|
188
|
+
{
|
189
|
+
ares_array_remove_last(labels);
|
190
|
+
}
|
191
|
+
|
192
|
+
static ares_status_t ares_parse_dns_name_escape(ares_buf_t *namebuf,
|
193
|
+
ares_buf_t *label,
|
194
|
+
ares_bool_t validate_hostname)
|
195
|
+
{
|
196
|
+
ares_status_t status;
|
197
|
+
unsigned char c;
|
198
|
+
|
199
|
+
status = ares_buf_fetch_bytes(namebuf, &c, 1);
|
200
|
+
if (status != ARES_SUCCESS) {
|
201
|
+
return ARES_EBADNAME;
|
202
|
+
}
|
203
|
+
|
204
|
+
/* If next character is a digit, read 2 more digits */
|
205
|
+
if (ares_isdigit(c)) {
|
206
|
+
size_t i;
|
207
|
+
unsigned int val = 0;
|
208
|
+
|
209
|
+
val = c - '0';
|
210
|
+
|
211
|
+
for (i = 0; i < 2; i++) {
|
212
|
+
status = ares_buf_fetch_bytes(namebuf, &c, 1);
|
213
|
+
if (status != ARES_SUCCESS) {
|
214
|
+
return ARES_EBADNAME;
|
215
|
+
}
|
216
|
+
|
217
|
+
if (!ares_isdigit(c)) {
|
218
|
+
return ARES_EBADNAME;
|
219
|
+
}
|
220
|
+
val *= 10;
|
221
|
+
val += c - '0';
|
222
|
+
}
|
223
|
+
|
224
|
+
/* Out of range */
|
225
|
+
if (val > 255) {
|
226
|
+
return ARES_EBADNAME;
|
227
|
+
}
|
228
|
+
|
229
|
+
if (validate_hostname && !ares_is_hostnamech((unsigned char)val)) {
|
230
|
+
return ARES_EBADNAME;
|
231
|
+
}
|
232
|
+
|
233
|
+
return ares_buf_append_byte(label, (unsigned char)val);
|
234
|
+
}
|
235
|
+
|
236
|
+
/* We can just output the character */
|
237
|
+
if (validate_hostname && !ares_is_hostnamech(c)) {
|
238
|
+
return ARES_EBADNAME;
|
239
|
+
}
|
240
|
+
|
241
|
+
return ares_buf_append_byte(label, c);
|
242
|
+
}
|
243
|
+
|
244
|
+
static ares_status_t ares_split_dns_name(ares_array_t *labels,
|
245
|
+
ares_bool_t validate_hostname,
|
246
|
+
const char *name)
|
247
|
+
{
|
248
|
+
ares_status_t status;
|
249
|
+
ares_buf_t *label = NULL;
|
250
|
+
ares_buf_t *namebuf = NULL;
|
251
|
+
size_t i;
|
252
|
+
size_t total_len = 0;
|
253
|
+
unsigned char c;
|
254
|
+
|
255
|
+
if (name == NULL || labels == NULL) {
|
256
|
+
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
|
257
|
+
}
|
258
|
+
|
259
|
+
/* Put name into a buffer for parsing */
|
260
|
+
namebuf = ares_buf_create();
|
261
|
+
if (namebuf == NULL) {
|
262
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
263
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
264
|
+
}
|
265
|
+
|
266
|
+
if (*name != '\0') {
|
267
|
+
status =
|
268
|
+
ares_buf_append(namebuf, (const unsigned char *)name, ares_strlen(name));
|
269
|
+
if (status != ARES_SUCCESS) {
|
270
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
/* Start with 1 label */
|
275
|
+
label = ares_dns_labels_add(labels);
|
276
|
+
if (label == NULL) {
|
277
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
278
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
279
|
+
}
|
280
|
+
|
281
|
+
while (ares_buf_fetch_bytes(namebuf, &c, 1) == ARES_SUCCESS) {
|
282
|
+
/* New label */
|
283
|
+
if (c == '.') {
|
284
|
+
label = ares_dns_labels_add(labels);
|
285
|
+
if (label == NULL) {
|
286
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
287
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
288
|
+
}
|
289
|
+
continue;
|
290
|
+
}
|
291
|
+
|
292
|
+
/* Escape */
|
293
|
+
if (c == '\\') {
|
294
|
+
status = ares_parse_dns_name_escape(namebuf, label, validate_hostname);
|
295
|
+
if (status != ARES_SUCCESS) {
|
296
|
+
goto done;
|
297
|
+
}
|
298
|
+
continue;
|
299
|
+
}
|
300
|
+
|
301
|
+
/* Output direct character */
|
302
|
+
if (validate_hostname && !ares_is_hostnamech(c)) {
|
303
|
+
status = ARES_EBADNAME;
|
304
|
+
goto done;
|
305
|
+
}
|
306
|
+
|
307
|
+
status = ares_buf_append_byte(label, c);
|
308
|
+
if (status != ARES_SUCCESS) {
|
309
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
/* Remove trailing blank label */
|
314
|
+
if (ares_buf_len(ares_dns_labels_get_last(labels)) == 0) {
|
315
|
+
ares_dns_name_labels_del_last(labels);
|
316
|
+
}
|
317
|
+
|
318
|
+
/* If someone passed in "." there could have been 2 blank labels, check for
|
319
|
+
* that */
|
320
|
+
if (ares_array_len(labels) == 1 &&
|
321
|
+
ares_buf_len(ares_dns_labels_get_last(labels)) == 0) {
|
322
|
+
ares_dns_name_labels_del_last(labels);
|
323
|
+
}
|
324
|
+
|
325
|
+
/* Scan to make sure label lengths are valid */
|
326
|
+
for (i = 0; i < ares_array_len(labels); i++) {
|
327
|
+
const ares_buf_t *buf = ares_dns_labels_get_at(labels, i);
|
328
|
+
size_t len = ares_buf_len(buf);
|
329
|
+
/* No 0-length labels, and no labels over 63 bytes */
|
330
|
+
if (len == 0 || len > 63) {
|
331
|
+
status = ARES_EBADNAME;
|
332
|
+
goto done;
|
333
|
+
}
|
334
|
+
total_len += len;
|
335
|
+
}
|
336
|
+
|
337
|
+
/* Can't exceed maximum (unescaped) length */
|
338
|
+
if (ares_array_len(labels) && total_len + ares_array_len(labels) - 1 > 255) {
|
339
|
+
status = ARES_EBADNAME;
|
340
|
+
goto done;
|
341
|
+
}
|
342
|
+
|
343
|
+
status = ARES_SUCCESS;
|
344
|
+
|
345
|
+
done:
|
346
|
+
ares_buf_destroy(namebuf);
|
347
|
+
return status;
|
348
|
+
}
|
349
|
+
|
350
|
+
ares_status_t ares_dns_name_write(ares_buf_t *buf, ares_llist_t **list,
|
351
|
+
ares_bool_t validate_hostname,
|
352
|
+
const char *name)
|
353
|
+
{
|
354
|
+
const ares_nameoffset_t *off = NULL;
|
355
|
+
size_t name_len;
|
356
|
+
size_t orig_name_len;
|
357
|
+
size_t pos = ares_buf_len(buf);
|
358
|
+
ares_array_t *labels = NULL;
|
359
|
+
char name_copy[512];
|
360
|
+
ares_status_t status;
|
361
|
+
|
362
|
+
if (buf == NULL || name == NULL) {
|
363
|
+
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
|
364
|
+
}
|
365
|
+
|
366
|
+
labels = ares_array_create(sizeof(ares_buf_t *), ares_dns_labels_free_cb);
|
367
|
+
if (labels == NULL) {
|
368
|
+
return ARES_ENOMEM;
|
369
|
+
}
|
370
|
+
|
371
|
+
/* NOTE: due to possible escaping, name_copy buffer is > 256 to allow for
|
372
|
+
* this */
|
373
|
+
name_len = ares_strcpy(name_copy, name, sizeof(name_copy));
|
374
|
+
orig_name_len = name_len;
|
375
|
+
|
376
|
+
/* Find longest match */
|
377
|
+
if (list != NULL) {
|
378
|
+
off = ares_nameoffset_find(*list, name_copy);
|
379
|
+
if (off != NULL && off->name_len != name_len) {
|
380
|
+
/* truncate */
|
381
|
+
name_len -= (off->name_len + 1);
|
382
|
+
name_copy[name_len] = 0;
|
383
|
+
}
|
384
|
+
}
|
385
|
+
|
386
|
+
/* Output labels */
|
387
|
+
if (off == NULL || off->name_len != orig_name_len) {
|
388
|
+
size_t i;
|
389
|
+
|
390
|
+
status = ares_split_dns_name(labels, validate_hostname, name_copy);
|
391
|
+
if (status != ARES_SUCCESS) {
|
392
|
+
goto done;
|
393
|
+
}
|
394
|
+
|
395
|
+
for (i = 0; i < ares_array_len(labels); i++) {
|
396
|
+
size_t len = 0;
|
397
|
+
const ares_buf_t *lbuf = ares_dns_labels_get_at(labels, i);
|
398
|
+
const unsigned char *ptr = ares_buf_peek(lbuf, &len);
|
399
|
+
|
400
|
+
status = ares_buf_append_byte(buf, (unsigned char)(len & 0xFF));
|
401
|
+
if (status != ARES_SUCCESS) {
|
402
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
403
|
+
}
|
404
|
+
|
405
|
+
status = ares_buf_append(buf, ptr, len);
|
406
|
+
if (status != ARES_SUCCESS) {
|
407
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
408
|
+
}
|
409
|
+
}
|
410
|
+
|
411
|
+
/* If we are NOT jumping to another label, output terminator */
|
412
|
+
if (off == NULL) {
|
413
|
+
status = ares_buf_append_byte(buf, 0);
|
414
|
+
if (status != ARES_SUCCESS) {
|
415
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
416
|
+
}
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
/* Output name compression offset jump */
|
421
|
+
if (off != NULL) {
|
422
|
+
unsigned short u16 =
|
423
|
+
(unsigned short)0xC000 | (unsigned short)(off->idx & 0x3FFF);
|
424
|
+
status = ares_buf_append_be16(buf, u16);
|
425
|
+
if (status != ARES_SUCCESS) {
|
426
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
427
|
+
}
|
428
|
+
}
|
429
|
+
|
430
|
+
/* Store pointer for future jumps as long as its not an exact match for
|
431
|
+
* a prior entry */
|
432
|
+
if (list != NULL && (off == NULL || off->name_len != orig_name_len) &&
|
433
|
+
name_len > 0) {
|
434
|
+
status = ares_nameoffset_create(list, name /* not truncated copy! */, pos);
|
435
|
+
if (status != ARES_SUCCESS) {
|
436
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
status = ARES_SUCCESS;
|
441
|
+
|
442
|
+
done:
|
443
|
+
ares_array_destroy(labels);
|
444
|
+
return status;
|
445
|
+
}
|
446
|
+
|
447
|
+
/* Reserved characters for names that need to be escaped */
|
448
|
+
static ares_bool_t is_reservedch(int ch)
|
449
|
+
{
|
450
|
+
switch (ch) {
|
451
|
+
case '"':
|
452
|
+
case '.':
|
453
|
+
case ';':
|
454
|
+
case '\\':
|
455
|
+
case '(':
|
456
|
+
case ')':
|
457
|
+
case '@':
|
458
|
+
case '$':
|
459
|
+
return ARES_TRUE;
|
460
|
+
default:
|
461
|
+
break;
|
462
|
+
}
|
463
|
+
|
464
|
+
return ARES_FALSE;
|
465
|
+
}
|
466
|
+
|
467
|
+
static ares_status_t ares_fetch_dnsname_into_buf(ares_buf_t *buf,
|
468
|
+
ares_buf_t *dest, size_t len,
|
469
|
+
ares_bool_t is_hostname)
|
470
|
+
{
|
471
|
+
size_t remaining_len;
|
472
|
+
const unsigned char *ptr = ares_buf_peek(buf, &remaining_len);
|
473
|
+
ares_status_t status;
|
474
|
+
size_t i;
|
475
|
+
|
476
|
+
if (buf == NULL || len == 0 || remaining_len < len) {
|
477
|
+
return ARES_EBADRESP;
|
478
|
+
}
|
479
|
+
|
480
|
+
for (i = 0; i < len; i++) {
|
481
|
+
unsigned char c = ptr[i];
|
482
|
+
|
483
|
+
/* Hostnames have a very specific allowed character set. Anything outside
|
484
|
+
* of that (non-printable and reserved included) are disallowed */
|
485
|
+
if (is_hostname && !ares_is_hostnamech(c)) {
|
486
|
+
status = ARES_EBADRESP;
|
487
|
+
goto fail;
|
488
|
+
}
|
489
|
+
|
490
|
+
/* NOTE: dest may be NULL if the user is trying to skip the name. validation
|
491
|
+
* still occurs above. */
|
492
|
+
if (dest == NULL) {
|
493
|
+
continue;
|
494
|
+
}
|
495
|
+
|
496
|
+
/* Non-printable characters need to be output as \DDD */
|
497
|
+
if (!ares_isprint(c)) {
|
498
|
+
unsigned char escape[4];
|
499
|
+
|
500
|
+
escape[0] = '\\';
|
501
|
+
escape[1] = '0' + (c / 100);
|
502
|
+
escape[2] = '0' + ((c % 100) / 10);
|
503
|
+
escape[3] = '0' + (c % 10);
|
504
|
+
|
505
|
+
status = ares_buf_append(dest, escape, sizeof(escape));
|
506
|
+
if (status != ARES_SUCCESS) {
|
507
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
508
|
+
}
|
509
|
+
|
510
|
+
continue;
|
511
|
+
}
|
512
|
+
|
513
|
+
/* Reserved characters need to be escaped, otherwise normal */
|
514
|
+
if (is_reservedch(c)) {
|
515
|
+
status = ares_buf_append_byte(dest, '\\');
|
516
|
+
if (status != ARES_SUCCESS) {
|
517
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
518
|
+
}
|
519
|
+
}
|
520
|
+
|
521
|
+
status = ares_buf_append_byte(dest, c);
|
522
|
+
if (status != ARES_SUCCESS) {
|
523
|
+
return status; /* LCOV_EXCL_LINE: OutOfMemory */
|
524
|
+
}
|
525
|
+
}
|
526
|
+
|
527
|
+
return ares_buf_consume(buf, len);
|
528
|
+
|
529
|
+
fail:
|
530
|
+
return status;
|
531
|
+
}
|
532
|
+
|
533
|
+
ares_status_t ares_dns_name_parse(ares_buf_t *buf, char **name,
|
534
|
+
ares_bool_t is_hostname)
|
535
|
+
{
|
536
|
+
size_t save_offset = 0;
|
537
|
+
unsigned char c;
|
538
|
+
ares_status_t status;
|
539
|
+
ares_buf_t *namebuf = NULL;
|
540
|
+
size_t label_start = ares_buf_get_position(buf);
|
541
|
+
|
542
|
+
if (buf == NULL) {
|
543
|
+
return ARES_EFORMERR;
|
544
|
+
}
|
545
|
+
|
546
|
+
if (name != NULL) {
|
547
|
+
namebuf = ares_buf_create();
|
548
|
+
if (namebuf == NULL) {
|
549
|
+
status = ARES_ENOMEM;
|
550
|
+
goto fail;
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
/* The compression scheme allows a domain name in a message to be
|
555
|
+
* represented as either:
|
556
|
+
*
|
557
|
+
* - a sequence of labels ending in a zero octet
|
558
|
+
* - a pointer
|
559
|
+
* - a sequence of labels ending with a pointer
|
560
|
+
*/
|
561
|
+
while (1) {
|
562
|
+
/* Keep track of the minimum label starting position to prevent forward
|
563
|
+
* jumping */
|
564
|
+
if (label_start > ares_buf_get_position(buf)) {
|
565
|
+
label_start = ares_buf_get_position(buf);
|
566
|
+
}
|
567
|
+
|
568
|
+
status = ares_buf_fetch_bytes(buf, &c, 1);
|
569
|
+
if (status != ARES_SUCCESS) {
|
570
|
+
goto fail;
|
571
|
+
}
|
572
|
+
|
573
|
+
/* Pointer/Redirect */
|
574
|
+
if ((c & 0xc0) == 0xc0) {
|
575
|
+
/* The pointer takes the form of a two octet sequence:
|
576
|
+
*
|
577
|
+
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
578
|
+
* | 1 1| OFFSET |
|
579
|
+
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
580
|
+
*
|
581
|
+
* The first two bits are ones. This allows a pointer to be distinguished
|
582
|
+
* from a label, since the label must begin with two zero bits because
|
583
|
+
* labels are restricted to 63 octets or less. (The 10 and 01
|
584
|
+
* combinations are reserved for future use.) The OFFSET field specifies
|
585
|
+
* an offset from the start of the message (i.e., the first octet of the
|
586
|
+
* ID field in the domain header). A zero offset specifies the first byte
|
587
|
+
* of the ID field, etc.
|
588
|
+
*/
|
589
|
+
size_t offset = (size_t)((c & 0x3F) << 8);
|
590
|
+
|
591
|
+
/* Fetch second byte of the redirect length */
|
592
|
+
status = ares_buf_fetch_bytes(buf, &c, 1);
|
593
|
+
if (status != ARES_SUCCESS) {
|
594
|
+
goto fail;
|
595
|
+
}
|
596
|
+
|
597
|
+
offset |= ((size_t)c);
|
598
|
+
|
599
|
+
/* According to RFC 1035 4.1.4:
|
600
|
+
* In this scheme, an entire domain name or a list of labels at
|
601
|
+
* the end of a domain name is replaced with a pointer to a prior
|
602
|
+
* occurrence of the same name.
|
603
|
+
* Note the word "prior", meaning it must go backwards. This was
|
604
|
+
* confirmed via the ISC BIND code that it also prevents forward
|
605
|
+
* pointers.
|
606
|
+
*/
|
607
|
+
if (offset >= label_start) {
|
608
|
+
status = ARES_EBADNAME;
|
609
|
+
goto fail;
|
610
|
+
}
|
611
|
+
|
612
|
+
/* First time we make a jump, save the current position */
|
613
|
+
if (save_offset == 0) {
|
614
|
+
save_offset = ares_buf_get_position(buf);
|
615
|
+
}
|
616
|
+
|
617
|
+
status = ares_buf_set_position(buf, offset);
|
618
|
+
if (status != ARES_SUCCESS) {
|
619
|
+
status = ARES_EBADNAME;
|
620
|
+
goto fail;
|
621
|
+
}
|
622
|
+
|
623
|
+
continue;
|
624
|
+
} else if ((c & 0xc0) != 0) {
|
625
|
+
/* 10 and 01 are reserved */
|
626
|
+
status = ARES_EBADNAME;
|
627
|
+
goto fail;
|
628
|
+
} else if (c == 0) {
|
629
|
+
/* termination via zero octet*/
|
630
|
+
break;
|
631
|
+
}
|
632
|
+
|
633
|
+
/* New label */
|
634
|
+
|
635
|
+
/* Labels are separated by periods */
|
636
|
+
if (ares_buf_len(namebuf) != 0 && name != NULL) {
|
637
|
+
status = ares_buf_append_byte(namebuf, '.');
|
638
|
+
if (status != ARES_SUCCESS) {
|
639
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
640
|
+
}
|
641
|
+
}
|
642
|
+
|
643
|
+
status = ares_fetch_dnsname_into_buf(buf, namebuf, c, is_hostname);
|
644
|
+
if (status != ARES_SUCCESS) {
|
645
|
+
goto fail;
|
646
|
+
}
|
647
|
+
}
|
648
|
+
|
649
|
+
/* Restore offset read after first redirect/pointer as this is where the DNS
|
650
|
+
* message continues */
|
651
|
+
if (save_offset) {
|
652
|
+
ares_buf_set_position(buf, save_offset);
|
653
|
+
}
|
654
|
+
|
655
|
+
if (name != NULL) {
|
656
|
+
*name = ares_buf_finish_str(namebuf, NULL);
|
657
|
+
if (*name == NULL) {
|
658
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
659
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
660
|
+
}
|
661
|
+
}
|
662
|
+
|
663
|
+
return ARES_SUCCESS;
|
664
|
+
|
665
|
+
fail:
|
666
|
+
/* We want badname response if we couldn't parse */
|
667
|
+
if (status == ARES_EBADRESP) {
|
668
|
+
status = ARES_EBADNAME;
|
669
|
+
}
|
670
|
+
|
671
|
+
ares_buf_destroy(namebuf);
|
672
|
+
return status;
|
673
|
+
}
|