Skip to content

Commit 0d5501c

Browse files
Vlad Yasevichdavem330
authored andcommitted
net: Always untag vlan-tagged traffic on input.
Currently the functionality to untag traffic on input resides as part of the vlan module and is build only when VLAN support is enabled in the kernel. When VLAN is disabled, the function vlan_untag() turns into a stub and doesn't really untag the packets. This seems to create an interesting interaction between VMs supporting checksum offloading and some network drivers. There are some drivers that do not allow the user to change tx-vlan-offload feature of the driver. These drivers also seem to assume that any VLAN-tagged traffic they transmit will have the vlan information in the vlan_tci and not in the vlan header already in the skb. When transmitting skbs that already have tagged data with partial checksum set, the checksum doesn't appear to be updated correctly by the card thus resulting in a failure to establish TCP connections. The following is a packet trace taken on the receiver where a sender is a VM with a VLAN configued. The host VM is running on doest not have VLAN support and the outging interface on the host is tg3: 10:12:43.503055 52:54:00:ae:42:3f > 28:d2:44:7d:c2:de, ethertype 802.1Q (0x8100), length 78: vlan 100, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 27243, offset 0, flags [DF], proto TCP (6), length 60) 10.0.100.1.58545 > 10.0.100.10.ircu-2: Flags [S], cksum 0xdc39 (incorrect -> 0x48d9), seq 1069378582, win 29200, options [mss 1460,sackOK,TS val 4294837885 ecr 0,nop,wscale 7], length 0 10:12:44.505556 52:54:00:ae:42:3f > 28:d2:44:7d:c2:de, ethertype 802.1Q (0x8100), length 78: vlan 100, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 27244, offset 0, flags [DF], proto TCP (6), length 60) 10.0.100.1.58545 > 10.0.100.10.ircu-2: Flags [S], cksum 0xdc39 (incorrect -> 0x44ee), seq 1069378582, win 29200, options [mss 1460,sackOK,TS val 4294838888 ecr 0,nop,wscale 7], length 0 This connection finally times out. I've only access to the TG3 hardware in this configuration thus have only tested this with TG3 driver. There are a lot of other drivers that do not permit user changes to vlan acceleration features, and I don't know if they all suffere from a similar issue. The patch attempt to fix this another way. It moves the vlan header stipping code out of the vlan module and always builds it into the kernel network core. This way, even if vlan is not supported on a virtualizatoin host, the virtual machines running on top of such host will still work with VLANs enabled. CC: Patrick McHardy <[email protected]> CC: Nithin Nayak Sujir <[email protected]> CC: Michael Chan <[email protected]> CC: Jiri Pirko <[email protected]> Signed-off-by: Vladislav Yasevich <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 217e606 commit 0d5501c

File tree

6 files changed

+56
-61
lines changed

6 files changed

+56
-61
lines changed

include/linux/if_vlan.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ vlan_dev_get_egress_qos_mask(struct net_device *dev, u32 skprio)
187187
}
188188

189189
extern bool vlan_do_receive(struct sk_buff **skb);
190-
extern struct sk_buff *vlan_untag(struct sk_buff *skb);
191190

192191
extern int vlan_vid_add(struct net_device *dev, __be16 proto, u16 vid);
193192
extern void vlan_vid_del(struct net_device *dev, __be16 proto, u16 vid);
@@ -241,11 +240,6 @@ static inline bool vlan_do_receive(struct sk_buff **skb)
241240
return false;
242241
}
243242

244-
static inline struct sk_buff *vlan_untag(struct sk_buff *skb)
245-
{
246-
return skb;
247-
}
248-
249243
static inline int vlan_vid_add(struct net_device *dev, __be16 proto, u16 vid)
250244
{
251245
return 0;

include/linux/skbuff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,7 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen);
25552555
void skb_scrub_packet(struct sk_buff *skb, bool xnet);
25562556
unsigned int skb_gso_transport_seglen(const struct sk_buff *skb);
25572557
struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features);
2558+
struct sk_buff *skb_vlan_untag(struct sk_buff *skb);
25582559

25592560
struct skb_checksum_ops {
25602561
__wsum (*update)(const void *mem, int len, __wsum wsum);

net/8021q/vlan_core.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -112,59 +112,6 @@ __be16 vlan_dev_vlan_proto(const struct net_device *dev)
112112
}
113113
EXPORT_SYMBOL(vlan_dev_vlan_proto);
114114

