commit d63f73adf955ef31b3ac3990a92db54c47c7bba2
parent 55491f5c02959abea1ffc81f37a3561bf4d4e089
Author: Denis Kenzior <denkenz@gmail.com>
Date: Tue, 23 Jul 2019 07:24:20 -0500
monitor: Generalize flag printing
Diffstat:
1 file changed, 27 insertions(+), 26 deletions(-)
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
@@ -5863,27 +5863,8 @@ static void print_rtnl_attributes(int indent, const struct attr_entry *table,
}
}
-static struct flag_names rtnl_flags[] = {
- { IFF_UP, "up" },
- { IFF_BROADCAST, "broadcast" },
- { IFF_DEBUG, "debug" },
- { IFF_LOOPBACK, "loopback" },
- { IFF_POINTOPOINT, "pointopoint"},
- { IFF_NOTRAILERS, "notrailers" },
- { IFF_RUNNING, "running" },
- { IFF_NOARP, "noarp" },
- { IFF_PROMISC, "promisc" },
- { IFF_ALLMULTI, "allmulti" },
- { IFF_MASTER, "master" },
- { IFF_SLAVE, "slave" },
- { IFF_MULTICAST, "multicast" },
- { IFF_PORTSEL, "portsel" },
- { IFF_AUTOMEDIA, "automedia" },
- { IFF_DYNAMIC, "dynamic" },
- { },
-};
-
-static void ififlags_str(char *str, size_t size, uint16_t flags)
+static void flags_str(const struct flag_names *table,
+ char *str, size_t size, uint16_t flags)
{
int pos, i;
@@ -5893,10 +5874,10 @@ static void ififlags_str(char *str, size_t size, uint16_t flags)
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,
+ 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 ? "," : "");
}
}
@@ -5906,6 +5887,26 @@ static void ififlags_str(char *str, size_t size, uint16_t flags)
static void print_ifinfomsg(const struct ifinfomsg *info)
{
+ static struct flag_names iff_flags[] = {
+ { IFF_UP, "up" },
+ { IFF_BROADCAST, "broadcast" },
+ { IFF_DEBUG, "debug" },
+ { IFF_LOOPBACK, "loopback" },
+ { IFF_POINTOPOINT, "pointopoint"},
+ { IFF_NOTRAILERS, "notrailers" },
+ { IFF_RUNNING, "running" },
+ { IFF_NOARP, "noarp" },
+ { IFF_PROMISC, "promisc" },
+ { IFF_ALLMULTI, "allmulti" },
+ { IFF_MASTER, "master" },
+ { IFF_SLAVE, "slave" },
+ { IFF_MULTICAST, "multicast" },
+ { IFF_PORTSEL, "portsel" },
+ { IFF_AUTOMEDIA, "automedia" },
+ { IFF_DYNAMIC, "dynamic" },
+ { },
+ };
+
char str[256];
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 Index: %d", info->ifi_index);
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);
}