3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

monitor: Generalize flag printing

This commit is contained in:
Denis Kenzior 2019-07-23 07:24:20 -05:00
parent 55491f5c02
commit d63f73adf9

View File

@ -5863,7 +5863,31 @@ static void print_rtnl_attributes(int indent, const struct attr_entry *table,
} }
} }
static struct flag_names rtnl_flags[] = { static void flags_str(const struct flag_names *table,
char *str, size_t size, uint16_t flags)
{
int pos, i;
pos = sprintf(str, "(0x%02x)", flags);
if (!flags)
return;
pos += sprintf(str + pos, " [");
for (i = 0; table[i].name; i++) {
if (flags & table[i].flag) {
flags &= ~table[i].flag;
pos += sprintf(str + pos, "%s%s", table[i].name,
flags ? "," : "");
}
}
pos += sprintf(str + pos, "]");
}
static void print_ifinfomsg(const struct ifinfomsg *info)
{
static struct flag_names iff_flags[] = {
{ IFF_UP, "up" }, { IFF_UP, "up" },
{ IFF_BROADCAST, "broadcast" }, { IFF_BROADCAST, "broadcast" },
{ IFF_DEBUG, "debug" }, { IFF_DEBUG, "debug" },
@ -5881,31 +5905,8 @@ static struct flag_names rtnl_flags[] = {
{ IFF_AUTOMEDIA, "automedia" }, { IFF_AUTOMEDIA, "automedia" },
{ IFF_DYNAMIC, "dynamic" }, { IFF_DYNAMIC, "dynamic" },
{ }, { },
}; };
static void ififlags_str(char *str, size_t size, uint16_t flags)
{
int pos, i;
pos = sprintf(str, "(0x%02x)", flags);
if (!flags)
return;
pos += sprintf(str + pos, " [");
for (i = 0; rtnl_flags[i].name; i++) {
if (flags & rtnl_flags[i].flag) {
flags &= ~rtnl_flags[i].flag;
pos += sprintf(str + pos, "%s%s", rtnl_flags[i].name,
flags ? "," : "");
}
}
pos += sprintf(str + pos, "]");
}
static void print_ifinfomsg(const struct ifinfomsg *info)
{
char str[256]; char str[256];
if (!info) if (!info)
@ -5915,7 +5916,7 @@ static void print_ifinfomsg(const struct ifinfomsg *info)
print_field("IFLA Type: %u", info->ifi_type); print_field("IFLA Type: %u", info->ifi_type);
print_field("IFLA Index: %d", info->ifi_index); print_field("IFLA Index: %d", info->ifi_index);
print_field("IFLA ChangeMask: %u", info->ifi_change); print_field("IFLA ChangeMask: %u", info->ifi_change);
ififlags_str(str, sizeof(str), info->ifi_flags); flags_str(iff_flags, str, sizeof(str), info->ifi_flags);
print_field("IFLA Flags: %s", str); print_field("IFLA Flags: %s", str);
} }