mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 09:19:51 +00:00
udp: Use uh->len instead of skb->len to compute checksum in segmentation
The segmentation code was having to do a bunch of work to pull the skb->len and strip the udp header offset before the value could be used to adjust the checksum. Instead of doing all this work we can just use the value that goes into uh->len since that is the correct value with the correct byte order that we need anyway. By using this value we can save ourselves a bunch of pain as there is no need to do multiple byte swaps. Signed-off-by: Alexander Duyck <aduyck@mirantis.com> Acked-by: Tom Herbert <tom@herbertland.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
fdaefd62fd
commit
dbef491ebe
1 changed files with 13 additions and 15 deletions
|
@ -32,20 +32,23 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
|
||||||
netdev_features_t features),
|
netdev_features_t features),
|
||||||
__be16 new_protocol, bool is_ipv6)
|
__be16 new_protocol, bool is_ipv6)
|
||||||
{
|
{
|
||||||
|
int tnl_hlen = skb_inner_mac_header(skb) - skb_transport_header(skb);
|
||||||
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
||||||
bool remcsum, need_csum, offload_csum;
|
bool remcsum, need_csum, offload_csum;
|
||||||
|
struct udphdr *uh = udp_hdr(skb);
|
||||||
u16 mac_offset = skb->mac_header;
|
u16 mac_offset = skb->mac_header;
|
||||||
int mac_len = skb->mac_len;
|
|
||||||
int tnl_hlen = skb_inner_mac_header(skb) - skb_transport_header(skb);
|
|
||||||
__be16 protocol = skb->protocol;
|
__be16 protocol = skb->protocol;
|
||||||
|
u16 mac_len = skb->mac_len;
|
||||||
int udp_offset, outer_hlen;
|
int udp_offset, outer_hlen;
|
||||||
unsigned int oldlen;
|
u32 partial;
|
||||||
|
|
||||||
oldlen = (u16)~skb->len;
|
|
||||||
|
|
||||||
if (unlikely(!pskb_may_pull(skb, tnl_hlen)))
|
if (unlikely(!pskb_may_pull(skb, tnl_hlen)))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
/* adjust partial header checksum to negate old length */
|
||||||
|
partial = (__force u32)uh->check + (__force u16)~uh->len;
|
||||||
|
|
||||||
|
/* setup inner skb. */
|
||||||
skb->encapsulation = 0;
|
skb->encapsulation = 0;
|
||||||
__skb_pull(skb, tnl_hlen);
|
__skb_pull(skb, tnl_hlen);
|
||||||
skb_reset_mac_header(skb);
|
skb_reset_mac_header(skb);
|
||||||
|
@ -89,9 +92,7 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
|
||||||
udp_offset = outer_hlen - tnl_hlen;
|
udp_offset = outer_hlen - tnl_hlen;
|
||||||
skb = segs;
|
skb = segs;
|
||||||
do {
|
do {
|
||||||
struct udphdr *uh;
|
__be16 len;
|
||||||
int len;
|
|
||||||
__be32 delta;
|
|
||||||
|
|
||||||
if (remcsum)
|
if (remcsum)
|
||||||
skb->ip_summed = CHECKSUM_NONE;
|
skb->ip_summed = CHECKSUM_NONE;
|
||||||
|
@ -105,22 +106,19 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
|
||||||
skb->mac_len = mac_len;
|
skb->mac_len = mac_len;
|
||||||
skb->protocol = protocol;
|
skb->protocol = protocol;
|
||||||
|
|
||||||
skb_push(skb, outer_hlen);
|
__skb_push(skb, outer_hlen);
|
||||||
skb_reset_mac_header(skb);
|
skb_reset_mac_header(skb);
|
||||||
skb_set_network_header(skb, mac_len);
|
skb_set_network_header(skb, mac_len);
|
||||||
skb_set_transport_header(skb, udp_offset);
|
skb_set_transport_header(skb, udp_offset);
|
||||||
len = skb->len - udp_offset;
|
len = htons(skb->len - udp_offset);
|
||||||
uh = udp_hdr(skb);
|
uh = udp_hdr(skb);
|
||||||
uh->len = htons(len);
|
uh->len = len;
|
||||||
|
|
||||||
if (!need_csum)
|
if (!need_csum)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
delta = htonl(oldlen + len);
|
|
||||||
|
|
||||||
uh->check = ~csum_fold((__force __wsum)
|
uh->check = ~csum_fold((__force __wsum)
|
||||||
((__force u32)uh->check +
|
((__force u32)len + partial));
|
||||||
(__force u32)delta));
|
|
||||||
|
|
||||||
if (skb->encapsulation || !offload_csum) {
|
if (skb->encapsulation || !offload_csum) {
|
||||||
uh->check = gso_make_checksum(skb, ~uh->check);
|
uh->check = gso_make_checksum(skb, ~uh->check);
|
||||||
|
|
Loading…
Reference in a new issue