aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2025-01-20 20:53:07 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2025-01-20 20:53:07 +0000
commitfb63082c0cc6a7da68ff9c5b3a9bd023abafe1d2 (patch)
tree0f08a11eb18fa0b321339168a75be434acd2b61e
parent127b443124d1e720b246ad381648c436c3d240de (diff)
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
-rw-r--r--sys/netlink/netlink_snl.h14
1 files 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)