aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/filters/client_channel
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ext/filters/client_channel')
-rw-r--r--src/core/ext/filters/client_channel/client_channel_factory.cc2
-rw-r--r--src/core/ext/filters/client_channel/client_channel_factory.h4
-rw-r--r--src/core/ext/filters/client_channel/lb_policy/subchannel_list.h5
-rw-r--r--src/core/ext/filters/client_channel/parse_address.cc29
-rw-r--r--src/core/ext/filters/client_channel/subchannel.cc36
-rw-r--r--src/core/ext/filters/client_channel/subchannel.h15
-rw-r--r--src/core/ext/filters/client_channel/subchannel_index.cc32
-rw-r--r--src/core/ext/filters/client_channel/subchannel_index.h3
8 files changed, 42 insertions, 84 deletions
diff --git a/src/core/ext/filters/client_channel/client_channel_factory.cc b/src/core/ext/filters/client_channel/client_channel_factory.cc
index 172e9f03c7..130bbe0418 100644
--- a/src/core/ext/filters/client_channel/client_channel_factory.cc
+++ b/src/core/ext/filters/client_channel/client_channel_factory.cc
@@ -30,7 +30,7 @@ void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory) {
}
grpc_subchannel* grpc_client_channel_factory_create_subchannel(
- grpc_client_channel_factory* factory, const grpc_subchannel_args* args) {
+ grpc_client_channel_factory* factory, const grpc_channel_args* args) {
return factory->vtable->create_subchannel(factory, args);
}
diff --git a/src/core/ext/filters/client_channel/client_channel_factory.h b/src/core/ext/filters/client_channel/client_channel_factory.h
index 601ec46b2a..91dec12282 100644
--- a/src/core/ext/filters/client_channel/client_channel_factory.h
+++ b/src/core/ext/filters/client_channel/client_channel_factory.h
@@ -49,7 +49,7 @@ struct grpc_client_channel_factory_vtable {
void (*ref)(grpc_client_channel_factory* factory);
void (*unref)(grpc_client_channel_factory* factory);
grpc_subchannel* (*create_subchannel)(grpc_client_channel_factory* factory,
- const grpc_subchannel_args* args);
+ const grpc_channel_args* args);
grpc_channel* (*create_client_channel)(grpc_client_channel_factory* factory,
const char* target,
grpc_client_channel_type type,
@@ -61,7 +61,7 @@ void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory);
/** Create a new grpc_subchannel */
grpc_subchannel* grpc_client_channel_factory_create_subchannel(
- grpc_client_channel_factory* factory, const grpc_subchannel_args* args);
+ grpc_client_channel_factory* factory, const grpc_channel_args* args);
/** Create a new grpc_channel */
grpc_channel* grpc_client_channel_factory_create_channel(
diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h
index 6f31a643c1..1d0ecbe3f6 100644
--- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h
+++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h
@@ -509,12 +509,10 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
GRPC_ARG_SERVER_ADDRESS_LIST,
GRPC_ARG_INHIBIT_HEALTH_CHECKING};
// Create a subchannel for each address.
- grpc_subchannel_args sc_args;
for (size_t i = 0; i < addresses.size(); i++) {
// If there were any balancer addresses, we would have chosen grpclb
// policy, which does not use a SubchannelList.
GPR_ASSERT(!addresses[i].IsBalancer());
- memset(&sc_args, 0, sizeof(grpc_subchannel_args));
InlinedVector<grpc_arg, 4> args_to_add;
args_to_add.emplace_back(
grpc_create_subchannel_address_arg(&addresses[i].address()));
@@ -527,9 +525,8 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
&args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove),
args_to_add.data(), args_to_add.size());
gpr_free(args_to_add[0].value.string);
- sc_args.args = new_args;
grpc_subchannel* subchannel = grpc_client_channel_factory_create_subchannel(
- client_channel_factory, &sc_args);
+ client_channel_factory, new_args);
grpc_channel_args_destroy(new_args);
if (subchannel == nullptr) {
// Subchannel could not be created.
diff --git a/src/core/ext/filters/client_channel/parse_address.cc b/src/core/ext/filters/client_channel/parse_address.cc
index 707beb8876..c5e1ed811b 100644
--- a/src/core/ext/filters/client_channel/parse_address.cc
+++ b/src/core/ext/filters/client_channel/parse_address.cc
@@ -19,6 +19,7 @@
#include <grpc/support/port_platform.h>
#include "src/core/ext/filters/client_channel/parse_address.h"
+#include "src/core/lib/iomgr/grpc_if_nametoindex.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/socket_utils.h"
@@ -35,6 +36,11 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
+#ifdef GRPC_POSIX_SOCKET
+#include <errno.h>
+#include <net/if.h>
+#endif
+
#ifdef GRPC_HAVE_UNIX_SOCKET
bool grpc_parse_unix(const grpc_uri* uri,
@@ -69,7 +75,12 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
// Split host and port.
char* host;
char* port;
- if (!gpr_split_host_port(hostport, &host, &port)) return false;
+ if (!gpr_split_host_port(hostport, &host, &port)) {
+ if (log_errors) {
+ gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
+ }
+ return false;
+ }
// Parse IP address.
memset(addr, 0, sizeof(*addr));
addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in));
@@ -115,7 +126,12 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
// Split host and port.
char* host;
char* port;
- if (!gpr_split_host_port(hostport, &host, &port)) return false;
+ if (!gpr_split_host_port(hostport, &host, &port)) {
+ if (log_errors) {
+ gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
+ }
+ return false;
+ }
// Parse IP address.
memset(addr, 0, sizeof(*addr));
addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in6));
@@ -150,10 +166,13 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
if (gpr_parse_bytes_to_uint32(host_end + 1,
strlen(host) - host_without_scope_len - 1,
&sin6_scope_id) == 0) {
- if (log_errors) {
- gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
+ if ((sin6_scope_id = grpc_if_nametoindex(host_end + 1)) == 0) {
+ gpr_log(GPR_ERROR,
+ "Invalid interface name: '%s'. "
+ "Non-numeric and failed if_nametoindex.",
+ host_end + 1);
+ goto done;
}
- goto done;
}
// Handle "sin6_scope_id" being type "u_long". See grpc issue #10027.
in6->sin6_scope_id = sin6_scope_id;
diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc
index 9077aa9753..640a052e91 100644
--- a/src/core/ext/filters/client_channel/subchannel.cc
+++ b/src/core/ext/filters/client_channel/subchannel.cc
@@ -64,18 +64,6 @@
#define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120
#define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2
-namespace {
-struct state_watcher {
- grpc_closure closure;
- grpc_subchannel* subchannel;
- grpc_connectivity_state connectivity_state;
- grpc_connectivity_state last_connectivity_state;
- grpc_core::OrphanablePtr<grpc_core::HealthCheckClient> health_check_client;
- grpc_closure health_check_closure;
- grpc_connectivity_state health_state;
-};
-} // namespace
-
typedef struct external_state_watcher {
grpc_subchannel* subchannel;
grpc_pollset_set* pollset_set;
@@ -101,9 +89,6 @@ struct grpc_subchannel {
keep the subchannel open */
gpr_atm ref_pair;
- /** non-transport related channel filters */
- const grpc_channel_filter** filters;
- size_t num_filters;
/** channel arguments */
grpc_channel_args* args;
@@ -384,7 +369,6 @@ static void subchannel_destroy(void* arg, grpc_error* error) {
c->channelz_subchannel->MarkSubchannelDestroyed();
c->channelz_subchannel.reset();
}
- gpr_free((void*)c->filters);
c->health_check_service_name.reset();
grpc_channel_args_destroy(c->args);
grpc_connectivity_state_destroy(&c->state_tracker);
@@ -553,7 +537,7 @@ struct HealthCheckParams {
} // namespace grpc_core
grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
- const grpc_subchannel_args* args) {
+ const grpc_channel_args* args) {
grpc_subchannel_key* key = grpc_subchannel_key_create(args);
grpc_subchannel* c = grpc_subchannel_index_find(key);
if (c) {
@@ -567,23 +551,13 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS);
c->connector = connector;
grpc_connector_ref(c->connector);
- c->num_filters = args->filter_count;
- if (c->num_filters > 0) {
- c->filters = static_cast<const grpc_channel_filter**>(
- gpr_malloc(sizeof(grpc_channel_filter*) * c->num_filters));
- memcpy((void*)c->filters, args->filters,
- sizeof(grpc_channel_filter*) * c->num_filters);
- } else {
- c->filters = nullptr;
- }
c->pollset_set = grpc_pollset_set_create();
grpc_resolved_address* addr =
static_cast<grpc_resolved_address*>(gpr_malloc(sizeof(*addr)));
- grpc_get_subchannel_address_arg(args->args, addr);
+ grpc_get_subchannel_address_arg(args, addr);
grpc_resolved_address* new_address = nullptr;
grpc_channel_args* new_args = nullptr;
- if (grpc_proxy_mappers_map_address(addr, args->args, &new_address,
- &new_args)) {
+ if (grpc_proxy_mappers_map_address(addr, args, &new_address, &new_args)) {
GPR_ASSERT(new_address != nullptr);
gpr_free(addr);
addr = new_address;
@@ -592,7 +566,7 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
grpc_arg new_arg = grpc_create_subchannel_address_arg(addr);
gpr_free(addr);
c->args = grpc_channel_args_copy_and_add_and_remove(
- new_args != nullptr ? new_args : args->args, keys_to_remove,
+ new_args != nullptr ? new_args : args, keys_to_remove,
GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1);
gpr_free(new_arg.value.string);
if (new_args != nullptr) grpc_channel_args_destroy(new_args);
@@ -605,7 +579,7 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
grpc_connectivity_state_init(&c->state_and_health_tracker, GRPC_CHANNEL_IDLE,
"subchannel");
grpc_core::BackOff::Options backoff_options;
- parse_args_for_backoff_values(args->args, &backoff_options,
+ parse_args_for_backoff_values(args, &backoff_options,
&c->min_connect_timeout_ms);
c->backoff.Init(backoff_options);
gpr_mu_init(&c->mu);
diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h
index 14f87f2c68..8c994c64f5 100644
--- a/src/core/ext/filters/client_channel/subchannel.h
+++ b/src/core/ext/filters/client_channel/subchannel.h
@@ -38,7 +38,6 @@
address. Provides a target for load balancing. */
typedef struct grpc_subchannel grpc_subchannel;
typedef struct grpc_subchannel_call grpc_subchannel_call;
-typedef struct grpc_subchannel_args grpc_subchannel_args;
typedef struct grpc_subchannel_key grpc_subchannel_key;
#ifndef NDEBUG
@@ -186,21 +185,9 @@ void grpc_subchannel_call_set_cleanup_closure(
grpc_call_stack* grpc_subchannel_call_get_call_stack(
grpc_subchannel_call* subchannel_call);
-struct grpc_subchannel_args {
- /* When updating this struct, also update subchannel_index.c */
-
- /** Channel filters for this channel - wrapped factories will likely
- want to mutate this */
- const grpc_channel_filter** filters;
- /** The number of filters in the above array */
- size_t filter_count;
- /** Channel arguments to be supplied to the newly created channel */
- const grpc_channel_args* args;
-};
-
/** create a subchannel given a connector */
grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
- const grpc_subchannel_args* args);
+ const grpc_channel_args* args);
/// Sets \a addr from \a args.
void grpc_get_subchannel_address_arg(const grpc_channel_args* args,
diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc
index aa8441f17b..d0ceda8312 100644
--- a/src/core/ext/filters/client_channel/subchannel_index.cc
+++ b/src/core/ext/filters/client_channel/subchannel_index.cc
@@ -39,55 +39,37 @@ static gpr_mu g_mu;
static gpr_refcount g_refcount;
struct grpc_subchannel_key {
- grpc_subchannel_args args;
+ grpc_channel_args* args;
};
static bool g_force_creation = false;
static grpc_subchannel_key* create_key(
- const grpc_subchannel_args* args,
+ const grpc_channel_args* args,
grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args)) {
grpc_subchannel_key* k =
static_cast<grpc_subchannel_key*>(gpr_malloc(sizeof(*k)));
- k->args.filter_count = args->filter_count;
- if (k->args.filter_count > 0) {
- k->args.filters = static_cast<const grpc_channel_filter**>(
- gpr_malloc(sizeof(*k->args.filters) * k->args.filter_count));
- memcpy(reinterpret_cast<grpc_channel_filter*>(k->args.filters),
- args->filters, sizeof(*k->args.filters) * k->args.filter_count);
- } else {
- k->args.filters = nullptr;
- }
- k->args.args = copy_channel_args(args->args);
+ k->args = copy_channel_args(args);
return k;
}
-grpc_subchannel_key* grpc_subchannel_key_create(
- const grpc_subchannel_args* args) {
+grpc_subchannel_key* grpc_subchannel_key_create(const grpc_channel_args* args) {
return create_key(args, grpc_channel_args_normalize);
}
static grpc_subchannel_key* subchannel_key_copy(grpc_subchannel_key* k) {
- return create_key(&k->args, grpc_channel_args_copy);
+ return create_key(k->args, grpc_channel_args_copy);
}
int grpc_subchannel_key_compare(const grpc_subchannel_key* a,
const grpc_subchannel_key* b) {
// To pretend the keys are different, return a non-zero value.
if (GPR_UNLIKELY(g_force_creation)) return 1;
- int c = GPR_ICMP(a->args.filter_count, b->args.filter_count);
- if (c != 0) return c;
- if (a->args.filter_count > 0) {
- c = memcmp(a->args.filters, b->args.filters,
- a->args.filter_count * sizeof(*a->args.filters));
- if (c != 0) return c;
- }
- return grpc_channel_args_compare(a->args.args, b->args.args);
+ return grpc_channel_args_compare(a->args, b->args);
}
void grpc_subchannel_key_destroy(grpc_subchannel_key* k) {
- gpr_free(reinterpret_cast<grpc_channel_args*>(k->args.filters));
- grpc_channel_args_destroy(const_cast<grpc_channel_args*>(k->args.args));
+ grpc_channel_args_destroy(k->args);
gpr_free(k);
}
diff --git a/src/core/ext/filters/client_channel/subchannel_index.h b/src/core/ext/filters/client_channel/subchannel_index.h
index c135613d26..429634bd54 100644
--- a/src/core/ext/filters/client_channel/subchannel_index.h
+++ b/src/core/ext/filters/client_channel/subchannel_index.h
@@ -27,8 +27,7 @@
shared amongst channels */
/** Create a key that can be used to uniquely identify a subchannel */
-grpc_subchannel_key* grpc_subchannel_key_create(
- const grpc_subchannel_args* args);
+grpc_subchannel_key* grpc_subchannel_key_create(const grpc_channel_args* args);
/** Destroy a subchannel key */
void grpc_subchannel_key_destroy(grpc_subchannel_key* key);