aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ext/filters/client_channel/client_channel_plugin.cc4
-rw-r--r--src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc11
-rw-r--r--src/core/ext/transport/chttp2/client/insecure/channel_create.cc36
-rw-r--r--src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc25
-rw-r--r--src/core/lib/channel/client_authority_filter.cc117
-rw-r--r--src/core/lib/channel/client_authority_filter.h34
-rw-r--r--src/core/lib/security/credentials/ssl/ssl_credentials.cc2
-rw-r--r--src/core/lib/security/security_connector/security_connector.cc10
-rw-r--r--src/core/lib/surface/channel.cc80
-rw-r--r--src/core/lib/surface/init.cc8
10 files changed, 266 insertions, 61 deletions
diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc
index 3c3a97532f..ed3ebd2696 100644
--- a/src/core/ext/filters/client_channel/client_channel_plugin.cc
+++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc
@@ -39,6 +39,8 @@ static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
+// Only used for direct channels, as they don't create subchannels, which is
+// where default authority is handled for regular channels.
static bool set_default_host_if_unset(grpc_channel_stack_builder* builder,
void* unused) {
const grpc_channel_args* args =
@@ -69,7 +71,7 @@ void grpc_client_channel_init(void) {
grpc_proxy_mapper_registry_init();
grpc_register_http_proxy_mapper();
grpc_subchannel_index_init();
- grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MIN,
+ grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MIN,
set_default_host_if_unset, nullptr);
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
index cb39e4224e..49918e11b7 100644
--- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
+++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
@@ -504,9 +504,7 @@ GrpcLb::BalancerCallState::BalancerCallState(
// the polling entities from client_channel.
GPR_ASSERT(grpclb_policy()->server_name_ != nullptr);
GPR_ASSERT(grpclb_policy()->server_name_[0] != '\0');
- grpc_slice host =
- grpc_slice_from_copied_string(grpclb_policy()->server_name_);
- grpc_millis deadline =
+ const grpc_millis deadline =
grpclb_policy()->lb_call_timeout_ms_ == 0
? GRPC_MILLIS_INF_FUTURE
: ExecCtx::Get()->Now() + grpclb_policy()->lb_call_timeout_ms_;
@@ -514,8 +512,7 @@ GrpcLb::BalancerCallState::BalancerCallState(
grpclb_policy()->lb_channel_, nullptr, GRPC_PROPAGATE_DEFAULTS,
grpclb_policy_->interested_parties(),
GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD,
- &host, deadline, nullptr);
- grpc_slice_unref_internal(host);
+ nullptr, deadline, nullptr);
// Init the LB call request payload.
grpc_grpclb_request* request =
grpc_grpclb_request_create(grpclb_policy()->server_name_);
@@ -982,6 +979,10 @@ grpc_channel_args* BuildBalancerChannelArgs(
// with the one from the grpclb policy, used to propagate updates to
// the LB channel.
GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
+ // The LB channel should use the authority indicated by the target
+ // authority table (see \a grpc_lb_policy_grpclb_modify_lb_channel_args),
+ // as opposed to the authority from the parent channel.
+ GRPC_ARG_DEFAULT_AUTHORITY,
};
// Channel args to add.
const grpc_arg args_to_add[] = {
diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc
index 60800365b8..8424cc5bc6 100644
--- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc
+++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc
@@ -38,11 +38,41 @@ static void client_channel_factory_ref(
static void client_channel_factory_unref(
grpc_client_channel_factory* cc_factory) {}
+static grpc_channel_args* add_default_authority_if_not_present(
+ const grpc_channel_args* args) {
+ const bool has_default_authority =
+ grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) != nullptr;
+ grpc_arg new_args[1];
+ size_t num_new_args = 0;
+ grpc_core::UniquePtr<char> default_authority;
+ if (!has_default_authority) {
+ const grpc_arg* server_uri_arg =
+ grpc_channel_args_find(args, GRPC_ARG_SERVER_URI);
+ const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg);
+ GPR_ASSERT(server_uri_str != nullptr);
+ default_authority =
+ grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str);
+ GPR_ASSERT(default_authority != nullptr);
+ new_args[num_new_args++] = grpc_channel_arg_string_create(
+ const_cast<char*>(GRPC_ARG_DEFAULT_AUTHORITY), default_authority.get());
+ }
+ return grpc_channel_args_copy_and_add(args, new_args, num_new_args);
+}
+
static grpc_subchannel* client_channel_factory_create_subchannel(
grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) {
+ grpc_subchannel_args* final_sc_args =
+ static_cast<grpc_subchannel_args*>(gpr_malloc(sizeof(*final_sc_args)));
+ memcpy(final_sc_args, args, sizeof(*args));
+ final_sc_args->args = add_default_authority_if_not_present(args->args);
+
grpc_connector* connector = grpc_chttp2_connector_create();
- grpc_subchannel* s = grpc_subchannel_create(connector, args);
+ grpc_subchannel* s = grpc_subchannel_create(connector, final_sc_args);
grpc_connector_unref(connector);
+
+ grpc_channel_args_destroy(
+ const_cast<grpc_channel_args*>(final_sc_args->args));
+ gpr_free(final_sc_args);
return s;
}
@@ -56,8 +86,8 @@ static grpc_channel* client_channel_factory_create_channel(
// Add channel arg containing the server URI.
grpc_core::UniquePtr<char> canonical_target =
grpc_core::ResolverRegistry::AddDefaultPrefixIfNeeded(target);
- grpc_arg arg = grpc_channel_arg_string_create((char*)GRPC_ARG_SERVER_URI,
- canonical_target.get());
+ grpc_arg arg = grpc_channel_arg_string_create(
+ const_cast<char*>(GRPC_ARG_SERVER_URI), canonical_target.get());
const char* to_remove[] = {GRPC_ARG_SERVER_URI};
grpc_channel_args* new_args =
grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1);
diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
index a82009ff69..5ce73a95d7 100644
--- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
+++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
@@ -71,9 +71,6 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
grpc_uri* server_uri =
grpc_uri_parse(server_uri_str, true /* supress errors */);
GPR_ASSERT(server_uri != nullptr);
- const char* server_uri_path;
- server_uri_path =
- server_uri->path[0] == '/' ? server_uri->path + 1 : server_uri->path;
const grpc_core::TargetAuthorityTable* target_authority_table =
grpc_core::FindTargetAuthorityTableInArgs(args->args);
grpc_core::UniquePtr<char> authority;
@@ -98,33 +95,49 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
// authority table was present or because the target was not present
// in the table), fall back to using the original server URI.
if (authority == nullptr) {
- authority.reset(gpr_strdup(server_uri_path));
+ authority =
+ grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str);
}
+ grpc_arg args_to_add[2];
+ size_t num_args_to_add = 0;
+ if (grpc_channel_args_find(args->args, GRPC_ARG_DEFAULT_AUTHORITY) ==
+ nullptr) {
+ // If the channel args don't already contain GRPC_ARG_DEFAULT_AUTHORITY, add
+ // the arg, setting it to the value just obtained.
+ args_to_add[num_args_to_add++] = grpc_channel_arg_string_create(
+ const_cast<char*>(GRPC_ARG_DEFAULT_AUTHORITY), authority.get());
+ }
+ grpc_channel_args* args_with_authority =
+ grpc_channel_args_copy_and_add(args->args, args_to_add, num_args_to_add);
grpc_uri_destroy(server_uri);
grpc_channel_security_connector* subchannel_security_connector = nullptr;
// Create the security connector using the credentials and target name.
grpc_channel_args* new_args_from_connector = nullptr;
const grpc_security_status security_status =
grpc_channel_credentials_create_security_connector(
- channel_credentials, authority.get(), args->args,
+ channel_credentials, authority.get(), args_with_authority,
&subchannel_security_connector, &new_args_from_connector);
if (security_status != GRPC_SECURITY_OK) {
gpr_log(GPR_ERROR,
"Failed to create secure subchannel for secure name '%s'",
authority.get());
+ grpc_channel_args_destroy(args_with_authority);
return nullptr;
}
grpc_arg new_security_connector_arg =
grpc_security_connector_to_arg(&subchannel_security_connector->base);
grpc_channel_args* new_args = grpc_channel_args_copy_and_add(
- new_args_from_connector != nullptr ? new_args_from_connector : args->args,
+ new_args_from_connector != nullptr ? new_args_from_connector
+ : args_with_authority,
&new_security_connector_arg, 1);
+
GRPC_SECURITY_CONNECTOR_UNREF(&subchannel_security_connector->base,
"lb_channel_create");
if (new_args_from_connector != nullptr) {
grpc_channel_args_destroy(new_args_from_connector);
}
+ grpc_channel_args_destroy(args_with_authority);
grpc_subchannel_args* final_sc_args =
static_cast<grpc_subchannel_args*>(gpr_malloc(sizeof(*final_sc_args)));
memcpy(final_sc_args, args, sizeof(*args));
diff --git a/src/core/lib/channel/client_authority_filter.cc b/src/core/lib/channel/client_authority_filter.cc
new file mode 100644
index 0000000000..57c5d29a93
--- /dev/null
+++ b/src/core/lib/channel/client_authority_filter.cc
@@ -0,0 +1,117 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <grpc/support/port_platform.h>
+
+#include <assert.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+
+#include "src/core/lib/channel/channel_args.h"
+#include "src/core/lib/channel/client_authority_filter.h"
+#include "src/core/lib/gpr/string.h"
+#include "src/core/lib/slice/slice_internal.h"
+#include "src/core/lib/slice/slice_string_helpers.h"
+#include "src/core/lib/surface/call.h"
+#include "src/core/lib/surface/channel_init.h"
+#include "src/core/lib/surface/channel_stack_type.h"
+#include "src/core/lib/transport/static_metadata.h"
+
+namespace {
+
+struct call_data {
+ grpc_linked_mdelem authority_storage;
+ grpc_call_combiner* call_combiner;
+};
+
+struct channel_data {
+ grpc_slice default_authority;
+};
+
+void authority_start_transport_stream_op_batch(
+ grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ // Handle send_initial_metadata.
+ auto* initial_metadata =
+ batch->payload->send_initial_metadata.send_initial_metadata;
+ // If the initial metadata doesn't already contain :authority, add it.
+ if (batch->send_initial_metadata &&
+ initial_metadata->idx.named.authority == nullptr) {
+ grpc_error* error = grpc_metadata_batch_add_head(
+ initial_metadata, &calld->authority_storage,
+ grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY,
+ grpc_slice_ref(chand->default_authority)));
+ if (error != GRPC_ERROR_NONE) {
+ grpc_transport_stream_op_batch_finish_with_failure(batch, error,
+ calld->call_combiner);
+ return;
+ }
+ }
+ // Pass control down the stack.
+ grpc_call_next_op(elem, batch);
+}
+
+/* Constructor for call_data */
+grpc_error* init_call_elem(grpc_call_element* elem,
+ const grpc_call_element_args* args) {
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ calld->call_combiner = args->call_combiner;
+ return GRPC_ERROR_NONE;
+}
+
+/* Destructor for call_data */
+void destroy_call_elem(grpc_call_element* elem,
+ const grpc_call_final_info* final_info,
+ grpc_closure* ignored) {}
+
+/* Constructor for channel_data */
+grpc_error* init_channel_elem(grpc_channel_element* elem,
+ grpc_channel_element_args* args) {
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
+ const grpc_arg* default_authority_arg =
+ grpc_channel_args_find(args->channel_args, GRPC_ARG_DEFAULT_AUTHORITY);
+ GPR_ASSERT(default_authority_arg != nullptr);
+ chand->default_authority = grpc_slice_from_copied_string(
+ grpc_channel_arg_get_string(default_authority_arg));
+ GPR_ASSERT(!args->is_last);
+ return GRPC_ERROR_NONE;
+}
+
+/* Destructor for channel data */
+void destroy_channel_elem(grpc_channel_element* elem) {
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
+ grpc_slice_unref(chand->default_authority);
+}
+} // namespace
+
+const grpc_channel_filter grpc_client_authority_filter = {
+ authority_start_transport_stream_op_batch,
+ grpc_channel_next_op,
+ sizeof(call_data),
+ init_call_elem,
+ grpc_call_stack_ignore_set_pollset_or_pollset_set,
+ destroy_call_elem,
+ sizeof(channel_data),
+ init_channel_elem,
+ destroy_channel_elem,
+ grpc_channel_next_get_info,
+ "authority"};
diff --git a/src/core/lib/channel/client_authority_filter.h b/src/core/lib/channel/client_authority_filter.h
new file mode 100644
index 0000000000..ba996dc823
--- /dev/null
+++ b/src/core/lib/channel/client_authority_filter.h
@@ -0,0 +1,34 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H
+#define GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H
+
+#include <grpc/support/port_platform.h>
+
+#include <grpc/impl/codegen/compression_types.h>
+
+#include "src/core/lib/channel/channel_stack.h"
+
+/// Filter responsible for setting the authority header, if not already set. It
+/// uses the value of the GRPC_ARG_DEFAULT_AUTHORITY channel arg if the initial
+/// metadata doesn't already contain an authority value.
+
+extern const grpc_channel_filter grpc_client_authority_filter;
+
+#endif /* GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H */
diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc
index 252b25bc0a..295f13c3b7 100644
--- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc
+++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc
@@ -58,7 +58,7 @@ static grpc_security_status ssl_create_security_connector(
const char* overridden_target_name = nullptr;
for (size_t i = 0; args && i < args->num_args; i++) {
grpc_arg* arg = &args->args[i];
- if (strcmp(arg->key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == 0 &&
+ if (strcmp(arg->key, GRPC_ARG_DEFAULT_AUTHORITY) == 0 &&
arg->type == GRPC_ARG_STRING) {
overridden_target_name = arg->value.string;
break;
diff --git a/src/core/lib/security/security_connector/security_connector.cc b/src/core/lib/security/security_connector/security_connector.cc
index 3cc151bec7..7b90b19075 100644
--- a/src/core/lib/security/security_connector/security_connector.cc
+++ b/src/core/lib/security/security_connector/security_connector.cc
@@ -465,12 +465,10 @@ static bool fake_channel_check_call_host(grpc_channel_security_connector* sc,
grpc_error** error) {
grpc_fake_channel_security_connector* c =
reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
- if (c->is_lb_channel) {
- // TODO(dgq): verify that the host (ie, authority header) matches that of
- // the LB, as opposed to that of the backends.
- } else {
- // TODO(dgq): verify that the host (ie, authority header) matches that of
- // the backend, not the LB's.
+ if (c->is_lb_channel && strcmp(host, c->target) != 0) {
+ gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s' for an LB call",
+ host, c->target);
+ abort();
}
return true;
}
diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc
index 03353d6beb..48bc69509f 100644
--- a/src/core/lib/surface/channel.cc
+++ b/src/core/lib/surface/channel.cc
@@ -32,6 +32,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/string.h"
+#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h"
@@ -55,7 +56,6 @@ typedef struct registered_call {
struct grpc_channel {
int is_client;
grpc_compression_options compression_options;
- grpc_mdelem default_authority;
gpr_atm call_size_estimate;
@@ -108,40 +108,8 @@ grpc_channel* grpc_channel_create_with_builder(
grpc_compression_options_init(&channel->compression_options);
for (size_t i = 0; i < args->num_args; i++) {
- if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) {
- if (args->args[i].type != GRPC_ARG_STRING) {
- gpr_log(GPR_ERROR, "%s ignored: it must be a string",
- GRPC_ARG_DEFAULT_AUTHORITY);
- } else {
- if (!GRPC_MDISNULL(channel->default_authority)) {
- /* setting this takes precedence over anything else */
- GRPC_MDELEM_UNREF(channel->default_authority);
- }
- channel->default_authority = grpc_mdelem_from_slices(
- GRPC_MDSTR_AUTHORITY,
- grpc_slice_intern(
- grpc_slice_from_static_string(args->args[i].value.string)));
- }
- } else if (0 ==
- strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) {
- if (args->args[i].type != GRPC_ARG_STRING) {
- gpr_log(GPR_ERROR, "%s ignored: it must be a string",
- GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
- } else {
- if (!GRPC_MDISNULL(channel->default_authority)) {
- /* other ways of setting this (notably ssl) take precedence */
- gpr_log(GPR_ERROR,
- "%s ignored: default host already set some other way",
- GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
- } else {
- channel->default_authority = grpc_mdelem_from_slices(
- GRPC_MDSTR_AUTHORITY,
- grpc_slice_intern(
- grpc_slice_from_static_string(args->args[i].value.string)));
- }
- }
- } else if (0 == strcmp(args->args[i].key,
- GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL)) {
+ if (0 ==
+ strcmp(args->args[i].key, GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL)) {
channel->compression_options.default_level.is_set = true;
channel->compression_options.default_level.level =
static_cast<grpc_compression_level>(grpc_channel_arg_get_integer(
@@ -169,12 +137,49 @@ done:
return channel;
}
+static grpc_core::UniquePtr<char> get_default_authority(
+ const char* target, const grpc_channel_args* input_args,
+ grpc_channel_stack_type channel_stack_type) {
+ bool has_default_authority = false;
+ char* ssl_override = nullptr;
+ grpc_core::UniquePtr<char> default_authority;
+ const size_t num_args = input_args != nullptr ? input_args->num_args : 0;
+ for (size_t i = 0; i < num_args; ++i) {
+ if (0 == strcmp(input_args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) {
+ has_default_authority = true;
+ } else if (0 == strcmp(input_args->args[i].key,
+ GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) {
+ ssl_override = input_args->args[i].value.string;
+ }
+ }
+ if (!has_default_authority && ssl_override != nullptr) {
+ default_authority.reset(gpr_strdup(ssl_override));
+ }
+ return default_authority;
+}
+
+static grpc_channel_args* build_channel_args(
+ const grpc_channel_args* input_args, char* default_authority) {
+ grpc_arg new_args[1];
+ size_t num_new_args = 0;
+ if (default_authority != nullptr) {
+ new_args[num_new_args++] = grpc_channel_arg_string_create(
+ const_cast<char*>(GRPC_ARG_DEFAULT_AUTHORITY), default_authority);
+ }
+ return grpc_channel_args_copy_and_add(input_args, new_args, num_new_args);
+}
+
grpc_channel* grpc_channel_create(const char* target,
const grpc_channel_args* input_args,
grpc_channel_stack_type channel_stack_type,
grpc_transport* optional_transport) {
grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create();
- grpc_channel_stack_builder_set_channel_arguments(builder, input_args);
+ const grpc_core::UniquePtr<char> default_authority =
+ get_default_authority(target, input_args, channel_stack_type);
+ grpc_channel_args* args =
+ build_channel_args(input_args, default_authority.get());
+ grpc_channel_stack_builder_set_channel_arguments(builder, args);
+ grpc_channel_args_destroy(args);
grpc_channel_stack_builder_set_target(builder, target);
grpc_channel_stack_builder_set_transport(builder, optional_transport);
if (!grpc_channel_init_create_stack(builder, channel_stack_type)) {
@@ -246,8 +251,6 @@ static grpc_call* grpc_channel_create_call_internal(
send_metadata[num_metadata++] = path_mdelem;
if (!GRPC_MDISNULL(authority_mdelem)) {
send_metadata[num_metadata++] = authority_mdelem;
- } else if (!GRPC_MDISNULL(channel->default_authority)) {
- send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority);
}
grpc_call_create_args args;
@@ -377,7 +380,6 @@ static void destroy_channel(void* arg, grpc_error* error) {
GRPC_MDELEM_UNREF(rc->authority);
gpr_free(rc);
}
- GRPC_MDELEM_UNREF(channel->default_authority);
gpr_mu_destroy(&channel->registered_call_mu);
gpr_free(channel->target);
gpr_free(channel);
diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc
index ac9f9e6066..10c65ce09f 100644
--- a/src/core/lib/surface/init.cc
+++ b/src/core/lib/surface/init.cc
@@ -27,6 +27,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack.h"
+#include "src/core/lib/channel/client_authority_filter.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/debug/stats.h"
@@ -83,6 +84,13 @@ static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) {
}
static void register_builtin_channel_init() {
+ grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX,
+ prepend_filter,
+ (void*)(&grpc_client_authority_filter));
+ grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
+ prepend_filter,
+ (void*)(&grpc_client_authority_filter));
+
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);