summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-03-14 14:46:26 +0100
committerThomas Haller <thaller@redhat.com>2015-07-12 13:56:52 +0200
commit8407a55a5d4dc18a89b9db4e92196a3a44b9869f (patch)
tree8afac9bb50c6a6fce8e97777868327ab1c99f689
parentd74a3b1194ecd64e290586b3ce61bdf1110bce26 (diff)
downloadNetworkManager-8407a55a5d4dc18a89b9db4e92196a3a44b9869f.tar.gz
platform: fix wrapper nm_platform_addr_flags2str() for rtnl_addr_flags2str()
The compatibily wrapper for rtnl_addr_flags2str() did not behave identical because libnl adds a trailing ',' if it encounters unknown attributes. Also add test cases.
-rw-r--r--src/platform/nm-platform.c47
-rw-r--r--src/platform/tests/test-general.c33
2 files changed, 66 insertions, 14 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index cfeb5319c7..d940cd7482 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -2521,20 +2521,39 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address)
void
nm_platform_addr_flags2str (int flags, char *buf, size_t size)
{
- rtnl_addr_flags2str(flags, buf, size);
-
- /* There are two recent flags IFA_F_MANAGETEMPADDR and IFA_F_NOPREFIXROUTE.
- * If libnl does not yet support them, add them by hand.
- * These two flags were introduced together with the extended ifa_flags,
- * so, check for that.
- */
- if ((flags & IFA_F_MANAGETEMPADDR) && !nm_platform_check_support_libnl_extended_ifa_flags ()) {
- strncat (buf, buf[0] ? "," IFA_F_MANAGETEMPADDR_STR : IFA_F_MANAGETEMPADDR_STR,
- size - strlen (buf) - 1);
- }
- if ((flags & IFA_F_NOPREFIXROUTE) && !nm_platform_check_support_libnl_extended_ifa_flags ()) {
- strncat (buf, buf[0] ? "," IFA_F_NOPREFIXROUTE_STR : IFA_F_NOPREFIXROUTE_STR,
- size - strlen (buf) - 1);
+ if ( !NM_FLAGS_ANY (flags, IFA_F_MANAGETEMPADDR | IFA_F_NOPREFIXROUTE)
+ || nm_platform_check_support_libnl_extended_ifa_flags ())
+ rtnl_addr_flags2str (flags, buf, size);
+ else {
+ /* There are two recent flags IFA_F_MANAGETEMPADDR and IFA_F_NOPREFIXROUTE.
+ * If libnl does not yet support them, add them by hand.
+ * These two flags were introduced together with the extended ifa_flags
+ * so check for nm_platform_check_support_libnl_extended_ifa_flags (). */
+ gboolean has_other_unknown_flags = FALSE;
+ size_t len;
+
+ /* if there are unknown flags to rtnl_addr_flags2str(), libnl appends ','
+ * to indicate them. We want to keep this behavior, if there are other
+ * unknown flags present. */
+
+ rtnl_addr_flags2str (flags & ~(IFA_F_MANAGETEMPADDR | IFA_F_NOPREFIXROUTE), buf, size);
+
+ len = strlen (buf);
+ if (len > 0) {
+ has_other_unknown_flags = (buf[len - 1] == ',');
+ if (!has_other_unknown_flags)
+ g_strlcat (buf, ",", size);
+ }
+
+ if (NM_FLAGS_ALL (flags, IFA_F_MANAGETEMPADDR | IFA_F_NOPREFIXROUTE))
+ g_strlcat (buf, IFA_F_MANAGETEMPADDR_STR","IFA_F_NOPREFIXROUTE_STR, size);
+ else if (NM_FLAGS_HAS (flags, IFA_F_MANAGETEMPADDR))
+ g_strlcat (buf, IFA_F_MANAGETEMPADDR_STR, size);
+ else
+ g_strlcat (buf, IFA_F_NOPREFIXROUTE_STR, size);
+
+ if (has_other_unknown_flags)
+ g_strlcat (buf, ",", size);
}
}
diff --git a/src/platform/tests/test-general.c b/src/platform/tests/test-general.c
index 0a397b3788..94d9650365 100644
--- a/src/platform/tests/test-general.c
+++ b/src/platform/tests/test-general.c
@@ -53,6 +53,37 @@ test_link_get_all (void)
/******************************************************************/
+static void
+test_nm_platform_ip6_address_to_string_flags (void)
+{
+ NMPlatformIP6Address addr = { 0 };
+
+ g_assert_cmpstr (strstr (nm_platform_ip6_address_to_string (&addr), " flags "), ==, NULL);
+
+ addr.flags = IFA_F_MANAGETEMPADDR;
+ nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags mngtmpaddr ");
+
+ addr.flags = IFA_F_NOPREFIXROUTE;
+ nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags noprefixroute ");
+
+ addr.flags = IFA_F_MANAGETEMPADDR | IFA_F_NOPREFIXROUTE;
+ nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags mngtmpaddr,noprefixroute ");
+
+ addr.flags = IFA_F_TENTATIVE | IFA_F_NOPREFIXROUTE;
+ nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,noprefixroute ");
+
+ addr.flags = IFA_F_TENTATIVE | IFA_F_PERMANENT | IFA_F_MANAGETEMPADDR| IFA_F_NOPREFIXROUTE;
+ nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,permanent,mngtmpaddr,noprefixroute ");
+
+ addr.flags = IFA_F_TENTATIVE | IFA_F_PERMANENT | IFA_F_MANAGETEMPADDR| IFA_F_NOPREFIXROUTE | 0x8000;
+ nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,permanent,mngtmpaddr,noprefixroute, ");
+
+ addr.flags = IFA_F_TENTATIVE | IFA_F_PERMANENT | IFA_F_MANAGETEMPADDR| IFA_F_NOPREFIXROUTE | ((G_MAXUINT - (G_MAXUINT >> 1)) >> 1);
+ nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,permanent,mngtmpaddr,noprefixroute, ");
+}
+
+/******************************************************************/
+
NMTST_DEFINE ();
int
@@ -62,6 +93,8 @@ main (int argc, char **argv)
g_test_add_func ("/general/init_linux_platform", test_init_linux_platform);
g_test_add_func ("/general/link_get_all", test_link_get_all);
+ g_test_add_func ("/general/nm_platform_ip6_address_to_string/flags", test_nm_platform_ip6_address_to_string_flags);
return g_test_run ();
}
+