From nobody Tue Nov 30 01:35:38 2021 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 D11E318BBB98; Tue, 30 Nov 2021 01:35:39 +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 4J34Y70Z2pz3n5q; Tue, 30 Nov 2021 01:35:39 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D4C0154D9; Tue, 30 Nov 2021 01:35:38 +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 1AU1Zcj2054631; Tue, 30 Nov 2021 01:35:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AU1ZcCC054630; Tue, 30 Nov 2021 01:35:38 GMT (envelope-from git) Date: Tue, 30 Nov 2021 01:35:38 GMT Message-Id: <202111300135.1AU1ZcCC054630@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 422456ae27f5 - stable/13 - sctp: Use m_apply() to calcuate a checksum for an mbuf chain 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 422456ae27f5f79dee3969de9190fbe9b9301c3c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638236139; 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=ujecD9ihZvX7EQy6pZT8qEKudshjvSnhNEv9FEf027g=; b=ONqlZtZHVBxO1pOmiWFNDND2RJHYDUxlFJmCrV7mlnk0MJq+k5JA07kPyAANLJVEt/U7Ip TmU1xzk4ekA9qeWjGXTJWa/bQBHQkekOLiluIJqnoBcDFJcymi7+pVPGVliDkiWLha6zFL IoukliXYR29+eUu2D0kzDY2IuDJY8rXb2CjkefCzMm6EwYy7RMrUaS1/ASxzxkGmcCwbBy v8kIszGHCX7ZR32CKP3dzft51TMyOIi0+OXYI0PAd7jNs+ZOy3VHmXTBPy4Us8VQYYxgYv Q7lk8mhnO1puOsYZGYtMQF2Azl4afj+mGxjLfS4S7k23Dt7KpvKCQWPB1IZY3g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638236139; a=rsa-sha256; cv=none; b=Jv8UufvmZuXuCYuWIqZ7IThho1mMvKxd45FV3VOw4c5Z/Yc88/dmhI7C7NKRbCvTRueNN+ 26ZXuUOszr1qXb64bbVeuYLXlBakGXAeTK+3ZmR5TrbhM6mBkGTMUP/1kteZoy6/OK26PU dYmSCPUpI1yoK1reUvPWS/ChIMSzmMbqiSgI0VmVyzBArpmiGO6R+8XNpdVFftYSyVVV5r MNBuemjN1faNrN/9lDtIooNtfOdE4/yY3gZN+bRGQtsc0zpoo4/jmrJunc3VZP27JqpDhT 81AFtURawof7lDZsEE2vl+YIs+19/wN0pP+vqna4+e1AWjEHNTrNEU1yrLagkA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=422456ae27f5f79dee3969de9190fbe9b9301c3c commit 422456ae27f5f79dee3969de9190fbe9b9301c3c Author: Mark Johnston AuthorDate: 2021-11-16 18:36:30 +0000 Commit: Mark Johnston CommitDate: 2021-11-30 01:35:08 +0000 sctp: Use m_apply() to calcuate a checksum for an mbuf chain m_apply() works on unmapped mbufs, so this will let us elide mb_unmapped_to_ext() calls preceding sctp_calculate_cksum() calls in the network stack. Modify sctp_calculate_cksum() to assume it's passed an mbuf header. This assumption appears to be true in practice, and we need to know the full length of the chain. No functional change intended. Reviewed by: tuexen, jhb Sponsored by: The FreeBSD Foundation (cherry picked from commit b4d758a0cc54d991d2bdf7f697ec0b6b3fd6230d) --- sys/netinet/sctp_crc32.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/sys/netinet/sctp_crc32.c b/sys/netinet/sctp_crc32.c index a36d36dc4861..97b881bb5062 100644 --- a/sys/netinet/sctp_crc32.c +++ b/sys/netinet/sctp_crc32.c @@ -80,6 +80,16 @@ sctp_finalize_crc32c(uint32_t crc32c) return (crc32c); } +static int +sctp_calculate_cksum_cb(void *arg, void *data, u_int len) +{ + uint32_t *basep; + + basep = arg; + *basep = calculate_crc32c(*basep, data, len); + return (0); +} + /* * Compute the SCTP checksum in network byte order for a given mbuf chain m * which contains an SCTP packet starting at offset. @@ -89,30 +99,17 @@ sctp_finalize_crc32c(uint32_t crc32c) uint32_t sctp_calculate_cksum(struct mbuf *m, uint32_t offset) { - uint32_t base = 0xffffffff; - - while (offset > 0) { - KASSERT(m != NULL, ("sctp_calculate_cksum, offset > length of mbuf chain")); - if (offset < (uint32_t)m->m_len) { - break; - } - offset -= m->m_len; - m = m->m_next; - } - if (offset > 0) { - base = calculate_crc32c(base, - (unsigned char *)(m->m_data + offset), - (unsigned int)(m->m_len - offset)); - m = m->m_next; - } - while (m != NULL) { - base = calculate_crc32c(base, - (unsigned char *)m->m_data, - (unsigned int)m->m_len); - m = m->m_next; - } - base = sctp_finalize_crc32c(base); - return (base); + uint32_t base; + int len; + + M_ASSERTPKTHDR(m); + KASSERT(offset < m->m_pkthdr.len, + ("%s: invalid offset %u into mbuf %p", __func__, offset, m)); + + base = 0xffffffff; + len = m->m_pkthdr.len - offset; + (void)m_apply(m, offset, len, sctp_calculate_cksum_cb, &base); + return (sctp_finalize_crc32c(base)); } #if defined(SCTP) || defined(SCTP_SUPPORT)