mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 05:58:01 +02:00
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.
This commit is contained in:
parent
d74a3b1194
commit
8407a55a5d
2 changed files with 65 additions and 13 deletions
|
|
@ -2521,20 +2521,39 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address)
|
||||||
void
|
void
|
||||||
nm_platform_addr_flags2str (int flags, char *buf, size_t size)
|
nm_platform_addr_flags2str (int flags, char *buf, size_t size)
|
||||||
{
|
{
|
||||||
rtnl_addr_flags2str(flags, buf, size);
|
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;
|
||||||
|
|
||||||
/* There are two recent flags IFA_F_MANAGETEMPADDR and IFA_F_NOPREFIXROUTE.
|
/* if there are unknown flags to rtnl_addr_flags2str(), libnl appends ','
|
||||||
* If libnl does not yet support them, add them by hand.
|
* to indicate them. We want to keep this behavior, if there are other
|
||||||
* These two flags were introduced together with the extended ifa_flags,
|
* unknown flags present. */
|
||||||
* so, check for that.
|
|
||||||
*/
|
rtnl_addr_flags2str (flags & ~(IFA_F_MANAGETEMPADDR | IFA_F_NOPREFIXROUTE), buf, size);
|
||||||
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,
|
len = strlen (buf);
|
||||||
size - strlen (buf) - 1);
|
if (len > 0) {
|
||||||
}
|
has_other_unknown_flags = (buf[len - 1] == ',');
|
||||||
if ((flags & IFA_F_NOPREFIXROUTE) && !nm_platform_check_support_libnl_extended_ifa_flags ()) {
|
if (!has_other_unknown_flags)
|
||||||
strncat (buf, buf[0] ? "," IFA_F_NOPREFIXROUTE_STR : IFA_F_NOPREFIXROUTE_STR,
|
g_strlcat (buf, ",", size);
|
||||||
size - strlen (buf) - 1);
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 ();
|
NMTST_DEFINE ();
|
||||||
|
|
||||||
int
|
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/init_linux_platform", test_init_linux_platform);
|
||||||
g_test_add_func ("/general/link_get_all", test_link_get_all);
|
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 ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue