Commit ec8468e4 authored by Thomas Haller's avatar Thomas Haller
Browse files

libnm: add NM_IP_ADDRESS_ATTRIBUTE_LABEL define

There is only one supported attribute for addresses. The "lable".
Give it a #define.
parent d4aae4c2
......@@ -2523,7 +2523,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
if (label) {
if (!g_variant_is_of_type (label, G_VARIANT_TYPE_STRING)) {
g_set_error (error,
......
......@@ -32,6 +32,8 @@
G_BEGIN_DECLS
#define NM_IP_ADDRESS_ATTRIBUTE_LABEL "label"
typedef struct NMIPAddress NMIPAddress;
GType nm_ip_address_get_type (void);
......
......@@ -363,7 +363,7 @@ ip4_addresses_set (NMSetting *setting,
if (g_variant_lookup (s_ip4, "address-labels", "^as", &labels)) {
for (i = 0; i < addrs->len && labels[i]; i++)
if (*labels[i])
nm_ip_address_set_attribute (addrs->pdata[i], "label", g_variant_new_string (labels[i]));
nm_ip_address_set_attribute (addrs->pdata[i], NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string (labels[i]));
g_strfreev (labels);
}
g_variant_unref (s_ip4);
......@@ -391,7 +391,7 @@ ip4_address_labels_get (NMSetting *setting,
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");
GVariant *label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
if (label) {
have_labels = TRUE;
......@@ -404,7 +404,7 @@ ip4_address_labels_get (NMSetting *setting,
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");
GVariant *label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_ptr_array_add (labels, (char *) (label ? g_variant_get_string (label, NULL) : ""));
}
......
......@@ -959,7 +959,7 @@ test_setting_ip4_config_labels (void)
nmtst_assert_setting_verifies (NM_SETTING (s_ip4));
addr = nm_setting_ip_config_get_address (s_ip4, 0);
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label == NULL);
/* The 'address-labels' property should be omitted from the serialization if
......@@ -984,28 +984,28 @@ test_setting_ip4_config_labels (void)
/* addr 2 */
addr = nm_ip_address_new (AF_INET, "2.3.4.5", 24, &error);
g_assert_no_error (error);
nm_ip_address_set_attribute (addr, "label", g_variant_new_string ("eth0:1"));
nm_ip_address_set_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string ("eth0:1"));
nm_setting_ip_config_add_address (s_ip4, addr);
nm_ip_address_unref (addr);
nmtst_assert_setting_verifies (NM_SETTING (s_ip4));
addr = nm_setting_ip_config_get_address (s_ip4, 1);
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label != NULL);
g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
/* addr 3 */
addr = nm_ip_address_new (AF_INET, "3.4.5.6", 24, &error);
g_assert_no_error (error);
nm_ip_address_set_attribute (addr, "label", NULL);
nm_ip_address_set_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL, NULL);
nm_setting_ip_config_add_address (s_ip4, addr);
nm_ip_address_unref (addr);
nmtst_assert_setting_verifies (NM_SETTING (s_ip4));
addr = nm_setting_ip_config_get_address (s_ip4, 2);
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label == NULL);
/* Remove addr 1 and re-verify remaining addresses */
......@@ -1014,13 +1014,13 @@ test_setting_ip4_config_labels (void)
addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.3.4.5");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label != NULL);
g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
addr = nm_setting_ip_config_get_address (s_ip4, 1);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.4.5.6");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label == NULL);
/* If we serialize as the daemon, the labels should appear in the D-Bus
......@@ -1051,11 +1051,11 @@ test_setting_ip4_config_labels (void)
g_assert (addrs != NULL);
g_assert_cmpint (addrs->len, ==, 2);
addr = addrs->pdata[0];
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label != NULL);
g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
addr = addrs->pdata[1];
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label == NULL);
g_ptr_array_unref (addrs);
......@@ -1078,13 +1078,13 @@ test_setting_ip4_config_labels (void)
addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.3.4.5");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label != NULL);
g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
addr = nm_setting_ip_config_get_address (s_ip4, 1);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.4.5.6");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label == NULL);
g_object_unref (conn);
......@@ -1101,12 +1101,12 @@ test_setting_ip4_config_labels (void)
addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.3.4.5");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
addr = nm_setting_ip_config_get_address (s_ip4, 1);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.4.5.6");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label == NULL);
/* Test explicit property assignment */
......@@ -1126,13 +1126,13 @@ test_setting_ip4_config_labels (void)
addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.3.4.5");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label != NULL);
g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
addr = nm_setting_ip_config_get_address (s_ip4, 1);
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.4.5.6");
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
g_assert (label == NULL);
g_object_unref (conn);
......@@ -3057,10 +3057,10 @@ test_setting_compare_addresses (void)
a = nm_ip_address_new (AF_INET, "192.168.7.5", 24, NULL);
nm_ip_address_set_attribute (a, "label", g_variant_new_string ("xoxoxo"));
nm_ip_address_set_attribute (a, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string ("xoxoxo"));
nm_setting_ip_config_add_address ((NMSettingIPConfig *) s1, a);
nm_ip_address_set_attribute (a, "label", g_variant_new_string ("hello"));
nm_ip_address_set_attribute (a, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string ("hello"));
nm_setting_ip_config_add_address ((NMSettingIPConfig *) s2, a);
nm_ip_address_unref (a);
......@@ -3089,10 +3089,10 @@ test_setting_compare_routes (void)
r = nm_ip_route_new (AF_INET, "192.168.12.0", 24, "192.168.11.1", 473, NULL);
nm_ip_route_set_attribute (r, "label", g_variant_new_string ("xoxoxo"));
nm_ip_route_set_attribute (r, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string ("xoxoxo"));
nm_setting_ip_config_add_route ((NMSettingIPConfig *) s1, r);
nm_ip_route_set_attribute (r, "label", g_variant_new_string ("hello"));
nm_ip_route_set_attribute (r, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string ("hello"));
nm_setting_ip_config_add_route ((NMSettingIPConfig *) s2, r);
nm_ip_route_unref (r);
......
......@@ -957,7 +957,7 @@ nm_ip4_config_merge_setting (NMIP4Config *self,
address.preferred = NM_PLATFORM_LIFETIME_PERMANENT;
address.addr_source = NM_IP_CONFIG_SOURCE_USER;
label = nm_ip_address_get_attribute (s_addr, "label");
label = nm_ip_address_get_attribute (s_addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
if (label)
g_strlcpy (address.label, g_variant_get_string (label, NULL), sizeof (address.label));
......@@ -1069,7 +1069,7 @@ nm_ip4_config_create_setting (const NMIP4Config *self)
s_addr = nm_ip_address_new_binary (AF_INET, &address->address, address->plen, NULL);
if (*address->label)
nm_ip_address_set_attribute (s_addr, "label", g_variant_new_string (address->label));
nm_ip_address_set_attribute (s_addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string (address->label));
nm_setting_ip_config_add_address (s_ip4, s_addr);
nm_ip_address_unref (s_addr);
......@@ -2963,7 +2963,7 @@ get_property (GObject *object, guint prop_id,
if (*address->label) {
g_variant_builder_add (&addr_builder, "{sv}",
"label",
NM_IP_ADDRESS_ATTRIBUTE_LABEL,
g_variant_new_string (address->label));
}
......
......@@ -1625,7 +1625,7 @@ read_aliases (NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *file
read_defroute ? &gateway : NULL,
&err);
if (ok) {
nm_ip_address_set_attribute (addr, "label", g_variant_new_string (device));
nm_ip_address_set_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string (device));
if (!nm_setting_ip_config_add_address (s_ip4, addr))
PARSE_WARNING ("duplicate IP4 address in alias file %s", item);
if (nm_streq0 (nm_setting_ip_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_DISABLED))
......
......@@ -2275,7 +2275,7 @@ write_ip4_setting (NMConnection *connection,
if (i > 0) {
GVariant *label;
label = nm_ip_address_get_attribute (addr, "label");
label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
if (label)
continue;
}
......@@ -2478,7 +2478,7 @@ write_ip4_aliases (NMConnection *connection, const char *base_ifcfg_path)
addr = nm_setting_ip_config_get_address (s_ip4, i);
label_var = nm_ip_address_get_attribute (addr, "label");
label_var = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
if (!label_var)
continue;
label = g_variant_get_string (label_var, NULL);
......
......@@ -2079,7 +2079,7 @@ test_read_wired_aliases_good (gconstpointer test_data)
g_assert (j < expected_num_addresses);
g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
label = nm_ip_address_get_attribute (ip4_addr, "label");
label = nm_ip_address_get_attribute (ip4_addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
if (expected_label[j])
g_assert_cmpstr (g_variant_get_string (label, NULL), ==, expected_label[j]);
else
......@@ -2131,7 +2131,7 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id)
g_assert (ip4_addr != NULL);
g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.1.5");
g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
g_assert (nm_ip_address_get_attribute (ip4_addr, "label") == NULL);
g_assert (nm_ip_address_get_attribute (ip4_addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL) == NULL);
/* Gateway */
g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.1");
......@@ -5141,7 +5141,7 @@ test_write_wired_aliases (void)
addr = nm_ip_address_new (AF_INET, ip[i], 24, &error);
g_assert_no_error (error);
if (label[i])
nm_ip_address_set_attribute (addr, "label", g_variant_new_string (label[i]));
nm_ip_address_set_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string (label[i]));
nm_setting_ip_config_add_address (s_ip4, addr);
nm_ip_address_unref (addr);
}
......@@ -5200,9 +5200,9 @@ test_write_wired_aliases (void)
else {
g_assert_cmpint (nm_ip_address_get_prefix (addr), ==, 24);
if (label[j])
g_assert_cmpstr (g_variant_get_string (nm_ip_address_get_attribute (addr, "label"), NULL), ==, label[j]);
g_assert_cmpstr (g_variant_get_string (nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL), NULL), ==, label[j]);
else
g_assert (nm_ip_address_get_attribute (addr, "label") == NULL);
g_assert (nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL) == NULL);
ip[j] = NULL;
}
}
......
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