From nobody Tue Jan 02 21:06:55 2024 X-Original-To: dev-commits-src-all@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 4T4QQS1YT2z56KLN; Tue, 2 Jan 2024 21:06:56 +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 4T4QQR68t4z4c9w; Tue, 2 Jan 2024 21:06:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704229615; 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=/M0dX5DYG6QtMGowX1I8qx57YlVYjaOVLNRXnP9QbAs=; b=csSkRWbP93ImzyrfJ1QpK2UInKs0tGsmbe9K6Xx7bUP4UokKbHZB5YFsQSFu7laA7youp1 Vu6f1Db2QA25s/2gq9uMJjBVeld1T09uy+UpKv8W8+N3Ua3X6ehkh73FmK4v65/PbEntKw a+9ZpBhrWgjm0JJxcmk+txiETDRcHv0hJUjv9Bxhq+x/Z22xxOWal0zJ0NYgWhocGrJMIb MV6lDW1LyAErF3QgnuU5bbS0pB79WwKsXDCdQ44EevsQnfLNmFuHsAXmeHoGPYkM2LjF5/ /RYgD/u54Kc7jcpP6u2REU51N+5pO+rzVoT3k5yrob1sGIuF0xgRJlEINBPCiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704229615; a=rsa-sha256; cv=none; b=YAyie8j7TKES2fqWHBv5xS7ICAW+7j6M7b6lV7DrIuca5XbjzfKNfWsfSmLzeh67tvskI2 9MFVZKvQLy9zJbJoszwi3Y1NhzdWnxbjS7Ex7hlcrVfNx5zHmSJEhA9HtyRsNEjnT9ebln F+oiM1SmpUwxdw9w6mBotnfXPtWTq4U2CuzLlJF2mNThZCbsGfLNIADNy142uJPriHTmg1 643YHCdJRz234ly7BTkvr/SGUl4x3AiUlxoS2RtSQli3j3awRFCkOaxUmPuMAwChMDjSpL ZqZDWoCHbAHz3MNcvaeFN/sKqpJ7DAvjOyXR3yQ0dQHnRK/Ea6yhsyUhy0ffXA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704229615; 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=/M0dX5DYG6QtMGowX1I8qx57YlVYjaOVLNRXnP9QbAs=; b=JQxX0cpCwnycP9yi909H+RhlcCwIBPEb2NhraANcSO+tAtPqROWFyJS8QEAO2vDihwO/Iq aAUvff2ChdoBMhCJSP/YOzq8abQE1EIZuZv9BosWtqOAO5pxvMXJnuCN49sasHZKc3iBbQ hVbKG/6dMcsczz98XEWYprZUxZ8Sulu3Y9tXNQ4dGQklumNIXcz9g1fvJ0m4oh7F1eUKc7 sg+hnueS36tKn47ujhqiO2Y3eWJkLMpUvjgIIeYNBSFJkM3JkIYoIO3gidUzyyrJss2V9J ihPjPyFy9fdIxwKhVvPiRRi9aAXp237+dCi+le0xBdeFdXKZOvKQRdJxTwsOuA== 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 4T4QQR5BLXz1G9Z; Tue, 2 Jan 2024 21:06:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 402L6tDF055946; Tue, 2 Jan 2024 21:06:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 402L6teG055943; Tue, 2 Jan 2024 21:06:55 GMT (envelope-from git) Date: Tue, 2 Jan 2024 21:06:55 GMT Message-Id: <202401022106.402L6teG055943@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 67d9023f07a4 - main - netlink: uninline some KPI functions that work with struct nl_writer List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 67d9023f07a495ca626fa7fec005713cbbd01ba2 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=67d9023f07a495ca626fa7fec005713cbbd01ba2 commit 67d9023f07a495ca626fa7fec005713cbbd01ba2 Author: Gleb Smirnoff AuthorDate: 2024-01-02 21:03:40 +0000 Commit: Gleb Smirnoff CommitDate: 2024-01-02 21:03:40 +0000 netlink: uninline some KPI functions that work with struct nl_writer These functions work with a buffer embedded into nl_writer, which is going to go opaque with upcoming changes. Make them private to the netlink module. No functional change intended. Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D42523 --- sys/netlink/netlink_message_writer.c | 52 ++++++++++++++++++++++++++++++++++++ sys/netlink/netlink_message_writer.h | 49 +++------------------------------ 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/sys/netlink/netlink_message_writer.c b/sys/netlink/netlink_message_writer.c index 00c7f84cbc0a..dafcca6ef038 100644 --- a/sys/netlink/netlink_message_writer.c +++ b/sys/netlink/netlink_message_writer.c @@ -783,4 +783,56 @@ _nlmsg_end_dump(struct nl_writer *nw, int error, struct nlmsghdr *hdr) return (true); } +/* + * KPI functions. + */ + +int +nlattr_save_offset(const struct nl_writer *nw) +{ + return (nw->offset - ((char *)nw->hdr - nw->data)); +} + +void * +nlmsg_reserve_data_raw(struct nl_writer *nw, size_t 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 += sz; + bzero(data_ptr, sz); + + return (data_ptr); +} + +bool +nlattr_add(struct nl_writer *nw, int attr_type, int attr_len, const void *data) +{ + int required_len = NLA_ALIGN(attr_len + sizeof(struct nlattr)); + + 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]); + + nla->nla_len = attr_len + sizeof(struct nlattr); + nla->nla_type = attr_type; + if (attr_len > 0) { + if ((attr_len % 4) != 0) { + /* clear padding bytes */ + bzero((char *)nla + required_len - 4, 4); + } + memcpy((nla + 1), data, attr_len); + } + nw->offset += required_len; + return (true); +} + #include diff --git a/sys/netlink/netlink_message_writer.h b/sys/netlink/netlink_message_writer.h index 97e5f828788a..68e434094678 100644 --- a/sys/netlink/netlink_message_writer.h +++ b/sys/netlink/netlink_message_writer.h @@ -193,11 +193,7 @@ nlmsg_reply(struct nl_writer *nw, const struct nlmsghdr *hdr, int payload_len) * current (uncompleted) header is guaranteed to be contiguous, * but can be reallocated, thus pointers may need to be readjusted. */ -static inline int -nlattr_save_offset(const struct nl_writer *nw) -{ - return (nw->offset - ((char *)nw->hdr - nw->data)); -} +u_int nlattr_save_offset(const struct nl_writer *nw); static inline void * _nlattr_restore_offset(const struct nl_writer *nw, int off) @@ -213,22 +209,7 @@ nlattr_set_len(const struct nl_writer *nw, int off) nla->nla_len = nlattr_save_offset(nw) - off; } -static inline void * -nlmsg_reserve_data_raw(struct nl_writer *nw, size_t 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 += sz; - bzero(data_ptr, sz); - - return (data_ptr); -} +void *nlmsg_reserve_data_raw(struct nl_writer *nw, size_t sz); #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)) @@ -258,30 +239,8 @@ _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(struct nl_writer *nw, int attr_type, int attr_len, const void *data) -{ - int required_len = NLA_ALIGN(attr_len + sizeof(struct nlattr)); - - 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]); - - nla->nla_len = attr_len + sizeof(struct nlattr); - nla->nla_type = attr_type; - if (attr_len > 0) { - if ((attr_len % 4) != 0) { - /* clear padding bytes */ - bzero((char *)nla + required_len - 4, 4); - } - memcpy((nla + 1), data, attr_len); - } - nw->offset += required_len; - return (true); -} +bool nlattr_add(struct nl_writer *nw, int attr_type, int attr_len, + const void *data); static inline bool nlattr_add_raw(struct nl_writer *nw, const struct nlattr *nla_src)