diff options
author | Danielle Ratson <danieller@nvidia.com> | 2024-07-31 09:35:51 +0300 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2024-07-31 09:12:57 +0200 |
commit | 102942be401a99943b2c68981b238dadfa788f2d (patch) | |
tree | fc42fd7427ce564252a39b12c68e5798296016f7 /src/attr.c | |
parent | 754c9de5ea1bea821495523cf01989299552e524 (diff) |
src: attr: Add mnl_attr_get_uint() function
NLA_UINT attributes have a 4-byte payload if possible, and an 8-byte one
if necessary.
There are some NLA_UINT attributes that lack an appropriate getter function.
Add a function mnl_attr_get_uint() to cover that extract these. Since we
need to dispatch on length anyway, make the getter truly universal by
supporting also u8 and u16.
Signed-off-by: Danielle Ratson <danieller@nvidia.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/attr.c')
-rw-r--r-- | src/attr.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -390,6 +390,28 @@ EXPORT_SYMBOL uint64_t mnl_attr_get_u64(const struct nlattr *attr) } /** + * mnl_attr_get_uint - returns 64-bit unsigned integer attribute. + * \param attr pointer to netlink attribute + * + * This function returns the 64-bit value of the attribute payload. + */ +EXPORT_SYMBOL uint64_t mnl_attr_get_uint(const struct nlattr *attr) +{ + switch (mnl_attr_get_payload_len(attr)) { + case sizeof(uint8_t): + return mnl_attr_get_u8(attr); + case sizeof(uint16_t): + return mnl_attr_get_u16(attr); + case sizeof(uint32_t): + return mnl_attr_get_u32(attr); + case sizeof(uint64_t): + return mnl_attr_get_u64(attr); + } + + return -1ULL; +} + +/** * mnl_attr_get_str - get pointer to string attribute * \param attr pointer to netlink attribute * |