提交 663ead3b 编写于 作者: H Herbert Xu 提交者: David S. Miller

[NET]: Use csum_start offset instead of skb_transport_header

The skb transport pointer is currently used to specify the start
of the checksum region for transmit checksum offload.  Unfortunately,
the same pointer is also used during receive side processing.

This creates a problem when we want to retransmit a received
packet with partial checksums since the skb transport pointer
would be overwritten.

This patch solves this problem by creating a new 16-bit csum_start
offset value to replace the skb transport header for the purpose
of checksums.  This offset is calculated from skb->head so that
it does not have to change when skb->data changes.

No extra space is required since csum_offset itself fits within
a 16-bit word so we can use the other 16 bits for csum_start.

For backwards compatibility, just before we push a packet with
partial checksums off into the device driver, we set the skb
transport header to what it would have been under the old scheme.
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 ac758e3c
...@@ -205,7 +205,9 @@ typedef unsigned char *sk_buff_data_t; ...@@ -205,7 +205,9 @@ typedef unsigned char *sk_buff_data_t;
* @len: Length of actual data * @len: Length of actual data
* @data_len: Data length * @data_len: Data length
* @mac_len: Length of link layer header * @mac_len: Length of link layer header
* @csum: Checksum * @csum: Checksum (must include start/offset pair)
* @csum_start: Offset from skb->head where checksumming should start
* @csum_offset: Offset from csum_start where checksum should be stored
* @local_df: allow local fragmentation * @local_df: allow local fragmentation
* @cloned: Head may be cloned (check refcnt to be sure) * @cloned: Head may be cloned (check refcnt to be sure)
* @nohdr: Payload reference only, must not modify header * @nohdr: Payload reference only, must not modify header
...@@ -261,7 +263,10 @@ struct sk_buff { ...@@ -261,7 +263,10 @@ struct sk_buff {
mac_len; mac_len;
union { union {
__wsum csum; __wsum csum;
__u32 csum_offset; struct {
__u16 csum_start;
__u16 csum_offset;
};
}; };
__u32 priority; __u32 priority;
__u8 local_df:1, __u8 local_df:1,
......
...@@ -1155,7 +1155,7 @@ EXPORT_SYMBOL(netif_device_attach); ...@@ -1155,7 +1155,7 @@ EXPORT_SYMBOL(netif_device_attach);
int skb_checksum_help(struct sk_buff *skb) int skb_checksum_help(struct sk_buff *skb)
{ {
__wsum csum; __wsum csum;
int ret = 0, offset = skb_transport_offset(skb); int ret = 0, offset;
if (skb->ip_summed == CHECKSUM_COMPLETE) if (skb->ip_summed == CHECKSUM_COMPLETE)
goto out_set_summed; goto out_set_summed;
...@@ -1171,15 +1171,16 @@ int skb_checksum_help(struct sk_buff *skb) ...@@ -1171,15 +1171,16 @@ int skb_checksum_help(struct sk_buff *skb)
goto out; goto out;
} }
offset = skb->csum_start - skb_headroom(skb);
BUG_ON(offset > (int)skb->len); BUG_ON(offset > (int)skb->len);
csum = skb_checksum(skb, offset, skb->len-offset, 0); csum = skb_checksum(skb, offset, skb->len-offset, 0);
offset = skb->tail - skb->transport_header; offset = skb_headlen(skb) - offset;
BUG_ON(offset <= 0); BUG_ON(offset <= 0);
BUG_ON(skb->csum_offset + 2 > offset); BUG_ON(skb->csum_offset + 2 > offset);
*(__sum16 *)(skb_transport_header(skb) + *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) =
skb->csum_offset) = csum_fold(csum); csum_fold(csum);
out_set_summed: out_set_summed:
skb->ip_summed = CHECKSUM_NONE; skb->ip_summed = CHECKSUM_NONE;
out: out:
...@@ -1431,12 +1432,16 @@ int dev_queue_xmit(struct sk_buff *skb) ...@@ -1431,12 +1432,16 @@ int dev_queue_xmit(struct sk_buff *skb)
/* If packet is not checksummed and device does not support /* If packet is not checksummed and device does not support
* checksumming for this protocol, complete checksumming here. * checksumming for this protocol, complete checksumming here.
*/ */
if (skb->ip_summed == CHECKSUM_PARTIAL && if (skb->ip_summed == CHECKSUM_PARTIAL) {
(!(dev->features & NETIF_F_GEN_CSUM) && skb_set_transport_header(skb, skb->csum_start -
(!(dev->features & NETIF_F_IP_CSUM) || skb_headroom(skb));
skb->protocol != htons(ETH_P_IP))))
if (skb_checksum_help(skb)) if (!(dev->features & NETIF_F_GEN_CSUM) &&
goto out_kfree_skb; (!(dev->features & NETIF_F_IP_CSUM) ||
skb->protocol != htons(ETH_P_IP)))
if (skb_checksum_help(skb))
goto out_kfree_skb;
}
gso: gso:
spin_lock_prefetch(&dev->queue_lock); spin_lock_prefetch(&dev->queue_lock);
......
...@@ -1358,7 +1358,7 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to) ...@@ -1358,7 +1358,7 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)
long csstart; long csstart;
if (skb->ip_summed == CHECKSUM_PARTIAL) if (skb->ip_summed == CHECKSUM_PARTIAL)
csstart = skb_transport_offset(skb); csstart = skb->csum_start - skb_headroom(skb);
else else
csstart = skb_headlen(skb); csstart = skb_headlen(skb);
......
...@@ -504,6 +504,7 @@ void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb) ...@@ -504,6 +504,7 @@ void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
if (skb->ip_summed == CHECKSUM_PARTIAL) { if (skb->ip_summed == CHECKSUM_PARTIAL) {
th->check = ~tcp_v4_check(len, inet->saddr, th->check = ~tcp_v4_check(len, inet->saddr,
inet->daddr, 0); inet->daddr, 0);
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->saddr, inet->daddr, th->check = tcp_v4_check(len, inet->saddr, inet->daddr,
...@@ -526,6 +527,7 @@ int tcp_v4_gso_send_check(struct sk_buff *skb) ...@@ -526,6 +527,7 @@ int tcp_v4_gso_send_check(struct sk_buff *skb)
th->check = 0; th->check = 0;
th->check = ~tcp_v4_check(skb->len, iph->saddr, iph->daddr, 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->csum_offset = offsetof(struct tcphdr, check);
skb->ip_summed = CHECKSUM_PARTIAL; skb->ip_summed = CHECKSUM_PARTIAL;
return 0; return 0;
......
...@@ -427,6 +427,7 @@ static void udp4_hwcsum_outgoing(struct sock *sk, struct sk_buff *skb, ...@@ -427,6 +427,7 @@ static void udp4_hwcsum_outgoing(struct sock *sk, struct sk_buff *skb,
/* /*
* Only one fragment on the socket. * Only one fragment on the socket.
*/ */
skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = offsetof(struct udphdr, check); skb->csum_offset = offsetof(struct udphdr, check);
uh->check = ~csum_tcpudp_magic(src, dst, len, IPPROTO_UDP, 0); uh->check = ~csum_tcpudp_magic(src, dst, len, IPPROTO_UDP, 0);
} else { } else {
......
...@@ -950,6 +950,7 @@ static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb) ...@@ -950,6 +950,7 @@ static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *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 = ~csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, 0);
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 = csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP,
...@@ -972,6 +973,7 @@ static int tcp_v6_gso_send_check(struct sk_buff *skb) ...@@ -972,6 +973,7 @@ static int tcp_v6_gso_send_check(struct sk_buff *skb)
th->check = 0; th->check = 0;
th->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len, th->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len,
IPPROTO_TCP, 0); IPPROTO_TCP, 0);
skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = offsetof(struct tcphdr, check); skb->csum_offset = offsetof(struct tcphdr, check);
skb->ip_summed = CHECKSUM_PARTIAL; skb->ip_summed = CHECKSUM_PARTIAL;
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册