summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorpneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 11:29:26 +0000
committerpneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 11:29:26 +0000
commitaf8f5450b5e2c80ccada296a88dc515701309d56 (patch)
treea158295d30f419f77e182779abfae07207a5e55f /chromeos
parenteb09a62ef40f62e8ae9a13071cf7e47d6915ebd9 (diff)
downloadchromium_src-af8f5450b5e2c80ccada296a88dc515701309d56.zip
chromium_src-af8f5450b5e2c80ccada296a88dc515701309d56.tar.gz
chromium_src-af8f5450b5e2c80ccada296a88dc515701309d56.tar.bz2
Add Shill to ONC translation of IPConfig.
So far, the ONC IPConfig object was only validated but not translated to or from Shill. This adds the one direction, from Shill to ONC. This allows exposing the current IP config state of Shill through ONC, e.g. with in the networkingPrivate API. BUG=288288 Review URL: https://codereview.chromium.org/249193003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266848 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/network/onc/onc_signature.cc6
-rw-r--r--chromeos/network/onc/onc_translation_tables.cc10
-rw-r--r--chromeos/network/onc/onc_translator_shill_to_onc.cc41
-rw-r--r--chromeos/network/onc/onc_translator_unittest.cc2
-rw-r--r--chromeos/network/onc/onc_validator_unittest.cc3
-rw-r--r--chromeos/test/data/network/shill_ethernet_with_ipconfig.json23
-rw-r--r--chromeos/test/data/network/translation_of_shill_ethernet_with_ipconfig.onc27
7 files changed, 101 insertions, 11 deletions
diff --git a/chromeos/network/onc/onc_signature.cc b/chromeos/network/onc/onc_signature.cc
index eb72ec8..a5f8cc3 100644
--- a/chromeos/network/onc/onc_signature.cc
+++ b/chromeos/network/onc/onc_signature.cc
@@ -163,11 +163,11 @@ const OncFieldSignature ethernet_fields[] = {
{ ::onc::ethernet::kEAP, &kEAPSignature},
{NULL}};
-// Not supported, yet.
+// Not supported for policy but for reading network state.
const OncFieldSignature ipconfig_fields[] = {
{ ::onc::ipconfig::kGateway, &kStringSignature},
{ ::onc::ipconfig::kIPAddress, &kStringSignature},
- { ::onc::network_config::kNameServers, &kStringSignature},
+ { ::onc::ipconfig::kNameServers, &kStringListSignature},
{ ::onc::ipconfig::kRoutingPrefix, &kIntegerSignature},
{ ::onc::network_config::kSearchDomains, &kStringListSignature},
{ ::onc::ipconfig::kType, &kStringSignature},
@@ -261,7 +261,7 @@ const OncFieldSignature network_configuration_fields[] = {
{ ::onc::kRecommended, &kRecommendedSignature},
{ ::onc::network_config::kEthernet, &kEthernetSignature},
{ ::onc::network_config::kGUID, &kStringSignature},
- // Not supported, yet.
+ // Not supported for policy but for reading network state.
{ ::onc::network_config::kIPConfigs, &kIPConfigListSignature},
{ ::onc::network_config::kName, &kStringSignature},
// Not supported, yet.
diff --git a/chromeos/network/onc/onc_translation_tables.cc b/chromeos/network/onc/onc_translation_tables.cc
index 603c3b3..c520cf9 100644
--- a/chromeos/network/onc/onc_translation_tables.cc
+++ b/chromeos/network/onc/onc_translation_tables.cc
@@ -18,8 +18,6 @@ namespace onc {
//
// Proxy settings are converted to Shill by function
// ConvertOncProxySettingsToProxyConfig(...).
-//
-// Translation of IPConfig objects is not supported, yet.
namespace {
@@ -175,6 +173,13 @@ const FieldTranslationEntry network_fields[] = {
// { ::onc::network_config::kConnectionState, shill::kStateProperty },
{NULL}};
+const FieldTranslationEntry ipconfig_fields[] = {
+ { ::onc::ipconfig::kIPAddress, shill::kAddressProperty},
+ { ::onc::ipconfig::kGateway, shill::kGatewayProperty},
+ { ::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
+ { ::onc::ipconfig::kNameServers, shill::kNameServersProperty},
+ {NULL}};
+
struct OncValueTranslationEntry {
const OncValueSignature* onc_signature;
const FieldTranslationEntry* field_translation_table;
@@ -196,6 +201,7 @@ const OncValueTranslationEntry onc_value_translation_table[] = {
{ &kCellularWithStateSignature, cellular_fields },
{ &kNetworkWithStateSignature, network_fields },
{ &kNetworkConfigurationSignature, network_fields },
+ { &kIPConfigSignature, ipconfig_fields },
{ NULL }
};
diff --git a/chromeos/network/onc/onc_translator_shill_to_onc.cc b/chromeos/network/onc/onc_translator_shill_to_onc.cc
index 11f59f4..7716fbf 100644
--- a/chromeos/network/onc/onc_translator_shill_to_onc.cc
+++ b/chromeos/network/onc/onc_translator_shill_to_onc.cc
@@ -66,6 +66,7 @@ class ShillToONCTranslator {
void TranslateWiFiWithState();
void TranslateCellularWithState();
void TranslateNetworkWithState();
+ void TranslateIPConfig();
// Creates an ONC object from |dictionary| according to the signature
// associated to |onc_field_name| and adds it to |onc_object_| at
@@ -131,6 +132,8 @@ ShillToONCTranslator::CreateTranslatedONCObject() {
TranslateWiFiWithState();
} else if (onc_signature_ == &kCellularWithStateSignature) {
TranslateCellularWithState();
+ } else if (onc_signature_ == &kIPConfigSignature) {
+ TranslateIPConfig();
} else {
CopyPropertiesAccordingToSignature();
}
@@ -254,10 +257,10 @@ void ShillToONCTranslator::TranslateCellularWithState() {
shill::kCellularApnProperty, &dictionary)) {
TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary);
}
- const base::ListValue* list = NULL;
+ const base::ListValue* shill_apns = NULL;
if (shill_dictionary_->GetListWithoutPathExpansion(
- shill::kCellularApnListProperty, &list)) {
- TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *list);
+ shill::kCellularApnListProperty, &shill_apns)) {
+ TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns);
}
}
@@ -299,6 +302,33 @@ void ShillToONCTranslator::TranslateNetworkWithState() {
onc_object_->SetStringWithoutPathExpansion(
::onc::network_config::kConnectionState, onc_state);
}
+
+ // Shill's Service has an IPConfig property (note the singular, and not a
+ // IPConfigs property). However, we require the caller of the translation to
+ // patch the Shill dictionary before passing it to the translator.
+ const base::ListValue* shill_ipconfigs = NULL;
+ if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty,
+ &shill_ipconfigs)) {
+ TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs,
+ *shill_ipconfigs);
+ }
+}
+
+void ShillToONCTranslator::TranslateIPConfig() {
+ CopyPropertiesAccordingToSignature();
+ std::string shill_ip_method;
+ shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty,
+ &shill_ip_method);
+ if (shill_ip_method != shill::kTypeIPv4 &&
+ shill_ip_method != shill::kTypeIPv6) {
+ LOG(ERROR) << "Unhandled IPConfig Method value " << shill_ip_method;
+ return;
+ }
+
+ std::string type = ::onc::ipconfig::kIPv4;
+ if (shill_ip_method == shill::kTypeIPv6)
+ type = ::onc::ipconfig::kIPv6;
+ onc_object_->SetStringWithoutPathExpansion(::onc::ipconfig::kType, type);
}
void ShillToONCTranslator::TranslateAndAddNestedObject(
@@ -345,14 +375,13 @@ void ShillToONCTranslator::TranslateAndAddListOfObjects(
*field_signature->value_signature->onc_array_entry_signature);
scoped_ptr<base::DictionaryValue> nested_object =
nested_translator.CreateTranslatedONCObject();
+ // If the nested object couldn't be parsed, simply omit it.
if (nested_object->empty())
- // The nested object couldn't be parsed, so simply omit it.
continue;
result->Append(nested_object.release());
}
+ // If there are no entries in the list, there is no need to expose this field.
if (result->empty())
- // There are no entries in the list, so there is no need to expose this
- // field.
return;
onc_object_->SetWithoutPathExpansion(onc_field_name, result.release());
}
diff --git a/chromeos/network/onc/onc_translator_unittest.cc b/chromeos/network/onc/onc_translator_unittest.cc
index c81aaa6..29a77b9 100644
--- a/chromeos/network/onc/onc_translator_unittest.cc
+++ b/chromeos/network/onc/onc_translator_unittest.cc
@@ -92,6 +92,8 @@ INSTANTIATE_TEST_CASE_P(
"translation_of_shill_ethernet.onc"),
std::make_pair("shill_ethernet_with_eap.json",
"translation_of_shill_ethernet_with_eap.onc"),
+ std::make_pair("shill_ethernet_with_ipconfig.json",
+ "translation_of_shill_ethernet_with_ipconfig.onc"),
std::make_pair("shill_wifi_clientcert.json",
"translation_of_shill_wifi_clientcert.onc"),
std::make_pair("shill_wifi_wpa1.json",
diff --git a/chromeos/network/onc/onc_validator_unittest.cc b/chromeos/network/onc/onc_validator_unittest.cc
index 4108d2f..51f4109 100644
--- a/chromeos/network/onc/onc_validator_unittest.cc
+++ b/chromeos/network/onc/onc_validator_unittest.cc
@@ -179,6 +179,9 @@ INSTANTIATE_TEST_CASE_P(
OncParams("ethernet_with_eap.onc",
&kNetworkConfigurationSignature,
true),
+ OncParams("translation_of_shill_ethernet_with_ipconfig.onc",
+ &kNetworkConfigurationSignature,
+ true),
OncParams("translation_of_shill_wifi_with_state.onc",
&kNetworkWithStateSignature,
false),
diff --git a/chromeos/test/data/network/shill_ethernet_with_ipconfig.json b/chromeos/test/data/network/shill_ethernet_with_ipconfig.json
new file mode 100644
index 0000000..3eae24e
--- /dev/null
+++ b/chromeos/test/data/network/shill_ethernet_with_ipconfig.json
@@ -0,0 +1,23 @@
+{
+ "GUID":"guid",
+ "IPConfigs":[
+ {
+ "Address":"123.123.123.123",
+ "Gateway":"1.1.1.1",
+ "Method":"ipv4",
+ "NameServers":[
+ "1.1.1.2",
+ "1.1.1.3"
+ ],
+ "Prefixlen":24
+ },
+ {
+ "Address":"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
+ "Gateway":"2001:db8:85a3::7a2e:370:7331",
+ "Method":"ipv6",
+ "NameServers":[],
+ "Prefixlen":12
+ }
+ ],
+ "Type":"ethernet"
+}
diff --git a/chromeos/test/data/network/translation_of_shill_ethernet_with_ipconfig.onc b/chromeos/test/data/network/translation_of_shill_ethernet_with_ipconfig.onc
new file mode 100644
index 0000000..d4a472f
--- /dev/null
+++ b/chromeos/test/data/network/translation_of_shill_ethernet_with_ipconfig.onc
@@ -0,0 +1,27 @@
+{
+ "Ethernet":{
+ "Authentication":"None"
+ },
+ "GUID":"guid",
+ "IPConfigs":[
+ {
+ "Gateway":"1.1.1.1",
+ "IPAddress":"123.123.123.123",
+ "NameServers":[
+ "1.1.1.2",
+ "1.1.1.3"
+ ],
+ "RoutingPrefix":24,
+ "Type":"IPv4"
+ },
+ {
+ "Gateway":"2001:db8:85a3::7a2e:370:7331",
+ "IPAddress":"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
+ "NameServers":[],
+ "RoutingPrefix":12,
+ "Type":"IPv6"
+ }
+ ],
+ "Name":"",
+ "Type":"Ethernet"
+}