git: fb63082c0cc6 - main - netlink: provide snl(3) API for variable length raw data attribute
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 20 Jan 2025 20:54:06 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=fb63082c0cc6a7da68ff9c5b3a9bd023abafe1d2 commit fb63082c0cc6a7da68ff9c5b3a9bd023abafe1d2 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2025-01-20 20:53:07 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2025-01-20 20:53:07 +0000 netlink: provide snl(3) API for variable length raw data attribute Rename supposedly internal _snl_reserve_msg_attr() into an official snl_reserve_msg_attr_raw(), that would return pointer to a struct nlattr followed by allocated memory. Adjust the snl_reserve_msg_attr() macro to work on top of that function. Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D48311 --- sys/netlink/netlink_snl.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 0f3b3b44622d..44967b6f444a 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -1109,20 +1109,22 @@ snl_reserve_msg_data_raw(struct snl_writer *nw, size_t sz) #define snl_reserve_msg_object(_ns, _t) ((_t *)snl_reserve_msg_data_raw(_ns, sizeof(_t))) #define snl_reserve_msg_data(_ns, _sz, _t) ((_t *)snl_reserve_msg_data_raw(_ns, _sz)) -static inline void * -_snl_reserve_msg_attr(struct snl_writer *nw, uint16_t nla_type, uint16_t sz) +static inline struct nlattr * +snl_reserve_msg_attr_raw(struct snl_writer *nw, uint16_t nla_type, uint16_t sz) { - sz += sizeof(struct nlattr); + struct nlattr *nla; - struct nlattr *nla = snl_reserve_msg_data(nw, sz, struct nlattr); + sz += sizeof(struct nlattr); + nla = snl_reserve_msg_data(nw, sz, struct nlattr); if (__predict_false(nla == NULL)) return (NULL); nla->nla_type = nla_type; nla->nla_len = sz; - return ((void *)(nla + 1)); + return (nla); } -#define snl_reserve_msg_attr(_ns, _at, _t) ((_t *)_snl_reserve_msg_attr(_ns, _at, sizeof(_t))) +#define snl_reserve_msg_attr(_ns, _at, _t) \ + ((_t *)(snl_reserve_msg_attr_raw(_ns, _at, sizeof(_t)) + 1)) static inline bool snl_add_msg_attr(struct snl_writer *nw, int attr_type, int attr_len, const void *data)