Commit 8ad50d96 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

tcp: Handle CHECKSUM_PARTIAL for SYNACK packets for IPv6

tcp: Handle CHECKSUM_PARTIAL for SYNACK packets for IPv6

This patch moves the common code between tcp_v6_send_check and
tcp_v6_gso_send_check into a new function __tcp_v6_send_check.

It then uses the new function in tcp_v6_send_synack as well as
tcp_v6_send_response so that they handle CHECKSUM_PARTIAL properly.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Tested-by: default avatarYinghai <yinghai.lu@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 419f9f89
...@@ -75,6 +75,9 @@ static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb, ...@@ -75,6 +75,9 @@ static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
struct request_sock *req); struct request_sock *req);
static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb); static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb);
static void __tcp_v6_send_check(struct sk_buff *skb,
struct in6_addr *saddr,
struct in6_addr *daddr);
static const struct inet_connection_sock_af_ops ipv6_mapped; static const struct inet_connection_sock_af_ops ipv6_mapped;
static const struct inet_connection_sock_af_ops ipv6_specific; static const struct inet_connection_sock_af_ops ipv6_specific;
...@@ -503,11 +506,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req, ...@@ -503,11 +506,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req,
skb = tcp_make_synack(sk, dst, req, rvp); skb = tcp_make_synack(sk, dst, req, rvp);
if (skb) { if (skb) {
struct tcphdr *th = tcp_hdr(skb); __tcp_v6_send_check(skb, &treq->loc_addr, &treq->rmt_addr);
th->check = tcp_v6_check(skb->len,
&treq->loc_addr, &treq->rmt_addr,
csum_partial(th, skb->len, skb->csum));
ipv6_addr_copy(&fl.fl6_dst, &treq->rmt_addr); ipv6_addr_copy(&fl.fl6_dst, &treq->rmt_addr);
err = ip6_xmit(sk, skb, &fl, opt, 0); err = ip6_xmit(sk, skb, &fl, opt, 0);
...@@ -918,22 +917,29 @@ static struct timewait_sock_ops tcp6_timewait_sock_ops = { ...@@ -918,22 +917,29 @@ static struct timewait_sock_ops tcp6_timewait_sock_ops = {
.twsk_destructor= tcp_twsk_destructor, .twsk_destructor= tcp_twsk_destructor,
}; };
static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb) static void __tcp_v6_send_check(struct sk_buff *skb,
struct in6_addr *saddr, struct in6_addr *daddr)
{ {
struct ipv6_pinfo *np = inet6_sk(sk);
struct tcphdr *th = tcp_hdr(skb); struct tcphdr *th = tcp_hdr(skb);
if (skb->ip_summed == CHECKSUM_PARTIAL) { if (skb->ip_summed == CHECKSUM_PARTIAL) {
th->check = ~csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, 0); th->check = ~tcp_v6_check(skb->len, saddr, daddr, 0);
skb->csum_start = skb_transport_header(skb) - skb->head; skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = offsetof(struct tcphdr, check); skb->csum_offset = offsetof(struct tcphdr, check);
} else { } else {
th->check = csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, th->check = tcp_v6_check(skb->len, saddr, daddr,
csum_partial(th, th->doff<<2, csum_partial(th, th->doff << 2,
skb->csum)); skb->csum));
} }
} }
static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb)
{
struct ipv6_pinfo *np = inet6_sk(sk);
__tcp_v6_send_check(skb, &np->saddr, &np->daddr);
}
static int tcp_v6_gso_send_check(struct sk_buff *skb) static int tcp_v6_gso_send_check(struct sk_buff *skb)
{ {
struct ipv6hdr *ipv6h; struct ipv6hdr *ipv6h;
...@@ -946,11 +952,8 @@ static int tcp_v6_gso_send_check(struct sk_buff *skb) ...@@ -946,11 +952,8 @@ static int tcp_v6_gso_send_check(struct sk_buff *skb)
th = tcp_hdr(skb); th = tcp_hdr(skb);
th->check = 0; th->check = 0;
th->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len,
IPPROTO_TCP, 0);
skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = offsetof(struct tcphdr, check);
skb->ip_summed = CHECKSUM_PARTIAL; skb->ip_summed = CHECKSUM_PARTIAL;
__tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr);
return 0; return 0;
} }
...@@ -1053,9 +1056,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win, ...@@ -1053,9 +1056,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,
ipv6_addr_copy(&fl.fl6_dst, &ipv6_hdr(skb)->saddr); ipv6_addr_copy(&fl.fl6_dst, &ipv6_hdr(skb)->saddr);
ipv6_addr_copy(&fl.fl6_src, &ipv6_hdr(skb)->daddr); ipv6_addr_copy(&fl.fl6_src, &ipv6_hdr(skb)->daddr);
t1->check = csum_ipv6_magic(&fl.fl6_src, &fl.fl6_dst, __tcp_v6_send_check(buff, &fl.fl6_src, &fl.fl6_dst);
tot_len, IPPROTO_TCP,
buff->csum);
fl.proto = IPPROTO_TCP; fl.proto = IPPROTO_TCP;
fl.oif = inet6_iif(skb); fl.oif = inet6_iif(skb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment