diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-02-05 11:21:31 -0500 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2013-02-05 19:56:50 -0500 |
commit | 4b47bc9a9e69141ed3a854c57601f548e82c78ba (patch) | |
tree | 3ba347682e08ac95194e7ec323157f6f164c630a /net/netfilter | |
parent | b425df4cdd953a400d814b4474c9d3ec04481858 (diff) |
ipvs: sctp: fix checksumming on snat and dnat handlers
In our test lab, we have a simple SCTP client connecting to a SCTP
server via an IPVS load balancer. On some machines, load balancing
works, but on others the initial handshake just fails, thus no
SCTP connection whatsoever can be established!
We observed that the SCTP INIT-ACK handshake reply from the IPVS
machine to the client had a correct IP checksum, but corrupt SCTP
checksum when forwarded, thus on the client-side the packet was
dropped and an intial handshake retriggered until all attempts
run into the void.
To fix this issue, this patch i) adds a missing CHECKSUM_UNNECESSARY
after the full checksum (re-)calculation (as done in IPVS TCP and UDP
code as well), ii) calculates the checksum in little-endian format
(as fixed with the SCTP code in commit 4458f04c: sctp: Clean up sctp
checksumming code) and iii) refactors duplicate checksum code into a
common function. Tested by myself.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/ipvs/ip_vs_proto_sctp.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c index 746048b13ef3..ae8ec6f27688 100644 --- a/net/netfilter/ipvs/ip_vs_proto_sctp.c +++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c | |||
@@ -61,14 +61,27 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, | |||
61 | return 1; | 61 | return 1; |
62 | } | 62 | } |
63 | 63 | ||
64 | static void sctp_nat_csum(struct sk_buff *skb, sctp_sctphdr_t *sctph, | ||
65 | unsigned int sctphoff) | ||
66 | { | ||
67 | __u32 crc32; | ||
68 | struct sk_buff *iter; | ||
69 | |||
70 | crc32 = sctp_start_cksum((__u8 *)sctph, skb_headlen(skb) - sctphoff); | ||
71 | skb_walk_frags(skb, iter) | ||
72 | crc32 = sctp_update_cksum((u8 *) iter->data, | ||
73 | skb_headlen(iter), crc32); | ||
74 | sctph->checksum = sctp_end_cksum(crc32); | ||
75 | |||
76 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
77 | } | ||
78 | |||
64 | static int | 79 | static int |
65 | sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, | 80 | sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, |
66 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph) | 81 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph) |
67 | { | 82 | { |
68 | sctp_sctphdr_t *sctph; | 83 | sctp_sctphdr_t *sctph; |
69 | unsigned int sctphoff = iph->len; | 84 | unsigned int sctphoff = iph->len; |
70 | struct sk_buff *iter; | ||
71 | __be32 crc32; | ||
72 | 85 | ||
73 | #ifdef CONFIG_IP_VS_IPV6 | 86 | #ifdef CONFIG_IP_VS_IPV6 |
74 | if (cp->af == AF_INET6 && iph->fragoffs) | 87 | if (cp->af == AF_INET6 && iph->fragoffs) |
@@ -92,13 +105,7 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, | |||
92 | sctph = (void *) skb_network_header(skb) + sctphoff; | 105 | sctph = (void *) skb_network_header(skb) + sctphoff; |
93 | sctph->source = cp->vport; | 106 | sctph->source = cp->vport; |
94 | 107 | ||
95 | /* Calculate the checksum */ | 108 | sctp_nat_csum(skb, sctph, sctphoff); |
96 | crc32 = sctp_start_cksum((u8 *) sctph, skb_headlen(skb) - sctphoff); | ||
97 | skb_walk_frags(skb, iter) | ||
98 | crc32 = sctp_update_cksum((u8 *) iter->data, skb_headlen(iter), | ||
99 | crc32); | ||
100 | crc32 = sctp_end_cksum(crc32); | ||
101 | sctph->checksum = crc32; | ||
102 | 109 | ||
103 | return 1; | 110 | return 1; |
104 | } | 111 | } |
@@ -109,8 +116,6 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, | |||
109 | { | 116 | { |
110 | sctp_sctphdr_t *sctph; | 117 | sctp_sctphdr_t *sctph; |
111 | unsigned int sctphoff = iph->len; | 118 | unsigned int sctphoff = iph->len; |
112 | struct sk_buff *iter; | ||
113 | __be32 crc32; | ||
114 | 119 | ||
115 | #ifdef CONFIG_IP_VS_IPV6 | 120 | #ifdef CONFIG_IP_VS_IPV6 |
116 | if (cp->af == AF_INET6 && iph->fragoffs) | 121 | if (cp->af == AF_INET6 && iph->fragoffs) |
@@ -134,13 +139,7 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, | |||
134 | sctph = (void *) skb_network_header(skb) + sctphoff; | 139 | sctph = (void *) skb_network_header(skb) + sctphoff; |
135 | sctph->dest = cp->dport; | 140 | sctph->dest = cp->dport; |
136 | 141 | ||
137 | /* Calculate the checksum */ | 142 | sctp_nat_csum(skb, sctph, sctphoff); |
138 | crc32 = sctp_start_cksum((u8 *) sctph, skb_headlen(skb) - sctphoff); | ||
139 | skb_walk_frags(skb, iter) | ||
140 | crc32 = sctp_update_cksum((u8 *) iter->data, skb_headlen(iter), | ||
141 | crc32); | ||
142 | crc32 = sctp_end_cksum(crc32); | ||
143 | sctph->checksum = crc32; | ||
144 | 143 | ||
145 | return 1; | 144 | return 1; |
146 | } | 145 | } |