Skip to content

Commit 48d2ab6

Browse files
David Aherndavem330
authored andcommitted
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>
1 parent 14972cb commit 48d2ab6

3 files changed

Lines changed: 40 additions & 13 deletions

File tree

‎net/mpls/mpls_gso.c‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,50 @@ static struct sk_buff *mpls_gso_segment(struct sk_buff *skb,
2323
netdev_features_t features)
2424
{
2525
struct sk_buff *segs = ERR_PTR(-EINVAL);
26+
u16 mac_offset = skb->mac_header;
2627
netdev_features_t mpls_features;
28+
u16 mac_len = skb->mac_len;
2729
__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;
2836

2937
/* Setup inner SKB. */
3038
mpls_protocol = skb->protocol;
3139
skb->protocol = skb->inner_protocol;
3240

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);
3745

3846
/* Segment inner packet. */
3947
mpls_features = skb->dev->mpls_features & features;
4048
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;
55+
56+
mpls_hlen += mac_len;
57+
do {
58+
skb->mac_len = mac_len;
59+
skb->protocol = mpls_protocol;
4160

61+
skb_reset_inner_network_header(skb);
4262

43-
/* Restore outer protocol. */
44-
skb->protocol = mpls_protocol;
63+
__skb_push(skb, mpls_hlen);
4564

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));
65+
skb_reset_mac_header(skb);
66+
skb_set_network_header(skb, mac_len);
67+
} while ((skb = skb->next));
5168

69+
out:
5270
return segs;
5371
}
5472

‎net/mpls/mpls_iptunnel.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ static int mpls_xmit(struct sk_buff *skb)
9090
if (skb_cow(skb, hh_len + new_header_size))
9191
goto drop;
9292

93+
skb_set_inner_protocol(skb, skb->protocol);
94+
skb_reset_inner_network_header(skb);
95+
9396
skb_push(skb, new_header_size);
97+
9498
skb_reset_network_header(skb);
9599

96100
skb->dev = out_dev;

‎net/openvswitch/actions.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,23 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
162162
if (skb_cow_head(skb, MPLS_HLEN) < 0)
163163
return -ENOMEM;
164164

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+
165170
skb_push(skb, MPLS_HLEN);
166171
memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb),
167172
skb->mac_len);
168173
skb_reset_mac_header(skb);
174+
skb_set_network_header(skb, skb->mac_len);
169175

170176
new_mpls_lse = (__be32 *)skb_mpls_header(skb);
171177
*new_mpls_lse = mpls->mpls_lse;
172178

173179
skb_postpush_rcsum(skb, new_mpls_lse, MPLS_HLEN);
174180

175181
update_ethertype(skb, eth_hdr(skb), mpls->mpls_ethertype);
176-
if (!skb->inner_protocol)
177-
skb_set_inner_protocol(skb, skb->protocol);
178182
skb->protocol = mpls->mpls_ethertype;
179183

180184
invalidate_flow_key(key);
@@ -198,6 +202,7 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
198202

199203
__skb_pull(skb, MPLS_HLEN);
200204
skb_reset_mac_header(skb);
205+
skb_set_network_header(skb, skb->mac_len);
201206

202207
/* skb_mpls_header() is used to locate the ethertype
203208
* field correctly in the presence of VLAN tags.

0 commit comments

Comments
 (0)