Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sctp: remove unnecessary byteshifting, calculate directly in big-endian

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Harvey Harrison and committed by
David S. Miller
336d3262 4e54064e

+20 -15
+14 -9
include/net/sctp/checksum.h
··· 46 46 #include <net/sctp/sctp.h> 47 47 #include <linux/crc32c.h> 48 48 49 - static inline __u32 sctp_start_cksum(__u8 *buffer, __u16 length) 49 + static inline __be32 sctp_crc32c(__be32 crc, u8 *buffer, u16 length) 50 50 { 51 - __u32 crc = ~(__u32) 0; 51 + return (__force __be32)crc32c((__force u32)crc, buffer, length); 52 + } 53 + 54 + static inline __be32 sctp_start_cksum(__u8 *buffer, __u16 length) 55 + { 56 + __be32 crc = ~cpu_to_be32(0); 52 57 __u8 zero[sizeof(__u32)] = {0}; 53 58 54 59 /* Optimize this routine to be SCTP specific, knowing how ··· 61 56 */ 62 57 63 58 /* Calculate CRC up to the checksum. */ 64 - crc = crc32c(crc, buffer, sizeof(struct sctphdr) - sizeof(__u32)); 59 + crc = sctp_crc32c(crc, buffer, sizeof(struct sctphdr) - sizeof(__u32)); 65 60 66 61 /* Skip checksum field of the header. */ 67 - crc = crc32c(crc, zero, sizeof(__u32)); 62 + crc = sctp_crc32c(crc, zero, sizeof(__u32)); 68 63 69 64 /* Calculate the rest of the CRC. */ 70 - crc = crc32c(crc, &buffer[sizeof(struct sctphdr)], 65 + crc = sctp_crc32c(crc, &buffer[sizeof(struct sctphdr)], 71 66 length - sizeof(struct sctphdr)); 72 67 return crc; 73 68 } 74 69 75 - static inline __u32 sctp_update_cksum(__u8 *buffer, __u16 length, __u32 crc32) 70 + static inline __be32 sctp_update_cksum(__u8 *buffer, __u16 length, __be32 crc32) 76 71 { 77 - return crc32c(crc32, buffer, length); 72 + return sctp_crc32c(crc32, buffer, length); 78 73 } 79 74 80 - static inline __u32 sctp_end_cksum(__u32 crc32) 75 + static inline __be32 sctp_end_cksum(__be32 crc32) 81 76 { 82 - return ntohl(~crc32); 77 + return ~crc32; 83 78 }
+2 -2
net/ipv4/netfilter/nf_nat_proto_sctp.c
··· 36 36 sctp_sctphdr_t *hdr; 37 37 unsigned int hdroff = iphdroff + iph->ihl*4; 38 38 __be32 oldip, newip; 39 - u32 crc32; 39 + __be32 crc32; 40 40 41 41 if (!skb_make_writable(skb, hdroff + sizeof(*hdr))) 42 42 return false; ··· 61 61 crc32 = sctp_update_cksum((u8 *)skb->data, skb_headlen(skb), 62 62 crc32); 63 63 crc32 = sctp_end_cksum(crc32); 64 - hdr->checksum = htonl(crc32); 64 + hdr->checksum = crc32; 65 65 66 66 return true; 67 67 }
+2 -2
net/sctp/input.c
··· 83 83 { 84 84 struct sk_buff *list = skb_shinfo(skb)->frag_list; 85 85 struct sctphdr *sh = sctp_hdr(skb); 86 - __u32 cmp = ntohl(sh->checksum); 87 - __u32 val = sctp_start_cksum((__u8 *)sh, skb_headlen(skb)); 86 + __be32 cmp = sh->checksum; 87 + __be32 val = sctp_start_cksum((__u8 *)sh, skb_headlen(skb)); 88 88 89 89 for (; list; list = list->next) 90 90 val = sctp_update_cksum((__u8 *)list->data, skb_headlen(list),
+2 -2
net/sctp/output.c
··· 365 365 struct sctp_transport *tp = packet->transport; 366 366 struct sctp_association *asoc = tp->asoc; 367 367 struct sctphdr *sh; 368 - __u32 crc32 = 0; 368 + __be32 crc32 = __constant_cpu_to_be32(0); 369 369 struct sk_buff *nskb; 370 370 struct sctp_chunk *chunk, *tmp; 371 371 struct sock *sk; ··· 538 538 /* 3) Put the resultant value into the checksum field in the 539 539 * common header, and leave the rest of the bits unchanged. 540 540 */ 541 - sh->checksum = htonl(crc32); 541 + sh->checksum = crc32; 542 542 543 543 /* IP layer ECN support 544 544 * From RFC 2481