mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 18:00:10 +01:00
platform/netlink: add nla_data_as() macro
This macro casts the return pointer and asserts that the netlink attribute is suitably large.
This commit is contained in:
parent
5920f187d3
commit
020000433b
1 changed files with 14 additions and 0 deletions
|
|
@ -154,6 +154,20 @@ nla_data (const struct nlattr *nla)
|
|||
return &(((char *) nla)[NLA_HDRLEN]);
|
||||
}
|
||||
|
||||
#define nla_data_as(type, nla) \
|
||||
({ \
|
||||
const struct nlattr *_nla = (nla); \
|
||||
\
|
||||
nm_assert (nla_len (_nla) >= sizeof (type)); \
|
||||
\
|
||||
/* note that casting the pointer is undefined behavior in C, if
|
||||
* the data has wrong alignment. Netlink data is aligned to 4 bytes,
|
||||
* that means, if the alignment is larger than 4, this is invalid. */ \
|
||||
G_STATIC_ASSERT_EXPR (_nm_alignof (type) <= NLA_ALIGNTO); \
|
||||
\
|
||||
(type *) nla_data (_nla); \
|
||||
})
|
||||
|
||||
static inline uint8_t
|
||||
nla_get_u8 (const struct nlattr *nla)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue