From 2331f9b00d27ab67aeaa2417ea40a74670b141b6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 Mar 2014 22:00:24 +0100 Subject: platform: extract function nm_platform_addr_flags2str() to wrap rtnl_addr_flags2str() Signed-off-by: Thomas Haller --- src/platform/nm-platform.c | 40 +++++++++++++++++++++++++--------------- src/platform/nm-platform.h | 2 ++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index a738e898db..a42910f2c1 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1937,6 +1937,30 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address) return to_string_buffer; } +/** + * nm_platform_addr_flags2str: wrapper for rtnl_addr_flags2str(), + * which might not yet support some recent address flags. + **/ +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); + } +} + /** * nm_platform_ip6_address_to_string: * @route: pointer to NMPlatformIP6Address address structure @@ -1970,21 +1994,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address) _to_string_dev (address->ifindex, str_dev, sizeof (str_dev)); - rtnl_addr_flags2str(address->flags, s_flags, sizeof (s_flags)); - - /* 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 ((address->flags & IFA_F_MANAGETEMPADDR) && !nm_platform_check_support_libnl_extended_ifa_flags ()) { - strncat (s_flags, s_flags[0] ? "," IFA_F_MANAGETEMPADDR_STR : IFA_F_MANAGETEMPADDR_STR, - sizeof (s_flags) - strlen (s_flags) - 1); - } - if ((address->flags & IFA_F_NOPREFIXROUTE) && !nm_platform_check_support_libnl_extended_ifa_flags ()) { - strncat (s_flags, s_flags[0] ? "," IFA_F_NOPREFIXROUTE_STR : IFA_F_NOPREFIXROUTE_STR, - sizeof (s_flags) - strlen (s_flags) - 1); - } + nm_platform_addr_flags2str (address->flags, s_flags, sizeof (s_flags)); str_flags = s_flags[0] ? g_strconcat (" flags ", s_flags, NULL) : NULL; diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 263cd9153a..cf41ad85fd 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -516,6 +516,8 @@ int nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6R gboolean nm_platform_check_support_libnl_extended_ifa_flags (void); gboolean nm_platform_check_support_kernel_extended_ifa_flags (void); +void nm_platform_addr_flags2str (int flags, char *buf, size_t size); + #define auto_g_free __attribute__((cleanup(put_g_free))) static void __attribute__((unused)) put_g_free (void *ptr) -- cgit v1.2.1