3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 17:59:25 +01:00

monitor: add better array type support

The ATTR_ARRAY type was quite limited, only supporting u16/u32 and
addresses. This changes the union to a struct so nested/function
can be defined along with array_type.
This commit is contained in:
James Prestwood 2022-08-09 14:04:47 -07:00 committed by Denis Kenzior
parent e67169337f
commit 0fdc5e87d1

View File

@ -139,7 +139,8 @@ struct attr_entry {
uint16_t attr; uint16_t attr;
const char *str; const char *str;
enum attr_type type; enum attr_type type;
union {
struct {
const struct attr_entry *nested; const struct attr_entry *nested;
enum attr_type array_type; enum attr_type array_type;
attr_func_t function; attr_func_t function;
@ -6691,6 +6692,7 @@ static void print_value(int indent, const char *label, enum attr_type type,
} }
static void print_array(int indent, enum attr_type type, static void print_array(int indent, enum attr_type type,
const struct attr_entry *entry,
const void *buf, uint32_t len) const void *buf, uint32_t len)
{ {
const struct nlattr *nla; const struct nlattr *nla;
@ -6700,8 +6702,20 @@ static void print_array(int indent, enum attr_type type,
char str[8]; char str[8];
snprintf(str, sizeof(str), "%u", nla_type); snprintf(str, sizeof(str), "%u", nla_type);
print_value(indent, str, type,
switch (type) {
case ATTR_NESTED:
if (entry->nested)
print_attributes(indent + 1, entry->nested,
NLA_DATA(nla), NLA_PAYLOAD(nla));
else
printf("missing nested table\n");
break;
default:
print_value(indent, str, type,
NLA_DATA(nla), NLA_PAYLOAD(nla)); NLA_DATA(nla), NLA_PAYLOAD(nla));
break;
}
} }
} }
@ -6832,7 +6846,7 @@ static void print_attributes(int indent, const struct attr_entry *table,
NLA_PAYLOAD(nla)); NLA_PAYLOAD(nla));
if (array_type == ATTR_UNSPEC) if (array_type == ATTR_UNSPEC)
printf("missing type\n"); printf("missing type\n");
print_array(indent + 1, array_type, print_array(indent + 1, array_type, &table[i],
NLA_DATA(nla), NLA_PAYLOAD(nla)); NLA_DATA(nla), NLA_PAYLOAD(nla));
break; break;
case ATTR_FLAG_OR_U16: case ATTR_FLAG_OR_U16: