Imported Upstream version 1.21.0
[platform/upstream/grpc.git] / src / core / ext / filters / client_channel / resolver / dns / c_ares / grpc_ares_wrapper.h
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
22 #include <grpc/support/port_platform.h>
23
24 #include "src/core/ext/filters/client_channel/server_address.h"
25 #include "src/core/lib/iomgr/iomgr.h"
26 #include "src/core/lib/iomgr/polling_entity.h"
27 #include "src/core/lib/iomgr/resolve_address.h"
28
29 #define GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS 120000
30
31 extern grpc_core::TraceFlag grpc_trace_cares_address_sorting;
32
33 extern grpc_core::TraceFlag grpc_trace_cares_resolver;
34
35 #define GRPC_CARES_TRACE_LOG(format, ...)                           \
36   do {                                                              \
37     if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_cares_resolver)) {       \
38       gpr_log(GPR_DEBUG, "(c-ares resolver) " format, __VA_ARGS__); \
39     }                                                               \
40   } while (0)
41
42 typedef struct grpc_ares_request grpc_ares_request;
43
44 /* Asynchronously resolve \a name. Use \a default_port if a port isn't
45    designated in \a name, otherwise use the port in \a name. grpc_ares_init()
46    must be called at least once before this function. \a on_done may be
47    called directly in this function without being scheduled with \a exec_ctx,
48    so it must not try to acquire locks that are being held by the caller. */
49 extern void (*grpc_resolve_address_ares)(const char* name,
50                                          const char* default_port,
51                                          grpc_pollset_set* interested_parties,
52                                          grpc_closure* on_done,
53                                          grpc_resolved_addresses** addresses);
54
55 /* Asynchronously resolve \a name. It will try to resolve grpclb SRV records in
56   addition to the normal address records. For normal address records, it uses
57   \a default_port if a port isn't designated in \a name, otherwise it uses the
58   port in \a name. grpc_ares_init() must be called at least once before this
59   function. \a on_done may be called directly in this function without being
60   scheduled with \a exec_ctx, so it must not try to acquire locks that are
61   being held by the caller. The returned grpc_ares_request object is owned
62   by the caller and it is safe to free after on_done is called back. */
63 extern grpc_ares_request* (*grpc_dns_lookup_ares_locked)(
64     const char* dns_server, const char* name, const char* default_port,
65     grpc_pollset_set* interested_parties, grpc_closure* on_done,
66     grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
67     bool check_grpclb, char** service_config_json, int query_timeout_ms,
68     grpc_combiner* combiner);
69
70 /* Cancel the pending grpc_ares_request \a request */
71 extern void (*grpc_cancel_ares_request_locked)(grpc_ares_request* request);
72
73 /* Initialize gRPC ares wrapper. Must be called at least once before
74    grpc_resolve_address_ares(). */
75 grpc_error* grpc_ares_init(void);
76
77 /* Uninitialized gRPC ares wrapper. If there was more than one previous call to
78    grpc_ares_init(), this function uninitializes the gRPC ares wrapper only if
79    it has been called the same number of times as grpc_ares_init(). */
80 void grpc_ares_cleanup(void);
81
82 /** Schedules the desired callback for request completion
83  * and destroys the grpc_ares_request */
84 void grpc_ares_complete_request_locked(grpc_ares_request* request);
85
86 /* Indicates whether or not AAAA queries should be attempted. */
87 /* E.g., return false if ipv6 is known to not be available. */
88 bool grpc_ares_query_ipv6();
89
90 /* Sorts destinations in lb_addrs according to RFC 6724. */
91 void grpc_cares_wrapper_address_sorting_sort(
92     grpc_core::ServerAddressList* addresses);
93
94 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H \
95         */