Skip to content

Commit fdd8fac

Browse files
Sriram Krishnandavem330
authored andcommitted
hv_netvsc: add support for vlans in AF_PACKET mode
Vlan tagged packets are getting dropped when used with DPDK that uses the AF_PACKET interface on a hyperV guest. The packet layer uses the tpacket interface to communicate the vlans information to the upper layers. On Rx path, these drivers can read the vlan info from the tpacket header but on the Tx path, this information is still within the packet frame and requires the paravirtual drivers to push this back into the NDIS header which is then used by the host OS to form the packet. This transition from the packet frame to NDIS header is currently missing hence causing the host OS to drop the all vlan tagged packets sent by the drivers that use AF_PACKET (ETH_P_ALL) such as DPDK. Here is an overview of the changes in the vlan header in the packet path: The RX path (userspace handles everything): 1. RX VLAN packet is stripped by HOST OS and placed in NDIS header 2. Guest Kernel RX hv_netvsc packets and moves VLAN info from NDIS header into kernel SKB 3. Kernel shares packets with user space application with PACKET_MMAP. The SKB VLAN info is copied to tpacket layer and indication set TP_STATUS_VLAN_VALID. 4. The user space application will re-insert the VLAN info into the frame The TX path: 1. The user space application has the VLAN info in the frame. 2. Guest kernel gets packets from the application with PACKET_MMAP. 3. The kernel later sends the frame to the hv_netvsc driver. The only way to send VLANs is when the SKB is setup & the VLAN is stripped from the frame. 4. TX VLAN is re-inserted by HOST OS based on the NDIS header. If it sees a VLAN in the frame the packet is dropped. Cc: xe-linux-external@cisco.com Cc: Sriram Krishnan <srirakr2@cisco.com> Signed-off-by: Sriram Krishnan <srirakr2@cisco.com> Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6ab301c commit fdd8fac

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎drivers/net/hyperv/hyperv_net.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ struct netvsc_ethtool_stats {
897897
unsigned long rx_no_memory;
898898
unsigned long stop_queue;
899899
unsigned long wake_queue;
900+
unsigned long vlan_error;
900901
};
901902

902903
struct netvsc_ethtool_pcpu_stats {

‎drivers/net/hyperv/netvsc_drv.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,29 @@ static int netvsc_xmit(struct sk_buff *skb, struct net_device *net, bool xdp_tx)
605605
*hash_info = hash;
606606
}
607607

608+
/* When using AF_PACKET we need to drop VLAN header from
609+
* the frame and update the SKB to allow the HOST OS
610+
* to transmit the 802.1Q packet
611+
*/
612+
if (skb->protocol == htons(ETH_P_8021Q)) {
613+
u16 vlan_tci;
614+
615+
skb_reset_mac_header(skb);
616+
if (eth_type_vlan(eth_hdr(skb)->h_proto)) {
617+
if (unlikely(__skb_vlan_pop(skb, &vlan_tci) != 0)) {
618+
++net_device_ctx->eth_stats.vlan_error;
619+
goto drop;
620+
}
621+
622+
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci);
623+
/* Update the NDIS header pkt lengths */
624+
packet->total_data_buflen -= VLAN_HLEN;
625+
packet->total_bytes -= VLAN_HLEN;
626+
rndis_msg->msg_len = packet->total_data_buflen;
627+
rndis_msg->msg.pkt.data_len = packet->total_data_buflen;
628+
}
629+
}
630+
608631
if (skb_vlan_tag_present(skb)) {
609632
struct ndis_pkt_8021q_info *vlan;
610633

@@ -1427,6 +1450,7 @@ static const struct {
14271450
{ "rx_no_memory", offsetof(struct netvsc_ethtool_stats, rx_no_memory) },
14281451
{ "stop_queue", offsetof(struct netvsc_ethtool_stats, stop_queue) },
14291452
{ "wake_queue", offsetof(struct netvsc_ethtool_stats, wake_queue) },
1453+
{ "vlan_error", offsetof(struct netvsc_ethtool_stats, vlan_error) },
14301454
}, pcpu_stats[] = {
14311455
{ "cpu%u_rx_packets",
14321456
offsetof(struct netvsc_ethtool_pcpu_stats, rx_packets) },

0 commit comments

Comments
 (0)