From patchwork Sat Jul 18 09:17:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sriram Krishnan (srirakr2)" X-Patchwork-Id: 1331516 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=cisco.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=cisco.com header.i=@cisco.com header.a=rsa-sha256 header.s=iport header.b=XtU7NVYq; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4B82dN1dNtz9sRf for ; Sat, 18 Jul 2020 19:24:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbgGRJYu (ORCPT ); Sat, 18 Jul 2020 05:24:50 -0400 Received: from bgl-iport-2.cisco.com ([72.163.197.26]:17572 "EHLO bgl-iport-2.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgGRJYt (ORCPT ); Sat, 18 Jul 2020 05:24:49 -0400 X-Greylist: delayed 431 seconds by postgrey-1.27 at vger.kernel.org; Sat, 18 Jul 2020 05:24:48 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1947; q=dns/txt; s=iport; t=1595064289; x=1596273889; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WXHweetNurO6QLaPH79F1tHWP4XFhUThgJN70Mv6QcA=; b=XtU7NVYqgDzjQBgcBZ/BwrL9bvjzqXxUXRmjaz1LJpZ3AUxQ90unVzsk yYIbUxoVk8e1D7aZDPyIQ7T3fzVFcqoaP3bYI12KJ2wIGGOwQ3Oqy2GC9 iQfVKKN2md+Jixmf3utA5VBdSKYNUSkA9nQLT3C6xn6ICT0JdPgZv7vra Q=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CMAABtvRJf/xjFo0hgHQEBAQEJARIBBQUBgXgGAQsBg2wBIBIsjTSGTAEBAQEBAQaLSI97gX0LAQEBDi8EAQGETIIcJTYHDgIQAQEFAQEBAgEGBG2FZ4YdCwFGKYEVCwiDJoJYJak9gXUziH6BQBSBJAGIAoYCgQePEgSBQwGZbZoWBoJhmVQPIZ9ILbB7gVoJKoFXTSOBboFLUBkNjioXjiw5AzA3AgYIAQEDCY8lAQE X-IronPort-AV: E=Sophos;i="5.75,366,1589241600"; d="scan'208";a="156060473" Received: from vla196-nat.cisco.com (HELO bgl-core-2.cisco.com) ([72.163.197.24]) by bgl-iport-2.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 18 Jul 2020 09:17:33 +0000 Received: from SRIRAKR2-M-R0A8.cisco.com ([10.65.75.112]) by bgl-core-2.cisco.com (8.15.2/8.15.2) with ESMTP id 06I9HWXw006124; Sat, 18 Jul 2020 09:17:32 GMT From: Sriram Krishnan To: Andrew Morton Cc: xe-linux-external@cisco.com, "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] AF_PACKET doesnt strip VLAN information Date: Sat, 18 Jul 2020 14:47:31 +0530 Message-Id: <20200718091732.8761-1-srirakr2@cisco.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.65.75.112, [10.65.75.112] X-Outbound-Node: bgl-core-2.cisco.com Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When an application sends with AF_PACKET and places a vlan header on the raw packet; then the AF_PACKET needs to move the tag into the skb so that it gets processed normally through the rest of the transmit path. This is particularly a problem on Hyper-V where the host only allows vlan in the offload info. Cc: xe-linux-external@cisco.com Cc: Sriram Krishnan Signed-off-by: Sriram Krishnan Reported-by: kernel test robot --- net/packet/af_packet.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 29bd405adbbd..10988639561e 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1857,15 +1857,35 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, return 0; } -static void packet_parse_headers(struct sk_buff *skb, struct socket *sock) +static int packet_parse_headers(struct sk_buff *skb, struct socket *sock) { if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) && sock->type == SOCK_RAW) { + __be16 ethertype; + skb_reset_mac_header(skb); + + ethertype = eth_hdr(skb)->h_proto; + /* + * If Vlan tag is present in the packet + * move it to skb + */ + if (eth_type_vlan(ethertype)) { + int err; + __be16 vlan_tci; + + err = __skb_vlan_pop(skb, &vlan_tci); + if (unlikely(err)) + return err; + + __vlan_hwaccel_put_tag(skb, ethertype, vlan_tci); + } + skb->protocol = dev_parse_header_protocol(skb); } skb_probe_transport_header(skb); + return 0; } /* @@ -1987,7 +2007,9 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg, if (unlikely(extra_len == 4)) skb->no_fcs = 1; - packet_parse_headers(skb, sock); + err = packet_parse_headers(skb, sock); + if (err) + goto out_unlock; dev_queue_xmit(skb); rcu_read_unlock();