aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Machata <petrm@nvidia.com>2024-03-14 15:52:12 +0100
committerDavid Ahern <dsahern@kernel.org>2024-03-15 15:03:06 +0000
commit95836fbf35d352f7c031ddac2e6093a935308cc9 (patch)
tree1609900537e226b662c96806590f3aebe2609c5b
parent8b3b71898d801e97ea9d098b314d4442c23f0e36 (diff)
downloadiproute2-next-95836fbf35d352f7c031ddac2e6093a935308cc9.tar.gz
libnetlink: Add rta_getattr_uint()
NLA_UINT attributes have a 4-byte payload if possible, and an 8-byte one if necessary. Add a function to extract these. Since we need to dispatch on length anyway, make the getter truly universal by supporting also u8 and u16. Signed-off-by: Petr Machata <petrm@nvidia.com> Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r--include/libnetlink.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/libnetlink.h b/include/libnetlink.h
index ad7e71272..35a9bb57d 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -260,6 +260,20 @@ static inline __u64 rta_getattr_u64(const struct rtattr *rta)
memcpy(&tmp, RTA_DATA(rta), sizeof(__u64));
return tmp;
}
+static inline __u64 rta_getattr_uint(const struct rtattr *rta)
+{
+ switch (RTA_PAYLOAD(rta)) {
+ case sizeof(__u8):
+ return rta_getattr_u8(rta);
+ case sizeof(__u16):
+ return rta_getattr_u16(rta);
+ case sizeof(__u32):
+ return rta_getattr_u32(rta);
+ case sizeof(__u64):
+ return rta_getattr_u64(rta);
+ }
+ return -1ULL;
+}
static inline __s32 rta_getattr_s32(const struct rtattr *rta)
{
return *(__s32 *)RTA_DATA(rta);