mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 11:20:23 +01:00
libnm-core: don't serialize empty address-labels
If no address in an NMSettingIP4Config has a label, then don't bother serializing an array of empty strings.
This commit is contained in:
parent
ca18b2d442
commit
ff608c24cd
2 changed files with 33 additions and 1 deletions
|
|
@ -304,16 +304,29 @@ ip4_address_labels_get (NMSetting *setting,
|
|||
const char *property)
|
||||
{
|
||||
NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
|
||||
gboolean have_labels = FALSE;
|
||||
GPtrArray *labels;
|
||||
GVariant *ret;
|
||||
int num_addrs, i;
|
||||
|
||||
labels = g_ptr_array_new ();
|
||||
num_addrs = nm_setting_ip_config_get_num_addresses (s_ip);
|
||||
for (i = 0; i < num_addrs; i++) {
|
||||
NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
|
||||
GVariant *label = nm_ip_address_get_attribute (addr, "label");
|
||||
|
||||
if (label) {
|
||||
have_labels = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!have_labels)
|
||||
return NULL;
|
||||
|
||||
labels = g_ptr_array_sized_new (num_addrs);
|
||||
for (i = 0; i < num_addrs; i++) {
|
||||
NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
|
||||
GVariant *label = nm_ip_address_get_attribute (addr, "label");
|
||||
|
||||
g_ptr_array_add (labels, (char *) (label ? g_variant_get_string (label, NULL) : ""));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -350,6 +350,25 @@ test_setting_ip4_config_labels (void)
|
|||
label = nm_ip_address_get_attribute (addr, "label");
|
||||
g_assert (label == NULL);
|
||||
|
||||
/* The 'address-labels' property should be omitted from the serialization if
|
||||
* there are no non-NULL labels.
|
||||
*/
|
||||
conn = nmtst_create_minimal_connection ("label test", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
|
||||
nm_connection_add_setting (conn, nm_setting_duplicate (NM_SETTING (s_ip4)));
|
||||
dict = nm_connection_to_dbus (conn, NM_CONNECTION_SERIALIZE_ALL);
|
||||
g_object_unref (conn);
|
||||
|
||||
setting_dict = g_variant_lookup_value (dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
|
||||
g_assert (setting_dict != NULL);
|
||||
|
||||
value = g_variant_lookup_value (setting_dict, "address-labels", NULL);
|
||||
g_assert (value == NULL);
|
||||
|
||||
g_variant_unref (setting_dict);
|
||||
g_variant_unref (dict);
|
||||
|
||||
/* Now back to constructing the original s_ip4... */
|
||||
|
||||
/* addr 2 */
|
||||
addr = nm_ip_address_new (AF_INET, "2.2.2.2", 24, &error);
|
||||
g_assert_no_error (error);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue