[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e48770c7fbf45e14b2bac182d4083f56e02b7805.1710427655.git.petrm@nvidia.com>
Date: Thu, 14 Mar 2024 15:52:12 +0100
From: Petr Machata <petrm@...dia.com>
To: David Ahern <dsahern@...nel.org>, Stephen Hemminger
<stephen@...workplumber.org>, <netdev@...r.kernel.org>
CC: Ido Schimmel <idosch@...dia.com>, Petr Machata <petrm@...dia.com>, "Jakub
Kicinski" <kuba@...nel.org>, <mlxsw@...dia.com>
Subject: [PATCH iproute2-next v2 1/4] 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@...dia.com>
---
Notes:
v2:
- have rta_getattr_uint() support 8- and 16-bit quantities as well
include/libnetlink.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/libnetlink.h b/include/libnetlink.h
index ad7e7127..35a9bb57 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);
--
2.43.0
Powered by blists - more mailing lists