grpc 1.6.7 → 1.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +579 -77
- data/include/grpc/byte_buffer.h +1 -63
- data/include/grpc/compression.h +27 -5
- data/include/grpc/fork.h +24 -0
- data/include/grpc/grpc.h +12 -6
- data/include/grpc/grpc_security.h +28 -7
- data/include/grpc/impl/codegen/atm.h +1 -0
- data/include/grpc/impl/codegen/byte_buffer.h +86 -0
- data/include/grpc/impl/codegen/compression_types.h +63 -5
- data/include/grpc/impl/codegen/fork.h +48 -0
- data/include/grpc/impl/codegen/grpc_types.h +26 -9
- data/include/grpc/impl/codegen/port_platform.h +11 -4
- data/include/grpc/impl/codegen/slice.h +6 -1
- data/include/grpc/impl/codegen/sync.h +3 -1
- data/include/grpc/impl/codegen/sync_custom.h +36 -0
- data/include/grpc/module.modulemap +75 -3
- data/include/grpc/slice.h +1 -5
- data/include/grpc/support/sync_custom.h +24 -0
- data/src/core/ext/census/base_resources.c +14 -14
- data/src/core/ext/census/context.c +7 -5
- data/src/core/ext/census/grpc_filter.c +12 -14
- data/src/core/ext/census/mlog.c +2 -1
- data/src/core/ext/census/resource.c +13 -9
- data/src/core/ext/filters/client_channel/channel_connectivity.c +15 -8
- data/src/core/ext/filters/client_channel/client_channel.c +418 -439
- data/src/core/ext/filters/client_channel/client_channel_factory.c +4 -5
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +2 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.c +7 -5
- data/src/core/ext/filters/client_channel/http_proxy.c +17 -21
- data/src/core/ext/filters/client_channel/lb_policy.c +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +7 -7
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +371 -257
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +7 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +25 -14
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +16 -16
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +33 -28
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +10 -8
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +7 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +62 -28
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +29 -23
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.c +25 -14
- data/src/core/ext/filters/client_channel/retry_throttle.c +9 -6
- data/src/core/ext/filters/client_channel/subchannel.c +30 -30
- data/src/core/ext/filters/client_channel/subchannel.h +1 -4
- data/src/core/ext/filters/client_channel/subchannel_index.c +31 -15
- data/src/core/ext/filters/client_channel/subchannel_index.h +7 -0
- data/src/core/ext/filters/client_channel/uri_parser.c +4 -3
- data/src/core/ext/filters/deadline/deadline_filter.c +78 -39
- data/src/core/ext/filters/deadline/deadline_filter.h +7 -1
- data/src/core/ext/filters/http/client/http_client_filter.c +14 -14
- data/src/core/ext/filters/http/http_filters_plugin.c +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.c +240 -175
- data/src/core/ext/filters/http/server/http_server_filter.c +48 -36
- data/src/core/ext/filters/load_reporting/{load_reporting_filter.c → server_load_reporting_filter.c} +11 -12
- data/src/core/ext/filters/load_reporting/{load_reporting_filter.h → server_load_reporting_filter.h} +6 -5
- data/src/core/ext/filters/load_reporting/{load_reporting.c → server_load_reporting_plugin.c} +19 -13
- data/src/core/ext/filters/load_reporting/{load_reporting.h → server_load_reporting_plugin.h} +4 -3
- data/src/core/ext/filters/max_age/max_age_filter.c +2 -3
- data/src/core/ext/filters/message_size/message_size_filter.c +4 -2
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +0 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +5 -5
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +20 -18
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +1 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +493 -210
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.c +9 -8
- data/src/core/ext/transport/chttp2/transport/frame_data.c +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +5 -4
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +10 -9
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +9 -5
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +62 -41
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +52 -8
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +3 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +60 -30
- data/src/core/ext/transport/chttp2/transport/parsing.c +16 -5
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -16
- data/src/core/ext/transport/chttp2/transport/stream_map.c +6 -4
- data/src/core/ext/transport/chttp2/transport/writing.c +133 -105
- data/src/core/ext/transport/inproc/inproc_transport.c +61 -65
- data/src/core/lib/channel/channel_args.c +112 -12
- data/src/core/lib/channel/channel_args.h +31 -0
- data/src/core/lib/channel/channel_stack.c +1 -15
- data/src/core/lib/channel/channel_stack.h +3 -10
- data/src/core/lib/channel/channel_stack_builder.c +41 -10
- data/src/core/lib/channel/channel_stack_builder.h +10 -0
- data/src/core/lib/channel/connected_channel.c +94 -23
- data/src/core/lib/channel/handshaker.c +8 -6
- data/src/core/lib/channel/handshaker_registry.c +1 -1
- data/src/core/lib/compression/algorithm_metadata.h +14 -0
- data/src/core/lib/compression/compression.c +101 -1
- data/src/core/lib/compression/stream_compression.c +32 -146
- data/src/core/lib/compression/stream_compression.h +28 -4
- data/src/core/lib/compression/stream_compression_gzip.c +228 -0
- data/src/core/lib/{iomgr/ev_epoll_thread_pool_linux.h → compression/stream_compression_gzip.h} +5 -7
- data/src/core/lib/compression/stream_compression_identity.c +94 -0
- data/src/core/lib/{iomgr/ev_epoll_limited_pollers_linux.h → compression/stream_compression_identity.h} +7 -8
- data/src/core/lib/debug/stats.c +174 -0
- data/src/core/lib/debug/stats.h +61 -0
- data/src/core/lib/debug/stats_data.c +687 -0
- data/src/core/lib/debug/stats_data.h +470 -0
- data/src/core/lib/debug/trace.c +3 -3
- data/src/core/lib/debug/trace.h +1 -1
- data/src/core/lib/http/format_request.c +1 -1
- data/src/core/lib/http/httpcli.c +8 -7
- data/src/core/lib/http/httpcli_security_connector.c +2 -1
- data/src/core/lib/http/parser.c +4 -3
- data/src/core/lib/iomgr/call_combiner.c +202 -0
- data/src/core/lib/iomgr/call_combiner.h +121 -0
- data/src/core/lib/iomgr/closure.c +18 -4
- data/src/core/lib/iomgr/combiner.c +11 -4
- data/src/core/lib/iomgr/error.c +26 -24
- data/src/core/lib/iomgr/ev_epoll1_linux.c +395 -212
- data/src/core/lib/iomgr/ev_epollex_linux.c +141 -128
- data/src/core/lib/iomgr/ev_epollsig_linux.c +44 -41
- data/src/core/lib/iomgr/ev_poll_posix.c +99 -75
- data/src/core/lib/iomgr/ev_posix.c +5 -9
- data/src/core/lib/iomgr/ev_posix.h +1 -1
- data/src/core/lib/iomgr/exec_ctx.h +6 -1
- data/src/core/lib/iomgr/executor.c +142 -36
- data/src/core/lib/iomgr/executor.h +6 -1
- data/src/core/lib/iomgr/fork_posix.c +88 -0
- data/src/core/lib/iomgr/fork_windows.c +39 -0
- data/src/core/lib/iomgr/iocp_windows.c +2 -0
- data/src/core/lib/iomgr/iomgr.c +2 -8
- data/src/core/lib/iomgr/is_epollexclusive_available.c +6 -6
- data/src/core/lib/iomgr/load_file.c +2 -1
- data/src/core/lib/iomgr/polling_entity.c +9 -9
- data/src/core/lib/iomgr/polling_entity.h +7 -1
- data/src/core/lib/iomgr/pollset.h +1 -1
- data/src/core/lib/iomgr/pollset_uv.c +1 -1
- data/src/core/lib/iomgr/pollset_windows.c +3 -3
- data/src/core/lib/iomgr/port.h +4 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +8 -7
- data/src/core/lib/iomgr/resolve_address_windows.c +1 -1
- data/src/core/lib/iomgr/resource_quota.c +24 -19
- data/src/core/lib/iomgr/socket_factory_posix.c +4 -4
- data/src/core/lib/iomgr/socket_mutator.c +4 -4
- data/src/core/lib/iomgr/socket_utils_windows.c +0 -4
- data/src/core/lib/iomgr/tcp_client_posix.c +5 -4
- data/src/core/lib/iomgr/tcp_posix.c +181 -20
- data/src/core/lib/iomgr/tcp_server_posix.c +8 -7
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +1 -1
- data/src/core/lib/iomgr/timer.h +4 -0
- data/src/core/lib/iomgr/timer_generic.c +138 -3
- data/src/core/lib/iomgr/timer_generic.h +3 -0
- data/src/core/lib/iomgr/timer_heap.c +4 -4
- data/src/core/lib/iomgr/timer_manager.c +2 -2
- data/src/core/lib/iomgr/timer_uv.c +2 -0
- data/src/core/lib/iomgr/udp_server.c +10 -8
- data/src/core/lib/iomgr/unix_sockets_posix.c +4 -2
- data/src/core/lib/iomgr/wakeup_fd_cv.c +9 -8
- data/src/core/lib/iomgr/wakeup_fd_cv.h +2 -2
- data/src/core/lib/json/json.c +1 -1
- data/src/core/lib/json/json_string.c +13 -13
- data/src/core/lib/profiling/timers.h +18 -8
- data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -10
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +2 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +11 -6
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +4 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +132 -50
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
- data/src/core/lib/security/transport/client_auth_filter.c +68 -135
- data/src/core/lib/security/transport/secure_endpoint.c +110 -90
- data/src/core/lib/security/transport/secure_endpoint.h +8 -3
- data/src/core/lib/security/transport/security_connector.c +10 -12
- data/src/core/lib/security/transport/security_handshaker.c +45 -24
- data/src/core/lib/security/transport/server_auth_filter.c +71 -20
- data/src/core/lib/slice/b64.c +2 -2
- data/src/core/lib/slice/slice.c +16 -14
- data/src/core/lib/slice/slice_buffer.c +5 -4
- data/src/core/lib/slice/slice_hash_table.c +3 -2
- data/src/core/lib/slice/slice_intern.c +8 -5
- data/src/core/lib/support/block_annotate.h +22 -0
- data/src/core/lib/support/fork.c +62 -0
- data/src/core/lib/support/fork.h +35 -0
- data/src/core/lib/support/log_linux.c +1 -1
- data/src/core/lib/support/string.c +15 -1
- data/src/core/lib/support/string.h +3 -0
- data/src/core/lib/support/thd_internal.h +6 -0
- data/src/core/lib/support/thd_posix.c +56 -0
- data/src/core/lib/support/thd_windows.c +2 -0
- data/src/core/lib/surface/alarm.c +22 -15
- data/src/core/lib/surface/byte_buffer.c +4 -2
- data/src/core/lib/surface/call.c +442 -141
- data/src/core/lib/surface/call.h +6 -6
- data/src/core/lib/surface/call_log_batch.c +1 -1
- data/src/core/lib/surface/call_test_only.h +12 -0
- data/src/core/lib/surface/channel.c +39 -4
- data/src/core/lib/surface/channel_init.c +6 -6
- data/src/core/lib/surface/channel_ping.c +2 -2
- data/src/core/lib/surface/completion_queue.c +56 -57
- data/src/core/lib/surface/init.c +17 -3
- data/src/core/lib/surface/init_secure.c +5 -1
- data/src/core/lib/surface/lame_client.cc +9 -10
- data/src/core/lib/surface/server.c +81 -72
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/byte_stream.c +1 -0
- data/src/core/lib/transport/byte_stream.h +3 -1
- data/src/core/lib/transport/connectivity_state.c +2 -1
- data/src/core/lib/transport/metadata.c +7 -4
- data/src/core/lib/transport/metadata_batch.c +18 -16
- data/src/core/lib/transport/metadata_batch.h +1 -0
- data/src/core/lib/transport/service_config.c +5 -3
- data/src/core/lib/transport/static_metadata.c +395 -614
- data/src/core/lib/transport/static_metadata.h +165 -133
- data/src/core/lib/transport/status_conversion.c +1 -1
- data/src/core/lib/transport/transport.c +20 -20
- data/src/core/lib/transport/transport.h +8 -5
- data/src/core/lib/transport/transport_impl.h +0 -3
- data/src/core/lib/transport/transport_op_string.c +8 -1
- data/src/core/plugin_registry/grpc_plugin_registry.c +4 -4
- data/src/core/tsi/fake_transport_security.c +133 -2
- data/src/core/tsi/fake_transport_security.h +5 -0
- data/src/core/tsi/ssl_transport_security.c +105 -8
- data/src/core/tsi/ssl_transport_security.h +30 -7
- data/src/core/tsi/transport_security.h +8 -2
- data/src/core/tsi/transport_security_grpc.c +20 -13
- data/src/core/tsi/transport_security_grpc.h +13 -9
- data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
- data/src/ruby/ext/grpc/rb_grpc.c +1 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
- data/src/ruby/lib/grpc.rb +1 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
- data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
- data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
- data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
- data/src/ruby/spec/channel_connection_spec.rb +1 -34
- data/src/ruby/spec/client_server_spec.rb +188 -82
- data/src/ruby/spec/generic/active_call_spec.rb +65 -11
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/spec_helper.rb +4 -0
- data/src/ruby/spec/support/helpers.rb +73 -0
- data/src/ruby/spec/support/services.rb +147 -0
- data/third_party/cares/ares_build.h +21 -62
- data/third_party/cares/cares/ares.h +23 -1
- data/third_party/cares/cares/ares__close_sockets.c +2 -2
- data/third_party/cares/cares/ares_create_query.c +3 -3
- data/third_party/cares/cares/ares_expand_name.c +6 -2
- data/third_party/cares/cares/ares_expand_string.c +1 -1
- data/third_party/cares/cares/ares_getnameinfo.c +27 -7
- data/third_party/cares/cares/ares_init.c +407 -39
- data/third_party/cares/cares/ares_library_init.c +10 -0
- data/third_party/cares/cares/ares_library_init.h +2 -1
- data/third_party/cares/cares/ares_nowarn.c +6 -6
- data/third_party/cares/cares/ares_nowarn.h +2 -2
- data/third_party/cares/cares/ares_parse_naptr_reply.c +6 -1
- data/third_party/cares/cares/ares_private.h +11 -0
- data/third_party/cares/cares/ares_process.c +126 -37
- data/third_party/cares/cares/ares_version.h +2 -2
- data/third_party/cares/cares/ares_writev.c +2 -2
- data/third_party/cares/cares/config-win32.h +8 -34
- data/third_party/cares/cares/inet_net_pton.c +2 -2
- data/third_party/cares/cares/setup_once.h +5 -5
- data/third_party/cares/config_darwin/ares_config.h +98 -196
- data/third_party/cares/config_linux/ares_config.h +103 -203
- metadata +47 -20
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +0 -1957
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +0 -1182
@@ -83,148 +83,88 @@
|
|
83
83
|
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
|
84
84
|
/* ================================================================ */
|
85
85
|
|
86
|
-
#ifdef CARES_SIZEOF_LONG
|
87
|
-
# error "CARES_SIZEOF_LONG shall not be defined except in ares_build.h"
|
88
|
-
Error Compilation_aborted_CARES_SIZEOF_LONG_already_defined
|
89
|
-
#endif
|
90
|
-
|
91
86
|
#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
|
92
87
|
# error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
|
93
88
|
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
|
94
89
|
#endif
|
95
90
|
|
96
|
-
#ifdef CARES_SIZEOF_ARES_SOCKLEN_T
|
97
|
-
# error "CARES_SIZEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
|
98
|
-
Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_already_defined
|
99
|
-
#endif
|
100
|
-
|
101
91
|
/* ================================================================ */
|
102
92
|
/* EXTERNAL INTERFACE SETTINGS FOR NON-CONFIGURE SYSTEMS ONLY */
|
103
93
|
/* ================================================================ */
|
104
94
|
|
105
95
|
#if defined(__DJGPP__) || defined(__GO32__)
|
106
|
-
# define CARES_SIZEOF_LONG 4
|
107
96
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
108
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
109
97
|
|
110
98
|
#elif defined(__SALFORDC__)
|
111
|
-
# define CARES_SIZEOF_LONG 4
|
112
99
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
113
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
114
100
|
|
115
101
|
#elif defined(__BORLANDC__)
|
116
|
-
# define CARES_SIZEOF_LONG 4
|
117
102
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
118
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
119
103
|
|
120
104
|
#elif defined(__TURBOC__)
|
121
|
-
# define CARES_SIZEOF_LONG 4
|
122
105
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
123
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
124
106
|
|
125
107
|
#elif defined(__WATCOMC__)
|
126
|
-
# define CARES_SIZEOF_LONG 4
|
127
108
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
128
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
129
109
|
|
130
110
|
#elif defined(__POCC__)
|
131
|
-
# define CARES_SIZEOF_LONG 4
|
132
111
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
133
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
134
112
|
|
135
113
|
#elif defined(__LCC__)
|
136
|
-
# define CARES_SIZEOF_LONG 4
|
137
114
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
138
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
139
115
|
|
140
116
|
#elif defined(__SYMBIAN32__)
|
141
|
-
# define CARES_SIZEOF_LONG 4
|
142
117
|
# define CARES_TYPEOF_ARES_SOCKLEN_T unsigned int
|
143
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
144
118
|
|
145
119
|
#elif defined(__MWERKS__)
|
146
|
-
# define CARES_SIZEOF_LONG 4
|
147
120
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
148
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
149
121
|
|
150
122
|
#elif defined(_WIN32_WCE)
|
151
|
-
# define CARES_SIZEOF_LONG 4
|
152
123
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
153
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
154
124
|
|
155
125
|
#elif defined(__MINGW32__)
|
156
|
-
# define CARES_SIZEOF_LONG 4
|
157
126
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
158
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
159
127
|
|
160
128
|
#elif defined(__VMS)
|
161
|
-
# define CARES_SIZEOF_LONG 4
|
162
129
|
# define CARES_TYPEOF_ARES_SOCKLEN_T unsigned int
|
163
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
164
130
|
|
165
131
|
#elif defined(__OS400__)
|
166
132
|
# if defined(__ILEC400__)
|
167
|
-
# define CARES_SIZEOF_LONG 4
|
168
133
|
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
169
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
170
134
|
# define CARES_PULL_SYS_TYPES_H 1
|
171
135
|
# define CARES_PULL_SYS_SOCKET_H 1
|
172
136
|
# endif
|
173
137
|
|
174
138
|
#elif defined(__MVS__)
|
175
139
|
# if defined(__IBMC__) || defined(__IBMCPP__)
|
176
|
-
# if defined(_ILP32)
|
177
|
-
# define CARES_SIZEOF_LONG 4
|
178
|
-
# elif defined(_LP64)
|
179
|
-
# define CARES_SIZEOF_LONG 8
|
180
|
-
# endif
|
181
140
|
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
182
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
183
141
|
# define CARES_PULL_SYS_TYPES_H 1
|
184
142
|
# define CARES_PULL_SYS_SOCKET_H 1
|
185
143
|
# endif
|
186
144
|
|
187
145
|
#elif defined(__370__)
|
188
146
|
# if defined(__IBMC__) || defined(__IBMCPP__)
|
189
|
-
# if defined(_ILP32)
|
190
|
-
# define CARES_SIZEOF_LONG 4
|
191
|
-
# elif defined(_LP64)
|
192
|
-
# define CARES_SIZEOF_LONG 8
|
193
|
-
# endif
|
194
147
|
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
195
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
196
148
|
# define CARES_PULL_SYS_TYPES_H 1
|
197
149
|
# define CARES_PULL_SYS_SOCKET_H 1
|
198
150
|
# endif
|
199
151
|
|
200
152
|
#elif defined(TPF)
|
201
|
-
# define CARES_SIZEOF_LONG 8
|
202
153
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
203
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
204
154
|
|
205
155
|
/* ===================================== */
|
206
156
|
/* KEEP MSVC THE PENULTIMATE ENTRY */
|
207
157
|
/* ===================================== */
|
208
158
|
|
209
159
|
#elif defined(_MSC_VER)
|
210
|
-
# define CARES_SIZEOF_LONG 4
|
211
160
|
# define CARES_TYPEOF_ARES_SOCKLEN_T int
|
212
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
213
161
|
|
214
162
|
/* ===================================== */
|
215
163
|
/* KEEP GENERIC GCC THE LAST ENTRY */
|
216
164
|
/* ===================================== */
|
217
165
|
|
218
166
|
#elif defined(__GNUC__)
|
219
|
-
# if defined(__LP64__) || \
|
220
|
-
defined(__x86_64__) || defined(__ppc64__)
|
221
|
-
# define CARES_SIZEOF_LONG 8
|
222
|
-
# elif defined(__ILP32__) || \
|
223
|
-
defined(__i386__) || defined(__ppc__) || defined(__arm__)
|
224
|
-
# define CARES_SIZEOF_LONG 4
|
225
|
-
# endif
|
226
167
|
# define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
|
227
|
-
# define CARES_SIZEOF_ARES_SOCKLEN_T 4
|
228
168
|
# define CARES_PULL_SYS_TYPES_H 1
|
229
169
|
# define CARES_PULL_SYS_SOCKET_H 1
|
230
170
|
|
@@ -251,8 +191,27 @@
|
|
251
191
|
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
|
252
192
|
#endif
|
253
193
|
|
254
|
-
/*
|
255
|
-
/*
|
194
|
+
/* Data type definition of ares_ssize_t. */
|
195
|
+
/* gRPC Manuel edit here!
|
196
|
+
* Possibly include <_mingw.h> header to define __int64 type under mingw */
|
197
|
+
#ifdef _WIN32
|
198
|
+
# ifdef _WIN64
|
199
|
+
# ifdef __MINGW32__
|
200
|
+
# include <_mingw.h>
|
201
|
+
# endif
|
202
|
+
# define CARES_TYPEOF_ARES_SSIZE_T __int64
|
203
|
+
# else
|
204
|
+
# define CARES_TYPEOF_ARES_SSIZE_T long
|
205
|
+
# endif
|
206
|
+
#else
|
207
|
+
# define CARES_TYPEOF_ARES_SSIZE_T ssize_t
|
208
|
+
#endif
|
209
|
+
|
210
|
+
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
|
211
|
+
|
212
|
+
/* IMPORTANT: gRPC MANUAL EDIT HERE!
|
213
|
+
* Undefine UNICODE, as c-ares does not use the ANSI version of functions
|
214
|
+
* explicitly. */
|
256
215
|
#ifdef UNICODE
|
257
216
|
# undef UNICODE
|
258
217
|
#endif
|
@@ -38,7 +38,8 @@
|
|
38
38
|
require it! */
|
39
39
|
#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
|
40
40
|
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
|
41
|
-
defined(ANDROID) || defined(__ANDROID__)
|
41
|
+
defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
|
42
|
+
defined(__QNXNTO__)
|
42
43
|
#include <sys/select.h>
|
43
44
|
#endif
|
44
45
|
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
|
@@ -356,6 +357,27 @@ CARES_EXTERN void ares_set_socket_configure_callback(ares_channel channel,
|
|
356
357
|
CARES_EXTERN int ares_set_sortlist(ares_channel channel,
|
357
358
|
const char *sortstr);
|
358
359
|
|
360
|
+
/*
|
361
|
+
* Virtual function set to have user-managed socket IO.
|
362
|
+
* Note that all functions need to be defined, and when
|
363
|
+
* set, the library will not do any bind nor set any
|
364
|
+
* socket options, assuming the client handles these
|
365
|
+
* through either socket creation or the
|
366
|
+
* ares_sock_config_callback call.
|
367
|
+
*/
|
368
|
+
struct iovec;
|
369
|
+
struct ares_socket_functions {
|
370
|
+
ares_socket_t(*asocket)(int, int, int, void *);
|
371
|
+
int(*aclose)(ares_socket_t, void *);
|
372
|
+
int(*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *);
|
373
|
+
ares_ssize_t(*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *);
|
374
|
+
ares_ssize_t(*asendv)(ares_socket_t, const struct iovec *, int, void *);
|
375
|
+
};
|
376
|
+
|
377
|
+
CARES_EXTERN void ares_set_socket_functions(ares_channel channel,
|
378
|
+
const struct ares_socket_functions * funcs,
|
379
|
+
void *user_data);
|
380
|
+
|
359
381
|
CARES_EXTERN void ares_send(ares_channel channel,
|
360
382
|
const unsigned char *qbuf,
|
361
383
|
int qlen,
|
@@ -48,14 +48,14 @@ void ares__close_sockets(ares_channel channel, struct server_state *server)
|
|
48
48
|
if (server->tcp_socket != ARES_SOCKET_BAD)
|
49
49
|
{
|
50
50
|
SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0);
|
51
|
-
|
51
|
+
ares__socket_close(channel, server->tcp_socket);
|
52
52
|
server->tcp_socket = ARES_SOCKET_BAD;
|
53
53
|
server->tcp_connection_generation = ++channel->tcp_connection_generation;
|
54
54
|
}
|
55
55
|
if (server->udp_socket != ARES_SOCKET_BAD)
|
56
56
|
{
|
57
57
|
SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0);
|
58
|
-
|
58
|
+
ares__socket_close(channel, server->udp_socket);
|
59
59
|
server->udp_socket = ARES_SOCKET_BAD;
|
60
60
|
}
|
61
61
|
}
|
@@ -134,7 +134,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
|
|
134
134
|
while (*name)
|
135
135
|
{
|
136
136
|
if (*name == '.') {
|
137
|
-
|
137
|
+
ares_free (buf);
|
138
138
|
return ARES_EBADNAME;
|
139
139
|
}
|
140
140
|
|
@@ -147,7 +147,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
|
|
147
147
|
len++;
|
148
148
|
}
|
149
149
|
if (len > MAXLABEL) {
|
150
|
-
|
150
|
+
ares_free (buf);
|
151
151
|
return ARES_EBADNAME;
|
152
152
|
}
|
153
153
|
|
@@ -190,7 +190,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
|
|
190
190
|
* to 255 octets or less."). */
|
191
191
|
if (buflen > (MAXCDNAME + HFIXEDSZ + QFIXEDSZ +
|
192
192
|
(max_udp_size ? EDNSFIXEDSZ : 0))) {
|
193
|
-
|
193
|
+
ares_free (buf);
|
194
194
|
return ARES_EBADNAME;
|
195
195
|
}
|
196
196
|
|
@@ -32,6 +32,9 @@
|
|
32
32
|
#include "ares_nowarn.h"
|
33
33
|
#include "ares_private.h" /* for the memdebug */
|
34
34
|
|
35
|
+
/* Maximum number of indirections allowed for a name */
|
36
|
+
#define MAX_INDIRS 50
|
37
|
+
|
35
38
|
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
|
36
39
|
int alen);
|
37
40
|
|
@@ -66,7 +69,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
|
|
66
69
|
char *q;
|
67
70
|
const unsigned char *p;
|
68
71
|
union {
|
69
|
-
|
72
|
+
ares_ssize_t sig;
|
70
73
|
size_t uns;
|
71
74
|
} nlen;
|
72
75
|
|
@@ -162,7 +165,8 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
|
|
162
165
|
/* If we've seen more indirects than the message length,
|
163
166
|
* then there's a loop.
|
164
167
|
*/
|
165
|
-
|
168
|
+
++indir;
|
169
|
+
if (indir > alen || indir > MAX_INDIRS)
|
166
170
|
return -1;
|
167
171
|
}
|
168
172
|
else if (top == 0x00)
|
@@ -356,12 +356,9 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
|
|
356
356
|
#ifdef HAVE_IF_INDEXTONAME
|
357
357
|
int is_ll, is_mcll;
|
358
358
|
#endif
|
359
|
-
static const char fmt_u[] = "%u";
|
360
|
-
static const char fmt_lu[] = "%lu";
|
361
359
|
char tmpbuf[IF_NAMESIZE + 2];
|
362
360
|
size_t bufl;
|
363
|
-
|
364
|
-
fmt_lu:fmt_u;
|
361
|
+
int is_scope_long = sizeof(addr6->sin6_scope_id) > sizeof(unsigned int);
|
365
362
|
|
366
363
|
tmpbuf[0] = '%';
|
367
364
|
|
@@ -371,15 +368,38 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
|
|
371
368
|
if ((flags & ARES_NI_NUMERICSCOPE) ||
|
372
369
|
(!is_ll && !is_mcll))
|
373
370
|
{
|
374
|
-
|
371
|
+
if (is_scope_long)
|
372
|
+
{
|
373
|
+
sprintf(&tmpbuf[1], "%lu", (unsigned long)addr6->sin6_scope_id);
|
374
|
+
}
|
375
|
+
else
|
376
|
+
{
|
377
|
+
sprintf(&tmpbuf[1], "%u", (unsigned int)addr6->sin6_scope_id);
|
378
|
+
}
|
375
379
|
}
|
376
380
|
else
|
377
381
|
{
|
378
382
|
if (if_indextoname(addr6->sin6_scope_id, &tmpbuf[1]) == NULL)
|
379
|
-
|
383
|
+
{
|
384
|
+
if (is_scope_long)
|
385
|
+
{
|
386
|
+
sprintf(&tmpbuf[1], "%lu", (unsigned long)addr6->sin6_scope_id);
|
387
|
+
}
|
388
|
+
else
|
389
|
+
{
|
390
|
+
sprintf(&tmpbuf[1], "%u", (unsigned int)addr6->sin6_scope_id);
|
391
|
+
}
|
392
|
+
}
|
380
393
|
}
|
381
394
|
#else
|
382
|
-
|
395
|
+
if (is_scope_long)
|
396
|
+
{
|
397
|
+
sprintf(&tmpbuf[1], "%lu", (unsigned long)addr6->sin6_scope_id);
|
398
|
+
}
|
399
|
+
else
|
400
|
+
{
|
401
|
+
sprintf(&tmpbuf[1], "%u", (unsigned int)addr6->sin6_scope_id);
|
402
|
+
}
|
383
403
|
(void) flags;
|
384
404
|
#endif
|
385
405
|
tmpbuf[IF_NAMESIZE + 1] = '\0';
|
@@ -84,7 +84,7 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
|
|
84
84
|
const char *str);
|
85
85
|
static int sortlist_alloc(struct apattern **sortlist, int *nsort,
|
86
86
|
struct apattern *pat);
|
87
|
-
static int ip_addr(const char *s,
|
87
|
+
static int ip_addr(const char *s, ares_ssize_t len, struct in_addr *addr);
|
88
88
|
static void natural_mask(struct apattern *pat);
|
89
89
|
#if !defined(WIN32) && !defined(WATT32) && \
|
90
90
|
!defined(ANDROID) && !defined(__ANDROID__) && !defined(CARES_USE_LIBRESOLV)
|
@@ -166,6 +166,8 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
|
|
166
166
|
channel->sock_create_cb_data = NULL;
|
167
167
|
channel->sock_config_cb = NULL;
|
168
168
|
channel->sock_config_cb_data = NULL;
|
169
|
+
channel->sock_funcs = NULL;
|
170
|
+
channel->sock_func_cb_data = NULL;
|
169
171
|
|
170
172
|
channel->last_server = 0;
|
171
173
|
channel->last_timeout_processed = (time_t)now.tv_sec;
|
@@ -292,6 +294,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
|
|
292
294
|
(*dest)->sock_create_cb_data = src->sock_create_cb_data;
|
293
295
|
(*dest)->sock_config_cb = src->sock_config_cb;
|
294
296
|
(*dest)->sock_config_cb_data = src->sock_config_cb_data;
|
297
|
+
(*dest)->sock_funcs = src->sock_funcs;
|
298
|
+
(*dest)->sock_func_cb_data = src->sock_func_cb_data;
|
295
299
|
|
296
300
|
strncpy((*dest)->local_dev_name, src->local_dev_name,
|
297
301
|
sizeof(src->local_dev_name));
|
@@ -828,6 +832,24 @@ static int get_DNS_Registry(char **outptr)
|
|
828
832
|
return 1;
|
829
833
|
}
|
830
834
|
|
835
|
+
static void commanjoin(char** dst, const char* const src, const size_t len)
|
836
|
+
{
|
837
|
+
char *newbuf;
|
838
|
+
size_t newsize;
|
839
|
+
|
840
|
+
/* 1 for terminating 0 and 2 for , and terminating 0 */
|
841
|
+
newsize = len + (*dst ? (strlen(*dst) + 2) : 1);
|
842
|
+
newbuf = ares_realloc(*dst, newsize);
|
843
|
+
if (!newbuf)
|
844
|
+
return;
|
845
|
+
if (*dst == NULL)
|
846
|
+
*newbuf = '\0';
|
847
|
+
*dst = newbuf;
|
848
|
+
if (strlen(*dst) != 0)
|
849
|
+
strcat(*dst, ",");
|
850
|
+
strncat(*dst, src, len);
|
851
|
+
}
|
852
|
+
|
831
853
|
/*
|
832
854
|
* commajoin()
|
833
855
|
*
|
@@ -835,24 +857,7 @@ static int get_DNS_Registry(char **outptr)
|
|
835
857
|
*/
|
836
858
|
static void commajoin(char **dst, const char *src)
|
837
859
|
{
|
838
|
-
|
839
|
-
|
840
|
-
if (*dst)
|
841
|
-
{
|
842
|
-
tmp = ares_malloc(strlen(*dst) + strlen(src) + 2);
|
843
|
-
if (!tmp)
|
844
|
-
return;
|
845
|
-
sprintf(tmp, "%s,%s", *dst, src);
|
846
|
-
ares_free(*dst);
|
847
|
-
*dst = tmp;
|
848
|
-
}
|
849
|
-
else
|
850
|
-
{
|
851
|
-
*dst = ares_malloc(strlen(src) + 1);
|
852
|
-
if (!*dst)
|
853
|
-
return;
|
854
|
-
strcpy(*dst, src);
|
855
|
-
}
|
860
|
+
commanjoin(dst, src, strlen(src));
|
856
861
|
}
|
857
862
|
|
858
863
|
/*
|
@@ -939,6 +944,116 @@ done:
|
|
939
944
|
return 1;
|
940
945
|
}
|
941
946
|
|
947
|
+
static BOOL ares_IsWindowsVistaOrGreater(void)
|
948
|
+
{
|
949
|
+
OSVERSIONINFO vinfo;
|
950
|
+
memset(&vinfo, 0, sizeof(vinfo));
|
951
|
+
vinfo.dwOSVersionInfoSize = sizeof(vinfo);
|
952
|
+
if (!GetVersionEx(&vinfo) || vinfo.dwMajorVersion < 6)
|
953
|
+
return FALSE;
|
954
|
+
return TRUE;
|
955
|
+
}
|
956
|
+
|
957
|
+
/* A structure to hold the string form of IPv4 and IPv6 addresses so we can
|
958
|
+
* sort them by a metric.
|
959
|
+
*/
|
960
|
+
typedef struct
|
961
|
+
{
|
962
|
+
/* The metric we sort them by. */
|
963
|
+
ULONG metric;
|
964
|
+
|
965
|
+
/* Room enough for the string form of any IPv4 or IPv6 address that
|
966
|
+
* ares_inet_ntop() will create. Based on the existing c-ares practice.
|
967
|
+
*/
|
968
|
+
char text[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
|
969
|
+
} Address;
|
970
|
+
|
971
|
+
/* Sort Address values \a left and \a right by metric, returning the usual
|
972
|
+
* indicators for qsort().
|
973
|
+
*/
|
974
|
+
static int compareAddresses(const void *arg1,
|
975
|
+
const void *arg2)
|
976
|
+
{
|
977
|
+
const Address * const left = arg1;
|
978
|
+
const Address * const right = arg2;
|
979
|
+
if(left->metric < right->metric) return -1;
|
980
|
+
if(left->metric > right->metric) return 1;
|
981
|
+
return 0;
|
982
|
+
}
|
983
|
+
|
984
|
+
/* There can be multiple routes to "the Internet". And there can be different
|
985
|
+
* DNS servers associated with each of the interfaces that offer those routes.
|
986
|
+
* We have to assume that any DNS server can serve any request. But, some DNS
|
987
|
+
* servers may only respond if requested over their associated interface. But
|
988
|
+
* we also want to use "the preferred route to the Internet" whenever possible
|
989
|
+
* (and not use DNS servers on a non-preferred route even by forcing request
|
990
|
+
* to go out on the associated non-preferred interface). i.e. We want to use
|
991
|
+
* the DNS servers associated with the same interface that we would use to
|
992
|
+
* make a general request to anything else.
|
993
|
+
*
|
994
|
+
* But, Windows won't sort the DNS servers by the metrics associated with the
|
995
|
+
* routes and interfaces _even_ though it obviously sends IP packets based on
|
996
|
+
* those same routes and metrics. So, we must do it ourselves.
|
997
|
+
*
|
998
|
+
* So, we sort the DNS servers by the same metric values used to determine how
|
999
|
+
* an outgoing IP packet will go, thus effectively using the DNS servers
|
1000
|
+
* associated with the interface that the DNS requests themselves will
|
1001
|
+
* travel. This gives us optimal routing and avoids issues where DNS servers
|
1002
|
+
* won't respond to requests that don't arrive via some specific subnetwork
|
1003
|
+
* (and thus some specific interface).
|
1004
|
+
*
|
1005
|
+
* This function computes the metric we use to sort. On the interface
|
1006
|
+
* identified by \a luid, it determines the best route to \a dest and combines
|
1007
|
+
* that route's metric with \a interfaceMetric to compute a metric for the
|
1008
|
+
* destination address on that interface. This metric can be used as a weight
|
1009
|
+
* to sort the DNS server addresses associated with each interface (lower is
|
1010
|
+
* better).
|
1011
|
+
*
|
1012
|
+
* Note that by restricting the route search to the specific interface with
|
1013
|
+
* which the DNS servers are associated, this function asks the question "What
|
1014
|
+
* is the metric for sending IP packets to this DNS server?" which allows us
|
1015
|
+
* to sort the DNS servers correctly.
|
1016
|
+
*/
|
1017
|
+
static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */
|
1018
|
+
const SOCKADDR_INET * const dest,
|
1019
|
+
const ULONG interfaceMetric)
|
1020
|
+
{
|
1021
|
+
/* On this interface, get the best route to that destination. */
|
1022
|
+
MIB_IPFORWARD_ROW2 row;
|
1023
|
+
SOCKADDR_INET ignored;
|
1024
|
+
if(!ares_fpGetBestRoute2 ||
|
1025
|
+
ares_fpGetBestRoute2(/* The interface to use. The index is ignored since we are
|
1026
|
+
* passing a LUID.
|
1027
|
+
*/
|
1028
|
+
luid, 0,
|
1029
|
+
/* No specific source address. */
|
1030
|
+
NULL,
|
1031
|
+
/* Our destination address. */
|
1032
|
+
dest,
|
1033
|
+
/* No options. */
|
1034
|
+
0,
|
1035
|
+
/* The route row. */
|
1036
|
+
&row,
|
1037
|
+
/* The best source address, which we don't need. */
|
1038
|
+
&ignored) != NO_ERROR
|
1039
|
+
/* If the metric is "unused" (-1) or too large for us to add the two
|
1040
|
+
* metrics, use the worst possible, thus sorting this last.
|
1041
|
+
*/
|
1042
|
+
|| row.Metric == (ULONG)-1
|
1043
|
+
|| row.Metric > ((ULONG)-1) - interfaceMetric) {
|
1044
|
+
/* Return the worst possible metric. */
|
1045
|
+
return (ULONG)-1;
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
/* Return the metric value from that row, plus the interface metric.
|
1049
|
+
*
|
1050
|
+
* See
|
1051
|
+
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa814494(v=vs.85).aspx
|
1052
|
+
* which describes the combination as a "sum".
|
1053
|
+
*/
|
1054
|
+
return row.Metric + interfaceMetric;
|
1055
|
+
}
|
1056
|
+
|
942
1057
|
/*
|
943
1058
|
* get_DNS_AdaptersAddresses()
|
944
1059
|
*
|
@@ -965,14 +1080,19 @@ static int get_DNS_AdaptersAddresses(char **outptr)
|
|
965
1080
|
int trying = IPAA_MAX_TRIES;
|
966
1081
|
int res;
|
967
1082
|
|
1083
|
+
/* The capacity of addresses, in elements. */
|
1084
|
+
size_t addressesSize;
|
1085
|
+
/* The number of elements in addresses. */
|
1086
|
+
size_t addressesIndex = 0;
|
1087
|
+
/* The addresses we will sort. */
|
1088
|
+
Address *addresses;
|
1089
|
+
|
968
1090
|
union {
|
969
1091
|
struct sockaddr *sa;
|
970
1092
|
struct sockaddr_in *sa4;
|
971
1093
|
struct sockaddr_in6 *sa6;
|
972
1094
|
} namesrvr;
|
973
1095
|
|
974
|
-
char txtaddr[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
|
975
|
-
|
976
1096
|
*outptr = NULL;
|
977
1097
|
|
978
1098
|
/* Verify run-time availability of GetAdaptersAddresses() */
|
@@ -983,6 +1103,17 @@ static int get_DNS_AdaptersAddresses(char **outptr)
|
|
983
1103
|
if (!ipaa)
|
984
1104
|
return 0;
|
985
1105
|
|
1106
|
+
/* Start with enough room for a few DNS server addresses and we'll grow it
|
1107
|
+
* as we encounter more.
|
1108
|
+
*/
|
1109
|
+
addressesSize = 4;
|
1110
|
+
addresses = (Address*)ares_malloc(sizeof(Address) * addressesSize);
|
1111
|
+
if(addresses == NULL) {
|
1112
|
+
/* We need room for at least some addresses to function. */
|
1113
|
+
ares_free(ipaa);
|
1114
|
+
return 0;
|
1115
|
+
}
|
1116
|
+
|
986
1117
|
/* Usually this call suceeds with initial buffer size */
|
987
1118
|
res = (*ares_fpGetAdaptersAddresses) (AF_UNSPEC, AddrFlags, NULL,
|
988
1119
|
ipaa, &ReqBufsz);
|
@@ -1012,6 +1143,12 @@ static int get_DNS_AdaptersAddresses(char **outptr)
|
|
1012
1143
|
if(ipaaEntry->OperStatus != IfOperStatusUp)
|
1013
1144
|
continue;
|
1014
1145
|
|
1146
|
+
/* For each interface, find any associated DNS servers as IPv4 or IPv6
|
1147
|
+
* addresses. For each found address, find the best route to that DNS
|
1148
|
+
* server address _on_ _that_ _interface_ (at this moment in time) and
|
1149
|
+
* compute the resulting total metric, just as Windows routing will do.
|
1150
|
+
* Then, sort all the addresses found by the metric.
|
1151
|
+
*/
|
1015
1152
|
for (ipaDNSAddr = ipaaEntry->FirstDnsServerAddress;
|
1016
1153
|
ipaDNSAddr;
|
1017
1154
|
ipaDNSAddr = ipaDNSAddr->Next)
|
@@ -1023,35 +1160,117 @@ static int get_DNS_AdaptersAddresses(char **outptr)
|
|
1023
1160
|
if ((namesrvr.sa4->sin_addr.S_un.S_addr == INADDR_ANY) ||
|
1024
1161
|
(namesrvr.sa4->sin_addr.S_un.S_addr == INADDR_NONE))
|
1025
1162
|
continue;
|
1163
|
+
|
1164
|
+
/* Allocate room for another address, if necessary, else skip. */
|
1165
|
+
if(addressesIndex == addressesSize) {
|
1166
|
+
const size_t newSize = addressesSize + 4;
|
1167
|
+
Address * const newMem =
|
1168
|
+
(Address*)ares_realloc(addresses, sizeof(Address) * newSize);
|
1169
|
+
if(newMem == NULL) {
|
1170
|
+
continue;
|
1171
|
+
}
|
1172
|
+
addresses = newMem;
|
1173
|
+
addressesSize = newSize;
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
/* Vista required for Luid or Ipv4Metric */
|
1177
|
+
if (ares_IsWindowsVistaOrGreater())
|
1178
|
+
{
|
1179
|
+
/* Save the address as the next element in addresses. */
|
1180
|
+
addresses[addressesIndex].metric =
|
1181
|
+
getBestRouteMetric(&ipaaEntry->Luid,
|
1182
|
+
(SOCKADDR_INET*)(namesrvr.sa),
|
1183
|
+
ipaaEntry->Ipv4Metric);
|
1184
|
+
}
|
1185
|
+
else
|
1186
|
+
{
|
1187
|
+
addresses[addressesIndex].metric = -1;
|
1188
|
+
}
|
1189
|
+
|
1026
1190
|
if (! ares_inet_ntop(AF_INET, &namesrvr.sa4->sin_addr,
|
1027
|
-
|
1191
|
+
addresses[addressesIndex].text,
|
1192
|
+
sizeof(addresses[0].text))) {
|
1028
1193
|
continue;
|
1194
|
+
}
|
1195
|
+
++addressesIndex;
|
1029
1196
|
}
|
1030
1197
|
else if (namesrvr.sa->sa_family == AF_INET6)
|
1031
1198
|
{
|
1032
1199
|
if (memcmp(&namesrvr.sa6->sin6_addr, &ares_in6addr_any,
|
1033
1200
|
sizeof(namesrvr.sa6->sin6_addr)) == 0)
|
1034
1201
|
continue;
|
1202
|
+
|
1203
|
+
/* Allocate room for another address, if necessary, else skip. */
|
1204
|
+
if(addressesIndex == addressesSize) {
|
1205
|
+
const size_t newSize = addressesSize + 4;
|
1206
|
+
Address * const newMem =
|
1207
|
+
(Address*)ares_realloc(addresses, sizeof(Address) * newSize);
|
1208
|
+
if(newMem == NULL) {
|
1209
|
+
continue;
|
1210
|
+
}
|
1211
|
+
addresses = newMem;
|
1212
|
+
addressesSize = newSize;
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
/* Vista required for Luid or Ipv4Metric */
|
1216
|
+
if (ares_IsWindowsVistaOrGreater())
|
1217
|
+
{
|
1218
|
+
/* Save the address as the next element in addresses. */
|
1219
|
+
addresses[addressesIndex].metric =
|
1220
|
+
getBestRouteMetric(&ipaaEntry->Luid,
|
1221
|
+
(SOCKADDR_INET*)(namesrvr.sa),
|
1222
|
+
ipaaEntry->Ipv6Metric);
|
1223
|
+
}
|
1224
|
+
else
|
1225
|
+
{
|
1226
|
+
addresses[addressesIndex].metric = -1;
|
1227
|
+
}
|
1228
|
+
|
1035
1229
|
if (! ares_inet_ntop(AF_INET6, &namesrvr.sa6->sin6_addr,
|
1036
|
-
|
1230
|
+
addresses[addressesIndex].text,
|
1231
|
+
sizeof(addresses[0].text))) {
|
1037
1232
|
continue;
|
1233
|
+
}
|
1234
|
+
++addressesIndex;
|
1038
1235
|
}
|
1039
|
-
else
|
1236
|
+
else {
|
1237
|
+
/* Skip non-IPv4/IPv6 addresses completely. */
|
1040
1238
|
continue;
|
1239
|
+
}
|
1240
|
+
}
|
1241
|
+
}
|
1041
1242
|
|
1042
|
-
|
1243
|
+
/* Sort all of the textual addresses by their metric. */
|
1244
|
+
qsort(addresses, addressesIndex, sizeof(*addresses), compareAddresses);
|
1043
1245
|
|
1044
|
-
|
1045
|
-
|
1246
|
+
/* Join them all into a single string, removing duplicates. */
|
1247
|
+
{
|
1248
|
+
size_t i;
|
1249
|
+
for(i = 0; i < addressesIndex; ++i) {
|
1250
|
+
size_t j;
|
1251
|
+
/* Look for this address text appearing previously in the results. */
|
1252
|
+
for(j = 0; j < i; ++j) {
|
1253
|
+
if(strcmp(addresses[j].text, addresses[i].text) == 0) {
|
1254
|
+
break;
|
1255
|
+
}
|
1256
|
+
}
|
1257
|
+
/* Iff we didn't emit this address already, emit it now. */
|
1258
|
+
if(j == i) {
|
1259
|
+
/* Add that to outptr (if we can). */
|
1260
|
+
commajoin(outptr, addresses[i].text);
|
1261
|
+
}
|
1046
1262
|
}
|
1047
1263
|
}
|
1048
1264
|
|
1049
1265
|
done:
|
1266
|
+
ares_free(addresses);
|
1267
|
+
|
1050
1268
|
if (ipaa)
|
1051
1269
|
ares_free(ipaa);
|
1052
1270
|
|
1053
|
-
if (!*outptr)
|
1271
|
+
if (!*outptr) {
|
1054
1272
|
return 0;
|
1273
|
+
}
|
1055
1274
|
|
1056
1275
|
return 1;
|
1057
1276
|
}
|
@@ -1072,23 +1291,158 @@ done:
|
|
1072
1291
|
*/
|
1073
1292
|
static int get_DNS_Windows(char **outptr)
|
1074
1293
|
{
|
1075
|
-
/*
|
1076
|
-
|
1077
|
-
|
1078
|
-
GetAdaptersAddresses will retrive dummy dns servers.
|
1079
|
-
That will slowing DNS lookup.
|
1080
|
-
*/
|
1081
|
-
/* Try using IP helper API GetNetworkParams() */
|
1082
|
-
if (get_DNS_NetworkParams(outptr))
|
1294
|
+
/* Try using IP helper API GetAdaptersAddresses(). IPv4 + IPv6, also sorts
|
1295
|
+
* DNS servers by interface route metrics to try to use the best DNS server. */
|
1296
|
+
if (get_DNS_AdaptersAddresses(outptr))
|
1083
1297
|
return 1;
|
1084
1298
|
|
1085
|
-
/* Try using IP helper API
|
1086
|
-
if (
|
1299
|
+
/* Try using IP helper API GetNetworkParams(). IPv4 only. */
|
1300
|
+
if (get_DNS_NetworkParams(outptr))
|
1087
1301
|
return 1;
|
1088
1302
|
|
1089
1303
|
/* Fall-back to registry information */
|
1090
1304
|
return get_DNS_Registry(outptr);
|
1091
1305
|
}
|
1306
|
+
|
1307
|
+
static void replace_comma_by_space(char* str)
|
1308
|
+
{
|
1309
|
+
/* replace ',' by ' ' to coincide with resolv.conf search parameter */
|
1310
|
+
char *p;
|
1311
|
+
for (p = str; *p != '\0'; p++)
|
1312
|
+
{
|
1313
|
+
if (*p == ',')
|
1314
|
+
*p = ' ';
|
1315
|
+
}
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
/* Search if 'suffix' is containted in the 'searchlist'. Returns true if yes,
|
1319
|
+
* otherwise false. 'searchlist' is a comma separated list of domain suffixes,
|
1320
|
+
* 'suffix' is one domain suffix, 'len' is the length of 'suffix'.
|
1321
|
+
* The search ignores case. E.g.:
|
1322
|
+
* contains_suffix("abc.def,ghi.jkl", "ghi.JKL") returns true */
|
1323
|
+
static bool contains_suffix(const char* const searchlist,
|
1324
|
+
const char* const suffix, const size_t len)
|
1325
|
+
{
|
1326
|
+
const char* beg = searchlist;
|
1327
|
+
const char* end;
|
1328
|
+
if (!*suffix)
|
1329
|
+
return true;
|
1330
|
+
for (;;)
|
1331
|
+
{
|
1332
|
+
while (*beg && (ISSPACE(*beg) || (*beg == ',')))
|
1333
|
+
++beg;
|
1334
|
+
if (!*beg)
|
1335
|
+
return false;
|
1336
|
+
end = beg;
|
1337
|
+
while (*end && !ISSPACE(*end) && (*end != ','))
|
1338
|
+
++end;
|
1339
|
+
if (len == (end - beg) && !strnicmp(beg, suffix, len))
|
1340
|
+
return true;
|
1341
|
+
beg = end;
|
1342
|
+
}
|
1343
|
+
}
|
1344
|
+
|
1345
|
+
/* advances list to the next suffix within a comma separated search list.
|
1346
|
+
* len is the length of the next suffix. */
|
1347
|
+
static size_t next_suffix(const char** list, const size_t advance)
|
1348
|
+
{
|
1349
|
+
const char* beg = *list + advance;
|
1350
|
+
const char* end;
|
1351
|
+
while (*beg && (ISSPACE(*beg) || (*beg == ',')))
|
1352
|
+
++beg;
|
1353
|
+
end = beg;
|
1354
|
+
while (*end && !ISSPACE(*end) && (*end != ','))
|
1355
|
+
++end;
|
1356
|
+
*list = beg;
|
1357
|
+
return end - beg;
|
1358
|
+
}
|
1359
|
+
|
1360
|
+
/*
|
1361
|
+
* get_SuffixList_Windows()
|
1362
|
+
*
|
1363
|
+
* Reads the "DNS Suffix Search List" from registry and writes the list items
|
1364
|
+
* whitespace separated to outptr. If the Search List is empty, the
|
1365
|
+
* "Primary Dns Suffix" is written to outptr.
|
1366
|
+
*
|
1367
|
+
* Returns 0 and nullifies *outptr upon inability to return the suffix list.
|
1368
|
+
*
|
1369
|
+
* Returns 1 and sets *outptr when returning a dynamically allocated string.
|
1370
|
+
*
|
1371
|
+
* Implementation supports Windows Server 2003 and newer
|
1372
|
+
*/
|
1373
|
+
static int get_SuffixList_Windows(char **outptr)
|
1374
|
+
{
|
1375
|
+
HKEY hKey, hKeyEnum;
|
1376
|
+
char keyName[256];
|
1377
|
+
DWORD keyNameBuffSize;
|
1378
|
+
DWORD keyIdx = 0;
|
1379
|
+
char *p = NULL;
|
1380
|
+
char *pp;
|
1381
|
+
size_t len = 0;
|
1382
|
+
|
1383
|
+
*outptr = NULL;
|
1384
|
+
|
1385
|
+
if (ares__getplatform() != WIN_NT)
|
1386
|
+
return 0;
|
1387
|
+
|
1388
|
+
/* 1. Global DNS Suffix Search List */
|
1389
|
+
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0,
|
1390
|
+
KEY_READ, &hKey) == ERROR_SUCCESS)
|
1391
|
+
{
|
1392
|
+
if (get_REG_SZ(hKey, SEARCHLIST_KEY, outptr))
|
1393
|
+
replace_comma_by_space(*outptr);
|
1394
|
+
RegCloseKey(hKey);
|
1395
|
+
if (*outptr)
|
1396
|
+
return 1;
|
1397
|
+
}
|
1398
|
+
|
1399
|
+
/* 2. Connection Specific Search List composed of:
|
1400
|
+
* a. Primary DNS Suffix */
|
1401
|
+
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_DNSCLIENT, 0,
|
1402
|
+
KEY_READ, &hKey) == ERROR_SUCCESS)
|
1403
|
+
{
|
1404
|
+
get_REG_SZ(hKey, PRIMARYDNSSUFFIX_KEY, outptr);
|
1405
|
+
RegCloseKey(hKey);
|
1406
|
+
}
|
1407
|
+
if (!*outptr)
|
1408
|
+
return 0;
|
1409
|
+
|
1410
|
+
/* b. Interface SearchList, Domain, DhcpDomain */
|
1411
|
+
if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY "\\" INTERFACES_KEY, 0,
|
1412
|
+
KEY_READ, &hKey) == ERROR_SUCCESS)
|
1413
|
+
return 0;
|
1414
|
+
for(;;)
|
1415
|
+
{
|
1416
|
+
keyNameBuffSize = sizeof(keyName);
|
1417
|
+
if (RegEnumKeyEx(hKey, keyIdx++, keyName, &keyNameBuffSize,
|
1418
|
+
0, NULL, NULL, NULL)
|
1419
|
+
!= ERROR_SUCCESS)
|
1420
|
+
break;
|
1421
|
+
if (RegOpenKeyEx(hKey, keyName, 0, KEY_QUERY_VALUE, &hKeyEnum)
|
1422
|
+
!= ERROR_SUCCESS)
|
1423
|
+
continue;
|
1424
|
+
if (get_REG_SZ(hKeyEnum, SEARCHLIST_KEY, &p) ||
|
1425
|
+
get_REG_SZ(hKeyEnum, DOMAIN_KEY, &p) ||
|
1426
|
+
get_REG_SZ(hKeyEnum, DHCPDOMAIN_KEY, &p))
|
1427
|
+
{
|
1428
|
+
/* p can be comma separated (SearchList) */
|
1429
|
+
pp = p;
|
1430
|
+
while (len = next_suffix(&pp, len))
|
1431
|
+
{
|
1432
|
+
if (!contains_suffix(*outptr, pp, len))
|
1433
|
+
commanjoin(outptr, pp, len);
|
1434
|
+
}
|
1435
|
+
ares_free(p);
|
1436
|
+
p = NULL;
|
1437
|
+
}
|
1438
|
+
RegCloseKey(hKeyEnum);
|
1439
|
+
}
|
1440
|
+
RegCloseKey(hKey);
|
1441
|
+
if (*outptr)
|
1442
|
+
replace_comma_by_space(*outptr);
|
1443
|
+
return *outptr != NULL;
|
1444
|
+
}
|
1445
|
+
|
1092
1446
|
#endif
|
1093
1447
|
|
1094
1448
|
static int init_by_resolv_conf(ares_channel channel)
|
@@ -1112,6 +1466,12 @@ static int init_by_resolv_conf(ares_channel channel)
|
|
1112
1466
|
ares_free(line);
|
1113
1467
|
}
|
1114
1468
|
|
1469
|
+
if (channel->ndomains == -1 && get_SuffixList_Windows(&line))
|
1470
|
+
{
|
1471
|
+
status = set_search(channel, line);
|
1472
|
+
ares_free(line);
|
1473
|
+
}
|
1474
|
+
|
1115
1475
|
if (status == ARES_SUCCESS)
|
1116
1476
|
status = ARES_EOF;
|
1117
1477
|
else
|
@@ -1950,7 +2310,7 @@ static char *try_config(char *s, const char *opt, char scc)
|
|
1950
2310
|
}
|
1951
2311
|
#endif /* !WIN32 & !WATT32 & !ANDROID & !__ANDROID__ */
|
1952
2312
|
|
1953
|
-
static int ip_addr(const char *ipbuf,
|
2313
|
+
static int ip_addr(const char *ipbuf, ares_ssize_t len, struct in_addr *addr)
|
1954
2314
|
{
|
1955
2315
|
|
1956
2316
|
/* Four octets and three periods yields at most 15 characters. */
|
@@ -2103,6 +2463,14 @@ void ares_set_socket_configure_callback(ares_channel channel,
|
|
2103
2463
|
channel->sock_config_cb_data = data;
|
2104
2464
|
}
|
2105
2465
|
|
2466
|
+
void ares_set_socket_functions(ares_channel channel,
|
2467
|
+
const struct ares_socket_functions * funcs,
|
2468
|
+
void *data)
|
2469
|
+
{
|
2470
|
+
channel->sock_funcs = funcs;
|
2471
|
+
channel->sock_func_cb_data = data;
|
2472
|
+
}
|
2473
|
+
|
2106
2474
|
int ares_set_sortlist(ares_channel channel, const char *sortstr)
|
2107
2475
|
{
|
2108
2476
|
int nsort = 0;
|