diff options
author | Joe Stringer <joe@wand.net.nz> | 2013-07-24 21:52:05 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-07-27 23:07:15 -0400 |
commit | 024ec3deac33ddbd81f3c887506f132b24ea21a7 (patch) | |
tree | 32e21519a6180435415dc89628929d0e6ed56ecf /net/netfilter | |
parent | e7428e95a06fb516fac1308bd0e176e27c0b9287 (diff) |
net/sctp: Refactor SCTP skb checksum computation
This patch consolidates the SCTP checksum calculation code from various
places to a single new function, sctp_compute_cksum(skb, offset).
Signed-off-by: Joe Stringer <joe@wand.net.nz>
Reviewed-by: Julian Anastasov <ja@ssi.bg>
Acked-by: Simon Horman <horms@verge.net.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/ipvs/ip_vs_proto_sctp.c | 23 | ||||
-rw-r--r-- | net/netfilter/nf_nat_proto_sctp.c | 8 |
2 files changed, 4 insertions, 27 deletions
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c index 3c0da8728036..23e596e438b3 100644 --- a/net/netfilter/ipvs/ip_vs_proto_sctp.c +++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c | |||
@@ -66,15 +66,7 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, | |||
66 | static void sctp_nat_csum(struct sk_buff *skb, sctp_sctphdr_t *sctph, | 66 | static void sctp_nat_csum(struct sk_buff *skb, sctp_sctphdr_t *sctph, |
67 | unsigned int sctphoff) | 67 | unsigned int sctphoff) |
68 | { | 68 | { |
69 | __u32 crc32; | 69 | sctph->checksum = sctp_compute_cksum(skb, sctphoff); |
70 | struct sk_buff *iter; | ||
71 | |||
72 | crc32 = sctp_start_cksum((__u8 *)sctph, skb_headlen(skb) - sctphoff); | ||
73 | skb_walk_frags(skb, iter) | ||
74 | crc32 = sctp_update_cksum((u8 *) iter->data, | ||
75 | skb_headlen(iter), crc32); | ||
76 | sctph->checksum = sctp_end_cksum(crc32); | ||
77 | |||
78 | skb->ip_summed = CHECKSUM_UNNECESSARY; | 70 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
79 | } | 71 | } |
80 | 72 | ||
@@ -151,10 +143,7 @@ sctp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp) | |||
151 | { | 143 | { |
152 | unsigned int sctphoff; | 144 | unsigned int sctphoff; |
153 | struct sctphdr *sh, _sctph; | 145 | struct sctphdr *sh, _sctph; |
154 | struct sk_buff *iter; | 146 | __le32 cmp, val; |
155 | __le32 cmp; | ||
156 | __le32 val; | ||
157 | __u32 tmp; | ||
158 | 147 | ||
159 | #ifdef CONFIG_IP_VS_IPV6 | 148 | #ifdef CONFIG_IP_VS_IPV6 |
160 | if (af == AF_INET6) | 149 | if (af == AF_INET6) |
@@ -168,13 +157,7 @@ sctp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp) | |||
168 | return 0; | 157 | return 0; |
169 | 158 | ||
170 | cmp = sh->checksum; | 159 | cmp = sh->checksum; |
171 | 160 | val = sctp_compute_cksum(skb, sctphoff); | |
172 | tmp = sctp_start_cksum((__u8 *) sh, skb_headlen(skb)); | ||
173 | skb_walk_frags(skb, iter) | ||
174 | tmp = sctp_update_cksum((__u8 *) iter->data, | ||
175 | skb_headlen(iter), tmp); | ||
176 | |||
177 | val = sctp_end_cksum(tmp); | ||
178 | 161 | ||
179 | if (val != cmp) { | 162 | if (val != cmp) { |
180 | /* CRC failure, dump it. */ | 163 | /* CRC failure, dump it. */ |
diff --git a/net/netfilter/nf_nat_proto_sctp.c b/net/netfilter/nf_nat_proto_sctp.c index 396e55d46f90..754536f2c674 100644 --- a/net/netfilter/nf_nat_proto_sctp.c +++ b/net/netfilter/nf_nat_proto_sctp.c | |||
@@ -34,9 +34,7 @@ sctp_manip_pkt(struct sk_buff *skb, | |||
34 | const struct nf_conntrack_tuple *tuple, | 34 | const struct nf_conntrack_tuple *tuple, |
35 | enum nf_nat_manip_type maniptype) | 35 | enum nf_nat_manip_type maniptype) |
36 | { | 36 | { |
37 | struct sk_buff *frag; | ||
38 | sctp_sctphdr_t *hdr; | 37 | sctp_sctphdr_t *hdr; |
39 | __u32 crc32; | ||
40 | 38 | ||
41 | if (!skb_make_writable(skb, hdroff + sizeof(*hdr))) | 39 | if (!skb_make_writable(skb, hdroff + sizeof(*hdr))) |
42 | return false; | 40 | return false; |
@@ -51,11 +49,7 @@ sctp_manip_pkt(struct sk_buff *skb, | |||
51 | hdr->dest = tuple->dst.u.sctp.port; | 49 | hdr->dest = tuple->dst.u.sctp.port; |
52 | } | 50 | } |
53 | 51 | ||
54 | crc32 = sctp_start_cksum((u8 *)hdr, skb_headlen(skb) - hdroff); | 52 | hdr->checksum = sctp_compute_cksum(skb, hdroff); |
55 | skb_walk_frags(skb, frag) | ||
56 | crc32 = sctp_update_cksum((u8 *)frag->data, skb_headlen(frag), | ||
57 | crc32); | ||
58 | hdr->checksum = sctp_end_cksum(crc32); | ||
59 | 53 | ||
60 | return true; | 54 | return true; |
61 | } | 55 | } |