]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
sctp: remove unnecessary byteshifting, calculate directly in big-endian
authorHarvey Harrison <harvey.harrison@gmail.com>
Sat, 19 Jul 2008 06:07:09 +0000 (23:07 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 19 Jul 2008 06:07:09 +0000 (23:07 -0700)
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>
include/net/sctp/checksum.h
net/ipv4/netfilter/nf_nat_proto_sctp.c
net/sctp/input.c
net/sctp/output.c

index ba75c67cb992da5b56b97c67dee427c6e26d3f87..b799fb21519aafd4331f52c55b09d7484ec62265 100644 (file)
 #include <net/sctp/sctp.h>
 #include <linux/crc32c.h>
 
-static inline __u32 sctp_start_cksum(__u8 *buffer, __u16 length)
+static inline __be32 sctp_crc32c(__be32 crc, u8 *buffer, u16 length)
 {
-       __u32 crc = ~(__u32) 0;
+       return (__force __be32)crc32c((__force u32)crc, buffer, length);
+}
+
+static inline __be32 sctp_start_cksum(__u8 *buffer, __u16 length)
+{
+       __be32 crc = ~cpu_to_be32(0);
        __u8  zero[sizeof(__u32)] = {0};
 
        /* Optimize this routine to be SCTP specific, knowing how
@@ -56,23 +61,23 @@ static inline __u32 sctp_start_cksum(__u8 *buffer, __u16 length)
         */
 
        /* Calculate CRC up to the checksum. */
-       crc = crc32c(crc, buffer, sizeof(struct sctphdr) - sizeof(__u32));
+       crc = sctp_crc32c(crc, buffer, sizeof(struct sctphdr) - sizeof(__u32));
 
        /* Skip checksum field of the header. */
-       crc = crc32c(crc, zero, sizeof(__u32));
+       crc = sctp_crc32c(crc, zero, sizeof(__u32));
 
        /* Calculate the rest of the CRC. */
-       crc = crc32c(crc, &buffer[sizeof(struct sctphdr)],
+       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)
+static inline __be32 sctp_update_cksum(__u8 *buffer, __u16 length, __be32 crc32)
 {
-       return crc32c(crc32, buffer, length);
+       return sctp_crc32c(crc32, buffer, length);
 }
 
-static inline __u32 sctp_end_cksum(__u32 crc32)
+static inline __be32 sctp_end_cksum(__be32 crc32)
 {
-       return ntohl(~crc32);
+       return ~crc32;
 }
index 82e4c0e286b870be0a3e23be1514f2e9576fe8cf..65e470bc6123dfcabf0956b8542ffa043f36980c 100644 (file)
@@ -36,7 +36,7 @@ sctp_manip_pkt(struct sk_buff *skb,
        sctp_sctphdr_t *hdr;
        unsigned int hdroff = iphdroff + iph->ihl*4;
        __be32 oldip, newip;
-       u32 crc32;
+       __be32 crc32;
 
        if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
                return false;
@@ -61,7 +61,7 @@ sctp_manip_pkt(struct sk_buff *skb,
                crc32 = sctp_update_cksum((u8 *)skb->data, skb_headlen(skb),
                                          crc32);
        crc32 = sctp_end_cksum(crc32);
-       hdr->checksum = htonl(crc32);
+       hdr->checksum = crc32;
 
        return true;
 }
index 5ed93c05c23ef245e12491c1ab9aa489b83b45d1..a49fa80b57b96ff2047d53d13c3a8ad134ecffbe 100644 (file)
@@ -83,8 +83,8 @@ static inline int sctp_rcv_checksum(struct sk_buff *skb)
 {
        struct sk_buff *list = skb_shinfo(skb)->frag_list;
        struct sctphdr *sh = sctp_hdr(skb);
-       __u32 cmp = ntohl(sh->checksum);
-       __u32 val = sctp_start_cksum((__u8 *)sh, skb_headlen(skb));
+       __be32 cmp = sh->checksum;
+       __be32 val = sctp_start_cksum((__u8 *)sh, skb_headlen(skb));
 
        for (; list; list = list->next)
                val = sctp_update_cksum((__u8 *)list->data, skb_headlen(list),
index 9a63a3fb90113331992a8a36a78eade8026e1e60..45684646b1dba32a9e1c565713adc527c84095c3 100644 (file)
@@ -365,7 +365,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
        struct sctp_transport *tp = packet->transport;
        struct sctp_association *asoc = tp->asoc;
        struct sctphdr *sh;
-       __u32 crc32 = 0;
+       __be32 crc32 = __constant_cpu_to_be32(0);
        struct sk_buff *nskb;
        struct sctp_chunk *chunk, *tmp;
        struct sock *sk;
@@ -538,7 +538,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
        /* 3) Put the resultant value into the checksum field in the
         *    common header, and leave the rest of the bits unchanged.
         */
-       sh->checksum = htonl(crc32);
+       sh->checksum = crc32;
 
        /* IP layer ECN support
         * From RFC 2481