Message ID | 501f27b908eed65e94b569e88ee8a6396db71932.1709934897.git.petrm@nvidia.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | David Ahern |
Headers | show |
Series | Support for nexthop group statistics | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
On Fri, 8 Mar 2024 23:29:06 +0100 Petr Machata <petrm@nvidia.com> wrote: > +static inline __u64 rta_getattr_uint(const struct rtattr *rta) > +{ > + if (RTA_PAYLOAD(rta) == sizeof(__u32)) > + return rta_getattr_u32(rta); > + return rta_getattr_u64(rta); Don't understand the use case here. The kernel always sends the same payload size for the same attribute.
On Fri, 8 Mar 2024 14:58:59 -0800 Stephen Hemminger wrote: > > +static inline __u64 rta_getattr_uint(const struct rtattr *rta) > > +{ > > + if (RTA_PAYLOAD(rta) == sizeof(__u32)) > > + return rta_getattr_u32(rta); > > + return rta_getattr_u64(rta); > > Don't understand the use case here. > The kernel always sends the same payload size for the same attribute. Please see commit 374d345d9b5e13380c in the kernel.
On Fri, 8 Mar 2024 19:43:34 -0800 Jakub Kicinski <kuba@kernel.org> wrote: > On Fri, 8 Mar 2024 14:58:59 -0800 Stephen Hemminger wrote: > > > +static inline __u64 rta_getattr_uint(const struct rtattr *rta) > > > +{ > > > + if (RTA_PAYLOAD(rta) == sizeof(__u32)) > > > + return rta_getattr_u32(rta); > > > + return rta_getattr_u64(rta); > > > > Don't understand the use case here. > > The kernel always sends the same payload size for the same attribute. > > Please see commit 374d345d9b5e13380c in the kernel. Ok, but maybe go further and handle u16 and u8
On Sat, 9 Mar 2024 09:21:58 -0800 Stephen Hemminger wrote: > > > Don't understand the use case here. > > > The kernel always sends the same payload size for the same attribute. > > > > Please see commit 374d345d9b5e13380c in the kernel. > > Ok, but maybe go further and handle u16 and u8 I guess you can if that's helpful in iproute2, as a "universal getter", cost of a few branches. In the kernel I try hard to convince people to never use u8 and u16 as they simply waste space on padding, and the bits may turn out to be needed later.
Stephen Hemminger <stephen@networkplumber.org> writes: > On Fri, 8 Mar 2024 19:43:34 -0800 > Jakub Kicinski <kuba@kernel.org> wrote: > >> On Fri, 8 Mar 2024 14:58:59 -0800 Stephen Hemminger wrote: >> > > +static inline __u64 rta_getattr_uint(const struct rtattr *rta) >> > > +{ >> > > + if (RTA_PAYLOAD(rta) == sizeof(__u32)) >> > > + return rta_getattr_u32(rta); >> > > + return rta_getattr_u64(rta); >> > >> > Don't understand the use case here. >> > The kernel always sends the same payload size for the same attribute. >> >> Please see commit 374d345d9b5e13380c in the kernel. > > Ok, but maybe go further and handle u16 and u8 I intended this as a getter of the corresponding kernel attribute type, which only ever sends 4- and 8-byte payloads, but sure, I can add that.
diff --git a/include/libnetlink.h b/include/libnetlink.h index ad7e7127..a1233659 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -260,6 +260,12 @@ 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) +{ + if (RTA_PAYLOAD(rta) == sizeof(__u32)) + return rta_getattr_u32(rta); + return rta_getattr_u64(rta); +} static inline __s32 rta_getattr_s32(const struct rtattr *rta) { return *(__s32 *)RTA_DATA(rta);
NLA_UINT attributes have a 4- or 8-byte payload. Add a function to extract these. Signed-off-by: Petr Machata <petrm@nvidia.com> --- include/libnetlink.h | 6 ++++++ 1 file changed, 6 insertions(+)