git: 5c8277ec2588 - main - netlink: cleanup netlink_writer code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 07 Mar 2023 17:45:36 UTC
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=5c8277ec2588a660f126e1a9866cd65f59336c51 commit 5c8277ec2588a660f126e1a9866cd65f59336c51 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-03-07 17:42:27 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-03-07 17:45:31 +0000 netlink: cleanup netlink_writer code * Remove unused nlattr_add_nla() - that's a duplicate of nlattr_add_raw(). * Calculate alignment only once in nlmsg_reserve_data_raw() MFC after: 2 weeks --- sys/netlink/netlink_message_writer.h | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/sys/netlink/netlink_message_writer.h b/sys/netlink/netlink_message_writer.h index bb4bb759251a..13acf5add559 100644 --- a/sys/netlink/netlink_message_writer.h +++ b/sys/netlink/netlink_message_writer.h @@ -124,17 +124,19 @@ nlattr_set_len(const struct nl_writer *nw, int off) static inline void * nlmsg_reserve_data_raw(struct nl_writer *nw, size_t sz) { - if (__predict_false(nw->offset + NETLINK_ALIGN(sz) > nw->alloc_len)) { - if (!nlmsg_refill_buffer(nw, NETLINK_ALIGN(sz))) + sz = NETLINK_ALIGN(sz); + + if (__predict_false(nw->offset + sz > nw->alloc_len)) { + if (!nlmsg_refill_buffer(nw, sz)) return (NULL); } void *data_ptr = &nw->data[nw->offset]; - nw->offset += NLMSG_ALIGN(sz); + nw->offset += sz; return (data_ptr); } -#define nlmsg_reserve_object(_ns, _t) ((_t *)nlmsg_reserve_data_raw(_ns, NLA_ALIGN(sizeof(_t)))) +#define nlmsg_reserve_object(_ns, _t) ((_t *)nlmsg_reserve_data_raw(_ns, sizeof(_t))) #define nlmsg_reserve_data(_ns, _sz, _t) ((_t *)nlmsg_reserve_data_raw(_ns, _sz)) static inline int @@ -163,27 +165,6 @@ _nlmsg_reserve_attr(struct nl_writer *nw, uint16_t nla_type, uint16_t sz) } #define nlmsg_reserve_attr(_ns, _at, _t) ((_t *)_nlmsg_reserve_attr(_ns, _at, NLA_ALIGN(sizeof(_t)))) -static inline bool -nlattr_add_nla(struct nl_writer *nw, const struct nlattr *nla_src) -{ - MPASS(nla_src->nla_len >= sizeof(struct nlattr)); - - int required_len = NLA_ALIGN(nla_src->nla_len); - if (__predict_false(nw->offset + required_len > nw->alloc_len)) { - if (!nlmsg_refill_buffer(nw, required_len)) - return (false); - } - - struct nlattr *nla = (struct nlattr *)(&nw->data[nw->offset]); - if ((nla_src->nla_len % 4) != 0) { - /* clear padding bytes */ - bzero((char *)nla + nla_src->nla_len - 4, 4); - } - memcpy(nla, nla_src, nla_src->nla_len); - nw->offset += required_len; - return (true); -} - static inline bool nlattr_add(struct nl_writer *nw, int attr_type, int attr_len, const void *data) {