Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 419f9f89 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller
Browse files

tcp: Handle CHECKSUM_PARTIAL for SYNACK packets for IPv4



tcp: Handle CHECKSUM_PARTIAL for SYNACK packets for IPv4

This patch moves the common code between tcp_v4_send_check and
tcp_v4_gso_send_check into a new function __tcp_v4_send_check.

It then uses the new function in tcp_v4_send_synack so that it
handles 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 871039f0
Loading
Loading
Loading
Loading
+14 −17
Original line number Original line Diff line number Diff line
@@ -519,26 +519,31 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
	sock_put(sk);
	sock_put(sk);
}
}


/* This routine computes an IPv4 TCP checksum. */
static void __tcp_v4_send_check(struct sk_buff *skb,
void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
				__be32 saddr, __be32 daddr)
{
{
	struct inet_sock *inet = inet_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 = ~tcp_v4_check(len, inet->inet_saddr,
		th->check = ~tcp_v4_check(skb->len, saddr, daddr, 0);
					  inet->inet_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 = tcp_v4_check(len, inet->inet_saddr,
		th->check = tcp_v4_check(skb->len, saddr, daddr,
					 inet->inet_daddr,
					 csum_partial(th,
					 csum_partial(th,
						      th->doff << 2,
						      th->doff << 2,
						      skb->csum));
						      skb->csum));
	}
	}
}
}


/* This routine computes an IPv4 TCP checksum. */
void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
{
	struct inet_sock *inet = inet_sk(sk);

	__tcp_v4_send_check(skb, inet->inet_saddr, inet->inet_daddr);
}

int tcp_v4_gso_send_check(struct sk_buff *skb)
int tcp_v4_gso_send_check(struct sk_buff *skb)
{
{
	const struct iphdr *iph;
	const struct iphdr *iph;
@@ -551,10 +556,8 @@ int tcp_v4_gso_send_check(struct sk_buff *skb)
	th = tcp_hdr(skb);
	th = tcp_hdr(skb);


	th->check = 0;
	th->check = 0;
	th->check = ~tcp_v4_check(skb->len, iph->saddr, iph->daddr, 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_v4_send_check(skb, iph->saddr, iph->daddr);
	return 0;
	return 0;
}
}


@@ -763,13 +766,7 @@ static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst,
	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_v4_send_check(skb, ireq->loc_addr, ireq->rmt_addr);

		th->check = tcp_v4_check(skb->len,
					 ireq->loc_addr,
					 ireq->rmt_addr,
					 csum_partial(th, skb->len,
						      skb->csum));


		err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr,
		err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr,
					    ireq->rmt_addr,
					    ireq->rmt_addr,