Commit 740b177c authored by Hugo Benichi's avatar Hugo Benichi Committed by Commit Bot

arc: net: populate new fields in NetworkConfiguration

This patch populates new fields relative to the host IP configuration
added in Change-Id I08dfd5daa9ba2946a847e555bb94a01da3866eb9 to
NetworkConfiguration mojo objects.

Currently, layer 3 information can come from shill Device properties
(kIPConfigsProperty) or from shill Service properties
(kIPConfigProperty, kSavedIPConfigProperty, kStaticIPConfigProperty).

This patch changes the order in which this properties are tried to
prioritize Device properties.

BUG=b:143258259
BUG=b:145960788
BUG=crbug:795603
TEST=Compiled, flashed eve, checked that ARC++ sees the host IPv4 and
IPv6 configuration, mtu, and search domains for following networks: eth,
wifi, L2TP vpn connections, Chrome extension VPN connections.

Change-Id: I6d5e6b6eed477b0aef762d2b18b8ef2ce9fa2ff9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1962129
Commit-Queue: Hugo Benichi <hugobenichi@google.com>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774528}
parent a12f7b08
...@@ -138,7 +138,10 @@ arc::mojom::NetworkType TranslateNetworkType(const std::string& type) { ...@@ -138,7 +138,10 @@ arc::mojom::NetworkType TranslateNetworkType(const std::string& type) {
// Parse a shill IPConfig dictionary and appends the resulting mojo // Parse a shill IPConfig dictionary and appends the resulting mojo
// IPConfiguration object to the given |ip_configs| vector, only if the // IPConfiguration object to the given |ip_configs| vector, only if the
// IPConfig dictionary contains an address and a gateway property. // IPConfig dictionary contains an address and a gateway property.
void AddIpConfiguration(std::vector<arc::mojom::IPConfigurationPtr>& ip_configs, // TODO(b/143258259) Stop setting IPConfiguration objects once ARC has
// migrated to the new IP configuration fields introduced in Change-Id
// I08dfd5daa9ba2946a847e555bb94a01da3866eb9.
void AddIpConfiguration(arc::mojom::NetworkConfiguration* network,
const base::Value* shill_ipconfig) { const base::Value* shill_ipconfig) {
if (!shill_ipconfig || !shill_ipconfig->is_dict()) if (!shill_ipconfig || !shill_ipconfig->is_dict())
return; return;
...@@ -180,36 +183,53 @@ void AddIpConfiguration(std::vector<arc::mojom::IPConfigurationPtr>& ip_configs, ...@@ -180,36 +183,53 @@ void AddIpConfiguration(std::vector<arc::mojom::IPConfigurationPtr>& ip_configs,
continue; continue;
ip_config->name_servers.push_back(dns); ip_config->name_servers.push_back(dns);
network->host_dns_addresses->push_back(dns);
} }
} }
ip_configs.push_back(std::move(ip_config)); switch (ip_config->type) {
} case arc::mojom::IPAddressType::IPV4: {
network->host_ipv4_prefix_length = ip_config->routing_prefix;
// Add shill's Device properties to the given mojo NetworkConfiguration objects. network->host_ipv4_address = ip_config->ip_address;
// This adds the network interface and current IP configurations. network->host_ipv4_gateway = ip_config->gateway;
void AddDeviceProperties(arc::mojom::NetworkConfiguration* network, break;
const std::string& device_path) { }
const auto* device = GetStateHandler()->GetDeviceState(device_path); case arc::mojom::IPAddressType::IPV6: {
if (!device) network->host_ipv6_prefix_length = ip_config->routing_prefix;
return; network->host_ipv6_global_addresses->push_back(ip_config->ip_address);
network->host_ipv6_gateway = ip_config->gateway;
break;
}
default: {
NOTREACHED() << "No IPAddressType defined";
break;
}
}
network->network_interface = device->interface(); if (const auto* domains =
shill_ipconfig->FindKey(shill::kSearchDomainsProperty)) {
if (domains->is_list()) {
for (const auto& domain : domains->GetList())
network->host_search_domains->push_back(domain.GetString());
}
}
std::vector<arc::mojom::IPConfigurationPtr> ip_configs; const int mtu = shill_ipconfig->FindIntPath(shill::kMtuProperty).value_or(0);
for (const auto& kv : device->ip_configs()) if (mtu > 0)
AddIpConfiguration(ip_configs, kv.second.get()); network->host_mtu = mtu;
// If the DeviceState had any IP configuration, always use them and ignore network->ip_configs->push_back(std::move(ip_config));
// any other IP configuration previously obtained through NetworkState.
if (!ip_configs.empty())
network->ip_configs = std::move(ip_configs);
} }
arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties( arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties(
const chromeos::NetworkState* network_state, const chromeos::NetworkState* network_state,
const base::Value* shill_dict) { const base::Value* shill_dict) {
auto mojo = arc::mojom::NetworkConfiguration::New(); auto mojo = arc::mojom::NetworkConfiguration::New();
// Initialize optional array fields to avoid null guards both here and in ARC.
mojo->ip_configs = std::vector<arc::mojom::IPConfigurationPtr>();
mojo->host_ipv6_global_addresses = std::vector<std::string>();
mojo->host_search_domains = std::vector<std::string>();
mojo->host_dns_addresses = std::vector<std::string>();
mojo->connection_state = mojo->connection_state =
TranslateConnectionState(network_state->connection_state()); TranslateConnectionState(network_state->connection_state());
mojo->guid = network_state->guid(); mojo->guid = network_state->guid();
...@@ -232,18 +252,26 @@ arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties( ...@@ -232,18 +252,26 @@ arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties(
// yet. This case is covered by requesting shill properties asynchronously // yet. This case is covered by requesting shill properties asynchronously
// when chromeos::NetworkStateHandlerObserver::NetworkPropertiesUpdated is // when chromeos::NetworkStateHandlerObserver::NetworkPropertiesUpdated is
// called. // called.
std::vector<arc::mojom::IPConfigurationPtr> ip_configs;
// Add shill's Device properties to the given mojo NetworkConfiguration
// objects. This adds the network interface and current IP configurations.
if (const auto* device =
GetStateHandler()->GetDeviceState(network_state->device_path())) {
mojo->network_interface = device->interface();
for (const auto& kv : device->ip_configs())
AddIpConfiguration(mojo.get(), kv.second.get());
}
if (shill_dict) { if (shill_dict) {
for (const auto* property : for (const auto* property :
{shill::kIPConfigProperty, shill::kStaticIPConfigProperty, {shill::kIPConfigProperty, shill::kStaticIPConfigProperty,
shill::kSavedIPConfigProperty}) { shill::kSavedIPConfigProperty}) {
if (!ip_configs.empty()) if (!mojo->ip_configs->empty())
break; break;
AddIpConfiguration(ip_configs, shill_dict->FindKey(property)); AddIpConfiguration(mojo.get(), shill_dict->FindKey(property));
} }
} }
mojo->ip_configs = std::move(ip_configs);
if (mojo->type == arc::mojom::NetworkType::WIFI) { if (mojo->type == arc::mojom::NetworkType::WIFI) {
mojo->wifi = arc::mojom::WiFi::New(); mojo->wifi = arc::mojom::WiFi::New();
...@@ -257,8 +285,6 @@ arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties( ...@@ -257,8 +285,6 @@ arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties(
mojo->wifi->signal_strength = network_state->signal_strength(); mojo->wifi->signal_strength = network_state->signal_strength();
} }
AddDeviceProperties(mojo.get(), network_state->device_path());
return mojo; return mojo;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment