Commit af8f5450 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

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
parent eb09a62e
...@@ -163,11 +163,11 @@ const OncFieldSignature ethernet_fields[] = { ...@@ -163,11 +163,11 @@ const OncFieldSignature ethernet_fields[] = {
{ ::onc::ethernet::kEAP, &kEAPSignature}, { ::onc::ethernet::kEAP, &kEAPSignature},
{NULL}}; {NULL}};
// Not supported, yet. // Not supported for policy but for reading network state.
const OncFieldSignature ipconfig_fields[] = { const OncFieldSignature ipconfig_fields[] = {
{ ::onc::ipconfig::kGateway, &kStringSignature}, { ::onc::ipconfig::kGateway, &kStringSignature},
{ ::onc::ipconfig::kIPAddress, &kStringSignature}, { ::onc::ipconfig::kIPAddress, &kStringSignature},
{ ::onc::network_config::kNameServers, &kStringSignature}, { ::onc::ipconfig::kNameServers, &kStringListSignature},
{ ::onc::ipconfig::kRoutingPrefix, &kIntegerSignature}, { ::onc::ipconfig::kRoutingPrefix, &kIntegerSignature},
{ ::onc::network_config::kSearchDomains, &kStringListSignature}, { ::onc::network_config::kSearchDomains, &kStringListSignature},
{ ::onc::ipconfig::kType, &kStringSignature}, { ::onc::ipconfig::kType, &kStringSignature},
...@@ -261,7 +261,7 @@ const OncFieldSignature network_configuration_fields[] = { ...@@ -261,7 +261,7 @@ const OncFieldSignature network_configuration_fields[] = {
{ ::onc::kRecommended, &kRecommendedSignature}, { ::onc::kRecommended, &kRecommendedSignature},
{ ::onc::network_config::kEthernet, &kEthernetSignature}, { ::onc::network_config::kEthernet, &kEthernetSignature},
{ ::onc::network_config::kGUID, &kStringSignature}, { ::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::kIPConfigs, &kIPConfigListSignature},
{ ::onc::network_config::kName, &kStringSignature}, { ::onc::network_config::kName, &kStringSignature},
// Not supported, yet. // Not supported, yet.
......
...@@ -18,8 +18,6 @@ namespace onc { ...@@ -18,8 +18,6 @@ namespace onc {
// //
// Proxy settings are converted to Shill by function // Proxy settings are converted to Shill by function
// ConvertOncProxySettingsToProxyConfig(...). // ConvertOncProxySettingsToProxyConfig(...).
//
// Translation of IPConfig objects is not supported, yet.
namespace { namespace {
...@@ -175,6 +173,13 @@ const FieldTranslationEntry network_fields[] = { ...@@ -175,6 +173,13 @@ const FieldTranslationEntry network_fields[] = {
// { ::onc::network_config::kConnectionState, shill::kStateProperty }, // { ::onc::network_config::kConnectionState, shill::kStateProperty },
{NULL}}; {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 { struct OncValueTranslationEntry {
const OncValueSignature* onc_signature; const OncValueSignature* onc_signature;
const FieldTranslationEntry* field_translation_table; const FieldTranslationEntry* field_translation_table;
...@@ -196,6 +201,7 @@ const OncValueTranslationEntry onc_value_translation_table[] = { ...@@ -196,6 +201,7 @@ const OncValueTranslationEntry onc_value_translation_table[] = {
{ &kCellularWithStateSignature, cellular_fields }, { &kCellularWithStateSignature, cellular_fields },
{ &kNetworkWithStateSignature, network_fields }, { &kNetworkWithStateSignature, network_fields },
{ &kNetworkConfigurationSignature, network_fields }, { &kNetworkConfigurationSignature, network_fields },
{ &kIPConfigSignature, ipconfig_fields },
{ NULL } { NULL }
}; };
......
...@@ -66,6 +66,7 @@ class ShillToONCTranslator { ...@@ -66,6 +66,7 @@ class ShillToONCTranslator {
void TranslateWiFiWithState(); void TranslateWiFiWithState();
void TranslateCellularWithState(); void TranslateCellularWithState();
void TranslateNetworkWithState(); void TranslateNetworkWithState();
void TranslateIPConfig();
// Creates an ONC object from |dictionary| according to the signature // Creates an ONC object from |dictionary| according to the signature
// associated to |onc_field_name| and adds it to |onc_object_| at // associated to |onc_field_name| and adds it to |onc_object_| at
...@@ -131,6 +132,8 @@ ShillToONCTranslator::CreateTranslatedONCObject() { ...@@ -131,6 +132,8 @@ ShillToONCTranslator::CreateTranslatedONCObject() {
TranslateWiFiWithState(); TranslateWiFiWithState();
} else if (onc_signature_ == &kCellularWithStateSignature) { } else if (onc_signature_ == &kCellularWithStateSignature) {
TranslateCellularWithState(); TranslateCellularWithState();
} else if (onc_signature_ == &kIPConfigSignature) {
TranslateIPConfig();
} else { } else {
CopyPropertiesAccordingToSignature(); CopyPropertiesAccordingToSignature();
} }
...@@ -254,10 +257,10 @@ void ShillToONCTranslator::TranslateCellularWithState() { ...@@ -254,10 +257,10 @@ void ShillToONCTranslator::TranslateCellularWithState() {
shill::kCellularApnProperty, &dictionary)) { shill::kCellularApnProperty, &dictionary)) {
TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary);
} }
const base::ListValue* list = NULL; const base::ListValue* shill_apns = NULL;
if (shill_dictionary_->GetListWithoutPathExpansion( if (shill_dictionary_->GetListWithoutPathExpansion(
shill::kCellularApnListProperty, &list)) { shill::kCellularApnListProperty, &shill_apns)) {
TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *list); TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns);
} }
} }
...@@ -299,6 +302,33 @@ void ShillToONCTranslator::TranslateNetworkWithState() { ...@@ -299,6 +302,33 @@ void ShillToONCTranslator::TranslateNetworkWithState() {
onc_object_->SetStringWithoutPathExpansion( onc_object_->SetStringWithoutPathExpansion(
::onc::network_config::kConnectionState, onc_state); ::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( void ShillToONCTranslator::TranslateAndAddNestedObject(
...@@ -345,14 +375,13 @@ void ShillToONCTranslator::TranslateAndAddListOfObjects( ...@@ -345,14 +375,13 @@ void ShillToONCTranslator::TranslateAndAddListOfObjects(
*field_signature->value_signature->onc_array_entry_signature); *field_signature->value_signature->onc_array_entry_signature);
scoped_ptr<base::DictionaryValue> nested_object = scoped_ptr<base::DictionaryValue> nested_object =
nested_translator.CreateTranslatedONCObject(); nested_translator.CreateTranslatedONCObject();
// If the nested object couldn't be parsed, simply omit it.
if (nested_object->empty()) if (nested_object->empty())
// The nested object couldn't be parsed, so simply omit it.
continue; continue;
result->Append(nested_object.release()); result->Append(nested_object.release());
} }
// If there are no entries in the list, there is no need to expose this field.
if (result->empty()) if (result->empty())
// There are no entries in the list, so there is no need to expose this
// field.
return; return;
onc_object_->SetWithoutPathExpansion(onc_field_name, result.release()); onc_object_->SetWithoutPathExpansion(onc_field_name, result.release());
} }
......
...@@ -92,6 +92,8 @@ INSTANTIATE_TEST_CASE_P( ...@@ -92,6 +92,8 @@ INSTANTIATE_TEST_CASE_P(
"translation_of_shill_ethernet.onc"), "translation_of_shill_ethernet.onc"),
std::make_pair("shill_ethernet_with_eap.json", std::make_pair("shill_ethernet_with_eap.json",
"translation_of_shill_ethernet_with_eap.onc"), "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", std::make_pair("shill_wifi_clientcert.json",
"translation_of_shill_wifi_clientcert.onc"), "translation_of_shill_wifi_clientcert.onc"),
std::make_pair("shill_wifi_wpa1.json", std::make_pair("shill_wifi_wpa1.json",
......
...@@ -179,6 +179,9 @@ INSTANTIATE_TEST_CASE_P( ...@@ -179,6 +179,9 @@ INSTANTIATE_TEST_CASE_P(
OncParams("ethernet_with_eap.onc", OncParams("ethernet_with_eap.onc",
&kNetworkConfigurationSignature, &kNetworkConfigurationSignature,
true), true),
OncParams("translation_of_shill_ethernet_with_ipconfig.onc",
&kNetworkConfigurationSignature,
true),
OncParams("translation_of_shill_wifi_with_state.onc", OncParams("translation_of_shill_wifi_with_state.onc",
&kNetworkWithStateSignature, &kNetworkWithStateSignature,
false), false),
......
{
"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"
}
{
"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"
}
...@@ -132,6 +132,7 @@ const char kGateway[] = "Gateway"; ...@@ -132,6 +132,7 @@ const char kGateway[] = "Gateway";
const char kIPAddress[] = "IPAddress"; const char kIPAddress[] = "IPAddress";
const char kIPv4[] = "IPv4"; const char kIPv4[] = "IPv4";
const char kIPv6[] = "IPv6"; const char kIPv6[] = "IPv6";
const char kNameServers[] = "NameServers";
const char kRoutingPrefix[] = "RoutingPrefix"; const char kRoutingPrefix[] = "RoutingPrefix";
const char kType[] = "Type"; const char kType[] = "Type";
} // namespace ipconfig } // namespace ipconfig
......
...@@ -142,6 +142,7 @@ ONC_EXPORT extern const char kGateway[]; ...@@ -142,6 +142,7 @@ ONC_EXPORT extern const char kGateway[];
ONC_EXPORT extern const char kIPAddress[]; ONC_EXPORT extern const char kIPAddress[];
ONC_EXPORT extern const char kIPv4[]; ONC_EXPORT extern const char kIPv4[];
ONC_EXPORT extern const char kIPv6[]; ONC_EXPORT extern const char kIPv6[];
ONC_EXPORT extern const char kNameServers[];
ONC_EXPORT extern const char kRoutingPrefix[]; ONC_EXPORT extern const char kRoutingPrefix[];
ONC_EXPORT extern const char kType[]; ONC_EXPORT extern const char kType[];
} // namespace ipconfig } // namespace ipconfig
......
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