From nobody Tue Mar 07 17:45:36 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PWNC51ktlz3wQgk; Tue, 7 Mar 2023 17:45:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PWNC51DKqz3Fwk; Tue, 7 Mar 2023 17:45:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678211137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hdMz2C6O84q0XWRL5fcZKjBl9NDMvT/I3bWM7q8S3YY=; b=IL96kFAmpMzcllIXAjPfyW6pvJpwLBdeJ1FH9PDLW7cbKu4UgvOmf2cJUDng/HEyG8+czu ybjLhqbb62Bq04kyj5/Uwp6PpcQrLIJyE9/JEhtrIVuOQ+IPJhzlTs/XmB7/KFrnogy7xl C02n9px1uFZiTSDGnwg1bVbQqcCfwellkrG6/U4RW2iaaWWDzMsxN0TH3kT0CZmS4X21zb ai8G6CjxT9LvgxS9PpwMFAcYJQCUbO7yQC9DkzKTzUhgW3/hD4WU1CxTO1Cup5dm8WxMnF ufcxP5a/qUJAxM9MWylJ6gBjJLXb6piVfpVq8uKt4O7vGX0t6gEhQ5An9UaBdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678211137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hdMz2C6O84q0XWRL5fcZKjBl9NDMvT/I3bWM7q8S3YY=; b=sGT7mz+Mr/z4dmmemY6AtHOHs8xJUDvv9DHkvOJ6YIWPJsYIC7twE3ScZCr9XcS9z+xJx7 1Ou93j2hgitSWvFmSNvPpKA74s6lTegEI2PkMuFnfPb3CcB/7AqksUoS8iztpedl+QMbbF X8EKwsvvN4CQNerSTiHsGoZKAC0Fn1+azrlIRSLa1S+SZJsePGc/ulvUQxo0nRgn+LnIZX RQX29G5QhnpUsE+Yeqlc0y2lR0Txs5KwJLRnB0voOaSbyz+W2Zo+QYaD2lM21P3KUNK+3l IAv+SRGcBnPzqYa6rmruxlkxINxPmy1xlpvuNy+hWwrcQtTK1WWdkzp7xOfD3w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678211137; a=rsa-sha256; cv=none; b=tVKTaf7U27GjQfgWpSNjC6uc2a/ocySNdG1GGoH3/027CNpI/NmmEwHgoiu6YnUL4szITq f08ocDFWdC2rBcpZwUApMOreI/fTpZkZi/nqtS8y79UgeJZa97HfUZOacwbvJyu0yhwd2e J/KgZl8Uzlt31lTBY+a+R0Sx9QYmu6+EE38Uzje0TxforJes1Ij5B38GNH9sa+htoln6AL biyJtXmpwyYuRq+hkxZ5rDYFonxe+6ra3j/zhoIspERjunniOMR+CBXrfhpHzkhaaEHBMR 09a+VPw/Z2EtVrTo1HRNTFiBjGTq04btkG32lAygcqtcJEoSePSud8qZsEQHGg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PWNC504Mhzsqk; Tue, 7 Mar 2023 17:45:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 327HjaNm006322; Tue, 7 Mar 2023 17:45:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 327Hja9Z006321; Tue, 7 Mar 2023 17:45:36 GMT (envelope-from git) Date: Tue, 7 Mar 2023 17:45:36 GMT Message-Id: <202303071745.327Hja9Z006321@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 5c8277ec2588 - main - netlink: cleanup netlink_writer code List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5c8277ec2588a660f126e1a9866cd65f59336c51 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=5c8277ec2588a660f126e1a9866cd65f59336c51 commit 5c8277ec2588a660f126e1a9866cd65f59336c51 Author: Alexander V. Chernikov AuthorDate: 2023-03-07 17:42:27 +0000 Commit: Alexander V. Chernikov 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) {