mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +01:00
monitor: Improve RTM_NEWADDR/GETADDR/DELADDR decoding
This commit is contained in:
parent
e9179c4270
commit
84e32ba448
102
monitor/nlmon.c
102
monitor/nlmon.c
@ -6585,6 +6585,28 @@ static void print_link_mode(unsigned int indent, const char *str,
|
||||
link_mode_to_ascii(link_mode), link_mode);
|
||||
}
|
||||
|
||||
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 struct attr_entry link_info_entry[] = {
|
||||
{ IFLA_INFO_KIND, "Kind", ATTR_STRING },
|
||||
{ },
|
||||
@ -6619,6 +6641,36 @@ static struct attr_entry info_entry[] = {
|
||||
{ },
|
||||
};
|
||||
|
||||
static struct flag_names ifa_flags[] = {
|
||||
{ IFA_F_SECONDARY, "temporary" },
|
||||
{ IFA_F_NODAD, "nodad" },
|
||||
{ IFA_F_OPTIMISTIC, "optimistic" },
|
||||
{ IFA_F_DADFAILED, "dadfailed" },
|
||||
{ IFA_F_HOMEADDRESS, "homeaddress" },
|
||||
{ IFA_F_DEPRECATED, "deprecated" },
|
||||
{ IFA_F_TENTATIVE, "tentative" },
|
||||
{ IFA_F_PERMANENT, "permanent" },
|
||||
{ IFA_F_MANAGETEMPADDR, "managetempaddr" },
|
||||
{ IFA_F_NOPREFIXROUTE, "noprefixroute" },
|
||||
{ IFA_F_MCAUTOJOIN, "mcautojoin" },
|
||||
{ IFA_F_STABLE_PRIVACY, "stableprivacy" },
|
||||
{ },
|
||||
};
|
||||
|
||||
static void print_ifa_flags(unsigned int indent, const char *str,
|
||||
const void *buf, uint16_t size)
|
||||
{
|
||||
uint32_t flags;
|
||||
char str_flags[1024];
|
||||
|
||||
if (size != 4)
|
||||
return;
|
||||
|
||||
flags = l_get_u32(buf);
|
||||
flags_str(ifa_flags, str_flags, sizeof(str_flags), flags);
|
||||
print_attr(indent, "%s: %s", str, str_flags);
|
||||
}
|
||||
|
||||
static void print_inet_addr(unsigned int indent, const char *str,
|
||||
const void *buf, uint16_t size)
|
||||
{
|
||||
@ -6642,6 +6694,8 @@ static struct attr_entry addr_entry[] = {
|
||||
{ .function = print_inet_addr } },
|
||||
{ IFA_LABEL, "Label", ATTR_STRING },
|
||||
{ IFA_CACHEINFO, "CacheInfo", ATTR_BINARY },
|
||||
{ IFA_FLAGS, "Flags", ATTR_CUSTOM,
|
||||
{ .function = print_ifa_flags } },
|
||||
{ },
|
||||
};
|
||||
|
||||
@ -6792,26 +6846,16 @@ static void print_rtnl_attributes(int indent, const struct attr_entry *table,
|
||||
}
|
||||
}
|
||||
|
||||
static void flags_str(const struct flag_names *table,
|
||||
char *str, size_t size, uint16_t flags)
|
||||
static const char *family_to_string(uint8_t family)
|
||||
{
|
||||
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 ? "," : "");
|
||||
}
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
return "AF_INET";
|
||||
case AF_INET6:
|
||||
return "AF_INET6";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
pos += sprintf(str + pos, "]");
|
||||
}
|
||||
|
||||
static void print_ifinfomsg(const struct ifinfomsg *info)
|
||||
@ -6841,7 +6885,7 @@ static void print_ifinfomsg(const struct ifinfomsg *info)
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
print_field("IFLA Family: %u", info->ifi_family);
|
||||
print_field("IFLA Family: %s", family_to_string(info->ifi_family));
|
||||
print_field("IFLA Type: %u", info->ifi_type);
|
||||
print_field("IFLA Index: %d", info->ifi_index);
|
||||
print_field("IFLA ChangeMask: %u", info->ifi_change);
|
||||
@ -6851,14 +6895,17 @@ static void print_ifinfomsg(const struct ifinfomsg *info)
|
||||
|
||||
static void print_ifaddrmsg(const struct ifaddrmsg *addr)
|
||||
{
|
||||
char str[1024];
|
||||
|
||||
if (!addr)
|
||||
return;
|
||||
|
||||
print_field("IFA Family: %u", addr->ifa_family);
|
||||
print_field("IFA Family: %s", family_to_string(addr->ifa_family));
|
||||
print_field("IFA Prefixlen: %u", addr->ifa_prefixlen);
|
||||
print_field("IFA Index: %d", addr->ifa_index);
|
||||
print_field("IFA Scope: %s", scope_to_string(addr->ifa_scope));
|
||||
print_field("IFA Flags: %u", addr->ifa_flags);
|
||||
flags_str(ifa_flags, str, sizeof(str), addr->ifa_flags);
|
||||
print_field("IFA Flags: %s", str);
|
||||
}
|
||||
|
||||
static void print_rtmsg(const struct rtmsg *msg)
|
||||
@ -6981,6 +7028,16 @@ static void print_rtm_route(uint16_t type, const struct rtmsg *msg, size_t len)
|
||||
print_rtnl_attributes(1, route_entry, RTM_RTA(msg), len);
|
||||
}
|
||||
|
||||
static void print_rtm_addr(uint16_t type, const struct ifaddrmsg *msg,
|
||||
size_t len)
|
||||
{
|
||||
if (!msg || len < sizeof(struct ifaddrmsg))
|
||||
return;
|
||||
|
||||
print_ifaddrmsg(msg);
|
||||
print_rtnl_attributes(1, addr_entry, IFA_RTA(msg), len);
|
||||
}
|
||||
|
||||
static const char *nlmsg_type_to_str(uint32_t msg_type)
|
||||
{
|
||||
const char *str = NULL;
|
||||
@ -7139,8 +7196,7 @@ static void print_rtnl_msg(const struct timeval *tv,
|
||||
return;
|
||||
|
||||
print_nlmsghdr(tv, nlmsg);
|
||||
print_ifaddrmsg(addr);
|
||||
print_rtnl_attributes(1, addr_entry, IFA_RTA(addr), len);
|
||||
print_rtm_addr(nlmsg->nlmsg_type, addr, len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user