Skip to content

Commit e586427

Browse files
vladimirolteangregkh
authored andcommitted
net: dsa: tag_8021q: replace dsa_8021q_remove_header with __skb_vlan_pop
[ Upstream commit e80f40c ] Not only did this wheel did not need reinventing, but there is also an issue with it: It doesn't remove the VLAN header in a way that preserves the L2 payload checksum when that is being provided by the DSA master hw. It should recalculate checksum both for the push, before removing the header, and for the pull afterwards. But the current implementation is quite dizzying, with pulls followed immediately afterwards by pushes, the memmove is done before the push, etc. This makes a DSA master with RX checksumming offload to print stack traces with the infamous 'hw csum failure' message. So remove the dsa_8021q_remove_header function and replace it with something that actually works with inet checksumming. Fixes: d461933 ("net: dsa: tag_8021q: Create helper function for removing VLAN header") Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0ec037c commit e586427

3 files changed

Lines changed: 9 additions & 60 deletions

File tree

‎include/linux/dsa/8021q.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ int dsa_8021q_rx_switch_id(u16 vid);
2828

2929
int dsa_8021q_rx_source_port(u16 vid);
3030

31-
struct sk_buff *dsa_8021q_remove_header(struct sk_buff *skb);
32-
3331
#else
3432

3533
int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int index,
@@ -64,11 +62,6 @@ int dsa_8021q_rx_source_port(u16 vid)
6462
return 0;
6563
}
6664

67-
struct sk_buff *dsa_8021q_remove_header(struct sk_buff *skb)
68-
{
69-
return NULL;
70-
}
71-
7265
#endif /* IS_ENABLED(CONFIG_NET_DSA_TAG_8021Q) */
7366

7467
#endif /* _NET_DSA_8021Q_H */

‎net/dsa/tag_8021q.c‎

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -299,49 +299,6 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
299299
}
300300
EXPORT_SYMBOL_GPL(dsa_8021q_xmit);
301301

302-
/* In the DSA packet_type handler, skb->data points in the middle of the VLAN
303-
* tag, after tpid and before tci. This is because so far, ETH_HLEN
304-
* (DMAC, SMAC, EtherType) bytes were pulled.
305-
* There are 2 bytes of VLAN tag left in skb->data, and upper
306-
* layers expect the 'real' EtherType to be consumed as well.
307-
* Coincidentally, a VLAN header is also of the same size as
308-
* the number of bytes that need to be pulled.
309-
*
310-
* skb_mac_header skb->data
311-
* | |
312-
* v v
313-
* | | | | | | | | | | | | | | | | | | |
314-
* +-----------------------+-----------------------+-------+-------+-------+
315-
* | Destination MAC | Source MAC | TPID | TCI | EType |
316-
* +-----------------------+-----------------------+-------+-------+-------+
317-
* ^ | |
318-
* |<--VLAN_HLEN-->to <---VLAN_HLEN--->
319-
* from |
320-
* >>>>>>> v
321-
* >>>>>>> | | | | | | | | | | | | | | |
322-
* >>>>>>> +-----------------------+-----------------------+-------+
323-
* >>>>>>> | Destination MAC | Source MAC | EType |
324-
* +-----------------------+-----------------------+-------+
325-
* ^ ^
326-
* (now part of | |
327-
* skb->head) skb_mac_header skb->data
328-
*/
329-
struct sk_buff *dsa_8021q_remove_header(struct sk_buff *skb)
330-
{
331-
u8 *from = skb_mac_header(skb);
332-
u8 *dest = from + VLAN_HLEN;
333-
334-
memmove(dest, from, ETH_HLEN - VLAN_HLEN);
335-
skb_pull(skb, VLAN_HLEN);
336-
skb_push(skb, ETH_HLEN);
337-
skb_reset_mac_header(skb);
338-
skb_reset_mac_len(skb);
339-
skb_pull_rcsum(skb, ETH_HLEN);
340-
341-
return skb;
342-
}
343-
EXPORT_SYMBOL_GPL(dsa_8021q_remove_header);
344-
345302
static const struct dsa_device_ops dsa_8021q_netdev_ops = {
346303
.name = "8021q",
347304
.proto = DSA_TAG_PROTO_8021Q,

‎net/dsa/tag_sja1105.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
238238
{
239239
struct sja1105_meta meta = {0};
240240
int source_port, switch_id;
241-
struct vlan_ethhdr *hdr;
241+
struct ethhdr *hdr;
242242
u16 tpid, vid, tci;
243243
bool is_link_local;
244244
bool is_tagged;
245245
bool is_meta;
246246

247-
hdr = vlan_eth_hdr(skb);
248-
tpid = ntohs(hdr->h_vlan_proto);
247+
hdr = eth_hdr(skb);
248+
tpid = ntohs(hdr->h_proto);
249249
is_tagged = (tpid == ETH_P_SJA1105);
250250
is_link_local = sja1105_is_link_local(skb);
251251
is_meta = sja1105_is_meta_frame(skb);
@@ -254,7 +254,12 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
254254

255255
if (is_tagged) {
256256
/* Normal traffic path. */
257-
tci = ntohs(hdr->h_vlan_TCI);
257+
skb_push_rcsum(skb, ETH_HLEN);
258+
__skb_vlan_pop(skb, &tci);
259+
skb_pull_rcsum(skb, ETH_HLEN);
260+
skb_reset_network_header(skb);
261+
skb_reset_transport_header(skb);
262+
258263
vid = tci & VLAN_VID_MASK;
259264
source_port = dsa_8021q_rx_source_port(vid);
260265
switch_id = dsa_8021q_rx_switch_id(vid);
@@ -283,12 +288,6 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
283288
return NULL;
284289
}
285290

286-
/* Delete/overwrite fake VLAN header, DSA expects to not find
287-
* it there, see dsa_switch_rcv: skb_push(skb, ETH_HLEN).
288-
*/
289-
if (is_tagged)
290-
skb = dsa_8021q_remove_header(skb);
291-
292291
return sja1105_rcv_meta_state_machine(skb, &meta, is_link_local,
293292
is_meta);
294293
}

0 commit comments

Comments
 (0)