Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mpls: Fixups for GSO

As reported by Lennert the MPLS GSO code is failing to properly segment
large packets. There are a couple of problems:

1. the inner protocol is not set so the gso segment functions for inner
protocol layers are not getting run, and

2 MPLS labels for packets that use the "native" (non-OVS) MPLS code
are not properly accounted for in mpls_gso_segment.

The MPLS GSO code was added for OVS. It is re-using skb_mac_gso_segment
to call the gso segment functions for the higher layer protocols. That
means skb_mac_gso_segment is called twice -- once with the network
protocol set to MPLS and again with the network protocol set to the
inner protocol.

This patch sets the inner skb protocol addressing item 1 above and sets
the network_header and inner_network_header to mark where the MPLS labels
start and end. The MPLS code in OVS is also updated to set the two
network markers.

>From there the MPLS GSO code uses the difference between the network
header and the inner network header to know the size of the MPLS header
that was pushed. It then pulls the MPLS header, resets the mac_len and
protocol for the inner protocol and then calls skb_mac_gso_segment
to segment the skb.

Afterward the inner protocol segmentation is done the skb protocol
is set to mpls for each segment and the network and mac headers
restored.

Reported-by: Lennert Buytenhek <buytenh@wantstofly.org>
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

David Ahern and committed by
David S. Miller
48d2ab60 14972cbd

+40 -13
+29 -11
net/mpls/mpls_gso.c
··· 23 23 netdev_features_t features) 24 24 { 25 25 struct sk_buff *segs = ERR_PTR(-EINVAL); 26 + u16 mac_offset = skb->mac_header; 26 27 netdev_features_t mpls_features; 28 + u16 mac_len = skb->mac_len; 27 29 __be16 mpls_protocol; 30 + unsigned int mpls_hlen; 31 + 32 + skb_reset_network_header(skb); 33 + mpls_hlen = skb_inner_network_header(skb) - skb_network_header(skb); 34 + if (unlikely(!pskb_may_pull(skb, mpls_hlen))) 35 + goto out; 28 36 29 37 /* Setup inner SKB. */ 30 38 mpls_protocol = skb->protocol; 31 39 skb->protocol = skb->inner_protocol; 32 40 33 - /* Push back the mac header that skb_mac_gso_segment() has pulled. 34 - * It will be re-pulled by the call to skb_mac_gso_segment() below 35 - */ 36 - __skb_push(skb, skb->mac_len); 41 + __skb_pull(skb, mpls_hlen); 42 + 43 + skb->mac_len = 0; 44 + skb_reset_mac_header(skb); 37 45 38 46 /* Segment inner packet. */ 39 47 mpls_features = skb->dev->mpls_features & features; 40 48 segs = skb_mac_gso_segment(skb, mpls_features); 49 + if (IS_ERR_OR_NULL(segs)) { 50 + skb_gso_error_unwind(skb, mpls_protocol, mpls_hlen, mac_offset, 51 + mac_len); 52 + goto out; 53 + } 54 + skb = segs; 41 55 56 + mpls_hlen += mac_len; 57 + do { 58 + skb->mac_len = mac_len; 59 + skb->protocol = mpls_protocol; 42 60 43 - /* Restore outer protocol. */ 44 - skb->protocol = mpls_protocol; 61 + skb_reset_inner_network_header(skb); 45 62 46 - /* Re-pull the mac header that the call to skb_mac_gso_segment() 47 - * above pulled. It will be re-pushed after returning 48 - * skb_mac_gso_segment(), an indirect caller of this function. 49 - */ 50 - __skb_pull(skb, skb->data - skb_mac_header(skb)); 63 + __skb_push(skb, mpls_hlen); 51 64 65 + skb_reset_mac_header(skb); 66 + skb_set_network_header(skb, mac_len); 67 + } while ((skb = skb->next)); 68 + 69 + out: 52 70 return segs; 53 71 } 54 72
+4
net/mpls/mpls_iptunnel.c
··· 90 90 if (skb_cow(skb, hh_len + new_header_size)) 91 91 goto drop; 92 92 93 + skb_set_inner_protocol(skb, skb->protocol); 94 + skb_reset_inner_network_header(skb); 95 + 93 96 skb_push(skb, new_header_size); 97 + 94 98 skb_reset_network_header(skb); 95 99 96 100 skb->dev = out_dev;
+7 -2
net/openvswitch/actions.c
··· 162 162 if (skb_cow_head(skb, MPLS_HLEN) < 0) 163 163 return -ENOMEM; 164 164 165 + if (!skb->inner_protocol) { 166 + skb_set_inner_network_header(skb, skb->mac_len); 167 + skb_set_inner_protocol(skb, skb->protocol); 168 + } 169 + 165 170 skb_push(skb, MPLS_HLEN); 166 171 memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb), 167 172 skb->mac_len); 168 173 skb_reset_mac_header(skb); 174 + skb_set_network_header(skb, skb->mac_len); 169 175 170 176 new_mpls_lse = (__be32 *)skb_mpls_header(skb); 171 177 *new_mpls_lse = mpls->mpls_lse; ··· 179 173 skb_postpush_rcsum(skb, new_mpls_lse, MPLS_HLEN); 180 174 181 175 update_ethertype(skb, eth_hdr(skb), mpls->mpls_ethertype); 182 - if (!skb->inner_protocol) 183 - skb_set_inner_protocol(skb, skb->protocol); 184 176 skb->protocol = mpls->mpls_ethertype; 185 177 186 178 invalidate_flow_key(key); ··· 202 198 203 199 __skb_pull(skb, MPLS_HLEN); 204 200 skb_reset_mac_header(skb); 201 + skb_set_network_header(skb, skb->mac_len); 205 202 206 203 /* skb_mpls_header() is used to locate the ethertype 207 204 * field correctly in the presence of VLAN tags.