|
|
@ -185,7 +185,8 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, |
|
|
|
sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses); |
|
|
|
sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses); |
|
|
|
for (i = prev_naddr; i < (*lb_addresses)->num_addresses; i++) { |
|
|
|
for (i = prev_naddr; i < (*lb_addresses)->num_addresses; i++) { |
|
|
|
memset(&(*lb_addresses)->addresses[i], 0, sizeof(grpc_lb_address)); |
|
|
|
memset(&(*lb_addresses)->addresses[i], 0, sizeof(grpc_lb_address)); |
|
|
|
if (hostent->h_addrtype == AF_INET6) { |
|
|
|
switch (hostent->h_addrtype) { |
|
|
|
|
|
|
|
case AF_INET6: { |
|
|
|
size_t addr_len = sizeof(struct sockaddr_in6); |
|
|
|
size_t addr_len = sizeof(struct sockaddr_in6); |
|
|
|
struct sockaddr_in6 addr; |
|
|
|
struct sockaddr_in6 addr; |
|
|
|
memcpy(&addr.sin6_addr, hostent->h_addr_list[i - prev_naddr], |
|
|
|
memcpy(&addr.sin6_addr, hostent->h_addr_list[i - prev_naddr], |
|
|
@ -197,14 +198,15 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, |
|
|
|
hr->is_balancer /* is_balancer */, |
|
|
|
hr->is_balancer /* is_balancer */, |
|
|
|
hr->is_balancer ? strdup(hr->host) : NULL /* balancer_name */, |
|
|
|
hr->is_balancer ? strdup(hr->host) : NULL /* balancer_name */, |
|
|
|
NULL /* user_data */); |
|
|
|
NULL /* user_data */); |
|
|
|
|
|
|
|
|
|
|
|
char output[INET6_ADDRSTRLEN]; |
|
|
|
char output[INET6_ADDRSTRLEN]; |
|
|
|
ares_inet_ntop(AF_INET6, &addr.sin6_addr, output, INET6_ADDRSTRLEN); |
|
|
|
ares_inet_ntop(AF_INET6, &addr.sin6_addr, output, INET6_ADDRSTRLEN); |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
"c-ares resolver gets a AF_INET6 result: \n" |
|
|
|
"c-ares resolver gets a AF_INET6 result: \n" |
|
|
|
" addr: %s\n port: %d\n sin6_scope_id: %d\n", |
|
|
|
" addr: %s\n port: %d\n sin6_scope_id: %d\n", |
|
|
|
output, ntohs(hr->port), addr.sin6_scope_id); |
|
|
|
output, ntohs(hr->port), addr.sin6_scope_id); |
|
|
|
} else { /* hostent->h_addrtype == AF_INET6 */ |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case AF_INET: { |
|
|
|
size_t addr_len = sizeof(struct sockaddr_in); |
|
|
|
size_t addr_len = sizeof(struct sockaddr_in); |
|
|
|
struct sockaddr_in addr; |
|
|
|
struct sockaddr_in addr; |
|
|
|
memcpy(&addr.sin_addr, hostent->h_addr_list[i - prev_naddr], |
|
|
|
memcpy(&addr.sin_addr, hostent->h_addr_list[i - prev_naddr], |
|
|
@ -216,13 +218,14 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, |
|
|
|
hr->is_balancer /* is_balancer */, |
|
|
|
hr->is_balancer /* is_balancer */, |
|
|
|
hr->is_balancer ? strdup(hr->host) : NULL /* balancer_name */, |
|
|
|
hr->is_balancer ? strdup(hr->host) : NULL /* balancer_name */, |
|
|
|
NULL /* user_data */); |
|
|
|
NULL /* user_data */); |
|
|
|
|
|
|
|
|
|
|
|
char output[INET_ADDRSTRLEN]; |
|
|
|
char output[INET_ADDRSTRLEN]; |
|
|
|
ares_inet_ntop(AF_INET, &addr.sin_addr, output, INET_ADDRSTRLEN); |
|
|
|
ares_inet_ntop(AF_INET, &addr.sin_addr, output, INET_ADDRSTRLEN); |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
"c-ares resolver gets a AF_INET result: \n" |
|
|
|
"c-ares resolver gets a AF_INET result: \n" |
|
|
|
" addr: %s\n port: %d\n", |
|
|
|
" addr: %s\n port: %d\n", |
|
|
|
output, ntohs(hr->port)); |
|
|
|
output, ntohs(hr->port)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { /* r->lb_addrs_out */ |
|
|
|
} else { /* r->lb_addrs_out */ |
|
|
@ -242,22 +245,25 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, |
|
|
|
sizeof(grpc_resolved_address) * (*addresses)->naddrs); |
|
|
|
sizeof(grpc_resolved_address) * (*addresses)->naddrs); |
|
|
|
for (i = prev_naddr; i < (*addresses)->naddrs; i++) { |
|
|
|
for (i = prev_naddr; i < (*addresses)->naddrs; i++) { |
|
|
|
memset(&(*addresses)->addrs[i], 0, sizeof(grpc_resolved_address)); |
|
|
|
memset(&(*addresses)->addrs[i], 0, sizeof(grpc_resolved_address)); |
|
|
|
if (hostent->h_addrtype == AF_INET6) { |
|
|
|
switch (hostent->h_addrtype) { |
|
|
|
|
|
|
|
case AF_INET6: { |
|
|
|
(*addresses)->addrs[i].len = sizeof(struct sockaddr_in6); |
|
|
|
(*addresses)->addrs[i].len = sizeof(struct sockaddr_in6); |
|
|
|
struct sockaddr_in6 *addr = |
|
|
|
struct sockaddr_in6 *addr = |
|
|
|
(struct sockaddr_in6 *)&(*addresses)->addrs[i].addr; |
|
|
|
(struct sockaddr_in6 *)&(*addresses)->addrs[i].addr; |
|
|
|
addr->sin6_family = (sa_family_t)hostent->h_addrtype; |
|
|
|
addr->sin6_family = (sa_family_t)hostent->h_addrtype; |
|
|
|
addr->sin6_port = hr->port; |
|
|
|
addr->sin6_port = hr->port; |
|
|
|
|
|
|
|
|
|
|
|
char output[INET6_ADDRSTRLEN]; |
|
|
|
char output[INET6_ADDRSTRLEN]; |
|
|
|
memcpy(&addr->sin6_addr, hostent->h_addr_list[i - prev_naddr], |
|
|
|
memcpy(&addr->sin6_addr, hostent->h_addr_list[i - prev_naddr], |
|
|
|
sizeof(struct in6_addr)); |
|
|
|
sizeof(struct in6_addr)); |
|
|
|
ares_inet_ntop(AF_INET6, &addr->sin6_addr, output, INET6_ADDRSTRLEN); |
|
|
|
ares_inet_ntop(AF_INET6, &addr->sin6_addr, output, |
|
|
|
|
|
|
|
INET6_ADDRSTRLEN); |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
"c-ares resolver gets a AF_INET6 result: \n" |
|
|
|
"c-ares resolver gets a AF_INET6 result: \n" |
|
|
|
" addr: %s\n port: %d\n sin6_scope_id: %d\n", |
|
|
|
" addr: %s\n port: %d\n sin6_scope_id: %d\n", |
|
|
|
output, ntohs(hr->port), addr->sin6_scope_id); |
|
|
|
output, ntohs(hr->port), addr->sin6_scope_id); |
|
|
|
} else { /* hostent->h_addrtype == AF_INET6 */ |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case AF_INET: { |
|
|
|
(*addresses)->addrs[i].len = sizeof(struct sockaddr_in); |
|
|
|
(*addresses)->addrs[i].len = sizeof(struct sockaddr_in); |
|
|
|
struct sockaddr_in *addr = |
|
|
|
struct sockaddr_in *addr = |
|
|
|
(struct sockaddr_in *)&(*addresses)->addrs[i].addr; |
|
|
|
(struct sockaddr_in *)&(*addresses)->addrs[i].addr; |
|
|
@ -265,13 +271,14 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, |
|
|
|
sizeof(struct in_addr)); |
|
|
|
sizeof(struct in_addr)); |
|
|
|
addr->sin_family = (sa_family_t)hostent->h_addrtype; |
|
|
|
addr->sin_family = (sa_family_t)hostent->h_addrtype; |
|
|
|
addr->sin_port = hr->port; |
|
|
|
addr->sin_port = hr->port; |
|
|
|
|
|
|
|
|
|
|
|
char output[INET_ADDRSTRLEN]; |
|
|
|
char output[INET_ADDRSTRLEN]; |
|
|
|
ares_inet_ntop(AF_INET, &addr->sin_addr, output, INET_ADDRSTRLEN); |
|
|
|
ares_inet_ntop(AF_INET, &addr->sin_addr, output, INET_ADDRSTRLEN); |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
gpr_log(GPR_DEBUG, |
|
|
|
"c-ares resolver gets a AF_INET result: \n" |
|
|
|
"c-ares resolver gets a AF_INET result: \n" |
|
|
|
" addr: %s\n port: %d\n", |
|
|
|
" addr: %s\n port: %d\n", |
|
|
|
output, ntohs(hr->port)); |
|
|
|
output, ntohs(hr->port)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -317,7 +324,6 @@ static void on_srv_query_done_cb(void *arg, int status, int timeouts, |
|
|
|
grpc_ares_ev_driver_start(&exec_ctx, r->ev_driver); |
|
|
|
grpc_ares_ev_driver_start(&exec_ctx, r->ev_driver); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (reply != NULL) { |
|
|
|
if (reply != NULL) { |
|
|
|
ares_free_data(reply); |
|
|
|
ares_free_data(reply); |
|
|
|
} |
|
|
|
} |
|
|
@ -337,11 +343,11 @@ static void on_srv_query_done_cb(void *arg, int status, int timeouts, |
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_dns_lookup_ares( |
|
|
|
void grpc_dns_lookup_ares(grpc_exec_ctx *exec_ctx, const char *dns_server, |
|
|
|
grpc_exec_ctx *exec_ctx, const char *dns_server, const char *name, |
|
|
|
const char *name, const char *default_port, |
|
|
|
const char *default_port, grpc_pollset_set *interested_parties, |
|
|
|
grpc_pollset_set *interested_parties, |
|
|
|
grpc_closure *on_done, |
|
|
|
grpc_closure *on_done, void **addrs, |
|
|
|
void **addrs, bool is_lb_addrs_out) { |
|
|
|
bool check_grpclb) { |
|
|
|
grpc_error *error = GRPC_ERROR_NONE; |
|
|
|
grpc_error *error = GRPC_ERROR_NONE; |
|
|
|
/* TODO(zyc): Enable tracing after #9603 is checked in */ |
|
|
|
/* TODO(zyc): Enable tracing after #9603 is checked in */ |
|
|
|
/* if (grpc_dns_trace) {
|
|
|
|
/* if (grpc_dns_trace) {
|
|
|
@ -376,8 +382,8 @@ void grpc_dns_lookup_ares( |
|
|
|
gpr_mu_init(&r->mu); |
|
|
|
gpr_mu_init(&r->mu); |
|
|
|
r->ev_driver = ev_driver; |
|
|
|
r->ev_driver = ev_driver; |
|
|
|
r->on_done = on_done; |
|
|
|
r->on_done = on_done; |
|
|
|
r->lb_addrs_out = is_lb_addrs_out; |
|
|
|
r->lb_addrs_out = check_grpclb; |
|
|
|
if (is_lb_addrs_out) { |
|
|
|
if (check_grpclb) { |
|
|
|
r->addrs_out.lb_addrs = (grpc_lb_addresses **)addrs; |
|
|
|
r->addrs_out.lb_addrs = (grpc_lb_addresses **)addrs; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
r->addrs_out.addrs = (grpc_resolved_addresses **)addrs; |
|
|
|
r->addrs_out.addrs = (grpc_resolved_addresses **)addrs; |
|
|
@ -428,7 +434,7 @@ void grpc_dns_lookup_ares( |
|
|
|
grpc_ares_hostbyname_request *hr = create_hostbyname_request( |
|
|
|
grpc_ares_hostbyname_request *hr = create_hostbyname_request( |
|
|
|
r, host, strhtons(port), false /* is_balancer */); |
|
|
|
r, host, strhtons(port), false /* is_balancer */); |
|
|
|
ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_cb, hr); |
|
|
|
ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_cb, hr); |
|
|
|
if (is_lb_addrs_out) { |
|
|
|
if (check_grpclb) { |
|
|
|
/* Query the SRV record */ |
|
|
|
/* Query the SRV record */ |
|
|
|
grpc_ares_request_ref(r); |
|
|
|
grpc_ares_request_ref(r); |
|
|
|
char *service_name; |
|
|
|
char *service_name; |
|
|
@ -455,7 +461,7 @@ void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name, |
|
|
|
grpc_resolved_addresses **addrs) { |
|
|
|
grpc_resolved_addresses **addrs) { |
|
|
|
grpc_dns_lookup_ares(exec_ctx, NULL /* dns_server */, name, default_port, |
|
|
|
grpc_dns_lookup_ares(exec_ctx, NULL /* dns_server */, name, default_port, |
|
|
|
interested_parties, on_done, (void **)addrs, |
|
|
|
interested_parties, on_done, (void **)addrs, |
|
|
|
false /* is_lb_addrs_out */); |
|
|
|
false /* check_grpclb */); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void (*grpc_resolve_address_ares)( |
|
|
|
void (*grpc_resolve_address_ares)( |
|
|
|