Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* SCTP kernel reference Implementation
0003  * Copyright (c) 1999-2001 Motorola, Inc.
0004  * Copyright (c) 2001-2003 International Business Machines, Corp.
0005  *
0006  * This file is part of the SCTP kernel reference Implementation
0007  *
0008  * SCTP Checksum functions
0009  *
0010  * Please send any bug reports or fixes you make to the
0011  * email address(es):
0012  *    lksctp developers <linux-sctp@vger.kernel.org>
0013  *
0014  * Written or modified by:
0015  *    Dinakaran Joseph
0016  *    Jon Grimm <jgrimm@us.ibm.com>
0017  *    Sridhar Samudrala <sri@us.ibm.com>
0018  *
0019  * Rewritten to use libcrc32c by:
0020  *    Vlad Yasevich <vladislav.yasevich@hp.com>
0021  */
0022 
0023 #ifndef __sctp_checksum_h__
0024 #define __sctp_checksum_h__
0025 
0026 #include <linux/types.h>
0027 #include <net/sctp/sctp.h>
0028 #include <linux/crc32c.h>
0029 #include <linux/crc32.h>
0030 
0031 static inline __wsum sctp_csum_update(const void *buff, int len, __wsum sum)
0032 {
0033     /* This uses the crypto implementation of crc32c, which is either
0034      * implemented w/ hardware support or resolves to __crc32c_le().
0035      */
0036     return (__force __wsum)crc32c((__force __u32)sum, buff, len);
0037 }
0038 
0039 static inline __wsum sctp_csum_combine(__wsum csum, __wsum csum2,
0040                        int offset, int len)
0041 {
0042     return (__force __wsum)__crc32c_le_combine((__force __u32)csum,
0043                            (__force __u32)csum2, len);
0044 }
0045 
0046 static const struct skb_checksum_ops sctp_csum_ops = {
0047     .update  = sctp_csum_update,
0048     .combine = sctp_csum_combine,
0049 };
0050 
0051 static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
0052                     unsigned int offset)
0053 {
0054     struct sctphdr *sh = (struct sctphdr *)(skb->data + offset);
0055     __le32 old = sh->checksum;
0056     __wsum new;
0057 
0058     sh->checksum = 0;
0059     new = ~__skb_checksum(skb, offset, skb->len - offset, ~(__wsum)0,
0060                   &sctp_csum_ops);
0061     sh->checksum = old;
0062 
0063     return cpu_to_le32((__force __u32)new);
0064 }
0065 
0066 #endif /* __sctp_checksum_h__ */