1 /* SCTP kernel reference Implementation
2 * Copyright (c) 1999-2001 Motorola, Inc.
3 * Copyright (c) 2001-2003 International Business Machines, Corp.
5 * This file is part of the SCTP kernel reference Implementation
7 * SCTP Checksum functions
9 * The SCTP reference implementation is free software;
10 * you can redistribute it and/or modify it under the terms of
11 * the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * The SCTP reference implementation is distributed in the hope that it
16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * ************************
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GNU CC; see the file COPYING. If not, see
23 * <http://www.gnu.org/licenses/>.
25 * Please send any bug reports or fixes you make to the
27 * lksctp developers <linux-sctp@vger.kernel.org>
29 * Written or modified by:
31 * Jon Grimm <jgrimm@us.ibm.com>
32 * Sridhar Samudrala <sri@us.ibm.com>
34 * Rewritten to use libcrc32c by:
35 * Vlad Yasevich <vladislav.yasevich@hp.com>
38 #ifndef __sctp_checksum_h__
39 #define __sctp_checksum_h__
41 #include <linux/types.h>
42 #include <net/sctp/sctp.h>
43 #include <linux/crc32c.h>
44 #include <linux/crc32.h>
46 static inline __wsum
sctp_csum_update(const void *buff
, int len
, __wsum sum
)
48 /* This uses the crypto implementation of crc32c, which is either
49 * implemented w/ hardware support or resolves to __crc32c_le().
51 return (__force __wsum
)crc32c((__force __u32
)sum
, buff
, len
);
54 static inline __wsum
sctp_csum_combine(__wsum csum
, __wsum csum2
,
57 return (__force __wsum
)__crc32c_le_combine((__force __u32
)csum
,
58 (__force __u32
)csum2
, len
);
61 static inline __le32
sctp_compute_cksum(const struct sk_buff
*skb
,
64 struct sctphdr
*sh
= sctp_hdr(skb
);
65 const struct skb_checksum_ops ops
= {
66 .update
= sctp_csum_update
,
67 .combine
= sctp_csum_combine
,
69 __le32 old
= sh
->checksum
;
73 new = ~__skb_checksum(skb
, offset
, skb
->len
- offset
, ~(__wsum
)0, &ops
);
76 return cpu_to_le32((__force __u32
)new);
79 #endif /* __sctp_checksum_h__ */