blob: 1d54a86c39a817e373e28be19459a117c94e9939 [file] [log] [blame]
Craig Tiller698d00c2015-07-20 12:32:58 -07001/*
2 *
Craig Tillerd4c98332016-03-31 13:45:47 -07003 * Copyright 2015-2016, Google Inc.
Craig Tiller698d00c2015-07-20 12:32:58 -07004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
David Garcia Quintas64ddf132016-03-30 23:53:50 -070034#include <stdbool.h>
Craig Tiller698d00c2015-07-20 12:32:58 -070035#include <stdio.h>
36#include <string.h>
Craig Tiller698d00c2015-07-20 12:32:58 -070037
38#include <grpc/support/alloc.h>
39#include <grpc/support/host_port.h>
David Garcia Quintasf47240e2016-04-04 13:51:29 -070040#include <grpc/support/port_platform.h>
Craig Tiller698d00c2015-07-20 12:32:58 -070041#include <grpc/support/string_util.h>
42
Craig Tillerf82ddc42016-04-05 17:15:07 -070043#ifdef GPR_HAVE_UNIX_SOCKET
44#include <sys/un.h>
45#endif
46
Craig Tillerd4c98332016-03-31 13:45:47 -070047#include "src/core/ext/client_config/lb_policy_registry.h"
48#include "src/core/ext/client_config/resolver_registry.h"
Craig Tiller9533d042016-03-25 17:11:06 -070049#include "src/core/lib/iomgr/resolve_address.h"
50#include "src/core/lib/iomgr/unix_sockets_posix.h"
51#include "src/core/lib/support/string.h"
Craig Tiller698d00c2015-07-20 12:32:58 -070052
Craig Tillera82950e2015-09-22 12:33:20 -070053typedef struct {
Craig Tiller698d00c2015-07-20 12:32:58 -070054 /** base class: must be first */
55 grpc_resolver base;
56 /** refcount */
57 gpr_refcount refs;
58 /** subchannel factory */
David Garcia Quintasfcf7ad62016-03-29 21:55:34 -070059 grpc_client_channel_factory *client_channel_factory;
David Garcia Quintas5c4543d2015-09-03 15:49:56 -070060 /** load balancing policy name */
61 char *lb_policy_name;
Craig Tiller698d00c2015-07-20 12:32:58 -070062
David Garcia Quintas2bfd2752015-08-20 11:42:29 -070063 /** the addresses that we've 'resolved' */
David Garcia Quintas67c0d042016-03-25 01:37:53 -070064 grpc_resolved_addresses *addresses;
Craig Tiller698d00c2015-07-20 12:32:58 -070065
66 /** mutex guarding the rest of the state */
67 gpr_mu mu;
68 /** have we published? */
69 int published;
70 /** pending next completion, or NULL */
Craig Tiller33825112015-09-18 07:44:19 -070071 grpc_closure *next_completion;
Craig Tiller698d00c2015-07-20 12:32:58 -070072 /** target config address for next completion */
73 grpc_client_config **target_config;
74} sockaddr_resolver;
75
Craig Tillera82950e2015-09-22 12:33:20 -070076static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
Craig Tiller698d00c2015-07-20 12:32:58 -070077
Craig Tillera82950e2015-09-22 12:33:20 -070078static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
79 sockaddr_resolver *r);
Craig Tiller698d00c2015-07-20 12:32:58 -070080
Craig Tillera82950e2015-09-22 12:33:20 -070081static void sockaddr_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
82static void sockaddr_channel_saw_error(grpc_exec_ctx *exec_ctx,
Craig Tillercb2609f2015-11-24 17:19:19 -080083 grpc_resolver *r);
Craig Tillera82950e2015-09-22 12:33:20 -070084static void sockaddr_next(grpc_exec_ctx *exec_ctx, grpc_resolver *r,
85 grpc_client_config **target_config,
86 grpc_closure *on_complete);
Craig Tiller698d00c2015-07-20 12:32:58 -070087
88static const grpc_resolver_vtable sockaddr_resolver_vtable = {
Craig Tillera82950e2015-09-22 12:33:20 -070089 sockaddr_destroy, sockaddr_shutdown, sockaddr_channel_saw_error,
90 sockaddr_next};
Craig Tiller698d00c2015-07-20 12:32:58 -070091
Craig Tillera82950e2015-09-22 12:33:20 -070092static void sockaddr_shutdown(grpc_exec_ctx *exec_ctx,
93 grpc_resolver *resolver) {
94 sockaddr_resolver *r = (sockaddr_resolver *)resolver;
95 gpr_mu_lock(&r->mu);
96 if (r->next_completion != NULL) {
97 *r->target_config = NULL;
Craig Tiller6c396862016-01-28 13:53:40 -080098 grpc_exec_ctx_enqueue(exec_ctx, r->next_completion, true, NULL);
Craig Tillera82950e2015-09-22 12:33:20 -070099 r->next_completion = NULL;
100 }
101 gpr_mu_unlock(&r->mu);
Craig Tiller698d00c2015-07-20 12:32:58 -0700102}
103
Craig Tillera82950e2015-09-22 12:33:20 -0700104static void sockaddr_channel_saw_error(grpc_exec_ctx *exec_ctx,
Craig Tillercb2609f2015-11-24 17:19:19 -0800105 grpc_resolver *resolver) {
Craig Tiller486ea352015-11-24 16:58:41 -0800106 sockaddr_resolver *r = (sockaddr_resolver *)resolver;
107 gpr_mu_lock(&r->mu);
108 r->published = 0;
109 sockaddr_maybe_finish_next_locked(exec_ctx, r);
110 gpr_mu_unlock(&r->mu);
111}
Craig Tiller698d00c2015-07-20 12:32:58 -0700112
Craig Tillera82950e2015-09-22 12:33:20 -0700113static void sockaddr_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
114 grpc_client_config **target_config,
115 grpc_closure *on_complete) {
116 sockaddr_resolver *r = (sockaddr_resolver *)resolver;
117 gpr_mu_lock(&r->mu);
118 GPR_ASSERT(!r->next_completion);
Craig Tiller698d00c2015-07-20 12:32:58 -0700119 r->next_completion = on_complete;
120 r->target_config = target_config;
Craig Tillera82950e2015-09-22 12:33:20 -0700121 sockaddr_maybe_finish_next_locked(exec_ctx, r);
122 gpr_mu_unlock(&r->mu);
Craig Tiller698d00c2015-07-20 12:32:58 -0700123}
124
Craig Tillera82950e2015-09-22 12:33:20 -0700125static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
126 sockaddr_resolver *r) {
Craig Tillera82950e2015-09-22 12:33:20 -0700127 if (r->next_completion != NULL && !r->published) {
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700128 grpc_client_config *cfg = grpc_client_config_create();
129 grpc_lb_policy_args lb_policy_args;
Craig Tillera82950e2015-09-22 12:33:20 -0700130 memset(&lb_policy_args, 0, sizeof(lb_policy_args));
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700131 lb_policy_args.addresses = r->addresses;
David Garcia Quintas86fcfcc2016-03-31 23:22:28 -0700132 lb_policy_args.client_channel_factory = r->client_channel_factory;
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700133 grpc_lb_policy *lb_policy =
134 grpc_lb_policy_create(exec_ctx, r->lb_policy_name, &lb_policy_args);
Craig Tillera82950e2015-09-22 12:33:20 -0700135 grpc_client_config_set_lb_policy(cfg, lb_policy);
136 GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "sockaddr");
137 r->published = 1;
138 *r->target_config = cfg;
Craig Tiller6c396862016-01-28 13:53:40 -0800139 grpc_exec_ctx_enqueue(exec_ctx, r->next_completion, true, NULL);
Craig Tillera82950e2015-09-22 12:33:20 -0700140 r->next_completion = NULL;
141 }
Craig Tiller698d00c2015-07-20 12:32:58 -0700142}
143
Craig Tillera82950e2015-09-22 12:33:20 -0700144static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
145 sockaddr_resolver *r = (sockaddr_resolver *)gr;
146 gpr_mu_destroy(&r->mu);
David Garcia Quintasfcf7ad62016-03-29 21:55:34 -0700147 grpc_client_channel_factory_unref(exec_ctx, r->client_channel_factory);
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700148 grpc_resolved_addresses_destroy(r->addresses);
Craig Tillera82950e2015-09-22 12:33:20 -0700149 gpr_free(r->lb_policy_name);
150 gpr_free(r);
Craig Tiller698d00c2015-07-20 12:32:58 -0700151}
152
Craig Tillera82950e2015-09-22 12:33:20 -0700153static char *ip_get_default_authority(grpc_uri *uri) {
Craig Tillerbc85be12015-08-24 10:36:39 -0700154 const char *path = uri->path;
Craig Tillera82950e2015-09-22 12:33:20 -0700155 if (path[0] == '/') ++path;
156 return gpr_strdup(path);
Craig Tillerbc85be12015-08-24 10:36:39 -0700157}
158
Craig Tillera82950e2015-09-22 12:33:20 -0700159static char *ipv4_get_default_authority(grpc_resolver_factory *factory,
160 grpc_uri *uri) {
161 return ip_get_default_authority(uri);
Craig Tillerbc85be12015-08-24 10:36:39 -0700162}
163
Craig Tillera82950e2015-09-22 12:33:20 -0700164static char *ipv6_get_default_authority(grpc_resolver_factory *factory,
165 grpc_uri *uri) {
166 return ip_get_default_authority(uri);
Craig Tillerbc85be12015-08-24 10:36:39 -0700167}
168
Craig Tillerf82ddc42016-04-05 17:15:07 -0700169#ifdef GPR_HAVE_UNIX_SOCKET
170static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr,
171 size_t *len) {
172 struct sockaddr_un *un = (struct sockaddr_un *)addr;
173
174 un->sun_family = AF_UNIX;
175 strcpy(un->sun_path, uri->path);
176 *len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
177
178 return 1;
179}
180
181char *unix_get_default_authority(grpc_resolver_factory *factory,
182 grpc_uri *uri) {
183 return gpr_strdup("localhost");
184}
185#endif
186
Craig Tillera82950e2015-09-22 12:33:20 -0700187static int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr,
188 size_t *len) {
Craig Tiller698d00c2015-07-20 12:32:58 -0700189 const char *host_port = uri->path;
190 char *host;
191 char *port;
192 int port_num;
193 int result = 0;
Craig Tillera82950e2015-09-22 12:33:20 -0700194 struct sockaddr_in *in = (struct sockaddr_in *)addr;
Craig Tiller698d00c2015-07-20 12:32:58 -0700195
Craig Tillera82950e2015-09-22 12:33:20 -0700196 if (*host_port == '/') ++host_port;
197 if (!gpr_split_host_port(host_port, &host, &port)) {
198 return 0;
199 }
Craig Tiller698d00c2015-07-20 12:32:58 -0700200
Craig Tillera82950e2015-09-22 12:33:20 -0700201 memset(in, 0, sizeof(*in));
202 *len = sizeof(*in);
Craig Tiller698d00c2015-07-20 12:32:58 -0700203 in->sin_family = AF_INET;
Craig Tillera82950e2015-09-22 12:33:20 -0700204 if (inet_pton(AF_INET, host, &in->sin_addr) == 0) {
205 gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host);
206 goto done;
207 }
Craig Tiller45724b32015-09-22 10:42:19 -0700208
Craig Tillera82950e2015-09-22 12:33:20 -0700209 if (port != NULL) {
210 if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 ||
211 port_num > 65535) {
212 gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port);
Craig Tiller45724b32015-09-22 10:42:19 -0700213 goto done;
214 }
Craig Tiller7536af02015-12-22 13:49:30 -0800215 in->sin_port = htons((uint16_t)port_num);
Craig Tillera82950e2015-09-22 12:33:20 -0700216 } else {
217 gpr_log(GPR_ERROR, "no port given for ipv4 scheme");
218 goto done;
219 }
Craig Tiller698d00c2015-07-20 12:32:58 -0700220
221 result = 1;
222done:
Craig Tillera82950e2015-09-22 12:33:20 -0700223 gpr_free(host);
224 gpr_free(port);
Craig Tiller698d00c2015-07-20 12:32:58 -0700225 return result;
226}
227
Craig Tillera82950e2015-09-22 12:33:20 -0700228static int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr,
229 size_t *len) {
Craig Tiller698d00c2015-07-20 12:32:58 -0700230 const char *host_port = uri->path;
231 char *host;
232 char *port;
233 int port_num;
234 int result = 0;
Craig Tillera82950e2015-09-22 12:33:20 -0700235 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr;
Craig Tiller698d00c2015-07-20 12:32:58 -0700236
Craig Tillera82950e2015-09-22 12:33:20 -0700237 if (*host_port == '/') ++host_port;
238 if (!gpr_split_host_port(host_port, &host, &port)) {
239 return 0;
240 }
Craig Tiller698d00c2015-07-20 12:32:58 -0700241
Craig Tillera82950e2015-09-22 12:33:20 -0700242 memset(in6, 0, sizeof(*in6));
243 *len = sizeof(*in6);
Craig Tiller698d00c2015-07-20 12:32:58 -0700244 in6->sin6_family = AF_INET6;
Craig Tillera82950e2015-09-22 12:33:20 -0700245 if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) {
246 gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
247 goto done;
248 }
Craig Tiller45724b32015-09-22 10:42:19 -0700249
Craig Tillera82950e2015-09-22 12:33:20 -0700250 if (port != NULL) {
251 if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 ||
252 port_num > 65535) {
253 gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port);
Craig Tiller45724b32015-09-22 10:42:19 -0700254 goto done;
255 }
Craig Tiller7536af02015-12-22 13:49:30 -0800256 in6->sin6_port = htons((uint16_t)port_num);
Craig Tillera82950e2015-09-22 12:33:20 -0700257 } else {
258 gpr_log(GPR_ERROR, "no port given for ipv6 scheme");
259 goto done;
260 }
Craig Tiller698d00c2015-07-20 12:32:58 -0700261
262 result = 1;
263done:
Craig Tillera82950e2015-09-22 12:33:20 -0700264 gpr_free(host);
265 gpr_free(port);
Craig Tiller698d00c2015-07-20 12:32:58 -0700266 return result;
267}
268
Craig Tillera82950e2015-09-22 12:33:20 -0700269static void do_nothing(void *ignored) {}
Craig Tiller45724b32015-09-22 10:42:19 -0700270
Craig Tillera82950e2015-09-22 12:33:20 -0700271static grpc_resolver *sockaddr_create(
272 grpc_resolver_args *args, const char *default_lb_policy_name,
273 int parse(grpc_uri *uri, struct sockaddr_storage *dst, size_t *len)) {
Craig Tillera82950e2015-09-22 12:33:20 -0700274 int errors_found = 0; /* GPR_FALSE */
Craig Tiller698d00c2015-07-20 12:32:58 -0700275 sockaddr_resolver *r;
David Garcia Quintas2bfd2752015-08-20 11:42:29 -0700276 gpr_slice path_slice;
277 gpr_slice_buffer path_parts;
Craig Tiller698d00c2015-07-20 12:32:58 -0700278
Craig Tillera82950e2015-09-22 12:33:20 -0700279 if (0 != strcmp(args->uri->authority, "")) {
280 gpr_log(GPR_ERROR, "authority based uri's not supported by the %s scheme",
281 args->uri->scheme);
282 return NULL;
283 }
Craig Tiller698d00c2015-07-20 12:32:58 -0700284
Craig Tillera82950e2015-09-22 12:33:20 -0700285 r = gpr_malloc(sizeof(sockaddr_resolver));
286 memset(r, 0, sizeof(*r));
David Garcia Quintas2bfd2752015-08-20 11:42:29 -0700287
David Garcia Quintasf9a7e282016-03-31 09:35:57 -0700288 r->lb_policy_name =
289 gpr_strdup(grpc_uri_get_query_arg(args->uri, "lb_policy"));
290 const char *lb_enabled_qpart =
291 grpc_uri_get_query_arg(args->uri, "lb_enabled");
292 /* anything other than "0" is interpreted as true */
293 const bool lb_enabled =
294 (lb_enabled_qpart != NULL && (strcmp("0", lb_enabled_qpart) != 0));
David Garcia Quintasfe7a6362015-09-10 11:06:46 -0700295
David Garcia Quintas64ddf132016-03-30 23:53:50 -0700296 if (r->lb_policy_name != NULL && strcmp("grpclb", r->lb_policy_name) == 0 &&
297 !lb_enabled) {
298 /* we want grpclb but the "resolved" addresses aren't LB enabled. Bail
299 * out, as this is meant mostly for tests. */
300 gpr_log(GPR_ERROR,
301 "Requested 'grpclb' LB policy but resolved addresses don't "
302 "support load balancing.");
303 abort();
Craig Tillera82950e2015-09-22 12:33:20 -0700304 }
David Garcia Quintas64ddf132016-03-30 23:53:50 -0700305
Craig Tillera82950e2015-09-22 12:33:20 -0700306 if (r->lb_policy_name == NULL) {
307 r->lb_policy_name = gpr_strdup(default_lb_policy_name);
308 }
David Garcia Quintasfe7a6362015-09-10 11:06:46 -0700309
Craig Tillera82950e2015-09-22 12:33:20 -0700310 path_slice =
311 gpr_slice_new(args->uri->path, strlen(args->uri->path), do_nothing);
312 gpr_slice_buffer_init(&path_parts);
David Garcia Quintas2bfd2752015-08-20 11:42:29 -0700313
Craig Tillera82950e2015-09-22 12:33:20 -0700314 gpr_slice_split(path_slice, ",", &path_parts);
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700315 r->addresses = gpr_malloc(sizeof(grpc_resolved_addresses));
316 r->addresses->naddrs = path_parts.count;
317 r->addresses->addrs =
318 gpr_malloc(sizeof(grpc_resolved_address) * r->addresses->naddrs);
David Garcia Quintas2bfd2752015-08-20 11:42:29 -0700319
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700320 for (size_t i = 0; i < r->addresses->naddrs; i++) {
Craig Tillera82950e2015-09-22 12:33:20 -0700321 grpc_uri ith_uri = *args->uri;
322 char *part_str = gpr_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII);
323 ith_uri.path = part_str;
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700324 if (!parse(&ith_uri,
325 (struct sockaddr_storage *)(&r->addresses->addrs[i].addr),
326 &r->addresses->addrs[i].len)) {
Craig Tillera82950e2015-09-22 12:33:20 -0700327 errors_found = 1; /* GPR_TRUE */
David Garcia Quintas2bfd2752015-08-20 11:42:29 -0700328 }
Craig Tillera82950e2015-09-22 12:33:20 -0700329 gpr_free(part_str);
330 if (errors_found) break;
331 }
David Garcia Quintas2bfd2752015-08-20 11:42:29 -0700332
Craig Tillera82950e2015-09-22 12:33:20 -0700333 gpr_slice_buffer_destroy(&path_parts);
334 gpr_slice_unref(path_slice);
335 if (errors_found) {
Craig Tillere8ab66c2015-12-11 14:47:01 -0800336 gpr_free(r->lb_policy_name);
David Garcia Quintas67c0d042016-03-25 01:37:53 -0700337 grpc_resolved_addresses_destroy(r->addresses);
Craig Tillera82950e2015-09-22 12:33:20 -0700338 gpr_free(r);
339 return NULL;
340 }
Craig Tiller698d00c2015-07-20 12:32:58 -0700341
Craig Tillera82950e2015-09-22 12:33:20 -0700342 gpr_ref_init(&r->refs, 1);
343 gpr_mu_init(&r->mu);
344 grpc_resolver_init(&r->base, &sockaddr_resolver_vtable);
David Garcia Quintasfcf7ad62016-03-29 21:55:34 -0700345 r->client_channel_factory = args->client_channel_factory;
346 grpc_client_channel_factory_ref(r->client_channel_factory);
Craig Tiller698d00c2015-07-20 12:32:58 -0700347
Craig Tiller698d00c2015-07-20 12:32:58 -0700348 return &r->base;
349}
350
351/*
352 * FACTORY
353 */
354
Craig Tillera82950e2015-09-22 12:33:20 -0700355static void sockaddr_factory_ref(grpc_resolver_factory *factory) {}
Craig Tiller698d00c2015-07-20 12:32:58 -0700356
Craig Tillera82950e2015-09-22 12:33:20 -0700357static void sockaddr_factory_unref(grpc_resolver_factory *factory) {}
Craig Tiller698d00c2015-07-20 12:32:58 -0700358
Craig Tillerf82ddc42016-04-05 17:15:07 -0700359#define DECL_FACTORY(name) \
Craig Tillerbc85be12015-08-24 10:36:39 -0700360 static grpc_resolver *name##_factory_create_resolver( \
Craig Tiller06a43f52015-09-15 07:41:28 -0700361 grpc_resolver_factory *factory, grpc_resolver_args *args) { \
Craig Tillerf82ddc42016-04-05 17:15:07 -0700362 return sockaddr_create(args, "pick_first", parse_##name); \
Craig Tillerbc85be12015-08-24 10:36:39 -0700363 } \
364 static const grpc_resolver_factory_vtable name##_factory_vtable = { \
365 sockaddr_factory_ref, sockaddr_factory_unref, \
Craig Tillerf82ddc42016-04-05 17:15:07 -0700366 name##_factory_create_resolver, name##_get_default_authority, #name}; \
Craig Tillerbc85be12015-08-24 10:36:39 -0700367 static grpc_resolver_factory name##_resolver_factory = { \
Craig Tiller65938df2016-03-31 13:08:49 -0700368 &name##_factory_vtable}
Craig Tiller698d00c2015-07-20 12:32:58 -0700369
ahedbergfcbcbff2016-03-22 13:23:47 -0400370#ifdef GPR_HAVE_UNIX_SOCKET
Craig Tillerf82ddc42016-04-05 17:15:07 -0700371DECL_FACTORY(unix);
Craig Tiller698d00c2015-07-20 12:32:58 -0700372#endif
Craig Tillerf82ddc42016-04-05 17:15:07 -0700373DECL_FACTORY(ipv4);
374DECL_FACTORY(ipv6);
Craig Tiller65938df2016-03-31 13:08:49 -0700375
376void grpc_resolver_sockaddr_init(void) {
377 grpc_register_resolver_type(&ipv4_resolver_factory);
378 grpc_register_resolver_type(&ipv6_resolver_factory);
379#ifdef GPR_HAVE_UNIX_SOCKET
380 grpc_register_resolver_type(&unix_resolver_factory);
381#endif
382}
383
384void grpc_resolver_sockaddr_shutdown(void) {}