blob: 6bd44fe94c26382e1130b9b989d1ed6efb68b349 [file] [log] [blame]
Vlad Yasevich9ad09772007-12-16 14:06:41 -08001/* SCTP kernel reference Implementation
2 * Copyright (c) 1999-2001 Motorola, Inc.
3 * Copyright (c) 2001-2003 International Business Machines, Corp.
4 *
5 * This file is part of the SCTP kernel reference Implementation
6 *
7 * SCTP Checksum functions
8 *
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)
13 * any later version.
14 *
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.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with GNU CC; see the file COPYING. If not, write to
23 * the Free Software Foundation, 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
25 *
26 * Please send any bug reports or fixes you make to the
27 * email address(es):
Daniel Borkmann91705c62013-07-23 14:51:47 +020028 * lksctp developers <linux-sctp@vger.kernel.org>
Vlad Yasevich9ad09772007-12-16 14:06:41 -080029 *
Vlad Yasevich9ad09772007-12-16 14:06:41 -080030 * Written or modified by:
31 * Dinakaran Joseph
32 * Jon Grimm <jgrimm@us.ibm.com>
33 * Sridhar Samudrala <sri@us.ibm.com>
34 *
35 * Rewritten to use libcrc32c by:
36 * Vlad Yasevich <vladislav.yasevich@hp.com>
Vlad Yasevich9ad09772007-12-16 14:06:41 -080037 */
38
Daniel Borkmanna05b1012013-07-01 18:10:36 +020039#ifndef __sctp_checksum_h__
40#define __sctp_checksum_h__
41
Vlad Yasevich9ad09772007-12-16 14:06:41 -080042#include <linux/types.h>
43#include <net/sctp/sctp.h>
44#include <linux/crc32c.h>
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010045#include <linux/crc32.h>
Vlad Yasevich9ad09772007-12-16 14:06:41 -080046
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010047static inline __wsum sctp_csum_update(const void *buff, int len, __wsum sum)
Vlad Yasevich9ad09772007-12-16 14:06:41 -080048{
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010049 /* This uses the crypto implementation of crc32c, which is either
50 * implemented w/ hardware support or resolves to __crc32c_le().
Vlad Yasevich9ad09772007-12-16 14:06:41 -080051 */
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010052 return crc32c(sum, buff, len);
Vlad Yasevich9ad09772007-12-16 14:06:41 -080053}
54
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010055static inline __wsum sctp_csum_combine(__wsum csum, __wsum csum2,
56 int offset, int len)
Vlad Yasevich9ad09772007-12-16 14:06:41 -080057{
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010058 return __crc32c_le_combine(csum, csum2, len);
Vlad Yasevich9ad09772007-12-16 14:06:41 -080059}
60
Joe Stringer024ec3d2013-07-25 10:52:05 +090061static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
62 unsigned int offset)
63{
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010064 struct sctphdr *sh = sctp_hdr(skb);
65 __le32 ret, old = sh->checksum;
66 const struct skb_checksum_ops ops = {
67 .update = sctp_csum_update,
68 .combine = sctp_csum_combine,
69 };
Joe Stringer024ec3d2013-07-25 10:52:05 +090070
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010071 sh->checksum = 0;
72 ret = cpu_to_le32(~__skb_checksum(skb, offset, skb->len - offset,
73 ~(__u32)0, &ops));
74 sh->checksum = old;
Joe Stringer024ec3d2013-07-25 10:52:05 +090075
Daniel Borkmanne6d8b642013-10-30 11:50:52 +010076 return ret;
Joe Stringer024ec3d2013-07-25 10:52:05 +090077}
78
Daniel Borkmanna05b1012013-07-01 18:10:36 +020079#endif /* __sctp_checksum_h__ */