sctp: use skb_crc32c() instead of __skb_checksum()
authorEric Biggers <ebiggers@google.com>
Mon, 19 May 2025 17:50:07 +0000 (10:50 -0700)
committerJakub Kicinski <kuba@kernel.org>
Wed, 21 May 2025 22:40:16 +0000 (15:40 -0700)
Make sctp_compute_cksum() just use the new function skb_crc32c(),
instead of calling __skb_checksum() with a skb_checksum_ops struct that
does CRC32C.  This is faster and simpler.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Link: https://patch.msgid.link/20250519175012.36581-6-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/sctp/checksum.h
net/netfilter/Kconfig
net/netfilter/ipvs/Kconfig
net/openvswitch/Kconfig
net/sched/Kconfig
net/sctp/Kconfig
net/sctp/offload.c

index 291465c2581024faa1dc701f3050a6b3749e4676..654d37ec04029b316c1b28e0827b1d008380b1f3 100644 (file)
@@ -15,8 +15,6 @@
  *    Dinakaran Joseph
  *    Jon Grimm <jgrimm@us.ibm.com>
  *    Sridhar Samudrala <sri@us.ibm.com>
- *
- * Rewritten to use libcrc32c by:
  *    Vlad Yasevich <vladislav.yasevich@hp.com>
  */
 
 
 #include <linux/types.h>
 #include <linux/sctp.h>
-#include <linux/crc32c.h>
-#include <linux/crc32.h>
-
-static inline __wsum sctp_csum_update(const void *buff, int len, __wsum sum)
-{
-       return (__force __wsum)crc32c((__force __u32)sum, buff, len);
-}
-
-static inline __wsum sctp_csum_combine(__wsum csum, __wsum csum2,
-                                      int offset, int len)
-{
-       return (__force __wsum)crc32c_combine((__force __u32)csum,
-                                             (__force __u32)csum2, len);
-}
-
-static const struct skb_checksum_ops sctp_csum_ops = {
-       .update  = sctp_csum_update,
-       .combine = sctp_csum_combine,
-};
 
 static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
                                        unsigned int offset)
 {
        struct sctphdr *sh = (struct sctphdr *)(skb->data + offset);
        __le32 old = sh->checksum;
-       __wsum new;
+       u32 new;
 
        sh->checksum = 0;
-       new = ~__skb_checksum(skb, offset, skb->len - offset, ~(__wsum)0,
-                             &sctp_csum_ops);
+       new = ~skb_crc32c(skb, offset, skb->len - offset, ~0);
        sh->checksum = old;
-
-       return cpu_to_le32((__force __u32)new);
+       return cpu_to_le32(new);
 }
 
 #endif /* __sctp_checksum_h__ */
index 3b2183fc7e563b086065980d220d11996723657a..2560416218d078b1b87b97c30df8f1afc327e280 100644 (file)
@@ -212,7 +212,7 @@ config NF_CT_PROTO_SCTP
        bool 'SCTP protocol connection tracking support'
        depends on NETFILTER_ADVANCED
        default y
-       select CRC32
+       select NET_CRC32C
        help
          With this option enabled, the layer 3 independent connection
          tracking code will be able to do state tracking on SCTP connections.
@@ -475,7 +475,7 @@ endif # NF_CONNTRACK
 
 config NF_TABLES
        select NETFILTER_NETLINK
-       select CRC32
+       select NET_CRC32C
        tristate "Netfilter nf_tables support"
        help
          nftables is the new packet classification framework that intends to
index 8c5b1fe12d0782a091538246c0e84c5687481472..c203252e856d8c5466c589c978c1605351d885f5 100644 (file)
@@ -105,7 +105,7 @@ config      IP_VS_PROTO_AH
 
 config  IP_VS_PROTO_SCTP
        bool "SCTP load balancing support"
-       select CRC32
+       select NET_CRC32C
        help
          This option enables support for load balancing SCTP transport
          protocol. Say Y if unsure.
index 5481bd561eb414e3bbb4b50922c84f1c1afe773a..e6aaee92dba4833cdc8ca4ea6c14cb5fe18dbc25 100644 (file)
@@ -11,8 +11,8 @@ config OPENVSWITCH
                                     (!NF_NAT || NF_NAT) && \
                                     (!NETFILTER_CONNCOUNT || NETFILTER_CONNCOUNT)))
        depends on PSAMPLE || !PSAMPLE
-       select CRC32
        select MPLS
+       select NET_CRC32C
        select NET_MPLS_GSO
        select DST_CACHE
        select NET_NSH
index 9f0b3f943fca869121a2194df03e114957fd8791..ad914d2b2e221ad502b368a2cc6b2ebf6712cceb 100644 (file)
@@ -796,7 +796,7 @@ config NET_ACT_SKBEDIT
 config NET_ACT_CSUM
        tristate "Checksum Updating"
        depends on NET_CLS_ACT && INET
-       select CRC32
+       select NET_CRC32C
        help
          Say Y here to update some common checksum after some direct
          packet alterations.
index 3669ba351856301f98378f18f0f36ad1af23a896..24d5a35ce894ae9cc856dc00775ef0076a75727c 100644 (file)
@@ -7,7 +7,6 @@ menuconfig IP_SCTP
        tristate "The SCTP Protocol"
        depends on INET
        depends on IPV6 || IPV6=n
-       select CRC32
        select CRYPTO
        select CRYPTO_HMAC
        select CRYPTO_SHA1
index 502095173d885636525f6dc100ef8060dc1ca9d1..e6f863c031b4cf38bfd37608ec1bbcf0bb38b19e 100644 (file)
@@ -111,7 +111,6 @@ int __init sctp_offload_init(void)
        if (ret)
                goto ipv4;
 
-       crc32c_csum_stub = &sctp_csum_ops;
        return ret;
 
 ipv4: