nlattr: introduce decode_nla_flags

Similar to decode_nla_xval.

* nlattr.c (decode_nla_flags): New function.
* nlattr.h: (DECL_NLA(flags)): New declaration.
This commit is contained in:
Eugene Syromyatnikov 2018-05-07 08:40:02 +02:00 committed by Dmitry V. Levin
parent dbc5d26b29
commit bdc6ca9e56
2 changed files with 27 additions and 0 deletions

View File

@ -295,6 +295,32 @@ decode_nla_ip_proto(struct tcb *const tcp,
return decode_nla_xval(tcp, addr, len, &opts);
}
bool
decode_nla_flags(struct tcb *const tcp,
const kernel_ulong_t addr,
const unsigned int len,
const void *const opaque_data)
{
const struct decode_nla_xlat_opts * const opts = opaque_data;
union {
uint64_t flags;
uint8_t bytes[sizeof(uint64_t)];
} data = { .flags = 0 };
const size_t bytes_offs = is_bigendian ? sizeof(data) - len : 0;
if (opts->xt == XT_INDEXED)
error_func_msg("indexed xlats are currently incompatible with "
"printflags");
if (len > sizeof(data))
return false;
else if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs))
printflags_ex(data.flags, opts->dflt, opts->style, opts->xlat,
NULL);
return true;
}
bool
decode_nla_be16(struct tcb *const tcp,
const kernel_ulong_t addr,

View File

@ -75,6 +75,7 @@ DECL_NLA(s64);
DECL_NLA(be16);
DECL_NLA(be64);
DECL_NLA(xval);
DECL_NLA(flags);
DECL_NLA(str);
DECL_NLA(strn);
DECL_NLA(fd);