Skip to content

Commit 9ad0977

Browse files
Vlad Yasevichdavem330
authored andcommitted
[SCTP]: Use crc32c library for checksum calculations.
The crc32c library used an identical table and algorithm as SCTP. Switch to using the library instead of carrying our own table. Using crypto layer proved to have too much overhead compared to using the library directly. Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1bf4095 commit 9ad0977

7 files changed

Lines changed: 82 additions & 230 deletions

File tree

‎include/net/sctp/checksum.h‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* 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):
28+
* lksctp developers <lksctp-developers@lists.sourceforge.net>
29+
*
30+
* Or submit a bug report through the following website:
31+
* http://www.sf.net/projects/lksctp
32+
*
33+
* Written or modified by:
34+
* Dinakaran Joseph
35+
* Jon Grimm <jgrimm@us.ibm.com>
36+
* Sridhar Samudrala <sri@us.ibm.com>
37+
*
38+
* Rewritten to use libcrc32c by:
39+
* Vlad Yasevich <vladislav.yasevich@hp.com>
40+
*
41+
* Any bugs reported given to us we will try to fix... any fixes shared will
42+
* be incorporated into the next SCTP release.
43+
*/
44+
45+
#include <linux/types.h>
46+
#include <net/sctp/sctp.h>
47+
#include <linux/crc32c.h>
48+
49+
static inline __u32 sctp_start_cksum(__u8 *buffer, __u16 length)
50+
{
51+
__u32 crc = ~(__u32) 0;
52+
__u8 zero[sizeof(__u32)] = {0};
53+
54+
/* Optimize this routine to be SCTP specific, knowing how
55+
* to skip the checksum field of the SCTP header.
56+
*/
57+
58+
/* Calculate CRC up to the checksum. */
59+
crc = crc32c(crc, buffer, sizeof(struct sctphdr) - sizeof(__u32));
60+
61+
/* Skip checksum field of the header. */
62+
crc = crc32c(crc, zero, sizeof(__u32));
63+
64+
/* Calculate the rest of the CRC. */
65+
crc = crc32c(crc, &buffer[sizeof(struct sctphdr)],
66+
length - sizeof(struct sctphdr));
67+
return crc;
68+
}
69+
70+
static inline __u32 sctp_update_cksum(__u8 *buffer, __u16 length, __u32 crc32)
71+
{
72+
return crc32c(crc32, buffer, length);
73+
}
74+
75+
static inline __u32 sctp_end_cksum(__u32 crc32)
76+
{
77+
return ntohl(~crc32);
78+
}

‎include/net/sctp/sctp.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,6 @@ int sctp_primitive_SEND(struct sctp_association *, void *arg);
149149
int sctp_primitive_REQUESTHEARTBEAT(struct sctp_association *, void *arg);
150150
int sctp_primitive_ASCONF(struct sctp_association *, void *arg);
151151

152-
/*
153-
* sctp/crc32c.c
154-
*/
155-
__u32 sctp_start_cksum(__u8 *ptr, __u16 count);
156-
__u32 sctp_update_cksum(__u8 *ptr, __u16 count, __u32 cksum);
157-
__u32 sctp_end_cksum(__u32 cksum);
158-
159152
/*
160153
* sctp/input.c
161154
*/

‎net/sctp/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ menuconfig IP_SCTP
1010
select CRYPTO_HMAC
1111
select CRYPTO_SHA1
1212
select CRYPTO_MD5 if SCTP_HMAC_MD5
13+
select LIBCRC32C
1314
---help---
1415
Stream Control Transmission Protocol
1516

‎net/sctp/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sctp-y := sm_statetable.o sm_statefuns.o sm_sideeffect.o \
99
transport.o chunk.o sm_make_chunk.o ulpevent.o \
1010
inqueue.o outqueue.o ulpqueue.o command.o \
1111
tsnmap.o bind_addr.o socket.o primitive.o \
12-
output.o input.o debug.o ssnmap.o proc.o crc32c.o \
12+
output.o input.o debug.o ssnmap.o proc.o \
1313
auth.o
1414

1515
sctp-$(CONFIG_SCTP_DBG_OBJCNT) += objcnt.o

‎net/sctp/crc32c.c‎

Lines changed: 0 additions & 222 deletions
This file was deleted.

‎net/sctp/input.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <net/xfrm.h>
6161
#include <net/sctp/sctp.h>
6262
#include <net/sctp/sm.h>
63+
#include <net/sctp/checksum.h>
6364

6465
/* Forward declarations for internal helpers. */
6566
static int sctp_rcv_ootb(struct sk_buff *);

‎net/sctp/output.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
#include <net/sctp/sctp.h>
6262
#include <net/sctp/sm.h>
63+
#include <net/sctp/checksum.h>
6364

6465
/* Forward declarations for private helpers. */
6566
static sctp_xmit_t sctp_packet_append_data(struct sctp_packet *packet,

0 commit comments

Comments
 (0)