eee1d5a147
Change the type of the crc32 parameter of sctp_end_cksum() from __be32 to __u32 to reflect that fact that it is passed to cpu_to_le32(). There are five in-tree users of sctp_end_cksum(). The following four had warnings flagged by sparse which are no longer present with this change. net/netfilter/ipvs/ip_vs_proto_sctp.c:sctp_nat_csum() net/netfilter/ipvs/ip_vs_proto_sctp.c:sctp_csum_check() net/sctp/input.c:sctp_rcv_checksum() net/sctp/output.c:sctp_packet_transmit() The fifth user is net/netfilter/nf_nat_proto_sctp.c:sctp_manip_pkt(). It has been updated to pass a __u32 instead of a __be32, the value in question was already calculated in cpu byte-order. net/netfilter/nf_nat_proto_sctp.c:sctp_manip_pkt() has also been updated to assign the return value of sctp_end_cksum() directly to a variable of type __le32, matching the type of the return value. Previously the return value was assigned to a variable of type __be32 and then that variable was finally assigned to another variable of type __le32. Problems flagged by sparse. Compile and sparse tested only. Signed-off-by: Simon Horman <horms@verge.net.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
83 lines
2.6 KiB
C
83 lines
2.6 KiB
C
/* SCTP kernel reference Implementation
|
|
* Copyright (c) 1999-2001 Motorola, Inc.
|
|
* Copyright (c) 2001-2003 International Business Machines, Corp.
|
|
*
|
|
* This file is part of the SCTP kernel reference Implementation
|
|
*
|
|
* SCTP Checksum functions
|
|
*
|
|
* The SCTP reference implementation is free software;
|
|
* you can redistribute it and/or modify it under the terms of
|
|
* the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* The SCTP reference implementation is distributed in the hope that it
|
|
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
* ************************
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with GNU CC; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*
|
|
* Please send any bug reports or fixes you make to the
|
|
* email address(es):
|
|
* lksctp developers <lksctp-developers@lists.sourceforge.net>
|
|
*
|
|
* Or submit a bug report through the following website:
|
|
* http://www.sf.net/projects/lksctp
|
|
*
|
|
* Written or modified by:
|
|
* 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>
|
|
*
|
|
* Any bugs reported given to us we will try to fix... any fixes shared will
|
|
* be incorporated into the next SCTP release.
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
#include <net/sctp/sctp.h>
|
|
#include <linux/crc32c.h>
|
|
|
|
static inline __u32 sctp_crc32c(__u32 crc, u8 *buffer, u16 length)
|
|
{
|
|
return crc32c(crc, buffer, length);
|
|
}
|
|
|
|
static inline __u32 sctp_start_cksum(__u8 *buffer, __u16 length)
|
|
{
|
|
__u32 crc = ~(__u32)0;
|
|
__u8 zero[sizeof(__u32)] = {0};
|
|
|
|
/* Optimize this routine to be SCTP specific, knowing how
|
|
* to skip the checksum field of the SCTP header.
|
|
*/
|
|
|
|
/* Calculate CRC up to the checksum. */
|
|
crc = sctp_crc32c(crc, buffer, sizeof(struct sctphdr) - sizeof(__u32));
|
|
|
|
/* Skip checksum field of the header. */
|
|
crc = sctp_crc32c(crc, zero, sizeof(__u32));
|
|
|
|
/* Calculate the rest of the CRC. */
|
|
crc = sctp_crc32c(crc, &buffer[sizeof(struct sctphdr)],
|
|
length - sizeof(struct sctphdr));
|
|
return crc;
|
|
}
|
|
|
|
static inline __u32 sctp_update_cksum(__u8 *buffer, __u16 length, __u32 crc32)
|
|
{
|
|
return sctp_crc32c(crc32, buffer, length);
|
|
}
|
|
|
|
static inline __le32 sctp_end_cksum(__u32 crc32)
|
|
{
|
|
return cpu_to_le32(~crc32);
|
|
}
|