grpc_ares_wrapper.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H
21 
23 
24 #include <stddef.h>
25 
26 #include <memory>
27 
28 #include <ares.h>
29 
30 #include "absl/base/thread_annotations.h"
31 
32 #include <grpc/support/log.h>
33 
40 
41 #define GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS 120000
42 
44 
46 
47 #define GRPC_CARES_TRACE_LOG(format, ...) \
48  do { \
49  if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_cares_resolver)) { \
50  gpr_log(GPR_DEBUG, "(c-ares resolver) " format, __VA_ARGS__); \
51  } \
52  } while (0)
53 
55 
61  struct ares_addr_port_node dns_server_addr ABSL_GUARDED_BY(mu);
64  grpc_closure* on_done ABSL_GUARDED_BY(mu) = nullptr;
66  std::unique_ptr<grpc_core::ServerAddressList>* addresses_out
69  std::unique_ptr<grpc_core::ServerAddressList>* balancer_addresses_out
72  char** service_config_json_out ABSL_GUARDED_BY(mu) = nullptr;
74  grpc_ares_ev_driver* ev_driver ABSL_GUARDED_BY(mu) = nullptr;
76  size_t pending_queries ABSL_GUARDED_BY(mu) = 0;
79 };
80 
81 /* Asynchronously resolve \a name. It will try to resolve grpclb SRV records in
82  addition to the normal address records. For normal address records, it uses
83  \a default_port if a port isn't designated in \a name, otherwise it uses the
84  port in \a name. grpc_ares_init() must be called at least once before this
85  function. The returned grpc_ares_request object is owned by the caller and it
86  is safe to free after on_done is called back.
87 
88  Note on synchronization: \a as on_done might be called from another thread
89  ~immediately, access to the grpc_ares_request* return value must be
90  synchronized by the caller. TODO(apolcyn): we should remove this requirement
91  by changing this API to use two phase initialization - one API to create
92  the grpc_ares_request* and another to start the async work. */
93 extern grpc_ares_request* (*grpc_dns_lookup_ares)(
94  const char* dns_server, const char* name, const char* default_port,
95  grpc_pollset_set* interested_parties, grpc_closure* on_done,
96  std::unique_ptr<grpc_core::ServerAddressList>* addresses,
97  std::unique_ptr<grpc_core::ServerAddressList>* balancer_addresses,
98  char** service_config_json, int query_timeout_ms);
99 
100 /* Cancel the pending grpc_ares_request \a request */
102 
103 /* Initialize gRPC ares wrapper. Must be called at least once before
104  grpc_resolve_address_ares(). */
106 
107 /* Uninitialized gRPC ares wrapper. If there was more than one previous call to
108  grpc_ares_init(), this function uninitializes the gRPC ares wrapper only if
109  it has been called the same number of times as grpc_ares_init(). */
110 void grpc_ares_cleanup(void);
111 
112 /* Indicates whether or not AAAA queries should be attempted. */
113 /* E.g., return false if ipv6 is known to not be available. */
114 bool grpc_ares_query_ipv6();
115 
116 /* Sorts destinations in lb_addrs according to RFC 6724. */
119 
120 /* Exposed in this header for C-core tests only */
122 
123 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H \
124  */
trace.h
grpc_trace_cares_resolver
grpc_core::TraceFlag grpc_trace_cares_resolver
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.h
dns_server
Definition: dns_server.py:1
ares.h
grpc_ares_cleanup
void grpc_ares_cleanup(void)
ares_addr_port_node
Definition: ares.h:704
grpc_pollset_set
struct grpc_pollset_set grpc_pollset_set
Definition: iomgr_fwd.h:23
benchmark.request
request
Definition: benchmark.py:77
error
grpc_error_handle error
Definition: retry_filter.cc:499
closure.h
grpc_ares_query_ipv6
bool grpc_ares_query_ipv6()
setup.name
name
Definition: setup.py:542
grpc_cares_wrapper_address_sorting_sort
void grpc_cares_wrapper_address_sorting_sort(const grpc_ares_request *request, grpc_core::ServerAddressList *addresses)
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
grpc_trace_cares_address_sorting
grpc_core::TraceFlag grpc_trace_cares_address_sorting
grpc_ares_request::mu
grpc_core::Mutex mu
Definition: grpc_ares_wrapper.h:59
server_address.h
error.h
grpc_core::ServerAddressList
std::vector< ServerAddress > ServerAddressList
Definition: server_address.h:120
grpc_core::TraceFlag
Definition: debug/trace.h:63
grpc_ares_request
Definition: grpc_ares_wrapper.h:56
ares_channeldata
Definition: ares_private.h:266
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_ares_ev_driver
struct grpc_ares_ev_driver grpc_ares_ev_driver
Definition: grpc_ares_wrapper.h:54
grpc_ares_request::ABSL_GUARDED_BY
struct ares_addr_port_node dns_server_addr ABSL_GUARDED_BY(mu)
grpc_ares_init
grpc_error_handle grpc_ares_init(void)
iomgr_fwd.h
grpc_error
Definition: error_internal.h:42
grpc_closure
Definition: closure.h:56
grpc_cancel_ares_request
void(* grpc_cancel_ares_request)(grpc_ares_request *request)
grpc_ares_test_only_inject_config
void(* grpc_ares_test_only_inject_config)(ares_channel channel)
sync.h
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:47