115-
static struct sk_buff *vlan_reorder_header(struct sk_buff *skb)
116-
{
117-
if (skb_cow(skb, skb_headroom(skb)) < 0) {
118-
kfree_skb(skb);
119-
return NULL;
120-
}
121-
122-
memmove(skb->data - ETH_HLEN, skb->data - VLAN_ETH_HLEN, 2 * ETH_ALEN);
123-
skb->mac_header += VLAN_HLEN;
124-
return skb;
125-
}
126-
127-
struct sk_buff *vlan_untag(struct sk_buff *skb)
128-
{
129-
struct vlan_hdr *vhdr;
130-
u16 vlan_tci;
131-
132-
if (unlikely(vlan_tx_tag_present(skb))) {
133-
/* vlan_tci is already set-up so leave this for another time */
134-
return skb;
135-
}
136-
137-
skb = skb_share_check(skb, GFP_ATOMIC);
138-
if (unlikely(!skb))
139-
goto err_free;
140-
141-
if (unlikely(!pskb_may_pull(skb, VLAN_HLEN)))
142-
goto err_free;
143-
144-
vhdr = (struct vlan_hdr *) skb->data;
145-
vlan_tci = ntohs(vhdr->h_vlan_TCI);
146-
__vlan_hwaccel_put_tag(skb, skb->protocol, vlan_tci);
147-
148-
skb_pull_rcsum(skb, VLAN_HLEN);
149-
vlan_set_encap_proto(skb, vhdr);
150-
151-
skb = vlan_reorder_header(skb);
152-
if (unlikely(!skb))
153-
goto err_free;
154-
155-
skb_reset_network_header(skb);
156-
skb_reset_transport_header(skb);
157-
skb_reset_mac_len(skb);
158-
159-
return skb;
160-
161-
err_free:
162-
kfree_skb(skb);
163-
return NULL;
164-
}
165-
EXPORT_SYMBOL(vlan_untag);
166-
167-
168115
/*
169116
* vlan info and vid list
170117
*/

net/bridge/br_vlan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
181181
*/
182182
if (unlikely(!vlan_tx_tag_present(skb) &&
183183
skb->protocol == proto)) {
184-
skb = vlan_untag(skb);
184+
skb = skb_vlan_untag(skb);
185185
if (unlikely(!skb))
186186
return false;
187187
}

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3602,7 +3602,7 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc)
36023602

36033603
if (skb->protocol == cpu_to_be16(ETH_P_8021Q) ||
36043604
skb->protocol == cpu_to_be16(ETH_P_8021AD)) {
3605-
skb = vlan_untag(skb);
3605+
skb = skb_vlan_untag(skb);
36063606
if (unlikely(!skb))
36073607
goto unlock;
36083608
}

net/core/skbuff.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <linux/scatterlist.h>
6363
#include <linux/errqueue.h>
6464
#include <linux/prefetch.h>
65+
#include <linux/if_vlan.h>
6566

6667
#include <net/protocol.h>
6768
#include <net/dst.h>
@@ -3973,3 +3974,55 @@ unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
39733974
return shinfo->gso_size;
39743975
}
39753976
EXPORT_SYMBOL_GPL(skb_gso_transport_seglen);
3977+
3978+
static struct sk_buff *skb_reorder_vlan_header(struct sk_buff *skb)
3979+
{
3980+
if (skb_cow(skb, skb_headroom(skb)) < 0) {
3981+
kfree_skb(skb);
3982+
return NULL;
3983+
}
3984+
3985+
memmove(skb->data - ETH_HLEN, skb->data - VLAN_ETH_HLEN, 2 * ETH_ALEN);
3986+
skb->mac_header += VLAN_HLEN;
3987+
return skb;
3988+
}
3989+
3990+
struct sk_buff *skb_vlan_untag(struct sk_buff *skb)
3991+
{
3992+
struct vlan_hdr *vhdr;
3993+
u16 vlan_tci;
3994+
3995+
if (unlikely(vlan_tx_tag_present(skb))) {
3996+
/* vlan_tci is already set-up so leave this for another time */
3997+
return skb;
3998+
}
3999+
4000+
skb = skb_share_check(skb, GFP_ATOMIC);
4001+
if (unlikely(!skb))
4002+
goto err_free;
4003+
4004+
if (unlikely(!pskb_may_pull(skb, VLAN_HLEN)))
4005+
goto err_free;
4006+
4007+
vhdr = (struct vlan_hdr *)skb->data;
4008+
vlan_tci = ntohs(vhdr->h_vlan_TCI);
4009+
__vlan_hwaccel_put_tag(skb, skb->protocol, vlan_tci);
4010+
4011+
skb_pull_rcsum(skb, VLAN_HLEN);
4012+
vlan_set_encap_proto(skb, vhdr);
4013+
4014+
skb = skb_reorder_vlan_header(skb);
4015+
if (unlikely(!skb))
4016+
goto err_free;
4017+
4018+
skb_reset_network_header(skb);
4019+
skb_reset_transport_header(skb);
4020+
skb_reset_mac_len(skb);
4021+
4022+
return skb;
4023+
4024+
err_free:
4025+
kfree_skb(skb);
4026+
return NULL;
4027+
}
4028+
EXPORT_SYMBOL(skb_vlan_untag);

0 commit comments

Comments
 (0)