Commit 05e67af0 authored by Hugo Benichi's avatar Hugo Benichi Committed by Commit Bot

arc: net: deprecate usage of arc::mojom::IPConfiguration

Also do not consider shill::kIPConfigProperty as a possible IP
configuration dictionary. This is instead always a single string or a
list of string referring to DBus path strings of IP configuration
objects and therefore never contains immediately useful properties.

BUG=b:143258259
BUG=b:145960788
TEST=Compiled. Flashed eve, checked ARC++ connectivity for various types
of networks.

Change-Id: I330edf9e2cd747252cd81a00b883f6f6094c88ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217686Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: Hugo Benichi <hugobenichi@google.com>
Auto-Submit: Hugo Benichi <hugobenichi@google.com>
Cr-Commit-Position: refs/heads/master@{#781856}
parent 936e436f
......@@ -92,7 +92,8 @@ enum IPAddressType {
IPV6,
};
// Layer 3 and proxy configuration information for an IP network.
// Deprecated. Individual fields added to NetworkConfiguration in version 13 of
// this file should be used instead.
struct IPConfiguration {
// Literal representation of the IP address of the ARC gateway.
......@@ -190,8 +191,9 @@ struct NetworkConfiguration {
// A string token that uniquely identifies this network service.
string guid;
// IP configuration for the network service inside ARC.
array<IPConfiguration>? ip_configs;
// Deprecated. Individual fields added to NetworkConfiguration in version 13
// of this file should be used instead.
array<IPConfiguration>? deprecated_ip_configs;
// Deprecated field unused from ARC P and later.
string? deprecated_mac_address;
......
......@@ -135,41 +135,32 @@ arc::mojom::NetworkType TranslateNetworkType(const std::string& type) {
return arc::mojom::NetworkType::ETHERNET;
}
// Parse a shill IPConfig dictionary and appends the resulting mojo
// IPConfiguration object to the given |ip_configs| vector, only if the
// IPConfig dictionary contains an address and a gateway property.
// TODO(b/143258259) Stop setting IPConfiguration objects once ARC has
// migrated to the new IP configuration fields introduced in Change-Id
// I08dfd5daa9ba2946a847e555bb94a01da3866eb9.
// Parses a shill IPConfig dictionary and adds the relevant fields to
// the given |network| NetworkConfiguration object.
void AddIpConfiguration(arc::mojom::NetworkConfiguration* network,
const base::Value* shill_ipconfig) {
if (!shill_ipconfig || !shill_ipconfig->is_dict())
return;
auto ip_config = arc::mojom::IPConfiguration::New();
if (const auto* address_property =
shill_ipconfig->FindStringPath(shill::kAddressProperty)) {
ip_config->ip_address = *address_property;
}
if (ip_config->ip_address.empty())
return;
if (const auto* gateway_property =
shill_ipconfig->FindStringPath(shill::kGatewayProperty)) {
ip_config->gateway = *gateway_property;
}
if (ip_config->gateway.empty())
return;
ip_config->routing_prefix =
// Only set the IP address and gateway if both are defined and non empty.
const auto* address = shill_ipconfig->FindStringPath(shill::kAddressProperty);
const auto* gateway = shill_ipconfig->FindStringPath(shill::kGatewayProperty);
const int prefixlen =
shill_ipconfig->FindIntPath(shill::kPrefixlenProperty).value_or(0);
if (address && !address->empty() && gateway && !gateway->empty()) {
if (prefixlen < 64) {
network->host_ipv4_prefix_length = prefixlen;
network->host_ipv4_address = *address;
network->host_ipv4_gateway = *gateway;
} else {
network->host_ipv6_prefix_length = prefixlen;
network->host_ipv6_global_addresses->push_back(*address);
network->host_ipv6_gateway = *gateway;
}
}
ip_config->type = (ip_config->routing_prefix < 64)
? arc::mojom::IPAddressType::IPV4
: arc::mojom::IPAddressType::IPV6;
// If the user has overridden DNS with the "Google nameservers" UI options,
// the kStaticIPConfigProperty object will be empty except for DNS addresses.
if (const auto* dns_list =
shill_ipconfig->FindListKey(shill::kNameServersProperty)) {
for (const auto& dns_value : dns_list->GetList()) {
......@@ -182,30 +173,10 @@ void AddIpConfiguration(arc::mojom::NetworkConfiguration* network,
if (dns == "0.0.0.0")
continue;
ip_config->name_servers.push_back(dns);
network->host_dns_addresses->push_back(dns);
}
}
switch (ip_config->type) {
case arc::mojom::IPAddressType::IPV4: {
network->host_ipv4_prefix_length = ip_config->routing_prefix;
network->host_ipv4_address = ip_config->ip_address;
network->host_ipv4_gateway = ip_config->gateway;
break;
}
case arc::mojom::IPAddressType::IPV6: {
network->host_ipv6_prefix_length = ip_config->routing_prefix;
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;
}
}
if (const auto* domains =
shill_ipconfig->FindKey(shill::kSearchDomainsProperty)) {
if (domains->is_list()) {
......@@ -217,8 +188,6 @@ void AddIpConfiguration(arc::mojom::NetworkConfiguration* network,
const int mtu = shill_ipconfig->FindIntPath(shill::kMtuProperty).value_or(0);
if (mtu > 0)
network->host_mtu = mtu;
network->ip_configs->push_back(std::move(ip_config));
}
arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties(
......@@ -226,7 +195,6 @@ arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties(
const base::Value* shill_dict) {
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>();
......@@ -264,11 +232,7 @@ arc::mojom::NetworkConfigurationPtr TranslateNetworkProperties(
if (shill_dict) {
for (const auto* property :
{shill::kIPConfigProperty, shill::kStaticIPConfigProperty,
shill::kSavedIPConfigProperty}) {
if (!mojo->ip_configs->empty())
break;
{shill::kStaticIPConfigProperty, shill::kSavedIPConfigProperty}) {
AddIpConfiguration(mojo.get(), shill_dict->FindKey(property));
}
}
......
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