Skip to contentSkip to conversation

macvtap: fix network header pointer for VLAN tagged pkts

PATCH Superseded Ivan Vecera 2 participants 2 messages Jul 21, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 macvtap: fix network header pointer for VLAN tagged pkts

Network header is set with offset ETH_HLEN but it is not true for VLAN (multiple-)tagged and results in checksum issues in lower devices.

v2: leave skb->protocol untouched (thx Vlad), comment added

---
 drivers/net/macvtap.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/macvtap.c +7 -0
index 3b933bb..b75776b 100644
@@ -796,6 +796,13 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 	skb_reset_mac_header(skb);
 	skb->protocol = eth_hdr(skb)->h_proto;
 
+	/* Move network header to the right position for VLAN tagged packets */
+	if (skb_vlan_tagged(skb)) {
+		int depth;
+		__vlan_get_protocol(skb, skb->protocol, &depth);
+		skb_set_network_header(skb, depth);
+	}
+
 	if (vnet_hdr_len) {
 		err = macvtap_skb_from_vnet_hdr(q, skb, &vnet_hdr);
 		if (err)
Signature · 1 line
2.3.6
#1 lore raw
Quoted 15 lines · Ivan Vecera

Network header is set with offset ETH_HLEN but it is not true for VLAN (multiple-)tagged and results in checksum issues in lower devices.

v2: leave skb->protocol untouched (thx Vlad), comment added

---
  drivers/net/macvtap.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/net/macvtap.c +0 -0
index 3b933bb..b75776b 100644

drivers/net/macvtap.c static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, · line 800

Quoted 5 lines
drivers/net/macvtap.c +2 -0
@@ -796,6 +796,13 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
  	skb_reset_mac_header(skb);
  	skb->protocol = eth_hdr(skb)->h_proto;
 
+	/* Move network header to the right position for VLAN tagged packets */
+	if (skb_vlan_tagged(skb)) {

I guess you don't need the condition skb_vlan_tag_present(skb), i.e.,

if (skb->protocol == htons(ETH_P_8021Q) ||

    skb->protocol == htons(ETH_P_8021AD))

drivers/net/macvtap.c static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, · line 802

Quoted 2 lines
drivers/net/macvtap.c +2 -0
+		int depth;
+		__vlan_get_protocol(skb, skb->protocol, &depth);

__vlan_get_protocol() can fail, and then, depth will not be initialized.

drivers/net/macvtap.c static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, · line 803

Quoted 1 line
drivers/net/macvtap.c +1 -0
+		skb_set_network_header(skb, depth);

I think you should set network_header after skb_probe_transport_header(). It calls skb_flow_dissect_flow_keys(), which seems to expect network_header to be ETH_HLEN.

Toshiaki Makita